]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.diagram/src/org/simantics/diagram/profile/SCLTextGridStyle.java
ConnectionNode returns local bounds even if it has empty child nodes
[simantics/platform.git] / bundles / org.simantics.diagram / src / org / simantics / diagram / profile / SCLTextGridStyle.java
1 package org.simantics.diagram.profile;
2
3 import java.awt.Font;
4 import java.awt.geom.AffineTransform;
5
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;
22
23 /**
24  * @author Antti Villberg
25  */
26 public class SCLTextGridStyle extends TextGridStyle {
27
28         final Resource style;
29         final Font font;
30
31         public SCLTextGridStyle(ReadGraph graph, Resource style) throws DatabaseException {
32                 this.style = style;
33                 G2DResource G2D = G2DResource.getInstance(graph);
34         Resource fontR = graph.getPossibleObject(style, G2D.HasFont);
35                 if(fontR != null) {
36                         font = G2DUtils.getFont(graph, fontR);
37                 } else {
38                         font = null;
39                 }
40
41         }
42
43         @Override
44         protected Font getFont() {
45                 if(font != null) return font;
46                 return super.getFont();
47         }
48
49         @Override
50         public Resource getPropertyRelation(ReadGraph graph, Resource module) {
51                 throw new Error("Fix this");
52         }
53
54         @Override
55         protected Object getIdentity(Resource entry) {
56                 return new Pair<Resource, Resource>(style, entry);
57         }
58
59         @Override
60         protected String rowId() {
61                 return getNodeName();
62         }
63
64         @Override
65         public MonitorTextGridResult calculateStyle(ReadGraph graph, Resource runtimeDiagram, Resource entry, Resource element, Variable configuration)
66                         throws DatabaseException {
67
68                 DiagramResource DIA = DiagramResource.getInstance(graph);
69                 ModelingResources MOD = ModelingResources.getInstance(graph);
70
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)
74                         return null;
75
76                 Resource module = graph.getPossibleObject(element, MOD.ElementToComponent);
77                 if (module == null)
78                         return null;
79
80                 Variable moduleVariable = activeVariable.browsePossible(graph, module);
81                 if (moduleVariable == null)
82                         return null;
83
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);
87                 
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);
93
94                 return new MonitorTextGridResult(rowId(), (String)result.c0, (String)result.c1, (String)result.c2, enabled, up, spacing, null, null, ElementTranslation.function(element), transform, offset);
95
96         }
97
98         @Override
99         public String getNodeName() {
100                 return "" + style.getResourceId();
101         }
102
103 }