Ejemplo n.º 1
0
    def ping_server(self, attempts=10):
        """Ping the server to check if it is available at the provided address.

        Parameters
        ----------
        attempst : int, optional
            The number of attemps before the function should give up.
            Default is ``10``.

        Returns
        -------
        int
            ``1`` if the server is available.
            ``0`` otherwise.

        """
        while attempts:
            try:
                result = self.send_request('ping')
            except Exception as e:
                if compas.IPY:
                    compas_rhino.wait()
                result = 0
                time.sleep(0.1)
                attempts -= 1
                print("    {} attempts left.".format(attempts))
            else:
                break
        return result
Ejemplo n.º 2
0
def callback(mesh, k, args):
    # prevent the dreaded Rhino spinning wheel
    compas_rhino.wait()

    # unpack the user-defined argument list
    conduit, fixed, target, border = args

    # find the boundary vertices
    boundary = set(mesh.vertices_on_boundary())

    # smooth
    smooth_mesh_centroid(mesh, fixed=boundary, kmax=1)
    smooth_mesh_boundary(mesh, boundary, fixed=fixed)

    # pull the mesh vertices back to the target and border
    for key, attr in mesh.vertices(data=True):
        if key in fixed:
            continue
        if key in boundary:
            x, y, z = border.closest_point(mesh.vertex_coordinates(key))
            attr['x'] = x
            attr['y'] = y
            attr['z'] = z
        else:
            x, y, z = target.closest_point(mesh.vertex_coordinates(key))
            attr['x'] = x
            attr['y'] = y
            attr['z'] = z

    # update the conduit at the specified rate
    conduit.redraw(k)
Ejemplo n.º 3
0
def callback(k, X, crits, args):
    for node in network.nodes():
        index = node_index[node]
        network.node_attributes(node, 'xyz', X[index])

    artist.draw_nodes(color={
        node: (255, 0, 0)
        for node in network.nodes_where({'is_anchor': True})
    })
    artist.draw_edges()
    compas_rhino.rs.Redraw()
    compas_rhino.wait()
Ejemplo n.º 4
0
def callback(k, xyz):
    compas_rhino.wait()

    print(k)

    if k < kmax - 1:
        xyz[slider][0] = c_double(0.1 * (k + 1))

    pointsconduit.points = [
        mesh.vertex_coordinates(key) for key in mesh.vertices()
    ]
    linesconduit.lines = [mesh.edge_coordinates(u, v) for u, v in edges]

    pointsconduit.redraw(k)
    linesconduit.redraw(k)

    for key, attr in mesh.vertices(True):
        attr['x'] = float(xyz[key][0])
        attr['y'] = float(xyz[key][1])
        attr['z'] = float(xyz[key][2])
Ejemplo n.º 5
0
 def callback(line, args):
     print(line)
     compas_rhino.wait()
Ejemplo n.º 6
0
# cutting process

compas_rhino.rs.Redraw()

for i, j in pairwise(range(len(left_poly.points))):
    left_start = left_poly.points[i]
    left_stop = left_poly.points[j]
    left_vector = left_stop - left_start

    right_start = right_poly.points[i]
    right_stop = right_poly.points[j]
    right_vector = right_stop - right_start

    for i in linspace(0, 1, 50):
        a = left_start + left_vector * i
        b = right_start + right_vector * i
        line = Line(a, b)
        artist = LineArtist(line,
                            color=(255, 255, 255),
                            layer="ITA20::HotWire::CutLines")
        artist.clear_layer()
        artist.draw()
        compas_rhino.rs.Redraw()
        compas_rhino.wait()

    polygon = Polygon([left_start, right_start, right_stop, left_stop])
    artist = PolygonArtist(polygon,
                           color=(255, 255, 255),
                           layer="ITA20::HotWire::CutPlane")
    artist.draw()