]> gerrit.simantics Code Review - simantics/3d.git/blobdiff - org.simantics.plant3d/src/org/simantics/plant3d/editor/Plant3DEditor.java
Use generics type variable for mapping db object.
[simantics/3d.git] / org.simantics.plant3d / src / org / simantics / plant3d / editor / Plant3DEditor.java
index 273e1062d15ae6e805fbf1507007000df30a6673..d3f3c5e47e11d199b838225ee16f7afa6a0fd4e0 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;
@@ -45,6 +46,7 @@ import org.simantics.plant3d.actions.AddNozzleAction;
 import org.simantics.plant3d.actions.RemoveAndSplitAction;
 import org.simantics.plant3d.actions.RoutePipeAction;
 import org.simantics.plant3d.actions.TranslateInlineAction;
+import org.simantics.plant3d.ontology.Plant3D;
 import org.simantics.plant3d.scenegraph.EndComponent;
 import org.simantics.plant3d.scenegraph.Equipment;
 import org.simantics.plant3d.scenegraph.IP3DNode;
@@ -138,7 +140,7 @@ public class Plant3DEditor extends ResourceEditorPart {
                panel.setPickType(4);
                
                try {
-                       ControlPointFactory.preloadCache();
+                       ControlPointFactory.preloadCache(getLibraryUri());
                        ComponentUtils.preloadCache();
                } catch (Exception e) {
                        ExceptionUtils.logAndShowError("Cannot open Plant3D editor",e);
@@ -151,19 +153,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");
                                }
                        });
                        
@@ -220,8 +228,12 @@ public class Plant3DEditor extends ResourceEditorPart {
            return new HoverHighlighter(panel,nodeMap);
        }
        
-       protected SelectionHighlighter<INode> createSelectionHighlighter() {
-           return new SelectionHighlighter<INode>(panel,nodeMap);
+       protected SelectionHighlighter<Resource,INode> createSelectionHighlighter() {
+           return new SelectionHighlighter<Resource,INode>(panel,nodeMap);
+       }
+       
+       protected String getLibraryUri() {
+           return Plant3D.URIs.Builtin;
        }
        
        protected void createActions() {
@@ -236,7 +248,7 @@ public class Plant3DEditor extends ResourceEditorPart {
                
                removeSplitAction = new RemoveAndSplitAction(nodeMap);
                routePipeAction = new RoutePipeAction(panel,rootNode);
-               addComponentAction = new AddComponentAction(panel, rootNode);
+               addComponentAction = new AddComponentAction(panel, rootNode, getLibraryUri());
        }
        
        public void populate() {
@@ -245,6 +257,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);  
+                        
+                    }
+                });
+                               
                        }
                });
                
@@ -328,7 +361,7 @@ public class Plant3DEditor extends ResourceEditorPart {
                List<IG3DNode> selected = selectionProvider.getSelectedNodes();
                try {
                        if (selected.size() == 0) {
-                               for (Item eq : P3DUtil.getEquipments()) {
+                               for (Item eq : P3DUtil.getEquipments(getLibraryUri())) {
                                        m.add(new AddEquipmentAction(rootNode, eq));
                                }
                        } else if (selected.size() == 1) {
@@ -336,7 +369,7 @@ public class Plant3DEditor extends ResourceEditorPart {
                                if (node instanceof Equipment) {
                                        m.add(translateAction);
                                        m.add(rotateAction);
-                                       for (Item eq : P3DUtil.getNozzles()) {
+                                       for (Item eq : P3DUtil.getNozzles(getLibraryUri())) {
                                                AddNozzleAction add = new AddNozzleAction(rootNode, eq);
                                                add.setEquipment((Equipment)node);
                                                m.add(add);