Draft: improve handling of anno DisplayMode and LineSpacing

* DisplayMode controlled by new pref DefaultAnnoDisplayMode. This replaces the old dimstyle pref.
* LineSpacing pref is now used when creating annotations. Will be added to prefs ui later.
* format_object no longer changes FontSize as this conflicted with the height parameter in the make_text function.
* make_text function updated.
This commit is contained in:
Roy-043
2023-11-27 12:50:11 +01:00
committed by Yorik van Havre
parent 5a4a358f13
commit 484bbf3807
9 changed files with 39 additions and 38 deletions

View File

@@ -143,7 +143,7 @@ such as &quot;Arial:Bold&quot;</string>
</size>
</property>
<property name="prefEntry" stdset="0">
<cstring>dimstyle</cstring>
<cstring>DefaultAnnoDisplayMode</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/Draft</cstring>

View File

@@ -113,7 +113,8 @@ class Text(gui_base_original.Creator):
_cmd = 'Draft.make_text'
_cmd += '('
_cmd += string + ', '
_cmd += 'placement=pl'
_cmd += 'placement=pl, '
_cmd += 'screen=None, height=None, line_spacing=None'
_cmd += ')'
_cmd_list = ['pl = FreeCAD.Placement()',
'pl.Rotation.Q = ' + rot,

View File

@@ -41,7 +41,7 @@ if App.GuiUp:
from draftviewproviders.view_text import ViewProviderText
def make_text(string, placement=None, screen=False, height=None):
def make_text(string, placement=None, screen=False, height=None, line_spacing=1):
"""Create a Text object containing the given list of strings.
The current color and text height and font specified in preferences
@@ -54,20 +54,26 @@ def make_text(string, placement=None, screen=False, height=None):
If it is a list, each element in the list represents a new text line.
placement: Base::Placement, Base::Vector3, or Base::Rotation, optional
It defaults to `None`.
Defaults to `None`.
If it is provided, it is the placement of the new text.
The input could be a full placement, just a vector indicating
the translation, or just a rotation.
screen: bool, optional
It defaults to `False`, in which case the text is placed in 3D space
oriented like any other object, on top of a given plane,
by the default the XY plane.
If it is `True`, the text will always face perpendicularly
to the camera direction, that is, it will be flat on the screen.
screen: bool or None, optional
Defaults to `False`.
If it is `True`, the DisplayMode is set to "Screen".
If it is `False`, it is set to "World".
If it is `None`, the DisplayMode depends on the current preferences.
height: float, optional
A height value for the text, in mm
height: float or None, optional
Defaults to `None`.
A height value for the text, in mm.
If it is `None` or zero, the FontSize depends on the current preferences.
line_spacing: float or None, optional
Defaults to 1.
The line spacing factor.
If it is `None` or zero, the LineSpacing depends on the current preferences.
Returns
-------
@@ -116,8 +122,7 @@ def make_text(string, placement=None, screen=False, height=None):
elif isinstance(placement, App.Rotation):
placement = App.Placement(App.Vector(), placement)
new_obj = doc.addObject("App::FeaturePython",
"Text")
new_obj = doc.addObject("App::FeaturePython", "Text")
Text(new_obj)
new_obj.Text = string
new_obj.Placement = placement
@@ -125,18 +130,19 @@ def make_text(string, placement=None, screen=False, height=None):
if App.GuiUp:
ViewProviderText(new_obj.ViewObject)
if not height: # zero or None
height = utils.get_param("textheight", 2)
new_obj.ViewObject.DisplayMode = "World"
if screen:
_msg("screen: {}".format(screen))
if screen is None:
# Keep value as set by viewprovider
pass
elif screen:
new_obj.ViewObject.DisplayMode = "Screen"
height *= 10
else:
new_obj.ViewObject.DisplayMode = "World"
new_obj.ViewObject.FontSize = height
new_obj.ViewObject.FontName = utils.get_param("textfont", "")
new_obj.ViewObject.LineSpacing = 1
if height: # Keep value as set by viewprovider if zero or None
new_obj.ViewObject.FontSize = height
if line_spacing: # Keep value as set by viewprovider if zero or None
new_obj.ViewObject.LineSpacing = line_spacing
gui_utils.format_object(new_obj)
gui_utils.select(new_obj)

View File

@@ -492,10 +492,7 @@ def format_object(target, origin=None):
tcol = (float(tcol[0]), float(tcol[1]), float(tcol[2]), 0.0)
fcol = (float(fcol[0]), float(fcol[1]), float(fcol[2]), 0.0)
lw = utils.getParam("linewidth",2)
fs = utils.getParam("textheight",0.20)
if not origin or not hasattr(origin, 'ViewObject'):
if "FontSize" in obrep.PropertiesList:
obrep.FontSize = fs
if "TextColor" in obrep.PropertiesList:
obrep.TextColor = tcol
if "LineWidth" in obrep.PropertiesList:

View File

@@ -173,7 +173,7 @@ def get_param_type(param):
"precision", "defaultWP", "snapRange", "gridEvery",
"linewidth", "modconstrain", "modsnap",
"maxSnapEdges", "modalt", "HatchPatternResolution",
"snapStyle", "dimstyle", "gridSize", "gridTransparency"):
"snapStyle", "DefaultAnnoDisplayMode", "gridSize", "gridTransparency"):
return "int"
elif param in ("constructiongroupname", "textfont",
"patternFile", "snapModes",
@@ -181,7 +181,8 @@ def get_param_type(param):
"labeltype", "gridSpacing") or "inCommandShortcut" in param:
return "string"
elif param in ("textheight", "arrowsize", "extlines", "dimspacing",
"dimovershoot", "extovershoot", "HatchPatternSize"):
"dimovershoot", "extovershoot", "HatchPatternSize",
"LineSpacing"):
return "float"
elif param in ("selectBaseObjects", "alwaysSnap", "grid",
"fillmode", "maxSnap", "DimShowLine",

View File

@@ -262,10 +262,6 @@ class ViewProviderDimensionBase(ViewProviderDraftAnnotation):
_tip)
vobj.ShowLine = utils.get_param("DimShowLine", True)
def getDefaultDisplayMode(self):
"""Return the default display mode."""
return ["World", "Screen"][utils.get_param("dimstyle", 0)]
def getIcon(self):
"""Return the path to the icon used by the viewprovider."""
return ":/icons/Draft_Dimension_Tree.svg"
@@ -550,7 +546,7 @@ class ViewProviderLinearDimension(ViewProviderDimensionBase):
try:
m = vobj.DisplayMode
except AssertionError:
m = ["World", "Screen"][utils.get_param("dimstyle", 0)]
m = ["World", "Screen"][utils.get_param("DefaultAnnoDisplayMode", 0)]
if m == "Screen":
offset = offset.negative()
@@ -975,7 +971,7 @@ class ViewProviderAngularDimension(ViewProviderDimensionBase):
try:
m = vobj.DisplayMode
except AssertionError:
m = ["World", "Screen"][utils.get_param("dimstyle", 0)]
m = ["World", "Screen"][utils.get_param("DefaultAnnoDisplayMode", 0)]
# Set the arc
first = self.circle.FirstParameter

View File

@@ -183,7 +183,7 @@ class ViewProviderDraftAnnotation(object):
def getDefaultDisplayMode(self):
"""Return the default display mode."""
return "World"
return ["World", "Screen"][utils.get_param("DefaultAnnoDisplayMode", 0)]
def setDisplayMode(self, mode):
"""Return the saved display mode."""

View File

@@ -90,7 +90,7 @@ class ViewProviderLabel(ViewProviderDraftAnnotation):
"LineSpacing",
"Text",
_tip)
vobj.LineSpacing = 1.0
vobj.LineSpacing = utils.get_param("LineSpacing", 1)
def set_graphics_properties(self, vobj, properties):
"""Set graphics properties only if they don't already exist."""

View File

@@ -66,7 +66,7 @@ class ViewProviderText(ViewProviderDraftAnnotation):
"LineSpacing",
"Text",
_tip)
vobj.LineSpacing = 1.0
vobj.LineSpacing = utils.get_param("LineSpacing", 1)
def getIcon(self):
"""Return the path to the icon used by the view provider."""