Skip to content

Commit

Permalink
Merge pull request FreeCAD#11722 from Roy-043/Draft-implement-new-get…
Browse files Browse the repository at this point in the history
…_param-functions-step-4

Draft: implement new get_param functions (step 4)
  • Loading branch information
Roy-043 authored Dec 13, 2023
2 parents 77305e2 + d0a87b2 commit e8ada53
Show file tree
Hide file tree
Showing 8 changed files with 132 additions and 228 deletions.
189 changes: 54 additions & 135 deletions src/Mod/Draft/DraftGui.py

Large diffs are not rendered by default.

7 changes: 3 additions & 4 deletions src/Mod/Draft/DraftVecUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,13 @@

import FreeCAD
from FreeCAD import Vector
import draftutils.messages as messages
from draftutils import params
from draftutils import messages

__title__ = "FreeCAD Draft Workbench - Vector library"
__author__ = "Yorik van Havre, Werner Mayer, Martin Burbaum, Ken Cline"
__url__ = "https://www.freecad.org"

params = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Draft")

## \addtogroup DRAFTVECUTILS
# @{

Expand All @@ -59,7 +58,7 @@ def precision():
Return the number of decimal places set up in the preferences,
or a standard value (6), if the parameter is missing.
"""
return params.GetInt("precision", 6)
return params.get_param("precision")


def typecheck(args_and_types, name="?"):
Expand Down
3 changes: 2 additions & 1 deletion src/Mod/Draft/WorkingPlane.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import DraftVecUtils
from FreeCAD import Vector
from draftutils import gui_utils
from draftutils import params
from draftutils import utils
from draftutils.messages import _wrn
from draftutils.translate import translate
Expand Down Expand Up @@ -1454,7 +1455,7 @@ def auto_align(self):

def set_to_default(self):
"""Set the WP to the default from the preferences."""
default_wp = utils.get_param("defaultWP", 0)
default_wp = params.get_param("defaultWP")
if default_wp == 0:
self.set_to_auto()
elif default_wp == 1:
Expand Down
16 changes: 15 additions & 1 deletion src/Mod/Draft/draftutils/params.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,27 +349,33 @@ def _get_param_dictionary():
"AnnotationStyleEditorHeight": ("int", 450),
"AnnotationStyleEditorWidth": ("int", 450),
"CenterPlaneOnView": ("bool", False),
"ContinueMode": ("bool", False),
"CopyMode": ("bool", False),
"DefaultAnnoDisplayMode": ("int", 0),
"DefaultDisplayMode": ("int", 0),
"DefaultDrawStyle": ("int", 0),
"DefaultPrintColor": ("unsigned", 255),
"Draft_array_fuse": ("bool", False),
"Draft_array_Link": ("bool", True),
"fillmode": ("bool", True),
"GlobalMode": ("bool", False),
"HatchPatternResolution": ("int", 128),
"HatchPatternRotation": ("float", 0.0),
"HatchPatternScale": ("float", 100.0),
"labeltype": ("string", "Custom"),
"LayersManagerHeight": ("int", 320),
"LayersManagerWidth": ("int", 640),
"maxSnapEdges": ("int", 0),
"OffsetCopyMode": ("bool", False),
"Offset_OCC": ("bool", False),
"RelativeMode": ("bool", True),
"ScaleClone": ("bool", False),
"ScaleCopy": ("bool", False),
"ScaleRelative": ("bool", False),
"ScaleUniform": ("bool", False),
"snapModes": ("string", "100000000000000"),
"snapRange": ("int", 8),
"SubelementMode": ("bool", False),
"SvgLinesBlack": ("bool", True),
"useSupport": ("bool", False),

Expand All @@ -378,23 +384,31 @@ def _get_param_dictionary():

# Arch parameters that are not in the preferences:
param_dict["Mod/Arch"] = {
"ColorHelpers": ("unsigned", 674321151),


}

# For the View parameters we do not check the preferences:
param_dict["View"] = {
"BackgroundColor": ("unsigned", 336897023),
"BackgroundColor2": ("unsigned", 859006463),
"BackgroundColor3": ("unsigned", 2543299327),
"DefaultShapeColor": ("unsigned", 3435973887),
"DefaultShapeLineColor": ("unsigned", 421075455),
"DefaultShapeLineWidth": ("int", 2),
"DefaultShapePointSize": ("int", 2),
"DefaultShapeTransparency": ("int", 0),
"DefaultShapeVertexColor": ("unsigned", 421075455),
"EnableSelection": ("bool", True),
"Gradient": ("bool", True),
"MarkerSize": ("int", 9),
}

# For the General parameters we do not check the preferences:
param_dict["General"] = {
"ToolbarIconSize": ("int", 24),
}

# For the Units parameters we do not check the preferences:
param_dict["Units"] = {
"Decimals": ("int", 2),
Expand Down
16 changes: 6 additions & 10 deletions src/Mod/Draft/importDWG.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@

import FreeCAD
from FreeCAD import Console as FCC
from draftutils import params

if FreeCAD.GuiUp:
from draftutils.translate import translate
Expand Down Expand Up @@ -153,8 +154,7 @@ def get_libredwg_converter(typ):
import os
import platform

p = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Draft")
path = p.GetString("TeighaFileConverter")
path = params.get_param("TeighaFileConverter")

if "dwg2dxf" in path or "dxf2dwg" in path: # path set manually
if typ not in path:
Expand Down Expand Up @@ -192,8 +192,7 @@ def get_oda_converter():
import os
import platform

p = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Draft")
path = p.GetString("TeighaFileConverter")
path = params.get_param("TeighaFileConverter")

if "ODAFileConverter" in path: # path set manually
if os.path.exists(path) and os.path.isfile(path):
Expand Down Expand Up @@ -234,8 +233,7 @@ def get_qcad_converter():
import os
import platform

p = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Draft")
path = p.GetString("TeighaFileConverter")
path = params.get_param("TeighaFileConverter")

if "dwg2dwg" in path: # path set manually
pass
Expand Down Expand Up @@ -277,8 +275,7 @@ def convertToDxf(dwgfilename):
import tempfile

dwgfilename = dwgfilename.replace("\\", "/")
p = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Draft")
conv = p.GetInt("DWGConversion", 0)
conv = params.get_param("DWGConversion")
error_msg = translate("draft", """Error during DWG conversion.
Try moving the DWG file to a directory path without spaces and non-english characters,
or try saving to a lower DWG version.""") + "\n"
Expand Down Expand Up @@ -367,8 +364,7 @@ def convertToDwg(dxffilename, dwgfilename):

dxffilename = dxffilename.replace("\\", "/")
dwgfilename = dwgfilename.replace("\\", "/")
p = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Draft")
conv = p.GetInt("DWGConversion", 0)
conv = params.get_param("DWGConversion")

if conv in [0, 1]: # LibreDWG
libredwg = get_libredwg_converter("dxf2dwg")
Expand Down
97 changes: 39 additions & 58 deletions src/Mod/Draft/importDXF.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,11 @@
import DraftVecUtils
import DraftGeomUtils
import WorkingPlane
from Draft import _Dimension
from FreeCAD import Vector
from FreeCAD import Console as FCC
from Draft import LinearDimension
from draftutils import params
from draftutils import utils

gui = FreeCAD.GuiUp
draftui = None
Expand Down Expand Up @@ -105,8 +107,7 @@ def errorDXFLib(gui):
-----
Use local variables, not global variables.
"""
p = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Draft")
dxfAllowDownload = p.GetBool("dxfAllowDownload", False)
dxfAllowDownload = params.get_param("dxfAllowDownload")
if dxfAllowDownload:
files = ['dxfColorMap.py', 'dxfImportObjects.py',
'dxfLibrary.py', 'dxfReader.py']
Expand Down Expand Up @@ -147,7 +148,7 @@ def errorDXFLib(gui):
QtGui.QMessageBox.Yes | QtGui.QMessageBox.No,
QtGui.QMessageBox.No)
if reply == QtGui.QMessageBox.Yes:
p.SetBool("dxfAllowDownload", True)
params.set_param("dxfAllowDownload", True)
errorDXFLib(gui)
if reply == QtGui.QMessageBox.No:
pass
Expand Down Expand Up @@ -534,26 +535,16 @@ def isBrightBackground():
which is considered light; otherwise it is considered dark
and returns `False`.
"""
p = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/View")
if p.GetBool("Gradient"):
c1 = p.GetUnsigned("BackgroundColor2")
c2 = p.GetUnsigned("BackgroundColor3")
r1 = float((c1 >> 24) & 0xFF)
g1 = float((c1 >> 16) & 0xFF)
b1 = float((c1 >> 8) & 0xFF)
r2 = float((c2 >> 24) & 0xFF)
g2 = float((c2 >> 16) & 0xFF)
b2 = float((c2 >> 8) & 0xFF)
if params.get_param_view("Gradient"):
r1, g1, b1, _ = utils.get_rgba_tuple(params.get_param_view("BackgroundColor2"))
r2, g2, b2, _ = utils.get_rgba_tuple(params.get_param_view("BackgroundColor3"))
v1 = Vector(r1, g1, b1)
v2 = Vector(r2, g2, b2)
v = v2.sub(v1)
v.multiply(0.5)
cv = v1.add(v)
else:
c1 = p.GetUnsigned("BackgroundColor")
r1 = float((c1 >> 24) & 0xFF)
g1 = float((c1 >> 16) & 0xFF)
b1 = float((c1 >> 8) & 0xFF)
r1, g1, b1, _ = utils.get_rgba_tuple(params.get_param_view("BackgroundColor"))
cv = Vector(r1, g1, b1)
value = cv.x*.3 + cv.y*.59 + cv.z*.11
if value < 128:
Expand Down Expand Up @@ -623,16 +614,12 @@ def getColor():
of the `DefaultShapeLineColor` in the parameter database.
"""
if gui and draftui:
r = float(draftui.color.red()/255.0)
g = float(draftui.color.green()/255.0)
b = float(draftui.color.blue()/255.0)
r = float(draftui.color.red() / 255.0)
g = float(draftui.color.green() / 255.0)
b = float(draftui.color.blue() / 255.0)
return (r, g, b, 0.0)
else:
p = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/View")
c = p.GetUnsigned("DefaultShapeLineColor", 0)
r = float(((c >> 24) & 0xFF)/255)
g = float(((c >> 16) & 0xFF)/255)
b = float(((c >> 8) & 0xFF)/255)
r, g, b, _ = utils.get_rgba_tuple(params.get_param_view("DefaultShapeLineColor"))
return (r, g, b, 0.0)


Expand Down Expand Up @@ -3026,8 +3013,7 @@ def getSplineSegs(edge):
If the `segmentlength` variable is zero in the parameters database,
then it only returns the first and the last point of the `edge`.
"""
params = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Draft")
seglength = params.GetFloat("maxsegmentlength", 5.0)
seglength = params.get_param("maxsegmentlength")
points = []
if seglength == 0:
points.append(edge.Vertexes[0].Point)
Expand Down Expand Up @@ -3333,7 +3319,7 @@ def writeShape(sh, ob, dxfobject, nospline=False, lwPoly=False,
color=getACI(ob),
layer=layer))
elif DraftGeomUtils.geomType(edge) == "Ellipse": # ellipses:
if FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Draft").GetBool("DiscretizeEllipses", True):
if params.get_param("DiscretizeEllipses"):
points = []
spline = getSplineSegs(edge)
for p in spline:
Expand Down Expand Up @@ -3637,7 +3623,7 @@ def export(objectslist, filename, nospline=False, lwPoly=False):
dxf = dxfLibrary.Drawing()
# add global variables
if hasattr(dxf,"header"):
dxf.header.append(" 9\n$DIMTXT\n 40\n"+str(Draft.getParam("textheight", 20))+"\n")
dxf.header.append(" 9\n$DIMTXT\n 40\n" + str(params.get_param("textheight")) + "\n")
dxf.header.append(" 9\n$INSUNITS\n 70\n4\n")
for ob in exportLayers:
if ob.Label != "0": # dxflibrary already creates it
Expand Down Expand Up @@ -3760,11 +3746,11 @@ def export(objectslist, filename, nospline=False, lwPoly=False):
if hasattr(ob, "Tessellation"):
if ob.Tessellation:
tess = [ob.Tessellation, ob.SegmentLength]
if FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Draft").GetBool("dxfmesh"):
if params.get_param("dxfmesh"):
sh = None
if not ob.Shape.isNull():
writeMesh(ob, dxf)
elif gui and FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Draft").GetBool("dxfproject"):
elif gui and params.get_param("dxfproject"):
_view = FreeCADGui.ActiveDocument.ActiveView
direction = _view.getViewDirection().multiply(-1)
sh = projectShape(ob.Shape, direction, tess)
Expand Down Expand Up @@ -4118,17 +4104,12 @@ def readPreferences():
The parameter path is ``User parameter:BaseApp/Preferences/Mod/Draft``
See also
--------
FreeCAD.ParamGet, FreeCAD.ParamGet.GetBool
To do
-----
Use local variables, not global variables.
"""
# reading parameters
p = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Draft")
if gui and p.GetBool("dxfShowDialog", False):
if gui and params.get_param("dxfShowDialog"):
FreeCADGui.showPreferences("Import-Export", 3)
global dxfCreatePart, dxfCreateDraft, dxfCreateSketch
global dxfDiscretizeCurves, dxfStarBlocks
Expand All @@ -4139,25 +4120,25 @@ def readPreferences():
global dxfFillMode, dxfBrightBackground, dxfDefaultColor
global dxfUseLegacyImporter, dxfExportBlocks, dxfScaling
global dxfUseLegacyExporter
dxfCreatePart = p.GetBool("dxfCreatePart", True)
dxfCreateDraft = p.GetBool("dxfCreateDraft", False)
dxfCreateSketch = p.GetBool("dxfCreateSketch", False)
dxfDiscretizeCurves = p.GetBool("DiscretizeEllipses", True)
dxfStarBlocks = p.GetBool("dxfstarblocks", False)
dxfMakeBlocks = p.GetBool("groupLayers", False)
dxfJoin = p.GetBool("joingeometry", False)
dxfRenderPolylineWidth = p.GetBool("renderPolylineWidth", False)
dxfImportTexts = p.GetBool("dxftext", False)
dxfImportLayouts = p.GetBool("dxflayouts", False)
dxfImportPoints = p.GetBool("dxfImportPoints", False)
dxfImportHatches = p.GetBool("importDxfHatches", False)
dxfUseStandardSize = p.GetBool("dxfStdSize", False)
dxfGetColors = p.GetBool("dxfGetOriginalColors", False)
dxfUseDraftVisGroups = p.GetBool("dxfUseDraftVisGroups", True)
dxfFillMode = p.GetBool("fillmode", True)
dxfUseLegacyImporter = p.GetBool("dxfUseLegacyImporter", False)
dxfUseLegacyExporter = p.GetBool("dxfUseLegacyExporter", False)
dxfCreatePart = params.get_param("dxfCreatePart")
dxfCreateDraft = params.get_param("dxfCreateDraft")
dxfCreateSketch = params.get_param("dxfCreateSketch")
dxfDiscretizeCurves = params.get_param("DiscretizeEllipses")
dxfStarBlocks = params.get_param("dxfstarblocks")
dxfMakeBlocks = params.get_param("groupLayers")
dxfJoin = params.get_param("joingeometry")
dxfRenderPolylineWidth = params.get_param("renderPolylineWidth")
dxfImportTexts = params.get_param("dxftext")
dxfImportLayouts = params.get_param("dxflayout")
dxfImportPoints = params.get_param("dxfImportPoints")
dxfImportHatches = params.get_param("importDxfHatches")
dxfUseStandardSize = params.get_param("dxfStdSize")
dxfGetColors = params.get_param("dxfGetOriginalColors")
dxfUseDraftVisGroups = params.get_param("dxfUseDraftVisGroups")
dxfFillMode = params.get_param("fillmode")
dxfUseLegacyImporter = params.get_param("dxfUseLegacyImporter")
dxfUseLegacyExporter = params.get_param("dxfUseLegacyExporter")
dxfBrightBackground = isBrightBackground()
dxfDefaultColor = getColor()
dxfExportBlocks = p.GetBool("dxfExportBlocks", True)
dxfScaling = p.GetFloat("dxfScaling", 1.0)
dxfExportBlocks = params.get_param("dxfExportBlocks")
dxfScaling = params.get_param("dxfScaling")
5 changes: 2 additions & 3 deletions src/Mod/Draft/importOCA.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import FreeCAD, os, Part, DraftVecUtils, DraftGeomUtils
from FreeCAD import Vector
from FreeCAD import Console as FCC
from draftutils import params

if FreeCAD.GuiUp:
from draftutils.translate import translate
Expand All @@ -55,8 +56,6 @@ def translate(context, txt):
if open.__module__ in ['__builtin__', 'io']:
pythonopen = open

params = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Draft")


def getpoint(data):
"""Turn an OCA point definition into a FreeCAD.Vector.
Expand Down Expand Up @@ -306,7 +305,7 @@ def parse(filename, doc):
if _id[0] == "P":
# point
objects[_id] = getpoint(data)
elif ((_id[0] == "A") and params.GetBool("ocaareas")):
elif ((_id[0] == "A") and params.get_param("ocaareas")):
# area
objects[_id] = getarea(data)
createobject(_id, doc)
Expand Down
Loading

0 comments on commit e8ada53

Please sign in to comment.