]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
ResourceSCLTextGridStyle for creating Resource-based monitors with SCL 60/1960/1
authorjsimomaa <jani.simomaa@gmail.com>
Fri, 27 Jul 2018 07:04:49 +0000 (10:04 +0300)
committerjsimomaa <jani.simomaa@gmail.com>
Fri, 27 Jul 2018 07:04:49 +0000 (10:04 +0300)
gitlab #62

Change-Id: I17b33e561ff5194e8ebaaf4522d702b222e762cf

bundles/org.simantics.diagram.ontology/graph/DiagramProfiles.pgraph
bundles/org.simantics.diagram/adapters.xml
bundles/org.simantics.diagram/src/org/simantics/diagram/profile/ResourceSCLTextGridStyle.java [new file with mode: 0644]

index ae177ce7d812f088beab575ae6dbb1def36e559b..9ddd6cc7413c9b2e2fb0dd8c488417017103503f 100644 (file)
@@ -63,6 +63,9 @@ DIA.ExpressionStyle <T DIA.Style
 DIA.SCLTextGridStyle <T DIA.Style
   >-- DIA.SCLTextGridStyle.texts ==> "Variable -> <ReadGraph> (String,String,String)" <R L0.HasProperty : L0.TotalFunction
 
+DIA.ResourceSCLTextGridStyle <T DIA.Style
+  >-- DIA.ResourceSCLTextGridStyle.texts ==> "Resource -> <ReadGraph> (String,String,String)" <R L0.HasProperty : L0.TotalFunction
+
 DIA.SCLTextStyle <T DIA.Style
 DIA.BasicExpressionTextStyle <T DIA.Style
 
index 9a91eca4f28f733c158b6918117d0e3eda6840dd..fd6de9e016e1eb31ec202b063812f823ca33abc0 100644 (file)
                        <graph />
                        <this />
                </type>
+        <type
+            uri="http://www.simantics.org/Diagram-0.0/ResourceSCLTextGridStyle"
+            class="org.simantics.diagram.profile.ResourceSCLTextGridStyle">
+            <graph />
+            <this />
+        </type>
        </target>
 
        <target interface="org.simantics.scenegraph.profile.Group">
diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/profile/ResourceSCLTextGridStyle.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/profile/ResourceSCLTextGridStyle.java
new file mode 100644 (file)
index 0000000..3bbbf80
--- /dev/null
@@ -0,0 +1,85 @@
+package org.simantics.diagram.profile;
+
+import java.awt.Font;
+import java.awt.geom.AffineTransform;
+
+import org.simantics.Simantics;
+import org.simantics.datatypes.literal.Vec2d;
+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.G2DUtils;
+import org.simantics.diagram.stubs.DiagramResource;
+import org.simantics.diagram.stubs.G2DResource;
+import org.simantics.diagram.synchronization.graph.DiagramGraphUtil;
+import org.simantics.scl.runtime.function.Function1;
+import org.simantics.scl.runtime.tuple.Tuple3;
+import org.simantics.utils.datastructures.Pair;
+
+/**
+ * @author Antti Villberg
+ */
+public class ResourceSCLTextGridStyle extends TextGridStyle {
+
+       final Resource style;
+       final Font font;
+
+       public ResourceSCLTextGridStyle(ReadGraph graph, Resource style) throws DatabaseException {
+               this.style = style;
+               G2DResource G2D = G2DResource.getInstance(graph);
+        Resource fontR = graph.getPossibleObject(style, G2D.HasFont);
+               if(fontR != null) {
+                       font = G2DUtils.getFont(graph, fontR);
+               } else {
+                       font = null;
+               }
+
+       }
+
+       @Override
+       protected Font getFont() {
+               if(font != null) return font;
+               return super.getFont();
+       }
+
+       @Override
+       public Resource getPropertyRelation(ReadGraph graph, Resource module) {
+               throw new Error("Fix this");
+       }
+
+       @Override
+       protected Object getIdentity(Resource entry) {
+               return new Pair<Resource, Resource>(style, entry);
+       }
+
+       @Override
+       protected String rowId() {
+               return getNodeName();
+       }
+
+       @Override
+       public MonitorTextGridResult calculateStyle(ReadGraph graph, Resource runtimeDiagram, Resource entry, Resource element, Variable configuration) throws DatabaseException {
+               DiagramResource DIA = DiagramResource.getInstance(graph);
+
+               Variable styleVariable = Variables.getVariable(graph, style);
+               Function1<Resource,Tuple3> function = styleVariable.getPossiblePropertyValue(graph, DIA.ResourceSCLTextGridStyle_texts);
+               Tuple3 result = Simantics.applySCLRead(graph, function, element);
+               
+               AffineTransform transform = DiagramGraphUtil.getAffineTransform(graph, element);
+               Vec2d offset = DiagramGraphUtil.getOffset(graph, element);
+               boolean enabled = !DiagramGraphUtil.getProfileMonitorsHidden(graph, element);
+               boolean up = DiagramGraphUtil.getProfileMonitorsUp(graph, element);
+               double spacing = DiagramGraphUtil.getProfileMonitorSpacing(graph, element);
+
+               return new MonitorTextGridResult(rowId(), (String)result.c0, (String)result.c1, (String)result.c2, enabled, up, spacing, null, null, ElementTranslation.function(element), transform, offset);
+
+       }
+
+       @Override
+       public String getNodeName() {
+               return "" + style.getResourceId();
+       }
+
+}