Skip to content

Commit

Permalink
Merge pull request #583 from tpaviot/review/tp-transparent-handles
Browse files Browse the repository at this point in the history
Review/tp transparent handles
  • Loading branch information
tpaviot committed Nov 20, 2018
2 parents ed42eb3 + 57989c6 commit 85d15cd
Show file tree
Hide file tree
Showing 399 changed files with 21,571 additions and 118,495 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,9 @@ install(TARGETS _GEOMAlgo DESTINATION ${PYTHONOCC_INSTALL_DIRECTORY}/Core )
# install Extend
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/src/Extend DESTINATION ${PYTHONOCC_INSTALL_DIRECTORY} )

# install Wrapper utils
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/src/Wrapper DESTINATION ${PYTHONOCC_INSTALL_DIRECTORY})

# install deprecated modules
file(GLOB DEPRECATED_MODULES ${CMAKE_CURRENT_SOURCE_DIR}/src/SWIG_files/deprecated_modules/*.py)
install(FILES ${DEPRECATED_MODULES} DESTINATION ${PYTHONOCC_INSTALL_DIRECTORY} )
1 change: 1 addition & 0 deletions ci/conda/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ requirements:
- tbb >=2018_20171205
- freetype >=2.7
- smesh ==6.7.6
- six

test:
requires:
Expand Down
81 changes: 27 additions & 54 deletions src/Display/OCCViewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
BRepBuilderAPI_MakeFace)
from OCC.Core.TopAbs import (TopAbs_FACE, TopAbs_EDGE, TopAbs_VERTEX,
TopAbs_SHELL, TopAbs_SOLID)
from OCC.Core.Geom import Handle_Geom_Curve, Handle_Geom_Surface
from OCC.Core.Geom2d import Handle_Geom2d_Curve
from OCC.Core.Geom import Geom_Curve, Geom_Surface
from OCC.Core.Geom2d import Geom2d_Curve
from OCC.Core.Visualization import Display3d
from OCC.Core.V3d import (V3d_ZBUFFER, V3d_PHONG, V3d_Zpos, V3d_Zneg, V3d_Xpos,
V3d_Xneg, V3d_Ypos, V3d_Yneg, V3d_XposYnegZpos, V3d_TEX_ALL,
Expand Down Expand Up @@ -120,14 +120,10 @@ def __init__(self, window_handle):
self._window_handle = window_handle
self._inited = False
self._local_context_opened = False
self.Context_handle = None
self.Viewer_handle = None
self.View_handle = None
self.Context = None
self.Viewer = None
self.View = None
self.OverLayer = None
self.OverLayer_handle = None
self.selected_shape = None
self.default_drawer = None
self._struc_mgr = None
Expand All @@ -145,7 +141,7 @@ def register_overlay_item(self, overlay_item):
def GetOverLayer(self):
""" returns an handle to the current overlayer
"""
return self.OverLayer_handle
return self.OverLayer

def register_select_callback(self, callback):
""" Adds a callback that will be called each time a shape s selected
Expand All @@ -164,7 +160,7 @@ def unregister_callback(self, callback):
self._select_callbacks.remove(callback)

def MoveTo(self, X, Y):
self.Context.MoveTo(X, Y, self.View_handle)
self.Context.MoveTo(X, Y, self.View)

def FitAll(self):
self.View.ZFitAll()
Expand All @@ -178,17 +174,14 @@ def Create(self, create_default_lights=True, draw_face_boundaries=True, phong_sh
self.Init(self._window_handle)
self._is_offscreen = False

self.Context_handle = self.GetContext()
self.Viewer_handle = self.GetViewer()
self.View_handle = self.GetView()
self.Context = self.Context_handle.GetObject()
self.Viewer = self.Viewer_handle.GetObject()
self.Context = self.GetContext()
self.Viewer = self.GetViewer()
self.View = self.GetView()
if create_default_lights:
self.Viewer.SetDefaultLights()
self.Viewer.SetLightOn()
self.View = self.View_handle.GetObject()
self.camera = self.View.Camera().GetObject()
self.default_drawer = self.Context.DefaultDrawer().GetObject()
self.camera = self.View.Camera()
self.default_drawer = self.Context.DefaultDrawer()

# draw black contour edges, like other famous CAD packages
if draw_face_boundaries:
Expand All @@ -206,17 +199,16 @@ def Create(self, create_default_lights=True, draw_face_boundaries=True, phong_sh
# self.Context.SelectionColor(Quantity_NOC_ORANGE)

# necessary for text rendering
self._struc_mgr = self.Context.MainPrsMgr().GetObject().StructureManager()
self._struc_mgr = self.Context.MainPrsMgr().StructureManager()

# overlayer
self.OverLayer_handle = self.Viewer.Viewer().GetObject().OverLayer()
if self.OverLayer_handle.IsNull():
aMgr = V3d_LayerMgr(self.View_handle)
self.OverLayer_handle = aMgr.Overlay()
self.View.SetLayerMgr(aMgr.GetHandle())
self.OverLayer = self.OverLayer_handle.GetObject()
self.OverLayer = self.Viewer.Viewer().OverLayer()
if self.OverLayer is None:
aMgr = V3d_LayerMgr(self.View)
self.OverLayer = aMgr.Overlay()
self.View.SetLayerMgr(aMgr)
print("Layer manager created")
height, width = self.View.Window().GetObject().Size()
height, width = self.View.Window().Size()
print("Layer dimensions: %i, %i" % (height, width))
self.OverLayer.SetViewport(height, width)

Expand Down Expand Up @@ -289,7 +281,7 @@ def EnableTextureEnv(self, name_of_texture=Graphic3d_NOT_ENV_CLOUDS):
Graphic3d_NOT_ENV_UNKNOWN
"""
texture_env = Graphic3d_TextureEnv(name_of_texture)
self.View.SetTextureEnv(texture_env.GetHandle())
self.View.SetTextureEnv(texture_env)
self.View.SetSurfaceDetail(V3d_TEX_ENVIRONMENT)
self.View.Redraw()

Expand Down Expand Up @@ -386,7 +378,7 @@ def DisplayVector(self, vec, pnt, update=False):
pnt_start = gp_Pnt(start.X(), start.Y(), start.Z())

Prs3d_Arrow.Draw(
aPresentation.GetHandle(),
aPresentation,
pnt_start,
gp_Dir(vec),
math.radians(20),
Expand Down Expand Up @@ -414,8 +406,8 @@ def DisplayMessage(self, point, text_to_write, height=None, message_color=None,
text_aspect.SetHeight(height)
if isinstance(point, gp_Pnt2d):
point = gp_Pnt(point.X(), point.Y(), 0)
Prs3d_Text.Draw(aPresentation.GetHandle(),
text_aspect.GetHandle(),
Prs3d_Text.Draw(aPresentation,
text_aspect,
to_string(text_to_write),
point)
aPresentation.Display()
Expand All @@ -438,38 +430,19 @@ def DisplayShape(self, shapes, material=None, texture=None, color=None, transpar
vertex = BRepBuilderAPI_MakeVertex(gp_Pnt(shapes.X(), shapes.Y(), 0))
shapes = [vertex.Shape()]
SOLO = True
# if a Geom_Curve is passed
elif callable(getattr(shapes, "GetHandle", None)):
handle = shapes.GetHandle()
if issubclass(handle.__class__, Handle_Geom_Curve):
edge = BRepBuilderAPI_MakeEdge(handle)
shapes = [edge.Shape()]
SOLO = True
elif issubclass(handle.__class__, Handle_Geom2d_Curve):
edge2d = BRepBuilderAPI_MakeEdge2d(handle)
shapes = [edge2d.Shape()]
SOLO = True
elif issubclass(handle.__class__, Handle_Geom_Surface):
bounds = True
toldegen = 1e-6
face = BRepBuilderAPI_MakeFace()
face.Init(handle, bounds, toldegen)
face.Build()
shapes = [face.Shape()]
SOLO = True
elif isinstance(shapes, Handle_Geom_Surface):
elif isinstance(shapes, Geom_Surface):
bounds = True
toldegen = 1e-6
face = BRepBuilderAPI_MakeFace()
face.Init(shapes, bounds, toldegen)
face.Build()
shapes = [face.Shape()]
SOLO = True
elif isinstance(shapes, Handle_Geom_Curve):
elif isinstance(shapes, Geom_Curve):
edge = BRepBuilderAPI_MakeEdge(shapes)
shapes = [edge.Shape()]
SOLO = True
elif isinstance(shapes, Handle_Geom2d_Curve):
elif isinstance(shapes, Geom2d_Curve):
edge2d = BRepBuilderAPI_MakeEdge2d(shapes)
shapes = [edge2d.Shape()]
SOLO = True
Expand Down Expand Up @@ -499,7 +472,7 @@ def DisplayShape(self, shapes, material=None, texture=None, color=None, transpar
# to this AIS_Shape instance?
shape_to_display = AIS_Shape(shape)

ais_shapes.append(shape_to_display.GetHandle())
ais_shapes.append(shape_to_display)

if not SOLO:
# computing graphic properties is expensive
Expand Down Expand Up @@ -527,12 +500,12 @@ def DisplayShape(self, shapes, material=None, texture=None, color=None, transpar
shape_to_display.SetTransparency(transparency)
if update:
# only update when explicitely told to do so
self.Context.Display(shape_to_display.GetHandle(), False)
self.Context.Display(shape_to_display, False)
# especially this call takes up a lot of time...
self.FitAll()
self.Repaint()
else:
self.Context.Display(shape_to_display.GetHandle(), False)
self.Context.Display(shape_to_display, False)

if SOLO:
return ais_shapes[0]
Expand Down Expand Up @@ -611,7 +584,7 @@ def GetSelectedShape(self):
return self.selected_shape

def SelectArea(self, Xmin, Ymin, Xmax, Ymax):
self.Context.Select(Xmin, Ymin, Xmax, Ymax, self.View_handle)
self.Context.Select(Xmin, Ymin, Xmax, Ymax, self.View)
self.Context.InitSelected()
# reinit the selected_shapes list
self.selected_shapes = []
Expand Down
33 changes: 12 additions & 21 deletions src/Extend/DataExchange.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,14 @@
from OCC.Core.STEPControl import STEPControl_Reader, STEPControl_Writer, STEPControl_AsIs
from OCC.Core.Interface import Interface_Static_SetCVal
from OCC.Core.IFSelect import IFSelect_RetDone, IFSelect_ItemsByEntity
from OCC.Core.TDocStd import Handle_TDocStd_Document
from OCC.Core.XCAFApp import XCAFApp_Application
from OCC.Core.TDocStd import TDocStd_Document
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.TDF import TDF_LabelSequence, TDF_Label, TDF_Tool
from OCC.Core.TDataStd import Handle_TDataStd_Name, TDataStd_Name_GetID
from OCC.Core.TDataStd import 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
Expand Down Expand Up @@ -110,18 +109,13 @@ def read_step_file_with_names_colors(filename):
# the list:
output_shapes = []
# 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)
doc = TDocStd_Document(TCollection_ExtendedString("pythonocc-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())
shape_tool = XCAFDoc_DocumentTool_ShapeTool(doc.Main())
color_tool = XCAFDoc_DocumentTool_ColorTool(doc.Main())
layer_tool = XCAFDoc_DocumentTool_LayerTool(doc.Main())
mat_tool = XCAFDoc_DocumentTool_MaterialTool(doc.Main())

step_reader = STEPCAFControl_Reader()
step_reader.SetColorMode(True)
Expand All @@ -131,23 +125,20 @@ def read_step_file_with_names_colors(filename):

status = step_reader.ReadFile(filename)
if status == IFSelect_RetDone:
step_reader.Transfer(doc.GetHandle())
step_reader.Transfer(doc)

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()
n = TDataStd_Name()
lab.FindAttribute(TDataStd_Name_GetID(), n)
if n:
return n.Get().PrintToString()
return "No Name"
Expand Down Expand Up @@ -290,7 +281,7 @@ def _get_sub_shapes(lab, loc):

def _get_shapes():
labels = TDF_LabelSequence()
h_shape_tool.GetObject().GetFreeShapes(labels)
shape_tool.GetFreeShapes(labels)
#global cnt
#cnt += 1

Expand Down
Loading

0 comments on commit 85d15cd

Please sign in to comment.