diff --git a/src/Mod/PartDesign/InvoluteGearFeature.py b/src/Mod/PartDesign/InvoluteGearFeature.py index dc2caee2a5..31216adea4 100644 --- a/src/Mod/PartDesign/InvoluteGearFeature.py +++ b/src/Mod/PartDesign/InvoluteGearFeature.py @@ -19,6 +19,7 @@ #* * #*************************************************************************** +import pathlib import FreeCAD, Part from fcgear import involute from fcgear import fcgear @@ -26,14 +27,12 @@ from fcgear import fcgear if FreeCAD.GuiUp: import FreeCADGui from PySide import QtCore, QtGui - from FreeCADGui import PySideUic as uic __title__="PartDesign InvoluteGearObject management" __author__ = "Juergen Riegel" __url__ = "http://www.freecadweb.org" - def makeInvoluteGear(name): '''makeInvoluteGear(name): makes an InvoluteGear''' obj = FreeCAD.ActiveDocument.addObject("Part::Part2DObjectPython",name) @@ -50,8 +49,9 @@ def makeInvoluteGear(name): part.Group=part.Group+[obj] return obj + class _CommandInvoluteGear: - "the Fem InvoluteGear command definition" + "GUI command to create an InvoluteGear" def GetResources(self): return {'Pixmap' : 'PartDesign_InternalExternalGear', 'MenuText': QtCore.QT_TRANSLATE_NOOP("PartDesign_InvoluteGear","Involute gear..."), @@ -59,7 +59,6 @@ class _CommandInvoluteGear: 'ToolTip': QtCore.QT_TRANSLATE_NOOP("PartDesign_InvoluteGear","Creates or edit the involute gear definition.")} def Activated(self): - FreeCAD.ActiveDocument.openTransaction("Create involute gear") FreeCADGui.addModule("InvoluteGearFeature") FreeCADGui.doCommand("InvoluteGearFeature.makeInvoluteGear('InvoluteGear')") @@ -125,7 +124,7 @@ class _InvoluteGear: filletCoeff=obj.RootFilletCoefficient) gearw = Part.Wire([o.toShape() for o in w.wire]) obj.Shape = gearw - obj.positionBySupport(); + obj.positionBySupport() return @@ -142,7 +141,6 @@ class _ViewProviderInvoluteGear: self.ViewObject = vobj self.Object = vobj.Object - def setEdit(self,vobj,mode): taskd = _InvoluteGearTaskPanel(self.Object,mode) taskd.obj = vobj.Object @@ -166,19 +164,33 @@ class _InvoluteGearTaskPanel: def __init__(self,obj,mode): self.obj = obj - self.form=FreeCADGui.PySideUic.loadUi(FreeCAD.getHomePath() + "Mod/PartDesign/InvoluteGearFeature.ui") + self.form=FreeCADGui.PySideUic.loadUi(str(pathlib.Path(__file__).with_suffix(".ui"))) self.form.setWindowIcon(QtGui.QIcon(":/icons/PartDesign_InternalExternalGear.svg")) - QtCore.QObject.connect(self.form.Quantity_Modules, QtCore.SIGNAL("valueChanged(double)"), self.modulesChanged) - QtCore.QObject.connect(self.form.Quantity_PressureAngle, QtCore.SIGNAL("valueChanged(double)"), self.angleChanged) - QtCore.QObject.connect(self.form.spinBox_NumberOfTeeth, QtCore.SIGNAL("valueChanged(int)"), self.numTeethChanged) - QtCore.QObject.connect(self.form.comboBox_HighPrecision, QtCore.SIGNAL("currentIndexChanged(int)"), self.numCurvesChanged) - #QtCore.QObject.connect(self.form.comboBox_ExternalGear, QtCore.SIGNAL("activated(QString)"), self.externalGearChanged) - #QtCore.QObject.connect(self.form.comboBox_ExternalGear, QtCore.SIGNAL("currentIndexChanged(int)"), self.externalGearChanged) - QtCore.QObject.connect(self.form.comboBox_ExternalGear, QtCore.SIGNAL("currentIndexChanged(int)"), self.externalGearChanged) - QtCore.QObject.connect(self.form.doubleSpinBox_Addendum, QtCore.SIGNAL("valueChanged(double)"), self.addendumChanged) - QtCore.QObject.connect(self.form.doubleSpinBox_Dedendum, QtCore.SIGNAL("valueChanged(double)"), self.dedendumChanged) - QtCore.QObject.connect(self.form.doubleSpinBox_RootFillet, QtCore.SIGNAL("valueChanged(double)"), self.rootFilletChanged) + def assignValue(property_name, fitView=False): + """Returns a function that takes a single value and assigns it to the given property""" + def assigner(value): + setattr(self.obj, property_name, value) + self.obj.Proxy.execute(self.obj) + if fitView: + FreeCAD.Gui.SendMsgToActiveView("ViewFit") + return assigner + + def assignIndexAsBool(property_name): + """Variant of assignValue that transforms the index of a Yes/No Combobox to a bool.""" + assigner = assignValue(property_name) + def transformingAssigner(value): + assigner(True if value == 0 else False) + return transformingAssigner + + self.form.Quantity_Modules.valueChanged.connect(assignValue("Modules", fitView=True)) + self.form.Quantity_PressureAngle.valueChanged.connect(assignValue("PressureAngle")) + self.form.spinBox_NumberOfTeeth.valueChanged.connect(assignValue("NumberOfTeeth", fitView=True)) + self.form.comboBox_HighPrecision.currentIndexChanged.connect(assignIndexAsBool("HighPrecision")) + self.form.comboBox_ExternalGear.currentIndexChanged.connect(assignIndexAsBool("ExternalGear")) + self.form.doubleSpinBox_Addendum.valueChanged.connect(assignValue("AddendumCoefficient")) + self.form.doubleSpinBox_Dedendum.valueChanged.connect(assignValue("DedendumCoefficient")) + self.form.doubleSpinBox_RootFillet.valueChanged.connect(assignValue("RootFilletCoefficient")) self.update() @@ -191,93 +203,28 @@ class _InvoluteGearTaskPanel: self.obj.NumberOfTeeth = self.form.spinBox_NumberOfTeeth.value() self.obj.Modules = self.form.Quantity_Modules.text() self.obj.PressureAngle = self.form.Quantity_PressureAngle.text() - if self.form.comboBox_HighPrecision.currentIndex() == 0: - self.obj.HighPrecision = True - else: - self.obj.HighPrecision = False - #self.obj.HighPrecision = self.form.comboBox_HighPrecision.currentIndex() - if self.form.comboBox_ExternalGear.currentIndex() == 0: - self.obj.ExternalGear = True - else: - self.obj.ExternalGear = False - #self.obj.ExternalGear = self.form.comboBox_ExternalGear.currentIndex() + self.obj.HighPrecision = True if self.form.comboBox_HighPrecision.currentIndex() == 0 else False + self.obj.ExternalGear = True if self.form.comboBox_ExternalGear.currentIndex() == 0 else False self.obj.AddendumCoefficient = self.form.doubleSpinBox_Addendum.value() self.obj.DedendumCoefficient = self.form.doubleSpinBox_Dedendum.value() self.obj.RootFilletCoefficient = self.form.doubleSpinBox_RootFillet.value() - def transferFrom(self): "Transfer from the object to the dialog" self.form.spinBox_NumberOfTeeth.setValue(self.obj.NumberOfTeeth) self.form.Quantity_Modules.setText(self.obj.Modules.UserString) self.form.Quantity_PressureAngle.setText(self.obj.PressureAngle.UserString) - if self.obj.HighPrecision: - self.form.comboBox_HighPrecision.setCurrentIndex(0) - else: - self.form.comboBox_HighPrecision.setCurrentIndex(1) - #self.form.comboBox_HighPrecision.setCurrentIndex(self.obj.HighPrecision) - if self.obj.ExternalGear: - self.form.comboBox_ExternalGear.setCurrentIndex(0) - else: - self.form.comboBox_ExternalGear.setCurrentIndex(1) - #self.form.comboBox_ExternalGear.setCurrentIndex(self.obj.ExternalGear) + self.form.comboBox_HighPrecision.setCurrentIndex(0 if self.obj.HighPrecision else 1) + self.form.comboBox_ExternalGear.setCurrentIndex(0 if self.obj.ExternalGear else 1) self.form.doubleSpinBox_Addendum.setValue(self.obj.AddendumCoefficient) self.form.doubleSpinBox_Dedendum.setValue(self.obj.DedendumCoefficient) self.form.doubleSpinBox_RootFillet.setValue(self.obj.RootFilletCoefficient) - def modulesChanged(self, value): - #print value - self.obj.Modules = value - self.obj.Proxy.execute(self.obj) - FreeCAD.Gui.SendMsgToActiveView("ViewFit") - - def angleChanged(self, value): - #print value - self.obj.PressureAngle = value - self.obj.Proxy.execute(self.obj) - - def numTeethChanged(self, value): - #print value - self.obj.NumberOfTeeth = value - self.obj.Proxy.execute(self.obj) - FreeCAD.Gui.SendMsgToActiveView("ViewFit") - - def numCurvesChanged(self, value): - #print value - if value == 0: - v=True - else: - v=False - self.obj.HighPrecision = v - self.obj.Proxy.execute(self.obj) - - def externalGearChanged(self, value): - #print value - if value == 0: - v=True - else: - v=False - self.obj.ExternalGear = v - self.obj.Proxy.execute(self.obj) - - def addendumChanged(self, value): - self.obj.AddendumCoefficient = value - self.obj.Proxy.execute(self.obj) - - def dedendumChanged(self, value): - self.obj.DedendumCoefficient = value - self.obj.Proxy.execute(self.obj) - - def rootFilletChanged(self, value): - self.obj.RootFilletCoefficient = value - self.obj.Proxy.execute(self.obj) - def getStandardButtons(self): return int(QtGui.QDialogButtonBox.Ok) | int(QtGui.QDialogButtonBox.Cancel)| int(QtGui.QDialogButtonBox.Apply) def clicked(self,button): if button == QtGui.QDialogButtonBox.Apply: - #print "Apply" self.transferTo() self.obj.Proxy.execute(self.obj) @@ -286,14 +233,11 @@ class _InvoluteGearTaskPanel: self.transferFrom() def accept(self): - #print 'accept(self)' self.transferTo() FreeCAD.ActiveDocument.recompute() FreeCADGui.ActiveDocument.resetEdit() - def reject(self): - #print 'reject(self)' FreeCADGui.ActiveDocument.resetEdit() FreeCAD.ActiveDocument.abortTransaction()