From e59acdce5720d84ce76134789b48c268e36446d6 Mon Sep 17 00:00:00 2001 From: Thomas Paviot Date: Sat, 17 Nov 2018 10:40:10 +0100 Subject: [PATCH] Refactored examples to use transparent handles --- examples/core_classic_occ_bottle.py | 20 +- examples/core_dimensions.py | 4 +- examples/core_display_clip_planes.py | 6 +- examples/core_display_customize_linewidth.py | 4 +- examples/core_display_customize_prs3d.py | 12 +- examples/core_display_export_to_EF.py | 10 +- examples/core_display_line_properties.py | 16 +- examples/core_display_overlayered_image.py | 4 +- examples/core_display_point_cloud.py | 18 +- examples/core_display_quality.py | 2 +- examples/core_display_set_edge_color.py | 7 +- examples/core_geometry_bisector.py | 2 +- examples/core_geometry_bspline.py | 4 +- examples/core_geometry_curves2d_from_curve.py | 4 +- examples/core_geometry_faircurve.py | 3 +- examples/core_geometry_geomplate.py | 14 +- examples/core_geometry_point_from_curve.py | 2 +- .../core_geometry_project_point_on_curve.py | 2 +- examples/core_geometry_surface_from_curves.py | 18 +- examples/core_load_step_ap203_ocaf.py | 28 +- examples/core_load_step_with_colors.py | 244 +----------------- examples/core_mesh_fast_stl_load.py | 15 +- examples/core_mesh_surfacic.py | 20 +- examples/core_mesh_volumic.py | 10 +- examples/core_modeling_sprocket.py | 58 ++--- examples/core_simple_mesh.py | 2 +- examples/core_topology_draft_angle.py | 4 +- examples/core_topology_edge.py | 4 +- examples/core_topology_face.py | 6 +- examples/core_topology_heightmap.py | 8 +- examples/core_topology_local_ops.py | 15 +- .../core_visualization_ais_coloredshape.py | 6 +- examples/core_visualization_camera.py | 2 +- examples/core_visualization_glsl.py | 14 +- ...e_visualization_graphic3d_custom_opengl.py | 6 +- examples/core_webgl_threejs_helix.py | 5 +- .../core_topology_draft_angle.ipynb | 4 +- 37 files changed, 181 insertions(+), 422 deletions(-) diff --git a/examples/core_classic_occ_bottle.py b/examples/core_classic_occ_bottle.py index f4ae24c..eaafd83 100755 --- a/examples/core_classic_occ_bottle.py +++ b/examples/core_classic_occ_bottle.py @@ -22,8 +22,8 @@ from OCC.Core.gp import gp_Pnt, gp_OX, gp_Vec, gp_Trsf, gp_DZ, gp_Ax2, gp_Ax3, gp_Pnt2d, gp_Dir2d, gp_Ax2d from OCC.Core.GC import GC_MakeArcOfCircle, GC_MakeSegment from OCC.Core.GCE2d import GCE2d_MakeSegment -from OCC.Core.Geom import Geom_Plane, Geom_CylindricalSurface, Handle_Geom_Plane, Handle_Geom_Surface -from OCC.Core.Geom2d import Geom2d_Ellipse, Geom2d_TrimmedCurve, Handle_Geom2d_Ellipse, Handle_Geom2d_Curve +from OCC.Core.Geom import Geom_Plane, Geom_CylindricalSurface, Geom_Plane, Geom_Surface +from OCC.Core.Geom2d import Geom2d_Ellipse, Geom2d_TrimmedCurve, Geom2d_Ellipse, Geom2d_Curve from OCC.Core.BRepBuilderAPI import BRepBuilderAPI_MakeEdge, BRepBuilderAPI_MakeWire, BRepBuilderAPI_MakeFace, \ BRepBuilderAPI_Transform from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakePrism, BRepPrimAPI_MakeCylinder @@ -42,7 +42,7 @@ def face_is_plane(face): Returns True if the TopoDS_Shape is a plane, False otherwise """ hs = BRep_Tool_Surface(face) - downcast_result = Handle_Geom_Plane.DownCast(hs) + downcast_result = Geom_Plane.DownCast(hs) # The handle is null if downcast failed or is not possible, that is to say the face is not a plane if downcast_result.IsNull(): return False @@ -54,7 +54,7 @@ def geom_plane_from_face(aFace): """ Returns the geometric plane entity from a planar surface """ - return Handle_Geom_Plane.DownCast(BRep_Tool_Surface(aFace)).GetObject() + return Geom_Plane.DownCast(BRep_Tool_Surface(aFace)) height = 70 @@ -176,8 +176,8 @@ def geom_plane_from_face(aFace): anEllipse1 = Geom2d_Ellipse(anAx2d, aMajor, aMinor) anEllipse2 = Geom2d_Ellipse(anAx2d, aMajor, aMinor / 4.0) -anArc1 = Geom2d_TrimmedCurve(Handle_Geom2d_Ellipse(anEllipse1), 0, math.pi) -anArc2 = Geom2d_TrimmedCurve(Handle_Geom2d_Ellipse(anEllipse2), 0, math.pi) +anArc1 = Geom2d_TrimmedCurve(Geom2d_Ellipse(anEllipse1), 0, math.pi) +anArc2 = Geom2d_TrimmedCurve(Geom2d_Ellipse(anEllipse2), 0, math.pi) anEllipsePnt1 = anEllipse1.Value(0) anEllipsePnt2 = anEllipse1.Value(math.pi) @@ -185,10 +185,10 @@ def geom_plane_from_face(aFace): aSegment = GCE2d_MakeSegment(anEllipsePnt1, anEllipsePnt2) # Build edges and wires for threading -anEdge1OnSurf1 = BRepBuilderAPI_MakeEdge(Handle_Geom2d_Curve(anArc1), Handle_Geom_Surface(aCyl1)) -anEdge2OnSurf1 = BRepBuilderAPI_MakeEdge(aSegment.Value(), Handle_Geom_Surface(aCyl1)) -anEdge1OnSurf2 = BRepBuilderAPI_MakeEdge(Handle_Geom2d_Curve(anArc2), Handle_Geom_Surface(aCyl2)) -anEdge2OnSurf2 = BRepBuilderAPI_MakeEdge(aSegment.Value(), Handle_Geom_Surface(aCyl2)) +anEdge1OnSurf1 = BRepBuilderAPI_MakeEdge(Geom2d_Curve(anArc1), Geom_Surface(aCyl1)) +anEdge2OnSurf1 = BRepBuilderAPI_MakeEdge(aSegment.Value(), Geom_Surface(aCyl1)) +anEdge1OnSurf2 = BRepBuilderAPI_MakeEdge(Geom2d_Curve(anArc2), Geom_Surface(aCyl2)) +anEdge2OnSurf2 = BRepBuilderAPI_MakeEdge(aSegment.Value(), Geom_Surface(aCyl2)) threadingWire1 = BRepBuilderAPI_MakeWire(anEdge1OnSurf1.Edge(), anEdge2OnSurf1.Edge()) threadingWire2 = BRepBuilderAPI_MakeWire(anEdge1OnSurf2.Edge(), anEdge2OnSurf2.Edge()) diff --git a/examples/core_dimensions.py b/examples/core_dimensions.py index f88568a..47e7b85 100644 --- a/examples/core_dimensions.py +++ b/examples/core_dimensions.py @@ -27,11 +27,11 @@ 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()) +display.Context.Display(ais_shp) rd = AIS_RadiusDimension(ec) #rd.SetArrowSize(12) -display.Context.Display(rd.GetHandle()) +display.Context.Display(rd) display.FitAll() start_display() diff --git a/examples/core_display_clip_planes.py b/examples/core_display_clip_planes.py index 0a9c55e..46b4f8e 100644 --- a/examples/core_display_clip_planes.py +++ b/examples/core_display_clip_planes.py @@ -17,8 +17,6 @@ ##You should have received a copy of the GNU Lesser General Public License ##along with pythonOCC. If not, see . -from __future__ import print_function - import sys from OCC.Core.gp import gp_Vec @@ -36,7 +34,7 @@ builder = BRep_Builder() breptools_Read(cylinder_head, '../assets/models/cylinder_head.brep', builder) -ais_shp = display.DisplayShape(cylinder_head).GetObject() +ais_shp = display.DisplayShape(cylinder_head) # clip plane number one, by default xOy clip_plane_1 = Graphic3d_ClipPlane() @@ -54,7 +52,7 @@ aMat.SetAmbientColor(aColor) aMat.SetDiffuseColor(aColor) clip_plane_1.SetCappingMaterial(aMat) -ais_shp.AddClipPlane(clip_plane_1.GetHandle()) +ais_shp.AddClipPlane(clip_plane_1) def enable_clip_plane(event=None): diff --git a/examples/core_display_customize_linewidth.py b/examples/core_display_customize_linewidth.py index 5104a5f..8e7cdd8 100644 --- a/examples/core_display_customize_linewidth.py +++ b/examples/core_display_customize_linewidth.py @@ -38,8 +38,8 @@ # Get context and display shape # # Get Context -ais_context = display.GetContext().GetObject() -ais_context.Display(ais_shp.GetHandle()) +ais_context = display.GetContext() +ais_context.Display(ais_shp) display.View_Iso() display.FitAll() diff --git a/examples/core_display_customize_prs3d.py b/examples/core_display_customize_prs3d.py index a5fd134..648cb83 100644 --- a/examples/core_display_customize_prs3d.py +++ b/examples/core_display_customize_prs3d.py @@ -24,28 +24,28 @@ from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeCylinder from OCC.Display.SimpleGui import init_display + display, start_display, add_menu, add_function_to_menu = init_display() display.SetModeHLR() # # Get Context # -ais_context = display.GetContext().GetObject() +ais_context = display.GetContext() # # Get Prs3d_drawer from previous context # -drawer_handle = ais_context.DefaultDrawer() -drawer = drawer_handle.GetObject() +drawer = ais_context.DefaultDrawer() drawer.SetIsoOnPlane(True) -la = drawer.LineAspect().GetObject() +la = drawer.LineAspect() la.SetWidth(4) # increase line width in the current viewer # This is only viewed in the HLR mode (hit 'e' key for instance) -line_aspect = drawer.SeenLineAspect().GetObject() +line_aspect = drawer.SeenLineAspect() drawer.EnableDrawHiddenLine() line_aspect.SetWidth(4) # -drawer.SetWireAspect(line_aspect.GetHandle()) +drawer.SetWireAspect(line_aspect) # # Displays a cylinder # diff --git a/examples/core_display_export_to_EF.py b/examples/core_display_export_to_EF.py index 74977d7..96b66ce 100644 --- a/examples/core_display_export_to_EF.py +++ b/examples/core_display_export_to_EF.py @@ -18,16 +18,16 @@ from OCC.Display.SimpleGui import init_display from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeTorus from OCC.Core.Graphic3d import (Graphic3d_EF_PDF, - Graphic3d_EF_SVG, - Graphic3d_EF_TEX, - Graphic3d_EF_PostScript, - Graphic3d_EF_EnhPostScript) + Graphic3d_EF_SVG, + Graphic3d_EF_TEX, + Graphic3d_EF_PostScript, + Graphic3d_EF_EnhPostScript) display, start_display, add_menu, add_function_to_menu = init_display() my_box = BRepPrimAPI_MakeTorus(40., 20.).Shape() display.DisplayShape(my_box, update=True) -f = display.View.View().GetObject() +f = display.View.View() #------------------------------------------------------------------------------- # for this example to work, pythonocc / OCE needs to be built with the gl2ps lib diff --git a/examples/core_display_line_properties.py b/examples/core_display_line_properties.py index c139064..40c9c67 100644 --- a/examples/core_display_line_properties.py +++ b/examples/core_display_line_properties.py @@ -36,7 +36,7 @@ def line(): d1 = gp_Dir(4., 5., 6.) line1 = Geom_Line(p1, d1) - ais_line1 = AIS_Line(line1.GetHandle()) + ais_line1 = AIS_Line(line1) # if we need to edit color, we can simply use SetColor # ais_line1.SetColor(Quantity_NOC_RED) @@ -45,25 +45,25 @@ def line(): # To do that, we need to do use AIS_Drawer and apply it to ais_line1 width = 1.0 drawer = Prs3d_Drawer() - ais_line1.SetAttributes(drawer.GetHandle()) + ais_line1.SetAttributes(drawer) - display.Context.Display(ais_line1.GetHandle(), False) + 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.GetHandle()) + ais_line2 = AIS_Line(line2) width = float(i) - drawer = ais_line2.Attributes().GetObject() + drawer = ais_line2.Attributes() # asp : first parameter color, second type, last width asp = Prs3d_LineAspect(9*i, i, width) - drawer.SetLineAspect(asp.GetHandle()) - ais_line2.SetAttributes(drawer.GetHandle()) + drawer.SetLineAspect(asp) + ais_line2.SetAttributes(drawer) - display.Context.Display(ais_line2.GetHandle(), False) + display.Context.Display(ais_line2, False) start_display() diff --git a/examples/core_display_overlayered_image.py b/examples/core_display_overlayered_image.py index 5a79e32..1b63db0 100644 --- a/examples/core_display_overlayered_image.py +++ b/examples/core_display_overlayered_image.py @@ -30,7 +30,7 @@ def absolute_position(event=None): # create a texture aTextureItem = TextureItem(TCollection_AsciiString("../assets/images/carre-200.png"), - display.GetView().GetObject(), + display.GetView(), display.GetOverLayer()) aTextureItem.SetAbsolutePosition(50, 50) display.register_overlay_item(aTextureItem) @@ -39,7 +39,7 @@ def absolute_position(event=None): def relative_position(event=None): # create a texture aTextureItem = TextureItem(TCollection_AsciiString("../assets/images/carre-200.png"), - display.GetView().GetObject(), + display.GetView(), display.GetOverLayer()) aTextureItem.SetRelativePosition(30, 60) # 30% width, 60% width display.register_overlay_item(aTextureItem) diff --git a/examples/core_display_point_cloud.py b/examples/core_display_point_cloud.py index e966f70..62f4580 100644 --- a/examples/core_display_point_cloud.py +++ b/examples/core_display_point_cloud.py @@ -42,11 +42,11 @@ def random_points(event=None): # then build the point cloud point_cloud = AIS_PointCloud() - point_cloud.SetPoints(points_3d.GetHandle()) + point_cloud.SetPoints(points_3d) # display - ais_context = display.GetContext().GetObject() - ais_context.Display(point_cloud.GetHandle()) + ais_context = display.GetContext() + ais_context.Display(point_cloud) display.View_Iso() display.FitAll() @@ -58,9 +58,9 @@ def bunny(event=None): x, y, z = map(float, line.split()) pc.AddVertex(x, y, z) point_cloud = AIS_PointCloud() - point_cloud.SetPoints(pc.GetHandle()) - ais_context = display.GetContext().GetObject() - ais_context.Display(point_cloud.GetHandle()) + point_cloud.SetPoints(pc) + ais_context = display.GetContext() + ais_context.Display(point_cloud) display.View_Iso() display.FitAll() @@ -76,10 +76,10 @@ def tabletop(event=None): # then build the point cloud point_cloud = AIS_PointCloud() - point_cloud.SetPoints(pc.GetHandle()) + point_cloud.SetPoints(pc) # display - ais_context = display.GetContext().GetObject() - ais_context.Display(point_cloud.GetHandle()) + ais_context = display.GetContext() + ais_context.Display(point_cloud) display.DisableAntiAliasing() display.View_Iso() display.FitAll() diff --git a/examples/core_display_quality.py b/examples/core_display_quality.py index 208ebcf..d493397 100644 --- a/examples/core_display_quality.py +++ b/examples/core_display_quality.py @@ -30,7 +30,7 @@ # # Get Context # -ais_context = display.GetContext().GetObject() +ais_context = display.GetContext() # # Display current quality dc = ais_context.DeviationCoefficient() diff --git a/examples/core_display_set_edge_color.py b/examples/core_display_set_edge_color.py index 33bc809..6349695 100644 --- a/examples/core_display_set_edge_color.py +++ b/examples/core_display_set_edge_color.py @@ -27,12 +27,11 @@ context.SetAutoActivateSelection(False) aisShape = AIS_Shape(myBox) -h_aisShape = aisShape.GetHandle() -context.Display(h_aisShape) +context.Display(aisShape) # Set shape transparency, a float number from 0.0 to 1.0 -context.SetTransparency(h_aisShape, 0.6) -context.HilightWithColor(h_aisShape, Quantity_NOC_BLACK) +context.SetTransparency(aisShape, 0.6) +context.HilightWithColor(aisShape, Quantity_NOC_BLACK) display.View_Iso() display.FitAll() diff --git a/examples/core_geometry_bisector.py b/examples/core_geometry_bisector.py index b0ef71e..7cb0dff 100644 --- a/examples/core_geometry_bisector.py +++ b/examples/core_geometry_bisector.py @@ -52,7 +52,7 @@ def bisect_linecircle(event=None): li1 = gp_Lin2d(gp_Pnt2d(2000000, 20), gp_Dir2d(0, 1)) bi = GccAna_CircLin2dBisec(ci1, li1) assert bi.IsDone() - bisec = bi.ThisSolution(1).GetObject() + bisec = bi.ThisSolution(1) pb = bisec.Parabola() display.DisplayShape([make_edge2d(ci1), make_edge2d(li1)]) display.DisplayColoredShape(make_edge2d(pb), 'BLUE') diff --git a/examples/core_geometry_bspline.py b/examples/core_geometry_bspline.py index c254afd..cb70fb0 100644 --- a/examples/core_geometry_bspline.py +++ b/examples/core_geometry_bspline.py @@ -45,7 +45,7 @@ def bspline(): harray.SetValue(4, gp_Pnt2d(4, 3)) harray.SetValue(5, gp_Pnt2d(5, 5)) - anInterpolation = Geom2dAPI_Interpolate(harray.GetHandle(), False, 0.01) + anInterpolation = Geom2dAPI_Interpolate(harray, False, 0.01) anInterpolation.Perform() bspline_2 = anInterpolation.Curve() @@ -56,7 +56,7 @@ def bspline(): harray2.SetValue(4, gp_Pnt2d(15, 3)) harray2.SetValue(5, gp_Pnt2d(16, 5)) - anInterpolation2 = Geom2dAPI_Interpolate(harray.GetHandle(), True, 0.01) + anInterpolation2 = Geom2dAPI_Interpolate(harray, True, 0.01) anInterpolation2.Perform() bspline_3 = anInterpolation2.Curve() diff --git a/examples/core_geometry_curves2d_from_curve.py b/examples/core_geometry_curves2d_from_curve.py index 60d33ed..4736b97 100644 --- a/examples/core_geometry_curves2d_from_curve.py +++ b/examples/core_geometry_curves2d_from_curve.py @@ -17,8 +17,6 @@ ##You should have received a copy of the GNU Lesser General Public License ##along with pythonOCC. If not, see . -from __future__ import print_function - from OCC.Core.gp import gp_OX2d from OCC.Core.GCE2d import GCE2d_MakeEllipse from OCC.Core.Geom2d import Geom2d_TrimmedCurve @@ -34,7 +32,7 @@ def curves2d_from_curves(): axis = gp_OX2d() ellipse = GCE2d_MakeEllipse(axis, major, minor).Value() trimmed_curve = Geom2d_TrimmedCurve(ellipse, -1, 2, True) - bspline = geom2dconvert_CurveToBSplineCurve(trimmed_curve.GetHandle(), + bspline = geom2dconvert_CurveToBSplineCurve(trimmed_curve, Convert_TgtThetaOver2) display.DisplayShape(bspline, update=True) diff --git a/examples/core_geometry_faircurve.py b/examples/core_geometry_faircurve.py index 161b590..db4acbc 100644 --- a/examples/core_geometry_faircurve.py +++ b/examples/core_geometry_faircurve.py @@ -17,7 +17,6 @@ ##You should have received a copy of the GNU Lesser General Public License ##along with pythonOCC. If not, see . -from __future__ import print_function import math import time @@ -66,7 +65,7 @@ def faircurve(event=None): bc = batten_curve(pt1, pt2, height, slope, math.radians(i), math.radians(-i)) display.EraseAll() - edge = BRepBuilderAPI_MakeEdge(bc, pl.GetHandle()).Edge() + edge = BRepBuilderAPI_MakeEdge(bc, pl).Edge() display.DisplayShape(edge, update=True) time.sleep(0.21) diff --git a/examples/core_geometry_geomplate.py b/examples/core_geometry_geomplate.py index 893ef89..c9188b6 100644 --- a/examples/core_geometry_geomplate.py +++ b/examples/core_geometry_geomplate.py @@ -136,12 +136,12 @@ def build_plate(polygon, points): for edg in WireExplorer(poly).ordered_edges(): c = BRepAdaptor_HCurve() c.ChangeCurve().Initialize(edg) - constraint = BRepFill_CurveConstraint(c.GetHandle(), 0) - bpSrf.Add(constraint.GetHandle()) + constraint = BRepFill_CurveConstraint(c, 0) + bpSrf.Add(constraint) # add point constraint for pt in points: - bpSrf.Add(GeomPlate_PointConstraint(pt, 0).GetHandle()) + bpSrf.Add(GeomPlate_PointConstraint(pt, 0)) bpSrf.Perform() maxSeg, maxDeg, critOrder = 9, 8, 0 @@ -150,7 +150,7 @@ def build_plate(polygon, points): srf = bpSrf.Surface() plate = GeomPlate_MakeApprox(srf, tol, maxSeg, maxDeg, dmax, critOrder) - uMin, uMax, vMin, vMax = srf.GetObject().Bounds() + uMin, uMax, vMin, vMax = srf.Bounds() return make_face(plate.Surface(), uMin, uMax, vMin, vMax, 1e-4) @@ -256,8 +256,8 @@ def build_geom_plate(edges): c = BRepAdaptor_HCurve() print('edge:', edg) c.ChangeCurve().Initialize(edg) - constraint = BRepFill_CurveConstraint(c.GetHandle(), 0) - bpSrf.Add(constraint.GetHandle()) + constraint = BRepFill_CurveConstraint(c, 0) + bpSrf.Add(constraint) # add point constraint try: @@ -268,7 +268,7 @@ def build_geom_plate(edges): srf = bpSrf.Surface() plate = GeomPlate_MakeApprox(srf, 0.01, 10, 5, 0.01, 0, GeomAbs_C0) - uMin, uMax, vMin, vMax = srf.GetObject().Bounds() + uMin, uMax, vMin, vMax = srf.Bounds() face = make_face(plate.Surface(), uMin, uMax, vMin, vMax, 1e-6) return face diff --git a/examples/core_geometry_point_from_curve.py b/examples/core_geometry_point_from_curve.py index 36e490c..522be64 100644 --- a/examples/core_geometry_point_from_curve.py +++ b/examples/core_geometry_point_from_curve.py @@ -30,7 +30,7 @@ def points_from_curve(): radius = 5. abscissa = 3. circle = Geom2d_Circle(gp_OX2d(), radius, True) - gac = Geom2dAdaptor_Curve(circle.GetHandle()) + gac = Geom2dAdaptor_Curve(circle) ua = GCPnts_UniformAbscissa(gac, abscissa) a_sequence = [] if ua.IsDone(): diff --git a/examples/core_geometry_project_point_on_curve.py b/examples/core_geometry_project_point_on_curve.py index 241207c..a9d3000 100644 --- a/examples/core_geometry_project_point_on_curve.py +++ b/examples/core_geometry_project_point_on_curve.py @@ -41,7 +41,7 @@ def project_point_on_curve(): # project the point P on the circle projection = GeomAPI_ProjectPointOnCurve(point_to_project, - circle.GetHandle()) + circle) # get the results of the projection # the point projected_point = projection.NearestPoint() diff --git a/examples/core_geometry_surface_from_curves.py b/examples/core_geometry_surface_from_curves.py index 29c642b..00e158e 100644 --- a/examples/core_geometry_surface_from_curves.py +++ b/examples/core_geometry_surface_from_curves.py @@ -21,11 +21,11 @@ from OCC.Core.gp import gp_Pnt, gp_Vec from OCC.Core.GeomFill import (GeomFill_BSplineCurves, - GeomFill_StretchStyle, - GeomFill_CoonsStyle, - GeomFill_CurvedStyle) + GeomFill_StretchStyle, + GeomFill_CoonsStyle, + GeomFill_CurvedStyle) from OCC.Core.GeomAPI import GeomAPI_PointsToBSpline -from OCC.Core.Geom import Handle_Geom_BSplineCurve_DownCast +from OCC.Core.Geom import Geom_BSplineCurve_DownCast from OCC.Display.SimpleGui import init_display @@ -48,7 +48,6 @@ def surface_from_curves(): pt_list1 = point_list_to_TColgp_Array1OfPnt(array) SPL1 = GeomAPI_PointsToBSpline(pt_list1).Curve() - SPL1_c = SPL1.GetObject() # Second spline a2 = [] @@ -59,21 +58,20 @@ def surface_from_curves(): a2.append(gp_Pnt(4, 9, -1)) pt_list2 = point_list_to_TColgp_Array1OfPnt(a2) SPL2 = GeomAPI_PointsToBSpline(pt_list2).Curve() - SPL2_c = SPL2.GetObject() # Fill with StretchStyle aGeomFill1 = GeomFill_BSplineCurves(SPL1, SPL2, GeomFill_StretchStyle) - SPL3 = Handle_Geom_BSplineCurve_DownCast(SPL1_c.Translated(gp_Vec(10, 0, 0))) - SPL4 = Handle_Geom_BSplineCurve_DownCast(SPL2_c.Translated(gp_Vec(10, 0, 0))) + SPL3 = Geom_BSplineCurve_DownCast(SPL1.Translated(gp_Vec(10, 0, 0))) + SPL4 = Geom_BSplineCurve_DownCast(SPL2.Translated(gp_Vec(10, 0, 0))) # Fill with CoonsStyle aGeomFill2 = GeomFill_BSplineCurves(SPL3, SPL4, GeomFill_CoonsStyle) - SPL5 = Handle_Geom_BSplineCurve_DownCast(SPL1_c.Translated(gp_Vec(20, 0, 0))) - SPL6 = Handle_Geom_BSplineCurve_DownCast(SPL2_c.Translated(gp_Vec(20, 0, 0))) + SPL5 = Geom_BSplineCurve_DownCast(SPL1.Translated(gp_Vec(20, 0, 0))) + SPL6 = Geom_BSplineCurve_DownCast(SPL2.Translated(gp_Vec(20, 0, 0))) # Fill with CurvedStyle aGeomFill3 = GeomFill_BSplineCurves(SPL5, SPL6, diff --git a/examples/core_load_step_ap203_ocaf.py b/examples/core_load_step_ap203_ocaf.py index 7f7493a..e513c30 100644 --- a/examples/core_load_step_ap203_ocaf.py +++ b/examples/core_load_step_ap203_ocaf.py @@ -20,12 +20,12 @@ from OCC.Core.TCollection import TCollection_ExtendedString -from OCC.Core.TDocStd import Handle_TDocStd_Document +from OCC.Core.TDocStd import TDocStd_Document from OCC.Core.XCAFApp import XCAFApp_Application from OCC.Core.XCAFDoc import (XCAFDoc_DocumentTool_ShapeTool, - XCAFDoc_DocumentTool_ColorTool, - XCAFDoc_DocumentTool_LayerTool, - XCAFDoc_DocumentTool_MaterialTool) + XCAFDoc_DocumentTool_ColorTool, + XCAFDoc_DocumentTool_LayerTool, + XCAFDoc_DocumentTool_MaterialTool) from OCC.Core.STEPCAFControl import STEPCAFControl_Reader from OCC.Core.IFSelect import IFSelect_RetDone from OCC.Core.TDF import TDF_LabelSequence @@ -36,15 +36,14 @@ _shapes = [] # create an handle to a document -h_doc = Handle_TDocStd_Document() +doc = TDocStd_Document() # Create the application -app = XCAFApp_Application.GetApplication().GetObject() -app.NewDocument(TCollection_ExtendedString("MDTV-CAF"), h_doc) +app = XCAFApp_Application.GetApplication() +app.NewDocument(TCollection_ExtendedString("MDTV-CAF"), doc) # Get root assembly -doc = h_doc.GetObject() -h_shape_tool = XCAFDoc_DocumentTool_ShapeTool(doc.Main()) +shape_tool = XCAFDoc_DocumentTool_ShapeTool(doc.Main()) l_colors = XCAFDoc_DocumentTool_ColorTool(doc.Main()) l_layers = XCAFDoc_DocumentTool_LayerTool(doc.Main()) l_materials = XCAFDoc_DocumentTool_MaterialTool(doc.Main()) @@ -57,13 +56,12 @@ status = step_reader.ReadFile(filename) if status == IFSelect_RetDone: - step_reader.Transfer(doc.GetHandle()) + step_reader.Transfer(doc) labels = TDF_LabelSequence() color_labels = TDF_LabelSequence() -shape_tool = h_shape_tool.GetObject() -h_shape_tool.GetObject().GetFreeShapes(labels) +shape_tool.GetFreeShapes(labels) print("Number of shapes at root :%i" % labels.Length()) for i in range(labels.Length()): @@ -71,7 +69,7 @@ print("Is Assembly :", shape_tool.IsAssembly(labels.Value(i+1))) sub_shapes = shape_tool.GetSubShapes(labels.Value(i+1), sub_shapes_labels) print("Number of subshapes in the assemly :%i" % sub_shapes_labels.Length()) -l_colors.GetObject().GetColors(color_labels) +l_colors.GetColors(color_labels) print("Number of colors=%i" % color_labels.Length()) for i in range(color_labels.Length()): @@ -80,8 +78,8 @@ for i in range(labels.Length()): label = labels.Value(i+1) - a_shape = h_shape_tool.GetObject().GetShape(label) - m = l_layers.GetObject().GetLayers(a_shape) + a_shape = shape_tool.GetShape(label) + m = l_layers.GetLayers(a_shape) _shapes.append(a_shape) # diff --git a/examples/core_load_step_with_colors.py b/examples/core_load_step_with_colors.py index fcbc725..1e5126c 100644 --- a/examples/core_load_step_with_colors.py +++ b/examples/core_load_step_with_colors.py @@ -15,243 +15,19 @@ ##You should have received a copy of the GNU Lesser General Public License ##along with pythonOCC. If not, see . -from __future__ import print_function - -import sys - -from OCC.Core.TDocStd import Handle_TDocStd_Document -from OCC.Core.XCAFApp import XCAFApp_Application -from OCC.Core.XCAFDoc import (XCAFDoc_DocumentTool_ShapeTool, - XCAFDoc_DocumentTool_ColorTool, - XCAFDoc_DocumentTool_LayerTool, - XCAFDoc_DocumentTool_MaterialTool) -from OCC.Core.STEPCAFControl import STEPCAFControl_Reader -from OCC.Core.IFSelect import IFSelect_RetDone -from OCC.Core.TDF import TDF_LabelSequence, TDF_Label, TDF_Tool -from OCC.Core.TDataStd import Handle_TDataStd_Name, TDataStd_Name_GetID -from OCC.Core.TCollection import TCollection_ExtendedString, TCollection_AsciiString -from OCC.Core.Quantity import Quantity_Color -from OCC.Core.TopLoc import TopLoc_Location -from OCC.Core.BRepBuilderAPI import BRepBuilderAPI_Transform -from OCC.Display.SimpleGui import init_display +from OCC.Extend.DataExchange import read_step_file_with_names_colors +from OCC.Display.WebGl import x3dom_renderer filename = '../assets/models/as1-oc-214.stp' +shapes_labels_colors = read_step_file_with_names_colors(filename) -# create an handle to a document -h_doc = Handle_TDocStd_Document() - -# Create the application -app = XCAFApp_Application.GetApplication().GetObject() -app.NewDocument(TCollection_ExtendedString("MDTV-CAF"), h_doc) - -# Get root assembly -doc = h_doc.GetObject() -h_shape_tool = XCAFDoc_DocumentTool_ShapeTool(doc.Main()) -h_color_tool = XCAFDoc_DocumentTool_ColorTool(doc.Main()) -h_layer_tool = XCAFDoc_DocumentTool_LayerTool(doc.Main()) -h_mat_tool = XCAFDoc_DocumentTool_MaterialTool(doc.Main()) - -step_reader = STEPCAFControl_Reader() -step_reader.SetColorMode(True) -step_reader.SetLayerMode(True) -step_reader.SetNameMode(True) -step_reader.SetMatMode(True) - -status = step_reader.ReadFile(filename) -if status == IFSelect_RetDone: - step_reader.Transfer(doc.GetHandle()) - -shape_tool = h_shape_tool.GetObject() -shape_tool.SetAutoNaming(True) - -color_tool = h_color_tool.GetObject() - -lvl = 0 -locs = [] -cnt = 0 - -def get_label_name(lab): - entry = TCollection_AsciiString() - TDF_Tool.Entry(lab, entry) - N = Handle_TDataStd_Name() - lab.FindAttribute(TDataStd_Name_GetID(), N) - n = N.GetObject() - if n: - return n.Get().PrintToString() - return "No Name" - -def getSubShapes(lab, loc): - global cnt, lvl - cnt += 1 - print("\n[%d] level %d, handling LABEL %s\n" % (cnt, lvl, get_label_name(lab))) - print() - print(lab.DumpToString()) - print() - print("Is Assembly :", shape_tool.IsAssembly(lab)) - print("Is Free :", shape_tool.IsFree(lab)) - print("Is Shape :", shape_tool.IsShape(lab)) - print("Is Compound :", shape_tool.IsCompound(lab)) - print("Is Component :", shape_tool.IsComponent(lab)) - print("Is SimpleShape :", shape_tool.IsSimpleShape(lab)) - print("Is Reference :", shape_tool.IsReference(lab)) - - users = TDF_LabelSequence() - users_cnt = shape_tool.GetUsers(lab, users) - print("Nr Users :", users_cnt) - - l_subss = TDF_LabelSequence() - shape_tool.GetSubShapes(lab, l_subss) - print("Nb subshapes :", l_subss.Length()) - l_comps = TDF_LabelSequence() - shape_tool.GetComponents(lab, l_comps) - print("Nb components :", l_comps.Length()) - print() - - if shape_tool.IsAssembly(lab): - l_c = TDF_LabelSequence() - shape_tool.GetComponents(lab, l_c) - for i in range(l_c.Length()): - label = l_c.Value(i+1) - if shape_tool.IsReference(label): - print("\n######## reference label :", label) - label_reference = TDF_Label() - shape_tool.GetReferredShape(label, label_reference) - loc = shape_tool.GetLocation(label) - print(" loc :", loc) - trans = loc.Transformation() - print(" tran form :", trans.Form()) - rot = trans.GetRotation() - print(" rotation :", rot) - print(" X :", rot.X()) - print(" Y :", rot.Y()) - print(" Z :", rot.Z()) - print(" W :", rot.W()) - tran = trans.TranslationPart() - print(" translation :", tran) - print(" X :", tran.X()) - print(" Y :", tran.Y()) - print(" Z :", tran.Z()) - - locs.append(loc) - print(">>>>") - lvl += 1 - getSubShapes(label_reference, loc) - lvl -= 1 - print("<<<<") - locs.pop() - - elif shape_tool.IsSimpleShape(lab): - print("\n######## simpleshape label :", lab) - shape = shape_tool.GetShape(lab) - print(" all ass locs :", locs) - - loc = TopLoc_Location() - for i in range(len(locs)): - print(" take loc :", locs[i]) - loc = loc.Multiplied(locs[i]) - - trans = loc.Transformation() - print(" FINAL loc :") - print(" tran form :", trans.Form()) - rot = trans.GetRotation() - print(" rotation :", rot) - print(" X :", rot.X()) - print(" Y :", rot.Y()) - print(" Z :", rot.Z()) - print(" W :", rot.W()) - tran = trans.TranslationPart() - print(" translation :", tran) - print(" X :", tran.X()) - print(" Y :", tran.Y()) - print(" Z :", tran.Z()) - shape = BRepBuilderAPI_Transform(shape, loc.Transformation()).Shape() - - c = Quantity_Color() - colorSet = False - if (color_tool.GetInstanceColor(shape, 0, c) or - color_tool.GetInstanceColor(shape, 1, c) or - color_tool.GetInstanceColor(shape, 2, c)): - for i in (0, 1, 2): - color_tool.SetInstanceColor(shape, i, c) - colorSet = True - n = c.Name(c.Red(), c.Green(), c.Blue()) - print(' instance color Name & RGB: ', c, n, c.Red(), c.Green(), c.Blue()) - - if not colorSet: - if (color_tool.GetColor(lab, 0, c) or - color_tool.GetColor(lab, 1, c) or - color_tool.GetColor(lab, 2, c)): - for i in (0, 1, 2): - color_tool.SetInstanceColor(shape, i, c) - - n = c.Name(c.Red(), c.Green(), c.Blue()) - print(' shape color Name & RGB: ', c, n, c.Red(), c.Green(), c.Blue()) - - # n = c.Name(c.Red(), c.Green(), c.Blue()) - # print(' color Name & RGB: ', c, n, c.Red(), c.Green(), c.Blue()) - # Display shape - # display.DisplayColoredShape(shape, c) - - for i in range(l_subss.Length()): - lab = l_subss.Value(i+1) - print("\n######## simpleshape subshape label :", lab) - shape_sub = shape_tool.GetShape(lab) - - c = Quantity_Color() - colorSet = False - if (color_tool.GetInstanceColor(shape_sub, 0, c) or - color_tool.GetInstanceColor(shape_sub, 1, c) or - color_tool.GetInstanceColor(shape_sub, 2, c)): - for i in (0, 1, 2): - color_tool.SetInstanceColor(shape_sub, i, c) - colorSet = True - n = c.Name(c.Red(), c.Green(), c.Blue()) - print(' instance color Name & RGB: ', c, n, c.Red(), c.Green(), c.Blue()) - - if not colorSet: - if (color_tool.GetColor(lab, 0, c) or - color_tool.GetColor(lab, 1, c) or - color_tool.GetColor(lab, 2, c)): - for i in (0, 1, 2): - color_tool.SetInstanceColor(shape, i, c) - - n = c.Name(c.Red(), c.Green(), c.Blue()) - print(' shape color Name & RGB: ', c, n, c.Red(), c.Green(), c.Blue()) - - # n = c.Name(c.Red(), c.Green(), c.Blue()) - # print(' color Name & RGB: ', c, n, c.Red(), c.Green(), c.Blue()) - # Display shape - # display.DisplayColoredShape(shape, c) - - display.DisplayColoredShape(shape, c) - -def getShapes(): - labels = TDF_LabelSequence() - h_shape_tool.GetObject().GetFreeShapes(labels) - global cnt - cnt += 1 - - print() - print("Number of shapes at root :", labels.Length()) - print() - root = labels.Value(1) - - getSubShapes(root, None) +# init graphic display +display, start_display, add_menu, add_function_to_menu = init_display() -def run(event=None): - display.EraseAll() - getShapes() - print() - print("Handled %d labels" % cnt) - print() - display.FitAll() -def exit(event=None): - sys.exit() +# traverse shapes, render in "face" mode +for shpt_lbl_color in shapes_labels_colors: + shape, label, c = shpt_lbl_color + display.DisplayColoredShape(shape, color=(c.Red(), c.Green(), c.Blue())) -if __name__ == '__main__': - display, start_display, add_menu, add_function_to_menu = init_display() - add_menu('STEP import') - add_function_to_menu('STEP import', run) - add_function_to_menu('STEP import', exit) - start_display() +start_display() diff --git a/examples/core_mesh_fast_stl_load.py b/examples/core_mesh_fast_stl_load.py index efa1da6..38e632d 100644 --- a/examples/core_mesh_fast_stl_load.py +++ b/examples/core_mesh_fast_stl_load.py @@ -21,7 +21,8 @@ import os.path from OCC.Core.SMESH import SMESH_Gen, SMESH_MeshVSLink -from OCC.Core.MeshVS import MeshVS_Mesh, MeshVS_BP_Mesh, MeshVS_MeshPrsBuilder, MeshVS_DMF_WireFrame +from OCC.Core.MeshVS import (MeshVS_Mesh, MeshVS_BP_Mesh, MeshVS_MeshPrsBuilder, + MeshVS_DMF_WireFrame) from OCC.Display.SimpleGui import init_display # Create the Mesh @@ -49,15 +50,15 @@ display, start_display, add_menu, add_function_to_menu = init_display() aDS = SMESH_MeshVSLink(aMesh) aMeshVS = MeshVS_Mesh(True) -aPrsBuilder = MeshVS_MeshPrsBuilder(aMeshVS.GetHandle(), +aPrsBuilder = MeshVS_MeshPrsBuilder(aMeshVS, MeshVS_DMF_WireFrame, - aDS.GetHandle(), + aDS, 0, MeshVS_BP_Mesh) -aMeshVS.SetDataSource(aDS.GetHandle()) -aMeshVS.AddBuilder(aPrsBuilder.GetHandle(), True) +aMeshVS.SetDataSource(aDS) +aMeshVS.AddBuilder(aPrsBuilder, True) context = display.Context -context.Display(aMeshVS.GetHandle()) -context.Deactivate(aMeshVS.GetHandle()) +context.Display(aMeshVS) +context.Deactivate(aMeshVS) display.FitAll() start_display() diff --git a/examples/core_mesh_surfacic.py b/examples/core_mesh_surfacic.py index bb22646..1470f53 100644 --- a/examples/core_mesh_surfacic.py +++ b/examples/core_mesh_surfacic.py @@ -48,9 +48,9 @@ def point_list_to_TColgp_Array1OfPnt(li): def get_simple_bound(pts): spl1 = GeomAPI_PointsToBSpline(pts).Curve() - spl1_adap_h = GeomAdaptor_HCurve(spl1).GetHandle() - bound1_h = GeomFill_SimpleBound(spl1_adap_h, 0.001, 0.001).GetHandle() - return spl1, bound1_h + spl1_adap = GeomAdaptor_HCurve(spl1) + bound1 = GeomFill_SimpleBound(spl1_adap, 0.001, 0.001) + return spl1, bound1 def constrained_filling(event=None): @@ -117,7 +117,7 @@ def occ_triangle_mesh(event=None): while ex.More(): F = topods_Face(ex.Current()) L = TopLoc_Location() - facing = (BRep_Tool().Triangulation(F, L)).GetObject() + facing = (BRep_Tool().Triangulation(F, L)) tab = facing.Nodes() tri = facing.Triangles() for i in range(1, facing.NbTriangles()+1): @@ -195,17 +195,17 @@ def display_mesh(the_mesh): aDS = SMESH_MeshVSLink(the_mesh) aMeshVS = MeshVS_Mesh(True) DMF = 1 # to wrap! - aPrsBuilder = MeshVS_MeshPrsBuilder(aMeshVS.GetHandle(), + aPrsBuilder = MeshVS_MeshPrsBuilder(aMeshVS, DMF, - aDS.GetHandle(), + aDS, 0, MeshVS_BP_Mesh) - aMeshVS.SetDataSource(aDS.GetHandle()) - aMeshVS.AddBuilder(aPrsBuilder.GetHandle(), True) + aMeshVS.SetDataSource(aDS) + aMeshVS.AddBuilder(aPrsBuilder, True) #Create the graphic window and display the mesh context = display.Context - context.Display(aMeshVS.GetHandle()) - context.Deactivate(aMeshVS.GetHandle()) + context.Display(aMeshVS) + context.Deactivate(aMeshVS) display.FitAll() diff --git a/examples/core_mesh_volumic.py b/examples/core_mesh_volumic.py index ccb217e..34d7c4b 100644 --- a/examples/core_mesh_volumic.py +++ b/examples/core_mesh_volumic.py @@ -79,11 +79,11 @@ DMF = 1 # to wrap! MeshVS_BP_Mesh = 5 # To wrap! -aPrsBuilder = MeshVS_MeshPrsBuilder(aMeshVS.GetHandle(), DMF, aDS.GetHandle(), 0, MeshVS_BP_Mesh) -aMeshVS.SetDataSource(aDS.GetHandle()) -aMeshVS.AddBuilder(aPrsBuilder.GetHandle(), True) +aPrsBuilder = MeshVS_MeshPrsBuilder(aMeshVS, DMF, aDS, 0, MeshVS_BP_Mesh) +aMeshVS.SetDataSource(aDS) +aMeshVS.AddBuilder(aPrsBuilder, True) context = display.Context -context.Display(aMeshVS.GetHandle()) -context.Deactivate(aMeshVS.GetHandle()) +context.Display(aMeshVS) +context.Deactivate(aMeshVS) display.FitAll() start_display() diff --git a/examples/core_modeling_sprocket.py b/examples/core_modeling_sprocket.py index ab719a1..8442fee 100644 --- a/examples/core_modeling_sprocket.py +++ b/examples/core_modeling_sprocket.py @@ -23,19 +23,20 @@ import sys from math import pi as M_PI, sin, cos, pow, atan -from OCC.Core.gp import gp_Pnt2d, gp_Ax2d, gp_Dir2d, gp_Circ2d, gp_Origin2d, gp_DX2d, \ - gp_Ax2, gp_OX2d, gp_Lin2d, gp_Trsf, gp_XOY, \ - gp_Pnt, gp_Vec, gp_Ax3, gp_Pln, gp_Origin, gp_DX, gp_DY, gp_DZ, gp_OZ +from OCC.Core.gp import (gp_Pnt2d, gp_Ax2d, gp_Dir2d, gp_Circ2d, gp_Origin2d, gp_DX2d, + gp_Ax2, gp_OX2d, gp_Lin2d, gp_Trsf, gp_XOY, + gp_Pnt, gp_Vec, gp_Ax3, gp_Pln, gp_Origin, gp_DX, gp_DY, + gp_DZ, gp_OZ) from OCC.Core.GCE2d import GCE2d_MakeArcOfCircle, GCE2d_MakeCircle, GCE2d_MakeLine from OCC.Core.Geom2dAPI import Geom2dAPI_InterCurveCurve -from OCC.Core.Geom2d import Handle_Geom2d_TrimmedCurve +from OCC.Core.Geom2d import Geom2d_TrimmedCurve from OCC.Core.GeomAPI import geomapi_To3d from OCC.Core.BRepBuilderAPI import (BRepBuilderAPI_MakeEdge, - BRepBuilderAPI_MakeWire, - BRepBuilderAPI_MakeFace, - BRepBuilderAPI_Transform) + BRepBuilderAPI_MakeWire, + BRepBuilderAPI_MakeFace, + BRepBuilderAPI_Transform) from OCC.Core.BRepPrimAPI import (BRepPrimAPI_MakePrism, BRepPrimAPI_MakeRevol, - BRepPrimAPI_MakeCylinder, BRepPrimAPI_MakeCone) + BRepPrimAPI_MakeCylinder, BRepPrimAPI_MakeCone) from OCC.Core.GccAna import GccAna_Circ2d2TanRad from OCC.Core.BRepAlgoAPI import BRepAlgoAPI_Cut, BRepAlgoAPI_Fuse from OCC.Core.BRepFilletAPI import BRepFilletAPI_MakeFillet2d @@ -76,24 +77,15 @@ hole_radius = 8.5 / 2. -class Proxy(object): - def __init__(self, obj): - self.obj = obj.GetObject() - - def __getattribute__(self, attr): - obj = object.__getattribute__(self, 'obj') - return getattr(obj, attr).__get__(obj) - - 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() + trimmed_base.Reverse() # just a trick + p0 = trimmed_base.StartPoint() + p1 = trimmed_base.EndPoint() # Determine the center of the profile circle x_distance = cos(roller_contact_angle / 2.) * (profile_radius + tooth_radius) @@ -135,22 +127,22 @@ def build_tooth(): # 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()) + mirror_base = Geom2d_TrimmedCurve.DownCast(trimmed_base.Copy()) + mirror_profile = Geom2d_TrimmedCurve.DownCast(trimmed_profile.Copy()) + mirror_outer = Geom2d_TrimmedCurve.DownCast(trimmed_outer.Copy()) - Proxy(mirror_base).Mirror(mirror_axis) - Proxy(mirror_profile).Mirror(mirror_axis) - Proxy(mirror_outer).Mirror(mirror_axis) + mirror_base.Mirror(mirror_axis) + mirror_profile.Mirror(mirror_axis) + mirror_outer.Mirror(mirror_axis) - Proxy(mirror_base).Reverse() - Proxy(mirror_profile).Reverse() - Proxy(mirror_outer).Reverse() + mirror_base.Reverse() + mirror_profile.Reverse() + 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_start = trimmed_outer.StartPoint() + outer_mid = trimmed_outer.EndPoint() + outer_end = mirror_outer.EndPoint() outer_arc = GCE2d_MakeArcOfCircle(outer_start, outer_mid, outer_end).Value() @@ -159,7 +151,7 @@ def build_tooth(): 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() + inner_arc.Reverse() # Convert the 2D arcs and two extra lines to 3D edges plane = gp_Pln(gp_Origin(), gp_DZ()) diff --git a/examples/core_simple_mesh.py b/examples/core_simple_mesh.py index ad0e76c..ae06aa6 100644 --- a/examples/core_simple_mesh.py +++ b/examples/core_simple_mesh.py @@ -51,7 +51,7 @@ def simple_mesh(): while ex.More(): face = topods_Face(ex.Current()) location = TopLoc_Location() - facing = (bt.Triangulation(face, location)).GetObject() + facing = (bt.Triangulation(face, location)) tab = facing.Nodes() tri = facing.Triangles() for i in range(1, facing.NbTriangles()+1): diff --git a/examples/core_topology_draft_angle.py b/examples/core_topology_draft_angle.py index 91fdd57..22819ac 100644 --- a/examples/core_topology_draft_angle.py +++ b/examples/core_topology_draft_angle.py @@ -23,7 +23,7 @@ from OCC.Core.BRep import BRep_Tool_Surface from OCC.Core.TopExp import TopExp_Explorer from OCC.Core.TopAbs import TopAbs_FACE -from OCC.Core.Geom import Handle_Geom_Plane_DownCast +from OCC.Core.Geom import Geom_Plane_DownCast from OCC.Core.TopoDS import topods_Face from OCC.Display.SimpleGui import init_display @@ -37,7 +37,7 @@ def draft_angle(event=None): topExp.Init(S, TopAbs_FACE) while topExp.More(): face = topods_Face(topExp.Current()) - surf = Handle_Geom_Plane_DownCast(BRep_Tool_Surface(face)).GetObject() + 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()): diff --git a/examples/core_topology_edge.py b/examples/core_topology_edge.py index 0536211..ec58a45 100644 --- a/examples/core_topology_edge.py +++ b/examples/core_topology_edge.py @@ -19,7 +19,7 @@ from OCC.Core.gp import gp_Pnt, gp_Lin, gp_Ax1, gp_Dir, gp_Elips, gp_Ax2 from OCC.Core.BRepBuilderAPI import (BRepBuilderAPI_MakeEdge, - BRepBuilderAPI_MakeVertex) + BRepBuilderAPI_MakeVertex) from OCC.Core.TColgp import TColgp_Array1OfPnt from OCC.Core.Geom import Geom_BezierCurve @@ -62,7 +62,7 @@ def edge(event=None): array.SetValue(7, P7) array.SetValue(8, P8) curve = Geom_BezierCurve(array) - ME = BRepBuilderAPI_MakeEdge(curve.GetHandle()) + ME = BRepBuilderAPI_MakeEdge(curve) GreenEdge = ME V3 = ME.Vertex1() V4 = ME.Vertex2() diff --git a/examples/core_topology_face.py b/examples/core_topology_face.py index 346d1d3..70912f8 100644 --- a/examples/core_topology_face.py +++ b/examples/core_topology_face.py @@ -103,11 +103,11 @@ def face(): 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(), + Edge1 = BRepBuilderAPI_MakeEdge(line1, BSplineSurf.Surface(), 0, P12d.Distance(P22d)).Edge() - Edge2 = BRepBuilderAPI_MakeEdge(line2.GetHandle(), BSplineSurf.Surface(), + Edge2 = BRepBuilderAPI_MakeEdge(line2, BSplineSurf.Surface(), 0, P22d.Distance(P32d)).Edge() - Edge3 = BRepBuilderAPI_MakeEdge(line3.GetHandle(), BSplineSurf.Surface(), + Edge3 = BRepBuilderAPI_MakeEdge(line3, BSplineSurf.Surface(), 0, P32d.Distance(P12d)).Edge() ## Wire1 = BRepBuilderAPI_MakeWire(Edge1, Edge2, Edge3).Wire() diff --git a/examples/core_topology_heightmap.py b/examples/core_topology_heightmap.py index 19e6be7..cdc7fb1 100644 --- a/examples/core_topology_heightmap.py +++ b/examples/core_topology_heightmap.py @@ -21,8 +21,8 @@ from OCC.Core.gp import gp_Pnt from OCC.Core.BRepBuilderAPI import (BRepBuilderAPI_MakeEdge, - BRepBuilderAPI_MakeFace, - BRepBuilderAPI_MakeWire) + BRepBuilderAPI_MakeFace, + BRepBuilderAPI_MakeWire) from OCC.Core.TColgp import TColgp_Array2OfPnt from OCC.Core.GeomAPI import GeomAPI_PointsToBSplineSurface from OCC.Core.GeomFill import GeomFill_SimpleBound, GeomFill_ConstrainedFilling @@ -90,8 +90,8 @@ def boundary_curve_from_2_points(p1, p2): # boundary for filling adap = BRepAdaptor_CompCurve(w0) p0_h = BRepAdaptor_HCompCurve(adap) - boundary = GeomFill_SimpleBound(p0_h.GetHandle(), 1e-6, 1e-6) - return boundary.GetHandle() + boundary = GeomFill_SimpleBound(p0_h, 1e-6, 1e-6) + return boundary def heightmap_from_image(event=None): """ takes the heightmap from a jpeg file diff --git a/examples/core_topology_local_ops.py b/examples/core_topology_local_ops.py index e8c1977..5287b61 100644 --- a/examples/core_topology_local_ops.py +++ b/examples/core_topology_local_ops.py @@ -29,7 +29,7 @@ from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeBox, BRepPrimAPI_MakePrism from OCC.Display.SimpleGui import init_display from OCC.Core.GCE2d import GCE2d_MakeLine -from OCC.Core.Geom import Handle_Geom_Plane_DownCast, Geom_Plane +from OCC.Core.Geom import Geom_Plane_DownCast, Geom_Plane from OCC.Core.Geom2d import Geom2d_Circle from OCC.Core.GeomAbs import GeomAbs_Arc from OCC.Core.TopTools import TopTools_ListOfShape @@ -52,9 +52,8 @@ def extrusion(event=None): surf = BRep_Tool_Surface(F) # Make a plane from this face - Pl = Handle_Geom_Plane_DownCast(surf) - Pln = Pl.GetObject() - + Pl = Geom_Plane_DownCast(surf) + # Get the normal of this plane. This will be the direction of extrusion. D = Pln.Axis().Direction() @@ -114,7 +113,7 @@ def brepfeat_prism(event=None): c = gp_Circ2d(gp_Ax2d(gp_Pnt2d(200, 130), gp_Dir2d(1, 0)), 75) - circle = Geom2d_Circle(c).GetHandle() + circle = Geom2d_Circle(c) wire = BRepBuilderAPI_MakeWire() wire.Add(BRepBuilderAPI_MakeEdge(circle, srf, 0., pi).Edge()) @@ -210,7 +209,7 @@ def brep_feat_rib(event=None): aplane = Geom_Plane(0., 1., 0., -45.) - aform = BRepFeat_MakeLinearForm(S.Shape(), W.Wire(), aplane.GetHandle(), + aform = BRepFeat_MakeLinearForm(S.Shape(), W.Wire(), aplane, gp_Vec(0., 10., 0.), gp_Vec(0., 0., 0.), 1, True) aform.Perform() @@ -262,7 +261,7 @@ def brep_feat_extrusion_protrusion(event=None): F = next(faces) surf1 = BRep_Tool_Surface(F) - Pl1 = Handle_Geom_Plane_DownCast(surf1).GetObject() + Pl1 = Geom_Plane_DownCast(surf1) D1 = Pl1.Pln().Axis().Direction().Reversed() MW = BRepBuilderAPI_MakeWire() @@ -299,7 +298,7 @@ def brep_feat_extrusion_protrusion(event=None): next(faces) F2 = next(faces) surf2 = BRep_Tool_Surface(F2) - Pl2 = Handle_Geom_Plane_DownCast(surf2).GetObject() + Pl2 = Geom_Plane_DownCast(surf2) D2 = Pl2.Pln().Axis().Direction().Reversed() MW2 = BRepBuilderAPI_MakeWire() p1, p2 = gp_Pnt2d(100., 100.), gp_Pnt2d(200., 100.) diff --git a/examples/core_visualization_ais_coloredshape.py b/examples/core_visualization_ais_coloredshape.py index 6f01713..243b0eb 100644 --- a/examples/core_visualization_ais_coloredshape.py +++ b/examples/core_visualization_ais_coloredshape.py @@ -27,13 +27,13 @@ my_box = BRepPrimAPI_MakeBox(10., 20., 30.).Shape() -ais = AIS_ColoredShape(my_box) +ais_shp = AIS_ColoredShape(my_box) for fc in TopologyExplorer(my_box).faces(): # set a custom color per-face - ais.SetCustomColor(fc, rgb_color(random(), random(), random())) + ais_shp.SetCustomColor(fc, rgb_color(random(), random(), random())) -display.Context.Display(ais.GetHandle()) +display.Context.Display(ais_shp) display.FitAll() start_display() diff --git a/examples/core_visualization_camera.py b/examples/core_visualization_camera.py index 1201dd1..8ec9825 100644 --- a/examples/core_visualization_camera.py +++ b/examples/core_visualization_camera.py @@ -37,7 +37,7 @@ def animate_viewpoint(): display.FitAll() display.Context.UpdateCurrentViewer() - cam = display.View.Camera().GetObject() # type: Graphic3d_Camera + cam = display.View.Camera() # type: Graphic3d_Camera center = cam.Center() eye = cam.Eye() diff --git a/examples/core_visualization_glsl.py b/examples/core_visualization_glsl.py index 362d6d4..8348b60 100644 --- a/examples/core_visualization_glsl.py +++ b/examples/core_visualization_glsl.py @@ -18,16 +18,16 @@ from OCC.Core.AIS import AIS_Shape from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeSphere -from OCC.Display.SimpleGui import init_display -from OCC.Core.Graphic3d import (Graphic3d_ShaderProgram, Graphic3d_TOS_VERTEX, Graphic3d_TOS_FRAGMENT, - Graphic3d_ShaderObject) +from OCC.Core.Graphic3d import (Graphic3d_ShaderProgram, Graphic3d_TOS_VERTEX, + Graphic3d_TOS_FRAGMENT, Graphic3d_ShaderObject) from OCC.Core.TCollection import TCollection_AsciiString +from OCC.Display.SimpleGui import init_display display, start_display, add_menu, add_function_to_menu = init_display() shape = BRepPrimAPI_MakeSphere(100).Shape() anIO = AIS_Shape(shape) -display.Context.Display(anIO.GetHandle()) +display.Context.Display(anIO) # gragment shader fs = """ @@ -53,10 +53,10 @@ aProgram.AttachShader(vs_shader) # attach the shader to the AIS_Shape representation that renders the sphere -aspect = anIO.Attributes().GetObject().ShadingAspect().GetObject().Aspect().GetObject() +aspect = anIO.Attributes().ShadingAspect().Aspect() if aProgram.IsDone(): - aspect.SetShaderProgram(aProgram.GetHandle()) + aspect.SetShaderProgram(aProgram) else: raise AssertionError("no valid shader program found") @@ -64,6 +64,6 @@ assert not aspect.ShaderProgram().IsNull(), "no shader program is null" # redisplay the sphere, when the shader was attached to its AIS_Shape aspect -display.Context.Redisplay(anIO.GetHandle()) +display.Context.Redisplay(anIO) display.FitAll() start_display() diff --git a/examples/core_visualization_graphic3d_custom_opengl.py b/examples/core_visualization_graphic3d_custom_opengl.py index 3a63f79..7800405 100644 --- a/examples/core_visualization_graphic3d_custom_opengl.py +++ b/examples/core_visualization_graphic3d_custom_opengl.py @@ -18,7 +18,7 @@ def create_ogl_group(display): create a group that will store an OpenGL buffer """ aPresentation = Prs3d_Presentation(display._struc_mgr) - group = Prs3d_Root_CurrentGroup(aPresentation.GetHandle()).GetObject() + group = Prs3d_Root_CurrentGroup(aPresentation) return aPresentation, group @@ -90,8 +90,8 @@ def draw_lines(pnt_list, nr_of_points, display): except StopIteration: pass - group.SetPrimitivesAspect(asp.GetHandle()) - group.AddPrimitiveArray(gg.GetHandle()) + group.SetPrimitivesAspect(asp) + group.AddPrimitiveArray(gg) a_presentation.Display() diff --git a/examples/core_webgl_threejs_helix.py b/examples/core_webgl_threejs_helix.py index 8b67963..4287993 100644 --- a/examples/core_webgl_threejs_helix.py +++ b/examples/core_webgl_threejs_helix.py @@ -22,17 +22,18 @@ from OCC.Core.Geom2dAPI import Geom2dAPI_Interpolate, Geom2dAPI_PointsToBSpline from OCC.Core.TColgp import TColgp_HArray1OfPnt2d, TColgp_Array1OfPnt2d from OCC.Core.BRepBuilderAPI import BRepBuilderAPI_MakeEdge, BRepBuilderAPI_MakeEdge2d -from OCC.Display.WebGl import threejs_renderer from OCC.Core.gp import gp_XOY, gp_Ax3, gp_Dir2d from OCC.Core.Geom import Geom_CylindricalSurface from OCC.Core.GCE2d import GCE2d_MakeSegment +from OCC.Display.WebGl import threejs_renderer + # First buil an helix aCylinder = Geom_CylindricalSurface(gp_Ax3(gp_XOY()), 6.0) aLine2d = gp_Lin2d (gp_Pnt2d(0.0, 0.0), gp_Dir2d(1.0, 1.0)) aSegment = GCE2d_MakeSegment(aLine2d, 0.0, pi * 2.0) -helix_edge = BRepBuilderAPI_MakeEdge(aSegment.Value(), aCylinder.GetHandle(), 0.0, 6.0 * pi).Edge() +helix_edge = BRepBuilderAPI_MakeEdge(aSegment.Value(), aCylinder, 0.0, 6.0 * pi).Edge() display = threejs_renderer.ThreejsRenderer() display.DisplayShape(helix_edge, color=(1, 0, 0), line_width=1.) diff --git a/jupyter_notebooks/core_topology_draft_angle.ipynb b/jupyter_notebooks/core_topology_draft_angle.ipynb index 90755ce..c9d1367 100644 --- a/jupyter_notebooks/core_topology_draft_angle.ipynb +++ b/jupyter_notebooks/core_topology_draft_angle.ipynb @@ -29,7 +29,7 @@ "from OCC.Core.BRep import BRep_Tool_Surface\n", "from OCC.Core.TopExp import TopExp_Explorer\n", "from OCC.Core.TopAbs import TopAbs_FACE\n", - "from OCC.Core.Geom import Handle_Geom_Plane_DownCast\n", + "from OCC.Core.Geom import Geom_Plane_DownCast\n", "from OCC.Core.TopoDS import topods_Face" ] }, @@ -94,7 +94,7 @@ "topExp.Init(S, TopAbs_FACE)\n", "while topExp.More():\n", " face = topods_Face(topExp.Current())\n", - " surf = Handle_Geom_Plane_DownCast(BRep_Tool_Surface(face)).GetObject()\n", + " surf = Geom_Plane_DownCast(BRep_Tool_Surface(face))\n", " dirf = surf.Pln().Axis().Direction()\n", " ddd = gp_Dir(0, 0, 1)\n", " if dirf.IsNormal(ddd, precision_Angular()):\n",