1 /*******************************************************************************
\r
2 * Copyright (c) 2007 VTT Technical Research Centre of Finland and others.
\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 if (!(selection instanceof StructuredResourceSelection)) {
\r
109 StructuredResourceSelection s = (StructuredResourceSelection) selection;
\r
110 selectionAdapter.setCurrentSelection(s);
\r
111 viewChanged = true;
\r
113 //if (s.getRootSelection() == null) {
\r
114 if (!(part instanceof ProcessEditor)) {
\r
115 //System.out.println("ShapeEditorView.pageSelectionChanged() no root selection");
\r
116 ((ProcessEditorSelectionAdapter)selectionAdapter).setEditorSelection(true);
\r
119 //if (!s.getRootSelection().getResource().getId().equals(plant.getResource().getId())) {
\r
120 ProcessEditor sender = (ProcessEditor)part;
\r
121 if (!sender.getPlantResource().equals(plantResource)) {
\r
122 // System.out.println("ShapeEditorView.pageSelectionChanged() not right group "
\r
123 // + s.getRootSelection().getResource().getId() + " != " + model.getResource().getId());
\r
124 selectionAdapter.setCurrentSelection(new StructuredResourceSelection());
\r
125 ((ProcessEditorSelectionAdapter)selectionAdapter).setEditorSelection(false);
\r
128 selectionAdapter.setEditorSelection();
\r
133 protected void reloadFrom(IEntity thing) {
\r
134 if (plantResource != null) {
\r
135 throw new UnsupportedOperationException("Reloading instantiated viewer not supported");
\r
137 if (thing.isInstanceOf(ProcessResource.plant3Dresource.Plant)) {
\r
138 plantResource = thing.getResource();
\r
139 G3DNode plant = new G3DNode(thing);
\r
140 adapter.setRootNode(plant);
\r
141 //adapter.addOutbound(plant);
\r
142 ControlPointTools.reloadCache(thing.getGraph(),plant.getResource());
\r
144 throw new IllegalArgumentException("Resource is not a plant");
\r
148 public Resource getPlantResource() {
\r
149 return plantResource;
\r
152 public Plant getPlant(Graph g) {
\r
153 return new Plant(g, plantResource);
\r
157 protected SelectionAdapter createSelectionAdapter() {
\r
158 return new ProcessEditorSelectionAdapter(adapter);
\r
162 protected void hookDragAndDrop() {
\r
163 super.hookDragAndDrop();
\r
164 dropTarget.addDropListener(new InsertEquipmentAction(this));
\r
165 dropTarget.addDropListener(new InsertNozzleAction(this));
\r
166 dropTarget.addDropListener(new InsertComponentAction(this));
\r
167 dropTarget.addDropListener(new RoutePipeAction(this));
\r
171 public Object getAdapter(Class adapter) {
\r
172 if (adapter == IContentOutlinePage.class) {
\r
173 if (getPlantResource() == null)
\r
175 final PlantStructureOutlinePage page = new PlantStructureOutlinePage(sessionContext,getPlantResource());
\r
177 getSelectionAdapter().addSelectionChangedListener(new ISelectionChangedListener() {
\r
179 public void selectionChanged(SelectionChangedEvent event) {
\r
180 page.setSelection(event.getSelection());
\r
184 parent.getDisplay().asyncExec(new Runnable() {
\r
186 public void run() {
\r
187 page.addSelectionChangedListener(new ISelectionChangedListener() {
\r
189 public void selectionChanged(SelectionChangedEvent event) {
\r
190 selectionAdapter.setSelection(SelectionAdapter.transformSelection(event.getSelection()));
\r