GrxExtraJointItem.java
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2008, AIST, the University of Tokyo and General Robotix Inc.
00003  * All rights reserved. This program is made available under the terms of the
00004  * Eclipse Public License v1.0 which accompanies this distribution, and is
00005  * available at http://www.eclipse.org/legal/epl-v10.html
00006  * Contributors:
00007  * General Robotix Inc.
00008  * National Institute of Advanced Industrial Science and Technology (AIST)
00009  */
00010 
00011 package com.generalrobotix.ui.item;
00012 
00013 import java.util.Iterator;
00014 import java.util.List;
00015 import java.util.Map;
00016 import java.util.Vector;
00017 
00018 import org.eclipse.jface.action.Action;
00019 import org.eclipse.jface.dialogs.InputDialog;
00020 import org.eclipse.jface.dialogs.MessageDialog;
00021 import org.eclipse.osgi.util.NLS;
00022 
00023 import jp.go.aist.hrp.simulator.ExtraJointInfo;
00024 import jp.go.aist.hrp.simulator.ExtraJointType;
00025 
00026 import com.generalrobotix.ui.GrxBaseItem;
00027 import com.generalrobotix.ui.GrxPluginManager;
00028 import com.generalrobotix.ui.GrxBasePlugin.ValueEditCombo;
00029 import com.generalrobotix.ui.GrxBasePlugin.ValueEditType;
00030 import com.generalrobotix.ui.util.MessageBundle;
00031 
00032 
00036 @SuppressWarnings("serial")
00037 
00038 public class GrxExtraJointItem extends GrxBaseItem {
00039         public static final String TITLE = "ExtraJoint";
00040         boolean isModel = true;
00041         private GrxModelItem model_;
00042         private GrxModelItem model1_, model2_;
00043         static final String[] extrajointTypeComboItem_ = new String[] { "xyz", "xy", "z" };
00044         
00045         public  GrxExtraJointItem(String name, GrxPluginManager manager) {
00046                 super(name, manager);
00047                 setIcon("extraJoint.png");
00048                 isModel = false;
00049                 model_ = null;
00050         }
00051         
00052         public GrxExtraJointItem(String name, GrxPluginManager manager, GrxModelItem model, ExtraJointInfo extraJointInfo) {
00053                 super(name, manager);
00054                 model_ = model;
00055                 
00056                 if(extraJointInfo != null){
00057                         setProperty("link1Name", extraJointInfo.link[0]);
00058                         setProperty("link2Name", extraJointInfo.link[1]);
00059                         setDblAry("link1LocalPos", extraJointInfo.point[0], 4);
00060                         setDblAry("link2LocalPos", extraJointInfo.point[1], 4);
00061                         if(extraJointInfo.jointType == ExtraJointType.EJ_XYZ){
00062                                 setProperty("jointType", "xyz");
00063                         }else if(extraJointInfo.jointType == ExtraJointType.EJ_XY){
00064                                 setProperty("jointType", "xy");
00065                         }else if(extraJointInfo.jointType == ExtraJointType.EJ_Z){
00066                                 setProperty("jointType", "z");
00067                         }
00068                         setDblAry("jointAxis", extraJointInfo.axis, 4);
00069                 }else{
00070                         setProperty("link1Name", "");
00071                         setProperty("link2Name", "");
00072                         setProperty("link1LocalPos", "0.0 0.0 0.0");
00073                         setProperty("link2LocalPos", "0.0 0.0 0.0");
00074                         setProperty("jointType", "xyz");
00075                         setProperty("jointAxis", "0 0 1");
00076                 }
00077         
00078                 setIcon("extraJoint.png");
00079         initMenu();
00080         }
00081         
00082         public void jointAxis(String axis){
00083         double[] newAxis = getDblAry(axis);
00084         if (newAxis != null && newAxis.length == 3){
00085                 setDblAry("jointAxis", newAxis, 4); 
00086                 if (model_ != null) model_.notifyModified();
00087         }  
00088     }
00089         
00090         public void link1LocalPos(String pos){
00091                 double[] newPos = getDblAry(pos);
00092         if (newPos != null && newPos.length == 3){
00093                 setDblAry("link1LocalPos", newPos, 4); 
00094                 if (model_ != null) model_.notifyModified();
00095         }  
00096         }
00097         
00098         public void link2LocalPos(String pos){
00099                 double[] newPos = getDblAry(pos);
00100         if (newPos != null && newPos.length == 3){
00101                 setDblAry("link2LocalPos", newPos, 4); 
00102                 if (model_ != null) model_.notifyModified();
00103         }  
00104         }
00105         
00106         public ValueEditType GetValueEditType(String key) {
00107                 if(key.equals("jointType"))
00108                 {
00109                         return new ValueEditCombo(extrajointTypeComboItem_);
00110                 }else if( key.equals("link1Name") || key.equals("link2Name") ){
00111                         String[] linkComboItem_ = null;
00112                         if(isModel){
00113                                 if(model_!=null){
00114                                         linkComboItem_ = model_.nameToLink_.keySet().toArray(new String[0]);
00115                                 }
00116                         }else{
00117                                 if( key.equals("link1Name") ){
00118                                         if(model1_!=null){
00119                                                 linkComboItem_ = model1_.nameToLink_.keySet().toArray(new String[0]);
00120                                         }
00121                                 }
00122                                 if( key.equals("link2Name") ){
00123                                         if(model2_!=null){
00124                                                 linkComboItem_ = model2_.nameToLink_.keySet().toArray(new String[0]);
00125                                         }
00126                                 }
00127                         }
00128                         if(linkComboItem_!=null)
00129                                 return new ValueEditCombo(linkComboItem_);
00130                         else
00131                                 return super.GetValueEditType(key);
00132                 }else if( key.equals("object1Name") || key.equals("object2Name") ){
00133                         if(!isModel){
00134                                 Map<?, ?> m = manager_.pluginMap_.get((GrxModelItem.class));
00135                             String[] modelComboItem_ = m.keySet().toArray(new String[0]);
00136                                 return new ValueEditCombo(modelComboItem_);
00137                         }
00138                 }
00139                 return super.GetValueEditType(key);
00140         }
00141         
00142         private void initMenu(){
00143                 getMenu().clear();
00144 
00145                 Action item;
00146 
00147                 // rename
00148                 item = new Action(){
00149                         public String getText(){
00150                                 return MessageBundle.get("GrxLinkItem.menu.rename"); //$NON-NLS-1$
00151                         }
00152                         public void run(){
00153                                 InputDialog dialog = new InputDialog( null, getText(),
00154                                                 MessageBundle.get("GrxLinkItem.dialog.message.rename"), getName(),null); //$NON-NLS-1$
00155                                 if ( dialog.open() == InputDialog.OK && dialog.getValue() != null)
00156                                         rename( dialog.getValue() );
00157                         }
00158                 };
00159                 setMenuItem(item);
00160 
00161                 // delete
00162                 item = new Action(){
00163                         public String getText(){
00164                                 return MessageBundle.get("GrxBaseItem.menu.delete"); //$NON-NLS-1$
00165                         }
00166                         public void run(){
00167                 String mes = MessageBundle.get("GrxBaseItem.dialog.message.delete"); //$NON-NLS-1$
00168                 mes = NLS.bind(mes, new String[]{getName()});
00169                                 if( MessageDialog.openQuestion( null, MessageBundle.get("GrxBaseItem.dialog.title.delete"), //$NON-NLS-1$
00170                                                 mes) )
00171                                         delete();
00172                         }
00173                 };
00174                 setMenuItem(item);
00175         }
00176         
00177         public boolean propertyChanged(String property, String value) {
00178                 if (property.equals("name")){ //$NON-NLS-1$
00179                         rename(value);
00180                 }else if(property.equals("link1Name")){
00181                         setProperty("link1Name", value);
00182                         if (model_ != null) model_.notifyModified();
00183                 }else if(property.equals("link2Name")){
00184                         setProperty("link2Name", value);
00185                         if (model_ != null) model_.notifyModified();
00186                 }else if(property.equals("link1LocalPos")){
00187                         link1LocalPos(value);
00188                 }else if(property.equals("link2LocalPos")){
00189                         link2LocalPos(value);
00190                 }else if(property.equals("jointType")){
00191                         setProperty("jointType", value);
00192                         if (model_ != null) model_.notifyModified();
00193                 }else if(property.equals("jointAxis")){
00194                         jointAxis(value);
00195                 }else if(property.equals("object1Name")){
00196                         setProperty("object1Name", value);
00197                         model1_ = (GrxModelItem)(manager_.getItem( GrxModelItem.class, value ));
00198                 }else if(property.equals("object2Name")){
00199                         setProperty("object2Name", value);
00200                         model2_ = (GrxModelItem)(manager_.getItem( GrxModelItem.class, value ));
00201                 }else
00202                         return false;
00203                 return true;
00204         }
00205         
00206         public void delete(){
00207                 if(isModel && model_!=null)
00208                         model_.removeExtraJoint(this);
00209                 super.delete();
00210         }
00211         
00212         public boolean create() {
00213                 setProperty("object1Name", "");
00214                 setProperty("object2Name", "");
00215                 setProperty("link1Name", "");
00216                 setProperty("link2Name", "");
00217                 setProperty("link1LocalPos", "0.0 0.0 0.0");
00218                 setProperty("link2LocalPos", "0.0 0.0 0.0");
00219                 setProperty("jointType", "xyz");
00220                 setProperty("jointAxis", "0 0 1");
00221                 return true;
00222         }
00223 }


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Thu Apr 11 2019 03:30:16