Skip to content

Commit 458ba6d

Browse files
committed
Set the proper part name on the object
1 parent 2655421 commit 458ba6d

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

src/OnshapeController.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Copyright (c) 2023 Erwan MATHIEU
22

3-
from typing import TYPE_CHECKING, List
3+
from typing import TYPE_CHECKING, List, Dict
44

55
import os
66
import math
@@ -34,8 +34,10 @@ def __init__(self, auth_controller: "OAuthController", api: "OnshapeApi"):
3434
self._logged_in: bool = False
3535
self._documents_model: DocumentsModel = DocumentsModel(DocumentsTreeNode(Root()), self._api, [])
3636
self._temp_files: List[str] = []
37+
self._parts_names: Dict[str, str] = {}
3738

3839
CuraApplication.getInstance().fileLoaded.connect(self._onFileLoaded)
40+
CuraApplication.getInstance().getController().getScene().sceneChanged.connect(self._onSceneChanged)
3941

4042
loggedInChanged = pyqtSignal()
4143

@@ -69,13 +71,27 @@ def _onFileLoaded(self, file_path: str) -> None:
6971
self._temp_files.remove(file_path)
7072
print("File removed ", file_path)
7173

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+
7282
@staticmethod
7383
def _onMeshDownloadProgress(message: Message, transmitted: int, total: int) -> None:
7484
message.setProgress(math.floor(transmitted * 100.0 / total))
7585

76-
def _onMeshDownloaded(self, message: Message, file_path: str):
86+
def _onMeshDownloaded(self, message: Message, part_name: str, file_path: str):
7787
message.hide()
88+
89+
# Save file name to delete the temp file once it has been loaded
7890
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+
7995
CuraApplication.getInstance().readLocalFile(QUrl.fromLocalFile(file_path), add_to_recent_files = False)
8096

8197
@staticmethod
@@ -111,7 +127,7 @@ def addToBuildPlate(self, items: List["DocumentsItem"], grouped: bool):
111127
first_element.tab_id,
112128
[element.id for element in elements],
113129
functools.partial(OnshapeController._onMeshDownloadProgress, message),
114-
functools.partial(self._onMeshDownloaded, message),
130+
functools.partial(self._onMeshDownloaded, message, first_element.name),
115131
functools.partial(OnshapeController._onMeshDownloadError, message))
116132

117133
print_information = CuraApplication.getInstance().getPrintInformation()

0 commit comments

Comments
 (0)