From bbf50fc505117a5269f0aaff504eaa3dc57b9d31 Mon Sep 17 00:00:00 2001 From: Marko Luukkainen Date: Thu, 24 Oct 2019 16:30:42 +0300 Subject: [PATCH] Data corruption on editor startup. 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 --- .../g3d/vtk/common/AbstractVTKNodeMap.java | 11 ++++- .../simantics/plant3d/editor/P3DNodeMap.java | 10 ++--- .../plant3d/editor/Plant3DEditor.java | 40 ++++++++++++++++--- .../org/simantics/plant3d/utils/P3DUtil.java | 20 ++++++---- 4 files changed, 60 insertions(+), 21 deletions(-) diff --git a/org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/common/AbstractVTKNodeMap.java b/org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/common/AbstractVTKNodeMap.java index b7622007..efb4c07b 100644 --- a/org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/common/AbstractVTKNodeMap.java +++ b/org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/common/AbstractVTKNodeMap.java @@ -50,7 +50,7 @@ import vtk.vtkProp; public abstract class AbstractVTKNodeMap implements VTKNodeMap, IMappingListener, RenderListener, NodeListener, UndoRedoSupport.ChangeListener{ - private static final boolean DEBUG = true; + private static final boolean DEBUG = false; protected Session session; protected IMapping mapping; @@ -143,6 +143,10 @@ public abstract class AbstractVTKNodeMap implements VTKNodeMap< private boolean rangeModified = false; + public boolean isRangeModified() { + return rangeModified; + } + @Override public void onChanged() { try { @@ -456,7 +460,10 @@ public abstract class AbstractVTKNodeMap 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 pn = (ParentNode)n; diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/editor/P3DNodeMap.java b/org.simantics.plant3d/src/org/simantics/plant3d/editor/P3DNodeMap.java index f7bb4230..510956ef 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/editor/P3DNodeMap.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/editor/P3DNodeMap.java @@ -265,7 +265,7 @@ public class P3DNodeMap extends AbstractVTKNodeMap { } 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 nozzles = new HashSet<>(); @@ -274,7 +274,7 @@ public class P3DNodeMap extends AbstractVTKNodeMap { 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 { 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 { 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 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."); } } } diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/editor/Plant3DEditor.java b/org.simantics.plant3d/src/org/simantics/plant3d/editor/Plant3DEditor.java index 273e1062..2c94b5da 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/editor/Plant3DEditor.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/editor/Plant3DEditor.java @@ -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 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); + + } + }); + } }); diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/utils/P3DUtil.java b/org.simantics.plant3d/src/org/simantics/plant3d/utils/P3DUtil.java index e5d1768a..71f844d8 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/utils/P3DUtil.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/utils/P3DUtil.java @@ -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); + } + } + } } -- 2.47.1