GrxExtraJointItem.java
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008, AIST, the University of Tokyo and General Robotix Inc.
3  * All rights reserved. This program is made available under the terms of the
4  * Eclipse Public License v1.0 which accompanies this distribution, and is
5  * available at http://www.eclipse.org/legal/epl-v10.html
6  * Contributors:
7  * General Robotix Inc.
8  * National Institute of Advanced Industrial Science and Technology (AIST)
9  */
10 
11 package com.generalrobotix.ui.item;
12 
13 import java.util.Iterator;
14 import java.util.List;
15 import java.util.Map;
16 import java.util.Vector;
17 
18 import org.eclipse.jface.action.Action;
19 import org.eclipse.jface.dialogs.InputDialog;
20 import org.eclipse.jface.dialogs.MessageDialog;
21 import org.eclipse.osgi.util.NLS;
22 
23 import jp.go.aist.hrp.simulator.ExtraJointInfo;
24 import jp.go.aist.hrp.simulator.ExtraJointType;
25 
31 
32 
36 @SuppressWarnings("serial")
37 
38 public class GrxExtraJointItem extends GrxBaseItem {
39  public static final String TITLE = "ExtraJoint";
40  boolean isModel = true;
42  private GrxModelItem model1_, model2_;
43  static final String[] extrajointTypeComboItem_ = new String[] { "xyz", "xy", "z" };
44 
45  public GrxExtraJointItem(String name, GrxPluginManager manager) {
46  super(name, manager);
47  setIcon("extraJoint.png");
48  isModel = false;
49  model_ = null;
50  }
51 
52  public GrxExtraJointItem(String name, GrxPluginManager manager, GrxModelItem model, ExtraJointInfo extraJointInfo) {
53  super(name, manager);
54  model_ = model;
55 
56  if(extraJointInfo != null){
57  setProperty("link1Name", extraJointInfo.link[0]);
58  setProperty("link2Name", extraJointInfo.link[1]);
59  setDblAry("link1LocalPos", extraJointInfo.point[0], 4);
60  setDblAry("link2LocalPos", extraJointInfo.point[1], 4);
61  if(extraJointInfo.jointType == ExtraJointType.EJ_XYZ){
62  setProperty("jointType", "xyz");
63  }else if(extraJointInfo.jointType == ExtraJointType.EJ_XY){
64  setProperty("jointType", "xy");
65  }else if(extraJointInfo.jointType == ExtraJointType.EJ_Z){
66  setProperty("jointType", "z");
67  }
68  setDblAry("jointAxis", extraJointInfo.axis, 4);
69  }else{
70  setProperty("link1Name", "");
71  setProperty("link2Name", "");
72  setProperty("link1LocalPos", "0.0 0.0 0.0");
73  setProperty("link2LocalPos", "0.0 0.0 0.0");
74  setProperty("jointType", "xyz");
75  setProperty("jointAxis", "0 0 1");
76  }
77 
78  setIcon("extraJoint.png");
79  initMenu();
80  }
81 
82  public void jointAxis(String axis){
83  double[] newAxis = getDblAry(axis);
84  if (newAxis != null && newAxis.length == 3){
85  setDblAry("jointAxis", newAxis, 4);
86  if (model_ != null) model_.notifyModified();
87  }
88  }
89 
90  public void link1LocalPos(String pos){
91  double[] newPos = getDblAry(pos);
92  if (newPos != null && newPos.length == 3){
93  setDblAry("link1LocalPos", newPos, 4);
94  if (model_ != null) model_.notifyModified();
95  }
96  }
97 
98  public void link2LocalPos(String pos){
99  double[] newPos = getDblAry(pos);
100  if (newPos != null && newPos.length == 3){
101  setDblAry("link2LocalPos", newPos, 4);
102  if (model_ != null) model_.notifyModified();
103  }
104  }
105 
106  public ValueEditType GetValueEditType(String key) {
107  if(key.equals("jointType"))
108  {
109  return new ValueEditCombo(extrajointTypeComboItem_);
110  }else if( key.equals("link1Name") || key.equals("link2Name") ){
111  String[] linkComboItem_ = null;
112  if(isModel){
113  if(model_!=null){
114  linkComboItem_ = model_.nameToLink_.keySet().toArray(new String[0]);
115  }
116  }else{
117  if( key.equals("link1Name") ){
118  if(model1_!=null){
119  linkComboItem_ = model1_.nameToLink_.keySet().toArray(new String[0]);
120  }
121  }
122  if( key.equals("link2Name") ){
123  if(model2_!=null){
124  linkComboItem_ = model2_.nameToLink_.keySet().toArray(new String[0]);
125  }
126  }
127  }
128  if(linkComboItem_!=null)
129  return new ValueEditCombo(linkComboItem_);
130  else
131  return super.GetValueEditType(key);
132  }else if( key.equals("object1Name") || key.equals("object2Name") ){
133  if(!isModel){
134  Map<?, ?> m = manager_.pluginMap_.get((GrxModelItem.class));
135  String[] modelComboItem_ = m.keySet().toArray(new String[0]);
136  return new ValueEditCombo(modelComboItem_);
137  }
138  }
139  return super.GetValueEditType(key);
140  }
141 
142  private void initMenu(){
143  getMenu().clear();
144 
145  Action item;
146 
147  // rename
148  item = new Action(){
149  public String getText(){
150  return MessageBundle.get("GrxLinkItem.menu.rename"); //$NON-NLS-1$
151  }
152  public void run(){
153  InputDialog dialog = new InputDialog( null, getText(),
154  MessageBundle.get("GrxLinkItem.dialog.message.rename"), getName(),null); //$NON-NLS-1$
155  if ( dialog.open() == InputDialog.OK && dialog.getValue() != null)
156  rename( dialog.getValue() );
157  }
158  };
159  setMenuItem(item);
160 
161  // delete
162  item = new Action(){
163  public String getText(){
164  return MessageBundle.get("GrxBaseItem.menu.delete"); //$NON-NLS-1$
165  }
166  public void run(){
167  String mes = MessageBundle.get("GrxBaseItem.dialog.message.delete"); //$NON-NLS-1$
168  mes = NLS.bind(mes, new String[]{getName()});
169  if( MessageDialog.openQuestion( null, MessageBundle.get("GrxBaseItem.dialog.title.delete"), //$NON-NLS-1$
170  mes) )
171  delete();
172  }
173  };
174  setMenuItem(item);
175  }
176 
177  public boolean propertyChanged(String property, String value) {
178  if (property.equals("name")){ //$NON-NLS-1$
179  rename(value);
180  }else if(property.equals("link1Name")){
181  setProperty("link1Name", value);
182  if (model_ != null) model_.notifyModified();
183  }else if(property.equals("link2Name")){
184  setProperty("link2Name", value);
185  if (model_ != null) model_.notifyModified();
186  }else if(property.equals("link1LocalPos")){
187  link1LocalPos(value);
188  }else if(property.equals("link2LocalPos")){
189  link2LocalPos(value);
190  }else if(property.equals("jointType")){
191  setProperty("jointType", value);
192  if (model_ != null) model_.notifyModified();
193  }else if(property.equals("jointAxis")){
194  jointAxis(value);
195  }else if(property.equals("object1Name")){
196  setProperty("object1Name", value);
197  model1_ = (GrxModelItem)(manager_.getItem( GrxModelItem.class, value ));
198  }else if(property.equals("object2Name")){
199  setProperty("object2Name", value);
200  model2_ = (GrxModelItem)(manager_.getItem( GrxModelItem.class, value ));
201  }else
202  return false;
203  return true;
204  }
205 
206  public void delete(){
207  if(isModel && model_!=null)
208  model_.removeExtraJoint(this);
209  super.delete();
210  }
211 
212  public boolean create() {
213  setProperty("object1Name", "");
214  setProperty("object2Name", "");
215  setProperty("link1Name", "");
216  setProperty("link2Name", "");
217  setProperty("link1LocalPos", "0.0 0.0 0.0");
218  setProperty("link2LocalPos", "0.0 0.0 0.0");
219  setProperty("jointType", "xyz");
220  setProperty("jointAxis", "0 0 1");
221  return true;
222  }
223 }
static final String get(String key)
#define null
our own NULL pointer
Definition: IceTypes.h:57
GrxExtraJointItem(String name, GrxPluginManager manager, GrxModelItem model, ExtraJointInfo extraJointInfo)
png_infop png_charpp name
Definition: png.h:2382
png_voidp int value
Definition: png.h:2113
item corresponds to a robot model
void notifyModified()
notify this model is modified
Map< String, GrxLinkItem > nameToLink_
GrxExtraJointItem(String name, GrxPluginManager manager)
void removeExtraJoint(GrxExtraJointItem extraJoint)
def run(tree, args)
プラグイン管理クラス GrxUIの核になるクラス。プラグインのロード等の、初期化を実行する。 プラグインとそ...
def getText(self, nodes=None)
org
boolean propertyChanged(String property, String value)


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Sat May 8 2021 02:42:38