def KugellagerZeichnen(self):
        #VALUES#
        #(radius of shaft/inner radius of inner ring)
        R1 = 15.0
        #(outer radius of inner ring)
        R2 = 25.0
        #(inner radius of outer ring)
        R3 = 30.0
        #(outer radius of outer ring)
        R4 = 40.0
        #(thickness of bearing)
        TH = 15.0
        #(number of balls)
        NBall = 15
        #(radius of ball)
        RBall = 5.0
        #(rounding radius for fillets)
        RR = 1
        #first coordinate of center of ball
        CBall = ((R3 - R2) / 2) + R2
        #second coordinate of center of ball
        PBall = TH / 2

        #Inner Ring#
        B1 = Part.makeCylinder(R1, TH)
        B2 = Part.makeCylinder(R2, TH)
        IR = B2.cut(B1)
        #get edges and apply fillets
        Bedges = IR.Edges
        IRF = IR.makeFillet(RR, Bedges)
        #create groove and show shape
        T1 = Part.makeTorus(CBall, RBall)
        T1.translate(App.Vector(0, 0, TH / 2))
        InnerRing = IRF.cut(T1)
        Part.show(InnerRing)
        #
        #Outer Ring#
        B3 = Part.makeCylinder(R3, TH)
        B4 = Part.makeCylinder(R4, TH)
        OR = B4.cut(B3)
        #get edges and apply fillets
        Bedges = OR.Edges
        ORF = OR.makeFillet(RR, Bedges)
        #create groove and show shape
        T2 = Part.makeTorus(CBall, RBall)
        T2.translate(App.Vector(0, 0, TH / 2))
        OuterRing = ORF.cut(T2)
        Part.show(OuterRing)
        #
        #Balls#
        for i in range(NBall):
            Ball = Part.makeSphere(RBall)
            Alpha = (i * 2 * Math.pi) / NBall
            BV = (CBall * Math.cos(Alpha), CBall * Math.sin(Alpha), TH / 2)
            Ball.translate(BV)
            Part.show(Ball)
        #
        #Make it pretty#
        Gui.SendMsgToActiveView("ViewFit")
Example #2
0
 def resolvePrimitive(self):
     if isinstance(self.component, barleycorn.primitives.Cone):
         self.partrep = Part.makeCone(0, self.component.radius,
                                      self.component.height)
     elif isinstance(self.component, barleycorn.primitives.Cylinder):
         self.partrep = Part.makeCylinder(self.component.radius,
                                          self.component.height)
     elif isinstance(self.component, barleycorn.primitives.Box):
         self.partrep = Part.makeBox(self.component.dimX,
                                     self.component.dimY,
                                     self.component.dimZ)
     elif isinstance(self.component, barleycorn.primitives.Torus):
         self.partrep = Part.makeTorus(self.component.radiusMajor,
                                       self.component.radiusMinor)
     elif isinstance(self.component, barleycorn.primitives.Wedge):
         self.partrep = Part.makeCylinder(self.component.radius,
                                          self.component.height,
                                          Base.Vector(0, 0, 0),
                                          Base.Vector(0, 0, 1),
                                          self.component.angle)
     elif isinstance(self.component, barleycorn.primitives.Sphere):
         self.partrep = Part.makeSphere(self.component.radius)
     else:
         raise Exception("unrecognized primitive: " +
                         str(type(self.component)))
     return self
Example #3
0
 def makeTorus(cls, radius1, radius2, pnt=None, dir=None, angleDegrees1=None, angleDegrees2=None):
     """
     makeTorus(radius1,radius2,[pnt,dir,angle1,angle2,angle]) --
     Make a torus with agiven radii and angles
     By default pnt=Vector(0,0,0),dir=Vector(0,0,1),angle1=0
     ,angle1=360 and angle=360'
     """
     return Shape.cast(FreeCADPart.makeTorus(radius1, radius2, pnt, dir, angleDegrees1, angleDegrees2))
 def makeTorus(cls, radius1, radius2, pnt=None, dir=None, angleDegrees1=None, angleDegrees2=None):
     """
     makeTorus(radius1,radius2,[pnt,dir,angle1,angle2,angle]) --
     Make a torus with agiven radii and angles
     By default pnt=Vector(0,0,0),dir=Vector(0,0,1),angle1=0
     ,angle1=360 and angle=360'
     """
     return Shape.cast(FreeCADPart.makeTorus(radius1, radius2, pnt, dir, angleDegrees1, angleDegrees2))
Example #5
0
def singlerowradialbearing(params,document):
	rout=0.5*params['d2']
	rin=0.5*params['d1']
	bth=0.5*params['B']
	name=params['name']
	detailed = params['detailed']

	#shapes---
	shapes=[]
	RR=0.015*rout
	if detailed:
		rb=(rout-rin)*0.25
		cb=((rout-rin)/2.00+rin)
		#outer ring--------------
		our1=Part.makeCylinder(rout,bth)
		our2=Part.makeCylinder(cb+rb*0.7,bth)
		our=our1.cut(our2)
		oure=our.Edges
		our=our.makeFillet(RR,oure)
		#inner ring--------------
		inr1=Part.makeCylinder(cb-rb*0.7,bth)
		inr2=Part.makeCylinder(rin,bth)
		inr=inr1.cut(inr2)
		inre=inr.Edges
		inr=inr.makeFillet(RR,inre)
		#track-------------------
		t=Part.makeTorus(cb,rb)
		vt=(0,0,bth/2)
		t.translate(vt)
		our=our.cut(t)
		inr=inr.cut(t)
		#shapes---
		shapes.append(our)
		shapes.append(inr)
		#Balls-------------------
		nb=(math.pi*cb)*0.8/(rb)
		nb=math.floor(nb)
		nb=int(nb)

		for i in range (nb):
			b=Part.makeSphere(rb)
			Alpha=(i*2*math.pi)/nb
			bv=(cb*math.cos(Alpha),cb*math.sin(Alpha),bth/2)
			b.translate(bv)
			shapes.append(b)
	else:
		body = Part.makeCylinder(rout,bth)
		hole = Part.makeCylinder(rin,bth)
		body = body.cut(hole)
		body = body.makeFillet(RR,body.Edges)
		shapes.append(body)

	part=document.addObject("Part::Feature",name)
	comp=Part.Compound(shapes)
	part.Shape=comp.removeSplitter()
Example #6
0
def axialthrustbearing(params, document):
	rin = 0.5*params['d']
	rout = 0.5*params['D']
	bth = params['T']
	name = params['name']
	fth=0.3*bth  #Thrust plate widh
	RR=0.015*rout
	#shapes--
	shapes=[]
	#Lower ring--------------------------
	lr1=Part.makeCylinder(rout,fth)
	lr2=Part.makeCylinder(rin,fth)
	lr=lr1.cut(lr2)
	lre=lr.Edges
	lr=lr.makeFillet(RR,lre)
	#Upper ring--------------------------
	ur1=Part.makeCylinder(rout,fth)
	ur2=Part.makeCylinder(rin,fth)
	ur=ur1.cut(ur2)
	ure=ur.Edges
	ur=ur.makeFillet(RR,ure)
	#Positioning Vector
	Vur=(0,0,bth-fth)
	ur.translate(Vur)
	#Balltracks---------------------------
	tbigradius=((rout-rin)/2.00)+rin
	tsmradius=(bth/2.00)-(0.75*fth)
	Vtorus=(0,0,bth/2.00)
	torus=Part.makeTorus(tbigradius,tsmradius)
	#Positioning vector
	torus.translate(Vtorus)
	#Booleans------------------------------
	lr=lr.cut(torus)
	shapes.append(ur)
	shapes.append(lr)
	#Balls--------------------------------
	RBall=tsmradius
	CBall=tbigradius
	#Ball number (constant multiplied by radius and rounded)
	NBall=(2*math.pi*CBall)/(2*RBall)
	NBall=math.floor(NBall)
	NBall=NBall*0.9
	NBall=int(NBall)
	#Ball creator
	for i in range (NBall): 
		Ball=Part.makeSphere(RBall)
		Alpha=(i*2*math.pi)/NBall 
		BV=(CBall*math.cos(Alpha),CBall*math.sin(Alpha),bth/2.00)
		Ball.translate(BV)
		shapes.append(Ball)

	part = document.addObject("Part::Feature",name)
	comp = Part.Compound(shapes)
	part.Shape = comp.removeSplitter()
Example #7
0
        def process(self):
            if not any(socket.is_linked for socket in self.outputs):
                return

            params = [s.sv_get()[0] for s in self.inputs]

            solids = []
            for rad, rad_small, origin, direc, angle in zip(*mlr(params)):
                solid = Part.makeTorus(rad, rad_small, Base.Vector(origin),
                                       Base.Vector(direc), 0, 360, angle)
                solids.append(solid)

            self.outputs['Solid'].sv_set(solids)
def ExtruderDriveGear():
	b = Part.makeCylinder(gearHubDia/2,gearLen)
	h = Part.makeCylinder(gearBore/2,gearLen)
	t=Part.makeTorus(gearDia/2+filamentDia/2,filamentDia/2)
	t.translate(Vector(0,0,gearCenter))
	b=b.cut(h.fuse(t))
	b.translate(Vector(0,0,-gearCenter))
	b.rotate(Vector(0,0,0),Vector(0,1,0),90)
	if positionOnMachine == 1:
		b.rotate(Vector(0,0,0),Vector(0,0,1),180)
		b.translate(Vector(ac.frameringxlen/2+ac.beamSize+ac.minthick+3,-ac.frameringylen/2+ac.tailadd/2-ac.beamSize/2+0.5,(ac.frameringczpos+ac.framezsupportszpos)/2+ac.minthick*3))
	if makeDual == 1:
		b2 = b.mirror(Vector(ac.frameringxlen/2+ac.beamSize/2,0,0),Vector(1,0,0))
		b2.rotate(Vector(ac.frameringxlen/2+ac.beamSize/2,-ac.frameringylen/2+ac.tailadd/2-ac.beamSize/2,0),Vector(0,0,1),90)
		b = b.fuse(b2)
	return b
def make_torus(segments, rings, width, thickness):
    """
    Function to make torus in FreeCAD
    :param segments: number of segments of the torus
    :param rings: number of segments of each segment
    :param width: with of the torus
    :param thickness: height / thickness of the torus
    :return: null, function will draw the torus in FreeCAD.
    """
    FreeCAD.newDocument()
    generated_torus_outside = torus(segments, rings, width, thickness)
    generated_torus_inside = torus(segments, rings, width, thickness*0.75)
    generated_torus = generated_torus_outside.cut(generated_torus_inside)
    sub_torus = Part.makeTorus(width/2, 1.1*thickness/2, FreeCAD.Vector(0, 0, 0), FreeCAD.Vector(0, 0, 1), 0, 360, 360*(rings-1)/rings)
    cross_section = generated_torus.cut(sub_torus)
    cross_section.translate(FreeCAD.Vector(1.25*(width+thickness), 0, 0))
    Part.show(generated_torus)
    Part.show(cross_section)

def setview():
    # Rearrange View
    FreeCAD.Gui.SendMsgToActiveView("ViewFit")
    FreeCAD.Gui.activeDocument().activeView().viewAxometric()


if DOC is None:
    FreeCAD.newDocument(DOC_NAME)
    FreeCAD.setActiveDocument(DOC_NAME)
    DOC = FreeCAD.activeDocument()
else:
    clear_doc()

# EPS= tolerance to use to cut the parts
EPS = 0.10
EPS_C = EPS * -0.5

torus = Part.makeTorus(19.05, 3.175)

Part.show(torus)

DOC.recompute()

step_file = "C:\\part_torus.stp"

Part.export([torus], step_file)

setview()
Example #11
0
def HCPB_detailed_module(blanket_parameters_dict):

      #loads in parameters
      envelope_directory_filename = blanket_parameters_dict['envelope_filename']
      output_folder = blanket_parameters_dict['output_folder']
      if 'output_files' in blanket_parameters_dict.keys():
        output_files = blanket_parameters_dict['output_files']
      else:
        output_files=['step','stl','h5m','merged_stl']
      output_folder_step = output_folder + '/step'
      output_folder_stl = output_folder + '/stl'
      output_folder_h5m = output_folder + '/h5m'
      output_folder_merged_stl = output_folder + '/merged_stl'
      armour_thickness = blanket_parameters_dict['armour_thickness']
      first_wall_thickness = blanket_parameters_dict['first_wall_thickness']
      end_cap_thickness = blanket_parameters_dict['end_cap_thickness']
      back_walls_thicknesses = blanket_parameters_dict['back_walls_thicknesses']

      if 'plasma_filename' in blanket_parameters_dict:
          plasma_filename = blanket_parameters_dict['plasma_filename']
          plasma = Part.read(plasma_filename)
      else:
          plasma = Part.makeTorus(9100, 2900)

      envelope = read_in_envelope_file(envelope_directory_filename)

      envelope_back_face = find_envelope_back_face(envelope, plasma)

      envelope_front_face = find_envelope_front_face(envelope, envelope_back_face)

      front_face_midpoint = find_front_face_midpoint(envelope_front_face)

      original_envelope_front_face_id = envelope_front_face_id(envelope,envelope_back_face)

      envelope_back_face_id = find_envelope_back_face_id(envelope, plasma)

      front_face_polodial_edges_to_fillet = find_front_face_polodial_edges_to_fillet(envelope_front_face.Edges)

      front_face_torodial_edges_to_fillet = find_front_face_torodial_edges_to_fillet(envelope_front_face.Edges)

      first_wall_poloidal_fillet_radius = blanket_parameters_dict['first_wall_poloidal_fillet_radius']

      filleted_envelope_solid = filleted_envelope(fillet_radius=first_wall_poloidal_fillet_radius,
                                                 edges=front_face_polodial_edges_to_fillet,
                                                 envelope=envelope)

      filleted_envelope_back_face = find_envelope_back_face(filleted_envelope_solid, plasma)

      filleted_envelope_front_face = find_envelope_front_face(filleted_envelope_solid,filleted_envelope_back_face)

      filleted_envelope_front_face_id = envelope_front_face_id(wedge=filleted_envelope_solid,
                                                                    envelope_back_face=filleted_envelope_back_face)

      end_cap_faces = find_end_cap_faces(faces_under_consideration=filleted_envelope_solid.Faces)

      first_wall_armour, envelope_removed_armour = chop_off_first_wall_armour(armour_thickness=armour_thickness,
                                                                                        faces_not_in_first_wall=[filleted_envelope_back_face] +end_cap_faces,
                                                                                        filleted_envelope=filleted_envelope_solid,
                                                                                        front_face=envelope_front_face)

      dictionary_of_parts = collections.defaultdict(dict)

      dictionary_of_parts['armour']['part'] = [first_wall_armour]

      envelope_removed_armour_end_cap_faces = find_end_cap_faces(faces_under_consideration=envelope_removed_armour.Faces)

      armour_removed_envelope_back_face = find_envelope_back_face(envelope_removed_armour, plasma)

      armour_removed_envelope_front_face = find_envelope_front_face(envelope_removed_armour,
                                                                         armour_removed_envelope_back_face)


      first_wall, first_wall_removed_envelope = chop_off_first_wall(faces_not_in_first_wall=[armour_removed_envelope_back_face] + envelope_removed_armour_end_cap_faces,
                                                                              thickness=first_wall_thickness,
                                                                              filleted_envelope= envelope_removed_armour)


      dictionary_of_parts['first_wall_homogenised']['part'] = [first_wall]

      first_wall_removed_envelope_back_face = find_envelope_back_face(first_wall_removed_envelope, plasma)

      first_wall_removed_envelope_front_face = find_envelope_front_face(first_wall_removed_envelope,first_wall_removed_envelope_back_face)

      first_wall_removed_envelope_midpoint = find_front_face_midpoint(first_wall_removed_envelope_front_face)

      if 'cooling_channel_offset_from_first_wall' in blanket_parameters_dict and 'first_wall_channel_radial_mm' in blanket_parameters_dict and 'first_wall_channel_poloidal_segmentations' in blanket_parameters_dict:

          cooling_channel_offset_from_first_wall = blanket_parameters_dict['cooling_channel_offset_from_first_wall']

          first_wall_channel_radial_mm = blanket_parameters_dict['first_wall_channel_radial_mm']

          first_wall_front_layer, first_wall_removed_envelope_temp1 = chop_off_first_wall(faces_not_in_first_wall=[armour_removed_envelope_back_face] + envelope_removed_armour_end_cap_faces,
                                                                                                    thickness=cooling_channel_offset_from_first_wall,
                                                                                                    filleted_envelope=envelope_removed_armour)

          first_wall_back_layer, first_wall_removed_envelope_temp2 = chop_off_first_wall(faces_not_in_first_wall=[armour_removed_envelope_back_face] + envelope_removed_armour_end_cap_faces,
                                                                                                   thickness=first_wall_channel_radial_mm + cooling_channel_offset_from_first_wall,
                                                                                                   filleted_envelope=envelope_removed_armour)

          first_wall_middle_layer = first_wall.common(first_wall_back_layer).cut(first_wall_front_layer)

          first_wall_back_layer = first_wall.cut(first_wall_back_layer)

          dictionary_of_parts['first_wall_material']['part'] = [first_wall_front_layer, first_wall_back_layer]

          first_wall_poloidally_segmented = chop_up_poloidally(midpoint=first_wall_removed_envelope_midpoint,
                                                                    poloidal_segmentations=blanket_parameters_dict['first_wall_channel_poloidal_segmentations'],
                                                                    envelope=first_wall_middle_layer,
                                                                    method='first_wall',
                                                                    top_bottom_edges=front_face_torodial_edges_to_fillet,
                                                                    front_face=envelope_front_face)

          for i, key in enumerate(blanket_parameters_dict['first_wall_channel_poloidal_segmentations']):
              dictionary_of_parts[key]['part'] = first_wall_poloidally_segmented[i]

          dictionary_of_parts['first_wall_material']['part'] = dictionary_of_parts['first_wall_material']['part'] \
                                                                    + [first_wall_front_layer, first_wall_back_layer]

      end_caps, envelope_removed_endcaps = chop_of_end_caps(end_cap_faces,end_cap_thickness,first_wall_removed_envelope)

      dictionary_of_parts['end_caps_homogenised']['part'] = end_caps

      back_face_envelope_removed_caps = find_envelope_back_face(envelope_removed_endcaps, plasma)

      back_walls, envelope_removed_back_wall = chop_off_back_walls(back_face=back_face_envelope_removed_caps,
                                                                             remaining_shapes=envelope_removed_endcaps,
                                                                             back_walls_thicknesses=back_walls_thicknesses)


      for i, key in enumerate(blanket_parameters_dict['back_walls_thicknesses']):
          dictionary_of_parts[key]['part'] = [back_walls[i]]

      poloidal_segmentations = blanket_parameters_dict['poloidal_segmentations']

      envelope_poloidally_segmented = chop_up_poloidally(midpoint=first_wall_removed_envelope_midpoint,
                                                              poloidal_segmentations=poloidal_segmentations,
                                                              envelope=envelope_removed_back_wall,
                                                              method='HCPB',top_bottom_edges=front_face_torodial_edges_to_fillet,
                                                              front_face=envelope_front_face)

      neutron_multiplier = envelope_poloidally_segmented[0]

      cooling_plate = envelope_poloidally_segmented[1] + envelope_poloidally_segmented[3]

      breeder_material = envelope_poloidally_segmented[2]

      for i, key in enumerate(blanket_parameters_dict['poloidal_segmentations']):
          dictionary_of_parts[key]['part'] = envelope_poloidally_segmented[i]

      cylinder_slice = make_cylinder_slice(10)

      prefix='_' + os.path.splitext(os.path.split(envelope_directory_filename)[-1])[0]

      dictionary_of_parts= save_components_as_step(dictionary_of_parts = dictionary_of_parts, output_folder = output_folder_step, filename_prefix =prefix)



      if 'step' in output_files:
          save_components_as_step(dictionary_of_parts = dictionary_of_parts, output_folder = output_folder_step, filename_prefix =prefix)

      if 'merged_stl' in output_files:
          save_components_as_merged_stl_file(dictionary_of_parts=dictionary_of_parts,
                                         output_folder=output_folder_merged_stl,
                                         blanket_type=blanket_parameters_dict['blanket_type'])

      if 'stl' in output_files:
          save_components_as_stl(dictionary_of_parts = dictionary_of_parts, output_folder = output_folder_stl)

      if 'h5m' in output_files:
          save_components_as_h5m_file(dictionary_of_parts = dictionary_of_parts, output_folder = output_folder_h5m, blanket_type=blanket_parameters_dict['blanket_type'])


      return dictionary_of_parts
Example #12
0
def HCLL_detailed_module(blanket_parameters_dict):

    dictionary_of_parts = collections.defaultdict(dict)

    envelope_directory_filename = blanket_parameters_dict['envelope_filename']
    output_folder = blanket_parameters_dict['output_folder']
    if 'output_files' in blanket_parameters_dict.keys():
        output_files = blanket_parameters_dict['output_files']
    else:
        output_files = ['step', 'stl', 'h5m', 'merged_stl']
    output_folder_step = output_folder + '/step'
    output_folder_stl = output_folder + '/stl'
    output_folder_h5m = output_folder + '/h5m'
    output_folder_merged_stl = output_folder + '/merged_stl'
    armour_thickness = blanket_parameters_dict['armour_thickness']
    first_wall_thickness = blanket_parameters_dict['first_wall_thickness']
    end_cap_thickness = blanket_parameters_dict['end_cap_thickness']
    back_plates_thicknesses = blanket_parameters_dict[
        'back_plates_thicknesses']

    if 'plasma_filename' in blanket_parameters_dict:
        plasma_filename = blanket_parameters_dict['plasma_filename']
        plasma = Part.read(plasma_filename)
    else:
        plasma = Part.makeTorus(9100, 2900)

    envelope = read_in_envelope_file(envelope_directory_filename)

    envelope_back_face = find_envelope_back_face(envelope, plasma)

    envelope_front_face = find_envelope_front_face(envelope,
                                                   envelope_back_face)

    front_face_midpoint = find_front_face_midpoint(envelope_front_face)

    original_envelope_front_face_id = envelope_front_face_id(
        envelope, envelope_back_face)

    envelope_back_face_id = find_envelope_back_face_id(envelope, plasma)

    front_face_polodial_edges_to_fillet = find_front_face_polodial_edges_to_fillet(
        envelope_front_face.Edges)

    front_face_torodial_edges_to_fillet = find_front_face_torodial_edges_to_fillet(
        envelope_front_face.Edges)

    first_wall_poloidal_fillet_radius = blanket_parameters_dict[
        'first_wall_poloidal_fillet_radius']

    filleted_envelope_solid = filleted_envelope(
        fillet_radius=first_wall_poloidal_fillet_radius,
        edges=front_face_polodial_edges_to_fillet,
        envelope=envelope)

    filleted_envelope_back_face = find_envelope_back_face(
        filleted_envelope_solid, plasma)

    filleted_envelope_front_face = find_envelope_front_face(
        filleted_envelope_solid, filleted_envelope_back_face)

    filleted_envelope_front_face_id = envelope_front_face_id(
        wedge=filleted_envelope_solid,
        envelope_back_face=filleted_envelope_back_face)

    end_cap_faces = find_end_cap_faces(
        faces_under_consideration=filleted_envelope_solid.Faces)

    first_wall_armour, envelope_removed_armour = chop_off_first_wall_armour(
        armour_thickness=armour_thickness,
        faces_not_in_first_wall=[filleted_envelope_back_face] + end_cap_faces,
        filleted_envelope=filleted_envelope_solid,
        front_face=envelope_front_face)
    dictionary_of_parts['armour']['part'] = [first_wall_armour]

    armour_removed_envelope_back_face = find_envelope_back_face(
        envelope_removed_armour, plasma)

    armour_removed_envelope_front_face = find_envelope_front_face(
        envelope_removed_armour, armour_removed_envelope_back_face)

    envelope_removed_armour_end_cap_faces = find_end_cap_faces(
        faces_under_consideration=envelope_removed_armour.Faces)

    armour_removed_envelope_back_face = find_envelope_back_face(
        envelope_removed_armour, plasma)

    armour_removed_envelope_front_face = find_envelope_front_face(
        envelope_removed_armour, armour_removed_envelope_back_face)

    first_wall, first_wall_removed_envelope = chop_off_first_wall(
        faces_not_in_first_wall=[armour_removed_envelope_back_face] +
        envelope_removed_armour_end_cap_faces,
        thickness=first_wall_thickness,
        filleted_envelope=envelope_removed_armour)

    dictionary_of_parts['first_wall_homogenised']['part'] = [first_wall]

    first_wall_removed_envelope_back_face = find_envelope_back_face(
        first_wall_removed_envelope, plasma)

    first_wall_removed_envelope_front_face = find_envelope_front_face(
        first_wall_removed_envelope, first_wall_removed_envelope_back_face)

    first_wall_removed_envelope_midpoint = find_front_face_midpoint(
        first_wall_removed_envelope_front_face)

    if 'cooling_channel_offset_from_first_wall' in blanket_parameters_dict and 'first_wall_channel_radial_mm' in blanket_parameters_dict and 'first_wall_channel_poloidal_segmentations' in blanket_parameters_dict:

        cooling_channel_offset_from_first_wall = blanket_parameters_dict[
            'cooling_channel_offset_from_first_wall']

        first_wall_channel_radial_mm = blanket_parameters_dict[
            'first_wall_channel_radial_mm']

        # first_wall_front_layer, first_wall_removed_envelope_temp1 = chop_off_first_wall(faces_not_in_first_wall=[filleted_envelope_back_face] + end_cap_faces,
        #                                                                                     thickness=cooling_channel_offset_from_first_wall,
        #                                                                                     filleted_envelope=filleted_envelope)

        first_wall_front_layer, first_wall_removed_envelope_temp1 = chop_off_first_wall(
            faces_not_in_first_wall=[armour_removed_envelope_back_face] +
            envelope_removed_armour_end_cap_faces,
            thickness=cooling_channel_offset_from_first_wall,
            filleted_envelope=envelope_removed_armour)

        first_wall_back_layer, first_wall_removed_envelope_temp2 = chop_off_first_wall(
            faces_not_in_first_wall=[armour_removed_envelope_back_face] +
            envelope_removed_armour_end_cap_faces,
            thickness=first_wall_channel_radial_mm +
            cooling_channel_offset_from_first_wall,
            filleted_envelope=envelope_removed_armour)

        first_wall_middle_layer = first_wall.common(first_wall_back_layer).cut(
            first_wall_front_layer)

        first_wall_back_layer = first_wall.cut(first_wall_back_layer)

        #dictionary_of_parts['first_wall_material']['part'] = [first_wall_front_layer, first_wall_back_layer]

        first_wall_poloidally_segmented = chop_up_poloidally(
            midpoint=first_wall_removed_envelope_midpoint,
            poloidal_segmentations=blanket_parameters_dict[
                'first_wall_channel_poloidal_segmentations'],
            envelope=first_wall_middle_layer,
            method='first_wall',
            top_bottom_edges=front_face_torodial_edges_to_fillet,
            front_face=envelope_front_face)

        #for i, key in enumerate(blanket_parameters_dict['first_wall_channel_poloidal_segmentations']):
        #    dictionary_of_parts[key]['part'] = first_wall_poloidally_segmented[i]

        dictionary_of_parts['first_wall_material'][
            'part'] = first_wall_poloidally_segmented[0]
        dictionary_of_parts['first_wall_coolant'][
            'part'] = first_wall_poloidally_segmented[1]

        dictionary_of_parts['first_wall_material'][
            'part'] = dictionary_of_parts['first_wall_material']['part'] + [
                first_wall_front_layer, first_wall_back_layer
            ]

    end_caps, envelope_removed_endcaps = chop_of_end_caps(
        end_cap_faces, end_cap_thickness, first_wall_removed_envelope)

    dictionary_of_parts['end_caps_homogenised']['part'] = end_caps

    back_face_envelope_removed_caps = find_envelope_back_face(
        envelope_removed_endcaps, plasma)

    back_plates, envelope_removed_back_plate = chop_off_back_plates(
        back_face=back_face_envelope_removed_caps,
        remaining_shapes=envelope_removed_endcaps,
        back_plates_thicknesses=back_plates_thicknesses)

    for i, key in enumerate(
            blanket_parameters_dict['back_plates_thicknesses']):
        dictionary_of_parts[key]['part'] = [back_plates[i]]

    poloidal_segmentations = blanket_parameters_dict['poloidal_segmentations']

    envelope_poloidally_segmented = chop_up_poloidally(
        midpoint=first_wall_removed_envelope_midpoint,
        poloidal_segmentations=poloidal_segmentations,
        envelope=envelope_removed_back_plate,
        method='HCLL',
        top_bottom_edges=front_face_torodial_edges_to_fillet,
        front_face=envelope_front_face)

    lithium_lead = envelope_poloidally_segmented[0]

    cooling_plate = envelope_poloidally_segmented[1]

    for i, key in enumerate(blanket_parameters_dict['poloidal_segmentations']):
        if dictionary_of_parts[key]:
            dictionary_of_parts[key]['part'] = dictionary_of_parts[key][
                'part'] + envelope_poloidally_segmented[i]
        else:
            dictionary_of_parts[key]['part'] = envelope_poloidally_segmented[i]

    if 'cooling_plates_channel_poloidal_mm' in blanket_parameters_dict and 'cooling_channel_offset_from_first_wall' in blanket_parameters_dict and 'first_wall_channel_radial_mm' in blanket_parameters_dict and 'first_wall_channel_poloidal_segmentations' in blanket_parameters_dict:
        #if 'slice' in blanket_parameters_dict:

        slice = chop_up_poloidally(
            midpoint=first_wall_removed_envelope_midpoint,
            poloidal_segmentations=poloidal_segmentations,
            envelope=envelope,
            method='HCLL_slice',
            top_bottom_edges=front_face_torodial_edges_to_fillet,
            front_face=envelope_front_face)

        dictionary_of_parts['slice_envelope']['part'] = slice

        dictionary_of_parts['slice_lithium_lead']['part'], dictionary_of_parts[
            'lithium_lead']['part'] = common_and_uncommon_solids_with_envelope(
                dictionary_of_parts['lithium_lead']['part'], slice)

        dictionary_of_parts['slice_armour']['part'], dictionary_of_parts[
            'armour']['part'] = common_and_uncommon_solids_with_envelope(
                dictionary_of_parts['armour']['part'], slice)
        dictionary_of_parts['slice_first_wall_homogenised'][
            'part'], dictionary_of_parts['first_wall_homogenised'][
                'part'] = common_and_uncommon_solids_with_envelope(
                    dictionary_of_parts['first_wall_homogenised']['part'],
                    slice)
        dictionary_of_parts['slice_first_wall_material'][
            'part'], dictionary_of_parts['first_wall_material'][
                'part'] = common_and_uncommon_solids_with_envelope(
                    dictionary_of_parts['first_wall_material']['part'], slice)
        dictionary_of_parts['slice_first_wall_coolant'][
            'part'], dictionary_of_parts['first_wall_coolant'][
                'part'] = common_and_uncommon_solids_with_envelope(
                    dictionary_of_parts['first_wall_coolant']['part'], slice)

        for i, key in enumerate(
                blanket_parameters_dict['back_plates_thicknesses']):
            dictionary_of_parts['slice_' + key]['part'], dictionary_of_parts[
                key]['part'] = common_and_uncommon_solids_with_envelope(
                    dictionary_of_parts[key]['part'], slice)
        #for i, key in enumerate(blanket_parameters_dict['poloidal_segmentations']):
        #  dictionary_of_parts['slice_'+key]['part'],dictionary_of_parts[key]['part'] = common_and_uncommon_solids_with_envelope(dictionary_of_parts[key]['part'],slice)

        slice_cooling_plate_homogenised, dictionary_of_parts[
            'cooling_plate_homogenised'][
                'part'] = common_and_uncommon_solids_with_envelope(
                    cooling_plate, slice)

        #Part.makeCompound(cooling_plate_in_slice).exportStep('cooling_plate_in_slice.step')

        list_of_cooling_pipes, list_of_structure = add_cooling_pipes_to_div(
            div_to_cool=slice_cooling_plate_homogenised[0],
            channel_poloidal_height=blanket_parameters_dict[
                'cooling_plates_channel_poloidal_mm'],
            channel_radial_height=blanket_parameters_dict[
                'cooling_plates_channel_radial_mm'],
            plate_poloidal_height=blanket_parameters_dict[
                'poloidal_segmentations']['cooling_plate_homogenised'],
            plasma=plasma)

        #dictionary_of_parts['slice']['part'] = slice

        dictionary_of_parts['slice_cooling_plate_coolant'][
            'part'] = list_of_cooling_pipes
        dictionary_of_parts['slice_cooling_plate_material'][
            'part'] = list_of_structure

    prefix = '_' + os.path.splitext(
        os.path.split(envelope_directory_filename)[-1])[0]

    if 'step' in output_files:
        dictionary_of_parts = save_components_as_step(
            dictionary_of_parts=dictionary_of_parts,
            output_folder=output_folder_step,
            filename_prefix=prefix)

    if 'merged_stl' in output_files:
        dictionary_of_parts = save_components_as_merged_stl_file(
            dictionary_of_parts=dictionary_of_parts,
            output_folder=output_folder_merged_stl,
            blanket_type=blanket_parameters_dict['blanket_type'])

    if 'stl' in output_files:
        dictionary_of_parts = save_components_as_stl(
            dictionary_of_parts=dictionary_of_parts,
            output_folder=output_folder_stl)

    if 'h5m' in output_files:
        dictionary_of_parts = save_components_as_h5m_file(
            dictionary_of_parts=dictionary_of_parts,
            output_folder=output_folder_h5m,
            blanket_type=blanket_parameters_dict['blanket_type'])

    if 'umesh' in output_files:
        dictionary_of_parts = save_components_as_umesh(
            dictionary_of_parts=dictionary_of_parts,
            output_folder=output_folder,
            output_folder_step=output_folder_step,
            mesh_component_prefix='slice_')

    return dictionary_of_parts  #.update({'logtime_data':logtime_data})
Example #13
0
def torus(a, b):
    bx = Part.makeTorus(a, b)
    return (center_object(bx))
def DCLL_detailed_module(blanket_parameters_dict):

    #loads in parameters
    envelope_directory_filename = blanket_parameters_dict['envelope_filename']
    output_folder = blanket_parameters_dict['output_folder']
    if 'output_files' in blanket_parameters_dict.keys():
        output_files = blanket_parameters_dict['output_files']
    else:
        output_files = ['step', 'stl', 'h5m', 'merged_stl']
    output_folder_step = output_folder + '/step'
    output_folder_stl = output_folder + '/stl'
    output_folder_h5m = output_folder + '/h5m'
    output_folder_merged_stl = output_folder + '/merged_stl'
    armour_thickness = blanket_parameters_dict['armour_thickness']
    first_wall_thickness = blanket_parameters_dict['first_wall_thickness']
    end_cap_thickness = blanket_parameters_dict['end_cap_thickness']
    back_walls_thicknesses = blanket_parameters_dict['back_walls_thicknesses']

    if 'plasma_filename' in blanket_parameters_dict:
        plasma_filename = blanket_parameters_dict['plasma_filename']
        plasma = Part.read(plasma_filename)
    else:
        plasma = Part.makeTorus(9100, 2900)

    envelope = read_in_envelope_file(envelope_directory_filename)

    envelope_back_face = find_envelope_back_face(envelope, plasma)

    envelope_front_face = find_envelope_front_face(envelope,
                                                   envelope_back_face)

    front_face_midpoint = find_front_face_midpoint(envelope_front_face)

    original_envelope_front_face_id = envelope_front_face_id(
        envelope, envelope_back_face)

    envelope_back_face_id = find_envelope_back_face_id(envelope, plasma)

    front_face_polodial_edges_to_fillet = find_front_face_polodial_edges_to_fillet(
        envelope_front_face.Edges)

    front_face_torodial_edges_to_fillet = find_front_face_torodial_edges_to_fillet(
        envelope_front_face.Edges)

    first_wall_toroidal_fillet_radius = blanket_parameters_dict[
        'first_wall_toroidal_fillet_radius']
    filleted_envelope_solid = filleted_envelope(
        fillet_radius=first_wall_toroidal_fillet_radius,
        edges=front_face_torodial_edges_to_fillet,
        envelope=envelope)

    filleted_envelope_back_face = find_envelope_back_face(
        filleted_envelope_solid, plasma)

    filleted_envelope_front_face = find_envelope_front_face(
        filleted_envelope_solid, filleted_envelope_back_face)

    filleted_envelope_front_face_id = envelope_front_face_id(
        wedge=filleted_envelope_solid,
        envelope_back_face=filleted_envelope_back_face)

    end_cap_faces = find_end_cap_faces(
        faces_under_consideration=filleted_envelope_solid.Faces)

    first_wall_armour, envelope_removed_armour = chop_off_first_wall_armour(
        armour_thickness=armour_thickness,
        faces_not_in_first_wall=[filleted_envelope_back_face] + end_cap_faces,
        filleted_envelope=filleted_envelope_solid,
        front_face=envelope_front_face)

    dictionary_of_parts = collections.defaultdict(dict)

    dictionary_of_parts['armour']['part'] = [first_wall_armour]

    envelope_removed_armour_end_cap_faces = find_end_cap_faces(
        faces_under_consideration=envelope_removed_armour.Faces)

    armour_removed_envelope_back_face = find_envelope_back_face(
        envelope_removed_armour, plasma)

    armour_removed_envelope_front_face = find_envelope_front_face(
        envelope_removed_armour, armour_removed_envelope_back_face)

    first_wall, first_wall_removed_envelope = chop_off_first_wall(
        faces_not_in_first_wall=[armour_removed_envelope_back_face] +
        envelope_removed_armour_end_cap_faces,
        thickness=first_wall_thickness,
        filleted_envelope=envelope_removed_armour)

    dictionary_of_parts['first_wall_homogenised']['part'] = [first_wall]

    first_wall_removed_envelope_back_face = find_envelope_back_face(
        first_wall_removed_envelope, plasma)

    first_wall_removed_envelope_front_face = find_envelope_front_face(
        first_wall_removed_envelope, first_wall_removed_envelope_back_face)

    first_wall_removed_envelope_midpoint = find_front_face_midpoint(
        first_wall_removed_envelope_front_face)

    if 'cooling_channel_offset_from_first_wall' in blanket_parameters_dict and 'first_wall_channel_radial_mm' in blanket_parameters_dict and 'first_wall_channel_toroidal_segmentations' in blanket_parameters_dict:

        cooling_channel_offset_from_first_wall = blanket_parameters_dict[
            'cooling_channel_offset_from_first_wall']

        first_wall_channel_radial_mm = blanket_parameters_dict[
            'first_wall_channel_radial_mm']

        first_wall_front_layer, first_wall_removed_envelope_temp1 = chop_off_first_wall(
            faces_not_in_first_wall=[armour_removed_envelope_back_face] +
            envelope_removed_armour_end_cap_faces,
            thickness=cooling_channel_offset_from_first_wall,
            filleted_envelope=envelope_removed_armour)

        first_wall_back_layer, first_wall_removed_envelope_temp2 = chop_off_first_wall(
            faces_not_in_first_wall=[armour_removed_envelope_back_face] +
            envelope_removed_armour_end_cap_faces,
            thickness=first_wall_channel_radial_mm +
            cooling_channel_offset_from_first_wall,
            filleted_envelope=envelope_removed_armour)

        first_wall_middle_layer = first_wall.common(first_wall_back_layer).cut(
            first_wall_front_layer)

        first_wall_back_layer = first_wall.cut(first_wall_back_layer)

        dictionary_of_parts['first_wall_material']['part'] = [
            first_wall_front_layer, first_wall_back_layer
        ]

        first_wall_toroidally_segmented = chop_up_toroidally(
            toroidal_segmentations=blanket_parameters_dict[
                'first_wall_channel_toroidal_segmentations'],
            envelope=first_wall_middle_layer,
            front_face=first_wall_removed_envelope_front_face,
            front_face_torodial_edges_to_fillet=
            front_face_torodial_edges_to_fillet)

        for i, key in enumerate(blanket_parameters_dict[
                'first_wall_channel_toroidal_segmentations']):
            dictionary_of_parts[key]['part'] = first_wall_toroidally_segmented[
                i]

        dictionary_of_parts['first_wall_material'][
            'part'] = dictionary_of_parts['first_wall_material']['part'] + [
                first_wall_front_layer, first_wall_back_layer
            ]

    end_caps, envelope_removed_endcaps = chop_of_end_caps(
        end_cap_faces, end_cap_thickness, first_wall_removed_envelope)

    dictionary_of_parts['end_caps_homogenised']['part'] = end_caps

    back_face_envelope_removed_caps = find_envelope_back_face(
        envelope_removed_endcaps, plasma)

    back_walls, envelope_removed_back_wall = chop_off_back_walls(
        back_face=back_face_envelope_removed_caps,
        remaining_shapes=envelope_removed_endcaps,
        back_walls_thicknesses=back_walls_thicknesses)

    for i, key in enumerate(blanket_parameters_dict['back_walls_thicknesses']):
        dictionary_of_parts[key]['part'] = [back_walls[i]]

    toroidal_segmentations = blanket_parameters_dict['toroidal_segmentations']

    envelope_toroidally_segmented = chop_up_toroidally(
        toroidal_segmentations=blanket_parameters_dict[
            'toroidal_segmentations'],
        envelope=envelope_removed_back_wall,
        front_face=first_wall_removed_envelope_front_face,
        front_face_torodial_edges_to_fillet=front_face_torodial_edges_to_fillet
    )

    back_walls_removed_envelope_back_face = find_envelope_back_face(
        envelope_removed_back_wall, plasma)

    back_walls_removed_envelope_front_face = find_envelope_front_face(
        envelope_removed_back_wall, back_walls_removed_envelope_back_face)

    back_wall_removed_envelope_radial_depth = back_walls_removed_envelope_back_face.distToShape(
        back_walls_removed_envelope_front_face)[0]

    radial_segmentations = blanket_parameters_dict['radial_segmentations']

    envelope_radially_segmented = chop_up_envelope_zone_radially_with_adjustable_rear_division(
        front_face=first_wall_removed_envelope_front_face,
        radial_segmentations=radial_segmentations,
        envelope=envelope_removed_back_wall,
        envelope_radial_depth=back_wall_removed_envelope_radial_depth,
        thinnest_two_layer_blanket=1500)

    top_and_bottom_faces_of_original_envelope = find_poloidal_upper_and_lower_faces(
        front_face=envelope_front_face,
        back_face=envelope_back_face,
        envelope=envelope,
        envelope_front_face_id=original_envelope_front_face_id,
        envelope_back_face_id=envelope_back_face_id)

    poloidal_upper_offset_for_breeder_channel = blanket_parameters_dict[
        'poloidal_upper_offset_for_breeder_channel']

    poloidal_lower_offset_for_breeder_channel = blanket_parameters_dict[
        'poloidal_lower_offset_for_breeder_channel']

    breeder_zone_lithium_cutter_upper = exstrude_and_cut_solids(
        list_of_distances=[
            armour_thickness + first_wall_thickness +
            poloidal_upper_offset_for_breeder_channel
        ],
        face=top_and_bottom_faces_of_original_envelope[0],
        envelope=envelope_removed_back_wall)

    poloidal_lower_offset_for_breeder_channel = blanket_parameters_dict[
        'poloidal_lower_offset_for_breeder_channel']

    breeder_zone_lithium_cutter_lower = exstrude_and_cut_solids(
        list_of_distances=[
            armour_thickness + first_wall_thickness +
            poloidal_lower_offset_for_breeder_channel
        ],
        face=top_and_bottom_faces_of_original_envelope[1],
        envelope=envelope_removed_back_wall)

    poloidal_upper_offset_for_plate = blanket_parameters_dict[
        'radial_segmentations'][1]

    upper_plate = exstrude_and_cut_solids(
        list_of_distances=[
            armour_thickness + first_wall_thickness +
            poloidal_upper_offset_for_plate +
            poloidal_upper_offset_for_breeder_channel
        ],
        face=top_and_bottom_faces_of_original_envelope[0],
        envelope=envelope_removed_back_wall)[0]

    upper_plate = upper_plate.cut(breeder_zone_lithium_cutter_upper)

    upper_plate = upper_plate.cut(envelope_radially_segmented[0][0])

    additional_lithium_lead_upper, reduced_solids_upper = find_common_bodies(
        breeder_zone_lithium_cutter_upper, envelope_radially_segmented[1])

    additional_lithium_lead_lower, reduced_solids_lower = find_common_bodies(
        breeder_zone_lithium_cutter_lower, envelope_radially_segmented[1])

    envelope_radially_segmented[0] = envelope_radially_segmented[
        0] + additional_lithium_lead_upper + additional_lithium_lead_lower

    lithium_lead = []
    for radial_ll in envelope_radially_segmented[0]:
        for toroidally_ll in envelope_toroidally_segmented[0]:
            lithium_lead.append(
                (radial_ll.common(toroidally_ll)).cut(upper_plate))

    structural_plate = []
    for radial_plate in envelope_radially_segmented[1]:
        #print('vol=',radial_plate.Volume)
        for chopper in additional_lithium_lead_upper:
            radial_plate = radial_plate.cut(chopper)
            #print('    vol=', radial_plate.Volume)
        for chopper in additional_lithium_lead_lower:
            radial_plate = radial_plate.cut(chopper)
            #print('    vol=', radial_plate.Volume)
        radial_plate = radial_plate.cut(upper_plate)
        #print('')
        for toroidal_plate in envelope_toroidally_segmented[1]:
            upper_plate = upper_plate.cut(toroidal_plate)
            radial_plate = radial_plate.cut(toroidal_plate)

        structural_plate.append(radial_plate)
    structural_plate = structural_plate + envelope_toroidally_segmented[
        1] + upper_plate.Solids

    available_breezer_zone_materials = [lithium_lead, structural_plate]
    for i, key in enumerate(blanket_parameters_dict['toroidal_segmentations']):

        dictionary_of_parts[key]['part'] = available_breezer_zone_materials[i]

    cylinder_slice = make_cylinder_slice(10)

    prefix = '_' + os.path.splitext(
        os.path.split(envelope_directory_filename)[-1])[0]

    if 'step' in output_files:
        save_components_as_step(dictionary_of_parts=dictionary_of_parts,
                                output_folder=output_folder_step,
                                filename_prefix=prefix)

    if 'merged_stl' in output_files:
        save_components_as_merged_stl_file(
            dictionary_of_parts=dictionary_of_parts,
            output_folder=output_folder_merged_stl,
            blanket_type=blanket_parameters_dict['blanket_type'])

    if 'stl' in output_files:
        save_components_as_stl(dictionary_of_parts=dictionary_of_parts,
                               output_folder=output_folder_stl)

    if 'h5m' in output_files:
        save_components_as_h5m_file(
            dictionary_of_parts=dictionary_of_parts,
            output_folder=output_folder_h5m,
            blanket_type=blanket_parameters_dict['blanket_type'])

    return dictionary_of_parts
Example #15
0
def buildObject(el, queue, refList, app):
    #expand and extract elements needed for object construction
    name, pos, b, objtype, tr = el
    queue.remove(el)

    #build the placement from the vector and quaternion stored in the xml file
    base = FreeCAD.Vector(float(pos['x']), float(pos['y']), float(pos['z']))
    quat = [
        float(pos['q0']),
        float(pos['q1']),
        float(pos['q2']),
        float(pos['q3'])
    ]
    q0, q1, q2, q3 = quat
    angle = 2 * math.acos(q3)
    axis = FreeCAD.Vector(q0, q1, q2)
    place = FreeCAD.Placement(base, axis, angle)

    isCreated = False
    defpnt = FreeCAD.Vector()
    defdir = FreeCAD.Vector(0, 0, 1)
    defplace = FreeCAD.Placement()
    #handler to determine which object constructor to call
    if objtype == 'box':
        isCreated = True
        part = Part.makeBox(float(b['length']), float(b['width']),
                            float(b['height']))
        obj = app.ActiveDocument.addObject('Part::Box', name)
        obj.Shape = part
    elif objtype == 'cylinder':
        isCreated = True
        part = Part.makeCylinder(float(b['radius']), float(b['height']))
        obj = app.ActiveDocument.addObject('Part::Cylinder', name)
        obj.Shape = part
    elif objtype == 'cone':
        isCreated = True
        part = Part.makeCone(float(b['radius1']), float(b['radius2']),
                             float(b['height']))
        obj = app.ActiveDocument.addObject('Part::Cone', name)
        obj.Shape = part
    elif objtype == 'sphere':
        isCreated = True
        part = Part.makeSphere(float(b['radius']), defpnt, defdir,
                               float(b['angle1']), float(b['angle2']),
                               float(b['angle3']))
        obj = app.ActiveDocument.addObject('Part::Sphere', name)
        obj.Shape = part
    elif objtype == 'torus':
        isCreated = True
        print el
        part = Part.makeTorus(float(b['radius1']), float(b['radius2']), defpnt,
                              defdir, float(b['angle1']), float(b['angle2']),
                              float(b['angle3']))
        obj = app.ActiveDocument.addObject('Part::Torus', name)
        obj.Shape = part
    elif objtype == 'line':
        isCreated = False
        obj = app.ActiveDocument.addObject('Part::Part2DObjectPython', name)
        secpnt = FreeCAD.Vector(float(b['length']), 0, 0)
        Draft.Wire(obj)
        obj.Points = [defpnt, secpnt]
        obj.Closed = False
        obj.Support = None
    elif objtype == 'circle':
        isCreated = True
        obj = app.ActiveDocument.addObject('Part::Part2DObjectPython', name)
        Circle(obj)
        obj.Radius = float(b['radius'])
        startangle = float(b['angle1'])
        endangle = float(b['angle2'])
        if (startangle != None) and (endangle != None):
            obj.FirstAngle = startangle
            obj.LastAngle = endangle
    elif objtype == 'cut':
        isCreated = True
        obj = addObject('Part::MultiCut', name)
        obj.Shapes = [refList[b['base']], refList[b['tool']]]
    elif objtype == 'fusion':
        isCreated = True
        obj = addObject('Part::MultiFuse', name)
        obj.Shapes = [refList[b['base']], refList[b['tool']]]
        #refList[att['base']].Visibility = False
        #refList[att['tool']].Visibility = False
    elif objtype == 'common':
        isCreated = True
        obj = addObject('Part::MultiCommon', name)
        obj.Shapes = [refList[b['base']], refList[b['tool']]]
    elif objtype == 'extrude':
        isCreated = True
        obj = app.ActiveDocument.addObject('Part::Extrusion', name)
        obj.Base = refList[b['base']]
        obj.Dir = float(
            FreeCAD.Vector(float(b['valueX']), float(b['valueY']),
                           float(b['valueZ'])))
    elif objtype == 'rectangle':
        isCreated = True
        obj = app.ActiveDocument.addObject("Part::Part2DObjectPython", name)
        Draft.Rectangle(obj)
        Draft.ViewProviderRectangle(obj.ViewObject)
        obj.Length = float(b['length'])
        obj.Height = float(b['height'])
        obj.Support = None
        obj.ViewObject.DisplayMode = "Wireframe"
        #Draft.formatObject(obj)
        app.ActiveDocument.recompute()

    #all objects are created with the default placement
    #now the actual placement is added to the FreeCAD object
    if isCreated:
        obj.Placement = place
        #add the mapping from the reference string(name of object) to the actual object.
        #this is needed in order to build 'extended objects'
        refList[name] = obj
Example #16
0
def xCarriage():
	xsize = ac.xBushing[2] - 0.01
	ysize = ac.xBushing[1] + ac.minthick * 2
	#print 'yszie={y}'.format(y=ysize)
	zsize = ac.xrodspacing
	faceplatethick = ysize
	clampsize = ac.beltWidth + ps.m3i[1]*2 + ac.minthick
	extraclamp = 4
	railsize = ac.minthick
	
	#options
	doBeltClampParts = 0
	
	#face plate
	fp = Part.makeBox(xsize,faceplatethick,zsize)
	fp.translate(Vector(-xsize/2,ac.xrodypos-ac.xBushing[1]/2 - ac.minthick,-zsize/2 + ac.xrodzcenter))
	#clamp add
	ec = Part.makeBox(xsize,extraclamp,clampsize)
	ec.translate(Vector(-xsize/2,ac.xrodypos+ysize/2,ac.gantrydrivecenter-clampsize/2))
	ec=ec.makeFillet(extraclamp-0.01,[ec.Edges[10],ec.Edges[11]])
	fp=fp.fuse(ec)
	#adjustable clamp cut
	acc = Part.makeBox(ps.m3n[1]+ac.minthick,extraclamp,clampsize)
	acc.translate(Vector(-xsize/2,ac.xrodypos+ysize/2,ac.gantrydrivecenter-clampsize/2))
	acc=acc.makeFillet(extraclamp-0.01,[acc.Edges[5],acc.Edges[7]])
	fp=fp.fuse(acc)
	
	#adjustable clamp add
	aca = Part.makeBox(ps.m3n[1]+ac.minthick,ac.minthick,clampsize)
	aca.translate(Vector(-xsize/2,ac.xrodypos+ysize/2+extraclamp+1,ac.gantrydrivecenter-clampsize/2))
	aca=aca.makeFillet(extraclamp-0.01,[aca.Edges[5],aca.Edges[7]])
	fp=fp.fuse(aca)
	
	#Face Rails
	fr = Part.makeBox(railsize,railsize,zsize)
	fr.translate(Vector(-railsize/2,-railsize/2,-zsize/2))
	fr.rotate(Vector(0,0,0),Vector(0,0,1),45)
	fr.translate(Vector(xsize/4,ac.xrodypos-ysize/2,ac.xrodzcenter))
	
	frm = Part.makeBox(railsize*2,railsize,zsize)
	frm.translate(Vector(-railsize,-railsize/2,-zsize/2))
	frm=frm.makeFillet(railsize-0.01,[frm.Edges[8],frm.Edges[9]])
	frm.translate(Vector(xsize/4,ac.xrodypos-ysize/2,ac.xrodzcenter))
	
	fr = fr.common(frm)
	
	fr1 = fr.copy()
	fr1.translate(Vector(-xsize/4,0,0))
	fr2 = fr1.copy()
	fr2.translate(Vector(-xsize/4,0,0))
	fr=fr.fuse(fr1.fuse(fr2))
	
	fp =fp.fuse(fr)
	
	#bushing tubes
	bt1 = Part.makeCylinder((ac.xBushing[1]+ac.minthick*2)/2,xsize)
	bt1.translate(Vector(0,0,-xsize/2))
	bt1.rotate(Vector(0,0,0),Vector(0,1,0),90)
	bt1.translate(Vector(0,ac.xrodypos,ac.xrodzcenter+ac.xrodspacing/2))
	bt2=bt1.copy()
	bt2.translate(Vector(0,0,-ac.xrodspacing))
	bts = bt1.fuse(bt2)
	
	xc=bts.fuse(fp)
	
	#rod cuts
	xr=Part.makeCylinder((bc.gantryRodDia+bc.rodClearance)/2,xsize)
	xr.translate(Vector(0,0,-xsize/2))
	xr.rotate(Vector(0,0,0),Vector(0,1,0),90)
	xr.translate(Vector(0,ac.xrodypos,ac.xrodzcenter+ac.xrodspacing/2))
	xr2=xr.copy()
	xr2.translate(Vector(0,0,-ac.xrodspacing))
	
	xc=xc.cut(xr.fuse(xr2))
	
	#bushing cuts
	xb=Part.makeCylinder((ac.xBushing[1]+bc.bushingTolerance)/2,ac.xBushing[2])
	xb.translate(Vector(0,0,-ac.xBushing[2]/2))
	xb.rotate(Vector(0,0,0),Vector(0,1,0),90)
	xb.translate(Vector(0,ac.xrodypos,ac.xrodzcenter+ac.xrodspacing/2))
	xb2=xb.copy()
	xb2.translate(Vector(0,0,-ac.xrodspacing))
	
	xc=xc.cut(xb.fuse(xb2))
	
	#beltpath
	bpy=ac.beltThick+ac.beltPath*2
	bpz=ac.beltWidth+ac.beltPath*2
	bp = Part.makeBox(xsize,bpy,bpz)
	bp.translate(Vector(-xsize/2,ac.gantrybidlerypos+bc.gantryIdlerDia/2+ac.beltThick/2-bpy/2,ac.gantrydrivecenter-bpz/2))
	bp=bp.makeFillet(ac.beltWidth/4,[bp.Edges[8],bp.Edges[9],bp.Edges[10],bp.Edges[11]])
	xc=xc.cut(bp)
	
	#belt clamp path
	bcp = Part.makeBox(xsize,ac.beltThick,ac.beltWidth+0.5)
	bcp.translate(Vector(-xsize/1.5,ac.gantrycidlerypos - ps.z624[1]/2 - ac.beltThick,ac.gantrydrivecenter-(ac.beltWidth+0.5)/2))
	bcp1 = Part.makeBox(xsize - ps.m3l[1] - ac.minthick,ac.beltThick*2,ac.beltWidth+2)
	bcp1=bcp1.makeFillet(ac.beltWidth/2,[bcp1.Edges[4]])
	bcp1=bcp1.makeFillet(ac.beltWidth/4,[bcp1.Edges[6],bcp1.Edges[12]])
	bcp1.translate(Vector(-xsize/2,ac.gantrycidlerypos - ps.z624[1]/2 - ac.beltThick-2,ac.gantrydrivecenter-(ac.beltWidth+2)/2))
	#return bcp1
	bcp = bcp.fuse(bcp1)
	xc=xc.cut(bcp)
	
	#belt clamp fixed teeth
	bct = Part.makeCylinder(0.6,ac.beltWidth+0.5)
	bct.translate(Vector(xsize/2-1,ac.xrodypos+ysize/4-1.75,ac.gantrydrivecenter-(ac.beltWidth+0.5)/2))
	bcts=bct.copy()
	for i in range(0,5):
		a=bct.copy()
		a.translate(Vector(-2*i,0,0))
		bcts=bcts.fuse(a)
	
	xc=xc.cut(bcts)
	
	#belt clamp adj teeth
	bcta = Part.makeCylinder(0.6,ac.beltWidth+0.5)
	bcta.translate(Vector(-xsize/2+1,ac.xrodypos+ysize/2+ac.minthick,ac.gantrydrivecenter-(ac.beltWidth+0.5)/2))
	bctsa=bcta.copy()
	for i in range(0,5):
		a=bcta.copy()
		a.translate(Vector(2*i,0,0))
		bctsa=bctsa.fuse(a)
	
	xc=xc.cut(bctsa)
	
	#Belt Clamp Cut
	bccx = xsize
	bccy = 20
	bccz = clampsize + 2
	thick = 1
	rad = 4
	bcc = Part.makeBox(bccx,bccy,bccz)
	bcc = bcc.makeFillet(rad,[bcc.Edges[8],bcc.Edges[9]])
	bcctool = bcc.copy()
	bcctool.translate(Vector(xsize/2-bccx,ac.gantrycidlerypos-ps.z624[1]/2-ac.beltThick,ac.gantrydrivecenter-bccz/2))
	bcc2 = Part.makeBox(bccx,bccy-thick,bccz-thick*2)
	bcc2 = bcc2.makeFillet(rad-thick/2,[bcc2.Edges[8],bcc2.Edges[9]])
	bcc2.translate(Vector(0,thick,thick))
	bcc=bcc.cut(bcc2)
	#bcc.rotate(Vector(0,0,0),Vector(0,0,1),180)
	bcc.translate(Vector(xsize/2-bccx,ac.gantrycidlerypos-ps.z624[1]/2-ac.beltThick,ac.gantrydrivecenter-bccz/2))
	#center cut
	ccx = xsize - ac.minthick*3 - ps.m3l[1]*2
	cc=Part.makeBox(ccx,ysize/2,ac.beltWidth+ac.beltSpace*2)
	cc.translate(Vector(-ccx/2+ac.minthick,ac.gantrycidlerypos-ps.z624[1]/2-ac.beltThick/2,ac.gantrydrivecenter - ac.beltWidth/2-ac.beltSpace))
	cc = cc.makeFillet(ac.minthick,[cc.Edges[5],cc.Edges[7]])
	
	xc = xc.cut(bcc.fuse(cc))
	#Ram guide slot
	guidewide = 4
	guidedeep = 2
	guidetol = 0.5 #added to each side
	rgs = Part.makeBox(ccx-ac.minthick,guidewide+guidetol*2,guidedeep+guidetol)
	rgs.translate(Vector(-ccx/2+ac.minthick,\
		((ac.xrodypos+ysize/2+extraclamp)+(ac.gantrycidlerypos-ps.z624[1]/2-ac.beltThick*1))/2 - ac.beltThick,\
		ac.gantrydrivecenter+(ac.beltWidth+ac.beltSpace*2)/2))
	rgs=rgs.fuse(rgs.mirror(Vector(0,0,ac.gantrydrivecenter),Vector(0,0,1)))
	#xc = xc.cut(rgs)
	
	#Ram Screw and Insert
	rs = CapHeadScrew(l=20,d=ps.m3l[0],hd=ps.m3l[1],hh=ps.m3l[2],cut=1)
	rs.rotate(Vector(0,0,0),Vector(0,1,0),-90)
	rs.translate(Vector(-ccx/2+ac.minthick/2-ps.m3i[1],((ac.xrodypos+ysize/2+extraclamp)+(ac.gantrycidlerypos-ps.z624[1]/2))/2,ac.gantrydrivecenter))
	ins = Part.makeCylinder(ps.m3i[0]/2,ps.m3i[1])
	ins.translate(Vector(0,0,-ac.minthick-3.5))
	ins.rotate(Vector(0,0,0),Vector(0,1,0),-90)
	ins.translate(Vector(-ccx/2+ac.minthick/2-ps.m3i[1],((ac.xrodypos+ysize/2+extraclamp)+(ac.gantrycidlerypos-ps.z624[1]/2))/2,ac.gantrydrivecenter))
	xc = xc.cut(rs.fuse(ins))
	
	#Belt Clamp Screws
	clslen=38
	adj1 = CapHeadScrew(l=clslen,d=ps.m3l[0],hd=ps.m3l[1],hh=ps.m3l[2],cut=1)
	adj1.rotate(Vector(0,0,0),Vector(1,0,0),90)
	adj1.translate(Vector(xsize/2-ac.minthick,ac.xrodypos-ysize/2+ps.m3l[2],ac.gantrydrivecenter+ac.beltWidth/2+ac.minthick-1))
	adj2 = CapHeadScrew(l=clslen,d=ps.m3l[0],hd=ps.m3l[1],hh=ps.m3l[2],cut=1)
	adj2.rotate(Vector(0,0,0),Vector(1,0,0),90)
	adj2.translate(Vector(xsize/2-ac.minthick,ac.xrodypos-ysize/2+ps.m3l[2],ac.gantrydrivecenter-ac.beltWidth/2-ac.minthick+1))
	adj = adj1.fuse(adj2)
	adj=adj.fuse(adj.mirror(Vector(0,0,0),Vector(1,0,0)))
	xc=xc.cut(adj)
	
	#Clamp Threaded inserts
	i1=Part.makeCylinder(ps.m3i[0]/2,ps.m3i[1])
	i1p=Part.makeCylinder(ps.m3i[0]/2,ps.m3i[1])
	i1p.translate(Vector(0,0,-ps.m3i[1]))
	i1=i1.fuse(i1p)
	i1.rotate(Vector(0,0,0),Vector(1,0,0),-90)
	i1.translate(Vector(xsize/2-ac.minthick,ac.xrodypos+ysize/2+extraclamp,ac.gantrydrivecenter+ac.beltWidth/2+ac.minthick-1))
	i2=i1.copy()
	i2.translate(Vector(0,0,-ac.beltWidth-ac.minthick*2+2))
	iss=i1.fuse(i2)
	iss=iss.fuse(iss.mirror(Vector(0,0,0),Vector(1,0,0)))
	
	xc=xc.cut(iss)
	
	#Back Fat Cut
	bfc = Part.makeBox(xsize-ac.minthick-4,ysize-ac.minthick,zsize/2-ac.minthick*2)
	bfc.translate(Vector(-(xsize-ac.minthick-4)/2,ac.xrodypos-ysize/2+ac.minthick,ac.xrodzcenter-ac.xrodspacing/2+ac.minthick))
	bfc=bfc.makeFillet(ac.minthick*2,[bfc.Edges[1],bfc.Edges[5],bfc.Edges[9],bfc.Edges[3],bfc.Edges[7]])
	bfc = bfc.cut(bt2)
	xc = xc.cut(bfc)
	#Thread block
	tb = Part.makeBox(xsize-ac.minthick-2,ac.minthick*2,ps.m3i[0]+ac.minthick*1.5)
	tb.translate(Vector(-(xsize-ac.minthick-2)/2,ac.xrodypos-ysize/2+ac.minthick,ac.xrodzcenter-ac.xrodspacing/2+ac.xBushing[1]/2))
	tb = tb.makeFillet(ac.minthick/2,[tb.Edges[11]])
	xc = xc.fuse(tb)
	
	#ToolHolder Mount Screws
	tms1 = CapHeadScrew(l=20,d=ps.m3l[0],hd=ps.m3l[1],hh=ps.m3l[2],cut=1)
	ins = Part.makeCylinder(ps.m3i[0]/2,ps.m3i[1]+ac.minthick)
	ins.translate(Vector(0,0,-20))
	tms1=tms1.fuse(ins)
	tms1.rotate(Vector(0,0,0),Vector(1,0,0),90)
	tms1.translate(Vector(-xsize/8,ac.xrodypos-ac.xBushing[1]/2-ac.minthick,ac.gantrydrivecenter+ac.beltWidth/2+ac.minthick-1))
	tms3 = tms1.copy()
	tms1 = tms1.fuse(tms1.mirror(Vector(0,0,0),Vector(1,0,0)))
	tms2 = tms1.mirror(Vector(0,0,ac.gantrydrivecenter),Vector(0,0,1))
	tms3 = tms3.mirror(Vector(0,0,ac.xrodzcenter),Vector(0,0,1))
	tms31= tms3.copy()
	tms31.translate(Vector(-xsize/4,0,0))
	tms3=tms3.fuse(tms31)
	tms3 = tms3.fuse(tms3.mirror(Vector(0,0,0),Vector(1,0,0)))
	
	xc = xc.cut(tms1.fuse(tms2.fuse(tms3)))
	
	#Bushing Clamp Slots
	bushingclampslotgap = 2
	bcs=Part.makeBox(xsize,ysize/2,bushingclampslotgap)
	bcs.translate(Vector(-xsize/2,ac.xrodypos,ac.xrodzcenter+ac.xrodspacing/2-bushingclampslotgap/2))
	bcs = bcs.fuse(bcs.mirror(Vector(0,0,ac.xrodzcenter),Vector(0,0,1)))
	
	xc = xc.cut(bcs)
	
	#EndStop Pocket
	esp = Part.makeBox(bc.gantrySwitchX,bc.gantrySwitchY,bc.gantrySwitchZ)
	esp = esp.makeFillet(bc.gantrySwitchZ/2-0.01,[esp.Edges[5],esp.Edges[7]])
	esp.translate(Vector(-xsize/2,ac.xrodypos - bc.gantrySwitchY/2,ac.gantrydrivecenter - bc.gantrySwitchZ - ac.beltThick - ac.minthick*2))
	#EndStop Screws
	ess = CapHeadScrew(l=16,d=bc.gantrySwitchScrewDia,hd=bc.gantrySwitchScrewDia*2,hh=bc.gantrySwitchScrewDia/2,cut=1)
	ess.rotate(Vector(0,0,0),Vector(1,0,0),-90)
	ess.translate(Vector(-xsize/2+bc.gantrySwitchScrewOffset/2,ac.xrodypos+bc.gantrySwitchY/2+ac.minthick,ac.gantrydrivecenter - bc.gantrySwitchZ/2 + bc.gantrySwitchScrewSpacing/2- ac.beltThick - ac.minthick*2))
	ess1 = ess.copy()
	ess1.translate(Vector(0,0,-bc.gantrySwitchScrewSpacing))
	ess = ess.fuse(ess1)
	
	esp = esp.fuse(ess)
	esp = esp.fuse(esp.mirror(Vector(0,0,0),Vector(1,0,0)))
	xc = xc.cut(esp)
	
	#Cable Tie Off
	top = Part.makeBox(14,4,2)
	top.translate(Vector(-7,ac.xrodypos+ysize/2-ac.minthick-1,ac.xrodzcenter-2.5))
	end = Part.makeBox(3,4,10)
	end.translate(Vector(-7,ac.xrodypos+ysize/2-ac.minthick-1,ac.xrodzcenter-10.5))
	end=end.fuse(end.mirror(Vector(0,0,0),Vector(1,0,0)))
	
	cto = top.fuse(end)
	cto = cto.makeFillet(2,[cto.Edges[9],cto.Edges[18]])
	xc = xc.cut(cto)
	
	#Cable Path
	cp = Part.makeBox(24,30,9)
	cp = cp.makeFillet(2,[cp.Edges[1],cp.Edges[3],cp.Edges[5],cp.Edges[7]])
	#cp.rotate(Vector(0,0,0),Vector(1,0,0),-20)
	cp.translate(Vector(-12,ac.xrodypos - 10 - ysize/2,ac.xrodzcenter-ac.minthick*2-4))
	
	xc = xc.cut(cp)
	
	#Belt Ram
	brx = ccx/3
	bry = ac.minthick*2+1
	brz = ac.beltWidth+ac.beltSpace*2-2
	br = Part.makeBox(brx,bry,brz)
	br = br.makeFillet(bry/2-0.01,[br.Edges[4],br.Edges[6]])
	
	br.translate(Vector(0,((ac.xrodypos+ysize/2+extraclamp)+(ac.gantrycidlerypos-ps.z624[1]/2-ac.beltThick*1))/2-bry/2+1,ac.gantrydrivecenter-brz/2))
	br = br.cut(rs)
	if dc.forPrint == 1:
		br.rotate(Vector(0,0,0),Vector(0,1,0),90)
		br.translate(Vector(-ac.gantrydrivecenter-22.5,9,ac.gantrydrivecenter-13))

	if doBeltClampParts == 1:
		xc = xc.fuse(br)
	
	#mount tabs
	mtx = xsize
	mty = ysize/2 + ps.m3l[1]+ac.minthick
	mtz = ac.xBushing[1]/2+ac.minthick-bushingclampslotgap/2
	
	#Fan Mount tabs
	fmt = Part.makeBox(mtx,mty,mtz)
	fmt.translate(Vector(-mtx,ac.xrodypos,0))
	fmt.translate(Vector(xsize/2,0,ac.xrodzcenter-ac.xrodspacing/2-ac.xBushing[1]/2-ac.minthick))
	#corner fillets
	fmt = fmt.makeFillet((ps.m3l[1]+ac.minthick)/2,[fmt.Edges[2],fmt.Edges[6]])
	# bushing cut
	fmt = fmt.cut(xb2)
	# fat cut
	fcy = ps.m3l[1]+ac.minthick
	fcz = mtz - ps.m3l[2]*2 - ac.minthick
	fc = Part.makeBox(xsize,fcy,fcz)
	fc.translate(Vector(-mtx,ac.xrodypos+ac.xBushing[1]/2+ac.minthick,-fcz))
	fc.translate(Vector(xsize/2,0,ac.xrodzcenter-ac.xrodspacing/2-ac.xBushing[1]/2-ac.minthick + mtz))
	fc = fc.makeFillet(fcz-0.01,[fc.Edges[8]])
	fmt = fmt.cut(fc)
	# toriod cut
	tc = Part.makeTorus((ac.xBushing[1]+ac.minthick)/2+ps.m3l[2]+ac.minthick*3.25,(ps.m3l[2]+ac.minthick*3))
	tc.rotate(Vector(0,0,0),Vector(0,1,0),90)
	tc.translate(Vector(0,ac.xrodypos+2,ac.xrodzcenter-ac.xrodspacing/2))
	fmt = fmt.cut(tc)
	#post fillets
	#return fmt
	fmt = fmt.makeFillet(fcz-0.01,[fmt.Edges[36],fmt.Edges[38]])
	#mount screws
	ms = Part.makeCylinder(ps.m3l[0]/2,mtz)
	ms.translate(Vector(xsize/2-ps.m3l[1]/2-ac.minthick/2,ac.xrodypos+mty-ps.m3l[1]/2-ac.minthick/2,ac.xrodzcenter-ac.xrodspacing/2-ac.xBushing[1]/2-ac.minthick))
	
	mshl = Part.makeCylinder(ps.m3l[1]/2,ps.m3l[2])
	mshl.translate(Vector(xsize/2-ps.m3l[1]/2-ac.minthick/2,ac.xrodypos+mty-ps.m3l[1]/2-ac.minthick/2,ac.xrodzcenter-ac.xrodspacing/2-ac.xBushing[1]/2-ac.minthick))
	ms = ms.fuse(mshl)
	
	mshh = Part.makeCylinder(ps.m3l[1]/2,ps.m3l[2]+ac.minthick)
	mshh.translate(Vector(xsize/2-ps.m3l[1]/2-ac.minthick/2,ac.xrodypos+mty-ps.m3l[1]/2-ac.minthick/2,ac.xrodzcenter-ac.xrodspacing/2-ac.xBushing[1]/2-ac.minthick+mtz-fcz-ps.m3l[2]))
	ms = ms.fuse(mshh)
	
	ms = ms.fuse(ms.mirror(Vector(0,0,0),Vector(1,0,0)))
	
	fmt = fmt.cut(ms)
	
	
	xc = xc.fuse(fmt)
	#Extruder Drive Mount tabs
	emt = fmt.mirror(Vector(0,0,ac.xrodzcenter),Vector(0,0,1))
	emt = emt.fuse(emt.mirror(Vector(0,ac.xrodypos,0),Vector(0,1,0)))
	
	xc = xc.fuse(emt)
	
	xc = xc.cut(xb2)
	
	if dc.forPrint == 1:
		xc.translate(Vector(xsize/2,-ac.xrodypos,-ac.xrodzcenter))
		xc.rotate(Vector(0,0,0),Vector(0,1,0),-90)
		xc.rotate(Vector(0,0,0),Vector(0,0,1),180)
	
	else:
		xc.translate(Vector(ac.mXpos,ac.mYpos,0))
	return xc
#Create new document
App.newDocument("Unnamed")
App.setActiveDocument("Unnamed")
App.ActiveDocument = App.getDocument("Unnamed")
Gui.ActiveDocument = Gui.getDocument("Unnamed")

#
#Inner Ring#
B1 = Part.makeCylinder(R1, TH)
B2 = Part.makeCylinder(R2, TH)
IR = B2.cut(B1)
#get edges and apply fillets
Bedges = IR.Edges
IRF = IR.makeFillet(RR, Bedges)
#create groove and show shape
T1 = Part.makeTorus(CBall, RBall)
T1.translate(Base.Vector(0, 0, TH / 2))
InnerRing = IRF.cut(T1)
Part.show(InnerRing)

#
#Outer Ring#
B3 = Part.makeCylinder(R3, TH)
B4 = Part.makeCylinder(R4, TH)
OR = B4.cut(B3)
#get edges and apply fillets
Bedges = OR.Edges
ORF = OR.makeFillet(RR, Bedges)
#create groove and show shape
T2 = Part.makeTorus(CBall, RBall)
T2.translate(Base.Vector(0, 0, TH / 2))
Example #18
0
def buildObject(el, queue, refList, app): 
    #expand and extract elements needed for object construction
    name, pos, b, objtype, tr = el
    queue.remove(el)
    
    #build the placement from the vector and quaternion stored in the xml file
    base = FreeCAD.Vector(float(pos['x']), float(pos['y']), float(pos['z']))
    quat = [float(pos['q0']), float(pos['q1']), float(pos['q2']), float(pos['q3'])]
    q0, q1, q2, q3 = quat
    angle = 2*math.acos(q3)
    axis = FreeCAD.Vector(q0, q1, q2)
    place = FreeCAD.Placement(base, axis, angle)

    isCreated = False
    defpnt = FreeCAD.Vector()
    defdir = FreeCAD.Vector(0,0,1)
    defplace = FreeCAD.Placement()
    #handler to determine which object constructor to call
    if objtype == 'box':
        isCreated = True
        part = Part.makeBox(float(b['length']), float(b['width']), float(b['height']))
        obj = app.ActiveDocument.addObject('Part::Box',name)
        obj.Shape = part
    elif objtype == 'cylinder':
        isCreated = True
        part = Part.makeCylinder(float(b['radius']), float(b['height']))
        obj = app.ActiveDocument.addObject('Part::Cylinder',name)
        obj.Shape = part
    elif objtype == 'cone':
        isCreated = True
        part = Part.makeCone(float(b['radius1']), float(b['radius2']), float(b['height']))
        obj = app.ActiveDocument.addObject('Part::Cone',name)
        obj.Shape = part
    elif objtype == 'sphere':
        isCreated = True
        part = Part.makeSphere(float(b['radius']), defpnt, defdir, float(b['angle1']),
                               float(b['angle2']),float(b['angle3']))
        obj = app.ActiveDocument.addObject('Part::Sphere',name)
        obj.Shape = part
    elif objtype == 'torus':
        isCreated = True
        print el
        part = Part.makeTorus(float(b['radius1']), float(b['radius2']), defpnt, defdir, 
                              float(b['angle1']),float(b['angle2']),float(b['angle3']))
        obj = app.ActiveDocument.addObject('Part::Torus',name)
        obj.Shape = part
    elif objtype == 'line':
        isCreated = False
        obj = app.ActiveDocument.addObject('Part::Part2DObjectPython', name)
        secpnt = FreeCAD.Vector(float(b['length']),0,0)
        Draft.Wire(obj)
        obj.Points = [defpnt, secpnt]
        obj.Closed = False
        obj.Support = None
    elif objtype == 'circle':
        isCreated = True
        obj = app.ActiveDocument.addObject('Part::Part2DObjectPython', name)
        Circle(obj)
        obj.Radius = float(b['radius'])
        startangle = float(b['angle1'])
        endangle = float(b['angle2'])
        if (startangle != None) and (endangle != None):
            obj.FirstAngle = startangle
            obj.LastAngle = endangle
    elif objtype == 'cut':
        isCreated = True
        obj = addObject('Part::MultiCut',name)
        obj.Shapes = [refList[b['base']],refList[b['tool']]]
    elif objtype == 'fusion':
        isCreated = True
        obj = addObject('Part::MultiFuse',name)
        obj.Shapes = [refList[b['base']],refList[b['tool']]]
        #refList[att['base']].Visibility = False
        #refList[att['tool']].Visibility = False
    elif objtype == 'common':
        isCreated = True
        obj = addObject('Part::MultiCommon',name)
        obj.Shapes = [refList[b['base']],refList[b['tool']]]
    elif objtype == 'extrude':
        isCreated = True
        obj = app.ActiveDocument.addObject('Part::Extrusion', name)
        obj.Base =refList[b['base']]
        obj.Dir = float(FreeCAD.Vector(float(b['valueX']),
                                       float(b['valueY']),
                                       float(b['valueZ'])))
    elif objtype == 'rectangle':
        isCreated = True
        obj = app.ActiveDocument.addObject("Part::Part2DObjectPython",name)
        Draft.Rectangle(obj)
        Draft.ViewProviderRectangle(obj.ViewObject)
        obj.Length = float(b['length'])
        obj.Height = float(b['height'])
        obj.Support =None
        obj.ViewObject.DisplayMode = "Wireframe"
        #Draft.formatObject(obj)
        app.ActiveDocument.recompute()
    
    #all objects are created with the default placement
    #now the actual placement is added to the FreeCAD object
    if isCreated:
        obj.Placement = place
        #add the mapping from the reference string(name of object) to the actual object.
        #this is needed in order to build 'extended objects'
        refList[name] = obj
plane = Part.makePlane(2, 2)
plane

plane = Part.makePlane(2, 2, Base.Vector(3, 0, 0), Base.Vector(0, 1, 0))
plane.BoundBox

Part.Ellipse()

eli = Part.Ellipse(Base.Vector(10, 0, 0), Base.Vector(0, 5, 0),
                   Base.Vector(0, 0, 0))
Part.show(eli.toShape())

eli = Part.Ellipse(Base.Vector(0, 0, 0), 10, 5)
Part.show(eli.toShape())

torus = Part.makeTorus(10, 2)

tor = Part.makeTorus(10, 5, Base.Vector(0, 0, 0), Base.Vector(0, 0, 1), 0, 180)

tor = Part.makeTorus(10, 5, Base.Vector(0, 0, 0), Base.Vector(0, 0, 1), 0, 360,
                     180)

box = Part.makeBox(10, 10, 10)
len(box.Vertexes)

sphere = Part.makeSphere(10)
hemisphere = Part.makeSphere(10, Base.Vector(0, 0, 0), Base.Vector(0, 0, 1),
                             -90, 90, 180)

cylinder = Part.makeCylinder(5, 20)
partCylinder = Part.makeCylinder(5, 20, Base.Vector(20, 0, 0),
Example #20
0
def doublerowradialbearing(params,document): 
	rin=0.5*params['DRBinr']
	rout=0.5*params['DRBour']
	bth=params['DRBbth']
	name = params['name']
	rb=0.3*(rout-rin)
	cb=(rout-rin)/2.0+rin
	RR=0.015*rout
	#shapes---
	shapes = []
	#outer ring---------------
	our1=Part.makeCylinder(rout,bth)
	our2=Part.makeCylinder(cb+rb*0.7,bth)
	our3=Part.makeCylinder(rout,0.1*bth)
	our4=Part.makeCylinder(rout-0.12*(rout-rin),0.1*bth)
	our=our1.cut(our2)
	oursv=(0,0,0.45*bth)
	ours=our3.cut(our4)
	ours.translate(oursv)
	our=our.cut(ours)
	oure=our.Edges
	our=our.makeFillet(RR,oure)
	#iner ring-----------------
	inr1=Part.makeCylinder(cb-rb*0.7,bth)
	inr2=Part.makeCylinder(rin,bth)
	inr=inr1.cut(inr2)
	inre=inr.Edges
	inr=inr.makeFillet(RR,inre)
	#track--------------------
	t1=Part.makeTorus(cb,rb)
	t2=Part.makeTorus(cb,rb)
	vt1=(0,0,rb+bth/2)
	vt2=(0,0,(bth/2)-rb)
	t1.translate(vt1)
	t2.translate(vt2)
	our=our.cut(t1)
	our=our.cut(t2)
	inr=inr.cut(t1)
	inr=inr.cut(t2)
	#shapes----
	shapes.append(our)
	shapes.append(inr)
	#Balls--------------------
	nb=(math.pi*cb)*0.8/(rb)
	nb=math.floor(nb)
	nb=int(nb)
	for i in range (nb):
		b=Part.makeSphere(rb)
		Alpha=(i*2*math.pi)/nb
		bv=(cb*math.cos(Alpha),cb*math.sin(Alpha),rb+bth/2)
		b.translate(bv)
		shapes.append(b) 
	
	offset=math.asin(rb/cb)
	for i in range(nb):
		b=Part.makeSphere(rb)
		Alpha=(i*2*math.pi)/nb
		bv=(cb*math.cos(Alpha+offset),cb*math.sin(Alpha+offset),(bth/2)-rb)
		b.translate(bv)
		shapes.append(b)

	part = document.addObject("Part::Feature",name)
	comp = Part.Compound(shapes)
	part.Shape = comp.removeSplitter()
def WCLL_detailed_module(blanket_parameters_dict):


        envelope_directory_filename = blanket_parameters_dict['envelope_filename']
        output_folder = blanket_parameters_dict['output_folder']
        if 'output_files' in blanket_parameters_dict.keys():
          output_files = blanket_parameters_dict['output_files']
        else:
          output_files=['step','stl','h5m','merged_stl']
        output_folder_step = output_folder+'/step'
        output_folder_stl = output_folder+'/stl'
        output_folder_h5m = output_folder + '/h5m'
        output_folder_merged_stl = output_folder + '/merged_stl'
        armour_thickness = blanket_parameters_dict['armour_thickness']
        first_wall_thickness = blanket_parameters_dict['first_wall_thickness']
        end_cap_thickness = blanket_parameters_dict['end_cap_thickness']
        back_walls_thicknesses = blanket_parameters_dict['back_walls_thicknesses']

        if 'plasma_filename' in blanket_parameters_dict:
            plasma_filename = blanket_parameters_dict['plasma_filename']
            plasma = Part.read(plasma_filename)
        else:
            plasma = Part.makeTorus(9100, 2900)

        envelope = read_in_envelope_file(envelope_directory_filename)

        envelope_back_face = find_envelope_back_face(envelope, plasma)

        envelope_front_face = find_envelope_front_face(envelope, envelope_back_face)

        front_face_midpoint = find_front_face_midpoint(envelope_front_face)

        original_envelope_front_face_id = envelope_front_face_id(envelope,envelope_back_face)

        envelope_back_face_id = find_envelope_back_face_id(envelope, plasma)

        front_face_polodial_edges_to_fillet = find_front_face_polodial_edges_to_fillet(envelope_front_face.Edges)

        front_face_torodial_edges_to_fillet = find_front_face_torodial_edges_to_fillet(envelope_front_face.Edges)

        first_wall_poloidal_fillet_radius = blanket_parameters_dict['first_wall_poloidal_fillet_radius']

        filleted_envelope_solid = filleted_envelope(fillet_radius=first_wall_poloidal_fillet_radius,
                                                   edges=front_face_polodial_edges_to_fillet,
                                                   envelope=envelope)

        filleted_envelope_back_face = find_envelope_back_face(filleted_envelope_solid, plasma)
        filleted_envelope_front_face = find_envelope_front_face(filleted_envelope_solid,
                                                                     filleted_envelope_back_face)

        filleted_envelope_front_face_id = envelope_front_face_id(wedge=filleted_envelope_solid,
                                                                      envelope_back_face=filleted_envelope_back_face)

        end_cap_faces = find_end_cap_faces(faces_under_consideration=filleted_envelope_solid.Faces)

        first_wall_armour, envelope_removed_armour = chop_off_first_wall_armour(armour_thickness=armour_thickness,
                                                                                          faces_not_in_first_wall=[filleted_envelope_back_face] +end_cap_faces,
                                                                                          filleted_envelope=filleted_envelope_solid,
                                                                                          front_face=envelope_front_face)

        # armour_removed_envelope_back_face = find_envelope_back_face(envelope_removed_armour, plasma)
        # armour_removed_envelope_front_face = find_envelope_front_face(envelope_removed_armour,
        #                                                                    armour_removed_envelope_back_face)

        dictionary_of_parts = collections.defaultdict(dict)

        dictionary_of_parts['armour']['part'] = [first_wall_armour]

        envelope_removed_armour_end_cap_faces = find_end_cap_faces(faces_under_consideration=envelope_removed_armour.Faces)

        armour_removed_envelope_back_face = find_envelope_back_face(envelope_removed_armour, plasma)

        armour_removed_envelope_front_face = find_envelope_front_face(envelope_removed_armour,
                                                                           armour_removed_envelope_back_face)


        first_wall, first_wall_removed_envelope = chop_off_first_wall(faces_not_in_first_wall=[armour_removed_envelope_back_face] + envelope_removed_armour_end_cap_faces,
                                                                                thickness=first_wall_thickness,
                                                                                filleted_envelope= envelope_removed_armour)

        dictionary_of_parts['first_wall_homogenised']['part'] = [first_wall]

        first_wall_removed_envelope_back_face = find_envelope_back_face(first_wall_removed_envelope,
                                                                             plasma)
        first_wall_removed_envelope_front_face = find_envelope_front_face(first_wall_removed_envelope,
                                                                               first_wall_removed_envelope_back_face)
        first_wall_removed_envelope_midpoint = find_front_face_midpoint(
            first_wall_removed_envelope_front_face)

        if 'cooling_channel_offset_from_first_wall' in blanket_parameters_dict and 'first_wall_channel_radial_mm' in blanket_parameters_dict and 'first_wall_channel_poloidal_segmentations' in blanket_parameters_dict:
            print('calculating first wall cooling pipes')

            cooling_channel_offset_from_first_wall = blanket_parameters_dict['cooling_channel_offset_from_first_wall']
            first_wall_channel_radial_mm = blanket_parameters_dict['first_wall_channel_radial_mm']

            first_wall_front_layer, first_wall_removed_envelope_temp1 = chop_off_first_wall(faces_not_in_first_wall=[armour_removed_envelope_back_face] + envelope_removed_armour_end_cap_faces,
                                                                                                      thickness=cooling_channel_offset_from_first_wall,
                                                                                                      filleted_envelope=envelope_removed_armour)

            first_wall_back_layer, first_wall_removed_envelope_temp2 = chop_off_first_wall(faces_not_in_first_wall=[armour_removed_envelope_back_face] + envelope_removed_armour_end_cap_faces,
                                                                                                     thickness=first_wall_channel_radial_mm + cooling_channel_offset_from_first_wall,
                                                                                                     filleted_envelope=envelope_removed_armour)

            first_wall_middle_layer = first_wall.common(first_wall_back_layer).cut(first_wall_front_layer)
            first_wall_back_layer = first_wall.cut(first_wall_back_layer)

            dictionary_of_parts['first_wall_material']['part'] = [first_wall_front_layer, first_wall_back_layer]

            first_wall_poloidally_segmented = chop_up_poloidally(midpoint=first_wall_removed_envelope_midpoint,
                                                                      poloidal_segmentations=blanket_parameters_dict['first_wall_channel_poloidal_segmentations'],
                                                                      envelope=first_wall_middle_layer,
                                                                      method='first_wall',
                                                                      top_bottom_edges=front_face_torodial_edges_to_fillet,
                                                                      front_face=envelope_front_face)


            for i, key in enumerate(blanket_parameters_dict['first_wall_channel_poloidal_segmentations']):
                dictionary_of_parts[key]['part'] = first_wall_poloidally_segmented[i]

            dictionary_of_parts['first_wall_material']['part'] = dictionary_of_parts['first_wall_material'][
                                                                          'part'] + [first_wall_front_layer,
                                                                                     first_wall_back_layer]



        end_caps, envelope_removed_endcaps = chop_of_end_caps(end_cap_faces, end_cap_thickness,
                                                                            first_wall_removed_envelope)

        dictionary_of_parts['end_caps_homogenised']['part'] = end_caps

        back_face_envelope_removed_caps = find_envelope_back_face(envelope_removed_endcaps, plasma)

        back_walls, envelope_removed_back_wall = chop_off_back_walls(back_face=back_face_envelope_removed_caps,
                                                                               remaining_shapes=envelope_removed_endcaps,
                                                                               back_walls_thicknesses=back_walls_thicknesses)

        for i, key in enumerate(blanket_parameters_dict['back_walls_thicknesses']):
            dictionary_of_parts[key]['part'] = [back_walls[i]]

        poloidal_segmentations = blanket_parameters_dict['poloidal_segmentations']

        envelope_poloidally_segmented = chop_up_poloidally(midpoint=first_wall_removed_envelope_midpoint,
                                                                poloidal_segmentations=poloidal_segmentations,
                                                                envelope=envelope_removed_back_wall,
                                                                method='WCLL',top_bottom_edges=front_face_torodial_edges_to_fillet,
                                                                front_face=envelope_front_face)

        toroidal_segmentations = blanket_parameters_dict['toroidal_segmentations']

        envelope_toroidally_segmented = chop_up_toroidally(toroidal_segmentations=blanket_parameters_dict['toroidal_segmentations'],
                                                                envelope=envelope_removed_back_wall,
                                                                front_face = first_wall_removed_envelope_front_face,
                                                                front_face_torodial_edges_to_fillet = front_face_torodial_edges_to_fillet)


        radial_segmentations = blanket_parameters_dict['radial_segmentations']

        envelope_radially_segmented = chop_up_envelope_zone_radially(radial_segmentations=radial_segmentations,
                                                                          number_required=1,
                                                                          front_face=first_wall_removed_envelope_front_face,
                                                                          envelope=envelope_removed_back_wall)

        list_of_plates_for_cutting = envelope_poloidally_segmented[0][2::4] + envelope_poloidally_segmented[0][3::4]

        additional_lithium_lead, reduced_solids = find_common_bodies(envelope_radially_segmented[0],
                                                                                    list_of_plates_for_cutting)

        envelope_poloidally_segmented[0] = reduced_solids + envelope_poloidally_segmented[0][0::4] + \
                                                envelope_poloidally_segmented[0][1::4]

        envelope_poloidally_segmented[1] = additional_lithium_lead + envelope_poloidally_segmented[1]

        lithium_lead = []
        for poloidally_ll in envelope_poloidally_segmented[1]:
            for toroidally_ll in envelope_toroidally_segmented[0]:
                lithium_lead.append(poloidally_ll.common(toroidally_ll))

        structural_plate = []
        for poloidally_div in envelope_poloidally_segmented[0]:
            for toroidal_div in envelope_toroidally_segmented[1]:
                poloidally_div = poloidally_div.cut(toroidal_div)
            structural_plate.append(poloidally_div)
        structural_plate = structural_plate + envelope_toroidally_segmented[1]

        available_breezer_zone_materials = [lithium_lead, structural_plate]
        for i, key in enumerate(blanket_parameters_dict['poloidal_segmentations']):
            dictionary_of_parts[key]['part'] = available_breezer_zone_materials[i]

        cylinder_slice = make_cylinder_slice(10)

        prefix='_' + os.path.splitext(os.path.split(envelope_directory_filename)[-1])[0]

        if 'step' in output_files:
            save_components_as_step(dictionary_of_parts = dictionary_of_parts, output_folder = output_folder_step, filename_prefix =prefix)

        if 'merged_stl' in output_files:
            save_components_as_merged_stl_file(dictionary_of_parts=dictionary_of_parts,
                                           output_folder=output_folder_merged_stl,
                                           blanket_type=blanket_parameters_dict['blanket_type'])

        if 'stl' in output_files:
            save_components_as_stl(dictionary_of_parts = dictionary_of_parts, output_folder = output_folder_stl)

        if 'h5m' in output_files:
            save_components_as_h5m_file(dictionary_of_parts = dictionary_of_parts, output_folder = output_folder_h5m, blanket_type=blanket_parameters_dict['blanket_type'])


        return dictionary_of_parts