aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2016-06-14 23:11:16 +0200
committerTrygve Laugstøl <trygvis@inamo.no>2016-06-14 23:13:00 +0200
commit32139455bfc7cbd3e6886ca195136b7b80a15d74 (patch)
tree9489ae3eb5956e2d1406440a01533f9130b02400
parent4d0ded8232f24370c586637c2ccd009725ffd53f (diff)
downloadfreecad-boxer-32139455bfc7cbd3e6886ca195136b7b80a15d74.tar.gz
freecad-boxer-32139455bfc7cbd3e6886ca195136b7b80a15d74.tar.bz2
freecad-boxer-32139455bfc7cbd3e6886ca195136b7b80a15d74.tar.xz
freecad-boxer-32139455bfc7cbd3e6886ca195136b7b80a15d74.zip
o Working code for disabling sides. Polish required.
-rw-r--r--Boxer.py217
-rw-r--r--BoxerDockWidget.py78
-rw-r--r--BoxerDockWidget.ui75
-rw-r--r--BoxerGui.py31
-rw-r--r--InitGui.py65
-rw-r--r--README.md6
6 files changed, 249 insertions, 223 deletions
diff --git a/Boxer.py b/Boxer.py
index af49dee..f331198 100644
--- a/Boxer.py
+++ b/Boxer.py
@@ -1,6 +1,3 @@
-# import Boxer; reload(Boxer); import BoxerGui as bg; reload(bg);
-
-#import FreeCAD
from FreeCAD import Base, Vector, Matrix, Placement, Rotation
import Part
from enum import Enum
@@ -88,10 +85,28 @@ class BoxSide(object):
self.extrudeVector = Vector(extrudeVector)
self.enabled = True
self.sideTypesByLineDirections = sideTypesByLineDirections
+ self._thickness = 10
+
+ def left(self, lineDirection):
+ sideType = self.sideTypesByLineDirections[lineDirection][0]
+ return self.cfg.sides[sideType]
- def opositeEnabled(self, lineDirection):
- sideType = self.sideTypesByLineDirections[lineDirection]
- return self.cfg.sides[sideType].enabled
+ def opposite(self, lineDirection):
+ sideType = self.sideTypesByLineDirections[lineDirection][1]
+ return self.cfg.sides[sideType]
+
+ def right(self, lineDirection):
+ sideType = self.sideTypesByLineDirections[lineDirection][2]
+ return self.cfg.sides[sideType]
+
+ @property
+ def thickness(self):
+ return self._thickness
+
+ @thickness.setter
+ def thickness(self, thickness):
+ self._thickness = thickness
+ self.cfg.calculate()
class NotchConfig(object):
@@ -105,65 +120,60 @@ class NotchConfig(object):
class BoxCfg(object):
def __init__(self):
- self._thickness = 10
- self._notchSize = 10
- self.generateExtrudes = True
- self.generateCrossSections = False # Not very useful so off by default
- self.outerDimmensions(100, 100, 100)
+ print('BoxCfg.__init__')
+
# yapf: disable
self.sides = {
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}),
+ {LineDirection.right: (SideType.left, SideType.top, SideType.right),
+ LineDirection.down: (SideType.top, SideType.right, SideType.bottom),
+ LineDirection.left: (SideType.right, SideType.bottom, SideType.left),
+ LineDirection.up: (SideType.bottom, SideType.left, SideType.top)}),
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}),
+ {LineDirection.right: (SideType.right, SideType.top, SideType.left),
+ LineDirection.down: (SideType.top, SideType.left, SideType.bottom),
+ LineDirection.left: (SideType.left, SideType.bottom, SideType.right),
+ LineDirection.up: (SideType.bottom, SideType.right, SideType.top)}),
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}),
+ {LineDirection.right: (SideType.front, SideType.top, SideType.back),
+ LineDirection.down: (SideType.top, SideType.back, SideType.bottom),
+ LineDirection.left: (SideType.back, SideType.bottom, SideType.front),
+ LineDirection.up: (SideType.bottom, SideType.front, SideType.top)}),
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}),
+ {LineDirection.right: (SideType.front, SideType.top, SideType.back),
+ LineDirection.down: (SideType.top, SideType.back, SideType.bottom),
+ LineDirection.left: (SideType.back, SideType.bottom, SideType.front),
+ LineDirection.up: (SideType.bottom, SideType.front, SideType.top)}),
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}),
+ {LineDirection.right: (SideType.left, SideType.back, SideType.right),
+ LineDirection.down: (SideType.back, SideType.right, SideType.front),
+ LineDirection.left: (SideType.right, SideType.front, SideType.left),
+ LineDirection.up: (SideType.front, SideType.left, SideType.back)}),
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})
+ {LineDirection.right: (SideType.left, SideType.front, SideType.right),
+ LineDirection.down: (SideType.front, SideType.right, SideType.back),
+ LineDirection.left: (SideType.right, SideType.back, SideType.left),
+ LineDirection.up: (SideType.back, SideType.left, SideType.front)})
}
# yapf: enable
- self.calculate()
- @property
- def thickness(self):
- return self._thickness
+ self._notchSize = 10
+ self.outerDimmensions(100, 100, 100)
- @thickness.setter
- def thickness(self, thickness):
- self._thickness = thickness
self.calculate()
-# TODO: replace this with a way to set number of notches in each direction
-# @property
-# def notches(self):
-# return self._notches
-#
-# @notches.setter
-# def notches(self, notches):
-# self._notches = notches
-# self.calculate()
+ self.generateExtrudes = True
+ self.generateCrossSections = False # Not very useful so off by default
+
+ for s in self.sides:
+ s.enabled = False
+ self.sides[SideType.left].enabled = True
+ self.sides[SideType.left].thickness = 20
+ self.sides[SideType.back].enabled = True
+
+ @property
+ def thickness(self):
+ raise Exception('thickness is de-implemented')
@property
def notchSize(self):
@@ -173,7 +183,8 @@ class BoxCfg(object):
def notchSize(self, notchSize):
self._notchSize = notchSize
- def side(self, sideType):
+ def sideForType(self, sideType):
+ #print('sideForType: sideType=' + str(sideType))
return self.sides[sideType]
def outerDimmensions(self, width, height, depth):
@@ -181,7 +192,6 @@ class BoxCfg(object):
self.outerHeight = height
self.outerDepth = depth
self.calculate()
- return self
def innerLength(self, lineDirection):
if lineDirection == MeasurementDirection.width:
@@ -209,21 +219,23 @@ class BoxCfg(object):
return NotchConfig(count, size)
def calculate(self):
- self.innerWidth = self.outerWidth - 2 * self._thickness
- self.innerHeight = self.outerHeight - 2 * self._thickness
- self.innerDepth = self.outerDepth - 2 * self._thickness
+ self.innerWidth = self.outerWidth - self.sideForType(SideType.left).thickness - self.sideForType(SideType.right).thickness
+ self.innerHeight = self.outerHeight - self.sideForType(SideType.top).thickness - self.sideForType(SideType.bottom).thickness
+ self.innerDepth = self.outerDepth - self.sideForType(SideType.front).thickness - self.sideForType(SideType.back).thickness
self._notchConfigWidth = self.createNotchConfig(self.innerWidth)
self._notchConfigHeight = self.createNotchConfig(self.innerHeight)
self._notchConfigDepth = self.createNotchConfig(self.innerDepth)
def prt(self):
print("Box configuration")
- print("Thickness : " + str(self._thickness))
print("Outer w/h/d: " + str(self.outerWidth) + "/" + str(self.outerHeight) + "/" + str(self.outerDepth))
print("Inner w/h/d: " + str(self.innerWidth) + "/" + str(self.innerHeight) + "/" + str(self.innerDepth))
print("Sides:")
- for (sideType, boxSide) in self.sides.items():
- print(" {:<9}: enabled: {}".format(boxSide.title, boxSide.enabled))
+ for sideType in SideType:
+ boxSide = self.sideForType(sideType)
+ print(" " + str(boxSide.title))
+ print(" enabled: " + str(boxSide.enabled))
+ print(" thickness: " + str(boxSide.thickness))
print("Notch size : " + str(self._notchSize))
print(" Width: " + str(self.notchConfig(MeasurementDirection.width)))
print(" Height: " + str(self.notchConfig(MeasurementDirection.height)))
@@ -248,61 +260,69 @@ class VGen(object):
self.move(self.dir.y_x * value, self.dir.y_y * value, 0)
-def line(cfg, start, lineDirection, boxSide, notchConfig, innerLength):
+# A line is though drawn from left to right, but is actually automatically
+# rotated to go either right, down, left or up by the lineDirection parameter.
+def line(cfg, start, boxSide, lineDirection, notchConfig, innerLength):
sideSize = boxSide.sideSize
+ opposite = boxSide.opposite(lineDirection)
+ left = boxSide.left(lineDirection)
+ right = boxSide.right(lineDirection)
+
+ print('line: lineDirection=' + str(lineDirection) + ', opposite=' + opposite.title + ', left=' + left.title + ', right=' + right.title)
+
inv = -1 if sideSize.inv(lineDirection) else 1
includeStart = sideSize.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(left.thickness)
- if opositeEnabled:
+ if opposite.enabled:
g.moveX(notchConfig.size)
for i in range(0, notchConfig.count):
- g.moveY(-cfg.thickness * inv)
+ g.moveY(-opposite.thickness * inv)
g.moveX(notchConfig.size)
- g.moveY(cfg.thickness * inv)
+ g.moveY(opposite.thickness * inv)
g.moveX(notchConfig.size)
else:
- print("innerLength: " + str(innerLength))
g.moveX(innerLength)
if includeStart:
- g.moveX(cfg.thickness)
+ g.moveX(right.thickness)
return g.list
def makeBoxSide(cfg, boxSide):
+ print('makeBoxSide: boxSide=' + boxSide.title)
+
notchConfigX = cfg.notchConfig(boxSide.directionX)
notchConfigY = cfg.notchConfig(boxSide.directionY)
innerLengthX = cfg.innerLength(boxSide.directionX)
innerLengthY = cfg.innerLength(boxSide.directionY)
+ opposite = boxSide.opposite(LineDirection.right)
+ left = boxSide.left(LineDirection.right)
+
# Offset the start so that the inner area starts at (0, 0)
if boxSide.sideSize is SideSize.large:
- start = Vector(-cfg.thickness, cfg.thickness, 0)
+ start = Vector(-left.thickness, opposite.thickness, 0)
elif boxSide.sideSize is SideSize.medium:
- start = Vector(-cfg.thickness, 0, 0)
+ start = Vector(-left.thickness, 0, 0)
else:
start = Vector(0, 0, 0)
v = [start]
- top = line(cfg, v[-1], LineDirection.right, boxSide, notchConfigX, innerLengthX)
+ top = line(cfg, v[-1], boxSide, LineDirection.right, notchConfigX, innerLengthX)
v.extend(top)
- left = line(cfg, v[-1], LineDirection.down, boxSide, notchConfigY, innerLengthY)
+ left = line(cfg, v[-1], boxSide, LineDirection.down, notchConfigY, innerLengthY)
v.extend(left)
- bottom = line(cfg, v[-1], LineDirection.left, boxSide, notchConfigX, innerLengthX)
+ bottom = line(cfg, v[-1], boxSide, LineDirection.left, notchConfigX, innerLengthX)
v.extend(bottom)
- right = line(cfg, v[-1], LineDirection.up, boxSide, notchConfigY, innerLengthY)
+ right = line(cfg, v[-1], boxSide, LineDirection.up, notchConfigY, innerLengthY)
v.extend(right)
return v
@@ -312,16 +332,22 @@ def makeParts(doc, cfg):
sep = cfg.outerWidth * 0.05
- def m(rotX, rotY, moveX, moveY, moveZ):
- if rotX and rotY:
- p = Placement(Vector(0, 0, 0), Rotation(Vector(1, 1, 1), 120))
- m = p.toMatrix()
- else:
- m = Matrix()
- if rotX:
- m.rotateX(math.radians(90))
- if rotY:
- m.rotateY(math.radians(90))
+ def m(rotX, rotY, rotZ, moveX, moveY, moveZ):
+ m = Matrix()
+ if rotX != 0:
+ x = Matrix()
+ x.rotateX(math.radians(rotX))
+ m = m * x
+
+ if rotY != 0:
+ y = Matrix()
+ y.rotateY(math.radians(rotY))
+ m = m * y
+
+ if rotZ != 0:
+ z = Matrix()
+ z.rotateZ(math.radians(rotZ))
+ m = m * z
v = Vector(cfg.innerWidth, cfg.innerDepth, cfg.innerHeight)
v.scale(moveX, moveY, moveZ)
@@ -331,17 +357,17 @@ def makeParts(doc, cfg):
# yapf: disable
ms = {
- SideType.front: m(True, False, -0.5, -0.5, 0.5),
- SideType.back: m(True, False, -0.5, 0.5, 0.5),
- SideType.left: m(True, True, -0.5, -0.5, 0.5),
- SideType.right: m(True, True, 0.5, -0.5, 0.5),
- SideType.top: m(False, False, -0.5, 0.5, 0.5),
- SideType.bottom: m(False, False, -0.5, 0.5, -0.5)
+ SideType.front: m( 90, 0, 0, -0.5, -0.5, 0.5),
+ SideType.back: m( 90, 180, 0, 0.5, 0.5, 0.5),
+ SideType.left: m( 90, 90, 0, -0.5, -0.5, 0.5),
+ SideType.right: m( 90, 90, 0, 0.5, -0.5, 0.5),
+ SideType.top: m( 0, 0, 0, -0.5, 0.5, 0.5),
+ SideType.bottom: m( 0, 180, 180, -0.5, -0.5, -0.5)
}
# yapf: enable
for sideType in SideType:
- boxSide = cfg.side(sideType)
+ boxSide = cfg.sideForType(sideType)
if not boxSide.enabled:
continue
@@ -358,11 +384,11 @@ def makeParts(doc, cfg):
def makeExtrudes(doc, parts, cfg):
def makeExtrude(doc, cfg, sideType):
- side = cfg.side(sideType)
+ side = cfg.sideForType(sideType)
part = parts[sideType]
extrude = doc.addObject("Part::Extrusion", side.title + "_Extrude")
extrude.Base = part
- extrude.Dir = side.extrudeVector * cfg.thickness
+ extrude.Dir = side.extrudeVector * side.thickness
extrude.Solid = (True)
extrude.TaperAngle = (0)
extrude.Label = side.title + ' Extrude'
@@ -390,6 +416,7 @@ def makeCrossSections(doc, cfg, extrudes):
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)
diff --git a/BoxerDockWidget.py b/BoxerDockWidget.py
index 00c2350..59f0055 100644
--- a/BoxerDockWidget.py
+++ b/BoxerDockWidget.py
@@ -2,7 +2,7 @@
# Form implementation generated from reading ui file 'BoxerDockWidget.ui'
#
-# Created: Sun Jun 12 11:53:34 2016
+# Created: Tue Jun 14 19:26:17 2016
# by: pyside-uic 0.2.15 running on PySide 1.2.2
#
# WARNING! All changes made in this file will be lost!
@@ -121,27 +121,48 @@ class Ui_BoxerDockWidget(object):
self.groupBox = QtGui.QGroupBox(self.dockWidgetContents)
self.groupBox.setEnabled(True)
self.groupBox.setObjectName("groupBox")
- self.verticalLayout_3 = QtGui.QVBoxLayout(self.groupBox)
- self.verticalLayout_3.setObjectName("verticalLayout_3")
+ self.gridLayout = QtGui.QGridLayout(self.groupBox)
+ self.gridLayout.setObjectName("gridLayout")
+ self.leftCheckBox = QtGui.QCheckBox(self.groupBox)
+ self.leftCheckBox.setObjectName("leftCheckBox")
+ self.gridLayout.addWidget(self.leftCheckBox, 3, 0, 1, 1)
+ self.bottomCheckBox = QtGui.QCheckBox(self.groupBox)
+ self.bottomCheckBox.setObjectName("bottomCheckBox")
+ self.gridLayout.addWidget(self.bottomCheckBox, 6, 0, 1, 1)
+ self.rightCheckBox = QtGui.QCheckBox(self.groupBox)
+ self.rightCheckBox.setObjectName("rightCheckBox")
+ self.gridLayout.addWidget(self.rightCheckBox, 4, 0, 1, 1)
self.frontCheckBox = QtGui.QCheckBox(self.groupBox)
self.frontCheckBox.setTristate(False)
self.frontCheckBox.setObjectName("frontCheckBox")
- self.verticalLayout_3.addWidget(self.frontCheckBox)
+ self.gridLayout.addWidget(self.frontCheckBox, 1, 0, 1, 1)
self.backCheckBox = QtGui.QCheckBox(self.groupBox)
self.backCheckBox.setObjectName("backCheckBox")
- self.verticalLayout_3.addWidget(self.backCheckBox)
- self.leftCheckBox = QtGui.QCheckBox(self.groupBox)
- self.leftCheckBox.setObjectName("leftCheckBox")
- self.verticalLayout_3.addWidget(self.leftCheckBox)
- self.rightCheckBox = QtGui.QCheckBox(self.groupBox)
- self.rightCheckBox.setObjectName("rightCheckBox")
- self.verticalLayout_3.addWidget(self.rightCheckBox)
+ self.gridLayout.addWidget(self.backCheckBox, 2, 0, 1, 1)
self.topCheckBox = QtGui.QCheckBox(self.groupBox)
self.topCheckBox.setObjectName("topCheckBox")
- self.verticalLayout_3.addWidget(self.topCheckBox)
- self.bottomCheckBox = QtGui.QCheckBox(self.groupBox)
- self.bottomCheckBox.setObjectName("bottomCheckBox")
- self.verticalLayout_3.addWidget(self.bottomCheckBox)
+ self.gridLayout.addWidget(self.topCheckBox, 5, 0, 1, 1)
+ self.label_3 = QtGui.QLabel(self.groupBox)
+ self.label_3.setObjectName("label_3")
+ self.gridLayout.addWidget(self.label_3, 0, 1, 1, 1)
+ self.frontThickness = QtGui.QSpinBox(self.groupBox)
+ self.frontThickness.setObjectName("frontThickness")
+ self.gridLayout.addWidget(self.frontThickness, 1, 1, 1, 1)
+ self.backThickness = QtGui.QSpinBox(self.groupBox)
+ self.backThickness.setObjectName("backThickness")
+ self.gridLayout.addWidget(self.backThickness, 2, 1, 1, 1)
+ self.leftThickness = QtGui.QSpinBox(self.groupBox)
+ self.leftThickness.setObjectName("leftThickness")
+ self.gridLayout.addWidget(self.leftThickness, 3, 1, 1, 1)
+ self.rightThickness = QtGui.QSpinBox(self.groupBox)
+ self.rightThickness.setObjectName("rightThickness")
+ self.gridLayout.addWidget(self.rightThickness, 4, 1, 1, 1)
+ self.topThickness = QtGui.QSpinBox(self.groupBox)
+ self.topThickness.setObjectName("topThickness")
+ self.gridLayout.addWidget(self.topThickness, 5, 1, 1, 1)
+ self.bottomThickness = QtGui.QSpinBox(self.groupBox)
+ self.bottomThickness.setObjectName("bottomThickness")
+ self.gridLayout.addWidget(self.bottomThickness, 6, 1, 1, 1)
self.verticalLayout.addWidget(self.groupBox)
self.generateButton = QtGui.QPushButton(self.dockWidgetContents)
self.generateButton.setEnabled(False)
@@ -177,12 +198,18 @@ class Ui_BoxerDockWidget(object):
BoxerDockWidget.setTabOrder(self.innerDepth, self.notchSize)
BoxerDockWidget.setTabOrder(self.notchSize, self.thickness)
BoxerDockWidget.setTabOrder(self.thickness, self.frontCheckBox)
- BoxerDockWidget.setTabOrder(self.frontCheckBox, self.backCheckBox)
- BoxerDockWidget.setTabOrder(self.backCheckBox, self.leftCheckBox)
- BoxerDockWidget.setTabOrder(self.leftCheckBox, self.rightCheckBox)
- BoxerDockWidget.setTabOrder(self.rightCheckBox, self.topCheckBox)
- BoxerDockWidget.setTabOrder(self.topCheckBox, self.bottomCheckBox)
- BoxerDockWidget.setTabOrder(self.bottomCheckBox, self.generateButton)
+ BoxerDockWidget.setTabOrder(self.frontCheckBox, self.frontThickness)
+ BoxerDockWidget.setTabOrder(self.frontThickness, self.backCheckBox)
+ BoxerDockWidget.setTabOrder(self.backCheckBox, self.backThickness)
+ BoxerDockWidget.setTabOrder(self.backThickness, self.leftCheckBox)
+ BoxerDockWidget.setTabOrder(self.leftCheckBox, self.leftThickness)
+ BoxerDockWidget.setTabOrder(self.leftThickness, self.rightCheckBox)
+ BoxerDockWidget.setTabOrder(self.rightCheckBox, self.rightThickness)
+ BoxerDockWidget.setTabOrder(self.rightThickness, self.topCheckBox)
+ BoxerDockWidget.setTabOrder(self.topCheckBox, self.topThickness)
+ BoxerDockWidget.setTabOrder(self.topThickness, self.bottomCheckBox)
+ BoxerDockWidget.setTabOrder(self.bottomCheckBox, self.bottomThickness)
+ BoxerDockWidget.setTabOrder(self.bottomThickness, self.generateButton)
BoxerDockWidget.setTabOrder(self.generateButton, self.fitViewButton)
def retranslateUi(self, BoxerDockWidget):
@@ -194,13 +221,14 @@ class Ui_BoxerDockWidget(object):
self.outerLabel.setText(QtGui.QApplication.translate("BoxerDockWidget", "Outer", None, QtGui.QApplication.UnicodeUTF8))
self.depthLabel.setText(QtGui.QApplication.translate("BoxerDockWidget", "Depth", None, QtGui.QApplication.UnicodeUTF8))
self.label.setText(QtGui.QApplication.translate("BoxerDockWidget", "Thickness", None, QtGui.QApplication.UnicodeUTF8))
- self.groupBox.setTitle(QtGui.QApplication.translate("BoxerDockWidget", "Enabled sides", None, QtGui.QApplication.UnicodeUTF8))
- self.frontCheckBox.setText(QtGui.QApplication.translate("BoxerDockWidget", "Front", None, QtGui.QApplication.UnicodeUTF8))
- self.backCheckBox.setText(QtGui.QApplication.translate("BoxerDockWidget", "Back", None, QtGui.QApplication.UnicodeUTF8))
+ self.groupBox.setTitle(QtGui.QApplication.translate("BoxerDockWidget", "Side configuration", None, QtGui.QApplication.UnicodeUTF8))
self.leftCheckBox.setText(QtGui.QApplication.translate("BoxerDockWidget", "Left", None, QtGui.QApplication.UnicodeUTF8))
+ self.bottomCheckBox.setText(QtGui.QApplication.translate("BoxerDockWidget", "Bottom", None, QtGui.QApplication.UnicodeUTF8))
self.rightCheckBox.setText(QtGui.QApplication.translate("BoxerDockWidget", "Right", None, QtGui.QApplication.UnicodeUTF8))
+ self.frontCheckBox.setText(QtGui.QApplication.translate("BoxerDockWidget", "Front", None, QtGui.QApplication.UnicodeUTF8))
+ self.backCheckBox.setText(QtGui.QApplication.translate("BoxerDockWidget", "Back", None, QtGui.QApplication.UnicodeUTF8))
self.topCheckBox.setText(QtGui.QApplication.translate("BoxerDockWidget", "Top", None, QtGui.QApplication.UnicodeUTF8))
- self.bottomCheckBox.setText(QtGui.QApplication.translate("BoxerDockWidget", "Bottom", None, QtGui.QApplication.UnicodeUTF8))
+ self.label_3.setText(QtGui.QApplication.translate("BoxerDockWidget", "Thickness", None, QtGui.QApplication.UnicodeUTF8))
self.generateButton.setText(QtGui.QApplication.translate("BoxerDockWidget", "Generate", None, QtGui.QApplication.UnicodeUTF8))
self.fitViewButton.setText(QtGui.QApplication.translate("BoxerDockWidget", "Fit all", None, QtGui.QApplication.UnicodeUTF8))
diff --git a/BoxerDockWidget.ui b/BoxerDockWidget.ui
index 5b24987..2b631f7 100644
--- a/BoxerDockWidget.ui
+++ b/BoxerDockWidget.ui
@@ -204,54 +204,79 @@
<bool>true</bool>
</property>
<property name="title">
- <string>Enabled sides</string>
+ <string>Side configuration</string>
</property>
- <layout class="QVBoxLayout" name="verticalLayout_3">
- <item>
- <widget class="QCheckBox" name="frontCheckBox">
+ <layout class="QGridLayout" name="gridLayout">
+ <item row="3" column="0">
+ <widget class="QCheckBox" name="leftCheckBox">
<property name="text">
- <string>Front</string>
+ <string>Left</string>
</property>
- <property name="tristate">
- <bool>false</bool>
+ </widget>
+ </item>
+ <item row="6" column="0">
+ <widget class="QCheckBox" name="bottomCheckBox">
+ <property name="text">
+ <string>Bottom</string>
</property>
</widget>
</item>
- <item>
- <widget class="QCheckBox" name="backCheckBox">
+ <item row="4" column="0">
+ <widget class="QCheckBox" name="rightCheckBox">
<property name="text">
- <string>Back</string>
+ <string>Right</string>
</property>
</widget>
</item>
- <item>
- <widget class="QCheckBox" name="leftCheckBox">
+ <item row="1" column="0">
+ <widget class="QCheckBox" name="frontCheckBox">
<property name="text">
- <string>Left</string>
+ <string>Front</string>
+ </property>
+ <property name="tristate">
+ <bool>false</bool>
</property>
</widget>
</item>
- <item>
- <widget class="QCheckBox" name="rightCheckBox">
+ <item row="2" column="0">
+ <widget class="QCheckBox" name="backCheckBox">
<property name="text">
- <string>Right</string>
+ <string>Back</string>
</property>
</widget>
</item>
- <item>
+ <item row="5" column="0">
<widget class="QCheckBox" name="topCheckBox">
<property name="text">
<string>Top</string>
</property>
</widget>
</item>
- <item>
- <widget class="QCheckBox" name="bottomCheckBox">
+ <item row="0" column="1">
+ <widget class="QLabel" name="label_3">
<property name="text">
- <string>Bottom</string>
+ <string>Thickness</string>
</property>
</widget>
</item>
+ <item row="1" column="1">
+ <widget class="QSpinBox" name="frontThickness"/>
+ </item>
+ <item row="2" column="1">
+ <widget class="QSpinBox" name="backThickness"/>
+ </item>
+ <item row="3" column="1">
+ <widget class="QSpinBox" name="leftThickness"/>
+ </item>
+ <item row="4" column="1">
+ <widget class="QSpinBox" name="rightThickness"/>
+ </item>
+ <item row="5" column="1">
+ <widget class="QSpinBox" name="topThickness"/>
+ </item>
+ <item row="6" column="1">
+ <widget class="QSpinBox" name="bottomThickness"/>
+ </item>
</layout>
</widget>
</item>
@@ -317,11 +342,17 @@
<tabstop>notchSize</tabstop>
<tabstop>thickness</tabstop>
<tabstop>frontCheckBox</tabstop>
+ <tabstop>frontThickness</tabstop>
<tabstop>backCheckBox</tabstop>
+ <tabstop>backThickness</tabstop>
<tabstop>leftCheckBox</tabstop>
+ <tabstop>leftThickness</tabstop>
<tabstop>rightCheckBox</tabstop>
+ <tabstop>rightThickness</tabstop>
<tabstop>topCheckBox</tabstop>
+ <tabstop>topThickness</tabstop>
<tabstop>bottomCheckBox</tabstop>
+ <tabstop>bottomThickness</tabstop>
<tabstop>generateButton</tabstop>
<tabstop>fitViewButton</tabstop>
</tabstops>
@@ -335,7 +366,7 @@
<hints>
<hint type="sourcelabel">
<x>233</x>
- <y>434</y>
+ <y>502</y>
</hint>
<hint type="destinationlabel">
<x>151</x>
@@ -351,7 +382,7 @@
<hints>
<hint type="sourcelabel">
<x>269</x>
- <y>476</y>
+ <y>544</y>
</hint>
<hint type="destinationlabel">
<x>219</x>
diff --git a/BoxerGui.py b/BoxerGui.py
index 3c949da..5e0ce43 100644
--- a/BoxerGui.py
+++ b/BoxerGui.py
@@ -20,15 +20,14 @@ class BoxerDocumentObserver:
class BoxerGui(object):
def __init__(self):
- self.cfg = Boxer.BoxCfg().outerDimmensions(100, 100, 100)
+ self.cfg = Boxer.BoxCfg()
+ self.cfg.outerDimmensions(100, 50, 200)
self.cfg.notchUnitWidth = 10
- self.cfg.thickness = 10
def setupGui(self):
doc = FreeCAD.ActiveDocument
self.dockWidget = dockWidget = QtGui.QDockWidget()
- dockWidget.setWindowTitle("Box config")
dockWidget.ui = BoxerDockWidget.Ui_BoxerDockWidget()
dockWidget.generateClicked = self.generateButtonClicked
dockWidget.fitAllClicked = self.fitAllButtonClicked
@@ -37,22 +36,23 @@ class BoxerGui(object):
dockWidget.ui.outerWidth.setValue(self.cfg.outerWidth)
dockWidget.ui.outerHeight.setValue(self.cfg.outerHeight)
dockWidget.ui.outerDepth.setValue(self.cfg.outerDepth)
- dockWidget.ui.thickness.setValue(self.cfg.thickness)
dockWidget.ui.notchSize.setValue(self.cfg.notchUnitWidth)
self.sideCheckBoxes = [
# yapf: disable
- (SideType.front, dockWidget.ui.frontCheckBox),
- (SideType.back, dockWidget.ui.backCheckBox),
- (SideType.left, dockWidget.ui.leftCheckBox),
- (SideType.right, dockWidget.ui.rightCheckBox),
- (SideType.top, dockWidget.ui.topCheckBox),
- (SideType.bottom, dockWidget.ui.bottomCheckBox)
+ (SideType.front, dockWidget.ui.frontCheckBox, dockWidget.ui.frontThickness),
+ (SideType.back, dockWidget.ui.backCheckBox, dockWidget.ui.backThickness),
+ (SideType.left, dockWidget.ui.leftCheckBox, dockWidget.ui.leftThickness),
+ (SideType.right, dockWidget.ui.rightCheckBox, dockWidget.ui.rightThickness),
+ (SideType.top, dockWidget.ui.topCheckBox, dockWidget.ui.topThickness),
+ (SideType.bottom, dockWidget.ui.bottomCheckBox, dockWidget.ui.bottomThickness)
# yapf: enable
]
- for (sideType, checkBox) in self.sideCheckBoxes:
- checkBox.setChecked(self.cfg.side(sideType).enabled)
+ for (sideType, checkBox, thickness) in self.sideCheckBoxes:
+ side = self.cfg.sideForType(sideType)
+ checkBox.setChecked(side.enabled)
+ thickness.setValue(side.thickness)
self.documentObserver = BoxerDocumentObserver()
FreeCAD.addDocumentObserver(self.documentObserver)
@@ -61,11 +61,12 @@ class BoxerGui(object):
ui = self.dockWidget.ui
self.cfg.outerDimmensions(ui.outerWidth.value(), ui.outerHeight.value(), ui.outerDepth.value())
- self.cfg.thickness = self.dockWidget.ui.thickness.value()
self.cfg.notchSize = self.dockWidget.ui.notchSize.value()
- for (sideType, checkBox) in self.sideCheckBoxes:
- self.cfg.side(sideType).enabled = checkBox.isChecked()
+ for (sideType, checkBox, thickness) in self.sideCheckBoxes:
+ side = self.cfg.sideForType(sideType)
+ side.enabled = checkBox.isChecked()
+ side.thickness = thickness.value()
self.cfg.prt()
doc = FreeCAD.ActiveDocument
diff --git a/InitGui.py b/InitGui.py
index c210802..316d1ea 100644
--- a/InitGui.py
+++ b/InitGui.py
@@ -1,45 +1,3 @@
-class MakeBoxCommandClass():
- def GetResources(self):
- return { #'Pixmap' : os.path.join( iconPath , 'AddWall.svg') , # the name of a svg file available in the resources
- 'MenuText': "Make Box",
- 'ToolTip': "Extends a wall from a side face of metal sheet"
- }
-
- def Activated(self):
- from Boxer import BoxCfg, makeBox
- # TODO: put all objects in a group:
- # group = doc.addObject("App::DocumentObjectGroup","Group")
-
- cfg = BoxCfg().outerDimmensions(300, 100, 50)
- # cfg.notches = 2
- cfg.notchUnitWidth = 10
- cfg.thickness = 10
- cfg.prt()
-
- doc = FreeCAD.ActiveDocument
- makeBox(doc, cfg)
-
- doc.recompute()
- Gui.SendMsgToActiveView("ViewFit")
-
- return
-
- def IsActive(self):
- return FreeCAD.ActiveDocument is not None
-
-
-class RemoveBoxCommandClass():
- def GetResources(self):
- return {'MenuText': "Remove Box", 'ToolTip': "Remove the box"}
-
- def Activated(self):
- import BoxerGui
- BoxerGui.gui.removeBox()
-
- def IsActive(self):
- return FreeCAD.ActiveDocument is not None
-
-
class ShowPanelCommandClass():
def GetResources(self):
return {'MenuText': "Show Panel"}
@@ -49,29 +7,10 @@ class ShowPanelCommandClass():
import BoxerGui
print('ShowPanelCommandClass.Activated')
- #dockWidget = QtGui.QDockWidget()
- #dockWidget.setWindowTitle("Boxer 3")
- #dockWidget.resize(656, 300)
- #dockWidget.setObjectName("BoxerDockWidget")
- #verticalLayout = QtGui.QVBoxLayout(dockWidget)
- #verticalLayout.setObjectName("verticalLayout")
- #tabSizeLabel = QtGui.QLabel(dockWidget)
- #tabSizeLabel.setObjectName("tabSizeLabel")
- #tabSizeLabel.setText("Tab size")
-
window = FreeCADGui.getMainWindow()
window.addDockWidget(QtCore.Qt.RightDockWidgetArea, BoxerGui.gui.dockWidget)
BoxerGui.gui.dockWidget.show()
- # app = QtGui.qApp
- # window = app.activeWindow()
- # window.addDockWidget(QtCore.Qt.RightDockWidgetArea, dockWidget)
-
- # d = QtGui.QWidget()
- # d.ui = BoxerDockWidget.Ui_BoxerDockWidget()
- # d.ui.setupUi(d)
- # d.show()
-
return
def IsActive(self):
@@ -84,7 +23,7 @@ class BoxerWorkbench(Workbench):
ToolTip = "Box Maker"
def Initialize(self):
- self.list = ["BoxerMakeBox", "BoxerRemoveBox", "BoxerShowPanel"]
+ self.list = ["BoxerShowPanel"]
self.appendToolbar("Boxer Commands", self.list)
import BoxerGui # Loads the Boxer modules
@@ -102,7 +41,5 @@ class BoxerWorkbench(Workbench):
return "Gui::PythonWorkbench"
-Gui.addCommand('BoxerMakeBox', MakeBoxCommandClass())
-Gui.addCommand('BoxerRemoveBox', RemoveBoxCommandClass())
Gui.addCommand('BoxerShowPanel', ShowPanelCommandClass())
Gui.addWorkbench(BoxerWorkbench())
diff --git a/README.md b/README.md
index 969fea3..5fe8626 100644
--- a/README.md
+++ b/README.md
@@ -9,10 +9,12 @@ When developing this module make sure you have the *Python console* and *report
To reload the module when running:
# This is only needed once
- import Boxer; import BoxerGui; import BoxerDockWidget
+ def r():
+ import Boxer; import BoxerGui; import BoxerDockWidget
+ reload(Boxer); reload(BoxerGui); reload(BoxerDockWidget)
# Reloads all the modules
- reload(Boxer); reload(BoxerGui); reload(BoxerDockWidget)
+ r()
## Possible new features