Ejemplo n.º 1
0
def makeEllipticalAnnularSolid(rx_outer, ry_outer, rx_inner, ry_inner, z_min,
                               z_max):

    # Make the outer part of the clamp
    ax = gp_Ax2(gp_Pnt(0, 0, z_min), gp_Dir(0, 0, 1), gp_Dir(1, 0, 0))
    ge = Geom_Ellipse(ax, rx_outer, ry_outer)
    elip = ge.Elips()
    me = BRepBuilderAPI_MakeEdge(elip, 0, 2 * pi)
    edge = me.Edge()
    mw = BRepBuilderAPI_MakeWire(edge)
    wire = mw.Wire()
    pln = gp_Pln(gp_Pnt(0, 0, z_min), gp_Dir(0, 0, 1))
    mf = BRepBuilderAPI_MakeFace(pln, wire)
    face = mf.Face()
    mp = BRepPrimAPI_MakePrism(face, gp_Vec(0, 0, z_max - z_min))
    body = mp.Shape()

    # Make the cutter for the inner hole body
    ax = gp_Ax2(gp_Pnt(0, 0, z_min - 1), gp_Dir(0, 0, 1), gp_Dir(1, 0, 0))
    ge = Geom_Ellipse(ax, rx_inner, ry_inner)
    elip = ge.Elips()
    me = BRepBuilderAPI_MakeEdge(elip, 0, 2 * pi)
    edge = me.Edge()
    mw = BRepBuilderAPI_MakeWire(edge)
    wire = mw.Wire()
    pln = gp_Pln(gp_Pnt(0, 0, z_min - 1), gp_Dir(0, 0, 1))
    mf = BRepBuilderAPI_MakeFace(pln, wire)
    face = mf.Face()
    mp = BRepPrimAPI_MakePrism(face, gp_Vec(0, 0, z_max + 1))
    innerHoleCutter = mp.Shape()

    # Cut out the middle
    mc = BRepAlgoAPI_Cut(body, innerHoleCutter)
    return mc.Shape()
Ejemplo n.º 2
0
def boolean_cut(base):
    # Create a cylinder
    cylinder_radius = 0.25
    cylinder_height = 2.0
    cylinder_origin = gp_Ax2(gp_Pnt(0.0, 0.0, -cylinder_height / 2.0),
                             gp_Dir(0.0, 0.0, 1.0))
    cylinder = BRepPrimAPI_MakeCylinder(cylinder_origin, cylinder_radius,
                                        cylinder_height)

    # Repeatedly move and subtract it from the input shape
    move = gp_Trsf()
    boolean_result = base
    clone_radius = 1.0

    for clone in range(8):
        angle = clone * pi / 4.0
        # Move the cylinder
        move.SetTranslation(
            gp_Vec(cos(angle) * clone_radius,
                   sin(angle) * clone_radius, 0.0))
        moved_cylinder = BRepBuilderAPI_Transform(cylinder.Shape(), move,
                                                  True).Shape()
        # Subtract the moved cylinder from the drilled sphere
        boolean_result = BRepAlgoAPI_Cut(boolean_result,
                                         moved_cylinder).Shape()
    return boolean_result
Ejemplo n.º 3
0
    def get_beamRModel(self):
        '''

        Returns: Wholes in right beam

        '''
        final_beam = self.beamRModel
        bolt_listRA = self.nut_bolt_array_AF.get_bolt_listRA()
        bolt_listRB = self.nut_bolt_array_BF.get_bolt_listRB()
        bolt_listWR = self.nut_bolt_array_Web.get_bolt_web_list()
        for boltRB in bolt_listRB[:]:
            final_beam = BRepAlgoAPI_Cut(final_beam, boltRB).Shape()
        for boltRA in bolt_listRA[:]:
            final_beam = BRepAlgoAPI_Cut(final_beam, boltRA).Shape()
        for boltWR in bolt_listWR[:]:
            final_beam = BRepAlgoAPI_Cut(final_beam, boltWR).Shape()
        return final_beam
Ejemplo n.º 4
0
    def get_beamLModel(self):
        '''

        Returns: Wholes in left beam

        '''
        final_beam = self.beamLModel
        bolt_listLA = self.nut_bolt_array_AF.get_bolt_listLA()
        bolt_listLB = self.nut_bolt_array_BF.get_bolt_listLB()
        bolt_listWL = self.nut_bolt_array_Web.get_bolt_web_list()
        for boltLB in bolt_listLB[:]:
            final_beam = BRepAlgoAPI_Cut(final_beam, boltLB).Shape()
        for boltLA in bolt_listLA[:]:
            final_beam = BRepAlgoAPI_Cut(final_beam, boltLA).Shape()
        for boltWL in bolt_listWL[:]:
            final_beam = BRepAlgoAPI_Cut(final_beam, boltWL).Shape()
        return final_beam
    def get_columnModel(self):

        final_col = self.columnModel
        nut_bolt_list = self.nut_bolt_array.get_colbolts()

        for bolt in nut_bolt_list[:]:
            final_col = BRepAlgoAPI_Cut(final_col, bolt).Shape()
        return final_col
    def get_beamModel(self):

        final_beam = self.beamModel
        nut_bolt_list = self.nut_bolt_array.get_beambolts()

        for bolt in nut_bolt_list[:]:
            final_beam = BRepAlgoAPI_Cut(final_beam, bolt).Shape()
        return final_beam
Ejemplo n.º 7
0
def mounting_holes(base):
    result = base
    for i in range(0, mounting_hole_count):
        center = gp_Pnt(
            cos(i * M_PI / 3) * mounting_radius,
            sin(i * M_PI / 3) * mounting_radius, 0.0)
        center_axis = gp_Ax2(center, gp_DZ())

        cylinder = BRepPrimAPI_MakeCylinder(center_axis, hole_radius,
                                            thickness).Shape()
        result = BRepAlgoAPI_Cut(result, cylinder).Shape()

        cone = BRepPrimAPI_MakeCone(center_axis, hole_radius + thickness / 2.,
                                    hole_radius, thickness / 2.)
        result = BRepAlgoAPI_Cut(result, cone.Shape()).Shape()

    return result
Ejemplo n.º 8
0
    def extrudeLinearWithRotation(cls, outerWire, innerWires, vecCenter,
                                  vecNormal, angleDegrees):
        """
            Creates a 'twisted prism' by extruding, while simultaneously rotating around the extrusion vector.

            Though the signature may appear to be similar enough to extrudeLinear to merit combining them, the
            construction methods used here are different enough that they should be separate.

            At a high level, the steps followed are:
            (1) accept a set of wires
            (2) create another set of wires like this one, but which are transformed and rotated
            (3) create a ruledSurface between the sets of wires
            (4) create a shell and compute the resulting object

            :param outerWire: the outermost wire, a cad.Wire
            :param innerWires: a list of inner wires, a list of cad.Wire
            :param vecCenter: the center point about which to rotate.  the axis of rotation is defined by
                   vecNormal, located at vecCenter. ( a cad.Vector )
            :param vecNormal: a vector along which to extrude the wires ( a cad.Vector )
            :param angleDegrees: the angle to rotate through while extruding
            :return: a cad.Solid object
        """
        # make straight spine
        straight_spine_e = Edge.makeLine(vecCenter, vecCenter.add(vecNormal))
        straight_spine_w = Wire.combine([
            straight_spine_e,
        ]).wrapped

        # make an auxliliary spine
        pitch = 360. / angleDegrees * vecNormal.Length
        radius = 1
        aux_spine_w = Wire.makeHelix(pitch,
                                     vecNormal.Length,
                                     radius,
                                     center=vecCenter,
                                     dir=vecNormal).wrapped

        # extrude the outer wire
        outer_solid = cls._extrudeAuxSpine(outerWire.wrapped, straight_spine_w,
                                           aux_spine_w)

        # extrude inner wires
        inner_solids = [
            cls._extrudeAuxSpine(w.wrapped, straight_spine_w.aux_spine_w)
            for w in innerWires
        ]

        # combine dthe inner solids into compund
        inner_comp = TopoDS_Compound()
        comp_builder = TopoDS_Builder()
        comp_builder.MakeCompound(inner_comp)  # TODO this could be not needed

        for i in inner_solids:
            comp_builder.Add(inner_comp, i)

        # subtract from the outer solid
        return cls(BRepAlgoAPI_Cut(outer_solid, inner_comp).Shape())
Ejemplo n.º 9
0
 def get_columnModel(self):
     finalBeam = self.columnModel
     nutBoltlist = self.nutBoltArray.getModels()
     for bolt in nutBoltlist[:]:
         finalBeam = BRepAlgoAPI_Cut(finalBeam,bolt).Shape()
     return finalBeam
 
 
 
     
Ejemplo n.º 10
0
    def get_plateBelwFlangeModel(self):
        '''

        Returns: Wholes in below plate of flange

        '''
        final_plateBP = self.plateBelwFlangeModel
        bolt_listBP = self.nut_bolt_array_BF.get_bolt_listRB()
        for boltBP in bolt_listBP[:]:
            final_plateBP = BRepAlgoAPI_Cut(final_plateBP, boltBP).Shape()
        return final_plateBP
Ejemplo n.º 11
0
    def get_plateAbvFlangeModel(self):
        '''

        Returns: Wholes in above plate of flange

        '''
        final_plateAP = self.plateAbvFlangeModel
        bolt_listAP = self.nut_bolt_array_AF.get_bolt_listLA()
        for boltAP in bolt_listAP[:]:
            final_plateAP = BRepAlgoAPI_Cut(final_plateAP, boltAP).Shape()
        return final_plateAP
Ejemplo n.º 12
0
    def get_WebPlateLeftModel(self):
        '''

        Returns: Wholes in left webplate

        '''
        final_plateLP = self.WebPlateLeftModel
        bolt_listLP = self.nut_bolt_array_Web.get_bolt_web_list()
        for boltLP in bolt_listLP[:]:
            final_plateLP = BRepAlgoAPI_Cut(final_plateLP, boltLP).Shape()
        return final_plateLP
Ejemplo n.º 13
0
    def get_innerplateAbvFlangeBack(self):
        '''

        Returns: Wholes in inner back plate of above flange

        '''
        final = self.innerplateAbvFlangeBackModel
        bolt = self.nut_bolt_array_AF.get_bolt_listLA()
        for a in bolt[:]:
            final = BRepAlgoAPI_Cut(final, a).Shape()
        return final
Ejemplo n.º 14
0
    def get_WebPlateRightModel(self):
        '''

        Returns: Wholes in right webplate

        '''
        final_plateRP = self.WebPlateRightModel
        bolt_listRP = self.nut_bolt_array_Web.get_bolt_web_list()
        for boltRP in bolt_listRP[:]:
            final_plateRP = BRepAlgoAPI_Cut(final_plateRP, boltRP).Shape()
        return final_plateRP
Ejemplo n.º 15
0
def min_cylinder(height_dimension, shape, bounding_box):
    axis = get_axis(height_dimension, bounding_box)
    lengths = pick_lengths(bounding_box)
    height_length = height_dimension + '_length'
    height = bounding_box[height_length]
    radius = max(
        [value
         for key, value in lengths.iteritems() if key != height_length]) / 2
    cylinder = BRepPrimAPI_MakeCylinder(axis, radius, height)
    cut = BRepAlgoAPI_Cut(shape, cylinder.Shape())
    return cylinder_dict(cylinder, cut, radius, height)
Ejemplo n.º 16
0
    def get_innerplateBelwFlangeBack(self):
        '''

        Returns: Wholes in inner back plate of below flange

        '''
        final = self.innerplateBelwFlangeBackModel
        bolt = self.nut_bolt_array_BF.get_bolt_listRB()
        for a in bolt[:]:
            final = BRepAlgoAPI_Cut(final, a).Shape()
        return final
Ejemplo n.º 17
0
def cut(event=None):
    # Create Box
    Box = BRepPrimAPI_MakeBox(200, 60, 60).Shape()
    # Create Sphere
    Sphere = BRepPrimAPI_MakeSphere(gp_Pnt(100, 20, 20), 80).Shape()
    # Cut: the shere is cut 'by' the box
    Cut = BRepAlgoAPI_Cut(Sphere, Box).Shape()
    display.EraseAll()
    ais_box = display.DisplayShape(Box)
    display.Context.SetTransparency(ais_box, 0.8)
    display.DisplayShape(Cut)
    display.FitAll()
Ejemplo n.º 18
0
    def Shape(self):
        ball_vecs = []
        for i in self.balls:
            ball_vecs.append(gp_Vec(i.getPnt().XYZ()))
        v_ball_to_ball = ball_vecs[1] - ball_vecs[0]
        ax = gp_Ax2(gp_Pnt(ball_vecs[0].XYZ()), gp_Dir(v_ball_to_ball.XYZ()))
        mcyl = BRepPrimAPI_MakeCylinder(ax, self.d_o / 2.0,
                                        v_ball_to_ball.Magnitude())
        cyl = mcyl.Shape()
        mch = BRepFilletAPI_MakeChamfer(cyl)

        endFaces = []
        for face in Topo(cyl).faces():
            adaptor = BRepAdaptor_Surface(face)
            if adaptor.GetType() == GeomAbs_Plane:
                endFaces.append(face)
                for edge in Topo(face).edges():
                    mch.Add(self.chamfer_distance, edge, face)
        try:
            chamferedCyl = mch.Shape()
        except:
            chamferedCyl = cyl
            print("chamfer on ForceTransferCylinder failed!")
        mc = BRepAlgoAPI_Cut(chamferedCyl, self.balls[0].Shape())
        mc = BRepAlgoAPI_Cut(mc.Shape(), self.balls[1].Shape())
        return mc.Shape()
Ejemplo n.º 19
0
def subtract(shape1, shape2):
    """Boolean difference of two shapes.

    Parameters
    ----------
    shape1, shape2 : TopoDS_Shape
        Surfaces.

    Returns
    -------
    difference : TopoDS_Shape
        The set difference :code:`shape1 \ shape2`.

    Notes
    -----
    The implementation follows the following sources:

    - https://techoverflow.net/2019/06/14/how-to-fuse-topods_shapes-in-opencascade-boolean-and/
    - https://github.com/tpaviot/pythonocc-demos/blob/master/examples/core_boolean_fuzzy_cut_emmenthaler.py#L41-L54

    For Boolean operations in Open CASCADE, see its `documentation
    <https://dev.opencascade.org/doc/overview/html/specification__boolean_operations.html>`_.

    """
    arguments = TopTools_ListOfShape()
    arguments.Append(shape1)
    tools = TopTools_ListOfShape()
    tools.Append(shape2)
    difference = BRepAlgoAPI_Cut()
    difference.SetTools(tools)
    difference.SetArguments(arguments)
    difference.Build()
    return difference.Shape()
def fuzzy_cut(shape_A, shape_B, tol=5e-5, parallel=False):
    """ returns shape_A - shape_B
    """
    cut = BRepAlgoAPI_Cut()
    L1 = TopTools_ListOfShape()
    L1.Append(shape_A)
    L2 = TopTools_ListOfShape()
    L2.Append(shape_B)
    cut.SetArguments(L1)
    cut.SetTools(L2)
    cut.SetFuzzyValue(tol)
    cut.SetRunParallel(parallel)
    cut.Build()
    return cut.Shape()
Ejemplo n.º 21
0
	def test_calculate_bb_dimensions_triangulate(self):
		a = gp_Pnt(-1, -1, -1)
		b = gp_Pnt(3, 3, 3)

		box = BRepPrimAPI_MakeBox(a, b).Shape()
		sphere = BRepPrimAPI_MakeSphere(3).Shape()
		section = BRepAlgoAPI_Cut(box, sphere).Shape()
		params = ffdp.FFDParameters()
		xyz_min, xyz_max = params._calculate_bb_dimension(section, triangulate=True)
		correct_min = -1 * np.ones(3)
		correct_max = 3 * np.ones(3)
		np.testing.assert_almost_equal(xyz_min, correct_min, decimal=1)
		np.testing.assert_almost_equal(xyz_max, correct_max, decimal=1)
Ejemplo n.º 22
0
    def create_model(self):

        edges = makeEdgesFromPoints(self.points)
        wire = makeWireFromEdges(edges)
        aFace = makeFaceFromWire(wire)
        extrudeDir = self.T * self.wDir  # extrudeDir is a numpy array
        prism = makePrismFromFace(aFace, extrudeDir)

        cylOrigin = self.sec_origin
        innerCyl = BRepPrimAPI_MakeCylinder(gp_Ax2(getGpPt(cylOrigin), getGpDir(self.wDir)), self.r1, self.H).Shape()

        result_shape = BRepAlgoAPI_Cut(prism, innerCyl).Shape()

        return result_shape
Ejemplo n.º 23
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.wDir  # extrudeDir is a numpy array
        prism = make_prism_from_face(aFace, extrudeDir)

        cylOrigin = self.sec_origin
        innerCyl = BRepPrimAPI_MakeCylinder(gp_Ax2(get_gp_pt(cylOrigin), get_gp_dir(self.wDir)), self.r1, self.H).Shape()

        result_shape = BRepAlgoAPI_Cut(prism, innerCyl).Shape()

        return result_shape
Ejemplo n.º 24
0
def boolean_cut(shapeToCutFrom, cuttingShape):
    from OCC.BRepAlgoAPI import BRepAlgoAPI_Cut
    try:
        cut = BRepAlgoAPI_Cut(shapeToCutFrom, cuttingShape)
        #print("Can work?", cut.BuilderCanWork())
        _error = {
            0: '- Ok',
            1: '- The Object is created but Nothing is Done',
            2: '- Null source shapes is not allowed',
            3: '- Check types of the arguments',
            4: '- Can not allocate memory for the DSFiller',
            5: '- The Builder can not work with such types of arguments',
            6: '- Unknown operation is not allowed',
            7: '- Can not allocate memory for the Builder',
        }
        #print("Error status:", _error[cut.ErrorStatus()])
        cut.RefineEdges()
        cut.FuseEdges()
        shp = cut.Shape()
        #cut.Destroy()
        return shp
    except:
        print("Failed to boolean cut")
        return shapeToCutFrom
def boolean_cut(shapeToCutFrom, cuttingShape, debug=False):
    """Boolean cut tool from PythonOCC-Utils"""
    try:

        cut = BRepAlgoAPI_Cut(shapeToCutFrom, cuttingShape)
        if debug:
            print(('can work?'), cut.BuilderCanWork())
            _error = {0: '- Ok',
                      1: '- The Object is created but Nothing is Done',
                      2: '- Null source shapes is not allowed',
                      3: '- Check types of the arguments',
                      4: '- Can not allocate memory for the DSFiller',
                      5: '- The Builder can not work with such types of arguments',
                      6: '- Unknown operation is not allowed',
                      7: '- Can not allocate memory for the Builder',
                      }
            print(('error status:'), _error[cut.ErrorStatus()])
        #        cut.RefineEdges()
        shp = cut.Shape()

        return shp
    except:
        print('FAILED TO BOOLEAN CUT')
        return shapeToCutFrom
Ejemplo n.º 26
0
def smallest_max_cylinder(shape, bounding_box):
    # cylinder with diagonal of smaller face of bounding box
    height, longest_dimension = get_longest_dimension(bounding_box)
    longest_length = longest_dimension + '_length'

    lengths = pick_lengths(bounding_box)
    face_sides = [
        value for key, value in lengths.iteritems() if key != longest_length
    ]
    radius = math.sqrt(sum([i**2 for i in face_sides])) / 2  # diagonal / 2

    axis = get_axis(longest_dimension, bounding_box)
    cylinder = BRepPrimAPI_MakeCylinder(axis, radius, height)
    cut = BRepAlgoAPI_Cut(shape, cylinder.Shape())
    return cylinder_dict(cylinder, cut, radius, height)
Ejemplo n.º 27
0
    def create_model(self):

        edges = makeEdgesFromPoints(self.points)
        wire = makeWireFromEdges(edges)
        aFace = makeFaceFromWire(wire)
        extrudeDir = self.length * self.wDir  # extrudeDir is a numpy array
        prism = makePrismFromFace(aFace, extrudeDir)

        if self.notchObj is not None:
            uDir = numpy.array([-1.0, 0.0, 0])
            wDir = numpy.array([0.0, 1.0, 0.0])
            shiftOri = self.D / 2.0 * self.vDir + self.notchObj.width / 2.0 * self.wDir + self.B / 2.0 * -self.uDir  # + self.notchObj.width* self.wDir + self.T/2.0 * -self.uDir
            origin2 = self.sec_origin + shiftOri

            self.notchObj.place(origin2, uDir, wDir)

            notchModel = self.notchObj.create_model()
            prism = BRepAlgoAPI_Cut(prism, notchModel).Shape()

        return prism
Ejemplo n.º 28
0
def revolved_cut(base):
    # Define 7 points
    face_points = TColgp_Array1OfPnt(1, 7)
    face_inner_radius = 0.6

    pts = [
        gp_Pnt(face_inner_radius - 0.05, 0.0, -0.05),
        gp_Pnt(face_inner_radius - 0.10, 0.0, -0.025),
        gp_Pnt(face_inner_radius - 0.10, 0.0, 0.025),
        gp_Pnt(face_inner_radius + 0.10, 0.0, 0.025),
        gp_Pnt(face_inner_radius + 0.10, 0.0, -0.025),
        gp_Pnt(face_inner_radius + 0.05, 0.0, -0.05),
        gp_Pnt(face_inner_radius - 0.05, 0.0, -0.05),
    ]

    for n, i in enumerate(pts):
        face_points.SetValue(n + 1, i)

    # Use these points to create edges and add these edges to a wire
    hexwire = BRepBuilderAPI_MakeWire()

    for i in range(1, 7):
        hexedge = BRepBuilderAPI_MakeEdge(face_points.Value(i),
                                          face_points.Value(i + 1)).Edge()
        hexwire.Add(hexedge)

    # Turn the wire into a 6 sided face
    hexface = BRepBuilderAPI_MakeFace(hexwire.Wire()).Face()

    # Revolve the face around an axis
    revolve_axis = gp_Ax1(gp_Pnt(0, 0, 0), gp_Dir(0, 0, 1))
    revolved_shape = BRepPrimAPI_MakeRevol(hexface, revolve_axis).Shape()

    # Move the generated shape
    move = gp_Trsf()
    move.SetTranslation(gp_Pnt(0, 0, 0), gp_Pnt(0, 0, sin(0.5)))
    moved_shape = BRepBuilderAPI_Transform(revolved_shape, move, False).Shape()

    # Remove the revolved shape
    cut = BRepAlgoAPI_Cut(base, moved_shape).Shape()
    return cut
Ejemplo n.º 29
0
    def createModel(self):
        edges = makeEdgesFromPoints(self.points)
        wire = makeWireFromEdges(edges)
        aFace = makeFaceFromWire(wire)
        extrudeDir = self.T * self.wDir # extrudeDir is a numpy array
        prism =  makePrismFromFace(aFace, extrudeDir)
        mkFillet = BRepFilletAPI_MakeFillet(prism)
        anEdgeExplorer = TopExp_Explorer(prism, TopAbs_EDGE)
        while anEdgeExplorer.More():
            aEdge = topods.Edge(anEdgeExplorer.Current())
            mkFillet.Add(self.T / 17. , aEdge)
            anEdgeExplorer.Next()
                
        prism = mkFillet.Shape()
        cylOrigin = self.secOrigin
        innerCyl = BRepPrimAPI_MakeCylinder(gp_Ax2(getGpPt(cylOrigin), getGpDir(self.wDir)), self.r1, self.H).Shape()
        result_shape = BRepAlgoAPI_Cut(prism, innerCyl).Shape()

        return result_shape
    
            
Ejemplo n.º 30
0
    def create_model(self):

        edges = make_edges_from_points(self.points)
        wire = make_wire_from_edges(edges)
        aFace = make_face_from_wire(wire)
        extrude_dir = self.length * self.wDir  # extrude_dir is a numpy array
        prism = make_prism_from_face(aFace, extrude_dir)

        if self.notch_obj is not None:
            uDir = numpy.array([-1.0, 0.0, 0])
            wDir = numpy.array([0.0, 1.0, 0.0])
            shift_origin = self.D / 2.0 * self.vDir + self.notch_obj.width / 2.0 * self.wDir + self.B / 2.0 * -self.uDir
            # + self.notch_obj.width* self.wDir + self.T/2.0 * -self.uDir
            origin2 = self.sec_origin + shift_origin

            self.notch_obj.place(origin2, uDir, wDir)

            notch_model = self.notch_obj.create_model()
            prism = BRepAlgoAPI_Cut(prism, notch_model).Shape()

        return prism