use of y.base.Edge in project binnavi by google.
the class ZyNodeRealizer method scalePortCoordinates.
protected void scalePortCoordinates(final Node node, final double wOld, final double wNew, final double hOld, final double hNew) {
final Graph2D graph = (Graph2D) node.getGraph();
final double wScaling = wOld > 0 ? wNew / wOld : 1.0d;
final double hScaling = hOld > 0 ? hNew / hOld : 1.0d;
for (Edge e = node.firstOutEdge(); e != null; e = e.nextOutEdge()) {
final EdgeRealizer er = graph.getRealizer(e);
final Port port = er.getSourcePort();
final double px = port.getOffsetX() * wScaling;
final double py = port.getOffsetY() * hScaling;
port.setOffsets(px, py);
graph.setSourcePointRel(e, new YPoint(px, py));
}
for (Edge e = node.firstInEdge(); e != null; e = e.nextInEdge()) {
final EdgeRealizer er = graph.getRealizer(e);
final Port port = er.getTargetPort();
final double px = port.getOffsetX() * wScaling;
final double py = port.getOffsetY() * hScaling;
port.setOffsets(px, py);
graph.setTargetPointRel(e, new YPoint(px, py));
}
}
use of y.base.Edge in project binnavi by google.
the class CBendClickedLeftState method mouseMoved.
@Override
public IMouseStateChange mouseMoved(final MouseEvent event, final AbstractZyGraph<?, ?> g) {
final double x = g.getEditMode().translateX(event.getX());
final double y = g.getEditMode().translateY(event.getY());
final HitInfo hitInfo = g.getGraph().getHitInfo(x, y);
if (hitInfo.hasHitNodes()) {
m_factory.createBendExitState(m_bend, event);
return CHitNodesTransformer.enterNode(m_factory, event, hitInfo);
} else if (hitInfo.hasHitNodeLabels()) {
throw new IllegalStateException();
} else if (hitInfo.hasHitEdges()) {
m_factory.createBendExitState(m_bend, event);
final Edge e = hitInfo.getHitEdge();
return new CStateChange(m_factory.createEdgeEnterState(e, event), true);
} else if (hitInfo.hasHitEdgeLabels()) {
m_factory.createBendExitState(m_bend, event);
final EdgeLabel l = hitInfo.getHitEdgeLabel();
return new CStateChange(m_factory.createEdgeLabelEnterState(l, event), true);
} else if (hitInfo.hasHitBends()) {
return CHitBendsTransformer.changeBend(m_factory, event, hitInfo, m_bend);
} else if (hitInfo.hasHitPorts()) {
return new CStateChange(this, true);
} else {
m_factory.createBendExitState(m_bend, event);
return new CStateChange(this, true);
}
}
use of y.base.Edge in project binnavi by google.
the class CBendEnterState method mouseMoved.
@Override
public IMouseStateChange mouseMoved(final MouseEvent event, final AbstractZyGraph<?, ?> graph) {
final double x = m_graph.getEditMode().translateX(event.getX());
final double y = m_graph.getEditMode().translateY(event.getY());
final HitInfo hitInfo = m_graph.getGraph().getHitInfo(x, y);
if (hitInfo.hasHitNodes()) {
m_factory.createBendExitState(m_bend, event);
return CHitNodesTransformer.enterNode(m_factory, event, hitInfo);
} else if (hitInfo.hasHitNodeLabels()) {
throw new IllegalStateException();
} else if (hitInfo.hasHitEdges()) {
final Edge e = hitInfo.getHitEdge();
m_factory.createBendExitState(m_bend, event);
return new CStateChange(m_factory.createEdgeEnterState(e, event), true);
} else if (hitInfo.hasHitEdgeLabels()) {
final EdgeLabel l = hitInfo.getHitEdgeLabel();
m_factory.createBendExitState(m_bend, event);
return new CStateChange(m_factory.createEdgeLabelEnterState(l, event), true);
} else if (hitInfo.hasHitBends()) {
return CHitBendsTransformer.changeBend(m_factory, event, hitInfo, m_bend);
} else if (hitInfo.hasHitPorts()) {
return new CStateChange(this, true);
} else {
return new CStateChange(m_factory.createBendExitState(m_bend, event), true);
}
}
use of y.base.Edge 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.Edge in project binnavi by google.
the class ZyGraphFactory method generateTestGraph.
public static ZyGraph generateTestGraph() throws FileReadException, CouldntLoadDataException, LoadCancelledException, CouldntSaveDataException {
ConfigManager.instance().read();
final MockDatabase database = new MockDatabase();
final SQLProvider provider = new MockSqlProvider();
final CModule module = new CModule(1, "", "", new Date(), new Date(), CommonTestObjects.MD5, CommonTestObjects.SHA1, 0, 0, new CAddress(0), new CAddress(0), null, null, Integer.MAX_VALUE, false, provider);
final ZyGraphViewSettings settings = new ZyGraphViewSettings(new CallGraphSettingsConfigItem());
settings.getLayoutSettings().setDefaultGraphLayout(LayoutStyle.CIRCULAR);
database.getContent().addModule(module);
final MockDatabaseManager manager = new MockDatabaseManager();
manager.addDatabase(database);
module.load();
final CView m_view = module.getContent().getViewContainer().createView("name", "description");
final LinkedHashMap<Node, NaviNode> nodeMap = new LinkedHashMap<Node, NaviNode>();
final ZyGraph2DView g2dView = new ZyGraph2DView();
final LinkedHashMap<Edge, NaviEdge> edgeMap = new LinkedHashMap<Edge, NaviEdge>();
final Node node1 = g2dView.getGraph2D().createNode();
final COperandTreeNode rootNode1 = new COperandTreeNode(-1, IOperandTree.NODE_TYPE_SIZE_PREFIX_ID, "b4", null, new ArrayList<IReference>(), provider, module.getTypeManager(), module.getContent().getTypeInstanceContainer());
final COperandTreeNode childNode1 = new COperandTreeNode(-1, IOperandTree.NODE_TYPE_REGISTER_ID, "eax", null, new ArrayList<IReference>(), provider, module.getTypeManager(), module.getContent().getTypeInstanceContainer());
COperandTreeNode.link(rootNode1, childNode1);
final COperandTreeNode rootNode2 = new COperandTreeNode(-1, IOperandTree.NODE_TYPE_SIZE_PREFIX_ID, "b4", null, new ArrayList<IReference>(), provider, module.getTypeManager(), module.getContent().getTypeInstanceContainer());
final COperandTreeNode childNode2 = new COperandTreeNode(-1, IOperandTree.NODE_TYPE_REGISTER_ID, "ebx", null, new ArrayList<IReference>(), provider, module.getTypeManager(), module.getContent().getTypeInstanceContainer());
COperandTreeNode.link(rootNode2, childNode2);
final COperandTree operand1 = new COperandTree(rootNode1, provider, module.getTypeManager(), module.getContent().getTypeInstanceContainer());
final COperandTree operand2 = new COperandTree(rootNode2, provider, module.getTypeManager(), module.getContent().getTypeInstanceContainer());
final ArrayList<COperandTree> operands1 = Lists.newArrayList(operand1, operand2);
final List<INaviInstruction> instructions1 = Lists.newArrayList((INaviInstruction) new MockInstruction(new CAddress(0x123456), "mov", operands1, null, module));
final INaviCodeNode rawNode1 = m_view.getContent().createCodeNode(null, instructions1);
final ZyLabelContent content = ZyCodeNodeBuilder.buildContent(rawNode1, settings, null);
nodeMap.put(node1, new NaviNode(node1, new ZyNormalNodeRealizer<NaviNode>(content), rawNode1));
final Node node2 = g2dView.getGraph2D().createNode();
final List<INaviInstruction> instructions2 = Lists.newArrayList((INaviInstruction) new MockInstruction());
final INaviCodeNode rawNode2 = m_view.getContent().createCodeNode(null, instructions2);
final ZyLabelContent content2 = ZyCodeNodeBuilder.buildContent(rawNode2, settings, null);
nodeMap.put(node2, new NaviNode(node2, new ZyNormalNodeRealizer<NaviNode>(content2), rawNode2));
rawNode2.setColor(Color.RED);
rawNode2.setVisible(false);
final CTag tag = new CTag(0, "Tag", "Description", TagType.NODE_TAG, new MockSqlProvider());
rawNode2.tagNode(tag);
final Node node3 = g2dView.getGraph2D().createNode();
final String mnemonicName = "call";
final List<COperandTree> operandTrees = new ArrayList<COperandTree>();
final int type = ExpressionType.REGISTER.ordinal();
final CReference reference = new CReference(new CAddress(0x123), ReferenceType.CALL_DIRECT);
final List<IReference> referencea = new ArrayList<IReference>();
referencea.add(reference);
final COperandTreeNode root = new COperandTreeNode(0, type, "eax", null, referencea, provider, module.getTypeManager(), module.getContent().getTypeInstanceContainer());
final COperandTree operandTree = new COperandTree(root, provider, module.getTypeManager(), module.getContent().getTypeInstanceContainer());
operandTrees.add(0, operandTree);
final List<INaviInstruction> instructions3 = Lists.newArrayList((INaviInstruction) new MockInstruction(mnemonicName, operandTrees, m_globalComment));
final INaviCodeNode rawNode3 = m_view.getContent().createCodeNode(null, instructions3);
final ZyLabelContent content3 = ZyCodeNodeBuilder.buildContent(rawNode3, settings, null);
nodeMap.put(node3, new NaviNode(node3, new ZyNormalNodeRealizer<NaviNode>(content3), rawNode3));
final Edge edge = g2dView.getGraph2D().createEdge(node1, node2);
final INaviEdge rawEdge = m_view.getContent().createEdge(rawNode1, rawNode2, EdgeType.JUMP_UNCONDITIONAL);
edgeMap.put(edge, new NaviEdge(nodeMap.get(node1), nodeMap.get(node2), edge, new ZyEdgeRealizer<NaviEdge>(new ZyLabelContent(null), null), rawEdge));
final Edge edge2 = g2dView.getGraph2D().createEdge(node2, node3);
final INaviEdge rawEdge2 = m_view.getContent().createEdge(rawNode2, rawNode3, EdgeType.JUMP_UNCONDITIONAL);
edgeMap.put(edge2, new NaviEdge(nodeMap.get(node2), nodeMap.get(node3), edge, new ZyEdgeRealizer<NaviEdge>(new ZyLabelContent(null), null), rawEdge2));
return new ZyGraph(m_view, nodeMap, edgeMap, settings, g2dView);
}
Aggregations