00001
00002
00003
00004
00005
00006
00007
00008
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")
00035 public class SimulationParameterPanel extends Composite{
00036 private GrxBaseItem currentItem_;
00037 public static final String[] METHOD_NAMES = { "RUNGE_KUTTA", "EULER" };
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"));
00058
00059
00060 label = new Label(this,SWT.SHADOW_NONE);
00061
00062 label = new Label(this,SWT.SHADOW_NONE);
00063 label.setText(MessageBundle.get("panel.simulation.start.totalTime"));
00064 GridData gridData = new GridData();
00065 gridData.horizontalAlignment = SWT.END;
00066 label.setLayoutData(gridData);
00067
00068
00069 spinTotalTime_ = new ItemPropertyDoubleSpinForSWT(this,SWT.NONE,MIN_TIME_STEP, Double.POSITIVE_INFINITY, 0.1);
00070 spinTotalTime_.setKey("totalTime");
00071
00072
00073 label = new Label(this,SWT.SHADOW_NONE);
00074 label.setText(MessageBundle.get("panel.simulation.start.stepTime"));
00075 gridData = new GridData();
00076 gridData.horizontalAlignment = SWT.END;
00077 label.setLayoutData(gridData);
00078
00079
00080 spinStepTime_ = new ItemPropertyDoubleSpinForSWT(this,SWT.NONE,MIN_TIME_STEP, 0.1, 0.001);
00081 spinStepTime_.setKey("timeStep");
00082
00083
00084 label = new Label(this,SWT.SHADOW_NONE);
00085 label.setText(MessageBundle.get("panel.simulation.start.logStepTime"));
00086 gridData = new GridData();
00087 gridData.horizontalAlignment = SWT.END;
00088 label.setLayoutData(gridData);
00089
00090
00091 spinLogStepTime_ = new ItemPropertyDoubleSpinForSWT(this,SWT.NONE,0.00001, 0.1, 0.001);
00092 spinLogStepTime_.setKey("logTimeStep");
00093
00094
00095 label = new Label(this,SWT.SHADOW_NONE);
00096 label.setText(MessageBundle.get("panel.simulation.start.method"));
00097 gridData = new GridData();
00098 gridData.horizontalAlignment = SWT.END;
00099 label.setLayoutData(gridData);
00100
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
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());
00117 }
00118
00119 });
00120
00121
00122
00123
00124
00125
00126
00127
00128 label = new Label(this,SWT.SHADOW_NONE);
00129 label.setText(MessageBundle.get("panel.simulation.start.gravitation"));
00130 gridData = new GridData();
00131 gridData.horizontalAlignment = SWT.END;
00132 label.setLayoutData(gridData);
00133
00134
00135 spinGravity_ = new ItemPropertyDoubleSpinForSWT(this,SWT.NONE,0, Double.POSITIVE_INFINITY, 0.1);
00136 spinGravity_.setKey("gravity");
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"));
00141
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()));
00150 }
00151 });
00152
00153 label = new Label(this,SWT.SHADOW_NONE);
00154
00155 chkRealTime_ = new Button(this,SWT.CHECK);
00156 chkRealTime_.setText(MessageBundle.get("panel.simulation.start.realTime"));
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()));
00165 }
00166 });
00167
00168 label = new Label(this,SWT.SHADOW_NONE);
00169
00170 chkViewSimulate_ = new Button(this,SWT.CHECK);
00171 chkViewSimulate_.setText(MessageBundle.get("panel.simulation.start.viewsimulate"));
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()));
00179 }
00180
00181 });
00182
00183
00184 label = new Label(this,SWT.SHADOW_NONE);
00185
00186 gridData = new GridData();
00187 gridData.horizontalAlignment = SWT.END;
00188
00189 this.setSize(260,330);
00190
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
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));
00273 setStepTime(item.getDbl("timeStep", 0.001));
00274 setGravity(item.getDbl("gravity", 9.8));
00275 setMethod(item.getProperty("method",METHOD_NAMES[0]));
00276 setIntegrate(item.isTrue("integrate", true));
00277 setRealTime(item.isTrue("realTime", false));
00278 setViewSimulate(item.isTrue("viewsimulate", false));
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));
00288 setEnabled(true);
00289 }
00290 }
00291
00292 public void fixParam(){
00293 spinTotalTime_.fixValue();
00294 spinStepTime_.fixValue();
00295 spinLogStepTime_.fixValue();
00296 spinGravity_.fixValue();
00297 }
00298 }