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;
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";
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);
--- /dev/null
+/*******************************************************************************
+ * 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();
+ }
+ }
+
+}