]> gerrit.simantics Code Review - simantics/3d.git/commitdiff
Added labels to piping component types 19/3819/1
authorReino Ruusu <reino.ruusu@semantum.fi>
Wed, 29 Jan 2020 13:10:04 +0000 (15:10 +0200)
committerReino Ruusu <reino.ruusu@semantum.fi>
Wed, 29 Jan 2020 13:10:41 +0000 (15:10 +0200)
gitlab #71

Change-Id: I956bb0ce2d9c449d805ee476f688bc9117926e7d

org.simantics.plant3d.ontology/graph/plant3d_builtins.pgraph
org.simantics.plant3d/src/org/simantics/plant3d/dialog/ComponentLabelProvider.java
org.simantics.plant3d/src/org/simantics/plant3d/utils/Item.java
org.simantics.plant3d/src/org/simantics/plant3d/utils/P3DUtil.java

index 4895630f4876409fdaae0fcda47192db873d9f67..ff4f149bb086ad30943f428fe86a308fcd0592c0 100644 (file)
@@ -19,12 +19,14 @@ P3D.Builtin.CapGeometryProvider : P3D.GeometryProvider
 
  
 P3D.Builtin.ConcentricReducer <T P3D.InlineComponent : P3D.InlineComponent
+    L0.HasLabel "Concentric reducer"
     @L0.assert P3D.hasGeometry P3D.Builtin.ReducerGeometryProvider
     @L0.tag P3D.SizeChangeComponent
     @L0.tag P3D.FixedLengthInlineComponent
     @L0.tag P3D.DualConnectedComponent
 
 P3D.Builtin.EccentricReducer <T P3D.InlineComponent : P3D.InlineComponent 
+    L0.HasLabel "Eccentric reducer"
     @L0.assert P3D.hasGeometry P3D.Builtin.ReducerGeometryProvider
     @L0.tag P3D.OffsetComponent
     @L0.tag P3D.SizeChangeComponent
@@ -33,31 +35,37 @@ P3D.Builtin.EccentricReducer <T P3D.InlineComponent : P3D.InlineComponent
     @L0.tag P3D.RotateComponent
 
 P3D.Builtin.Elbow <T P3D.TurnComponent : P3D.TurnComponent  
+    L0.HasLabel "Elbow"
     @L0.tag P3D.VariableAngleTurnComponent
     @L0.tag P3D.DualConnectedComponent
     @L0.assert P3D.hasGeometry P3D.Builtin.ElbowGeometryProvider
 
 P3D.Builtin.Straight <T P3D.InlineComponent : P3D.InlineComponent
+    L0.HasLabel "Straight pipe"
     @L0.tag P3D.DualConnectedComponent
     @L0.tag P3D.VariableLengthInlineComponent
     @L0.assert P3D.hasGeometry P3D.Builtin.StraightGeometryProvider
 
 P3D.Builtin.BranchSplitComponent <T P3D.InlineComponent : P3D.InlineComponent
+    L0.HasLabel "Branch split component"
     @L0.tag P3D.CodeComponent
     @L0.tag P3D.FixedLengthInlineComponent
     @L0.tag P3D.NonVisibleComponent
     
     
 P3D.Builtin.Nozzle <T P3D.Nozzle : P3D.Nozzle
+      L0.HasLabel "Nozzle"
       @L0.assert P3D.hasGeometry P3D.Builtin.NozzleGeometryProvider
       @L0.assert P3D.hasParameter
          _ :P3D.Parameter
            L0.HasName "length" : L0.String
            P3D.hasParameterValue 0.1 : L0.Double
 P3D.Builtin.FlatNozzle <T P3D.Nozzle : P3D.Nozzle
+      L0.HasLabel "Flat nozzle"
       @L0.assert P3D.hasGeometry P3D.Builtin.FlatNozzleGeometryProvider
       
 P3D.Builtin.HorizontalTank <T P3D.Equipment : P3D.Equipment
+     L0.HasLabel "Horizontal tank"
      @L0.assert P3D.hasGeometry P3D.Builtin.HorizontalTankGeometryProvider
      @L0.assert P3D.hasParameter
          _ :P3D.Parameter
@@ -68,6 +76,7 @@ P3D.Builtin.HorizontalTank <T P3D.Equipment : P3D.Equipment
            L0.HasName "length" : L0.String
            P3D.hasParameterValue 1.0 : L0.Double
 P3D.Builtin.VerticalTank <T P3D.Equipment : P3D.Equipment
+     L0.HasLabel "Vertical tank"
      @L0.assert P3D.hasGeometry P3D.Builtin.VerticalTankGeometryProvider
      @L0.assert P3D.hasParameter
          _ :P3D.Parameter
@@ -78,6 +87,7 @@ P3D.Builtin.VerticalTank <T P3D.Equipment : P3D.Equipment
            L0.HasName "height" : L0.String
            P3D.hasParameterValue 1.0 : L0.Double
 P3D.Builtin.Pump <T P3D.Equipment : P3D.Equipment
+     L0.HasLabel "Pump"
      @L0.assert P3D.hasGeometry P3D.Builtin.PumpGeometryProvider
      @L0.assert P3D.hasParameter
          _ :P3D.Parameter
@@ -90,6 +100,7 @@ P3D.Builtin.Pump <T P3D.Equipment : P3D.Equipment
      @L0.assert P3D.HasFixedNozzles 2
                 
 P3D.Builtin.BallValve <T P3D.InlineComponent : P3D.InlineComponent
+    L0.HasLabel "Ball valve"
     @L0.tag P3D.DualConnectedComponent
     @L0.tag P3D.FixedLengthInlineComponent
     @L0.assert P3D.hasGeometry P3D.Builtin.BallValveGeometryProvider
@@ -99,6 +110,7 @@ P3D.Builtin.BallValve <T P3D.InlineComponent : P3D.InlineComponent
            P3D.hasParameterValue 0.1 : L0.Double
            
 P3D.Builtin.CheckValve <T P3D.InlineComponent : P3D.InlineComponent
+    L0.HasLabel "Check valve"
     @L0.tag P3D.DualConnectedComponent
     @L0.tag P3D.FixedLengthInlineComponent
     @L0.tag P3D.ReverseComponent
@@ -109,6 +121,7 @@ P3D.Builtin.CheckValve <T P3D.InlineComponent : P3D.InlineComponent
            P3D.hasParameterValue 0.1 : L0.Double
            
 P3D.Builtin.GateValve <T P3D.InlineComponent : P3D.InlineComponent
+    L0.HasLabel "Gate valve"
     @L0.tag P3D.DualConnectedComponent
     @L0.tag P3D.FixedLengthInlineComponent
     @L0.tag P3D.RotateComponent
@@ -119,13 +132,15 @@ P3D.Builtin.GateValve <T P3D.InlineComponent : P3D.InlineComponent
            P3D.hasParameterValue 0.1 : L0.Double
            
 P3D.Builtin.Cap <T P3D.EndComponent : P3D.EndComponent
+    L0.HasLabel "Cap"
     @L0.assert P3D.hasGeometry P3D.Builtin.CapGeometryProvider
     @L0.assert P3D.hasParameter
          _ :P3D.Parameter
            L0.HasName "radius" : L0.String
            P3D.hasParameterValue 0.1 : L0.Double
      
-P3D.Builtin.Elbow90 <T P3D.TurnComponent : P3D.TurnComponent  
+P3D.Builtin.Elbow90 <T P3D.TurnComponent : P3D.TurnComponent
+    L0.HasLabel "90 degree elbow"
     @L0.tag P3D.FixedAngleTurnComponent
     @L0.tag P3D.DualConnectedComponent
     @L0.assert P3D.hasGeometry P3D.Builtin.ElbowGeometryProvider
@@ -138,6 +153,7 @@ P3D.Builtin.Elbow90 <T P3D.TurnComponent : P3D.TurnComponent
          1.5707963267948966192313216916398 : L0.Double
          
 P3D.Builtin.Elbow45 <T P3D.TurnComponent : P3D.TurnComponent  
+    L0.HasLabel "45 degree elbow"
     @L0.tag P3D.FixedAngleTurnComponent
     @L0.tag P3D.DualConnectedComponent
     @L0.assert P3D.hasGeometry P3D.Builtin.ElbowGeometryProvider
index ab32c89450fd079b51c7833caa49f854b535fad5..d680aeb04e7352c3794f891b1119f4654fddbbb1 100644 (file)
@@ -8,9 +8,34 @@ public class ComponentLabelProvider extends LabelProvider{
        @Override
        public String getText(Object element) {
                Item item = (Item)element;
-               return item.getName();
+               String label = item.getLabel();
+               return label != null ? label : fromCamelCase(item.getName());
        }
-       
-       
 
+       private static String fromCamelCase(String name) {
+               StringBuilder b = new StringBuilder(name);
+               for (int i = 0; i < b.length(); i++) {
+                       char ch = b.charAt(i);
+                       if (i == 0 && Character.isLowerCase(ch)) {
+                               b.setCharAt(i, Character.toUpperCase(ch));
+                       }
+                       else if (ch == '_') {
+                               if (i == 0 || b.charAt(i-1) == ' ') {
+                                       b.deleteCharAt(i);
+                                       i--;
+                               }
+                               else {
+                                       b.setCharAt(i, ' ');
+                               }
+                       }
+                       else if (i >= 2 && Character.isLowerCase(ch) &&
+                                       Character.isUpperCase(b.charAt(i-1)) &&
+                                       b.charAt(i-2) != ' ') {
+                               b.insert(i-1, ' ');
+                               i++;
+                       }
+               }
+               
+               return b.toString();
+       }
 }
index 1ce6ed20673bfc7eff67ded0f45c8c7f30d13cc0..2a5b205a3e0da40a16eaf22bd9e4f382eceeaeaf 100644 (file)
@@ -6,6 +6,7 @@ public class Item {
        
        private String uri;
        private String name;
+       private String label;
        
        private Type type;
        private boolean code = false;
@@ -20,7 +21,11 @@ public class Item {
                this.name = name;
        }
        
-       
+       public Item(String type, String name, String label) {
+               this.uri = type;
+               this.name = name;
+               this.label = label;
+       }
        
        public String getUri() {
                return uri;
@@ -91,4 +96,7 @@ public class Item {
                return uri.hashCode();
        }
 
+       public String getLabel() {
+               return label;
+       }
 }
index 055ffa11df29a5f388b9eea4e67089862247b40a..ab795acc23e413d48a298631e366d680f03d37c3 100644 (file)
@@ -188,7 +188,8 @@ public class P3DUtil {
                Plant3D p3d = Plant3D.getInstance(graph);
                String name = graph.getRelatedValue(r, l0.HasName);
                String uri = graph.getURI(r);
-               Item item = new Item(uri, name);
+               String label = graph.getPossibleRelatedValue(r, l0.HasLabel);
+               Item item = new Item(uri, name, label);
                if (graph.isInstanceOf(r, p3d.Equipment))
                        item.setType(Type.EQUIPMENT);
                else if (graph.isInstanceOf(r, p3d.InlineComponent))