SimulationParameterPanel.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  */
16 package com.generalrobotix.ui.view.simulation;
17 
18 import org.eclipse.swt.SWT;
19 import org.eclipse.swt.events.SelectionEvent;
20 import org.eclipse.swt.events.SelectionListener;
21 import org.eclipse.swt.layout.GridData;
22 import org.eclipse.swt.layout.GridLayout;
23 import org.eclipse.swt.widgets.Button;
24 import org.eclipse.swt.widgets.Combo;
25 import org.eclipse.swt.widgets.Composite;
26 import org.eclipse.swt.widgets.Control;
27 import org.eclipse.swt.widgets.Label;
28 
33 
34 @SuppressWarnings("serial") //$NON-NLS-1$
35 public class SimulationParameterPanel extends Composite{
37  public static final String[] METHOD_NAMES = { "RUNGE_KUTTA", "EULER" }; //$NON-NLS-1$ //$NON-NLS-2$
38  private static final SEEnumeration seTemp_ = new SEEnumeration(METHOD_NAMES, 0);
39 
40  private static final int COMBO_WIDTH = 100;
41  private static final double MIN_TIME_STEP = 0.000001;
42 
43  ItemPropertyDoubleSpinForSWT spinTotalTime_;
44  ItemPropertyDoubleSpinForSWT spinStepTime_;
45  ItemPropertyDoubleSpinForSWT spinLogStepTime_;
46  ItemPropertyDoubleSpinForSWT spinGravity_;
47  Button chkIntegrate_;
48  Button chkViewSimulate_;
49  Button chkRealTime_;
50  Combo cmbMethod_;
51 
52  public SimulationParameterPanel(Composite parent,int style) {
53  super(parent, style);
54  setLayout(new GridLayout(2,true));
55 
56  Label label = new Label(this,SWT.SHADOW_NONE);
57  label.setText(MessageBundle.get("panel.simulation.start.title")); //$NON-NLS-1$
58  //label.setBounds(12, 12, 240, 24);
59 
60  label = new Label(this,SWT.SHADOW_NONE);//dummy
61 
62  label = new Label(this,SWT.SHADOW_NONE);
63  label.setText(MessageBundle.get("panel.simulation.start.totalTime")); //$NON-NLS-1$
64  GridData gridData = new GridData();
65  gridData.horizontalAlignment = SWT.END;
66  label.setLayoutData(gridData);
67  //label.setBounds(12, 12 + 36, 130, 24);
68 
69  spinTotalTime_ = new ItemPropertyDoubleSpinForSWT(this,SWT.NONE,MIN_TIME_STEP, Double.POSITIVE_INFINITY, 0.1);
70  spinTotalTime_.setKey("totalTime"); //$NON-NLS-1$
71  //spinTotalTime_.setBounds(12 + 130 + 6, 12 + 36, 100, 24);
72 
73  label = new Label(this,SWT.SHADOW_NONE);
74  label.setText(MessageBundle.get("panel.simulation.start.stepTime")); //$NON-NLS-1$
75  gridData = new GridData();
76  gridData.horizontalAlignment = SWT.END;
77  label.setLayoutData(gridData);
78  //label.setBounds(12, 12 + 36 + 36, 130, 24);
79 
80  spinStepTime_ = new ItemPropertyDoubleSpinForSWT(this,SWT.NONE,MIN_TIME_STEP, 0.1, 0.001);
81  spinStepTime_.setKey("timeStep"); //$NON-NLS-1$
82  //spinStepTime_.setBounds(12 + 130 + 6, 12 + 36 + 36, 100, 24);
83 
84  label = new Label(this,SWT.SHADOW_NONE);
85  label.setText(MessageBundle.get("panel.simulation.start.logStepTime")); //$NON-NLS-1$
86  gridData = new GridData();
87  gridData.horizontalAlignment = SWT.END;
88  label.setLayoutData(gridData);
89  //label.setBounds(12, 12 + 36 + 36 + 36, 130, 24);
90 
91  spinLogStepTime_ = new ItemPropertyDoubleSpinForSWT(this,SWT.NONE,0.00001, 0.1, 0.001);
92  spinLogStepTime_.setKey("logTimeStep"); //$NON-NLS-1$
93  //spinLogStepTime_.setBounds(12 + 130 + 6, 12 + 36 + 36 + 36, 100, 24);
94 
95  label = new Label(this,SWT.SHADOW_NONE);
96  label.setText(MessageBundle.get("panel.simulation.start.method")); //$NON-NLS-1$
97  gridData = new GridData();
98  gridData.horizontalAlignment = SWT.END;
99  label.setLayoutData(gridData);
100  //label.setBounds(12, 12 + 36 + 36 + 36 + 36, 130, 24);
101 
102  cmbMethod_ = new Combo(this,SWT.DROP_DOWN | SWT.READ_ONLY);
103  cmbMethod_.setItems(METHOD_NAMES);
104  gridData = new GridData();
105  gridData.widthHint = COMBO_WIDTH;
106  cmbMethod_.setLayoutData(gridData);
107  cmbMethod_.select(0);
108  //cmbMethod_.setBounds(12 + 130 + 6, 12 + 36 + 36 + 36 + 36, 100, 24);
109  cmbMethod_.addSelectionListener(new SelectionListener(){
110 
111  public void widgetDefaultSelected(SelectionEvent e) {
112  }
113 
114  public void widgetSelected(SelectionEvent e) {
115  if (currentItem_ != null)
116  currentItem_.setProperty("method", cmbMethod_.getText()); //$NON-NLS-1$
117  }
118 
119  });
120 
121 // cmbMethod_.removeAll();
122 // for (int i = 0; i < METHOD_NAMES.length; i++) {
123 // cmbMethod_.addItem(new SEEnumeration(METHOD_NAMES, i));
124 // }
125 
126  //-------------------------
127 
128  label = new Label(this,SWT.SHADOW_NONE);
129  label.setText(MessageBundle.get("panel.simulation.start.gravitation")); //$NON-NLS-1$
130  gridData = new GridData();
131  gridData.horizontalAlignment = SWT.END;
132  label.setLayoutData(gridData);
133  //label.setBounds(12, 12 + 36 + 36 + 36 + 36 + 36, 130, 24);
134 
135  spinGravity_ = new ItemPropertyDoubleSpinForSWT(this,SWT.NONE,0, Double.POSITIVE_INFINITY, 0.1);
136  spinGravity_.setKey("gravity"); //$NON-NLS-1$
137  spinGravity_.setBounds(12 + 130 + 6, 12 + 36 + 36 + 36 + 36 + 36, 100, 24);
138 
139  chkIntegrate_ = new Button(this,SWT.CHECK);
140  chkIntegrate_.setText(MessageBundle.get("panel.simulation.start.integrate")); //$NON-NLS-1$
141  //chkIntegrate_.setBounds(12 + 80 + 6, 12 + 36 + 36 + 36 + 36 + 36 + 36, 160, 24);
142  chkIntegrate_.addSelectionListener(new SelectionListener() {
143 
144  public void widgetDefaultSelected(SelectionEvent e) {
145  }
146 
147  public void widgetSelected(SelectionEvent e) {
148  if (currentItem_ != null)
149  currentItem_.setProperty("integrate", String.valueOf(chkIntegrate_.getSelection())); //$NON-NLS-1$
150  }
151  });
152 
153  label = new Label(this,SWT.SHADOW_NONE);//dummy
154 
155  chkRealTime_ = new Button(this,SWT.CHECK);
156  chkRealTime_.setText(MessageBundle.get("panel.simulation.start.realTime")); //$NON-NLS-1$
157  chkRealTime_.addSelectionListener(new SelectionListener() {
158 
159  public void widgetDefaultSelected(SelectionEvent e) {
160  }
161 
162  public void widgetSelected(SelectionEvent e) {
163  if (currentItem_ != null)
164  currentItem_.setProperty("realTime", String.valueOf(chkRealTime_.getSelection())); //$NON-NLS-1$
165  }
166  });
167 
168  label = new Label(this,SWT.SHADOW_NONE);//dummy
169 
170  chkViewSimulate_ = new Button(this,SWT.CHECK);
171  chkViewSimulate_.setText(MessageBundle.get("panel.simulation.start.viewsimulate")); //$NON-NLS-1$
172  chkViewSimulate_.addSelectionListener(new SelectionListener() {
173  public void widgetDefaultSelected(SelectionEvent e) {
174  }
175 
176  public void widgetSelected(SelectionEvent e) {
177  if (currentItem_ != null)
178  currentItem_.setProperty("viewsimulate", String.valueOf(chkViewSimulate_.getSelection())); //$NON-NLS-1$
179  }
180 
181  });
182  //chkViewSimulate_.setBounds(12 + 80 + 6, 12 + 36 + 36 + 36 + 36 + 36 + 36 + 36, 160, 24);
183 
184  label = new Label(this,SWT.SHADOW_NONE);//dummy
185 
186  gridData = new GridData();
187  gridData.horizontalAlignment = SWT.END;
188 
189  this.setSize(260,330);
190  //setPreferredSize(new Dimension(260, 300));
191  }
192 
193  public void setEnabled(boolean flag) {
194  super.setEnabled(flag);
195  Control[] cmps = this.getChildren();
196  for (int i = 0; i < cmps.length; i++) {
197  cmps[i].setEnabled(flag);
198  }
199  }
200 
201 
202  public void setMethod(String method) {
203  seTemp_.fromString(method);
204  cmbMethod_.setText(cmbMethod_.getItem(seTemp_.getSelectedIndex()));
205  }
206 
207  public void setStepTime(double time) {
208  spinStepTime_.setValue(time);
209  }
210 
211  public void setLogStepTime(double time) {
212  spinLogStepTime_.setValue(time);
213  }
214 
215  public void setTotalTime(double time) {
216  spinTotalTime_.setValue(time);
217  }
218 
219  public void setIntegrate(boolean f) {
220  chkIntegrate_.setSelection(f);
221  }
222 
223  public void setRealTime(boolean f) {
224  chkRealTime_.setSelection(f);
225  }
226 
227  public void setViewSimulate(boolean f) {
228  chkViewSimulate_.setSelection(f);
229  }
230 
231  public void setGravity(double g) {
232  spinGravity_.setValue(g);
233  }
234 
235  public double getStepTime() {
236  return spinStepTime_.getValueDouble();
237  }
238 
239  public double getLogStepTime() {
240  return spinLogStepTime_.getValueDouble();
241  }
242 
243  public double getTotalTime() {
244  return spinTotalTime_.getValueDouble();
245  }
246 
247  public boolean isIntegrate() {
248  return chkIntegrate_.getSelection();
249  }
250 
251  public boolean isSimulatingView() {
252  return chkViewSimulate_.getSelection();
253  }
254 
255  public double getGravity() {
256  return spinGravity_.getValueDouble();
257  }
258 
260  return new SEEnumeration(METHOD_NAMES,cmbMethod_.getSelectionIndex());
261  //return (SEEnumeration) cmbMethod_.getSelectedItem();
262  }
263 
264  public void updateItem(GrxBaseItem item) {
265  setEnabled(item != null);
266  currentItem_ = item;
267  spinTotalTime_.setItem(item);
268  spinStepTime_.setItem(item);
269  spinGravity_.setItem(item);
270 
271  if (item != null) {
272  setTotalTime(item.getDbl("totalTime", 20.0)); //$NON-NLS-1$
273  setStepTime(item.getDbl("timeStep", 0.001)); //$NON-NLS-1$
274  setGravity(item.getDbl("gravity", 9.8)); //$NON-NLS-1$
275  setMethod(item.getProperty("method",METHOD_NAMES[0])); //$NON-NLS-1$
276  setIntegrate(item.isTrue("integrate", true)); //$NON-NLS-1$
277  setRealTime(item.isTrue("realTime", false)); //$NON-NLS-1$
278  setViewSimulate(item.isTrue("viewsimulate", false)); //$NON-NLS-1$
279  setEnabled(true);
280  }
281  }
282 
284  setEnabled(item != null);
285  spinLogStepTime_.setItem(item);
286  if (item != null) {
287  setLogStepTime(item.getDbl("logTimeStep", 0.001)); //$NON-NLS-1$
288  setEnabled(true);
289  }
290  }
291 
292  public void fixParam(){
293  spinTotalTime_.fixValue();
294  spinStepTime_.fixValue();
295  spinLogStepTime_.fixValue();
296  spinGravity_.fixValue();
297  }
298 }
static final String get(String key)
final boolean isTrue(String key)
check whether value associated to key includes a word "true"
#define null
our own NULL pointer
Definition: IceTypes.h:57
png_uint_32 i
Definition: png.h:2735
int method
Definition: png.h:1847
Object setProperty(String key, String value)
set property value associated with a keyword
final Double getDbl(String key, Double defaultVal)
get double value associated to key
org
png_infop png_uint_32 flag
Definition: png.h:2159


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:41