forked from Rowland/EG
239 lines
7.4 KiB
Python
239 lines
7.4 KiB
Python
#!/usr/bin/env python3
|
||
# -*- coding: utf-8 -*-
|
||
"""
|
||
坐标轴修复验证脚本
|
||
用于测试鼠标悬停高亮和拖动一致性的修复效果
|
||
"""
|
||
|
||
import warnings
|
||
warnings.filterwarnings("ignore", category=DeprecationWarning)
|
||
|
||
import sys
|
||
from PyQt5.QtWidgets import QApplication, QMainWindow, QVBoxLayout, QWidget, QLabel
|
||
from PyQt5.QtCore import Qt
|
||
from QPanda3D.QPanda3DWidget import QPanda3DWidget
|
||
from QPanda3D.Panda3DWorld import Panda3DWorld
|
||
from panda3d.core import *
|
||
|
||
class AxisTestWorld(Panda3DWorld):
|
||
def __init__(self):
|
||
super().__init__()
|
||
|
||
print("=== 坐标轴修复验证测试 ===")
|
||
self.setBackgroundColor(0.2, 0.2, 0.3)
|
||
|
||
# 调整相机位置
|
||
self.cam.setPos(8, -15, 8)
|
||
self.cam.lookAt(0, 0, 0)
|
||
|
||
# Qt部件引用
|
||
self.qtWidget = None
|
||
|
||
# 基础光照
|
||
alight = AmbientLight('alight')
|
||
alight.setColor((0.3, 0.3, 0.3, 1))
|
||
alnp = self.render.attachNewNode(alight)
|
||
self.render.setLight(alnp)
|
||
|
||
dlight = DirectionalLight('dlight')
|
||
dlight.setColor((0.8, 0.8, 0.8, 1))
|
||
dlnp = self.render.attachNewNode(dlight)
|
||
dlnp.setHpr(45, -45, 0)
|
||
self.render.setLight(dlnp)
|
||
|
||
# 创建测试立方体
|
||
self.createTestCube()
|
||
|
||
# 设置当前工具
|
||
self.currentTool = "移动"
|
||
|
||
# 模拟选择系统和工具管理器
|
||
from core.selection import SelectionSystem
|
||
self.selection = SelectionSystem(self)
|
||
|
||
# 简单的工具管理器模拟
|
||
class SimpleToolManager:
|
||
def isScaleTool(self):
|
||
return False
|
||
def isRotateTool(self):
|
||
return False
|
||
|
||
self.tool_manager = SimpleToolManager()
|
||
|
||
# 模拟属性面板
|
||
class SimplePropertyPanel:
|
||
def refreshModelValues(self, node):
|
||
print(f"属性更新: {node.getName()} 位置={node.getPos()}")
|
||
|
||
self.property_panel = SimplePropertyPanel()
|
||
|
||
# 自动选中立方体
|
||
self.selectedNode = self.testCube
|
||
self.selection.updateSelection(self.testCube)
|
||
|
||
print("测试说明:")
|
||
print("1. 鼠标悬停在坐标轴上应该变为黄色高亮")
|
||
print("2. 点击并拖拽坐标轴,立方体应该沿对应轴移动")
|
||
print("3. 拖动行为应该与鼠标移动方向一致")
|
||
|
||
def setQtWidget(self, widget):
|
||
"""设置Qt部件引用"""
|
||
self.qtWidget = widget
|
||
|
||
def getWindowSize(self):
|
||
"""获取准确的窗口尺寸"""
|
||
if self.qtWidget:
|
||
width, height = self.qtWidget.getActualSize()
|
||
if width > 0 and height > 0:
|
||
return width, height
|
||
|
||
if hasattr(self, 'win') and self.win:
|
||
width = self.win.getXSize()
|
||
height = self.win.getYSize()
|
||
return width, height
|
||
|
||
return 800, 600
|
||
|
||
def createTestCube(self):
|
||
"""创建测试立方体"""
|
||
from panda3d.core import CardMaker
|
||
|
||
cm = CardMaker('cube')
|
||
cm.setFrame(-1, 1, -1, 1)
|
||
|
||
self.testCube = self.render.attachNewNode("testCube")
|
||
|
||
# 6个面,不同颜色
|
||
faces = [
|
||
(Point3(0, 1, 0), Vec3(0, 0, 0), (1, 0.5, 0.5, 1)), # 前面
|
||
(Point3(0, -1, 0), Vec3(0, 0, 180), (0.5, 1, 0.5, 1)), # 后面
|
||
(Point3(-1, 0, 0), Vec3(0, 0, 90), (0.5, 0.5, 1, 1)), # 左面
|
||
(Point3(1, 0, 0), Vec3(0, 0, -90), (1, 1, 0.5, 1)), # 右面
|
||
(Point3(0, 0, 1), Vec3(-90, 0, 0), (1, 0.5, 1, 1)), # 顶面
|
||
(Point3(0, 0, -1), Vec3(90, 0, 0), (0.5, 1, 1, 1)) # 底面
|
||
]
|
||
|
||
for pos, hpr, color in faces:
|
||
face = self.testCube.attachNewNode(cm.generate())
|
||
face.setPos(pos)
|
||
face.setHpr(hpr)
|
||
face.setColor(*color)
|
||
|
||
print(f"✓ 创建测试立方体,位置: {self.testCube.getPos()}")
|
||
return self.testCube
|
||
|
||
def mousePressEventLeft(self, evt):
|
||
"""处理鼠标左键按下事件"""
|
||
if not evt:
|
||
return
|
||
|
||
x = evt.get('x', 0)
|
||
y = evt.get('y', 0)
|
||
|
||
# 检查坐标轴点击
|
||
if self.selection.gizmo:
|
||
gizmoAxis = self.selection.checkGizmoClick(x, y)
|
||
if gizmoAxis:
|
||
print(f"✓ 坐标轴点击检测成功: {gizmoAxis}")
|
||
self.selection.startGizmoDrag(gizmoAxis, x, y)
|
||
return
|
||
else:
|
||
print("× 坐标轴点击检测失败")
|
||
|
||
def mouseReleaseEventLeft(self, evt):
|
||
"""处理鼠标左键释放事件"""
|
||
if self.selection.isDraggingGizmo:
|
||
self.selection.stopGizmoDrag()
|
||
|
||
def mouseMoveEvent(self, evt):
|
||
"""处理鼠标移动事件"""
|
||
if not evt:
|
||
return
|
||
|
||
x = evt.get('x', 0)
|
||
y = evt.get('y', 0)
|
||
|
||
# 处理坐标轴拖拽
|
||
if self.selection.isDraggingGizmo:
|
||
self.selection.updateGizmoDrag(x, y)
|
||
return
|
||
|
||
# 更新坐标轴高亮
|
||
if self.selection.gizmo and not self.selection.isDraggingGizmo:
|
||
self.selection.updateGizmoHighlight(x, y)
|
||
|
||
|
||
class TestWidget(QPanda3DWidget):
|
||
"""测试部件"""
|
||
def __init__(self, world, parent=None):
|
||
super().__init__(world, parent)
|
||
self.world = world
|
||
|
||
if hasattr(world, 'setQtWidget'):
|
||
world.setQtWidget(self)
|
||
|
||
def getActualSize(self):
|
||
return (self.width(), self.height())
|
||
|
||
def mousePressEvent(self, event):
|
||
if event.button() == Qt.LeftButton:
|
||
self.world.mousePressEventLeft({
|
||
'x': event.x(),
|
||
'y': event.y()
|
||
})
|
||
event.accept()
|
||
|
||
def mouseReleaseEvent(self, event):
|
||
if event.button() == Qt.LeftButton:
|
||
self.world.mouseReleaseEventLeft({
|
||
'x': event.x(),
|
||
'y': event.y()
|
||
})
|
||
event.accept()
|
||
|
||
def mouseMoveEvent(self, event):
|
||
self.world.mouseMoveEvent({
|
||
'x': event.x(),
|
||
'y': event.y()
|
||
})
|
||
event.accept()
|
||
|
||
|
||
def main():
|
||
print("启动坐标轴修复验证测试...")
|
||
|
||
app = QApplication(sys.argv)
|
||
|
||
# 创建主窗口
|
||
mainWindow = QMainWindow()
|
||
mainWindow.setWindowTitle("坐标轴修复验证测试")
|
||
mainWindow.setGeometry(100, 100, 900, 700)
|
||
|
||
# 创建布局
|
||
centralWidget = QWidget()
|
||
layout = QVBoxLayout(centralWidget)
|
||
|
||
# 添加说明
|
||
label = QLabel("坐标轴修复验证测试 - 测试鼠标悬停高亮和拖动一致性")
|
||
label.setAlignment(Qt.AlignCenter)
|
||
label.setStyleSheet("background-color: lightgreen; padding: 10px; font-size: 12px;")
|
||
layout.addWidget(label)
|
||
|
||
# 创建世界和部件
|
||
world = AxisTestWorld()
|
||
pandaWidget = TestWidget(world)
|
||
layout.addWidget(pandaWidget)
|
||
|
||
mainWindow.setCentralWidget(centralWidget)
|
||
mainWindow.show()
|
||
|
||
print("\n修复验证项目:")
|
||
print("1. ✓ 鼠标悬停时坐标轴应该正确高亮为黄色")
|
||
print("2. ✓ 点击坐标轴应该能正确开始拖拽")
|
||
print("3. ✓ 拖拽方向应该与鼠标移动方向一致")
|
||
print("4. ✓ 减少了控制台调试输出")
|
||
|
||
return app.exec_()
|
||
|
||
if __name__ == "__main__":
|
||
sys.exit(main()) |