Math2mat
|
00001 00020 package m2m.frontend.actions; 00021 00022 import org.eclipse.jface.dialogs.Dialog; 00023 import org.eclipse.jface.dialogs.MessageDialog; 00024 import org.eclipse.swt.SWT; 00025 import org.eclipse.swt.layout.GridData; 00026 import org.eclipse.swt.layout.GridLayout; 00027 import org.eclipse.swt.widgets.Button; 00028 import org.eclipse.swt.widgets.Combo; 00029 import org.eclipse.swt.widgets.Composite; 00030 import org.eclipse.swt.widgets.Control; 00031 import org.eclipse.swt.widgets.Display; 00032 import org.eclipse.swt.widgets.Group; 00033 import org.eclipse.swt.widgets.Label; 00034 import org.eclipse.swt.widgets.Shell; 00035 import org.eclipse.swt.widgets.Spinner; 00036 import org.eclipse.swt.widgets.Text; 00037 import org.eclipse.ui.IWorkbenchWindow; 00038 00039 import m2m.backend.buildingblocks.BuildingBlock.NumType; 00040 import m2m.backend.project.M2MProject; 00041 import m2m.backend.project.OptimisationProperties; 00042 import m2m.frontend.actions.M2MAction; 00043 import m2m.frontend.view.Editor; 00044 00045 00046 public class ConfigureOptimisationAction extends M2MAction{ 00047 00048 00049 public ConfigureOptimisationAction(IWorkbenchWindow window, String label) { 00050 super(window,label); 00051 // The id is used to refer to the action in a menu or toolbar 00052 setId(ICommandIds.CMD_CONFOPTIM); 00053 // Associate the action with a pre-defined command, to allow key bindings. 00054 setActionDefinitionId(ICommandIds.CMD_CONFOPTIM); 00055 //setImageDescriptor(m2mgui.Activator.getImageDescriptor("/icons/open.gif")); 00056 } 00057 00061 public void run() { 00062 00063 00064 if (!getEditor("Error","Select the tab with the code you want to transform in VHDL")) 00065 return; 00066 00067 Display display = window.getShell().getDisplay(); 00068 final Shell shell = new Shell(display); 00069 shell.setText("Simulation configuration"); 00070 OptimisationPropertiesDlg dlg=new OptimisationPropertiesDlg(shell,editor.getM2MProject()); 00071 dlg.setOptimisationProperties(editor.getM2MProject().getOptimisationProperties()); 00072 dlg.open(); 00073 if (dlg.pressedOk()) { 00074 editor.setModified(true); 00075 } 00076 // editor.saveProject(); 00077 00078 } 00079 00080 00081 00082 00083 class OptimisationPropertiesDlg extends Dialog { 00084 00085 00089 private OptimisationProperties optimProp; 00093 private Editor editor; 00094 00098 private Combo optimChoice; 00102 private Combo dataTypeChoice; 00106 private Text freq; 00110 private Combo fifoChoice; 00111 00115 private Spinner fifoSize; 00116 00120 private Button optFifo; 00121 00125 private Button fifoComp; 00126 00130 private M2MProject project; 00131 00135 private boolean pressedOnOk; 00136 00137 00138 public OptimisationPropertiesDlg(Shell parentShell,M2MProject project) { 00139 super(parentShell); 00140 pressedOnOk=false; 00141 this.project=project; 00142 } 00143 00144 protected void configureShell(Shell shell) { 00145 super.configureShell(shell); 00146 shell.setText("Optimisation properties"); 00147 } 00148 00149 00150 @Override 00151 public void create() { 00152 super.create(); 00153 } 00154 00155 @Override 00156 protected Control createDialogArea(Composite parent) { 00157 00158 //create global GridLayout 00159 GridLayout globalGridLayout = new GridLayout(); 00160 globalGridLayout.numColumns = 1; 00161 00162 //create global Group 00163 Group globalGroup = new Group(parent, SWT.NONE); 00164 globalGroup.setLayout(globalGridLayout); 00165 00166 //create GridLayout 00167 GridLayout gridLayout = new GridLayout(); 00168 gridLayout.numColumns = 3; 00169 gridLayout.verticalSpacing = 5; 00170 00171 //create main group 00172 Group optimGroup = new Group(globalGroup, SWT.SHADOW_ETCHED_IN); 00173 optimGroup.setText("Optimisation settings"); 00174 optimGroup.setBounds(globalGroup.getClientArea()); 00175 optimGroup.setLayout(gridLayout); 00176 00177 //create label for optimisation type combo 00178 Label optimLabel = new Label(optimGroup, SWT.NONE); 00179 optimLabel.setText("Optimisation type :"); 00180 optimLabel.setBounds(optimGroup.getClientArea()); 00181 optimLabel.setLocation(10, 25); 00182 optimLabel.pack(); 00183 00184 //"optimisation type" combo placement 00185 GridData gridChoice = new GridData(); 00186 gridChoice.horizontalSpan = 2; 00187 00188 //"optimisation type" combobox 00189 optimChoice = new Combo(optimGroup, SWT.UP | SWT.TOP); 00190 optimChoice.add("None"); 00191 optimChoice.add("Parallel"); 00192 optimChoice.add("Pipeline"); 00193 optimChoice.setLayoutData(gridChoice); 00194 optimChoice.pack(); 00195 00196 //data format label placement 00197 GridData gridFormat = new GridData(); 00198 gridFormat.horizontalSpan = 2; 00199 00200 //data format label 00201 Label formatLabel = new Label(optimGroup, SWT.NONE); 00202 formatLabel.setText("Data type :"); 00203 formatLabel.setBounds(optimGroup.getClientArea()); 00204 // formatLabel.setLayoutData(gridFormat); 00205 formatLabel.pack(); 00206 00207 //"data type" combobox 00208 dataTypeChoice = new Combo(optimGroup, SWT.UP | SWT.TOP); 00209 dataTypeChoice.add(NumType.FLOAT32.name()); 00210 dataTypeChoice.add(NumType.FLOAT64.name()); 00211 dataTypeChoice.setLayoutData(gridFormat); 00212 dataTypeChoice.pack(); 00213 /* 00214 //significant text entry placement 00215 GridData gridSignificant = new GridData(); 00216 gridSignificant.widthHint = 100; 00217 gridSignificant.verticalSpan = 8; 00218 gridSignificant.verticalAlignment = SWT.BOTTOM; 00219 00220 //significant text entry 00221 significant = new Text(optimGroup, SWT.RIGHT); 00222 significant.setLayoutData(gridSignificant); 00223 significant.pack(); 00224 00225 //exponent text entry placement 00226 GridData gridExponent = new GridData(); 00227 gridExponent.widthHint = 100; 00228 gridExponent.verticalSpan = 8; 00229 gridExponent.verticalAlignment = SWT.BOTTOM; 00230 00231 //exponent text entry 00232 exponent = new Text(optimGroup, SWT.RIGHT); 00233 exponent.setLayoutData(gridExponent); 00234 exponent.pack(); 00235 00236 //significant label placement 00237 GridData gridManticeLabel = new GridData(); 00238 gridManticeLabel.widthHint = 208; 00239 gridManticeLabel.horizontalSpan = 2; 00240 00241 //significant label 00242 Label significantLabel = new Label(optimGroup, SWT.RIGHT); 00243 significantLabel.setText("Significant"); 00244 significantLabel.setLayoutData(gridManticeLabel); 00245 significantLabel.pack(); 00246 00247 //exponent label placement 00248 GridData gridExponentLabel = new GridData(); 00249 gridExponentLabel.widthHint = 80; 00250 00251 //exponent label 00252 Label exponentLabel = new Label(optimGroup, SWT.RIGHT); 00253 exponentLabel.setText("Exponent"); 00254 exponentLabel.setLayoutData(gridExponentLabel); 00255 exponentLabel.pack(); 00256 */ 00257 //frequency label placement 00258 GridData gridFreqLabel = new GridData(); 00259 gridFreqLabel.verticalSpan = 8; 00260 gridFreqLabel.verticalAlignment = SWT.BOTTOM; 00261 00262 //frequency label 00263 Label freqLabel = new Label(optimGroup, SWT.NONE); 00264 freqLabel.setText("Wished frequency :"); 00265 freqLabel.setLayoutData(gridFreqLabel); 00266 freqLabel.pack(); 00267 00268 //frequency text entry placement 00269 GridData gridFreq = new GridData(); 00270 gridFreq.widthHint = 100; 00271 gridFreq.verticalSpan = 8; 00272 gridFreq.verticalAlignment = SWT.BOTTOM; 00273 gridFreq.horizontalAlignment = SWT.RIGHT; 00274 00275 //frequency text entry 00276 freq = new Text(optimGroup, SWT.RIGHT); 00277 freq.setLayoutData(gridFreq); 00278 freq.pack(); 00279 00280 //frequency unit label placement 00281 GridData gridFreqUnit = new GridData(); 00282 gridFreqUnit.verticalSpan = 8; 00283 gridFreqUnit.verticalAlignment = SWT.BOTTOM; 00284 gridFreqUnit.horizontalAlignment = SWT.LEFT; 00285 00286 //frequency unit label 00287 Label freqUnit = new Label(optimGroup, SWT.LEFT); 00288 freqUnit.setText("MHz"); 00289 freqUnit.setLayoutData(gridFreqUnit); 00290 freqUnit.pack(); 00291 00292 //fifo label placement 00293 GridData gridFifoLabel = new GridData(); 00294 gridFifoLabel.verticalSpan = 8; 00295 gridFifoLabel.verticalAlignment = SWT.BOTTOM; 00296 00297 //create label for fifo type combo 00298 Label fifoLabel = new Label(optimGroup, SWT.NONE); 00299 fifoLabel.setText("Fifo type :"); 00300 fifoLabel.setLayoutData(gridFifoLabel); 00301 fifoLabel.pack(); 00302 00303 //"fifo type" combo placement 00304 GridData gridFifoChoice = new GridData(); 00305 gridFifoChoice.verticalSpan = 8; 00306 gridFifoChoice.horizontalSpan = 2; 00307 gridFifoChoice.verticalAlignment = SWT.BOTTOM; 00308 00309 //"fifo type" combobox 00310 fifoChoice = new Combo(optimGroup, SWT.UP | SWT.TOP); 00311 fifoChoice.add("Standard"); 00312 fifoChoice.add("Altera"); 00313 fifoChoice.add("Xilinx"); 00314 fifoChoice.setLayoutData(gridFifoChoice); 00315 fifoChoice.pack(); 00316 00317 00318 //Fifo size label placement 00319 GridData gridFifoSizeLabel = new GridData(); 00320 gridFifoSizeLabel.verticalSpan = 8; 00321 gridFifoSizeLabel.verticalAlignment = SWT.BOTTOM; 00322 00323 //Fifo size label 00324 Label fifoSizeLabel = new Label(optimGroup, SWT.NONE); 00325 fifoSizeLabel.setText("Fifo size :"); 00326 fifoSizeLabel.setLayoutData(gridFifoSizeLabel); 00327 fifoSizeLabel.pack(); 00328 00329 //Fifo size text entry placement 00330 GridData gridFifoSize = new GridData(); 00331 gridFifoSize.widthHint = 100; 00332 gridFifoSize.horizontalSpan = 2; 00333 gridFifoSize.verticalSpan = 8; 00334 gridFifoSize.verticalAlignment = SWT.BOTTOM; 00335 gridFifoSize.horizontalAlignment = SWT.LEFT; 00336 00337 //Fifo size entry 00338 fifoSize = new Spinner(optimGroup, SWT.LEFT); 00339 fifoSize.setLayoutData(gridFifoSize); 00340 fifoSize.pack(); 00341 00342 00343 /* //opt Fifo label placement 00344 GridData gridOptFifoLabel = new GridData(); 00345 gridOptFifoLabel.verticalSpan = 8; 00346 gridOptFifoLabel.verticalAlignment = SWT.BOTTOM; 00347 00348 //opt Fifo label 00349 Label optFifoLabel = new Label(optimGroup, SWT.NONE); 00350 optFifoLabel.setText("Optimize FIFOs :"); 00351 optFifoLabel.setLayoutData(gridOptFifoLabel); 00352 optFifoLabel.pack(); 00353 */ 00354 00355 //opt Fifo checkbox placement 00356 GridData gridOptFifo = new GridData(); 00357 gridOptFifo.widthHint = 200; 00358 gridOptFifo.horizontalSpan = 3; 00359 gridOptFifo.verticalSpan = 8; 00360 gridOptFifo.verticalAlignment = SWT.BOTTOM; 00361 gridOptFifo.horizontalAlignment = SWT.LEFT; 00362 00363 //Fifo size text entry 00364 optFifo = new Button(optimGroup, SWT.CHECK | SWT.LEFT); 00365 optFifo.setText("Optimize FIFOs"); 00366 optFifo.setLayoutData(gridOptFifo); 00367 optFifo.pack(); 00368 00369 00370 //opt Fifo checkbox placement 00371 GridData gridFifoComp = new GridData(); 00372 gridFifoComp.widthHint = 200; 00373 gridFifoComp.horizontalSpan = 3; 00374 gridFifoComp.verticalSpan = 8; 00375 gridFifoComp.verticalAlignment = SWT.BOTTOM; 00376 gridFifoComp.horizontalAlignment = SWT.LEFT; 00377 00378 //Fifo size text entry 00379 fifoComp = new Button(optimGroup, SWT.CHECK | SWT.LEFT); 00380 fifoComp.setText("Add Compensation Fifos"); 00381 fifoComp.setLayoutData(gridFifoComp); 00382 fifoComp.pack(); 00383 00384 this.refreshOptimisationPage(); 00385 00386 return parent; 00387 } 00388 00389 00390 00391 protected void okPressed() { 00392 saveOptimisationProperties(); 00393 pressedOnOk=true; 00394 this.close(); 00395 } 00396 00397 public boolean pressedOk() { 00398 return pressedOnOk; 00399 } 00403 private void saveOptimisationProperties() { 00404 if (optimChoice.getSelectionIndex() != -1) { 00405 optimProp.setOptimisationType(optimChoice.getItem(optimChoice.getSelectionIndex())); 00406 } 00407 if (dataTypeChoice.getSelectionIndex() != -1) { 00408 try { 00409 NumType newType=NumType.getNum(dataTypeChoice.getItem(dataTypeChoice.getSelectionIndex())); 00410 if (optimProp.getOptimisationDataType()!=newType) { 00411 optimProp.setOptimisationDataType(newType); 00412 project.getStructTreatment().modifyNumType(newType); 00413 } 00414 } 00415 catch (NumberFormatException e) { 00416 MessageDialog.openError(editor.getSite().getShell(), "Error", "Data size should be an integer!"); 00417 } 00418 } 00419 if (freq.getText() != null) { 00420 try { 00421 optimProp.setOptimisationFrequency(Integer.parseInt(freq.getText()));} 00422 catch (NumberFormatException e) { 00423 MessageDialog.openError(editor.getSite().getShell(), "Error", "Frequency should be an integer!"); 00424 } 00425 } 00426 if (fifoChoice.getSelectionIndex() != -1) { 00427 optimProp.setFifoType(fifoChoice.getItem(fifoChoice.getSelectionIndex())); 00428 } 00429 optimProp.setFifoSize(fifoSize.getSelection()); 00430 optimProp.setOptimizeFifo(optFifo.getSelection()); 00431 optimProp.setFifoCompensation(fifoComp.getSelection()); 00432 } 00433 00439 public void setOptimisationProperties(OptimisationProperties optimProp) { 00440 this.optimProp = optimProp; 00441 } 00442 00446 public void refreshOptimisationPage() { 00447 if (optimProp instanceof OptimisationProperties) { 00448 optimChoice.setText(optimProp.getOptimisationtype()); 00449 dataTypeChoice.setText(String.valueOf(optimProp.getOptimisationDataType().name())); 00450 freq.setText(String.valueOf(optimProp.getOptimisationfrequency())); 00451 fifoChoice.setText(optimProp.getFifoType()); 00452 fifoSize.setValues(optimProp.getFifoSize(),0,1000,0,1,1); 00453 optFifo.setSelection(optimProp.getOptimizeFifo()); 00454 fifoComp.setSelection(optimProp.getFifoCompensation()); 00455 } 00456 } 00457 } 00458 00459 }