X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=dev%2Forg.simantics.proconf.g3d%2Fsrc%2Forg%2Fsimantics%2Fproconf%2Fg3d%2Fgizmo%2FMultiSelectionGizmo.java;fp=dev%2Forg.simantics.proconf.g3d%2Fsrc%2Forg%2Fsimantics%2Fproconf%2Fg3d%2Fgizmo%2FMultiSelectionGizmo.java;h=b73b8865c983cd428339b90a9545ff2194ce822d;hb=c438604e3e6917205b9def75b17d5050041a3a1b;hp=0000000000000000000000000000000000000000;hpb=34ca2a15526fd19014b66de48717dd7a469ec222;p=simantics%2F3d.git diff --git a/dev/org.simantics.proconf.g3d/src/org/simantics/proconf/g3d/gizmo/MultiSelectionGizmo.java b/dev/org.simantics.proconf.g3d/src/org/simantics/proconf/g3d/gizmo/MultiSelectionGizmo.java new file mode 100644 index 00000000..b73b8865 --- /dev/null +++ b/dev/org.simantics.proconf.g3d/src/org/simantics/proconf/g3d/gizmo/MultiSelectionGizmo.java @@ -0,0 +1,110 @@ +/******************************************************************************* + * 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); + } +}