X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.proconf.g3d.shapeeditor%2Fsrc%2Forg%2Fsimantics%2Fproconf%2Fg3d%2Fshapeeditor%2Factions%2FLoadFileAction.java;fp=org.simantics.proconf.g3d.shapeeditor%2Fsrc%2Forg%2Fsimantics%2Fproconf%2Fg3d%2Fshapeeditor%2Factions%2FLoadFileAction.java;h=193fe45aecfc44e2e32f9d9e42c352ea05151dca;hb=477a3eae417fe71addfcf8f87dab41f87151a384;hp=0000000000000000000000000000000000000000;hpb=d0db32bb067d2a7c323054295f6356bdb42078c9;p=simantics%2F3d.git diff --git a/org.simantics.proconf.g3d.shapeeditor/src/org/simantics/proconf/g3d/shapeeditor/actions/LoadFileAction.java b/org.simantics.proconf.g3d.shapeeditor/src/org/simantics/proconf/g3d/shapeeditor/actions/LoadFileAction.java new file mode 100644 index 00000000..193fe45a --- /dev/null +++ b/org.simantics.proconf.g3d.shapeeditor/src/org/simantics/proconf/g3d/shapeeditor/actions/LoadFileAction.java @@ -0,0 +1,62 @@ +/******************************************************************************* + * Copyright (c) 2007 VTT Technical Research Centre of Finland and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.proconf.g3d.shapeeditor.actions; + +import org.eclipse.jface.action.Action; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.FileDialog; +import org.simantics.proconf.g3d.base.ThreeDimensionalEditorBase; +import org.simantics.proconf.g3d.occ.geometry.OccTriangulator; + +import com.jme.renderer.ColorRGBA; +import com.jme.scene.Geometry; +import com.jme.scene.state.MaterialState; + + +public class LoadFileAction extends Action { + private ThreeDimensionalEditorBase editor; + + public LoadFileAction(ThreeDimensionalEditorBase editor) { + super("Load file"); + this.editor = editor; + + } + + public void run() { + FileDialog loadDialog = new FileDialog(editor.getRenderingComposite().getShell(), SWT.OPEN); + String exts[] = { "*.stp;*.step", "*.iges", "*.brep", "*.ply" }; //$NON-NLS-1$ + String names[] = { "STEP (AP214/AP203)", "IGES", "BREP", "PLY" }; //$NON-NLS-1$ + loadDialog.setFilterNames(names); + loadDialog.setFilterExtensions(exts); + loadDialog.setText("Load model"); + + String filename = loadDialog.open(); + if (filename != null) { + Geometry g = OccTriangulator.getGeometryFromFile(filename)[0]; + MaterialState ms = editor.getRenderingComponent().getDisplaySystem().getRenderer().createMaterialState(); + ms.setAmbient(new ColorRGBA(0.f,0.f,0.f,0.f)); + ms.setEmissive(new ColorRGBA(0.f,0.f,0.f,0.f)); + ms.setShininess(128.f); + ms.setDiffuse(new ColorRGBA(0.8f,0.8f,0.8f,0.f)); + ms.setSpecular(new ColorRGBA(1.f,1.f,1.f,0.f)); + ms.setMaterialFace(MaterialState.MF_FRONT_AND_BACK); + if (g.getColorBuffer(0) != null) { + ms.setColorMaterial(MaterialState.CM_DIFFUSE); + } + g.setRenderState(ms); + editor.getRenderingComponent().getShadowRoot().attachChild(g); + // mo.setGeometry(mesh, filename); + // xithComposite.getScene().compile(); + } + + } + +}