]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Better support for ontological profiles 16/916/2
authorAntti Villberg <antti.villberg@semantum.fi>
Tue, 5 Sep 2017 10:01:50 +0000 (13:01 +0300)
committerJani Simomaa <jani.simomaa@semantum.fi>
Tue, 5 Sep 2017 10:19:33 +0000 (13:19 +0300)
refs #7465

Change-Id: I53e4dcdd4c0ffde62cf231bbcbde325e585096f9

bundles/org.simantics.diagram.ontology/graph/DiagramProfiles.pgraph
bundles/org.simantics.diagram.profile/src/org/simantics/diagram/profile/function/All.java
bundles/org.simantics.diagram.profile/src/org/simantics/diagram/profile/view/ProfileCheckContributor.java
bundles/org.simantics.diagram/adapters.xml
bundles/org.simantics.diagram/src/org/simantics/diagram/profile/SCLTextGridStyle.java [new file with mode: 0644]
bundles/org.simantics.platform.ui.ontology/META-INF/MANIFEST.MF
bundles/org.simantics.platform.ui.ontology/graph/PlatformUI.pgraph
bundles/org.simantics.platform.ui.ontology/graph/scl/SCLMain.scl
bundles/org.simantics.scenegraph.profile/src/org/simantics/scenegraph/profile/ProfileUtils.java
bundles/org.simantics.scenegraph.profile/src/org/simantics/scenegraph/profile/request/ProfileActiveEntryResources.java
bundles/org.simantics.scenegraph.profile/src/org/simantics/scenegraph/profile/request/RuntimeProfileActiveEntryResources.java

index e1e48e03b4eac8f10b92b81c31b8ce93a204cd57..ef868a5043b604b8f94a566d07320ed35d05b7eb 100644 (file)
@@ -36,6 +36,12 @@ DIA.ProfileEntry.HasPriority <R L0.HasProperty : L0.FunctionalRelation
 
 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
@@ -54,6 +60,9 @@ DIA.ConstantStyle <T DIA.Style
 
 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
 
@@ -76,6 +85,9 @@ DIA.RuntimeDiagram
     
 DIA.Profile.defaultEnabled
   @L0.defTag
+
+DIA.ProfileActivationState <T L0.Entity
+  >-- DIA.ProfileActivationState.HasProfile --> DIA.Profile <R L0.IsRelatedTo
   
 DIA.ConfigurableProfile <T L0.Entity
 
index 0a3245b52268fb79e4c0a180a80dabae15dda206..51fed01b43436b9046e3f72dade1fcc8d6b7e322 100644 (file)
@@ -93,7 +93,7 @@ public class All {
        
        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);
                        
@@ -110,7 +110,7 @@ public class All {
                                        singleSelGroups.add(group);
                                }
                                }
-                               processRecursively(graph, runtimeProfile, child, checked);
+                               processRecursively(graph, runtimeDiagram, runtimeProfile, child, checked);
                        }
                        
                } else if(graph.isInstanceOf(entry, DIA.ProfileEntry)) {
@@ -120,23 +120,43 @@ public class All {
                                         //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) {
@@ -162,7 +182,7 @@ public class All {
                                
                                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);
                                
                            }
 
index 2bc9f320fc84b49dd911f906bd627a086be71758..544c394c52714373d7746b71d1e8b3f60d4667a8 100644 (file)
@@ -35,22 +35,22 @@ public class ProfileCheckContributor implements CheckedStateRule {
             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;
index 04e85be36d8e054741368037bee0ee367d4bdf98..c7e65bfadcc27c5111186253da84a7c14d702770 100644 (file)
                        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">
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
new file mode 100644 (file)
index 0000000..5850ffb
--- /dev/null
@@ -0,0 +1,88 @@
+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();
+       }
+
+}
index 9db6c459310767b392559abbbd1ccec14c50bc8d..ef76a51473a2583dd7614589f2727ac3e7044af3 100644 (file)
@@ -17,6 +17,7 @@ Require-Bundle: org.simantics.layer0,
  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
index 88f2d0fa7e92ed233d16f5c9e69bdd17a72186c9..35e306a89f68895fca60f728952c026d9005140a 100644 (file)
@@ -1,6 +1,7 @@
 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>
@@ -43,4 +44,11 @@ PlatformUI.StandardPropertiesTabContribution : SEL.TypedVariableTabContribution
     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
index 83bb80ea893ab44f8c906e10df0d51ad0d9c6cb4..44bf61267b7b9fbe0f6fc0b2eda98534f62dcab8 100644 (file)
@@ -80,4 +80,14 @@ modifyCodeHandler self input ctx = do
   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
index 989b7bb05d5aaff05d429a6e6d070842e73834c7..88a69065be58d358294c0238f263a755ad38aa45 100644 (file)
@@ -2,11 +2,18 @@ package org.simantics.scenegraph.profile;
 
 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 {
 
@@ -22,4 +29,43 @@ 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;
+       }
+       
+       
 }
index 93bab97c411f52001891cb51e8328802868a0233..641362a7a05fc5ee03cf300174f8ade01819a41a 100644 (file)
@@ -25,8 +25,8 @@ public class ProfileActiveEntryResources extends ProfileEntryResources {
 
     SimulationResource SIMU;
 
-    public ProfileActiveEntryResources(Resource profile, Resource entry) {
-        super(profile, entry);
+    public ProfileActiveEntryResources(Resource activationResource, Resource entry) {
+        super(activationResource, entry);
     }
 
     @Override
index 5c438533d8c84f818bb14172c478a12e64a60b6f..f59c1d71a0978addc151df7c0705e23543ffbeb2 100644 (file)
@@ -21,6 +21,7 @@ import org.simantics.db.common.NamedResource;
 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
@@ -53,7 +54,14 @@ public class RuntimeProfileActiveEntryResources extends ResourceRead<Collection<
         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;