use of org.cytoscape.model.subnetwork.CySubNetwork in project cytoscape-impl by cytoscape.
the class AbstractGroupTask method getGroupName.
protected String getGroupName(CyGroup group) {
CyRootNetwork rootNet = ((CySubNetwork) net).getRootNetwork();
CyRow groupRow = rootNet.getRow(group.getGroupNode(), CyRootNetwork.SHARED_ATTRS);
return groupRow.get(CyRootNetwork.SHARED_NAME, String.class);
}
use of org.cytoscape.model.subnetwork.CySubNetwork in project cytoscape-impl by cytoscape.
the class DeleteSelectedNodesAndEdgesTask method run.
@Override
public void run(final TaskMonitor taskMonitor) {
taskMonitor.setProgress(0.0);
List<CyNode> nodeList = tunables.getNodeList(false);
List<CyEdge> edgeList = tunables.getEdgeList(false);
if (tunables.getNetwork() != null)
network = tunables.getNetwork();
// Delete from the base network so that our changes can be undone:
if (nodeList == null && edgeList == null) {
selectedNodes = CyTableUtil.getNodesInState(network, "selected", true);
taskMonitor.setProgress(0.1);
selectedEdges = new HashSet<CyEdge>(CyTableUtil.getEdgesInState(network, "selected", true));
} else {
if (nodeList != null && nodeList.size() > 0)
selectedNodes = nodeList;
else
selectedNodes = new ArrayList<CyNode>();
if (edgeList != null && edgeList.size() > 0)
selectedEdges = new HashSet<CyEdge>(edgeList);
else
selectedEdges = new HashSet<CyEdge>();
}
taskMonitor.setProgress(0.2);
// Make sure we're not loosing any edges for a possible undo!
for (CyNode selectedNode : selectedNodes) selectedEdges.addAll(network.getAdjacentEdgeList(selectedNode, CyEdge.Type.ANY));
taskMonitor.setProgress(0.3);
final UndoSupport undoSupport = serviceRegistrar.getService(UndoSupport.class);
final CyNetworkViewManager netViewMgr = serviceRegistrar.getService(CyNetworkViewManager.class);
final VisualMappingManager vmMgr = serviceRegistrar.getService(VisualMappingManager.class);
final CyEventHelper eventHelper = serviceRegistrar.getService(CyEventHelper.class);
undoSupport.postEdit(new DeleteEdit((CySubNetwork) network, selectedNodes, selectedEdges, netViewMgr, vmMgr, eventHelper));
// Delete the actual nodes and edges:
network.removeEdges(selectedEdges);
taskMonitor.setProgress(0.7);
network.removeNodes(selectedNodes);
taskMonitor.setProgress(0.9);
// Update network views
final Collection<CyNetworkView> views = netViewMgr.getNetworkViews(network);
for (final CyNetworkView netView : views) netView.updateView();
taskMonitor.setProgress(1.0);
}
use of org.cytoscape.model.subnetwork.CySubNetwork in project cytoscape-impl by cytoscape.
the class DGraphView method renderSubgraph.
int renderSubgraph(GraphGraphics graphics, final GraphLOD lod, Paint bgColor, double xCenter, double yCenter, double scale, LongHash hash, List<CyNode> nodeList, List<CyEdge> edgeList) {
// the overhead of creating the SpacialIndex2D and CySubNetwork
if (!largeModel || ((nodeList.size() + edgeList.size()) >= (m_drawPersp.getNodeCount() + m_drawPersp.getEdgeCount()) / 4))
return renderGraph(graphics, lod, bgColor, xCenter, yCenter, scale, hash);
// Make a copy of the nodes and edges arrays to avoid a conflict with selection events
// The assumption here is that these arrays are relatively small
List<CyNode> nodes = new ArrayList<>(nodeList);
List<CyEdge> edges = new ArrayList<>(edgeList);
// Make sure the graphics is initialized
if (!graphics.isInitialized())
graphics.clear(bgColor, xCenter, yCenter, scale);
Color bg = (Color) bgColor;
if (bg != null)
bg = new Color(bg.getRed(), bg.getBlue(), bg.getGreen(), 0);
// Create our private spacial index.
final SpacialIndex2DFactory spacialFactory = serviceRegistrar.getService(SpacialIndex2DFactory.class);
SpacialIndex2D sub_spacial = spacialFactory.createSpacialIndex2D();
// And our private subnetwork
CySubNetwork net = new MinimalNetwork(SUIDFactory.getNextSUID());
for (CyEdge edge : edges) {
nodes.add(edge.getTarget());
nodes.add(edge.getSource());
}
for (CyNode node : nodes) {
long idx = node.getSUID();
if (m_spacial.exists(idx, m_extentsBuff, 0)) {
if (!sub_spacial.exists(idx, new float[4], 0))
sub_spacial.insert(idx, m_extentsBuff[0], m_extentsBuff[1], m_extentsBuff[2], m_extentsBuff[3], 0.0);
net.addNode(node);
}
}
for (CyEdge edge : edges) {
net.addEdge(edge);
}
int lastRenderDetail = 0;
try {
// final VisualMappingManager vmm = serviceRegistrar.getService(VisualMappingManager.class);
final Set<VisualPropertyDependency<?>> dependencies = vmm.getVisualStyle(this).getAllVisualPropertyDependencies();
synchronized (m_lock) {
lastRenderDetail = GraphRenderer.renderGraph(this, sub_spacial, lod, m_nodeDetails, m_edgeDetails, hash, graphics, null, xCenter, yCenter, scale, haveZOrder, dependencies);
}
} catch (Exception e) {
e.printStackTrace();
}
setContentChanged(false);
setViewportChanged(false);
m_visualChanged = true;
return lastRenderDetail;
}
use of org.cytoscape.model.subnetwork.CySubNetwork in project cytoscape-impl by cytoscape.
the class ClipboardImpl method pasteEdge.
private CyEdge pasteEdge(final CyNetworkView sourceView, final CyNetworkView targetView, final CyEdge edge, final Map<CyRow, CyRow> rowMap, final Map<CyNode, CyNode> newNodeMap, final List<CyIdentifiable> pastedObjects) {
CyNetwork sourceNetwork = sourceView.getModel();
CyRootNetwork sourceRoot = ((CySubNetwork) sourceNetwork).getRootNetwork();
CySubNetwork targetNetwork = (CySubNetwork) targetView.getModel();
CyRootNetwork targetRoot = targetNetwork.getRootNetwork();
CyEdge newEdge = null;
CyNode sourceNode = edge.getSource();
CyNode targetNode = edge.getTarget();
// 3) We're copying edges to a new location in the same network
if (sourceRoot != targetRoot) {
if (!newNodeMap.containsKey(sourceNode)) {
addRows(sourceNode, sourceRoot, sourceNetwork);
final CyNode newNode = pasteNode(sourceView, targetView, sourceNode, rowMap);
newNodeMap.put(sourceNode, newNode);
pastedObjects.add(newNode);
}
if (!newNodeMap.containsKey(targetNode)) {
addRows(targetNode, sourceRoot, sourceNetwork);
final CyNode newNode = pasteNode(sourceView, targetView, targetNode, rowMap);
newNodeMap.put(targetNode, newNode);
pastedObjects.add(newNode);
}
// Create the edge
newEdge = targetNetwork.addEdge(newNodeMap.get(sourceNode), newNodeMap.get(targetNode), edge.isDirected());
// Copy the attributes over
rowMap.put(oldSharedRowMap.get(edge), targetNetwork.getRow(newEdge, CyNetwork.DEFAULT_ATTRS));
rowMap.put(oldLocalRowMap.get(edge), targetNetwork.getRow(newEdge, CyNetwork.LOCAL_ATTRS));
rowMap.put(oldHiddenRowMap.get(edge), targetNetwork.getRow(newEdge, CyNetwork.HIDDEN_ATTRS));
} else {
// First, see if we already have the nodes
if (!newNodeMap.containsKey(sourceNode)) {
if (targetNetwork.containsNode(sourceNode)) {
newNodeMap.put(sourceNode, sourceNode);
} else {
addRows(sourceNode, sourceRoot, sourceNetwork);
final CyNode newNode = pasteNode(sourceView, targetView, sourceNode, rowMap);
newNodeMap.put(sourceNode, newNode);
pastedObjects.add(newNode);
}
}
if (!newNodeMap.containsKey(targetNode)) {
if (targetNetwork.containsNode(targetNode)) {
newNodeMap.put(targetNode, targetNode);
} else {
addRows(targetNode, sourceRoot, sourceNetwork);
final CyNode newNode = pasteNode(sourceView, targetView, targetNode, rowMap);
newNodeMap.put(targetNode, newNode);
pastedObjects.add(newNode);
}
}
if (targetNetwork.containsEdge(edge)) {
// We want to create another copy of the edge
newEdge = targetNetwork.addEdge(newNodeMap.get(sourceNode), newNodeMap.get(targetNode), edge.isDirected());
} else {
// We just want to add the existing edge to this subnetwork
targetNetwork.addEdge(edge);
newEdge = edge;
}
// Copy the attributes over
rowMap.put(oldLocalRowMap.get(edge), targetNetwork.getRow(newEdge, CyNetwork.LOCAL_ATTRS));
rowMap.put(oldHiddenRowMap.get(edge), targetNetwork.getRow(newEdge, CyNetwork.HIDDEN_ATTRS));
}
return newEdge;
}
use of org.cytoscape.model.subnetwork.CySubNetwork in project cytoscape-impl by cytoscape.
the class CyGroupImpl method collapse.
/**
* @see org.cytoscape.group.CyGroup#collapse()
*/
@Override
public void collapse(CyNetwork net) {
CySubNetwork subnet;
CyNetwork groupNet;
synchronized (lock) {
// printGroup();
if (isCollapsed(net))
// Already collapsed
return;
if (!networkSet.contains(net))
// We're not in that network
return;
subnet = (CySubNetwork) net;
groupNet = groupNode.getNetworkPointer();
// First collapse any children that are groups
for (CyNode node : getNodeList()) {
// not in our network, it might have been collapsed by another group
if (mgr.isGroup(node, net)) {
final CyGroup gn = mgr.getGroup(node, net);
if (!gn.isCollapsed(net)) {
// Yes, collapse it
gn.collapse(net);
}
}
}
}
// Now collapse ourselves
cyEventHelper.fireEvent(new GroupAboutToCollapseEvent(CyGroupImpl.this, net, true));
collapsing = true;
// Since we're going to hide our nodes and edges, we probably shouldn't
// force these to redraw while we're collapsing. It causes a significant
// performance hit if we do.
cyEventHelper.silenceEventSource(net.getDefaultNodeTable());
cyEventHelper.silenceEventSource(net.getDefaultEdgeTable());
synchronized (lock) {
// Deselect all of the nodes
for (CyNode node : getNodeList()) {
if (net.containsNode(node))
net.getRow(node).set(CyNetwork.SELECTED, Boolean.FALSE);
}
// Deselect all of our internal edges
for (CyEdge edge : getInternalEdgeList()) {
if (net.containsEdge(edge))
net.getRow(edge).set(CyNetwork.SELECTED, Boolean.FALSE);
}
// Deselect all of our member edges
for (CyEdge edge : memberEdges) {
if (net.containsEdge(edge))
net.getRow(edge).set(CyNetwork.SELECTED, Boolean.FALSE);
}
}
// Make sure to restore any of our existing metaEdges
for (CyEdge e : metaEdges.values()) {
rootNetwork.restoreEdge(e);
}
List<CyNode> nodes;
synchronized (lock) {
// Deselect all of our external edges, and check for any possible
// collapsed partner groups
ListIterator<CyEdge> iterator = (new ArrayList<CyEdge>(externalEdges)).listIterator();
while (iterator.hasNext()) {
CyEdge edge = iterator.next();
if (net.containsEdge(edge)) {
net.getRow(edge).set(CyNetwork.SELECTED, Boolean.FALSE);
} else if (!externalEdgeProcessed.contains(edge)) {
// See if a partner node got collapsed
CyNode node = getPartner(edge);
if (!net.containsNode(node) && !mgr.getGroupsForNode(node).isEmpty()) {
for (CyGroup group : mgr.getGroupsForNode(node)) {
if (!group.equals(this)) {
// Create our meta-edge
CyEdge metaEdge = null;
metaEdge = createMetaEdge(edge, group.getGroupNode(), groupNode);
addMetaEdge(edge, metaEdge);
// Get the reciprocal edges
addPartnerMetaEdges(net, edge, group, metaEdge);
// Get the external edges and make them part of our external
ListIterator<CyEdge> edgeIterator = (new ArrayList<CyEdge>(group.getExternalEdgeList())).listIterator();
while (edgeIterator.hasNext()) {
CyEdge partnerEdge = edgeIterator.next();
CyEdge partnerMetaEdge = null;
if (groupNet.containsNode(partnerEdge.getSource())) {
partnerMetaEdge = createMetaEdge(partnerEdge, partnerEdge.getTarget(), groupNode);
} else if (groupNet.containsNode(partnerEdge.getTarget())) {
partnerMetaEdge = createMetaEdge(partnerEdge, partnerEdge.getSource(), groupNode);
}
if (partnerMetaEdge != null) {
((CyGroupImpl) group).addExternalEdge(partnerMetaEdge);
}
}
}
}
}
externalEdgeProcessed.add(edge);
}
}
cyEventHelper.unsilenceEventSource(net.getDefaultNodeTable());
cyEventHelper.unsilenceEventSource(net.getDefaultEdgeTable());
// Only collapse nodes that are actually in our
// network. This checks for nodes that are in
// multiple groups.
nodes = new ArrayList<CyNode>();
for (CyNode node : getNodeList()) {
if (net.containsNode(node)) {
nodes.add(node);
} else {
// This node may be in multiple groups, ours and at least one
// other, or it has been removed. We need to add a meta-edge
// to that node in case we expand it, and potentially remove
// a meta-edge that might not apply
List<CyGroup> otherGroups = mgr.getGroupsForNode(node);
// Make sure someone didn't remove it
if (otherGroups == null || otherGroups.size() == 0)
continue;
for (CyGroup group : otherGroups) {
if (!((CyGroupImpl) group).equals(this)) {
// Find any internal edges that point to this node
for (CyEdge edge : groupNet.getAdjacentEdgeList(node, CyEdge.Type.ANY)) {
// If this node has an internal edge, add a meta-edge to it
CyEdge metaEdge = createMetaEdge(edge, node, groupNode);
((CyGroupImpl) group).addExternalEdge(metaEdge);
// TODO: Need to deal with unnecessary meta-edge
}
}
}
}
}
// System.out.println(nodes.size()+" nodes to collapse: "+nodes);
collapsedNodes.put(net.getSUID(), nodes);
}
// We flush our events to renderers can process any edge
// creation events before we start removing things...
cyEventHelper.flushPayloadEvents();
// Remove all of the nodes from the target network:
// But first, Save their locked visual properties values...
final CyNetworkViewManager netViewMgr = mgr.getService(CyNetworkViewManager.class);
final Collection<CyNetworkView> netViewList = netViewMgr.getNetworkViews(subnet);
for (CyNode n : nodes) {
lvpMgr.saveLockedValues(n, netViewList);
saveLocalAttributes(net, n);
for (CyEdge e : subnet.getAdjacentEdgeList(n, CyEdge.Type.ANY)) {
lvpMgr.saveLockedValues(e, netViewList);
saveLocalAttributes(net, e);
}
}
// causes external edges to be removed as well
subnet.removeNodes(nodes);
// Make sure the external edges don't get auto-deleted
for (CyEdge edge : externalEdges) {
subnet.getRootNetwork().restoreEdge(edge);
}
final Set<CyIdentifiable> addedElements = new HashSet<CyIdentifiable>();
synchronized (lock) {
if (net.containsNode(groupNode)) {
// System.out.println("Network contains group node!");
nodeShownSet.add(net.getSUID());
}
// memberEdges.size()+" and nodeShownSet = "+nodeShownSet.contains(net.getSUID()));
if (memberEdges.size() == 0 && !nodeShownSet.contains(net.getSUID())) {
subnet.addNode(groupNode);
addedElements.add(groupNode);
for (CyEdge e : groupNodeEdges) {
// I have no idea why this would be necessary, but it is....
if (subnet.containsEdge(e)) {
// Save edge's locked visual properties values before they are removed
lvpMgr.saveLockedValues(e, netViewList);
saveLocalAttributes(net, e);
subnet.removeEdges(Collections.singletonList(e));
// But don't loose track of it...
rootNetwork.restoreEdge(e);
}
if (subnet.containsNode(e.getSource()) && subnet.containsNode(e.getTarget())) {
subnet.addEdge(e);
addedElements.add(e);
}
}
}
// Add the meta-edges
for (CyEdge e : getMetaEdgeList()) {
// The same meta-edge might represent multiple edges
if (subnet.containsEdge(e)) {
continue;
}
if (subnet.containsNode(e.getSource()) && subnet.containsNode(e.getTarget())) {
subnet.addEdge(e);
addedElements.add(e);
nameMetaEdge(e, e.getSource(), e.getTarget());
copyEdgeName(subnet, e);
}
}
collapseSet.add(net.getSUID());
// Update attributes
updateCountAttributes(net);
}
// Make sure the view "hears" about all of the changes...
cyEventHelper.flushPayloadEvents();
// Restore locked visual property values of added nodes/edges
lvpMgr.setLockedValues(netViewList, addedElements);
restoreLocalAttributes(net, addedElements);
// OK, all done
collapsing = false;
cyEventHelper.fireEvent(new GroupCollapsedEvent(CyGroupImpl.this, net, true));
// System.out.println("collapsed "+this.toString()+" in net "+net.toString()+": isCollapsed = "+isCollapsed(net));
// printGroup();
}
Aggregations