feat: 完善一级关系参数化建模与参数导出
This commit is contained in:
+52
-17
@@ -54,7 +54,7 @@ from .info_panel import InfoPanelMixin
|
||||
from .ui_helpers import * # noqa: F403
|
||||
from .window_actions import WindowActionMixin
|
||||
from .window_core import WindowCoreMixin
|
||||
from .window_state import WindowStateMixin
|
||||
from .window_state import PROPERTY_TABLE_HEADERS, WindowStateMixin
|
||||
|
||||
|
||||
_CRASH_LOG_HANDLE = None
|
||||
@@ -145,7 +145,7 @@ def _isolated_edit_worker_request(argv: list[str]) -> Path | None:
|
||||
class StepEditorWindow(WindowCoreMixin, WindowStateMixin, WindowActionMixin, InfoPanelMixin, QMainWindow):
|
||||
ui_task_requested = Signal(object)
|
||||
|
||||
def __init__(self, step_path: str | Path, *, background_load: bool = False):
|
||||
def __init__(self, step_path: str | Path | None = None, *, background_load: bool = False):
|
||||
_suppress_vtk_output_window()
|
||||
super().__init__()
|
||||
self.ui_task_requested.connect(self._run_ui_task, Qt.ConnectionType.QueuedConnection)
|
||||
@@ -154,7 +154,7 @@ class StepEditorWindow(WindowCoreMixin, WindowStateMixin, WindowActionMixin, Inf
|
||||
self.resize(1280, 820)
|
||||
|
||||
self.model: StepModel | None = None
|
||||
self.step_path = Path(step_path)
|
||||
self.step_path = Path(step_path) if step_path else None
|
||||
self.selected_kind: str | None = None
|
||||
self.selected_part_id: int | None = None
|
||||
self.selected_solid_id: int | None = None
|
||||
@@ -585,6 +585,32 @@ class StepEditorWindow(WindowCoreMixin, WindowStateMixin, WindowActionMixin, Inf
|
||||
color: #8f99a8;
|
||||
font-weight: 650;
|
||||
}
|
||||
QPushButton#exportParametersButton {
|
||||
background: #f0fdfa;
|
||||
border: 1px solid #0f766e;
|
||||
border-bottom-color: #115e59;
|
||||
border-radius: 6px;
|
||||
color: #134e4a;
|
||||
font-weight: 750;
|
||||
min-height: 30px;
|
||||
padding: 6px 11px;
|
||||
}
|
||||
QPushButton#exportParametersButton:hover {
|
||||
background: #ccfbf1;
|
||||
border-color: #0d9488;
|
||||
}
|
||||
QPushButton#exportParametersButton:pressed {
|
||||
background: #99f6e4;
|
||||
border-color: #0f766e;
|
||||
padding-top: 7px;
|
||||
padding-bottom: 5px;
|
||||
}
|
||||
QPushButton#exportParametersButton:disabled {
|
||||
background: #eef2f6;
|
||||
border: 1px dashed #bcc7d4;
|
||||
color: #8f99a8;
|
||||
font-weight: 650;
|
||||
}
|
||||
QPushButton#propertyRowEditButton {
|
||||
background: #ea580c;
|
||||
border: 1px solid #c2410c;
|
||||
@@ -885,12 +911,13 @@ class StepEditorWindow(WindowCoreMixin, WindowStateMixin, WindowActionMixin, Inf
|
||||
self.open_button.setMinimumWidth(96)
|
||||
help_tip(self.open_button, "选择并导入一个 .step 或 .stp 几何模型。打开失败时会保留当前模型。")
|
||||
self.open_button.clicked.connect(self.open_step)
|
||||
self.path_label = QLineEdit(str(self.step_path))
|
||||
self.path_label = QLineEdit(str(self.step_path) if self.step_path is not None else "")
|
||||
self.path_label.setObjectName("stepPathDisplay")
|
||||
self.path_label.setReadOnly(True)
|
||||
self.path_label.setMinimumWidth(120)
|
||||
help_tip(self.path_label, "当前 STEP 文件的完整路径。可以选中文字复制路径。")
|
||||
self.path_label.setToolTip(str(self.step_path))
|
||||
self.path_label.setPlaceholderText("未选择 STEP 文件")
|
||||
self.path_label.setToolTip(str(self.step_path) if self.step_path is not None else "未选择 STEP 文件")
|
||||
self.path_label.setCursorPosition(0)
|
||||
self.reload_button = QPushButton("读取模型")
|
||||
self.reload_button.setMinimumWidth(78)
|
||||
@@ -1086,7 +1113,7 @@ class StepEditorWindow(WindowCoreMixin, WindowStateMixin, WindowActionMixin, Inf
|
||||
export_box.setObjectName("exportSection")
|
||||
help_tip(export_box, "把当前模型或选中对象导出为 STEP,也可以做基础质量检查和修复。")
|
||||
export_layout = QVBoxLayout(export_box)
|
||||
self.export_all_button = QPushButton("导出当前完整 STEP")
|
||||
self.export_all_button = QPushButton("导出模型")
|
||||
help_tip(self.export_all_button, "把当前编辑后的整个模型导出为 STEP 文件。导出前会做基础质量检查。")
|
||||
self.export_all_button.clicked.connect(self.export_all)
|
||||
self.export_part_button = QPushButton("导出选中零件")
|
||||
@@ -1132,9 +1159,9 @@ class StepEditorWindow(WindowCoreMixin, WindowStateMixin, WindowActionMixin, Inf
|
||||
object_edit_layout = QVBoxLayout(self.object_edit_box)
|
||||
object_edit_layout.setContentsMargins(0, 8, 0, 4)
|
||||
object_edit_layout.setSpacing(4)
|
||||
self.property_table = QTableWidget(0, 4, self.object_edit_box)
|
||||
self.property_table = QTableWidget(0, len(PROPERTY_TABLE_HEADERS), self.object_edit_box)
|
||||
self.property_table.setObjectName("propertyTable")
|
||||
self.property_table.setHorizontalHeaderLabels(["尺寸参数", "当前值", "建模意图", "目标值"])
|
||||
self.property_table.setHorizontalHeaderLabels(list(PROPERTY_TABLE_HEADERS))
|
||||
self.property_table.setSelectionBehavior(QAbstractItemView.SelectionBehavior.SelectRows)
|
||||
self.property_table.setSelectionMode(QAbstractItemView.SelectionMode.SingleSelection)
|
||||
self.property_table.setAlternatingRowColors(True)
|
||||
@@ -1153,11 +1180,12 @@ class StepEditorWindow(WindowCoreMixin, WindowStateMixin, WindowActionMixin, Inf
|
||||
property_header.setSectionResizeMode(1, QHeaderView.ResizeMode.Fixed)
|
||||
property_header.setSectionResizeMode(2, QHeaderView.ResizeMode.Fixed)
|
||||
property_header.setSectionResizeMode(3, QHeaderView.ResizeMode.Fixed)
|
||||
property_header.setSectionResizeMode(3, QHeaderView.ResizeMode.Stretch)
|
||||
self.property_table.setColumnWidth(0, 148)
|
||||
self.property_table.setColumnWidth(1, 92)
|
||||
self.property_table.setColumnWidth(2, 112)
|
||||
self.property_table.setColumnWidth(3, 96)
|
||||
property_header.setSectionResizeMode(4, QHeaderView.ResizeMode.Fixed)
|
||||
self.property_table.setColumnWidth(0, 112)
|
||||
self.property_table.setColumnWidth(1, 104)
|
||||
self.property_table.setColumnWidth(2, 88)
|
||||
self.property_table.setColumnWidth(3, 82)
|
||||
self.property_table.setColumnWidth(4, 66)
|
||||
self.property_table.installEventFilter(self)
|
||||
help_tip(
|
||||
self.property_table,
|
||||
@@ -1217,14 +1245,21 @@ class StepEditorWindow(WindowCoreMixin, WindowStateMixin, WindowActionMixin, Inf
|
||||
self.apply_property_button.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Fixed)
|
||||
help_tip(self.apply_property_button, "应用当前被修改的一个参数;一次只执行一个几何修改,成功后可撤销。")
|
||||
self.apply_property_button.clicked.connect(self.apply_current_property_edit)
|
||||
self.quick_export_all_button = QPushButton("导出当前完整STEP")
|
||||
self.quick_export_all_button = QPushButton("导出模型")
|
||||
self.quick_export_all_button.setObjectName("quickExportStepButton")
|
||||
self.quick_export_all_button.setMinimumHeight(34)
|
||||
self.quick_export_all_button.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Fixed)
|
||||
help_tip(self.quick_export_all_button, "把当前编辑后的完整模型导出为 STEP 文件。导出前会做基础质量检查。")
|
||||
self.quick_export_all_button.clicked.connect(self.export_all)
|
||||
self.export_parameters_button = QPushButton("导出参数")
|
||||
self.export_parameters_button.setObjectName("exportParametersButton")
|
||||
self.export_parameters_button.setMinimumHeight(34)
|
||||
self.export_parameters_button.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Fixed)
|
||||
help_tip(self.export_parameters_button, "把已勾选为输入参数的尺寸行导出为 data.json。")
|
||||
self.export_parameters_button.clicked.connect(self.export_selected_parameters)
|
||||
property_action_row.addWidget(self.apply_property_button)
|
||||
property_action_row.addWidget(self.quick_export_all_button)
|
||||
property_action_row.addWidget(self.export_parameters_button)
|
||||
object_edit_layout.addLayout(property_action_row)
|
||||
|
||||
edit_box = QGroupBox(panel)
|
||||
@@ -1741,10 +1776,10 @@ class StepEditorWindow(WindowCoreMixin, WindowStateMixin, WindowActionMixin, Inf
|
||||
|
||||
|
||||
|
||||
def _parse_args(argv: list[str]) -> tuple[Path, bool]:
|
||||
def _parse_args(argv: list[str]) -> tuple[Path | None, bool]:
|
||||
smoke_test = "--smoke-test" in argv
|
||||
paths = [arg for arg in argv[1:] if not arg.startswith("--")]
|
||||
path = Path(paths[0]) if paths else DEFAULT_MODEL_PATH
|
||||
path = Path(paths[0]) if paths else None
|
||||
return path, smoke_test
|
||||
|
||||
|
||||
@@ -1764,7 +1799,7 @@ def main() -> int:
|
||||
app.setApplicationDisplayName("几何参数化")
|
||||
app.setOrganizationName("GeometryParametric")
|
||||
app.setWindowIcon(_application_icon())
|
||||
window = StepEditorWindow(path, background_load=not smoke_test)
|
||||
window = StepEditorWindow(path, background_load=bool(path) and not smoke_test)
|
||||
if smoke_test:
|
||||
print("smoke test ok")
|
||||
window.close()
|
||||
|
||||
Reference in New Issue
Block a user