From: Antti Villberg Date: Tue, 18 Apr 2017 13:10:21 +0000 (+0300) Subject: Symbol code style into platform X-Git-Tag: v1.29.0~103 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=d56508010d94c9cd5fe682b69a4cb2191abc6004;p=simantics%2Fplatform.git Symbol code style into platform refs #7146 Change-Id: Ic417ecdf8ff59c2f89747d82932dfd404c3293c4 --- diff --git a/bundles/org.simantics.modeling.ontology/graph.tg b/bundles/org.simantics.modeling.ontology/graph.tg index 0ac20b8f4..bf2b0b29c 100644 Binary files a/bundles/org.simantics.modeling.ontology/graph.tg and b/bundles/org.simantics.modeling.ontology/graph.tg differ diff --git a/bundles/org.simantics.modeling.ontology/graph/Modeling.pgraph b/bundles/org.simantics.modeling.ontology/graph/Modeling.pgraph index ebc49fbe0..94b3b5df1 100644 --- a/bundles/org.simantics.modeling.ontology/graph/Modeling.pgraph +++ b/bundles/org.simantics.modeling.ontology/graph/Modeling.pgraph @@ -515,4 +515,4 @@ MOD.SVGTabContribution : SEL.SCLTabContribution "svgTabContribution" "() -> TabContribution" - \ No newline at end of file +MOD.SymbolCodeStyle : DIA.Style \ No newline at end of file diff --git a/bundles/org.simantics.modeling.ontology/src/org/simantics/modeling/ModelingResources.java b/bundles/org.simantics.modeling.ontology/src/org/simantics/modeling/ModelingResources.java index 8504813e8..13cef22bc 100644 --- a/bundles/org.simantics.modeling.ontology/src/org/simantics/modeling/ModelingResources.java +++ b/bundles/org.simantics.modeling.ontology/src/org/simantics/modeling/ModelingResources.java @@ -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); diff --git a/bundles/org.simantics.modeling/adapters.xml b/bundles/org.simantics.modeling/adapters.xml index c56ab44ad..b1a0bf3e1 100644 --- a/bundles/org.simantics.modeling/adapters.xml +++ b/bundles/org.simantics.modeling/adapters.xml @@ -225,4 +225,11 @@ class="org.simantics.modeling.typicals.rules.PageSettingsTypicalRule" constructor="get" /> + + + + + + \ 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 index 000000000..fb584331e --- /dev/null +++ b/bundles/org.simantics.modeling/src/org/simantics/modeling/adapters/SymbolCodeStyle.java @@ -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, Object>> { + + @Override + public Pair, 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 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, Object> result) { + if (result == null || result.first == null || result.first.isEmpty()) + return; + + List styles = result.first; + List 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(); + } + } + +}