|
1 | 1 | # Copyright (c) 2023 Erwan MATHIEU |
2 | 2 |
|
3 | | -from typing import TYPE_CHECKING, List |
| 3 | +from typing import TYPE_CHECKING, List, Dict |
4 | 4 |
|
5 | 5 | import os |
6 | 6 | import math |
@@ -34,8 +34,10 @@ def __init__(self, auth_controller: "OAuthController", api: "OnshapeApi"): |
34 | 34 | self._logged_in: bool = False |
35 | 35 | self._documents_model: DocumentsModel = DocumentsModel(DocumentsTreeNode(Root()), self._api, []) |
36 | 36 | self._temp_files: List[str] = [] |
| 37 | + self._parts_names: Dict[str, str] = {} |
37 | 38 |
|
38 | 39 | CuraApplication.getInstance().fileLoaded.connect(self._onFileLoaded) |
| 40 | + CuraApplication.getInstance().getController().getScene().sceneChanged.connect(self._onSceneChanged) |
39 | 41 |
|
40 | 42 | loggedInChanged = pyqtSignal() |
41 | 43 |
|
@@ -69,13 +71,27 @@ def _onFileLoaded(self, file_path: str) -> None: |
69 | 71 | self._temp_files.remove(file_path) |
70 | 72 | print("File removed ", file_path) |
71 | 73 |
|
| 74 | + def _onSceneChanged(self, *args) -> None: |
| 75 | + for changed_node in args: |
| 76 | + if changed_node.callDecoration("isSliceable"): |
| 77 | + actual_name = changed_node.getName() |
| 78 | + if actual_name in self._parts_names: |
| 79 | + changed_node.setName(self._parts_names[actual_name]) |
| 80 | + self._parts_names.remove(actual_name) |
| 81 | + |
72 | 82 | @staticmethod |
73 | 83 | def _onMeshDownloadProgress(message: Message, transmitted: int, total: int) -> None: |
74 | 84 | message.setProgress(math.floor(transmitted * 100.0 / total)) |
75 | 85 |
|
76 | | - def _onMeshDownloaded(self, message: Message, file_path: str): |
| 86 | + def _onMeshDownloaded(self, message: Message, part_name: str, file_path: str): |
77 | 87 | message.hide() |
| 88 | + |
| 89 | + # Save file name to delete the temp file once it has been loaded |
78 | 90 | self._temp_files.append(file_path) |
| 91 | + |
| 92 | + # Save part name to set it once the scene node has been created |
| 93 | + self._parts_names[os.path.basename(file_path)] = part_name |
| 94 | + |
79 | 95 | CuraApplication.getInstance().readLocalFile(QUrl.fromLocalFile(file_path), add_to_recent_files = False) |
80 | 96 |
|
81 | 97 | @staticmethod |
@@ -111,7 +127,7 @@ def addToBuildPlate(self, items: List["DocumentsItem"], grouped: bool): |
111 | 127 | first_element.tab_id, |
112 | 128 | [element.id for element in elements], |
113 | 129 | functools.partial(OnshapeController._onMeshDownloadProgress, message), |
114 | | - functools.partial(self._onMeshDownloaded, message), |
| 130 | + functools.partial(self._onMeshDownloaded, message, first_element.name), |
115 | 131 | functools.partial(OnshapeController._onMeshDownloadError, message)) |
116 | 132 |
|
117 | 133 | print_information = CuraApplication.getInstance().getPrintInformation() |
|
0 commit comments