Search in sources :

Example 11 with Shape3D

use of javax.media.j3d.Shape3D in project ffx by mjschnie.

the class GraphicsEvents method processMouseEvent.

/**
 * <p>
 * processMouseEvent</p>
 *
 * @param evt a {@link java.awt.event.MouseEvent} object.
 */
public void processMouseEvent(MouseEvent evt) {
    buttonPress = false;
    leftButton = false;
    middleButton = false;
    rightButton = false;
    int mod = evt.getModifiersEx();
    if (evt.getID() == MouseEvent.MOUSE_PRESSED) {
        buttonPress = true;
    }
    // Left Button
    if ((mod & MouseEvent.BUTTON1_DOWN_MASK) == MouseEvent.BUTTON1_DOWN_MASK) {
        leftButton = true;
    }
    // Middle Button
    if ((mod & MouseEvent.BUTTON2_DOWN_MASK) == MouseEvent.BUTTON2_DOWN_MASK) {
        middleButton = true;
    }
    // Alternatively, map "alt + button1" to the middle button
    if ((mod & MouseEvent.ALT_DOWN_MASK) == MouseEvent.ALT_DOWN_MASK) {
        if (leftButton) {
            middleButton = true;
            leftButton = false;
        }
    }
    // Right Button
    if ((mod & MouseEvent.BUTTON3_DOWN_MASK) == MouseEvent.BUTTON3_DOWN_MASK) {
        rightButton = true;
    }
    // Alternatively, map "shift + button1" to the right button
    if ((mod & MouseEvent.SHIFT_DOWN_MASK) == MouseEvent.SHIFT_DOWN_MASK) {
        if (leftButton) {
            rightButton = true;
            leftButton = false;
        }
    }
    x = evt.getX();
    y = evt.getY();
    atom = null;
    axisSelected = false;
    if (buttonPress) {
        // Picking Results
        pickCanvas.setShapeLocation(x, y);
        // Catch and ignore this until a fix is determined...
        try {
            pickResult = pickCanvas.pickClosest();
        } catch (Exception e) {
            pickResult = null;
        }
        if (pickResult != null) {
            SceneGraphPath sgp = pickResult.getSceneGraphPath();
            Node node = sgp.getObject();
            if (node instanceof Shape3D) {
                Shape3D s = (Shape3D) node;
                Object o = s.getUserData();
                if (o instanceof MolecularAssembly) {
                    MolecularAssembly sys = (MolecularAssembly) o;
                    if (pickResult.numIntersections() > 0) {
                        PickIntersection pi = pickResult.getIntersection(0);
                        int[] coords = pi.getPrimitiveCoordinateIndices();
                        atom = sys.getAtomFromWireVertex(coords[0]);
                    }
                } else if (o instanceof Atom) {
                    atom = (Atom) o;
                } else if (o instanceof GraphicsAxis) {
                    axisSelected = true;
                }
            }
        }
    }
}
Also used : MolecularAssembly(ffx.potential.MolecularAssembly) SceneGraphPath(javax.media.j3d.SceneGraphPath) Node(javax.media.j3d.Node) Shape3D(javax.media.j3d.Shape3D) PickIntersection(com.sun.j3d.utils.picking.PickIntersection) Atom(ffx.potential.bonded.Atom)

Aggregations

Shape3D (javax.media.j3d.Shape3D)11 TransformGroup (javax.media.j3d.TransformGroup)4 Atom (ffx.potential.bonded.Atom)3 BranchGroup (javax.media.j3d.BranchGroup)3 Node (javax.media.j3d.Node)3 PickIntersection (com.sun.j3d.utils.picking.PickIntersection)2 MolecularAssembly (ffx.potential.MolecularAssembly)2 MSNode (ffx.potential.bonded.MSNode)2 Appearance (javax.media.j3d.Appearance)2 BoundingSphere (javax.media.j3d.BoundingSphere)2 ColoringAttributes (javax.media.j3d.ColoringAttributes)2 LineArray (javax.media.j3d.LineArray)2 LineAttributes (javax.media.j3d.LineAttributes)2 RenderingAttributes (javax.media.j3d.RenderingAttributes)2 SceneGraphPath (javax.media.j3d.SceneGraphPath)2 Color3f (javax.vecmath.Color3f)2 Point3d (javax.vecmath.Point3d)2 Vector3d (javax.vecmath.Vector3d)2 PickResult (com.sun.j3d.utils.picking.PickResult)1 Bond (ffx.potential.bonded.Bond)1