diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2016-06-12 12:35:17 +0200 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2016-06-12 12:40:10 +0200 |
commit | 4d0ded8232f24370c586637c2ccd009725ffd53f (patch) | |
tree | d8df79e290b3f11b968261e713b5701a8bdeed85 | |
parent | 05347f2f8df2437c9a915858bc89035901feda5d (diff) | |
download | freecad-boxer-4d0ded8232f24370c586637c2ccd009725ffd53f.tar.gz freecad-boxer-4d0ded8232f24370c586637c2ccd009725ffd53f.tar.bz2 freecad-boxer-4d0ded8232f24370c586637c2ccd009725ffd53f.tar.xz freecad-boxer-4d0ded8232f24370c586637c2ccd009725ffd53f.zip |
o More work on disabling sides.
-rw-r--r-- | Boxer.py | 103 | ||||
-rw-r--r-- | BoxerDockWidget.py | 4 | ||||
-rw-r--r-- | BoxerDockWidget.ui | 2 | ||||
-rw-r--r-- | BoxerGui.py | 3 | ||||
-rw-r--r-- | README.md | 21 |
5 files changed, 106 insertions, 27 deletions
@@ -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) diff --git a/BoxerDockWidget.py b/BoxerDockWidget.py index cbaa482..00c2350 100644 --- a/BoxerDockWidget.py +++ b/BoxerDockWidget.py @@ -2,7 +2,7 @@ # Form implementation generated from reading ui file 'BoxerDockWidget.ui' # -# Created: Thu Jun 9 22:48:14 2016 +# Created: Sun Jun 12 11:53:34 2016 # by: pyside-uic 0.2.15 running on PySide 1.2.2 # # WARNING! All changes made in this file will be lost! @@ -186,7 +186,7 @@ class Ui_BoxerDockWidget(object): BoxerDockWidget.setTabOrder(self.generateButton, self.fitViewButton) def retranslateUi(self, BoxerDockWidget): - BoxerDockWidget.setWindowTitle(QtGui.QApplication.translate("BoxerDockWidget", "DockWidget", None, QtGui.QApplication.UnicodeUTF8)) + BoxerDockWidget.setWindowTitle(QtGui.QApplication.translate("BoxerDockWidget", "Boxer", None, QtGui.QApplication.UnicodeUTF8)) self.notchSizeLabel.setText(QtGui.QApplication.translate("BoxerDockWidget", "Notch size", None, QtGui.QApplication.UnicodeUTF8)) self.widthLabel.setText(QtGui.QApplication.translate("BoxerDockWidget", "Width", None, QtGui.QApplication.UnicodeUTF8)) self.heightLabel.setText(QtGui.QApplication.translate("BoxerDockWidget", "Height", None, QtGui.QApplication.UnicodeUTF8)) diff --git a/BoxerDockWidget.ui b/BoxerDockWidget.ui index d604084..5b24987 100644 --- a/BoxerDockWidget.ui +++ b/BoxerDockWidget.ui @@ -12,7 +12,7 @@ </rect> </property> <property name="windowTitle"> - <string>DockWidget</string> + <string>Boxer</string> </property> <widget class="QWidget" name="dockWidgetContents"> <property name="sizePolicy"> diff --git a/BoxerGui.py b/BoxerGui.py index 1527ca4..3c949da 100644 --- a/BoxerGui.py +++ b/BoxerGui.py @@ -83,6 +83,9 @@ class BoxerGui(object): Gui.SendMsgToActiveView("ViewSelection") Gui.Selection.clearSelection() + # This results in some strange flickering. Perhaps all the items should be set visible=False while rotating + Gui.SendMsgToActiveView("ViewAxo") + def removeBox(self): doc = FreeCAD.ActiveDocument Boxer.removeEverything(doc) @@ -1 +1,22 @@ FreeCAD module for creating boxes / cases suitable for laser cutting. + +# Development + +## Tips and tricks + +When developing this module make sure you have the *Python console* and *report views* visible. Enable them under View -> Panels if you don't have them visible. + +To reload the module when running: + + # This is only needed once + import Boxer; import BoxerGui; import BoxerDockWidget + + # Reloads all the modules + reload(Boxer); reload(BoxerGui); reload(BoxerDockWidget) + +## Possible new features + +**Make text labels indicating the box sides**: + + import Draft + Draft.makeText(["Front"], point = FreeCAD.Vector(50.0,50.0,0.0)) |