From 991bd588112372a91f63b272b5c507582ba9d4f7 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Wed, 15 Jun 2016 00:08:39 +0200 Subject: o Replacing non-working cross section generation with Shape2DViews instead, much better. --- Boxer.py | 67 ++++++++++++++++++++++++++++++++++++++-------------------------- 1 file changed, 40 insertions(+), 27 deletions(-) diff --git a/Boxer.py b/Boxer.py index f331198..b31098d 100644 --- a/Boxer.py +++ b/Boxer.py @@ -1,4 +1,4 @@ -from FreeCAD import Base, Vector, Matrix, Placement, Rotation +from FreeCAD import Base, Vector, Matrix, Placement, Rotation, Draft import Part from enum import Enum import math @@ -163,7 +163,7 @@ class BoxCfg(object): self.calculate() self.generateExtrudes = True - self.generateCrossSections = False # Not very useful so off by default + self.generateViews = True for s in self.sides: s.enabled = False @@ -411,26 +411,27 @@ def makeExtrudes(doc, parts, cfg): return extrudes -def makeCrossSections(doc, cfg, extrudes): - def makeCrossSection(extrude, name): - wires = list() - shape = extrude.Shape - - raise Exception('cfg.thickness is de-implemented') - for i in shape.slice(Base.Vector(0, 0, 1), cfg.thickness / 2): - wires.append(i) +def makeShape2DViews(doc, cfg, extrudes): + pvs = { + SideType.front: Vector(0, 1, 0), + SideType.back: Vector(0, 1, 0), + SideType.left: Vector(1, 0, 0), + SideType.right: Vector(1, 0, 0), + SideType.top: Vector(0, 0, 1), + SideType.bottom: Vector(0, 0, 1) + } - comp = Part.Compound(wires) - cs = doc.addObject("Part::Feature", name + "_Cross_Section") - cs.Shape = comp - cs.ViewObject.Visibility = False - cs.purgeTouched() - return cs + def makeShape2DView(extrude, sideType): + boxSide = cfg.sideForType(sideType) + print('pvs[sideType]=' + str(pvs[sideType])) + s = Draft.makeShape2DView(extrude, projectionVector = pvs[sideType]) + s.Label = boxSide.title + ' View' + return s - crossSections = {} - for key, extrude in extrudes.items(): - crossSections[key] = makeCrossSection(extrude, key.title()) - return crossSections + objects = {} + for sideType, extrude in extrudes.items(): + objects[sideType] = makeShape2DView(extrude, sideType) + return objects def make(doc, cfg): @@ -447,13 +448,19 @@ def make(doc, cfg): doc.recompute() - crossSections = None - if cfg.generateCrossSections: - crossSections = makeCrossSections(doc, cfg, extrudes) - crossSectionsGroup = doc.addObject("App::DocumentObjectGroup", "Cross Sections") - [crossSectionsGroup.addObject(cs) for cs in crossSections.values()] + views = None + cfg.generateViews = True + if cfg.generateViews: + views = makeShape2DViews(doc, cfg, extrudes) + viewsGroup = doc.addObject("App::DocumentObjectGroup", "Views") + viewsGroup.Label = 'Views' + for sideType, view in views.items(): + viewsGroup.addObject(view) - return {'parts': parts, 'extrudes': extrudes, 'crossSections': crossSections} + return { + 'parts': parts, + 'extrudes': extrudes, + 'views': views} def removeEverything(doc): @@ -462,9 +469,15 @@ def removeEverything(doc): doc.removeObject(name) rm("Box") - rm("Cross Sections") + rm("Views") for key in ['Front', 'Back', 'Left', 'Right', 'Top', 'Bottom']: rm(key + '_Cross_Section') rm(key + '_Extrude') rm(key + '_Part') + rm('Shape2DView') + rm('Shape2DView001') + rm('Shape2DView002') + rm('Shape2DView003') + rm('Shape2DView004') + rm('Shape2DView005') -- cgit v1.2.3