Beispiel #1
0
 def add_wired_edge(self, src: CanvasNode, dst: CanvasNode,
                    link: Link) -> None:
     token = create_edge_token(src.id, dst.id)
     if token in self.edges and link.options.unidirectional:
         edge = self.edges[token]
         edge.asymmetric_link = link
     elif token not in self.edges:
         node1 = src.core_node
         node2 = dst.core_node
         src_pos = (node1.position.x, node1.position.y)
         dst_pos = (node2.position.x, node2.position.y)
         edge = CanvasEdge(self, src.id, src_pos, dst_pos)
         edge.token = token
         edge.dst = dst.id
         edge.set_link(link)
         edge.check_wireless()
         src.edges.add(edge)
         dst.edges.add(edge)
         self.edges[edge.token] = edge
         self.core.links[edge.token] = edge
         if link.iface1:
             iface1 = link.iface1
             self.core.iface_to_edge[(node1.id, iface1.id)] = token
             src.ifaces[iface1.id] = iface1
             edge.src_iface = iface1
         if link.iface2:
             iface2 = link.iface2
             self.core.iface_to_edge[(node2.id, iface2.id)] = edge.token
             dst.ifaces[iface2.id] = iface2
             edge.dst_iface = iface2
Beispiel #2
0
    def draw_session(self, session: core_pb2.Session):
        """
        Draw existing session.
        """
        # draw existing nodes
        for core_node in session.nodes:
            logging.debug("drawing node %s", core_node)
            # peer to peer node is not drawn on the GUI
            if NodeUtils.is_ignore_node(core_node.type):
                continue
            image = NodeUtils.node_image(core_node, self.app.guiconfig,
                                         self.app.app_scale)
            # if the gui can't find node's image, default to the "edit-node" image
            if not image:
                image = Images.get(ImageEnum.EDITNODE,
                                   int(ICON_SIZE * self.app.app_scale))
            x = core_node.position.x
            y = core_node.position.y
            node = CanvasNode(self.app, x, y, core_node, image)
            self.nodes[node.id] = node
            self.core.canvas_nodes[core_node.id] = node

        # draw existing links
        for link in session.links:
            logging.debug("drawing link: %s", link)
            canvas_node_one = self.core.canvas_nodes[link.node_one_id]
            node_one = canvas_node_one.core_node
            canvas_node_two = self.core.canvas_nodes[link.node_two_id]
            node_two = canvas_node_two.core_node
            token = create_edge_token(canvas_node_one.id, canvas_node_two.id)

            if link.type == core_pb2.LinkType.WIRELESS:
                self.add_wireless_edge(canvas_node_one, canvas_node_two, link)
            else:
                if token not in self.edges:
                    src_pos = (node_one.position.x, node_one.position.y)
                    dst_pos = (node_two.position.x, node_two.position.y)
                    edge = CanvasEdge(self, canvas_node_one.id, src_pos,
                                      dst_pos)
                    edge.token = token
                    edge.dst = canvas_node_two.id
                    edge.set_link(link)
                    edge.check_wireless()
                    canvas_node_one.edges.add(edge)
                    canvas_node_two.edges.add(edge)
                    self.edges[edge.token] = edge
                    self.core.links[edge.token] = edge
                    if link.HasField("interface_one"):
                        canvas_node_one.interfaces.append(link.interface_one)
                        edge.src_interface = link.interface_one
                    if link.HasField("interface_two"):
                        canvas_node_two.interfaces.append(link.interface_two)
                        edge.dst_interface = link.interface_two
                elif link.options.unidirectional:
                    edge = self.edges[token]
                    edge.asymmetric_link = link
                else:
                    logging.error("duplicate link received: %s", link)

        # raise the nodes so they on top of the links
        self.tag_raise(tags.NODE)
Beispiel #3
0
    def draw_session(self, session):
        """
        Draw existing session.

        :return: nothing
        """
        # draw existing nodes
        for core_node in session.nodes:
            # peer to peer node is not drawn on the GUI
            if NodeUtils.is_ignore_node(core_node.type):
                continue

            # draw nodes on the canvas
            logging.info("drawing core node: %s", core_node)
            image = NodeUtils.node_icon(core_node.type, core_node.model)
            if core_node.icon:
                try:
                    image = Images.create(core_node.icon, nodeutils.ICON_SIZE)
                except OSError:
                    logging.error("invalid icon: %s", core_node.icon)

            x = core_node.position.x
            y = core_node.position.y
            node = CanvasNode(self.master, x, y, core_node, image)
            self.nodes[node.id] = node
            self.core.canvas_nodes[core_node.id] = node

        # draw existing links
        for link in session.links:
            logging.info("drawing link: %s", link)
            canvas_node_one = self.core.canvas_nodes[link.node_one_id]
            node_one = canvas_node_one.core_node
            canvas_node_two = self.core.canvas_nodes[link.node_two_id]
            node_two = canvas_node_two.core_node
            token = tuple(sorted((canvas_node_one.id, canvas_node_two.id)))

            if link.type == core_pb2.LinkType.WIRELESS:
                self.add_wireless_edge(canvas_node_one, canvas_node_two)
            else:
                if token not in self.edges:
                    edge = CanvasEdge(
                        node_one.position.x,
                        node_one.position.y,
                        node_two.position.x,
                        node_two.position.y,
                        canvas_node_one.id,
                        self,
                    )
                    edge.token = token
                    edge.dst = canvas_node_two.id
                    edge.set_link(link)
                    edge.check_wireless()
                    canvas_node_one.edges.add(edge)
                    canvas_node_two.edges.add(edge)
                    self.edges[edge.token] = edge
                    self.core.links[edge.token] = edge
                    if link.HasField("interface_one"):
                        canvas_node_one.interfaces.append(link.interface_one)
                    if link.HasField("interface_two"):
                        canvas_node_two.interfaces.append(link.interface_two)
                elif link.options.unidirectional:
                    edge = self.edges[token]
                    edge.asymmetric_link = link
                else:
                    logging.error("duplicate link received: %s", link)

        # raise the nodes so they on top of the links
        self.tag_raise(tags.NODE)