diff --git a/src/Mod/Draft/Resources/ui/TaskPanel_SetStyle.ui b/src/Mod/Draft/Resources/ui/TaskPanel_SetStyle.ui index ec0ca1d091..8cd8416281 100644 --- a/src/Mod/Draft/Resources/ui/TaskPanel_SetStyle.ui +++ b/src/Mod/Draft/Resources/ui/TaskPanel_SetStyle.ui @@ -19,7 +19,7 @@ - Fills the values below with a stored style preset + Fill the values below from a stored style preset @@ -37,7 +37,7 @@ - Save current style as a preset... + Save the current style as a preset... @@ -53,52 +53,99 @@ - Lines and faces + Shapes QLayout::SetDefaultConstraint - + + + Shape color + + + + + + + + + + + Transparency + + + + + + + % + + + 100 + + + + + Line color - + - - The color of lines - - - + + Line width - + px - - + + + + Point color + + + + + + + + + + + Point size + + + + + + + px + + + + + Draw style - + - - The line style - Solid @@ -121,33 +168,30 @@ - - + + Display mode - + - - The display mode for faces - Flat Lines - - - Wireframe - - Shaded + + + Wireframe + + Points @@ -155,40 +199,6 @@ - - - - Shape color - - - - - - - The color of faces - - - - - - - Transparency - - - - - - - The transparency of faces - - - % - - - 100 - - - @@ -197,53 +207,29 @@ Annotations - - - - - The size of texts and dimension texts - - - - - - - - - - The color of texts and dimension texts - - - + - - - Text font - - - - - - - Text size - - - - - - - Line spacing - - - - - + Text color + + + The color for texts, dimension texts and label texts + + + + + + + Font name + + + + @@ -252,14 +238,38 @@ - The font to use for texts and dimensions + The font for texts, dimensions and labels - + + + + Font size + + + + + + + The height for texts, dimension texts and label texts + + + + + + + + + + Line spacing + + + + - The spacing between different lines of text + The line spacing for multi-line texts and labels (relative to the font size) @@ -271,29 +281,41 @@ Dimensions - + - + - Arrow style - - - - - - - The space between the text and the dimension line - - - + Line and arrow color - - - The type of dimension arrows + + + + + + + Line width + + + + + + px + + + + + + + Arrow type + + + + + Dot @@ -321,44 +343,59 @@ - - + + - Ext lines + Arrow size - + - - The size of dimension arrows - - + + + + Show unit + + + + - If the unit suffix is shown on dimension texts or not - - - Qt::RightToLeft + If checked, a unit symbol is added to dimension texts - - + + - Text spacing + Unit override + + + The unit override for dimensions. Leave blank to use the current FreeCAD unit. + + + + + + + Dim overshoot + + + + The distance the dimension line is extended past the extension lines @@ -368,34 +405,37 @@ - - + + - Arrow size - - - - - - - Dim overshoot + Ext lines - + - Length of the extension lines beyond the dimension line + The length of extension lines. Use 0 for full extension lines. A negative value +defines the gap between the ends of the extension lines and the measured points. +A positive value defines the maximum length of the extension lines. Only used +for linear dimensions. - - + + + + Ext overshoot + + + + + - Length of the extension lines + The length of extension lines above the dimension line @@ -403,30 +443,19 @@ - + - Show unit + Text spacing - - - - Ext overshoot - - - - - - - Unit override - - - - - + + - The unit to use for dimensions. Leave blank to use current FreeCAD unit + The space between the dimension line and the dimension text + + + @@ -438,7 +467,7 @@ - Apply above style to selected object(s) + Apply the above style to selected object(s) Selected @@ -452,7 +481,7 @@ - Apply above style to all annotations (texts, dimensions and labels) + Apply the above style to all annotations (texts, dimensions and labels) Annotations diff --git a/src/Mod/Draft/draftguitools/gui_setstyle.py b/src/Mod/Draft/draftguitools/gui_setstyle.py index 91cc61d991..241034e0ed 100644 --- a/src/Mod/Draft/draftguitools/gui_setstyle.py +++ b/src/Mod/Draft/draftguitools/gui_setstyle.py @@ -28,22 +28,26 @@ ## \addtogroup draftguitools # @{ -import FreeCAD -import os -import draftutils.utils as utils +from PySide import QtCore +from PySide import QtGui + +import FreeCAD as App +import FreeCADGui as Gui +import Draft_rc +import os + +from FreeCAD import Units as U +from draftutils import utils -if FreeCAD.GuiUp: - import FreeCADGui - import Draft_rc def QT_TRANSLATE_NOOP(ctx,txt): return txt -translate = FreeCAD.Qt.translate +translate = App.Qt.translate __title__ = "FreeCAD Draft Workbench GUI Tools - Styling tools" __author__ = ("Yorik van Havre") __url__ = "https://www.freecad.org" -PRESETPATH = os.path.join(FreeCAD.getUserAppDataDir(),"Draft","StylePresets.json") +PRESETPATH = os.path.join(App.getUserAppDataDir(), "Draft", "StylePresets.json") class Draft_SetStyle: @@ -52,16 +56,16 @@ class Draft_SetStyle: def GetResources(self): - d = {'Pixmap': 'Draft_Apply', - 'Accel': "S, S", - 'MenuText': QT_TRANSLATE_NOOP("Draft_SetStyle", "Set style"), - 'ToolTip': QT_TRANSLATE_NOOP("Draft_SetStyle", "Sets default styles")} - return d + return { + "Pixmap": "Draft_Apply", + "Accel": "S, S", + "MenuText": QT_TRANSLATE_NOOP("Draft_SetStyle", "Set style"), + "ToolTip": QT_TRANSLATE_NOOP("Draft_SetStyle", "Sets default styles") + } def Activated(self): - FreeCADGui.Control.showDialog(Draft_SetStyle_TaskPanel()) - + Gui.Control.showDialog(Draft_SetStyle_TaskPanel()) class Draft_SetStyle_TaskPanel: @@ -70,35 +74,45 @@ class Draft_SetStyle_TaskPanel: def __init__(self): - from PySide import QtCore,QtGui self.p = "User parameter:BaseApp/Preferences/" - self.form = FreeCADGui.PySideUic.loadUi(":/ui/TaskPanel_SetStyle.ui") + param_draft = App.ParamGet(self.p + "Mod/Draft") + param_view = App.ParamGet(self.p + "View") + + self.form = Gui.PySideUic.loadUi(":/ui/TaskPanel_SetStyle.ui") self.form.setWindowIcon(QtGui.QIcon.fromTheme("gtk-apply", QtGui.QIcon(":/icons/Draft_Apply.svg"))) + + self.form.saveButton.setIcon(QtGui.QIcon.fromTheme("gtk-save", QtGui.QIcon(":/icons/document-save.svg"))) self.form.applyButton.setIcon(QtGui.QIcon.fromTheme("gtk-apply", QtGui.QIcon(":/icons/Draft_Apply.svg"))) self.form.annotButton.setIcon(QtGui.QIcon(":/icons/Draft_Text.svg")) - self.form.LineColor.setProperty("color",self.getPrefColor("View","DefaultShapeLineColor",255)) - self.form.LineWidth.setValue(FreeCAD.ParamGet(self.p+"View").GetInt("DefaultShapeLineWidth",2)) - self.form.DrawStyle.setCurrentIndex(FreeCAD.ParamGet(self.p+"Mod/Draft").GetInt("DefaultDrawStyle",0)) - self.form.DisplayMode.setCurrentIndex(FreeCAD.ParamGet(self.p+"Mod/Draft").GetInt("DefaultDisplayMode",0)) - self.form.ShapeColor.setProperty("color",self.getPrefColor("View","DefaultShapeColor",4294967295)) - self.form.Transparency.setValue(FreeCAD.ParamGet(self.p+"View").GetInt("DefaultShapeTransparency",0)) - self.form.TextFont.setCurrentFont(QtGui.QFont(FreeCAD.ParamGet(self.p+"Mod/Draft").GetString("textfont","Sans"))) - self.form.TextSize.setText(FreeCAD.Units.Quantity(FreeCAD.ParamGet(self.p+"Mod/Draft").GetFloat("textheight",10),FreeCAD.Units.Length).UserString) - self.form.TextColor.setProperty("color",self.getPrefColor("Mod/Draft","DefaultTextColor",255)) - self.form.ArrowStyle.setCurrentIndex(FreeCAD.ParamGet(self.p+"Mod/Draft").GetInt("dimsymbol",0)) - self.form.ArrowSize.setText(FreeCAD.Units.Quantity(FreeCAD.ParamGet(self.p+"Mod/Draft").GetFloat("arrowsize",5),FreeCAD.Units.Length).UserString) - self.form.ShowUnit.setChecked(FreeCAD.ParamGet(self.p+"Mod/Draft").GetBool("showUnit",True)) - self.form.UnitOverride.setText(FreeCAD.ParamGet(self.p+"Mod/Draft").GetString("overrideUnit","")) - self.form.saveButton.setIcon(QtGui.QIcon.fromTheme("gtk-save", QtGui.QIcon(":/icons/document-save.svg"))) - self.form.TextSpacing.setText(FreeCAD.Units.Quantity(FreeCAD.ParamGet(self.p+"Mod/Draft").GetFloat("dimspacing",1),FreeCAD.Units.Length).UserString) - self.form.LineSpacing.setValue(FreeCAD.ParamGet(self.p+"Mod/Draft").GetFloat("LineSpacing",1)) - self.form.DimOvershoot.setText(FreeCAD.Units.Quantity(FreeCAD.ParamGet(self.p+"Mod/Draft").GetFloat("dimovershoot",0),FreeCAD.Units.Length).UserString) - self.form.ExtLines.setText(FreeCAD.Units.Quantity(FreeCAD.ParamGet(self.p+"Mod/Draft").GetFloat("extlines",0),FreeCAD.Units.Length).UserString) - self.form.ExtOvershoot.setText(FreeCAD.Units.Quantity(FreeCAD.ParamGet(self.p+"Mod/Draft").GetFloat("extovershoot",0),FreeCAD.Units.Length).UserString) + + self.form.ShapeColor.setProperty("color", self.getColor(param_view.GetUnsigned("DefaultShapeColor", 3435973887))) + self.form.Transparency.setValue(param_view.GetInt("DefaultShapeTransparency", 0)) + self.form.LineColor.setProperty("color", self.getColor(param_view.GetUnsigned("DefaultShapeLineColor", 255))) + self.form.LineWidth.setValue(param_view.GetInt("DefaultShapeLineWidth", 2)) + self.form.PointColor.setProperty("color", self.getColor(param_view.GetUnsigned("DefaultShapeVertexColor", 255))) + self.form.PointSize.setValue(param_view.GetInt("DefaultShapePointSize", 2)) + self.form.DrawStyle.setCurrentIndex(param_draft.GetInt("DefaultDrawStyle", 0)) + self.form.DisplayMode.setCurrentIndex(param_draft.GetInt("DefaultDisplayMode", 0)) + self.form.TextColor.setProperty("color", self.getColor(param_draft.GetUnsigned("DefaultTextColor", 255))) + self.form.TextFont.setCurrentFont(QtGui.QFont(param_draft.GetString("textfont", "Sans"))) + self.form.TextSize.setText(U.Quantity(param_draft.GetFloat("textheight", 3.5), U.Length).UserString) + self.form.LineSpacing.setValue(param_draft.GetFloat("LineSpacing", 1)) + self.form.AnnoLineColor.setProperty("color", self.getColor(param_draft.GetUnsigned("DefaultAnnoLineColor", 255))) + self.form.AnnoLineWidth.setValue(param_draft.GetInt("DefaultAnnoLineWidth", 2)) + self.form.ArrowStyle.setCurrentIndex(param_draft.GetInt("dimsymbol", 0)) + self.form.ArrowSize.setText(U.Quantity(param_draft.GetFloat("arrowsize", 1), U.Length).UserString) + self.form.ShowUnit.setChecked(param_draft.GetBool("showUnit", True)) + self.form.UnitOverride.setText(param_draft.GetString("overrideUnit", "")) + self.form.DimOvershoot.setText(U.Quantity(param_draft.GetFloat("dimovershoot", 0), U.Length).UserString) + self.form.ExtLines.setText(U.Quantity(param_draft.GetFloat("extlines", -0.5), U.Length).UserString) + self.form.ExtOvershoot.setText(U.Quantity(param_draft.GetFloat("extovershoot", 2), U.Length).UserString) + self.form.TextSpacing.setText(U.Quantity(param_draft.GetFloat("dimspacing", 1), U.Length).UserString) + self.form.saveButton.clicked.connect(self.onSaveStyle) self.form.applyButton.clicked.connect(self.onApplyStyle) self.form.annotButton.clicked.connect(self.onApplyAnnot) self.form.comboPresets.currentIndexChanged.connect(self.onLoadStyle) + self.loadDefaults() def loadDefaults(self): @@ -111,106 +125,115 @@ class Draft_SetStyle_TaskPanel: self.form.comboPresets.addItems(presets) current = self.getValues() for name, preset in pdict.items(): - if all(item in current.items() for item in preset.items()): #if preset == current: + if all(item in current.items() for item in preset.items()): # if preset == current: self.form.comboPresets.setCurrentIndex(1 + (pdict_keys.index(name))) break - def getPrefColor(self,group,prop,default): + def getColor(self, c): - c = FreeCAD.ParamGet(self.p+group).GetUnsigned(prop,default) - return self.getColor(c) - - def getColor(self,c): - - from PySide import QtGui return QtGui.QColor(utils.rgba_to_argb(c)) def getValues(self): preset = {} - preset["LineColor"] = utils.argb_to_rgba(self.form.LineColor.property("color").rgba()) - preset["LineWidth"] = self.form.LineWidth.value() - preset["DrawStyle"] = self.form.DrawStyle.currentIndex() - preset["DisplayMode"] = self.form.DisplayMode.currentIndex() preset["ShapeColor"] = utils.argb_to_rgba(self.form.ShapeColor.property("color").rgba()) preset["Transparency"] = self.form.Transparency.value() - preset["TextFont"] = self.form.TextFont.currentFont().family() - preset["TextSize"] = FreeCAD.Units.Quantity(self.form.TextSize.text()).Value + preset["LineColor"] = utils.argb_to_rgba(self.form.LineColor.property("color").rgba()) + preset["LineWidth"] = self.form.LineWidth.value() + preset["PointColor"] = utils.argb_to_rgba(self.form.PointColor.property("color").rgba()) + preset["PointSize"] = self.form.PointSize.value() + preset["DrawStyle"] = self.form.DrawStyle.currentIndex() + preset["DisplayMode"] = self.form.DisplayMode.currentIndex() preset["TextColor"] = utils.argb_to_rgba(self.form.TextColor.property("color").rgba()) + preset["TextFont"] = self.form.TextFont.currentFont().family() + preset["TextSize"] = U.Quantity(self.form.TextSize.text()).Value + preset["LineSpacing"] = self.form.LineSpacing.value() + preset["AnnoLineColor"] = utils.argb_to_rgba(self.form.AnnoLineColor.property("color").rgba()) + preset["AnnoLineWidth"] = self.form.AnnoLineWidth.value() preset["ArrowStyle"] = self.form.ArrowStyle.currentIndex() - preset["ArrowSize"] = FreeCAD.Units.Quantity(self.form.ArrowSize.text()).Value + preset["ArrowSize"] = U.Quantity(self.form.ArrowSize.text()).Value preset["ShowUnit"] = self.form.ShowUnit.isChecked() preset["UnitOverride"] = self.form.UnitOverride.text() - preset["TextSpacing"] = FreeCAD.Units.Quantity(self.form.TextSpacing.text()).Value - preset["LineSpacing"] = self.form.LineSpacing.value() - preset["DimOvershoot"] = FreeCAD.Units.Quantity(self.form.DimOvershoot.text()).Value - preset["ExtLines"] = FreeCAD.Units.Quantity(self.form.ExtLines.text()).Value - preset["ExtOvershoot"] = FreeCAD.Units.Quantity(self.form.ExtOvershoot.text()).Value + preset["DimOvershoot"] = U.Quantity(self.form.DimOvershoot.text()).Value + preset["ExtLines"] = U.Quantity(self.form.ExtLines.text()).Value + preset["ExtOvershoot"] = U.Quantity(self.form.ExtOvershoot.text()).Value + preset["TextSpacing"] = U.Quantity(self.form.TextSpacing.text()).Value return preset def setValues(self,preset): - from PySide import QtCore,QtGui - self.form.LineColor.setProperty("color",self.getColor(preset.get("LineColor",255))) - self.form.LineWidth.setValue(preset.get("LineWidth",1)) - self.form.DrawStyle.setCurrentIndex(preset.get("DrawStyle",0)) - self.form.DisplayMode.setCurrentIndex(preset.get("DisplayMode",0)) - self.form.ShapeColor.setProperty("color",self.getColor(preset.get("ShapeColor",4294967295))) - self.form.Transparency.setValue(preset.get("Transparency",0)) - self.form.TextFont.setCurrentFont(QtGui.QFont(preset.get("TextFont","sans"))) - self.form.TextColor.setProperty("color",self.getColor(preset.get("TextColor",255))) - self.form.ArrowStyle.setCurrentIndex(preset.get("ArrowStyle",0)) - self.form.ShowUnit.setChecked(preset.get("ShowUnit",False)) - self.form.UnitOverride.setText(preset.get("UnitOverride","")) - self.form.TextSize.setText(FreeCAD.Units.Quantity(preset.get("TextSize",25),FreeCAD.Units.Length).UserString) - self.form.ArrowSize.setText(FreeCAD.Units.Quantity(preset.get("ArrowSize",5),FreeCAD.Units.Length).UserString) - self.form.TextSpacing.setText(FreeCAD.Units.Quantity(preset.get("TextSpacing",25),FreeCAD.Units.Length).UserString) - self.form.LineSpacing.setValue(preset.get("LineSpacing",3)) - self.form.DimOvershoot.setText(FreeCAD.Units.Quantity(preset.get("DimOvershoot",0),FreeCAD.Units.Length).UserString) - self.form.ExtLines.setText(FreeCAD.Units.Quantity(preset.get("ExtLines",0),FreeCAD.Units.Length).UserString) - self.form.ExtOvershoot.setText(FreeCAD.Units.Quantity(preset.get("ExtOvershoot",0),FreeCAD.Units.Length).UserString) + # For compatibility with V0.21 and earlier some properties, if missing, revert to others: + # 'new' prop -> old prop + # --------------------------- + # PointColor -> LineColor + # PointSize -> LineWidth + # AnnoLineColor -> LineColor + # AnnoLineWidth -> LineWidth + self.form.ShapeColor.setProperty("color", self.getColor(preset.get("ShapeColor", 3435973887))) + self.form.Transparency.setValue(preset.get("Transparency", 0)) + self.form.LineColor.setProperty("color", self.getColor(preset.get("LineColor", 255))) + self.form.LineWidth.setValue(preset.get("LineWidth", 2)) + self.form.PointColor.setProperty("color", self.getColor(preset.get("PointColor", preset.get("LineColor", 255)))) + self.form.PointSize.setValue(preset.get("PointSize", preset.get("LineWidth", 2))) + self.form.DrawStyle.setCurrentIndex(preset.get("DrawStyle", 0)) + self.form.DisplayMode.setCurrentIndex(preset.get("DisplayMode", 0)) + self.form.TextColor.setProperty("color", self.getColor(preset.get("TextColor", 255))) + self.form.TextFont.setCurrentFont(QtGui.QFont(preset.get("TextFont", "Sans"))) + self.form.TextSize.setText(U.Quantity(preset.get("TextSize", 3.5),U.Length).UserString) + self.form.LineSpacing.setValue(preset.get("LineSpacing", 1)) + self.form.AnnoLineColor.setProperty("color", self.getColor(preset.get("AnnoLineColor", preset.get("LineColor", 255)))) + self.form.AnnoLineWidth.setValue(preset.get("AnnoLineWidth", preset.get("LineWidth", 2))) + self.form.ArrowStyle.setCurrentIndex(preset.get("ArrowStyle", 0)) + self.form.ArrowSize.setText(U.Quantity(preset.get("ArrowSize", 1), U.Length).UserString) + self.form.ShowUnit.setChecked(preset.get("ShowUnit", True)) + self.form.UnitOverride.setText(preset.get("UnitOverride", "")) + self.form.DimOvershoot.setText(U.Quantity(preset.get("DimOvershoot", 0), U.Length).UserString) + self.form.ExtLines.setText(U.Quantity(preset.get("ExtLines", -0.5), U.Length).UserString) + self.form.ExtOvershoot.setText(U.Quantity(preset.get("ExtOvershoot", 2), U.Length).UserString) + self.form.TextSpacing.setText(U.Quantity(preset.get("TextSpacing", 1), U.Length).UserString) def reject(self): - FreeCADGui.Control.closeDialog() + Gui.Control.closeDialog() def accept(self): - param_draft = FreeCAD.ParamGet(self.p + "Mod/Draft") - param_view = FreeCAD.ParamGet(self.p + "View") + param_draft = App.ParamGet(self.p + "Mod/Draft") + param_view = App.ParamGet(self.p + "View") - param_view.SetUnsigned("DefaultShapeLineColor",utils.argb_to_rgba(self.form.LineColor.property("color").rgba())) - param_view.SetInt("DefaultShapeLineWidth",self.form.LineWidth.value()) - param_view.SetUnsigned("DefaultShapeVertexColor",utils.argb_to_rgba(self.form.LineColor.property("color").rgba())) - param_view.SetInt("DefaultShapePointSize",self.form.LineWidth.value()) - param_draft.SetInt("DefaultDrawStyle",self.form.DrawStyle.currentIndex()) - param_draft.SetInt("DefaultDisplayMode",self.form.DisplayMode.currentIndex()) - param_view.SetUnsigned("DefaultShapeColor",utils.argb_to_rgba(self.form.ShapeColor.property("color").rgba())) - param_view.SetInt("DefaultShapeTransparency",self.form.Transparency.value()) - param_draft.SetString("textfont",self.form.TextFont.currentFont().family()) - param_draft.SetFloat("textheight",FreeCAD.Units.Quantity(self.form.TextSize.text()).Value) - param_draft.SetUnsigned("DefaultTextColor",utils.argb_to_rgba(self.form.TextColor.property("color").rgba())) - param_draft.SetInt("dimsymbol",self.form.ArrowStyle.currentIndex()) - param_draft.SetFloat("arrowsize",FreeCAD.Units.Quantity(self.form.ArrowSize.text()).Value) - param_draft.SetBool("showUnit",self.form.ShowUnit.isChecked()) - param_draft.SetString("overrideUnit",self.form.UnitOverride.text()) - param_draft.SetFloat("dimspacing",FreeCAD.Units.Quantity(self.form.TextSpacing.text()).Value) - param_draft.SetFloat("LineSpacing",self.form.LineSpacing.value()) - param_draft.SetFloat("dimovershoot",FreeCAD.Units.Quantity(self.form.DimOvershoot.text()).Value) - param_draft.SetFloat("extlines",FreeCAD.Units.Quantity(self.form.ExtLines.text()).Value) - param_draft.SetFloat("extovershoot",FreeCAD.Units.Quantity(self.form.ExtOvershoot.text()).Value) + param_view.SetUnsigned("DefaultShapeColor", utils.argb_to_rgba(self.form.ShapeColor.property("color").rgba())) + param_view.SetInt("DefaultShapeTransparency", self.form.Transparency.value()) + param_view.SetUnsigned("DefaultShapeLineColor", utils.argb_to_rgba(self.form.LineColor.property("color").rgba())) + param_view.SetInt("DefaultShapeLineWidth", self.form.LineWidth.value()) + param_view.SetUnsigned("DefaultShapeVertexColor", utils.argb_to_rgba(self.form.PointColor.property("color").rgba())) + param_view.SetInt("DefaultShapePointSize", self.form.PointSize.value()) + param_draft.SetInt("DefaultDrawStyle", self.form.DrawStyle.currentIndex()) + param_draft.SetInt("DefaultDisplayMode", self.form.DisplayMode.currentIndex()) + param_draft.SetUnsigned("DefaultTextColor", utils.argb_to_rgba(self.form.TextColor.property("color").rgba())) + param_draft.SetString("textfont", self.form.TextFont.currentFont().family()) + param_draft.SetFloat("textheight", U.Quantity(self.form.TextSize.text()).Value) + param_draft.SetFloat("LineSpacing", self.form.LineSpacing.value()) + param_draft.SetUnsigned("DefaultAnnoLineColor", utils.argb_to_rgba(self.form.AnnoLineColor.property("color").rgba())) + param_draft.SetInt("DefaultAnnoLineWidth", self.form.AnnoLineWidth.value()) + param_draft.SetInt("dimsymbol", self.form.ArrowStyle.currentIndex()) + param_draft.SetFloat("arrowsize", U.Quantity(self.form.ArrowSize.text()).Value) + param_draft.SetBool("showUnit", self.form.ShowUnit.isChecked()) + param_draft.SetString("overrideUnit", self.form.UnitOverride.text()) + param_draft.SetFloat("dimovershoot", U.Quantity(self.form.DimOvershoot.text()).Value) + param_draft.SetFloat("extlines", U.Quantity(self.form.ExtLines.text()).Value) + param_draft.SetFloat("extovershoot", U.Quantity(self.form.ExtOvershoot.text()).Value) + param_draft.SetFloat("dimspacing", U.Quantity(self.form.TextSpacing.text()).Value) self.reject() def onApplyStyle(self): - for obj in FreeCADGui.Selection.getSelection(): + for obj in Gui.Selection.getSelection(): self.apply_style_to_obj(obj) def onApplyAnnot(self): - if FreeCAD.ActiveDocument is not None: # Command can be called without a document. - from draftutils import utils - objs = FreeCAD.ActiveDocument.Objects + if App.ActiveDocument is not None: # Command can be called without a document. + objs = App.ActiveDocument.Objects typs = ["Dimension", "LinearDimension", "AngularDimension", "Text", "DraftText", "Label"] for obj in objs: @@ -224,49 +247,56 @@ class Draft_SetStyle_TaskPanel: return properties = vobj.PropertiesList - if "LineColor" in properties: - vobj.LineColor = self.form.LineColor.property("color").getRgbF()[:3] # Remove Alpha (which is 1 instead of 0). - if "LineWidth" in properties: - vobj.LineWidth = self.form.LineWidth.value() - if "PointColor" in properties: - vobj.PointColor = self.form.LineColor.property("color").getRgbF()[:3] - if "PointSize" in properties: - vobj.PointSize = self.form.LineWidth.value() - if "DrawStyle" in properties: - vobj.DrawStyle = ["Solid", "Dashed", "Dotted", "Dashdot"][self.form.DrawStyle.currentIndex()] - if "DisplayMode" in properties: - dmodes = ["Flat Lines", "Wireframe", "Shaded", "Points"] - dm = dmodes[self.form.DisplayMode.currentIndex()] - if dm in vobj.getEnumerationsOfProperty("DisplayMode"): - vobj.DisplayMode = dm - if "ShapeColor" in properties: - vobj.ShapeColor = self.form.ShapeColor.property("color").getRgbF()[:3] - if "Transparency" in properties: - vobj.Transparency = self.form.Transparency.value() - if "FontName" in properties: - vobj.FontName = self.form.TextFont.currentFont().family() - if "FontSize" in properties: - vobj.FontSize = FreeCAD.Units.Quantity(self.form.TextSize.text()).Value - if "TextColor" in properties: - vobj.TextColor = self.form.TextColor.property("color").getRgbF()[:3] - if "ArrowType" in properties: - vobj.ArrowType = ["Dot", "Circle", "Arrow", "Tick", "Tick-2"][self.form.ArrowStyle.currentIndex()] - if "ArrowSize" in properties: - vobj.ArrowSize = FreeCAD.Units.Quantity(self.form.ArrowSize.text()).Value - if "ShowUnit" in properties: - vobj.ShowUnit = self.form.ShowUnit.isChecked() - if "UnitOverride" in properties: - vobj.UnitOverride = self.form.UnitOverride.text() - if "TextSpacing" in properties: - vobj.TextSpacing = FreeCAD.Units.Quantity(self.form.TextSpacing.text()).Value - if "LineSpacing" in properties: - vobj.LineSpacing = self.form.LineSpacing.value() - if "DimOvershoot" in properties: - vobj.DimOvershoot = FreeCAD.Units.Quantity(self.form.DimOvershoot.text()).Value - if "ExtLines" in properties: - vobj.ExtLines = FreeCAD.Units.Quantity(self.form.ExtLines.text()).Value - if "ExtOvershoot" in properties: - vobj.ExtOvershoot = FreeCAD.Units.Quantity(self.form.ExtOvershoot.text()).Value + if "FontName" not in properties: # Shapes + if "ShapeColor" in properties: + vobj.ShapeColor = self.form.ShapeColor.property("color").getRgbF()[:3] # Remove Alpha (which is 1 instead of 0). + if "Transparency" in properties: + vobj.Transparency = self.form.Transparency.value() + if "LineColor" in properties: + vobj.LineColor = self.form.LineColor.property("color").getRgbF()[:3] + if "LineWidth" in properties: + vobj.LineWidth = self.form.LineWidth.value() + if "PointColor" in properties: + vobj.PointColor = self.form.PointColor.property("color").getRgbF()[:3] + if "PointSize" in properties: + vobj.PointSize = self.form.PointSize.value() + if "DrawStyle" in properties: + dstyles = ["Solid", "Dashed", "Dotted", "Dashdot"] + vobj.DrawStyle = dstyles[self.form.DrawStyle.currentIndex()] + if "DisplayMode" in properties: + dmodes = ["Flat Lines", "Shaded", "Wireframe", "Points"] + dm = dmodes[self.form.DisplayMode.currentIndex()] + if dm in vobj.getEnumerationsOfProperty("DisplayMode"): + vobj.DisplayMode = dm + else: # Annotations + if "TextColor" in properties: + vobj.TextColor = self.form.TextColor.property("color").getRgbF()[:3] + if "FontName" in properties: + vobj.FontName = self.form.TextFont.currentFont().family() + if "FontSize" in properties: + vobj.FontSize = U.Quantity(self.form.TextSize.text()).Value + if "LineSpacing" in properties: + vobj.LineSpacing = self.form.LineSpacing.value() + if "LineColor" in properties: + vobj.LineColor = self.form.AnnoLineColor.property("color").getRgbF()[:3] + if "LineWidth" in properties: + vobj.LineWidth = self.form.AnnoLineWidth.value() + if "ArrowType" in properties: + vobj.ArrowType = ["Dot", "Circle", "Arrow", "Tick", "Tick-2"][self.form.ArrowStyle.currentIndex()] + if "ArrowSize" in properties: + vobj.ArrowSize = U.Quantity(self.form.ArrowSize.text()).Value + if "ShowUnit" in properties: + vobj.ShowUnit = self.form.ShowUnit.isChecked() + if "UnitOverride" in properties: + vobj.UnitOverride = self.form.UnitOverride.text() + if "DimOvershoot" in properties: + vobj.DimOvershoot = U.Quantity(self.form.DimOvershoot.text()).Value + if "ExtLines" in properties: + vobj.ExtLines = U.Quantity(self.form.ExtLines.text()).Value + if "ExtOvershoot" in properties: + vobj.ExtOvershoot = U.Quantity(self.form.ExtOvershoot.text()).Value + if "TextSpacing" in properties: + vobj.TextSpacing = U.Quantity(self.form.TextSpacing.text()).Value def onLoadStyle(self,index): @@ -278,18 +308,17 @@ class Draft_SetStyle_TaskPanel: def onSaveStyle(self): - from PySide import QtCore,QtGui reply = QtGui.QInputDialog.getText(None, - translate("Draft","Save style"), - translate("Draft","Name of this new style:")) + translate("Draft", "Save style"), + translate("Draft", "Name of this new style:")) if reply[1]: name = reply[0] pdict = self.load() if pdict: if name in pdict: reply = QtGui.QMessageBox.question(None, - translate("Draft","Warning"), - translate("Draft","Name exists. Overwrite?"), + translate("Draft", "Warning"), + translate("Draft", "Name exists. Overwrite?"), QtGui.QMessageBox.Yes | QtGui.QMessageBox.No, QtGui.QMessageBox.No) if reply == QtGui.QMessageBox.No: @@ -308,10 +337,12 @@ class Draft_SetStyle_TaskPanel: import json from json.decoder import JSONDecodeError except Exception: - FreeCAD.Console.PrintError(translate("Draft","Error: json module not found. Unable to load style")+"\n") + App.Console.PrintError( + translate("Draft", "Error: json module not found. Unable to load style") + "\n" + ) return if os.path.exists(PRESETPATH): - with open(PRESETPATH,"r") as f: + with open(PRESETPATH, "r") as f: try: pdict = json.load(f) except JSONDecodeError: @@ -325,15 +356,17 @@ class Draft_SetStyle_TaskPanel: try: import json except Exception: - FreeCAD.Console.PrintError(translate("Draft","Error: json module not found. Unable to save style")+"\n") + App.Console.PrintError( + translate("Draft", "Error: json module not found. Unable to save style") + "\n" + ) return folder = os.path.dirname(PRESETPATH) if not os.path.exists(folder): os.makedirs(folder) - with open(PRESETPATH,"w") as f: - json.dump(d,f,indent=4) + with open(PRESETPATH, "w") as f: + json.dump(d, f, indent=4) -FreeCADGui.addCommand('Draft_SetStyle', Draft_SetStyle()) +Gui.addCommand("Draft_SetStyle", Draft_SetStyle()) ## @} diff --git a/src/Mod/Draft/draftutils/gui_utils.py b/src/Mod/Draft/draftutils/gui_utils.py index 2625ce6004..a518c32ae6 100644 --- a/src/Mod/Draft/draftutils/gui_utils.py +++ b/src/Mod/Draft/draftutils/gui_utils.py @@ -464,6 +464,16 @@ def format_object(target, origin=None): if not hasattr(target, 'ViewObject'): return obrep = target.ViewObject + obprops = obrep.PropertiesList + if "FontName" not in obprops: + if "DrawStyle" in obprops: + dstyles = ["Solid", "Dashed", "Dotted", "Dashdot"] + obrep.DrawStyle = dstyles[utils.getParam("DefaultDrawStyle", 0)] + if "DisplayMode" in obprops: + dmodes = ["Flat Lines", "Shaded", "Wireframe", "Points"] + dm = dmodes[utils.getParam("DefaultDisplayMode", 0)] + if dm in obrep.getEnumerationsOfProperty("DisplayMode"): + obrep.DisplayMode = dm if Gui.draftToolBar.isConstructionMode(): doc = App.ActiveDocument col = Gui.draftToolBar.getDefaultColor("constr") + (0.0,) @@ -472,13 +482,13 @@ def format_object(target, origin=None): grp = doc.addObject("App::DocumentObjectGroup", "Draft_Construction") grp.Label = utils.get_param("constructiongroupname", "Construction") grp.addObject(target) - if "TextColor" in obrep.PropertiesList: + if "TextColor" in obprops: obrep.TextColor = col - if "PointColor" in obrep.PropertiesList: + if "PointColor" in obprops: obrep.PointColor = col - if "LineColor" in obrep.PropertiesList: + if "LineColor" in obprops: obrep.LineColor = col - if "ShapeColor" in obrep.PropertiesList: + if "ShapeColor" in obprops: obrep.ShapeColor = col if hasattr(obrep, "Transparency"): obrep.Transparency = 80 @@ -487,7 +497,7 @@ def format_object(target, origin=None): for p in matchrep.PropertiesList: if p not in ("DisplayMode", "BoundingBox", "Proxy", "RootNode", "Visibility"): - if p in obrep.PropertiesList: + if p in obprops: if not obrep.getEditorMode(p): if hasattr(getattr(matchrep, p), "Value"): val = getattr(matchrep, p).Value diff --git a/src/Mod/Draft/draftutils/utils.py b/src/Mod/Draft/draftutils/utils.py index 4b3580cd01..67ee641d70 100644 --- a/src/Mod/Draft/draftutils/utils.py +++ b/src/Mod/Draft/draftutils/utils.py @@ -173,6 +173,7 @@ def get_param_type(param): "linewidth", "modconstrain", "modsnap", "maxSnapEdges", "modalt", "HatchPatternResolution", "snapStyle", "DefaultAnnoDisplayMode", "DefaultAnnoLineWidth", + "DefaultDrawStyle", "DefaultDisplayMode", "gridSize", "gridTransparency"): return "int" elif param in ("constructiongroupname", "textfont",