Skip to content

Commit

Permalink
Draft: Downgrade now splits multi-solid compounds into individual solids
Browse files Browse the repository at this point in the history
  • Loading branch information
yorikvanhavre committed Mar 27, 2014
1 parent f9e26ee commit ebb921d
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions src/Mod/Draft/Draft.py
Expand Up @@ -282,8 +282,10 @@ def shapify(obj):
shape = obj.Shape
if len(shape.Faces) == 1:
name = "Face"
elif len(shape.Solids) > 0:
elif len(shape.Solids) == 1:
name = "Solid"
elif len(shape.Solids) > 1:
name = "Compound"
elif len(shape.Faces) > 1:
name = "Shell"
elif len(shape.Wires) == 1:
Expand Down Expand Up @@ -2595,7 +2597,7 @@ def downgrade(objects,delete=False,force=None):
an object or a list of objects). If delete is True, old objects are deleted.
The force attribute can be used to
force a certain way of downgrading. It can be: explode, shapify, subtr,
splitFaces, cut2, getWire, splitWires.
splitFaces, cut2, getWire, splitWires, splitCompounds.
Returns a dictionnary containing two lists, a list of new objects and a list
of objects to be deleted"""

Expand Down Expand Up @@ -2630,6 +2632,19 @@ def cut2(objects):
addList.append(newobj)
return newobj
return None

def splitCompounds(objects):
"""split solids contained in compound objects into new objects"""
result = False
for o in objects:
if o.Shape.Solids:
for s in o.Shape.Solids:
newobj = FreeCAD.ActiveDocument.addObject("Part::Feature","Solid")
newobj.Shape = s
addList.append(newobj)
result = True
deleteList.append(o)
return result

def splitFaces(objects):
"""split faces contained in objects into new objects"""
Expand Down Expand Up @@ -2691,9 +2706,12 @@ def splitWires(objects):
edges = []
onlyedges = True
parts = []
solids = []

for o in objects:
if o.isDerivedFrom("Part::Feature"):
for s in o.Shape.Solids:
solids.append(s)
for f in o.Shape.Faces:
faces.append(f)
for e in o.Shape.Edges:
Expand All @@ -2718,6 +2736,12 @@ def splitWires(objects):
if (len(objects) == 1) and (getType(objects[0]) == "Block"):
result = explode(objects[0])
if result: msg(translate("draft", "Found 1 block: exploding it\n"))

# we have one multi-solids compound object: extract its solids
elif (len(objects) == 1) and (getType(objects[0]) == "Part") and (len(solids) > 1):
result = splitCompounds(objects)
print result
if result: msg(translate("draft", "Found 1 multi-solids compound: exploding it\n"))

# special case, we have one parametric object: we "de-parametrize" it
elif (len(objects) == 1) and (objects[0].isDerivedFrom("Part::Feature")) and ("Base" in objects[0].PropertiesList):
Expand Down

0 comments on commit ebb921d

Please sign in to comment.