From: jsimomaa Date: Fri, 27 Jul 2018 07:04:49 +0000 (+0300) Subject: ResourceSCLTextGridStyle for creating Resource-based monitors with SCL X-Git-Tag: v1.43.0~136^2~430^2 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F60%2F1960%2F1;p=simantics%2Fplatform.git ResourceSCLTextGridStyle for creating Resource-based monitors with SCL gitlab #62 Change-Id: I17b33e561ff5194e8ebaaf4522d702b222e762cf --- diff --git a/bundles/org.simantics.diagram.ontology/graph/DiagramProfiles.pgraph b/bundles/org.simantics.diagram.ontology/graph/DiagramProfiles.pgraph index ae177ce7d..9ddd6cc74 100644 --- a/bundles/org.simantics.diagram.ontology/graph/DiagramProfiles.pgraph +++ b/bundles/org.simantics.diagram.ontology/graph/DiagramProfiles.pgraph @@ -63,6 +63,9 @@ DIA.ExpressionStyle -- DIA.SCLTextGridStyle.texts ==> "Variable -> (String,String,String)" -- DIA.ResourceSCLTextGridStyle.texts ==> "Resource -> (String,String,String)" + + + + diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/profile/ResourceSCLTextGridStyle.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/profile/ResourceSCLTextGridStyle.java new file mode 100644 index 000000000..3bbbf8081 --- /dev/null +++ b/bundles/org.simantics.diagram/src/org/simantics/diagram/profile/ResourceSCLTextGridStyle.java @@ -0,0 +1,85 @@ +package org.simantics.diagram.profile; + +import java.awt.Font; +import java.awt.geom.AffineTransform; + +import org.simantics.Simantics; +import org.simantics.datatypes.literal.Vec2d; +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.G2DUtils; +import org.simantics.diagram.stubs.DiagramResource; +import org.simantics.diagram.stubs.G2DResource; +import org.simantics.diagram.synchronization.graph.DiagramGraphUtil; +import org.simantics.scl.runtime.function.Function1; +import org.simantics.scl.runtime.tuple.Tuple3; +import org.simantics.utils.datastructures.Pair; + +/** + * @author Antti Villberg + */ +public class ResourceSCLTextGridStyle extends TextGridStyle { + + final Resource style; + final Font font; + + public ResourceSCLTextGridStyle(ReadGraph graph, Resource style) throws DatabaseException { + this.style = style; + G2DResource G2D = G2DResource.getInstance(graph); + Resource fontR = graph.getPossibleObject(style, G2D.HasFont); + if(fontR != null) { + font = G2DUtils.getFont(graph, fontR); + } else { + font = null; + } + + } + + @Override + protected Font getFont() { + if(font != null) return font; + return super.getFont(); + } + + @Override + public Resource getPropertyRelation(ReadGraph graph, Resource module) { + throw new Error("Fix this"); + } + + @Override + protected Object getIdentity(Resource entry) { + return new Pair(style, entry); + } + + @Override + protected String rowId() { + return getNodeName(); + } + + @Override + public MonitorTextGridResult calculateStyle(ReadGraph graph, Resource runtimeDiagram, Resource entry, Resource element, Variable configuration) throws DatabaseException { + DiagramResource DIA = DiagramResource.getInstance(graph); + + Variable styleVariable = Variables.getVariable(graph, style); + Function1 function = styleVariable.getPossiblePropertyValue(graph, DIA.ResourceSCLTextGridStyle_texts); + Tuple3 result = Simantics.applySCLRead(graph, function, element); + + AffineTransform transform = DiagramGraphUtil.getAffineTransform(graph, element); + Vec2d offset = DiagramGraphUtil.getOffset(graph, element); + boolean enabled = !DiagramGraphUtil.getProfileMonitorsHidden(graph, element); + boolean up = DiagramGraphUtil.getProfileMonitorsUp(graph, element); + double spacing = DiagramGraphUtil.getProfileMonitorSpacing(graph, element); + + return new MonitorTextGridResult(rowId(), (String)result.c0, (String)result.c1, (String)result.c2, enabled, up, spacing, null, null, ElementTranslation.function(element), transform, offset); + + } + + @Override + public String getNodeName() { + return "" + style.getResourceId(); + } + +}