示例#1
0
    def draw_angles(self, tol=5.0):
        self.clear_angles()

        a = self.form.edges_attribute('_a')
        a_max = tol
        a_min = 0
        a_range = a_max - a_min

        if a_range:
            labels = []
            for u, v, attr in self.form.edges(True):
                a = 180 * attr['_a'] / 3.14159
                if a > tol:
                    labels.append({
                        'pos':
                        self.form.edge_midpoint(u, v),
                        'text':
                        "{:.2f}".format(attr['a'] / 3.14159 * 180),
                        'color':
                        i_to_green((attr['a'] - a_min) / a_range),
                        'name':
                        "{}.angle.{}-{}".format(self.form.name, u, v)
                    })

            compas_rhino.draw_labels(labels,
                                     layer=self.layer,
                                     clear=False,
                                     redraw=False)
示例#2
0
    def draw_nodelabels(self, text=None, color=None):
        """Draw labels for a selection nodes.

        Parameters
        ----------
        text : dict
            A dictionary of node labels as key-text pairs.
            The default value is ``None``, in which case every node will be labelled with its key.
        color : str, tuple, dict
            The color sepcification of the labels.
            String values are interpreted as hex colors.
            Tuples are interpreted as RGB component specifications.
            If a dictionary of specififcations is provided,
            the keys of the should refer to node keys and the values should be color specifications in the form of strings or tuples.
            The default value is ``None``, in which case the labels are assigned the default node color (``self.settings['color.nodes']``).

        Returns
        -------
        list
            The GUIDs of the created Rhino objects.

        """
        if text is None:
            textdict = {key: str(key) for key in self.network.nodes()}
        elif isinstance(text, dict):
            textdict = text
        elif text == 'key':
            textdict = {key: str(key) for key in self.network.nodes()}
        elif text == 'index':
            textdict = {
                key: str(index)
                for index, key in enumerate(self.network.nodes())
            }
        else:
            raise NotImplementedError

        colordict = color_to_colordict(color,
                                       textdict.keys(),
                                       default=self.settings['color.nodes'],
                                       colorformat='rgb',
                                       normalize=False)
        labels = []
        for key, text in iter(textdict.items()):
            labels.append({
                'pos':
                self.network.node_coordinates(key),
                'name':
                "{}.nodelabel.{}".format(self.network.name, key),
                'color':
                colordict[key],
                'text':
                textdict[key]
            })

        guids = compas_rhino.draw_labels(labels,
                                         layer=self.layer,
                                         clear=False,
                                         redraw=False)
        self.guids += guids
        return guids
示例#3
0
    def draw_edgelabels(self, text=None, color=None):
        """Draw labels for a selection of edges.

        Parameters
        ----------
        text : dict, optional
            A dictionary of edge labels as edge-text pairs.
            The default value is ``None``, in which case every edge will be labelled with its key.
        color : tuple or dict of tuple, optional
            The color specification of the labels.
            The default color is the same as the default color for edges.

        Returns
        -------
        list
            The GUIDs of the created Rhino objects.

        """
        if text is None:
            edge_text = {(u, v): "{}-{}".format(u, v) for u, v in self.edges}
        elif isinstance(text, dict):
            edge_text = text
        else:
            raise NotImplementedError
        vertex_xyz = self.vertex_xyz
        edge_color = colordict(color, edge_text.keys(), default=self.default_edgecolor)
        labels = []
        for edge in edge_text:
            labels.append({
                'pos': centroid_points([vertex_xyz[edge[0]], vertex_xyz[edge[1]]]),
                'name': "{}.edgelabel.{}-{}".format(self.mesh.name, *edge),
                'color': edge_color[edge],
                'text': edge_text[edge]
            })
        return compas_rhino.draw_labels(labels, layer=self.layer, clear=False, redraw=False)
示例#4
0
    def draw_strips_division_num(self, redraw=False):
        """draw the subdivision number for all strips"""

        labels = []
        strips = []
        for strip in list(self._edge_strips.keys()):

            division = self._strip_division[strip][0]
            color = self._strip_division[strip][1]
            edges = self._edge_strips[strip]
            boundary_edge_a_point = self.item.edge_midpoint(*edges[0])
            boundary_edge_b_point = self.item.edge_midpoint(*edges[-1])
            labels.append({
                'pos': boundary_edge_a_point,
                'text': str(division),
                'color': color
            })
            labels.append({
                'pos': boundary_edge_b_point,
                'text': str(division),
                'color': color
            })
            strips.append(strip)
            strips.append(strip)

        guids = compas_rhino.draw_labels(labels,
                                         layer=self.settings['layer.coarse'],
                                         clear=False,
                                         redraw=redraw)
        self.guid_strip_division = zip(guids, strips)
示例#5
0
    def draw_edgelabels(self, text=None, color=None):
        """Draw labels for a selection of edges.

        Parameters
        ----------
        text : dict
            A dictionary of edge labels as key-text pairs.
            The default value is ``None``, in which case every edge will be labelled with its key.
        color : str, tuple, dict
            The color sepcification of the labels.
            String values are interpreted as hex colors (e.g. ``'#ff0000'`` for red).
            Tuples are interpreted as RGB component specifications (e.g. ``(255, 0, 0) for red``.
            Individual colors can be assigned using a dictionary
            of key-color pairs. Missing keys will be assigned the default face
            color (``self.settings['edge.color']``).
            The default is ``None``, in which case all edges are assigned the
            default edge color.

        Notes
        -----
        All labels are assigned a name using the folling template:
        ``"{}.edge.{}".format(self.network.name, key)``.

        """
        if text is None:
            textdict = {(u, v): "{}-{}".format(u, v)
                        for u, v in self.network.edges()}
        elif isinstance(text, dict):
            textdict = text
        else:
            raise NotImplementedError

        colordict = color_to_colordict(color,
                                       textdict.keys(),
                                       default=self.settings.get('color.edge'),
                                       colorformat='rgb',
                                       normalize=False)
        labels = []

        for (u, v), text in iter(textdict.items()):
            labels.append({
                'pos':
                self.network.edge_midpoint(u, v),
                'name':
                "{}.edge.label.{}-{}".format(self.network.name, u, v),
                'color':
                colordict[(u, v)],
                'text':
                textdict[(u, v)],
                'layer':
                self.network.get_edge_attribute((u, v), 'layer', None)
            })

        return compas_rhino.draw_labels(labels,
                                        layer=self.layer,
                                        clear=False,
                                        redraw=False)
示例#6
0
    def draw_facelabels(self, text=None, color=None):
        """Draw labels for a selection of faces.

        Parameters
        ----------
        text : dict
            A dictionary of face labels as key-text pairs.
            The default value is ``None``, in which case every face will be labelled with its key.
        color : str, tuple, dict
            The color sepcification of the labels.
            String values are interpreted as hex colors (e.g. ``'#ff0000'`` for red).
            Tuples are interpreted as RGB component specifications (e.g. ``(255, 0, 0) for red``.
            If a dictionary of specififcations is provided, the keys of the
            should refer to face keys and the values should be color
            specifications in the form of strings or tuples.
            The default value is ``None``, in which case the labels are assigned
            the default face color (``self.defaults['color.face']``).

        Notes
        -----
        The face labels are named using the following template:
        ``"{}.face.label.{}".format(self.datastructure.name, key)``.
        This name is used afterwards to identify faces and face labels in the Rhino model.

        """
        if text is None:
            textdict = {key: str(key) for key in self.datastructure.faces()}
        elif isinstance(text, dict):
            textdict = text
        else:
            raise NotImplementedError

        colordict = color_to_colordict(color,
                                       textdict.keys(),
                                       default=self.defaults.get('color.face'),
                                       colorformat='rgb',
                                       normalize=False)

        labels = []
        for key, text in iter(textdict.items()):
            labels.append({
                'pos':
                self.datastructure.face_center(key),
                'name':
                "{}.face.label.{}".format(self.datastructure.name, key),
                'color':
                colordict[key],
                'text':
                textdict[key],
                'layer':
                self.datastructure.face_attribute(key, 'layer', None)
            })
        return compas_rhino.draw_labels(labels,
                                        layer=self.layer,
                                        clear=False,
                                        redraw=False)
示例#7
0
def _draw_labels(pattern, openings):
    labels = []
    for i, opening in enumerate(openings):
        points = pattern.datastructure.vertices_attributes('xyz', keys=opening)
        centroid = centroid_points(points)
        labels.append({'pos': centroid, 'text': str(i)})
    return compas_rhino.draw_labels(labels,
                                    layer=pattern.settings['layer'],
                                    clear=False,
                                    redraw=True)
示例#8
0
    def draw_edgelabels(self, text=None, color=None):
        """Draw labels for a selection of edges.

        Parameters
        ----------
        text : dict
            A dictionary of edge labels as key-text pairs.
            The default value is ``None``, in which case every edge will be labelled with its key.
        color : str, tuple, dict
            The color sepcification of the labels.
            String values are interpreted as hex colors.
            Tuples are interpreted as RGB component specifications.
            Individual colors can be assigned using a dictionary of edge-color pairs.
            Missing keys will be assigned the default edge color (``self.settings['color.edges']``).
            The default is ``None``, in which case all edges are assigned the default edge color.

        Returns
        -------
        list
            The GUIDs of the created Rhino objects.

        """
        if text is None:
            edge_text = {(u, v): "{}-{}".format(u, v)
                         for u, v in self.mesh.edges()}
        elif isinstance(text, dict):
            edge_text = text
        else:
            raise NotImplementedError

        edge_color = color_to_colordict(color,
                                        edge_text.keys(),
                                        default=self.settings['color.edges'],
                                        colorformat='rgb',
                                        normalize=False)
        labels = []
        for edge in edge_text:
            labels.append({
                'pos':
                self.mesh.edge_midpoint(*edge),
                'name':
                "{}.edgelabel.{}-{}".format(self.mesh.name, *edge),
                'color':
                edge_color[edge],
                'text':
                edge_text[edge]
            })

        guids = compas_rhino.draw_labels(labels,
                                         layer=self.layer,
                                         clear=False,
                                         redraw=False)
        self.guid_edgelabel = zip(guids, edge_text.keys())
        return guids
示例#9
0
    def draw_vertexlabels(self, text=None, color=None):
        """Draw labels for a selection vertices.

        Parameters
        ----------
        text : dict
            A dictionary of vertex labels as vertex-text pairs.
            The default value is ``None``, in which case every vertex will be labelled with its key.
        color : str, tuple, dict
            The color sepcification of the labels.
            The default color is the same as the color of the vertices.

        Returns
        -------
        list
            The GUIDs of the created Rhino objects.

        """
        if not text or text == 'key':
            vertex_text = {
                vertex: str(vertex)
                for vertex in self.volmesh.vertices()
            }
        elif text == 'index':
            vertex_text = {
                vertex: str(index)
                for index, vertex in enumerate(self.volmesh.vertices())
            }
        elif isinstance(text, dict):
            vertex_text = text
        else:
            raise NotImplementedError
        vertex_xyz = self.vertex_xyz
        vertex_color = colordict(color,
                                 vertex_text.keys(),
                                 default=self.color_vertices)
        labels = []
        for vertex in vertex_text:
            labels.append({
                'pos':
                vertex_xyz[vertex],
                'name':
                "{}.vertexlabel.{}".format(self.volmesh.name, vertex),
                'color':
                vertex_color[vertex],
                'text':
                vertex_text[vertex]
            })
        return compas_rhino.draw_labels(labels,
                                        layer=self.layer,
                                        clear=False,
                                        redraw=False)
示例#10
0
    def draw_celllabels(self, text=None, color=None):
        """Draw labels for cells.

        Parameters
        ----------
        text : dict
            A dictionary of cell labels as cell-text pairs.
            The default value is ``None``, in which case every cell will be labelled with its key.
        color : str, tuple, dict
            The color sepcification of the labels.
            The default color is the same as the color of the cells.

        Returns
        -------
        list
            The GUIDs of the created Rhino objects.

        """
        if not text or text == 'key':
            cell_text = {cell: str(cell) for cell in self.volmesh.cells()}
        elif text == 'index':
            cell_text = {
                cell: str(index)
                for index, cell in enumerate(self.volmesh.cells())
            }
        elif isinstance(text, dict):
            cell_text = text
        else:
            raise NotImplementedError
        vertex_xyz = self.vertex_xyz
        cell_color = colordict(color,
                               cell_text.keys(),
                               default=self.color_cells)
        labels = []
        for cell in cell_text:
            labels.append({
                'pos':
                centroid_points([
                    vertex_xyz[vertex]
                    for vertex in self.volmesh.cell_vertices(cell)
                ]),
                'name':
                "{}.facelabel.{}".format(self.volmesh.name, cell),
                'color':
                cell_color[cell],
                'text':
                cell_text[cell]
            })
        return compas_rhino.draw_labels(labels,
                                        layer=self.layer,
                                        clear=False,
                                        redraw=False)
示例#11
0
    def draw_facelabels(self, text=None, color=None):
        """Draw labels for a selection of faces.

        Parameters
        ----------
        text : dict, optional
            A dictionary of face labels as face-text pairs.
            The default value is ``None``, in which case every face will be labelled with its key.
        color : tuple or dict of tuple, optional
            The color sepcification of the labels.
            The default color is the same as the default face color.

        Returns
        -------
        list
            The GUIDs of the created Rhino objects.

        """
        if not text or text == 'key':
            face_text = {face: str(face) for face in self.mesh.faces()}
        elif text == 'index':
            face_text = {
                face: str(index)
                for index, face in enumerate(self.mesh.faces())
            }
        elif isinstance(text, dict):
            face_text = text
        else:
            raise NotImplementedError
        vertex_xyz = self.vertex_xyz
        face_color = colordict(color,
                               face_text.keys(),
                               default=self.color_faces)
        labels = []
        for face in face_text:
            labels.append({
                'pos':
                centroid_points([
                    vertex_xyz[vertex]
                    for vertex in self.mesh.face_vertices(face)
                ]),
                'name':
                "{}.facelabel.{}".format(self.mesh.name, face),
                'color':
                face_color[face],
                'text':
                face_text[face]
            })
        return compas_rhino.draw_labels(labels,
                                        layer=self.layer,
                                        clear=False,
                                        redraw=False)
示例#12
0
    def _draw_strips_label(self):
        labels = []
        strips = []
        for i, edges in self._edge_strips.items():
            boundary_edge_a_point = self.item.edge_midpoint(*edges[0])
            boundary_edge_b_point = self.item.edge_midpoint(*edges[-1])
            labels.append({'pos': boundary_edge_a_point, 'text': str(i)})
            labels.append({'pos': boundary_edge_b_point, 'text': str(i)})
            strips.append(i)
            strips.append(i)

        guids = compas_rhino.draw_labels(labels, layer=self.settings['layer.coarse'], clear=False, redraw=False)
        self.guid_label = zip(guids, strips)
示例#13
0
    def draw_edgelabels(self, text=None, color=None):
        """Draw labels for a selection of edges.

        Parameters
        ----------
        text : dict
            A dictionary of edge labels as key-text pairs.
            The default value is ``None``, in which case every edge will be labelled with its key.
        color : str, tuple, dict
            The color sepcification of the labels.
            String values are interpreted as hex colors.
            Tuples are interpreted as RGB component specifications.
            Individual colors can be assigned using a dictionary of key-color pairs.
            Missing keys will be assigned the default face color (``self.settings['edge.color']``).
            The default is ``None``, in which case all edges are assigned the default edge color.

        Returns
        -------
        list
            The GUIDs of the created Rhino objects.

        Notes
        -----
        The edge labels are named using the following template: ``"{mesh.name}.edge_label.{u}-{v}"``.
        This name can be used afterwards to identify edges in the Rhino model.

        """
        if text is None:
            textdict = {(u, v): "{}-{}".format(u, v) for u, v in self.mesh.edges()}
        elif isinstance(text, dict):
            textdict = text
        else:
            raise NotImplementedError

        colordict = color_to_colordict(color,
                                       textdict.keys(),
                                       default=self.settings.get('color.edges'),
                                       colorformat='rgb',
                                       normalize=False)
        labels = []
        for (u, v), text in iter(textdict.items()):
            labels.append({
                'pos': self.mesh.edge_midpoint(u, v),
                'name': "{}.edge_label.{}-{}".format(self.mesh.name, u, v),
                'color': colordict[(u, v)],
                'text': textdict[(u, v)]})

        guids = compas_rhino.draw_labels(labels, layer=self.layer, clear=False, redraw=False)
        self.guids += guids
        return guids
示例#14
0
    def draw_nodelabels(self, text=None, color=None):
        """Draw labels for a selection nodes.

        Parameters
        ----------
        text : dict, optional
            A dictionary of node labels as node-text pairs.
            The default value is ``None``, in which case every node will be labelled with its key.
        color : 3-tuple or dict of 3-tuple, optional
            The color sepcification of the labels.
            The default color is the same as the default color of the nodes.

        Returns
        -------
        list
            The GUIDs of the created Rhino objects.

        """
        if not text or text == 'key':
            node_text = {node: str(node) for node in self.network.nodes()}
        elif text == 'index':
            node_text = {
                node: str(index)
                for index, node in enumerate(self.network.nodes())
            }
        elif isinstance(text, dict):
            node_text = text
        else:
            raise NotImplementedError
        node_xyz = self.node_xyz
        node_color = colordict(color,
                               node_text.keys(),
                               default=self.color_nodes)
        labels = []
        for node in node_text:
            labels.append({
                'pos':
                node_xyz[node],
                'name':
                "{}.nodelabel.{}".format(self.network.name, node),
                'color':
                node_color[node],
                'text':
                node_text[node]
            })
        return compas_rhino.draw_labels(labels,
                                        layer=self.layer,
                                        clear=False,
                                        redraw=False)
示例#15
0
    def draw_edgelabels(self, text=None, color=None):
        """Draw labels for a selection of edges.

        Parameters
        ----------
        text : dict[tuple[int, int], str], optional
            A dictionary of edge labels as edge-text pairs.
            The default value is None, in which case every edge will be labelled with its key.
        color : tuple[int, int, int] or dict[tuple[int, int], tuple[int, int, int]], optional
            Color of the labels.
            The default color is tha same as the color of the edges.

        Returns
        -------
        list[System.Guid]
            The GUIDs of the created Rhino objects.

        """
        if text is None:
            edge_text = {
                edge: "{}-{}".format(*edge)
                for edge in self.volmesh.edges()
            }
        elif isinstance(text, dict):
            edge_text = text
        else:
            raise NotImplementedError
        vertex_xyz = self.vertex_xyz
        edge_color = colordict(color,
                               edge_text.keys(),
                               default=self.color_edges)
        labels = []
        for edge in edge_text:
            labels.append({
                'pos':
                centroid_points([vertex_xyz[edge[0]], vertex_xyz[edge[1]]]),
                'name':
                "{}.edgelabel.{}-{}".format(self.volmesh.name, *edge),
                'color':
                edge_color[edge],
                'text':
                edge_text[edge]
            })
        return compas_rhino.draw_labels(labels,
                                        layer=self.layer,
                                        clear=False,
                                        redraw=False)
示例#16
0
 def draw_edgelabels(self, text, color):
     labels = []
     for key in text:
         u, v = key
         a = self.mesh.vertex_attributes(u, 'xy') + [0]
         b = self.mesh.vertex_attributes(v, 'xy') + [0]
         pos = [0.5 * (a[0] + b[0]), 0.5 * (a[1] + b[1]), 0.0]
         labels.append({
             'pos': pos,
             'text': text[key],
             'name': "ForceDiagram.edgelabel",
             'color': color[key]
         })
     return compas_rhino.draw_labels(labels,
                                     layer=self.layer,
                                     clear=False,
                                     redraw=False)
def _draw_labels(form, force):
    labels = []

    dual_edges = list(force.datastructure.edges())
    primal_edges = [
        force.datastructure.primal_edge(dual_edge) for dual_edge in dual_edges
    ]

    for primal, dual in zip(primal_edges, dual_edges):
        tension = form.datastructure.edge_attribute(primal, '_is_tension')
        xyz = force.datastructure.edge_midpoint(dual[0], dual[1])
        if tension:
            labels.append({'pos': xyz, 'color': (255, 0, 0), 'text': 'T'})
        else:
            labels.append({'pos': xyz, 'color': (0, 0, 255), 'text': 'C'})

    return compas_rhino.draw_labels(labels,
                                    layer=force.settings['layer'],
                                    clear=False,
                                    redraw=True)
示例#18
0
    def draw_angles(self, tol=5.0):
        """Draw the angle deviations.

        Parameters
        ----------
        tol : float, optional
            Tolerance value for angle deviations.
            Default value is ``5.0``.

        Returns
        -------
        list
            The GUIDs of the created Rhino objects.
        """
        labels = []
        for u, v in self.form.edges_where({'_is_edge': True}):
            a_rad = self.form.edge_attribute((u, v), '_a')
            a_deg = 180 * a_rad / 3.14159
            if a_deg > tol:
                color = i_to_green(a_rad / tol)
                labels.append({
                    'pos':
                    self.form.edge_midpoint(u, v),
                    'text':
                    "{:.1f}".format(a_deg),
                    'color':
                    color,
                    'name':
                    "{}.angle.{}-{}".format(self.form.name, u, v)
                })
        guids = compas_rhino.draw_labels(labels,
                                         layer=self.layer,
                                         clear=False,
                                         redraw=False)
        self.guids += guids
        return guids
示例#19
0
    def draw_values(self, sceneNode, keys, attr):

        self.clear_label()
        datastructure = sceneNode.datastructure

        def get_edges_lable():
            is_not_edge = list(datastructure.edges_where({'_is_edge': False}))
            edges_to_draw = list(
                set(list(datastructure.edges())) - set(is_not_edge))
            edges_selected = list(set(keys) & set(edges_to_draw))
            edges_unselected = list(set(edges_to_draw) -
                                    set(edges_selected))  # noqa E501

            labels = []
            values = [
                datastructure.edge_attribute(edge, attr)
                for edge in edges_to_draw
            ]
            v_max = max(values)
            v_min = min(values)
            v_range = v_max - v_min or v_max or 1

            for edge in edges_to_draw:
                value = datastructure.edge_attribute(edge, attr)
                if edge in edges_selected:
                    color = [0, 0, 0]
                else:
                    color = i_to_rgb(value / v_range)

                # project to xy plane
                if datastructure.attributes['name'] == 'form':
                    pos = [
                        datastructure.edge_midpoint(*edge)[0],
                        datastructure.edge_midpoint(*edge)[1], 0
                    ]
                else:
                    pos = datastructure.edge_midpoint(*edge)

                value = '{:.3g}'.format(value)
                labels.append({'pos': pos, 'text': value, 'color': color})

            return labels, edges_to_draw

        def get_vertices_lable():
            vertices_to_draw = list(datastructure.vertices())
            vertices_selected = keys
            vertices_unselected = list(
                set(vertices_to_draw) - set(vertices_selected))  # noqa E501

            labels = []
            values = [
                datastructure.vertex_attribute(vertex, attr)
                for vertex in vertices_to_draw
            ]
            v_max = max(values)
            v_min = min(values)
            v_range = v_max - v_min or v_max or 1

            for vertex in vertices_to_draw:
                value = datastructure.vertex_attribute(vertex, attr)

                if vertex in vertices_selected:
                    color = [0, 0, 0]
                else:
                    color = i_to_rgb(value / v_range)

                # project to xy plane
                if datastructure.attributes['name'] == 'form':
                    pos = [
                        datastructure.vertex_coordinates(vertex)[0],
                        datastructure.vertex_coordinates(vertex)[1], 0
                    ]
                else:
                    pos = datastructure.vertex_coordinates(vertex)

                value = '{:.3g}'.format(value)
                labels.append({'pos': pos, 'text': value, 'color': color})

            return labels, vertices_to_draw

        def get_faces_lable():
            is_not_loaded = list(
                datastructure.faces_where({'_is_loaded': False}))
            faces_to_draw = list(
                set(list(datastructure.faces())) - set(is_not_loaded))
            faces_selected = keys
            faces_unselected = list(set(faces_to_draw) -
                                    set(faces_selected))  # noqa E501

            labels = []
            values = [
                datastructure.face_attribute(face, attr)
                for face in faces_to_draw
            ]
            v_max = max(values)
            v_min = min(values)
            v_range = v_max - v_min or v_max or 1

            for face in faces_to_draw:
                value = datastructure.face_attribute(face, attr)
                if face in faces_selected:
                    color = [0, 0, 0]
                else:
                    color = i_to_rgb(value / v_range)
                pos = datastructure.face_centroid(face)
                value = '{:.3g}'.format(value)
                labels.append({'pos': pos, 'text': value, 'color': color})

            return labels, faces_to_draw

        if self.table_type == 'vertices':
            if attr == 'constraints':
                return
            else:
                labels, keys = get_vertices_lable()
        elif self.table_type == 'edges':
            labels, keys = get_edges_lable()
        else:
            labels, keys = get_faces_lable()

        guids = compas_rhino.draw_labels(labels,
                                         layer='Default',
                                         clear=False,
                                         redraw=True)  # noqa E501
        guid_lable = dict(zip(guids, keys))
        self._guid_lable.update(guid_lable)
示例#20
0
from __future__ import absolute_import
示例#21
0
    def draw_vertexlabels(self, text=None, color=None):
        """Draw labels for a selection vertices.

        Parameters
        ----------
        text : dict
            A dictionary of vertex labels as key-text pairs.
            The default value is ``None``, in which case every vertex will be labelled with its key.
        color : str, tuple, dict
            The color sepcification of the labels.
            String values are interpreted as hex colors (e.g. ``'#ff0000'`` for red).
            Tuples are interpreted as RGB component specifications (e.g. ``(255, 0, 0) for red``.
            If a dictionary of specififcations is provided, the keys of the
            should refer to vertex keys and the values should be color
            specifications in the form of strings or tuples.
            The default value is ``None``, in which case the labels are assigned
            the default vertex color (``self.settings['color.vertex']``).

        Notes
        -----
        All labels are assigned a name using the folling template:
        ``"{}.vertex.label.{}".format(self.mesh.name, key)``.

        """
        if text is None:
            textdict = {key: str(key) for key in self.mesh.vertices()}
        elif isinstance(text, dict):
            textdict = text
        elif text == 'key':
            textdict = {key: str(key) for key in self.mesh.vertices()}
        elif text == 'index':
            textdict = {
                key: str(index)
                for index, key in enumerate(self.mesh.vertices())
            }
        else:
            raise NotImplementedError

        colordict = color_to_colordict(
            color,
            textdict.keys(),
            default=self.settings.get('color.vertex'),
            colorformat='rgb',
            normalize=False)
        labels = []

        for key, text in iter(textdict.items()):
            labels.append({
                'pos':
                self.mesh.vertex_coordinates(key),
                'name':
                "{}.vertex.label.{}".format(self.mesh.name, key),
                'color':
                colordict[key],
                'text':
                textdict[key]
            })

        return compas_rhino.draw_labels(labels,
                                        layer=self.layer,
                                        clear=False,
                                        redraw=False)