Search in sources :

Example 1 with SimpleContainerShape

use of cbit.gui.graph.SimpleContainerShape in project vcell by virtualcell.

the class ConstraintsGraphModel method refreshAll.

public void refreshAll() {
    Set<Shape> unwantedShapes = new HashSet<Shape>();
    unwantedShapes.addAll(getShapes());
    for (Shape shape : getShapes()) {
        if (shape instanceof ConstraintVarNode) {
            ((ConstraintVarNode) shape).setDegree(1);
        }
    }
    ContainerShape containerShape = (ContainerShape) getShapeFromModelObject(getConstraintContainerImpl());
    if (containerShape == null) {
        containerShape = new SimpleContainerShape(getConstraintContainerImpl(), this, "constraint network");
        containerShape.setLabel("constraint network");
        addShape(containerShape);
    }
    containerShape.refreshLabel();
    unwantedShapes.remove(containerShape);
    // 
    // add nodes for GeneralConstraints and edges to its Variables (add Variable when necessary)
    // 
    GeneralConstraint[] generalConstraints = getConstraintContainerImpl().getGeneralConstraints();
    for (int i = 0; i < generalConstraints.length; i++) {
        String[] symbols = generalConstraints[i].getExpression().getSymbols();
        if (symbols == null) {
            continue;
        }
        GeneralConstraintNode generalConstraintNode = (GeneralConstraintNode) getShapeFromModelObject(generalConstraints[i]);
        if (generalConstraintNode == null) {
            generalConstraintNode = new GeneralConstraintNode(generalConstraints[i], this, symbols.length);
            containerShape.addChildShape(generalConstraintNode);
            addShape(generalConstraintNode);
        }
        generalConstraintNode.refreshLabel();
        unwantedShapes.remove(generalConstraintNode);
        for (int j = 0; j < symbols.length; j++) {
            ConstraintVarNode constraintVarNode = (ConstraintVarNode) getShapeFromLabel(symbols[j]);
            if (constraintVarNode == null) {
                constraintVarNode = new ConstraintVarNode(symbols[j], this, 1);
                containerShape.addChildShape(constraintVarNode);
                addShape(constraintVarNode);
            } else {
                constraintVarNode.setDegree(constraintVarNode.getDegree() + 1);
            }
            constraintVarNode.refreshLabel();
            unwantedShapes.remove(constraintVarNode);
            ConstraintDependencyEdgeShape constraintDependencyEdgeShape = null;
            for (Shape shape : getShapes()) {
                if (shape instanceof ConstraintDependencyEdgeShape) {
                    if (((ConstraintDependencyEdgeShape) shape).getConstraintShape() == generalConstraintNode && ((ConstraintDependencyEdgeShape) shape).getVarShape() == constraintVarNode) {
                        constraintDependencyEdgeShape = (ConstraintDependencyEdgeShape) shape;
                    }
                }
            }
            if (constraintDependencyEdgeShape == null) {
                constraintDependencyEdgeShape = new ConstraintDependencyEdgeShape(generalConstraintNode, constraintVarNode, this);
                containerShape.addChildShape(constraintDependencyEdgeShape);
                addShape(constraintDependencyEdgeShape);
            }
            unwantedShapes.remove(constraintDependencyEdgeShape);
        }
    }
    // 
    // add nodes for SimpleBounds and edges to its Variables (add Variable when necessary)
    // 
    cbit.vcell.constraints.SimpleBounds[] simpleBounds = getConstraintContainerImpl().getSimpleBounds();
    for (int i = 0; i < simpleBounds.length; i++) {
        BoundsNode boundsNode = (BoundsNode) getShapeFromModelObject(simpleBounds[i]);
        if (boundsNode == null) {
            boundsNode = new BoundsNode(simpleBounds[i], this);
            containerShape.addChildShape(boundsNode);
            addShape(boundsNode);
        }
        boundsNode.refreshLabel();
        unwantedShapes.remove(boundsNode);
        ConstraintVarNode constraintVarNode = (ConstraintVarNode) getShapeFromLabel(simpleBounds[i].getIdentifier());
        if (constraintVarNode == null) {
            constraintVarNode = new ConstraintVarNode(simpleBounds[i].getIdentifier(), this, 1);
            containerShape.addChildShape(constraintVarNode);
            addShape(constraintVarNode);
        } else {
            constraintVarNode.setDegree(constraintVarNode.getDegree() + 1);
        }
        constraintVarNode.refreshLabel();
        unwantedShapes.remove(constraintVarNode);
        ConstraintDependencyEdgeShape constraintDependencyEdgeShape = null;
        for (Shape shape : getShapes()) {
            if (shape instanceof ConstraintDependencyEdgeShape) {
                if (((ConstraintDependencyEdgeShape) shape).getConstraintShape() == boundsNode && ((ConstraintDependencyEdgeShape) shape).getVarShape() == constraintVarNode) {
                    constraintDependencyEdgeShape = (ConstraintDependencyEdgeShape) shape;
                }
            }
        }
        if (constraintDependencyEdgeShape == null) {
            constraintDependencyEdgeShape = new ConstraintDependencyEdgeShape(boundsNode, constraintVarNode, this);
            containerShape.addChildShape(constraintDependencyEdgeShape);
            addShape(constraintDependencyEdgeShape);
        }
        constraintDependencyEdgeShape.refreshLabel();
        unwantedShapes.remove(constraintDependencyEdgeShape);
    }
    for (Shape unwantedShape : unwantedShapes) {
        removeShape(unwantedShape);
    }
    fireGraphChanged(new GraphEvent(this));
}
Also used : SimpleContainerShape(cbit.gui.graph.SimpleContainerShape) ContainerShape(cbit.gui.graph.ContainerShape) Shape(cbit.gui.graph.Shape) SimpleBounds(cbit.vcell.constraints.SimpleBounds) GeneralConstraint(cbit.vcell.constraints.GeneralConstraint) SimpleContainerShape(cbit.gui.graph.SimpleContainerShape) GeneralConstraint(cbit.vcell.constraints.GeneralConstraint) GraphEvent(cbit.gui.graph.GraphEvent) SimpleContainerShape(cbit.gui.graph.SimpleContainerShape) ContainerShape(cbit.gui.graph.ContainerShape) HashSet(java.util.HashSet)

Example 2 with SimpleContainerShape

use of cbit.gui.graph.SimpleContainerShape in project vcell by virtualcell.

the class WorkflowGraphModel method refreshAll.

/**
 * Insert the method's description here.
 * Creation date: (7/8/2003 9:11:57 AM)
 */
@Override
public void refreshAll() {
    clearAllShapes();
    if (getWorkflow() == null) {
        fireGraphChanged(new GraphEvent(this));
        return;
    }
    ContainerShape containerShape = new SimpleContainerShape(new Object(), this, "workflow-container");
    addShape(containerShape);
    // 
    for (Task task : getWorkflow().getTasks()) {
        TaskShape taskShape = new TaskShape(task, this);
        containerShape.addChildShape(taskShape);
        addShape(taskShape);
        // 
        for (DataOutput<? extends Object> output : task.getOutputs()) {
            if (!output.getName().equals("displayed")) {
                DataHolderShape dataHolderShape = new DataHolderShape(output, this);
                containerShape.addChildShape(dataHolderShape);
                addShape(dataHolderShape);
                WorkflowEdgeShape workflowEdgeShape = new WorkflowEdgeShape(task.getName() + ":" + output.getName(), taskShape, dataHolderShape, this, true, false);
                containerShape.addChildShape(workflowEdgeShape);
                addShape(workflowEdgeShape);
            }
        }
    // //
    // // add a DataInputShape for each input and connect to TaskShape with an edge
    // //
    // for (DataInput<? extends Object> input : task.getInputs()){
    // DataInputShape dataInputShape = new DataInputShape(input,this);
    // containerShape.addChildShape(dataInputShape);
    // addShape(dataInputShape);
    // 
    // WorkflowEdgeShape workflowEdgeShape = new WorkflowEdgeShape("input:"+task.getName()+":"+input.name,dataInputShape, taskShape, this, true, false);
    // containerShape.addChildShape(workflowEdgeShape);
    // addShape(workflowEdgeShape);
    // }
    }
    // 
    for (Task task : getWorkflow().getTasks()) {
        for (DataInput<? extends Object> input : task.getInputs()) {
            DataObject<? extends Object> source = getWorkflow().getConnectorSource(input);
            if (source instanceof DataOutput) {
                DataHolderShape dataHolderShape = (DataHolderShape) getShapeFromModelObject(source);
                TaskShape taskShape = (TaskShape) getShapeFromModelObject(task);
                WorkflowEdgeShape workflowEdgeShape = new WorkflowEdgeShape("connection:" + input.getName(), dataHolderShape, taskShape, this, true, false);
                containerShape.addChildShape(workflowEdgeShape);
                addShape(workflowEdgeShape);
            }
        }
    }
    fireGraphChanged(new GraphEvent(this));
}
Also used : DataOutput(org.vcell.workflow.DataOutput) Task(org.vcell.workflow.Task) GraphEvent(cbit.gui.graph.GraphEvent) SimpleContainerShape(cbit.gui.graph.SimpleContainerShape) ContainerShape(cbit.gui.graph.ContainerShape) DataObject(org.vcell.workflow.DataObject) SimpleContainerShape(cbit.gui.graph.SimpleContainerShape)

Aggregations

ContainerShape (cbit.gui.graph.ContainerShape)2 GraphEvent (cbit.gui.graph.GraphEvent)2 SimpleContainerShape (cbit.gui.graph.SimpleContainerShape)2 Shape (cbit.gui.graph.Shape)1 GeneralConstraint (cbit.vcell.constraints.GeneralConstraint)1 SimpleBounds (cbit.vcell.constraints.SimpleBounds)1 HashSet (java.util.HashSet)1 DataObject (org.vcell.workflow.DataObject)1 DataOutput (org.vcell.workflow.DataOutput)1 Task (org.vcell.workflow.Task)1