DIA.GroupStyleProfileEntry <T DIA.ProfileEntry
+DIA.groupStyleProfileEntry : L0.Template
+ @template %subject %style %group
+ %subject : DIA.GroupStyleProfileEntry
+ DIA.ProfileEntry.HasStyle %style
+ DIA.ProfileEntry.HasGroup %group
+
DIA.Group <T L0.Entity
DIA.TypeGroup <T DIA.Group
DIA.ExpressionStyle <T DIA.Style
+DIA.SCLTextGridStyle <T DIA.Style
+ >-- DIA.SCLTextGridStyle.function ==> "Variable -> <ReadGraph> String" <R L0.HasProperty : L0.TotalFunction
+
DIA.SCLTextStyle <T DIA.Style
DIA.BasicExpressionTextStyle <T DIA.Style
DIA.Profile.defaultEnabled
@L0.defTag
+
+DIA.ProfileActivationState <T L0.Entity
+ >-- DIA.ProfileActivationState.HasProfile --> DIA.Profile <R L0.IsRelatedTo
DIA.ConfigurableProfile <T L0.Entity
return new FunctionImpl1<Object, Boolean>() {
- public void processRecursively(WriteGraph graph, Resource runtimeProfile, Resource entry, boolean checked) throws DatabaseException {
+ public void processRecursively(WriteGraph graph, Resource runtimeDiagram, Resource runtimeProfile, Resource entry, boolean checked) throws DatabaseException {
DiagramResource DIA = DiagramResource.getInstance(graph);
singleSelGroups.add(group);
}
}
- processRecursively(graph, runtimeProfile, child, checked);
+ processRecursively(graph, runtimeDiagram, runtimeProfile, child, checked);
}
} else if(graph.isInstanceOf(entry, DIA.ProfileEntry)) {
//enable selected item from single selection groups, disable the rest.
Collection<Resource> entries = graph.getObjects(group, DIA.ProfileEntry_HasGroup_Inverse);
for (Resource e : entries) {
- graph.denyStatement(runtimeProfile, SimulationResource.getInstance(graph).IsActive, e);
+ deactivate(graph, runtimeDiagram, runtimeProfile, e);
}
- graph.claim(runtimeProfile, SimulationResource.getInstance(graph).IsActive, null, entry);
+ activate(graph, runtimeDiagram, runtimeProfile, entry);
} else {
- graph.denyStatement(runtimeProfile, SimulationResource.getInstance(graph).IsActive, entry);
+ deactivate(graph, runtimeDiagram, runtimeProfile, entry);
}
} else {
if(checked) {
- graph.claim(runtimeProfile, SimulationResource.getInstance(graph).IsActive, null, entry);
+ activate(graph, runtimeDiagram, runtimeProfile, entry);
} else {
- graph.denyStatement(runtimeProfile, SimulationResource.getInstance(graph).IsActive, entry);
+ deactivate(graph, runtimeDiagram, runtimeProfile, entry);
}
}
}
}
+
+ private void activate(WriteGraph graph, Resource runtimeDiagram, Resource runtimeProfile, Resource entry) throws DatabaseException {
+ if(graph.isImmutable(runtimeProfile)) {
+ Resource activationState = ProfileUtils.claimProfileActivationState(graph, runtimeDiagram, runtimeProfile, entry);
+ if(activationState != null)
+ graph.claim(activationState, SimulationResource.getInstance(graph).IsActive, null, entry);
+ } else {
+ graph.claim(runtimeProfile, SimulationResource.getInstance(graph).IsActive, null, entry);
+ }
+ }
+
+ private void deactivate(WriteGraph graph, Resource runtimeDiagram, Resource runtimeProfile, Resource entry) throws DatabaseException {
+ if(graph.isImmutable(runtimeProfile)) {
+ Resource activationState = ProfileUtils.claimProfileActivationState(graph, runtimeDiagram, runtimeProfile, entry);
+ if(activationState != null)
+ graph.denyStatement(activationState, SimulationResource.getInstance(graph).IsActive, entry);
+ } else {
+ graph.denyStatement(runtimeProfile, SimulationResource.getInstance(graph).IsActive, entry);
+ }
+ }
@Override
public Boolean apply(Object _event) {
DiagramResource DIA = DiagramResource.getInstance(graph);
Resource runtimeProfile = graph.getPossibleObject(runtimeDiagram, DIA.RuntimeDiagram_HasRuntimeProfile);
- processRecursively(graph, runtimeProfile, entry.getSecond(), checked);
+ processRecursively(graph, runtimeDiagram, runtimeProfile, entry.getSecond(), checked);
}
throws DatabaseException {
ResourcePair entry = (ResourcePair)parent;
+ Resource activeProfile = entry.getFirst();
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);
- Collection<Resource> activeEntries = graph.syncRequest( new ProfileActiveEntryResources(entry.getFirst(), list) );
+ Collection<Resource> activeEntries = graph.syncRequest( new ProfileActiveEntryResources(activeProfile, list) );
if (activeEntries.isEmpty()) {
return CheckedState.NOT_CHECKED;
} else {
- Collection<Resource> entries = graph.syncRequest( new ProfileEntryResources(entry.getFirst(), list) );
+ Collection<Resource> 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(entry.getFirst(), SIMU.IsActive, entry.getSecond())) return CheckedState.CHECKED;
+ if(graph.hasStatement(activeProfile, SIMU.IsActive, entry.getSecond())) return CheckedState.CHECKED;
}
return CheckedState.NOT_CHECKED;
class="org.simantics.diagram.adapter.ExpressionStyle">
<this />
</type>
+ <type
+ uri="http://www.simantics.org/Diagram-0.0/SCLTextGridStyle"
+ class="org.simantics.diagram.profile.SCLTextGridStyle">
+ <this />
+ </type>
</target>
<target interface="org.simantics.scenegraph.profile.Group">
--- /dev/null
+package org.simantics.diagram.profile;
+
+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;
+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.stubs.DiagramResource;
+import org.simantics.diagram.synchronization.graph.DiagramGraphUtil;
+import org.simantics.modeling.ModelingResources;
+import org.simantics.scl.runtime.function.Function1;
+import org.simantics.utils.datastructures.Pair;
+
+/**
+ * @author Antti Villberg
+ */
+public class SCLTextGridStyle extends TextGridStyle {
+
+ final Resource style;
+
+ public SCLTextGridStyle(Resource style) {
+ this.style = style;
+ }
+
+ @Override
+ public Resource getPropertyRelation(ReadGraph graph, Resource module) {
+ throw new Error("Fix this");
+ }
+
+ @Override
+ protected Object getIdentity(Resource entry) {
+ return new Pair<Resource, Resource>(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);
+ ModelingResources MOD = ModelingResources.getInstance(graph);
+
+ String variableURI = graph.getPossibleRelatedValue(runtimeDiagram, DIA.RuntimeDiagram_HasVariable, Bindings.STRING);
+ Variable activeVariable = org.simantics.db.layer0.variable.Variables.getPossibleVariable(graph, variableURI);
+ if (activeVariable == null)
+ return null;
+
+ Resource module = graph.getPossibleObject(element, MOD.ElementToComponent);
+ if (module == null)
+ return null;
+
+ Variable moduleVariable = activeVariable.browsePossible(graph, module);
+ if (moduleVariable == null)
+ return null;
+
+ Variable styleVariable = Variables.getVariable(graph, style);
+ Function1<Variable,String> function = styleVariable.getPossiblePropertyValue(graph, "function");
+ String 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);
+
+ }
+
+ @Override
+ public String getNodeName() {
+ return "" + style.getResourceId();
+ }
+
+}
org.simantics.annotation.ontology;bundle-version="1.0.0",
org.simantics.modeling.template2d.ontology;bundle-version="1.0.0",
org.simantics.spreadsheet.ontology;bundle-version="1.2.0",
- org.simantics.selectionview.ui.ontology;bundle-version="1.1.0"
+ org.simantics.selectionview.ui.ontology;bundle-version="1.1.0",
+ org.simantics.diagram.ontology;bundle-version="2.2.0"
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Export-Package: org.simantics.platform.ui
L0 = <http://www.simantics.org/Layer0-1.1>
PROJECT = <http://www.simantics.org/Project-1.2>
MOD = <http://www.simantics.org/Modeling-1.2>
+DIA = <http://www.simantics.org/Diagram-2.2>
STR = <http://www.simantics.org/Structural-1.2>
SEL = <http://www.simantics.org/SelectionView-1.2>
SEL_UI = <http://www.simantics.org/SelectionViewUI-1.1>
SEL.TypedVariableTabContribution.HasType L0.Entity
SEL.VariableTabContribution.HasView SEL_UI.StandardProperties
SEL.VariableTabContribution.HasPriority -1
- L0.HasLabel "Properties"
\ No newline at end of file
+ @MOD.scl SEL.VariableTabContribution.transformation "standardPropertiesElementTransformation" "Variable -> <ReadGraph> Variable"
+ L0.HasLabel "Properties"
+
+PlatformUI.StandardElementProperties : SEL.TypedVariableTabContribution
+ SEL.TypedVariableTabContribution.HasType DIA.Element
+ L0.HasLabel "Element Properties"
+ SEL.VariableTabContribution.HasPriority -2
+ SEL.VariableTabContribution.HasView SEL_UI.StandardProperties
variable = currentRangeExpressionVariable self input
setExpression variable val
Nothing
+
+standardPropertiesElementTransformation :: Variable -> <ReadGraph> Variable
+standardPropertiesElementTransformation var = do
+ match getPossibleType var with
+ Nothing -> var
+ Just resourceType -> if isInheritedFrom resourceType DIA.Element then do
+ match possibleObject (represents var) MOD.ElementToComponent with
+ Nothing -> var
+ Just component -> resourceVariable component
+ else var
\ No newline at end of file
import java.util.Collections;
import java.util.List;
+import java.util.UUID;
+import org.simantics.databoard.Bindings;
import org.simantics.db.ReadGraph;
import org.simantics.db.Resource;
+import org.simantics.db.WriteGraph;
+import org.simantics.db.common.request.ObjectsWithType;
+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;
public class ProfileUtils {
return graph.getRelatedValue2(entries, DIA.Profile_children, entries);
}
+ public static Resource getPossibleProfileActivationState(ReadGraph graph, Resource runtimeDiagram, Resource profile) throws DatabaseException {
+
+ Layer0 L0 = Layer0.getInstance(graph);
+ DiagramResource DIA = DiagramResource.getInstance(graph);
+ Resource conf = graph.getPossibleObject(runtimeDiagram, DIA.RuntimeDiagram_HasConfiguration);
+ if(conf == null) return null;
+ Resource indexRoot = graph.syncRequest(new PossibleIndexRoot(conf));
+ if(indexRoot == null) return null;
+ // Find existing state
+ for(Resource state : graph.syncRequest(new ObjectsWithType(indexRoot, L0.ConsistsOf, DIA.ProfileActivationState))) {
+ Resource ref = graph.getPossibleObject(state, DIA.ProfileActivationState_HasProfile);
+ 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);
+ Resource conf = graph.getPossibleObject(runtimeDiagram, DIA.RuntimeDiagram_HasConfiguration);
+ if(conf == null) return null;
+ Resource indexRoot = graph.syncRequest(new PossibleIndexRoot(conf));
+ if(indexRoot == null) return null;
+ // Find existing state
+ for(Resource state : graph.syncRequest(new ObjectsWithType(indexRoot, L0.ConsistsOf, DIA.ProfileActivationState))) {
+ Resource profile = graph.getPossibleObject(state, DIA.ProfileActivationState_HasProfile);
+ if(profile.equals(runtimeProfile)) return state;
+ }
+ // Create new state
+ Resource state = graph.newResource();
+ graph.claim(state, L0.InstanceOf, DIA.ProfileActivationState);
+ graph.claimLiteral(state, L0.HasName, L0.String, UUID.randomUUID().toString(), Bindings.STRING);
+ graph.claim(state, DIA.ProfileActivationState_HasProfile, runtimeProfile);
+ graph.claim(indexRoot, L0.ConsistsOf, state);
+ return state;
+ }
+
+
}
SimulationResource SIMU;
- public ProfileActiveEntryResources(Resource profile, Resource entry) {
- super(profile, entry);
+ public ProfileActiveEntryResources(Resource activationResource, Resource entry) {
+ super(activationResource, entry);
}
@Override
import org.simantics.db.common.request.ResourceRead;
import org.simantics.db.exception.DatabaseException;
import org.simantics.diagram.stubs.DiagramResource;
+import org.simantics.scenegraph.profile.ProfileUtils;
/**
* @author Antti Villberg
if (rootEntries == null)
return result;
- result.addAll(graph.syncRequest(new ProfileActiveEntryResources(activeProfile, rootEntries)));
+ if(graph.isImmutable(activeProfile)) {
+ Resource activationState = ProfileUtils.getPossibleProfileActivationState(graph, resource, activeProfile);
+ if(activationState != null) {
+ result.addAll(graph.syncRequest(new ProfileActiveEntryResources(activationState, rootEntries)));
+ }
+ } else {
+ result.addAll(graph.syncRequest(new ProfileActiveEntryResources(activeProfile, rootEntries)));
+ }
return result;