diff options
-rw-r--r-- | Boxer.py | 60 | ||||
-rw-r--r-- | BoxerGui.py | 16 |
2 files changed, 50 insertions, 26 deletions
@@ -296,22 +296,54 @@ def makeExtrudes(doc, cfg): objects['bottom'] = makeExtrude(doc, cfg, "Bottom", doc.Bottom) return objects +def makeCrossSections(doc, cfg, extrudes): + def makeCrossSection(extrude, name): + wires = list() + shape = extrude.Shape + + for i in shape.slice(Base.Vector(0, 0, 1), cfg.thickness / 2): + wires.append(i) + + comp = Part.Compound(wires) + cs = doc.addObject("Part::Feature", name + "_Cross_Section") + cs.Shape = comp + cs.ViewObject.Visibility = False + cs.purgeTouched() + return cs + + objects = {} + for key, extrude in extrudes.items(): + objects[key] = makeCrossSection(extrude, key.title()) + return objects + +def make(doc, cfg): + # Cretate the underlying parts + parts = makeBox(doc, cfg) + + # Extrude each part + extrudes = makeExtrudes(doc, cfg) + + # Put all extrudes in a group + box = doc.addObject("App::DocumentObjectGroup", "Box") + for e in extrudes.values(): + box.addObject(e) + + doc.recompute() + + # Create cross sections for export + crossSections = makeCrossSections(doc, cfg, extrudes) + crossSectionsGroup = doc.addObject("App::DocumentObjectGroup", "Cross Sections") + [crossSectionsGroup.addObject(cs) for cs in crossSections.values()] + def removeEverything(doc): def rm(name): if hasattr(doc, name): doc.removeObject(name) - rm("Top_Extrude") - rm("Back_Extrude") - rm("Left_Extrude") - rm("Front_Extrude") - rm("Right_Extrude") - rm("Bottom_Extrude") - - rm("Top") - rm("Back") - rm("Left") - rm("Front") - rm("Right") - rm("Bottom") - + rm("Box") + rm("Cross Sections") + + for key in ['Front', 'Back', 'Left', 'Right', 'Top', 'Bottom']: + rm(key + '_Cross_Section') + rm(key + '_Extrude') + rm(key) diff --git a/BoxerGui.py b/BoxerGui.py index 853c2be..c57a517 100644 --- a/BoxerGui.py +++ b/BoxerGui.py @@ -64,20 +64,12 @@ class BoxerGui(object): ui.outerDepth.value()) self.cfg.thickness = self.dockWidget.ui.thickness.value() self.cfg.notchSize = self.dockWidget.ui.notchSize.value() - + self.cfg.prt() - self.removeBox() doc = FreeCAD.ActiveDocument - parts = Boxer.makeBox(doc, self.cfg) - extrudes = Boxer.makeExtrudes(doc, self.cfg) - print(extrudes) - group = doc.addObject("App::DocumentObjectGroup", "Box") -# [group.addObject(e) for e in extrudes.values()] - for e in extrudes.values(): - print("e:" + str(e)) - group.addObject(e) - doc.recompute() - + Boxer.removeEverything(doc) + Boxer.make(doc, self.cfg) + def removeBox(self): doc = FreeCAD.ActiveDocument Boxer.removeEverything(doc) |