<-- 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
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
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
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
<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
@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
\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
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
--- /dev/null
+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