]> gerrit.simantics Code Review - simantics/3d.git/blobdiff - org.simantics.processeditor/src/org/simantics/processeditor/tools/PlantEditContribution.java
Removing ancient 3d framework
[simantics/3d.git] / org.simantics.processeditor / src / org / simantics / processeditor / tools / PlantEditContribution.java
diff --git a/org.simantics.processeditor/src/org/simantics/processeditor/tools/PlantEditContribution.java b/org.simantics.processeditor/src/org/simantics/processeditor/tools/PlantEditContribution.java
deleted file mode 100644 (file)
index beaf9f4..0000000
+++ /dev/null
@@ -1,340 +0,0 @@
-/*******************************************************************************\r
- * Copyright (c) 2007- VTT Technical Research Centre of Finland.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- *     VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.processeditor.tools;\r
-\r
-import java.util.ArrayList;\r
-import java.util.Collection;\r
-import java.util.Iterator;\r
-import java.util.List;\r
-\r
-import org.eclipse.jface.action.Action;\r
-import org.eclipse.jface.action.IMenuManager;\r
-import org.eclipse.jface.action.IToolBarManager;\r
-import org.eclipse.jface.dialogs.MessageDialog;\r
-import org.eclipse.swt.SWT;\r
-import org.eclipse.swt.layout.FormAttachment;\r
-import org.eclipse.swt.layout.FormData;\r
-import org.eclipse.swt.layout.FormLayout;\r
-import org.eclipse.swt.layout.GridData;\r
-import org.eclipse.swt.layout.GridLayout;\r
-import org.eclipse.swt.widgets.Composite;\r
-import org.eclipse.swt.widgets.Text;\r
-import org.simantics.db.Graph;\r
-import org.simantics.db.GraphRequestStatus;\r
-import org.simantics.db.Resource;\r
-import org.simantics.layer0.utils.EntityFactory;\r
-import org.simantics.layer0.utils.IEntity;\r
-import org.simantics.processeditor.Activator;\r
-import org.simantics.processeditor.ProcessResource;\r
-import org.simantics.processeditor.actions.InsertComponentAction;\r
-import org.simantics.processeditor.actions.InsertEquipmentAction;\r
-import org.simantics.processeditor.actions.InsertNozzleAction;\r
-import org.simantics.processeditor.actions.ReversePipelineAction;\r
-import org.simantics.processeditor.actions.RoutePipeAction;\r
-import org.simantics.processeditor.actions.TranslateElbowAction;\r
-import org.simantics.processeditor.actions.TranslateInlineComponentAction;\r
-import org.simantics.processeditor.actions.TranslateStraightAction;\r
-import org.simantics.processeditor.common.ControlPointTools;\r
-import org.simantics.processeditor.stubs.InlineComponent;\r
-import org.simantics.processeditor.stubs.PipeControlPoint;\r
-import org.simantics.proconf.g3d.actions.ContextAction;\r
-import org.simantics.proconf.g3d.actions.FocusAction;\r
-import org.simantics.proconf.g3d.actions.RemoveAction;\r
-import org.simantics.proconf.g3d.actions.RotateAction;\r
-import org.simantics.proconf.g3d.actions.TranslateAction;\r
-import org.simantics.proconf.g3d.base.EditorContribution;\r
-import org.simantics.proconf.g3d.base.ThreeDimensionalEditorBase;\r
-import org.simantics.proconf.g3d.common.StructuredResourceSelection;\r
-import org.simantics.utils.ui.jface.MenuTools;\r
-\r
-import com.jme.intersection.CollisionData;\r
-import com.jme.intersection.CollisionResults;\r
-import com.jme.intersection.TriangleCollisionResults;\r
-import com.jme.scene.Geometry;\r
-import com.jme.scene.Node;\r
-import com.jme.scene.Spatial;\r
-\r
-\r
-public class PlantEditContribution implements EditorContribution {\r
-       private List<ContextAction> actions = new ArrayList<ContextAction>();\r
-       private ThreeDimensionalEditorBase parent;\r
-       private Composite infoComposite;\r
-       private Text infoText;\r
-       \r
-       private Action checkInterferencesAction = null;\r
-       \r
-       public PlantEditContribution(ThreeDimensionalEditorBase parent) {\r
-               this.parent = parent;\r
-       }\r
-       \r
-       @Override\r
-       public void createControl(Composite parent) {\r
-               FormLayout flayout = new FormLayout();\r
-               parent.setLayout(flayout);\r
-               infoComposite = new Composite(parent, SWT.BORDER);\r
-               FormData data = new FormData();\r
-               data.top = new FormAttachment(0, 0);\r
-               data.left = new FormAttachment(0, 0);\r
-               data.right = new FormAttachment(100, 0);\r
-               data.bottom = new FormAttachment(infoComposite, 0, SWT.TOP);\r
-               this.parent.getRenderingComposite().setLayoutData(data);\r
-               data = new FormData();\r
-               data.left = new FormAttachment(0, 0);\r
-               data.right = new FormAttachment(100, 0);\r
-               data.bottom = new FormAttachment(100, 0);\r
-               data.height = 18;\r
-               infoComposite.setLayoutData(data);\r
-               GridLayout layout = new GridLayout(1,false);\r
-               layout.marginWidth = 1;\r
-               layout.marginHeight = 1;\r
-               infoComposite.setLayout(layout);\r
-               infoText = new Text(infoComposite, SWT.NONE);\r
-               GridData gdata = new GridData();\r
-               gdata.grabExcessHorizontalSpace = true;\r
-               gdata.horizontalAlignment = SWT.FILL;\r
-               infoText.setLayoutData(gdata);\r
-               \r
-       }\r
-       \r
-       @Override\r
-       public void disposeControl() {\r
-               infoComposite.dispose();\r
-               \r
-       }\r
-       \r
-       @Override\r
-       public void dispose() {\r
-\r
-       }\r
-       \r
-       \r
-       \r
-       @Override\r
-       public void fillContextMenu(Graph graph, IMenuManager manager,\r
-                       StructuredResourceSelection selection) {\r
-\r
-       }\r
-       \r
-       @Override\r
-       public void fillLocalPullDown(IMenuManager manager) {\r
-               MenuTools.getOrCreate(parent.getMenuID(),"Advanced", manager).add(checkInterferencesAction);\r
-               \r
-       }\r
-       \r
-       @Override\r
-       public void fillLocalToolBar(IToolBarManager manager) {\r
-\r
-       }\r
-       \r
-       @Override\r
-       public Collection<ContextAction> getActions() {\r
-               return actions;\r
-       }\r
-       \r
-       @Override\r
-       public String getName() {\r
-               return "Plant Editing";\r
-       }\r
-       \r
-       @Override\r
-       public void initialize(Graph graph) {\r
-               actions.add(new TranslateAction(parent){\r
-            @Override\r
-            public boolean usable(Graph graph,List<Resource> resources) {\r
-                if (super.usable(graph, resources)) {\r
-                    for (Resource r : resources) {\r
-                       // FIXME : use new ontology :\r
-                       // 1. lose ends works like end components (just what this code does, but type checks are not correct)\r
-                       // 2. connected components are moved inline. (TranslateInlineAction)\r
-                       IEntity t = EntityFactory.create(graph, r);\r
-                        if (t.isInstanceOf(ProcessResource.plant3Dresource.InlineComponent)) {\r
-                            InlineComponent component = new InlineComponent(t);\r
-                               PipeControlPoint pcp = component.getControlPoint();\r
-                               if (pcp.getNext() != null && pcp.getPrevious() != null)\r
-                                       return false;\r
-                        }\r
-                    }\r
-                    return true;\r
-                }\r
-                return false;\r
-            }\r
-            \r
-            @Override\r
-            public void setInfoText(String text) {\r
-               infoText.setText(text);\r
-            }\r
-        });\r
-        actions.add(new TranslateInlineComponentAction(parent) {\r
-               @Override\r
-               public void setInfoText(String text) {\r
-                       infoText.setText(text);\r
-               }\r
-        });\r
-        actions.add(new TranslateStraightAction(parent) {\r
-               @Override\r
-               public void setInfoText(String text) {\r
-                       infoText.setText(text);\r
-               }\r
-        });\r
-        actions.add(new TranslateElbowAction(parent) {\r
-               @Override\r
-               public void setInfoText(String text) {\r
-                       infoText.setText(text);\r
-               }\r
-        });\r
-        actions.add(new RotateAction(parent){\r
-            @Override\r
-            public boolean usable(Graph graph,List<Resource> resources) {\r
-                if (super.usable(graph,resources)) {\r
-                    for (Resource r : resources) {\r
-                       IEntity t = EntityFactory.create(graph,r);\r
-                       // FIXME : use new ontology\r
-                       // TODO : create rotate action that can rotate inline components\r
-                       // TODO : ontology change: pipes and similar components cannot be rotated, since there is no point to do that.\r
-                       if (t.isInstanceOf(ProcessResource.plant3Dresource.InlineComponent)) {\r
-                               return false;\r
-                       }\r
-                    }\r
-                    return true;\r
-                }\r
-                \r
-                return false;\r
-            }\r
-            \r
-            @Override\r
-            public void setInfoText(String text) {\r
-               infoText.setText(text);\r
-            }\r
-        });\r
-        actions.add(new RemoveAction(parent) {\r
-               @Override\r
-                       public GraphRequestStatus doChanges(Graph graph) {\r
-                               Iterator<Resource> i = parent.getSelectionAdapter().getCurrentSelection().iterator();\r
-                               while (i.hasNext()) {\r
-                                               Resource s = i.next();\r
-                                               IEntity r = EntityFactory.create(graph, s);\r
-                                               if (r.isInstanceOf(ProcessResource.g3dResource.G3DNode)) {\r
-                                                       Collection<IEntity> parentNode= r.getRelatedObjects(ProcessResource.g3dResource.HasParent);\r
-                                                       if (parentNode.size() == 1) {\r
-                                                               Collection<IEntity> rs = r.getRelatedObjects(ProcessResource.plant3Dresource.HasControlPoint);\r
-                                                               for (IEntity cp  : rs) {\r
-                                                                       ControlPointTools.removeControlPoint(new PipeControlPoint(cp));\r
-                                                               }\r
-                                                               r.removeRelatedStatements(ProcessResource.g3dResource.HasParent);\r
-                                                       } else {\r
-                                                               if (parentNode.size() == 0) {\r
-                                                                       parent.showMessage("Object has no parent, don't know what to do!");\r
-                                                               } else {\r
-                                                                       parent.showMessage("Object has more than one parent, don't know what to do!");\r
-                                                               }\r
-                                                       }\r
-                                               }\r
-\r
-                                       }\r
-                                       //parent.getSelectionAdapter().setSelection(new StructuredResourceSelection());\r
-                               return GraphRequestStatus.transactionComplete();\r
-                       }\r
-               });\r
-        actions.add(new FocusAction(parent));\r
-        actions.add(new RoutePipeAction(parent){\r
-               @Override\r
-               public void setInfoText(String text) {\r
-                       infoText.setText(text);\r
-               }\r
-        });   \r
-        actions.add(new InsertComponentAction(parent));\r
-        actions.add(new InsertEquipmentAction(parent));\r
-        actions.add(new InsertNozzleAction(parent));\r
-        actions.add(new ReversePipelineAction(parent));\r
-        \r
-        checkInterferencesAction = new Action() {\r
-               public void run() {\r
-                       CollisionResults results = new TriangleCollisionResults();\r
-                       //getRenderingComponent().getNormalRoot().calculateCollisions(getRenderingComponent().getNormalRoot(), results);\r
-                       collide(parent.getRenderingComponent().getShadowRoot(),parent.getRenderingComponent().getShadowRoot(),results);\r
-                       results = filterResults(results);\r
-                       for (int i = 0; i < results.getNumber(); i++) {\r
-                               CollisionData data = results.getCollisionData(i);\r
-                               Geometry s =  data.getSourceMesh();\r
-                               Geometry t = data.getTargetMesh();\r
-                               MessageDialog dialog = new MessageDialog(parent.getRenderingComposite().getShell(),"Interference " + i + " / " + results.getNumber(), null, "Interference between " + s + " and " + t,MessageDialog.WARNING,new String[]{"Next","Cancel"},0);\r
-                               try {\r
-                                       Resource sid = parent.getScenegraphAdapter().getNodeResource(s.getName());\r
-                                       Resource tid = parent.getScenegraphAdapter().getNodeResource(t.getName());\r
-\r
-                                       StructuredResourceSelection sel = new StructuredResourceSelection();\r
-                                       if (sid == tid) {\r
-                                               sel.add(sid);\r
-                                       } else {\r
-                                               sel.add(sid);\r
-                                               sel.add(tid);\r
-                                       }\r
-                                       parent.getSelectionAdapter().setSelection(sel);\r
-                               } catch(NumberFormatException e) {\r
-                                       \r
-                               }\r
-                               if (dialog.open() == 1)\r
-                                       break;\r
-                       }\r
-               }\r
-               \r
-               private void collide(Spatial s, Spatial p, CollisionResults r) {\r
-                       s.calculateCollisions(p, r);\r
-                       if (s instanceof Node) {\r
-                               Node n = (Node)s;\r
-                               for (Spatial t : n.getChildren())\r
-                                       collide(t,p,r);\r
-                       }\r
-               }\r
-               \r
-               private CollisionResults filterResults(CollisionResults results) {\r
-                       CollisionResults r = new TriangleCollisionResults();\r
-                       for (int i = 0; i < results.getNumber(); i++) {\r
-                               CollisionData d = results.getCollisionData(i);\r
-                               if (d.getSourceMesh() == d.getTargetMesh())\r
-                                       continue;\r
-                               boolean found = false;\r
-                               for (int j = 0; j < r.getNumber(); j++) {\r
-                                       CollisionData d2 = r.getCollisionData(j);\r
-                                       if (d2.getSourceMesh() == d.getSourceMesh() &&\r
-                                               d2.getTargetMesh() == d.getTargetMesh()) {\r
-                                               found = true;\r
-                                               break;\r
-                                       }\r
-                                       if (d2.getSourceMesh() == d.getTargetMesh() &&\r
-                                       d2.getTargetMesh() == d.getSourceMesh()) {\r
-                                       found = true;\r
-                                       break;\r
-                               }               \r
-                               }\r
-                               if (!found) {\r
-                                       if (d.getSourceTris().size() == 0)\r
-                                               continue;\r
-                                       if (d.getTargetTris().size() == 0)\r
-                                               continue;\r
-                                       r.addCollisionData(d);\r
-                               }\r
-                       }\r
-                       return r;\r
-               }\r
-\r
-        };\r
-        checkInterferencesAction.setText("Interferences");\r
-        checkInterferencesAction.setImageDescriptor(Activator.imageDescriptorFromPlugin("fi.vtt.proconf.ode", "icons/silk/delete.png"));\r
-        \r
-       }\r
-       \r
-       @Override\r
-       public void run() {\r
-               \r
-       }\r
-\r
-}\r