예제 #1
0
파일: _dao_01.py 프로젝트: headfire/crpoint
def dao_01_scene(r):

    #compute primitives

    r2 = r/2

    gpPntMinC = gp_Pnt(0,r2,0)

    p0 = gp_Pnt(0,0,0)
    p1 = getPntRotate(gpPntMinC , p0, -pi/4)
    p2 = gp_Pnt(-r2,r2,0)
    p3 = getPntRotate(gpPntMinC , p0, -pi/4*3)
    p4 = gp_Pnt(0,r,0)
    p5 = gp_Pnt(r,0,0)
    p6 = gp_Pnt(0,-r,0)
    p7 = gp_Pnt(r2,-r2,0)

    arc1 =  GC_MakeArcOfCircle(p0,p1,p2).Value()
    arc2 =  GC_MakeArcOfCircle(p2,p3,p4).Value()
    arc3 =  GC_MakeArcOfCircle(p4,p5,p6).Value()
    arc4 =  GC_MakeArcOfCircle(p6,p7,p0).Value()

    edge1 = BRepBuilderAPI_MakeEdge(arc1).Edge()
    edge2 = BRepBuilderAPI_MakeEdge(arc2).Edge()
    edge3 = BRepBuilderAPI_MakeEdge(arc3).Edge()
    edge4 = BRepBuilderAPI_MakeEdge(arc4).Edge()

    daoWire =  BRepBuilderAPI_MakeWire(edge1, edge2, edge3, edge4).Wire()

    # scene template
    sc = new Scene

    # scene transform
    sc.Circle('baseCircle',gp_Pnt(r,0,0), gp_Pnt(0,r,0), gp_Pnt(-r,0,0), 'stInfo')

    sc.Point('p0', p0)
    sc.Point('p1', p0)
    sc.Point('p2', p0)
    sc.Point('p3', p0)
    sc.Point('p4', p0)
    sc.Point('p5', p0)
    sc.Point('p6', p0)
    sc.Point('p7', p0)

    sc.Wire('daoWire', daoWire)

    # styling
    sc.Styling('baseCircle','stInfo')

    return sc
예제 #2
0
    def getDaoClassicWire(self):

        p = self.getCached('getDaoBasePoints')

        arc0 = GC_MakeArcOfCircle(p[0], p[1], p[2]).Value()
        arc1 = GC_MakeArcOfCircle(p[2], p[3], p[4]).Value()
        arc2 = GC_MakeArcOfCircle(p[4], p[5], p[6]).Value()
        arc3 = GC_MakeArcOfCircle(p[6], p[7], p[0]).Value()

        edge0 = BRepBuilderAPI_MakeEdge(arc0).Edge()
        edge1 = BRepBuilderAPI_MakeEdge(arc1).Edge()
        edge2 = BRepBuilderAPI_MakeEdge(arc2).Edge()
        edge3 = BRepBuilderAPI_MakeEdge(arc3).Edge()

        aWire = BRepBuilderAPI_MakeWire(edge0, edge1, edge2, edge3).Wire()

        return aWire
예제 #3
0
 def arc3p(self, ps, pe, p3):
     """Create an arc from start pt, end pt, and 3rd pt on the arc."""
     gp_ps = gp_Pnt(ps[0], ps[1], 0).Transformed(self.Trsf)
     gp_pe = gp_Pnt(pe[0], pe[1], 0).Transformed(self.Trsf)
     gp_p3 = gp_Pnt(p3[0], p3[1], 0).Transformed(self.Trsf)
     geom_arc = GC_MakeArcOfCircle(gp_ps, gp_pe, gp_p3).Value()
     edge = BRepBuilderAPI_MakeEdge(geom_arc).Edge()
     self.edgeList.append(edge)
예제 #4
0
def getWireDaoClassic(ppBase):

    p0, p1, p2, p3, p4, p5, p6, p7  = ppBase

    # base dao
    arc1 =  GC_MakeArcOfCircle(p0,p1,p2).Value()
    arc2 =  GC_MakeArcOfCircle(p2,p3,p4).Value()
    arc3 =  GC_MakeArcOfCircle(p4,p5,p6).Value()
    arc4 =  GC_MakeArcOfCircle(p6,p7,p0).Value()

    edge1 = BRepBuilderAPI_MakeEdge(arc1).Edge()
    edge2 = BRepBuilderAPI_MakeEdge(arc2).Edge()
    edge3 = BRepBuilderAPI_MakeEdge(arc3).Edge()
    edge4 = BRepBuilderAPI_MakeEdge(arc4).Edge()

    shape =  BRepBuilderAPI_MakeWire(edge1, edge2, edge3, edge4).Wire()

    return shape
예제 #5
0
 def arcc2p(self, pc, ps, pe):
     """Create an arc from center pt, start pt and end pt."""
     rad = p2p_dist(pc, ps)
     circ2d = (pc, rad)
     geom_circ = self.convert_circ_to_geomCirc(circ2d)
     gp_circ = geom_circ.Circ()
     gp_ps = gp_Pnt(ps[0], ps[1], 0).Transformed(self.Trsf)
     gp_pe = gp_Pnt(pe[0], pe[1], 0).Transformed(self.Trsf)
     geom_arc = GC_MakeArcOfCircle(gp_circ, gp_ps, gp_pe, True).Value()
     edge = BRepBuilderAPI_MakeEdge(geom_arc).Edge()
     self.edgeList.append(edge)
예제 #6
0
def makeLines():
    global aEdge1, aEdge2, aEdge3
    # Make type 'Geom_TrimmedCurve' from type 'gp_Pnt'
    aArcOfCircle = GC_MakeArcOfCircle(aPnt2, aPnt3, aPnt4)
    aSegment1 = GC_MakeSegment(aPnt1, aPnt2)
    aSegment2 = GC_MakeSegment(aPnt4, aPnt5)
    # Make type 'TopoDS_Edge' from type 'Geom_TrimmedCurve'
    aEdge1 = BRepBuilderAPI_MakeEdge(aSegment1.Value())
    aEdge2 = BRepBuilderAPI_MakeEdge(aArcOfCircle.Value())
    aEdge3 = BRepBuilderAPI_MakeEdge(aSegment2.Value())
    return (aEdge1.Edge(), aEdge2.Edge(), aEdge3.Edge())
예제 #7
0
def makeLines(event=None):
    global aEdge1, aEdge2, aEdge3
    aArcOfCircle = GC_MakeArcOfCircle(aPnt2, aPnt3, aPnt4)
    aSegment1 = GC_MakeSegment(aPnt1, aPnt2)
    aSegment2 = GC_MakeSegment(aPnt4, aPnt5)
    # Display lines
    aEdge1 = BRepBuilderAPI_MakeEdge(aSegment1.Value())
    aEdge2 = BRepBuilderAPI_MakeEdge(aArcOfCircle.Value())
    aEdge3 = BRepBuilderAPI_MakeEdge(aSegment2.Value())
    display.DisplayColoredShape(aEdge1.Edge(), 'RED')
    display.DisplayColoredShape(aEdge2.Edge(), 'RED')
    display.DisplayColoredShape(aEdge3.Edge(), 'RED')
    display.Repaint()
    win.statusBar().showMessage('Make lines complete')
예제 #8
0
def segments_to_edges(segments) -> List[TopoDS_Edge]:
    from ada.concepts.curves import ArcSegment

    edges = []
    for seg in segments:
        if type(seg) is ArcSegment:
            a_arc_of_circle = GC_MakeArcOfCircle(
                gp_Pnt(*list(seg.p1)),
                gp_Pnt(*list(seg.midpoint)),
                gp_Pnt(*list(seg.p2)),
            )
            a_edge2 = BRepBuilderAPI_MakeEdge(a_arc_of_circle.Value()).Edge()
            edges.append(a_edge2)
        else:
            edge = make_edge(seg.p1, seg.p2)
            edges.append(edge)

    return edges
예제 #9
0
파일: __init__.py 프로젝트: ocastrup/OCX
 def __init__(self, p1: numpy, p2: numpy, p3: numpy):
     # p1: StartPoint
     # p2: EndPoint
     # p3: IntermediatePoint
     super().__init__()
     self.edge = TopAbs_EDGE
     gp1 = OccPoint(p1)
     gp2 = OccPoint(p2)
     gp3 = OccPoint(p3)
     mkarc = GC_MakeArcOfCircle(
         gp1.Value(), gp3.Value(),
         gp2.Value())  # Sequence: StartPoint, IntermediatePoint, EndPoint
     if not mkarc.IsDone():
         OCCWrapper.OccError(mkarc.Error())
     else:
         mkedge = BRepBuilderAPI_MakeEdge(mkarc.Value())
         if not mkedge.IsDone():
             OCCWrapper.OccError(mkedge.Error())
         else:
             self.done = True
             self.edge = mkedge.Edge()
     return
예제 #10
0
def startBottle(startOnly=True):  # minus the neck fillet, shelling & threads
    partName = "Bottle-start"
    # The points we'll use to create the profile of the bottle's body
    aPnt1 = gp_Pnt(-width / 2.0, 0, 0)
    aPnt2 = gp_Pnt(-width / 2.0, -thickness / 4.0, 0)
    aPnt3 = gp_Pnt(0, -thickness / 2.0, 0)
    aPnt4 = gp_Pnt(width / 2.0, -thickness / 4.0, 0)
    aPnt5 = gp_Pnt(width / 2.0, 0, 0)

    aArcOfCircle = GC_MakeArcOfCircle(aPnt2, aPnt3, aPnt4)
    aSegment1 = GC_MakeSegment(aPnt1, aPnt2)
    aSegment2 = GC_MakeSegment(aPnt4, aPnt5)

    # Could also construct the line edges directly using the points
    # instead of the resulting line.
    aEdge1 = BRepBuilderAPI_MakeEdge(aSegment1.Value())
    aEdge2 = BRepBuilderAPI_MakeEdge(aArcOfCircle.Value())
    aEdge3 = BRepBuilderAPI_MakeEdge(aSegment2.Value())

    # Create a wire out of the edges
    aWire = BRepBuilderAPI_MakeWire(aEdge1.Edge(), aEdge2.Edge(),
                                    aEdge3.Edge())

    # Quick way to specify the X axis
    xAxis = gp_OX()

    # Set up the mirror
    aTrsf = gp_Trsf()
    aTrsf.SetMirror(xAxis)

    # Apply the mirror transformation
    aBRespTrsf = BRepBuilderAPI_Transform(aWire.Wire(), aTrsf)

    # Get the mirrored shape back out of the transformation
    # and convert back to a wire
    aMirroredShape = aBRespTrsf.Shape()

    # A wire instead of a generic shape now
    aMirroredWire = topods.Wire(aMirroredShape)

    # 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.Shape()

    # 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, mkCylinder.Shape())
    if startOnly:  # quit here
        uid = win.getNewPartUID(myBody.Shape(), name=partName)
        win.redraw()
        return

    partName = "Bottle-complete"
    # 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
    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
            aPnt = aPlane.Location()
            aZ = aPnt.Z()
            if aZ > zMax:
                zMax = aZ
                faceToRemove = aFace

        aFaceExplorer.Next()

    facesToRemove = TopTools_ListOfShape()
    facesToRemove.Append(faceToRemove)

    myBody = BRepOffsetAPI_MakeThickSolid(myBody.Shape(), facesToRemove,
                                          -thickness / 50.0, 0.001)

    # Set up our surfaces for the threading on the neck
    neckAx2_Ax3 = gp_Ax3(neckLocation, gp_DZ())
    aCyl1 = Geom_CylindricalSurface(neckAx2_Ax3, myNeckRadius * 0.99)
    aCyl2 = Geom_CylindricalSurface(neckAx2_Ax3, myNeckRadius * 1.05)

    # Set up the curves for the threads on the bottle's neck
    aPnt = gp_Pnt2d(2.0 * math.pi, myNeckHeight / 2.0)
    aDir = gp_Dir2d(2.0 * math.pi, myNeckHeight / 4.0)
    anAx2d = gp_Ax2d(aPnt, aDir)

    aMajor = 2.0 * math.pi
    aMinor = myNeckHeight / 10.0

    anEllipse1 = Geom2d_Ellipse(anAx2d, aMajor, aMinor)
    anEllipse2 = Geom2d_Ellipse(anAx2d, aMajor, aMinor / 4.0)

    anArc1 = Geom2d_TrimmedCurve(anEllipse1, 0, math.pi)
    anArc2 = Geom2d_TrimmedCurve(anEllipse2, 0, math.pi)

    anEllipsePnt1 = anEllipse1.Value(0)
    anEllipsePnt2 = anEllipse1.Value(math.pi)

    aSegment = GCE2d_MakeSegment(anEllipsePnt1, anEllipsePnt2)

    # Build edges and wires for threading
    anEdge1OnSurf1 = BRepBuilderAPI_MakeEdge(anArc1, aCyl1)
    anEdge2OnSurf1 = BRepBuilderAPI_MakeEdge(aSegment.Value(), aCyl1)
    anEdge1OnSurf2 = BRepBuilderAPI_MakeEdge(anArc2, aCyl2)
    anEdge2OnSurf2 = BRepBuilderAPI_MakeEdge(aSegment.Value(), aCyl2)

    threadingWire1 = BRepBuilderAPI_MakeWire(anEdge1OnSurf1.Edge(),
                                             anEdge2OnSurf1.Edge())
    threadingWire2 = BRepBuilderAPI_MakeWire(anEdge1OnSurf2.Edge(),
                                             anEdge2OnSurf2.Edge())

    # Compute the 3D representations of the edges/wires
    breplib.BuildCurves3d(threadingWire1.Shape())
    breplib.BuildCurves3d(threadingWire2.Shape())

    # Create the surfaces of the threading
    aTool = BRepOffsetAPI_ThruSections(True)
    aTool.AddWire(threadingWire1.Wire())
    aTool.AddWire(threadingWire2.Wire())
    aTool.CheckCompatibility(False)
    myThreading = aTool.Shape()

    # Build the resulting compound
    aRes = TopoDS_Compound()
    aBuilder = BRep_Builder()
    aBuilder.MakeCompound(aRes)
    aBuilder.Add(aRes, myBody.Shape())
    aBuilder.Add(aRes, myThreading)
    uid = win.getNewPartUID(aRes, name=partName)
    win.redraw()
예제 #11
0
    def create_model(self):

        ######################################################
        edges = []
        if self.R2 == 0.0 or self.R1 == 0.0:
            self.a3 = self.a4 = self.a5
            edge1 = make_edge(getGpPt(self.a1), getGpPt(self.a2))
            edges.append(edge1)
            edge2 = make_edge(getGpPt(self.a2), getGpPt(self.a3))
            edges.append(edge2)
            edge3 = make_edge(getGpPt(self.a3), getGpPt(self.a6))
            edges.append(edge3)
            # arc2 = GC_MakeArcOfCircle(getGpPt(self.a6), getGpPt(self.a7), getGpPt(self.a8))
            # edge4 = make_edge(arc2.Value())
            # edges.append(edge4)
            # edge5 = make_edge(getGpPt(self.a8), getGpPt(self.a9))
            # edges.append(edge5)
            # edge6 = make_edge(getGpPt(self.a9), getGpPt(self.a12))
            # edges.append(edge6)
            # edge7 = make_edge(getGpPt(self.a12), getGpPt(self.a1))
            # edges.append(edge7)
            edge4 = make_edge(getGpPt(self.a6), getGpPt(self.a9))
            edges.append(edge4)
            edge5 = make_edge(getGpPt(self.a9), getGpPt(self.a12))
            edges.append(edge5)
            edge6 = make_edge(getGpPt(self.a12), getGpPt(self.a1))
            edges.append(edge6)

        else:
            edge1 = make_edge(getGpPt(self.a1), getGpPt(self.a2))
            edges.append(edge1)
            edge2 = make_edge(getGpPt(self.a2), getGpPt(self.a3))
            edges.append(edge2)
            arc1 = GC_MakeArcOfCircle(getGpPt(self.a3), getGpPt(self.a4),
                                      getGpPt(self.a5))
            edge3 = make_edge(arc1.Value())
            edges.append(edge3)
            edge4 = make_edge(getGpPt(self.a5), getGpPt(self.a6))
            edges.append(edge4)
            arc2 = GC_MakeArcOfCircle(getGpPt(self.a6), getGpPt(self.a7),
                                      getGpPt(self.a8))
            edge5 = make_edge(arc2.Value())
            edges.append(edge5)
            edge6 = make_edge(getGpPt(self.a8), getGpPt(self.a9))
            edges.append(edge6)
            arc3 = GC_MakeArcOfCircle(getGpPt(self.a9), getGpPt(self.a10),
                                      getGpPt(self.a11))
            edge7 = make_edge(arc3.Value())
            edges.append(edge7)
            edge8 = make_edge(getGpPt(self.a11), getGpPt(self.a12))
            edges.append(edge8)
            edge9 = make_edge(getGpPt(self.a12), getGpPt(self.a1))
            edges.append(edge9)

        wire = makeWireFromEdges(edges)
        aFace = makeFaceFromWire(wire)
        extrudeDir = self.L * 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()
        return prism
    return BRepAdaptor_Surface(aFace, True).Plane()


height = 70
width = 50
thickness = 30

print("creating bottle")
# The points we'll use to create the profile of the bottle's body
aPnt1 = gp_Pnt(-width / 2.0, 0, 0)
aPnt2 = gp_Pnt(-width / 2.0, -thickness / 4.0, 0)
aPnt3 = gp_Pnt(0, -thickness / 2.0, 0)
aPnt4 = gp_Pnt(width / 2.0, -thickness / 4.0, 0)
aPnt5 = gp_Pnt(width / 2.0, 0, 0)

aArcOfCircle = GC_MakeArcOfCircle(aPnt2, aPnt3, aPnt4)
aSegment1 = GC_MakeSegment(aPnt1, aPnt2)
aSegment2 = GC_MakeSegment(aPnt4, aPnt5)

# Could also construct the line edges directly using the points instead of the resulting line
aEdge1 = BRepBuilderAPI_MakeEdge(aSegment1.Value())
aEdge2 = BRepBuilderAPI_MakeEdge(aArcOfCircle.Value())
aEdge3 = BRepBuilderAPI_MakeEdge(aSegment2.Value())

# Create a wire out of the edges
aWire = BRepBuilderAPI_MakeWire(aEdge1.Edge(), aEdge2.Edge(), aEdge3.Edge())

# Quick way to specify the X axis
xAxis = gp_OX()

# Set up the mirror
예제 #13
0
def _circle_arc(p1, p2, p3):
    aArcOfCircle = GC_MakeArcOfCircle(to_Pnt(p1), to_Pnt(p2), to_Pnt(p3))
    return Shape(BRepBuilderAPI_MakeEdge(aArcOfCircle.Value()).Edge())