Draft: split clone from Draft.py
. .
This commit is contained in:
committed by
Yorik van Havre
parent
1a04f97d8f
commit
d711de1b4a
@@ -67,6 +67,7 @@ SET(Draft_make_functions
|
||||
draftmake/make_bezcurve.py
|
||||
draftmake/make_bspline.py
|
||||
draftmake/make_circle.py
|
||||
draftmake/make_clone.py
|
||||
draftmake/make_line.py
|
||||
draftmake/make_polygon.py
|
||||
draftmake/make_rectangle.py
|
||||
@@ -80,6 +81,7 @@ SET(Draft_objects
|
||||
draftobjects/bspline.py
|
||||
draftobjects/circulararray.py
|
||||
draftobjects/circle.py
|
||||
draftobjects/clone.py
|
||||
draftobjects/orthoarray.py
|
||||
draftobjects/polararray.py
|
||||
draftobjects/arc_3points.py
|
||||
@@ -97,6 +99,7 @@ SET(Draft_view_providers
|
||||
draftviewproviders/__init__.py
|
||||
draftviewproviders/view_base.py
|
||||
draftviewproviders/view_circulararray.py
|
||||
draftviewproviders/view_clone.py
|
||||
draftviewproviders/view_orthoarray.py
|
||||
draftviewproviders/view_polararray.py
|
||||
draftviewproviders/view_draft_annotation.py
|
||||
|
||||
@@ -228,6 +228,13 @@ if FreeCAD.GuiUp:
|
||||
# for compatibility with older versions
|
||||
_ViewProviderBezCurve = ViewProviderWire
|
||||
|
||||
# clone
|
||||
from draftmake.make_clone import make_clone, clone
|
||||
from draftobjects.clone import Clone, _Clone
|
||||
if FreeCAD.GuiUp:
|
||||
from draftviewproviders.view_clone import ViewProviderClone
|
||||
from draftviewproviders.view_clone import _ViewProviderClone
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
# Draft annotation objects
|
||||
#---------------------------------------------------------------------------
|
||||
@@ -1923,90 +1930,6 @@ def makeShapeString(String,FontFile,Size = 100,Tracking = 0):
|
||||
obj.recompute()
|
||||
return obj
|
||||
|
||||
def clone(obj,delta=None,forcedraft=False):
|
||||
"""clone(obj,[delta,forcedraft]): makes a clone of the given object(s). The clone is an exact,
|
||||
linked copy of the given object. If the original object changes, the final object
|
||||
changes too. Optionally, you can give a delta Vector to move the clone from the
|
||||
original position. If forcedraft is True, the resulting object is a Draft clone
|
||||
even if the input object is an Arch object."""
|
||||
|
||||
prefix = getParam("ClonePrefix","")
|
||||
cl = None
|
||||
if prefix:
|
||||
prefix = prefix.strip()+" "
|
||||
if not isinstance(obj,list):
|
||||
obj = [obj]
|
||||
if (len(obj) == 1) and obj[0].isDerivedFrom("Part::Part2DObject"):
|
||||
cl = FreeCAD.ActiveDocument.addObject("Part::Part2DObjectPython","Clone2D")
|
||||
cl.Label = prefix + obj[0].Label + " (2D)"
|
||||
elif (len(obj) == 1) and (hasattr(obj[0],"CloneOf") or (getType(obj[0]) == "BuildingPart")) and (not forcedraft):
|
||||
# arch objects can be clones
|
||||
import Arch
|
||||
if getType(obj[0]) == "BuildingPart":
|
||||
cl = Arch.makeComponent()
|
||||
else:
|
||||
try:
|
||||
clonefunc = getattr(Arch,"make"+obj[0].Proxy.Type)
|
||||
except:
|
||||
pass # not a standard Arch object... Fall back to Draft mode
|
||||
else:
|
||||
cl = clonefunc()
|
||||
if cl:
|
||||
base = getCloneBase(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 getType(obj[0]) != "BuildingPart":
|
||||
cl.Placement = obj[0].Placement
|
||||
try:
|
||||
cl.Role = base.Role
|
||||
cl.Description = base.Description
|
||||
cl.Tag = base.Tag
|
||||
except:
|
||||
pass
|
||||
if gui:
|
||||
formatObject(cl,base)
|
||||
cl.ViewObject.DiffuseColor = base.ViewObject.DiffuseColor
|
||||
if getType(obj[0]) in ["Window","BuildingPart"]:
|
||||
from DraftGui import todo
|
||||
todo.delay(Arch.recolorize,cl)
|
||||
select(cl)
|
||||
return cl
|
||||
# fall back to Draft clone mode
|
||||
if not cl:
|
||||
cl = FreeCAD.ActiveDocument.addObject("Part::FeaturePython","Clone")
|
||||
cl.addExtension("Part::AttachExtensionPython", None)
|
||||
cl.Label = prefix + obj[0].Label
|
||||
_Clone(cl)
|
||||
if gui:
|
||||
_ViewProviderClone(cl.ViewObject)
|
||||
cl.Objects = obj
|
||||
if delta:
|
||||
cl.Placement.move(delta)
|
||||
elif (len(obj) == 1) and hasattr(obj[0],"Placement"):
|
||||
cl.Placement = obj[0].Placement
|
||||
formatObject(cl,obj[0])
|
||||
if hasattr(cl,"LongName") and hasattr(obj[0],"LongName"):
|
||||
cl.LongName = obj[0].LongName
|
||||
if gui and (len(obj) > 1):
|
||||
cl.ViewObject.Proxy.resetColors(cl.ViewObject)
|
||||
select(cl)
|
||||
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. 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 getType(obj) == "Clone":
|
||||
return obj.Objects[0]
|
||||
if strict:
|
||||
return False
|
||||
return obj
|
||||
|
||||
|
||||
def mirror(objlist, p1, p2):
|
||||
"""mirror(objlist, p1, p2)
|
||||
@@ -3758,132 +3681,6 @@ class _ViewProviderPoint(_ViewProviderDraft):
|
||||
def getIcon(self):
|
||||
return ":/icons/Draft_Dot.svg"
|
||||
|
||||
class _Clone(_DraftObject):
|
||||
"""The Clone object"""
|
||||
|
||||
def __init__(self,obj):
|
||||
_DraftObject.__init__(self,obj,"Clone")
|
||||
obj.addProperty("App::PropertyLinkListGlobal","Objects","Draft",QT_TRANSLATE_NOOP("App::Property","The objects included in this clone"))
|
||||
obj.addProperty("App::PropertyVector","Scale","Draft",QT_TRANSLATE_NOOP("App::Property","The scale factor of this clone"))
|
||||
obj.addProperty("App::PropertyBool","Fuse","Draft",QT_TRANSLATE_NOOP("App::Property","If this clones several objects, this specifies if the result is a fusion or a compound"))
|
||||
obj.Scale = Vector(1,1,1)
|
||||
|
||||
def join(self,obj,shapes):
|
||||
fuse = getattr(obj,'Fuse',False)
|
||||
if fuse:
|
||||
tmps = []
|
||||
for s in shapes:
|
||||
tmps += s.Solids
|
||||
if not tmps:
|
||||
for s in shapes:
|
||||
tmps += s.Faces
|
||||
if not tmps:
|
||||
for s in shapes:
|
||||
tmps += s.Edges
|
||||
shapes = tmps
|
||||
if len(shapes) == 1:
|
||||
return shapes[0]
|
||||
import Part
|
||||
if fuse:
|
||||
try:
|
||||
sh = shapes[0].multiFuse(shapes[1:])
|
||||
sh = sh.removeSplitter()
|
||||
except:
|
||||
pass
|
||||
else:
|
||||
return sh
|
||||
return Part.makeCompound(shapes)
|
||||
|
||||
def execute(self,obj):
|
||||
import Part, DraftGeomUtils
|
||||
pl = obj.Placement
|
||||
shapes = []
|
||||
if obj.isDerivedFrom("Part::Part2DObject"):
|
||||
# if our clone is 2D, make sure all its linked geometry is 2D too
|
||||
for o in obj.Objects:
|
||||
if not o.getLinkedObject(True).isDerivedFrom("Part::Part2DObject"):
|
||||
FreeCAD.Console.PrintWarning("Warning 2D Clone "+obj.Name+" contains 3D geometry")
|
||||
return
|
||||
for o in obj.Objects:
|
||||
sh = Part.getShape(o)
|
||||
if not sh.isNull():
|
||||
shapes.append(sh)
|
||||
if shapes:
|
||||
sh = self.join(obj,shapes)
|
||||
m = FreeCAD.Matrix()
|
||||
if hasattr(obj,"Scale") and not sh.isNull():
|
||||
sx,sy,sz = obj.Scale
|
||||
if not DraftVecUtils.equals(obj.Scale,Vector(1,1,1)):
|
||||
op = sh.Placement
|
||||
sh.Placement = FreeCAD.Placement()
|
||||
m.scale(obj.Scale)
|
||||
if sx == sy == sz:
|
||||
sh.transformShape(m)
|
||||
else:
|
||||
sh = sh.transformGeometry(m)
|
||||
sh.Placement = op
|
||||
obj.Shape = sh
|
||||
|
||||
obj.Placement = pl
|
||||
if hasattr(obj,"positionBySupport"):
|
||||
obj.positionBySupport()
|
||||
|
||||
def getSubVolume(self,obj,placement=None):
|
||||
# this allows clones of arch windows to return a subvolume too
|
||||
if obj.Objects:
|
||||
if hasattr(obj.Objects[0],"Proxy"):
|
||||
if hasattr(obj.Objects[0].Proxy,"getSubVolume"):
|
||||
if not placement:
|
||||
# clones must displace the original subvolume too
|
||||
placement = obj.Placement
|
||||
return obj.Objects[0].Proxy.getSubVolume(obj.Objects[0],placement)
|
||||
return None
|
||||
|
||||
class _ViewProviderClone:
|
||||
"""a view provider that displays a Clone icon instead of a Draft icon"""
|
||||
|
||||
def __init__(self,vobj):
|
||||
vobj.Proxy = self
|
||||
|
||||
def getIcon(self):
|
||||
return ":/icons/Draft_Clone.svg"
|
||||
|
||||
def __getstate__(self):
|
||||
return None
|
||||
|
||||
def __setstate__(self, state):
|
||||
return None
|
||||
|
||||
def getDisplayModes(self, vobj):
|
||||
modes=[]
|
||||
return modes
|
||||
|
||||
def setDisplayMode(self, mode):
|
||||
return mode
|
||||
|
||||
def resetColors(self, vobj):
|
||||
colors = []
|
||||
for o in getGroupContents(vobj.Object.Objects):
|
||||
if o.isDerivedFrom("Part::Feature"):
|
||||
if len(o.ViewObject.DiffuseColor) > 1:
|
||||
colors.extend(o.ViewObject.DiffuseColor)
|
||||
else:
|
||||
c = o.ViewObject.ShapeColor
|
||||
c = (c[0],c[1],c[2],o.ViewObject.Transparency/100.0)
|
||||
for f in o.Shape.Faces:
|
||||
colors.append(c)
|
||||
elif o.hasExtension("App::GeoFeatureGroupExtension"):
|
||||
for so in vobj.Object.Group:
|
||||
if so.isDerivedFrom("Part::Feature"):
|
||||
if len(so.ViewObject.DiffuseColor) > 1:
|
||||
colors.extend(so.ViewObject.DiffuseColor)
|
||||
else:
|
||||
c = so.ViewObject.ShapeColor
|
||||
c = (c[0],c[1],c[2],so.ViewObject.Transparency/100.0)
|
||||
for f in so.Shape.Faces:
|
||||
colors.append(c)
|
||||
if colors:
|
||||
vobj.DiffuseColor = colors
|
||||
|
||||
class _ViewProviderDraftArray(_ViewProviderDraft):
|
||||
"""a view provider that displays a Array icon instead of a Draft icon"""
|
||||
|
||||
159
src/Mod/Draft/draftmake/make_clone.py
Normal file
159
src/Mod/Draft/draftmake/make_clone.py
Normal file
@@ -0,0 +1,159 @@
|
||||
# ***************************************************************************
|
||||
# * 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) *
|
||||
# * as published by the Free Software Foundation; either version 2 of *
|
||||
# * the License, or (at your option) any later version. *
|
||||
# * for detail see the LICENCE text file. *
|
||||
# * *
|
||||
# * This program is distributed in the hope that it will be useful, *
|
||||
# * but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
# * GNU Library General Public License for more details. *
|
||||
# * *
|
||||
# * You should have received a copy of the GNU Library General Public *
|
||||
# * License along with this program; if not, write to the Free Software *
|
||||
# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
|
||||
# * USA *
|
||||
# * *
|
||||
# ***************************************************************************
|
||||
"""This module provides the code for Draft make_clone function.
|
||||
"""
|
||||
## @package make_clone
|
||||
# \ingroup DRAFT
|
||||
# \brief This module provides the code for Draft make_clone function.
|
||||
|
||||
import FreeCAD as App
|
||||
|
||||
import DraftGeomUtils
|
||||
|
||||
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
|
||||
from draftviewproviders.view_clone import ViewProviderClone
|
||||
|
||||
|
||||
def make_clone(obj, delta=None, forcedraft=False):
|
||||
"""clone(obj,[delta,forcedraft])
|
||||
|
||||
Makes a clone of the given object(s).
|
||||
The clone is an exact, linked copy of the given object. If the original
|
||||
object changes, the final object changes too.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
obj :
|
||||
|
||||
delta : Base.Vector
|
||||
Delta Vector to move the clone from the original position.
|
||||
|
||||
forcedraft : bool
|
||||
If forcedraft is True, the resulting object is a Draft clone
|
||||
even if the input object is an Arch object.
|
||||
|
||||
"""
|
||||
|
||||
prefix = get_param("ClonePrefix","")
|
||||
|
||||
cl = None
|
||||
|
||||
if prefix:
|
||||
prefix = prefix.strip() + " "
|
||||
|
||||
if not isinstance(obj,list):
|
||||
obj = [obj]
|
||||
|
||||
if (len(obj) == 1) and obj[0].isDerivedFrom("Part::Part2DObject"):
|
||||
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):
|
||||
# arch objects can be clones
|
||||
import Arch
|
||||
if get_type(obj[0]) == "BuildingPart":
|
||||
cl = Arch.makeComponent()
|
||||
else:
|
||||
try:
|
||||
clonefunc = getattr(Arch,"make"+obj[0].Proxy.Type)
|
||||
except:
|
||||
pass # not a standard Arch object... Fall back to Draft mode
|
||||
else:
|
||||
cl = clonefunc()
|
||||
if cl:
|
||||
base = getCloneBase(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":
|
||||
cl.Placement = obj[0].Placement
|
||||
try:
|
||||
cl.Role = base.Role
|
||||
cl.Description = base.Description
|
||||
cl.Tag = base.Tag
|
||||
except:
|
||||
pass
|
||||
if App.GuiUp:
|
||||
format_object(cl,base)
|
||||
cl.ViewObject.DiffuseColor = base.ViewObject.DiffuseColor
|
||||
if get_type(obj[0]) in ["Window","BuildingPart"]:
|
||||
ToDo.delay(Arch.recolorize,cl)
|
||||
select(cl)
|
||||
return cl
|
||||
# fall back to Draft clone mode
|
||||
if not cl:
|
||||
cl = App.ActiveDocument.addObject("Part::FeaturePython","Clone")
|
||||
cl.addExtension("Part::AttachExtensionPython", None)
|
||||
cl.Label = prefix + obj[0].Label
|
||||
Clone(cl)
|
||||
if App.GuiUp:
|
||||
ViewProviderClone(cl.ViewObject)
|
||||
cl.Objects = obj
|
||||
if delta:
|
||||
cl.Placement.move(delta)
|
||||
elif (len(obj) == 1) and hasattr(obj[0],"Placement"):
|
||||
cl.Placement = obj[0].Placement
|
||||
format_object(cl,obj[0])
|
||||
if hasattr(cl,"LongName") and hasattr(obj[0],"LongName"):
|
||||
cl.LongName = obj[0].LongName
|
||||
if App.GuiUp and (len(obj) > 1):
|
||||
cl.ViewObject.Proxy.resetColors(cl.ViewObject)
|
||||
select(cl)
|
||||
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
|
||||
131
src/Mod/Draft/draftobjects/clone.py
Normal file
131
src/Mod/Draft/draftobjects/clone.py
Normal file
@@ -0,0 +1,131 @@
|
||||
# ***************************************************************************
|
||||
# * 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) *
|
||||
# * as published by the Free Software Foundation; either version 2 of *
|
||||
# * the License, or (at your option) any later version. *
|
||||
# * for detail see the LICENCE text file. *
|
||||
# * *
|
||||
# * This program is distributed in the hope that it will be useful, *
|
||||
# * but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
# * GNU Library General Public License for more details. *
|
||||
# * *
|
||||
# * You should have received a copy of the GNU Library General Public *
|
||||
# * License along with this program; if not, write to the Free Software *
|
||||
# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
|
||||
# * USA *
|
||||
# * *
|
||||
# ***************************************************************************
|
||||
"""This module provides the object code for Draft Clone.
|
||||
"""
|
||||
## @package clone
|
||||
# \ingroup DRAFT
|
||||
# \brief This module provides the object code for Draft Clone.
|
||||
|
||||
from PySide.QtCore import QT_TRANSLATE_NOOP
|
||||
|
||||
import FreeCAD as App
|
||||
|
||||
import DraftVecUtils
|
||||
|
||||
from draftobjects.base import DraftObject
|
||||
|
||||
|
||||
class Clone(DraftObject):
|
||||
"""The Clone object"""
|
||||
|
||||
def __init__(self,obj):
|
||||
super(Clone, self).__init__(obj, "Clone")
|
||||
|
||||
_tip = "The objects included in this clone"
|
||||
obj.addProperty("App::PropertyLinkListGlobal", "Objects",
|
||||
"Draft", QT_TRANSLATE_NOOP("App::Property", _tip))
|
||||
|
||||
_tip = "The scale factor of this clone"
|
||||
obj.addProperty("App::PropertyVector", "Scale",
|
||||
"Draft", QT_TRANSLATE_NOOP("App::Property", _tip))
|
||||
|
||||
_tip = "If Clones includes several objects,\n\
|
||||
set True for fusion or False for compound"
|
||||
obj.addProperty("App::PropertyBool", "Fuse",
|
||||
"Draft", QT_TRANSLATE_NOOP("App::Property", _tip))
|
||||
|
||||
obj.Scale = App.Vector(1,1,1)
|
||||
|
||||
def join(self,obj,shapes):
|
||||
fuse = getattr(obj, 'Fuse', False)
|
||||
if fuse:
|
||||
tmps = []
|
||||
for s in shapes:
|
||||
tmps += s.Solids
|
||||
if not tmps:
|
||||
for s in shapes:
|
||||
tmps += s.Faces
|
||||
if not tmps:
|
||||
for s in shapes:
|
||||
tmps += s.Edges
|
||||
shapes = tmps
|
||||
if len(shapes) == 1:
|
||||
return shapes[0]
|
||||
import Part
|
||||
if fuse:
|
||||
try:
|
||||
sh = shapes[0].multiFuse(shapes[1:])
|
||||
sh = sh.removeSplitter()
|
||||
except:
|
||||
pass
|
||||
else:
|
||||
return sh
|
||||
return Part.makeCompound(shapes)
|
||||
|
||||
def execute(self,obj):
|
||||
import Part
|
||||
pl = obj.Placement
|
||||
shapes = []
|
||||
if obj.isDerivedFrom("Part::Part2DObject"):
|
||||
# if our clone is 2D, make sure all its linked geometry is 2D too
|
||||
for o in obj.Objects:
|
||||
if not o.getLinkedObject(True).isDerivedFrom("Part::Part2DObject"):
|
||||
App.Console.PrintWarning("Warning 2D Clone "+obj.Name+" contains 3D geometry")
|
||||
return
|
||||
for o in obj.Objects:
|
||||
sh = Part.getShape(o)
|
||||
if not sh.isNull():
|
||||
shapes.append(sh)
|
||||
if shapes:
|
||||
sh = self.join(obj, shapes)
|
||||
m = App.Matrix()
|
||||
if hasattr(obj,"Scale") and not sh.isNull():
|
||||
sx,sy,sz = obj.Scale
|
||||
if not DraftVecUtils.equals(obj.Scale,App.Vector(1, 1, 1)):
|
||||
op = sh.Placement
|
||||
sh.Placement = App.Placement()
|
||||
m.scale(obj.Scale)
|
||||
if sx == sy == sz:
|
||||
sh.transformShape(m)
|
||||
else:
|
||||
sh = sh.transformGeometry(m)
|
||||
sh.Placement = op
|
||||
obj.Shape = sh
|
||||
|
||||
obj.Placement = pl
|
||||
if hasattr(obj,"positionBySupport"):
|
||||
obj.positionBySupport()
|
||||
|
||||
def getSubVolume(self,obj,placement=None):
|
||||
# this allows clones of arch windows to return a subvolume too
|
||||
if obj.Objects:
|
||||
if hasattr(obj.Objects[0],"Proxy"):
|
||||
if hasattr(obj.Objects[0].Proxy, "getSubVolume"):
|
||||
if not placement:
|
||||
# clones must displace the original subvolume too
|
||||
placement = obj.Placement
|
||||
return obj.Objects[0].Proxy.getSubVolume(obj.Objects[0], placement)
|
||||
return None
|
||||
|
||||
|
||||
_Clone = Clone
|
||||
80
src/Mod/Draft/draftviewproviders/view_clone.py
Normal file
80
src/Mod/Draft/draftviewproviders/view_clone.py
Normal file
@@ -0,0 +1,80 @@
|
||||
# ***************************************************************************
|
||||
# * 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) *
|
||||
# * as published by the Free Software Foundation; either version 2 of *
|
||||
# * the License, or (at your option) any later version. *
|
||||
# * for detail see the LICENCE text file. *
|
||||
# * *
|
||||
# * This program is distributed in the hope that it will be useful, *
|
||||
# * but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
# * GNU Library General Public License for more details. *
|
||||
# * *
|
||||
# * You should have received a copy of the GNU Library General Public *
|
||||
# * License along with this program; if not, write to the Free Software *
|
||||
# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
|
||||
# * USA *
|
||||
# * *
|
||||
# ***************************************************************************
|
||||
"""This module provides the view provider code for the Draft Clone object.
|
||||
"""
|
||||
## @package view_clone
|
||||
# \ingroup DRAFT
|
||||
# \brief This module provides the view provider code for the Draft Clone object.
|
||||
|
||||
import draftutils.utils as utils
|
||||
|
||||
|
||||
class ViewProviderClone:
|
||||
"""a view provider that displays a Clone icon instead of a Draft icon"""
|
||||
|
||||
def __init__(self,vobj):
|
||||
vobj.Proxy = self
|
||||
|
||||
def getIcon(self):
|
||||
return ":/icons/Draft_Clone.svg"
|
||||
|
||||
def __getstate__(self):
|
||||
return None
|
||||
|
||||
def __setstate__(self, state):
|
||||
return None
|
||||
|
||||
def getDisplayModes(self, vobj):
|
||||
modes=[]
|
||||
return modes
|
||||
|
||||
def setDisplayMode(self, mode):
|
||||
return mode
|
||||
|
||||
def resetColors(self, vobj):
|
||||
colors = []
|
||||
for o in utils.get_group_contents(vobj.Object.Objects):
|
||||
if o.isDerivedFrom("Part::Feature"):
|
||||
if len(o.ViewObject.DiffuseColor) > 1:
|
||||
colors.extend(o.ViewObject.DiffuseColor)
|
||||
else:
|
||||
c = o.ViewObject.ShapeColor
|
||||
c = (c[0],c[1],c[2],o.ViewObject.Transparency/100.0)
|
||||
for f in o.Shape.Faces: # TODO: verify this line
|
||||
colors.append(c)
|
||||
|
||||
elif o.hasExtension("App::GeoFeatureGroupExtension"):
|
||||
for so in vobj.Object.Group:
|
||||
if so.isDerivedFrom("Part::Feature"):
|
||||
if len(so.ViewObject.DiffuseColor) > 1:
|
||||
colors.extend(so.ViewObject.DiffuseColor)
|
||||
else:
|
||||
c = so.ViewObject.ShapeColor
|
||||
c = (c[0],c[1],c[2],so.ViewObject.Transparency/100.0)
|
||||
for f in so.Shape.Faces:
|
||||
colors.append(c)
|
||||
if colors:
|
||||
vobj.DiffuseColor = colors
|
||||
|
||||
|
||||
_ViewProviderClone = ViewProviderClone
|
||||
Reference in New Issue
Block a user