Skip to content

Commit

Permalink
Refactored examples to use transparent handles
Browse files Browse the repository at this point in the history
  • Loading branch information
tpaviot committed Nov 17, 2018
1 parent 9681797 commit e59acdc
Show file tree
Hide file tree
Showing 37 changed files with 181 additions and 422 deletions.
20 changes: 10 additions & 10 deletions examples/core_classic_occ_bottle.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -176,19 +176,19 @@ 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)

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())
Expand Down
4 changes: 2 additions & 2 deletions examples/core_dimensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
6 changes: 2 additions & 4 deletions examples/core_display_clip_planes.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
##You should have received a copy of the GNU Lesser General Public License
##along with pythonOCC. If not, see <http://www.gnu.org/licenses/>.

from __future__ import print_function

import sys

from OCC.Core.gp import gp_Vec
Expand All @@ -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()
Expand All @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions examples/core_display_customize_linewidth.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
12 changes: 6 additions & 6 deletions examples/core_display_customize_prs3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
#
Expand Down
10 changes: 5 additions & 5 deletions examples/core_display_export_to_EF.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions examples/core_display_line_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()


Expand Down
4 changes: 2 additions & 2 deletions examples/core_display_overlayered_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
18 changes: 9 additions & 9 deletions examples/core_display_point_cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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()

Expand All @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion examples/core_display_quality.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#
# Get Context
#
ais_context = display.GetContext().GetObject()
ais_context = display.GetContext()
#
# Display current quality
dc = ais_context.DeviationCoefficient()
Expand Down
7 changes: 3 additions & 4 deletions examples/core_display_set_edge_color.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion examples/core_geometry_bisector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
4 changes: 2 additions & 2 deletions examples/core_geometry_bspline.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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()

Expand Down
4 changes: 1 addition & 3 deletions examples/core_geometry_curves2d_from_curve.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
##You should have received a copy of the GNU Lesser General Public License
##along with pythonOCC. If not, see <http://www.gnu.org/licenses/>.

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
Expand All @@ -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)

Expand Down
3 changes: 1 addition & 2 deletions examples/core_geometry_faircurve.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
##You should have received a copy of the GNU Lesser General Public License
##along with pythonOCC. If not, see <http://www.gnu.org/licenses/>.

from __future__ import print_function

import math
import time
Expand Down Expand Up @@ -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)

Expand Down
14 changes: 7 additions & 7 deletions examples/core_geometry_geomplate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

Expand Down Expand Up @@ -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:
Expand All @@ -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

Expand Down
Loading

0 comments on commit e59acdc

Please sign in to comment.