Skip to content

Commit

Permalink
Draft: Bugfix to getCloneBase after objects splitting
Browse files Browse the repository at this point in the history
  • Loading branch information
carlopav authored and yorikvanhavre committed May 12, 2020
1 parent 6df8201 commit 64619a6
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 34 deletions.
3 changes: 3 additions & 0 deletions src/Mod/Draft/Draft.py
Expand Up @@ -116,6 +116,9 @@
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

Expand Down
42 changes: 8 additions & 34 deletions src/Mod/Draft/draftmake/make_clone.py
Expand Up @@ -30,12 +30,11 @@

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
Expand All @@ -62,7 +61,7 @@ def make_clone(obj, delta=None, forcedraft=False):
"""

prefix = get_param("ClonePrefix","")
prefix = utils.get_param("ClonePrefix","")

cl = None

Expand All @@ -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:
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
28 changes: 28 additions & 0 deletions src/Mod/Draft/draftutils/utils.py
Expand Up @@ -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.
Expand Down

0 comments on commit 64619a6

Please sign in to comment.