示例#1
0
 def on_apply(self, sender, event):
     try:
         for page in self.TabControl.Pages:
             if hasattr(page, 'apply'):
                 page.apply()
         get_scene().update()
     except Exception as e:
         print(e)
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

    RV2settings_cmd.RunCommand(True)
示例#4
0
def RunCommand(is_interactive):

    system = get_system()
    if not system:
        return

    scene = get_scene()
    if not scene:
        return

    filepath = select_filepath_open(system['session.dirname'],
                                    system['session.extension'])
    if not filepath:
        return

    dirname, basename = os.path.split(filepath)
    filename, extension = os.path.splitext(basename)

    system['session.dirname'] = dirname
    system['session.filename'] = filename

    with open(filepath, "r") as f:
        session = json.load(f, cls=DataDecoder)

    load_session(session)
示例#5
0
def RunCommand(is_interactive):

    scene = get_scene()
    if not scene:
        return

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

    options = [
        "DiagramAttributes", "VerticesAttributes", "FacesAttributes",
        "MoveSupports"
    ]
    option = compas_rhino.rs.GetString("Modify thrust diagram:",
                                       strings=options)

    if not option:
        return

    if option == "DiagramAttributes":
        RV2thrust_attributes_cmd.RunCommand(True)

    elif option == "VerticesAttributes":
        RV2thrust_modify_vertices_cmd.RunCommand(True)

    elif option == "FacesAttributes":
        RV2thrust_modify_faces_cmd.RunCommand(True)

    elif option == "MoveSupports":
        RV2thrust_move_supports_cmd.RunCommand(True)
def RunCommand(is_interactive):

    scene = get_scene()
    if not scene:
        return

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

    options = ["DiagramAttributes", "VerticesAttributes", "EdgesAttributes", "MoveVertices", "Relax"]
    option = compas_rhino.rs.GetString("Modify form diagram:", strings=options)

    if not option:
        return

    if option == "DiagramAttributes":
        RV2form_attributes_cmd.RunCommand(True)

    elif option == "VerticesAttributes":
        RV2form_modify_vertices_cmd.RunCommand(True)

    elif option == "EdgesAttributes":
        RV2form_modify_edges_cmd.RunCommand(True)

    elif option == "MoveVertices":
        RV2form_move_vertices_cmd.RunCommand(True)

    elif option == "Relax":
        RV2form_relax_cmd.RunCommand(True)
def RunCommand(is_interactive):

    scene = get_scene()
    if not scene:
        return

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

    options = ["All", "Continuous", "Parallel", "Manual"]
    option = compas_rhino.rs.GetString("Selection Type", strings=options)

    if not option:
        return

    if option == "All":
        keys = keys = list(pattern.datastructure.edges())

    elif option == "Continuous":
        temp = pattern.select_edges()
        keys = list(set(flatten([pattern.datastructure.edge_loop(key) for key in temp])))

    elif option == "Parallel":
        temp = pattern.select_edges()
        keys = list(set(flatten([pattern.datastructure.edge_strip(key) for key in temp])))

    elif option == "Manual":
        keys = pattern.select_edges()

    if keys:
        public = [name for name in pattern.datastructure.default_edge_attributes.keys() if not name.startswith('_')]
        if pattern.update_edges_attributes(keys, names=public):
            scene.update()
示例#8
0
def RunCommand(is_interactive):

    scene = get_scene()
    if not scene:
        return

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

    options = ["ByContinuousEdges", "Manual"]
    option = compas_rhino.rs.GetString("Selection Type.", strings=options)
    if not option:
        return

    if option == "ByContinuousEdges":
        temp = pattern.select_edges()
        keys = list(
            set(
                flatten([
                    pattern.datastructure.vertices_on_edge_loop(key)
                    for key in temp
                ])))

    elif option == "Manual":
        keys = pattern.select_vertices()

    if keys:
        if pattern.move_vertices(keys):
            scene.update()
示例#9
0
def RunCommand(is_interactive):

    system = get_system()
    if not system:
        return

    scene = get_scene()
    if not scene:
        return

    dirname = system['session.dirname']
    filename = system['session.filename']
    extension = system['session.extension']

    if not filename:
        filepath = select_filepath_save(dirname, extension)
        if not filepath:
            return
        dirname, basename = os.path.split(filepath)
        filename, _ = os.path.splitext(basename)

    filepath = os.path.join(dirname, filename + '.' + extension)

    # this should be templated somewhere
    # perhaps there should be a Session class/object/singleton

    session = save_session()

    with open(filepath, 'w+') as f:
        json.dump(session, f, cls=DataEncoder)
def RunCommand(is_interactive):

    scene = get_scene()
    if not scene:
        return

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

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

    options = ["ByContinuousEdges", "Manual"]
    option = compas_rhino.rs.GetString("Selection Type.", strings=options)
    if not option:
        return

    if option == "ByContinuousEdges":
        temp = force.select_edges()
        keys = list(set(flatten([force.datastructure.vertices_on_edge_loop(key) for key in temp])))

    elif option == "Manual":
        keys = force.select_vertices()

    if keys:
        if force.move_vertices(keys):
            if force.datastructure.primal:
                force.datastructure.update_angle_deviations()
            if thrust:
                thrust.settings['_is.valid'] = False
            scene.update()
示例#11
0
def RunCommand(is_interactive):

    scene = get_scene()
    if not scene:
        return

    options = [
        "FromLines", "FromMesh", "FromSurface", "FromSkeleton",
        "FromTriangulation", "FromFeatures"
    ]
    option = compas_rhino.rs.GetString("Create Pattern:", strings=options)

    if not option:
        return

    if option == "FromLines":
        RV2pattern_from_lines_cmd.RunCommand(True)

    elif option == "FromMesh":
        RV2pattern_from_mesh_cmd.RunCommand(True)

    elif option == "FromSurface":
        RV2pattern_from_surface_cmd.RunCommand(True)

    elif option == "FromSkeleton":
        RV2pattern_from_skeleton_cmd.RunCommand(True)

    elif option == "FromTriangulation":
        RV2pattern_from_triangulation_cmd.RunCommand(True)

    elif option == "FromFeatures":
        RV2pattern_from_features_cmd.RunCommand(True)
示例#12
0
def RunCommand(is_interactive):
    scene = get_scene()
    if not scene:
        return

    # get untrimmed surface(s) -------------------------------------------------
    guid = compas_rhino.select_surface(
        message='select an untrimmed surface or a polysurface')

    if not guid:
        return

    compas_rhino.rs.HideObjects(guid)

    # make subd object ---------------------------------------------------------
    subdobject = SubdObject.from_guid(guid)

    if not subdobject:
        return

    compas_rhino.rs.HideObjects(guid)
    subdobject.draw_coarse()
    subdobject.get_draw_default_subd()
    subdobject.draw_subd()

    # interactively  modify subdivision ----------------------------------------
    while True:
        menu = CommandMenu(config)
        action = menu.select_action()

        if not action or action is None:
            subdobject.clear()
            print("Pattern from surface(s) aborted!")
            compas_rhino.rs.ShowObjects(guid)
            return

        if action['name'] == 'Finish':
            break

        action['action'](subdobject)

    # make pattern -------------------------------------------------------------
    mesh = subdobject.subd
    xyz = mesh.vertices_attributes('xyz')
    faces = [mesh.face_vertices(fkey) for fkey in mesh.faces()]
    pattern = Pattern.from_vertices_and_faces(xyz, faces)

    # clear skeleton
    layer = subdobject.settings['layer']
    subdobject.clear()
    compas_rhino.delete_layers([layer])

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

    print(
        "Pattern object successfully created. Input surface(s) have been hidden."
    )
示例#13
0
def RunCommand(is_interactive):

    scene = get_scene()
    if not scene:
        return

    SettingsForm.from_scene(scene, object_types=["PatternObject", "FormObject", "ForceObject", "ThrustObject"], global_settings=["RV2", "Solvers"])

    scene.update()
示例#14
0
def RunCommand(is_interactive):

    scene = get_scene()
    if not scene:
        return

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

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

    options = ["All", "ByContinuousEdges", "Manual"]
    option = compas_rhino.rs.GetString("Selection Type.", strings=options)
    if not option:
        return

    if option == "All":
        keys = list(force.datastructure.vertices())

    elif option == "ByContinuousEdges":
        temp = force.select_edges()
        keys = list(
            set(
                flatten([
                    force.datastructure.vertices_on_edge_loop(key)
                    for key in temp
                ])))

    elif option == "Manual":
        keys = force.select_vertices()

    if keys:
        # current = scene.settings['RV2']['show.angles']
        # scene.settings['RV2']['show.angles'] = False
        # scene.update()

        # ModifyAttributesForm.from_sceneNode(force, 'vertices', keys)

        # scene.settings['RV2']['show.angles'] = current
        # if thrust:
        #     thrust.settings['_is.valid'] = False
        # scene.update()
        public = [
            name
            for name in force.datastructure.default_vertex_attributes.keys()
            if not name.startswith('_')
        ]
        if force.update_vertices_attributes(keys, names=public):
            if thrust:
                thrust.settings['_is.valid'] = False

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

    rhinoform = scene.get("form")[0]

    if not rhinoform:
        return

    AttributesForm.from_diagram(rhinoform)
def RunCommand(is_interactive):

    scene = get_scene()
    if not scene:
        return

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

    AttributesForm.from_sceneNode(force)
def RunCommand(is_interactive):

    scene = get_scene()
    if not scene:
        return

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

    AttributesForm.from_sceneNode(pattern)
def RunCommand(is_interactive):

    scene = get_scene()
    if not scene:
        return

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

    AttributesForm.from_sceneNode(thrust)
示例#19
0
def RunCommand(is_interactive):

    scene = get_scene()
    if not scene:
        return

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

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

    # show the form vertices
    form_vertices = "{}::vertices".format(form.settings['layer'])
    compas_rhino.rs.ShowGroup(form_vertices)

    if thrust:
        # hide the thrust vertices
        thrust_vertices_free = "{}::vertices_free".format(thrust.settings['layer'])
        thrust_vertices_anchor = "{}::vertices_anchor".format(thrust.settings['layer'])
        compas_rhino.rs.HideGroup(thrust_vertices_free)
        compas_rhino.rs.HideGroup(thrust_vertices_anchor)

    compas_rhino.rs.Redraw()

    # selection options
    options = ["ByContinuousEdges", "Manual"]
    option = compas_rhino.rs.GetString("Selection Type.", strings=options)
    if not option:
        scene.update()
        return

    if option == "ByContinuousEdges":
        temp = form.select_edges()
        keys = list(set(flatten([form.datastructure.vertices_on_edge_loop(key) for key in temp])))

    elif option == "Manual":
        keys = form.select_vertices()

    if keys:
        if form.move_vertices(keys):
            if form.datastructure.dual:
                form.datastructure.dual.update_angle_deviations()
            if thrust:
                thrust.settings['_is.valid'] = False

    # the scene needs to be updated
    # even if the vertices where not modified
    # to reset group visibility to the configuration of settings
    scene.update()
示例#20
0
def RunCommand(is_interactive):

    scene = get_scene()
    if not scene:
        return

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

    if not pattern:
        print("There is no Pattern in the scene.")
        return

    if not list(pattern.datastructure.vertices_where({'is_anchor': True})):
        print(
            "Pattern has no anchor vertices! Please define anchor (support) vertices."
        )
        return

    form = FormDiagram.from_pattern(pattern.datastructure)
    form.vertices_attribute('is_fixed', False)

    normals = [
        form.face_normal(face)
        for face in form.faces_where({'_is_loaded': True})
    ]
    scale = 1 / len(normals)
    normal = scale_vector(sum_vectors(normals), scale)
    if normal[2] < 0:
        form.flip_cycles()

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

    if fixed:
        for key in fixed:
            if form.has_vertex(key):
                form.vertex_attribute(key, 'is_anchor', True)

    thrust = form.copy(cls=ThrustDiagram)

    bbox_form = form.bounding_box_xy()
    diagonal = length_vector(subtract_vectors(bbox_form[2], bbox_form[0]))
    zmax = 0.25 * diagonal

    scene.settings['Solvers']['tna.vertical.zmax'] = round(zmax, 1)
    scene.clear()
    scene.add(form, name='form')
    scene.add(thrust, name='thrust')
    scene.update()

    print('FormDiagram object successfully created.')
def RunCommand(is_interactive):

    scene = get_scene()
    if not scene:
        return

    options = ["Yes", "No"]
    option = compas_rhino.rs.GetString("Clear all RV2 objects?",
                                       strings=options,
                                       defaultString="No")
    if not option:
        return

    if option == "Yes":
        scene.clear()
def RunCommand(is_interactive):

    system = get_system()
    if not system:
        return

    scene = get_scene()
    if not scene:
        return

    dirname = system['session.dirname']
    filename = system['session.filename']
    extension = system['session.extension']

    filepath = select_filepath_save(dirname, extension)
    if not filepath:
        return
    dirname, basename = os.path.split(filepath)
    filename, _ = os.path.splitext(basename)

    filepath = os.path.join(dirname, filename + '.' + extension)

    # this should be templated somewhere
    # perhaps there should be a Session class/object/singleton

    session = {
        "data": {
            "pattern": None,
            "form": None,
            "force": None
        },
        "settings": scene.settings,
    }

    pattern = scene.get('pattern')[0]
    if pattern:
        session['data']['pattern'] = pattern.datastructure.to_data()

    form = scene.get('form')[0]
    if form:
        session['data']['form'] = form.datastructure.to_data()

    force = scene.get('force')[0]
    if force:
        session['data']['force'] = force.datastructure.to_data()

    with open(filepath, 'w+') as f:
        json.dump(session, f, cls=DataEncoder)
示例#23
0
def RunCommand(is_interactive):

    scene = get_scene()
    if not scene:
        return

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

    # select vertices and faces
    # delete selected vertices and faces
    # update scene

    raise NotImplementedError
示例#24
0
def RunCommand(is_interactive):
    scene = get_scene()
    if not scene:
        return

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

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

    if not action:
        return

    action["action"](rhinoform)
示例#25
0
def RunCommand(is_interactive):

    scene = get_scene()
    if not scene:
        return

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

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

    options = ["All", "Continuous", "Parallel", "Manual"]
    option = compas_rhino.rs.GetString("Selection Type.", strings=options)
    if not option:
        return

    if option == "All":
        keys = list(force.datastructure.edges())

    elif option == "Continuous":
        edges = force.select_edges()
        keys = list(
            set(
                flatten(
                    [force.datastructure.edge_loop(edge) for edge in edges])))

    elif option == "Parallel":
        temp = force.select_edges()
        keys = list(
            set(flatten([force.datastructure.edge_strip(key)
                         for key in temp])))

    elif option == "Manual":
        keys = force.select_edges()

    if keys:
        public = [
            name
            for name in force.datastructure.default_edge_attributes.keys()
            if not name.startswith("_")
        ]
        if force.update_edges_attributes(keys, names=public):
            if thrust:
                thrust.settings['_is.valid'] = False
            scene.update()
示例#26
0
def RunCommand(is_interactive):

    scene = get_scene()
    if not scene:
        return

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

    options = ["AllBoundaryVertices", "Corners", "ByContinuousEdges", "Manual"]

    while True:
        option = compas_rhino.rs.GetString("Selection mode:", strings=options)

        if not option:
            return

        if option == "AllBoundaryVertices":
            keys = pattern.datastructure.vertices_on_boundary()

        elif option == "Corners":
            angle = compas_rhino.rs.GetInteger(
                'Angle tolerance for non-quad face corners:', 170, 1, 180)
            keys = pattern.datastructure.corner_vertices(tol=angle)

        elif option == "ByContinuousEdges":
            temp = pattern.select_edges()
            keys = list(
                set(
                    flatten([
                        pattern.datastructure.vertices_on_edge_loop(key)
                        for key in temp
                    ])))

        elif option == "Manual":
            keys = pattern.select_vertices()

        if keys:
            public = [
                name for name in
                pattern.datastructure.default_vertex_attributes.keys()
                if not name.startswith('_')
            ]
            if pattern.update_vertices_attributes(keys, names=public):
                scene.update()
def RunCommand(is_interactive):

    scene = get_scene()
    if not scene:
        return

    # both form and thrust need to be available

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

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

    # hide the form vertices
    form_vertices = "{}::vertices".format(form.settings['layer'])
    compas_rhino.rs.HideGroup(form_vertices)

    # show the thrust vertices
    thrust_vertices_free = "{}::vertices_free".format(thrust.settings['layer'])
    thrust_vertices_anchor = "{}::vertices_anchor".format(
        thrust.settings['layer'])
    compas_rhino.rs.HideGroup(thrust_vertices_free)
    compas_rhino.rs.ShowGroup(thrust_vertices_anchor)

    compas_rhino.rs.Redraw()

    # select anchored vertices
    keys = thrust.select_vertices_anchor()

    if keys:
        if thrust.move_vertices_vertical(keys):
            for key in keys:
                # update the corresponding form diagram vertices
                z = thrust.datastructure.vertex_attribute(key, 'z')
                form.datastructure.vertex_attribute(key, 'z', z)
            thrust.settings['_is.valid'] = False

    # the scene needs to be updated
    # in any case
    # to reset object visualisation
    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 = 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

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

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

    # hide the form vertices
    form_vertices = "{}::vertices".format(form.settings['layer'])
    compas_rhino.rs.HideGroup(form_vertices)

    # selection options
    options = ["Manual"]
    option = compas_rhino.rs.GetString("Selection Type.", strings=options)
    if not option:
        scene.update()
        return

    if option == "Manual":
        keys = thrust.select_faces()

    thrust_name = thrust.name

    if keys:
        public = [
            name for name in form.datastructure.default_face_attributes.keys()
            if not name.startswith('_')
        ]
        if form.update_faces_attributes(keys, names=public):
            thrust.datastructure.data = form.datastructure.data
            thrust.name = thrust_name
            thrust.settings['_is.valid'] = False

    scene.update()
示例#30
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()