Draft: Draft.move() support new objects (fix #3754)
and small refactor consequent to the introduction of App.ActiveDocument.copyObject support in Draft.makeCopy()
This commit is contained in:
committed by
Yorik van Havre
parent
e366a3a961
commit
9542e1b508
@@ -35,12 +35,6 @@ from draftmake.make_copy import make_copy
|
||||
from draftmake.make_line import make_line
|
||||
from draftfunctions.join import join_wires
|
||||
|
||||
from draftobjects.dimension import LinearDimension
|
||||
from draftobjects.text import Text
|
||||
if App.GuiUp:
|
||||
from draftviewproviders.view_text import ViewProviderText
|
||||
from draftviewproviders.view_dimension import ViewProviderLinearDimension
|
||||
|
||||
|
||||
def move(objectslist, vector, copy=False):
|
||||
"""move(objects,vector,[copy])
|
||||
@@ -70,27 +64,30 @@ def move(objectslist, vector, copy=False):
|
||||
newobjlist = []
|
||||
newgroups = {}
|
||||
objectslist = utils.filter_objects_for_modifiers(objectslist, copy)
|
||||
|
||||
for obj in objectslist:
|
||||
newobj = None
|
||||
# real_vector have been introduced to take into account
|
||||
# the possibility that object is inside an App::Part
|
||||
# TODO: Make Move work also with App::Link
|
||||
if hasattr(obj, "getGlobalPlacement"):
|
||||
v_minus_global = obj.getGlobalPlacement().inverse().Rotation.multVec(vector)
|
||||
real_vector = obj.Placement.Rotation.multVec(v_minus_global)
|
||||
else:
|
||||
real_vector = vector
|
||||
|
||||
if utils.get_type(obj) == "Point":
|
||||
v = App.Vector(obj.X,obj.Y,obj.Z)
|
||||
v = v.add(real_vector)
|
||||
if copy:
|
||||
newobj = make_copy(obj)
|
||||
else:
|
||||
newobj = obj
|
||||
newobj.X = v.x
|
||||
newobj.Y = v.y
|
||||
newobj.Z = v.z
|
||||
newobj.X = obj.X + real_vector.x
|
||||
newobj.Y = obj.Y + real_vector.y
|
||||
newobj.Z = obj.Z + real_vector.z
|
||||
|
||||
elif obj.isDerivedFrom("App::DocumentObjectGroup"):
|
||||
pass
|
||||
|
||||
elif hasattr(obj,'Shape'):
|
||||
if copy:
|
||||
newobj = make_copy(obj)
|
||||
@@ -98,56 +95,48 @@ def move(objectslist, vector, copy=False):
|
||||
newobj = obj
|
||||
pla = newobj.Placement
|
||||
pla.move(real_vector)
|
||||
|
||||
elif utils.get_type(obj) == "Annotation":
|
||||
if copy:
|
||||
newobj = App.ActiveDocument.addObject("App::Annotation",
|
||||
utils.getRealName(obj.Name))
|
||||
newobj.LabelText = obj.LabelText
|
||||
if App.GuiUp:
|
||||
gui_utils.formatObject(newobj,obj)
|
||||
newobj = make_copy(obj)
|
||||
else:
|
||||
newobj = obj
|
||||
newobj.Position = obj.Position.add(real_vector)
|
||||
|
||||
elif utils.get_type(obj) == "Text":
|
||||
if copy:
|
||||
# TODO: Why make_copy do not handle Text object??
|
||||
newobj = App.ActiveDocument.addObject("App::FeaturePython",
|
||||
utils.getRealName(obj.Name))
|
||||
Text(newobj)
|
||||
if App.GuiUp:
|
||||
ViewProviderText(newobj.ViewObject)
|
||||
gui_utils.formatObject(newobj,obj)
|
||||
newobj.Text = obj.Text
|
||||
newobj.Placement = obj.Placement
|
||||
if App.GuiUp:
|
||||
gui_utils.formatObject(newobj,obj)
|
||||
newobj = make_copy(obj)
|
||||
else:
|
||||
newobj = obj
|
||||
newobj.Placement.Base = obj.Placement.Base.add(real_vector)
|
||||
elif utils.get_type(obj) in ["Dimension","LinearDimension"]:
|
||||
|
||||
elif utils.get_type(obj) in ["Dimension", "LinearDimension"]:
|
||||
if copy:
|
||||
# TODO: Why make_copy do not handle Dimension object??
|
||||
# TODO: Support also Label and Angular dimension
|
||||
newobj = App.ActiveDocument.addObject("App::FeaturePython",
|
||||
utils.getRealName(obj.Name))
|
||||
LinearDimension(newobj)
|
||||
if App.GuiUp:
|
||||
ViewProviderLinearDimension(newobj.ViewObject)
|
||||
gui_utils.formatObject(newobj,obj)
|
||||
newobj = make_copy(obj)
|
||||
else:
|
||||
newobj = obj
|
||||
newobj.Start = obj.Start.add(real_vector)
|
||||
newobj.End = obj.End.add(real_vector)
|
||||
newobj.Dimline = obj.Dimline.add(real_vector)
|
||||
else:
|
||||
if copy and obj.isDerivedFrom("Mesh::Feature"):
|
||||
print("Mesh copy not supported at the moment") # TODO
|
||||
newobj = obj
|
||||
if "Placement" in obj.PropertiesList:
|
||||
pla = obj.Placement
|
||||
pla.move(real_vector)
|
||||
|
||||
elif utils.get_type(obj) in ["AngularDimension"]:
|
||||
if copy:
|
||||
newobj = make_copy(obj)
|
||||
else:
|
||||
newobj = obj
|
||||
newobj.Center = obj.Start.add(real_vector)
|
||||
|
||||
elif "Placement" in obj.PropertiesList:
|
||||
if copy:
|
||||
newobj = make_copy(obj)
|
||||
else:
|
||||
newobj = obj
|
||||
pla = obj.Placement
|
||||
pla.move(real_vector)
|
||||
|
||||
if newobj is not None:
|
||||
newobjlist.append(newobj)
|
||||
|
||||
if copy:
|
||||
for p in obj.InList:
|
||||
if p.isDerivedFrom("App::DocumentObjectGroup") and (p in objectslist):
|
||||
@@ -156,6 +145,7 @@ def move(objectslist, vector, copy=False):
|
||||
break
|
||||
if utils.get_type(p) == "Layer":
|
||||
p.Proxy.addObject(p,newobj)
|
||||
|
||||
if copy and utils.get_param("selectBaseObjects",False):
|
||||
gui_utils.select(objectslist)
|
||||
else:
|
||||
|
||||
@@ -57,12 +57,14 @@ def make_copy(obj, force=None, reparent=False, simple_copy=False):
|
||||
App.Console.PrintError("No active document. Aborting\n")
|
||||
return
|
||||
|
||||
newobj = None
|
||||
|
||||
if simple_copy and hasattr(obj, 'Shape'):
|
||||
_name = utils.get_real_name(obj.Name)
|
||||
newobj = App.ActiveDocument.addObject("Part::Feature", _name)
|
||||
newobj.Shape = obj.Shape
|
||||
gui_utils.format_object(newobj, obj)
|
||||
elif not simple_copy and hasattr(obj, 'Shape'):
|
||||
elif not simple_copy:
|
||||
newobj = App.ActiveDocument.copyObject(obj)
|
||||
|
||||
if not newobj:
|
||||
@@ -74,10 +76,13 @@ def make_copy(obj, force=None, reparent=False, simple_copy=False):
|
||||
for par in parents:
|
||||
if par.isDerivedFrom("App::DocumentObjectGroup"):
|
||||
par.addObject(newobj)
|
||||
else: # Carlo: when is it used?
|
||||
for prop in par.PropertiesList:
|
||||
if getattr(par, prop) == obj:
|
||||
setattr(par, prop, newobj)
|
||||
else:
|
||||
# That's the case of Arch_BuildingParts or Draft_Layers for example
|
||||
if "Group" in par.PropertiesList:
|
||||
if obj in par.Group:
|
||||
group = par.Group
|
||||
group.append(newobj)
|
||||
par.Group = group
|
||||
|
||||
return newobj
|
||||
|
||||
Reference in New Issue
Block a user