def __init__(self, doc, name='cone'): self.data = { 'len lo': 70., # mm 'len up': 120., # mm 'int diameter': 36., # mm 'thick': 1., # mm } int_diam = self.data['int diameter'] len_up = self.data['len up'] len_lo = self.data['len lo'] ext_diam = int_diam + 2 * self.data['thick'] int_cone = Part.makeSphere(int_diam / 2) ext_cone = Part.makeSphere(ext_diam / 2) box = Part.makeBox(ext_diam, ext_diam, ext_diam) box.translate(Vector(-ext_diam / 2, -ext_diam / 2, 0)) cone_up = ext_cone.cut(int_cone) cone_up = cone_up.common(box) matrix = Matrix() matrix.scale(1., 1., len_up / (ext_diam / 2)) cone_up = cone_up.transformGeometry(matrix) cone_up.translate(Vector(0, 0, len_lo)) cone_up = cone_up.fuse(cone_up) # blocking thread (pas de vis de blocage) # radius = self.data['int diameter'] / 2 # # helix = Part.makeHelix(4., 20., radius) # # p0 = (radius, 0, 0) # p1 = (radius, 0, 3) # p2 = (radius - 1, 0, 2) # p3 = (radius - 1, 0, 1) # # e0 = Part.makeLine(p0, p1) # e1 = Part.makeLine(p1, p2) # e2 = Part.makeLine(p2, p3) # e3 = Part.makeLine(p3, p0) # section = Part.Wire([e0, e1, e2, e3]) # helix = Part.Wire(helix).makePipeShell([section], 1, 1) # helix.translate(Vector(0, 0, len_lo - 20)) int_tube = Part.makeCylinder(int_diam / 2, len_lo) ext_tube = Part.makeCylinder(ext_diam / 2, len_lo) cone_lo = ext_tube.cut(int_tube) # cone_lo = cone_lo.fuse(helix) #comp = cone_up.fuse(cone_lo) # BUG: this fusion fails!!! comp = cone_lo MecaComponent.__init__(self, doc, comp, name, (1., 1., 0.))
def cone_setup(doc, profil, data): """create all the shapes needed for the cone parts""" # if the final shapes already existed (true if one shape exists) # return them immediatly cone_top_obj = doc.getObject('_cone_top_base') cone_side_obj = doc.getObject('_cone_side_base') cone_struct_obj = doc.getObject('_cone_struct_base') cone_top_thread_obj = doc.getObject('_cone_top_thread') cone_struct_thread_obj = doc.getObject('_cone_struct_thread') if cone_top_obj: cone_top = cone_top_obj.Shape.copy() cone_side0 = cone_side_obj.Shape.copy() cone_side1 = cone_side_obj.Shape.copy() cone_side2 = cone_side_obj.Shape.copy() cone_struct = cone_struct_obj.Shape.copy() cone_top_thread = cone_top_thread_obj.Shape.copy() cone_struct_thread = cone_struct_thread_obj.Shape.copy() return cone_top, cone_side0, cone_side1, cone_side2, cone_struct, \ cone_top_thread, cone_struct_thread side = profil['side'] radius = profil['radius'] diam_int = data['diameter'] diam_ext = data['diameter'] + data['thick'] length = data['len_lo'] + data['len_hi'] struct_thick = data['struct_thick'] # to modify the sphere to make it a ellipsoid matrix = Matrix() matrix.scale(1., 1., length / (diam_ext / 2)) # to suppress the lower half of the sphere/ellipsoid lower = Part.makeBox(diam_ext, diam_ext, length) lower.translate(Vector(-diam_ext / 2, -diam_ext / 2, 0)) gui_doc = FreeCADGui.ActiveDocument # make the external shape base of the cone sphere = Part.makeSphere(diam_ext / 2) sphere = sphere.transformGeometry(matrix) cone_base_ext = sphere.common(lower) cone_base_ext_obj = doc.addObject("Part::Feature", '_cone_base_ext') cone_base_ext_obj.Shape = cone_base_ext gui_doc.getObject('_cone_base_ext').Visibility = False # make the internal shape base of the cone sphere = Part.makeSphere(diam_int / 2) sphere = sphere.transformGeometry(matrix) cone_base_int = sphere.common(lower) cone_base_int_obj = doc.addObject("Part::Feature", '_cone_base_int') cone_base_int_obj.Shape = cone_base_int gui_doc.getObject('_cone_base_int').Visibility = False # make the skin skin = cone_base_ext.cut(cone_base_int) skin_obj = doc.addObject("Part::Feature", '_skin') skin_obj.Shape = skin gui_doc.getObject('_skin').Visibility = False # use profile shapes to make suppressed parts of the skin # full profil part shape = [] shape.append(Vector(radius - 10, side / 2, 0)) shape.append(Vector(radius + diam_ext, side / 2, 0)) shape.append(Vector(radius + diam_ext, -side / 2, 0)) shape.append(Vector(radius - 10, -side / 2, 0)) shape.append(Vector(radius - 10, side / 2, 0)) wire = Part.makePolygon(shape) face = Part.Face(wire) # make the volume long_cut_base = face.extrude(Vector(0, 0, length)) long_cut_obj = doc.addObject("Part::Feature", '_long_cut_base') long_cut_obj.Shape = long_cut_base gui_doc.getObject('_long_cut_base').Visibility = False # full profil part shape = [] shape.append(Vector(radius, side / 2, 0)) shape.append(Vector(radius + diam_ext, side / 2, 0)) shape.append(Vector(radius + diam_ext, -side / 2, 0)) shape.append(Vector(radius, -side / 2, 0)) shape.append(Vector(radius, side / 2, 0)) wire = Part.makePolygon(shape) face = Part.Face(wire) # make the volume short_cut_base = face.extrude(Vector(0, 0, data['len_lo'])) short_cut_obj = doc.addObject("Part::Feature", '_short_cut_base') short_cut_obj.Shape = short_cut_base gui_doc.getObject('_short_cut_base').Visibility = False # create 1/3 cylinder cylinder = Part.makeCylinder(diam_ext / 2, length, Vector(0, 0, 0), Vector(0, 0, 1), 120) cylinder_obj = doc.addObject("Part::Feature", '_cylinder_1_3') cylinder_obj.Shape = cylinder gui_doc.getObject('_cylinder_1_3').Visibility = False # thread bases radius_ext = diam_ext / 2 - struct_thick - 5 thread_ext = Part.makeHelix(8, struct_thick - 8, radius_ext) radius_int = diam_ext / 2 - struct_thick - 9 thread_int = Part.makeHelix(8, struct_thick, radius_int) # tube to make the space for threads tube_thread_ext = Part.makeCylinder(radius_ext, struct_thick) tube_thread_int = Part.makeCylinder(radius_int, struct_thick) tube_thread = tube_thread_ext.cut(tube_thread_int) tube_thread_obj = doc.addObject("Part::Feature", '_tube_thread') tube_thread_obj.Shape = tube_thread gui_doc.getObject('_tube_thread').Visibility = False # tube to cut the top of the structure tube_cut_ext = Part.makeCylinder(diam_ext / 2 - struct_thick / 2, struct_thick) tube_cut_int = tube_thread_int tube_cut = tube_cut_ext.cut(tube_cut_int) tube_cut_obj = doc.addObject("Part::Feature", '_tube_cut') tube_cut_obj.Shape = tube_cut gui_doc.getObject('_tube_cut').Visibility = False # tube to make the locking of the cone tube_lock_0 = Part.makeCylinder(diam_ext / 2 - struct_thick - 2, struct_thick / 2) tube_lock_1 = Part.makeCylinder(diam_ext / 2 - struct_thick + 2, struct_thick / 2) tube_lock_2 = Part.makeCylinder(diam_ext / 2, struct_thick / 4) tube_lock_int = tube_lock_1.cut(tube_lock_0) tube_lock_int.translate(Vector(0, 0, data['len_lo'] - 0.25 * data['struct_thick'])) tube_lock_obj = doc.addObject("Part::Feature", '_tube_lock_int') tube_lock_obj.Shape = tube_lock_int gui_doc.getObject('_tube_lock_int').Visibility = False tube_lock_ext = tube_lock_2.cut(tube_lock_0) tube_lock_ext.translate(Vector(0, 0, data['len_lo'] - 0.25 * data['struct_thick'])) tube_lock_obj = doc.addObject("Part::Feature", '_tube_lock_ext') tube_lock_obj.Shape = tube_lock_ext gui_doc.getObject('_tube_lock_ext').Visibility = False # make cone top part cone_top = cone_top_make(doc, gui_doc, data, skin, lower, cone_base_int, tube_cut, tube_thread, tube_lock_int) cone_top = cone_top.copy() cone_side = cone_side_make(doc, gui_doc, skin, lower, data, cone_base_int, long_cut_base, cylinder, tube_lock_int, tube_lock_ext) cone_side0 = cone_side.copy() cone_side0.rotate(Vector(0, 0, 0), Vector(0, 0, 1), 0) cone_side1 = cone_side.copy() cone_side1.rotate(Vector(0, 0, 0), Vector(0, 0, 1), 120) cone_side2 = cone_side.copy() cone_side2.rotate(Vector(0, 0, 0), Vector(0, 0, 1), 240) cone_struct = cone_struct_make(doc, gui_doc, cone_base_ext, short_cut_base, data, cone_top, cone_side, tube_thread) # internal thread profile p0 = (radius_int, 0, 0) p1 = (radius_int + 4, 0, 4) p2 = (radius_int, 0, 8) e0 = Part.makeLine(p0, p1) e1 = Part.makeLine(p1, p2) e2 = Part.makeLine(p2, p0) section = Part.Wire([e0, e1, e2]) cone_struct_thread = Part.Wire(thread_int).makePipeShell([section], 1, 1) cone_struct_thread_obj = doc.addObject("Part::Feature", '_cone_struct_thread') cone_struct_thread_obj.Shape = cone_struct_thread.copy() gui_doc.getObject('_cone_struct_thread').Visibility = False # external thread profile p0 = (radius_ext, 0, 0) p1 = (radius_ext - 4, 0, 4) p2 = (radius_ext, 0, 8) e0 = Part.makeLine(p0, p1) e1 = Part.makeLine(p1, p2) e2 = Part.makeLine(p2, p0) section = Part.Wire([e0, e1, e2]) cone_top_thread = Part.Wire(thread_ext).makePipeShell([section], 1, 1) cone_top_thread_obj = doc.addObject("Part::Feature", '_cone_top_thread') cone_top_thread_obj.Shape = cone_top_thread.copy() gui_doc.getObject('_cone_top_thread').Visibility = False return cone_top, cone_side0, cone_side1, cone_side2, cone_struct, \ cone_top_thread, cone_struct_thread