]> gerrit.simantics Code Review - simantics/3d.git/commitdiff
Ask component rotation angle when adding components 59/3559/1
authorMarko Luukkainen <marko.luukkainen@semantum.fi>
Mon, 18 Nov 2019 13:24:56 +0000 (15:24 +0200)
committerMarko Luukkainen <marko.luukkainen@semantum.fi>
Mon, 18 Nov 2019 13:34:52 +0000 (13:34 +0000)
gitlab #13

Change-Id: I13cbd9905fe6a0fa123375b44a88b15fe84067e7
(cherry picked from commit 15e688c6d6148fdbda457e5f55bdea4259c97aa8)

org.simantics.plant3d/src/org/simantics/plant3d/actions/AddComponentAction.java
org.simantics.plant3d/src/org/simantics/plant3d/dialog/ComponentSelectionDialog.java
org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/InlineComponent.java
org.simantics.plant3d/src/org/simantics/plant3d/scenegraph/controlpoint/PipeControlPoint.java
org.simantics.plant3d/src/org/simantics/plant3d/utils/ComponentUtils.java
org.simantics.plant3d/src/org/simantics/plant3d/utils/Item.java
org.simantics.plant3d/src/org/simantics/plant3d/utils/P3DUtil.java

index 56b0443eb203b71a16300387d7e8c7e292e3c53d..ea25230ab57c745bbe8e229e648d5604c293d4a7 100644 (file)
@@ -83,6 +83,7 @@ public class AddComponentAction extends vtkSwtAction {
        
        private Double length;
        private Double angle;
+       private Double rotationAngle;
        private Double diameter;
        private Double turnRadius;
        
@@ -100,6 +101,7 @@ public class AddComponentAction extends vtkSwtAction {
                this.lengthAdjustable = dialog.isLenghtAdjustable();
                this.length = dialog.getLength();
                this.angle = dialog.getAngle();
+               this.rotationAngle = dialog.getRotationAngle();
                this.diameter = dialog.getDiameter();
                this.turnRadius = dialog.getTurnRadius();
                allowed = dialog.filterAllowed();
@@ -177,6 +179,7 @@ public class AddComponentAction extends vtkSwtAction {
                        inst.length = length;
                        inst.turnRadius = turnRadius;
                        inst.insertPosition = insertPosition;
+                       inst.rotationAngle = rotationAngle;
                        inst.position = position;
                        ComponentUtils.addComponent(root, component, inst);
                } catch (Exception e) {
index 7c124eb0ecb269076d4979bc1155305befc385dd..dd3f48076b1a1c12836d24359643c992255bf2a4 100644 (file)
@@ -62,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;
@@ -198,6 +205,9 @@ public class ComponentSelectionDialog extends Dialog implements ISelectionChange
                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);
                
@@ -232,6 +242,9 @@ public class ComponentSelectionDialog extends Dialog implements ISelectionChange
                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");
@@ -242,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) {
@@ -269,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) {
@@ -295,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);
                
@@ -412,11 +440,13 @@ public class ComponentSelectionDialog extends Dialog implements ISelectionChange
                                        if (inlineSplit) {
                                                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;
                                        }
@@ -425,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()) {
@@ -495,6 +529,10 @@ public class ComponentSelectionDialog extends Dialog implements ISelectionChange
                return length;
        }
        
+       public Double getRotationAngle() {
+        return rotationAngle;
+    }
+       
        public Double getDiameter() {
                return diameter;
        }
index aa51073a5a0f9665748d887b05a928118b061bce..a94303efc4ec22d35bb952e872db8947a4446d41 100644 (file)
@@ -86,12 +86,8 @@ public class InlineComponent extends PipelineComponent {
                if (controlPoint.getRotationAngle() != null && Math.abs(controlPoint.getRotationAngle()-angle) < MathTools.NEAR_ZERO)
                        return;
                controlPoint.setRotationAngle(angle);
-               try {
-                       PipingRules.requestUpdate(getControlPoint());
-               } catch (Exception e) {
-                       // TODO Auto-generated catch block
-                       e.printStackTrace();
-               }       
+               PipingRules.requestUpdate(getControlPoint());
+
        }
        
        @RelatedGetValue(Plant3D.URIs.IsReversed)
@@ -112,12 +108,7 @@ public class InlineComponent extends PipelineComponent {
                        return;
                }
                controlPoint.setReversed(reverse);
-               try {
-                       PipingRules.requestUpdate(getControlPoint());
-               } catch (Exception e) {
-                       // TODO Auto-generated catch block
-                       e.printStackTrace();
-               }       
+               PipingRules.requestUpdate(getControlPoint());
        }
        
        @Override
index 232b8ab45dfdf46b2321f95398bc05dbd3fd3e47..eae8ec33220aacc91b27873cf86e9eef4d7110a9 100644 (file)
@@ -398,7 +398,7 @@ public class PipeControlPoint extends G3DNode implements IP3DNode {
 
        @GetPropertyValue(name="Rotation Angle",tabId="Debug",value="rotationAngle")
        public Double getRotationAngle() {
-           if (asFixedAngle())
+           if (isRotate || asFixedAngle())
                return rotationAngle;
            return null;
        }
index 9b6ea1895507f359c671c54df8b7ff4e4f65cb50..0ae36e33a2f51ca7a3aa549c14244f4547c873c9 100644 (file)
@@ -275,6 +275,9 @@ public class ComponentUtils {
                
                // Variable angle
                public Double angle;
+               
+               // Rotation angle used with turns and rotated inline.
+               public Double rotationAngle;
 
                public String getTypeUri() {
                        return typeUri;
@@ -331,6 +334,14 @@ public class ComponentUtils {
                public void setAngle(Double angle) {
                        this.angle = angle;
                }
+               
+               public Double getRotationAngle() {
+            return rotationAngle;
+        }
+               
+               public void setRotationAngle(Double rotationAngle) {
+            this.rotationAngle = rotationAngle;
+        }
 
        }
        
@@ -438,14 +449,19 @@ public class ComponentUtils {
                                newPcp.setLength(inst.length);
                                newComponent.setParameter("length", inst.length);
                            }
+                           if (inst.rotationAngle != null)
+                               ((InlineComponent) newComponent).setRotationAngle(inst.rotationAngle);
                        } else if (newComponent instanceof TurnComponent) {
                            TurnComponent turnComponent = (TurnComponent)newComponent;
                            if  (turnComponent.isVariableAngle()) {
                                newPcp.setTurnAngle(inst.angle);
                                newComponent.setParameter("turnAngle", inst.angle);
                            }
+                           if (inst.rotationAngle != null)
+                       ((TurnComponent) newComponent).setRotationAngle(inst.rotationAngle);
                        }
                        
+                       
                        newComponent.updateParameters();
                        
                        Vector3d v = new Vector3d(dir);
@@ -505,6 +521,7 @@ public class ComponentUtils {
                                PipingRules.addSizeChange(true, pipeRun, other, (InlineComponent)newComponent, toPcp, null);
                        }
                        newPcp.setWorldPosition(pos);
+
                        // TODO : chicken-egg problem
                        newComponent.updateParameters();
                        Vector3d v = new Vector3d(dir);
@@ -522,6 +539,8 @@ public class ComponentUtils {
                                break;
                        }
                        newPcp.setWorldPosition(pos);
+               if (inst.rotationAngle != null)
+                  ((InlineComponent) newComponent).setRotationAngle(inst.rotationAngle);
                        
                }
                                
index 799d072702c830e5077d6c2aab414eff838b66b9..1ce6ed20673bfc7eff67ded0f45c8c7f30d13cc0 100644 (file)
@@ -12,6 +12,7 @@ public class Item {
        private boolean variable = false;
        private boolean modifiable = false;
        private boolean sizeChange = false;
+       private boolean rotated = false;
 
        
        public Item(String type, String name) {
@@ -68,7 +69,14 @@ public class Item {
        public void setSizeChange(boolean sizeChange) {
                this.sizeChange = sizeChange;
        }
-
+       
+       public boolean isRotated() {
+        return rotated;
+    }
+       
+       public void setRotated(boolean rotated) {
+        this.rotated = rotated;
+    }
 
 
        @Override
index 55cfead45ea55259972c62eaf65592e62b98006a..18d5b2cd2e9e0e908e532e619e22890b0f7f7d56 100644 (file)
@@ -211,6 +211,8 @@ public class P3DUtil {
                    item.setModifiable(true);
                if (graph.hasStatement(r, p3d.SizeChangeComponent))
                        item.setSizeChange(true);
+               if (graph.hasStatement(r, p3d.RotateComponent))
+            item.setRotated(true);
                return item;
        }