]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Partial update of arrays was broken
authorvillberg <villberg@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Mon, 8 Sep 2014 11:27:01 +0000 (11:27 +0000)
committervillberg <villberg@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Mon, 8 Sep 2014 11:27:01 +0000 (11:27 +0000)
refs #5224

git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@30229 ac1ea38d-2e2b-0410-8846-a27921b304fc

fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Array.java
fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Variable.java
fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/VariableBase.java

index 12ffdf4fd0ced12f860b972c9584235e619700dc..e7b1959d63865cc68fc0489ab514f626c70b8fc0 100644 (file)
@@ -503,4 +503,37 @@ public class Array implements IExpression {
                return subscript(environment, subscripts, 0);\r
        }\r
 \r
+       public void applyPartial(Array[] indices, Array value, int pos) {\r
+               Array arr = indices[pos];\r
+               if(Array.FULL == arr) {\r
+                       for(int i=0;i<elements.size();i++) {\r
+                               if(pos < (indices.length-1)) {\r
+                                       ((Array)elements.get(i)).applyPartial(indices, (Array)value.element(i), pos+1);\r
+                               } else {\r
+                                       elements.set(i, value.element(i));\r
+                               }\r
+                       }\r
+               } else if(arr.dimension() == 1) {\r
+                       int index = ((Double)arr.element(0)).intValue();\r
+                       if(pos < (indices.length-1)) {\r
+                               ((Array)elements.get(index)).applyPartial(indices, value, pos+1);\r
+                       } else {\r
+                               elements.set(index, (Array)value.element(index));\r
+                       }\r
+               } else {\r
+                       for(Object element : arr.elements) {\r
+                               int i = ((Double)element).intValue();\r
+                               if(pos < (indices.length-1)) {\r
+                                       ((Array)elements.get(i)).applyPartial(indices, (Array)value.element(i), pos+1);\r
+                               } else {\r
+                                       elements.set(i, value.element(i));\r
+                               }\r
+                       }\r
+               }\r
+       }\r
+\r
+       public void applyPartial(Array[] indices, Array value) {\r
+               applyPartial(indices, value, 0);\r
+       }\r
+\r
 }\r
index 05ac71fdf868a43dee31a353407c77750d01dc5f..2f28d4b89bc828d11394b6917dbbde138927d4c1 100644 (file)
@@ -170,7 +170,14 @@ public class Variable implements IExpression {
                \r
                if(value instanceof Array) {\r
                        if(base.isStoredAsArray(env)) {\r
-                               env.put(base.index(env, subscripts), value);\r
+                               if(SolverUtils.isFullSubscript(subscripts)) {\r
+                                       env.put(base.index(env, subscripts), value);\r
+                               } else {\r
+                                       Array[] indices = SolverUtils.parseSubscripts(env, subscripts);\r
+                                       Array current = (Array)env.getValue(base.index);\r
+                                       current.applyPartial(indices, (Array)value);\r
+                                       env.put(base.index, current);\r
+                               }\r
                        } else {\r
                                assignArray(env, base.index(env, subscripts), (Array)value, 0);\r
                        }\r
index 40c75d2db582a6c899ab43ecb36bdb9012e059bb..e18fc45d8055f07e7e3863aa492f2273b5bfb007 100644 (file)
@@ -212,11 +212,14 @@ public class VariableBase {
                \r
                if(isStoredAsArray(environment)) {\r
                        \r
-                       Array array = (Array)environment.getValue(index);\r
-                       if(subscripts != null) {\r
-                               return array.subscript(environment, subscripts);\r
+                       Object value = environment.getValue(index);\r
+                       if(value instanceof Array) {\r
+                               Array array = (Array)value;\r
+                               if(subscripts != null) {\r
+                                       return array.subscript(environment, subscripts);\r
+                               }\r
                        }\r
-                       else return array;\r
+                       return value;\r
                        \r
                } else {\r
 \r