+++ /dev/null
-/*******************************************************************************\r
- * Copyright (c) 2007 VTT Technical Research Centre of Finland and others.\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.proconf.g3d.gizmo;\r
-\r
-import java.nio.FloatBuffer;\r
-\r
-import javax.vecmath.Color4f;\r
-\r
-import org.simantics.proconf.g3d.base.VecmathJmeTools;\r
-\r
-import com.jme.renderer.ColorRGBA;\r
-import com.jme.scene.TriMesh;\r
-import com.jme.util.geom.BufferUtils;\r
-\r
-\r
-\r
-public abstract class MultiSelectionGizmo extends AbstractGizmo {\r
- \r
- public static final int UNSELECTED = 0;\r
- public static final int SELECTED = 1;\r
-\r
- private TriMesh geoms[] = new TriMesh[4];\r
- private ColorRGBA colors[][] = new ColorRGBA[4][2];\r
- \r
-\r
- private boolean selected[];\r
- \r
- \r
- private int selectedIndex = -1;\r
- \r
- \r
- public MultiSelectionGizmo() {\r
- super();\r
-\r
- colors = new ColorRGBA[getCount()][2];\r
- geoms = new TriMesh[getCount()];\r
- selected = new boolean[getCount()];\r
- for (int i = 0; i < selected.length; i++) {\r
- selected[i] = false;\r
- }\r
- }\r
- \r
- protected abstract int getCount();\r
- protected abstract int getIndexForName(String name);\r
- \r
- public int getSelected() {\r
- return selectedIndex;\r
- }\r
- \r
- private void updateColor(int index, int selected) {\r
-\r
- FloatBuffer buff = geoms[index].getColorBuffer(0);\r
- for (int i = 0; i < geoms[index].getBatch(0).getVertexCount(); i++) {\r
- BufferUtils.setInBuffer(colors[index][selected], buff, i);\r
- }\r
- }\r
- \r
- /* (non-Javadoc)\r
- * @see fi.vtt.proconf.shapeeditor.common.Gizmo#changeSelected(java.lang.String)\r
- */\r
- public void setSelected(String name) {\r
- \r
- if (name == null) {\r
- for (int j = 0; j < getCount(); j++) {\r
- if (selected[j]) {\r
- selected[j] = false;\r
- updateColor(j,UNSELECTED);\r
- setChanged(true);\r
- }\r
- }\r
- selectedIndex = -1;\r
- return;\r
- }\r
- int index = getIndexForName(name);\r
- if (index == -1)\r
- return;\r
- selectedIndex = index;\r
- if (!selected[index]) {\r
- selected[index] = true;\r
- updateColor(index,SELECTED);\r
- setChanged(true);\r
- }\r
- for (int j = 0; j < getCount(); j++) {\r
- if (j != index) {\r
- if (selected[j]) {\r
- selected[j] = false;\r
- updateColor(j,UNSELECTED);\r
- setChanged(true);\r
- }\r
- }\r
- } \r
- }\r
- \r
- \r
- protected void setGeometry(int index, TriMesh geom) {\r
- geoms[index] = geom;\r
- }\r
- \r
- protected void setColor(int index, int selected, Color4f color) {\r
- colors[index][selected] = VecmathJmeTools.get(color);\r
- }\r
-}\r