Draft: implement new get_param functions (step 5)

See #11677

Last bits...
This commit is contained in:
Roy-043
2023-12-14 12:28:32 +01:00
committed by Yorik van Havre
parent cba09aac50
commit c2e16f2525
3 changed files with 18 additions and 11 deletions

View File

@@ -1601,8 +1601,7 @@ class PlaneGui(PlaneBase):
"""Align the view to the WP."""
if self._view is not None:
try:
param = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/View")
default_cam_dist = abs(param.GetFloat("NewDocumentCameraScale", 100.0))
default_cam_dist = abs(params.get_param_view("NewDocumentCameraScale"))
cam = self._view.getCameraNode()
cur_cam_dist = abs(self.get_local_coords(Vector(cam.position.getValue().getValue())).z)
cam_dist = max(default_cam_dist, cur_cam_dist)
@@ -1678,7 +1677,7 @@ class PlaneGui(PlaneBase):
return FreeCAD.Units.Quantity(coord, FreeCAD.Units.Length).UserString
def _format_vector(self, vec):
dec = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Units").GetInt("Decimals", 2)
dec = params.get_param("Decimals", path="Units")
return f"({vec.x:.{dec}f} {vec.y:.{dec}f} {vec.z:.{dec}f})"
def _update_all(self, _hist_add=True):

View File

@@ -45,7 +45,6 @@ from draftguitools import gui_base_original
from draftguitools import gui_tool_utils
from draftguitools import gui_trackers as trackers
from draftutils import params
from draftutils import utils
from draftutils.messages import _toolmsg
from draftutils.translate import translate
@@ -84,7 +83,7 @@ class Label(gui_base_original.Creator):
"""Set the type of label, if it is associated to an object."""
from draftobjects.label import get_label_types
self.labeltype = get_label_types()[i]
utils.setParam("labeltype", self.labeltype)
params.set_param("labeltype", self.labeltype)
def finish(self, cont=False):
"""Finish the command."""

View File

@@ -150,7 +150,7 @@ def _param_observer_callback_snapcolor():
def _param_observer_callback_svg_pattern():
# imports have to happen here to avoid circular imports
from draftutils import utils
from draftutils import utils
from draftviewproviders import view_base
utils.load_svg_patterns()
if App.ActiveDocument is None:
@@ -264,7 +264,7 @@ def _param_from_PrefDoubleSpinBox(widget):
for elem in list(widget):
if "name" in elem.keys():
att_name = elem.attrib["name"]
if att_name == "value": # Can be missing.
if att_name == "value": # Can be missing.
value = float(elem.find("double").text)
elif att_name == "prefEntry":
entry = elem.find("cstring").text
@@ -274,7 +274,17 @@ def _param_from_PrefDoubleSpinBox(widget):
def _param_from_PrefUnitSpinBox(widget):
return _param_from_PrefDoubleSpinBox(widget)
value = 0.0
for elem in list(widget):
if "name" in elem.keys():
att_name = elem.attrib["name"]
if att_name == "rawValue": # Can be missing.
value = float(elem.find("double").text)
elif att_name == "prefEntry":
entry = elem.find("cstring").text
elif att_name == "prefPath":
path = elem.find("cstring").text
return path, entry, value
def _param_from_PrefQuantitySpinBox(widget):
@@ -282,7 +292,7 @@ def _param_from_PrefQuantitySpinBox(widget):
for elem in list(widget):
if "name" in elem.keys():
att_name = elem.attrib["name"]
if att_name == "rawValue": # Not sure if this can be missing.
if att_name == "rawValue": # Can be missing.
value = elem.find("double").text.rstrip(".0")
elif att_name == "unit":
unit = elem.find("string").text
@@ -378,8 +388,6 @@ def _get_param_dictionary():
"SubelementMode": ("bool", False),
"SvgLinesBlack": ("bool", True),
"useSupport": ("bool", False),
}
# Arch parameters that are not in the preferences:
@@ -402,6 +410,7 @@ def _get_param_dictionary():
"EnableSelection": ("bool", True),
"Gradient": ("bool", True),
"MarkerSize": ("int", 9),
"NewDocumentCameraScale": ("float", 100.0),
}
# For the General parameters we do not check the preferences: