示例#1
0
 def clear(self):
     guids_nodes = list(self.guid_node.keys())
     guids_edges = list(self.guid_edge.keys())
     guids = guids_nodes + guids_edges
     compas_rhino.delete_objects(guids, purge=True)
     self._guid_node = {}
     self._guid_edge = {}
示例#2
0
def display_mesh_face_normals(mesh,
                              display=True,
                              layer=None,
                              scale=1.0,
                              color=(0, 0, 255)):

    guids = compas_rhino.get_objects(
        name='{0}.face.normal.*'.format(mesh.attributes['name']))
    compas_rhino.delete_objects(guids)

    if not display:
        return

    lines = []

    for fkey in mesh.faces():
        normal = mesh.face_normal(fkey)
        start = mesh.face_center(fkey)
        end = [start[axis] + normal[axis] for axis in range(3)]
        name = '{0}.face.normal.{1}'.format(mesh.attributes['name'], fkey)

        lines.append({
            'start': start,
            'end': end,
            'name': name,
            'color': color,
            'arrow': 'end',
        })

    compas_rhino.xdraw_lines(lines, layer=layer, clear=False, redraw=True)
示例#3
0
 def clear(self):
     guids_vertices = list(self.guid_vertex.keys())
     guids_faces = list(self.guid_face.keys())
     guids_edges = list(self.guid_edge.keys())
     guids = guids_vertices + guids_faces + guids_edges
     compas_rhino.delete_objects(guids, purge=True)
     self._guid_vertex = {}
     self._guid_face = {}
     self._guid_edge = {}
示例#4
0
    def clear(self):
        """Delete all objects drawn by this artist.

        Returns
        -------
        None

        """
        guids = compas_rhino.get_objects(name="{}.*".format(self.network.name))
        compas_rhino.delete_objects(guids, purge=True)
示例#5
0
    def clear_mesh(self):
        """Delete the mesh drawn by this artist.

        Returns
        -------
        None

        """
        guids = compas_rhino.get_objects(name="{}.mesh".format(self.mesh.name))
        compas_rhino.delete_objects(guids, purge=True)
示例#6
0
    def clear_vertices(self):
        """Delete all vertices drawn by this artist.

        Returns
        -------
        None

        """
        guids = compas_rhino.get_objects(
            name="{}.vertex.*".format(self.mesh.name))
        compas_rhino.delete_objects(guids, purge=True)
示例#7
0
 def clear_vertexlabels(self, keys=None):
     if not keys:
         name = '{}.vertex.label.*'.format(self.datastructure.name)
         guids = compas_rhino.get_objects(name=name)
     else:
         guids = []
         for key in keys:
             name = self.datastructure.vertex_label_name(key)
             guid = compas_rhino.get_object(name=name)
             guids.append(guid)
     compas_rhino.delete_objects(guids)
示例#8
0
 def clear_vertices(self, keys=None):
     if not keys:
         name = '{}.vertex.*'.format(self.mesh.attributes['name'])
         guids = compas_rhino.get_objects(name=name)
     else:
         guids = []
         for key in keys:
             name = '{}.vertex.{}'.format(self.attributes['name'], key)
             guid = compas_rhino.get_object(name=name)
             guids.append(guid)
     compas_rhino.delete_objects(guids)
示例#9
0
 def clear_edges(self, keys=None):
     if not keys:
         name = '{}.edge.*'.format(self.mesh.attributes['name'])
         guids = compas_rhino.get_objects(name=name)
     else:
         guids = []
         for u, v in keys:
             name = '{}.edge.{}-{}'.format(self.attributes['name'], u, v)
             guid = compas_rhino.get_object(name=name)
             guids.append(guid)
     compas_rhino.delete_objects(guids)
示例#10
0
 def clear_edges(self, keys=None):
     if not keys:
         name = '{}.edge.*'.format(self.datastructure.name)
         guids = compas_rhino.get_objects(name=name)
     else:
         guids = []
         for u, v in keys:
             name = self.datastructure.edge_name(u, v)
             guid = compas_rhino.get_object(name=name)
             guids.append(guid)
     compas_rhino.delete_objects(guids)
示例#11
0
    def clear_facelabels(self):
        """Delete all face labels drawn by this artist.

        Returns
        -------
        None

        """
        guids = compas_rhino.get_objects(
            name="{}.facelabel.*".format(self.mesh.name))
        compas_rhino.delete_objects(guids, purge=True)
示例#12
0
 def clear(self):
     """Clear all objects previously drawn by this artist.
     """
     compas_rhino.delete_objects(self.guids, purge=True)
     self._guid_vertex = {}
     self._guid_edge = {}
     self._guid_face = {}
     self._guid_cell = {}
     self._guid_vertexlabel = {}
     self._guid_edgelabel = {}
     self._guid_facelabel = {}
     self._guid_celllabel = {}
示例#13
0
 def clear(self):
     """Clear all Rhino objects associated with this object.
     """
     compas_rhino.delete_objects(self.guids, purge=True)
     self._guids = []
     self._guid_vertex = {}
     self._guid_edge = {}
     self._guid_face = {}
     self._guid_vertexnormal = {}
     self._guid_facenormal = {}
     self._guid_vertexlabel = {}
     self._guid_edgelabel = {}
     self._guid_facelabel = {}
示例#14
0
def network_draw_axial_forces(network, scale=0.1, layer=None, clear_layer=False):
    cylinders = []
    for u, v, attr in network.edges(True):
        if attr['f'] > 0.0:
            cylinders.append({
                'start' : network.vertex_coordinates(u),
                'end'   : network.vertex_coordinates(v),
                'radius': scale * 3.14159 * attr['f'] ** 2,
                'name'  : '{}.axial.{}-{}'.format(network.name, u, v),
                'color' : (255, 0, 0),
            })
    guids = compas_rhino.get_objects(name='{}.axial.*'.format(network.name))
    compas_rhino.delete_objects(guids)
    compas_rhino.xdraw_cylinders(cylinders, layer=layer, clear=clear_layer)
示例#15
0
def move_network(network):
    """Move the entire network.

    Parameters:
        network (compas.datastructures.network.Network): A network object.

    """
    color  = Rhino.ApplicationSettings.AppearanceSettings.FeedbackColor
    origin = {key: network.vertex_coordinates(key) for key in network.vertices()}
    vertex = {key: network.vertex_coordinates(key) for key in network.vertices()}
    edges  = network.edges()
    start  = compas_rhino.pick_point('Point to move from?')

    if not start:
        return

    def OnDynamicDraw(sender, e):
        current = list(e.CurrentPoint)
        vec = [current[i] - start[i] for i in range(3)]
        for key in vertex:
            vertex[key] = [origin[key][i] + vec[i] for i in range(3)]
        for u, v in iter(edges):
            sp = vertex[u]
            ep = vertex[v]
            sp = Point3d(*sp)
            ep = Point3d(*ep)
            e.Display.DrawDottedLine(sp, ep, color)

    guids = compas_rhino.get_objects(name='{0}.*'.format(network.attributes['name']))
    compas_rhino.delete_objects(guids, False)

    gp = Rhino.Input.Custom.GetPoint()
    gp.SetCommandPrompt('Point to move to?')
    gp.DynamicDraw += OnDynamicDraw
    gp.Get()

    if gp.CommandResult() == Rhino.Commands.Result.Success:
        end = list(gp.Point())
        vec = [end[i] - start[i] for i in range(3)]
        for key, attr in network.vertices(True):
            attr['x'] += vec[0]
            attr['y'] += vec[1]
            attr['z'] += vec[2]

    try:
        network.draw()
    except AttributeError:
        # this may result in the network being drawn in a different layer then before
        draw_network(network)
示例#16
0
def draw_mesh_as_faces(mesh,
                       layer=None,
                       clear_layer=False,
                       facecolor=None,
                       redraw=True):

    guids = compas_rhino.get_objects(
        name='{0}.*'.format(mesh.attributes['name']))
    compas_rhino.delete_objects(guids)

    if clear_layer:
        if not layer:
            compas_rhino.clear_current_layer()
        else:
            compas_rhino.clear_layer(layer)

    facecolor = facecolor or {}

    meshes = []

    for fkey in mesh.faces():
        vertices = mesh.face_coordinates(fkey)
        faces = [range(len(vertices))]
        color = facecolor.get(fkey, (255, 255, 255))
        guid = compas_rhino.xdraw_mesh(vertices,
                                       faces,
                                       None,
                                       '{0}.face.{1}'.format(
                                           mesh.attributes['name'], fkey),
                                       layer=layer,
                                       clear=False,
                                       redraw=False)
        compas_rhino.set_mesh_vertex_colors(
            guid, [color for i in range(len(vertices))])
        meshes.append(guid)

    if layer:
        previous = rs.CurrentLayer(layer)

    guid = rs.JoinMeshes(meshes, delete_input=True)

    if layer:
        rs.CurrentLayer(previous)

    rs.ObjectName(guid, '{0}'.format(mesh.attributes['name']))

    rs.EnableRedraw()
    rs.Redraw()
示例#17
0
def network_draw_loads(network, scale=1.0, layer=None, clear_layer=False):
    lines = []
    for key, attr in network.vertices(True):
        if not attr['is_fixed']:
            force = attr['px'], attr['py'], attr['pz']
            start = network.vertex_coordinates(key)
            end = [start[axis] + scale * force[axis] for axis in (0, 1, 2)]
            lines.append({
                'start': start,
                'end'  : end,
                'name' : '{}.load.{}'.format(network.name, key),
                'color': (0, 255, 255),
                'arrow': 'end',
            })
    guids = compas_rhino.get_objects(name='{}.load.*'.format(network.name))
    compas_rhino.delete_objects(guids)
    compas_rhino.xdraw_lines(lines, layer=layer, clear=clear_layer)
示例#18
0
 def clear(self):
     super(ThrustObject, self).clear()
     guids = []
     guids += list(self.guid_free)
     guids += list(self.guid_anchor)
     guids += list(self.guid_selfweight)
     guids += list(self.guid_reaction)
     guids += list(self.guid_load)
     guids += list(self.guid_residual)
     guids += list(self.guid_pipe)
     compas_rhino.delete_objects(guids, purge=True)
     self._guid_free = {}
     self._guid_anchor = {}
     self._guid_selfweight = {}
     self._guid_load = {}
     self._guid_residual = {}
     self._guid_reaction = {}
     self._guid_pipe = {}
示例#19
0
    def clear_edgelabels(self, keys=None):
        """Clear all previously drawn edge labels.

        Parameters
        ----------
        keys : list, optional
            The keys of a specific set of edges of which the labels should be cleared.
            Default is to clear all edge labels.

        """
        if not keys:
            name = '{}.edge.label.*'.format(self.mesh.name)
            guids = compas_rhino.get_objects(name=name)
        else:
            guids = []
            for u, v in keys:
                name = '{}.edge.label.{}-{}'.format(self.mesh.name, u, v)
                guids += compas_rhino.get_objects(name=name)
        compas_rhino.delete_objects(guids)
示例#20
0
def RunCommand(is_interactive):
    scene = get_scene()
    if not scene:
        return

    guids = compas_rhino.select_point()
    if not guids:
        return

    pt = compas_rhino.get_point_coordinates([guids])[0]
    skeleton = Skeleton.from_center_point(pt)
    if not skeleton:
        return

    compas_rhino.delete_objects([guids])

    rhinoskeleton = scene.add(skeleton, 'skeleton')
    rhinoskeleton.dynamic_draw_self()
    rhinoskeleton.draw_self()
示例#21
0
    def clear_vertexlabels(self, keys=None):
        """Clear all previously drawn vertex labels.

        Parameters
        ----------
        keys : list, optional
            The keys of a specific set of vertex labels that should be cleared.
            Default is to clear all vertex labels.

        """
        if not keys:
            name = '{}.vertex.label.*'.format(self.mesh.name)
            guids = compas_rhino.get_objects(name=name)
        else:
            guids = []
            for key in keys:
                name = '{}.vertex.label.{}'.format(self.mesh.name, key)
                guids += compas_rhino.get_objects(name=name)
        compas_rhino.delete_objects(guids)
示例#22
0
    def clear_facenormals(self, keys=None):
        """Clear the all previously drawn face normals.

        Parameters
        ----------
        keys : list, optional
            The keys of a specific set of faces of which the normals should be cleared.
            Default is to clear the normals of all faces.

        """
        if not keys:
            name = '{}.face.normal.*'.format(self.mesh.name)
            guids = compas_rhino.get_objects(name=name)
        else:
            guids = []
            for key in keys:
                name = '{}.face.normal.{}'.format(self.mesh.name, key)
                guids += compas_rhino.get_objects(name=name)
        compas_rhino.delete_objects(guids)
示例#23
0
    def clear_nodes(self, keys=None):
        """Clear all previously drawn nodes.

        Parameters
        ----------
        keys : list, optional
            The keys of a specific set of nodes that should be cleared.
            Default is to clear all nodes.

        """
        if not keys:
            name = '{}.node.*'.format(self.network.name)
            guids = compas_rhino.get_objects(name=name)
        else:
            guids = []
            for key in keys:
                name = '{}.node.{}'.format(self.network.name, key)
                guids += compas_rhino.get_objects(name=name)
        compas_rhino.delete_objects(guids)
示例#24
0
    def closest_point_on_boundaries(self, xyz):
        """Return the XYZ coordinates of the closest point on the boundaries of the surface from input XYZ-coordinates.

        Parameters
        ----------
        xyz : list
            XYZ coordinates.

        Returns
        -------
        list
            The XYZ coordinates of the closest point on the boundaries of the surface.

        """
        from .curve import RhinoCurve
        borders = self.borders(type=0)
        proj_dist = {tuple(proj_xyz): distance_point_point(xyz, proj_xyz) for proj_xyz in [RhinoCurve(border).closest_point(xyz) for border in borders]}
        compas_rhino.delete_objects(borders)
        return min(proj_dist, key=proj_dist.get)
示例#25
0
    def clear_facenormals(self, keys=None):
        """Clear the normals of all faces previously drawn by the ``FaceArtist``.

        Parameters
        ----------
        keys : list, optional
            The keys of a specific set of faces of which the normals should be cleared.
            Default is to clear the normals of all faces.

        """
        if not keys:
            name = '{}.face.normal.*'.format(self.datastructure.name)
            guids = compas_rhino.get_objects(name=name)
        else:
            guids = []
            for key in keys:
                name = self.datastructure.face_name(key)
                guid = compas_rhino.get_object(name=name)
                guids.append(guid)
        compas_rhino.delete_objects(guids)
示例#26
0
    def clear_edges(self, keys=None):
        """Clear all edges previously drawn by the ``EdgeArtist``.

        Parameters
        ----------
        keys : list, optional
            The keys of a specific set of edges that should be cleared.
            Default is to clear all edges.

        """
        if not keys:
            name = '{}.edge.*'.format(self.datastructure.name)
            guids = compas_rhino.get_objects(name=name)
        else:
            guids = []
            for u, v in keys:
                name = self.datastructure.edge_name(u, v)
                guid = compas_rhino.get_object(name=name)
                guids.append(guid)
        compas_rhino.delete_objects(guids)
示例#27
0
    def clear_vertexlabels(self, keys=None):
        """Clear all vertex labels previously drawn by the ``VertexArtist``.

        Parameters
        ----------
        keys : list, optional
            The keys of a specific set of vertex labels that should be cleared.
            Default is to clear all vertex labels.

        """
        if not keys:
            name = '{}.vertex.label.*'.format(self.datastructure.name)
            guids = compas_rhino.get_objects(name=name)
        else:
            guids = []
            for key in keys:
                name = self.datastructure.vertex_label_name(key)
                guid = compas_rhino.get_object(name=name)
                guids.append(guid)
        compas_rhino.delete_objects(guids)
示例#28
0
    def clear_normals(self, keys=None):
        """Clear all normals previously drawn by the ``MeshArtist``.

        Parameters
        ----------
        keys : list, optional
            The keys of a specific set of normals that should be cleared.
            Default is to clear all normals.

        """
        if not keys:
            name = '{}.normal.*'.format(self.mesh.name)
            guids = compas_rhino.get_objects(name=name)
        else:
            guids = []
            for key in keys:
                name = '{}.normal.{}'.format(self.mesh.name, key)
                guid = compas_rhino.get_object(name=name)
                guids.append(guid)
        compas_rhino.delete_objects(guids)
示例#29
0
def display_network_residual_forces(network,
                                    display=True,
                                    layer=None,
                                    clear_layer=False,
                                    scale=1.0,
                                    color=(0, 255, 255),
                                    attr_name='is_anchor'):

    tol = compas_rhino.get_tolerance()
    guids = compas_rhino.get_objects(name='{0}.force:residual.*'.format(network.attributes['name']))
    compas_rhino.delete_objects(guids)

    if not display:
        return

    lines = []

    for key, attr in network.vertices(True):

        if attr[attr_name]:
            continue

        force  = attr['rx'], attr['ry'], attr['rz']
        start  = network.vertex_coordinates(key)
        end    = [start[i] + scale * force[i] for i in range(3)]
        length = distance_point_point(start, end)
        arrow  = 'end'
        name   = '{0}.force:residual.{1}'.format(network.attributes['name'], key)

        if length < tol:
            continue

        lines.append({
            'start' : start,
            'end'   : end,
            'name'  : name,
            'color' : color,
            'arrow' : arrow,
        })

    compas_rhino.xdraw_lines(lines, layer=layer, clear=clear_layer)
示例#30
0
    def draw_reactions(self, scale=1.0, color=None):
        compas_rhino.delete_objects(
            compas_rhino.get_objects(
                name="{}.reaction.*".format(self.mesh.name)))

        color = color or (0, 255, 0)
        lines = []
        for key, attr in self.mesh.vertices(True):
            if not attr['is_anchor']:
                continue

            r = [attr['rx'], attr['ry'], attr['rz']]
            sp = [attr['x'], attr['y'], attr['z']]
            ep = add_vectors(sp, scale_vector(r, -scale))

            lines.append({
                'start': sp,
                'end': ep,
                'color': color,
                'name': "{}.reaction.{}".format(self.mesh.name, key),
                'arrow': 'end'
            })

        compas_rhino.xdraw_lines(lines, layer=self.layer, redraw=True)