]> gerrit.simantics Code Review - simantics/3d.git/blobdiff - org.simantics.plant3d/src/org/simantics/plant3d/editor/Plant3DEditor.java
Enable model loading using an existing transaction.
[simantics/3d.git] / org.simantics.plant3d / src / org / simantics / plant3d / editor / Plant3DEditor.java
index 4059d938f0d939f754dd0204190cf1452703d487..a7559f8009b35a599469a6d7d45cc7845b698a43 100644 (file)
@@ -16,10 +16,10 @@ import org.eclipse.jface.viewers.SelectionChangedEvent;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.events.DisposeEvent;
 import org.eclipse.swt.events.DisposeListener;
-import org.eclipse.swt.layout.FillLayout;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Menu;
 import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
+import org.simantics.Simantics;
 import org.simantics.db.ReadGraph;
 import org.simantics.db.Resource;
 import org.simantics.db.Session;
@@ -120,6 +120,11 @@ public class Plant3DEditor extends ResourceEditorPart {
        
        private P3DNodeMap nodeMap;
        
+       /** Constants for selecting the up-direction */
+       public static final int X = 0, Y = 1, Z = 2;
+       
+       protected int upDirection = 1;
+       
        @Override
        public void createPartControl(Composite parent) {
                this.parent = parent;
@@ -162,13 +167,25 @@ public class Plant3DEditor extends ResourceEditorPart {
                new ContextMenuListener(panel, contextMenu);
                
                cameraAction = createCameraAction();
+               switch (upDirection) {
+               case 0:
+                       cameraAction.setUpDirection(new double[] { 1, 0, 0 });
+                       break;
+               case 1:
+                       cameraAction.setUpDirection(new double[] { 0, 1, 0 });
+                       break;
+               case 2:
+                       cameraAction.setUpDirection(new double[] { 0, 0, 1 });
+                       break;
+               }
+               
                panel.setDefaultAction(cameraAction);
                panel.useDefaultAction();
                panel.setPickType(4);
                
                try {
-                       ControlPointFactory.preloadCache(getLibraryUri());
-                       ComponentUtils.preloadCache();
+                       ControlPointFactory.preloadCache(Simantics.getSession(), getLibraryUri());
+                       ComponentUtils.preloadCache(Simantics.getSession());
                } catch (Exception e) {
                        ExceptionUtils.logAndShowError("Cannot open Plant3D editor",e);
                        return;
@@ -179,7 +196,7 @@ public class Plant3DEditor extends ResourceEditorPart {
                                
                                @Override
                                public void run(ReadGraph graph) throws DatabaseException {
-                                   System.out.println("START PLANT3D LOAD");
+                                   //System.out.println("START PLANT3D LOAD");
                                        PipingRules.setEnabled(false);
                                        IMappingSchema<Resource,INode> schema = getSchema(graph);
                                        mapping = Mappings.createWithListening(schema);
@@ -195,7 +212,7 @@ public class Plant3DEditor extends ResourceEditorPart {
                         throw new DatabaseException(e);
                     }
                                        
-                                       System.out.println("END PLANT3D LOAD");
+                                       //System.out.println("END PLANT3D LOAD");
                                }
                        });
                        
@@ -240,6 +257,10 @@ public class Plant3DEditor extends ResourceEditorPart {
                
        }
        
+       public void setUpDirection(int upDirection) {
+               this.upDirection = upDirection;
+       }
+
        protected vtkCameraAndSelectorAction createCameraAction() {
            return new vtkCameraAndSelectorAction(panel); 
        }
@@ -293,6 +314,7 @@ public class Plant3DEditor extends ResourceEditorPart {
                             if (nodeMap.isRangeModified());
                                 nodeMap.commit("Load sync");
                         } catch (Exception e) {
+                            ExceptionUtils.logAndShowError("Failed to load model correctly", e);
                             //throw new DatabaseException(e);
                         }
                         panel.removeListener(this);  
@@ -377,7 +399,8 @@ public class Plant3DEditor extends ResourceEditorPart {
                ren1.SetGradientBackground(true);
 
                // vtkActor grid = vtkShape.createGridActor(8,1.0,1|2|4);
-               vtkActor grid = vtkShape.createGridActor(8,1.0, 2 );
+               int dir = 1 << upDirection;
+               vtkActor grid = vtkShape.createGridActor(8, 1.0, dir);
                grid.SetPickable(0);
                ren1.AddActor(grid);
                panel.addDeletable(grid);
@@ -418,15 +441,16 @@ public class Plant3DEditor extends ResourceEditorPart {
                }
                try {
                        if (selected.size() == 0) {
-                               for (Item eq : P3DUtil.getEquipments(getLibraryUri())) {
-                                       m.add(new AddEquipmentAction(rootNode, eq));
-                               }
+                           m.add(new AddEquipmentAction(rootNode, getLibraryUri()));
+//                             for (Item eq : P3DUtil.getEquipments(getLibraryUri())) {
+//                                     m.add(new AddEquipmentAction(rootNode, eq));
+//                             }
                        } else if (selected.size() == 1) {
                                IP3DNode node = (IP3DNode)selected.get(0);
                                if (node instanceof Equipment) {
                                        m.add(translateAction);
                                        m.add(rotateAction);
-                                       for (Item eq : P3DUtil.getNozzles(getLibraryUri())) {
+                                       for (Item eq : P3DUtil.getNozzles(Simantics.getSession(), getLibraryUri())) {
                                                AddNozzleAction add = new AddNozzleAction(rootNode, eq);
                                                add.setEquipment((Equipment)node);
                                                m.add(add);