Beispiel #1
0
    def add_node(self, x, y, **kwargs):
        '''
    positional arguments:
      x (number)
      y (number)

    keyword arguments:
      name (str)
      anchor (bool):
        True - node is the anchor node.
        False - node is not the anchor node unless it is the first
                node added to the graph.
    '''
        name = process_name("Node " + str(len(Node._instances)), kwargs)

        # location
        self.nodes[name] = Node(x, y, label_string=name, **kwargs)
        self.unique_nodes.append(name)

        # anchor
        if ('anchor' in kwargs):
            if kwargs['anchor']:
                self.anchor = name
                self.anchored_nodes = [self.anchor]
        elif self.anchor is None:
            self.anchor = name
            self.anchored_nodes = [self.anchor]

        return name
Beispiel #2
0
  def add_node(self, x, y, **kwargs):
    '''
    positional arguments:
      x (number)
      y (number)

    keyword arguments:
      name (str)
      anchor (bool):
        True - node is the anchor node.
        False - node is not the anchor node unless it is the first
                node added to the graph.
    '''
    name = process_name("Node " + str( len(Node._instances) ), kwargs)

    # location
    self.nodes[name] = Node(x, y, label_string = name, **kwargs)
    self.unique_nodes.append(name)

    # anchor
    if ('anchor' in kwargs):
      if kwargs['anchor']:
        self.anchor = name
        self.anchored_nodes = [self.anchor]
    elif self.anchor is None:
      self.anchor = name
      self.anchored_nodes = [self.anchor]

    return name
Beispiel #3
0
 def __init__(self, junction_edges, **kwargs):
   self.junction_edges = junction_edges
   self.label_edge_number = process_label_edge_number(0, kwargs)
   self.labeled_edge = self.junction_edges[self.label_edge_number]
   self.label_location = process_label_location('top', kwargs)
   self.label_shift = process_label_shift(0.0, kwargs)
   self.name = process_name(None, kwargs)
   super(Junction, self).__init__(Point(0.0, 0.0), ll = self.label_location, **kwargs)
   self.label_string = self.name
   self.reflect = process_reflect(None, kwargs)
   self.angle = None
Beispiel #4
0
 def __init__(self, junction_edges, **kwargs):
     self.junction_edges = junction_edges
     self.label_edge_number = process_label_edge_number(0, kwargs)
     self.labeled_edge = self.junction_edges[self.label_edge_number]
     self.label_location = process_label_location('top', kwargs)
     self.label_shift = process_label_shift(0.0, kwargs)
     self.name = process_name(None, kwargs)
     super(Junction, self).__init__(Point(0.0, 0.0),
                                    ll=self.label_location,
                                    **kwargs)
     self.label_string = self.name
     self.reflect = process_reflect(None, kwargs)
     self.angle = None
Beispiel #5
0
  def copy(self, x=0.0, y=0.0, **kwargs):
    name = process_name(self.name + '(copy)', kwargs)

    duplicate = System(name, systems = self.subsystems)

    for component in self.components:
      duplicate.add_component(deepcopy(component))

    for name in self.graph.unique_nodes:
      duplicate.add_node(self.graph.nodes[name].x, self.graph.nodes[name].y, name = name)

    for connection, kwargs in zip(self.connections, self.connections_kwargs):
      duplicate.connect(*connection, **kwargs)

    duplicate.move(x, y)
    return duplicate
Beispiel #6
0
    def copy(self, x=0.0, y=0.0, **kwargs):
        '''
    default arguments:
      x (number)
      y (number)

    keyword arguments:
      name (str)
    '''
        name = process_name(self.name + '(copy)', kwargs)

        duplicate = deepcopy(self)

        self._remangle_subgraph_names(duplicate, name, duplicate.name)
        duplicate.name = name
        duplicate.move(x, y)
        Graph.graphs.append(duplicate.name)
        return duplicate
Beispiel #7
0
  def copy(self, x=0.0, y=0.0, **kwargs):
    '''
    default arguments:
      x (number)
      y (number)

    keyword arguments:
      name (str)
    '''
    name = process_name(self.name + '(copy)', kwargs)

    duplicate = deepcopy(self)

    self._remangle_subgraph_names(duplicate, name, duplicate.name)
    duplicate.name = name
    duplicate.move(x, y)
    Graph.graphs.append(duplicate.name)
    return duplicate
Beispiel #8
0
    def __init__(self, **kwargs):
        '''
    default arguments:
      name (str)
      graphs (list of graphs)
    '''

        self.node_line_width = process_line_width(1.5, kwargs)
        self.node_radius = process_radius(0.05, kwargs)

        self.namespace = ''
        self.namespace_size = 0
        self.nodes = OrderedDict()
        self.edges = OrderedDict()
        self.anchor = None
        self.anchored = False
        self.anchored_nodes = []
        self.anchored_edges = []
        # uniqueness -- just added to a graph. i.e. doesn't exist within a subgraph
        self.unique_nodes = []
        self.unique_anchored_edges = []
        self.unique_unanchored_edges = []
        self.subgraphs = []
        self.anchored_subgraphs = [
        ]  # subgraphs that are internally anchored and anchored.

        self.angle = 0.0
        self._angle_radians = 0.0

        self.name = process_name("Graph " + str(len(Graph.graphs)), kwargs)

        Graph.graphs.append(self.name)

        graphs = process_graphs([], kwargs)
        if len(graphs):
            for i, graph in enumerate(graphs):
                self.add_graph(graph)

                if i == 0:
                    self.anchor = graph.anchor
                    self.anchored_nodes.extend(graph.anchored_nodes)
                    self.anchored_edges.extend(graph.anchored_edges)
Beispiel #9
0
    def __init__(self, center_of_rotation, **kwargs):
        Component.stats[self.__class__.__name__] += 1

        super(Component, self).__init__(center_of_rotation, **kwargs)
        Transformation.__init__(self, center_of_rotation, **kwargs)

        self.name = process_name(None, kwargs)
        self.label_string = self.name

        self.graph = Graph(name=self.name)
        self._get_nodes()
        self._connect_nodes()

        self.face_color = process_face_color((1.0, 1.0, 1.0), kwargs)
        self.edge_color = process_edge_color((0.0, 0.0, 0.0), kwargs)
        self.line_width = process_line_width(1.5, kwargs)
        self.patch = None

        self._points = []
        self._connections = []
Beispiel #10
0
  def __init__(self, center_of_rotation, **kwargs):
    Component.stats[self.__class__.__name__] += 1

    super(Component, self).__init__(center_of_rotation, **kwargs)
    Transformation.__init__(self, center_of_rotation, **kwargs)

    self.name = process_name(None, kwargs)
    self.label_string = self.name

    self.graph = Graph(name = self.name)
    self._get_nodes()
    self._connect_nodes()

    self.face_color = process_face_color((1.0, 1.0, 1.0), kwargs)
    self.edge_color = process_edge_color((0.0, 0.0, 0.0), kwargs)
    self.line_width = process_line_width(1.5, kwargs)
    self.patch = None

    self._points = []
    self._connections = []
Beispiel #11
0
  def __init__(self, **kwargs):
    '''
    default arguments:
      name (str)
      graphs (list of graphs)
    '''

    self.node_line_width = process_line_width(1.5, kwargs)
    self.node_radius = process_radius(0.05, kwargs)

    self.namespace = ''
    self.namespace_size = 0
    self.nodes = OrderedDict()
    self.edges = OrderedDict()
    self.anchor = None
    self.anchored = False
    self.anchored_nodes = []
    self.anchored_edges = []
    # uniqueness -- just added to a graph. i.e. doesn't exist within a subgraph
    self.unique_nodes = []
    self.unique_anchored_edges = []
    self.unique_unanchored_edges = []
    self.subgraphs = []
    self.anchored_subgraphs = [] # subgraphs that are internally anchored and anchored.

    self.angle = 0.0
    self._angle_radians = 0.0

    self.name = process_name("Graph " + str(len(Graph.graphs)), kwargs)

    Graph.graphs.append(self.name)

    graphs = process_graphs([], kwargs)
    if len(graphs):
      for i, graph in enumerate(graphs):
        self.add_graph(graph)

        if i == 0:
          self.anchor = graph.anchor
          self.anchored_nodes.extend(graph.anchored_nodes)
          self.anchored_edges.extend(graph.anchored_edges)
Beispiel #12
0
    def connect(self, tail, head, **kwargs):
        '''
    positional arguments:
      tail (str): name of the 'tail' node
      head (str): name of the 'head' node (where the arrow points to)

    keyword arguments:
      name (str): name of the edge
      directional (bool): True - draw arrow pointing twords the head.
                          False - draw straight line between nodes.
    '''
        name = process_name("Edge " + str(len(Edge._instances)), kwargs)

        self._check_if_node_exists(tail)
        self._check_if_node_exists(head)
        self._check_if_edge_exists(tail, head, name)

        self.edges[name] = Edge(tail, head, **kwargs)

        if tail in self.anchored_nodes:
            self.anchored_edges.append(name)
            self.unique_anchored_edges.append(name)
            if head not in self.anchored_nodes:
                self.anchored_nodes.append(head)
                self._anchor_subgraph(head)
        elif head in self.anchored_nodes:
            self.anchored_edges.append(name)
            self.unique_anchored_edges.append(name)
            if tail not in self.anchored_nodes:
                self.anchored_nodes.append(tail)
                self._anchor_subgraph(tail)
        else:
            self.unique_unanchored_edges.append(name)

        self.anchor_graph()
        return name
Beispiel #13
0
  def connect(self, tail, head, **kwargs):
    '''
    positional arguments:
      tail (str): name of the 'tail' node
      head (str): name of the 'head' node (where the arrow points to)

    keyword arguments:
      name (str): name of the edge
      directional (bool): True - draw arrow pointing twords the head.
                          False - draw straight line between nodes.
    '''
    name = process_name("Edge " + str( len(Edge._instances) ), kwargs)

    self._check_if_node_exists(tail)
    self._check_if_node_exists(head)
    self._check_if_edge_exists(tail, head, name)

    self.edges[name] = Edge(tail, head, **kwargs)

    if tail in self.anchored_nodes:
      self.anchored_edges.append(name)
      self.unique_anchored_edges.append(name)
      if head not in self.anchored_nodes:
        self.anchored_nodes.append(head)
        self._anchor_subgraph(head)
    elif head in self.anchored_nodes:
      self.anchored_edges.append(name)
      self.unique_anchored_edges.append(name)
      if tail not in self.anchored_nodes:
        self.anchored_nodes.append(tail)
        self._anchor_subgraph(tail)
    else:
      self.unique_unanchored_edges.append(name)

    self.anchor_graph()
    return name