Skip to content

Commit

Permalink
Draft: moved ConvertDraftText to utils.py
Browse files Browse the repository at this point in the history
  • Loading branch information
carlopav authored and yorikvanhavre committed May 15, 2020
1 parent 95fe307 commit 2c4de88
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 29 deletions.
36 changes: 7 additions & 29 deletions src/Mod/Draft/Draft.py
Expand Up @@ -2,6 +2,7 @@
# ***************************************************************************
# * Copyright (c) 2009, 2010 Yorik van Havre <yorik@uncreated.net> *
# * Copyright (c) 2009, 2010 Ken Cline <cline@frii.com> *
# * Copyright (c) 2020 FreeCAD Developers *
# * *
# * This program is free software; you can redistribute it and/or modify *
# * it under the terms of the GNU Lesser General Public License (LGPL) *
Expand Down Expand Up @@ -69,13 +70,17 @@
"Dmitry Chigrin, Daniel Falck")
__url__ = "https://www.freecadweb.org"


# ---------------------------------------------------------------------------
# Backwards compatibility
# ---------------------------------------------------------------------------
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
# ---------------------------------------------------------------------------
Expand Down Expand Up @@ -183,6 +188,7 @@
from draftutils.gui_utils import loadTexture
from draftutils.gui_utils import load_texture


#---------------------------------------------------------------------------
# Draft functions
#---------------------------------------------------------------------------
Expand Down Expand Up @@ -229,6 +235,7 @@

from draftfunctions.upgrade import upgrade


#---------------------------------------------------------------------------
# Draft objects
#---------------------------------------------------------------------------
Expand Down Expand Up @@ -404,33 +411,4 @@
from draftviewproviders.view_text import ViewProviderText
ViewProviderDraftText = ViewProviderText

def convertDraftTexts(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 FreeCAD.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:
FreeCAD.ActiveDocument.removeObject(n)


## @}
32 changes: 32 additions & 0 deletions src/Mod/Draft/draftutils/utils.py
Expand Up @@ -1109,6 +1109,38 @@ 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 FreeCAD.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:
FreeCAD.ActiveDocument.removeObject(n)


convertDraftTexts = convert_draft_texts


def utf8_decode(text):
r"""Decode the input string and return a unicode string.
Expand Down

0 comments on commit 2c4de88

Please sign in to comment.