Example #1
0
def cut_out(base):
    outer = gp_Circ2d(gp_OX2d(), top_radius - 1.75 * roller_diameter)
    inner = gp_Circ2d(gp_OX2d(), center_radius + 0.75 * roller_diameter)

    geom_outer = GCE2d_MakeCircle(outer).Value()
    geom_inner = GCE2d_MakeCircle(inner).Value()
    Proxy(geom_inner).Reverse()

    base_angle = (2. * M_PI) / mounting_hole_count
    hole_angle = atan(hole_radius / mounting_radius)
    correction_angle = 3 * hole_angle

    left = gp_Lin2d(gp_Origin2d(), gp_DX2d())
    right = gp_Lin2d(gp_Origin2d(), gp_DX2d())
    left.Rotate(gp_Origin2d(), correction_angle)
    right.Rotate(gp_Origin2d(), base_angle - correction_angle)

    geom_left = GCE2d_MakeLine(left).Value()
    geom_right = GCE2d_MakeLine(right).Value()

    inter_1 = Geom2dAPI_InterCurveCurve(geom_outer, geom_left)
    inter_2 = Geom2dAPI_InterCurveCurve(geom_outer, geom_right)
    inter_3 = Geom2dAPI_InterCurveCurve(geom_inner, geom_right)
    inter_4 = Geom2dAPI_InterCurveCurve(geom_inner, geom_left)

    if inter_1.Point(1).X() > 0:
        p1 = inter_1.Point(1)
    else:
        p1 = inter_1.Point(2)

    if inter_2.Point(1).X() > 0:
        p2 = inter_2.Point(1)
    else:
        p2 = inter_2.Point(2)

    if inter_3.Point(1).X() > 0:
        p3 = inter_3.Point(1)
    else:
        p3 = inter_3.Point(2)

    if inter_4.Point(1).X() > 0:
        p4 = inter_4.Point(1)
    else:
        p4 = inter_4.Point(2)

    trimmed_outer = GCE2d_MakeArcOfCircle(outer, p1, p2).Value()
    trimmed_inner = GCE2d_MakeArcOfCircle(inner, p4, p3).Value()

    plane = gp_Pln(gp_Origin(), gp_DZ())

    arc1 = BRepBuilderAPI_MakeEdge(geomapi_To3d(trimmed_outer, plane)).Edge()

    lin1 = BRepBuilderAPI_MakeEdge(gp_Pnt(p2.X(), p2.Y(), 0),
                                   gp_Pnt(p3.X(), p3.Y(), 0)).Edge()

    arc2 = BRepBuilderAPI_MakeEdge(geomapi_To3d(trimmed_inner, plane)).Edge()

    lin2 = BRepBuilderAPI_MakeEdge(gp_Pnt(p4.X(), p4.Y(), 0),
                                   gp_Pnt(p1.X(), p1.Y(), 0)).Edge()

    cutout_wire = BRepBuilderAPI_MakeWire(arc1)
    cutout_wire.Add(lin1)
    cutout_wire.Add(arc2)
    cutout_wire.Add(lin2)

    # Turn the wire into a face
    cutout_face = BRepBuilderAPI_MakeFace(cutout_wire.Wire())
    filleted_face = BRepFilletAPI_MakeFillet2d(cutout_face.Face())

    explorer = BRepTools_WireExplorer(cutout_wire.Wire())
    while explorer.More():
        vertex = explorer.CurrentVertex()
        filleted_face.AddFillet(vertex, roller_radius)
        explorer.Next()

    cutout = BRepPrimAPI_MakePrism(filleted_face.Shape(),
                                   gp_Vec(0.0, 0.0, thickness)).Shape()

    result = base
    rotate = gp_Trsf()
    for i in range(0, mounting_hole_count):
        rotate.SetRotation(gp_OZ(), i * 2. * M_PI / mounting_hole_count)
        rotated_cutout = BRepBuilderAPI_Transform(cutout, rotate, True)

        result = BRepAlgoAPI_Cut(result,
                                 rotated_cutout.Shape()).Shape()

    return result
def brep_feat_extrusion_protrusion(event=None):
    # Extrusion
    S = BRepPrimAPI_MakeBox(400., 250., 300.).Shape()
    faces = Topo(S).faces()
    F = next(faces)
    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)

    display.EraseAll()
    MKP = BRepFeat_MakePrism(S, FP, F, D1, 0, True)
    MKP.PerformThruAll()

    res1 = MKP.Shape()
    display.DisplayShape(res1)

    # Protrusion
    next(faces)
    F2 = next(faces)
    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.)
    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()

    FP = MKF2.Face()
    breplib_BuildCurves3d(FP)
    MKP2 = BRepFeat_MakePrism(res1, FP, F2, D2, 0, True)
    MKP2.PerformThruAll()
    display.EraseAll()

    trf = gp_Trsf()
    trf.SetTranslation(gp_Vec(0, 0, 300))
    gtrf = gp_GTrsf()
    gtrf.SetTrsf(trf)
    tr = BRepBuilderAPI_GTransform(MKP2.Shape(), gtrf, True)

    fused = BRepAlgoAPI_Fuse(tr.Shape(), MKP2.Shape())
    fused.RefineEdges()
    fused.Build()
    print('Boolean operation error status:', fused.ErrorStatus())
    display.DisplayShape(fused.Shape())
    display.FitAll()
# Explore the faces of the shape (these are known to be named)
exp = TopExp_Explorer(shape, TopAbs_FACE)
while exp.More():
    s = exp.Current()

    tp = Topo(s)
    for face in tp.faces():
        ifcopenshell.geom.utils.display_shape(face)
        for edge in list(Topo(face).edges()):

            curve_handle, first, last = BRep_Tool.CurveOnSurface(
                edge, section_face)

            plane = Geom_Plane(section_plane)

            e = BRepBuilderAPI_MakeEdge(curve_handle, plane.GetHandle(), first,
                                        last).Edge()

            handle_adaptor = Geom2dAdaptor_Curve(curve_handle)
            if handle_adaptor.GetType() == GeomAbs_Line:
                v = list(Topo(e).vertices())
                x1, z1 = BRep_Tool.Pnt(v[0]).X(), BRep_Tool.Pnt(v[0]).Z()
                x2, z2 = BRep_Tool.Pnt(v[-1]).X(), BRep_Tool.Pnt(v[-1]).Z()
                plt.plot([x1, x2], [z1, z2], color="red", alpha=0.2)

                ifcopenshell.geom.utils.display_shape(e, clr=RED)

            elif handle_adaptor.GetType() == GeomAbs_Circle:
                v = list(Topo(e).vertices())
                start = (BRep_Tool.Pnt(v[0]).X(), BRep_Tool.Pnt(v[0]).Z())
                end = (BRep_Tool.Pnt(v[-1]).X(), BRep_Tool.Pnt(v[-1]).Z())
width = 50
thickness = 30

# 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)
def make_edge(*args):
    edge = BRepBuilderAPI_MakeEdge(*args)
    result = edge.Edge()
    return result
def face():
    p1 = gp_Pnt()
    p2 = gp_Pnt()
    p3 = gp_Pnt()
    p4 = gp_Pnt()
    p5 = gp_Pnt()
    p6 = gp_Pnt()

    # The white Face
    sphere = gp_Sphere(gp_Ax3(gp_Pnt(0, 0, 0), gp_Dir(1, 0, 0)), 150)
    green_face = BRepBuilderAPI_MakeFace(sphere, 0.1, 0.7, 0.2, 0.9)

    # The red face
    p1.SetCoord(-15, 200, 10)
    p2.SetCoord(5, 204, 0)
    p3.SetCoord(15, 200, 0)
    p4.SetCoord(-15, 20, 15)
    p5.SetCoord(-5, 20, 0)
    p6.SetCoord(15, 20, 35)
    array = TColgp_Array2OfPnt(1, 3, 1, 2)
    array.SetValue(1, 1, p1)
    array.SetValue(2, 1, p2)
    array.SetValue(3, 1, p3)
    array.SetValue(1, 2, p4)
    array.SetValue(2, 2, p5)
    array.SetValue(3, 2, p6)
    curve = GeomAPI_PointsToBSplineSurface(array, 3, 8, GeomAbs_C2,
                                           0.001).Surface()
    red_face = BRepBuilderAPI_MakeFace(curve, 1e-6)

    #The brown face
    circle = gp_Circ(gp_Ax2(gp_Pnt(0, 0, 0), gp_Dir(1, 0, 0)), 80)
    Edge1 = BRepBuilderAPI_MakeEdge(circle, 0, math.pi)
    Edge2 = BRepBuilderAPI_MakeEdge(gp_Pnt(0, 0, -80), gp_Pnt(0, -10, 40))
    Edge3 = BRepBuilderAPI_MakeEdge(gp_Pnt(0, -10, 40), gp_Pnt(0, 0, 80))

    ##TopoDS_Wire YellowWire
    MW1 = BRepBuilderAPI_MakeWire(Edge1.Edge(), Edge2.Edge(), Edge3.Edge())
    assert MW1.IsDone()
    yellow_wire = MW1.Wire()
    brown_face = BRepBuilderAPI_MakeFace(yellow_wire)

    #The pink face
    p1.SetCoord(35, -200, 40)
    p2.SetCoord(50, -204, 30)
    p3.SetCoord(65, -200, 30)
    p4.SetCoord(35, -20, 45)
    p5.SetCoord(45, -20, 30)
    p6.SetCoord(65, -20, 65)
    array2 = TColgp_Array2OfPnt(1, 3, 1, 2)
    array2.SetValue(1, 1, p1)
    array2.SetValue(2, 1, p2)
    array2.SetValue(3, 1, p3)
    array2.SetValue(1, 2, p4)
    array2.SetValue(2, 2, p5)
    array2.SetValue(3, 2, p6)
    BSplineSurf = GeomAPI_PointsToBSplineSurface(array2, 3, 8, GeomAbs_C2,
                                                 0.001)
    aFace = BRepBuilderAPI_MakeFace(BSplineSurf.Surface(), 1e-6).Face()
    ##
    ##//2d lines
    P12d = gp_Pnt2d(0.9, 0.1)
    P22d = gp_Pnt2d(0.2, 0.7)
    P32d = gp_Pnt2d(0.02, 0.1)
    ##
    line1 = Geom2d_Line(P12d, gp_Dir2d((0.2 - 0.9), (0.7 - 0.1)))
    line2 = Geom2d_Line(P22d, gp_Dir2d((0.02 - 0.2), (0.1 - 0.7)))
    line3 = Geom2d_Line(P32d, gp_Dir2d((0.9 - 0.02), (0.1 - 0.1)))
    ##
    ##//Edges are on the BSpline surface
    Edge1 = BRepBuilderAPI_MakeEdge(line1.GetHandle(), BSplineSurf.Surface(),
                                    0, P12d.Distance(P22d)).Edge()
    Edge2 = BRepBuilderAPI_MakeEdge(line2.GetHandle(), BSplineSurf.Surface(),
                                    0, P22d.Distance(P32d)).Edge()
    Edge3 = BRepBuilderAPI_MakeEdge(line3.GetHandle(), BSplineSurf.Surface(),
                                    0, P32d.Distance(P12d)).Edge()
    ##
    Wire1 = BRepBuilderAPI_MakeWire(Edge1, Edge2, Edge3).Wire()
    Wire1.Reverse()
    pink_face = BRepBuilderAPI_MakeFace(aFace, Wire1).Face()
    breplib_BuildCurves3d(pink_face)

    display.DisplayColoredShape(green_face.Face(), 'GREEN')
    display.DisplayColoredShape(red_face.Face(), 'RED')
    display.DisplayColoredShape(pink_face, Quantity_Color(Quantity_NOC_PINK))
    display.DisplayColoredShape(brown_face.Face(), 'BLUE')
    display.DisplayColoredShape(yellow_wire, 'YELLOW', update=True)
#!/usr/bin/python
# coding: utf-8
r"""Core dimensions display example"""

import os

from OCC.gp import gp_Dir, gp_Ax2, gp_Circ, gp_Pnt
from OCC.AIS import AIS_Shape, AIS_RadiusDimension
from OCC.BRepBuilderAPI import BRepBuilderAPI_MakeEdge
from OCC.Display.SimpleGui import init_display

display, start_display, add_menu, add_function_to_menu = init_display('wx')

c = gp_Circ(gp_Ax2(gp_Pnt(200., 200., 0.), gp_Dir(0., 0., 1.)), 80)
ec = BRepBuilderAPI_MakeEdge(c).Edge()
ais_shp = AIS_Shape(ec)
display.Context.Display(ais_shp.GetHandle())

# Does not solve problem !!
# os.environ["OCE_LIB_PATH"] = \
#     "C:/_Guillaume/__gf_files__/____Projets/5xx-Developpement/_Repositories/github/guillaume-florent/oce"
os.environ["CASROOT"] = \
    "C:/_Guillaume/__gf_files__/____Projets/5xx-Developpement/_Repositories/github/guillaume-florent/oce"
os.environ["CSF_UnitsLexicon"] = \
    os.environ["CASROOT"] + "/src/UnitsAPI/Lexi_Expr.dat"
os.environ["CSF_UnitsDefinition"] = \
    os.environ["CASROOT"] + "/src/UnitsAPI/Units.dat"

rd = AIS_RadiusDimension(ec)
# rd.SetArrowSize(12)
handle = rd.GetHandle()
from OCC.gp import gp_Pnt
from OCC.BRepBuilderAPI import (BRepBuilderAPI_MakeEdge,
                                BRepBuilderAPI_MakeWire,
                                BRepBuilderAPI_MakeFace,
                                BRepBuilderAPI_Sewing)
from OCC.Display.SimpleGui import init_display

# create vertices
v1 = gp_Pnt(1, 0, 0)
v2 = gp_Pnt(0, 1, 0)
v3 = gp_Pnt(0, 0, 1)
v4 = gp_Pnt(0, 0, 0)

# create edges
e0 = BRepBuilderAPI_MakeEdge(v1, v4).Edge()
e1 = BRepBuilderAPI_MakeEdge(v4, v2).Edge()
e2 = BRepBuilderAPI_MakeEdge(v4, v3).Edge()
e3 = BRepBuilderAPI_MakeEdge(v2, v1).Edge()
e4 = BRepBuilderAPI_MakeEdge(v3, v2).Edge()
e5 = BRepBuilderAPI_MakeEdge(v3, v1).Edge()

# create wires
w0 = BRepBuilderAPI_MakeWire(e5, e3, e4).Wire()
w1 = BRepBuilderAPI_MakeWire(e1, e3, e0).Wire()
w2 = BRepBuilderAPI_MakeWire(e0, e5, e2).Wire()
w3 = BRepBuilderAPI_MakeWire(e2, e4, e1).Wire()

# then create faces
f0 = BRepBuilderAPI_MakeFace(w0).Face()
f1 = BRepBuilderAPI_MakeFace(w1).Face()
Example #9
0
 def make_edge(self,*args):
     self.shape = BRepBuilderAPI_MakeEdge(*args)
Example #10
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")
Example #11
0
def edge(event=None):
    # The blud edge
    blue_edge = BRepBuilderAPI_MakeEdge(gp_Pnt(-80, -50, -20),
                                        gp_Pnt(-30, -60, -60))
    v1 = BRepBuilderAPI_MakeVertex(gp_Pnt(-20, 10, -30))
    v2 = BRepBuilderAPI_MakeVertex(gp_Pnt(10, 7, -25))
    yellow_edge = BRepBuilderAPI_MakeEdge(v1.Vertex(), v2.Vertex())

    # The white edge
    line = gp_Lin(gp_Ax1(gp_Pnt(10, 10, 10), gp_Dir(1, 0, 0)))
    white_edge = BRepBuilderAPI_MakeEdge(line, -20, 10)

    # The red edge
    elips = gp_Elips(gp_Ax2(gp_Pnt(10, 0, 0), gp_Dir(1, 1, 1)), 60, 30)
    red_edge = BRepBuilderAPI_MakeEdge(elips, 0, math.pi / 2)

    # The green edge and the both extreme vertex
    p1 = gp_Pnt(-15, 200, 10)
    p2 = gp_Pnt(5, 204, 0)
    p3 = gp_Pnt(15, 200, 0)
    p4 = gp_Pnt(-15, 20, 15)
    p5 = gp_Pnt(-5, 20, 0)
    p6 = gp_Pnt(15, 20, 0)
    p7 = gp_Pnt(24, 120, 0)
    p8 = gp_Pnt(-24, 120, 12.5)
    array = TColgp_Array1OfPnt(1, 8)
    array.SetValue(1, p1)
    array.SetValue(2, p2)
    array.SetValue(3, p3)
    array.SetValue(4, p4)
    array.SetValue(5, p5)
    array.SetValue(6, p6)
    array.SetValue(7, p7)
    array.SetValue(8, p8)
    curve = Geom_BezierCurve(array)
    make_edge = BRepBuilderAPI_MakeEdge(curve.GetHandle())
    green_edge = make_edge
    v3 = make_edge.Vertex1()
    v4 = make_edge.Vertex2()

    display.DisplayColoredShape(blue_edge.Edge(), 'BLUE')
    display.DisplayShape(v1.Vertex())
    display.DisplayShape(v2.Vertex())
    display.DisplayColoredShape(white_edge.Edge(), 'WHITE')
    display.DisplayColoredShape(yellow_edge.Edge(), 'YELLOW')
    display.DisplayColoredShape(red_edge.Edge(), 'RED')
    display.DisplayColoredShape(green_edge.Edge(), 'GREEN')
    display.DisplayShape(v3)
    display.DisplayShape(v4, update=True)
 def get_updated_le(self):
     self.le = tigl3.curve_factories.interpolate_points(self.le_points, [0., 0.25, 0.55, 0.8, 1.0])
     return BRepBuilderAPI_MakeEdge(self.le).Edge()
from OCC.gp import gp_Pnt,gp_Dir,gp_Pln
from OCC.ChFi2d import ChFi2d_AnaFilletAlgo
from OCC.BRepBuilderAPI import BRepBuilderAPI_MakeEdge,BRepBuilderAPI_MakeWire

from OCC.Extend.ShapeFactory import make_wire

from OCC.Display.SimpleGui import init_display
display,start_display, add_menu,add_functionto_menu = init_display()

# Defining the points
p1 = gp_Pnt(0, 0, 0) 
p2 = gp_Pnt(5, 5, 0)
p3 = gp_Pnt(-5,5, 0)

# Making the edges
ed1 = BRepBuilderAPI_MakeEdge(p3,p2).Edge()
ed2 = BRepBuilderAPI_MakeEdge(p2,p1).Edge()

#Making the 2dFillet
f = ChFi2d_AnaFilletAlgo()
f.Init(ed1,ed2,gp_Pln())
radius = 1.0
f.Perform(radius)
fillet2d = f.Result(ed1,ed2)

# Create and display a wire
w = make_wire([ed1, fillet2d, ed2])
display.DisplayShape(w)
start_display()
Example #14
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:
        sys.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()
Example #15
0
 def testVertices(self):
     e = Shape.cast(
         BRepBuilderAPI_MakeEdge(gp_Pnt(0, 0, 0), gp_Pnt(1, 1, 0)).Edge())
     self.assertEqual(2, len(e.Vertices()))
Example #16
0
def make_circle(pycentre_pt, pydirection, radius):
    circle = gp_Circ(
        gp_Ax2(gp_Pnt(pycentre_pt[0], pycentre_pt[1], pycentre_pt[2]),
               gp_Dir(pydirection[0], pydirection[1], pydirection[2])), radius)
    circle_edge = BRepBuilderAPI_MakeEdge(circle, 0, circle.Length())
    return circle_edge.Edge()
Example #17
0
    def _make_circle(self):

        circle = gp_Circ(gp_Ax2(gp_Pnt(1, 2, 3), gp_DZ()), 2.)
        return Shape.cast(BRepBuilderAPI_MakeEdge(circle).Edge())
Example #18
0
def make_edge(pypt1, pypt2):
    gp_point1 = gp_Pnt(pypt1[0], pypt1[1], pypt1[2])
    gp_point2 = gp_Pnt(pypt2[0], pypt2[1], pypt2[2])

    make_edge = BRepBuilderAPI_MakeEdge(gp_point1, gp_point2)
    return make_edge.Edge()
Example #19
0
from OCC.TopoDS import TopoDS_Edge
from OCC.gp import gp_Pnt
from OCC.BRep import BRep_Tool

from OCC.Display.SimpleGui import init_display


class InheritEdge(TopoDS_Edge):
    def __init__(self, edge):
        # following constructor creates an empy TopoDS_Edge
        super(InheritEdge, self).__init__()
        # we need to copy the base shape using the following three lines
        print(self.IsNull())
        self.TShape(edge.TShape())
        self.Location(edge.Location())
        self.Orientation(edge.Orientation())
        print(self.IsNull())
        # then it becomes possible to extend the base class

    def get_curve(self):
        return BRep_Tool.Curve(self)


if __name__ == "__main__":
    base_edge = BRepBuilderAPI_MakeEdge(gp_Pnt(), gp_Pnt(100., 0., 0.)).Edge()
    inherited_edge = InheritEdge(base_edge)
    print(inherited_edge.get_curve())
    display, start_display, add_menu, add_function_to_menu = init_display()
    display.DisplayShape(inherited_edge, update=True)
    start_display()
Example #20
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()
Example #21
0
    def write(self, mesh_points, filename, tolerance=None):
        """
        Writes a output file, called filename, copying all the structures
        from self.filename but the coordinates. `mesh_points` is a matrix
        that contains the new coordinates to write in the output file.

        :param numpy.ndarray mesh_points: it is a `n_points`-by-3 matrix
            containing the coordinates of the points of the mesh
        :param string filename: name of the output file.
        :param float tolerance: tolerance for the construction of the faces
            and wires in the write function. If not given it uses
            `self.tolerance`.
        """
        self._check_filename_type(filename)
        self._check_extension(filename)
        self._check_infile_instantiation()

        self.outfile = filename

        if tolerance is not None:
            self.tolerance = tolerance

        # cycle on the faces to update the control points position
        # init some quantities
        faces_explorer = TopExp_Explorer(self.shape, TopAbs_FACE)
        n_faces = 0
        control_point_position = self._control_point_position

        compound_builder = BRep_Builder()
        compound = TopoDS_Compound()
        compound_builder.MakeCompound(compound)

        while faces_explorer.More():
            # similar to the parser method
            face = topods_Face(faces_explorer.Current())
            nurbs_converter = BRepBuilderAPI_NurbsConvert(face)
            nurbs_converter.Perform(face)
            nurbs_face = nurbs_converter.Shape()
            face_aux = topods_Face(nurbs_face)
            brep_face = BRep_Tool.Surface(topods_Face(nurbs_face))
            bspline_face = geomconvert_SurfaceToBSplineSurface(brep_face)
            occ_face = bspline_face.GetObject()

            n_poles_u = occ_face.NbUPoles()
            n_poles_v = occ_face.NbVPoles()

            i = 0
            for pole_u_direction in range(n_poles_u):
                for pole_v_direction in range(n_poles_v):
                    control_point_coordinates = mesh_points[
                        i + control_point_position[n_faces], :]
                    point_xyz = gp_XYZ(*control_point_coordinates)

                    gp_point = gp_Pnt(point_xyz)
                    occ_face.SetPole(pole_u_direction + 1,
                                     pole_v_direction + 1, gp_point)
                    i += 1

            # construct the deformed wire for the trimmed surfaces
            wire_maker = BRepBuilderAPI_MakeWire()
            tol = ShapeFix_ShapeTolerance()
            brep = BRepBuilderAPI_MakeFace(occ_face.GetHandle(),
                                           self.tolerance).Face()
            brep_face = BRep_Tool.Surface(brep)

            # cycle on the edges
            edge_explorer = TopExp_Explorer(nurbs_face, TopAbs_EDGE)
            while edge_explorer.More():
                edge = topods_Edge(edge_explorer.Current())
                # edge in the (u,v) coordinates
                edge_uv_coordinates = BRep_Tool.CurveOnSurface(edge, face_aux)
                # evaluating the new edge: same (u,v) coordinates, but different (x,y,x) ones
                edge_phis_coordinates_aux = BRepBuilderAPI_MakeEdge(
                    edge_uv_coordinates[0], brep_face)
                edge_phis_coordinates = edge_phis_coordinates_aux.Edge()
                tol.SetTolerance(edge_phis_coordinates, self.tolerance)
                wire_maker.Add(edge_phis_coordinates)
                edge_explorer.Next()

            # grouping the edges in a wire
            wire = wire_maker.Wire()

            # trimming the surfaces
            brep_surf = BRepBuilderAPI_MakeFace(occ_face.GetHandle(),
                                                wire).Shape()
            compound_builder.Add(compound, brep_surf)
            n_faces += 1
            faces_explorer.Next()
        self.write_shape_to_file(compound, self.outfile)
Example #22
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()
Example #23
0
def EdgeOnSurface(edge, section_plane, lim_coord1, lim_coord2, XYZ):

    section_face = BRepBuilderAPI_MakeFace(section_plane, lim_coord1[0],
                                           lim_coord1[1], lim_coord2[0],
                                           lim_coord2[1]).Face()
    curve_handle, first, last = BRep_Tool.CurveOnSurface(edge, section_face)

    plane = Geom_Plane(section_plane)
    edge_on_surface = BRepBuilderAPI_MakeEdge(curve_handle, plane.GetHandle(),
                                              first, last).Edge()
    curve_adaptor = BRepAdaptor_Curve(edge_on_surface)

    if curve_adaptor.GetType() == GeomAbs_Line:

        v = list(Topo(edge_on_surface).vertices())
        v1 = BRep_Tool.Pnt(v[0]).X(), BRep_Tool.Pnt(v[0]).Y(), BRep_Tool.Pnt(
            v[0]).Z()
        v2 = BRep_Tool.Pnt(v[-1]).X(), BRep_Tool.Pnt(v[-1]).Y(), BRep_Tool.Pnt(
            v[-1]).Z()

        obj = Line3D(v1, v2)

    elif curve_adaptor.GetType() == GeomAbs_Circle:
        v = list(Topo(edge_on_surface).vertices())
        v1 = BRep_Tool.Pnt(v[0]).X(), BRep_Tool.Pnt(v[0]).Y(), BRep_Tool.Pnt(
            v[0]).Z()
        v2 = BRep_Tool.Pnt(v[-1]).X(), BRep_Tool.Pnt(v[-1]).Y(), BRep_Tool.Pnt(
            v[-1]).Z()

        start = [v1[i] for i in range(len(XYZ)) if XYZ[i]]
        end = [v2[i] for i in range(len(XYZ)) if XYZ[i]]

        circle = curve_adaptor.Circle()
        center = []
        for i in range(len(XYZ)):
            if XYZ[i] and i == 0:
                center.append(circle.Location().X())
            elif XYZ[i] and i == 1:
                center.append(circle.Location().Y())
            elif XYZ[i] and i == 2:
                center.append(circle.Location().Z())
            else:
                center.append(0.5 * (v1[i] + v2[i]))
        radius = circle.Radius()

        vec_start = (start[0] - center[0], start[1] - center[1])
        vec_end = (end[0] - center[0], end[1] - center[1])

        t1 = angle360(vec_start)
        t2 = angle360(vec_end)

        if not XYZ[0]:
            axis = circle.Axis().Direction().X()
        elif not XYZ[1]:
            axis = circle.Axis().Direction().Y()
        elif not XYZ[2]:
            axis = circle.Axis().Direction().Z()

        if axis < 0:
            t1, t2 = t2, t1

        obj = Arc3D(v1, v2, t1, t2, center, radius)

    elif curve_adaptor.GetType() == GeomAbs_BSplineCurve:

        bspline = curve_adaptor.BSpline().GetObject()
        degree = bspline.Degree()
        knots = [
            bspline.Knot(index) for index in range(1,
                                                   bspline.NbKnots() + 1)
        ]
        mults = [
            bspline.Multiplicity(index)
            for index in range(1,
                               bspline.NbKnots() + 1)
        ]
        poles = [(bspline.Pole(index).X(), bspline.Pole(index).Y(),
                  bspline.Pole(index).Z())
                 for index in range(1,
                                    bspline.NbPoles() + 1)]
        periodic = bspline.IsPeriodic()
        obj = BSpline3D(poles, mults, knots, degree, periodic)

    else:

        print(curve_adaptor.GetType())
        warnings.warn("Not recognized curve!")

    return obj
Example #24
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()
Example #25
0
def make_edge(*args):
    edge = BRepBuilderAPI_MakeEdge(*args)
    with assert_isdone(edge, 'failed to produce edge'):
        result = edge.Edge()
        edge.Delete()
        return result
Example #26
0
    api = BRepOffsetAPI_ThruSections()
    for z in np.linspace(0, 1000, 10):
        r_z = z + 1/z*(np.pi*w0/wave)**2
        w_z = w0 * np.sqrt (1 + (wave*z/(np.pi*w0**2))**2)
        print (z, r_z, w_z)
        pnt = gp_Pnt (0, 0, z)
        axs = gp_Ax3 (pnt, gp_Dir(0, 0, 1))
        ax2 = axs.Ax2()
        px  = np.linspace(-1, 1, 100) * 100 
        py  = np.linspace(-1, 1, 100) * 100
        pxy = np.meshgrid (px, py)
        pz  = -1*(pxy[0]**2/(2*r_z) + pxy[1]**2/(2*r_z))
        pln = surf_spl(*pxy, pz, axs)
        wxy = Geom_Ellipse (ax2, w_z, w_z).Elips()
        wxy = BRepBuilderAPI_MakeWire(BRepBuilderAPI_MakeEdge (wxy).Edge()).Wire() 
        print (wxy, pln)
        api.AddWire(wxy)
        display.DisplayShape (pnt)
        display.DisplayShape (pln)
        display.DisplayShape (wxy)
    api.Build()
    surf_wxy = api.Shape()
    display.DisplayShape(surf_wxy)

    pnt = gp_Pnt (0, 0, 500)    
    axs = gp_Ax3 (pnt, gp_Dir(0, 0, 1))
    axs.Rotate(gp_Ax1(axs.Location(), axs.XDirection()), np.deg2rad(5))
    axs.Rotate(gp_Ax1(axs.Location(), axs.YDirection()), np.deg2rad(30))
    ax2 = axs.Ax2()
    px = np.linspace(-1, 1, 100) * 100 
def extrusion(event=None):
    # Make a box
    Box = BRepPrimAPI_MakeBox(400., 250., 300.)
    S = Box.Shape()

    # Choose the first Face of the box
    F = next(Topo(S).faces())
    surf = BRep_Tool_Surface(F)

    #  Make a plane from this face
    Pl = Handle_Geom_Plane_DownCast(surf)
    Pln = Pl.GetObject()

    # Get the normal of this plane. This will be the direction of extrusion.
    D = Pln.Axis().Direction()

    # Inverse normal
    D.Reverse()

    # Create the 2D planar sketch
    MW = BRepBuilderAPI_MakeWire()
    p1 = gp_Pnt2d(200., -100.)
    p2 = gp_Pnt2d(100., -100.)
    aline = GCE2d_MakeLine(p1, p2).Value()
    Edge1 = BRepBuilderAPI_MakeEdge(aline, surf, 0., p1.Distance(p2))
    MW.Add(Edge1.Edge())
    p1 = p2
    p2 = gp_Pnt2d(100., -200.)
    aline = GCE2d_MakeLine(p1, p2).Value()
    Edge2 = BRepBuilderAPI_MakeEdge(aline, surf, 0., p1.Distance(p2))
    MW.Add(Edge2.Edge())
    p1 = p2
    p2 = gp_Pnt2d(200., -200.)
    aline = GCE2d_MakeLine(p1, p2).Value()
    Edge3 = BRepBuilderAPI_MakeEdge(aline, surf, 0., p1.Distance(p2))
    MW.Add(Edge3.Edge())
    p1 = p2
    p2 = gp_Pnt2d(200., -100.)
    aline = GCE2d_MakeLine(p1, p2).Value()
    Edge4 = BRepBuilderAPI_MakeEdge(aline, surf, 0., p1.Distance(p2))
    MW.Add(Edge4.Edge())

    #  Build Face from Wire. NB: a face is required to generate a solid.
    MKF = BRepBuilderAPI_MakeFace()
    MKF.Init(surf, False, 1e-6)
    MKF.Add(MW.Wire())
    FP = MKF.Face()
    breplib_BuildCurves3d(FP)

    MKP = BRepFeat_MakePrism(S, FP, F, D, False, True)
    MKP.Perform(200.)
    # TODO MKP completes, seeing a split operation but no extrusion
    assert MKP.IsDone()
    res1 = MKP.Shape()

    display.EraseAll()
    display.DisplayColoredShape(res1, 'BLUE')
    display.FitAll()
Example #28
0
    def write(cls, filename, data, tolerance=1e-6):

        # cycle on the faces to update the control points position
        # init some quantities
        shape = data.shape
        control_point_position = data.control_point_position
        mesh_points = data.points

        faces_explorer = TopExp_Explorer(shape, TopAbs_FACE)
        n_faces = 0
        compound_builder = BRep_Builder()
        compound = TopoDS_Compound()
        compound_builder.MakeCompound(compound)

        while faces_explorer.More():
            # similar to the parser method
            face = topods_Face(faces_explorer.Current())
            nurbs_converter = BRepBuilderAPI_NurbsConvert(face)
            nurbs_converter.Perform(face)
            nurbs_face = nurbs_converter.Shape()
            face_aux = topods_Face(nurbs_face)
            brep_face = BRep_Tool.Surface(topods_Face(nurbs_face))
            bspline_face = geomconvert_SurfaceToBSplineSurface(brep_face)
            occ_face = bspline_face.GetObject()

            n_poles_u = occ_face.NbUPoles()
            n_poles_v = occ_face.NbVPoles()

            i = 0
            for pole_u_direction in range(n_poles_u):
                for pole_v_direction in range(n_poles_v):
                    control_point_coordinates = mesh_points[
                        +control_point_position[n_faces], :]
                    point_xyz = gp_XYZ(*control_point_coordinates)

                    gp_point = gp_Pnt(point_xyz)
                    occ_face.SetPole(pole_u_direction + 1,
                                     pole_v_direction + 1, gp_point)
                    i += 1

            # construct the deformed wire for the trimmed surfaces
            wire_maker = BRepBuilderAPI_MakeWire()
            tol = ShapeFix_ShapeTolerance()
            brep = BRepBuilderAPI_MakeFace(occ_face.GetHandle(),
                                           tolerance).Face()
            brep_face = BRep_Tool.Surface(brep)

            # cycle on the edges
            edge_explorer = TopExp_Explorer(nurbs_face, TopAbs_EDGE)
            while edge_explorer.More():
                edge = topods_Edge(edge_explorer.Current())
                # edge in the (u,v) coordinates
                edge_uv_coordinates = BRep_Tool.CurveOnSurface(edge, face_aux)
                # evaluating the new edge: same (u,v) coordinates, but
                # different (x,y,x) ones
                edge_phis_coordinates_aux = BRepBuilderAPI_MakeEdge(
                    edge_uv_coordinates[0], brep_face)
                edge_phis_coordinates = edge_phis_coordinates_aux.Edge()
                tol.SetTolerance(edge_phis_coordinates, tolerance)
                wire_maker.Add(edge_phis_coordinates)
                edge_explorer.Next()

            # grouping the edges in a wire
            wire = wire_maker.Wire()

            # trimming the surfaces
            brep_surf = BRepBuilderAPI_MakeFace(occ_face.GetHandle(),
                                                wire).Shape()
            compound_builder.Add(compound, brep_surf)
            n_faces += 1
            faces_explorer.Next()

        IGESControl_Controller_Init()
        writer = IGESControl_Writer()
        writer.AddShape(compound)
        writer.Write(filename)
Example #29
0
    def DisplayShape(self,
                     shapes,
                     material=None,
                     texture=None,
                     color=None,
                     transparency=None,
                     update=False):
        '''
        '''
        print('V3d_View size is', self.View.Size())
        p = self.View.RenderingParams()
        print(p.Resolution())
        # if a gp_Pnt is passed, first convert to vertex
        if issubclass(shapes.__class__, gp_Pnt):
            vertex = BRepBuilderAPI_MakeVertex(shapes)
            shapes = [vertex.Shape()]
            SOLO = True
        elif isinstance(shapes, gp_Pnt2d):
            vertex = BRepBuilderAPI_MakeVertex(
                gp_Pnt(shapes.X(), shapes.Y(), 0))
            shapes = [vertex.Shape()]
            SOLO = True
        # if a Geom_Curve is passed
        elif callable(getattr(shapes, "GetHandle", None)):
            handle = shapes.GetHandle()
            if issubclass(handle.__class__, Handle_Geom_Curve):
                edge = BRepBuilderAPI_MakeEdge(handle)
                shapes = [edge.Shape()]
                SOLO = True
            elif issubclass(handle.__class__, Handle_Geom2d_Curve):
                edge2d = BRepBuilderAPI_MakeEdge2d(handle)
                shapes = [edge2d.Shape()]
                SOLO = True
            elif issubclass(handle.__class__, Handle_Geom_Surface):
                bounds = True
                toldegen = 1e-6
                face = BRepBuilderAPI_MakeFace()
                face.Init(handle, bounds, toldegen)
                face.Build()
                shapes = [face.Shape()]
                SOLO = True
        elif isinstance(shapes, Handle_Geom_Surface):
            bounds = True
            toldegen = 1e-6
            face = BRepBuilderAPI_MakeFace()
            face.Init(shapes, bounds, toldegen)
            face.Build()
            shapes = [face.Shape()]
            SOLO = True
        elif isinstance(shapes, Handle_Geom_Curve):
            edge = BRepBuilderAPI_MakeEdge(shapes)
            shapes = [edge.Shape()]
            SOLO = True
        elif isinstance(shapes, Handle_Geom2d_Curve):
            edge2d = BRepBuilderAPI_MakeEdge2d(shapes)
            shapes = [edge2d.Shape()]
            SOLO = True
        elif issubclass(shapes.__class__, TopoDS_Shape):
            shapes = [shapes]
            SOLO = True
        else:
            SOLO = False

        ais_shapes = []

        for shape in shapes:
            if material or texture:
                if texture:
                    self.View.SetSurfaceDetail(OCC.V3d.V3d_TEX_ALL)
                    shape_to_display = OCC.AIS.AIS_TexturedShape(shape)
                    filename, toScaleU, toScaleV, toRepeatU, toRepeatV, originU, originV = texture.GetProperties(
                    )
                    shape_to_display.SetTextureFileName(
                        TCollection_AsciiString(filename))
                    shape_to_display.SetTextureMapOn()
                    shape_to_display.SetTextureScale(True, toScaleU, toScaleV)
                    shape_to_display.SetTextureRepeat(True, toRepeatU,
                                                      toRepeatV)
                    shape_to_display.SetTextureOrigin(True, originU, originV)
                    shape_to_display.SetDisplayMode(3)
                elif material:
                    shape_to_display = AIS_Shape(shape)
                    shape_to_display.SetMaterial(material)
            else:
                # TODO: can we use .Set to attach all TopoDS_Shapes
                # to this AIS_Shape instance?
                shape_to_display = AIS_Shape(shape)

            ais_shapes.append(shape_to_display.GetHandle())

        if not SOLO:
            # computing graphic properties is expensive
            # if an iterable is found, so cluster all TopoDS_Shape under
            # an AIS_MultipleConnectedInteractive
            shape_to_display = AIS_MultipleConnectedInteractive()
            for i in ais_shapes:
                shape_to_display.Connect(i)

        # set the graphic properties
        if material is None:
            #The default material is too shiny to show the object
            #color well, so I set it to something less reflective
            shape_to_display.SetMaterial(Graphic3d_NOM_NEON_GNC)
        if color:
            if isinstance(color, str):
                color = get_color_from_name(color)
            for shp in ais_shapes:
                self.Context.SetColor(shp, color, False)
        if transparency:
            shape_to_display.SetTransparency(transparency)
        if update:
            # only update when explicitely told to do so
            self.Context.Display(shape_to_display.GetHandle(), False)
            # especially this call takes up a lot of time...
            self.FitAll()
            self.Repaint()
        else:
            self.Context.Display(shape_to_display.GetHandle(), False)

        if SOLO:
            return ais_shapes[0]
        else:
            return shape_to_display
Example #30
0
def round_tooth(wedge):
    round_x = 2.6
    round_z = 0.06 * pitch
    round_radius = pitch

    # Determine where the circle used for rounding has to start and stop
    p2d_1 = gp_Pnt2d(top_radius - round_x, 0)
    p2d_2 = gp_Pnt2d(top_radius, round_z)

    # Construct the rounding circle
    round_circle = GccAna_Circ2d2TanRad(p2d_1, p2d_2, round_radius, 0.01)
    if (round_circle.NbSolutions() != 2):
        sys.exit(-2)

    round_circle_2d_1 = round_circle.ThisSolution(1)
    round_circle_2d_2 = round_circle.ThisSolution(2)

    if (round_circle_2d_1.Position().Location().Coord()[1] >= 0):
        round_circle_2d = round_circle_2d_1
    else:
        round_circle_2d = round_circle_2d_2

    # Remove the arc used for rounding
    trimmed_circle = GCE2d_MakeArcOfCircle(round_circle_2d, p2d_1, p2d_2).Value()

    # Calculate extra points used to construct lines
    p1 = gp_Pnt(p2d_1.X(), 0, p2d_1.Y())
    p2 = gp_Pnt(p2d_2.X(), 0, p2d_2.Y())
    p3 = gp_Pnt(p2d_2.X() + 1, 0, p2d_2.Y())
    p4 = gp_Pnt(p2d_2.X() + 1, 0, p2d_1.Y() - 1)
    p5 = gp_Pnt(p2d_1.X(), 0, p2d_1.Y() - 1)

    # Convert the arc and four extra lines into 3D edges
    plane = gp_Pln(gp_Ax3(gp_Origin(), gp_DY().Reversed(), gp_DX()))
    arc1 = BRepBuilderAPI_MakeEdge(geomapi_To3d(trimmed_circle, plane)).Edge()
    lin1 = BRepBuilderAPI_MakeEdge(p2, p3).Edge()
    lin2 = BRepBuilderAPI_MakeEdge(p3, p4).Edge()
    lin3 = BRepBuilderAPI_MakeEdge(p4, p5).Edge()
    lin4 = BRepBuilderAPI_MakeEdge(p5, p1).Edge()

    # Make a wire composed of the edges
    round_wire = BRepBuilderAPI_MakeWire(arc1)
    round_wire.Add(lin1)
    round_wire.Add(lin2)
    round_wire.Add(lin3)
    round_wire.Add(lin4)

    # Turn the wire into a face
    round_face = BRepBuilderAPI_MakeFace(round_wire.Wire()).Shape()

    # Revolve the face around the Z axis over the tooth angle
    rounding_cut_1 = BRepPrimAPI_MakeRevol(round_face, gp_OZ(), tooth_angle).Shape()

    # Construct a mirrored copy of the first cutting shape
    mirror = gp_Trsf()
    mirror.SetMirror(gp_XOY())
    mirrored_cut_1 = BRepBuilderAPI_Transform(rounding_cut_1, mirror, True).Shape()

    # and translate it so that it ends up on the other side of the wedge
    translate = gp_Trsf()
    translate.SetTranslation(gp_Vec(0, 0, thickness))
    rounding_cut_2 = BRepBuilderAPI_Transform(mirrored_cut_1, translate, False).Shape()

    # Cut the wedge using the first and second cutting shape
    cut_1 = BRepAlgoAPI_Cut(wedge, rounding_cut_1).Shape()
    cut_2 = BRepAlgoAPI_Cut(cut_1, rounding_cut_2).Shape()

    return cut_2