From 7bc2e3ad487fff0f16c20f18042b2e7b926b2525 Mon Sep 17 00:00:00 2001 From: vocx-fc Date: Tue, 11 Feb 2020 02:36:28 -0600 Subject: [PATCH] Draft: move ScaleTaskPanel to a module We remove it from `DraftGui.py` to reduce the size of this file. Then we import it and tie it to its command defined in `DraftTools.py`. --- src/Mod/Draft/CMakeLists.txt | 1 + src/Mod/Draft/DraftGui.py | 107 -------------- src/Mod/Draft/DraftTools.py | 5 +- src/Mod/Draft/drafttaskpanels/task_scale.py | 152 ++++++++++++++++++++ 4 files changed, 156 insertions(+), 109 deletions(-) create mode 100644 src/Mod/Draft/drafttaskpanels/task_scale.py diff --git a/src/Mod/Draft/CMakeLists.txt b/src/Mod/Draft/CMakeLists.txt index 0400cb1a5f47..fa8f6673c20a 100644 --- a/src/Mod/Draft/CMakeLists.txt +++ b/src/Mod/Draft/CMakeLists.txt @@ -93,6 +93,7 @@ SET(Draft_task_panels drafttaskpanels/task_circulararray.py drafttaskpanels/task_orthoarray.py drafttaskpanels/task_polararray.py + drafttaskpanels/task_scale.py drafttaskpanels/task_shapestring.py drafttaskpanels/README.md ) diff --git a/src/Mod/Draft/DraftGui.py b/src/Mod/Draft/DraftGui.py index 692b51319ad0..8e3798f8243d 100644 --- a/src/Mod/Draft/DraftGui.py +++ b/src/Mod/Draft/DraftGui.py @@ -2169,113 +2169,6 @@ def retranslateUi(self, TaskPanel): self.addButton.setText(QtGui.QApplication.translate("draft", "Add", None)) self.title.setText(QtGui.QApplication.translate("draft", "Facebinder elements", None)) - -class ScaleTaskPanel: - """A Task Panel for the Scale tool""" - - def __init__(self): - self.sourceCmd = None - self.form = QtGui.QWidget() - layout = QtGui.QGridLayout(self.form) - self.xLabel = QtGui.QLabel() - layout.addWidget(self.xLabel,0,0,1,1) - self.xValue = QtGui.QDoubleSpinBox() - self.xValue.setRange(.0000001,1000000.0) - self.xValue.setDecimals(Draft.getParam("precision")) - self.xValue.setValue(1) - layout.addWidget(self.xValue,0,1,1,1) - self.yLabel = QtGui.QLabel() - layout.addWidget(self.yLabel,1,0,1,1) - self.yValue = QtGui.QDoubleSpinBox() - self.yValue.setRange(.0000001,1000000.0) - self.yValue.setDecimals(Draft.getParam("precision")) - self.yValue.setValue(1) - layout.addWidget(self.yValue,1,1,1,1) - self.zLabel = QtGui.QLabel() - layout.addWidget(self.zLabel,2,0,1,1) - self.zValue = QtGui.QDoubleSpinBox() - self.zValue.setRange(.0000001,1000000.0) - self.zValue.setDecimals(Draft.getParam("precision")) - self.zValue.setValue(1) - layout.addWidget(self.zValue,2,1,1,1) - self.lock = QtGui.QCheckBox() - self.lock.setChecked(FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Draft").GetBool("ScaleUniform",False)) - layout.addWidget(self.lock,3,0,1,2) - self.relative = QtGui.QCheckBox() - self.relative.setChecked(FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Draft").GetBool("ScaleRelative",False)) - layout.addWidget(self.relative,4,0,1,2) - self.isCopy = QtGui.QCheckBox() - self.isCopy.setChecked(FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Draft").GetBool("ScaleCopy",False)) - layout.addWidget(self.isCopy,5,0,1,2) - self.isSubelementMode = QtGui.QCheckBox() - layout.addWidget(self.isSubelementMode,6,0,1,2) - self.isClone = QtGui.QCheckBox() - layout.addWidget(self.isClone,7,0,1,2) - self.isClone.setChecked(FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Draft").GetBool("ScaleClone",False)) - self.pickrefButton = QtGui.QPushButton() - layout.addWidget(self.pickrefButton,8,0,1,2) - QtCore.QObject.connect(self.xValue,QtCore.SIGNAL("valueChanged(double)"),self.setValue) - QtCore.QObject.connect(self.yValue,QtCore.SIGNAL("valueChanged(double)"),self.setValue) - QtCore.QObject.connect(self.zValue,QtCore.SIGNAL("valueChanged(double)"),self.setValue) - QtCore.QObject.connect(self.pickrefButton,QtCore.SIGNAL("clicked()"),self.pickRef) - QtCore.QObject.connect(self.lock,QtCore.SIGNAL("toggled(bool)"),self.setLock) - QtCore.QObject.connect(self.relative,QtCore.SIGNAL("toggled(bool)"),self.setRelative) - QtCore.QObject.connect(self.isCopy,QtCore.SIGNAL("toggled(bool)"),self.setCopy) - QtCore.QObject.connect(self.isClone,QtCore.SIGNAL("toggled(bool)"),self.setClone) - self.retranslateUi() - - def setLock(self,state): - FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Draft").SetBool("ScaleUniform",state) - - def setRelative(self,state): - FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Draft").SetBool("ScaleRelative",state) - - def setCopy(self,state): - FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Draft").SetBool("ScaleCopy",state) - if state and self.isClone.isChecked(): - self.isClone.setChecked(False) - - def setClone(self,state): - FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Draft").SetBool("ScaleClone",state) - if state and self.isCopy.isChecked(): - self.isCopy.setChecked(False) - - def setValue(self,val=None): - if self.lock.isChecked(): - self.xValue.setValue(val) - self.yValue.setValue(val) - self.zValue.setValue(val) - if self.sourceCmd: - self.sourceCmd.scaleGhost(self.xValue.value(),self.yValue.value(),self.zValue.value(),self.relative.isChecked()) - - def retranslateUi(self,widget=None): - self.form.setWindowTitle(QtGui.QApplication.translate("Draft", "Scale", None)) - self.xLabel.setText(QtGui.QApplication.translate("Draft", "X factor", None)) - self.yLabel.setText(QtGui.QApplication.translate("Draft", "Y factor", None)) - self.zLabel.setText(QtGui.QApplication.translate("Draft", "Z factor", None)) - self.lock.setText(QtGui.QApplication.translate("Draft", "Uniform scaling", None)) - self.relative.setText(QtGui.QApplication.translate("Draft", "Working plane orientation", None)) - self.isCopy.setText(QtGui.QApplication.translate("draft", "Copy")) - self.isSubelementMode.setText(QtGui.QApplication.translate("draft", "Modify subelements")) - self.pickrefButton.setText(QtGui.QApplication.translate("Draft", "Pick from/to points", None)) - self.isClone.setText(QtGui.QApplication.translate("Draft", "Create a clone", None)) - - def pickRef(self): - if self.sourceCmd: - self.sourceCmd.pickRef() - - def accept(self): - if self.sourceCmd: - self.sourceCmd.scale() - FreeCADGui.ActiveDocument.resetEdit() - return True - - def reject(self): - if self.sourceCmd: - self.sourceCmd.finish() - FreeCADGui.ActiveDocument.resetEdit() - return True - #def translateWidget(w, context=None, disAmb=None): # '''translator for items where retranslateUi() is unavailable. # translates widget w and children.''' diff --git a/src/Mod/Draft/DraftTools.py b/src/Mod/Draft/DraftTools.py index dcde86d859eb..912e11f8033d 100644 --- a/src/Mod/Draft/DraftTools.py +++ b/src/Mod/Draft/DraftTools.py @@ -39,10 +39,10 @@ import sys, os, FreeCAD, FreeCADGui, WorkingPlane, math, re, Draft, Draft_rc, DraftVecUtils from FreeCAD import Vector from PySide import QtCore,QtGui +import DraftGui from draftutils.todo import todo from draftutils.translate import translate import draftguitools.gui_snapper as gui_snapper -import DraftGui import draftguitools.gui_trackers as trackers from pivy import coin @@ -60,6 +60,7 @@ # import DraftFillet import draftguitools.gui_selectplane import drafttaskpanels.task_shapestring as task_shapestring +import drafttaskpanels.task_scale as task_scale #--------------------------------------------------------------------------- # Preflight stuff @@ -4130,7 +4131,7 @@ def numericInput(self,numx,numy,numz): self.ui.offUi() if self.call: self.view.removeEventCallback("SoEvent",self.call) - self.task = DraftGui.ScaleTaskPanel() + self.task = task_scale.ScaleTaskPanel() self.task.sourceCmd = self todo.delay(FreeCADGui.Control.showDialog,self.task) todo.delay(self.task.xValue.selectAll,None) diff --git a/src/Mod/Draft/drafttaskpanels/task_scale.py b/src/Mod/Draft/drafttaskpanels/task_scale.py new file mode 100644 index 000000000000..801bfb3365f4 --- /dev/null +++ b/src/Mod/Draft/drafttaskpanels/task_scale.py @@ -0,0 +1,152 @@ +"""Provide the task panel for the Draft Scale tool.""" +## @package task_scale +# \ingroup DRAFT +# \brief Provide the task panel for the Draft Scale tool. + +# *************************************************************************** +# * (c) 2009 Yorik van Havre * +# * (c) 2020 Eliud Cabrera Castillo * +# * * +# * This file is part of the FreeCAD CAx development system. * +# * * +# * This program is free software; you can redistribute it and/or modify * +# * it under the terms of the GNU Lesser General Public License (LGPL) * +# * as published by the Free Software Foundation; either version 2 of * +# * the License, or (at your option) any later version. * +# * for detail see the LICENCE text file. * +# * * +# * FreeCAD is distributed in the hope that it will be useful, * +# * but WITHOUT ANY WARRANTY; without even the implied warranty of * +# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +# * GNU Library General Public License for more details. * +# * * +# * You should have received a copy of the GNU Library General Public * +# * License along with FreeCAD; if not, write to the Free Software * +# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * +# * USA * +# * * +# *************************************************************************** +import sys +import FreeCAD as App +import FreeCADGui as Gui +import Draft +import Draft_rc +import DraftVecUtils +import DraftTools +import PySide.QtCore as QtCore +import PySide.QtGui as QtGui +from draftutils.translate import translate +from draftutils.messages import _msg, _err + +_Quantity = App.Units.Quantity + + +# So the resource file doesn't trigger errors from code checkers (flake8) +True if Draft_rc.__name__ else False + + +class ScaleTaskPanel: + """A Task Panel for the Scale tool""" + + def __init__(self): + self.sourceCmd = None + self.form = QtGui.QWidget() + layout = QtGui.QGridLayout(self.form) + self.xLabel = QtGui.QLabel() + layout.addWidget(self.xLabel,0,0,1,1) + self.xValue = QtGui.QDoubleSpinBox() + self.xValue.setRange(.0000001,1000000.0) + self.xValue.setDecimals(Draft.getParam("precision")) + self.xValue.setValue(1) + layout.addWidget(self.xValue,0,1,1,1) + self.yLabel = QtGui.QLabel() + layout.addWidget(self.yLabel,1,0,1,1) + self.yValue = QtGui.QDoubleSpinBox() + self.yValue.setRange(.0000001,1000000.0) + self.yValue.setDecimals(Draft.getParam("precision")) + self.yValue.setValue(1) + layout.addWidget(self.yValue,1,1,1,1) + self.zLabel = QtGui.QLabel() + layout.addWidget(self.zLabel,2,0,1,1) + self.zValue = QtGui.QDoubleSpinBox() + self.zValue.setRange(.0000001,1000000.0) + self.zValue.setDecimals(Draft.getParam("precision")) + self.zValue.setValue(1) + layout.addWidget(self.zValue,2,1,1,1) + self.lock = QtGui.QCheckBox() + self.lock.setChecked(App.ParamGet("User parameter:BaseApp/Preferences/Mod/Draft").GetBool("ScaleUniform", False)) + layout.addWidget(self.lock,3,0,1,2) + self.relative = QtGui.QCheckBox() + self.relative.setChecked(App.ParamGet("User parameter:BaseApp/Preferences/Mod/Draft").GetBool("ScaleRelative", False)) + layout.addWidget(self.relative,4,0,1,2) + self.isCopy = QtGui.QCheckBox() + self.isCopy.setChecked(App.ParamGet("User parameter:BaseApp/Preferences/Mod/Draft").GetBool("ScaleCopy", False)) + layout.addWidget(self.isCopy,5,0,1,2) + self.isSubelementMode = QtGui.QCheckBox() + layout.addWidget(self.isSubelementMode,6,0,1,2) + self.isClone = QtGui.QCheckBox() + layout.addWidget(self.isClone,7,0,1,2) + self.isClone.setChecked(App.ParamGet("User parameter:BaseApp/Preferences/Mod/Draft").GetBool("ScaleClone", False)) + self.pickrefButton = QtGui.QPushButton() + layout.addWidget(self.pickrefButton,8,0,1,2) + QtCore.QObject.connect(self.xValue,QtCore.SIGNAL("valueChanged(double)"),self.setValue) + QtCore.QObject.connect(self.yValue,QtCore.SIGNAL("valueChanged(double)"),self.setValue) + QtCore.QObject.connect(self.zValue,QtCore.SIGNAL("valueChanged(double)"),self.setValue) + QtCore.QObject.connect(self.pickrefButton,QtCore.SIGNAL("clicked()"),self.pickRef) + QtCore.QObject.connect(self.lock,QtCore.SIGNAL("toggled(bool)"),self.setLock) + QtCore.QObject.connect(self.relative,QtCore.SIGNAL("toggled(bool)"),self.setRelative) + QtCore.QObject.connect(self.isCopy,QtCore.SIGNAL("toggled(bool)"),self.setCopy) + QtCore.QObject.connect(self.isClone,QtCore.SIGNAL("toggled(bool)"),self.setClone) + self.retranslateUi() + + def setLock(self,state): + App.ParamGet("User parameter:BaseApp/Preferences/Mod/Draft").SetBool("ScaleUniform", state) + + def setRelative(self,state): + App.ParamGet("User parameter:BaseApp/Preferences/Mod/Draft").SetBool("ScaleRelative", state) + + def setCopy(self,state): + App.ParamGet("User parameter:BaseApp/Preferences/Mod/Draft").SetBool("ScaleCopy", state) + if state and self.isClone.isChecked(): + self.isClone.setChecked(False) + + def setClone(self,state): + App.ParamGet("User parameter:BaseApp/Preferences/Mod/Draft").SetBool("ScaleClone", state) + if state and self.isCopy.isChecked(): + self.isCopy.setChecked(False) + + def setValue(self,val=None): + if self.lock.isChecked(): + self.xValue.setValue(val) + self.yValue.setValue(val) + self.zValue.setValue(val) + if self.sourceCmd: + self.sourceCmd.scaleGhost(self.xValue.value(),self.yValue.value(),self.zValue.value(),self.relative.isChecked()) + + def retranslateUi(self,widget=None): + self.form.setWindowTitle(QtGui.QApplication.translate("Draft", "Scale", None)) + self.xLabel.setText(QtGui.QApplication.translate("Draft", "X factor", None)) + self.yLabel.setText(QtGui.QApplication.translate("Draft", "Y factor", None)) + self.zLabel.setText(QtGui.QApplication.translate("Draft", "Z factor", None)) + self.lock.setText(QtGui.QApplication.translate("Draft", "Uniform scaling", None)) + self.relative.setText(QtGui.QApplication.translate("Draft", "Working plane orientation", None)) + self.isCopy.setText(QtGui.QApplication.translate("draft", "Copy")) + self.isSubelementMode.setText(QtGui.QApplication.translate("draft", "Modify subelements")) + self.pickrefButton.setText(QtGui.QApplication.translate("Draft", "Pick from/to points", None)) + self.isClone.setText(QtGui.QApplication.translate("Draft", "Create a clone", None)) + + def pickRef(self): + if self.sourceCmd: + self.sourceCmd.pickRef() + + def accept(self): + if self.sourceCmd: + self.sourceCmd.scale() + Gui.ActiveDocument.resetEdit() + return True + + def reject(self): + if self.sourceCmd: + self.sourceCmd.finish() + Gui.ActiveDocument.resetEdit() + return True