]> gerrit.simantics Code Review - simantics/3d.git/commitdiff
Data corruption on editor startup. 07/3407/1
authorMarko Luukkainen <marko.luukkainen@semantum.fi>
Thu, 24 Oct 2019 13:30:42 +0000 (16:30 +0300)
committerMarko Luukkainen <marko.luukkainen@semantum.fi>
Thu, 24 Oct 2019 13:30:42 +0000 (16:30 +0300)
PipingRules were executed "silently" on editor startup. If rules changed
pipeline structure, these changes were never reflected to DB, causing
mismatch between DB and pipeline Java objects.

gitlab #35

Change-Id: I62de99c1465bbb3658e9d2a52617b7a8778523b6

org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/common/AbstractVTKNodeMap.java
org.simantics.plant3d/src/org/simantics/plant3d/editor/P3DNodeMap.java
org.simantics.plant3d/src/org/simantics/plant3d/editor/Plant3DEditor.java
org.simantics.plant3d/src/org/simantics/plant3d/utils/P3DUtil.java

index b762200786217a0434515a068a8d0f89cbe222e6..efb4c07b151d95b4ee336984f861c8dc094de69c 100644 (file)
@@ -50,7 +50,7 @@ import vtk.vtkProp;
 
 public abstract class AbstractVTKNodeMap<E extends INode> implements VTKNodeMap<E>, IMappingListener, RenderListener, NodeListener, UndoRedoSupport.ChangeListener{
 
-       private static final boolean DEBUG = true;
+       private static final boolean DEBUG = false;
        
        protected Session session;
        protected IMapping<Object,E> mapping;
@@ -143,6 +143,10 @@ public abstract class AbstractVTKNodeMap<E extends INode> implements VTKNodeMap<
 
        private boolean rangeModified = false;
        
+       public boolean isRangeModified() {
+        return rangeModified;
+    }
+       
        @Override
        public void onChanged() {
                try {
@@ -456,7 +460,10 @@ public abstract class AbstractVTKNodeMap<E extends INode> implements VTKNodeMap<
                    E n = stack.pop();
                    boolean conflict = filterChange(removed, n);
                    if (conflict) {
-                       filterChange(added, n);   
+                       System.out.println("Prevent removing " + n);
+                       //filterChange(added, n)
+                       if (filterChange(added, n))
+                           System.out.println("Prevent adding " + n);
                    }
                    if (n instanceof ParentNode) {
                        ParentNode<INode> pn = (ParentNode<INode>)n;
index f7bb42306aad6690a9088d35e8eac79d5ccac054..510956efaa45edc772a31280182c631446a57ab2 100644 (file)
@@ -265,7 +265,7 @@ public class P3DNodeMap extends AbstractVTKNodeMap<INode> {
                } else if (graph.isInstanceOf(r, P3D.PipeRun)) {
                    pipeRuns.add(r);
                } else {
-                   throw new DatabaseException("Unknown resource " + r);
+                   throw new DatabaseException("Unknown resource " + r+ " " + mapping.get(r));
                }
            }
            Set<Resource> nozzles = new HashSet<>();
@@ -274,7 +274,7 @@ public class P3DNodeMap extends AbstractVTKNodeMap<INode> {
                    if (graph.isInstanceOf(n, P3D.Nozzle)) {
                        nozzles.add(n);
                    } else {
-                       throw new DatabaseException("Unknown nozzle resource " + n);
+                       throw new DatabaseException("Unknown nozzle resource " + n+ " " + mapping.get(n));
                    }
                }
            }
@@ -285,7 +285,7 @@ public class P3DNodeMap extends AbstractVTKNodeMap<INode> {
                 if (graph.isInstanceOf(c, P3D.PipelineComponent)) {
                     components.add(c);
                 } else {
-                    throw new DatabaseException("Unknown component resource " + c);
+                    throw new DatabaseException("Unknown component resource " + c + " " + mapping.get(c));
                 }
             }
         }
@@ -293,11 +293,11 @@ public class P3DNodeMap extends AbstractVTKNodeMap<INode> {
         for (Resource c : components) {
             for (Resource connected : graph.getObjects(c, P3D.Connects)) {
                 if (!components.contains(connected) && !nozzles.contains(connected)) {
-                    throw new DatabaseException("Unbrowsable component resource " + connected + " connected to " + c);
+                    throw new DatabaseException("Unbrowsable component resource " + connected + " " + mapping.get(connected) +" connected to " + c + " " + mapping.get(c));
                 }
                 Collection<Resource> connectedConnected = graph.getObjects(connected, P3D.Connects);
                 if (!connectedConnected.contains(c)) {
-                    throw new DatabaseException("Component resource " + c + " is connected to " + connected +", but its has no connection back.");
+                    throw new DatabaseException("Component resource " + c + " " + mapping.get(c) + " is connected to " + connected + " " + mapping.get(connected) +", but its has no connection back.");
                 }
             }
         }
index 273e1062d15ae6e805fbf1507007000df30a6673..2c94b5daea3fa4d191f7dda53dbc7960f350063d 100644 (file)
@@ -23,6 +23,7 @@ import org.simantics.db.common.request.ReadRequest;
 import org.simantics.db.exception.DatabaseException;
 import org.simantics.g3d.scenegraph.IG3DNode;
 import org.simantics.g3d.scenegraph.NodeMap;
+import org.simantics.g3d.scenegraph.RenderListener;
 import org.simantics.g3d.scenegraph.base.INode;
 import org.simantics.g3d.vtk.action.RemoveAction;
 import org.simantics.g3d.vtk.common.HoverHighlighter;
@@ -151,19 +152,25 @@ public class Plant3DEditor extends ResourceEditorPart {
                                @SuppressWarnings({ "rawtypes", "unchecked" })
                                @Override
                                public void run(ReadGraph graph) throws DatabaseException {
+                                   System.out.println("START PLANT3D LOAD");
                                        PipingRules.setEnabled(false);
                                        IMappingSchema<Resource, Object> schema = getSchema(graph);
                                        mapping = Mappings.createWithListening(schema);
                                        rootNode = (P3DRootNode)mapping.map(graph, input);
                                        // update control points.
                                        // TODO : this should be optimized.
+                                       
+                                       
+                                       
                                        try {
-                                               P3DUtil.finalizeDBLoad(rootNode);
-                                               
-                                       } catch (Exception e) {
-                                               throw new DatabaseException(e);
-                                       }
-                                       nodeMap = createNodeMap(getSession(), mapping, panel,rootNode);
+                                           P3DUtil.finalizeDBLoad(rootNode);
+                                           nodeMap = createNodeMap(getSession(), mapping, panel,rootNode);
+                                          
+                    } catch (Exception e) {
+                        throw new DatabaseException(e);
+                    }
+                                       
+                                       System.out.println("END PLANT3D LOAD");
                                }
                        });
                        
@@ -245,6 +252,27 @@ public class Plant3DEditor extends ResourceEditorPart {
                        @Override
                        public void run() {
                                nodeMap.populate();
+                               panel.addListener(new RenderListener() {
+                    
+                    @Override
+                    public void preRender() {
+                   
+                    }
+                    
+                    @Override
+                    public void postRender() {
+                        try {
+                            P3DUtil.finalizeDBLoad2(rootNode);
+                            if (nodeMap.isRangeModified());
+                                nodeMap.commit("Load sync");
+                        } catch (Exception e) {
+                            //throw new DatabaseException(e);
+                        }
+                        panel.removeListener(this);  
+                        
+                    }
+                });
+                               
                        }
                });
                
index e5d1768a2c85da2cf2cdcb9bdcfbea36e6216c1e..71f844d866329fe2dac458d7e9c468c6eb28ce33 100644 (file)
@@ -228,14 +228,18 @@ public class P3DUtil {
                                PipingRules.validate((PipeRun)node);
                        }
                }
-               PipingRules.setEnabled(true);
-               for (INode node : rootNode.getChild()) {
-                       if (node instanceof PipeRun) {
-                               PipeRun run = (PipeRun)node;
-                               for (PipeControlPoint pcp : run.getControlPoints())
-                                       PipingRules.positionUpdate(pcp);        
-                       }
-               }
        }
+       
+   public static void finalizeDBLoad2(P3DRootNode rootNode) throws Exception{
+       PipingRules.setEnabled(true);
+        for (INode node : rootNode.getChild()) {
+            if (node instanceof PipeRun) {
+                PipeRun run = (PipeRun)node;
+                for (PipeControlPoint pcp : run.getControlPoints())
+                    PipingRules.positionUpdate(pcp);
+                    //PipingRules.requestUpdate(pcp);
+            }
+        }
+   }
 
 }