-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainGUI.py
More file actions
231 lines (202 loc) · 7.31 KB
/
mainGUI.py
File metadata and controls
231 lines (202 loc) · 7.31 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
import os
import sys
from OCC.Core.AIS import AIS_InteractiveContext, AIS_NArray1OfEntityOwner, AIS_Shape, AIS_ViewCube
from OCC.Core.Aspect import Aspect_GradientFillMethod, Aspect_TypeOfTriedronPosition
from OCC.Core.BRepBuilderAPI import (
BRepBuilderAPI_MakeEdge,
BRepBuilderAPI_MakeFace,
BRepBuilderAPI_MakeVertex,
BRepBuilderAPI_MakeWire,
)
from OCC.Core.BRepMesh import BRepMesh_IncrementalMesh
from OCC.Core.BRepOffsetAPI import BRepOffsetAPI_MakePipe
from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeBox
from OCC.Core.gp import gp_Ax2, gp_Circ, gp_Dir, gp_Pnt, gp_Trsf, gp_Vec
from OCC.Core.Graphic3d import (
Graphic3d_Camera,
Graphic3d_GraduatedTrihedron,
Graphic3d_NOM_ALUMINIUM,
Graphic3d_NOM_STEEL,
Graphic3d_RenderingParams,
Graphic3d_RM_RASTERIZATION,
Graphic3d_StereoMode_QuadBuffer,
Graphic3d_StructureManager,
Graphic3d_TransformPers,
Graphic3d_TransModeFlags,
Graphic3d_Vec2i,
)
from OCC.Core.Message import Message_ProgressRange
from OCC.Core.Prs3d import Prs3d_DatumAspect
from OCC.Core.Quantity import Quantity_Color
from OCC.Core.RWMesh import RWMesh_CoordinateSystem_Zup
from OCC.Core.RWObj import RWObj_CafReader
from OCC.Core.TopAbs import TopAbs_FACE
from OCC.Core.TopExp import TopExp_Explorer
from OCC.Core.TopoDS import TopoDS_Edge, TopoDS_Shape, TopoDS_Wire, topods
from OCC.Core.V3d import V3d_View
from OCC.Core.XCAFApp import XCAFApp_Application
from OCC.Core.XCAFDoc import XCAFDoc_DocumentTool
from OCC.Display.OCCViewer import Viewer3d
# PySide6
from PySide6.QtCore import QRect, Qt, Signal, Slot
from PySide6.QtGui import QGuiApplication
from PySide6.QtWidgets import QApplication, QMainWindow, QWidget
from pyOCC import createTrihedron, getColor, readStep, readStepWithColor
from qtViewer3d import qtViewer3dWidget
# from test04 import ReadObjWithColor
class MainWindow(QMainWindow):
def __init__(self):
QMainWindow.__init__(self)
self.setWindowTitle("机器人通用平台")
primary_screen = QGuiApplication.primaryScreen().size()
self.setGeometry(0, 0, primary_screen.width() * 0.8, primary_screen.height() * 0.8)
# 去掉窗口标题
# self.setWindowFlags(Qt.FramelessWindowHint)
self.canvas = qtViewer3dWidget(
self,
bg_color_aspect=(
(37, 55, 113),
(36, 151, 132),
Aspect_GradientFillMethod.Aspect_GradientFillMethod_Vertical,
),
selection_color=(13, 141, 255),
)
self.setCentralWidget(self.canvas)
# 开启抗锯齿
self.canvas.viewer3d.EnableAntiAliasing()
self.centerOnScreen()
# # 设置视图为隐藏线模式 (HLR)
# gui.v3d.SetModeHLR()
if True:
# 测试其它显示渲染效果
self.canvas.viewer3d.ChangeRenderingParams(
Method=Graphic3d_RM_RASTERIZATION,
RaytracingDepth=3,
IsShadowEnabled=True,
IsReflectionEnabled=True,
IsAntialiasingEnabled=True,
IsTransparentShadowEnabled=True,
StereoMode=Graphic3d_StereoMode_QuadBuffer,
AnaglyphFilter=Graphic3d_RenderingParams.Anaglyph_RedCyan_Optimized,
ToReverseStere=False,
)
# self.canvas.viewer3d.Context.HilightWithColor()
# end alternate constructor
@property
def display(self):
return self.canvas.viewer3d.Context.Display
# end property
@property
def context(self):
return self.canvas.viewer3d.Context
# end property
@property
def view(self):
return self.canvas.viewer3d.View
# end property
@property
def v3d(self):
return self.canvas.viewer3d
# end property
def centerOnScreen(self):
# 获取屏幕的尺寸
primary_screen = QGuiApplication.primaryScreen().size()
size = self.geometry()
x = (primary_screen.width() - size.width()) // 2
y = 0.7 * (primary_screen.height() - size.height()) // 2
# 移动主窗口到中心位置
self.move(x, y)
# end def
# end class
def read_point(file_path, gui):
from OCC.Core.BRepBuilderAPI import BRepBuilderAPI_MakeVertex
point_list = []
with open(file_path, "r") as f:
for i in f:
x, y, z = i.split(" ")
# print(f"x:{x},y:{y},z:{z}")
a_pnt = gp_Pnt(float(x), float(y), float(z))
point_list.append(a_pnt)
# end open file
point_list
for pnt in point_list:
a_point_shape = BRepBuilderAPI_MakeVertex(pnt).Shape()
a_ais_point = AIS_Shape(a_point_shape)
gui.canvas.viewer3d.Context.Display(a_ais_point, False)
gui.canvas.viewer3d.Context.UpdateCurrent()
# end def
def test(gui: MainWindow):
test_list: list[AIS_Shape] = []
# 设置鼠标滑过时显示选择对象
# gui.context.SetAutoActivateSelection(False)
# 设置高亮时的颜色
aHighlightStyle = gui.context.HighlightStyle()
aHighlightStyle.SetColor(getColor(255, 0, 0))
# 创建 box
box_shape = BRepPrimAPI_MakeBox(5.0, 5.0, 5.0).Shape()
# ais_box = AIS_Shape(box_shape)
# ais_box.SetColor(Quantity_Color(Graphic3d_NOM_STEEL))
for n in range(5):
a_trsf = gp_Trsf()
a_trsf.SetTranslation(gp_Vec(n * 10, 0, 0))
ais_box = AIS_Shape(box_shape)
ais_box.SetLocalTransformation(a_trsf)
ais_box.SetColor(Quantity_Color(Graphic3d_NOM_STEEL))
gui.display(ais_box, True)
test_list.append(ais_box)
gui.v3d.FitAll()
# gui.context.HilightSelected(False)
# for ais in test_list:
# gui.context.Hilight(ais, True)
# for ais in test_list:
# gui.context.UpdateSelected(True)
# print(gui.context.IsSelected(ais))
# 显示 AIS_Shape
# gui.display(ais_box, True)
# gui.v3d.FitAll()
# 设置高亮
# gui.context.Hilight(ais_box, True)
# 设置选择
gui.context.InitSelected()
gui.context.AddSelect(test_list[2])
print(gui.context.IsSelected(test_list[2]))
# gui.context.Select(test_list[2],True)
gui.context.UpdateSelected(True)
gui.context.UpdateCurrentViewer()
gui.context.ClearSelected(True)
print(gui.context.IsSelected(test_list[2]))
gui.context.UpdateSelected(True)
gui.context.AddSelect(test_list[1])
# gui.context.Select(test_list[2],True)
gui.context.UpdateSelected(True)
gui.context.UpdateCurrentViewer()
# my_SelectMgr_EntityOwner = ais_box.GetOwner()
# print(my_SelectMgr_EntityOwner)
# gui.context.Selection().AddSelect(my_SelectMgr_EntityOwner)
# gui.context.SetSelected(my_SelectMgr_EntityOwner, True)
# xpmin, ypmin, xpmax, ypmax = 0, 0, 5000, 5000
# gui.context.Select(xpmin, ypmin, xpmax, ypmax, gui.view, True)
# gui.context.AddOrRemoveSelected(ais_box, True)
# gui.context.ClearSelected()
# print(gui.context.IsSelected(ais_box))
# gui.context.UpdateSelected(True)
# 选中高亮
# gui.context.HilightSelected(False)
# gui.update()
# end def
def mainGUI():
app = QApplication().instance()
if not app:
app = QApplication(sys.argv)
gui = MainWindow()
gui.show()
gui.canvas.InitDriver()
gui.canvas.qApp = app
test(gui)
# 窗口置顶
gui.raise_()
app.exec()
# end def
if __name__ == "__main__":
mainGUI()
# end main