From 9c5706dc1f922ecd593ea57a9c499c0ca0311e78 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Sat, 4 Jun 2016 21:07:19 +0200 Subject: o Adding a special 'Fit all' button. --- Boxer.py | 3 +++ BoxerDockWidget.py | 27 ++++++++++++++++++++--- BoxerDockWidget.ui | 63 +++++++++++++++++++++++++++++++++++++++++++++++++----- BoxerGui.py | 24 +++++++++++++++++---- 4 files changed, 105 insertions(+), 12 deletions(-) diff --git a/Boxer.py b/Boxer.py index facb4e3..0319e43 100644 --- a/Boxer.py +++ b/Boxer.py @@ -363,11 +363,14 @@ def make(doc, cfg): doc.recompute() + crossSections = None if cfg.generateCrossSections: crossSections = makeCrossSections(doc, cfg, extrudes) crossSectionsGroup = doc.addObject("App::DocumentObjectGroup", "Cross Sections") [crossSectionsGroup.addObject(cs) for cs in crossSections.values()] + return {'parts': parts, 'extrudes': extrudes, 'crossSections': crossSections}; + def removeEverything(doc): def rm(name): if hasattr(doc, name): diff --git a/BoxerDockWidget.py b/BoxerDockWidget.py index 67dd59b..1d82898 100644 --- a/BoxerDockWidget.py +++ b/BoxerDockWidget.py @@ -2,7 +2,7 @@ # Form implementation generated from reading ui file 'BoxerDockWidget.ui' # -# Created: Wed May 25 23:23:01 2016 +# Created: Tue May 31 00:39:43 2016 # by: pyside-uic 0.2.15 running on PySide 1.2.2 # # WARNING! All changes made in this file will be lost! @@ -12,7 +12,7 @@ from PySide import QtCore, QtGui class Ui_BoxerDockWidget(object): def setupUi(self, BoxerDockWidget): BoxerDockWidget.setObjectName("BoxerDockWidget") - BoxerDockWidget.resize(499, 213) + BoxerDockWidget.resize(499, 522) self.dockWidgetContents = QtGui.QWidget() sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Preferred) sizePolicy.setHorizontalStretch(0) @@ -123,14 +123,34 @@ class Ui_BoxerDockWidget(object): self.generateButton.setMaximumSize(QtCore.QSize(484, 16777215)) self.generateButton.setObjectName("generateButton") self.verticalLayout.addWidget(self.generateButton) + self.line = QtGui.QFrame(self.dockWidgetContents) + self.line.setFrameShape(QtGui.QFrame.HLine) + self.line.setFrameShadow(QtGui.QFrame.Sunken) + self.line.setObjectName("line") + self.verticalLayout.addWidget(self.line) + self.horizontalLayout = QtGui.QHBoxLayout() + self.horizontalLayout.setObjectName("horizontalLayout") + self.verticalLayout.addLayout(self.horizontalLayout) + self.fitViewButton = QtGui.QPushButton(self.dockWidgetContents) + self.fitViewButton.setObjectName("fitViewButton") + self.verticalLayout.addWidget(self.fitViewButton) + spacerItem = QtGui.QSpacerItem(20, 40, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding) + self.verticalLayout.addItem(spacerItem) BoxerDockWidget.setWidget(self.dockWidgetContents) self.retranslateUi(BoxerDockWidget) QtCore.QObject.connect(self.generateButton, QtCore.SIGNAL("clicked()"), BoxerDockWidget.generateClicked) + QtCore.QObject.connect(self.fitViewButton, QtCore.SIGNAL("clicked()"), BoxerDockWidget.fitAllClicked) QtCore.QMetaObject.connectSlotsByName(BoxerDockWidget) + BoxerDockWidget.setTabOrder(self.outerWidth, self.outerHeight) + BoxerDockWidget.setTabOrder(self.outerHeight, self.outerDepth) + BoxerDockWidget.setTabOrder(self.outerDepth, self.innerWidth) BoxerDockWidget.setTabOrder(self.innerWidth, self.innerHeight) BoxerDockWidget.setTabOrder(self.innerHeight, self.innerDepth) - BoxerDockWidget.setTabOrder(self.innerDepth, self.generateButton) + BoxerDockWidget.setTabOrder(self.innerDepth, self.notchSize) + BoxerDockWidget.setTabOrder(self.notchSize, self.thickness) + BoxerDockWidget.setTabOrder(self.thickness, self.generateButton) + BoxerDockWidget.setTabOrder(self.generateButton, self.fitViewButton) def retranslateUi(self, BoxerDockWidget): BoxerDockWidget.setWindowTitle(QtGui.QApplication.translate("BoxerDockWidget", "DockWidget", None, QtGui.QApplication.UnicodeUTF8)) @@ -142,4 +162,5 @@ class Ui_BoxerDockWidget(object): 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)) + self.fitViewButton.setText(QtGui.QApplication.translate("BoxerDockWidget", "Fit all", None, QtGui.QApplication.UnicodeUTF8)) diff --git a/BoxerDockWidget.ui b/BoxerDockWidget.ui index dcac6a1..061cf31 100644 --- a/BoxerDockWidget.ui +++ b/BoxerDockWidget.ui @@ -8,7 +8,7 @@ 0 0 499 - 213 + 522 @@ -213,14 +213,50 @@ + + + + Qt::Horizontal + + + + + + + + + + Fit all + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + outerWidth + outerHeight + outerDepth innerWidth innerHeight innerDepth + notchSize + thickness generateButton + fitViewButton @@ -231,17 +267,34 @@ generateClicked() - 199 - 242 + 233 + 199 + + + 128 + 286 + + + + + fitViewButton + clicked() + BoxerDockWidget + fitAllClicked() + + + 255 + 244 - 208 - 110 + 122 + 350 generateClicked() + fitAllClicked() diff --git a/BoxerGui.py b/BoxerGui.py index c57a517..5cb8315 100644 --- a/BoxerGui.py +++ b/BoxerGui.py @@ -43,7 +43,8 @@ class BoxerGui(object): self.dockWidget = dockWidget = QtGui.QDockWidget() dockWidget.setWindowTitle("Box config") dockWidget.ui = BoxerDockWidget.Ui_BoxerDockWidget() - dockWidget.generateClicked = self.generateButtonClick + dockWidget.generateClicked = self.generateButtonClicked + dockWidget.fitAllClicked = self.fitAllButtonClicked dockWidget.ui.setupUi(dockWidget) dockWidget.ui.generateButton.setEnabled(doc is not None) dockWidget.ui.outerWidth.setValue(self.cfg.outerWidth) @@ -55,7 +56,7 @@ class BoxerGui(object): self.documentObserver = BoxerDocumentObserver() FreeCAD.addDocumentObserver(self.documentObserver) - def generateButtonClick(self): + def generateButtonClicked(self): ui = self.dockWidget.ui self.cfg.outerDimmensions( @@ -68,11 +69,26 @@ class BoxerGui(object): self.cfg.prt() doc = FreeCAD.ActiveDocument Boxer.removeEverything(doc) - Boxer.make(doc, self.cfg) - + objects = Boxer.make(doc, self.cfg) + + itemsToSelect = objects['parts'] + + extrudes = objects['extrudes'] + if extrudes is not None: + itemsToSelect = extrudes + + Gui.Selection.clearSelection() + [Gui.Selection.addSelection(e) for e in itemsToSelect.values()] + Gui.SendMsgToActiveView("ViewSelection") + Gui.Selection.clearSelection() + + def removeBox(self): doc = FreeCAD.ActiveDocument Boxer.removeEverything(doc) + def fitAllButtonClicked(self): + Gui.SendMsgToActiveView("ViewFit") + gui = BoxerGui() gui.setupGui() -- cgit v1.2.3