コード例 #1
0
def line():
    # create a line
    p1 = gp_Pnt(2., 3., 4.)
    d1 = gp_Dir(4., 5., 6.)
    line1 = Geom_Line(p1, d1)

    ais_line1 = AIS_Line(line1)

    # if we need to edit color, we can simply use SetColor
    # ais_line1.SetColor(Quantity_NOC_RED)

    # but actually we need to edit more, not just color. Line width and style as well
    # To do that, we need to do use AIS_Drawer and apply it to ais_line1
    drawer = Prs3d_Drawer()
    ais_line1.SetAttributes(drawer)

    display.Context.Display(ais_line1, False)
    # we can apply the same rule for other lines by just doing a for loop
    for i in range(1, 5):
        p2 = gp_Pnt(i, 2., 5.)
        d2 = gp_Dir(4 * i, 6., 9.)
        line2 = Geom_Line(p2, d2)

        ais_line2 = AIS_Line(line2)

        width = float(i)
        drawer = ais_line2.Attributes()
        # asp : first parameter color, second type, last width
        asp = Prs3d_LineAspect(Quantity_Color(9 * i), i, width)
        drawer.SetLineAspect(asp)
        ais_line2.SetAttributes(drawer)

        display.Context.Display(ais_line2, False)
    start_display()
コード例 #2
0
    def get_transform(self):
        d = self.declaration
        result = gp_Trsf()
        #: TODO: Order matters... how to configure it???
        if d.operations:
            for op in d.operations:
                t = gp_Trsf()
                if isinstance(op, Translate):
                    t.SetTranslation(gp_Vec(op.x, op.y, op.z))
                elif isinstance(op, Rotate):
                    t.SetRotation(
                        gp_Ax1(gp_Pnt(*op.point), gp_Dir(*op.direction)),
                        op.angle)
                elif isinstance(op, Mirror):
                    Ax = gp_Ax2 if op.plane else gp_Ax1
                    t.SetMirror(Ax(gp_Pnt(*op.point), gp_Dir(op.x, op.y,
                                                             op.z)))
                elif isinstance(op, Scale):
                    t.SetScale(gp_Pnt(*op.point), op.s)
                result.Multiply(t)
        else:
            axis = gp_Ax3()
            axis.SetDirection(d.direction.proxy)
            result.SetTransformation(axis)
            result.SetTranslationPart(gp_Vec(*d.position))
            if d.rotation:
                t = gp_Trsf()
                t.SetRotation(gp_Ax1(d.position.proxy, d.direction.proxy),
                              d.rotation)
                result.Multiply(t)

        return result
コード例 #3
0
 def tangent(self, u, v):
     dU, dV = gp_Dir(), gp_Dir()
     curv = self.curvature(u, v)
     if curv.IsTangentUDefined() and curv.IsTangentVDefined():
         curv.TangentU(dU), curv.TangentV(dV)
         return dU, dV
     else:
         return None, None
コード例 #4
0
def edge(event=None):
    # The blud edge
    BlueEdge = 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))
    YellowEdge = BRepBuilderAPI_MakeEdge(V1.Vertex(), V2.Vertex())

    #The white edge
    line = gp_Lin(gp_Ax1(gp_Pnt(10, 10, 10), gp_Dir(1, 0, 0)))
    WhiteEdge = 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)
    RedEdge = 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)
    ME = BRepBuilderAPI_MakeEdge(curve)
    GreenEdge = ME
    V3 = ME.Vertex1()
    V4 = ME.Vertex2()

    display.DisplayColoredShape(BlueEdge.Edge(), 'BLUE')
    display.DisplayShape(V1.Vertex())
    display.DisplayShape(V2.Vertex())
    display.DisplayColoredShape(WhiteEdge.Edge(), 'WHITE')
    display.DisplayColoredShape(YellowEdge.Edge(), 'YELLOW')
    display.DisplayColoredShape(RedEdge.Edge(), 'RED')
    display.DisplayColoredShape(GreenEdge.Edge(), 'GREEN')
    display.DisplayShape(V3)
    display.DisplayShape(V4, update=True)
コード例 #5
0
 def make_custom_plane(self, dimension):
     d = self.declaration
     pln = dimension.GetPlane()
     axis = pln.Axis()
     axis.SetDirection(gp_Dir(*d.direction))
     pln.SetAxis(axis)
     return pln
コード例 #6
0
def split_edge_with_face(event=None):
    display.EraseAll()
    p0 = gp_Pnt()
    vnorm = gp_Dir(1, 0, 0)
    pln = gp_Pln(p0, vnorm)
    face = BRepBuilderAPI_MakeFace(pln, -10, 10, -10, 10).Face()
    p1 = gp_Pnt(0, 0, 15)
    p2 = gp_Pnt(0, 0, -15)
    edge = BRepBuilderAPI_MakeEdge(p1, p2).Edge()
    # Initialize splitter
    splitter = BOPAlgo_Splitter()
    # Add the edge as an argument and the face as a tool. This will split
    # the edge with the face.
    splitter.AddArgument(edge)
    splitter.AddTool(face)
    splitter.Perform()

    edges = []
    exp = TopExp_Explorer(splitter.Shape(), TopAbs_EDGE)
    while exp.More():
        edges.append(exp.Current())
        exp.Next()
    print('Number of edges in split shape: ', len(edges))
    display.DisplayShape(edges[0], color='red')
    display.DisplayShape(edges[1], color='green')
    display.DisplayShape(edges[2], color='yellow')
    display.FitAll()
コード例 #7
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
コード例 #8
0
 def set_position(self, position, direction=None):
     d = self.declaration
     direction = direction or d.direction
     clip_plane = self.clip_plane
     pln = clip_plane.ToPlane()
     pln.SetPosition(gp_Ax3(gp_Pnt(*position), gp_Dir(*direction)))
     clip_plane.SetEquation(pln)
     self.update_viewer()
コード例 #9
0
def generate_shape():
    """Create a sphere with faces top and bottom"""
    sphere_radius = 1.0
    sphere_angle = atan(0.5)
    sphere_origin = gp_Ax2(gp_Pnt(0, 0, 0), gp_Dir(0, 0, 1))
    sphere = BRepPrimAPI_MakeSphere(sphere_origin, sphere_radius,
                                    -sphere_angle, sphere_angle).Shape()
    return sphere
コード例 #10
0
def rotating_cube_2_axis(event=None):
    display.EraseAll()
    ais_boxshp = build_shape()
    ax1 = gp_Ax1(gp_Pnt(0., 0., 0.), gp_Dir(0., 0., 1.))
    ax2 = gp_Ax1(gp_Pnt(0., 0., 0.), gp_Dir(0., 1., 0.))
    a_cube_trsf = gp_Trsf()
    a_cube_trsf2 = gp_Trsf()
    angle = 0.0
    tA = time.time()
    n_rotations = 200
    for i in range(n_rotations):
        a_cube_trsf.SetRotation(ax1, angle)
        a_cube_trsf2.SetRotation(ax2, angle)
        aCubeToploc = TopLoc_Location(a_cube_trsf * a_cube_trsf2)
        display.Context.SetLocation(ais_boxshp, aCubeToploc)
        display.Context.UpdateCurrentViewer()
        angle += 2 * pi / n_rotations
    print("%i rotations took %f" % (n_rotations, time.time() - tA))
コード例 #11
0
ファイル: test_Geom.py プロジェクト: tnakaicode/pythonocct
 def setUpClass(cls):
     """
     Set up with a Geom_SphericalSurface.
     """
     p = gp_Pnt()
     v = gp_Dir()
     a = gp_Ax3(p, v)
     s = gp_Sphere(a, 1.0)
     cls._surf = Geom_SphericalSurface(s)
コード例 #12
0
def ConvertBndToShape(theBox):
    aBaryCenter = theBox.Center()
    aXDir = theBox.XDirection()
    aYDir = theBox.YDirection()
    aZDir = theBox.ZDirection()
    aHalfX = theBox.XHSize()
    aHalfY = theBox.YHSize()
    aHalfZ = theBox.ZHSize()

    ax = gp_XYZ(aXDir.X(), aXDir.Y(), aXDir.Z())
    ay = gp_XYZ(aYDir.X(), aYDir.Y(), aYDir.Z())
    az = gp_XYZ(aZDir.X(), aZDir.Y(), aZDir.Z())
    p = gp_Pnt(aBaryCenter.X(), aBaryCenter.Y(), aBaryCenter.Z())
    anAxes = gp_Ax2(p, gp_Dir(aZDir), gp_Dir(aXDir))
    anAxes.SetLocation(
        gp_Pnt(p.XYZ() - ax * aHalfX - ay * aHalfY - az * aHalfZ))
    aBox = BRepPrimAPI_MakeBox(anAxes, 2.0 * aHalfX, 2.0 * aHalfY,
                               2.0 * aHalfZ).Shape()
    return aBox
コード例 #13
0
def add_feature(base):
    """Add a "feature" to a shape. In this case we drill a hole through it."""
    feature_diameter = 0.8
    feature_origin = gp_Ax1(gp_Pnt(0, 0, 0), gp_Dir(0, 0, 1))
    feature_maker = BRepFeat_MakeCylindricalHole()
    feature_maker.Init(base, feature_origin)
    feature_maker.Build()
    feature_maker.Perform(feature_diameter / 2.0)
    shape = feature_maker.Shape()
    return shape
コード例 #14
0
 def tangent(self, u):
     '''sets or gets ( iff vector ) the tangency at the u parameter
     tangency can be constrained so when setting the tangency,
     you're constrainting it in fact
     '''
     self._curvature.SetParameter(u)
     if self._curvature.IsTangentDefined():
         ddd = gp_Dir()
         self._curvature.Tangent(ddd)
         return ddd
     else:
         raise ValueError('no tangent defined')
コード例 #15
0
def through_sections():
    #ruled
    circle_1 = gp_Circ(gp_Ax2(gp_Pnt(-100., 0., -100.), gp_Dir(0., 0., 1.)),
                       40.)
    wire_1 = BRepBuilderAPI_MakeWire(
        BRepBuilderAPI_MakeEdge(circle_1).Edge()).Wire()
    circle_2 = gp_Circ(gp_Ax2(gp_Pnt(-10., 0., -0.), gp_Dir(0., 0., 1.)), 40.)
    wire_2 = BRepBuilderAPI_MakeWire(
        BRepBuilderAPI_MakeEdge(circle_2).Edge()).Wire()
    circle_3 = gp_Circ(gp_Ax2(gp_Pnt(-75., 0., 100.), gp_Dir(0., 0., 1.)), 40.)
    wire_3 = BRepBuilderAPI_MakeWire(
        BRepBuilderAPI_MakeEdge(circle_3).Edge()).Wire()
    circle_4 = gp_Circ(gp_Ax2(gp_Pnt(0., 0., 200.), gp_Dir(0., 0., 1.)), 40.)
    wire_4 = BRepBuilderAPI_MakeWire(
        BRepBuilderAPI_MakeEdge(circle_4).Edge()).Wire()

    generatorA = BRepOffsetAPI_ThruSections(False, True)
    # the use of the map function fails at producing the ThruSection
    # on py3k. Why ?
    # map(generatorA.AddWire, [wire_1, wire_2, wire_3, wire_4])
    # we have to use a loop
    for wir in [wire_1, wire_2, wire_3, wire_4]:
        generatorA.AddWire(wir)
    generatorA.Build()
    display.DisplayShape(generatorA.Shape())

    #smooth
    circle_1b = gp_Circ(gp_Ax2(gp_Pnt(100., 0., -100.), gp_Dir(0., 0., 1.)),
                        40.)
    wire_1b = BRepBuilderAPI_MakeWire(
        BRepBuilderAPI_MakeEdge(circle_1b).Edge()).Wire()
    circle_2b = gp_Circ(gp_Ax2(gp_Pnt(210., 0., -0.), gp_Dir(0., 0., 1.)), 40.)
    wire_2b = BRepBuilderAPI_MakeWire(
        BRepBuilderAPI_MakeEdge(circle_2b).Edge()).Wire()
    circle_3b = gp_Circ(gp_Ax2(gp_Pnt(275., 0., 100.), gp_Dir(0., 0., 1.)),
                        40.)
    wire_3b = BRepBuilderAPI_MakeWire(
        BRepBuilderAPI_MakeEdge(circle_3b).Edge()).Wire()
    circle_4b = gp_Circ(gp_Ax2(gp_Pnt(200., 0., 200.), gp_Dir(0., 0., 1.)),
                        40.)
    wire_4b = BRepBuilderAPI_MakeWire(
        BRepBuilderAPI_MakeEdge(circle_4b).Edge()).Wire()
    generatorB = BRepOffsetAPI_ThruSections(True, False)
    # same here, the following line fails
    # map(generatorB.AddWire, [wire_1b, wire_2b, wire_3b, wire_4b])
    for wir in [wire_1b, wire_2b, wire_3b, wire_4b]:
        generatorB.AddWire(wir)
    generatorB.Build()
    display.DisplayShape(generatorB.Shape(), update=True)
コード例 #16
0
def vectorized_slicer(li):
    # Create Plane defined by a point and the perpendicular direction
    z_values, shape = li
    _slices = []
    for z in z_values:
        #print 'slicing index:', z, 'sliced by process:', os.getpid()
        plane = gp_Pln(gp_Pnt(0., 0., z), gp_Dir(0., 0., 1.))
        face = BRepBuilderAPI_MakeFace(plane).Shape()
        # Computes Shape/Plane intersection
        section = BRepAlgoAPI_Section(shape, face)
        section.Build()
        if section.IsDone():
            _slices.append(section.Shape())
    return _slices
コード例 #17
0
    def normal(self, u):
        '''returns the normal at u

        computes the main normal if no normal is found
        see:
        www.opencascade.org/org/forum/thread_645+&cd=10&hl=nl&ct=clnk&gl=nl
        '''
        try:
            self._curvature.SetParameter(u)
            a_dir = gp_Dir()
            self._curvature.Normal(a_dir)
            return a_dir
        except:
            raise ValueError('no normal was found')
コード例 #18
0
def draft_angle(event=None):
    S = BRepPrimAPI_MakeBox(200., 300., 150.).Shape()
    adraft = BRepOffsetAPI_DraftAngle(S)
    topExp = TopExp_Explorer()
    topExp.Init(S, TopAbs_FACE)
    while topExp.More():
        face = topods_Face(topExp.Current())
        surf = Geom_Plane.DownCast(BRep_Tool_Surface(face))
        dirf = surf.Pln().Axis().Direction()
        ddd = gp_Dir(0, 0, 1)
        if dirf.IsNormal(ddd, precision_Angular()):
            adraft.Add(face, ddd, math.radians(15), gp_Pln(gp_Ax3(gp_XOY())))
        topExp.Next()
    adraft.Build()
    display.DisplayShape(adraft.Shape(), update=True)
コード例 #19
0
    def make_shape(self):
        # 1 - retrieve the data from the UIUC airfoil data page
        foil_dat_url = 'http://m-selig.ae.illinois.edu/ads/coord_seligFmt/%s.dat' % self.profile
        print("Connecting to m-selig, retrieving foil data")
        f = urllib2.urlopen(foil_dat_url)
        print("Building foil geometry")
        plan = gp_Pln(gp_Pnt(0., 0., 0.), gp_Dir(0., 0.,
                                                 1.))  # Z=0 plan / XY plan
        section_pts_2d = []

        for line in f.readlines()[1:]:  # The first line contains info only
            # 2 - do some cleanup on the data (mostly dealing with spaces)
            data = line.split()
            # 3 - create an array of points
            if len(data) == 2:  # two coordinates for each point
                section_pts_2d.append(
                    gp_Pnt2d(
                        float(data[0]) * self.chord,
                        float(data[1]) * self.chord))

        # 4 - use the array to create a spline describing the airfoil section
        spline_2d = Geom2dAPI_PointsToBSpline(
            point2d_list_to_TColgp_Array1OfPnt2d(section_pts_2d),
            len(section_pts_2d) - 1,  # order min
            len(section_pts_2d))  # order max
        spline = geomapi.To3d(spline_2d.Curve(), plan)

        # 5 - figure out if the trailing edge has a thickness or not,
        # and create a Face
        try:
            # first and last point of spline -> trailing edge
            trailing_edge = make_edge(
                gp_Pnt(section_pts_2d[0].X(), section_pts_2d[0].Y(), 0.0),
                gp_Pnt(section_pts_2d[-1].X(), section_pts_2d[-1].Y(), 0.0))
            face = BRepBuilderAPI_MakeFace(
                make_wire([make_edge(spline), trailing_edge]))
        except AssertionError:
            # the trailing edge segment could not be created, probably because
            # the points are too close
            # No need to build a trailing edge
            face = BRepBuilderAPI_MakeFace(make_wire(make_edge(spline)))

        # 6 - extrude the Face to create a Solid
        return BRepPrimAPI_MakePrism(
            face.Face(), gp_Vec(gp_Pnt(0., 0., 0.),
                                gp_Pnt(0., 0., self.span))).Shape()
コード例 #20
0
def split_face_with_edge(event=None):
    display.EraseAll()
    p0 = gp_Pnt()
    vnorm = gp_Dir(1, 0, 0)
    pln = gp_Pln(p0, vnorm)
    face = BRepBuilderAPI_MakeFace(pln, -10, 10, -10, 10).Face()
    p1 = gp_Pnt(0, 0, 15)
    p2 = gp_Pnt(0, 0, -15)
    edge = BRepBuilderAPI_MakeEdge(p1, p2).Edge()
    # Initialize splitter
    splitter = BOPAlgo_Splitter()
    # Add the face as an argument and the edge as a tool. This will split
    # the face with the edge.
    splitter.AddArgument(face)
    splitter.AddTool(edge)
    splitter.Perform()
    display.DisplayShape(splitter.Shape())
    display.FitAll()
コード例 #21
0
def axis():
    p1 = gp_Pnt(2., 3., 4.)
    d = gp_Dir(4., 5., 6.)
    a = gp_Ax3(p1, d)
    a_IsDirect = a.Direct()
    print("a is direct:", a_IsDirect)
    # a_XDirection = a.XDirection()
    # a_YDirection = a.YDirection()
    p2 = gp_Pnt(5., 3., 4.)
    a2 = gp_Ax3(p2, d)
    a2.YReverse()
    # axis3 is now left handed
    a2_IsDirect = a2.Direct()
    print("a2 is direct:", a2_IsDirect)
    # a2_XDirection = a2.XDirection()
    # a2_YDirection = a2.YDirection()
    gui.add(p1)
    gui.add(p2)
コード例 #22
0
    def create_shape(self):
        d = self.declaration
        if not d.source:
            return
        if os.path.exists(os.path.expanduser(d.source)):
            svg = etree.parse(os.path.expanduser(d.source)).getroot()
        else:
            svg = etree.fromstring(d.source)
        node = self.doc = OccSvgDoc(element=svg)
        viewbox = svg.attrib.get('viewBox')
        x, y = (0, 0)
        sx, sy = (1, 1)
        if viewbox:
            ow = parse_unit(svg.attrib.get('width'))
            oh = parse_unit(svg.attrib.get('height'))
            x, y, iw, ih = map(parse_unit, viewbox.split())
            sx = ow / iw
            sy = oh / ih

        builder = BRep_Builder()
        shape = TopoDS_Compound()
        builder.MakeCompound(shape)

        shapes = node.create_shape()
        for s in shapes:
            builder.Add(shape, s)

        bbox = self.get_bounding_box(shape)

        # Move to position and align along direction axis
        t = self.get_transform()
        if d.mirror:
            m = gp_Trsf()
            m.SetMirror(gp_Ax2(gp_Pnt(*bbox.center), gp_Dir(0, 1, 0)))
            t.Multiply(m)

        # Apply viewport scale
        s = gp_Trsf()
        s.SetValues(sx, 0, 0, x, 0, sy, 0, y, 0, 0, 1, 0)
        t.Multiply(s)

        self.shape = BRepBuilderAPI_Transform(shape, t, False).Shape()
コード例 #23
0
def axis():
    p1 = gp_Pnt(2., 3., 4.)
    d = gp_Dir(4., 5., 6.)
    a = gp_Ax3(p1, d)
    a_IsDirect = a.Direct()
    print("a is direct:", a_IsDirect)
    # a_XDirection = a.XDirection()
    # a_YDirection = a.YDirection()
    p2 = gp_Pnt(5., 3., 4.)
    a2 = gp_Ax3(p2, d)
    a2.YReverse()
    # axis3 is now left handed
    a2_IsDirect = a2.Direct()
    print("a2 is direct:", a2_IsDirect)
    # a2_XDirection = a2.XDirection()
    # a2_YDirection = a2.YDirection()
    display.DisplayShape(p1, update=True)
    display.DisplayShape(p2, update=True)
    display.DisplayMessage(p1, "P1")
    display.DisplayMessage(p2, "P2")
コード例 #24
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
コード例 #25
0
def revolved_shape():
    """ demonstrate how to create a revolved shape from an edge

    adapted from algotopia.com's opencascade_basic tutorial:
    http://www.algotopia.com/contents/opencascade/opencascade_basic

    """
    face_inner_radius = 0.6
    # point to create an edge from
    edg_points = [
        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),
    ]

    # aggregate edges in wire
    hexwire = BRepBuilderAPI_MakeWire()

    for i in range(6):
        hexedge = BRepBuilderAPI_MakeEdge(edg_points[i],
                                          edg_points[i + 1]).Edge()
        hexwire.Add(hexedge)

    hexwire_wire = hexwire.Wire()
    # face from wire
    hexface = BRepBuilderAPI_MakeFace(hexwire_wire).Face()
    revolve_axis = gp_Ax1(gp_Pnt(0, 0, 0), gp_Dir(0, 0, 1))
    # create revolved shape
    revolved_shape_ = BRepPrimAPI_MakeRevol(hexface, revolve_axis,
                                            math.radians(90.)).Shape()

    # render wire & revolved shape
    display.DisplayShape([revolved_shape_, hexwire_wire])
    display.FitAll()
    start_display()
コード例 #26
0
ファイル: occ_svg.py プロジェクト: hixio-mh/declaracad
#from OCCT.BRepLib import breplib_BuildCurves3d
from OCCT.GC import GC_MakeArcOfEllipse
from OCCT.Geom import Geom_BezierCurve, Geom_BSplineCurve
from OCCT.gp import (
    gp_Dir, gp_Pnt, gp_Circ, gp_Elips, gp_Ax1, gp_Ax2, gp_Trsf, gp_Ax3, gp_Vec
)
from OCCT.TColgp import TColgp_Array1OfPnt
from OCCT.TopoDS import TopoDS_Shape, TopoDS_Compound#, topods


from .occ_shape import OccShape
from ..draw import ProxySvg

from declaracad.core.utils import log

Z_DIR = gp_Dir(0, 0, 1)
NEG_Z_DIR = gp_Dir(0, 0, -1)
Z_AXIS = gp_Ax1(gp_Pnt(0, 0, 0), Z_DIR)

UNITS = {
    'in': 90.0, 'pt': 1.25, 'px': 1, 'mm': 3.5433070866,
    'cm': 35.433070866, 'm': 3543.3070866,
    'km': 3543307.0866, 'pc': 15.0, 'yd': 3240, 'ft': 1080
}

# From  simplepath.py's parsePath by Aaron Spike, [email protected]
PATHDEFS = {
    'M': ['L', 2, [float, float], ['x', 'y']],
    'L': ['L', 2, [float, float], ['x', 'y']],
    'H': ['H', 1, [float], ['x']],
    'V': ['V', 1, [float], ['y']],
コード例 #27
0
                 tube_radius,
                 axis_length,
                 cone_radius,
                 cone_length,
                 number_of_facetts=360):
        super().__init__()
        self.params = (axis, tube_radius, axis_length, cone_radius,
                       cone_length, int(number_of_facetts))
        self.SetInfiniteState(True)

    def Compute(self, prs_mgr, pres, mode):
        group = pres.CurrentGroup()
        handle = Prs3d_Arrow.DrawShaded_(*self.params)
        group.SetPrimitivesAspect(self.Attributes().ShadingAspect().Aspect())
        group.__class__ = Graphic3d_Group  # Hack?
        group.AddPrimitiveArray(handle)

    def ComputeSelection(self, pres, mode):
        pass


axis = gp_Ax2(gp_Pnt(0, 0, 0), gp_Dir(1, 0, 0)).Axis()
ais_arrow = AIS_Arrow(axis, 0.5, 3, 1, 1)

v = ShapeViewer()
if use_wx:
    v.display_ais(ais_arrow)
else:
    v.view.display(ais_arrow)
v.start()
コード例 #28
0
 def YZ(cls, x, y):
     # Create a direction in the XY plane
     v = gp_Dir()
     v.Rotate(gp.OX_(), math.atan2(y, x))
     return Direction(v.X(), v.Y(), v.Z())
コード例 #29
0
 def _default_proxy(self):
     return gp_Dir(self.x, self.y, self.z)
コード例 #30
0
def variable_filleting(event=None):
    display.EraseAll()
    # Create Box
    Box = BRepPrimAPI_MakeBox(200, 200, 200).Shape()
    # Fillet
    Rake = BRepFilletAPI_MakeFillet(Box)
    ex = TopologyExplorer(Box).edges()
    next(ex)
    next(ex)
    next(ex)

    Rake.Add(8, 50, next(ex))
    Rake.Build()
    if Rake.IsDone():
        evolvedBox = Rake.Shape()
        display.DisplayShape(evolvedBox)
    else:
        print("Rake not done.")
    # Create Cylinder
    Cylinder = BRepPrimAPI_MakeCylinder(
        gp_Ax2(gp_Pnt(-300, 0, 0), gp_Dir(0, 0, 1)), 100, 200).Shape()
    fillet_ = BRepFilletAPI_MakeFillet(Cylinder)

    TabPoint2 = TColgp_Array1OfPnt2d(0, 20)
    for i in range(0, 20):
        Point2d = gp_Pnt2d(i * 2 * pi / 19,
                           60 * cos(i * pi / 19 - pi / 2) + 10)
        TabPoint2.SetValue(i, Point2d)

    exp2 = TopologyExplorer(Cylinder).edges()
    fillet_.Add(TabPoint2, next(exp2))
    fillet_.Build()
    if fillet_.IsDone():
        LawEvolvedCylinder = fillet_.Shape()
        display.DisplayShape(LawEvolvedCylinder)
    else:
        print("fillet not done.")  ## TODO : fillet not done
    P = gp_Pnt(350, 0, 0)
    Box2 = BRepPrimAPI_MakeBox(P, 200, 200, 200).Shape()
    afillet = BRepFilletAPI_MakeFillet(Box2)

    TabPoint = TColgp_Array1OfPnt2d(1, 6)
    P1 = gp_Pnt2d(0., 8.)
    P2 = gp_Pnt2d(0.2, 16.)
    P3 = gp_Pnt2d(0.4, 25.)
    P4 = gp_Pnt2d(0.6, 55.)
    P5 = gp_Pnt2d(0.8, 28.)
    P6 = gp_Pnt2d(1., 20.)
    TabPoint.SetValue(1, P1)
    TabPoint.SetValue(2, P2)
    TabPoint.SetValue(3, P3)
    TabPoint.SetValue(4, P4)
    TabPoint.SetValue(5, P5)
    TabPoint.SetValue(6, P6)

    exp = TopologyExplorer(Box2).edges()
    next(exp)
    next(exp)
    next(exp)

    afillet.Add(TabPoint, next(exp))
    afillet.Build()
    if afillet.IsDone():
        LawEvolvedBox = afillet.Shape()
        display.DisplayShape(LawEvolvedBox)
    else:
        print("aFillet not done.")
    display.FitAll()