]> gerrit.simantics Code Review - simantics/3d.git/blobdiff - org.simantics.processeditor/src/org/simantics/processeditor/monitors/TextMonitor.java
Removing ancient 3d framework
[simantics/3d.git] / org.simantics.processeditor / src / org / simantics / processeditor / monitors / TextMonitor.java
diff --git a/org.simantics.processeditor/src/org/simantics/processeditor/monitors/TextMonitor.java b/org.simantics.processeditor/src/org/simantics/processeditor/monitors/TextMonitor.java
deleted file mode 100644 (file)
index 39ab07d..0000000
+++ /dev/null
@@ -1,272 +0,0 @@
-/*******************************************************************************\r
- * Copyright (c) 2007- VTT Technical Research Centre of Finland.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- *     VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.processeditor.monitors;\r
-\r
-import java.net.URL;\r
-import java.util.ArrayList;\r
-\r
-import javax.vecmath.Point3d;\r
-import javax.vecmath.Vector3d;\r
-\r
-import org.eclipse.core.runtime.FileLocator;\r
-import org.eclipse.core.runtime.Path;\r
-import org.eclipse.swt.graphics.Rectangle;\r
-import org.simantics.db.Graph;\r
-import org.simantics.processeditor.ProcessResource;\r
-import org.simantics.processeditor.stubs.InlineComponent;\r
-import org.simantics.proconf.g3d.base.G3DTools;\r
-import org.simantics.proconf.g3d.base.MathTools;\r
-import org.simantics.proconf.g3d.base.ThreeDimensionalEditorBase;\r
-import org.simantics.proconf.g3d.base.VecmathJmeTools;\r
-import org.simantics.proconf.g3d.scenegraph.IGraphicsNode;\r
-import org.simantics.proconf.g3d.stubs.G3DNode;\r
-\r
-import com.jme.image.Texture;\r
-import com.jme.math.Vector2f;\r
-import com.jme.math.Vector3f;\r
-import com.jme.renderer.ColorRGBA;\r
-import com.jme.renderer.Renderer;\r
-import com.jme.scene.Node;\r
-import com.jme.scene.Text;\r
-import com.jme.scene.shape.Quad;\r
-import com.jme.scene.state.AlphaState;\r
-import com.jme.scene.state.MaterialState;\r
-import com.jme.scene.state.RenderState;\r
-import com.jme.scene.state.TextureState;\r
-import com.jme.util.TextureManager;\r
-\r
-\r
-/**\r
- * A monitor implemetation that uses JME's text component to show it's information. \r
- * \r
- * @author Marko Luukkainen\r
- *\r
- */\r
-public class TextMonitor implements Monitor {\r
-       private enum Type{POSITION,PIPE};\r
-       private Type type;\r
-       \r
-       public static String fontLocation = "data/textures/tahoma512.png";\r
-    \r
-       \r
-       private ThreeDimensionalEditorBase editor;\r
-       private ArrayList<Text> texts = new ArrayList<Text>();\r
-       private Node monitorNode = new Node("");\r
-       Node textNode;\r
-       private IGraphicsNode node = null;\r
-       \r
-    Point3d start;\r
-    Point3d end;\r
-    Point3d middle;\r
-    \r
-    float width = 0.f;\r
-    float height = 0.f;\r
-    float textHeight = 0.f;\r
-    \r
-    Quad background;\r
-    \r
-    private MonitorTextProvider provider = new ObjectPropertyProvider();\r
-       \r
-       public TextMonitor(ThreeDimensionalEditorBase editor) {\r
-               this.editor = editor;\r
-               textNode = new Node("");\r
-               \r
-               \r
-               \r
-               AlphaState as1 = editor.getRenderingComponent().getDisplaySystem().getRenderer().createAlphaState();\r
-        as1.setBlendEnabled(true);\r
-        as1.setSrcFunction(AlphaState.SB_SRC_ALPHA);\r
-        as1.setDstFunction(AlphaState.DB_ONE_MINUS_SRC_ALPHA);\r
-        as1.setTestEnabled(true);\r
-        as1.setTestFunction(AlphaState.TF_GREATER);\r
-        as1.setEnabled(true);\r
-        \r
-        MaterialState ms = editor.getRenderingComponent().getDisplaySystem().getRenderer().createMaterialState();\r
-        ms.setEmissive(new ColorRGBA(0.f,1.f,0.f,0.f));\r
-        \r
-        TextureState font = editor.getRenderingComponent().getDisplaySystem().getRenderer().createTextureState();\r
-        /** The texture is loaded from fontLocation */\r
-        font.setTexture(loadFontTexture());\r
-        font.setEnabled(true);\r
-        textNode.setRenderState(font);\r
-        textNode.setRenderState(as1);\r
-        textNode.setRenderState(ms);\r
-        background = new Quad("",100.f,100.f);\r
-        \r
-        MaterialState ms2 = editor.getRenderingComponent().getDisplaySystem().getRenderer().createMaterialState();\r
-        ms2.setEmissive(new ColorRGBA(0.f,0.f,0.f,0.8f));\r
-        ms2.setDiffuse(new ColorRGBA(0.f,0.f,0.f,0.8f));\r
-\r
-        AlphaState as2 = editor.getRenderingComponent().getDisplaySystem().getRenderer().createAlphaState();\r
-        as2.setBlendEnabled(true);\r
-        as2.setSrcFunction(AlphaState.SB_SRC_ALPHA);\r
-        as2.setDstFunction(AlphaState.DB_ONE_MINUS_SRC_ALPHA);\r
-        as2.setTestEnabled(true);\r
-        as2.setTestFunction(AlphaState.TF_GREATER);\r
-        as2.setEnabled(true);\r
-        monitorNode.setRenderState(ms2);\r
-        monitorNode.setRenderState(as2);\r
-        \r
-        background.setRenderQueueMode(Renderer.QUEUE_ORTHO);\r
-        textNode.setRenderQueueMode(Renderer.QUEUE_ORTHO);\r
-        \r
-        monitorNode.attachChild(background);\r
-        monitorNode.attachChild(textNode);\r
-       // editor.getRenderingComponent().getOrthoNode().attachChild(monitorNode);\r
-        \r
-               \r
-       }\r
-       \r
-       public boolean acceptNode(Graph graph,IGraphicsNode node) {\r
-               G3DNode n = node.getG3DNode(graph);\r
-               if (this.node == null || !node.equals(this.node)) {\r
-                       if (n.getLocalPosition() != null) {\r
-                               return true;\r
-                       } else if (n.isInstanceOf(ProcessResource.plant3Dresource.VariableLengthInlineComponent)) {\r
-                               return true;\r
-                       }\r
-               }\r
-\r
-               return false;\r
-\r
-       }\r
-       \r
-       public void setNode(Graph graph, IGraphicsNode node) {\r
-               G3DNode n = node.getG3DNode(graph);\r
-               if (n.getLocalPosition() != null) {\r
-                       type = Type.POSITION;\r
-               } else if (n.isInstanceOf(ProcessResource.plant3Dresource.VariableLengthInlineComponent)) {\r
-                       type = Type.PIPE;\r
-                       InlineComponent ic = new InlineComponent(n);\r
-                       start = G3DTools.getPoint(ic.getControlPoint().getPrevious().getWorldPosition());\r
-                       end = G3DTools.getPoint(ic.getControlPoint().getNext().getWorldPosition());\r
-                       Vector3d dir = new Vector3d(end);\r
-                       dir.sub(start);\r
-                       dir.scale(0.5);\r
-                       middle = new Point3d(start);\r
-                       middle.add(dir);\r
-               } else {\r
-                       return;\r
-               }\r
-               \r
-               this.node = node;\r
-               provider.setSource(n);\r
-               ArrayList<String> titles = provider.getTexts(graph);\r
-               \r
-               for (int i = titles.size() - 1; i < texts.size(); i++) {\r
-                       texts.get(i).removeFromParent();\r
-               }\r
-               while (texts.size() < titles.size()) {\r
-                       Text text = new Text("", "");\r
-                       texts.add(text);\r
-                       textNode.attachChild(text);\r
-               }\r
-               width = 0.f;\r
-               height = 0.f;\r
-               for (int i = 0; i < titles.size(); i++) {\r
-                       Text text = texts.get(i);\r
-                       text.print(titles.get(i));\r
-                       width = Math.max(width,text.getWidth());\r
-                       textHeight = text.getHeight();\r
-                       height += textHeight;\r
-                       textNode.attachChild(text);\r
-               }\r
-               background.resize(width+20.f, height+10.f);\r
-               if (monitorNode.getParent() == null)\r
-                       editor.getScenegraphAdapter().getRoot().attachChild(monitorNode);\r
-               \r
-       }\r
-       \r
-       private void updateText(Graph graph) {\r
-               ArrayList<String> titles = provider.getTexts(graph);\r
-               float newWidth = 0.f;\r
-               for (int i = 0; i < titles.size(); i++) {\r
-                       Text text = texts.get(i);\r
-                       text.print(titles.get(i));\r
-                       newWidth = Math.max(newWidth,text.getWidth());\r
-               }\r
-               if (newWidth != width) {\r
-                       width = newWidth;\r
-                       background.resize(width+20.f, height+10.f);\r
-               }\r
-                       \r
-       }\r
-       \r
-       public void update() {\r
-               if (node == null)\r
-                       return;\r
-               Vector2f v;\r
-                       \r
-               if (type == Type.POSITION) {\r
-                       v = editor.getScreenCoord(VecmathJmeTools.getD(node.getGroup().getWorldTranslation()));\r
-               } else {\r
-                       float mx = editor.getRenderingComponent().getDisplaySystem().getWidth();\r
-                       float my = editor.getRenderingComponent().getDisplaySystem().getHeight();\r
-                       Vector2f s = editor.getScreenCoord(start);\r
-                       Vector2f e = editor.getScreenCoord(end);\r
-                       Vector2f rs = new Vector2f();\r
-                       Vector2f re = new Vector2f();\r
-                       boolean in = MathTools.clipLineRectangle(s, e, new Vector2f(0.f,0.f), new Vector2f(mx,my), rs, re);\r
-                       if (in) {\r
-                               re.subtractLocal(rs);\r
-                               re.multLocal(0.5f);\r
-                               rs.addLocal(re);\r
-                               v = rs;\r
-                       } else {\r
-                               // just a hack to move monitor out of the view\r
-                               v = new Vector2f (mx+width,my+height);\r
-                       }\r
-                       \r
-                       \r
-               }\r
-               background.setLocalTranslation(new Vector3f(v.x,v.y,0.f));\r
-               float y = v.y + (height * 0.5f) - textHeight;\r
-               v.x -= width * 0.5f;\r
-               \r
-               for (Text text : texts) {\r
-                       text.setLocalTranslation(new Vector3f(v.x,y,0.f));\r
-                       y -= textHeight;\r
-               }\r
-               \r
-               \r
-               \r
-       }\r
-       \r
-       @Override\r
-       public void update(Graph graph) {\r
-               updateText(graph);\r
-               update();\r
-       }\r
-       \r
-       public IGraphicsNode getNode() {\r
-               return node;\r
-       }\r
-       \r
-       public void remove() {\r
-               monitorNode.removeFromParent();\r
-               node = null;\r
-       }\r
-       \r
-       protected Texture loadFontTexture() {\r
-               URL url = FileLocator.find(com.jme.eclipse.Activator.getDefault().getBundle(),new Path(fontLocation),null);\r
-        return TextureManager.loadTexture(url, Texture.MM_LINEAR,\r
-                Texture.FM_LINEAR);\r
-       }\r
-       \r
-       public void setTextProvider(MonitorTextProvider provider) {\r
-               this.provider = provider;\r
-       }\r
-       \r
-       \r
-\r
-       \r
-       \r
-}\r