From 739b0e37ee6ce461cdfa550f3a5d410470f18f6c Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Wed, 25 May 2016 23:31:20 +0200 Subject: o Working FreeCAD module for creating boxes useful for laser cutting. --- BoxerGui | 135 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 135 insertions(+) create mode 100644 BoxerGui (limited to 'BoxerGui') 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 -- cgit v1.2.3