-
Notifications
You must be signed in to change notification settings - Fork 137
Expand file tree
/
Copy pathcore_display_callbacks.py
More file actions
56 lines (49 loc) · 1.98 KB
/
core_display_callbacks.py
File metadata and controls
56 lines (49 loc) · 1.98 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
##Copyright 2010-2014 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/>.
from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeBox, BRepPrimAPI_MakeTorus
from OCC.Core.Bnd import Bnd_Box
from OCC.Core.BRepBndLib import brepbndlib_Add
from OCC.Display.SimpleGui import init_display
def print_xy_click(shp, *kwargs):
for shape in shp:
print("Shape selected: ", shape)
print(kwargs)
def compute_bbox(shp, *kwargs):
print(f"Compute bbox for {shp} ")
for shape in shp:
bbox = Bnd_Box()
brepbndlib_Add(shape, bbox)
xmin, ymin, zmin, xmax, ymax, zmax = bbox.Get()
dx = xmax - xmin
dy = ymax - ymin
dz = zmax - zmin
print("Selected shape bounding box : dx=%f, dy=%f, dz=%f." % (dx, dy, dz))
print(
" bounding box center: x=%f, y=%f, z=%f"
% (xmin + dx / 2.0, ymin + dy / 2.0, zmin + dz / 2.0)
)
display, start_display, add_menu, add_function_to_menu = init_display()
# register callbacks
display.register_select_callback(print_xy_click)
display.register_select_callback(compute_bbox)
# creating geometry
my_torus = BRepPrimAPI_MakeBox(10.0, 20.0, 30.0).Shape()
my_box = BRepPrimAPI_MakeTorus(30.0, 5.0).Shape()
# and finally display geometry
display.DisplayShape(my_torus)
display.DisplayShape(my_box, update=True)
start_display()