From 1379b541ea5e561eefb88f6e89415c6ad7545efb Mon Sep 17 00:00:00 2001 From: carlopav Date: Mon, 11 May 2020 12:48:09 +0200 Subject: [PATCH] Draft: Bugfix to getCloneBase after objects splitting --- src/Mod/Draft/Draft.py | 3 ++ src/Mod/Draft/draftmake/make_clone.py | 42 +++++---------------------- src/Mod/Draft/draftutils/utils.py | 28 ++++++++++++++++++ 3 files changed, 39 insertions(+), 34 deletions(-) diff --git a/src/Mod/Draft/Draft.py b/src/Mod/Draft/Draft.py index 8ab33bbf17..7deeec0dc8 100644 --- a/src/Mod/Draft/Draft.py +++ b/src/Mod/Draft/Draft.py @@ -116,6 +116,9 @@ from draftutils.utils import get_objects_of_type from draftutils.utils import isClone from draftutils.utils import is_clone +from draftutils.utils import getCloneBase +from draftutils.utils import get_clone_base + from draftutils.utils import getGroupNames from draftutils.utils import get_group_names diff --git a/src/Mod/Draft/draftmake/make_clone.py b/src/Mod/Draft/draftmake/make_clone.py index 2032418404..a3446bf8a2 100644 --- a/src/Mod/Draft/draftmake/make_clone.py +++ b/src/Mod/Draft/draftmake/make_clone.py @@ -30,12 +30,11 @@ import FreeCAD as App import DraftGeomUtils +import draftutils.utils as utils + from draftutils.gui_utils import format_object from draftutils.gui_utils import select -from draftutils.utils import get_param -from draftutils.utils import get_type - from draftobjects.clone import Clone if App.GuiUp: from draftutils.todo import ToDo @@ -62,7 +61,7 @@ def make_clone(obj, delta=None, forcedraft=False): """ - prefix = get_param("ClonePrefix","") + prefix = utils.get_param("ClonePrefix","") cl = None @@ -76,10 +75,10 @@ def make_clone(obj, delta=None, forcedraft=False): cl = App.ActiveDocument.addObject("Part::Part2DObjectPython","Clone2D") cl.Label = prefix + obj[0].Label + " (2D)" - elif (len(obj) == 1) and (hasattr(obj[0],"CloneOf") or (get_type(obj[0]) == "BuildingPart")) and (not forcedraft): + elif (len(obj) == 1) and (hasattr(obj[0],"CloneOf") or (utils.get_type(obj[0]) == "BuildingPart")) and (not forcedraft): # arch objects can be clones import Arch - if get_type(obj[0]) == "BuildingPart": + if utils.get_type(obj[0]) == "BuildingPart": cl = Arch.makeComponent() else: try: @@ -89,12 +88,12 @@ def make_clone(obj, delta=None, forcedraft=False): else: cl = clonefunc() if cl: - base = getCloneBase(obj[0]) + base = utils.get_clone_base(obj[0]) cl.Label = prefix + base.Label cl.CloneOf = base if hasattr(cl,"Material") and hasattr(obj[0],"Material"): cl.Material = obj[0].Material - if get_type(obj[0]) != "BuildingPart": + if utils.get_type(obj[0]) != "BuildingPart": cl.Placement = obj[0].Placement try: cl.Role = base.Role @@ -105,7 +104,7 @@ def make_clone(obj, delta=None, forcedraft=False): if App.GuiUp: format_object(cl,base) cl.ViewObject.DiffuseColor = base.ViewObject.DiffuseColor - if get_type(obj[0]) in ["Window","BuildingPart"]: + if utils.get_type(obj[0]) in ["Window","BuildingPart"]: ToDo.delay(Arch.recolorize,cl) select(cl) return cl @@ -131,29 +130,4 @@ def make_clone(obj, delta=None, forcedraft=False): return cl -def getCloneBase(obj, strict=False): - """getCloneBase(obj, [strict]) - - Returns the object cloned by this object, if any, or this object if - it is no clone. - - Parameters - ---------- - obj : - TODO: describe - - strict : bool (default = False) - If strict is True, if this object is not a clone, - this function returns False - """ - if hasattr(obj,"CloneOf"): - if obj.CloneOf: - return getCloneBase(obj.CloneOf) - if get_type(obj) == "Clone": - return obj.Objects[0] - if strict: - return False - return obj - - clone = make_clone \ No newline at end of file diff --git a/src/Mod/Draft/draftutils/utils.py b/src/Mod/Draft/draftutils/utils.py index 8976842e80..bd3fca197d 100644 --- a/src/Mod/Draft/draftutils/utils.py +++ b/src/Mod/Draft/draftutils/utils.py @@ -524,6 +524,34 @@ def is_clone(obj, objtype, recursive=False): isClone = is_clone +def get_clone_base(obj, strict=False): + """get_clone_base(obj, [strict]) + + Returns the object cloned by this object, if any, or this object if + it is no clone. + + Parameters + ---------- + obj : + TODO: describe + + strict : bool (default = False) + If strict is True, if this object is not a clone, + this function returns False + """ + if hasattr(obj,"CloneOf"): + if obj.CloneOf: + return get_clone_base(obj.CloneOf) + if get_type(obj) == "Clone": + return obj.Objects[0] + if strict: + return False + return obj + + +getCloneBase = get_clone_base + + def get_group_names(): """Return a list of names of existing groups in the document.