Draft: Improve downgrading of PD bodies (#9934)
This commit is contained in:
@@ -88,15 +88,12 @@ def downgrade(objects, delete=False, force=None):
|
||||
def explode(obj):
|
||||
"""Explode a Draft block."""
|
||||
pl = obj.Placement
|
||||
newobj = []
|
||||
for o in obj.Components:
|
||||
o.Placement = o.Placement.multiply(pl)
|
||||
o.Placement = pl.multiply(o.Placement)
|
||||
if App.GuiUp:
|
||||
o.ViewObject.Visibility = True
|
||||
if newobj:
|
||||
delete_list(obj)
|
||||
return newobj
|
||||
return None
|
||||
delete_list.append(obj)
|
||||
return True
|
||||
|
||||
def cut2(objects):
|
||||
"""Cut first object from the last one."""
|
||||
@@ -196,6 +193,24 @@ def downgrade(objects, delete=False, force=None):
|
||||
result = True
|
||||
return result
|
||||
|
||||
def delete_object(obj):
|
||||
if obj.FullName == "?": # Already deleted.
|
||||
return
|
||||
# special case: obj is a body or belongs to a body:
|
||||
if obj.TypeId == "PartDesign::Body":
|
||||
obj.removeObjectsFromDocument()
|
||||
if hasattr(obj, "_Body") and obj._Body is not None:
|
||||
obj = obj._Body
|
||||
obj.removeObjectsFromDocument()
|
||||
else:
|
||||
for parent in obj.InList:
|
||||
if parent.TypeId == "PartDesign::Body" \
|
||||
and obj in parent.Group:
|
||||
obj = parent
|
||||
obj.removeObjectsFromDocument()
|
||||
break
|
||||
doc.removeObject(obj.Name)
|
||||
|
||||
# analyzing objects
|
||||
faces = []
|
||||
edges = []
|
||||
@@ -238,16 +253,19 @@ def downgrade(objects, delete=False, force=None):
|
||||
_msg(translate("draft","Found 1 block: exploding it"))
|
||||
|
||||
# we have one multi-solids compound object: extract its solids
|
||||
elif (len(objects) == 1 and hasattr(objects[0], 'Shape')
|
||||
and len(solids) > 1):
|
||||
elif len(objects) == 1 \
|
||||
and hasattr(objects[0], "Shape") \
|
||||
and len(solids) > 1:
|
||||
result = splitCompounds(objects)
|
||||
# print(result)
|
||||
if result:
|
||||
_msg(translate("draft","Found 1 multi-solids compound: exploding it"))
|
||||
|
||||
# special case, we have one parametric object: we "de-parametrize" it
|
||||
elif (len(objects) == 1 and hasattr(objects[0], 'Shape')
|
||||
and hasattr(objects[0], 'Base')):
|
||||
elif len(objects) == 1 \
|
||||
and hasattr(objects[0], "Shape") \
|
||||
and hasattr(objects[0], "Base") \
|
||||
and not objects[0].isDerivedFrom("PartDesign::Feature"):
|
||||
result = utils.shapify(objects[0])
|
||||
if result:
|
||||
_msg(translate("draft","Found 1 parametric object: breaking its dependencies"))
|
||||
@@ -271,6 +289,7 @@ def downgrade(objects, delete=False, force=None):
|
||||
result = subtr(objects)
|
||||
if result:
|
||||
_msg(translate("draft","Found several objects: subtracting them from the first one"))
|
||||
|
||||
# only one face: we extract its wires
|
||||
elif len(faces) > 0:
|
||||
result = getWire(objects[0])
|
||||
@@ -288,12 +307,9 @@ def downgrade(objects, delete=False, force=None):
|
||||
_msg(translate("draft","No more downgrade possible"))
|
||||
|
||||
if delete:
|
||||
names = []
|
||||
for o in delete_list:
|
||||
names.append(o.Name)
|
||||
delete_object(o)
|
||||
delete_list = []
|
||||
for n in names:
|
||||
doc.removeObject(n)
|
||||
|
||||
gui_utils.select(add_list)
|
||||
return add_list, delete_list
|
||||
|
||||
Reference in New Issue
Block a user