use of org.ivis.layout.LGraph in project cytoscape-impl by cytoscape.
the class SbgnPDLayout method createPortNodes.
/**
* This method creates two port nodes and a compound for each process nodes
* and adds them to graph.
*/
private void createPortNodes() {
for (Object o : this.getAllNodes()) {
SbgnPDNode originalProcessNode = (SbgnPDNode) o;
if (originalProcessNode.type.equals(SbgnPDConstants.PROCESS)) {
LGraph ownerGraph = originalProcessNode.getOwner();
// create new nodes and graphs
SbgnProcessNode processNode = (SbgnProcessNode) newProcessNode(null);
SbgnPDNode inputPort = (SbgnPDNode) newPortNode(null, SbgnPDConstants.INPUT_PORT);
SbgnPDNode outputPort = (SbgnPDNode) newPortNode(null, SbgnPDConstants.OUTPUT_PORT);
// create a dummy compound
SbgnPDNode compoundNode = (SbgnPDNode) newNode(null);
compoundNode.type = SbgnPDConstants.DUMMY_COMPOUND;
// add labels
compoundNode.label = "DummyCompound_" + originalProcessNode.label;
inputPort.label = "InputPort_" + originalProcessNode.label;
outputPort.label = "OutputPort_" + originalProcessNode.label;
// create child graph (= 2port+process) to be set as child to
// dummy compound
LGraph childGraph = newGraph(null);
ownerGraph.add(processNode);
// convert the process node to SbgnProcessNode
processNode.copyFromSBGNPDNode(originalProcessNode, this.getGraphManager());
processNode.connectNodes(compoundNode, inputPort, outputPort);
// create rigid edges, change edge connections
processNode.reconnectEdges(idealEdgeLength);
SbgnPDEdge rigidToProduction = (SbgnPDEdge) newRigidEdge(null);
rigidToProduction.label = "" + (this.graphManager.getAllEdges().length + 1);
SbgnPDEdge rigidToConsumption = (SbgnPDEdge) newRigidEdge(null);
rigidToConsumption.label = "" + (this.graphManager.getAllEdges().length + 2);
ownerGraph.remove(processNode);
// organize child graph
childGraph.add(processNode);
childGraph.add(inputPort);
childGraph.add(outputPort);
childGraph.add(rigidToProduction, inputPort, processNode);
childGraph.add(rigidToConsumption, outputPort, processNode);
// organize the compound node
compoundNode.setOwner(ownerGraph);
compoundNode.setCenter(processNode.getCenterX(), processNode.getCenterY());
ownerGraph.add(compoundNode);
this.graphManager.add(childGraph, compoundNode);
// remove the original process node
ownerGraph.remove(originalProcessNode);
this.processNodeList.add(processNode);
this.graphManager.updateBounds();
}
}
// reset the topology
this.graphManager.resetAllNodes();
this.graphManager.resetAllNodesToApplyGravitation();
this.graphManager.resetAllEdges();
this.calculateNodesToApplyGravitationTo();
}
use of org.ivis.layout.LGraph in project cytoscape-impl by cytoscape.
the class SbgnPDLayout method repopulateComplexes.
/**
* Reassigns the complex content. The outermost complex is placed first.
*/
protected void repopulateComplexes() {
for (SbgnPDNode comp : emptiedDummyComplexMap.keySet()) {
LGraph chGr = emptiedDummyComplexMap.get(comp);
comp.setChild(chGr);
this.getGraphManager().getGraphs().add(chGr);
}
for (int i = complexOrder.size() - 1; i >= 0; i--) {
SbgnPDNode comp = complexOrder.get(i);
LGraph chGr = childGraphMap.get(comp);
// repopulate the complex
comp.setChild(chGr);
// if the child graph is not null, adjust the positions of members
if (chGr != null) {
// adjust the positions of the members
if (compactionMethod == DefaultCompactionAlgorithm.POLYOMINO_PACKING) {
adjustLocation(comp, chGr);
getGraphManager().getGraphs().add(chGr);
} else if (compactionMethod == DefaultCompactionAlgorithm.TILING) {
getGraphManager().getGraphs().add(chGr);
MemberPack pack = memberPackMap.get(comp);
pack.adjustLocations(comp.getLeft(), comp.getTop());
}
}
}
for (SbgnPDNode comp : emptiedDummyComplexMap.keySet()) {
LGraph chGr = emptiedDummyComplexMap.get(comp);
adjustLocation(comp, chGr);
}
removeDummyComplexes();
// reset
getGraphManager().resetAllNodes();
getGraphManager().resetAllNodesToApplyGravitation();
getGraphManager().resetAllEdges();
this.calculateNodesToApplyGravitationTo();
}
use of org.ivis.layout.LGraph in project cytoscape-impl by cytoscape.
the class SbgnPDLayout method clearComplex.
// ********************* SECTION : TILING METHODS *********************
private void clearComplex(SbgnPDNode comp) {
MemberPack pack = null;
LGraph childGr = comp.getChild();
childGraphMap.put(comp, childGr);
if (childGr == null)
return;
if (compactionMethod == DefaultCompactionAlgorithm.POLYOMINO_PACKING) {
applyPolyomino(comp);
} else if (compactionMethod == DefaultCompactionAlgorithm.TILING) {
pack = new MemberPack(childGr);
memberPackMap.put(comp, pack);
}
if (dummyComplexList.contains(comp)) {
for (Object o : comp.getChild().getNodes()) {
clearDummyComplexGraphs((SbgnPDNode) o);
}
}
getGraphManager().getGraphs().remove(childGr);
comp.setChild(null);
if (compactionMethod == DefaultCompactionAlgorithm.TILING) {
comp.setWidth(pack.getWidth());
comp.setHeight(pack.getHeight());
}
// Redirect the edges of complex members to the complex.
if (childGr != null) {
for (Object ch : childGr.getNodes()) {
SbgnPDNode chNd = (SbgnPDNode) ch;
for (Object obj : new ArrayList(chNd.getEdges())) {
LEdge edge = (LEdge) obj;
if (edge.getSource() == chNd) {
chNd.getEdges().remove(edge);
edge.setSource(comp);
comp.getEdges().add(edge);
} else if (edge.getTarget() == chNd) {
chNd.getEdges().remove(edge);
edge.setTarget(comp);
comp.getEdges().add(edge);
}
}
}
}
}
use of org.ivis.layout.LGraph in project cytoscape-impl by cytoscape.
the class CoSELayoutAlgorithmTask method layoutPartition.
@Override
public void layoutPartition(final LayoutPartition partition) {
if (cancelled)
return;
final CyGroupManager groupManager = serviceRegistrar.getService(CyGroupManager.class);
final CyNetwork network = networkView.getModel();
// Create the CoSE model
// (see http://www.cs.bilkent.edu.tr/~ivis/chilay/ChiLay-2.0-PG.pdf)
cose = new CoSELayout();
cose.addProgressListener(new ProgressListener() {
@Override
public void update(double value) {
taskMonitor.setProgress(value);
}
});
final LGraphManager gm = cose.getGraphManager();
final LGraph root = gm.addRoot();
// Index all LayoutNodes by CyNode for future reference
final Map<CyNode, LayoutNode> layoutNodeMap = new HashMap<>();
for (LayoutNode n : partition.getNodeList()) layoutNodeMap.put(n.getNode(), n);
// Create all CoSE nodes
final Map<CyNode, LNode> lNodeMap = new HashMap<>();
for (LayoutNode n : partition.getNodeList()) {
// If this node does not belong to a CyGroup, let's traverse its potential compound node tree.
if (groupManager.getGroupsForNode(n.getNode(), network).isEmpty())
traverseLNodeTree(n, root, cose, lNodeMap, layoutNodeMap, groupManager);
}
if (cancelled)
return;
// Create all CoSE edges
final Map<CyEdge, LEdge> lEdgeMap = new HashMap<>();
final Iterator<LayoutEdge> edgeIter = partition.edgeIterator();
while (edgeIter.hasNext() && !cancelled) {
final LayoutEdge e = edgeIter.next();
createLEdge(e, cose, lNodeMap, lEdgeMap);
}
if (cancelled)
return;
// Run the layout
try {
cose.runLayout();
} catch (Exception e) {
logger.error("Error running CoSE Layout", e);
return;
}
if (cancelled)
return;
// Move all Node Views to the new positions
for (LayoutNode n : partition.getNodeList()) partition.moveNodeToLocation(n);
}
use of org.ivis.layout.LGraph in project cytoscape-impl by cytoscape.
the class CoSELayoutAlgorithmTask method traverseLNodeTree.
private void traverseLNodeTree(final LayoutNode layoutNode, final LGraph graph, final CoSELayout cose, final Map<CyNode, LNode> lNodeMap, final Map<CyNode, LayoutNode> layoutNodeMap, final CyGroupManager groupManager) {
if (lNodeMap.containsKey(layoutNode.getNode()))
// This node has already been visited!
return;
final LNode ln = createLNode(layoutNode, graph, cose, lNodeMap);
if (groupManager.isGroup(layoutNode.getNode(), networkView.getModel())) {
final CyGroup group = groupManager.getGroup(layoutNode.getNode(), networkView.getModel());
if (group != null) {
final LGraphManager gm = cose.getGraphManager();
final LGraph subGraph = gm.add(cose.newGraph("G" + group.getGroupNetwork().getSUID()), ln);
for (CyNode childNode : group.getNodeList()) {
final LayoutNode childLayoutNode = layoutNodeMap.get(childNode);
if (childLayoutNode != null)
traverseLNodeTree(childLayoutNode, subGraph, cose, lNodeMap, layoutNodeMap, groupManager);
}
}
}
}
Aggregations