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
9 * VTT Technical Research Centre of Finland - initial API and implementation
\r
10 *******************************************************************************/
\r
11 package org.simantics.processeditor.views;
\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
44 import com.jme.math.Vector3f;
\r
45 import com.jme.scene.Geometry;
\r
48 public class ProcessEditor extends ThreeDimensionalEditorBase {
\r
50 private Resource plantResource = null;
\r
52 private ConfigureFloorAction configureFloorAction = null;
\r
54 private Geometry floorShape = null;
\r
56 public ProcessEditor(ISessionContext session) {
\r
58 addEditorContribution(new PlantEditContribution(this));
\r
59 addEditorContribution(new PlantVisualizationContribution(this));
\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
69 protected ScenegraphAdapter createScenegraphAdapter() {
\r
70 return new ProcessEditorAdapter(this,session,getRenderingComponent());
\r
74 public void createControl(Graph graph,Composite parent) {
\r
75 super.createControl(graph,parent);
\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
84 protected void makeActions(Graph graph) {
\r
85 super.makeActions(graph);
\r
87 //actions.add(new ShowTrendsAction(this));
\r
89 configureFloorAction = new ConfigureFloorAction(this);
\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
97 protected void fillLocalPullDown() {
\r
98 super.fillLocalPullDown();
\r
99 MenuTools.getOrCreate(getMenuID(),"Advanced", menuManager).add(configureFloorAction);
\r
104 protected void pageSelectionChanged(IWorkbenchPart part, ISelection selection) {
\r
105 StructuredResourceSelection s = SelectionAdapter.transformSelection(selection);
\r
107 selectionAdapter.setCurrentSelection(s);
\r
108 viewChanged = true;
\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
121 selectionAdapter.setEditorSelection();
\r
126 protected void reloadFrom(IEntity thing) {
\r
127 if (plantResource != null) {
\r
128 throw new UnsupportedOperationException("Reloading instantiated viewer not supported");
\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
137 throw new IllegalArgumentException("Resource is not a plant");
\r
141 public Resource getPlantResource() {
\r
142 return plantResource;
\r
145 public Plant getPlant(Graph g) {
\r
146 return new Plant(g, plantResource);
\r
150 protected SelectionAdapter createSelectionAdapter() {
\r
151 return new ProcessEditorSelectionAdapter(adapter);
\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
164 public Object getAdapter(Class adapter) {
\r
165 if (adapter == IContentOutlinePage.class) {
\r
166 if (getPlantResource() == null)
\r
168 final PlantStructureOutlinePage page = new PlantStructureOutlinePage(sessionContext,getPlantResource());
\r
170 getSelectionAdapter().addSelectionChangedListener(new ISelectionChangedListener() {
\r
172 public void selectionChanged(SelectionChangedEvent event) {
\r
173 page.setSelection(event.getSelection());
\r
177 parent.getDisplay().asyncExec(new Runnable() {
\r
179 public void run() {
\r
180 page.addSelectionChangedListener(new ISelectionChangedListener() {
\r
182 public void selectionChanged(SelectionChangedEvent event) {
\r
183 selectionAdapter.setSelection(SelectionAdapter.transformSelection(event.getSelection()));
\r