|
| 1 | +##Copyright 2021 Thomas Paviot ([email protected]) |
| 2 | +## |
| 3 | +##This file is part of pythonOCC. |
| 4 | +## |
| 5 | +##pythonOCC is free software: you can redistribute it and/or modify |
| 6 | +##it under the terms of the GNU Lesser General Public License as published by |
| 7 | +##the Free Software Foundation, either version 3 of the License, or |
| 8 | +##(at your option) any later version. |
| 9 | +## |
| 10 | +##pythonOCC is distributed in the hope that it will be useful, |
| 11 | +##but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | +##MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | +##GNU Lesser General Public License for more details. |
| 14 | +## |
| 15 | +##You should have received a copy of the GNU Lesser General Public License |
| 16 | +##along with pythonOCC. If not, see <http://www.gnu.org/licenses/>. |
| 17 | + |
| 18 | +from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeBox, BRepPrimAPI_MakeCylinder, BRepPrimAPI_MakeSphere |
| 19 | +from OCC.Core.BRepBuilderAPI import BRepBuilderAPI_Transform |
| 20 | +from OCC.Core.gp import gp_Trsf, gp_Vec |
| 21 | + |
| 22 | +from OCC.Display.SimpleGui import init_display |
| 23 | + |
| 24 | +def erase_box(event=None): |
| 25 | + display.Context.Erase(ais_box, True) |
| 26 | + |
| 27 | +def erase_cylinder(event=None): |
| 28 | + display.Context.Erase(ais_cylinder, True) |
| 29 | + |
| 30 | +def erase_sphere(event=None): |
| 31 | + display.Context.Erase(ais_sphere, True) |
| 32 | + |
| 33 | +display, start_display, add_menu, add_function_to_menu = init_display() |
| 34 | +# a box at the origin |
| 35 | +a_box = BRepPrimAPI_MakeBox(10., 20., 30.).Shape() |
| 36 | + |
| 37 | +# a translated sphere along the x axis |
| 38 | +trns = gp_Trsf() |
| 39 | +trns.SetTranslation(gp_Vec(50, 0, 0)) |
| 40 | +a_sphere = BRepBuilderAPI_Transform(BRepPrimAPI_MakeSphere(10.).Shape(), trns, False).Shape() |
| 41 | + |
| 42 | +# a translated cylinder along the x axis |
| 43 | +trns = gp_Trsf() |
| 44 | +trns.SetTranslation(gp_Vec(-50, 0, 0)) |
| 45 | +a_cylinder = BRepBuilderAPI_Transform(BRepPrimAPI_MakeCylinder(10., 40.).Shape(), trns, False).Shape() |
| 46 | + |
| 47 | +ais_box = display.DisplayShape(a_box)[0] |
| 48 | +ais_sphere = display.DisplayShape(a_sphere)[0] |
| 49 | +ais_cylinder = display.DisplayShape(a_cylinder)[0] |
| 50 | + |
| 51 | + |
| 52 | +if __name__ == '__main__': |
| 53 | + add_menu('Erase Shapes') |
| 54 | + add_function_to_menu('Erase Shapes', erase_box) |
| 55 | + add_function_to_menu('Erase Shapes', erase_cylinder) |
| 56 | + add_function_to_menu('Erase Shapes', erase_sphere) |
| 57 | + display.FitAll() |
| 58 | + start_display() |
0 commit comments