diff options
-rw-r--r-- | .gitignore | 3 | ||||
-rw-r--r-- | Boxer.py | 73 | ||||
-rw-r--r-- | BoxerGui.py | 23 | ||||
-rw-r--r-- | InitGui.py | 6 |
4 files changed, 83 insertions, 22 deletions
@@ -1 +1,4 @@ *.pyc +*.tmp +tmp.* +*.tmp.* @@ -214,6 +214,7 @@ def makeBoxSide(cfg, boxSide): return v def makeBox(doc, cfg): + objects = {} # front back left # right top bottom @@ -223,34 +224,94 @@ def makeBox(doc, cfg): m.move(cfg.outerWidth * -0.55, 0, 0) s = Part.makePolygon(makeBoxSide(cfg, BoxSide.front)) s.transformShape(m) - doc.addObject("Part::Feature", "Front").Shape = s + front = doc.addObject("Part::Feature", "Front") + front.Shape = s m = Matrix() m.move(cfg.outerWidth * 0.55, 0, 0) s = Part.makePolygon(makeBoxSide(cfg, BoxSide.back)) s.transformShape(m) - doc.addObject("Part::Feature", "Back").Shape = s + back = doc.addObject("Part::Feature", "Back") + back.Shape = s m = Matrix() m.move(cfg.outerWidth * 1.60, 0, 0) l = Part.makePolygon(makeBoxSide(cfg, BoxSide.left)) l.transformShape(m) - doc.addObject("Part::Feature", "Left").Shape = l + left = doc.addObject("Part::Feature", "Left") + left.Shape = l m = Matrix() m.move(cfg.outerWidth * -0.55, cfg.outerWidth * -1.1, 0) l = Part.makePolygon(makeBoxSide(cfg, BoxSide.right)) l.transformShape(m) - doc.addObject("Part::Feature", "Right").Shape = l + right = doc.addObject("Part::Feature", "Right") + right.Shape = l m = Matrix() m.move(cfg.outerWidth * 0.55, cfg.outerWidth * -1.1, 0) l = Part.makePolygon(makeBoxSide(cfg, BoxSide.top)) l.transformShape(m) - doc.addObject("Part::Feature", "Top").Shape = l + top = doc.addObject("Part::Feature", "Top") + top.Shape = l m = Matrix() m.move(cfg.outerWidth * 1.60, cfg.outerWidth * -1.1, 0) l = Part.makePolygon(makeBoxSide(cfg, BoxSide.bottom)) l.transformShape(m) - doc.addObject("Part::Feature", "Bottom").Shape = l + bottom = doc.addObject("Part::Feature", "Bottom") + bottom.Shape = l + + return {'front': front, 'back': back, + 'left': left, 'right': right, + 'top': top, 'bottom': bottom} + +def makeExtrudes(doc, cfg): + + def makeExtrude(doc, cfg, name, part): + extrude = doc.addObject("Part::Extrusion", name + "_Extrude") + extrude.Base = part + extrude.Dir = (0, 0, cfg.thickness) + extrude.Solid = (True) + extrude.TaperAngle = (0) + extrude.Label = name + ' Extrude' + + partView = part.ViewObject + extrudeView = extrude.ViewObject + + if partView is not None and extrudeView is not None: + partView.Visibility = False + extrudeView.ShapeColor = partView.ShapeColor + extrudeView.LineColor = partView.LineColor + extrudeView.PointColor = partView.PointColor + + return extrude + + objects = {} + objects['front'] = makeExtrude(doc, cfg, "Front", doc.Front) + objects['back'] = makeExtrude(doc, cfg, "Back", doc.Back) + objects['left'] = makeExtrude(doc, cfg, "Left", doc.Left) + objects['right'] = makeExtrude(doc, cfg, "Right", doc.Right) + objects['top'] = makeExtrude(doc, cfg, "Top", doc.Top) + objects['bottom'] = makeExtrude(doc, cfg, "Bottom", doc.Bottom) + return objects + +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") + diff --git a/BoxerGui.py b/BoxerGui.py index b4d6258..853c2be 100644 --- a/BoxerGui.py +++ b/BoxerGui.py @@ -68,22 +68,19 @@ class BoxerGui(object): self.cfg.prt() self.removeBox() doc = FreeCAD.ActiveDocument - Boxer.makeBox(doc, self.cfg) + 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() def removeBox(self): doc = FreeCAD.ActiveDocument - - def rm(name): - o = getattr(doc, name, None); - if hasattr(doc, name): - doc.removeObject(name) - - rm("Top") - rm("Back") - rm("Left") - rm("Front") - rm("Right") - rm("Bottom") + Boxer.removeEverything(doc) gui = BoxerGui() gui.setupGui() @@ -85,16 +85,16 @@ class BoxerWorkbench(Workbench): def Initialize(self): self.list = ["BoxerMakeBox", "BoxerRemoveBox", "BoxerShowPanel"] self.appendToolbar("Boxer Commands", self.list) - import BoxerGui + import BoxerGui # Loads the Boxer modules def Activated(self): - return + Gui.runCommand('BoxerShowPanel') + return def Deactivated(self): return def ContextMenu(self, recipient): - # "recipient" will be either "view" or "tree" self.appendContextMenu("Boxer", self.list) def GetClassName(self): |