aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2016-05-29 12:07:48 +0200
committerTrygve Laugstøl <trygvis@inamo.no>2016-05-29 12:07:48 +0200
commitc061d1b281b219019592c543be9ea96381258c96 (patch)
treec5a029bff5e5fc2bf90de5acd9a0f05d70da1f67
parent250455628d78afc402ba60f3765b3fb44d269be2 (diff)
downloadfreecad-boxer-c061d1b281b219019592c543be9ea96381258c96.tar.gz
freecad-boxer-c061d1b281b219019592c543be9ea96381258c96.tar.bz2
freecad-boxer-c061d1b281b219019592c543be9ea96381258c96.tar.xz
freecad-boxer-c061d1b281b219019592c543be9ea96381258c96.zip
o Creating Cross Sections.
-rw-r--r--Boxer.py60
-rw-r--r--BoxerGui.py16
2 files changed, 50 insertions, 26 deletions
diff --git a/Boxer.py b/Boxer.py
index 164aaff..0385060 100644
--- a/Boxer.py
+++ b/Boxer.py
@@ -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)