]> gerrit.simantics Code Review - simantics/3d.git/blob - org.simantics.proconf.processeditor/src/org/simantics/processeditor/views/ProcessEditor.java
Set copyright texts for java files in the latest development branches.
[simantics/3d.git] / org.simantics.proconf.processeditor / src / org / simantics / processeditor / views / ProcessEditor.java
1 /*******************************************************************************\r
2  * Copyright (c) 2007- VTT Technical Research Centre of Finland.\r
3  * All rights reserved. This program and the accompanying materials\r
4  * are made available under the terms of the Eclipse Public License v1.0\r
5  * which accompanies this distribution, and is available at\r
6  * http://www.eclipse.org/legal/epl-v10.html\r
7  *\r
8  * Contributors:\r
9  *     VTT Technical Research Centre of Finland - initial API and implementation\r
10  *******************************************************************************/\r
11 package org.simantics.processeditor.views;\r
12 \r
13 import org.eclipse.jface.viewers.ISelection;\r
14 import org.eclipse.jface.viewers.ISelectionChangedListener;\r
15 import org.eclipse.jface.viewers.SelectionChangedEvent;\r
16 import org.eclipse.swt.widgets.Composite;\r
17 import org.eclipse.ui.IWorkbenchPart;\r
18 import org.eclipse.ui.views.contentoutline.IContentOutlinePage;\r
19 import org.simantics.db.Graph;\r
20 import org.simantics.db.Resource;\r
21 import org.simantics.db.management.ISessionContext;\r
22 import org.simantics.layer0.utils.IEntity;\r
23 import org.simantics.processeditor.ProcessResource;\r
24 import org.simantics.processeditor.actions.ConfigureFloorAction;\r
25 import org.simantics.processeditor.actions.InsertComponentAction;\r
26 import org.simantics.processeditor.actions.InsertEquipmentAction;\r
27 import org.simantics.processeditor.actions.InsertNozzleAction;\r
28 import org.simantics.processeditor.actions.RoutePipeAction;\r
29 import org.simantics.processeditor.adapters.ProcessEditorAdapter;\r
30 import org.simantics.processeditor.adapters.ProcessEditorSelectionAdapter;\r
31 import org.simantics.processeditor.common.ControlPointTools;\r
32 import org.simantics.processeditor.stubs.Plant;\r
33 import org.simantics.processeditor.tools.PlantEditContribution;\r
34 import org.simantics.processeditor.tools.PlantVisualizationContribution;\r
35 import org.simantics.proconf.g3d.base.JmeRenderingComponent;\r
36 import org.simantics.proconf.g3d.base.ScenegraphAdapter;\r
37 import org.simantics.proconf.g3d.base.SelectionAdapter;\r
38 import org.simantics.proconf.g3d.base.ThreeDimensionalEditorBase;\r
39 import org.simantics.proconf.g3d.common.StructuredResourceSelection;\r
40 import org.simantics.proconf.g3d.shapes.FloorShape;\r
41 import org.simantics.proconf.g3d.stubs.G3DNode;\r
42 import org.simantics.utils.ui.jface.MenuTools;\r
43 \r
44 import com.jme.math.Vector3f;\r
45 import com.jme.scene.Geometry;\r
46 \r
47 \r
48 public class ProcessEditor extends ThreeDimensionalEditorBase {\r
49     \r
50     private Resource plantResource = null;\r
51     \r
52     private ConfigureFloorAction configureFloorAction = null;\r
53 \r
54     private Geometry floorShape = null;\r
55 \r
56     public ProcessEditor(ISessionContext session) {\r
57         super(session);\r
58         addEditorContribution(new PlantEditContribution(this));\r
59         addEditorContribution(new PlantVisualizationContribution(this));\r
60     }\r
61     \r
62     public ProcessEditor(ISessionContext session,JmeRenderingComponent component) {\r
63         super(session,component);\r
64         addEditorContribution(new PlantEditContribution(this));\r
65         addEditorContribution(new PlantVisualizationContribution(this));\r
66     }\r
67     \r
68     @Override\r
69     protected ScenegraphAdapter createScenegraphAdapter() {\r
70         return new ProcessEditorAdapter(this,session,getRenderingComponent());\r
71     }\r
72     \r
73     @Override\r
74     public void createControl(Graph graph,Composite parent) {\r
75         super.createControl(graph,parent);\r
76 \r
77         floorShape = FloorShape.getShape(getRenderingComponent().getDisplaySystem().getRenderer(), 100.f,0.2f);\r
78         getRenderingComponent().getNoCastRoot().attachChild(floorShape);\r
79         floorShape.setLocalTranslation(new Vector3f(0.f,-0.01f,0.f));\r
80         configureFloorAction.setFloorShape(floorShape);\r
81     }\r
82 \r
83     @Override\r
84     protected void makeActions(Graph graph) {\r
85         super.makeActions(graph);\r
86 \r
87         //actions.add(new ShowTrendsAction(this));\r
88 \r
89         configureFloorAction = new ConfigureFloorAction(this);\r
90 \r
91 //        ContextActionFactory extended[] = ContextActionRegistry.getActions("fi.vtt.proconf.shapeeditor.processeditorview");\r
92 //        for (ContextActionFactory c : extended) {\r
93 //              actions.add(c.createAction(this));\r
94 //        }\r
95     }\r
96     \r
97     protected void fillLocalPullDown() {\r
98         super.fillLocalPullDown();\r
99         MenuTools.getOrCreate(getMenuID(),"Advanced", menuManager).add(configureFloorAction);\r
100     }\r
101     \r
102 \r
103     @Override\r
104     protected void pageSelectionChanged(IWorkbenchPart part, ISelection selection) {\r
105         StructuredResourceSelection s = SelectionAdapter.transformSelection(selection);\r
106 \r
107         selectionAdapter.setCurrentSelection(s);\r
108         viewChanged = true;\r
109 \r
110         /*\r
111         if (part instanceof ProcessEditor) {\r
112                 ProcessEditor sender = (ProcessEditor)part;\r
113             if (!sender.getPlantResource().equals(plantResource)) {\r
114                 selectionAdapter.setCurrentSelection(new StructuredResourceSelection());\r
115                 selectionAdapter.setEditorSelection();\r
116               return;\r
117             }\r
118         } \r
119                 */\r
120         \r
121         selectionAdapter.setEditorSelection();\r
122         \r
123     }\r
124 \r
125     @Override\r
126     protected void reloadFrom(IEntity thing) {\r
127         if (plantResource != null) {\r
128             throw new UnsupportedOperationException("Reloading instantiated viewer not supported");\r
129         }\r
130         if (thing.isInstanceOf(ProcessResource.plant3Dresource.Plant)) {\r
131             plantResource = thing.getResource();\r
132             G3DNode plant = new G3DNode(thing);\r
133             adapter.setRootNode(plant);\r
134             //adapter.addOutbound(plant);\r
135             ControlPointTools.reloadCache(thing.getGraph(),plant.getResource());\r
136         } else {\r
137             throw new IllegalArgumentException("Resource is not a plant");\r
138         } \r
139     }\r
140 \r
141     public Resource getPlantResource() {\r
142         return plantResource;\r
143     }\r
144     \r
145     public Plant getPlant(Graph g) {\r
146         return new Plant(g, plantResource);\r
147     }\r
148     \r
149     @Override\r
150     protected SelectionAdapter createSelectionAdapter() {\r
151         return new ProcessEditorSelectionAdapter(adapter);\r
152     }\r
153 \r
154     @Override\r
155     protected void hookDragAndDrop() {\r
156         super.hookDragAndDrop();\r
157         dropTarget.addDropListener(new InsertEquipmentAction(this));\r
158         dropTarget.addDropListener(new InsertNozzleAction(this));\r
159         dropTarget.addDropListener(new InsertComponentAction(this));\r
160         dropTarget.addDropListener(new RoutePipeAction(this));\r
161     }\r
162     \r
163     @Override\r
164         public Object getAdapter(Class adapter) {\r
165                 if (adapter == IContentOutlinePage.class) {\r
166                         if (getPlantResource() == null)\r
167                                 return null;\r
168                         final PlantStructureOutlinePage page = new PlantStructureOutlinePage(sessionContext,getPlantResource());\r
169                         \r
170                         getSelectionAdapter().addSelectionChangedListener(new ISelectionChangedListener() {\r
171                                 @Override\r
172                                 public void selectionChanged(SelectionChangedEvent event) {\r
173                                         page.setSelection(event.getSelection());\r
174                                         \r
175                                 }\r
176                         });\r
177                         parent.getDisplay().asyncExec(new Runnable() {\r
178                                 @Override\r
179                                 public void run() {\r
180                                         page.addSelectionChangedListener(new ISelectionChangedListener() {\r
181                                                 @Override\r
182                                                 public void selectionChanged(SelectionChangedEvent event) {\r
183                                                         selectionAdapter.setSelection(SelectionAdapter.transformSelection(event.getSelection()));\r
184                                                 }\r
185                                         });\r
186                                 }\r
187                         });\r
188 \r
189                         return page;\r
190                 }\r
191                 return null;\r
192         }\r
193 }