Merge pull request #11593 from Roy-043/Draft-update-Draft_SetStyle

Draft: update Draft_SetStyle
This commit is contained in:
Roy-043
2023-12-01 13:49:09 +01:00
committed by GitHub
4 changed files with 406 additions and 333 deletions

View File

@@ -19,7 +19,7 @@
<item>
<widget class="QComboBox" name="comboPresets">
<property name="toolTip">
<string>Fills the values below with a stored style preset</string>
<string>Fill the values below from a stored style preset</string>
</property>
<item>
<property name="text">
@@ -37,7 +37,7 @@
</size>
</property>
<property name="toolTip">
<string>Save current style as a preset...</string>
<string>Save the current style as a preset...</string>
</property>
<property name="text">
<string/>
@@ -53,52 +53,99 @@
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Lines and faces</string>
<string>Shapes</string>
</property>
<layout class="QGridLayout" name="gridLayout" columnstretch="1,0" columnminimumwidth="0,120">
<property name="sizeConstraint">
<enum>QLayout::SetDefaultConstraint</enum>
</property>
<item row="0" column="0">
<widget class="QLabel" name="label">
<widget class="QLabel" name="label_ShapeColor">
<property name="text">
<string>Shape color</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="Gui::ColorButton" name="ShapeColor">
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_Transparency">
<property name="text">
<string>Transparency</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QSpinBox" name="Transparency">
<property name="suffix">
<string notr="true"> %</string>
</property>
<property name="maximum">
<number>100</number>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_LineColor">
<property name="text">
<string>Line color</string>
</property>
</widget>
</item>
<item row="0" column="1">
<item row="2" column="1">
<widget class="Gui::ColorButton" name="LineColor">
<property name="toolTip">
<string>The color of lines</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<item row="3" column="0">
<widget class="QLabel" name="label_LineWidth">
<property name="text">
<string>Line width</string>
</property>
</widget>
</item>
<item row="1" column="1">
<item row="3" column="1">
<widget class="QSpinBox" name="LineWidth">
<property name="suffix">
<string> px</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_10">
<item row="4" column="0">
<widget class="QLabel" name="label_PointColor">
<property name="text">
<string>Point color</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="Gui::ColorButton" name="PointColor">
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="label_PointSize">
<property name="text">
<string>Point size</string>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QSpinBox" name="PointSize">
<property name="suffix">
<string> px</string>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QLabel" name="label_DrawStyle">
<property name="text">
<string>Draw style</string>
</property>
</widget>
</item>
<item row="2" column="1">
<item row="6" column="1">
<widget class="QComboBox" name="DrawStyle">
<property name="toolTip">
<string>The line style</string>
</property>
<item>
<property name="text">
<string>Solid</string>
@@ -121,33 +168,30 @@
</item>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_11">
<item row="7" column="0">
<widget class="QLabel" name="label_DisplayMode">
<property name="text">
<string>Display mode</string>
</property>
</widget>
</item>
<item row="3" column="1">
<item row="7" column="1">
<widget class="QComboBox" name="DisplayMode">
<property name="toolTip">
<string>The display mode for faces</string>
</property>
<item>
<property name="text">
<string>Flat Lines</string>
</property>
</item>
<item>
<property name="text">
<string>Wireframe</string>
</property>
</item>
<item>
<property name="text">
<string>Shaded</string>
</property>
</item>
<item>
<property name="text">
<string>Wireframe</string>
</property>
</item>
<item>
<property name="text">
<string>Points</string>
@@ -155,40 +199,6 @@
</item>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Shape color</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="Gui::ColorButton" name="ShapeColor">
<property name="toolTip">
<string>The color of faces</string>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="label_12">
<property name="text">
<string>Transparency</string>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QSpinBox" name="Transparency">
<property name="toolTip">
<string>The transparency of faces</string>
</property>
<property name="suffix">
<string notr="true"> %</string>
</property>
<property name="maximum">
<number>100</number>
</property>
</widget>
</item>
</layout>
</widget>
</item>
@@ -197,53 +207,29 @@
<property name="title">
<string>Annotations</string>
</property>
<layout class="QGridLayout" name="gridLayout_3" columnstretch="1,0" columnminimumwidth="0,120">
<item row="1" column="1">
<widget class="Gui::InputField" name="TextSize">
<property name="toolTip">
<string>The size of texts and dimension texts</string>
</property>
<property name="unit" stdset="0">
<string notr="true"/>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="Gui::ColorButton" name="TextColor">
<property name="toolTip">
<string>The color of texts and dimension texts</string>
</property>
</widget>
</item>
<layout class="QGridLayout" name="gridLayout_2" columnstretch="1,0" columnminimumwidth="0,120">
<item row="0" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Text font</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Text size</string>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="label_15">
<property name="text">
<string>Line spacing</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_7">
<widget class="QLabel" name="label_TextColor">
<property name="text">
<string>Text color</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="Gui::ColorButton" name="TextColor">
<property name="toolTip">
<string>The color for texts, dimension texts and label texts</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_TextFont">
<property name="text">
<string>Font name</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QFontComboBox" name="TextFont">
<property name="sizePolicy">
<sizepolicy hsizetype="Ignored" vsizetype="Fixed">
@@ -252,14 +238,38 @@
</sizepolicy>
</property>
<property name="toolTip">
<string>The font to use for texts and dimensions</string>
<string>The font for texts, dimensions and labels</string>
</property>
</widget>
</item>
<item row="5" column="1">
<item row="2" column="0">
<widget class="QLabel" name="label_TextSize">
<property name="text">
<string>Font size</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="Gui::InputField" name="TextSize">
<property name="toolTip">
<string>The height for texts, dimension texts and label texts</string>
</property>
<property name="unit" stdset="0">
<string notr="true"/>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_LineSpacing">
<property name="text">
<string>Line spacing</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QDoubleSpinBox" name="LineSpacing">
<property name="toolTip">
<string>The spacing between different lines of text</string>
<string>The line spacing for multi-line texts and labels (relative to the font size)</string>
</property>
</widget>
</item>
@@ -271,29 +281,41 @@
<property name="title">
<string>Dimensions</string>
</property>
<layout class="QGridLayout" name="gridLayout_2" columnstretch="1,0" columnminimumwidth="0,120">
<layout class="QGridLayout" name="gridLayout_3" columnstretch="1,0" columnminimumwidth="0,120">
<item row="0" column="0">
<widget class="QLabel" name="label_6">
<widget class="QLabel" name="label_AnnoLineColor">
<property name="text">
<string>Arrow style</string>
</property>
</widget>
</item>
<item row="8" column="1">
<widget class="Gui::InputField" name="TextSpacing">
<property name="toolTip">
<string>The space between the text and the dimension line</string>
</property>
<property name="unit" stdset="0">
<string notr="true"/>
<string>Line and arrow color</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="ArrowStyle">
<property name="toolTip">
<string>The type of dimension arrows</string>
<widget class="Gui::ColorButton" name="AnnoLineColor">
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_AnnoLineWidth">
<property name="text">
<string>Line width</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QSpinBox" name="AnnoLineWidth">
<property name="suffix">
<string> px</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_ArrowStyle">
<property name="text">
<string>Arrow type</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QComboBox" name="ArrowStyle">
<item>
<property name="text">
<string>Dot</string>
@@ -321,44 +343,59 @@
</item>
</widget>
</item>
<item row="6" column="0">
<widget class="QLabel" name="label_17">
<item row="3" column="0">
<widget class="QLabel" name="label_ArrowSize">
<property name="text">
<string>Ext lines</string>
<string>Arrow size</string>
</property>
</widget>
</item>
<item row="1" column="1">
<item row="3" column="1">
<widget class="Gui::InputField" name="ArrowSize">
<property name="toolTip">
<string>The size of dimension arrows</string>
</property>
<property name="unit" stdset="0">
<string notr="true"/>
</property>
</widget>
</item>
<item row="9" column="1">
<item row="4" column="0">
<widget class="QLabel" name="label_ShowUnit">
<property name="text">
<string>Show unit</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QCheckBox" name="ShowUnit">
<property name="toolTip">
<string>If the unit suffix is shown on dimension texts or not</string>
</property>
<property name="layoutDirection">
<enum>Qt::RightToLeft</enum>
<string>If checked, a unit symbol is added to dimension texts</string>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="8" column="0">
<widget class="QLabel" name="label_9">
<item row="5" column="0">
<widget class="QLabel" name="label_UnitOverride">
<property name="text">
<string>Text spacing</string>
<string>Unit override</string>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QLineEdit" name="UnitOverride">
<property name="toolTip">
<string>The unit override for dimensions. Leave blank to use the current FreeCAD unit.</string>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QLabel" name="label_DimOvershoot">
<property name="text">
<string>Dim overshoot</string>
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="Gui::InputField" name="DimOvershoot">
<property name="toolTip">
<string>The distance the dimension line is extended past the extension lines</string>
@@ -368,34 +405,37 @@
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_8">
<item row="7" column="0">
<widget class="QLabel" name="label_ExtLines">
<property name="text">
<string>Arrow size</string>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="label_16">
<property name="text">
<string>Dim overshoot</string>
<string>Ext lines</string>
</property>
</widget>
</item>
<item row="7" column="1">
<widget class="Gui::InputField" name="ExtOvershoot">
<widget class="Gui::InputField" name="ExtLines">
<property name="toolTip">
<string>Length of the extension lines beyond the dimension line</string>
<string>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.</string>
</property>
<property name="unit" stdset="0">
<string notr="true"/>
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="Gui::InputField" name="ExtLines">
<item row="8" column="0">
<widget class="QLabel" name="label_ExtOvershoot">
<property name="text">
<string>Ext overshoot</string>
</property>
</widget>
</item>
<item row="8" column="1">
<widget class="Gui::InputField" name="ExtOvershoot">
<property name="toolTip">
<string>Length of the extension lines</string>
<string>The length of extension lines above the dimension line</string>
</property>
<property name="unit" stdset="0">
<string notr="true"/>
@@ -403,30 +443,19 @@
</widget>
</item>
<item row="9" column="0">
<widget class="QLabel" name="label_13">
<widget class="QLabel" name="label_TextSpacing">
<property name="text">
<string>Show unit</string>
<string>Text spacing</string>
</property>
</widget>
</item>
<item row="7" column="0">
<widget class="QLabel" name="label_18">
<property name="text">
<string>Ext overshoot</string>
</property>
</widget>
</item>
<item row="10" column="0">
<widget class="QLabel" name="label_14">
<property name="text">
<string>Unit override</string>
</property>
</widget>
</item>
<item row="10" column="1">
<widget class="QLineEdit" name="UnitOverride">
<item row="9" column="1">
<widget class="Gui::InputField" name="TextSpacing">
<property name="toolTip">
<string>The unit to use for dimensions. Leave blank to use current FreeCAD unit</string>
<string>The space between the dimension line and the dimension text</string>
</property>
<property name="unit" stdset="0">
<string notr="true"/>
</property>
</widget>
</item>
@@ -438,7 +467,7 @@
<item>
<widget class="QPushButton" name="applyButton">
<property name="toolTip">
<string>Apply above style to selected object(s)</string>
<string>Apply the above style to selected object(s)</string>
</property>
<property name="text">
<string>Selected</string>
@@ -452,7 +481,7 @@
<item>
<widget class="QPushButton" name="annotButton">
<property name="toolTip">
<string>Apply above style to all annotations (texts, dimensions and labels)</string>
<string>Apply the above style to all annotations (texts, dimensions and labels)</string>
</property>
<property name="text">
<string>Annotations</string>

View File

@@ -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())
## @}

View File

@@ -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

View File

@@ -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",