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