示例#1
0
def RunCommand(is_interactive):

    config = {
        "name": "Cloud",
        "message": "start cloud in ?",
        "options": [
            {
                "name": "background",
                "message": "background",
                "action": None
            },
            {
                "name": "console",
                "message": "console",
                "action": None
            }
        ]
    }

    menu = CommandMenu(config)
    action = menu.select_action()

    if action['name'] == 'background':
        background = True
    if action['name'] == 'console':
        background = False

    p = get_proxy()
    p.background = background
    p.restart()
def RunCommand(is_interactive):

    scene = get_scene()
    if not scene:
        return

    proxy = get_proxy()
    if not proxy:
        return

    pattern = scene.get("pattern")[0]
    if not pattern:
        print("There is no Pattern in the scene.")
        return

    options = ["Finer", "Coarser"]
    while True:

        option = compas_rhino.rs.GetString("Select mode", strings=options)

        if not option:
            break

        if option == "Finer":
            raise NotImplementedError

        elif option == "Coarser":
            raise NotImplementedError

        else:
            raise NotImplementedError
def RunCommand(is_interactive):
    scene = get_scene()
    if not scene:
        return

    proxy = get_proxy()
    if not proxy:
        return

    form = scene.get("form")[0]
    if not form:
        print("There is no FormDiagram in the scene.")
        return

    thrust = scene.get("thrust")[0]

    anchors = list(form.datastructure.vertices_where({'is_anchor': True}))
    fixed = list(form.datastructure.vertices_where({'is_fixed': True}))
    fixed = anchors + fixed

    options = ['True', 'False']
    option = compas_rhino.rs.GetString(
        "Press Enter to smooth or ESC to exit. Keep all boundaries fixed?",
        options[0], options)

    if option is None:
        print('Form smoothing aborted!')
        return

    if option == 'True':
        fixed += list(flatten(form.datastructure.vertices_on_boundaries()))
        fixed += list(
            flatten([
                form.datastructure.face_vertices(face) for face in
                form.datastructure.faces_where({'_is_loaded': False})
            ]))

    fixed = list(set(fixed))

    form.datastructure.smooth_area(fixed=fixed)

    if thrust:
        thrust.settings['_is.valid'] = False

    scene.update()
def RunCommand(is_interactive):

    scene = get_scene()
    if not scene:
        return

    proxy = get_proxy()
    if not proxy:
        return

    pattern = scene.get("pattern")[0]
    if not pattern:
        print("There is no Pattern in the scene.")
        return

    keys = pattern.select_vertices()
    for key in keys:
        if pattern.datastructure.has_vertex(key):
            pattern.datastructure.delete_vertex(key)
    scene.update()
示例#5
0
def RunCommand(is_interactive):
    scene = get_scene()
    if not scene:
        return

    proxy = get_proxy()
    if not proxy:
        return

    pattern = scene.get("pattern")[0]
    if not pattern:
        print("There is no Pattern in the scene.")
        return

    fixed = list(pattern.datastructure.vertices_where({'is_fixed': True}))

    if not fixed:
        print(
            "Pattern has no fixed vertices! Relaxation requires fixed vertices."
        )
        return

    relax = proxy.function("compas.numerical.fd_numpy")

    key_index = pattern.datastructure.key_index()
    xyz = pattern.datastructure.vertices_attributes('xyz')
    loads = [[0.0, 0.0, 0.0] for _ in xyz]
    fixed[:] = [key_index[key] for key in fixed]
    edges = [(key_index[u], key_index[v])
             for u, v in pattern.datastructure.edges()]

    q = pattern.datastructure.edges_attribute('q')

    xyz, q, f, l, r = relax(xyz, edges, fixed, q, loads)

    for key in pattern.datastructure.vertices():
        index = key_index[key]
        pattern.datastructure.vertex_attributes(key, 'xyz', xyz[index])

    scene.update()
def RunCommand(is_interactive):
    scene = get_scene()
    if not scene:
        return

    proxy = get_proxy()
    if not proxy:
        return

    form = scene.get("form")[0]
    if not form:
        print("There is no FormDiagram in the scene.")
        return

    thrust = scene.get("thrust")[0]

    anchors = list(form.datastructure.vertices_where({'is_anchor': True}))
    fixed = list(form.datastructure.vertices_where({'is_fixed': True}))
    fixed = list(set(anchors + fixed))

    relax = proxy.function("compas.numerical.fd_numpy")

    key_index = form.datastructure.key_index()
    xyz = form.datastructure.vertices_attributes('xyz')
    loads = [[0.0, 0.0, 0.0] for _ in xyz]
    fixed[:] = [key_index[key] for key in fixed]
    edges = [(key_index[u], key_index[v]) for u, v in form.datastructure.edges()]

    q = form.datastructure.edges_attribute('q')

    xyz, q, f, l, r = relax(xyz, edges, fixed, q, loads)

    for key in form.datastructure.vertices():
        index = key_index[key]
        form.datastructure.vertex_attributes(key, 'xyz', xyz[index])

    if thrust:
        thrust.settings['_is.valid'] = False

    scene.update()
def RunCommand(is_interactive):
    scene = get_scene()
    if not scene:
        return

    proxy = get_proxy()
    if not proxy:
        return

    pattern = scene.get("pattern")[0]
    if not pattern:
        print("There is no Pattern in the scene.")
        return

    fixed = list(pattern.datastructure.vertices_where({'is_fixed': True}))

    if not fixed:
        print(
            "Pattern has no fixed vertices! Smoothing requires fixed vertices."
        )
        return

    options = ['True', 'False']
    option = compas_rhino.rs.GetString(
        "Press Enter to smooth or ESC to exit. Keep all boundaries fixed?",
        options[0], options)

    if option is None:
        print('Pattern smoothing aborted!')
        return

    if option == 'True':
        fixed = fixed + list(
            flatten(pattern.datastructure.vertices_on_boundaries()))

    pattern.datastructure.smooth_area(fixed=fixed)

    scene.update()
def RunCommand(is_interactive):
    scene = get_scene()
    if not scene:
        return

    proxy = get_proxy()
    if not proxy:
        return

    delaunay = proxy.function('compas.geometry.delaunay_from_points_numpy')

    # Get input data.
    surf_guid = compas_rhino.select_surface("Select a surface to decompose.")
    if not surf_guid:
        return
    point_guids = compas_rhino.select_points(
        "Select points to include in the decomposition.")
    curve_guids = []

    compas_rhino.rs.HideObjects([surf_guid] + point_guids + curve_guids)

    surface = RhinoSurface.from_guid(surf_guid)
    curves = [RhinoCurve.from_guid(guid) for guid in curve_guids]
    points = [RhinoPoint.from_guid(guid) for guid in point_guids]

    # Compute the feature discretisation length.
    box = compas_rhino.rs.BoundingBox([surf_guid])
    diagonal = compas_rhino.rs.Distance(box[0], box[6])
    D = 0.05 * diagonal

    # Get the target length for the final quad mesh.
    L = compas_rhino.rs.GetReal(
        "Define the target edge length of the pattern.", 1.0)

    # Generate the pattern
    pattern = Pattern.from_surface_and_features(D,
                                                L,
                                                surf_guid,
                                                curve_guids,
                                                point_guids,
                                                delaunay=delaunay)

    scene.clear()
    scene.add(pattern, name='pattern')
    scene.update()

    kmax = 10

    # Constrain mesh components to the feature geometry.
    constraints = automated_smoothing_surface_constraints(pattern, surface)
    constraints.update(
        automated_smoothing_constraints(pattern,
                                        rhinopoints=points,
                                        rhinocurves=curves))

    while True:
        option = compas_rhino.rs.GetString("Smoothen the pattern?", "No",
                                           ["Yes", "No"])
        if not option:
            break
        if option != "Yes":
            break

        constrained_smoothing(pattern,
                              kmax=kmax,
                              damping=0.5,
                              constraints=constraints,
                              algorithm="area")
        scene.update()

    print('Pattern object successfully created. Input object has been hidden.')
示例#9
0
def RunCommand(is_interactive):

    scene = get_scene()
    if not scene:
        return

    proxy = get_proxy()
    if not proxy:
        return

    vertical = proxy.function('compas_tna.equilibrium.vertical_from_zmax_proxy')

    form = scene.get('form')[0]
    force = scene.get('force')[0]
    thrust = scene.get('thrust')[0]

    if not form:
        print("There is no FormDiagram in the scene.")
        return

    if not force:
        print("There is no ForceDiagram in the scene.")
        return

    if not thrust:
        print("There is no ThrustDiagram in the scene.")
        return

    bbox = form.datastructure.bounding_box_xy()
    diagonal = length_vector(subtract_vectors(bbox[2], bbox[0]))

    zmax = scene.settings['Solvers']['tna.vertical.zmax']
    kmax = scene.settings['Solvers']['tna.vertical.kmax']

    options = ['TargetHeight']

    while True:
        option = compas_rhino.rs.GetString('Press Enter to run or ESC to exit.', strings=options)

        if option is None:
            print("Vetical equilibrium aborted!")
            return

        if not option:
            break

        if option == 'TargetHeight':
            new_zmax = compas_rhino.rs.GetReal('Enter target height of the ThrustDiagram', zmax, 0.0, 1.0 * diagonal)
            if new_zmax or new_zmax is not None:
                zmax = new_zmax

    scene.settings['Solvers']['tna.vertical.zmax'] = zmax

    result = vertical(form.datastructure.data, zmax, kmax=kmax)

    if not result:
        print("Vertical equilibrium failed!")
        return

    formdata, scale = result

    force.datastructure.attributes['scale'] = scale
    form.datastructure.data = formdata
    thrust.datastructure.data = formdata

    form.datastructure.dual = force.datastructure
    force.datastructure.primal = form.datastructure
    thrust.datastructure.dual = force.datastructure

    thrust.settings['_is.valid'] = True

    scene.update()

    print('Vertical equilibrium found!')
    print('ThrustDiagram object successfully created with target height of {}.'.format(zmax))
示例#10
0
def RunCommand(is_interactive):
    scene = get_scene()
    if not scene:
        return

    proxy = get_proxy()
    if not proxy:
        return

    relax = proxy.function("compas.numerical.fd_numpy")

    pattern = scene.get("pattern")[0]
    if not pattern:
        return

    # split the exterior boundary
    openings = split_boundary(pattern.datastructure)

    # make a label drawing function
    draw_labels = partial(_draw_labels, pattern, openings)

    # draw a label per opening
    guids = draw_labels()

    # convert the list of vertices to a list of segments
    openings = [list(pairwise(opening)) for opening in openings]

    # compute current opening sags
    targets = []
    for opening in openings:
        sag = compute_sag(pattern.datastructure, opening)
        if sag < 0.05:
            sag = 0.05
        targets.append(sag)

    # compute current opening Qs
    Q = []
    for opening in openings:
        q = pattern.datastructure.edges_attribute('q', keys=opening)
        q = sum(q) / len(q)
        Q.append(q)
        pattern.datastructure.edges_attribute('q', q, keys=opening)

    # relax the pattern
    relax_pattern(pattern.datastructure, relax)

    # update Qs to match target sag
    count = 0
    while True and count < 10:
        count += 1
        sags = [
            compute_sag(pattern.datastructure, opening) for opening in openings
        ]
        if all((sag - target)**2 < TOL2 for sag, target in zip(sags, targets)):
            break
        for i in range(len(openings)):
            sag = sags[i]
            target = targets[i]
            q = Q[i]
            q = sag / target * q
            Q[i] = q
            opening = openings[i]
            pattern.datastructure.edges_attribute('q', Q[i], keys=opening)
        relax_pattern(pattern.datastructure, relax)

    if count == 10:
        print("did not converge after 10 iterations")
    else:
        print("converged after %s iterations" % count)

    compas_rhino.delete_objects(guids, purge=True)
    scene.update()
    guids = draw_labels()

    # allow user to select label
    # and specify a target sag
    options1 = ['All'] + [
        "Boundary{}".format(i) for i, opening in enumerate(openings)
    ]
    options2 = ["Sag_{}".format(i * 5) for i in range(1, 11)]

    while True:
        option1 = compas_rhino.rs.GetString("Select boundary:",
                                            strings=options1)

        if not option1:
            break

        if option1 == 'All':
            N = [i for i, opening in enumerate(openings)]

        else:
            N = [int(option1[8:])]

        while True:
            option2 = compas_rhino.rs.GetString("Select sag/span percentage:",
                                                strings=options2)

            if not option2:
                break

            for boundary in N:

                targets[boundary] = float(option2[4:]) / 100

                count = 0

                while True and count < 10:
                    count += 1
                    sags = [
                        compute_sag(pattern.datastructure, opening)
                        for opening in openings
                    ]

                    if all((sag - target)**2 < TOL2
                           for sag, target in zip(sags, targets)):
                        break

                    for i in range(len(openings)):
                        sag = sags[i]
                        target = targets[i]
                        q = Q[i]
                        q = sag / target * q
                        Q[i] = q
                        opening = openings[i]
                        pattern.datastructure.edges_attribute('q',
                                                              Q[i],
                                                              keys=opening)
                    relax_pattern(pattern.datastructure, relax)

                if count == 10:
                    print("did not converge after 10 iterations")
                else:
                    print("converged after %s iterations" % count)

            compas_rhino.delete_objects(guids, purge=True)
            scene.update()
            guids = draw_labels()

            break

    compas_rhino.delete_objects(guids, purge=True)
    scene.update()
def RunCommand(is_interactive):

    scene = get_scene()
    if not scene:
        return

    proxy = get_proxy()
    if not proxy:
        return

    srf_guid = compas_rhino.select_surface("Select a surface.")
    if not srf_guid:
        return

    crv_guids = []
    pt_guids = compas_rhino.select_points(
        "Step 1/3 (Optional) - Select points for pole singularities.") or []

    box = compas_rhino.rs.BoundingBox([srf_guid])
    input_subdivision_spacing = 0.01 * compas_rhino.rs.Distance(box[0], box[6])

    mesh_edge_length = compas_rhino.rs.GetReal(
        "Step 2/3 - Enter target length for edges.", 1.0)

    delaunay = proxy.function(
        "compas.geometry.triangulation.triangulation_numpy.delaunay_from_points_numpy"
    )

    pattern = Pattern.from_surface_and_features(input_subdivision_spacing,
                                                mesh_edge_length, srf_guid,
                                                crv_guids, pt_guids, delaunay)

    scene.clear()
    scene.add(pattern, name='pattern')
    scene.update()

    kmax = 10

    while True:
        option = compas_rhino.rs.GetString(
            "Step 3/3 (Optional) - Press Enter to run constrained Laplacian smoothing or ESC to skip.",
            strings=['Iterations'])

        if option is None:
            break

        if not option:
            constraints = automated_smoothing_surface_constraints(
                pattern, srf_guid)
            constraints.update(
                automated_smoothing_constraints(pattern,
                                                points=pt_guids,
                                                curves=crv_guids))
            constrained_smoothing(pattern,
                                  kmax=kmax,
                                  damping=0.5,
                                  constraints=constraints,
                                  algorithm='area')
            objs = set(constraints.values())
            inputs = [srf_guid] + crv_guids + pt_guids
            for obj in objs:
                if obj not in inputs:
                    compas_rhino.rs.DeleteObject(obj)
            compas_rhino.rs.HideObjects(inputs)
            break

        if option == 'Iterations':
            new_kmax = compas_rhino.rs.GetInteger("Number of iterations:",
                                                  kmax)
            if new_kmax or new_kmax is not None:
                kmax = new_kmax

    scene.update()

    print('Pattern object successfully created. Input object has been hidden.')
示例#12
0
def RunCommand(is_interactive):

    scene = get_scene()
    if not scene:
        return

    proxy = get_proxy()
    if not proxy:
        return

    conforming_delaunay_triangulation = proxy.function(
        'compas.geometry.conforming_delaunay_triangulation')

    boundary_guids = compas_rhino.select_curves('Select outer boundary.')
    if not boundary_guids:
        return

    hole_guids = compas_rhino.select_curves('Select inner boundaries.')
    segments_guids = compas_rhino.select_curves('Select constraint curves.')

    target_length = rs.GetReal('Specifiy target edge length.', 1.0)
    if not target_length:
        return

    gkey_constraints = {}

    # outer boundary
    boundary = []
    for guid in boundary_guids:
        compas_rhino.rs.EnableRedraw(False)
        segments = compas_rhino.rs.ExplodeCurves(guid)
        for segment in segments:
            curve = RhinoCurve.from_guid(segment)
            N = max(int(curve.length() / target_length), 1)
            points = map(list, curve.divide(N, over_space=True))
            for point in points:
                gkey = geometric_key(point)
                if gkey not in gkey_constraints:
                    gkey_constraints[gkey] = []
                gkey_constraints[gkey].append(segment)
            boundary.extend(points)
        compas_rhino.delete_objects(segments, purge=True)
        compas_rhino.rs.EnableRedraw(True)

    # constraint polylines
    polylines = []
    if segments_guids:
        for guid in segments_guids:
            curve = RhinoCurve.from_guid(guid)
            N = int(curve.length() / target_length) or 1
            points = map(list, curve.divide(N, over_space=True))
            for point in points:
                gkey = geometric_key(point)
                if gkey not in gkey_constraints:
                    gkey_constraints[gkey] = []
                gkey_constraints[gkey].append(guid)
            polylines.append(points)

    # hole polygons
    polygons = []
    if hole_guids:
        for guid in hole_guids:
            curve = RhinoCurve.from_guid(guid)
            N = int(curve.length() / target_length) or 1
            points = map(list, curve.divide(N, over_space=True))
            for point in points[:-1]:
                gkey = geometric_key(point)
                if gkey not in gkey_constraints:
                    gkey_constraints[gkey] = []
                gkey_constraints[gkey].append(guid)
            polygons.append(points)

    area = target_length**2 * 0.5 * 0.5 * 1.732

    vertices, faces = conforming_delaunay_triangulation(boundary,
                                                        polylines=polylines,
                                                        polygons=polygons,
                                                        angle=30,
                                                        area=area)
    # vertices, faces = constrained_delaunay_triangulation(boundary, polylines=polylines, polygons=polygons)
    vertices[:] = [[float(x), float(y), float(z)] for x, y, z in vertices]

    pattern = Pattern.from_vertices_and_faces(vertices, faces)

    gkey_key = {
        geometric_key(pattern.vertex_coordinates(key)): key
        for key in pattern.vertices()
    }

    for gkey in gkey_constraints:
        guids = gkey_constraints[gkey]
        if gkey in gkey_key:
            key = gkey_key[gkey]
            if len(guids) > 1:
                pattern.vertex_attribute(key, 'is_fixed', True)
            pattern.vertex_attribute(key, 'constraints',
                                     [str(guid) for guid in guids])

    compas_rhino.rs.HideObject(boundary_guids + hole_guids + segments_guids)

    scene.clear()
    scene.add(pattern, name='pattern')
    scene.update()

    print(
        "Pattern object successfully created. Input geometry have been hidden."
    )
示例#13
0
def check():
    p = get_proxy()
    print(p.check())
示例#14
0
def shutdown():
    p = get_proxy()
    p.shutdown()
示例#15
0
def RunCommand(is_interactive):
    p = get_proxy()
    print(p.check())