|
| 1 | +##Author github user @Tanneguydv, 2021 |
| 2 | + |
| 3 | +import sys |
| 4 | +from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeBox |
| 5 | + |
| 6 | +from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QHBoxLayout, QGroupBox, QDialog, QVBoxLayout |
| 7 | + |
| 8 | +from OCC.Display.backend import load_backend |
| 9 | +load_backend('qt-pyqt5') |
| 10 | +import OCC.Display.qtDisplay as qtDisplay |
| 11 | + |
| 12 | +class App(QDialog): |
| 13 | + |
| 14 | + def __init__(self): |
| 15 | + super().__init__() |
| 16 | + self.title = 'PyQt5 / pythonOCC' |
| 17 | + self.left = 300 |
| 18 | + self.top = 300 |
| 19 | + self.width = 800 |
| 20 | + self.height = 300 |
| 21 | + self.initUI() |
| 22 | + |
| 23 | + def initUI(self): |
| 24 | + self.setWindowTitle(self.title) |
| 25 | + self.setGeometry(self.left, self.top, self.width, self.height) |
| 26 | + self.createHorizontalLayout() |
| 27 | + |
| 28 | + windowLayout = QVBoxLayout() |
| 29 | + windowLayout.addWidget(self.horizontalGroupBox) |
| 30 | + self.setLayout(windowLayout) |
| 31 | + self.show() |
| 32 | + |
| 33 | + def createHorizontalLayout(self): |
| 34 | + self.horizontalGroupBox = QGroupBox("Display PythonOCC") |
| 35 | + layout = QHBoxLayout() |
| 36 | + |
| 37 | + disp = QPushButton('Display Box', self) |
| 38 | + disp.clicked.connect(self.displayBOX) |
| 39 | + layout.addWidget(disp) |
| 40 | + |
| 41 | + eras = QPushButton('Erase Box', self) |
| 42 | + eras.clicked.connect(self.eraseBOX) |
| 43 | + layout.addWidget(eras) |
| 44 | + |
| 45 | + self.canvas = qtDisplay.qtViewer3d(self) |
| 46 | + layout.addWidget(self.canvas) |
| 47 | + self.canvas.resize(200, 200) |
| 48 | + self.canvas.InitDriver() |
| 49 | + self.display = self.canvas._display |
| 50 | + self.horizontalGroupBox.setLayout(layout) |
| 51 | + |
| 52 | + def displayBOX(self): |
| 53 | + a_box = BRepPrimAPI_MakeBox(10., 20., 30.).Shape() |
| 54 | + self.ais_box = self.display.DisplayShape(a_box)[0] |
| 55 | + self.display.FitAll() |
| 56 | + |
| 57 | + def eraseBOX(self): |
| 58 | + self.display.Context.Erase(self.ais_box, True) |
| 59 | + |
| 60 | + |
| 61 | + |
| 62 | +if __name__ == '__main__': |
| 63 | + app = QApplication(sys.argv) |
| 64 | + ex = App() |
| 65 | + sys.exit(app.exec_()) |
0 commit comments