]> gerrit.simantics Code Review - simantics/3d.git/blob
193fe45aecfc44e2e32f9d9e42c352ea05151dca
[simantics/3d.git] /
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
7  *\r
8  * Contributors:\r
9  *     VTT Technical Research Centre of Finland - initial API and implementation\r
10  *******************************************************************************/\r
11 package org.simantics.proconf.g3d.shapeeditor.actions;\r
12 \r
13 import org.eclipse.jface.action.Action;\r
14 import org.eclipse.swt.SWT;\r
15 import org.eclipse.swt.widgets.FileDialog;\r
16 import org.simantics.proconf.g3d.base.ThreeDimensionalEditorBase;\r
17 import org.simantics.proconf.g3d.occ.geometry.OccTriangulator;\r
18 \r
19 import com.jme.renderer.ColorRGBA;\r
20 import com.jme.scene.Geometry;\r
21 import com.jme.scene.state.MaterialState;\r
22 \r
23 \r
24 public class LoadFileAction extends Action {\r
25         private ThreeDimensionalEditorBase editor;\r
26         \r
27         public LoadFileAction(ThreeDimensionalEditorBase editor) {\r
28                 super("Load file");\r
29                 this.editor = editor;\r
30                 \r
31         }\r
32         \r
33         public void run() {\r
34         FileDialog loadDialog = new FileDialog(editor.getRenderingComposite().getShell(), SWT.OPEN);\r
35         String exts[] = { "*.stp;*.step", "*.iges", "*.brep", "*.ply" }; //$NON-NLS-1$\r
36         String names[] = { "STEP (AP214/AP203)", "IGES", "BREP", "PLY" }; //$NON-NLS-1$\r
37         loadDialog.setFilterNames(names);\r
38         loadDialog.setFilterExtensions(exts);\r
39         loadDialog.setText("Load model");\r
40 \r
41         String filename = loadDialog.open();\r
42         if (filename != null) {\r
43             Geometry g = OccTriangulator.getGeometryFromFile(filename)[0];\r
44             MaterialState ms = editor.getRenderingComponent().getDisplaySystem().getRenderer().createMaterialState();\r
45             ms.setAmbient(new ColorRGBA(0.f,0.f,0.f,0.f));\r
46             ms.setEmissive(new ColorRGBA(0.f,0.f,0.f,0.f));\r
47             ms.setShininess(128.f);\r
48             ms.setDiffuse(new ColorRGBA(0.8f,0.8f,0.8f,0.f));\r
49             ms.setSpecular(new ColorRGBA(1.f,1.f,1.f,0.f));\r
50             ms.setMaterialFace(MaterialState.MF_FRONT_AND_BACK);\r
51             if (g.getColorBuffer(0) != null) {\r
52                 ms.setColorMaterial(MaterialState.CM_DIFFUSE);\r
53             }\r
54             g.setRenderState(ms);\r
55             editor.getRenderingComponent().getShadowRoot().attachChild(g);\r
56             // mo.setGeometry(mesh, filename);\r
57             // xithComposite.getScene().compile();\r
58         }\r
59 \r
60     }\r
61 \r
62 }\r