Search in sources :

Example 6 with Graph2D

use of y.view.Graph2D in project binnavi by google.

the class CGraphBuilder method buildGraph.

/**
   * Builds a displayable graph from a view.
   *
   * @param view The view to be turned into a graph.
   *
   * @return The generated graph.
   * @throws LoadCancelledException Thrown if loading the graph was canceled.
   */
public static ZyGraph buildGraph(final INaviView view) throws LoadCancelledException {
    Preconditions.checkNotNull(view, "IE01763: View argument can't be null");
    final Pair<Map<String, String>, ZyGraphViewSettings> viewSettings = loadSettings(view);
    final Map<String, String> rawSettings = viewSettings.first();
    final ZyGraphViewSettings graphSettings = viewSettings.second();
    graphSettings.rawSettings = rawSettings;
    final ZyGraphBuilder builder = new ZyGraphBuilder();
    ZyGraphBuilderManager.instance().setBuilder(view, builder);
    final Graph2D graph = builder.convert(view.getGraph().getNodes(), view.getGraph().getEdges(), graphSettings, view.getType() == ViewType.Native);
    final ZyGraph2DView graphView = new ZyGraph2DView(graph);
    final ZyGraph zyGraph = new ZyGraph(view, builder.getNodeMap(), builder.getEdgeMap(), graphSettings, graphView);
    zyGraph.getView().setCenter(CViewSettingsGenerator.createDoubleSetting(rawSettings, "view_center_x", 0), CViewSettingsGenerator.createDoubleSetting(rawSettings, "view_center_y", 0));
    zyGraph.getView().setWorldRect(CViewSettingsGenerator.createIntegerSetting(rawSettings, "world_rect_x", 0), CViewSettingsGenerator.createIntegerSetting(rawSettings, "world_rect_y", 0), CViewSettingsGenerator.createIntegerSetting(rawSettings, "world_rect_width", 800), CViewSettingsGenerator.createIntegerSetting(rawSettings, "world_rect_height", 600));
    zyGraph.getView().setZoom(CViewSettingsGenerator.createDoubleSetting(rawSettings, "zoom", 1));
    ZyGraphBuilderManager.instance().removeBuilder(view);
    return zyGraph;
}
Also used : ZyGraphBuilder(com.google.security.zynamics.binnavi.yfileswrap.zygraph.Builders.ZyGraphBuilder) ZyGraphViewSettings(com.google.security.zynamics.binnavi.ZyGraph.ZyGraphViewSettings) ZyGraph(com.google.security.zynamics.binnavi.yfileswrap.zygraph.ZyGraph) ZyGraph2DView(com.google.security.zynamics.zylib.yfileswrap.gui.zygraph.ZyGraph2DView) HashMap(java.util.HashMap) Map(java.util.Map) Graph2D(y.view.Graph2D)

Example 7 with Graph2D

use of y.view.Graph2D in project binnavi by google.

the class ZyGraphBuilder method convert.

/**
   * Converts a view to a Graph2D object.
   *
   * @param nodes Nodes to convert.
   * @param edges Edges to convert.
   * @param graphSettings Graph settings used to build the graph.
   * @param adjustColors True, to initialize the colors of the nodes. False, otherwise.
   *
   * @return The created Graph2D object.
   * @throws LoadCancelledException Thrown if loading the graph was cancelled.
   */
public Graph2D convert(final Collection<INaviViewNode> nodes, final Collection<INaviEdge> edges, final ZyGraphViewSettings graphSettings, final boolean adjustColors) throws LoadCancelledException {
    Preconditions.checkNotNull(nodes, "IE00905: View can not be null");
    Preconditions.checkNotNull(edges, "IE00906: Edges argument can not be null");
    if (!m_loadReporter.report(GraphBuilderEvents.Started)) {
        throw new LoadCancelledException();
    }
    m_loadReporter.start();
    final Graph2D graph2D = new Graph2D();
    final HierarchyManager hierarchyManager = new HierarchyManager(graph2D);
    graph2D.setHierarchyManager(hierarchyManager);
    hierarchyManager.addHierarchyListener(new GroupNodeRealizer.StateChangeListener());
    checkCancellation(GraphBuilderEvents.InitializedGraph);
    // Keep track of all connections between view nodes and yfiles nodes
    final HashMap<INaviViewNode, Node> rawNodeToNodeMap = new HashMap<INaviViewNode, Node>();
    // To convert the view into a Graph2D object, it is necessary to convert every node
    // and every edge from the view into the corresponding yfiles objects.
    convertNodes(nodes, graph2D, rawNodeToNodeMap, graphSettings);
    checkCancellation(GraphBuilderEvents.ConvertedNodes);
    convertEdges(edges, graph2D, rawNodeToNodeMap, adjustColors);
    checkCancellation(GraphBuilderEvents.ConvertedEdges);
    setupGroupNodes(nodes, graph2D, rawNodeToNodeMap);
    checkCancellation(GraphBuilderEvents.CreatedGroupNodes);
    checkCancellation(GraphBuilderEvents.Finished);
    return graph2D;
}
Also used : GroupNodeRealizer(y.view.hierarchy.GroupNodeRealizer) HierarchyManager(y.view.hierarchy.HierarchyManager) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Node(y.base.Node) NaviNode(com.google.security.zynamics.binnavi.yfileswrap.zygraph.NaviNode) INaviViewNode(com.google.security.zynamics.binnavi.disassembly.INaviViewNode) INaviViewNode(com.google.security.zynamics.binnavi.disassembly.INaviViewNode) LoadCancelledException(com.google.security.zynamics.binnavi.Database.Exceptions.LoadCancelledException) Graph2D(y.view.Graph2D)

Example 8 with Graph2D

use of y.view.Graph2D in project binnavi by google.

the class ZyGraphDefaultRenderer method bringNodeToFront.

public void bringNodeToFront(final Node node) {
    final Graph2D g = (Graph2D) node.getGraph();
    final NodeRealizer r = g.getRealizer(node);
    if (r.isSelected()) {
        // This does not work properly! Why? NH
        for (final NodeCursor nc = g.selectedNodes(); nc.ok(); nc.next()) {
            m_nodesInDrawingOrder.remove(nc.node());
            m_nodesInDrawingOrder.add(nc.node());
        }
    } else {
        // This seems to work correctly.
        m_nodesInDrawingOrder.remove(node);
        m_nodesInDrawingOrder.add(node);
    }
}
Also used : ZyGroupNodeRealizer(com.google.security.zynamics.zylib.yfileswrap.gui.zygraph.realizers.ZyGroupNodeRealizer) NodeRealizer(y.view.NodeRealizer) NodeCursor(y.base.NodeCursor) Graph2D(y.view.Graph2D)

Example 9 with Graph2D

use of y.view.Graph2D in project binnavi by google.

the class ZyGraphLayeredRenderer method isAnyParentNodeSelected.

/**
   * Determines whether any of the parent nodes of the given node is selected.
   */
private boolean isAnyParentNodeSelected(final Node n) {
    final Graph2D graph = (Graph2D) n.getGraph();
    final HierarchyManager hierarchy = graph.getHierarchyManager();
    if (hierarchy == null) {
        return false;
    }
    boolean result = false;
    Node parent = hierarchy.getParentNode(n);
    while (parent != null) {
        if (graph.isSelected(parent)) {
            result = true;
            break;
        }
        parent = hierarchy.getParentNode(parent);
    }
    return result;
}
Also used : HierarchyManager(y.view.hierarchy.HierarchyManager) Node(y.base.Node) Graph2D(y.view.Graph2D)

Example 10 with Graph2D

use of y.view.Graph2D in project binnavi by google.

the class CEdgeHighlighter method highlightEdgesOfNode.

/**
   * Highlights all edges of a node.
   * 
   * @param node The node whose edges are highlighted.
   * @param highlight True to add highlighting to the edges. False to remove it.
   */
public static void highlightEdgesOfNode(final Node node, final boolean highlight) {
    final EdgeCursor edges = node.edges();
    int edgeCount = node.degree();
    for (Edge edge = edges.edge(); edgeCount > 0; edgeCount--) {
        final EdgeRealizer edgeRealizer = ((Graph2D) node.getGraph()).getRealizer(edge);
        highlightEdge(edgeRealizer, highlight);
        edges.cyclicNext();
        edge = edges.edge();
    }
}
Also used : EdgeCursor(y.base.EdgeCursor) EdgeRealizer(y.view.EdgeRealizer) Edge(y.base.Edge) Graph2D(y.view.Graph2D)

Aggregations

Graph2D (y.view.Graph2D)12 HierarchyManager (y.view.hierarchy.HierarchyManager)5 NaviNode (com.google.security.zynamics.binnavi.yfileswrap.zygraph.NaviNode)3 MockSqlProvider (com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider)2 CFunction (com.google.security.zynamics.binnavi.disassembly.CFunction)2 CInstruction (com.google.security.zynamics.binnavi.disassembly.CInstruction)2 CModule (com.google.security.zynamics.binnavi.disassembly.Modules.CModule)2 CView (com.google.security.zynamics.binnavi.disassembly.views.CView)2 ZyLabelContent (com.google.security.zynamics.zylib.gui.zygraph.realizers.ZyLabelContent)2 ZyGraph2DView (com.google.security.zynamics.zylib.yfileswrap.gui.zygraph.ZyGraph2DView)2 ZyNormalNodeRealizer (com.google.security.zynamics.zylib.yfileswrap.gui.zygraph.realizers.ZyNormalNodeRealizer)2 HashMap (java.util.HashMap)2 Edge (y.base.Edge)2 EdgeCursor (y.base.EdgeCursor)2 Node (y.base.Node)2 NodeCursor (y.base.NodeCursor)2 NodeList (y.base.NodeList)2 YPoint (y.geom.YPoint)2 EdgeRealizer (y.view.EdgeRealizer)2 LoadCancelledException (com.google.security.zynamics.binnavi.Database.Exceptions.LoadCancelledException)1