From fd452722e97db9cf876f4f03a9e44fe750625a92 Mon Sep 17 00:00:00 2001 From: Tuukka Lehtonen Date: Fri, 16 Sep 2016 13:45:33 +0300 Subject: [PATCH] Sync git svn branch with SVN repository r33203. refs #6695 --- .../graph/Typicals.pgraph | 3 ++ .../simantics/modeling/ModelingResources.java | 3 ++ bundles/org.simantics.modeling/adapters.xml | 2 +- .../AvailableSynchronizationRules.java | 31 ++++++++------ .../SyncTypicalTemplatesToInstances.java | 30 ++++++++++++++ .../rules/PageSettingsTypicalRule.java | 41 +++++++++++++++++++ 6 files changed, 97 insertions(+), 13 deletions(-) create mode 100644 bundles/org.simantics.modeling/src/org/simantics/modeling/typicals/rules/PageSettingsTypicalRule.java diff --git a/bundles/org.simantics.modeling.ontology/graph/Typicals.pgraph b/bundles/org.simantics.modeling.ontology/graph/Typicals.pgraph index 0250167df..2c332450c 100644 --- a/bundles/org.simantics.modeling.ontology/graph/Typicals.pgraph +++ b/bundles/org.simantics.modeling.ontology/graph/Typicals.pgraph @@ -52,6 +52,9 @@ MOD.HasTypicalSynchronizationRule MOD.TypicalSynchronizationRule +MOD.PageSettingsTypicalRule : MOD.TypicalSynchronizationRule + L0.HasLabel "Diagram Page Settings" + //########################################################################## //## MOD.StructuralModel additions //########################################################################## diff --git a/bundles/org.simantics.modeling.ontology/src/org/simantics/modeling/ModelingResources.java b/bundles/org.simantics.modeling.ontology/src/org/simantics/modeling/ModelingResources.java index 5d42efbab..0c4febf84 100644 --- a/bundles/org.simantics.modeling.ontology/src/org/simantics/modeling/ModelingResources.java +++ b/bundles/org.simantics.modeling.ontology/src/org/simantics/modeling/ModelingResources.java @@ -332,6 +332,7 @@ public class ModelingResources { public final Resource OntologyDependencies; public final Resource Operations; public final Resource Operations_NavigateToTarget; + public final Resource PageSettingsTypicalRule; public final Resource PartialIC; public final Resource PlainModelBrowser; public final Resource Predicates; @@ -755,6 +756,7 @@ public class ModelingResources { public static final String OntologyDependencies = "http://www.simantics.org/Modeling-1.2/OntologyDependencies"; public static final String Operations = "http://www.simantics.org/Modeling-1.2/Operations"; public static final String Operations_NavigateToTarget = "http://www.simantics.org/Modeling-1.2/Operations/NavigateToTarget"; + public static final String PageSettingsTypicalRule = "http://www.simantics.org/Modeling-1.2/PageSettingsTypicalRule"; public static final String PartialIC = "http://www.simantics.org/Modeling-1.2/PartialIC"; public static final String PlainModelBrowser = "http://www.simantics.org/Modeling-1.2/PlainModelBrowser"; public static final String Predicates = "http://www.simantics.org/Modeling-1.2/Predicates"; @@ -1188,6 +1190,7 @@ public class ModelingResources { OntologyDependencies = getResourceOrNull(graph, URIs.OntologyDependencies); Operations = getResourceOrNull(graph, URIs.Operations); Operations_NavigateToTarget = getResourceOrNull(graph, URIs.Operations_NavigateToTarget); + PageSettingsTypicalRule = getResourceOrNull(graph, URIs.PageSettingsTypicalRule); PartialIC = getResourceOrNull(graph, URIs.PartialIC); PlainModelBrowser = getResourceOrNull(graph, URIs.PlainModelBrowser); Predicates = getResourceOrNull(graph, URIs.Predicates); diff --git a/bundles/org.simantics.modeling/adapters.xml b/bundles/org.simantics.modeling/adapters.xml index 9703ae723..892fdbfcf 100644 --- a/bundles/org.simantics.modeling/adapters.xml +++ b/bundles/org.simantics.modeling/adapters.xml @@ -54,5 +54,5 @@ - http://www.simantics.org/Modeling-0.0/ComponentToElement http://www.simantics.org/Modeling-0.0/HasParentComponent/Inverse + http://www.simantics.org/Modeling-0.0/ComponentToElement http://www.simantics.org/Modeling-0.0/HasParentComponent/Inverse \ No newline at end of file diff --git a/bundles/org.simantics.modeling/src/org/simantics/modeling/typicals/AvailableSynchronizationRules.java b/bundles/org.simantics.modeling/src/org/simantics/modeling/typicals/AvailableSynchronizationRules.java index 07c8bc2ae..a396d3399 100644 --- a/bundles/org.simantics.modeling/src/org/simantics/modeling/typicals/AvailableSynchronizationRules.java +++ b/bundles/org.simantics.modeling/src/org/simantics/modeling/typicals/AvailableSynchronizationRules.java @@ -36,27 +36,34 @@ public class AvailableSynchronizationRules extends ResourceRead perform(ReadGraph graph) throws DatabaseException { - + Layer0 L0 = Layer0.getInstance(graph); DiagramResource DIA = DiagramResource.getInstance(graph); - ModelingResources MOD = ModelingResources.getInstance(graph); - + Set rules = new HashSet(); - for(Resource element : graph.syncRequest(new ObjectsWithType(resource, L0.ConsistsOf, DIA.Element))) { - for (Resource rule : graph.getObjects(element, MOD.HasTypicalSynchronizationRule)) { - ITypicalSynchronizationRule r = graph.getPossibleAdapter(rule, ITypicalSynchronizationRule.class); - if (r != null) rules.add(rule); - } + tryAddRules(graph, resource, rules); + for (Resource element : graph.syncRequest(new ObjectsWithType(resource, L0.ConsistsOf, DIA.Element))) { + tryAddRules(graph, element, rules); } - - Collection result = new ArrayList(); + + Collection result = new ArrayList<>(); for(Resource rule : rules) { String name = NameUtils.getSafeLabel(graph, rule); result.add(new NamedResource(name, rule)); } - + return result; - + } + + private int tryAddRules(ReadGraph graph, Resource r, Set rules) throws DatabaseException { + ModelingResources MOD = ModelingResources.getInstance(graph); + int count = 0; + for (Resource ruleResource : graph.getObjects(r, MOD.HasTypicalSynchronizationRule)) { + ITypicalSynchronizationRule rule = graph.getPossibleAdapter(ruleResource, ITypicalSynchronizationRule.class); + if (rule != null && rules.add(ruleResource)) + ++count; + } + return count; } } \ No newline at end of file diff --git a/bundles/org.simantics.modeling/src/org/simantics/modeling/typicals/SyncTypicalTemplatesToInstances.java b/bundles/org.simantics.modeling/src/org/simantics/modeling/typicals/SyncTypicalTemplatesToInstances.java index 56d61c868..55f5aef3d 100644 --- a/bundles/org.simantics.modeling/src/org/simantics/modeling/typicals/SyncTypicalTemplatesToInstances.java +++ b/bundles/org.simantics.modeling/src/org/simantics/modeling/typicals/SyncTypicalTemplatesToInstances.java @@ -545,6 +545,7 @@ public class SyncTypicalTemplatesToInstances extends WriteRequest { // Perform changes boolean changed = false; + changed |= synchronizeDiagramChanges(graph, info, template, instance); changed |= removeElements(graph, info, instanceElementsRemovedFromTemplate); changed |= addMissingElements(graph, info, template, instance, templateElementsAddedToTemplate); changed |= synchronizeChangedElements(graph, info, template, instance, changedTemplateElements, templateElementsAddedToTemplate, changedElementsByDiagram == ALL); @@ -553,6 +554,35 @@ public class SyncTypicalTemplatesToInstances extends WriteRequest { metadata.addTypical(instance); } + /** + * Synchronize any configurable aspects of the typical diagram instance itself. + * Every rule executed here comes from the ontology, nothing is fixed. + * + * @param graph + * @param typicalInfo + * @param template + * @param instance + * @return if any changes were made. + * @throws DatabaseException + */ + private boolean synchronizeDiagramChanges( + WriteGraph graph, + TypicalInfo typicalInfo, + Resource template, + Resource instance) + throws DatabaseException + { + boolean changed = false; + for (Resource rule : graph.getObjects(template, MOD.HasTypicalSynchronizationRule)) { + if (selectedRules != null && !selectedRules.contains(rule)) + continue; + ITypicalSynchronizationRule r = graph.getPossibleAdapter(rule, ITypicalSynchronizationRule.class); + if (r != null) + changed |= r.synchronize(graph, template, instance, typicalInfo); + } + return changed; + } + /** * Add elements from template that do not yet exist in the instance. * 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 index 000000000..cf6c60f20 --- /dev/null +++ b/bundles/org.simantics.modeling/src/org/simantics/modeling/typicals/rules/PageSettingsTypicalRule.java @@ -0,0 +1,41 @@ +package org.simantics.modeling.typicals.rules; + +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.exception.DatabaseException; +import org.simantics.diagram.query.DiagramRequests; +import org.simantics.diagram.synchronization.graph.DiagramGraphUtil; +import org.simantics.g2d.page.DiagramDesc; +import org.simantics.modeling.typicals.ITypicalSynchronizationRule; +import org.simantics.modeling.typicals.TypicalInfo; + +/** + * @author Tuukka Lehtonen + * @since 1.22.2, 1.25.0 + */ +public enum PageSettingsTypicalRule implements ITypicalSynchronizationRule { + + INSTANCE; + + public static PageSettingsTypicalRule get() { + return INSTANCE; + } + + @Override + public boolean synchronize(WriteGraph graph, Resource template, Resource instance, TypicalInfo info) throws DatabaseException { + DiagramDesc mdesc = graph.syncRequest(DiagramRequests.getDiagramDesc(template)); + DiagramDesc idesc = graph.syncRequest(DiagramRequests.getDiagramDesc(instance)); + if (mdesc.equals(idesc)) + return false; + + DiagramGraphUtil.setDiagramDesc(graph, instance, mdesc); + info.messageLog.add("\t\tset diagram page settings:" + + "\n\t\t\tshow page borders: " + mdesc.isPageBordersVisible() + + "\n\t\t\tshow margins: " + mdesc.isMarginsVisible() + + "\n\t\t\tgrid size: " + mdesc.getGridSize() + + "\n\t\t\tpage settings: " + mdesc.getPageDesc() + + "\n"); + return true; + } + +} -- 2.43.2