Draft: move the convertDraftTexts function to make_text

The old `convertDraftTexts` function was moved from the `Draft.py`
module to the `draftutils.utils` module; however, here it is
not possible to use because the `makeText` function
is not accessible. Therefore, the function is moved to
`draftmake.make_text`.
This commit is contained in:
vocx-fc
2020-06-25 20:30:40 -05:00
committed by Yorik van Havre
parent fbfe821e8c
commit ec1a720bfb
3 changed files with 67 additions and 36 deletions

View File

@@ -78,9 +78,6 @@ from DraftLayer import Layer as _VisGroup
from DraftLayer import ViewProviderLayer as _ViewProviderVisGroup
from DraftLayer import makeLayer
from draftutils.utils import convert_draft_texts
from draftutils.utils import convertDraftTexts
# ---------------------------------------------------------------------------
# General functions
# ---------------------------------------------------------------------------
@@ -416,7 +413,9 @@ from draftobjects.text import (Text,
DraftText)
from draftmake.make_text import (make_text,
makeText)
makeText,
convert_draft_texts,
convertDraftTexts)
if FreeCAD.GuiUp:
from draftviewproviders.view_text import (ViewProviderText,

View File

@@ -154,3 +154,67 @@ def makeText(stringlist, point=App.Vector(0, 0, 0), screen=False):
utils.use_instead("make_text")
return make_text(stringlist, point, screen)
def convert_draft_texts(textslist=None):
"""Convert the given Annotation to a Draft text.
In the past, the `Draft Text` object didn't exist; text objects
were of type `App::Annotation`. This function was introduced
to convert those older objects to a `Draft Text` scripted object.
This function was already present at splitting time during v0.19.
Parameters
----------
textslist: list of objects, optional
It defaults to `None`.
A list containing `App::Annotation` objects or a single of these
objects.
If it is `None` it will convert all objects in the current document.
"""
_name = "convert_draft_texts"
utils.print_header(_name, "Convert Draft texts")
found, doc = utils.find_doc(App.activeDocument())
if not found:
_err(_tr("No active document. Aborting."))
return None
if not textslist:
textslist = list()
for obj in doc.Objects:
if obj.TypeId == "App::Annotation":
textslist.append(obj)
if not isinstance(textslist, list):
textslist = [textslist]
to_delete = []
for obj in textslist:
label = obj.Label
obj.Label = label + ".old"
# Create a new Draft Text object
new_obj = make_text(obj.LabelText, placement=obj.Position)
new_obj.Label = label
to_delete.append(obj)
# Move the new object to the group which contained the old object
for in_obj in obj.InList:
if in_obj.isDerivedFrom("App::DocumentObjectGroup"):
if obj in in_obj.Group:
group = in_obj.Group
group.append(new_obj)
in_obj.Group = group
for obj in to_delete:
doc.removeObject(obj.Name)
def convertDraftTexts(textslist=[]):
"""Convert Text. DEPRECATED. Use 'convert_draft_texts'."""
utils.use_instead("convert_draft_texts")
return convert_draft_texts(textslist)

View File

@@ -1146,38 +1146,6 @@ def is_closed_edge(edge_index, object):
isClosedEdge = is_closed_edge
def convert_draft_texts(textslist=[]):
"""
converts the given Draft texts (or all that is found
in the active document) to the new object
This function was already present at splitting time during v 0.19
"""
if not isinstance(textslist,list):
textslist = [textslist]
if not textslist:
for o in App.ActiveDocument.Objects:
if o.TypeId == "App::Annotation":
textslist.append(o)
todelete = []
for o in textslist:
l = o.Label
o.Label = l+".old"
obj = makeText(o.LabelText,point=o.Position)
obj.Label = l
todelete.append(o.Name)
for p in o.InList:
if p.isDerivedFrom("App::DocumentObjectGroup"):
if o in p.Group:
g = p.Group
g.append(obj)
p.Group = g
for n in todelete:
App.ActiveDocument.removeObject(n)
convertDraftTexts = convert_draft_texts
def utf8_decode(text):
r"""Decode the input string and return a unicode string.