SimulationParameterPanel.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  */
00016 package com.generalrobotix.ui.view.simulation;
00017 
00018 import org.eclipse.swt.SWT;
00019 import org.eclipse.swt.events.SelectionEvent;
00020 import org.eclipse.swt.events.SelectionListener;
00021 import org.eclipse.swt.layout.GridData;
00022 import org.eclipse.swt.layout.GridLayout;
00023 import org.eclipse.swt.widgets.Button;
00024 import org.eclipse.swt.widgets.Combo;
00025 import org.eclipse.swt.widgets.Composite;
00026 import org.eclipse.swt.widgets.Control;
00027 import org.eclipse.swt.widgets.Label;
00028 
00029 import com.generalrobotix.ui.GrxBaseItem;
00030 import com.generalrobotix.ui.util.ItemPropertyDoubleSpinForSWT;
00031 import com.generalrobotix.ui.util.MessageBundle;
00032 import com.generalrobotix.ui.view.graph.SEEnumeration;
00033 
00034 @SuppressWarnings("serial") //$NON-NLS-1$
00035 public class SimulationParameterPanel extends Composite{
00036   private GrxBaseItem currentItem_;
00037   public static final String[] METHOD_NAMES = { "RUNGE_KUTTA", "EULER" }; //$NON-NLS-1$ //$NON-NLS-2$
00038   private static final SEEnumeration seTemp_ = new SEEnumeration(METHOD_NAMES, 0);
00039   
00040   private static final int COMBO_WIDTH = 100;
00041   private static final double MIN_TIME_STEP = 0.000001;
00042   
00043   ItemPropertyDoubleSpinForSWT spinTotalTime_;
00044   ItemPropertyDoubleSpinForSWT spinStepTime_;
00045   ItemPropertyDoubleSpinForSWT spinLogStepTime_;
00046   ItemPropertyDoubleSpinForSWT spinGravity_;
00047   Button chkIntegrate_;
00048   Button chkViewSimulate_;
00049   Button chkRealTime_;
00050   Combo cmbMethod_;
00051   
00052   public SimulationParameterPanel(Composite parent,int style) {
00053     super(parent, style);
00054     setLayout(new GridLayout(2,true));
00055 
00056     Label label = new Label(this,SWT.SHADOW_NONE);
00057     label.setText(MessageBundle.get("panel.simulation.start.title")); //$NON-NLS-1$
00058     //label.setBounds(12, 12, 240, 24);
00059 
00060     label = new Label(this,SWT.SHADOW_NONE);//dummy
00061 
00062     label = new Label(this,SWT.SHADOW_NONE);
00063     label.setText(MessageBundle.get("panel.simulation.start.totalTime")); //$NON-NLS-1$
00064     GridData gridData = new GridData();
00065     gridData.horizontalAlignment = SWT.END;
00066     label.setLayoutData(gridData);
00067     //label.setBounds(12, 12 + 36, 130, 24);
00068     
00069     spinTotalTime_ = new ItemPropertyDoubleSpinForSWT(this,SWT.NONE,MIN_TIME_STEP, Double.POSITIVE_INFINITY, 0.1);
00070     spinTotalTime_.setKey("totalTime"); //$NON-NLS-1$
00071     //spinTotalTime_.setBounds(12 + 130 + 6, 12 + 36, 100, 24);
00072 
00073     label = new Label(this,SWT.SHADOW_NONE);
00074     label.setText(MessageBundle.get("panel.simulation.start.stepTime")); //$NON-NLS-1$
00075     gridData = new GridData();
00076     gridData.horizontalAlignment = SWT.END;
00077     label.setLayoutData(gridData);
00078     //label.setBounds(12, 12 + 36 + 36, 130, 24);
00079     
00080     spinStepTime_ = new ItemPropertyDoubleSpinForSWT(this,SWT.NONE,MIN_TIME_STEP, 0.1, 0.001);
00081     spinStepTime_.setKey("timeStep"); //$NON-NLS-1$
00082     //spinStepTime_.setBounds(12 + 130 + 6, 12 + 36 + 36, 100, 24);
00083     
00084     label = new Label(this,SWT.SHADOW_NONE);
00085     label.setText(MessageBundle.get("panel.simulation.start.logStepTime")); //$NON-NLS-1$
00086     gridData = new GridData();
00087     gridData.horizontalAlignment = SWT.END;
00088     label.setLayoutData(gridData);
00089     //label.setBounds(12, 12 + 36 + 36 + 36, 130, 24);
00090 
00091     spinLogStepTime_ = new ItemPropertyDoubleSpinForSWT(this,SWT.NONE,0.00001, 0.1, 0.001);
00092     spinLogStepTime_.setKey("logTimeStep"); //$NON-NLS-1$
00093     //spinLogStepTime_.setBounds(12 + 130 + 6, 12 + 36 + 36 + 36, 100, 24);
00094     
00095     label = new Label(this,SWT.SHADOW_NONE);
00096     label.setText(MessageBundle.get("panel.simulation.start.method")); //$NON-NLS-1$
00097     gridData = new GridData();
00098     gridData.horizontalAlignment = SWT.END;
00099     label.setLayoutData(gridData);
00100     //label.setBounds(12, 12 + 36 + 36 + 36 + 36, 130, 24);
00101 
00102     cmbMethod_ = new Combo(this,SWT.DROP_DOWN | SWT.READ_ONLY);
00103     cmbMethod_.setItems(METHOD_NAMES);
00104     gridData = new GridData();
00105     gridData.widthHint = COMBO_WIDTH;
00106     cmbMethod_.setLayoutData(gridData);
00107     cmbMethod_.select(0);
00108     //cmbMethod_.setBounds(12 + 130 + 6, 12 + 36 + 36 + 36 + 36, 100, 24);
00109     cmbMethod_.addSelectionListener(new SelectionListener(){
00110 
00111         public void widgetDefaultSelected(SelectionEvent e) {
00112         }
00113 
00114         public void widgetSelected(SelectionEvent e) {
00115             if (currentItem_ != null)
00116                 currentItem_.setProperty("method", cmbMethod_.getText()); //$NON-NLS-1$
00117         }
00118         
00119     });
00120 
00121 //    cmbMethod_.removeAll();
00122 //    for (int i = 0; i < METHOD_NAMES.length; i++) {
00123 //        cmbMethod_.addItem(new SEEnumeration(METHOD_NAMES, i));
00124 //    }
00125 
00126     //-------------------------
00127 
00128     label = new Label(this,SWT.SHADOW_NONE);
00129     label.setText(MessageBundle.get("panel.simulation.start.gravitation")); //$NON-NLS-1$
00130     gridData = new GridData();
00131     gridData.horizontalAlignment = SWT.END;
00132     label.setLayoutData(gridData);
00133     //label.setBounds(12, 12 + 36 + 36 + 36 + 36 + 36, 130, 24);
00134 
00135     spinGravity_ = new ItemPropertyDoubleSpinForSWT(this,SWT.NONE,0, Double.POSITIVE_INFINITY, 0.1);
00136     spinGravity_.setKey("gravity"); //$NON-NLS-1$
00137     spinGravity_.setBounds(12 + 130 + 6, 12 + 36 + 36 + 36 + 36 + 36, 100, 24);
00138 
00139     chkIntegrate_ = new Button(this,SWT.CHECK);
00140     chkIntegrate_.setText(MessageBundle.get("panel.simulation.start.integrate")); //$NON-NLS-1$
00141     //chkIntegrate_.setBounds(12 + 80 + 6, 12 + 36 + 36 + 36 + 36 + 36 + 36, 160, 24);
00142     chkIntegrate_.addSelectionListener(new SelectionListener() {
00143 
00144         public void widgetDefaultSelected(SelectionEvent e) {
00145         }
00146 
00147         public void widgetSelected(SelectionEvent e) {
00148             if (currentItem_ != null)
00149                 currentItem_.setProperty("integrate", String.valueOf(chkIntegrate_.getSelection())); //$NON-NLS-1$
00150         }
00151     });
00152     
00153     label = new Label(this,SWT.SHADOW_NONE);//dummy
00154     
00155     chkRealTime_ = new Button(this,SWT.CHECK);
00156     chkRealTime_.setText(MessageBundle.get("panel.simulation.start.realTime")); //$NON-NLS-1$
00157     chkRealTime_.addSelectionListener(new SelectionListener() {
00158 
00159         public void widgetDefaultSelected(SelectionEvent e) {
00160         }
00161 
00162         public void widgetSelected(SelectionEvent e) {
00163             if (currentItem_ != null)
00164                 currentItem_.setProperty("realTime", String.valueOf(chkRealTime_.getSelection())); //$NON-NLS-1$
00165         }
00166     });
00167     
00168     label = new Label(this,SWT.SHADOW_NONE);//dummy
00169     
00170     chkViewSimulate_ = new Button(this,SWT.CHECK);
00171     chkViewSimulate_.setText(MessageBundle.get("panel.simulation.start.viewsimulate")); //$NON-NLS-1$
00172     chkViewSimulate_.addSelectionListener(new SelectionListener() {
00173         public void widgetDefaultSelected(SelectionEvent e) {
00174         }
00175 
00176         public void widgetSelected(SelectionEvent e) {
00177             if (currentItem_ != null)
00178                 currentItem_.setProperty("viewsimulate", String.valueOf(chkViewSimulate_.getSelection())); //$NON-NLS-1$
00179         }
00180 
00181     });
00182     //chkViewSimulate_.setBounds(12 + 80 + 6, 12 + 36 + 36 + 36 + 36 + 36 + 36 + 36, 160, 24);
00183     
00184     label = new Label(this,SWT.SHADOW_NONE);//dummy
00185 
00186     gridData = new GridData();
00187     gridData.horizontalAlignment = SWT.END;
00188     
00189     this.setSize(260,330);
00190     //setPreferredSize(new Dimension(260, 300));
00191   }
00192 
00193   public void setEnabled(boolean flag) {
00194     super.setEnabled(flag);
00195     Control[] cmps = this.getChildren();
00196     for (int i = 0; i < cmps.length; i++) {
00197       cmps[i].setEnabled(flag);
00198     }
00199   }
00200   
00201 
00202   public void setMethod(String method) {
00203     seTemp_.fromString(method);
00204     cmbMethod_.setText(cmbMethod_.getItem(seTemp_.getSelectedIndex()));
00205   }
00206   
00207   public void setStepTime(double time) {
00208     spinStepTime_.setValue(time);
00209   }
00210   
00211   public void setLogStepTime(double time) {
00212     spinLogStepTime_.setValue(time);
00213   }
00214   
00215   public void setTotalTime(double time) {
00216     spinTotalTime_.setValue(time);
00217   }
00218     
00219   public void setIntegrate(boolean f) {
00220     chkIntegrate_.setSelection(f);
00221   }
00222 
00223   public void setRealTime(boolean f) {
00224             chkRealTime_.setSelection(f);
00225           }
00226   
00227   public void setViewSimulate(boolean f) {
00228     chkViewSimulate_.setSelection(f);
00229   }
00230 
00231   public void setGravity(double g) {
00232     spinGravity_.setValue(g);
00233   }
00234 
00235   public double getStepTime() {
00236     return spinStepTime_.getValueDouble();
00237   }
00238   
00239   public double getLogStepTime() {
00240     return spinLogStepTime_.getValueDouble();
00241   }
00242   
00243   public double getTotalTime() {
00244       return spinTotalTime_.getValueDouble();
00245   }
00246   
00247   public boolean isIntegrate() {
00248     return chkIntegrate_.getSelection();
00249   }
00250 
00251   public boolean isSimulatingView() {
00252     return chkViewSimulate_.getSelection();
00253   }
00254 
00255   public double getGravity() {
00256             return spinGravity_.getValueDouble();
00257   }
00258   
00259   public SEEnumeration getMethod() {
00260       return new SEEnumeration(METHOD_NAMES,cmbMethod_.getSelectionIndex());
00261       //return (SEEnumeration) cmbMethod_.getSelectedItem();
00262   }
00263   
00264   public void updateItem(GrxBaseItem item) {
00265       setEnabled(item != null);
00266       currentItem_ = item;
00267       spinTotalTime_.setItem(item);
00268       spinStepTime_.setItem(item);
00269           spinGravity_.setItem(item);
00270           
00271           if (item != null) { 
00272                   setTotalTime(item.getDbl("totalTime", 20.0)); //$NON-NLS-1$
00273                   setStepTime(item.getDbl("timeStep", 0.001)); //$NON-NLS-1$
00274                   setGravity(item.getDbl("gravity", 9.8)); //$NON-NLS-1$
00275                   setMethod(item.getProperty("method",METHOD_NAMES[0])); //$NON-NLS-1$
00276                   setIntegrate(item.isTrue("integrate", true)); //$NON-NLS-1$
00277                   setRealTime(item.isTrue("realTime", false)); //$NON-NLS-1$
00278                   setViewSimulate(item.isTrue("viewsimulate", false)); //$NON-NLS-1$
00279                   setEnabled(true);
00280           }
00281   }
00282   
00283   public void updateLogTime(GrxBaseItem item) {
00284       setEnabled(item != null);
00285           spinLogStepTime_.setItem(item);
00286           if (item != null) { 
00287                   setLogStepTime(item.getDbl("logTimeStep", 0.001)); //$NON-NLS-1$
00288                   setEnabled(true);
00289           }
00290   }
00291 
00292   public void fixParam(){
00293       spinTotalTime_.fixValue();
00294       spinStepTime_.fixValue();
00295       spinLogStepTime_.fixValue();
00296       spinGravity_.fixValue();
00297   }
00298 }


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Sun Apr 2 2017 03:43:57