Skip to content

Commit a48e684

Browse files
committed
Merge remote-tracking branch 'tpaviot/master'
2 parents c41ede3 + cf83d18 commit a48e684

15 files changed

Lines changed: 96 additions & 90 deletions

appveyor.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ version: pythonocc-core-0.18.2-dev.{build}
33
environment:
44
binstar_token:
55
# below the secure to upload to anaconda cloud
6-
# take the travis-ci token generated from the command line
6+
# take the anaconda token generated from the command line
77
# anaconda auth -n the_token_name --max-age 22896000 -c --scopes api
88
# and copy paste to
99
# https://ci.appveyor.com/tools/encrypt
1010
# then copy/paste the result below
11-
secure: yaM9tAVoGSlLnqMDUz996EX5y8Z7eb5Jz+DHKyk0SHfp3kD4YZqHFn7VOrhehJIS
12-
11+
secure: +BLEI1wg9klPN7BVAY1thK7n1x1/L10dWtgKzOmGCI4mg4V77hes9yj3kjZ168xf
12+
1313
global:
1414
# SDK v7.0 MSVC Express 2008's SetEnv.cmd script will fail if the
1515
# /E:ON and /V:ON options are not enabled in the batch script intepreter

ci/conda/meta.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ requirements:
2424
- python
2525
- oce ==0.18.3
2626
- tbb ==2018_20171205
27-
- cmake ==3.12.2
27+
- cmake
2828
- ninja ==1.8.2
2929
- swig ==3.0.12
3030
- freetype ==2.9.1

cmake/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def require_pythonocc_version(required_version):
3030
elif len(spl) == 2:
3131
major, minor = spl
3232
patch = 0
33-
33+
3434
if ((int(major) > PYTHONOCC_VERSION_MAJOR) or
3535
(int(major) == PYTHONOCC_VERSION_MAJOR and int(minor) > PYTHONOCC_VERSION_MINOR) or
3636
(int(major) == PYTHONOCC_VERSION_MAJOR and int(minor) == PYTHONOCC_VERSION_MINOR and

src/Display/OCCViewer.py

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import itertools
2828

2929
import OCC
30+
from OCC.Core.Aspect import Aspect_GFM_VER
3031
from OCC.Core.AIS import AIS_Shape, AIS_Shaded, AIS_TexturedShape, AIS_WireFrame
3132
from OCC.Core.TopoDS import TopoDS_Shape
3233
from OCC.Core.gp import gp_Dir, gp_Pnt, gp_Pnt2d, gp_Vec
@@ -116,16 +117,16 @@ def to_string(_string):
116117

117118

118119
class Viewer3d(Display3d):
119-
def __init__(self, window_handle):
120+
def __init__(self, window_handle, parent=None):
120121
Display3d.__init__(self)
122+
self._parent = parent # the parent opengl GUI container
121123
self._window_handle = window_handle
122124
self._inited = False
123125
self._local_context_opened = False
124126
self.Context = None
125127
self.Viewer = None
126128
self.View = None
127129
self.OverLayer = None
128-
self.selected_shape = None
129130
self.default_drawer = None
130131
self._struc_mgr = None
131132
self._is_offscreen = None
@@ -134,6 +135,9 @@ def __init__(self, window_handle):
134135
self._select_callbacks = []
135136
self._overlay_items = []
136137

138+
def get_parent(self):
139+
return self._parent
140+
137141
def register_overlay_item(self, overlay_item):
138142
self._overlay_items.append(overlay_item)
139143
self.View.MustBeResized()
@@ -345,18 +349,32 @@ def ExportToImage(self, image_filename):
345349
def display_graduated_trihedron(self):
346350
self.View.GraduatedTrihedronDisplay()
347351

348-
def display_trihedron(self):
349-
""" Show a black trihedron in lower right corner
352+
def display_triedron(self):
353+
""" Show a black triedron in lower right corner
350354
"""
351355
self.View.TriedronDisplay(Aspect_TOTP_RIGHT_LOWER, Quantity_NOC_BLACK, 0.1, V3d_ZBUFFER)
352356

353-
def set_bg_gradient_color(self, R1, G1, B1, R2, G2, B2):
357+
def hide_triedron(self):
358+
""" Show a black triedron in lower right corner
359+
"""
360+
self.View.TriedronErase()
361+
362+
def set_bg_gradient_color(self, color1, color2, fill_method=Aspect_GFM_VER):
354363
""" set a bg vertical gradient color.
355-
R, G and B are floats.
364+
color1 is [R1, G1, B1], each being bytes or an instance of Quantity_Color
365+
color2 is [R2, G2, B2], each being bytes or an instance of Quantity_Color
366+
fill_method is one of Aspect_GFM_VER value Aspect_GFM_NONE, Aspect_GFM_HOR,
367+
Aspect_GFM_VER, Aspect_GFM_DIAG1, Aspect_GFM_DIAG2, Aspect_GFM_CORNER1, Aspect_GFM_CORNER2,
368+
Aspect_GFM_CORNER3, Aspect_GFM_CORNER4
356369
"""
357-
aColor1 = rgb_color(float(R1)/255., float(G1)/255., float(B1)/255.)
358-
aColor2 = rgb_color(float(R2)/255., float(G2)/255., float(B2)/255.)
359-
self.View.SetBgGradientColors(aColor1, aColor2, 2, True)
370+
if isinstance(color1, list) and isinstance(color2, list):
371+
R1, G1, B1 = color1
372+
R2, G2, B2 = color2
373+
color1 = rgb_color(float(R1)/255., float(G1)/255., float(B1)/255.)
374+
color2 = rgb_color(float(R2)/255., float(G2)/255., float(B2)/255.)
375+
elif not isinstance(color1, Quantity_Color) and isinstance(color2, Quantity_Color):
376+
raise AssertionError("color1 and color2 mmust be either [R, G, B] lists or a Quantity_Color")
377+
self.View.SetBgGradientColors(color1, color2, fill_method, True)
360378

361379
def SetBackgroundImage(self, image_filename, stretch=True):
362380
""" displays a background image (jpg, png etc.)
@@ -651,8 +669,8 @@ def __init__(self, screen_size=(640, 480)):
651669
self.Create()
652670
self.SetSize(screen_size[0], screen_size[1])
653671
self.SetModeShaded()
654-
self.set_bg_gradient_color(206, 215, 222, 128, 128, 128)
655-
self.display_trihedron()
672+
self.set_bg_gradient_color([206, 215, 222], [128, 128, 128])
673+
self.display_triedron()
656674
self.capture_number = 0
657675

658676
def DisplayShape(self, shapes, material=None, texture=None, color=None, transparency=None, update=True):

src/Display/SimpleGui.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@ def check_callable(_callable):
3333
raise AssertionError("The function supplied is not callable")
3434

3535

36-
def init_display(backend_str=None, size=(1024, 768)):
36+
def init_display(backend_str=None,
37+
size=(1024, 768),
38+
display_triedron=True,
39+
background_gradient_color1=[206, 215, 222],
40+
background_gradient_color2=[128, 128, 128]):
3741
""" This function loads and initialize a GUI using either wx, pyq4, pyqt5 or pyside.
3842
If ever the environment variable PYTHONOCC_OFFSCREEN_RENDERER, then the GUI is simply
3943
ignored and an offscreen renderer is returned.
@@ -111,11 +115,6 @@ def add_function_to_menu(self, menu_name, _callable):
111115
win.canva.InitDriver()
112116
app.SetTopWindow(win)
113117
display = win.canva._display
114-
# background gradient
115-
display.set_bg_gradient_color(206, 215, 222, 128, 128, 128)
116-
# display black trihedron
117-
display.display_trihedron()
118-
119118

120119
def add_menu(*args, **kwargs):
121120
win.add_menu(*args, **kwargs)
@@ -189,10 +188,6 @@ def add_function_to_menu(self, menu_name, _callable):
189188
win.canva.InitDriver()
190189
win.canva.qApp = app
191190
display = win.canva._display
192-
# background gradient
193-
display.set_bg_gradient_color(206, 215, 222, 128, 128, 128)
194-
# display black trihedron
195-
display.display_trihedron()
196191

197192
def add_menu(*args, **kwargs):
198193
win.add_menu(*args, **kwargs)
@@ -203,6 +198,14 @@ def add_function_to_menu(*args, **kwargs):
203198
def start_display():
204199
win.raise_() # make the application float to the top
205200
app.exec_()
201+
202+
if display_triedron:
203+
display.display_triedron()
204+
205+
if background_gradient_color1 and background_gradient_color2:
206+
# background gradient
207+
display.set_bg_gradient_color(background_gradient_color1, background_gradient_color2)
208+
206209
return display, start_display, add_menu, add_function_to_menu
207210

208211

src/Display/WebGl/threejs_renderer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
from OCC.Extend.TopologyUtils import is_edge, is_wire, discretize_edge, discretize_wire
3131
from OCC.Display.WebGl.simple_server import start_server
3232

33-
THREEJS_RELEASE = "r100"
33+
THREEJS_RELEASE = "r101"
3434

3535
def spinning_cursor():
3636
while True:

src/Display/backend.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@
77
PYQT4 = "qt-pyqt4"
88
PYQT5 = "qt-pyqt5"
99

10-
global QtCore, QtGui, QtWidgets, QtOpenGL
11-
global HAVE_PYQT5, HAVE_PYQT4, HAVE_PYSIDE, HAVE_WX, HAVE_BACKEND, \
12-
BACKEND_MODULE, QtCore, QtGui, QtWidgets, QtOpenGL
13-
1410
# backend module
1511
HAVE_PYQT5, HAVE_PYQT4, HAVE_PYSIDE, HAVE_WX = False, False, False, False
1612

src/Display/qtDisplay.py

Lines changed: 23 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env python
22

3-
##Copyright 2009-2014 Thomas Paviot (tpaviot@gmail.com)
3+
##Copyright 2009-2019 Thomas Paviot (tpaviot@gmail.com)
44
##
55
##This file is part of pythonOCC.
66
##
@@ -27,6 +27,7 @@
2727
from OCC.Display.backend import get_qt_modules
2828

2929
QtCore, QtGui, QtWidgets, QtOpenGL = get_qt_modules()
30+
3031
# check if signal available, not available
3132
# on PySide
3233
HAVE_PYQT_SIGNAL = hasattr(QtCore, 'pyqtSignal')
@@ -38,28 +39,28 @@
3839
class qtBaseViewer(QtOpenGL.QGLWidget):
3940
''' The base Qt Widget for an OCC viewer
4041
'''
41-
4242
def __init__(self, parent=None):
43-
QtOpenGL.QGLWidget.__init__(self, parent)
43+
super(qtBaseViewer, self).__init__(parent)
4444
self._display = None
4545
self._inited = False
4646

4747
# enable Mouse Tracking
4848
self.setMouseTracking(True)
49+
4950
# Strong focus
5051
self.setFocusPolicy(QtCore.Qt.WheelFocus)
5152

5253
# required for overpainting the widget
5354
self.setAttribute(QtCore.Qt.WA_PaintOnScreen)
5455
self.setAttribute(QtCore.Qt.WA_NoSystemBackground)
56+
5557
self.setAutoFillBackground(False)
5658

5759
def GetHandle(self):
5860
''' returns an the identifier of the GUI widget.
5961
It must be an integer
6062
'''
6163
win_id = self.winId() # this returns either an int or voitptr
62-
6364
if "%s" % type(win_id) == "<type 'PyCObject'>": # PySide
6465
### with PySide, self.winId() does not return an integer
6566
if sys.platform == "win32":
@@ -104,7 +105,7 @@ def __init__(self, *kargs):
104105
self._rightisdown = False
105106
self._selection = None
106107
self._drawtext = True
107-
self._qApp = QtWidgets.QApplication.instance()
108+
self._qApp = QtWidgets.QApplication.instance()
108109
self._key_map = {}
109110
self._current_cursor = "arrow"
110111
self._available_cursors = {}
@@ -119,19 +120,19 @@ def qApp(self, value):
119120
self._qApp = value
120121

121122
def InitDriver(self):
122-
self._display = OCCViewer.Viewer3d(self.GetHandle())
123+
self._display = OCCViewer.Viewer3d(window_handle=self.GetHandle(), parent=self)
123124
self._display.Create()
124125
# background gradient
125-
self._display.set_bg_gradient_color(206, 215, 222, 128, 128, 128)
126-
# background gradient
127-
self._display.display_trihedron()
128126
self._display.SetModeShaded()
129-
self._display.DisableAntiAliasing()
130127
self._inited = True
131128
# dict mapping keys to functions
132-
self._SetupKeyMap()
133-
#
134-
self._display.thisown = False
129+
self._key_map = {ord('W'): self._display.SetModeWireFrame,
130+
ord('S'): self._display.SetModeShaded,
131+
ord('A'): self._display.EnableAntiAliasing,
132+
ord('B'): self._display.DisableAntiAliasing,
133+
ord('H'): self._display.SetModeHLR,
134+
ord('F'): self._display.FitAll,
135+
ord('G'): self._display.SetSelectionMode}
135136
self.createCursors()
136137

137138
def createCursors(self):
@@ -153,25 +154,14 @@ def createCursors(self):
153154

154155
self._current_cursor = "arrow"
155156

156-
def _SetupKeyMap(self):
157-
self._key_map = {ord('W'): self._display.SetModeWireFrame,
158-
ord('S'): self._display.SetModeShaded,
159-
ord('A'): self._display.EnableAntiAliasing,
160-
ord('B'): self._display.DisableAntiAliasing,
161-
ord('H'): self._display.SetModeHLR,
162-
ord('F'): self._display.FitAll,
163-
ord('G'): self._display.SetSelectionMode}
164-
165157
def keyPressEvent(self, event):
166158
code = event.key()
167159
if code in self._key_map:
168160
self._key_map[code]()
161+
elif code in range(256):
162+
log.info('key: "%s"(code %i) not mapped to any function' % (chr(code), code))
169163
else:
170-
log.info("key: %s \nnot mapped to any function", code)
171-
172-
def Test(self):
173-
if self._inited:
174-
self._display.Test()
164+
log.info('key: code %i not mapped to any function' % code)
175165

176166
def focusInEvent(self, event):
177167
if self._inited:
@@ -182,20 +172,14 @@ def focusOutEvent(self, event):
182172
self._display.Repaint()
183173

184174
def paintEvent(self, event):
185-
if self._inited:
186-
self._display.Context.UpdateCurrentViewer()
187-
# important to allow overpainting of the OCC OpenGL context in Qt
188-
self.swapBuffers()
189-
190175
if self._drawbox:
176+
self._display.Repaint()
177+
self._display.Repaint()
191178
painter = QtGui.QPainter(self)
192-
painter.setPen(QtGui.QPen(QtGui.QColor(0, 0, 0), 1))
179+
painter.setPen(QtGui.QPen(QtGui.QColor(0, 0, 0), 2))
193180
rect = QtCore.QRect(*self._drawbox)
194181
painter.drawRect(rect)
195182

196-
def ZoomAll(self, evt):
197-
self._display.FitAll()
198-
199183
def wheelEvent(self, event):
200184
try: # PyQt4/PySide
201185
delta = event.delta()
@@ -205,12 +189,8 @@ def wheelEvent(self, event):
205189
zoom_factor = 2.
206190
else:
207191
zoom_factor = 0.5
208-
self._display.Repaint()
209192
self._display.ZoomFactor(zoom_factor)
210193

211-
def dragMoveEvent(self, event):
212-
pass
213-
214194
@property
215195
def cursor(self):
216196
return self._current_cursor
@@ -271,7 +251,7 @@ def DrawBox(self, event):
271251
if abs(dx) <= tolerance and abs(dy) <= tolerance:
272252
return
273253
self._drawbox = [self.dragStartPosX, self.dragStartPosY, dx, dy]
274-
self.update()
254+
275255

276256
def mouseMoveEvent(self, evt):
277257
pt = evt.pos()
@@ -310,11 +290,13 @@ def mouseMoveEvent(self, evt):
310290
self._zoom_area = True
311291
self.cursor = "zoom-area"
312292
self.DrawBox(evt)
293+
self.update()
313294
# SELECT AREA
314295
elif (buttons == QtCore.Qt.LeftButton and
315296
modifiers == QtCore.Qt.ShiftModifier):
316297
self._select_area = True
317298
self.DrawBox(evt)
299+
self.update()
318300
else:
319301
self._drawbox = False
320302
self._display.MoveTo(pt.x(), pt.y())

src/Extend/DataExchange.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,9 +216,9 @@ def _get_sub_shapes(lab, loc):
216216
#print(" all ass locs :", locs)
217217

218218
loc = TopLoc_Location()
219-
for i in range(len(locs)):
220-
#print(" take loc :", locs[i])
221-
loc = loc.Multiplied(locs[i])
219+
for l in locs:
220+
#print(" take loc :", l)
221+
loc = loc.Multiplied(l)
222222

223223
#trans = loc.Transformation()
224224
#print(" FINAL loc :")

0 commit comments

Comments
 (0)