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 {
30 public SCLTextGridStyle(ReadGraph graph, Resource style) throws DatabaseException {
32 G2DResource G2D = G2DResource.getInstance(graph);
33 Resource fontR = graph.getPossibleObject(style, G2D.HasFont);
35 font = G2DUtils.getFont(graph, fontR);
43 protected Font getFont() {
44 if(font != null) return font;
45 return super.getFont();
49 public Resource getPropertyRelation(ReadGraph graph, Resource module) {
50 throw new Error("Fix this");
54 protected Object getIdentity(Resource entry) {
55 return new Pair<Resource, Resource>(getResource(), entry);
59 protected String rowId() {
64 public MonitorTextGridResult calculateStyle(ReadGraph graph, Resource runtimeDiagram, Resource entry, Resource element, Variable configuration)
65 throws DatabaseException {
67 DiagramResource DIA = DiagramResource.getInstance(graph);
68 ModelingResources MOD = ModelingResources.getInstance(graph);
70 String variableURI = graph.getPossibleRelatedValue(runtimeDiagram, DIA.RuntimeDiagram_HasVariable, Bindings.STRING);
71 Variable activeVariable = org.simantics.db.layer0.variable.Variables.getPossibleVariable(graph, variableURI);
72 if (activeVariable == null)
75 Resource module = graph.getPossibleObject(element, MOD.ElementToComponent);
79 Variable moduleVariable = activeVariable.browsePossible(graph, module);
80 if (moduleVariable == null)
83 Variable styleVariable = Variables.getVariable(graph, getResource());
84 Function1<Variable,Tuple3> function = styleVariable.getPossiblePropertyValue(graph, DIA.SCLTextGridStyle_texts);
85 Tuple3 result = Simantics.applySCLRead(graph, function, moduleVariable);
87 AffineTransform transform = DiagramGraphUtil.getAffineTransform(graph, element);
88 Vec2d offset = DiagramGraphUtil.getOffset(graph, element);
89 boolean enabled = !DiagramGraphUtil.getProfileMonitorsHidden(graph, element);
90 boolean up = DiagramGraphUtil.getProfileMonitorsUp(graph, element);
91 double spacing = DiagramGraphUtil.getProfileMonitorSpacing(graph, element);
93 return new MonitorTextGridResult(rowId(), (String)result.c0, (String)result.c1, (String)result.c2, enabled, up, spacing, null, null, ElementTranslation.function(element), transform, offset);
98 public String getNodeName() {
99 return "" + getResource().getResourceId();