1 /*******************************************************************************
\r
2 * Copyright (c) 2007- VTT Technical Research Centre of Finland.
\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.proconf.g3d.gizmo;
\r
13 import java.nio.FloatBuffer;
\r
15 import javax.vecmath.Color4f;
\r
17 import org.simantics.proconf.g3d.base.VecmathJmeTools;
\r
19 import com.jme.renderer.ColorRGBA;
\r
20 import com.jme.scene.TriMesh;
\r
21 import com.jme.util.geom.BufferUtils;
\r
25 public abstract class MultiSelectionGizmo extends AbstractGizmo {
\r
27 public static final int UNSELECTED = 0;
\r
28 public static final int SELECTED = 1;
\r
30 private TriMesh geoms[] = new TriMesh[4];
\r
31 private ColorRGBA colors[][] = new ColorRGBA[4][2];
\r
34 private boolean selected[];
\r
37 private int selectedIndex = -1;
\r
40 public MultiSelectionGizmo() {
\r
43 colors = new ColorRGBA[getCount()][2];
\r
44 geoms = new TriMesh[getCount()];
\r
45 selected = new boolean[getCount()];
\r
46 for (int i = 0; i < selected.length; i++) {
\r
47 selected[i] = false;
\r
51 protected abstract int getCount();
\r
52 protected abstract int getIndexForName(String name);
\r
54 public int getSelected() {
\r
55 return selectedIndex;
\r
58 private void updateColor(int index, int selected) {
\r
60 FloatBuffer buff = geoms[index].getColorBuffer(0);
\r
61 for (int i = 0; i < geoms[index].getBatch(0).getVertexCount(); i++) {
\r
62 BufferUtils.setInBuffer(colors[index][selected], buff, i);
\r
67 * @see fi.vtt.proconf.shapeeditor.common.Gizmo#changeSelected(java.lang.String)
\r
69 public void setSelected(String name) {
\r
72 for (int j = 0; j < getCount(); j++) {
\r
74 selected[j] = false;
\r
75 updateColor(j,UNSELECTED);
\r
82 int index = getIndexForName(name);
\r
85 selectedIndex = index;
\r
86 if (!selected[index]) {
\r
87 selected[index] = true;
\r
88 updateColor(index,SELECTED);
\r
91 for (int j = 0; j < getCount(); j++) {
\r
94 selected[j] = false;
\r
95 updateColor(j,UNSELECTED);
\r
103 protected void setGeometry(int index, TriMesh geom) {
\r
104 geoms[index] = geom;
\r
107 protected void setColor(int index, int selected, Color4f color) {
\r
108 colors[index][selected] = VecmathJmeTools.get(color);
\r