Search in sources :

Example 1 with PickResult

use of com.sun.j3d.utils.picking.PickResult 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 PickResult

use of com.sun.j3d.utils.picking.PickResult in project ffx by mjschnie.

the class PickSelectionBehavior method updateScene.

/*
     * Update the scene to manipulate any nodes.
     * @param xpos Current mouse X pos. @param ypos Current mouse Y pos.
     */
/**
 * {@inheritDoc}
 */
public void updateScene(int xpos, int ypos) {
    TransformGroup tg = null;
    if ((mevent.getModifiersEx() & MouseEvent.BUTTON1) == MouseEvent.BUTTON1) {
        pickCanvas.setShapeLocation(xpos, ypos);
        PickResult r = pickCanvas.pickClosest();
        if (r != null) {
            tg = (TransformGroup) r.getNode(PickResult.TRANSFORM_GROUP);
            if ((tg != null) && (tg.getCapability(TransformGroup.ALLOW_TRANSFORM_READ)) && (tg.getCapability(TransformGroup.ALLOW_TRANSFORM_WRITE))) {
                drag.wakeup();
                currentTG = tg;
                if (callback != null) {
                    callback.transformClicked(PickingCallback.SELECTION, currentTG);
                }
            }
        } else if (callback != null) {
            callback.transformClicked(PickingCallback.NO_PICK, null);
        }
    }
}
Also used : PickResult(com.sun.j3d.utils.picking.PickResult) TransformGroup(javax.media.j3d.TransformGroup)

Example 3 with PickResult

use of com.sun.j3d.utils.picking.PickResult in project ffx by mjschnie.

the class PickZoomBehavior method updateScene.

/*
     * Update the scene to manipulate any nodes. This is not meant to be called
     * by users. Behavior automatically calls this. You can call this only if
     * you know what you are doing.
     * @param xpos Current mouse X pos. @param ypos Current mouse Y pos.
     */
/**
 * {@inheritDoc}
 */
public void updateScene(int xpos, int ypos) {
    TransformGroup tg = null;
    if ((mevent.getModifiersEx() & MouseEvent.BUTTON3) == MouseEvent.BUTTON3) {
        pickCanvas.setShapeLocation(xpos, ypos);
        PickResult r = pickCanvas.pickClosest();
        if (r != null) {
            tg = (TransformGroup) r.getNode(PickResult.TRANSFORM_GROUP);
            if ((tg != null) && (tg.getCapability(TransformGroup.ALLOW_TRANSFORM_READ)) && (tg.getCapability(TransformGroup.ALLOW_TRANSFORM_WRITE))) {
                zoom.setTransformGroup(tg);
                zoom.wakeup();
                currentTG = tg;
                if (callback != null) {
                    callback.transformClicked(PickingCallback.ZOOM, currentTG);
                }
            } else if (callback != null) {
                callback.transformChanged(PickingCallback.NO_PICK, null);
            }
        }
    }
}
Also used : PickResult(com.sun.j3d.utils.picking.PickResult) TransformGroup(javax.media.j3d.TransformGroup)

Example 4 with PickResult

use of com.sun.j3d.utils.picking.PickResult in project ffx by mjschnie.

the class PickOrbitBehavior method updateScene.

/*
     * Update the scene to manipulate any nodes. This is not meant to be called
     * by users. Behavior automatically calls this. You can call this only if
     * you know what you are doing.
     * @param xpos Current mouse X pos. @param ypos Current mouse Y pos.
     */
/**
 * {@inheritDoc}
 */
public void updateScene(int xpos, int ypos) {
    TransformGroup tg = null;
    if (mevent.isMetaDown() && !mevent.isAltDown()) {
        pickCanvas.setShapeLocation(xpos, ypos);
        PickResult r = pickCanvas.pickClosest();
        if (r != null) {
            tg = (TransformGroup) r.getNode(PickResult.TRANSFORM_GROUP);
            if ((tg != null) && (tg.getCapability(TransformGroup.ALLOW_TRANSFORM_READ)) && (tg.getCapability(TransformGroup.ALLOW_TRANSFORM_WRITE))) {
                orbit.setTransformGroup(tg);
                orbit.wakeup();
                currentTG = tg;
                if (callback != null) {
                    callback.transformClicked(PickingCallback.ORBIT, currentTG);
                }
            }
        } else if (callback != null) {
            callback.transformChanged(PickingCallback.NO_PICK, null);
        }
    }
}
Also used : PickResult(com.sun.j3d.utils.picking.PickResult) TransformGroup(javax.media.j3d.TransformGroup)

Example 5 with PickResult

use of com.sun.j3d.utils.picking.PickResult in project ffx by mjschnie.

the class PickPropertiesBehavior method updateScene.

/*
     * Update the scene to manipulate any nodes.
     * @param xpos Current mouse X pos. @param ypos Current mouse Y pos.
     */
/**
 * {@inheritDoc}
 */
public void updateScene(int xpos, int ypos) {
    TransformGroup tg = null;
    if (!mevent.isMetaDown() && !mevent.isAltDown()) {
        pickCanvas.setShapeLocation(xpos, ypos);
        PickResult r = pickCanvas.pickClosest();
        if (r != null) {
            tg = (TransformGroup) r.getNode(PickResult.TRANSFORM_GROUP);
            if ((tg != null) && (tg.getCapability(TransformGroup.ALLOW_TRANSFORM_READ)) && (tg.getCapability(TransformGroup.ALLOW_TRANSFORM_WRITE))) {
                drag.wakeup();
                currentTG = tg;
                if (callback != null && mevent.getClickCount() == 2) {
                    callback.transformDoubleClicked(PickingCallback.PROPERTIES, currentTG);
                }
            }
        } else if (callback != null) {
            callback.transformDoubleClicked(PickingCallback.NO_PICK, null);
        }
    }
}
Also used : PickResult(com.sun.j3d.utils.picking.PickResult) TransformGroup(javax.media.j3d.TransformGroup)

Aggregations

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