1
# ***************************************************************************
2
# * Copyright (c) 2009, 2010 Yorik van Havre <yorik@uncreated.net> *
3
# * Copyright (c) 2009, 2010 Ken Cline <cline@frii.com> *
4
# * Copyright (c) 2020 FreeCAD Developers *
6
# * This program is free software; you can redistribute it and/or modify *
7
# * it under the terms of the GNU Lesser General Public License (LGPL) *
8
# * as published by the Free Software Foundation; either version 2 of *
9
# * the License, or (at your option) any later version. *
10
# * for detail see the LICENCE text file. *
12
# * This program is distributed in the hope that it will be useful, *
13
# * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15
# * GNU Library General Public License for more details. *
17
# * You should have received a copy of the GNU Library General Public *
18
# * License along with this program; if not, write to the Free Software *
19
# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
22
# ***************************************************************************
23
"""Provides functions to create Clone objects."""
26
# \brief Provides functions to create Clone objects.
28
## \addtogroup draftmake
31
from draftobjects.clone import Clone
32
from draftutils import params
33
from draftutils import utils
34
from draftutils import gui_utils
37
from draftviewproviders.view_clone import ViewProviderClone
40
def make_clone(obj, delta=None, forcedraft=False):
41
"""clone(obj,[delta,forcedraft])
43
Makes a clone of the given object(s).
44
The clone is an exact, linked copy of the given object. If the original
45
object changes, the final object changes too.
52
Delta Vector to move the clone from the original position.
55
If forcedraft is True, the resulting object is a Draft clone
56
even if the input object is an Arch object.
60
prefix = params.get_param("ClonePrefix")
65
prefix = prefix.strip() + " "
67
if not isinstance(obj,list):
70
if (len(obj) == 1) and obj[0].isDerivedFrom("Part::Part2DObject"):
71
cl = App.ActiveDocument.addObject("Part::Part2DObjectPython","Clone2D")
72
cl.Label = prefix + obj[0].Label + " (2D)"
73
elif (len(obj) == 1) and (hasattr(obj[0],"CloneOf") or (utils.get_type(obj[0]) == "BuildingPart")) and (not forcedraft):
74
# arch objects can be clones
76
if utils.get_type(obj[0]) == "BuildingPart":
77
cl = Arch.makeComponent()
79
try: # new-style make function
80
cl = getattr(Arch, "make_" + obj[0].Proxy.Type.lower())()
82
try: # old-style make function
83
cl = getattr(Arch, "make" + obj[0].Proxy.Type)()
85
pass # not a standard Arch object... Fall back to Draft mode
87
base = utils.get_clone_base(obj[0])
88
cl.Label = prefix + base.Label
90
if utils.get_type(obj[0]) != "BuildingPart":
91
cl.Placement = obj[0].Placement
92
for prop in ("Description", "IfcType", "Material", "Subvolume", "Tag"):
94
setattr(cl, prop, getattr(base, prop))
98
gui_utils.format_object(cl, base)
102
# fall back to Draft clone mode
104
cl = App.ActiveDocument.addObject("Part::FeaturePython","Clone")
105
cl.addExtension("Part::AttachExtensionPython")
106
cl.Label = prefix + obj[0].Label
110
cl.Placement.move(delta)
111
elif (len(obj) == 1) and hasattr(obj[0],"Placement"):
112
cl.Placement = obj[0].Placement
113
if hasattr(cl,"LongName") and hasattr(obj[0],"LongName"):
114
cl.LongName = obj[0].LongName
116
ViewProviderClone(cl.ViewObject)
117
gui_utils.format_object(cl, obj[0])