From 4d0ded8232f24370c586637c2ccd009725ffd53f Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Sun, 12 Jun 2016 12:35:17 +0200 Subject: o More work on disabling sides. --- Boxer.py | 103 ++++++++++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 79 insertions(+), 24 deletions(-) (limited to 'Boxer.py') diff --git a/Boxer.py b/Boxer.py index be2ee80..af49dee 100644 --- a/Boxer.py +++ b/Boxer.py @@ -7,7 +7,7 @@ from enum import Enum import math -# These names are silly, should be X, Y, Z instead +# These names are silly, class should be named Axis and its values X, Y, Z class MeasurementDirection(Enum): width = 1 # X height = 2 # Z @@ -29,7 +29,7 @@ class LineDirection(Enum): # Configuration for each line in a box side -class SideConfig(Enum): +class SideSize(Enum): large = (False, True, False, True, False, True, False, True) medium = (True, True, False, False, True, True, False, False) small = (True, False, True, False, True, False, True, False) @@ -79,13 +79,19 @@ class SideType(Enum): class BoxSide(object): - def __init__(self, title, directionX, directionY, sideConfig, extrudeVector): + def __init__(self, cfg, title, directionX, directionY, sideSize, extrudeVector, sideTypesByLineDirections): + self.cfg = cfg self.title = title self.directionX = directionX self.directionY = directionY - self.sideConfig = sideConfig + self.sideSize = sideSize self.extrudeVector = Vector(extrudeVector) self.enabled = True + self.sideTypesByLineDirections = sideTypesByLineDirections + + def opositeEnabled(self, lineDirection): + sideType = self.sideTypesByLineDirections[lineDirection] + return self.cfg.sides[sideType].enabled class NotchConfig(object): @@ -104,14 +110,40 @@ class BoxCfg(object): self.generateExtrudes = True self.generateCrossSections = False # Not very useful so off by default self.outerDimmensions(100, 100, 100) + # yapf: disable self.sides = { - SideType.front: BoxSide('Front', MeasurementDirection.width, MeasurementDirection.height, SideConfig.large, (0, -1, 0)), - SideType.back: BoxSide('Back', MeasurementDirection.width, MeasurementDirection.height, SideConfig.large, (0, 1, 0)), - SideType.left: BoxSide('Left', MeasurementDirection.depth, MeasurementDirection.height, SideConfig.small, (-1, 0, 0)), - SideType.right: BoxSide('Right', MeasurementDirection.depth, MeasurementDirection.height, SideConfig.small, (1, 0, 0)), - SideType.top: BoxSide('Top', MeasurementDirection.width, MeasurementDirection.depth, SideConfig.medium, (0, 0, 1)), - SideType.bottom: BoxSide('Bottom', MeasurementDirection.width, MeasurementDirection.depth, SideConfig.medium, (0, 0, -1)) + SideType.front: BoxSide(self, 'Front', MeasurementDirection.width, MeasurementDirection.height, SideSize.large, (0, -1, 0), + {LineDirection.right: SideType.top, + LineDirection.down: SideType.right, + LineDirection.left: SideType.bottom, + LineDirection.up: SideType.left}), + SideType.back: BoxSide(self, 'Back', MeasurementDirection.width, MeasurementDirection.height, SideSize.large, (0, 1, 0), + {LineDirection.right: SideType.top, + LineDirection.down: SideType.right, + LineDirection.left: SideType.bottom, + LineDirection.up: SideType.left}), + SideType.left: BoxSide(self, 'Left', MeasurementDirection.depth, MeasurementDirection.height, SideSize.small, (-1, 0, 0), + {LineDirection.right: SideType.top, + LineDirection.down: SideType.front, + LineDirection.left: SideType.bottom, + LineDirection.up: SideType.back}), + SideType.right: BoxSide(self, 'Right', MeasurementDirection.depth, MeasurementDirection.height, SideSize.small, (1, 0, 0), + {LineDirection.right: SideType.top, + LineDirection.down: SideType.front, + LineDirection.left: SideType.bottom, + LineDirection.up: SideType.back}), + SideType.top: BoxSide(self, 'Top', MeasurementDirection.width, MeasurementDirection.depth, SideSize.medium, (0, 0, 1), + {LineDirection.right: SideType.back, + LineDirection.down: SideType.right, + LineDirection.left: SideType.back, + LineDirection.up: SideType.left}), + SideType.bottom: BoxSide(self, 'Bottom', MeasurementDirection.width, MeasurementDirection.depth, SideSize.medium, (0, 0, -1), + {LineDirection.right: SideType.back, + LineDirection.down: SideType.right, + LineDirection.left: SideType.back, + LineDirection.up: SideType.left}) } + # yapf: enable self.calculate() @property @@ -151,6 +183,16 @@ class BoxCfg(object): self.calculate() return self + def innerLength(self, lineDirection): + if lineDirection == MeasurementDirection.width: + return self.innerWidth + elif lineDirection == MeasurementDirection.height: + return self.innerHeight + elif lineDirection == MeasurementDirection.depth: + return self.innerDepth + else: + raise Exception("Unknown LineDirection: " + str(lineDirection)) + def notchConfig(self, direction): if direction == MeasurementDirection.width: return self._notchConfigWidth @@ -206,23 +248,33 @@ class VGen(object): self.move(self.dir.y_x * value, self.dir.y_y * value, 0) -def line(cfg, start, lineDirection, sideConfig, notchConfig): +def line(cfg, start, lineDirection, boxSide, notchConfig, innerLength): + + sideSize = boxSide.sideSize + inv = -1 if sideSize.inv(lineDirection) else 1 + includeStart = sideSize.includeStart(lineDirection) - inv = -1 if sideConfig.inv(lineDirection) else 1 - includeStart = sideConfig.includeStart(lineDirection) + opositeEnabled = boxSide.opositeEnabled(lineDirection) + print("boxSide: " + str(boxSide)) + print("opositeEnabled: " + str(opositeEnabled)) g = VGen(start, lineDirection) if includeStart: g.moveX(cfg.thickness) - g.moveX(notchConfig.size) - for i in range(0, notchConfig.count): - g.moveY(-cfg.thickness * inv) - g.moveX(notchConfig.size) - g.moveY(cfg.thickness * inv) + if opositeEnabled: g.moveX(notchConfig.size) + for i in range(0, notchConfig.count): + g.moveY(-cfg.thickness * inv) + g.moveX(notchConfig.size) + g.moveY(cfg.thickness * inv) + g.moveX(notchConfig.size) + else: + print("innerLength: " + str(innerLength)) + g.moveX(innerLength) + if includeStart: g.moveX(cfg.thickness) @@ -232,23 +284,25 @@ def line(cfg, start, lineDirection, sideConfig, notchConfig): def makeBoxSide(cfg, boxSide): notchConfigX = cfg.notchConfig(boxSide.directionX) notchConfigY = cfg.notchConfig(boxSide.directionY) + innerLengthX = cfg.innerLength(boxSide.directionX) + innerLengthY = cfg.innerLength(boxSide.directionY) # Offset the start so that the inner area starts at (0, 0) - if boxSide.sideConfig is SideConfig.large: + if boxSide.sideSize is SideSize.large: start = Vector(-cfg.thickness, cfg.thickness, 0) - elif boxSide.sideConfig is SideConfig.medium: + elif boxSide.sideSize is SideSize.medium: start = Vector(-cfg.thickness, 0, 0) else: start = Vector(0, 0, 0) v = [start] - top = line(cfg, v[-1], LineDirection.right, boxSide.sideConfig, notchConfigX) + top = line(cfg, v[-1], LineDirection.right, boxSide, notchConfigX, innerLengthX) v.extend(top) - left = line(cfg, v[-1], LineDirection.down, boxSide.sideConfig, notchConfigY) + left = line(cfg, v[-1], LineDirection.down, boxSide, notchConfigY, innerLengthY) v.extend(left) - bottom = line(cfg, v[-1], LineDirection.left, boxSide.sideConfig, notchConfigX) + bottom = line(cfg, v[-1], LineDirection.left, boxSide, notchConfigX, innerLengthX) v.extend(bottom) - right = line(cfg, v[-1], LineDirection.up, boxSide.sideConfig, notchConfigY) + right = line(cfg, v[-1], LineDirection.up, boxSide, notchConfigY, innerLengthY) v.extend(right) return v @@ -356,6 +410,7 @@ def make(doc, cfg): # Cretate the underlying parts parts = makeParts(doc, cfg) + extrudes = {} if cfg.generateExtrudes: extrudes = makeExtrudes(doc, parts, cfg) -- cgit v1.2.3