forked from tpaviot/pythonocc-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtkDisplay.py
More file actions
79 lines (67 loc) · 2.65 KB
/
Copy pathtkDisplay.py
File metadata and controls
79 lines (67 loc) · 2.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
##Copyright 2023 Thomas Paviot (tpaviot@gmail.com)
##
##This file is part of pythonOCC.
##
##pythonOCC is free software: you can redistribute it and/or modify
##it under the terms of the GNU Lesser General Public License as published by
##the Free Software Foundation, either version 3 of the License, or
##(at your option) any later version.
##
##pythonOCC is distributed in the hope that it will be useful,
##but WITHOUT ANY WARRANTY; without even the implied warranty of
##MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
##GNU Lesser General Public License for more details.
##
##You should have received a copy of the GNU Lesser General Public License
##along with pythonOCC. If not, see <http://www.gnu.org/licenses/>.
import tkinter as tk
from OCC.Display import OCCViewer
class tkViewer3d(tk.Frame):
def __init__(self, parent, default=""):
tk.Frame.__init__(self, parent, width=1024, height=768)
self.bind("<Map>", self.Map)
self.bind("<Configure>", self.Resize)
self.bind("<B1-Motion>", self.Rotate)
self.bind("<Button-1>", self.LeftDown)
self.bind("<B2-Motion>", self.Pan)
self.bind("<Button-2>", self.LeftDown)
# zoom
self.bind("<MouseWheel>", self.Zoom) # windows
self.bind("<Button-4>", self.Zoom) # Linux
self.bind("<Button-5>", self.Zoom) # Linux
self._display = None
self._inited = False
self.drag_pos_y = self.drag_pos_x = 0
def LeftDown(self, event):
self.drag_pos_x = event.x
self.drag_pos_y = event.y
self._display.StartRotation(self.drag_pos_x, self.drag_pos_y)
def Rotate(self, event):
self._display.Rotation(event.x, event.y)
def Pan(self, event):
dx = event.x - self.drag_pos_x
dy = event.y - self.drag_pos_y
self.drag_pos_x = event.x
self.drag_pos_y = event.y
self._display.Pan(dx, -dy)
def Zoom(self, event):
# Linux
if event.num == 4 or event.delta > 0: # zoom in
zoom_factor = 2.0
elif event.num == 5 or event.delta < 0: # zoom out
zoom_factor = 0.5
# Windows
if event.delta < 0: # zoom out
zoom_factor = 1/1.2
elif event.delta > 0: # zoom in
zoom_factor = 1.2
self._display.ZoomFactor(zoom_factor)
def Resize(self, event):
if self._inited:
self._display.Repaint()
def Map(self, event):
if not self._inited:
self._display = OCCViewer.Viewer3d()
self._display.Create(window_handle=self.winfo_id(), parent=self)
self._display.SetModeShaded()
self._inited = True