]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Sync git svn branch with SVN repository r33203.
authorTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Fri, 16 Sep 2016 10:45:33 +0000 (13:45 +0300)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Fri, 16 Sep 2016 10:47:04 +0000 (13:47 +0300)
refs #6695

bundles/org.simantics.modeling.ontology/graph/Typicals.pgraph
bundles/org.simantics.modeling.ontology/src/org/simantics/modeling/ModelingResources.java
bundles/org.simantics.modeling/adapters.xml
bundles/org.simantics.modeling/src/org/simantics/modeling/typicals/AvailableSynchronizationRules.java
bundles/org.simantics.modeling/src/org/simantics/modeling/typicals/SyncTypicalTemplatesToInstances.java
bundles/org.simantics.modeling/src/org/simantics/modeling/typicals/rules/PageSettingsTypicalRule.java [new file with mode: 0644]

index 0250167df7befb1d27e5db72eee32c3acedb8928..2c332450c98fe75c1881b571d951ee3384af9431 100644 (file)
@@ -52,6 +52,9 @@ MOD.HasTypicalSynchronizationRule <R L0.IsRelatedTo
     <-- DIA.Element\r
     --> MOD.TypicalSynchronizationRule\r
 \r
+MOD.PageSettingsTypicalRule : MOD.TypicalSynchronizationRule\r
+    L0.HasLabel "Diagram Page Settings"\r
+\r
 //##########################################################################\r
 //## MOD.StructuralModel additions\r
 //##########################################################################\r
index 5d42efbabe6a680b7ffcbf67107cdeeda2c30edd..0c4febf8458bd799aa6421d11bc562253601e232 100644 (file)
@@ -332,6 +332,7 @@ public class ModelingResources {
     public final Resource OntologyDependencies;\r
     public final Resource Operations;\r
     public final Resource Operations_NavigateToTarget;\r
+    public final Resource PageSettingsTypicalRule;\r
     public final Resource PartialIC;\r
     public final Resource PlainModelBrowser;\r
     public final Resource Predicates;\r
@@ -755,6 +756,7 @@ public class ModelingResources {
         public static final String OntologyDependencies = "http://www.simantics.org/Modeling-1.2/OntologyDependencies";\r
         public static final String Operations = "http://www.simantics.org/Modeling-1.2/Operations";\r
         public static final String Operations_NavigateToTarget = "http://www.simantics.org/Modeling-1.2/Operations/NavigateToTarget";\r
+        public static final String PageSettingsTypicalRule = "http://www.simantics.org/Modeling-1.2/PageSettingsTypicalRule";\r
         public static final String PartialIC = "http://www.simantics.org/Modeling-1.2/PartialIC";\r
         public static final String PlainModelBrowser = "http://www.simantics.org/Modeling-1.2/PlainModelBrowser";\r
         public static final String Predicates = "http://www.simantics.org/Modeling-1.2/Predicates";\r
@@ -1188,6 +1190,7 @@ public class ModelingResources {
         OntologyDependencies = getResourceOrNull(graph, URIs.OntologyDependencies);\r
         Operations = getResourceOrNull(graph, URIs.Operations);\r
         Operations_NavigateToTarget = getResourceOrNull(graph, URIs.Operations_NavigateToTarget);\r
+        PageSettingsTypicalRule = getResourceOrNull(graph, URIs.PageSettingsTypicalRule);\r
         PartialIC = getResourceOrNull(graph, URIs.PartialIC);\r
         PlainModelBrowser = getResourceOrNull(graph, URIs.PlainModelBrowser);\r
         Predicates = getResourceOrNull(graph, URIs.Predicates);\r
index 9703ae7234b7558f3e309a094d56b648ce37683a..892fdbfcf95eaf7e333e865edb9c2d62198c57dd 100644 (file)
@@ -54,5 +54,5 @@
                        <single uri="http://www.simantics.org/Modeling-0.0/HasBaseRules"\r
                                to="org.simantics.structural2.modelingRules.IModelingRules" />\r
                </type>\r
-       </target>\r\r     <target interface="org.simantics.db.layer0.adapter.Remover">\r           <type uri="http://www.simantics.org/Structural-0.0/Component"\r                  class="org.simantics.db.layer0.adapter.impl.RelatedObjectRemover">\r                     <graph />\r                      <this />\r                       <string>http://www.simantics.org/Modeling-0.0/ComponentToElement</string>\r                      <string>http://www.simantics.org/Modeling-0.0/HasParentComponent/Inverse</string>\r              </type>\r                <type uri="http://www.simantics.org/Diagram-0.0/Element" class="org.simantics.modeling.adapters.ElementRemover">\r                       <this />\r               </type>\r                <type uri="http://www.simantics.org/Diagram-0.0/Monitor" class="org.simantics.modeling.adapters.MonitorRemover">\r                       <this />\r               </type>\r                <type uri="http://www.simantics.org/Charts-0.0/Chart"\r                  class="org.simantics.db.layer0.adapter.impl.ConsistsOfRemover">\r                        <this />\r               </type>\r                <type uri="http://www.simantics.org/Simulation-0.0/Run" \r                     class="org.simantics.modeling.adapters.RunRemover">\r                      <this />\r               </type>\r                <type uri="http://www.simantics.org/Diagram-0.0/Flag"\r                  class="org.simantics.modeling.adapters.FlagRemover">\r                   <this />\r               </type>\r                <type uri="http://www.simantics.org/Structural-0.0/ConnectionRelation"\r                 class="org.simantics.modeling.adapters.ConnectionRelationRemover">\r                     <this />\r               </type>\r                <type uri="http://www.simantics.org/Diagram-0.0/Terminal"\r                      class="org.simantics.modeling.adapters.TerminalRemover">\r                       <this />\r               </type>\r                <type uri="http://www.simantics.org/Modeling-0.0/ReferenceElement"\r                     class="org.simantics.modeling.adapters.ReferenceElementRemover">\r                       <this />\r               </type>\r        </target>\r      \r       <target interface="org.simantics.scl.runtime.function.Function">\r        <resource uri="http://www.simantics.org/Simulation-0.0/ActiveExperiment"\r            class="org.simantics.modeling.adapters.ActiveExperiment">\r        </resource>\r    </target>\r\r    <target interface="org.simantics.db.layer0.adapter.ActionFactory">\r        <type uri="http://www.simantics.org/Modeling-0.0/NewComposite"\r            class="org.simantics.modeling.adapters.NewCompositeActionFactory">\r            <single uri="http://www.simantics.org/Modeling-0.0/NewComposite/HasCompositeType" />\r            <single uri="http://www.simantics.org/Modeling-0.0/NewComposite/HasDefaultName"\r                    to="java.lang.String" />\r        </type>\r    </target>\r    \r    <target interface="org.simantics.db.layer0.adapter.ActionFactory">\r        <type uri="http://www.simantics.org/Modeling-0.0/ExportModel"\r            class="org.simantics.modeling.adapters.ExportModelActionFactory">\r            <single uri="http://www.simantics.org/Modeling-0.0/ExportModel/extension"\r                    to="java.lang.String" />\r            <single uri="http://www.simantics.org/Modeling-0.0/ExportModel/format"\r                    to="java.lang.String" />\r        </type>\r        <type uri="http://www.simantics.org/Modeling-0.0/SCLAction"\r            class="org.simantics.modeling.SCLAction">\r            <graph/>\r            <this/>\r        </type>\r          <resource uri="http://www.simantics.org/Modeling-0.0/ModelingActionContext/Actions/Help"\r                       class="org.simantics.modeling.actions.Help" />\r    </target>\r    \r    <target interface="org.simantics.browsing.ui.model.children.ChildRule">\r        <type uri="http://www.simantics.org/Modeling-0.0/SCLChildRule"\r            class="org.simantics.modeling.adapters.SCLChildRule">\r                 <graph />\r                      <this />\r        </type>\r    </target>    \r\r    <target interface="org.simantics.browsing.ui.model.visuals.VisualsRule">\r        <type uri="http://www.simantics.org/Modeling-0.0/SCLLabelRule"\r            class="org.simantics.modeling.adapters.SCLLabelRule">\r                      <graph />\r                      <this />\r        </type>\r    </target>    \r\r    <target interface="org.simantics.browsing.ui.model.tests.Test">\r        <type uri="http://www.simantics.org/Modeling-0.0/SCLTest"\r            class="org.simantics.modeling.adapters.SCLTest">\r                 <graph />\r                      <this />\r        </type>\r    </target>    \r\r    <target interface="org.simantics.db.layer0.adapter.StringModifierFactory">\r             <type\r                  uri="http://www.simantics.org/Structural-0.0/ConnectionRelation"\r                       class="org.simantics.modeling.adapters.ConnectionRelationStringModifierFactory">\r                       <this />\r               </type>\r        </target>\r\r\r    <target interface="org.simantics.db.layer0.variable.VariableBuilder">\r          <type uri="http://www.simantics.org/Modeling-1.2/SCLCommandSession" class="org.simantics.modeling.scl.SCLVariableBuilder" />\r   </target>\r\r     <target interface="org.simantics.db.layer0.migration.MigrationStep">\r           <resource uri="http://www.simantics.org/Modeling-1.2/Migration/attachCreationInformationStep"\r                  class="org.simantics.modeling.migration.AttachCreationInformationStep"\r                 constructor="get">\r             </resource>\r            <resource uri="http://www.simantics.org/Modeling-1.2/Migration/guidCreationStep"\r                       class="org.simantics.modeling.migration.GuidCreationStep"\r                      constructor="get">\r             </resource>\r            <resource uri="http://www.simantics.org/Modeling-1.2/Migration/layerCleanupMigrationStep"\r                      class="org.simantics.modeling.migration.LayerCleanupMigrationStep">\r            </resource>\r            <resource uri="http://www.simantics.org/Modeling-1.2/Migration/documentCleanupMigrationStep"\r                   class="org.simantics.modeling.migration.DocumentCleanupMigrationStep">\r         </resource>\r    </target>\r\r
+       </target>\r\r     <target interface="org.simantics.db.layer0.adapter.Remover">\r           <type uri="http://www.simantics.org/Structural-0.0/Component"\r                  class="org.simantics.db.layer0.adapter.impl.RelatedObjectRemover">\r                     <graph />\r                      <this />\r                       <string>http://www.simantics.org/Modeling-0.0/ComponentToElement</string>\r                      <string>http://www.simantics.org/Modeling-0.0/HasParentComponent/Inverse</string>\r              </type>\r                <type uri="http://www.simantics.org/Diagram-0.0/Element" class="org.simantics.modeling.adapters.ElementRemover">\r                       <this />\r               </type>\r                <type uri="http://www.simantics.org/Diagram-0.0/Monitor" class="org.simantics.modeling.adapters.MonitorRemover">\r                       <this />\r               </type>\r                <type uri="http://www.simantics.org/Charts-0.0/Chart"\r                  class="org.simantics.db.layer0.adapter.impl.ConsistsOfRemover">\r                        <this />\r               </type>\r                <type uri="http://www.simantics.org/Simulation-0.0/Run" \r                     class="org.simantics.modeling.adapters.RunRemover">\r                      <this />\r               </type>\r                <type uri="http://www.simantics.org/Diagram-0.0/Flag"\r                  class="org.simantics.modeling.adapters.FlagRemover">\r                   <this />\r               </type>\r                <type uri="http://www.simantics.org/Structural-0.0/ConnectionRelation"\r                 class="org.simantics.modeling.adapters.ConnectionRelationRemover">\r                     <this />\r               </type>\r                <type uri="http://www.simantics.org/Diagram-0.0/Terminal"\r                      class="org.simantics.modeling.adapters.TerminalRemover">\r                       <this />\r               </type>\r                <type uri="http://www.simantics.org/Modeling-0.0/ReferenceElement"\r                     class="org.simantics.modeling.adapters.ReferenceElementRemover">\r                       <this />\r               </type>\r        </target>\r      \r       <target interface="org.simantics.scl.runtime.function.Function">\r        <resource uri="http://www.simantics.org/Simulation-0.0/ActiveExperiment"\r            class="org.simantics.modeling.adapters.ActiveExperiment">\r        </resource>\r    </target>\r\r    <target interface="org.simantics.db.layer0.adapter.ActionFactory">\r        <type uri="http://www.simantics.org/Modeling-0.0/NewComposite"\r            class="org.simantics.modeling.adapters.NewCompositeActionFactory">\r            <single uri="http://www.simantics.org/Modeling-0.0/NewComposite/HasCompositeType" />\r            <single uri="http://www.simantics.org/Modeling-0.0/NewComposite/HasDefaultName"\r                    to="java.lang.String" />\r        </type>\r    </target>\r    \r    <target interface="org.simantics.db.layer0.adapter.ActionFactory">\r        <type uri="http://www.simantics.org/Modeling-0.0/ExportModel"\r            class="org.simantics.modeling.adapters.ExportModelActionFactory">\r            <single uri="http://www.simantics.org/Modeling-0.0/ExportModel/extension"\r                    to="java.lang.String" />\r            <single uri="http://www.simantics.org/Modeling-0.0/ExportModel/format"\r                    to="java.lang.String" />\r        </type>\r        <type uri="http://www.simantics.org/Modeling-0.0/SCLAction"\r            class="org.simantics.modeling.SCLAction">\r            <graph/>\r            <this/>\r        </type>\r          <resource uri="http://www.simantics.org/Modeling-0.0/ModelingActionContext/Actions/Help"\r                       class="org.simantics.modeling.actions.Help" />\r    </target>\r    \r    <target interface="org.simantics.browsing.ui.model.children.ChildRule">\r        <type uri="http://www.simantics.org/Modeling-0.0/SCLChildRule"\r            class="org.simantics.modeling.adapters.SCLChildRule">\r                 <graph />\r                      <this />\r        </type>\r    </target>    \r\r    <target interface="org.simantics.browsing.ui.model.visuals.VisualsRule">\r        <type uri="http://www.simantics.org/Modeling-0.0/SCLLabelRule"\r            class="org.simantics.modeling.adapters.SCLLabelRule">\r                      <graph />\r                      <this />\r        </type>\r    </target>    \r\r    <target interface="org.simantics.browsing.ui.model.tests.Test">\r        <type uri="http://www.simantics.org/Modeling-0.0/SCLTest"\r            class="org.simantics.modeling.adapters.SCLTest">\r                 <graph />\r                      <this />\r        </type>\r    </target>    \r\r    <target interface="org.simantics.db.layer0.adapter.StringModifierFactory">\r             <type\r                  uri="http://www.simantics.org/Structural-0.0/ConnectionRelation"\r                       class="org.simantics.modeling.adapters.ConnectionRelationStringModifierFactory">\r                       <this />\r               </type>\r        </target>\r\r\r    <target interface="org.simantics.db.layer0.variable.VariableBuilder">\r          <type uri="http://www.simantics.org/Modeling-1.2/SCLCommandSession" class="org.simantics.modeling.scl.SCLVariableBuilder" />\r   </target>\r\r     <target interface="org.simantics.db.layer0.migration.MigrationStep">\r           <resource uri="http://www.simantics.org/Modeling-1.2/Migration/attachCreationInformationStep"\r                  class="org.simantics.modeling.migration.AttachCreationInformationStep"\r                 constructor="get">\r             </resource>\r            <resource uri="http://www.simantics.org/Modeling-1.2/Migration/guidCreationStep"\r                       class="org.simantics.modeling.migration.GuidCreationStep"\r                      constructor="get">\r             </resource>\r            <resource uri="http://www.simantics.org/Modeling-1.2/Migration/layerCleanupMigrationStep"\r                      class="org.simantics.modeling.migration.LayerCleanupMigrationStep">\r            </resource>\r            <resource uri="http://www.simantics.org/Modeling-1.2/Migration/documentCleanupMigrationStep"\r                   class="org.simantics.modeling.migration.DocumentCleanupMigrationStep">\r         </resource>\r    </target>\r\r     <target interface="org.simantics.modeling.typicals.ITypicalSynchronizationRule">\r               <baseType\r                      uri="http://www.simantics.org/Modeling-0.0/TypicalSynchronizationRule" />\r              <resource\r                      uri="http://www.simantics.org/Modeling-0.0/PageSettingsTypicalRule"\r                    class="org.simantics.modeling.typicals.rules.PageSettingsTypicalRule"\r                  constructor="get" />\r   </target>\r\r
 </adapters>
\ No newline at end of file
index 07c8bc2aefbb65eb374a2b2b90f905b9e3dcfbd3..a396d3399ff608ca04a8a2904bdf3e3f58254138 100644 (file)
@@ -36,27 +36,34 @@ public class AvailableSynchronizationRules extends ResourceRead<Collection<Named
        @Override\r
        public Collection<NamedResource> perform(ReadGraph graph)\r
                        throws DatabaseException {\r
-               \r
+\r
                Layer0 L0 = Layer0.getInstance(graph);\r
                DiagramResource DIA = DiagramResource.getInstance(graph);\r
-               ModelingResources MOD = ModelingResources.getInstance(graph);\r
-               \r
+\r
                Set<Resource> rules = new HashSet<Resource>();\r
-               for(Resource element : graph.syncRequest(new ObjectsWithType(resource, L0.ConsistsOf, DIA.Element))) {\r
-                       for (Resource rule : graph.getObjects(element, MOD.HasTypicalSynchronizationRule)) {\r
-                               ITypicalSynchronizationRule r = graph.getPossibleAdapter(rule, ITypicalSynchronizationRule.class);\r
-                               if (r != null) rules.add(rule);\r
-                       }\r
+               tryAddRules(graph, resource, rules);\r
+               for (Resource element : graph.syncRequest(new ObjectsWithType(resource, L0.ConsistsOf, DIA.Element))) {\r
+                       tryAddRules(graph, element, rules);\r
                }\r
-               \r
-               Collection<NamedResource> result = new ArrayList<NamedResource>();\r
+\r
+               Collection<NamedResource> result = new ArrayList<>();\r
                for(Resource rule : rules) {\r
                        String name = NameUtils.getSafeLabel(graph, rule);\r
                        result.add(new NamedResource(name, rule));\r
                }\r
-               \r
+\r
                return result;\r
-               \r
+       }\r
+\r
+       private int tryAddRules(ReadGraph graph, Resource r, Set<Resource> rules) throws DatabaseException {\r
+               ModelingResources MOD = ModelingResources.getInstance(graph);\r
+               int count = 0;\r
+               for (Resource ruleResource : graph.getObjects(r, MOD.HasTypicalSynchronizationRule)) {\r
+                       ITypicalSynchronizationRule rule = graph.getPossibleAdapter(ruleResource, ITypicalSynchronizationRule.class);\r
+                       if (rule != null && rules.add(ruleResource))\r
+                               ++count;\r
+               }\r
+               return count;\r
        }\r
 \r
 }
\ No newline at end of file
index 56d61c86845b3a4941e8da58b088f786aac9dcb6..55f5aef3dabf1869b305b5376d14633abbcf9850 100644 (file)
@@ -545,6 +545,7 @@ public class SyncTypicalTemplatesToInstances extends WriteRequest {
         \r
         // Perform changes\r
         boolean changed = false;\r
+        changed |= synchronizeDiagramChanges(graph, info, template, instance);\r
         changed |= removeElements(graph, info, instanceElementsRemovedFromTemplate);\r
         changed |= addMissingElements(graph, info, template, instance, templateElementsAddedToTemplate);\r
         changed |= synchronizeChangedElements(graph, info, template, instance, changedTemplateElements, templateElementsAddedToTemplate, changedElementsByDiagram == ALL);\r
@@ -553,6 +554,35 @@ public class SyncTypicalTemplatesToInstances extends WriteRequest {
             metadata.addTypical(instance);\r
     }\r
 \r
+    /**\r
+     * Synchronize any configurable aspects of the typical diagram instance itself.\r
+     * Every rule executed here comes from the ontology, nothing is fixed. \r
+     * \r
+     * @param graph\r
+     * @param typicalInfo\r
+     * @param template\r
+     * @param instance\r
+     * @return if any changes were made. \r
+     * @throws DatabaseException\r
+     */\r
+    private boolean synchronizeDiagramChanges(\r
+            WriteGraph graph,\r
+            TypicalInfo typicalInfo,\r
+            Resource template,\r
+            Resource instance)\r
+                    throws DatabaseException\r
+    {\r
+        boolean changed = false;\r
+        for (Resource rule : graph.getObjects(template, MOD.HasTypicalSynchronizationRule)) {\r
+            if (selectedRules != null && !selectedRules.contains(rule))\r
+                continue;\r
+            ITypicalSynchronizationRule r = graph.getPossibleAdapter(rule, ITypicalSynchronizationRule.class);\r
+            if (r != null)\r
+                changed |= r.synchronize(graph, template, instance, typicalInfo);\r
+        }\r
+        return changed;\r
+    }\r
+\r
     /**\r
      * Add elements from template that do not yet exist in the instance.\r
      * \r
diff --git a/bundles/org.simantics.modeling/src/org/simantics/modeling/typicals/rules/PageSettingsTypicalRule.java b/bundles/org.simantics.modeling/src/org/simantics/modeling/typicals/rules/PageSettingsTypicalRule.java
new file mode 100644 (file)
index 0000000..cf6c60f
--- /dev/null
@@ -0,0 +1,41 @@
+package org.simantics.modeling.typicals.rules;\r
+\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.diagram.query.DiagramRequests;\r
+import org.simantics.diagram.synchronization.graph.DiagramGraphUtil;\r
+import org.simantics.g2d.page.DiagramDesc;\r
+import org.simantics.modeling.typicals.ITypicalSynchronizationRule;\r
+import org.simantics.modeling.typicals.TypicalInfo;\r
+\r
+/**\r
+ * @author Tuukka Lehtonen\r
+ * @since 1.22.2, 1.25.0\r
+ */\r
+public enum PageSettingsTypicalRule implements ITypicalSynchronizationRule {\r
+\r
+       INSTANCE;\r
+\r
+       public static PageSettingsTypicalRule get() {\r
+               return INSTANCE;\r
+       }\r
+\r
+       @Override\r
+       public boolean synchronize(WriteGraph graph, Resource template, Resource instance, TypicalInfo info) throws DatabaseException {\r
+               DiagramDesc mdesc = graph.syncRequest(DiagramRequests.getDiagramDesc(template));\r
+               DiagramDesc idesc = graph.syncRequest(DiagramRequests.getDiagramDesc(instance));\r
+               if (mdesc.equals(idesc))\r
+                       return false;\r
+\r
+               DiagramGraphUtil.setDiagramDesc(graph, instance, mdesc);\r
+               info.messageLog.add("\t\tset diagram page settings:"\r
+                               + "\n\t\t\tshow page borders: " + mdesc.isPageBordersVisible()\r
+                               + "\n\t\t\tshow margins:      " + mdesc.isMarginsVisible()\r
+                               + "\n\t\t\tgrid size:         " + mdesc.getGridSize()\r
+                               + "\n\t\t\tpage settings:     " + mdesc.getPageDesc()\r
+                               + "\n");\r
+               return true;\r
+       }\r
+\r
+}\r