Search in sources :

Example 1 with ROLSP

use of ffx.potential.bonded.ROLSP in project ffx by mjschnie.

the class Renderer method processStimulus.

/**
 * {@inheritDoc}
 *
 * This method is called by the Java3D Behavior thread after the following
 * sequence of events: 1.) A graphics operation is loaded using the "arm"
 * method. 2.) The PostID call is processed by the Java3D Behavior Thread.
 */
@Override
public void processStimulus(Enumeration parm1) {
    // Do not perform two operations before the frame has be refreshed.
    if (getView().getFrameNumber() == frameNumber) {
        System.out.print(".");
        wakeupOn(postid);
        postId(1);
        return;
    }
    // Check that the requested View and Color Models are known.
    String viewString = null;
    String colorString = null;
    if (viewModel != null) {
        try {
            viewString = viewModel.toString();
        } catch (Exception e) {
            statusBar.setText("Unknown ViewModel: " + viewModel);
            return;
        }
    }
    if (colorModel != null) {
        try {
            colorString = colorModel.toString();
        } catch (Exception e) {
            statusBar.setText("Unknown ColorModel: " + colorModel);
            return;
        }
    }
    if (timer) {
        startTimer();
        if (viewString != null) {
            logger.info("Applying ViewModel Change: " + viewString);
        }
        if (colorString != null) {
            System.out.println("Applying ColorModel Change: " + colorString);
        }
    }
    // Perform the requested rendering operation
    ArrayList<ArrayList<BranchGroup>> newChildren = new ArrayList<ArrayList<BranchGroup>>();
    for (MSNode nodeToUpdate : nodesToUpdate) {
        if (nodeToUpdate == null) {
            continue;
        }
        if (doTransform) {
            nodeToUpdate.update();
        }
        if (doColor) {
            nodeToUpdate.setColor(colorModel, null, null);
            if (statusBar != null) {
                statusBar.setText("  Color by \"" + colorString + "\" applied to " + nodeToUpdate.toString());
            }
        }
        if (doView) {
            ArrayList<BranchGroup> newShapes = new ArrayList<BranchGroup>();
            newChildren.add(newShapes);
            nodeToUpdate.setView(viewModel, newShapes);
            if (statusBar != null) {
                statusBar.setText("  Style \"" + viewString + "\" applied to " + nodeToUpdate.toString());
            }
        }
    }
    // Wait for the parallel nodes to finish
    try {
        if (ROLSP.GO_PARALLEL && ROLSP.parallelNotDone > 0) {
            logger.info("Renderer waiting for " + ROLSP.parallelNotDone + " processes...");
        }
        while (ROLSP.GO_PARALLEL && ROLSP.parallelNotDone > 0) {
            synchronized (this) {
                wait(10);
            }
        }
    } catch (Exception e) {
        System.out.println("Exception Waiting for Parallel MultiScale Methods to Finish");
    } finally {
        // the MolecularAssembly.
        for (int i = 0; i < nodesToUpdate.size(); i++) {
            if (newChildren.isEmpty()) {
                break;
            }
            MSNode nodeToUpdate = nodesToUpdate.get(i);
            if (nodeToUpdate == null) {
                continue;
            }
            if (nodeToUpdate instanceof MolecularAssembly) {
                MolecularAssembly ma = (MolecularAssembly) nodeToUpdate;
                ma.sceneGraphChange(null);
            } else if (nodeToUpdate instanceof ROLSP) {
                MolecularAssembly ma = (MolecularAssembly) nodeToUpdate.getChildAt(0);
                ma.sceneGraphChange(null);
            } else if (nodeToUpdate instanceof MSRoot) {
                for (Enumeration e = nodeToUpdate.children(); e.hasMoreElements(); ) {
                    MSNode updatedNode = (MSNode) e.nextElement();
                    if (updatedNode instanceof ROLSP) {
                        MolecularAssembly ma = (MolecularAssembly) updatedNode.getChildAt(0);
                        ma.sceneGraphChange(null);
                    } else {
                        MolecularAssembly ma = (MolecularAssembly) updatedNode;
                        ma.sceneGraphChange(null);
                    }
                }
            } else {
                ArrayList<BranchGroup> newShapes = newChildren.get(i);
                if (!newShapes.isEmpty()) {
                    MolecularAssembly ma = (MolecularAssembly) nodeToUpdate.getMSNode(MolecularAssembly.class);
                    ma.sceneGraphChange(newShapes);
                }
            }
        }
    }
    if (timer) {
        stopTimer();
    }
    nodesToUpdate = null;
    wakeupOn(postid);
    if (nodesCache != null) {
        nodesToUpdate = nodesCache;
        doTransform = doTransformCache;
        doView = doViewCache;
        viewModel = viewModelCache;
        doColor = doColorCache;
        colorModel = colorModelCache;
        nodesCache = null;
        postId(1);
    }
}
Also used : MSNode(ffx.potential.bonded.MSNode) Enumeration(java.util.Enumeration) ROLSP(ffx.potential.bonded.ROLSP) BranchGroup(javax.media.j3d.BranchGroup) MSRoot(ffx.potential.bonded.MSRoot) ArrayList(java.util.ArrayList)

Example 2 with ROLSP

use of ffx.potential.bonded.ROLSP in project ffx by mjschnie.

the class Hierarchy method addTreeNode.

/**
 * <p>
 * addTreeNode</p>
 *
 * @param nodeToAdd a {@link ffx.potential.bonded.MSNode} object.
 * @param parent a {@link ffx.potential.bonded.MSNode} object.
 * @param index a int.
 */
public void addTreeNode(MSNode nodeToAdd, MSNode parent, int index) {
    synchronized (this) {
        if (nodeToAdd == null || nodeToAdd.getParent() != null) {
            return;
        }
        int childCount = parent.getChildCount();
        if (index < 0 || index > childCount) {
            index = parent.getChildCount();
        }
        String name = nodeToAdd.getName();
        for (int i = 0; i < parent.getChildCount(); i++) {
            MSNode node = (MSNode) parent.getChildAt(i);
            if (node.getName().equals(name)) {
                logger.info(" Parent already has a node with the name " + name);
            }
        }
        // Add a parallel node if the ffe.lang.parallel flag was set
        if (ROLSP.GO_PARALLEL) {
            ROLSP parallelNode = new ROLSP();
            parallelNode.add(nodeToAdd);
            hierarchyModel.insertNodeInto(parallelNode, parent, index);
        } else {
            hierarchyModel.insertNodeInto(nodeToAdd, parent, index);
        }
        if (nodeToAdd instanceof FFXSystem) {
            attach((FFXSystem) nodeToAdd);
            hierarchyModel.nodeStructureChanged(nodeToAdd);
        }
        onlySelection(nodeToAdd);
        if (!isRootVisible()) {
            setRootVisible(true);
        }
    }
}
Also used : MSNode(ffx.potential.bonded.MSNode) ROLSP(ffx.potential.bonded.ROLSP)

Aggregations

MSNode (ffx.potential.bonded.MSNode)2 ROLSP (ffx.potential.bonded.ROLSP)2 MSRoot (ffx.potential.bonded.MSRoot)1 ArrayList (java.util.ArrayList)1 Enumeration (java.util.Enumeration)1 BranchGroup (javax.media.j3d.BranchGroup)1