]> gerrit.simantics Code Review - simantics/interop.git/commitdiff
Three-way comparison
authorMarko Luukkainen <marko.luukkainen@vtt.fi>
Fri, 20 Oct 2017 12:29:08 +0000 (15:29 +0300)
committerMarko Luukkainen <marko.luukkainen@vtt.fi>
Fri, 20 Oct 2017 12:29:08 +0000 (15:29 +0300)
org.simantics.interop.update/scl/Interop/Update.scl
org.simantics.interop.update/src/org/simantics/interop/update/model/ModelUpdate.java
org.simantics.interop.update/src/org/simantics/interop/update/model/UpdateNode3.java [new file with mode: 0644]

index 06e778540c47b40830c77ecb527cba92074bde60..1498a864737a84e9b43f879c8542c5dec8c24d11 100644 (file)
@@ -20,6 +20,24 @@ importJava "org.simantics.interop.update.model.ModelUpdate" where
   @JavaName applySelected
   applySelectedUpdates :: ModelUpdate -> <WriteGraph> ()
   
+  @JavaName getUpdateTree2
+  getUpdateTree2 :: ModelUpdate -> <Proc> UpdateTree
+  
+  @JavaName getUpdateList2
+  getUpdateList2 :: ModelUpdate -> <Proc> UpdateList
+  
+  @JavaName getChanges2
+  getGraphChanges2 :: ModelUpdate -> <Proc> GraphChanges
+  
+  @JavaName getUpdateTree3
+  getUpdateTree3 :: ModelUpdate -> <Proc> Maybe UpdateTree
+  
+  @JavaName getUpdateList
+  getUpdateList3 :: ModelUpdate -> <Proc> Maybe UpdateList
+  
+  @JavaName getChanges
+  getGraphChanges3 :: ModelUpdate -> <Proc> Maybe GraphChanges
+  
 importJava "org.simantics.interop.update.model.UpdateTree" where
   data UpdateTree
   
@@ -114,6 +132,24 @@ importJava "org.simantics.interop.update.model.UpdateOp" where
   @JavaName isChange
   opIsChange :: UpdateOp -> <Proc> Boolean
   
+importJava "org.simantics.interop.update.model.UpdateNode3" where
+  data UpdateNode3
+  
+  @JavaName getUn1
+  getNode1 :: UpdateNode3 -> <Proc> Maybe UpdateNode
+  
+  @JavaName getUn2
+  getNode2 :: UpdateNode3 -> <Proc> Maybe UpdateNode
+  
+  @JavaName getUn3
+  getNode3 :: UpdateNode3 -> <Proc> Maybe UpdateNode
+  
+  @JavaName getChildren
+  getNode3Children :: UpdateNode3 -> <Proc> [UpdateNode3]
+  
+  @JavaName getCombinedTree
+  getCombinedTree :: ModelUpdate -> <Proc> UpdateNode3
+  
 importJava "org.simantics.utils.datastructures.Pair" where
   data Pair
   
index 0ddd4e40378b8bd543def326ed84926b1998be79..2a263f117ff5f26eb398f468f7d41df270a622f2 100644 (file)
@@ -25,10 +25,13 @@ public abstract class ModelUpdate {
        private UpdateList updateList;
        
        private GraphChanges changes2;
-       private GraphChanges changes3;
        private UpdateTree updateTree2;
        private UpdateList updateList2;
        
+       private GraphChanges changes3;
+       private UpdateTree updateTree3;
+       private UpdateList updateList3;
+       
        private List<ChangeFilter> filters = new ArrayList<ChangeFilter>();
        
        boolean init = false;
@@ -141,15 +144,28 @@ public abstract class ModelUpdate {
        public GraphChanges getChanges2() {
                return changes2;
        }
-       public GraphChanges getChanges3() {
-               return changes3;
-       }
+       
        public UpdateTree getUpdateTree2() {
                return updateTree2;
        }
        public UpdateList getUpdateList2() {
                return updateList2;
        }
+       
+       public GraphChanges getChanges3() {
+               return changes3;
+       }
+       
+       public UpdateTree getUpdateTree3() throws DatabaseException{
+               if (updateTree3 == null && changes3 != null)
+                       updateTree3 = getUpdateTree(changes3);
+               return updateTree3;
+       }
+       public UpdateList getUpdateList3() throws DatabaseException {
+               if (updateList3 == null && changes3 != null)
+                       updateList3 = getUpdateList(changes3);
+               return updateList3;
+       }
 
        
        public void applyAll(WriteGraph graph) throws DatabaseException {
diff --git a/org.simantics.interop.update/src/org/simantics/interop/update/model/UpdateNode3.java b/org.simantics.interop.update/src/org/simantics/interop/update/model/UpdateNode3.java
new file mode 100644 (file)
index 0000000..cdff0d8
--- /dev/null
@@ -0,0 +1,131 @@
+package org.simantics.interop.update.model;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.simantics.db.Resource;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.interop.test.GraphChanges;
+
+public class UpdateNode3 {
+       
+       UpdateNode un1;
+       UpdateNode un2;
+       UpdateNode un3;
+       
+       private Collection<UpdateNode3> children = new ArrayList<UpdateNode3>();
+       
+       
+       public Collection<UpdateNode3> getChildren() {
+               return children;
+       }
+       
+       public UpdateNode getUn1() {
+               return un1;
+       }
+       
+       public UpdateNode getUn2() {
+               return un2;
+       }
+       
+       public UpdateNode getUn3() {
+               return un3;
+       }
+       
+       public UpdateNode3(UpdateNode un1, UpdateNode un2, UpdateNode un3) {
+               this.un1 = un1;
+               this.un2 = un2;
+               this.un3 = un3;
+       }
+       
+       public static UpdateNode3 getCombinedTree(ModelUpdate update) throws DatabaseException {
+               UpdateTree updateTree1 = update.getUpdateTree();
+               UpdateTree updateTree2 = update.getUpdateTree2();
+               UpdateTree updateTree3 = update.getUpdateTree3();
+               
+               UpdateNode3 n3 = new UpdateNode3(updateTree1.getRootNode(), updateTree2.getRootNode(), updateTree3.getRootNode());
+               
+               populate(n3, update.getChanges(), update.getChanges2(), update.getChanges3());
+               return n3;
+       }
+       
+       private static void populate(UpdateNode3 un, GraphChanges gc1, GraphChanges gc2, GraphChanges gc3) {
+               Set<UpdateNode> p1 = new HashSet<>();
+               Set<UpdateNode> p2 = new HashSet<>();
+               Set<UpdateNode> p3 = new HashSet<>();
+               
+               if (un.getUn1() != null) {
+                       for (UpdateNode n1 : un.getUn1().getChildren())  {
+                               p1.add(n1);
+                               UpdateNode n2 = null;
+                               if (un.getUn2() != null)
+                                       n2 = getMathcing(n1, un.getUn2().getChildren(), gc1);
+                               UpdateNode n3 = null;
+                               if (un.getUn3() != null) {
+                                       n3 = getMathcing(n1, un.getUn3().getChildren(), gc2);
+                                       if (n3 == null && n2 != null)
+                                               n3 = getMathcing(n2, un.getUn3().getChildren(), gc3);
+                               }
+                               UpdateNode3 cn = new UpdateNode3(n1, n2, n3);
+                               un.children.add(cn);
+                               populate(cn, gc1, gc2, gc3);
+                               
+                               if (n2 != null)
+                                       p2.add(n2);
+                               if (n3 != null)
+                                       p3.add(n3);
+                       }
+               }
+               if (un.getUn2() != null) {
+                       for (UpdateNode n2 : un.getUn2().getChildren())  {
+                               if (p2.contains(n2))
+                                       continue;
+                               p2.add(n2);
+                               
+                               UpdateNode n3 = null;
+                               if (un.getUn3() != null) {
+                                       n3 = getMathcing(n2, un.getUn3().getChildren(), gc3);
+                               }
+                               UpdateNode3 cn = new UpdateNode3(null, n2, n3);
+                               un.children.add(cn);
+                               populate(cn, gc1, gc2, gc3);
+                               
+                               if (n3 != null)
+                                       p3.add(n3);
+                       }
+               }
+               if (un.getUn3() != null) {
+                       for (UpdateNode n3 : un.getUn3().getChildren())  {
+                               if (p3.contains(n3))
+                                       continue;
+                               p3.add(n3);
+                               UpdateNode3 cn = new UpdateNode3(null, null, n3);
+                               un.children.add(cn);
+                               populate(cn, gc1, gc2, gc3);
+                       }
+               }
+       }
+       
+       private static UpdateNode getMathcing(UpdateNode n , Collection<UpdateNode> coll, GraphChanges gc) {
+               if (n.getResource() == null) {
+                       if (coll.size() != 1)
+                               return null;
+                       UpdateNode n2 = coll.iterator().next();
+                       if (n2.getClass() != n.getClass())
+                               return null;
+                       return n2;
+               }
+               Resource o = gc.getComparable().getLeft(n.getResource());
+               if (o == null)
+                       o = gc.getComparable().getRight(n.getResource());
+               if (o == null)
+                       o = n.getResource();
+               for (UpdateNode c : coll) {
+                       if (o.equals(c.getResource()))
+                               return c;
+               }
+               return null;
+       }
+}