Draft: Fix and improve Draft_AnnotationStyleEditor (#8207)
* Draft: Fix and improve Draft_AnnotationStyleEditor * Draft: Fix and improve Draft_AnnotationStyleEditor 2
This commit is contained in:
@@ -91,7 +91,9 @@ from draftutils.utils import (string_encode_coin,
|
||||
svg_patterns,
|
||||
svgpatterns,
|
||||
get_rgb,
|
||||
getrgb)
|
||||
getrgb,
|
||||
argb_to_rgba,
|
||||
rgba_to_argb)
|
||||
|
||||
from draftfunctions.svg import (get_svg,
|
||||
getSVG)
|
||||
|
||||
@@ -193,40 +193,57 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="toolTip">
|
||||
<string>Font size in the system units</string>
|
||||
<string>The font size in system units</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Font size</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<item row="1" column="1">
|
||||
<widget class="Gui::InputField" name="FontSize">
|
||||
<property name="toolTip">
|
||||
<string>Font size in the system units</string>
|
||||
<string>The font size in system units</string>
|
||||
</property>
|
||||
<property name="quantity" stdset="0">
|
||||
<double>12.000000000000000</double>
|
||||
<property name="unit" stdset="0">
|
||||
<string notr="true"/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="toolTip">
|
||||
<string>Line spacing in system units</string>
|
||||
<string>The line spacing (relative to the font size)</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Line spacing</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="1">
|
||||
<item row="2" column="1">
|
||||
<widget class="QDoubleSpinBox" name="LineSpacing">
|
||||
<property name="value">
|
||||
<double>1.000000000000000</double>
|
||||
<property name="toolTip">
|
||||
<string>The line spacing (relative to the font size)</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="label_16">
|
||||
<property name="toolTip">
|
||||
<string>The color of texts, dimension texts and label texts</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Text color</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="Gui::ColorButton" name="TextColor">
|
||||
<property name="toolTip">
|
||||
<string>The color of texts, dimension texts and label texts</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@@ -254,12 +271,6 @@
|
||||
<property name="toolTip">
|
||||
<string>A multiplier factor that affects the size of texts and markers</string>
|
||||
</property>
|
||||
<property name="decimals">
|
||||
<number>4</number>
|
||||
</property>
|
||||
<property name="value">
|
||||
<double>1.000000000000000</double>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
@@ -317,9 +328,6 @@
|
||||
<property name="toolTip">
|
||||
<string>The number of decimals to show for dimension values</string>
|
||||
</property>
|
||||
<property name="value">
|
||||
<number>2</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
@@ -328,7 +336,7 @@
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox_4">
|
||||
<property name="title">
|
||||
<string>Line and arrows</string>
|
||||
<string>Lines and arrows</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_3">
|
||||
<item row="0" column="0">
|
||||
@@ -337,12 +345,12 @@
|
||||
<string>If it is checked it will display the dimension line</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Show lines</string>
|
||||
<string>Show line</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QCheckBox" name="ShowLines">
|
||||
<widget class="QCheckBox" name="ShowLine">
|
||||
<property name="toolTip">
|
||||
<string>If it is checked it will display the dimension line</string>
|
||||
</property>
|
||||
@@ -360,7 +368,7 @@
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_14">
|
||||
<property name="toolTip">
|
||||
<string>The width of the dimension lines</string>
|
||||
<string>The width of the lines</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Line width</string>
|
||||
@@ -370,51 +378,24 @@
|
||||
<item row="2" column="1">
|
||||
<widget class="QSpinBox" name="LineWidth">
|
||||
<property name="toolTip">
|
||||
<string>The width of the dimension lines</string>
|
||||
<string>The width of the lines</string>
|
||||
</property>
|
||||
<property name="suffix">
|
||||
<string>px</string>
|
||||
</property>
|
||||
<property name="value">
|
||||
<number>1</number>
|
||||
<string> px</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="label_15">
|
||||
<property name="toolTip">
|
||||
<string>The color of dimension lines, arrows and texts</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Line / text color</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="Gui::ColorButton" name="LineColor">
|
||||
<property name="toolTip">
|
||||
<string>The color of dimension lines, arrows and texts</string>
|
||||
</property>
|
||||
<property name="color">
|
||||
<color>
|
||||
<red>0</red>
|
||||
<green>0</green>
|
||||
<blue>0</blue>
|
||||
</color>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
<widget class="QLabel" name="label_9">
|
||||
<property name="toolTip">
|
||||
<string>The type of arrows or markers to use at the end of dimension lines</string>
|
||||
<string>The type of arrows or markers to use for dimensions and labels</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Arrow type</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="1">
|
||||
<item row="3" column="1">
|
||||
<widget class="QComboBox" name="ArrowType">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
|
||||
@@ -429,7 +410,7 @@
|
||||
</size>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>The type of arrows or markers to use at the end of dimension lines</string>
|
||||
<string>The type of arrows or markers to use for dimensions and labels</string>
|
||||
</property>
|
||||
<item>
|
||||
<property name="text">
|
||||
@@ -458,30 +439,47 @@
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="0">
|
||||
<item row="4" column="0">
|
||||
<widget class="QLabel" name="label_8">
|
||||
<property name="toolTip">
|
||||
<string>The size of the dimension arrows or markers in system units</string>
|
||||
<string>The size of the arrows or markers in system units</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Arrow size</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="1">
|
||||
<item row="4" column="1">
|
||||
<widget class="Gui::InputField" name="ArrowSize">
|
||||
<property name="toolTip">
|
||||
<string>The size of the dimension arrows or markers in system units</string>
|
||||
<string>The size of the arrows or markers in system units</string>
|
||||
</property>
|
||||
<property name="quantity" stdset="0">
|
||||
<double>5.000000000000000</double>
|
||||
<property name="unit" stdset="0">
|
||||
<string notr="true"/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="0">
|
||||
<widget class="QLabel" name="label_15">
|
||||
<property name="toolTip">
|
||||
<string>The color of lines and arrows</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Line and arrow color</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="1">
|
||||
<widget class="Gui::ColorButton" name="LineColor">
|
||||
<property name="toolTip">
|
||||
<string>The color of lines and arrows</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="0">
|
||||
<widget class="QLabel" name="label_10">
|
||||
<property name="toolTip">
|
||||
<string>The distance that the dimension line is additionally extended</string>
|
||||
<string>The distance the dimension line is additionally extended</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Dimension overshoot</string>
|
||||
@@ -489,12 +487,12 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="1">
|
||||
<widget class="Gui::InputField" name="DimensionOvershoot">
|
||||
<widget class="Gui::InputField" name="DimOvershoot">
|
||||
<property name="toolTip">
|
||||
<string>The distance that the dimension line is additionally extended</string>
|
||||
<string>The distance the dimension line is additionally extended</string>
|
||||
</property>
|
||||
<property name="quantity" stdset="0">
|
||||
<double>1.000000000000000</double>
|
||||
<property name="unit" stdset="0">
|
||||
<string notr="true"/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@@ -509,19 +507,19 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item row="7" column="1">
|
||||
<widget class="Gui::InputField" name="ExtensionLines">
|
||||
<widget class="Gui::InputField" name="ExtLines">
|
||||
<property name="toolTip">
|
||||
<string>The length of the extension lines</string>
|
||||
</property>
|
||||
<property name="quantity" stdset="0">
|
||||
<double>10.000000000000000</double>
|
||||
<property name="unit" stdset="0">
|
||||
<string notr="true"/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="8" column="0">
|
||||
<widget class="QLabel" name="label_12">
|
||||
<property name="toolTip">
|
||||
<string>The distance that the extension lines are additionally extended beyond the dimension line</string>
|
||||
<string>The distance the extension lines are additionally extended beyond the dimension line</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Extension overshoot</string>
|
||||
@@ -529,12 +527,12 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item row="8" column="1">
|
||||
<widget class="Gui::InputField" name="ExtensionOvershoot">
|
||||
<widget class="Gui::InputField" name="ExtOvershoot">
|
||||
<property name="toolTip">
|
||||
<string>The distance that the extension lines are additionally extended beyond the dimension line</string>
|
||||
<string>The distance the extension lines are additionally extended beyond the dimension line</string>
|
||||
</property>
|
||||
<property name="quantity" stdset="0">
|
||||
<double>1.000000000000000</double>
|
||||
<property name="unit" stdset="0">
|
||||
<string notr="true"/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
||||
@@ -37,7 +37,6 @@ import draftutils.utils as utils
|
||||
import draftfunctions.svgtext as svgtext
|
||||
|
||||
from draftfunctions.svgshapes import get_proj, get_circle, get_path
|
||||
from draftutils.utils import param
|
||||
from draftutils.messages import _wrn, _err
|
||||
|
||||
# Delay import of module until first use because it is heavy
|
||||
@@ -51,6 +50,7 @@ DraftGeomUtils = lz.LazyLoader("DraftGeomUtils", globals(), "DraftGeomUtils")
|
||||
|
||||
def get_line_style(line_style, scale):
|
||||
"""Return a linestyle scaled by a factor."""
|
||||
param = App.ParamGet("User parameter:BaseApp/Preferences/Mod/Draft")
|
||||
style = None
|
||||
|
||||
if line_style == "Dashed":
|
||||
|
||||
@@ -34,7 +34,6 @@ import FreeCAD as App
|
||||
import DraftVecUtils
|
||||
import draftutils.utils as utils
|
||||
|
||||
from draftutils.utils import param
|
||||
from draftutils.messages import _msg, _wrn
|
||||
|
||||
# Delay import of module until first use because it is heavy
|
||||
@@ -90,6 +89,7 @@ def getProj(vec, plane=None):
|
||||
|
||||
def get_discretized(edge, plane):
|
||||
"""Get a discretized edge on a plane."""
|
||||
param = App.ParamGet("User parameter:BaseApp/Preferences/Mod/Draft")
|
||||
pieces = param.GetFloat("svgDiscretization", 10.0)
|
||||
|
||||
if pieces == 0:
|
||||
|
||||
@@ -34,8 +34,8 @@ import FreeCAD as App
|
||||
import FreeCADGui as Gui
|
||||
import draftguitools.gui_base as gui_base
|
||||
|
||||
from FreeCAD import Units as U
|
||||
from draftutils.translate import translate
|
||||
from draftutils import utils
|
||||
from draftutils.utils import ANNOTATION_STYLE as DEFAULT
|
||||
|
||||
param = App.ParamGet("User parameter:BaseApp/Preferences/Mod/Draft")
|
||||
@@ -69,6 +69,7 @@ class AnnotationStyleEditor(gui_base.GuiCommandSimplest):
|
||||
self.doc = None
|
||||
self.styles = {}
|
||||
self.renamed = {}
|
||||
self.current_style = None
|
||||
self.form = None
|
||||
|
||||
def GetResources(self):
|
||||
@@ -85,8 +86,9 @@ class AnnotationStyleEditor(gui_base.GuiCommandSimplest):
|
||||
The document attribute is set here by the parent class.
|
||||
"""
|
||||
super(AnnotationStyleEditor, self).Activated()
|
||||
# reset rename table
|
||||
# reset rename table and current style
|
||||
self.renamed = {}
|
||||
self.current_style = None
|
||||
|
||||
# load dialog
|
||||
ui_file = ":/ui/dialog_AnnotationStyleEditor.ui"
|
||||
@@ -123,16 +125,10 @@ class AnnotationStyleEditor(gui_base.GuiCommandSimplest):
|
||||
self.form.pushButtonRename.clicked.connect(self.on_rename)
|
||||
self.form.pushButtonImport.clicked.connect(self.on_import)
|
||||
self.form.pushButtonExport.clicked.connect(self.on_export)
|
||||
for attr in DEFAULT.keys():
|
||||
control = getattr(self.form, attr)
|
||||
for signal in ("clicked", "textChanged",
|
||||
"valueChanged", "stateChanged",
|
||||
"currentIndexChanged"):
|
||||
if hasattr(control, signal):
|
||||
getattr(control, signal).connect(self.update_style)
|
||||
break
|
||||
self.form.buttonBox.accepted.connect(self.update_style)
|
||||
|
||||
# show editor dialog
|
||||
self.fill_editor()
|
||||
result = self.form.exec_()
|
||||
|
||||
# process if OK was clicked
|
||||
@@ -149,7 +145,7 @@ class AnnotationStyleEditor(gui_base.GuiCommandSimplest):
|
||||
meta = self.doc.Meta
|
||||
for key, value in meta.items():
|
||||
if key.startswith("Draft_Style_"):
|
||||
styles[key[12:]] = json.loads(value)
|
||||
styles[key[12:]] = self.repair_style(json.loads(value))
|
||||
return styles
|
||||
|
||||
def save_meta(self, styles):
|
||||
@@ -195,16 +191,14 @@ class AnnotationStyleEditor(gui_base.GuiCommandSimplest):
|
||||
if vobj.AnnotationStyle in styles.keys():
|
||||
if vobj.AnnotationStyle in changedstyles:
|
||||
# the style has changed
|
||||
for attr, attrvalue in styles[vobj.AnnotationStyle].items():
|
||||
for attr, value in styles[vobj.AnnotationStyle].items():
|
||||
if hasattr(vobj, attr):
|
||||
try:
|
||||
getattr(vobj,attr).setValue(attrvalue)
|
||||
except Exception:
|
||||
try:
|
||||
setattr(vobj,attr,attrvalue)
|
||||
except Exception:
|
||||
unitvalue = U.Quantity(attrvalue, U.Length).Value
|
||||
setattr(vobj,attr,unitvalue)
|
||||
if vobj.getTypeIdOfProperty(attr) == "App::PropertyColor":
|
||||
value = value & 0xFFFFFF00
|
||||
setattr(vobj, attr, value)
|
||||
except:
|
||||
pass
|
||||
else:
|
||||
# the style has been removed
|
||||
vobj.AnnotationStyle = ""
|
||||
@@ -212,35 +206,46 @@ class AnnotationStyleEditor(gui_base.GuiCommandSimplest):
|
||||
|
||||
def on_style_changed(self, index):
|
||||
"""Execute as a callback when the styles combobox changes."""
|
||||
if index <= 1:
|
||||
if index == 0:
|
||||
# nothing happens
|
||||
self.form.pushButtonDelete.setEnabled(False)
|
||||
self.form.pushButtonRename.setEnabled(False)
|
||||
self.fill_editor(None)
|
||||
if index == 1:
|
||||
elif index == 1:
|
||||
# Add new... entry
|
||||
reply = QtGui.QInputDialog.getText(None,
|
||||
"Create new style",
|
||||
"Style name:")
|
||||
if reply[1]:
|
||||
# OK or Enter pressed
|
||||
name = reply[0]
|
||||
if name in self.styles:
|
||||
reply = QtGui.QMessageBox.information(None,
|
||||
"Style exists",
|
||||
"This style name already exists")
|
||||
name = reply[0].strip()
|
||||
if name == "":
|
||||
QtGui.QMessageBox.information(None,
|
||||
"Style name required",
|
||||
"No style name specified")
|
||||
self.form.comboBoxStyles.setCurrentIndex(0)
|
||||
elif name in self.styles:
|
||||
QtGui.QMessageBox.information(None,
|
||||
"Style exists",
|
||||
"This style name already exists")
|
||||
self.form.comboBoxStyles.setCurrentIndex(0)
|
||||
else:
|
||||
# create new default style
|
||||
self.styles[name] = {}
|
||||
for key, val in DEFAULT.items():
|
||||
self.styles[name][key] = val[1]
|
||||
# create new style from current editor values
|
||||
self.styles[name] = self.get_editor_values()
|
||||
self.form.comboBoxStyles.addItem(name)
|
||||
self.form.comboBoxStyles.setCurrentIndex(self.form.comboBoxStyles.count() - 1)
|
||||
elif index > 1:
|
||||
self.current_style = name
|
||||
else:
|
||||
# Cancel or Escape pressed
|
||||
self.form.comboBoxStyles.setCurrentIndex(0)
|
||||
else:
|
||||
# Existing style
|
||||
if self.current_style is not None:
|
||||
# save editor values to current style first
|
||||
self.styles[self.current_style] = self.get_editor_values()
|
||||
self.current_style = self.form.comboBoxStyles.itemText(index)
|
||||
self.fill_editor(self.current_style)
|
||||
self.form.pushButtonDelete.setEnabled(True)
|
||||
self.form.pushButtonRename.setEnabled(True)
|
||||
self.fill_editor(self.form.comboBoxStyles.itemText(index))
|
||||
|
||||
def on_delete(self):
|
||||
"""Execute as a callback when the delete button is pressed."""
|
||||
@@ -282,54 +287,69 @@ class AnnotationStyleEditor(gui_base.GuiCommandSimplest):
|
||||
self.styles[newname] = value
|
||||
self.renamed[style] = newname
|
||||
|
||||
|
||||
def on_import(self):
|
||||
"""imports styles from a json file"""
|
||||
"""Import styles from a json file."""
|
||||
filename = QtGui.QFileDialog.getOpenFileName(
|
||||
QtGui.QApplication.activeWindow(),
|
||||
translate("draft","Open styles file"),
|
||||
None,
|
||||
translate("draft","JSON file (*.json)"))
|
||||
if filename and filename[0]:
|
||||
nstyles = {}
|
||||
with open(filename[0]) as f:
|
||||
nstyles = json.load(f)
|
||||
if nstyles:
|
||||
self.styles.update(nstyles)
|
||||
l1 = self.form.comboBoxStyles.itemText(0)
|
||||
l2 = self.form.comboBoxStyles.itemText(1)
|
||||
self.form.comboBoxStyles.clear()
|
||||
self.form.comboBoxStyles.addItem(l1)
|
||||
self.form.comboBoxStyles.addItem(l2)
|
||||
for style in self.styles.keys():
|
||||
for key, val in json.load(f).items():
|
||||
nstyles[key] = self.repair_style(val)
|
||||
if nstyles:
|
||||
self.styles.update(nstyles)
|
||||
for style in self.styles.keys():
|
||||
if self.form.comboBoxStyles.findText(style) == -1:
|
||||
self.form.comboBoxStyles.addItem(style)
|
||||
print("Styles updated from "+filename[0])
|
||||
|
||||
self.fill_editor(self.current_style) # The current style may have changed.
|
||||
print("Styles updated from " + filename[0])
|
||||
|
||||
def on_export(self):
|
||||
"""exports styles to a json file"""
|
||||
"""Export styles to a json file."""
|
||||
filename = QtGui.QFileDialog.getSaveFileName(
|
||||
QtGui.QApplication.activeWindow(),
|
||||
translate("draft","Save styles file"),
|
||||
None,
|
||||
translate("draft","JSON file (*.json)"))
|
||||
if filename and filename[0]:
|
||||
self.update_style()
|
||||
with open(filename[0],"w") as f:
|
||||
json.dump(self.styles,f,indent=4)
|
||||
print("Styles saved to "+filename[0])
|
||||
print("Styles saved to " + filename[0])
|
||||
|
||||
def repair_style(self, style):
|
||||
"""Repair a V0.19 or V0.20 style.
|
||||
|
||||
def fill_editor(self, style):
|
||||
Some properties were missing or misspelled.
|
||||
Some float values were wrongly stored as strings.
|
||||
"""
|
||||
new = {}
|
||||
for key, val in DEFAULT.items():
|
||||
if style.get(key) is None:
|
||||
new[key] = val[1]
|
||||
elif type(style[key]) == type(val[1]):
|
||||
new[key] = style[key]
|
||||
elif isinstance(style[key], str):
|
||||
new[key] = float(style[key].replace(",", "."))
|
||||
else:
|
||||
new[key] = val[1]
|
||||
return new
|
||||
|
||||
def fill_editor(self, style=None):
|
||||
"""Fill the editor fields with the contents of a style."""
|
||||
if style is None:
|
||||
if style is None or style == "":
|
||||
style = {}
|
||||
for key, val in DEFAULT.items():
|
||||
style[key] = val[1]
|
||||
|
||||
if not isinstance(style, dict):
|
||||
if style in self.styles:
|
||||
style = self.styles[style]
|
||||
else:
|
||||
print("debug: unable to fill dialog from style", style)
|
||||
elif isinstance(style, dict):
|
||||
pass
|
||||
elif isinstance(style, str) and style in self.styles:
|
||||
style = self.styles[style]
|
||||
else:
|
||||
print("debug: unable to fill dialog from style", style)
|
||||
|
||||
for key, value in style.items():
|
||||
control = getattr(self.form, key)
|
||||
@@ -338,42 +358,52 @@ class AnnotationStyleEditor(gui_base.GuiCommandSimplest):
|
||||
elif DEFAULT[key][0] == "font":
|
||||
control.setCurrentFont(QtGui.QFont(value))
|
||||
elif DEFAULT[key][0] == "color":
|
||||
r = ((value >> 24) & 0xFF) / 255.0
|
||||
g = ((value >> 16) & 0xFF) / 255.0
|
||||
b = ((value >> 8) & 0xFF) / 255.0
|
||||
color = QtGui.QColor.fromRgbF(r, g, b)
|
||||
color = QtGui.QColor(utils.rgba_to_argb(value))
|
||||
control.setProperty("color", color)
|
||||
elif DEFAULT[key][0] in ["int", "float"]:
|
||||
elif DEFAULT[key][0] == "int":
|
||||
control.setValue(value)
|
||||
elif DEFAULT[key][0] == "float":
|
||||
if hasattr(control, "setText"):
|
||||
control.setText(App.Units.Quantity(value, App.Units.Length).UserString)
|
||||
else:
|
||||
control.setValue(value)
|
||||
elif DEFAULT[key][0] == "bool":
|
||||
control.setChecked(value)
|
||||
elif DEFAULT[key][0] == "index":
|
||||
control.setCurrentIndex(value)
|
||||
|
||||
def update_style(self, arg=None):
|
||||
def update_style(self):
|
||||
"""Update the current style with the values from the editor."""
|
||||
index = self.form.comboBoxStyles.currentIndex()
|
||||
if index > 1:
|
||||
values = {}
|
||||
style = self.form.comboBoxStyles.itemText(index)
|
||||
for key in DEFAULT.keys():
|
||||
control = getattr(self.form, key)
|
||||
if DEFAULT[key][0] == "str":
|
||||
values[key] = control.text()
|
||||
elif DEFAULT[key][0] == "font":
|
||||
values[key] = control.currentFont().family()
|
||||
elif DEFAULT[key][0] == "color":
|
||||
values[key] = control.property("color").rgb() << 8
|
||||
elif DEFAULT[key][0] in ["int", "float"]:
|
||||
self.styles[style] = self.get_editor_values()
|
||||
|
||||
def get_editor_values(self):
|
||||
values = {}
|
||||
for key in DEFAULT.keys():
|
||||
control = getattr(self.form, key)
|
||||
if DEFAULT[key][0] == "str":
|
||||
values[key] = control.text()
|
||||
elif DEFAULT[key][0] == "font":
|
||||
values[key] = control.currentFont().family()
|
||||
elif DEFAULT[key][0] == "color":
|
||||
values[key] = utils.argb_to_rgba(control.property("color").rgba())
|
||||
elif DEFAULT[key][0] == "int":
|
||||
values[key] = control.value()
|
||||
elif DEFAULT[key][0] == "float":
|
||||
if hasattr(control, "setText"):
|
||||
values[key] = App.Units.Quantity(control.text()).Value
|
||||
else:
|
||||
values[key] = control.value()
|
||||
elif DEFAULT[key][0] == "bool":
|
||||
values[key] = control.isChecked()
|
||||
elif DEFAULT[key][0] == "index":
|
||||
values[key] = control.currentIndex()
|
||||
self.styles[style] = values
|
||||
elif DEFAULT[key][0] == "bool":
|
||||
values[key] = control.isChecked()
|
||||
elif DEFAULT[key][0] == "index":
|
||||
values[key] = control.currentIndex()
|
||||
return values
|
||||
|
||||
def get_annotations(self):
|
||||
"""Get all the objects that support annotation styles."""
|
||||
"""Get all objects that support annotation styles."""
|
||||
users = []
|
||||
for obj in self.doc.Objects:
|
||||
vobj = obj.ViewObject
|
||||
|
||||
@@ -53,27 +53,29 @@ if App.GuiUp:
|
||||
# The module is used to prevent complaints from code checkers (flake8)
|
||||
True if Draft_rc else False
|
||||
|
||||
param = App.ParamGet("User parameter:BaseApp/Preferences/Mod/Draft")
|
||||
|
||||
ARROW_TYPES = ["Dot", "Circle", "Arrow", "Tick", "Tick-2"]
|
||||
arrowtypes = ARROW_TYPES
|
||||
|
||||
param_draft = App.ParamGet("User parameter:BaseApp/Preferences/Mod/Draft")
|
||||
param_view = App.ParamGet("User parameter:BaseApp/Preferences/View")
|
||||
|
||||
ANNOTATION_STYLE = {
|
||||
"FontName": ("font", param.GetString("textfont", "Sans")),
|
||||
"FontSize": ("str", str(param.GetFloat("textheight", 100))),
|
||||
"LineSpacing": ("float", 1),
|
||||
"FontName": ("font", param_draft.GetString("textfont", "Sans")),
|
||||
"FontSize": ("float", param_draft.GetFloat("textheight", 100)),
|
||||
"LineSpacing": ("float", param_draft.GetFloat("LineSpacing", 1)),
|
||||
"TextColor": ("color", param_draft.GetUnsigned("DefaultTextColor", 255)),
|
||||
"ScaleMultiplier": ("float", 1),
|
||||
"ShowUnit": ("bool", False),
|
||||
"UnitOverride": ("str", ""),
|
||||
"Decimals": ("int", 2),
|
||||
"ShowLines": ("bool", True),
|
||||
"LineWidth": ("int", param.GetInt("linewidth", 1)),
|
||||
"LineColor": ("color", param.GetInt("color", 255)),
|
||||
"ArrowType": ("index", param.GetInt("dimsymbol", 0)),
|
||||
"ArrowSize": ("str", str(param.GetFloat("arrowsize", 20))),
|
||||
"DimensionOvershoot": ("str", str(param.GetFloat("dimovershoot", 20))),
|
||||
"ExtensionLines": ("str", str(param.GetFloat("extlines", 300))),
|
||||
"ExtensionOvershoot": ("str", str(param.GetFloat("extovershoot", 20))),
|
||||
"ShowUnit": ("bool", param_draft.GetBool("showUnit", True)),
|
||||
"UnitOverride": ("str", param_draft.GetString("overrideUnit", "")),
|
||||
"Decimals": ("int", param_draft.GetInt("dimPrecision", 2)),
|
||||
"ShowLine": ("bool", True),
|
||||
"LineWidth": ("int", param_view.GetInt("DefaultShapeLineWidth", 1)),
|
||||
"ArrowType": ("index", param_draft.GetInt("dimsymbol", 0)),
|
||||
"ArrowSize": ("float", param_draft.GetFloat("arrowsize", 20)),
|
||||
"LineColor": ("color", param_view.GetUnsigned("DefaultShapeLineColor", 255)),
|
||||
"DimOvershoot": ("float", param_draft.GetFloat("dimovershoot", 20)),
|
||||
"ExtLines": ("float", param_draft.GetFloat("extlines", 300)),
|
||||
"ExtOvershoot": ("float", param_draft.GetFloat("extovershoot", 20)),
|
||||
}
|
||||
|
||||
|
||||
@@ -797,8 +799,10 @@ def get_rgb(color, testbw=True):
|
||||
|
||||
Parameters
|
||||
----------
|
||||
color : list or tuple with RGB values
|
||||
The values must be in the 0.0-1.0 range.
|
||||
testwb : bool (default = True)
|
||||
pure white will be converted into pure black
|
||||
Pure white will be converted into pure black.
|
||||
"""
|
||||
r = str(hex(int(color[0]*255)))[2:].zfill(2)
|
||||
g = str(hex(int(color[1]*255)))[2:].zfill(2)
|
||||
@@ -815,6 +819,29 @@ def get_rgb(color, testbw=True):
|
||||
getrgb = get_rgb
|
||||
|
||||
|
||||
def argb_to_rgba(color):
|
||||
"""Change byte order of a 4 byte color int from ARGB (Qt) to RGBA (FreeCAD).
|
||||
|
||||
Alpha in both integers is always 255.
|
||||
Alpha in color properties, although ignored, is always zero however.
|
||||
|
||||
Usage:
|
||||
|
||||
freecad_int = argb_to_rgba(qt_int)
|
||||
FreeCAD.ParamGet("User parameter:BaseApp/Preferences/View")\
|
||||
.SetUnsigned("DefaultShapeColor", freecad_int)
|
||||
|
||||
obj.ViewObject.ShapeColor = freecad_int & 0xFFFFFF00
|
||||
"""
|
||||
return ((color & 0xFFFFFF) << 8) + ((color & 0xFF000000) >> 24)
|
||||
|
||||
|
||||
def rgba_to_argb(color):
|
||||
"""Change byte order of a 4 byte color int from RGBA (FreeCAD) to ARGB (Qt).
|
||||
"""
|
||||
return ((color & 0xFFFFFF00) >> 8) + ((color & 0xFF) << 24)
|
||||
|
||||
|
||||
def filter_objects_for_modifiers(objects, isCopied=False):
|
||||
filteredObjects = []
|
||||
for obj in objects:
|
||||
|
||||
@@ -217,18 +217,16 @@ class ViewProviderDraftAnnotation(object):
|
||||
style = styles[vobj.AnnotationStyle]
|
||||
for visprop in style.keys():
|
||||
if visprop in properties:
|
||||
try:
|
||||
getattr(vobj, visprop).setValue(style[visprop])
|
||||
_msg("setValue: "
|
||||
"'{}', '{}'".format(visprop,
|
||||
style[visprop]))
|
||||
except AttributeError:
|
||||
setattr(vobj, visprop, style[visprop])
|
||||
_msg("setattr: "
|
||||
"'{}', '{}'".format(visprop,
|
||||
style[visprop]))
|
||||
# make property read-only
|
||||
vobj.setPropertyStatus(visprop, 'ReadOnly')
|
||||
vobj.setPropertyStatus(visprop, "ReadOnly")
|
||||
value = style[visprop]
|
||||
try:
|
||||
if vobj.getTypeIdOfProperty(visprop) == "App::PropertyColor":
|
||||
value = value & 0xFFFFFF00
|
||||
setattr(vobj, visprop, value)
|
||||
_msg("setattr: '{}', '{}'".format(visprop, value))
|
||||
except:
|
||||
pass
|
||||
|
||||
def execute(self, vobj):
|
||||
"""Execute when the object is created or recomputed."""
|
||||
|
||||
Reference in New Issue
Block a user