Skip to content

Commit

Permalink
SceneNode settings use native python types
Browse files Browse the repository at this point in the history
Only booleans for now.
  • Loading branch information
Piezoid committed Sep 6, 2022
1 parent 7f0a3fd commit 70d918a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 18 deletions.
4 changes: 2 additions & 2 deletions UM/Scene/SceneNode.py
Original file line number Diff line number Diff line change
Expand Up @@ -812,10 +812,10 @@ def setCalculateBoundingBox(self, calculate: bool) -> None:
def getShear(self) -> Vector:
return self._shear

def getSetting(self, key: str, default_value: str = "") -> str:
def getSetting(self, key: str, default_value: Any = None) -> Any:
return self._settings.get(key, default_value)

def setSetting(self, key: str, value: str) -> None:
def setSetting(self, key: str, value: Any) -> None:
self._settings[key] = value

def invertNormals(self) -> None:
Expand Down
13 changes: 6 additions & 7 deletions UM/Tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from UM.Scene.Selection import Selection
from UM.Scene.ToolHandle import ToolHandle
from UM.Signal import Signal, signalemitter
from UM.Util import parseBool
from UM.View.SelectionPass import SelectionPass


Expand Down Expand Up @@ -170,7 +169,7 @@ def getDragVector(self, x: float, y: float) -> Optional[Vector]:

return None

def setSettingToSelection(self, key: str, value: str) -> None:
def setSettingToSelection(self, key: str, value: bool) -> None:
"""Set a setting on all selected objects without ancestors
:param key: The name of the setting.
Expand All @@ -181,9 +180,9 @@ def setSettingToSelection(self, key: str, value: str) -> None:
selected_node.setSetting(key, value)
sceneChanged.emit(selected_node)

def getBoolSettingFromSelection(self, key: str, default: str="False") -> Union[str, bool]:
def getBoolSettingFromSelection(self, key: str, default: bool) -> Optional[bool]:
"""Get a boolean setting on selection.
Return True or False if all the selected object agree, "partially" otherwise.
Return True or False if all the selected object agree, None otherwise.
:param key: The name of the setting.
:param default: The default value when the setting is not set on the object.
Expand All @@ -192,10 +191,10 @@ def getBoolSettingFromSelection(self, key: str, default: str="False") -> Union[s
false_state_counter = 0
true_state_counter = 0
if not Selection.hasSelection():
return False
return default

for selected_node in self._getSelectedObjectsWithoutSelectedAncestors():
if parseBool(selected_node.getSetting(key, default)):
if selected_node.getSetting(key, default):
true_state_counter += 1
else:
false_state_counter += 1
Expand All @@ -205,7 +204,7 @@ def getBoolSettingFromSelection(self, key: str, default: str="False") -> Union[s
elif total_size == true_state_counter: # All settings values are Frue
return True
else:
return "partially" # At least one is True, but not all
return None # At least one is True, but not all

def _onToolEnabledChanged(self, tool_id: str, enabled: bool) -> None:
if tool_id == self._plugin_id:
Expand Down
16 changes: 8 additions & 8 deletions plugins/Tools/TranslateTool/TranslateTool.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,21 +207,21 @@ def setLockPosition(self, value: bool) -> None:
model movement on the build plate.
:param value: The setting state.
"""
self.setSettingToSelection(SceneNodeSettings.LockPosition, str(value))
self.setSettingToSelection(SceneNodeSettings.LockPosition, value)

def getLockPosition(self) -> Union[str, bool]:
return self.getBoolSettingFromSelection(SceneNodeSettings.LockPosition, "False")
def getLockPosition(self) -> Optional[bool]:
return self.getBoolSettingFromSelection(SceneNodeSettings.LockPosition, False)

def setAutoDropDown(self, value: bool) -> None:
"""Set auto drop down setting to the object. This setting will be used
to make the model flush with the build plate.
:param value: The setting state.
"""
self.setSettingToSelection(SceneNodeSettings.AutoDropDown, str(value))
self.setSettingToSelection(SceneNodeSettings.AutoDropDown, value)

def getAutoDropDown(self) -> Union[str, bool]:
def getAutoDropDown(self) -> Optional[bool]:
default = Application.getInstance().getPreferences().getValue("physics/automatic_drop_down")
return self.getBoolSettingFromSelection(SceneNodeSettings.AutoDropDown, str(default))
return self.getBoolSettingFromSelection(SceneNodeSettings.AutoDropDown, default)

def event(self, event: Event) -> bool:
"""Handle mouse and keyboard events.
Expand Down Expand Up @@ -325,12 +325,12 @@ def event(self, event: Event) -> bool:
if len(selected_nodes) > 1:
op = GroupedOperation()
for node in selected_nodes:
if node.getSetting(SceneNodeSettings.LockPosition, "False") == "False":
if node.getSetting(SceneNodeSettings.LockPosition, False) == False:
op.addOperation(TranslateOperation(node, drag))
op.push()
else:
for node in selected_nodes:
if node.getSetting(SceneNodeSettings.LockPosition, "False") == "False":
if node.getSetting(SceneNodeSettings.LockPosition, False) == False:
TranslateOperation(node, drag).push()

if not self._distance:
Expand Down
2 changes: 1 addition & 1 deletion plugins/Tools/TranslateTool/TranslateTool.qml
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ Item
if (value) {
return Qt.Checked
}
else if (value === "partially"){
else if (value === undefined){
return Qt.PartiallyChecked
}
else {
Expand Down

0 comments on commit 70d918a

Please sign in to comment.