Exemple #1
0
def network_draw_vertices(network,
                          keys=None,
                          color=None,
                          layer=None,
                          clear_layer=False,
                          redraw=True):
    """Draw a selection of vertices of a network.

    Parameters
    ----------
    keys : list (None)
        A list of vertex keys identifying which vertices to draw.
        Default is to draw all vertices.
    color : str, tuple, dict (None)
        The color specififcation for the vertices.
        Colors should be specified in the form of a string (hex colors) or as a tuple of RGB components.
        To apply the same color to all vertices, provide a single color specification.
        Individual colors can be assigned using a dictionary of key-color pairs.
        Missing keys will be assigned the default vertex color (``self.defaults['color.vertex']``).
        Default is to inherit the color from the layer.
    layer : str (None)
        The layer in which the vertices are drawn.
        Default is to draw in the current layer.
    clear_layer : bool (False)
        Clear the drawing layer.
    redraw : bool (True)
        Redraw the view after adding the vertices.

    Notes
    -----
    The vertices are named using the following template:
    ``"{}.vertex.{}".format(self.network.name, key)``.
    This name is used afterwards to identify vertices of the networkin the Rhino model.

    Examples
    --------
    >>> network_draw_vertices(network)
    >>> network_draw_vertices(network, color='#ff0000')
    >>> network_draw_vertices(network, color=(255, 0, 0))
    >>> network_draw_vertices(network, keys=network.vertices_on_boundary())
    >>> network_draw_vertices(network, color={(u, v): '#00ff00' for u, v in network.vertices_on_boundary()})

    """
    artist = NetworkArtist(network)
    artist.layer = layer
    if clear_layer:
        artist.clear_layer()
    artist.clear_vertices()
    artist.draw_vertices(keys=keys, color=color)
    if redraw:
        artist.redraw()
Exemple #2
0
def network_draw(network,
                 layer=None,
                 clear_layer=False,
                 clear_vertices=True,
                 clear_edges=True,
                 vertexcolor=None,
                 edgecolor=None):
    """Draw a network data structure in Rhino.

    Parameters
    ----------
    network : compas.datastructures.Network
        A network object.
    layer : str (None)
        The layer to draw in.
        Default is the current layer.
    clear_layer : bool (False)
        Clear the layer.
    vertexcolor : list, tuple, str, dict (None)
        The color specification for the vertices.
        * list, tuple: rgb color, with color specs between 0 and 255 (e.g. ``(255, 0, 0)``).
        * str: hex color (e.g. ``'#ff0000'``).
        * dict: dictionary of hex or rgb colors.
    edgecolor : list, tuple, str, dict (None)
        The color specification for the edges.
        * list, tuple: rgb color, with color specs between 0 and 255 (e.g. ``(255, 0, 0)``).
        * str: hex color (e.g. ``'#ff0000'``).
        * dict: dictionary of hex or rgb color.

    Notes
    -----
    * Any network objects with the same name that are already present in the
      model will be deleted by this function.
    * To also clear the entire layer the network will be drawn on, for
      example, if you have a dedicated network layer, use the ``clear_layer`` flag as well.

    See Also
    --------
    * :func:`network_draw_vertices`
    * :func:`network_draw_edges`

    Examples
    --------
    >>>

    """
    artist = NetworkArtist(network)
    artist.layer = layer

    if clear_layer:
        artist.clear_layer()

    if clear_vertices:
        artist.clear_vertices()

    if clear_edges:
        artist.clear_edges()

    artist.draw_vertices(color=vertexcolor)
    artist.draw_edges(color=edgecolor)
    artist.redraw()