X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.plant3d%2Fsrc%2Forg%2Fsimantics%2Fplant3d%2Fdialog%2FComponentSelectionDialog.java;h=00b52f3bb1073b0e12e1cb43dd64b5b18f47b97d;hb=f8e541f1d66cda57802da11aaa715b9f9c1c79a9;hp=adfd98c97278dbc0e9b9df57a15bcf47d9a77032;hpb=62fb6eb651ae640336d71746d7bfa79bcfa211df;p=simantics%2F3d.git diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/dialog/ComponentSelectionDialog.java b/org.simantics.plant3d/src/org/simantics/plant3d/dialog/ComponentSelectionDialog.java index adfd98c9..00b52f3b 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/dialog/ComponentSelectionDialog.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/dialog/ComponentSelectionDialog.java @@ -33,6 +33,7 @@ import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Text; import org.simantics.db.exception.DatabaseException; import org.simantics.plant3d.Activator; +import org.simantics.plant3d.ontology.Plant3D; import org.simantics.plant3d.scenegraph.EndComponent; import org.simantics.plant3d.scenegraph.InlineComponent; import org.simantics.plant3d.scenegraph.Nozzle; @@ -46,8 +47,10 @@ import org.simantics.utils.ui.ExceptionUtils; public class ComponentSelectionDialog extends Dialog implements ISelectionChangedListener{ - private ResourceManager resourceManager; - + private ResourceManager resourceManager; + + private String libUri; + private Item selected; private Set allowed; private Set filterAllowed; @@ -59,16 +62,23 @@ public class ComponentSelectionDialog extends Dialog implements ISelectionChange private Double angle; private Double length; + private Double rotationAngle; + // In-line component private Text lengthText; + // Turn component private Text angleText; + // Rotated In-line, or turn conponent. + private Text rotationAngleText; + // Input for new PipeRun private Double diameter; private Double turnRadius; private Text diameterText; private Text turnRadiusText; + // Position selection private Button startButton; private Button middleButton; private Button endButton; @@ -81,18 +91,35 @@ public class ComponentSelectionDialog extends Dialog implements ISelectionChange public ComponentSelectionDialog(Shell parentShell, Set allowed, PipelineComponent component){ - super(parentShell); - this.allowed = allowed; - this.component = component; - filterAllowed = new HashSet(); - insertAdjustable = component instanceof InlineComponent ? ((InlineComponent)component).isVariableLength() : false; - lenghtAdjustable = false; + this(parentShell, allowed, component, Plant3D.URIs.Builtin); } + public ComponentSelectionDialog(Shell parentShell, Set allowed, PipelineComponent component, String libUri){ + super(parentShell); + this.allowed = allowed; + this.component = component; + filterAllowed = new HashSet(); + insertAdjustable = component instanceof InlineComponent ? ((InlineComponent)component).isVariableLength() : false; + lenghtAdjustable = false; + this.libUri = libUri; + } + + protected List getItems(Class c, String libUri) throws DatabaseException{ + if (InlineComponent.class.equals(c)) { + return P3DUtil.getInlines(libUri); + } else if (TurnComponent.class.equals(c)) { + return P3DUtil.getTurns(libUri); + } else if (EndComponent.class.equals(c)) { + return P3DUtil.getEnds(libUri); + } else { + return null; + } + } + @Override protected Control createDialogArea(Composite parent) { - resourceManager = new LocalResourceManager(JFaceResources.getResources(), parent); - + resourceManager = new LocalResourceManager(JFaceResources.getResources(), parent); + Composite composite = new Composite(parent, SWT.NONE); GridLayout layout = new GridLayout(2,false); layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN); @@ -115,9 +142,9 @@ public class ComponentSelectionDialog extends Dialog implements ISelectionChange List turns = null; List inlines = null; try { - ends = P3DUtil.getEnds(); - turns= P3DUtil.getTurns(); - inlines = P3DUtil.getInlines(); + ends = getItems(EndComponent.class, libUri); + turns= getItems(TurnComponent.class, libUri); + inlines = getItems(InlineComponent.class, libUri); } catch (DatabaseException e) { Label label = new Label(composite, SWT.NONE); label.setText("Cannot load pipeline components: " + e.getMessage()); @@ -170,48 +197,54 @@ public class ComponentSelectionDialog extends Dialog implements ISelectionChange GridDataFactory.fillDefaults().minSize(500, 500).hint(500, 500).applyTo(composite); Label label = new Label(composite, SWT.NONE); - label.setText("Position"); + label.setText("Position"); Composite buttonComposite = new Composite(composite, SWT.NONE); - startButton = new Button(buttonComposite, SWT.TOGGLE); - middleButton = new Button(buttonComposite, SWT.TOGGLE); - endButton = new Button(buttonComposite, SWT.TOGGLE); - startButton.setImage(resourceManager.createImage(Activator.imageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/insert_start.png"))); - middleButton.setImage(resourceManager.createImage(Activator.imageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/insert_middle.png"))); - endButton.setImage(resourceManager.createImage(Activator.imageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/insert_end.png"))); - GridDataFactory.fillDefaults().grab(true, false).align(SWT.FILL, SWT.TOP).applyTo(buttonComposite); - GridLayoutFactory.fillDefaults().numColumns(3).applyTo(buttonComposite); + startButton = new Button(buttonComposite, SWT.TOGGLE); + middleButton = new Button(buttonComposite, SWT.TOGGLE); + endButton = new Button(buttonComposite, SWT.TOGGLE); + startButton.setImage(resourceManager.createImage(Activator.imageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/insert_start.png"))); + middleButton.setImage(resourceManager.createImage(Activator.imageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/insert_middle.png"))); + endButton.setImage(resourceManager.createImage(Activator.imageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/insert_end.png"))); + startButton.setToolTipText("Overlapping insert"); + middleButton.setToolTipText("Cutting insert"); + endButton.setToolTipText("Adding insert"); + GridDataFactory.fillDefaults().grab(true, false).align(SWT.FILL, SWT.TOP).applyTo(buttonComposite); + GridLayoutFactory.fillDefaults().numColumns(3).applyTo(buttonComposite); + + startButton.setEnabled(false); + middleButton.setEnabled(false); + endButton.setEnabled(false); + + startButton.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + updateInsertPosition(PositionType.PREVIOUS); + } + }); + + middleButton.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + updateInsertPosition(PositionType.SPLIT); + } + }); + endButton.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + updateInsertPosition(PositionType.NEXT); + } + }); + endButton.setSelection(true); - startButton.setEnabled(false); - middleButton.setEnabled(false); - endButton.setEnabled(false); - - startButton.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - updateInsertPosition(PositionType.PREVIOUS); - } - }); - - middleButton.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - updateInsertPosition(PositionType.SPLIT); - } - }); - endButton.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - updateInsertPosition(PositionType.NEXT); - } - }); - endButton.setSelection(true); - label = new Label(composite, SWT.NONE); label.setText("Length"); lengthText = new Text(composite, SWT.SINGLE|SWT.BORDER); label = new Label(composite, SWT.NONE); label.setText("Angle"); angleText = new Text(composite, SWT.SINGLE|SWT.BORDER); + label = new Label(composite, SWT.NONE); + label.setText("Rotation angle"); + rotationAngleText = new Text(composite, SWT.SINGLE|SWT.BORDER); label = new Label(composite, SWT.NONE); label.setText("Diameter"); @@ -222,9 +255,11 @@ public class ComponentSelectionDialog extends Dialog implements ISelectionChange lengthText.setEnabled(false); angleText.setEnabled(false); + rotationAngleText.setEnabled(false); turnRadiusText.setEnabled(false); diameterText.setEnabled(false); + lengthText.addKeyListener(new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { @@ -249,6 +284,18 @@ public class ComponentSelectionDialog extends Dialog implements ISelectionChange } }); + rotationAngleText.addKeyListener(new KeyAdapter() { + @Override + public void keyReleased(KeyEvent e) { + try { + rotationAngle = Double.parseDouble(rotationAngleText.getText()); + } catch (NumberFormatException err) { + rotationAngle = null; + } + validate(); + } + }); + diameterText.addKeyListener(new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { @@ -275,6 +322,7 @@ public class ComponentSelectionDialog extends Dialog implements ISelectionChange GridDataFactory.fillDefaults().grab(true, false).align(SWT.FILL, SWT.TOP).applyTo(lengthText); GridDataFactory.fillDefaults().grab(true, false).align(SWT.FILL, SWT.TOP).applyTo(angleText); + GridDataFactory.fillDefaults().grab(true, false).align(SWT.FILL, SWT.TOP).applyTo(rotationAngleText); GridDataFactory.fillDefaults().grab(true, false).align(SWT.FILL, SWT.TOP).applyTo(diameterText); GridDataFactory.fillDefaults().grab(true, false).align(SWT.FILL, SWT.TOP).applyTo(turnRadiusText); @@ -289,12 +337,12 @@ public class ComponentSelectionDialog extends Dialog implements ISelectionChange private void updateInsertPosition(PositionType type) { - if (insertPosition == type) - return; - endButton.setSelection(type == PositionType.NEXT); - middleButton.setSelection(type == PositionType.SPLIT); - startButton.setSelection(type == PositionType.PREVIOUS); - insertPosition = type; + if (insertPosition == type) + return; + endButton.setSelection(type == PositionType.NEXT); + middleButton.setSelection(type == PositionType.SPLIT); + startButton.setSelection(type == PositionType.PREVIOUS); + insertPosition = type; } @Override @@ -302,18 +350,18 @@ public class ComponentSelectionDialog extends Dialog implements ISelectionChange IStructuredSelection sel = (IStructuredSelection)event.getSelection(); Item i = (Item)sel.getFirstElement(); if (i != null) { - selected = i; - if (event.getSource() == inlineViewer) { - turnViewer.setSelection(new StructuredSelection()); - endViewer.setSelection(new StructuredSelection()); - } else if (event.getSource() == turnViewer) { - inlineViewer.setSelection(new StructuredSelection()); - endViewer.setSelection(new StructuredSelection()); - } else if (event.getSource() == endViewer) { - inlineViewer.setSelection(new StructuredSelection()); - turnViewer.setSelection(new StructuredSelection()); - } - validate(); + selected = i; + if (event.getSource() == inlineViewer) { + turnViewer.setSelection(new StructuredSelection()); + endViewer.setSelection(new StructuredSelection()); + } else if (event.getSource() == turnViewer) { + inlineViewer.setSelection(new StructuredSelection()); + endViewer.setSelection(new StructuredSelection()); + } else if (event.getSource() == endViewer) { + inlineViewer.setSelection(new StructuredSelection()); + turnViewer.setSelection(new StructuredSelection()); + } + validate(); } } @@ -326,77 +374,79 @@ public class ComponentSelectionDialog extends Dialog implements ISelectionChange } else if (selected.isCode()) {// TODO : instead of disabling the button, we should filter the content. ok = false; } else { - lenghtAdjustable = ((selected.getType() == Type.INLINE) && selected.isVariable()); - if (insertAdjustable) { - switch (selected.getType()) { - case END: - startButton.setEnabled(false); - middleButton.setEnabled(false); - endButton.setEnabled(true); - updateInsertPosition(PositionType.NEXT); - break; - case INLINE: - if (!selected.isVariable()) { - startButton.setEnabled(true); - middleButton.setEnabled(true); - endButton.setEnabled(true); - } else { - startButton.setEnabled(false); - middleButton.setEnabled(false); - endButton.setEnabled(true); - updateInsertPosition(PositionType.NEXT); - } - break; - case NOZZLE: - startButton.setEnabled(false); - middleButton.setEnabled(false); - endButton.setEnabled(true); - updateInsertPosition(PositionType.NEXT); - break; - case TURN: - startButton.setEnabled(false); - middleButton.setEnabled(true); - endButton.setEnabled(true); - if (insertPosition == PositionType.PREVIOUS) - updateInsertPosition(PositionType.NEXT); - break; - case EQUIPMENT: - throw new RuntimeException("Expected component, got equipment " + selected); - } - } else if (lenghtAdjustable) { - if (component instanceof InlineComponent) { - startButton.setEnabled(true); - middleButton.setEnabled(true); - endButton.setEnabled(true); - } else if (component instanceof TurnComponent) { - startButton.setEnabled(false); - middleButton.setEnabled(true); - endButton.setEnabled(true); - if (insertPosition == PositionType.PREVIOUS) - updateInsertPosition(PositionType.NEXT); - } else if (component instanceof EndComponent || component instanceof Nozzle) { - startButton.setEnabled(false); - middleButton.setEnabled(false); - endButton.setEnabled(true); - updateInsertPosition(PositionType.NEXT); - } - } else { - startButton.setEnabled(false); - middleButton.setEnabled(false); - endButton.setEnabled(true); - } - if (selected.isVariable()) { + lenghtAdjustable = ((selected.getType() == Type.INLINE) && (selected.isVariable() || selected.isModifiable())); + if (insertAdjustable) { + switch (selected.getType()) { + case END: + startButton.setEnabled(false); + middleButton.setEnabled(false); + endButton.setEnabled(true); + updateInsertPosition(PositionType.NEXT); + break; + case INLINE: + if (!selected.isVariable()) { + startButton.setEnabled(true); + middleButton.setEnabled(true); + endButton.setEnabled(true); + } else { + startButton.setEnabled(false); + middleButton.setEnabled(false); + endButton.setEnabled(true); + updateInsertPosition(PositionType.NEXT); + } + break; + case NOZZLE: + startButton.setEnabled(false); + middleButton.setEnabled(false); + endButton.setEnabled(true); + updateInsertPosition(PositionType.NEXT); + break; + case TURN: + startButton.setEnabled(false); + middleButton.setEnabled(true); + endButton.setEnabled(true); + if (insertPosition == PositionType.PREVIOUS) + updateInsertPosition(PositionType.NEXT); + break; + case EQUIPMENT: + throw new RuntimeException("Expected component, got equipment " + selected); + } + } else if (lenghtAdjustable) { + if (component instanceof InlineComponent) { + startButton.setEnabled(true); + middleButton.setEnabled(true); + endButton.setEnabled(true); + } else if (component instanceof TurnComponent) { + startButton.setEnabled(false); + middleButton.setEnabled(true); + endButton.setEnabled(true); + if (insertPosition == PositionType.PREVIOUS) + updateInsertPosition(PositionType.NEXT); + } else if (component instanceof EndComponent || component instanceof Nozzle) { + startButton.setEnabled(false); + middleButton.setEnabled(false); + endButton.setEnabled(true); + updateInsertPosition(PositionType.NEXT); + } + } else { + startButton.setEnabled(false); + middleButton.setEnabled(false); + endButton.setEnabled(true); + } + if (selected.isVariable() || selected.isModifiable()) { if (selected.getType() == Type.INLINE) { filterAllowed.add(PositionType.NEXT); filterAllowed.add(PositionType.PREVIOUS); - if (inlineSplit) { + if (inlineSplit && selected.isVariable()) { lengthText.setEnabled(false); angleText.setEnabled(false); + rotationAngleText.setEnabled(selected.isRotated()); ok = false; } else { lengthText.setEnabled(true); angleText.setEnabled(false); + rotationAngleText.setEnabled(selected.isRotated()); if (length == null) ok = false; } @@ -405,16 +455,20 @@ public class ComponentSelectionDialog extends Dialog implements ISelectionChange filterAllowed.add(PositionType.PREVIOUS); lengthText.setEnabled(false); angleText.setEnabled(true); + rotationAngleText.setEnabled(true); if (angle == null) ok = false; } else { - // this should not happen + // this should not happen, since end components should not have variable, or modifiable flag. lengthText.setEnabled(false); angleText.setEnabled(false); + rotationAngleText.setEnabled(false); + } } else { lengthText.setEnabled(false); - angleText.setEnabled(false); + angleText.setEnabled(false); + rotationAngleText.setEnabled(selected.getType() == Type.TURN || selected.isRotated()); } if (selected.isSizeChange()) { @@ -475,6 +529,10 @@ public class ComponentSelectionDialog extends Dialog implements ISelectionChange return length; } + public Double getRotationAngle() { + return rotationAngle; + } + public Double getDiameter() { return diameter; } @@ -488,15 +546,15 @@ public class ComponentSelectionDialog extends Dialog implements ISelectionChange } public PositionType getInsertPosition() { - return insertPosition; - } + return insertPosition; + } public boolean isInsertAdjustable() { - return insertAdjustable; - } + return insertAdjustable; + } public boolean isLenghtAdjustable() { - return lenghtAdjustable; - } + return lenghtAdjustable; + } }