Merge pull request #11722 from Roy-043/Draft-implement-new-get_param-functions-step-4

Draft: implement new get_param functions (step 4)
This commit is contained in:
Roy-043
2023-12-13 21:55:45 +01:00
committed by GitHub
8 changed files with 132 additions and 228 deletions

View File

@@ -47,14 +47,12 @@ import FreeCADGui
import Draft
import DraftVecUtils
import WorkingPlane
from draftutils import params
from draftutils import utils
from draftutils.todo import todo
from draftutils.translate import translate
from draftutils.units import display_external
_param_draft = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Draft")
_param_view = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/View")
translate("draft", "Relative")
translate("draft", "Global")
translate("draft", "Continue")
@@ -77,63 +75,8 @@ translate("draft", "Set Working Plane")
translate("draft", "Cycle snap object")
translate("draft", "Undo last segment")
def _get_incmd_shortcut_default(itm):
if itm == "Relative":
# isRelative
return "R"
if itm == "Global":
# isGlobal
return "G"
if itm == "Continue":
# continueCmd
return "T"
if itm == "Close":
# closeButton
return "O"
if itm == "Copy":
# isCopy
return "P"
if itm == "SubelementMode":
# isSubelementMode
return "D"
if itm == "Fill":
# hasFill
return "L"
if itm == "Exit":
# finishButton
return "A"
if itm == "Snap":
return "S"
if itm == "IncreaseRadius":
return "["
if itm == "DecreaseRadius":
return "]"
if itm == "RestrictX":
return "X"
if itm == "RestrictY":
return "Y"
if itm == "RestrictZ":
return "Z"
if itm == "SelectEdge":
return "E"
if itm == "AddHold":
return "Q"
if itm == "Length":
# lengthValue
return "H"
if itm == "Wipe":
# wipeButton
return "W"
if itm == "SetWP":
# orientWPButton
return "U"
if itm == "CycleSnap":
return "`"
if itm == "Undo":
return "/"
def _get_incmd_shortcut(itm):
return Draft.getParam("inCommandShortcut" + itm, _get_incmd_shortcut_default(itm)).upper()
return params.get_param("inCommandShortcut" + itm).upper()
#---------------------------------------------------------------------------
@@ -214,22 +157,20 @@ class DraftToolBar:
subcommands activation, continue mode, etc. from Task Panel Ui
"""
def __init__(self):
print("init")
self.tray = None
self.sourceCmd = None
self.cancel = None
self.pointcallback = None
# OBSOLETE BUT STILL USED BY SOME ADDONS AND MACROS
self.paramcolor = Draft.getParam("color",255)>>8
self.paramcolor = utils.rgba_to_argb(params.get_param_view("DefaultShapeLineColor"))
self.color = QtGui.QColor(self.paramcolor)
self.facecolor = _param_view.GetUnsigned("DefaultShapeColor",4294967295)>>8
self.linewidth = Draft.getParam("linewidth",2)
self.fontsize = Draft.getParam("textheight",0.20)
# ToDo: in setStyleButton() self.facecolor is assigned a QColor
self.facecolor = utils.rgba_to_argb(params.get_param_view("DefaultShapeColor"))
self.linewidth = params.get_param_view("DefaultShapeLineWidth")
self.fontsize = params.get_param("textheight")
self.paramconstr = Draft.getParam("constructioncolor",746455039)>>8
self.paramconstr = utils.rgba_to_argb(params.get_param("constructioncolor"))
self.constrMode = False
self.continueMode = False
self.relativeMode = True
@@ -282,15 +223,11 @@ class DraftToolBar:
def _pushbutton(self,name, layout, hide=True, icon=None,
width=None, checkable=False, square=False):
p = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/General")
bsize = p.GetInt("ToolbarIconSize",24)+2
isize = p.GetInt("ToolbarIconSize",24)/3*2
button = QtGui.QPushButton(self.baseWidget)
button.setObjectName(name)
if square:
button.setMaximumSize(QtCore.QSize(button.height(), button.height()))
button.setFlat(True)
#button.setMaximumSize(QtCore.QSize(width,bsize))
if hide:
button.hide()
if icon:
@@ -299,7 +236,6 @@ class DraftToolBar:
else:
button.setIcon(QtGui.QIcon.fromTheme(
icon, QtGui.QIcon(':/icons/'+icon+'.svg')))
#button.setIconSize(QtCore.QSize(isize, isize))
if checkable:
button.setCheckable(True)
button.setChecked(False)
@@ -316,8 +252,7 @@ class DraftToolBar:
return label
def _lineedit (self,name, layout, hide=True, width=None):
p = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/General")
bsize = p.GetInt("ToolbarIconSize",24)-2
bsize = params.get_param("ToolbarIconSize", path="General") - 2
lineedit = DraftLineEdit(self.baseWidget)
lineedit.setObjectName(name)
if hide: lineedit.hide()
@@ -344,8 +279,7 @@ class DraftToolBar:
hide=True, double=False, size=None):
if double:
sbox = QtGui.QDoubleSpinBox(self.baseWidget)
sbox.setDecimals(FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Units")\
.GetInt("Decimals",2))
sbox.setDecimals(params.get_param("Decimals", path="Units"))
else:
sbox = QtGui.QSpinBox(self.baseWidget)
sbox.setObjectName(name)
@@ -465,10 +399,10 @@ class DraftToolBar:
self.selectButton = self._pushbutton("selectButton", bl, icon='view-select')
# update modes from parameters:
self.continueMode = _param_draft.GetBool("ContinueMode", False)
self.relativeMode = _param_draft.GetBool("RelativeMode", True)
self.globalMode = _param_draft.GetBool("GlobalMode", False)
self.fillmode = _param_draft.GetBool("fillmode", True)
self.continueMode = params.get_param("ContinueMode")
self.relativeMode = params.get_param("RelativeMode")
self.globalMode = params.get_param("GlobalMode")
self.fillmode = params.get_param("fillmode")
# update checkboxes with parameters and internal modes:
self.continueCmd = self._checkbox("continueCmd", self.layout, checked=self.continueMode)
@@ -480,10 +414,10 @@ class DraftToolBar:
# self.isCopy is also updated in modUi ("CopyMode") and offsetUi ("OffsetCopyMode")
self.isCopy = self._checkbox("isCopy",
self.layout,
checked=_param_draft.GetBool("CopyMode", False))
checked=params.get_param("CopyMode"))
self.isSubelementMode = self._checkbox("isSubelementMode",
self.layout,
checked=_param_draft.GetBool("SubelementMode", False))
checked=params.get_param("SubelementMode"))
# update checkboxes without parameters and without internal modes:
self.occOffset = self._checkbox("occOffset", self.layout, checked=False)
@@ -697,7 +631,7 @@ class DraftToolBar:
self.checkLocal()
def setFocus(self,f=None):
if _param_draft.GetBool("focusOnLength",False) and self.lengthValue.isVisible():
if params.get_param("focusOnLength") and self.lengthValue.isVisible():
self.lengthValue.setFocus()
self.lengthValue.setSelection(0,self.number_length(self.lengthValue.text()))
elif self.angleLock.isVisible() and self.angleLock.isChecked():
@@ -762,7 +696,7 @@ class DraftToolBar:
self.pointUi(title, cancel, extra, getcoords, rel, icon)
self.xValue.setEnabled(True)
self.yValue.setEnabled(True)
if Draft.getParam("UsePartPrimitives",False):
if params.get_param("UsePartPrimitives"):
self.hasFill.setEnabled(False)
else:
self.hasFill.setEnabled(True)
@@ -826,7 +760,7 @@ class DraftToolBar:
types = get_label_types()
for s in types:
combo.addItem(translate("Draft", s), userData=s)
combo.setCurrentIndex(types.index(Draft.getParam("labeltype","Custom")))
combo.setCurrentIndex(types.index(params.get_param("labeltype")))
l.addWidget(combo)
QtCore.QObject.connect(combo,QtCore.SIGNAL("currentIndexChanged(int)"),callback)
self.pointUi(title=title, extra=w, icon="Draft_Label")
@@ -838,7 +772,7 @@ class DraftToolBar:
self.taskUi(translate("draft","Offset"), icon="Draft_Offset")
self.radiusUi()
self.isCopy.show()
self.isCopy.setChecked(_param_draft.GetBool("OffsetCopyMode",False))
self.isCopy.setChecked(params.get_param("OffsetCopyMode"))
self.occOffset.show()
self.labelRadius.setText(translate("draft","Distance"))
self.radiusValue.setToolTip(translate("draft", "Offset distance"))
@@ -917,7 +851,7 @@ class DraftToolBar:
self.makeDumbTask(on_close_call=self.finish)
def extUi(self):
if Draft.getParam("UsePartPrimitives",False):
if params.get_param("UsePartPrimitives"):
self.hasFill.setEnabled(False)
else:
self.hasFill.setEnabled(True)
@@ -927,7 +861,7 @@ class DraftToolBar:
def modUi(self):
self.isCopy.show()
self.isSubelementMode.show()
self.isCopy.setChecked(_param_draft.GetBool("CopyMode",False))
self.isCopy.setChecked(params.get_param("CopyMode"))
self.continueCmd.show()
def checkLocal(self):
@@ -998,7 +932,7 @@ class DraftToolBar:
#---------------------------------------------------------------------------
def setContinue(self, val):
_param_draft.SetBool("ContinueMode", bool(val))
params.set_param("ContinueMode", bool(val))
self.continueMode = bool(val)
# val=-1 is used to temporarily switch to relativeMode and disable the checkbox.
@@ -1016,35 +950,35 @@ class DraftToolBar:
self.isRelative.setChecked(True)
self.relativeMode = True
elif val == -2:
val = _param_draft.GetBool("RelativeMode", True)
val = params.get_param("RelativeMode")
self.isRelative.setChecked(val)
self.relativeMode = val
QtCore.QObject.connect(self.isRelative,
QtCore.SIGNAL("stateChanged(int)"),
self.setRelative)
else:
_param_draft.SetBool("RelativeMode", bool(val))
params.set_param("RelativeMode", bool(val))
self.relativeMode = bool(val)
self.checkLocal()
def setGlobal(self, val):
_param_draft.SetBool("GlobalMode", bool(val))
params.set_param("GlobalMode", bool(val))
self.globalMode = bool(val)
self.checkLocal()
def setFill(self, val):
_param_draft.SetBool("fillmode", bool(val))
params.set_param("fillmode", bool(val))
self.fillmode = bool(val)
def setCopymode(self, val):
# special value for offset command
if self.sourceCmd and self.sourceCmd.featureName == "Offset":
_param_draft.SetBool("OffsetCopyMode", bool(val))
params.set_param("OffsetCopyMode", bool(val))
else:
_param_draft.SetBool("CopyMode", bool(val))
params.set_param("CopyMode", bool(val))
def setSubelementMode(self, val):
_param_draft.SetBool("SubelementMode", bool(val))
params.set_param("SubelementMode", bool(val))
self.sourceCmd.set_ghosts()
def checkx(self):
@@ -1371,45 +1305,30 @@ class DraftToolBar:
self.setFocus()
def getDefaultColor(self,type,rgb=False):
def getDefaultColor(self, typ, rgb=False):
"""gets color from the preferences or toolbar"""
r = 0
g = 0
b = 0
if type == "snap":
color = Draft.getParam("snapcolor",4294967295)
r = ((color>>24)&0xFF)/255
g = ((color>>16)&0xFF)/255
b = ((color>>8)&0xFF)/255
elif type == "ui":
if typ == "snap":
r, g, b, _ = utils.get_rgba_tuple(params.get_param("snapcolor"))
elif typ == "ui":
print("draft: deprecation warning: Do not use getDefaultColor(\"ui\") anymore - use getDefaultColor(\"line\") instead.")
r = float(self.color.red()/255.0)
g = float(self.color.green()/255.0)
b = float(self.color.blue()/255.0)
elif type == "line":
color = _param_view.GetUnsigned("DefaultShapeLineColor",255)
r = ((color>>24)&0xFF)/255
g = ((color>>16)&0xFF)/255
b = ((color>>8)&0xFF)/255
elif type == "text":
color = _param_draft.GetUnsigned("DefaultTextColor",255)
r = ((color>>24)&0xFF)/255
g = ((color>>16)&0xFF)/255
b = ((color>>8)&0xFF)/255
elif type == "face":
color = _param_view.GetUnsigned("DefaultShapeColor",4294967295)
r = ((color>>24)&0xFF)/255
g = ((color>>16)&0xFF)/255
b = ((color>>8)&0xFF)/255
elif type == "constr":
color = Draft.getParam("constructioncolor",746455039)
r = ((color>>24)&0xFF)/255
g = ((color>>16)&0xFF)/255
b = ((color>>8)&0xFF)/255
r = float(self.color.red() / 255.0)
g = float(self.color.green() / 255.0)
b = float(self.color.blue() / 255.0)
elif typ == "line":
r, g, b, _ = utils.get_rgba_tuple(params.get_param_view("DefaultShapeLineColor"))
elif typ == "text":
r, g, b, _ = utils.get_rgba_tuple(params.get_param("DefaultTextColor"))
elif typ == "face":
r, g, b, _ = utils.get_rgba_tuple(params.get_param_view("DefaultShapeColor"))
elif typ == "constr":
r, g, b, _ = utils.get_rgba_tuple(params.get_param("constructioncolor"))
else:
print("draft: error: couldn't get a color for ",type," type.")
print("draft: error: couldn't get a color for ", typ, " typ.")
if rgb:
return("rgb("+str(int(r*255))+","+str(int(g*255))+","+str(int(b*255)) + ")")
return("rgb(" + str(int(r * 255)) + "," + str(int(g * 255)) + "," + str(int(b * 255)) + ")")
else:
return (r,g,b)
@@ -1455,8 +1374,8 @@ class DraftToolBar:
def setStyleButton(self):
"sets icon and text on the style button"
linecolor = QtGui.QColor(Draft.getParam("color",255)>>8)
facecolor = QtGui.QColor(_param_view.GetUnsigned( "DefaultShapeColor",4294967295)>>8)
linecolor = QtGui.QColor(utils.rgba_to_argb(params.get_param_view("DefaultShapeLineColor")))
facecolor = QtGui.QColor(utils.rgba_to_argb(params.get_param_view("DefaultShapeColor")))
im = QtGui.QImage(32,32,QtGui.QImage.Format_ARGB32)
im.fill(QtCore.Qt.transparent)
pt = QtGui.QPainter(im)
@@ -1469,8 +1388,8 @@ class DraftToolBar:
pt.drawPolygon(pts,QtCore.Qt.OddEvenFill)
pt.end()
icon = QtGui.QIcon(QtGui.QPixmap.fromImage(im))
linewidth = Draft.getParam("linewidth",2)
fontsize = Draft.getParam("textheight",0.20)
linewidth = params.get_param_view("DefaultShapeLineWidth")
fontsize = params.get_param("textheight")
txt = str(linewidth) + "px | "\
+ FreeCAD.Units.Quantity(fontsize,FreeCAD.Units.Length).UserString
self.styleButton.setIcon(icon)
@@ -1555,8 +1474,8 @@ class DraftToolBar:
def toggleradius(self,val):
if hasattr(FreeCADGui,"Snapper"):
par = Draft.getParam("snapRange", 8)
Draft.setParam("snapRange", max(0, par+val))
par = params.get_param("snapRange")
params.set_param("snapRange", max(0, par+val))
FreeCADGui.Snapper.showradius()
def constrain(self,val):

View File

@@ -38,14 +38,13 @@ import math
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
# @{
@@ -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="?"):

View File

@@ -42,6 +42,7 @@ import FreeCAD
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
@@ -1454,7 +1455,7 @@ class PlaneGui(PlaneBase):
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:

View File

@@ -349,6 +349,8 @@ 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),
@@ -356,6 +358,7 @@ def _get_param_dictionary():
"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),
@@ -363,13 +366,16 @@ def _get_param_dictionary():
"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),
@@ -378,13 +384,15 @@ 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),
@@ -392,9 +400,15 @@ def _get_param_dictionary():
"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),

View File

@@ -42,6 +42,7 @@ https://knowledge.autodesk.com/support/autocad/downloads/
import FreeCAD
from FreeCAD import Console as FCC
from draftutils import params
if FreeCAD.GuiUp:
from draftutils.translate import translate
@@ -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:
@@ -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):
@@ -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
@@ -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"
@@ -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")

View File

@@ -61,9 +61,11 @@ import Mesh
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
@@ -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']
@@ -147,7 +148,7 @@ To enabled FreeCAD to download these libraries, answer Yes.""")
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
@@ -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:
@@ -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)
@@ -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)
@@ -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:
@@ -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
@@ -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)
@@ -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
@@ -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")

View File

@@ -44,6 +44,7 @@ __url__ = "https://www.freecad.org"
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
@@ -55,8 +56,6 @@ else:
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.
@@ -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)

View File

@@ -57,8 +57,10 @@ import FreeCAD
import Draft
import DraftVecUtils
from FreeCAD import Vector
from draftutils import params
from draftutils import utils
from draftutils.translate import translate
from draftutils.messages import _msg, _wrn, _err
from draftutils.messages import _err, _msg, _wrn
if FreeCAD.GuiUp:
from PySide import QtGui
@@ -655,11 +657,8 @@ class svgHandler(xml.sax.ContentHandler):
def __init__(self):
super().__init__()
"""Retrieve Draft parameters and initialize."""
_prefs = "User parameter:BaseApp/Preferences/Mod/Draft"
params = FreeCAD.ParamGet(_prefs)
self.style = params.GetInt("svgstyle")
self.disableUnitScaling = params.GetBool("svgDisableUnitScaling",
False)
self.style = params.get_param("svgstyle")
self.disableUnitScaling = params.get_param("svgDisableUnitScaling")
self.count = 0
self.transform = None
self.grouptransform = []
@@ -674,16 +673,13 @@ class svgHandler(xml.sax.ContentHandler):
import Part
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)
self.lw = float(draftui.linewidth)
else:
self.lw = float(params.GetInt("linewidth"))
c = params.GetUnsigned("color")
r = float(((c >> 24) & 0xFF)/255)
g = float(((c >> 16) & 0xFF)/255)
b = float(((c >> 8) & 0xFF)/255)
self.lw = float(params.get_param_view("DefaultShapeLineWidth"))
r, g, b, _ = utils.get_rgba_tuple(params.get_param_view("DefaultShapeLineColor"))
self.col = (r, g, b, 0.0)
def format(self, obj):
@@ -1812,8 +1808,7 @@ def export(exportList, filename):
None
If `exportList` doesn't have shapes to export.
"""
_prefs = "User parameter:BaseApp/Preferences/Mod/Draft"
svg_export_style = FreeCAD.ParamGet(_prefs).GetInt("svg_export_style")
svg_export_style = params.get_param("svg_export_style")
if svg_export_style != 0 and svg_export_style != 1:
_msg(translate("ImportSVG",
"Unknown SVG export style, switching to Translated"))