Пример #1
0
def fillet(event=None):
    Box = BRepPrimAPI_MakeBox(gp_Pnt(-400, 0, 0), 200, 230, 180).Shape()
    fillet = BRepFilletAPI_MakeFillet(Box)
    # Add fillet on each edge
    for e in Topo(Box).edges():
        fillet.Add(20, e)

    blendedBox = fillet.Shape()

    P1 = gp_Pnt(250, 150, 75)
    S1 = BRepPrimAPI_MakeBox(300, 200, 200).Shape()
    S2 = BRepPrimAPI_MakeBox(P1, 120, 180, 70).Shape()
    Fuse = BRepAlgoAPI_Fuse(S1, S2)
    FusedShape = Fuse.Shape()

    fill = BRepFilletAPI_MakeFillet(FusedShape)
    for e in Topo(FusedShape).edges():
        fill.Add(e)

    for i in range(1, fill.NbContours() + 1):
        length = fill.Length(i)
        Rad = 0.15 * length
        fill.SetRadius(Rad, i, 1)

    blendedFusedSolids = fill.Shape()

    display.EraseAll()
    display.DisplayShape(blendedBox)
    display.DisplayShape(blendedFusedSolids)
    display.FitAll()
Пример #2
0
def clone_tooth(base_shape):
    clone = gp_Trsf()
    grouped_shape = base_shape

    # Find a divisor, between 1 and 8, for the number_of teeth
    multiplier = 1
    max_multiplier = 1
    for i in range(0, 8):
        if num_teeth % multiplier == 0:
            max_multiplier = i + 1

    multiplier = max_multiplier
    for i in range(1, multiplier):
        clone.SetRotation(gp_OZ(), -i * tooth_angle)
        rotated_shape = BRepBuilderAPI_Transform(base_shape, clone,
                                                 True).Shape()
        grouped_shape = BRepAlgoAPI_Fuse(grouped_shape, rotated_shape).Shape()

    # Rotate the basic tooth and fuse together
    aggregated_shape = grouped_shape
    for i in range(1, int(num_teeth / multiplier)):
        clone.SetRotation(gp_OZ(), -i * multiplier * tooth_angle)
        rotated_shape = BRepBuilderAPI_Transform(grouped_shape, clone,
                                                 True).Shape()
        aggregated_shape = BRepAlgoAPI_Fuse(aggregated_shape,
                                            rotated_shape).Shape()

    cylinder = BRepPrimAPI_MakeCylinder(gp_XOY(), top_radius - roller_diameter,
                                        thickness)
    aggregated_shape = BRepAlgoAPI_Fuse(aggregated_shape,
                                        cylinder.Shape()).Shape()

    return aggregated_shape
Пример #3
0
def boolean_fuse(shapeToCutFrom, joiningShape):
    from OCC.BRepAlgoAPI import BRepAlgoAPI_Fuse
    join = BRepAlgoAPI_Fuse(shapeToCutFrom, joiningShape)
    join.RefineEdges()
    join.FuseEdges()
    shape = join.Shape()
    #join.Destroy()
    return shape
def pipe_3(radius_pipe, radius_sphere):
    pipe1 = pipe(gp_Pnt(0, 0, 0), gp_Pnt(0, 0, 1), radius_pipe)
    sphere1 = sphere(gp_Pnt(0, 0, 1), radius_sphere)
    pipe2 = pipe(gp_Pnt(0, 0, 1), gp_Pnt(0, 1, 2), radius_pipe)
    sphere2 = sphere(gp_Pnt(0, 1, 2), radius_sphere)
    pipe3 = pipe(gp_Pnt(0, 1, 2), gp_Pnt(0, 2, 2), radius_pipe)
    glued1 = BRepAlgoAPI_Fuse(pipe1, sphere1).Shape()
    glued2 = BRepAlgoAPI_Fuse(glued1, pipe2).Shape()
    glued3 = BRepAlgoAPI_Fuse(glued2, sphere2).Shape()
    glued4 = BRepAlgoAPI_Fuse(glued3, pipe3).Shape()
    return glued4
Пример #5
0
def fuse(event=None):
    display.EraseAll()
    box1 = BRepPrimAPI_MakeBox(2, 1, 1).Shape()
    box2 = BRepPrimAPI_MakeBox(2, 1, 1).Shape()
    box1 = translate_topods_from_vector(box1, gp_Vec(.5, .5, 0))
    fuse_shp = BRepAlgoAPI_Fuse(box1, box2).Shape()
    display.DisplayShape(fuse_shp)
    display.FitAll()
Пример #6
0
 def createModel(self):
     Pnt = getGpPt(self.secOrigin)
     edges = makeEdgesFromPoints(self.points)
     wire = makeWireFromEdges(edges)
     aFace = makeFaceFromWire(wire)
     extrudeDir = self.L * (self.wDir)  # extrudeDir is a numpy array
     prism = makePrismFromFace(aFace, extrudeDir)
     my_sphere = BRepPrimAPI_MakeSphere(Pnt, 5.0).Shape()
     spherebody = BRepAlgoAPI_Fuse(prism, my_sphere).Shape()
     return prism
Пример #7
0
    def createModel(self):

        edges = makeEdgesFromPoints(self.points)
        wire = makeWireFromEdges(edges)
        aFace = makeFaceFromWire(wire)
        extrudeDir = -self.T * self.shaftDir  # extrudeDir is a numpy array
        boltHead = makePrismFromFace(aFace, extrudeDir)
        cylOrigin = self.origin
        boltCylinder = BRepPrimAPI_MakeCylinder(gp_Ax2(getGpPt(cylOrigin), getGpDir(self.shaftDir)), self.r, self.H).Shape()

        whole_Bolt = BRepAlgoAPI_Fuse(boltHead, boltCylinder).Shape()

        return whole_Bolt
Пример #8
0
    def create_model(self):

        edges = make_edges_from_points(self.points)
        wire = make_wire_from_edges(edges)
        aFace = make_face_from_wire(wire)
        extrudeDir = -self.T * self.shaft_dir  # extrudeDir is a numpy array
        boltHead = make_prism_from_face(aFace, extrudeDir)
        cylOrigin = self.origin
        boltCylinder = BRepPrimAPI_MakeCylinder(
            gp_Ax2(get_gp_pt(cylOrigin), get_gp_dir(self.shaft_dir)), self.r,
            self.H).Shape()

        whole_Bolt = BRepAlgoAPI_Fuse(boltHead, boltCylinder).Shape()

        return whole_Bolt
Пример #9
0
    def fuse(self, toFuse):
        """
        Fuse shapes together
        """

        fuse_op = BRepAlgoAPI_Fuse(self.wrapped, toFuse.wrapped)
        fuse_op.RefineEdges()
        fuse_op.FuseEdges()
        # fuse_op.SetFuzzyValue(TOLERANCE)
        fuse_op.Build()

        return Shape.cast(fuse_op.Shape())
Пример #10
0
def simple_mesh():
    #
    # Create the shape
    #
    shape = BRepPrimAPI_MakeBox(200, 200, 200).Shape()
    theBox = BRepPrimAPI_MakeBox(200, 60, 60).Shape()
    theSphere = BRepPrimAPI_MakeSphere(gp_Pnt(100, 20, 20), 80).Shape()
    shape = BRepAlgoAPI_Fuse(theSphere, theBox).Shape()
    #
    # Mesh the shape
    #
    BRepMesh_IncrementalMesh(shape, 0.8)
    builder = BRep_Builder()
    comp = TopoDS_Compound()
    builder.MakeCompound(comp)

    bt = BRep_Tool()
    ex = TopExp_Explorer(shape, TopAbs_FACE)
    while ex.More():
        face = topods_Face(ex.Current())
        location = TopLoc_Location()
        facing = (bt.Triangulation(face, location)).GetObject()
        tab = facing.Nodes()
        tri = facing.Triangles()
        for i in range(1, facing.NbTriangles()+1):
            trian = tri.Value(i)
            index1, index2, index3 = trian.Get()
            for j in range(1, 4):
                if j == 1:
                    m = index1
                    n = index2
                elif j == 2:
                    n = index3
                elif j == 3:
                    m = index2
                me = BRepBuilderAPI_MakeEdge(tab.Value(m), tab.Value(n))
                if me.IsDone():
                    builder.Add(comp, me.Edge())
        ex.Next()
    display.EraseAll()
    display.DisplayShape(shape)
    display.DisplayShape(comp, update=True)
Пример #11
0
 def createModel(self):
     
     edges = makeEdgesFromPoints(self.points)
     wire = makeWireFromEdges(edges)
     aFace = makeFaceFromWire(wire)
     extrudeDir = -self.T * self.shaftDir # extrudeDir is a numpy array
     boltHead =  makePrismFromFace(aFace, extrudeDir)
     mkFillet = BRepFilletAPI_MakeFillet(boltHead)
     anEdgeExplorer = TopExp_Explorer(boltHead, TopAbs_EDGE)
     while anEdgeExplorer.More():
         aEdge = topods.Edge(anEdgeExplorer.Current())
         mkFillet.Add(self.T / 17. , aEdge)
         anEdgeExplorer.Next()
             
     boltHead = mkFillet.Shape()
     cylOrigin = self.origin
   
     boltCylinder = BRepPrimAPI_MakeCylinder(gp_Ax2(getGpPt(cylOrigin), getGpDir(self.shaftDir)), self.r, self.H).Shape()
     whole_Bolt = BRepAlgoAPI_Fuse(boltHead,boltCylinder).Shape()
     mkFillet = BRepFilletAPI_MakeFillet(whole_Bolt)
     
     return whole_Bolt
    def create_single_assembly(self,
                               tire_radius,
                               wheel_radius,
                               struct_length,
                               scale=1):
        tire_radius = tire_radius
        wheel_radius = wheel_radius
        struct_length = struct_length

        straight_arm_height = tire_radius * 1.5

        ring_radius = wheel_radius
        torus_radius = tire_radius
        torus = BRepPrimAPI_MakeTorus(torus_radius, ring_radius).Shape()

        straight_arm_radius = ring_radius / 2

        straight_arm = BRepPrimAPI_MakeCylinder(straight_arm_radius,
                                                straight_arm_height).Shape()

        angled_arm_radius = straight_arm_radius
        angled_arm_height = tire_radius * 1.5
        angle = -40

        angled_arm = BRepPrimAPI_MakeCylinder(angled_arm_radius,
                                              angled_arm_height).Shape()
        traf = CTiglTransformation()
        traf.add_rotation_x(angle)
        angled_arm = traf.transform(angled_arm)
        traf = CTiglTransformation()
        traf.add_translation(0, angled_arm_height * sin(angle), 0)
        angled_arm = traf.transform(angled_arm)

        traf = CTiglTransformation()
        traf.add_translation(0, angled_arm_height * cos(angle),
                             angled_arm_height * sin(angle))
        straight_arm = traf.transform(straight_arm)
        arm_assembly = BRepAlgoAPI_Fuse(straight_arm, angled_arm).Shape()

        traf = CTiglTransformation()
        traf.add_rotation_x(90)
        torus = traf.transform(torus)

        pin_radius = wheel_radius
        pin_height = tire_radius

        pin = BRepPrimAPI_MakeCylinder(pin_radius, pin_height).Shape()

        traf = CTiglTransformation()
        traf.add_translation(0, 0, -straight_arm_height + torus_radius / 2)
        torus = traf.transform(torus)

        traf = CTiglTransformation()
        traf.add_rotation_x(90)
        pin = traf.transform(pin)

        traf = CTiglTransformation()
        traf.add_translation(0, 0, -straight_arm_height + pin_radius)
        pin = traf.transform(pin)

        traf = CTiglTransformation()
        traf.add_mirroring_at_xzplane()
        mirrored_arm_assembly = traf.transform(arm_assembly)

        traf = CTiglTransformation()
        traf.add_mirroring_at_xzplane()
        mirrored_pin = traf.transform(pin)

        arm_assembly = BRepAlgoAPI_Fuse(mirrored_arm_assembly,
                                        arm_assembly).Shape()

        struct_radius = wheel_radius - 0.5 * wheel_radius
        struct_height = struct_length
        struct = BRepPrimAPI_MakeCylinder(struct_radius, struct_height).Shape()
        traf = CTiglTransformation()
        traf.add_translation(0, 0, torus_radius)
        struct = traf.transform(struct)

        pin = BRepAlgoAPI_Fuse(mirrored_pin, pin).Shape()
        part_1 = BRepAlgoAPI_Fuse(arm_assembly, pin).Shape()
        part_2 = BRepAlgoAPI_Fuse(part_1, struct).Shape()
        part_3 = BRepAlgoAPI_Fuse(part_2, pin).Shape()

        return BRepAlgoAPI_Fuse(part_3, torus).Shape()
Пример #13
0
def boolean_fuse(base):
    ring_radius = 0.25
    torus_radius = 1.0 - ring_radius
    torus = BRepPrimAPI_MakeTorus(torus_radius, ring_radius).Shape()
    fuse = BRepAlgoAPI_Fuse(base, torus).Shape()
    return fuse
def brep_feat_extrusion_protrusion(event=None):
    #Extrusion 
    S = BRepPrimAPI_MakeBox(400.,250.,300.).Shape()
    faces = Topo(S).faces()
    F = faces.next()
    surf1 = BRep_Tool_Surface(F)
    
    Pl1 = Handle_Geom_Plane_DownCast(surf1).GetObject()
    
    D1 = Pl1.Pln().Axis().Direction().Reversed()
    MW = BRepBuilderAPI_MakeWire()
    p1,p2 = gp_Pnt2d(200.,-100.), gp_Pnt2d(100.,-100.) 
    aline = GCE2d_MakeLine(p1,p2).Value()
    MW.Add(BRepBuilderAPI_MakeEdge(aline,surf1,0.,p1.Distance(p2)).Edge())
    
    p1,p2 = gp_Pnt2d(100.,-100.), gp_Pnt2d(100.,-200.)
    aline = GCE2d_MakeLine(p1,p2).Value()
    MW.Add(BRepBuilderAPI_MakeEdge(aline,surf1,0.,p1.Distance(p2)).Edge())
    
    p1,p2 = gp_Pnt2d(100.,-200.), gp_Pnt2d(200.,-200.)
    aline = GCE2d_MakeLine(p1,p2).Value()
    MW.Add(BRepBuilderAPI_MakeEdge(aline,surf1,0.,p1.Distance(p2)).Edge())
    
    p1,p2 = gp_Pnt2d(200.,-200.), gp_Pnt2d(200.,-100.)
    aline = GCE2d_MakeLine(p1,p2).Value()
    MW.Add(BRepBuilderAPI_MakeEdge(aline,surf1,0.,p1.Distance(p2)).Edge())
    
    MKF = BRepBuilderAPI_MakeFace() 
    MKF.Init(surf1,False,1e-6)
    MKF.Add(MW.Wire())
    FP = MKF.Face()
    BRepLib_BuildCurves3d(FP)
#    MKP = BRepFeat_MakePrism(S,FP,F,D1,0,True)
#    MKP.Perform(-200)
#    print 'depth 200'
#    res1 = MKP.Shape()
#    display.DisplayShape(res1)
#    time.sleep(1)
    
    display.EraseAll()
    MKP = BRepFeat_MakePrism(S,FP,F,D1,0,True)
    MKP.PerformThruAll()
    print 'depth thru all'
    res1 = MKP.Shape()
#    display.DisplayShape(res1)
    
    # Protrusion
    faces.next()  
    F2 = faces.next()
    surf2 = BRep_Tool_Surface(F2)
    Pl2 = Handle_Geom_Plane_DownCast(surf2).GetObject()
    D2 = Pl2.Pln().Axis().Direction().Reversed()
    MW2 = BRepBuilderAPI_MakeWire() 
    p1, p2 = gp_Pnt2d(100.,100.), gp_Pnt2d(200.,100.)
#    p1, p2 = gp_Pnt2d(100.,100.), gp_Pnt2d(150.,100.)
    aline = GCE2d_MakeLine(p1,p2).Value()
    MW2.Add(BRepBuilderAPI_MakeEdge(aline,surf2,0.,p1.Distance(p2)).Edge())

    p1, p2 = gp_Pnt2d(200.,100.), gp_Pnt2d(150.,200.)
    aline = GCE2d_MakeLine(p1,p2).Value()
    MW2.Add(BRepBuilderAPI_MakeEdge(aline,surf2,0.,p1.Distance(p2)).Edge())

    p1, p2 = gp_Pnt2d(150.,200.), gp_Pnt2d(100.,100.)
    aline = GCE2d_MakeLine(p1,p2).Value()
    MW2.Add(BRepBuilderAPI_MakeEdge(aline,surf2,0.,p1.Distance(p2)).Edge())

    MKF2 = BRepBuilderAPI_MakeFace()
    MKF2.Init(surf2,False,1e-6)
    MKF2.Add(MW2.Wire())
    MKF2.Build()
    
#    display.DisplayShape(MW2.Wire())
    
    FP = MKF2.Face()
    BRepLib_BuildCurves3d(FP)
    MKP2 = BRepFeat_MakePrism(res1,FP,F2,D2,0,True)
    MKP2.PerformThruAll()
    display.EraseAll()
#    display.DisplayShape(MKP2.Shape())
    
    trf = gp_Trsf()
    trf.SetTranslation(gp_Vec(0,0,300))
    gtrf = gp_GTrsf()
    gtrf.SetTrsf(trf)
    tr = BRepBuilderAPI_GTransform(MKP2.Shape(), gtrf, True)
    
    
    from OCC.BRepAlgoAPI import BRepAlgoAPI_Fuse
    fused = BRepAlgoAPI_Fuse(tr.Shape(), MKP2.Shape())
    fused.RefineEdges()
    fused.Build()
    print 'boolean operation error status:', fused.ErrorStatus()
    display.DisplayShape(fused.Shape())
Пример #15
0
def union(shp1: TopoDS_Shape, shp2: TopoDS_Shape, merge=False) -> TopoDS_Shape:
    """ shp1 + shape2 """
    intrs = BRepAlgoAPI_Fuse(shp1, shp2)
    return _bool_op(intrs)
Пример #16
0
 def _do_operation(self,shape1,shape2):
     d = self.declaration
     args = [shape1,shape2]
     if d.pave_filler:
         args.append(d.pave_filler)
     return BRepAlgoAPI_Fuse(*args)
Пример #17
0
BIHSm = 0.5                       # height of small CI
BIRLg = 4                         # radius of large CI
BIHLg = float(BIRLg*BIHSm)/BIRSm  # height of large CI (proportional)
BIS = 0.5                         # seperation between CIs

BIHPack = BIHSm+BIHLg+2*BIS  # pack length
BIno = int(BCL//BIHPack)     # number of packs fitted into core length
BIrem = BCL % BIHPack        # remainder length

# building bushing shape
Btap = BRepPrimAPI_MakeCylinder(BOR,BTL).Shape()
p = gp_Ax2(gp_Pnt(0,0,BTL),gp_DZ())     # placement
Bcore = BRepPrimAPI_MakeCylinder(p,BCR,BCL).Shape()
p = gp_Ax2(gp_Pnt(0,0,BTL+BCL),gp_DZ()) # placement
Bhead = BRepPrimAPI_MakeCylinder(p,BOR,BHL).Shape()
bushing = BRepAlgoAPI_Fuse(Btap, Bcore).Shape()
bushing = BRepAlgoAPI_Fuse(bushing, Bhead).Shape()

# adding composite insulators to shape
BIinit = BTL+float(BIrem)/2+BIS     # initial height for first cone
for i in range(0,BIno):
	Bconez = BIinit + i*BIHPack # local height for cones
  	p = gp_Ax2(gp_Pnt(0,0,Bconez),gp_DZ())           # placement
	BconeLg = BRepPrimAPI_MakeCone(p,BIRLg,BCR,BIHLg).Shape()
  	bushing = BRepAlgoAPI_Fuse(bushing, BconeLg).Shape()
  	p = gp_Ax2(gp_Pnt(0,0,Bconez+BIHLg+BIS),gp_DZ()) # placement
	BconeSm = BRepPrimAPI_MakeCone(p,BIRSm,BCR,BIHSm).Shape()
	bushing = BRepAlgoAPI_Fuse(bushing, BconeSm).Shape()

BSIN = BOR*math.sin(math.radians(BA)) ; BCOS = BOR*math.cos(math.radians(BA))
Пример #18
0
  def char_to_solid(self, glyph):

    layer = glyph.layers['Fore']
    bodies = []
    
    for contour in layer:
      i = 0
      total = len(contour)
      curve_points = []

      if total <= 2:
        # Can't make solid out of 1 or 2 points
        continue

      wire = BRepBuilderAPI_MakeWire()
      for point in contour:
        if point.on_curve:
          if i > 0:
            # Complete old curve
            curve_points.append(gp_Pnt(point.x, point.y, 0))
            self.add_to_wire(curve_points, wire)

          if i < total:
            # Start new curve
            curve_points = [gp_Pnt(point.x, point.y, 0)]

          if i == total-1:
            first = contour[0]
            curve_points.append(gp_Pnt(first.x, first.y, 0))
            self.add_to_wire(curve_points, wire)
        else:
          curve_points.append(gp_Pnt(point.x, point.y, 0))
          if i == total-1:
            first = contour[0]
            curve_points.append(gp_Pnt(first.x, first.y, 0))
            self.add_to_wire(curve_points, wire)
        i += 1

      face = BRepBuilderAPI_MakeFace(wire.Wire())
      extrusion_vector = gp_Vec(0, 0, self.thickness)
      prism = BRepPrimAPI_MakePrism(face.Shape(), extrusion_vector)

      bodies.append(dict(
        prism = prism,
        isClockwise = contour.isClockwise(),
      ))

    if len(bodies) > 0:
      if len(bodies) == 1:
        return bodies[0]['prism'].Shape()
      elif len(bodies) > 1:
        final = None
        positive_union = None
        for body in bodies:
          if body['isClockwise'] == 1:
            if positive_union:
              positive_union = BRepAlgoAPI_Fuse(
                positive_union.Shape(), body['prism'].Shape())
            else:
              positive_union = body['prism']

        negative_union = None
        for body in bodies:
          if body['isClockwise'] == 0:
            if negative_union:
              negative_union = BRepAlgoAPI_Fuse(
                negative_union.Shape(), body['prism'].Shape())
            else:
              negative_union = body['prism']
        
        if positive_union and negative_union:
          final = BRepAlgoAPI_Cut(
            positive_union.Shape(), negative_union.Shape())
        elif positive_union:
          final = positive_union
        elif negative_union:
          final = negative_union
        return final.Shape()
    anEdgeExplorer.Next()

myBody = mkFillet

# Create the neck of the bottle
neckLocation = gp_Pnt(0, 0, height)
neckAxis = gp_DZ()
neckAx2 = gp_Ax2(neckLocation, neckAxis)

myNeckRadius = thickness / 4.0
myNeckHeight = height / 10.0

mkCylinder = BRepPrimAPI_MakeCylinder(neckAx2, myNeckRadius, myNeckHeight)

myBody = BRepAlgoAPI_Fuse(myBody.Shape(), mkCylinder.Shape())

# Our goal is to find the highest Z face and remove it
faceToRemove = None
zMax = -1

# We have to work our way through all the faces to find
# the highest Z face so we can remove it for the shell
aFaceExplorer = TopExp_Explorer(myBody.Shape(), TopAbs_FACE)
while aFaceExplorer.More():
    aFace = topods.Face(aFaceExplorer.Current())

    if face_is_plane(aFace):
        aPlane = geom_plane_from_face(aFace)

        # We want the highest Z face, so compare this to the previous faces