Beispiel #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()
Beispiel #2
0
    def extrudeLinear(cls, outerWire, innerWires, vecNormal):
        """
            Attempt to extrude the list of wires  into a prismatic solid in the provided direction

            :param outerWire: the outermost wire
            :param innerWires: a list of inner wires
            :param vecNormal: a vector along which to extrude the wires
            :return: a Solid object

            The wires must not intersect

            Extruding wires is very non-trivial.  Nested wires imply very different geometry, and
            there are many geometries that are invalid. In general, the following conditions must be met:

            * all wires must be closed
            * there cannot be any intersecting or self-intersecting wires
            * wires must be listed from outside in
            * more than one levels of nesting is not supported reliably

            This method will attempt to sort the wires, but there is much work remaining to make this method
            reliable.
        """

        # one would think that fusing faces into a compound and then extruding would work,
        # but it doesnt-- the resulting compound appears to look right, ( right number of faces, etc),
        # but then cutting it from the main solid fails with BRep_NotDone.
        # the work around is to extrude each and then join the resulting solids, which seems to work

        # FreeCAD allows this in one operation, but others might not

        face = Face.makeFromWires(outerWire, innerWires)
        prism_builder = BRepPrimAPI_MakePrism(face.wrapped, vecNormal.wrapped,
                                              True)

        return cls(prism_builder.Shape())
def brep_feat_rib(event=None):
    mkw = BRepBuilderAPI_MakeWire()

    mkw.Add(BRepBuilderAPI_MakeEdge(gp_Pnt(0., 0., 0.), gp_Pnt(200., 0., 0.)).Edge())
    mkw.Add(BRepBuilderAPI_MakeEdge(gp_Pnt(200., 0., 0.), gp_Pnt(200., 0., 50.)).Edge())
    mkw.Add(BRepBuilderAPI_MakeEdge(gp_Pnt(200., 0., 50.), gp_Pnt(50., 0., 50.)).Edge())
    mkw.Add(BRepBuilderAPI_MakeEdge(gp_Pnt(50., 0., 50.), gp_Pnt(50., 0., 200.)).Edge())
    mkw.Add(BRepBuilderAPI_MakeEdge(gp_Pnt(50., 0., 200.), gp_Pnt(0., 0., 200.)).Edge())
    mkw.Add(BRepBuilderAPI_MakeEdge(gp_Pnt(0., 0., 200.), gp_Pnt(0., 0., 0.)).Edge())

    S = BRepPrimAPI_MakePrism(BRepBuilderAPI_MakeFace(mkw.Wire()).Face(),
                              gp_Vec(gp_Pnt(0., 0., 0.),
                                     gp_Pnt(0., 100., 0.)))
    display.EraseAll()
    #    display.DisplayShape(S.Shape())

    W = BRepBuilderAPI_MakeWire(BRepBuilderAPI_MakeEdge(gp_Pnt(50., 45., 100.),
                                                        gp_Pnt(100., 45., 50.)).Edge())

    aplane = Geom_Plane(0., 1., 0., -45.)

    aform = BRepFeat_MakeLinearForm(S.Shape(), W.Wire(), aplane.GetHandle(),
                                    gp_Vec(0., 10., 0.), gp_Vec(0., 0., 0.),
                                    1, True)
    aform.Perform()
    display.DisplayShape(aform.Shape())
    display.FitAll()
Beispiel #4
0
def makePieSlice(r, theta0, theta1, z_min, z_max):
    p0 = gp_Pnt(0, 0, z_min)
    p1 = gp_Pnt(r * cos(theta0), r * sin(theta0), z_min)
    p2 = gp_Pnt(r * cos(theta1), r * sin(theta1), z_min)
    edges = []
    los = TopTools_ListOfShape()
    me = BRepBuilderAPI_MakeEdge(p0, p1)
    edges.append(me.Edge())
    los.Append(me.Edge())
    ax = gp_Ax2(gp_Pnt(0, 0, z_min), gp_Dir(0, 0, 1), gp_Dir(1, 0, 0))
    circ = gp_Circ(ax, r)
    me = BRepBuilderAPI_MakeEdge(circ, theta0, theta1)
    edges.append(me.Edge())
    los.Append(me.Edge())
    me = BRepBuilderAPI_MakeEdge(p2, p0)
    edges.append(me.Edge())
    los.Append(me.Edge())
    """
    mw = BRepBuilderAPI_MakeWire()
    for i in edges:
      mw.Add(i)
    """
    mw = BRepBuilderAPI_MakeWire()
    mw.Add(los)

    pln = gp_Pln(gp_Pnt(0, 0, z_min), gp_Dir(0, 0, 1))
    mf = BRepBuilderAPI_MakeFace(pln, mw.Wire())
    face = mf.Face()
    mp = BRepPrimAPI_MakePrism(face, gp_Vec(0, 0, z_max - z_min))
    return mp.Shape()
Beispiel #5
0
def make_prism(profile, vec):
    """
    makes a finite prism
    """
    pri = BRepPrimAPI_MakePrism(profile, vec, True)
    with assert_isdone(pri, 'failed building prism'):
        pri.Build()
        return pri.Shape()
Beispiel #6
0
    def Solid(self):

        mw = BRepBuilderAPI_MakeWire()
        points = []

        x = -self.length / 2.0
        y = -self.width / 2.0
        z = 0.0
        points.append(gp_Pnt(x, y, z))

        x = self.length / 2.0
        points.append(gp_Pnt(x, y, z))

        me = BRepBuilderAPI_MakeEdge(points[0], points[1])
        mw.Add(me.Edge())  # bottom edge

        ax = gp_Ax2(gp_Pnt(x, 0, 0), gp_Dir(0, 0, 1), gp_Dir(0, -1, 0))
        circ = gp_Circ(ax, self.width / 2.0)
        me = BRepBuilderAPI_MakeEdge(circ, 0, pi)
        mw.Add(me.Edge())

        points = []
        y = self.width / 2.0
        points.append(gp_Pnt(x, y, z))

        x = -self.length / 2.0
        points.append(gp_Pnt(x, y, z))
        me = BRepBuilderAPI_MakeEdge(points[0], points[1])
        mw.Add(me.Edge())  # top edge

        ax = gp_Ax2(gp_Pnt(x, 0, 0), gp_Dir(0, 0, 1), gp_Dir(0, 1, 0))
        circ = gp_Circ(ax, self.width / 2.0)
        me = BRepBuilderAPI_MakeEdge(circ, 0, pi)
        mw.Add(me.Edge())

        mf = BRepBuilderAPI_MakeFace(mw.Wire())
        mp = BRepPrimAPI_MakePrism(mf.Face(), gp_Vec(0, 0, self.thickness))

        shape = mp.Shape()

        #v_trans = gp_Vec(self.ax2.Location().XYZ())
        ax = gp_Ax2(gp_Pnt(0, 0, 0), gp_Dir(0, 0, 1), gp_Dir(1, 0, 0))
        #mainRotationAngle = ax.Angle(self.ax2)

        trsf = gp_Trsf()
        trsf.SetTransformation(gp_Ax3(self.ax2), gp_Ax3(ax))

        mt = BRepBuilderAPI_Transform(shape, trsf)
        return mt.Shape()
Beispiel #7
0
def build(input, output):
    #sample xml for testing
    xml = "<eagle version=\"7\"><drawing><board><plain><wire x1=\"0\" y1=\"0\" x2=\"0\" y2=\"2\" width=\"0.254\" layer=\"20\"/><wire x1=\"0\" y1=\"2\" x2=\"1.5\" y2=\"2\" width=\"0.254\" layer=\"20\"/><wire x1=\"1.5\" y1=\"2\" x2=\"1\" y2=\"0\" width=\"0.254\" layer=\"20\"/><wire x1=\"1\" y1=\"0\" x2=\"0\" y2=\"0\" width=\"0.254\" layer=\"20\"/></plain></board></drawing></eagle>"

    #xmldoc = minidom.parseString( xml )

    xmldoc = minidom.parse(input)

    wires = xmldoc.getElementsByTagName('wire')

    makeWire = BRepBuilderAPI_MakeWire()

    for wire in wires:

        if wire.attributes['layer'].value == '20':
            x1 = float(wire.attributes['x1'].value)
            y1 = float(wire.attributes['y1'].value)

            x2 = float(wire.attributes['x2'].value)
            y2 = float(wire.attributes['y2'].value)

            #print('Building edge from  {}, {} to {}, {}'.format( x1,y1,x2,y2))

            edge = BRepBuilderAPI_MakeEdge( gp_Pnt( x1, y1, 0.0 ), \
                                            gp_Pnt( x2, y2, 0.0 ) \
                                                      )

            makeWire.Add(edge.Edge())

    face = BRepBuilderAPI_MakeFace(makeWire.Wire())

    #vector & height
    vector = gp_Vec(0, 0, .1)

    body = BRepPrimAPI_MakePrism(face.Face(), vector)

    # initialize the STEP exporter
    step_writer = STEPControl_Writer()
    Interface_Static_SetCVal("write.step.schema", "AP203")

    # transfer shapes and write file
    step_writer.Transfer(body.Shape(), STEPControl_AsIs)
    status = step_writer.Write(output)

    if status != IFSelect_RetDone:
        raise AssertionError("load failed")
def ExtrudeFace(face, vec=gp_Vec(1, 0, 0)):
    """Extrudes a face by input vector

    Parameters
    ----------
    face : TopoDS_Face

    vec : OCC.gp.gp_Vec
        The offset vector to extrude through
    Returns
    -------
    shape : TopoDS_Shape
        The extruded shape

    Notes
    -----
    Uses BRepBuilderAPI_MakePrism
    """
    from OCC.BRepPrimAPI import BRepPrimAPI_MakePrism
    builder = BRepPrimAPI_MakePrism(face, vec)
    builder.Build()
    return builder.Shape()
Beispiel #9
0
def build_test(path):
    #points
    pt1 = gp_Pnt(0, 0, 0)
    pt2 = gp_Pnt(0, 2, 0)
    pt3 = gp_Pnt(1.5, 2, 0)
    pt4 = gp_Pnt(1, 0, 0)

    edge1 = BRepBuilderAPI_MakeEdge(pt1, pt2)
    edge2 = BRepBuilderAPI_MakeEdge(pt2, pt3)
    edge3 = BRepBuilderAPI_MakeEdge(pt3, pt4)
    edge4 = BRepBuilderAPI_MakeEdge(pt4, pt1)

    #make wire with 4 edges
    wire = BRepBuilderAPI_MakeWire(edge1.Edge(), edge2.Edge(), edge3.Edge(),
                                   edge4.Edge())

    #alternate wire. create and then add in
    #makeWire = BRepBuilderAPI_MakeWire()
    #makeWire.add( wire )
    #wireProfile = makeWire.Wire()

    face = BRepBuilderAPI_MakeFace(wire.Wire())

    #vector & height
    vector = gp_Vec(0, 0, .1)

    body = BRepPrimAPI_MakePrism(face.Face(), vector)

    # initialize the STEP exporter
    step_writer = STEPControl_Writer()
    Interface_Static_SetCVal("write.step.schema", "AP203")

    # transfer shapes and write file
    step_writer.Transfer(body.Shape(), STEPControl_AsIs)
    status = step_writer.Write(path)

    if status != IFSelect_RetDone:
        raise AssertionError("load failed")
Beispiel #10
0
def build_tooth():
    base_center = gp_Pnt2d(
        pitch_circle_radius + (tooth_radius - roller_radius), 0)
    base_circle = gp_Circ2d(gp_Ax2d(base_center, gp_Dir2d()), tooth_radius)
    trimmed_base = GCE2d_MakeArcOfCircle(base_circle,
                                         M_PI - (roller_contact_angle / 2.),
                                         M_PI).Value()
    Proxy(trimmed_base).Reverse()  # just a trick
    p0 = Proxy(trimmed_base).StartPoint()
    p1 = Proxy(trimmed_base).EndPoint()

    # Determine the center of the profile circle
    x_distance = cos(
        roller_contact_angle / 2.) * (profile_radius + tooth_radius)
    y_distance = sin(
        roller_contact_angle / 2.) * (profile_radius + tooth_radius)
    profile_center = gp_Pnt2d(pitch_circle_radius - x_distance, y_distance)

    # Construct the profile circle gp_Circ2d
    profile_circle = gp_Circ2d(gp_Ax2d(profile_center, gp_Dir2d()),
                               profile_center.Distance(p1))
    geom_profile_circle = GCE2d_MakeCircle(profile_circle).Value()

    # Construct the outer circle gp_Circ2d
    outer_circle = gp_Circ2d(gp_Ax2d(gp_Pnt2d(0, 0), gp_Dir2d()), top_radius)
    geom_outer_circle = GCE2d_MakeCircle(outer_circle).Value()

    inter = Geom2dAPI_InterCurveCurve(geom_profile_circle, geom_outer_circle)
    num_points = inter.NbPoints()
    assert isinstance(p1, gp_Pnt2d)
    if num_points == 2:
        if p1.Distance(inter.Point(1)) < p1.Distance(inter.Point(2)):
            p2 = inter.Point(1)
        else:
            p2 = inter.Point(2)
    elif num_points == 1:
        p2 = inter.Point(1)
    else:
        exit(-1)

    # Trim the profile circle and mirror
    trimmed_profile = GCE2d_MakeArcOfCircle(profile_circle, p1, p2).Value()

    # Calculate the outermost point
    p3 = gp_Pnt2d(
        cos(tooth_angle / 2.) * top_radius,
        sin(tooth_angle / 2.) * top_radius)

    # and use it to create the third arc
    trimmed_outer = GCE2d_MakeArcOfCircle(outer_circle, p2, p3).Value()

    # Mirror and reverse the three arcs
    mirror_axis = gp_Ax2d(gp_Origin2d(), gp_DX2d().Rotated(tooth_angle / 2.))

    mirror_base = Handle_Geom2d_TrimmedCurve.DownCast(
        Proxy(trimmed_base).Copy())
    mirror_profile = Handle_Geom2d_TrimmedCurve.DownCast(
        Proxy(trimmed_profile).Copy())
    mirror_outer = Handle_Geom2d_TrimmedCurve.DownCast(
        Proxy(trimmed_outer).Copy())

    Proxy(mirror_base).Mirror(mirror_axis)
    Proxy(mirror_profile).Mirror(mirror_axis)
    Proxy(mirror_outer).Mirror(mirror_axis)

    Proxy(mirror_base).Reverse()
    Proxy(mirror_profile).Reverse()
    Proxy(mirror_outer).Reverse()

    # Replace the two outer arcs with a single one
    outer_start = Proxy(trimmed_outer).StartPoint()
    outer_mid = Proxy(trimmed_outer).EndPoint()
    outer_end = Proxy(mirror_outer).EndPoint()

    outer_arc = GCE2d_MakeArcOfCircle(outer_start, outer_mid,
                                      outer_end).Value()

    # Create an arc for the inside of the wedge
    inner_circle = gp_Circ2d(gp_Ax2d(gp_Pnt2d(0, 0), gp_Dir2d()),
                             top_radius - roller_diameter)
    inner_start = gp_Pnt2d(top_radius - roller_diameter, 0)
    inner_arc = GCE2d_MakeArcOfCircle(inner_circle, inner_start,
                                      tooth_angle).Value()
    Proxy(inner_arc).Reverse()

    # Convert the 2D arcs and two extra lines to 3D edges
    plane = gp_Pln(gp_Origin(), gp_DZ())
    arc1 = BRepBuilderAPI_MakeEdge(geomapi_To3d(trimmed_base, plane)).Edge()
    arc2 = BRepBuilderAPI_MakeEdge(geomapi_To3d(trimmed_profile, plane)).Edge()
    arc3 = BRepBuilderAPI_MakeEdge(geomapi_To3d(outer_arc, plane)).Edge()
    arc4 = BRepBuilderAPI_MakeEdge(geomapi_To3d(mirror_profile, plane)).Edge()
    arc5 = BRepBuilderAPI_MakeEdge(geomapi_To3d(mirror_base, plane)).Edge()

    p4 = Proxy(mirror_base).EndPoint()
    p5 = Proxy(inner_arc).StartPoint()

    lin1 = BRepBuilderAPI_MakeEdge(gp_Pnt(p4.X(), p4.Y(), 0),
                                   gp_Pnt(p5.X(), p5.Y(), 0)).Edge()
    arc6 = BRepBuilderAPI_MakeEdge(geomapi_To3d(inner_arc, plane)).Edge()

    p6 = Proxy(inner_arc).EndPoint()
    lin2 = BRepBuilderAPI_MakeEdge(gp_Pnt(p6.X(), p6.Y(), 0),
                                   gp_Pnt(p0.X(), p0.Y(), 0)).Edge()

    wire = BRepBuilderAPI_MakeWire(arc1)
    wire.Add(arc2)
    wire.Add(arc3)
    wire.Add(arc4)
    wire.Add(arc5)
    wire.Add(lin1)
    wire.Add(arc6)
    wire.Add(lin2)

    face = BRepBuilderAPI_MakeFace(wire.Wire())

    wedge = BRepPrimAPI_MakePrism(face.Shape(), gp_Vec(0.0, 0.0, thickness))

    return wedge.Shape()
# Combine the two constituent wires
mkWire = BRepBuilderAPI_MakeWire()
mkWire.Add(aWire.Wire())
mkWire.Add(aMirroredWire)
myWireProfile = mkWire.Wire()

# The face that we'll sweep to make the prism
myFaceProfile = BRepBuilderAPI_MakeFace(myWireProfile)

# We want to sweep the face along the Z axis to the height
aPrismVec = gp_Vec(0, 0, height)
myBody = BRepPrimAPI_MakePrism(myFaceProfile.Face(), aPrismVec)

# Add fillets to all edges through the explorer
mkFillet = BRepFilletAPI_MakeFillet(myBody.Shape())
anEdgeExplorer = TopExp_Explorer(myBody.Shape(), TopAbs_EDGE)

while anEdgeExplorer.More():
    anEdge = topods.Edge(anEdgeExplorer.Current())
    mkFillet.Add(thickness / 12.0, anEdge)

    anEdgeExplorer.Next()

myBody = mkFillet

# Create the neck of the bottle
neckLocation = gp_Pnt(0, 0, height)
neckAxis = gp_DZ()
neckAx2 = gp_Ax2(neckLocation, neckAxis)
Beispiel #12
0
aMirroredWire = OCC.TopoDS.topods().Wire(aMirroredWire)

mkWire = MakeWire()
mkWire.Add(aWire.Wire())
mkWire.Add(aMirroredWire)
myWireProfile = mkWire.Wire()

# Body : Prism the Profile
myFaceProfile = MakeFace(myWireProfile)
if myFaceProfile.IsDone():
    bottomFace = myFaceProfile.Face()
aPrismVec = gp_Vec(0, 0, myHeight)
myBody = MakePrism(myFaceProfile.Shape(), aPrismVec)

# Body : Apply Fillets
mkFillet = MakeFillet(myBody.Shape())
aEdgeExplorer = Explorer(myBody.Shape(), OCC.TopAbs.TopAbs_EDGE)
while aEdgeExplorer.More():
    aEdge = OCC.TopoDS.topods_Edge(aEdgeExplorer.Current())
    mkFillet.Add(myThickness / 12, aEdge)
    aEdgeExplorer.Next()
myBody = mkFillet.Shape()

# Body : Add the Neck
neckLocation = OCC.gp.gp_Pnt(0, 0, myHeight)
neckNormal = OCC.gp.gp_DZ()
neckAx2 = OCC.gp.gp_Ax2(neckLocation, neckNormal)
myNeckRadius = myThickness / 4
myNeckHeight = myHeight / 10
MKCylinder = MakeCylinder(neckAx2, myNeckRadius, myNeckHeight)
myNeck = MKCylinder.Shape()
Beispiel #13
0
def makeStringerWithContinuousSlot():
    thickness = 5.0
    width = 25.0
    slot_width = 5.0
    slot_depth = thickness / 4.0
    length = 150.0

    points = []

    x = 0
    y = 0
    z = 0

    x = thickness / 2.0
    y = -width / 2.0
    points.append(gp_Pnt(x, y, z))  # bottom right corner

    y = -slot_width / 2.0
    points.append(gp_Pnt(x, y, z))

    x = x - slot_depth
    points.append(gp_Pnt(x, y, z))

    y = slot_width / 2.0
    points.append(gp_Pnt(x, y, z))

    x = x + slot_depth
    points.append(gp_Pnt(x, y, z))

    y = width / 2.0  # top right corner
    points.append(gp_Pnt(x, y, z))

    x = -thickness / 2.0  # top left corner
    points.append(gp_Pnt(x, y, z))

    y = slot_width / 2.0
    points.append(gp_Pnt(x, y, z))

    x = x + slot_depth
    points.append(gp_Pnt(x, y, z))

    y = -slot_width / 2.0
    points.append(gp_Pnt(x, y, z))

    x = x - slot_depth
    points.append(gp_Pnt(x, y, z))

    y = -width / 2.0
    points.append(gp_Pnt(x, y, z))  # bottom left corner

    x = thickness / 2.0
    points.append(gp_Pnt(x, y, z))  # back to the bottom right corner

    mw = BRepBuilderAPI_MakeWire()
    for i in range(len(points) - 1):
        me = BRepBuilderAPI_MakeEdge(points[i], points[i + 1])
        edge = me.Edge()
        mw.Add(edge)

    mf = BRepBuilderAPI_MakeFace(mw.Wire())
    mp = BRepPrimAPI_MakePrism(mf.Face(), gp_Vec(0, 0, length))
    return mp.Shape()