Search in sources :

Example 1 with SceneGraphPath

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

the class GraphicsPicking method updateScene.

/**
 * {@inheritDoc}
 *
 * Called by Java3D when an atom is picked
 */
public void updateScene(int xpos, int ypos) {
    if (picking == false) {
        return;
    }
    // Determine what FNode was picked
    pickCanvas.setShapeLocation(xpos, ypos);
    PickResult result = pickCanvas.pickClosest();
    if (result != null) {
        SceneGraphPath sceneGraphPath = result.getSceneGraphPath();
        Node node = sceneGraphPath.getObject();
        if (!(node instanceof Shape3D)) {
            return;
        }
        Shape3D pickedShape3D = (Shape3D) node;
        Object userData = pickedShape3D.getUserData();
        if (userData instanceof MolecularAssembly) {
            FFXSystem sys = (FFXSystem) userData;
            if (result.numIntersections() > 0) {
                PickIntersection pickIntersection = result.getIntersection(0);
                int[] coords = pickIntersection.getPrimitiveCoordinateIndices();
                userData = sys.getAtomFromWireVertex(coords[0]);
            } else {
                return;
            }
        }
        if (userData instanceof Atom) {
            Atom a = (Atom) userData;
            // Check to see if the pickLevel has changed
            if (!(pickLevel == newPickLevel)) {
                pickLevel = newPickLevel;
                pickNumber = 0;
            }
            // Clear selections between measurements
            String pickLevelString = pickLevel.toString();
            boolean measure = pickLevelString.startsWith("MEASURE");
            if (!measure || count == 0) {
                for (Atom matom : atomCache) {
                    matom.setSelected(false);
                    matom.setColor(RendererCache.ColorModel.SELECT, null, null);
                }
                atomCache.clear();
                count = 0;
            }
            // If measuring, select the current atom and add it to the cache
            if (measure && !atomCache.contains(a)) {
                atomCache.add(0, a);
                a.setSelected(true);
                a.setColor(RendererCache.ColorModel.PICK, null, null);
                count++;
                measure();
            }
            if (!measure) {
                // This allows iteration through the atom's terms
                if (a == previousAtom) {
                    pickNumber++;
                } else {
                    previousAtom = a;
                    pickNumber = 0;
                }
                MSNode currentPick = null;
                switch(pickLevel) {
                    case PICKATOM:
                        currentPick = a;
                        break;
                    case PICKBOND:
                    case PICKANGLE:
                    case PICKDIHEDRAL:
                        ArrayList terms = null;
                        if (pickLevel == PickLevel.PICKBOND) {
                            terms = a.getBonds();
                        } else if (pickLevel == PickLevel.PICKANGLE) {
                            terms = a.getAngles();
                        } else if (pickLevel == PickLevel.PICKDIHEDRAL) {
                            terms = a.getTorsions();
                        }
                        if (terms == null) {
                            return;
                        }
                        int num = terms.size();
                        if (pickNumber >= num) {
                            pickNumber = 0;
                        }
                        currentPick = (BondedTerm) terms.get(pickNumber);
                        break;
                    case PICKRESIDUE:
                    case PICKPOLYMER:
                    case PICKMOLECULE:
                    case PICKSYSTEM:
                        MSNode dataNode = null;
                        if (pickLevel == PickLevel.PICKRESIDUE) {
                            dataNode = (MSNode) a.getMSNode(Residue.class);
                        } else if (pickLevel == PickLevel.PICKPOLYMER) {
                            dataNode = (MSNode) a.getMSNode(Polymer.class);
                        } else if (pickLevel == PickLevel.PICKSYSTEM) {
                            dataNode = (MSNode) a.getMSNode(MolecularAssembly.class);
                        } else if (pickLevel == PickLevel.PICKMOLECULE) {
                            dataNode = (MSNode) a.getMSNode(Molecule.class);
                            if (dataNode == null) {
                                dataNode = (MSNode) a.getMSNode(Polymer.class);
                            }
                        }
                        currentPick = dataNode;
                        break;
                    case MEASUREANGLE:
                    case MEASUREDIHEDRAL:
                    case MEASUREDISTANCE:
                        break;
                }
                // Add the selected node to the Tree View
                if (currentPick != null) {
                    if (controlButton) {
                        mainPanel.getHierarchy().toggleSelection(currentPick);
                    } else if (currentPick != previousPick) {
                        mainPanel.getHierarchy().onlySelection(currentPick);
                    }
                    // Color the Current Pick by Picking Color
                    mainPanel.getGraphics3D().updateScene(currentPick, false, false, null, true, RendererCache.ColorModel.PICK);
                }
                // Remove picking color from the previousPick
                if (previousPick != null && previousPick != currentPick) {
                    previousPick.setColor(RendererCache.ColorModel.REVERT, null, null);
                }
                previousPick = currentPick;
            }
        }
    }
}
Also used : SceneGraphPath(javax.media.j3d.SceneGraphPath) MSNode(ffx.potential.bonded.MSNode) Node(javax.media.j3d.Node) ArrayList(java.util.ArrayList) Polymer(ffx.potential.bonded.Polymer) PickIntersection(com.sun.j3d.utils.picking.PickIntersection) Atom(ffx.potential.bonded.Atom) Molecule(ffx.potential.bonded.Molecule) MolecularAssembly(ffx.potential.MolecularAssembly) MSNode(ffx.potential.bonded.MSNode) PickResult(com.sun.j3d.utils.picking.PickResult) Shape3D(javax.media.j3d.Shape3D)

Example 2 with SceneGraphPath

use of javax.media.j3d.SceneGraphPath 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

PickIntersection (com.sun.j3d.utils.picking.PickIntersection)2 MolecularAssembly (ffx.potential.MolecularAssembly)2 Atom (ffx.potential.bonded.Atom)2 Node (javax.media.j3d.Node)2 SceneGraphPath (javax.media.j3d.SceneGraphPath)2 Shape3D (javax.media.j3d.Shape3D)2 PickResult (com.sun.j3d.utils.picking.PickResult)1 MSNode (ffx.potential.bonded.MSNode)1 Molecule (ffx.potential.bonded.Molecule)1 Polymer (ffx.potential.bonded.Polymer)1 ArrayList (java.util.ArrayList)1