]> gerrit.simantics Code Review - simantics/3d.git/blobdiff - org.simantics.plant3d/src/org/simantics/plant3d/dialog/ComponentSelectionDialog.java
Use inside diameter for eccentric reducer offset calculation
[simantics/3d.git] / org.simantics.plant3d / src / org / simantics / plant3d / dialog / ComponentSelectionDialog.java
index 720d88cec826729ba748870ace5a4acb7472b02a..c0851fd25d19913b8ed4b114b34bfd8fc551633e 100644 (file)
@@ -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;
@@ -53,6 +55,8 @@ public class ComponentSelectionDialog extends Dialog implements ISelectionChange
        private static final String DIALOG = "ComponentSelectionDialog"; //$NON-NLS-1$
 
        private IDialogSettings dialogSettings;
+       
+       private double lengthFactor = 1.0;
 
        private ResourceManager resourceManager;
 
@@ -84,9 +88,11 @@ 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;
 
        // Position selection
@@ -126,6 +132,10 @@ public class ComponentSelectionDialog extends Dialog implements ISelectionChange
                if (dialogSettings == null)
                        dialogSettings = settings.addNewSection(DIALOG);
        }
+       
+       public void setLengthFactor(double lengthFactor) {
+               this.lengthFactor = lengthFactor;
+       }
 
        @Override
        protected IDialogSettings getDialogBoundsSettings() {
@@ -143,12 +153,13 @@ public class ComponentSelectionDialog extends Dialog implements ISelectionChange
        }
 
        protected List<Item> 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;
                }
@@ -296,7 +307,10 @@ 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);
 
                lengthText.setEnabled(false);
@@ -304,6 +318,7 @@ public class ComponentSelectionDialog extends Dialog implements ISelectionChange
                rotationAngleText.setEnabled(false);
                turnRadiusText.setEnabled(false);
                diameterText.setEnabled(false);
+               thicknessText.setEnabled(false);
 
                nameText.addKeyListener(new KeyAdapter() {
                        @Override
@@ -317,7 +332,7 @@ public class ComponentSelectionDialog extends Dialog implements ISelectionChange
                        @Override
                        public void keyReleased(KeyEvent e) {
                                try {
-                                       length = Double.parseDouble(lengthText.getText());
+                                       length = Double.parseDouble(lengthText.getText()) / lengthFactor;
                                } catch (NumberFormatException err) {
                                        length = null;
                                }
@@ -353,19 +368,31 @@ public class ComponentSelectionDialog extends Dialog implements ISelectionChange
                        @Override
                        public void keyReleased(KeyEvent e) {
                                try {
-                                       diameter = Double.parseDouble(diameterText.getText());
+                                       diameter = Double.parseDouble(diameterText.getText()) / lengthFactor;
                                } catch (NumberFormatException err) {
                                        diameter = null;
                                }
                                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
                        public void keyReleased(KeyEvent e) {
                                try {
-                                       turnRadius = Double.parseDouble(turnRadiusText.getText());
+                                       turnRadius = Double.parseDouble(turnRadiusText.getText()) / lengthFactor;
                                } catch (NumberFormatException err) {
                                        turnRadius = null;
                                }
@@ -378,6 +405,7 @@ public class ComponentSelectionDialog extends Dialog implements ISelectionChange
                horizFillData.applyTo(angleText);
                horizFillData.applyTo(rotationAngleText);
                horizFillData.applyTo(diameterText);
+               horizFillData.applyTo(thicknessText);
                horizFillData.applyTo(turnRadiusText);
 
                if (!allowed.contains(PositionType.NEXT) && !allowed.contains(PositionType.PREVIOUS)) {
@@ -533,7 +561,8 @@ 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 || turnRadius == null || thickness == null)
                                        ok = false;
                        } else {
                                turnRadiusText.setEnabled(false);
@@ -622,4 +651,8 @@ public class ComponentSelectionDialog extends Dialog implements ISelectionChange
                return lenghtAdjustable;
        }
 
+       public Double getThickness() {
+               return thickness;
+       }
+
 }