use of y.base.EdgeCursor in project binnavi by google.
the class YHelpers method openFolder.
/**
* Opens a folder node.
*
* @param graph The graph the folder node belongs to.
* @param folderNode The folder node to be opened.
*/
public static void openFolder(final Graph2D graph, final Node folderNode) {
Preconditions.checkNotNull(graph, "Error: Graph argument can not be null");
Preconditions.checkNotNull(folderNode, "Error: Folder node argument can not be null");
final HierarchyManager hierarchy = graph.getHierarchyManager();
final double w = graph.getWidth(folderNode);
final double h = graph.getHeight(folderNode);
final NodeList folderNodes = new NodeList();
folderNodes.add(folderNode);
graph.firePreEvent();
for (final NodeCursor nc = folderNodes.nodes(); nc.ok(); nc.next()) {
// get original location of folder node
final Graph2D innerGraph = (Graph2D) hierarchy.getInnerGraph(nc.node());
final YPoint folderP = graph.getLocation(nc.node());
final NodeList innerNodes = new NodeList(innerGraph.nodes());
hierarchy.openFolder(nc.node());
// get new location of group node
final Rectangle2D.Double gBox = graph.getRealizer(nc.node()).getBoundingBox();
// move grouped nodes to former location of folder node
LayoutTool.moveSubgraph(graph, innerNodes.nodes(), folderP.x - gBox.x, folderP.y - gBox.y);
}
graph.firePostEvent();
graph.unselectAll();
for (final NodeCursor nc = folderNodes.nodes(); nc.ok(); nc.next()) {
graph.setSelected(nc.node(), true);
}
// to the node
if ((w != graph.getWidth(folderNode)) || (h != graph.getHeight(folderNode))) {
for (final EdgeCursor ec = folderNode.outEdges(); ec.ok(); ec.next()) {
graph.setSourcePointRel(ec.edge(), YPoint.ORIGIN);
}
for (final EdgeCursor ec = folderNode.inEdges(); ec.ok(); ec.next()) {
graph.setTargetPointRel(ec.edge(), YPoint.ORIGIN);
}
}
graph.updateViews();
}
use of y.base.EdgeCursor in project binnavi by google.
the class TypeDependenceGraph method willCreateCycle.
/**
* Tests if adding a member of type memberType to containingType would create a cyclic type
* declaration.
*
* @param containingType The base type that contains memberType.
* @param memberType The base type of a member contained in containingType.
* @return Returns whether adding memberType to containingType would create a cyclic type
* declaration.
*/
public boolean willCreateCycle(final BaseType containingType, final BaseType memberType) {
Preconditions.checkNotNull(containingType, "Error: Containing type can not be null.");
Preconditions.checkNotNull(memberType, "Error: Member type can not be null.");
if (containingType == memberType) {
return true;
}
// 0) The pre-condition is that the existing graph is cycle free.
// 1) Contained types is the set of types that are explicitly and implicitly contained within
// the structure this member belongs to.
// 2) The intersection of this set and all types that are contained by parentType must be empty.
// TODO(jannewger): instead of creating a copy, the implementation for determining dependent
// types should be parameterizable whether to include the contained type or not.
final Set<BaseType> containedTypes = Sets.newHashSet(determineDependentTypes(containingType));
containedTypes.remove(containingType);
final Node startNode = containedRelationMap.get(memberType);
final Queue<Edge> edgesToVisit = new LinkedList<Edge>();
for (final EdgeCursor ec = startNode.inEdges(); ec.ok(); ec.next()) {
edgesToVisit.add((Edge) ec.current());
}
final Set<Node> visitednodes = new HashSet<Node>();
while (!edgesToVisit.isEmpty()) {
final Edge currentEdge = edgesToVisit.poll();
final Node nextNode = currentEdge.source();
final BaseType baseType = containedRelationMap.inverse().get(nextNode);
if (containedTypes.contains(baseType)) {
return true;
}
if (!visitednodes.contains(nextNode)) {
for (final EdgeCursor ec = nextNode.inEdges(); ec.ok(); ec.next()) {
edgesToVisit.add((Edge) ec.current());
}
}
visitednodes.add(nextNode);
}
return false;
}
use of y.base.EdgeCursor in project binnavi by google.
the class CReilInstructionGraph method getIncomingEdgesForAddress.
/**
* Convenience method to obtain the edge in the ReilInstructionGraph that corresponds to ENTERING
* a particular native instruction
*
* @param nativeInstructionAddress The address of the native instruction
*
* @return The edge corresponding to entering the native instruction
*/
public Iterable<IInstructionGraphEdge> getIncomingEdgesForAddress(final IAddress nativeInstructionAddress) {
final ArrayList<IInstructionGraphEdge> result = new ArrayList<IInstructionGraphEdge>();
final EdgeCursor edgeCursor = m_internalGraph.edges();
while (edgeCursor.ok()) {
final Edge currentEdge = (Edge) edgeCursor.current();
final long targetAddress = m_nodesMap.get(currentEdge.target()).getReilInstruction().getAddress().toLong();
if ((targetAddress >> 8) == nativeInstructionAddress.toLong()) {
result.add(m_edgesMap.get(currentEdge));
}
edgeCursor.next();
}
return result;
}
use of y.base.EdgeCursor in project binnavi by google.
the class CReilInstructionGraph method getOutgoingEdgesForAddress.
/**
* Convenience method to obtain the edge in the ReilInstructionGraph that corresponds to LEAVING a
* particular native instruction
*
* @param nativeInstructionAddress The address of the native instruction
*
* @return The edge corresponding to entering the native instruction
*/
public Iterable<IInstructionGraphEdge> getOutgoingEdgesForAddress(final IAddress nativeInstructionAddress) {
final ArrayList<IInstructionGraphEdge> result = new ArrayList<IInstructionGraphEdge>();
final EdgeCursor edgeCursor = m_internalGraph.edges();
while (edgeCursor.ok()) {
final Edge edge = (Edge) edgeCursor.current();
final long sourceAddress = m_nodesMap.get(edge.source()).getReilInstruction().getAddress().toLong();
final long targetAddress = m_nodesMap.get(edge.target()).getReilInstruction().getAddress().toLong();
if (((targetAddress & 0xFF) == 0) && ((sourceAddress >> 8) == nativeInstructionAddress.toLong())) {
result.add(m_edgesMap.get(edge));
}
edgeCursor.next();
}
return result;
}
use of y.base.EdgeCursor in project binnavi by google.
the class YHelpers method closeGroup.
/**
* Closes a group node.
*
* @param graph The graph the group node belongs to.
* @param groupNode The group node to be closed.
*/
public static void closeGroup(final Graph2D graph, final Node groupNode) {
Preconditions.checkNotNull(graph, "Error: Graph argument can not be null");
Preconditions.checkNotNull(groupNode, "Error: Group node argument can not be null");
final HierarchyManager hierarchy = graph.getHierarchyManager();
final double w = graph.getWidth(groupNode);
final double h = graph.getHeight(groupNode);
final NodeList groupNodes = new NodeList();
groupNodes.add(groupNode);
graph.firePreEvent();
for (final NodeCursor nc = groupNodes.nodes(); nc.ok(); nc.next()) {
hierarchy.closeGroup(nc.node());
}
graph.firePostEvent();
// to the node
if ((w != graph.getWidth(groupNode)) || (h != graph.getHeight(groupNode))) {
for (final EdgeCursor ec = groupNode.outEdges(); ec.ok(); ec.next()) {
graph.setSourcePointRel(ec.edge(), YPoint.ORIGIN);
}
for (final EdgeCursor ec = groupNode.inEdges(); ec.ok(); ec.next()) {
graph.setTargetPointRel(ec.edge(), YPoint.ORIGIN);
}
}
graph.updateViews();
}
Aggregations