Ejemplo n.º 1
0
def RunCommand(is_interactive):
    if 'TNA' not in sc.sticky:
        raise Exception("Initialise the plugin first!")

    TNA = sc.sticky['TNA']
    form = TNA['form']
    force = TNA['force']
    settings = TNA['settings']

    options = ['form', 'force']
    option = rs.GetString("Select a Diagram", options[0], options)
    if not option:
        return

    if option == 'form':
        if not form:
            return

        options = ['vertices', 'edges', 'faces']
        option = rs.GetString("Select a component", options[0], options)
        if not option:
            return

        if option == 'vertices':
            options = ['selection', 'boundary', 'anchors', 'external', 'all']
            option = rs.GetString("Selection mode", options[0], options)
            if not option:
                return

            if option == 'selection':
                keys = DiagramHelper.select_vertices(form)
            elif option == 'boundary':
                keys = list(form.vertices_on_boundary())
            elif option == 'anchors':
                keys = list(form.vertices_where({'is_anchor': True}))
            elif option == 'external':
                keys = list(form.vertices_where({'is_external': True}))
            elif option == 'all':
                keys = list(form.vertices())
            else:
                raise NotImplementedError

            if not keys:
                return

            if DiagramHelper.update_vertex_attributes(form, keys):
                form.draw(layer=settings['layer.form'],
                          clear_layer=True,
                          settings=settings)

        elif option == 'edges':
            options = [
                'selection', 'parallel', 'continuous', 'boundary', 'external',
                'all'
            ]
            option = rs.GetString("Selection mode", options[0], options)

            if option == 'selection':
                keys = DiagramHelper.select_edges(form)
            elif option == 'parallel':
                keys = DiagramHelper.select_parallel_edges(form)
            elif option == 'continuous':
                keys = DiagramHelper.select_continuous_edges(form)
            elif option == 'boundary':
                keys = list(form.edges_on_boundary())
            elif option == 'external':
                keys = list(form.edges_where({'is_external': True}))
            elif option == 'all':
                keys = list(form.edges())
            else:
                raise NotImplementedError

            if not keys:
                return

            if DiagramHelper.update_edge_attributes(form, keys):
                form.draw(layer=settings['layer.form'],
                          clear_layer=True,
                          settings=settings)

        elif option == 'faces':
            pass

        else:
            raise NotImplementedError
Ejemplo n.º 2
0

# visualise the result

force.draw(layer='AAG::ForceDiagram')


# move the force diagram to a different location

DiagramHelper.move(force)

force.draw(layer='AAG::ForceDiagram')


# fix one of the force diagram vertices to keep it there in the future

key = DiagramHelper.select_vertex(force)

if key is not None:
    DiagramHelper.update_vertex_attributes(force, [key])


# redraw the force diagram

force.draw(layer='AAG::ForceDiagram')


# and serialise the result

force.to_json('aag_03_forcediagram.json')
Ejemplo n.º 3
0
def RunCommand(is_interactive):
    if 'TNA' not in sc.sticky:
        raise Exception("Initialise the plugin first!")

    TNA = sc.sticky['TNA']

    options = ['form', 'force']
    option = rs.GetString("Select a Diagram", options[0], options)
    if not option:
        return

    if option == 'form':
        form = TNA['form']
        if not form:
            return

        options = ['vertices', 'edges', 'faces']
        option = rs.GetString("Select a component type", options[0], options)
        if not option:
            return

        if option == 'vertices':
            keys = DiagramHelper.select_vertices(form)
            if not keys:
                return
            if DiagramHelper.update_vertex_attributes(form, keys):
                form.draw(layer=TNA['settings']['layer.form'],
                          clear_layer=True,
                          settings=TNA['settings'])

        elif option == 'edges':
            keys = DiagramHelper.select_edges(form)
            if not keys:
                return
            if DiagramHelper.update_edge_attributes(form, keys):
                form.draw(layer=TNA['settings']['layer.form'],
                          clear_layer=True,
                          settings=TNA['settings'])

        elif option == 'faces':
            keys = DiagramHelper.select_faces(form)
            if not keys:
                return
            if DiagramHelper.update_face_attributes(form, keys):
                form.draw(layer=TNA['settings']['layer.form'],
                          clear_layer=True,
                          settings=TNA['settings'])

    if option == 'force':
        force = TNA['force']
        if not force:
            return

        options = ['vertices', 'edges']
        option = rs.GetString("Select a component type", options[0], options)
        if not option:
            return

        if option == 'vertices':
            keys = DiagramHelper.select_vertices(force)
            if not keys:
                return
            if DiagramHelper.update_vertex_attributes(force, keys):
                force.draw(layer=TNA['settings']['layer.force'],
                           clear_layer=True,
                           settings=TNA['settings'])

        elif option == 'edges':
            keys = DiagramHelper.select_edges(force)
            if not keys:
                return
            if DiagramHelper.update_edge_attributes(force, keys):
                force.draw(layer=TNA['settings']['layer.force'],
                           clear_layer=True,
                           settings=TNA['settings'])