From 26eeab37c76e17ea0539cd366ccd8f5564896989 Mon Sep 17 00:00:00 2001 From: miettinen Date: Fri, 7 Feb 2014 08:03:36 +0000 Subject: [PATCH] Unit parser of Sysdyn to match equivalents in reducing units (refs #4704). Centered the text in auxiliary, input, stock and module. git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@28789 ac1ea38d-2e2b-0410-8846-a27921b304fc --- .../sysdyn/ui/elements/AuxiliaryFactory.java | 2 +- .../sysdyn/ui/elements/InputFactory.java | 2 +- .../sysdyn/ui/elements/ModuleFactory.java | 2 +- .../sysdyn/ui/elements/StockFactory.java | 2 +- .../ResourceSelectionProcessor.java | 4 +-- .../sysdyn/unitParser/nodes/UnitResult.java | 33 ++++++++++++++----- 6 files changed, 30 insertions(+), 15 deletions(-) diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/AuxiliaryFactory.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/AuxiliaryFactory.java index 40e523b1..ab3bbd30 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/AuxiliaryFactory.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/AuxiliaryFactory.java @@ -52,7 +52,7 @@ public class AuxiliaryFactory extends SysdynElementFactory { new StaticObjectAdapter(elementType), new StaticSymbolImpl(AUX_STATIC_IMAGE), StaticSymbolImageInitializer.INSTANCE, - new SysdynTextElementHandler(0, 0, Alignment.LEADING, 0, 1.5, 1.5, true), + new SysdynTextElementHandler(0, 0, Alignment.CENTER, 0, 1.5, 1.5, true), BoundsOutline.INSTANCE, ResizeRectangularSceneGraph.INSTANCE, RESIZE_PROPERTY_SETTER, diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/InputFactory.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/InputFactory.java index 7f0aca6a..b19f43da 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/InputFactory.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/InputFactory.java @@ -90,7 +90,7 @@ public class InputFactory extends SysdynElementFactory { new StaticSymbolImpl(INPUT_IMAGE), StaticSymbolImageInitializer.INSTANCE, Input.INSTANCE, - new InputSceneGraph(0, 0, Alignment.LEADING, 0, 1.5, 1.5, true), + new InputSceneGraph(0, 0, Alignment.CENTER, 0, 1.5, 1.5, true), BoundsOutline.INSTANCE, ResizeRectangularSceneGraph.INSTANCE, RESIZE_PROPERTY_SETTER, diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/ModuleFactory.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/ModuleFactory.java index be30fe1f..175a95d5 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/ModuleFactory.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/ModuleFactory.java @@ -58,7 +58,7 @@ public class ModuleFactory extends SysdynElementFactory { new StaticObjectAdapter(elementType), new StaticSymbolImpl(DEFAULT_IMAGE), StaticSymbolImageInitializer.INSTANCE, - new ModuleSceneGraph(0, 0, Alignment.LEADING, 1f , 2, 3, true), + new ModuleSceneGraph(0, 0, Alignment.CENTER, 1f , 2, 3, true), BoundsOutline.INSTANCE, new BorderColorImpl(Color.BLACK), ResizeRectangularSceneGraph.INSTANCE, diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/StockFactory.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/StockFactory.java index a821104c..96b68951 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/StockFactory.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/StockFactory.java @@ -58,7 +58,7 @@ public class StockFactory extends SysdynElementFactory { new StaticObjectAdapter(elementType), new StaticSymbolImpl(STOCK_IMAGE), StaticSymbolImageInitializer.INSTANCE, - new SysdynTextElementHandler(0, 0, Alignment.LEADING, 1f, 1.0, 1.0, true), + new SysdynTextElementHandler(0, 0, Alignment.CENTER, 1f, 1.0, 1.0, true), BoundsOutline.INSTANCE, new BorderColorImpl(Color.BLACK), ResizeRectangularSceneGraph.INSTANCE, diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ResourceSelectionProcessor.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ResourceSelectionProcessor.java index 8db3657c..1fb36162 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ResourceSelectionProcessor.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/ResourceSelectionProcessor.java @@ -95,8 +95,8 @@ public class ResourceSelectionProcessor implements SelectionProcessor copyDividers1 = new ArrayList(dividers); ArrayList copyDividents1 = new ArrayList(dividents); - reduceUnitLists(dividents, copyDividents1, copyDividers1); + reduceUnitLists(dividents, copyDividents1, copyDividers1, allowEquivalents); StringBuilder sb = new StringBuilder(); Iterator iterator = copyDividents1.iterator(); @@ -190,11 +190,11 @@ public class UnitResult { ArrayList copyDividers1 = new ArrayList(dividers); ArrayList copyDividents1 = new ArrayList(dividents); - reduceUnitLists(dividents, copyDividents1, copyDividers1); + reduceUnitLists(dividents, copyDividents1, copyDividers1, allowEquivalents); ArrayList copyDividers2 = new ArrayList(other.dividers); ArrayList copyDividents2 = new ArrayList(other.dividents); - reduceUnitLists(other.dividents, copyDividents2, copyDividers2); + reduceUnitLists(other.dividents, copyDividents2, copyDividers2, allowEquivalents); if(copyDividents1.size() != copyDividents2.size()) return false; @@ -247,11 +247,26 @@ public class UnitResult { return unit; } - public void reduceUnitLists(ArrayList originalDividents, ArrayList copyDividents, ArrayList copyDividers) { + public void reduceUnitLists( + ArrayList originalDividents, + ArrayList copyDividents, + ArrayList copyDividers, + boolean allowEquivalents) { + if (allowEquivalents) { + // Replace equivalents + for(int i = 0; i < originalDividents.size(); i++) { + copyDividents.set(i, getDefaultForm(copyDividents.get(i))); + } + for(int i = 0; i < copyDividers.size(); i++) { + copyDividers.set(i, getDefaultForm(copyDividers.get(i))); + } + } + for(String s : originalDividents) { - if(copyDividers.contains(s)) { - copyDividers.remove(s); - copyDividents.remove(s); + String equiv = allowEquivalents ? getDefaultForm(s) : s; + if(copyDividers.contains(equiv)) { + copyDividers.remove(equiv); + copyDividents.remove(equiv); } } -- 2.47.1