]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Symbol code style into platform 20/420/4
authorAntti Villberg <antti.villberg@semantum.fi>
Tue, 18 Apr 2017 13:10:21 +0000 (16:10 +0300)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Tue, 18 Apr 2017 21:42:00 +0000 (00:42 +0300)
refs #7146

Change-Id: Ic417ecdf8ff59c2f89747d82932dfd404c3293c4

bundles/org.simantics.modeling.ontology/graph.tg
bundles/org.simantics.modeling.ontology/graph/Modeling.pgraph
bundles/org.simantics.modeling.ontology/src/org/simantics/modeling/ModelingResources.java
bundles/org.simantics.modeling/adapters.xml
bundles/org.simantics.modeling/src/org/simantics/modeling/adapters/SymbolCodeStyle.java [new file with mode: 0644]

index 0ac20b8f448112534d33dc0f7fd3536aacec62c6..bf2b0b29ca527232fdbd540daab731ae6eb01772 100644 (file)
Binary files a/bundles/org.simantics.modeling.ontology/graph.tg and b/bundles/org.simantics.modeling.ontology/graph.tg differ
index ebc49fbe09ccdf7357592909ab355980c418333f..94b3b5df1dac85c289e7a3119c658ecfaca604a2 100644 (file)
@@ -515,4 +515,4 @@ MOD.SVGTabContribution : SEL.SCLTabContribution
     "svgTabContribution"
     "() -> <Proc> TabContribution"
 
-      
\ No newline at end of file
+MOD.SymbolCodeStyle : DIA.Style
\ No newline at end of file
index 8504813e88353db3452e3f009dd805e9530001ca..13cef22bcff11870c4fea3f9a5a81dcbedc65f49 100644 (file)
@@ -406,6 +406,7 @@ public class ModelingResources {
     public final Resource Subscription_Item_Unit_Inverse;
     public final Resource Subscription_Item_VariableId;
     public final Resource Subscription_Item_VariableId_Inverse;
+    public final Resource SymbolCodeStyle;
     public final Resource SymbolToComponentType;
     public final Resource SystemPropertyInfo;
     @Deprecated public final Resource TestTerminal;
@@ -833,6 +834,7 @@ public class ModelingResources {
         public static final String Subscription_Item_Unit_Inverse = "http://www.simantics.org/Modeling-1.2/Subscription/Item/Unit/Inverse";
         public static final String Subscription_Item_VariableId = "http://www.simantics.org/Modeling-1.2/Subscription/Item/VariableId";
         public static final String Subscription_Item_VariableId_Inverse = "http://www.simantics.org/Modeling-1.2/Subscription/Item/VariableId/Inverse";
+        public static final String SymbolCodeStyle = "http://www.simantics.org/Modeling-1.2/SymbolCodeStyle";
         public static final String SymbolToComponentType = "http://www.simantics.org/Modeling-1.2/SymbolToComponentType";
         public static final String SystemPropertyInfo = "http://www.simantics.org/Modeling-1.2/SystemPropertyInfo";
         @Deprecated public static final String TestTerminal = "http://www.simantics.org/Modeling-1.2/TestTerminal";
@@ -1270,6 +1272,7 @@ public class ModelingResources {
         Subscription_Item_Unit_Inverse = getResourceOrNull(graph, URIs.Subscription_Item_Unit_Inverse);
         Subscription_Item_VariableId = getResourceOrNull(graph, URIs.Subscription_Item_VariableId);
         Subscription_Item_VariableId_Inverse = getResourceOrNull(graph, URIs.Subscription_Item_VariableId_Inverse);
+        SymbolCodeStyle = getResourceOrNull(graph, URIs.SymbolCodeStyle);
         SymbolToComponentType = getResourceOrNull(graph, URIs.SymbolToComponentType);
         SystemPropertyInfo = getResourceOrNull(graph, URIs.SystemPropertyInfo);
         TestTerminal = getResourceOrNull(graph, URIs.TestTerminal);
index c56ab44ad39f527a121829d13409e7bbfd5ac652..b1a0bf3e15cde228e022bfcff9b73d9d166a2e25 100644 (file)
                        class="org.simantics.modeling.typicals.rules.PageSettingsTypicalRule"
                        constructor="get" />
        </target>
+
+       <target interface="org.simantics.scenegraph.profile.Style">
+               <resource uri="http://www.simantics.org/Modeling-0.0/SymbolCodeStyle"
+                       class="org.simantics.modeling.adapters.SymbolCodeStyle">
+               </resource>
+       </target>
+
 </adapters>
\ No newline at end of file
diff --git a/bundles/org.simantics.modeling/src/org/simantics/modeling/adapters/SymbolCodeStyle.java b/bundles/org.simantics.modeling/src/org/simantics/modeling/adapters/SymbolCodeStyle.java
new file mode 100644 (file)
index 0000000..fb58433
--- /dev/null
@@ -0,0 +1,71 @@
+/*******************************************************************************
+ * Copyright (c) 2017 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     Semantum Oy - initial API and implementation
+ *******************************************************************************/
+package org.simantics.modeling.adapters;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.variable.Variable;
+import org.simantics.db.layer0.variable.Variables;
+import org.simantics.diagram.profile.StyleBase;
+import org.simantics.diagram.stubs.DiagramResource;
+import org.simantics.scenegraph.INode;
+import org.simantics.scenegraph.g2d.nodes.SVGNode;
+import org.simantics.scenegraph.g2d.nodes.SVGNode.SVGNodeAssignment;
+import org.simantics.scenegraph.profile.EvaluationContext;
+import org.simantics.scenegraph.utils.NodeUtil;
+import org.simantics.utils.datastructures.Pair;
+
+/**
+ * @author Antti Villberg
+ * @since 1.29.0
+ */
+public class SymbolCodeStyle extends StyleBase<Pair<List<String>, Object>> {
+
+    @Override
+    public Pair<List<String>, Object> calculateStyle(ReadGraph graph, Resource runtimeDiagram, Resource entry, Resource element, Variable configuration) throws DatabaseException {
+        DiagramResource DIA = DiagramResource.getInstance(graph);
+
+        // Find a component for the element 
+        Variable elementVariable = Variables.getPossibleVariable(graph, element);
+        if (elementVariable == null)
+            return null;
+        List<String> styles = elementVariable.getPossiblePropertyValue(graph, DIA.symbolCode);
+        if (styles == null)
+            return null;
+
+        // If element is moved, recalculate style
+        Object transform = graph.getPossibleRelatedValue(element, DIA.HasTransform);
+
+        return Pair.make(styles, transform);
+    }
+
+    @Override
+    public void applyStyleForNode(EvaluationContext evaluationContext, INode node, Pair<List<String>, Object> result) {
+        if (result == null || result.first == null || result.first.isEmpty())
+            return;
+
+        List<String> styles = result.first;
+        List<SVGNodeAssignment> assignments = new ArrayList<>(styles.size()/3);
+        for (int i = 0; i < styles.size()/3; i++)
+            assignments.add(new SVGNodeAssignment(styles.get(3*i), styles.get(3*i+1), styles.get(3*i+2)));
+
+        for (SVGNode p : NodeUtil.collectNodes(node, SVGNode.class)) {
+            p.setAssignments(assignments);
+            p.cleanDiagramCache();
+        }
+    }
+
+}