From 08dc7080753f3ea35985e76e9effb9d3ff92c3b5 Mon Sep 17 00:00:00 2001 From: Antti Villberg Date: Tue, 5 Sep 2017 21:05:51 +0300 Subject: [PATCH] Better support for ontological profiles refs #7465 Change-Id: I6b832067db3a7db4903934c97b4c9e48ee301c0a --- .../graph/DiagramProfiles.pgraph | 2 +- .../graph/ProfilesView.pgraph | 2 +- .../diagram/profile/function/All.java | 6 +-- .../profile/view/DirectProfileEntries.java | 14 +++---- .../diagram/profile/view/EntryLabeler.java | 6 +-- .../profile/view/ProfileCheckContributor.java | 19 +++++---- .../profile/view/ProfileEntryChildren.java | 27 +++++++------ .../view/ProfileEntrySelectionListener.java | 39 +++++++------------ .../view/ProfileSelectionProcessor.java | 14 +++---- .../diagram/profile/view/ProfileTuple.java | 26 +++++++++++++ .../profile/view/RemoveEntriesAction.java | 9 ++--- .../diagram/profile/view/ResourcePair.java | 22 ----------- .../profile/view/ResourcePairImageRule.java | 4 +- .../profile/view/ResourcePairLabelRule.java | 4 +- .../view/RuntimeDirectProfileEntries.java | 2 +- bundles/org.simantics.diagram/adapters.xml | 1 + .../diagram/profile/SCLTextGridStyle.java | 33 +++++++++++----- .../diagram/profile/TextGridStyle.java | 34 ++++++++++------ .../graph/G2D.pgraph | 17 ++++++++ .../scenegraph/profile/ProfileUtils.java | 23 ++++++++--- 20 files changed, 175 insertions(+), 129 deletions(-) create mode 100644 bundles/org.simantics.diagram.profile/src/org/simantics/diagram/profile/view/ProfileTuple.java delete mode 100644 bundles/org.simantics.diagram.profile/src/org/simantics/diagram/profile/view/ResourcePair.java diff --git a/bundles/org.simantics.diagram.ontology/graph/DiagramProfiles.pgraph b/bundles/org.simantics.diagram.ontology/graph/DiagramProfiles.pgraph index ef868a504..ae177ce7d 100644 --- a/bundles/org.simantics.diagram.ontology/graph/DiagramProfiles.pgraph +++ b/bundles/org.simantics.diagram.ontology/graph/DiagramProfiles.pgraph @@ -61,7 +61,7 @@ DIA.ConstantStyle -- DIA.SCLTextGridStyle.function ==> "Variable -> String" -- DIA.SCLTextGridStyle.texts ==> "Variable -> (String,String,String)" > { +public class DirectProfileEntries extends UnaryRead> { - public DirectProfileEntries(ResourcePair resource) { - super(resource); + public DirectProfileEntries(ProfileTuple tuple) { + super(tuple); } @Override - public List perform(ReadGraph graph) throws DatabaseException { + public List perform(ReadGraph graph) throws DatabaseException { DiagramResource dr = DiagramResource.getInstance(graph); - ArrayList entries = new ArrayList(); - Resource list = graph.getPossibleObject(parameter.getSecond(), dr.HasEntries); + List entries = new ArrayList<>(); + Resource list = graph.getPossibleObject(parameter.getEntry(), dr.HasEntries); if(list == null) return entries; for(Resource entry : ProfileUtils.getProfileChildrenFromEntries(graph, list)) { - entries.add(new ResourcePair(parameter.getFirst(), entry)); + entries.add(new ProfileTuple(parameter.getBaseProfile(), entry, parameter.getRuntimeDiagram())); } return entries; } diff --git a/bundles/org.simantics.diagram.profile/src/org/simantics/diagram/profile/view/EntryLabeler.java b/bundles/org.simantics.diagram.profile/src/org/simantics/diagram/profile/view/EntryLabeler.java index 00a9b7a58..b05f0e449 100644 --- a/bundles/org.simantics.diagram.profile/src/org/simantics/diagram/profile/view/EntryLabeler.java +++ b/bundles/org.simantics.diagram.profile/src/org/simantics/diagram/profile/view/EntryLabeler.java @@ -15,11 +15,11 @@ import org.simantics.browsing.ui.graph.contributor.labeler.LabelerContributor; import org.simantics.db.ReadGraph; import org.simantics.db.exception.DatabaseException; -public class EntryLabeler extends LabelerContributor { +public class EntryLabeler extends LabelerContributor { @Override - public String getLabel(ReadGraph graph, ResourcePair entry) throws DatabaseException { - return graph.adapt(entry.getSecond(), String.class); + public String getLabel(ReadGraph graph, ProfileTuple entry) throws DatabaseException { + return graph.adapt(entry.getEntry(), String.class); } } diff --git a/bundles/org.simantics.diagram.profile/src/org/simantics/diagram/profile/view/ProfileCheckContributor.java b/bundles/org.simantics.diagram.profile/src/org/simantics/diagram/profile/view/ProfileCheckContributor.java index 544c394c5..37e6d81e3 100644 --- a/bundles/org.simantics.diagram.profile/src/org/simantics/diagram/profile/view/ProfileCheckContributor.java +++ b/bundles/org.simantics.diagram.profile/src/org/simantics/diagram/profile/view/ProfileCheckContributor.java @@ -19,28 +19,28 @@ import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.exception.DatabaseException; import org.simantics.diagram.stubs.DiagramResource; +import org.simantics.scenegraph.profile.ProfileUtils; import org.simantics.scenegraph.profile.request.ProfileActiveEntryResources; import org.simantics.scenegraph.profile.request.ProfileEntryResources; -import org.simantics.simulation.ontology.SimulationResource; public class ProfileCheckContributor implements CheckedStateRule { @Override public boolean isCompatible(Class contentType) { - return contentType.equals(ResourcePair.class); + return contentType.equals(ProfileTuple.class); } @Override public CheckedState getCheckedState(ReadGraph graph, Object parent) throws DatabaseException { - ResourcePair entry = (ResourcePair)parent; - Resource activeProfile = entry.getFirst(); + ProfileTuple tuple = (ProfileTuple)parent; + Resource activeProfile = tuple.getBaseProfile(); + Resource entry = tuple.getEntry(); DiagramResource DIA = DiagramResource.getInstance(graph); - SimulationResource SIMU = SimulationResource.getInstance(graph); - if(graph.isInstanceOf(entry.getSecond(), DIA.Profile)) { - Resource list = graph.getPossibleObject(entry.getSecond(), DIA.HasEntries); + if(graph.isInstanceOf(entry, DIA.Profile)) { + Resource list = graph.getPossibleObject(entry, DIA.HasEntries); Collection activeEntries = graph.syncRequest( new ProfileActiveEntryResources(activeProfile, list) ); if (activeEntries.isEmpty()) { return CheckedState.NOT_CHECKED; @@ -48,11 +48,10 @@ public class ProfileCheckContributor implements CheckedStateRule { Collection entries = graph.syncRequest( new ProfileEntryResources(activeProfile, list) ); return entries.equals(activeEntries) ? CheckedState.CHECKED : CheckedState.GRAYED; } - - } else if(graph.isInstanceOf(entry.getSecond(), DIA.ProfileEntry)) { - if(graph.hasStatement(activeProfile, SIMU.IsActive, entry.getSecond())) return CheckedState.CHECKED; } + if(ProfileUtils.isActive(graph, tuple.getRuntimeDiagram(), activeProfile, entry)) return CheckedState.CHECKED; + return CheckedState.NOT_CHECKED; } diff --git a/bundles/org.simantics.diagram.profile/src/org/simantics/diagram/profile/view/ProfileEntryChildren.java b/bundles/org.simantics.diagram.profile/src/org/simantics/diagram/profile/view/ProfileEntryChildren.java index d16a776c7..712bd50fb 100644 --- a/bundles/org.simantics.diagram.profile/src/org/simantics/diagram/profile/view/ProfileEntryChildren.java +++ b/bundles/org.simantics.diagram.profile/src/org/simantics/diagram/profile/view/ProfileEntryChildren.java @@ -18,7 +18,6 @@ import java.util.Collections; import org.simantics.browsing.ui.model.children.ChildRule; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; -import org.simantics.db.common.utils.ListUtils; import org.simantics.db.exception.DatabaseException; import org.simantics.diagram.stubs.DiagramResource; import org.simantics.scenegraph.profile.ProfileUtils; @@ -27,28 +26,28 @@ public class ProfileEntryChildren implements ChildRule { @Override public boolean isCompatible(Class contentType) { - return contentType.equals(ResourcePair.class); + return contentType.equals(ProfileTuple.class); } @Override public Collection getChildren(ReadGraph graph, Object parent) throws DatabaseException { - - ResourcePair entry = (ResourcePair)parent; - ArrayList entries = new ArrayList(); - DiagramResource DIA = DiagramResource.getInstance(graph); - Resource children = graph.getPossibleObject(entry.getSecond(), DIA.HasEntries); - if(children == null) return Collections.emptyList(); - else { - for(Resource entry2 : ProfileUtils.getProfileChildrenFromEntries(graph, children)) entries.add(new ResourcePair(entry.getFirst(), entry2)); - return entries; - } - } + ProfileTuple entry = (ProfileTuple) parent; + ArrayList entries = new ArrayList<>(); + DiagramResource DIA = DiagramResource.getInstance(graph); + Resource children = graph.getPossibleObject(entry.getEntry(), DIA.HasEntries); + if (children != null) { + for (Resource entry2 : ProfileUtils.getProfileChildrenFromEntries(graph, children)) + entries.add(new ProfileTuple(entry.getBaseProfile(), entry2, entry.getRuntimeDiagram())); + return entries; + } + return Collections.emptyList(); + } @Override public Collection getParents(ReadGraph graph, Object child) throws DatabaseException { - return new ArrayList(); + return Collections.emptyList(); } } diff --git a/bundles/org.simantics.diagram.profile/src/org/simantics/diagram/profile/view/ProfileEntrySelectionListener.java b/bundles/org.simantics.diagram.profile/src/org/simantics/diagram/profile/view/ProfileEntrySelectionListener.java index c67558b27..f87a8286b 100644 --- a/bundles/org.simantics.diagram.profile/src/org/simantics/diagram/profile/view/ProfileEntrySelectionListener.java +++ b/bundles/org.simantics.diagram.profile/src/org/simantics/diagram/profile/view/ProfileEntrySelectionListener.java @@ -20,52 +20,41 @@ import org.simantics.simulation.ontology.SimulationResource; public class ProfileEntrySelectionListener implements Listener { - public void processRecursively(WriteGraph graph, Resource runtimeProfile, Resource entry, boolean checked) throws DatabaseException { + public void processRecursively(WriteGraph graph, Resource runtimeProfile, Resource entry, boolean checked) throws DatabaseException { + DiagramResource DIA = DiagramResource.getInstance(graph); - DiagramResource DIA = DiagramResource.getInstance(graph); - - if(graph.isInstanceOf(entry, DIA.Profile)) { - - for(Resource child : ProfileUtils.getProfileChildren(graph, entry)) { - processRecursively(graph, runtimeProfile, child, checked); - } - - } else if(graph.isInstanceOf(entry, DIA.ProfileEntry)) { - - if(checked) { + if (graph.isInstanceOf(entry, DIA.Profile)) { + for (Resource child : ProfileUtils.getProfileChildren(graph, entry)) { + processRecursively(graph, runtimeProfile, child, checked); + } + } else if (graph.isInstanceOf(entry, DIA.ProfileEntry)) { + if (checked) { graph.claim(runtimeProfile, SimulationResource.getInstance(graph).IsActive, null, entry); } else { graph.denyStatement(runtimeProfile, SimulationResource.getInstance(graph).IsActive, entry); } + } + } - } - - } - @Override public void handleEvent (Event event) { - if(event.detail == SWT.CHECK) { - final TreeItem item = (TreeItem)event.item; Tree tree = item.getParent(); GraphExplorer explorer = (GraphExplorer)tree.getData(GraphExplorer.KEY_GRAPH_EXPLORER); final Resource runtimeDiagram = (Resource)explorer.getRoot().getConstant(BuiltinKeys.INPUT); final boolean checked = item.getChecked(); NodeContext context = (NodeContext)item.getData(); - final ResourcePair entry = (ResourcePair)context.getConstant(BuiltinKeys.INPUT); + final ProfileTuple entry = (ProfileTuple)context.getConstant(BuiltinKeys.INPUT); try { - VirtualGraphSupport support = Simantics.getSession().getService(VirtualGraphSupport.class); Simantics.getSession().syncRequest(new WriteRequest(support.getWorkspacePersistent("profiles")) { @Override public void perform(WriteGraph graph) throws DatabaseException { - - DiagramResource DIA = DiagramResource.getInstance(graph); - Resource runtimeProfile = graph.getPossibleObject(runtimeDiagram, DIA.RuntimeDiagram_HasRuntimeProfile); - processRecursively(graph, runtimeProfile, entry.getSecond(), checked); - + DiagramResource DIA = DiagramResource.getInstance(graph); + Resource runtimeProfile = graph.getPossibleObject(runtimeDiagram, DIA.RuntimeDiagram_HasRuntimeProfile); + processRecursively(graph, runtimeProfile, entry.getEntry(), checked); } }); diff --git a/bundles/org.simantics.diagram.profile/src/org/simantics/diagram/profile/view/ProfileSelectionProcessor.java b/bundles/org.simantics.diagram.profile/src/org/simantics/diagram/profile/view/ProfileSelectionProcessor.java index 118d46f8e..c060f067a 100644 --- a/bundles/org.simantics.diagram.profile/src/org/simantics/diagram/profile/view/ProfileSelectionProcessor.java +++ b/bundles/org.simantics.diagram.profile/src/org/simantics/diagram/profile/view/ProfileSelectionProcessor.java @@ -25,7 +25,7 @@ public class ProfileSelectionProcessor implements SelectionProcessor process(Object selection, ReadGraph g) { try { Resource object = ISelectionUtils.getSinglePossibleKey(selection, SelectionHints.KEY_MAIN, Resource.class); - ResourcePair object2 = ISelectionUtils.getSinglePossibleKey(selection, SelectionHints.KEY_MAIN, ResourcePair.class); + ProfileTuple object2 = ISelectionUtils.getSinglePossibleKey(selection, SelectionHints.KEY_MAIN, ProfileTuple.class); return processInternal(g, object, object2, selection); @@ -36,7 +36,7 @@ public class ProfileSelectionProcessor implements SelectionProcessor processInternal(ReadGraph g, Resource object, ResourcePair pair, Object selection) throws DatabaseException { + private Collection processInternal(ReadGraph g, Resource object, ProfileTuple pair, Object selection) throws DatabaseException { Collection inputs = new ArrayList(); @@ -59,11 +59,11 @@ public class ProfileSelectionProcessor implements SelectionProcessor inputs) throws DatabaseException { + private void parseResourceInput(ReadGraph g, Resource part, ProfileTuple pair, Collection inputs) throws DatabaseException { getGroups(g, part, pair, inputs); } - void getGroups(ReadGraph g, Resource r, ResourcePair p, Collection result) throws DatabaseException { + void getGroups(ReadGraph g, Resource r, ProfileTuple p, Collection result) throws DatabaseException { DiagramResource dr = DiagramResource.getInstance(g); if (r != null && g.isInstanceOf(r, dr.SCLGroup)) { result.add(new SCLInput(r, 1, "SCL Group")); @@ -71,12 +71,12 @@ public class ProfileSelectionProcessor implements SelectionProcessor T getAdapter(Class adapter) { + if (adapter == Resource.class) { + return (T) getEntry(); + } + return null; + } + +} \ No newline at end of file diff --git a/bundles/org.simantics.diagram.profile/src/org/simantics/diagram/profile/view/RemoveEntriesAction.java b/bundles/org.simantics.diagram.profile/src/org/simantics/diagram/profile/view/RemoveEntriesAction.java index 0e51deac1..f83bbf928 100644 --- a/bundles/org.simantics.diagram.profile/src/org/simantics/diagram/profile/view/RemoveEntriesAction.java +++ b/bundles/org.simantics.diagram.profile/src/org/simantics/diagram/profile/view/RemoveEntriesAction.java @@ -23,9 +23,8 @@ public class RemoveEntriesAction extends ModelledActionImpl { public void run(Resource runtimeDiagram) { ISelection selection = getParameter(DiagramResource.URIs.ProfilesView_SelectedEntries); - final List selectedEntries = ISelectionUtils.getPossibleKeys(selection, SelectionHints.KEY_MAIN, ResourcePair.class); + final List selectedEntries = ISelectionUtils.getPossibleKeys(selection, SelectionHints.KEY_MAIN, ProfileTuple.class); if(selectedEntries != null && !selectedEntries.isEmpty()) { - System.err.println("RemoveEntriesAction has " + selection + " for " + runtimeDiagram); try { Simantics.getSession().syncRequest(new WriteRequest() { @@ -33,9 +32,9 @@ public class RemoveEntriesAction extends ModelledActionImpl { public void perform(WriteGraph graph) throws DatabaseException { DiagramResource DIA = DiagramResource.getInstance(graph); - for(ResourcePair entry : selectedEntries) { - Resource list = graph.getPossibleObject(entry.getFirst(), DIA.HasEntries); - OrderedSetUtils.remove(graph, list, entry.getSecond()); + for(ProfileTuple entry : selectedEntries) { + Resource list = graph.getPossibleObject(entry.getBaseProfile(), DIA.HasEntries); + OrderedSetUtils.remove(graph, list, entry.getEntry()); } } diff --git a/bundles/org.simantics.diagram.profile/src/org/simantics/diagram/profile/view/ResourcePair.java b/bundles/org.simantics.diagram.profile/src/org/simantics/diagram/profile/view/ResourcePair.java deleted file mode 100644 index c64149920..000000000 --- a/bundles/org.simantics.diagram.profile/src/org/simantics/diagram/profile/view/ResourcePair.java +++ /dev/null @@ -1,22 +0,0 @@ -package org.simantics.diagram.profile.view; - -import org.eclipse.core.runtime.IAdaptable; -import org.simantics.db.Resource; -import org.simantics.utils.datastructures.map.Tuple; - -public class ResourcePair extends Tuple implements IAdaptable{ - ResourcePair(Resource first, Resource second) { super(first ,second); } - public Resource getFirst() { return (Resource) getField(0); } - public Resource getSecond() { return (Resource) getField(1); } - - @SuppressWarnings("rawtypes") - @Override - public Object getAdapter(Class adapter) { - if (adapter == Resource.class) { - return getSecond(); - } - return null; - } - - -} \ No newline at end of file diff --git a/bundles/org.simantics.diagram.profile/src/org/simantics/diagram/profile/view/ResourcePairImageRule.java b/bundles/org.simantics.diagram.profile/src/org/simantics/diagram/profile/view/ResourcePairImageRule.java index 6f8ebe0a6..daf038a39 100644 --- a/bundles/org.simantics.diagram.profile/src/org/simantics/diagram/profile/view/ResourcePairImageRule.java +++ b/bundles/org.simantics.diagram.profile/src/org/simantics/diagram/profile/view/ResourcePairImageRule.java @@ -25,13 +25,13 @@ public class ResourcePairImageRule implements ImageRule { @Override public boolean isCompatible(Class contentType) { - return contentType.equals(ResourcePair.class); + return contentType.equals(ProfileTuple.class); } @Override public Map getImage(ReadGraph graph, Object content) throws DatabaseException { - ImageDescriptorProvider provider = graph.getPossibleAdapter(((ResourcePair)content).getSecond(), ImageDescriptorProvider.class); + ImageDescriptorProvider provider = graph.getPossibleAdapter(((ProfileTuple)content).getEntry(), ImageDescriptorProvider.class); return provider != null ? Collections.singletonMap(ColumnKeys.SINGLE, provider.get()) : null; } diff --git a/bundles/org.simantics.diagram.profile/src/org/simantics/diagram/profile/view/ResourcePairLabelRule.java b/bundles/org.simantics.diagram.profile/src/org/simantics/diagram/profile/view/ResourcePairLabelRule.java index 1810722ae..3e07a9e01 100644 --- a/bundles/org.simantics.diagram.profile/src/org/simantics/diagram/profile/view/ResourcePairLabelRule.java +++ b/bundles/org.simantics.diagram.profile/src/org/simantics/diagram/profile/view/ResourcePairLabelRule.java @@ -18,13 +18,13 @@ public class ResourcePairLabelRule implements LabelRule { @Override public boolean isCompatible(Class contentType) { - return contentType.equals(ResourcePair.class); + return contentType.equals(ProfileTuple.class); } @Override public Map getLabel(ReadGraph graph, Object content) throws DatabaseException { return Collections.singletonMap(ColumnKeys.SINGLE, - NameUtils.getSafeLabel(graph, ((ResourcePair)content).getSecond()) + NameUtils.getSafeLabel(graph, ((ProfileTuple)content).getEntry()) ); } } diff --git a/bundles/org.simantics.diagram.profile/src/org/simantics/diagram/profile/view/RuntimeDirectProfileEntries.java b/bundles/org.simantics.diagram.profile/src/org/simantics/diagram/profile/view/RuntimeDirectProfileEntries.java index 6ec408ecd..86b20df53 100644 --- a/bundles/org.simantics.diagram.profile/src/org/simantics/diagram/profile/view/RuntimeDirectProfileEntries.java +++ b/bundles/org.simantics.diagram.profile/src/org/simantics/diagram/profile/view/RuntimeDirectProfileEntries.java @@ -36,7 +36,7 @@ public class RuntimeDirectProfileEntries implements ChildRule { DiagramResource dr = DiagramResource.getInstance(graph); Resource runtimeProfile = graph.getPossibleObject(runtimeDiagram, dr.RuntimeDiagram_HasRuntimeProfile); if(runtimeProfile == null) return Collections.emptyList(); - return graph.syncRequest(new DirectProfileEntries(new ResourcePair(runtimeProfile, runtimeProfile))); + return graph.syncRequest(new DirectProfileEntries(new ProfileTuple(runtimeProfile, runtimeProfile, runtimeDiagram))); } diff --git a/bundles/org.simantics.diagram/adapters.xml b/bundles/org.simantics.diagram/adapters.xml index c7e65bfad..9a91eca4f 100644 --- a/bundles/org.simantics.diagram/adapters.xml +++ b/bundles/org.simantics.diagram/adapters.xml @@ -37,6 +37,7 @@ + diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/profile/SCLTextGridStyle.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/profile/SCLTextGridStyle.java index 5850ffb37..4401f2213 100644 --- a/bundles/org.simantics.diagram/src/org/simantics/diagram/profile/SCLTextGridStyle.java +++ b/bundles/org.simantics.diagram/src/org/simantics/diagram/profile/SCLTextGridStyle.java @@ -1,12 +1,9 @@ package org.simantics.diagram.profile; +import java.awt.Font; import java.awt.geom.AffineTransform; -import java.text.DecimalFormat; -import java.text.DecimalFormatSymbols; -import java.util.Locale; import org.simantics.Simantics; -import org.simantics.common.format.Formatter; import org.simantics.databoard.Bindings; import org.simantics.datatypes.literal.Vec2d; import org.simantics.db.ReadGraph; @@ -14,10 +11,13 @@ 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.modeling.ModelingResources; import org.simantics.scl.runtime.function.Function1; +import org.simantics.scl.runtime.tuple.Tuple3; import org.simantics.utils.datastructures.Pair; /** @@ -26,9 +26,24 @@ import org.simantics.utils.datastructures.Pair; public class SCLTextGridStyle extends TextGridStyle { final Resource style; + final Font font; - public SCLTextGridStyle(Resource style) { + public SCLTextGridStyle(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 @@ -67,16 +82,16 @@ public class SCLTextGridStyle extends TextGridStyle { return null; Variable styleVariable = Variables.getVariable(graph, style); - Function1 function = styleVariable.getPossiblePropertyValue(graph, "function"); - String result = Simantics.applySCLRead(graph, function, moduleVariable); - + Function1 function = styleVariable.getPossiblePropertyValue(graph, DIA.SCLTextGridStyle_texts); + Tuple3 result = Simantics.applySCLRead(graph, function, moduleVariable); + 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(), result, "", "", enabled, up, spacing, null, null, ElementTranslation.function(element), transform, offset); + return new MonitorTextGridResult(rowId(), (String)result.c0, (String)result.c1, (String)result.c2, enabled, up, spacing, null, null, ElementTranslation.function(element), transform, offset); } diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/profile/TextGridStyle.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/profile/TextGridStyle.java index d660d47a5..54972155d 100644 --- a/bundles/org.simantics.diagram/src/org/simantics/diagram/profile/TextGridStyle.java +++ b/bundles/org.simantics.diagram/src/org/simantics/diagram/profile/TextGridStyle.java @@ -94,7 +94,7 @@ public abstract class TextGridStyle extends StyleBase { String name = graph.getPossibleRelatedValue(config, getPropertyRelation(graph,element), Bindings.STRING); return name; } - + public AffineTransform getTransform(INode node, AffineTransform parentTransform, Rectangle2D elementBounds, int location, boolean up) { return getTransform(parentTransform, elementBounds, location, up); } @@ -110,7 +110,7 @@ public abstract class TextGridStyle extends StyleBase { at.scale(0.15, 0.15); return at; - + } protected String rowId() { @@ -161,7 +161,7 @@ public abstract class TextGridStyle extends StyleBase { String value2 = result != null ? result.getText2() : null; String value3 = result != null ? result.getText3() : null; - + double spacing = result.getSpacing(); final Function1 modifier = result != null ? result.getModifier() : null; @@ -209,7 +209,7 @@ public abstract class TextGridStyle extends StyleBase { node.setCache(1, row, result); boolean isConnection = _node instanceof ConnectionNode; - + Rectangle2D elementBounds = isConnection ? EMPTY_BOUNDS : NodeUtil.getLocalElementBounds(_node); if(elementBounds == null) { new Exception("Cannot get local element bounds for node " + _node.toString()).printStackTrace(); @@ -225,14 +225,14 @@ public abstract class TextGridStyle extends StyleBase { Vec2d offset = result.getOffset(); Point2D[] cellOffsets = getCellOffsets(); - + AffineTransform at1 = new AffineTransform(at); at1.translate(cellOffsets[0].getX(),cellOffsets[0].getY()); AffineTransform at2 = new AffineTransform(at); at2.translate(cellOffsets[1].getX()+spacing,cellOffsets[1].getY()); AffineTransform at3 = new AffineTransform(at); at3.translate(cellOffsets[2].getX()+spacing,cellOffsets[2].getY()); - + at1.translate(offset.x, offset.y); at2.translate(offset.x, offset.y); at3.translate(offset.x, offset.y); @@ -251,7 +251,7 @@ public abstract class TextGridStyle extends StyleBase { node.setHorizontalAlignment(2, row, (byte) getAlignment(2).ordinal()); node.setHorizontalAlignment(3, row, (byte) getAlignment(3).ordinal()); } - + Alignment[] verticalAlignments = result.getVerticalAlignments(); if(verticalAlignments != null) { node.setVerticalAlignment(1, row, (byte) verticalAlignments[0].ordinal()); @@ -266,11 +266,13 @@ public abstract class TextGridStyle extends StyleBase { node.setZIndex(3000); org.simantics.common.color.Color color = result.getColor(); - java.awt.Color awtColor = color != null ? Colors.awt(color) : Color.DARK_GRAY; + Color awtColor = color != null ? Colors.awt(color) : Color.DARK_GRAY; + Color bgColor = getBackgroundColor(); + Font font = getFont(); - setTextNodeData(node, 1, row, value, FONT, awtColor, BACKGROUND_COLOR); - setTextNodeData(node, 2, row, value2, result.getPending(), FONT, awtColor, BACKGROUND_COLOR); - setTextNodeData(node, 3, row, value3, FONT, awtColor, BACKGROUND_COLOR); + setTextNodeData(node, 1, row, value, font, awtColor, bgColor); + setTextNodeData(node, 2, row, value2, result.getPending(), font, awtColor, bgColor); + setTextNodeData(node, 3, row, value3, font, awtColor, bgColor); node.setEditable(1, row, false); node.setForceEventListening(2, row, true); @@ -309,7 +311,7 @@ public abstract class TextGridStyle extends StyleBase { node.setInputValidator(2, row, validator); node.setTranslator(translator); - + node.setRVI(2, row, rvi); postProcessNode(node, row); @@ -336,6 +338,14 @@ public abstract class TextGridStyle extends StyleBase { node.setPending(x, y, pending); } + protected Font getFont() { + return FONT; + } + + protected Color getBackgroundColor() { + return BACKGROUND_COLOR; + } + protected Alignment getAlignment(int column) { switch(column) { case 1: return Alignment.TRAILING; diff --git a/bundles/org.simantics.g2d.ontology/graph/G2D.pgraph b/bundles/org.simantics.g2d.ontology/graph/G2D.pgraph index fc58ade46..15506f545 100644 --- a/bundles/org.simantics.g2d.ontology/graph/G2D.pgraph +++ b/bundles/org.simantics.g2d.ontology/graph/G2D.pgraph @@ -261,3 +261,20 @@ G2D.HasSVGScript L0.Boolean + +G2D.fontProperty : L0.Template + @template %subject %predicate %family %size %style + %subject + %predicate _ : G2D.Font + G2D.HasFontFamily %family + G2D.HasFontSize %size + G2D.HasFontStyle %style + +G2D.font : L0.Template + @template %subject %family %size %style + %subject : G2D.Font + G2D.HasFontFamily %family + G2D.HasFontSize %size + G2D.HasFontStyle %style + + \ No newline at end of file diff --git a/bundles/org.simantics.scenegraph.profile/src/org/simantics/scenegraph/profile/ProfileUtils.java b/bundles/org.simantics.scenegraph.profile/src/org/simantics/scenegraph/profile/ProfileUtils.java index 88a69065b..92326248f 100644 --- a/bundles/org.simantics.scenegraph.profile/src/org/simantics/scenegraph/profile/ProfileUtils.java +++ b/bundles/org.simantics.scenegraph.profile/src/org/simantics/scenegraph/profile/ProfileUtils.java @@ -13,7 +13,7 @@ import org.simantics.db.common.request.PossibleIndexRoot; import org.simantics.db.exception.DatabaseException; import org.simantics.diagram.stubs.DiagramResource; import org.simantics.layer0.Layer0; -import org.simantics.scenegraph.profile.request.ProfileActiveEntryResources; +import org.simantics.simulation.ontology.SimulationResource; public class ProfileUtils { @@ -43,9 +43,9 @@ public class ProfileUtils { if(profile.equals(ref)) return state; } return null; - + } - + public static Resource claimProfileActivationState(WriteGraph graph, Resource runtimeDiagram, Resource runtimeProfile, Resource entry) throws DatabaseException { Layer0 L0 = Layer0.getInstance(graph); DiagramResource DIA = DiagramResource.getInstance(graph); @@ -66,6 +66,19 @@ public class ProfileUtils { graph.claim(indexRoot, L0.ConsistsOf, state); return state; } - - + + public static boolean isActive(ReadGraph graph, Resource runtimeDiagram, Resource profile, Resource entry) throws DatabaseException { + DiagramResource DIA = DiagramResource.getInstance(graph); + SimulationResource SIMU = SimulationResource.getInstance(graph); + if(graph.isInstanceOf(entry, DIA.ProfileEntry)) { + if(graph.isImmutable(profile)) { + Resource state = getPossibleProfileActivationState(graph, runtimeDiagram, profile); + if(state != null && graph.hasStatement(state, SIMU.IsActive, entry)) return true; + } else { + if(graph.hasStatement(profile, SIMU.IsActive, entry)) return true; + } + } + return false; + } + } -- 2.47.1