diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2016-05-25 23:31:20 +0200 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2016-05-25 23:31:20 +0200 |
commit | 739b0e37ee6ce461cdfa550f3a5d410470f18f6c (patch) | |
tree | 396441e8cc66b93a10c023be42d223beffe83b72 | |
parent | 5c386786c57ffc09f53976c488db68adbc932b98 (diff) | |
download | freecad-boxer-739b0e37ee6ce461cdfa550f3a5d410470f18f6c.tar.gz freecad-boxer-739b0e37ee6ce461cdfa550f3a5d410470f18f6c.tar.bz2 freecad-boxer-739b0e37ee6ce461cdfa550f3a5d410470f18f6c.tar.xz freecad-boxer-739b0e37ee6ce461cdfa550f3a5d410470f18f6c.zip |
o Working FreeCAD module for creating boxes useful for laser cutting.
-rw-r--r-- | Boxer.py | 78 | ||||
-rw-r--r-- | BoxerDockWidget.py | 145 | ||||
-rw-r--r-- | BoxerDockWidget.ui | 247 | ||||
-rw-r--r-- | BoxerGui | 135 | ||||
-rw-r--r-- | BoxerGui.py | 89 | ||||
-rw-r--r-- | BoxerPanelWidget.py | 43 | ||||
-rw-r--r-- | BoxerPanelWidget.ui | 53 | ||||
-rw-r--r-- | Init.py | 2 | ||||
-rw-r--r-- | InitGui.py | 95 | ||||
-rw-r--r-- | Makefile | 11 |
10 files changed, 819 insertions, 79 deletions
@@ -1,6 +1,6 @@ -# import Boxer; reload(Boxer); Gui.runCommand("BoxerRemoveBox"); Gui.runCommand("BoxerMakeBox"); +# import Boxer; reload(Boxer); import BoxerGui as bg; reload(bg); -import FreeCAD +#import FreeCAD from FreeCAD import Base, Vector, Matrix import Part from enum import Enum @@ -113,7 +113,7 @@ class BoxCfg(object): @property def notchSize(self): - return self._notchUnitWidth + return self._notchSize @notchSize.setter def notchSize(self, notchSize): @@ -151,12 +151,13 @@ class BoxCfg(object): 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("Notch size: " + str(self._notchSize)) - print(" Width: " + str(self.notchConfig(MeasurementDirection.width))) - print(" Height: " + str(self.notchConfig(MeasurementDirection.height))) - print(" Depth: " + str(self.notchConfig(MeasurementDirection.depth))) + print("Notch size : " + str(self._notchSize)) + print(" Width: " + str(self.notchConfig(MeasurementDirection.width))) + print(" Height: " + str(self.notchConfig(MeasurementDirection.height))) + print(" Depth: " + str(self.notchConfig(MeasurementDirection.depth))) class VGen(object): def __init__(self, current, dir): @@ -253,66 +254,3 @@ def makeBox(doc, cfg): l = Part.makePolygon(makeBoxSide(cfg, BoxSide.bottom)) l.transformShape(m) doc.addObject("Part::Feature", "Bottom").Shape = l - -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): - # 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): -# if len(Gui.Selection.getSelection()) < 1 or len(Gui.Selection.getSelectionEx()[0].SubElementNames) < 1: -# return False -# selobj = Gui.Selection.getSelection()[0] -# for selFace in Gui.Selection.getSelectionEx()[0].SubObjects: -# if type(selFace) != Part.Face: -# return False -# return True - return FreeCAD.ActiveDocument is not None - -class RemoveBoxCommandClass(): - def GetResources(self): - return { - 'MenuText': "Remove Box", - 'ToolTip' : "Remove the box"} - - def Activated(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") - return - - def IsActive(self): - return FreeCAD.ActiveDocument is not None - -from FreeCAD import Gui -Gui.addCommand('BoxerMakeBox', MakeBoxCommandClass()) -Gui.addCommand('BoxerRemoveBox', RemoveBoxCommandClass()) diff --git a/BoxerDockWidget.py b/BoxerDockWidget.py new file mode 100644 index 0000000..67dd59b --- /dev/null +++ b/BoxerDockWidget.py @@ -0,0 +1,145 @@ +# -*- coding: utf-8 -*- + +# Form implementation generated from reading ui file 'BoxerDockWidget.ui' +# +# Created: Wed May 25 23:23:01 2016 +# by: pyside-uic 0.2.15 running on PySide 1.2.2 +# +# WARNING! All changes made in this file will be lost! + +from PySide import QtCore, QtGui + +class Ui_BoxerDockWidget(object): + def setupUi(self, BoxerDockWidget): + BoxerDockWidget.setObjectName("BoxerDockWidget") + BoxerDockWidget.resize(499, 213) + self.dockWidgetContents = QtGui.QWidget() + sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Preferred) + sizePolicy.setHorizontalStretch(0) + sizePolicy.setVerticalStretch(0) + sizePolicy.setHeightForWidth(self.dockWidgetContents.sizePolicy().hasHeightForWidth()) + self.dockWidgetContents.setSizePolicy(sizePolicy) + self.dockWidgetContents.setObjectName("dockWidgetContents") + self.verticalLayout = QtGui.QVBoxLayout(self.dockWidgetContents) + self.verticalLayout.setSizeConstraint(QtGui.QLayout.SetMaximumSize) + self.verticalLayout.setObjectName("verticalLayout") + self.gridLayout_2 = QtGui.QGridLayout() + self.gridLayout_2.setObjectName("gridLayout_2") + self.notchSizeLabel = QtGui.QLabel(self.dockWidgetContents) + sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Preferred) + sizePolicy.setHorizontalStretch(0) + sizePolicy.setVerticalStretch(0) + sizePolicy.setHeightForWidth(self.notchSizeLabel.sizePolicy().hasHeightForWidth()) + self.notchSizeLabel.setSizePolicy(sizePolicy) + self.notchSizeLabel.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter) + self.notchSizeLabel.setObjectName("notchSizeLabel") + self.gridLayout_2.addWidget(self.notchSizeLabel, 3, 0, 1, 1) + self.widthLabel = QtGui.QLabel(self.dockWidgetContents) + sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Fixed) + sizePolicy.setHorizontalStretch(0) + sizePolicy.setVerticalStretch(0) + sizePolicy.setHeightForWidth(self.widthLabel.sizePolicy().hasHeightForWidth()) + self.widthLabel.setSizePolicy(sizePolicy) + self.widthLabel.setObjectName("widthLabel") + self.gridLayout_2.addWidget(self.widthLabel, 0, 1, 1, 1) + self.heightLabel = QtGui.QLabel(self.dockWidgetContents) + self.heightLabel.setObjectName("heightLabel") + self.gridLayout_2.addWidget(self.heightLabel, 0, 2, 1, 1) + self.innerLabel = QtGui.QLabel(self.dockWidgetContents) + self.innerLabel.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter) + self.innerLabel.setObjectName("innerLabel") + self.gridLayout_2.addWidget(self.innerLabel, 2, 0, 1, 1) + self.outerLabel = QtGui.QLabel(self.dockWidgetContents) + self.outerLabel.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter) + self.outerLabel.setObjectName("outerLabel") + self.gridLayout_2.addWidget(self.outerLabel, 1, 0, 1, 1) + self.innerHeight = QtGui.QLineEdit(self.dockWidgetContents) + self.innerHeight.setEnabled(False) + sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed) + sizePolicy.setHorizontalStretch(0) + sizePolicy.setVerticalStretch(0) + sizePolicy.setHeightForWidth(self.innerHeight.sizePolicy().hasHeightForWidth()) + self.innerHeight.setSizePolicy(sizePolicy) + self.innerHeight.setObjectName("innerHeight") + self.gridLayout_2.addWidget(self.innerHeight, 2, 2, 1, 1) + self.innerDepth = QtGui.QLineEdit(self.dockWidgetContents) + self.innerDepth.setEnabled(False) + sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed) + sizePolicy.setHorizontalStretch(0) + sizePolicy.setVerticalStretch(0) + sizePolicy.setHeightForWidth(self.innerDepth.sizePolicy().hasHeightForWidth()) + self.innerDepth.setSizePolicy(sizePolicy) + self.innerDepth.setObjectName("innerDepth") + self.gridLayout_2.addWidget(self.innerDepth, 2, 3, 1, 1) + self.depthLabel = QtGui.QLabel(self.dockWidgetContents) + self.depthLabel.setObjectName("depthLabel") + self.gridLayout_2.addWidget(self.depthLabel, 0, 3, 1, 1) + self.label = QtGui.QLabel(self.dockWidgetContents) + self.label.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter) + self.label.setObjectName("label") + self.gridLayout_2.addWidget(self.label, 3, 2, 1, 1) + self.outerWidth = QtGui.QSpinBox(self.dockWidgetContents) + self.outerWidth.setMinimum(1) + self.outerWidth.setMaximum(99999) + self.outerWidth.setObjectName("outerWidth") + self.gridLayout_2.addWidget(self.outerWidth, 1, 1, 1, 1) + self.outerHeight = QtGui.QSpinBox(self.dockWidgetContents) + self.outerHeight.setMinimum(1) + self.outerHeight.setMaximum(99999) + self.outerHeight.setObjectName("outerHeight") + self.gridLayout_2.addWidget(self.outerHeight, 1, 2, 1, 1) + self.outerDepth = QtGui.QSpinBox(self.dockWidgetContents) + self.outerDepth.setMinimum(1) + self.outerDepth.setMaximum(99999) + self.outerDepth.setObjectName("outerDepth") + self.gridLayout_2.addWidget(self.outerDepth, 1, 3, 1, 1) + self.notchSize = QtGui.QSpinBox(self.dockWidgetContents) + self.notchSize.setMinimum(1) + self.notchSize.setMaximum(99999) + self.notchSize.setObjectName("notchSize") + self.gridLayout_2.addWidget(self.notchSize, 3, 1, 1, 1) + self.thickness = QtGui.QSpinBox(self.dockWidgetContents) + self.thickness.setMinimum(1) + self.thickness.setMaximum(99999) + self.thickness.setObjectName("thickness") + self.gridLayout_2.addWidget(self.thickness, 3, 3, 1, 1) + self.innerWidth = QtGui.QLineEdit(self.dockWidgetContents) + self.innerWidth.setEnabled(False) + sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed) + sizePolicy.setHorizontalStretch(0) + sizePolicy.setVerticalStretch(0) + sizePolicy.setHeightForWidth(self.innerWidth.sizePolicy().hasHeightForWidth()) + self.innerWidth.setSizePolicy(sizePolicy) + self.innerWidth.setObjectName("innerWidth") + self.gridLayout_2.addWidget(self.innerWidth, 2, 1, 1, 1) + self.verticalLayout.addLayout(self.gridLayout_2) + self.generateButton = QtGui.QPushButton(self.dockWidgetContents) + self.generateButton.setEnabled(False) + sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Maximum) + sizePolicy.setHorizontalStretch(0) + sizePolicy.setVerticalStretch(0) + sizePolicy.setHeightForWidth(self.generateButton.sizePolicy().hasHeightForWidth()) + self.generateButton.setSizePolicy(sizePolicy) + self.generateButton.setMaximumSize(QtCore.QSize(484, 16777215)) + self.generateButton.setObjectName("generateButton") + self.verticalLayout.addWidget(self.generateButton) + BoxerDockWidget.setWidget(self.dockWidgetContents) + + self.retranslateUi(BoxerDockWidget) + QtCore.QObject.connect(self.generateButton, QtCore.SIGNAL("clicked()"), BoxerDockWidget.generateClicked) + QtCore.QMetaObject.connectSlotsByName(BoxerDockWidget) + BoxerDockWidget.setTabOrder(self.innerWidth, self.innerHeight) + BoxerDockWidget.setTabOrder(self.innerHeight, self.innerDepth) + BoxerDockWidget.setTabOrder(self.innerDepth, self.generateButton) + + def retranslateUi(self, BoxerDockWidget): + BoxerDockWidget.setWindowTitle(QtGui.QApplication.translate("BoxerDockWidget", "DockWidget", 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)) + self.innerLabel.setText(QtGui.QApplication.translate("BoxerDockWidget", "Inner", None, QtGui.QApplication.UnicodeUTF8)) + 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.generateButton.setText(QtGui.QApplication.translate("BoxerDockWidget", "Generate", None, QtGui.QApplication.UnicodeUTF8)) + diff --git a/BoxerDockWidget.ui b/BoxerDockWidget.ui new file mode 100644 index 0000000..dcac6a1 --- /dev/null +++ b/BoxerDockWidget.ui @@ -0,0 +1,247 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <author>Trygve Laugstøl <trygvis@inamo.no></author> + <class>BoxerDockWidget</class> + <widget class="QDockWidget" name="BoxerDockWidget"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>499</width> + <height>213</height> + </rect> + </property> + <property name="windowTitle"> + <string>DockWidget</string> + </property> + <widget class="QWidget" name="dockWidgetContents"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Fixed" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <layout class="QVBoxLayout" name="verticalLayout"> + <property name="sizeConstraint"> + <enum>QLayout::SetMaximumSize</enum> + </property> + <item> + <layout class="QGridLayout" name="gridLayout_2"> + <item row="3" column="0"> + <widget class="QLabel" name="notchSizeLabel"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Fixed" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>Notch size</string> + </property> + <property name="alignment"> + <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> + </property> + </widget> + </item> + <item row="0" column="1"> + <widget class="QLabel" name="widthLabel"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Preferred" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>Width</string> + </property> + </widget> + </item> + <item row="0" column="2"> + <widget class="QLabel" name="heightLabel"> + <property name="text"> + <string>Height</string> + </property> + </widget> + </item> + <item row="2" column="0"> + <widget class="QLabel" name="innerLabel"> + <property name="text"> + <string>Inner</string> + </property> + <property name="alignment"> + <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> + </property> + </widget> + </item> + <item row="1" column="0"> + <widget class="QLabel" name="outerLabel"> + <property name="text"> + <string>Outer</string> + </property> + <property name="alignment"> + <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> + </property> + </widget> + </item> + <item row="2" column="2"> + <widget class="QLineEdit" name="innerHeight"> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="sizePolicy"> + <sizepolicy hsizetype="Fixed" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + </item> + <item row="2" column="3"> + <widget class="QLineEdit" name="innerDepth"> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="sizePolicy"> + <sizepolicy hsizetype="Fixed" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + </item> + <item row="0" column="3"> + <widget class="QLabel" name="depthLabel"> + <property name="text"> + <string>Depth</string> + </property> + </widget> + </item> + <item row="3" column="2"> + <widget class="QLabel" name="label"> + <property name="text"> + <string>Thickness</string> + </property> + <property name="alignment"> + <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> + </property> + </widget> + </item> + <item row="1" column="1"> + <widget class="QSpinBox" name="outerWidth"> + <property name="minimum"> + <number>1</number> + </property> + <property name="maximum"> + <number>99999</number> + </property> + </widget> + </item> + <item row="1" column="2"> + <widget class="QSpinBox" name="outerHeight"> + <property name="minimum"> + <number>1</number> + </property> + <property name="maximum"> + <number>99999</number> + </property> + </widget> + </item> + <item row="1" column="3"> + <widget class="QSpinBox" name="outerDepth"> + <property name="minimum"> + <number>1</number> + </property> + <property name="maximum"> + <number>99999</number> + </property> + </widget> + </item> + <item row="3" column="1"> + <widget class="QSpinBox" name="notchSize"> + <property name="minimum"> + <number>1</number> + </property> + <property name="maximum"> + <number>99999</number> + </property> + </widget> + </item> + <item row="3" column="3"> + <widget class="QSpinBox" name="thickness"> + <property name="minimum"> + <number>1</number> + </property> + <property name="maximum"> + <number>99999</number> + </property> + </widget> + </item> + <item row="2" column="1"> + <widget class="QLineEdit" name="innerWidth"> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="sizePolicy"> + <sizepolicy hsizetype="Fixed" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + </item> + </layout> + </item> + <item> + <widget class="QPushButton" name="generateButton"> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="sizePolicy"> + <sizepolicy hsizetype="Minimum" vsizetype="Maximum"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="maximumSize"> + <size> + <width>484</width> + <height>16777215</height> + </size> + </property> + <property name="text"> + <string>Generate</string> + </property> + </widget> + </item> + </layout> + </widget> + </widget> + <tabstops> + <tabstop>innerWidth</tabstop> + <tabstop>innerHeight</tabstop> + <tabstop>innerDepth</tabstop> + <tabstop>generateButton</tabstop> + </tabstops> + <resources/> + <connections> + <connection> + <sender>generateButton</sender> + <signal>clicked()</signal> + <receiver>BoxerDockWidget</receiver> + <slot>generateClicked()</slot> + <hints> + <hint type="sourcelabel"> + <x>199</x> + <y>242</y> + </hint> + <hint type="destinationlabel"> + <x>208</x> + <y>110</y> + </hint> + </hints> + </connection> + </connections> + <slots> + <slot>generateClicked()</slot> + </slots> +</ui> diff --git a/BoxerGui b/BoxerGui new file mode 100644 index 0000000..f21283f --- /dev/null +++ b/BoxerGui @@ -0,0 +1,135 @@ +class BoxerDocumentObserver: + def __init__(self): + bgui.dockWidget.generateButton.enabled = False + +# def slotCreatedDocument(self, doc): +# print('slotCreatedDocument') + + def slotDeletedDocument(self, doc): + print('slotDeletedDocument') + bgui.dockWidget.generateButton.enabled = False + +# def slotRelabelDocument(self, doc): +# print('slotRelabelDocument') + + def slotActivateDocument(self, doc): + print('slotActivateDocument') + bgui.dockWidget.generateButton.enabled = True + +# def slotCreatedObject(self, obj): +# print('slotCreatedObject') + +# def slotDeletedObject(self, obj): +# print('slotDeletedObject') + +# def slotChangedObject(self, obj, prop): +# print('slotChangedObject') + +class BoxerGui(object): + def __init__(self): + from PySide import QtGui, QtCore + + self.dockWidget = dockWidget = QtGui.QDockWidget() + dockWidget.setWindowTitle("Box config") + dockWidget.ui = BoxerDockWidget.Ui_BoxerDockWidget() + dockWidget.generateClicked = self.generateButtonClick + dockWidget.ui.setupUi(dockWidget) + + self.documentObserver = BoxerDocumentObserver() + +print('BoxerGui: ' + str(BoxerGui)) + +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): + 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") + return + + def IsActive(self): + return FreeCAD.ActiveDocument is not None + +class ShowPanelCommandClass(): + def GetResources(self): + return { + 'MenuText': "Show Panel"} + + def generateButtonClick(e): + print("generateButtonClick!") + + def Activated(self): + 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") + + dockWiget = bgui.dockWidget + + window = FreeCADGui.getMainWindow() + window.addDockWidget(QtCore.Qt.RightDockWidgetArea, dockWidget) + +# 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): + return True + +bgui = None diff --git a/BoxerGui.py b/BoxerGui.py new file mode 100644 index 0000000..b4d6258 --- /dev/null +++ b/BoxerGui.py @@ -0,0 +1,89 @@ +import FreeCAD +from FreeCAD import Gui +from PySide import QtGui, QtCore +import Boxer, BoxerDockWidget + +class BoxerDocumentObserver: + def __init__(self): + pass + +# def slotCreatedDocument(self, doc): +# print('slotCreatedDocument') + + def slotDeletedDocument(self, doc): + print('slotDeletedDocument') + gui.dockWidget.ui.generateButton.setEnabled(False) + +# def slotRelabelDocument(self, doc): +# print('slotRelabelDocument') + + def slotActivateDocument(self, doc): + print('slotActivateDocument') + gui.dockWidget.ui.generateButton.setEnabled(True) + +# def slotCreatedObject(self, obj): +# print('slotCreatedObject') + +# def slotDeletedObject(self, obj): +# print('slotDeletedObject') + +# def slotChangedObject(self, obj, prop): +# print('slotChangedObject') + +class BoxerGui(object): + + def __init__(self): + self.cfg = Boxer.BoxCfg().outerDimmensions(100, 100, 100) + 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.generateButtonClick + dockWidget.ui.setupUi(dockWidget) + dockWidget.ui.generateButton.setEnabled(doc is not None) + 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.documentObserver = BoxerDocumentObserver() + FreeCAD.addDocumentObserver(self.documentObserver) + + def generateButtonClick(self): + 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() + + self.cfg.prt() + self.removeBox() + doc = FreeCAD.ActiveDocument + Boxer.makeBox(doc, self.cfg) + + 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") + +gui = BoxerGui() +gui.setupGui() diff --git a/BoxerPanelWidget.py b/BoxerPanelWidget.py new file mode 100644 index 0000000..6893f43 --- /dev/null +++ b/BoxerPanelWidget.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- + +# Form implementation generated from reading ui file 'BoxerPanelWidget.ui' +# +# Created: Wed May 25 20:56:50 2016 +# by: pyside-uic 0.2.15 running on PySide 1.2.2 +# +# WARNING! All changes made in this file will be lost! + +from PySide import QtCore, QtGui + +class Ui_BoxerDockWidget(object): + def setupUi(self, BoxerDockWidget): + BoxerDockWidget.setObjectName("BoxerDockWidget") + BoxerDockWidget.resize(400, 300) + self.dockWidgetContents = QtGui.QWidget() + self.dockWidgetContents.setObjectName("dockWidgetContents") + self.gridLayout = QtGui.QGridLayout(self.dockWidgetContents) + self.gridLayout.setObjectName("gridLayout") + self.tabSizeLabel = QtGui.QLabel(self.dockWidgetContents) + self.tabSizeLabel.setObjectName("tabSizeLabel") + self.gridLayout.addWidget(self.tabSizeLabel, 0, 0, 1, 1) + self.tabSize = QtGui.QLineEdit(self.dockWidgetContents) + self.tabSize.setMinimumSize(QtCore.QSize(312, 32)) + self.tabSize.setInputMethodHints(QtCore.Qt.ImhDigitsOnly) + self.tabSize.setObjectName("tabSize") + self.gridLayout.addWidget(self.tabSize, 1, 0, 1, 1) + self.lineEdit = QtGui.QLineEdit(self.dockWidgetContents) + self.lineEdit.setObjectName("lineEdit") + self.gridLayout.addWidget(self.lineEdit, 2, 0, 1, 1) + self.generateButton = QtGui.QPushButton(self.dockWidgetContents) + self.generateButton.setObjectName("generateButton") + self.gridLayout.addWidget(self.generateButton, 3, 0, 1, 1) + BoxerDockWidget.setWidget(self.dockWidgetContents) + + self.retranslateUi(BoxerDockWidget) + QtCore.QMetaObject.connectSlotsByName(BoxerDockWidget) + + def retranslateUi(self, BoxerDockWidget): + BoxerDockWidget.setWindowTitle(QtGui.QApplication.translate("BoxerDockWidget", "DockWidget", None, QtGui.QApplication.UnicodeUTF8)) + self.tabSizeLabel.setText(QtGui.QApplication.translate("BoxerDockWidget", "Tab size", None, QtGui.QApplication.UnicodeUTF8)) + self.generateButton.setText(QtGui.QApplication.translate("BoxerDockWidget", "Generate", None, QtGui.QApplication.UnicodeUTF8)) + diff --git a/BoxerPanelWidget.ui b/BoxerPanelWidget.ui new file mode 100644 index 0000000..5feaf7d --- /dev/null +++ b/BoxerPanelWidget.ui @@ -0,0 +1,53 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>BoxerDockWidget</class> + <widget class="QDockWidget" name="BoxerDockWidget"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>400</width> + <height>300</height> + </rect> + </property> + <property name="windowTitle"> + <string>DockWidget</string> + </property> + <widget class="QWidget" name="dockWidgetContents"> + <layout class="QGridLayout" name="gridLayout"> + <item row="0" column="0"> + <widget class="QLabel" name="tabSizeLabel"> + <property name="text"> + <string>Tab size</string> + </property> + </widget> + </item> + <item row="1" column="0"> + <widget class="QLineEdit" name="tabSize"> + <property name="minimumSize"> + <size> + <width>312</width> + <height>32</height> + </size> + </property> + <property name="inputMethodHints"> + <set>Qt::ImhDigitsOnly</set> + </property> + </widget> + </item> + <item row="2" column="0"> + <widget class="QLineEdit" name="lineEdit"/> + </item> + <item row="3" column="0"> + <widget class="QPushButton" name="generateButton"> + <property name="text"> + <string>Generate</string> + </property> + </widget> + </item> + </layout> + </widget> + </widget> + <resources/> + <connections/> +</ui> @@ -1 +1 @@ -print "Caser loaded" + @@ -1,16 +1,92 @@ -print "GUI: Caser loaded" +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 BoxerWorkbench (Workbench): +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"} + + def Activated(self): + from PySide import QtCore + 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): + return True + +class BoxerWorkbench(Workbench): MenuText = "Boxer" ToolTip = "Box Maker" -# Icon = def Initialize(self): - import Boxer - self.list = ["BoxerMakeBox", "BoxerRemoveBox"] - self.appendToolbar("Boxer Commands", self.list) - + self.list = ["BoxerMakeBox", "BoxerRemoveBox", "BoxerShowPanel"] + self.appendToolbar("Boxer Commands", self.list) + import BoxerGui + def Activated(self): return @@ -23,5 +99,8 @@ class BoxerWorkbench (Workbench): def GetClassName(self): return "Gui::PythonWorkbench" - + +Gui.addCommand('BoxerMakeBox', MakeBoxCommandClass()) +Gui.addCommand('BoxerRemoveBox', RemoveBoxCommandClass()) +Gui.addCommand('BoxerShowPanel', ShowPanelCommandClass()) Gui.addWorkbench(BoxerWorkbench()) diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..d88fa9c --- /dev/null +++ b/Makefile @@ -0,0 +1,11 @@ +PY=BoxerPanelWidget.py BoxerDockWidget.py + +all: $(PY) + +clean: + rm -f $(PY) + +#BoxerPanelWidget.py: BoxerPanelWidget.ui + +%.py: %.ui + pyside-uic -o $@ $< |