1 package org.simantics.diagram.profile;
4 import java.awt.geom.AffineTransform;
6 import org.simantics.Simantics;
7 import org.simantics.databoard.Bindings;
8 import org.simantics.datatypes.literal.Vec2d;
9 import org.simantics.db.ReadGraph;
10 import org.simantics.db.Resource;
11 import org.simantics.db.exception.DatabaseException;
12 import org.simantics.db.layer0.variable.Variable;
13 import org.simantics.db.layer0.variable.Variables;
14 import org.simantics.diagram.G2DUtils;
15 import org.simantics.diagram.stubs.DiagramResource;
16 import org.simantics.diagram.stubs.G2DResource;
17 import org.simantics.diagram.synchronization.graph.DiagramGraphUtil;
18 import org.simantics.modeling.ModelingResources;
19 import org.simantics.scl.runtime.function.Function1;
20 import org.simantics.scl.runtime.tuple.Tuple3;
21 import org.simantics.utils.datastructures.Pair;
24 * @author Antti Villberg
26 public class SCLTextGridStyle extends TextGridStyle {
31 public SCLTextGridStyle(ReadGraph graph, Resource style) throws DatabaseException {
33 G2DResource G2D = G2DResource.getInstance(graph);
34 Resource fontR = graph.getPossibleObject(style, G2D.HasFont);
36 font = G2DUtils.getFont(graph, fontR);
44 protected Font getFont() {
45 if(font != null) return font;
46 return super.getFont();
50 public Resource getPropertyRelation(ReadGraph graph, Resource module) {
51 throw new Error("Fix this");
55 protected Object getIdentity(Resource entry) {
56 return new Pair<Resource, Resource>(style, entry);
60 protected String rowId() {
65 public MonitorTextGridResult calculateStyle(ReadGraph graph, Resource runtimeDiagram, Resource entry, Resource element, Variable configuration)
66 throws DatabaseException {
68 DiagramResource DIA = DiagramResource.getInstance(graph);
69 ModelingResources MOD = ModelingResources.getInstance(graph);
71 String variableURI = graph.getPossibleRelatedValue(runtimeDiagram, DIA.RuntimeDiagram_HasVariable, Bindings.STRING);
72 Variable activeVariable = org.simantics.db.layer0.variable.Variables.getPossibleVariable(graph, variableURI);
73 if (activeVariable == null)
76 Resource module = graph.getPossibleObject(element, MOD.ElementToComponent);
80 Variable moduleVariable = activeVariable.browsePossible(graph, module);
81 if (moduleVariable == null)
84 Variable styleVariable = Variables.getVariable(graph, style);
85 Function1<Variable,Tuple3> function = styleVariable.getPossiblePropertyValue(graph, DIA.SCLTextGridStyle_texts);
86 Tuple3 result = Simantics.applySCLRead(graph, function, moduleVariable);
88 AffineTransform transform = DiagramGraphUtil.getAffineTransform(graph, element);
89 Vec2d offset = DiagramGraphUtil.getOffset(graph, element);
90 boolean enabled = !DiagramGraphUtil.getProfileMonitorsHidden(graph, element);
91 boolean up = DiagramGraphUtil.getProfileMonitorsUp(graph, element);
92 double spacing = DiagramGraphUtil.getProfileMonitorSpacing(graph, element);
94 return new MonitorTextGridResult(rowId(), (String)result.c0, (String)result.c1, (String)result.c2, enabled, up, spacing, null, null, ElementTranslation.function(element), transform, offset);
99 public String getNodeName() {
100 return "" + style.getResourceId();