X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.plant3d%2Fsrc%2Forg%2Fsimantics%2Fplant3d%2Fdialog%2FComponentSelectionDialog.java;h=fb5060922a7aaf24678c692686bee4fca59e001e;hb=d10785f0cc103f8eb9e7b21893da8fe5c4d99ec6;hp=35e761ccfa6eb436071352e6721b192e67255f76;hpb=9029e681fb0c47e9041c5527b966a247b23029b3;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 35e761cc..fb506092 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/dialog/ComponentSelectionDialog.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/dialog/ComponentSelectionDialog.java @@ -34,6 +34,8 @@ import org.eclipse.swt.widgets.ExpandItem; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Text; +import org.simantics.Simantics; +import org.simantics.db.Session; import org.simantics.db.exception.DatabaseException; import org.simantics.plant3d.Activator; import org.simantics.plant3d.ontology.Plant3D; @@ -86,10 +88,15 @@ public class ComponentSelectionDialog extends Dialog implements ISelectionChange // Input for new PipeRun private Double diameter; + private Double thickness; private Double turnRadius; private Text diameterText; + private Text thicknessText; private Text turnRadiusText; + + // Validation message label + private Label validationLabel; // Position selection private Button startButton; @@ -149,12 +156,13 @@ public class ComponentSelectionDialog extends Dialog implements ISelectionChange } protected List getItems(Class c, String libUri) throws DatabaseException { + Session session = Simantics.getSession(); if (InlineComponent.class.equals(c)) { - return P3DUtil.getInlines(libUri); + return P3DUtil.getInlines(session, libUri); } else if (TurnComponent.class.equals(c)) { - return P3DUtil.getTurns(libUri); + return P3DUtil.getTurns(session, libUri); } else if (EndComponent.class.equals(c)) { - return P3DUtil.getEnds(libUri); + return P3DUtil.getEnds(session, libUri); } else { return null; } @@ -302,14 +310,21 @@ public class ComponentSelectionDialog extends Dialog implements ISelectionChange label.setText("Diameter"); diameterText = new Text(composite, SWT.SINGLE | SWT.BORDER); label = new Label(composite, SWT.NONE); - label.setText("Turn Radius"); + label.setText("Wall thickness"); + thicknessText = new Text(composite, SWT.SINGLE | SWT.BORDER); + label = new Label(composite, SWT.NONE); + label.setText("Turn radius"); turnRadiusText = new Text(composite, SWT.SINGLE | SWT.BORDER); + + validationLabel = new Label(composite, SWT.NONE); + validationLabel.setText(""); lengthText.setEnabled(false); angleText.setEnabled(false); rotationAngleText.setEnabled(false); turnRadiusText.setEnabled(false); diameterText.setEnabled(false); + thicknessText.setEnabled(false); nameText.addKeyListener(new KeyAdapter() { @Override @@ -366,6 +381,18 @@ public class ComponentSelectionDialog extends Dialog implements ISelectionChange validate(); } }); + + thicknessText.addKeyListener(new KeyAdapter() { + @Override + public void keyReleased(KeyEvent e) { + try { + thickness = Double.parseDouble(thicknessText.getText()) / lengthFactor; + } catch (NumberFormatException err) { + thickness = null; + } + validate(); + } + }); turnRadiusText.addKeyListener(new KeyAdapter() { @Override @@ -384,7 +411,10 @@ public class ComponentSelectionDialog extends Dialog implements ISelectionChange horizFillData.applyTo(angleText); horizFillData.applyTo(rotationAngleText); horizFillData.applyTo(diameterText); + horizFillData.applyTo(thicknessText); horizFillData.applyTo(turnRadiusText); + + GridDataFactory.fillDefaults().span(2, 1).align(SWT.END, SWT.END).grab(true, false).applyTo(validationLabel); if (!allowed.contains(PositionType.NEXT) && !allowed.contains(PositionType.PREVIOUS)) { turnViewer.getList().setEnabled(false); @@ -432,6 +462,18 @@ public class ComponentSelectionDialog extends Dialog implements ISelectionChange filterAllowed.clear(); Set filterAllowed = new HashSet(); boolean ok = true; + String msg = null; + + if (name.isEmpty() || usedNames.contains(name)) { + ok = false; + if (msg == null) { + if (name.isEmpty()) + msg = "Please provide a valid name"; + else + msg = "Name \"" + name + "\" is already in use"; + } + } + if (selected == null) { ok = false; } else if (selected.isCode()) {// TODO : instead of disabling the button, we should filter the content. @@ -506,13 +548,15 @@ public class ComponentSelectionDialog extends Dialog implements ISelectionChange angleText.setEnabled(false); rotationAngleText.setEnabled(selected.isRotated()); ok = false; - + if (msg == null) msg = "Cannot split a straight pipe with a straight pipe"; } else { lengthText.setEnabled(true); angleText.setEnabled(false); rotationAngleText.setEnabled(selected.isRotated()); - if (length == null) + if (length == null || length <= 0.0) { ok = false; + if (msg == null) msg = "Please provide a valid length"; + } } } else if (selected.getType() == Type.TURN) { filterAllowed.add(PositionType.NEXT); @@ -520,8 +564,10 @@ public class ComponentSelectionDialog extends Dialog implements ISelectionChange lengthText.setEnabled(false); angleText.setEnabled(true); rotationAngleText.setEnabled(true); - if (angle == null) + if (angle == null) { ok = false; + if (msg == null) msg = "Please provide a turn angle"; + } } else { // this should not happen, since end components should not have variable, or // modifiable flag. @@ -539,8 +585,19 @@ public class ComponentSelectionDialog extends Dialog implements ISelectionChange if (selected.isSizeChange()) { turnRadiusText.setEnabled(true); diameterText.setEnabled(true); - if (diameter == null || turnRadius == null) + thicknessText.setEnabled(true); + if (diameter == null || diameter <= 0.0) { + ok = false; + if (msg == null) msg = "Please provide a valid diameter"; + } + if (turnRadius == null || diameter != null && turnRadius < diameter / 2) { + ok = false; + if (msg == null) msg = "Please provide a valid turn radius"; + } + if (thickness == null || thickness < 0.0 || diameter != null && thickness >= diameter / 2) { ok = false; + if (msg == null) msg = "Please provide a valid wall thickness"; + } } else { turnRadiusText.setEnabled(false); diameterText.setEnabled(false); @@ -570,8 +627,8 @@ public class ComponentSelectionDialog extends Dialog implements ISelectionChange this.filterAllowed.add(t); } - if (name.isEmpty() || usedNames.contains(name)) - ok = false; + validationLabel.setText(msg != null ? msg : ""); + validationLabel.requestLayout(); getButton(OK).setEnabled(ok); } @@ -628,4 +685,8 @@ public class ComponentSelectionDialog extends Dialog implements ISelectionChange return lenghtAdjustable; } + public Double getThickness() { + return thickness; + } + }