def main():
    geometry, variables, constraints, all_vars = samples.problem2()

    solver = gs.GCS()

    for g in geometry:
        solver.add_geometry(g)

    for v in variables:
        solver.add_variable(v)

    for c in constraints:
        solver.add_constraint(c)

    v = display.view()
    display.start()

    solver.draw(v)
    #    display.start()

    #    time.sleep(1.0)

    # solved system
    solver.update()

    v.clear()
    solver.draw(v)
Example #2
0
    def display_3d(self):
        r"""Display the Assembly in a 3D viewer (currently ccad viewer)"""
        v = cd.view()
        # print(self.nodes())

        for node in self.nodes():
            # print(node)
            # print(node.shape)

            # Use edges to place nodes
            in_edges_of_node = self.in_edges(node, data=True)
            print("Node : %s" % str(node))
            print("Edges of node : %s" % str(in_edges_of_node))

            assert len(in_edges_of_node) <= 1  # Pour commencer ...

            if len(in_edges_of_node) == 1:
                placed_shape = in_edges_of_node[0][2]['object'].transform(
                    node.shape)
            elif len(in_edges_of_node) == 0:
                placed_shape = node.shape
            else:
                raise NotImplementedError

            # v.display(node.shape,
            #           ccolor=(uniform(0, 1), uniform(0, 1), uniform(0, 1)),
            #           transparency=0.5)
            v.display(placed_shape,
                      color=(uniform(0, 1), uniform(0, 1), uniform(0, 1)),
                      transparency=0.)
            if node.anchors is not None:
                for k, anchor in node.anchors.items():
                    v.display_vector(origin=anchor['position'],
                                     direction=anchor['direction'])
        cd.start()
Example #3
0
def reverse_engineering_with_ccad(_step_filename,
                                  dirname='step',
                                  view=False,
                                  direct=False):
    r"""Reverse engineering using ccad

    Parameters
    ----------

    step_filename : str
        Path to the STEP file
    view : bool, optional (default is False)
        Launch the ccad viewer?
    direct : boolean 

    """
    step_filename = os.path.join(dirname, _step_filename)
    # get Assembly from step file
    assembly = cm.Assembly()
    # read from step file
    assembly.from_step(step_filename, direct=direct)
    # tag nodes with geometrical information
    assembly.tag_nodes()
    # save individual components in separated files
    assembly.write_components()

    if view:
        ccad_viewer = cd.view()
        for shell in assembly.shape.subshapes("Shell"):
            ccad_viewer.display(shell)
        cd.start()

    return assembly
Example #4
0
 def display(self, folded=True):
     viewer = cd.view()
     if folded:
         viewer.display(self.shell)
     else:
         viewer.display(self.shell)
     cd.start()
Example #5
0
def main():
    s1 = cm.sphere(1.0)
    s2 = cm.box(1.0, 2.0, 3.0)
    s2.translate((2.0, 0.0, 0.0))
    v1 = cd.view()
    v1.display(s1)
    v1.display(s2)
    cd.start()
def main():
    s1 = cm.sphere(1.0)
    s2 = cm.box(1.0, 2.0, 3.0)
    s2.translate((2.0, 0.0, 0.0))
    v1 = cd.view()
    v1.display(s1)
    v1.display(s2)
    cd.start()
Example #7
0
def reverse(step_filename, view=False):
    r"""Reverse STEP file using ccad

    Parameters
    ----------
    step_filename : str
        Path to the STEP file
    view : bool, optional (default is False)
        Launch the ccad viewer?

    """
    # read a step file and add nodes to graph
    assembly = Assembly()
    assembly.from_step(step_filename)
    # write a separate step file for each node
    # print("write_components")
    # tic = time.time()
    assembly.write_components()
    # toc = time.time()
    # print(toc-tic)
    # tag and analyze nodes - creates edges between nodes based
    # on dicovered pointcloud similarity and proximity
    #
    # similarity precursor of symmetry
    # proximity precursor of contact
    # join axiality precursor of co-axiality (alignment)
    #
    print("equal_sim_nodes_edges")
    assembly.equalsim_nodes_edges()
    print("delete_edges")
    # assembly.delete_edges(kind='equal')
    print("intersect_nodes_edges")
    assembly.intersect_nodes_edges()
    # assembly saving
    # assembly.save_gml()
    print('save json')
    # assembly.save_json()

    if view:
        ccad_viewer = cd.view()
        for shell in assembly.shape.subshapes("Shell"):
            ccad_viewer.display(shell)
        cd.start()

    return assembly
Example #8
0
def reverse_engineering_with_ccad(step_filename, view=False):
    r"""Reverse engineering using ccad

    Parameters
    ----------
    step_filename : str
        Path to the STEP file
    view : bool, optional (default is False)
        Launch the ccad viewer?

    """
    assembly = cm.Assembly.from_step(step_filename, direct=False)
    assembly.write_components()
    assembly.tag_nodes()

    if view:
        ccad_viewer = cd.view()
        for shell in assembly.shape.subshapes("Shell"):
            ccad_viewer.display(shell)
        cd.start()
head_height = 5.0
key_size = 4.0
socket_depth = 2.5

if length - threaded_length > 0.:
    body = cm.cylinder(threaded_diameter / 2, length) + \
           cm.cylinder(unthreaded_diameter / 2, length - threaded_length)
else:
    body = cm.cylinder(threaded_diameter / 2, length)

socket = cm.translated(
    cm.prism(
        cm.filling
        # ngon is written in a circle of a given radius,
        # the socket definition is the diameter of the
        # circle written in the hexagon
        # -> multiply by 2 / sqrt(3)
        (cm.ngon(2 / 3**.5 * key_size / 2., 6)),
        (0, 0, socket_depth)),
    (0, 0, -head_height))

head = cm.translated(cm.cylinder(head_diameter / 2., head_height),
                     (0, 0, -head_height)) - socket
part = head + body

if __name__ == "__main__":
    import ccad.display as cd
    v = cd.view()
    v.display(part)
    cd.start()
Example #10
0
def view_assembly_nodes(x, node_index=-1):
    """
    Parameters
    ----------

    x : An Assembly Graph
    node_index : a list of Assembly nodes (-1 : all nodes)

    Notes
    -----

    An Assembly is a graph 
    Each node of an assembly has attached
        + a filename describing a solid in its own local frame
        + a quaternion for solid orientation in the global frame
        + a translation vector for solid placement in the global frame

    This function takes an Assembly as argument and produces the view in the global 
    frame. 

    """
    if type(node_index) == int:
        if node_index == -1:
            node_index = x.node.keys()
        else:
            node_index = [node_index]

    assert (max(node_index) <= max(x.node.keys())), "Wrong node index"

    if x.serialized:
        s.unserialize()

    # viewer initialisation
    ccad_viewer = cd.view()
    # get the list of all shape associated with Assembly x
    #
    # This is for debug purpose.
    # In the final implementation.
    # The assembly structure is not supposed to save shapes themselves
    # but only references to files (.py or .step)
    #
    #lshapes1 = [x.node[k]['shape'] for k in node_index]
    # get the list of all filename associated with Assembly x
    lfiles = [str(x.node[k]['name']) + '.stp' for k in node_index]
    # select directory where node files are saved
    # temporary
    #
    fileorig = x.origin.split('.')[0]

    rep = os.path.join('.', fileorig)

    # get the local frame shapes from the list .step files
    lshapes2 = [cm.from_step(os.path.join(rep, s)) for s in lfiles]

    # get unitary matrix and translation for global frame placement
    lV = [x.node[k]['V'] for k in node_index]
    lptm = [x.node[k]['ptc'] for k in node_index]
    #lbmx = [x.node[k]['bmirrorx'] for k in node_index]
    #
    # iter on selected local shapes and apply the graph stored geometrical transformation sequence
    # 1 : rotation
    # 2 : translation
    #
    for k, shp in enumerate(lshapes2):
        V = lV[k]
        shp.transform(V)
        # if 'mx' in x.node[k]:
        #     if x.node[k]['mx']:
        #         print(k,"mx")
        #         shp.mirrorx()
        # if 'my' in x.node[k]:
        #     if x.node[k]['my']:
        #         print(k,"my")
        #         shp.mirrory()
        # if 'mz' in x.node[k]:
        #     if x.node[k]['mz']:
        #         print(k,"mz")
        #         shp.mirrorz()
        #shp.rotate(np.array([0,0,0]),vec,-ang)

        shp.translate(lptm[k])
        shp.foreground = (1, 1, 0.5)

    # create a solid with the transformed shapes
    solid = cm.Solid(lshapes2)
    ccad_viewer.set_background((1, 1, 1))  # White
    ccad_viewer.display(solid, transparency=0.5, material='copper')
    cd.start()
    return lshapes2, lV, lptm
Example #11
0
import ccad.display as cd
import brick

sizes = [(1, 1),
         (2, 1),
         (4, 1),
         (6, 1),
         (8, 1),
         (2, 2),
         (2, 4),
         (2, 8),
         (4, 4)]


def display_brick(view, size):
    view.clear()
    view.display(brick.brick(size[0], size[1]))

if __name__ == '__main__':
    view1 = cd.view()
    for size in sizes:
        name = 'brick' + str(size[0]) + 'x' + str(size[1])
        view1.add_menuitem(('Bricks', name), display_brick, view1, size)
    cd.start()