def srf_nrml_facing_solid_inward(occ_face, occ_solid): #move the face in the direction of the normal #first offset the face so that vert will be within the solid o_wire = Construct.make_offset(occ_face, 0.0001) o_face = BRepBuilderAPI_MakeFace(o_wire).Face() wire_list = list(Topology.Topo(o_face).wires()) occpt_list = [] for wire in wire_list: occpts = Topology.WireExplorer(wire).ordered_vertices() occpt_list.extend(occpts) pt = BRep_Tool.Pnt(occpt_list[0]) #a point that is on the edge of the face normal = face_normal(occ_face) gp_direction2move = gp_Vec(normal[0], normal[1], normal[2]) gp_moved_pt = pt.Translated(gp_direction2move.Multiplied(0.001)) mv_pt = (gp_moved_pt.X(), gp_moved_pt.Y(), gp_moved_pt.Z()) in_solid = point_in_solid(occ_solid, mv_pt) if in_solid: return True else: return False
def trim_wire(occwire, pypt1, pypt2, is_periodic=False): """ This function trims the wire. Parameters ---------- occwire : OCCwire The OCCwire to be fixed. pypt1 : tuple of floats The starting point of the trim. A pypt is a tuple that documents the xyz coordinates of a pt e.g. (x,y,z) pypt2 : tuple of floats The ending point of the trim. A pypt is a tuple that documents the xyz coordinates of a pt e.g. (x,y,z) is_periodic : bool, optional Indicates if the wire is open or close, True for close, False for open, Default = False. Returns ------- trimmed wire : OCCwire The trimmed OCCwire. """ gppnt1 = construct.make_gppnt(pypt1) gppnt2 = construct.make_gppnt(pypt2) trimmed = Construct.trim_wire(occwire, gppnt1, gppnt2, periodic=is_periodic) return trimmed
def trim_wire(occwire, pypt1, pypt2, is_periodic=False): """ This function trims the wire. Parameters ---------- occwire : OCCwire The OCCwire to be fixed. pypt1 : tuple of floats The starting point of the trim. A pypt is a tuple that documents the xyz coordinates of a pt e.g. (x,y,z) pypt2 : tuple of floats The ending point of the trim. A pypt is a tuple that documents the xyz coordinates of a pt e.g. (x,y,z) is_periodic : bool, optional Indicates if the wire is open or close, True for close, False for open, Default = False. Returns ------- trimmed wire : OCCwire The trimmed OCCwire. """ gppnt1 = construct.make_gppnt(pypt1) gppnt2 = construct.make_gppnt(pypt2) trimmed = Construct.trim_wire(occwire, gppnt1, gppnt2, periodic= is_periodic ) return trimmed
def make_loft(occ_face_list, rule_face=True): #get the wires from the face_list wire_list = [] for f in occ_face_list: wires = fetch.wires_frm_face(f) wire_list.extend(wires) loft = Construct.make_loft(wire_list, ruled=rule_face) return loft
def fix_shape(occtopology): """ This function fixes an OCCtopology. Parameters ---------- occtopology : OCCtopology The OCCtopology to be fixed. OCCtopology includes: OCCshape, OCCcompound, OCCcompsolid, OCCsolid, OCCshell, OCCface, OCCwire, OCCedge, OCCvertex Returns ------- fixed topology : OCCtopology (OCCshape) The fixed OCCtopology. """ fixed_shape = Construct.fix_shape(occtopology) return fixed_shape
def srf_nrml_facing_solid_inward(occface, occsolid): """ This function checks if the OCCface is facing the inside of the OCCsolid. Parameters ---------- occface : OCCface The OCCface to be checked. occsolid : OCCsolid The OCCsolid. Returns ------- True or False : bool If True the face is facing the inside of the solid, if False the face is not facing inwards. """ #move the face in the direction of the normal #first offset the face so that vert will be within the solid o_wire = Construct.make_offset(occface, 0.0001) o_face = BRepBuilderAPI_MakeFace(o_wire).Face() wire_list = list(Topology.Topo(o_face).wires()) occpt_list = [] for wire in wire_list: occpts = Topology.WireExplorer(wire).ordered_vertices() occpt_list.extend(occpts) pt = BRep_Tool.Pnt(occpt_list[0]) #a point that is on the edge of the face normal = face_normal(occface) gp_direction2move = gp_Vec(normal[0], normal[1], normal[2]) gp_moved_pt = pt.Translated(gp_direction2move.Multiplied(0.001)) mv_pt = (gp_moved_pt.X(), gp_moved_pt.Y(), gp_moved_pt.Z()) in_solid = point_in_solid(occsolid, mv_pt) if in_solid: return True else: return False
def trim_wire(occ_wire, shapeLimit1, shapeLimit2, is_periodic=False): ''' occwire: wire to be trimmed type: occwire shapeLimit1: the 1st point where to cut the wire type: tuple, e.g. (0,1,2.5) shapeLimit1: the 2nd point where to cut the wire type: tuple, e.g. (0,1,2.5) is_periodic: indicate if the wire is open or close, true for close, false for open type: bool, e.g. True or False ''' trimmed = Construct.trim_wire(occ_wire, shapeLimit1, shapeLimit2, periodic=is_periodic) return trimmed
def make_wire_frm_edges(occ_edge_list): wire = Construct.make_wire(occ_edge_list) return wire
def rotate(shape, rot_pt, axis, degree): gp_ax3 = gp_Ax1(gp_Pnt(rot_pt[0], rot_pt[1], rot_pt[2]), gp_Dir(axis[0], axis[1], axis[2])) rot_shape = Construct.rotate(shape, gp_ax3, degree, copy=False) return rot_shape
def fix_face(occ_face): fixed_face = Construct.fix_face(occ_face) return fixed_face
def fix_shape(occ_shape): fixed_shape = Construct.fix_shape(occ_shape) return fixed_shape
def make_offset_face2wire(occ_face, offset_value): o_wire = Construct.make_offset(occ_face, offset_value) return fetch.shape2shapetype(o_wire)
def make_offset(occ_face, offset_value): o_wire = Construct.make_offset(occ_face, offset_value) occface = BRepBuilderAPI_MakeFace(o_wire) return occface.Face()
def make_compound(topo): return Construct.compound(topo)
def make_plane_w_dir(centre_pypt, normal_pydir): plane_face = Construct.make_plane( center=gp_Pnt(centre_pypt[0], centre_pypt[1], centre_pypt[2]), vec_normal=gp_Vec(normal_pydir[0], normal_pydir[1], normal_pydir[2])) return plane_face
def make_vertex(pypt): gppt = make_gppnt(pypt) vert = Construct.make_vertex(gppt) return vert
def boolean_difference(occshape2cutfrm, occ_cuttingshape): difference = Construct.boolean_cut(occshape2cutfrm, occ_cuttingshape) compound = fetch.shape2shapetype(difference) return compound
def boolean_fuse(occshape1, occshape2): fused = Construct.boolean_fuse(occshape1, occshape2) compound = fetch.shape2shapetype(fused) return compound
'upper': upper_curve, 'outer': outer_curve, 'lower': lower_curve, 'inner': inner_curve } TF = {} for part in TFprofile: segments = [] for curve in TFprofile[part]: pipe = BRepFill_PipeShell(TFcurve[curve].Wire()) for profile in TFprofile[part][curve]: pipe.Add(profile) pipe.Build() segments.append(pipe.Shape()) quilt = Construct.sew_shapes(segments) TF[part] = Construct.make_solid(quilt) # outer inter-coil supports OISloop = [[] for i in range(2)] pnt = [[] for i in range(2)] OISface = [[] for i in range(2)] yo = depth / 2 + side # coil half thickness ro = yo / np.arctan(theta) # radial offset for name in OISsupport: OISloop[0] = BRepBuilderAPI_MakePolygon() # inter-coil support for node in OISsupport[name]: pnt[0] = gp_Pnt(node[0], yo, node[1]) OISloop[0].Add(pnt[0]) OISloop[0].Close()
def make_loft_with_wires(occ_wire_list): loft = Construct.make_loft(occ_wire_list, ruled=False) return loft