All: Reformat according to new standard

This commit is contained in:
pre-commit-ci[bot]
2025-11-11 13:49:01 +01:00
committed by Kacper Donat
parent ef997f2259
commit 9fe130cd73
2390 changed files with 154630 additions and 115818 deletions

View File

@@ -1,23 +1,23 @@
#***************************************************************************
#* Copyright (c) 2014 Juergen Riegel <FreeCAD@juergen-riegel.net> *
#* *
#* 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. *
#* *
#* This program 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 this program; if not, write to the Free Software *
#* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
#* USA *
#* *
#***************************************************************************
# ***************************************************************************
# * Copyright (c) 2014 Juergen Riegel <FreeCAD@juergen-riegel.net> *
# * *
# * 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. *
# * *
# * This program 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 this program; if not, write to the Free Software *
# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
# * USA *
# * *
# ***************************************************************************
import pathlib
import FreeCAD, Part
@@ -29,35 +29,40 @@ if FreeCAD.GuiUp:
import FreeCADGui
from PySide import QtGui
__title__="PartDesign InvoluteGearObject management"
__title__ = "PartDesign InvoluteGearObject management"
__author__ = "Juergen Riegel"
__url__ = "https://www.freecad.org"
def makeInvoluteGear(name):
'''makeInvoluteGear(name): makes an InvoluteGear'''
obj = FreeCAD.ActiveDocument.addObject("Part::Part2DObjectPython",name)
"""makeInvoluteGear(name): makes an InvoluteGear"""
obj = FreeCAD.ActiveDocument.addObject("Part::Part2DObjectPython", name)
_InvoluteGear(obj)
if FreeCAD.GuiUp:
_ViewProviderInvoluteGear(obj.ViewObject)
#FreeCAD.ActiveDocument.recompute()
# FreeCAD.ActiveDocument.recompute()
if FreeCAD.GuiUp:
body=FreeCADGui.ActiveDocument.ActiveView.getActiveObject("pdbody")
part=FreeCADGui.ActiveDocument.ActiveView.getActiveObject("part")
body = FreeCADGui.ActiveDocument.ActiveView.getActiveObject("pdbody")
part = FreeCADGui.ActiveDocument.ActiveView.getActiveObject("part")
if body:
body.Group=body.Group+[obj]
body.Group = body.Group + [obj]
elif part:
part.Group=part.Group+[obj]
part.Group = part.Group + [obj]
return obj
class CommandInvoluteGear:
"GUI command to create an InvoluteGear"
def GetResources(self):
return {'Pixmap' : 'PartDesign_InternalExternalGear',
'MenuText': QtCore.QT_TRANSLATE_NOOP("PartDesign_InvoluteGear","Involute Gear"),
'Accel': "",
'ToolTip': QtCore.QT_TRANSLATE_NOOP("PartDesign_InvoluteGear","Creates or edits the involute gear definition")}
return {
"Pixmap": "PartDesign_InternalExternalGear",
"MenuText": QtCore.QT_TRANSLATE_NOOP("PartDesign_InvoluteGear", "Involute Gear"),
"Accel": "",
"ToolTip": QtCore.QT_TRANSLATE_NOOP(
"PartDesign_InvoluteGear", "Creates or edits the involute gear definition"
),
}
def Activated(self):
FreeCAD.ActiveDocument.openTransaction("Create involute gear")
@@ -74,7 +79,8 @@ class CommandInvoluteGear:
class _InvoluteGear:
"The InvoluteGear object"
def __init__(self,obj):
def __init__(self, obj):
self.Type = "InvoluteGear"
self._ensure_properties(obj, is_restore=False)
obj.Proxy = self
@@ -94,45 +100,94 @@ class _InvoluteGear:
# for details about the property's docstring translation,
# see https://tracker.freecad.org/view.php?id=2524
ensure_property("App::PropertyInteger", "NumberOfTeeth",
ensure_property(
"App::PropertyInteger",
"NumberOfTeeth",
doc=QtCore.QT_TRANSLATE_NOOP("App::Property", "Number of gear teeth"),
default=26)
ensure_property("App::PropertyLength", "Modules",
default=26,
)
ensure_property(
"App::PropertyLength",
"Modules",
doc=QtCore.QT_TRANSLATE_NOOP("App::Property", "Module of the gear"),
default="2.5 mm")
ensure_property("App::PropertyAngle", "PressureAngle",
default="2.5 mm",
)
ensure_property(
"App::PropertyAngle",
"PressureAngle",
doc=QtCore.QT_TRANSLATE_NOOP("App::Property", "Pressure angle of gear teeth"),
default="20 deg")
ensure_property("App::PropertyBool", "HighPrecision",
doc=QtCore.QT_TRANSLATE_NOOP("App::Property",
"True=2 curves with each 3 control points, False=1 curve with 4 control points."),
default=True)
ensure_property("App::PropertyBool", "ExternalGear",
doc=QtCore.QT_TRANSLATE_NOOP("App::Property", "True=external Gear, False=internal Gear"),
default=True)
ensure_property("App::PropertyFloat", "AddendumCoefficient",
doc=QtCore.QT_TRANSLATE_NOOP("App::Property",
"The height of the tooth from the pitch circle up to its tip, normalized by the module."),
default=lambda: 1.0 if obj.ExternalGear else 0.6)
ensure_property("App::PropertyFloat","DedendumCoefficient",
doc=QtCore.QT_TRANSLATE_NOOP("App::Property",
"The height of the tooth from the pitch circle down to its root, normalized by the module."),
default=1.25)
ensure_property("App::PropertyFloat","RootFilletCoefficient",
doc=QtCore.QT_TRANSLATE_NOOP("App::Property",
"The radius of the fillet at the root of the tooth, normalized by the module."),
default=lambda: 0.375 if is_restore else 0.38)
ensure_property("App::PropertyFloat","ProfileShiftCoefficient",
doc=QtCore.QT_TRANSLATE_NOOP("App::Property",
"The distance by which the reference profile is shifted outwards, normalized by the module."),
default=0.0)
default="20 deg",
)
ensure_property(
"App::PropertyBool",
"HighPrecision",
doc=QtCore.QT_TRANSLATE_NOOP(
"App::Property",
"True=2 curves with each 3 control points, False=1 curve with 4 control points.",
),
default=True,
)
ensure_property(
"App::PropertyBool",
"ExternalGear",
doc=QtCore.QT_TRANSLATE_NOOP(
"App::Property", "True=external Gear, False=internal Gear"
),
default=True,
)
ensure_property(
"App::PropertyFloat",
"AddendumCoefficient",
doc=QtCore.QT_TRANSLATE_NOOP(
"App::Property",
"The height of the tooth from the pitch circle up to its tip, normalized by the module.",
),
default=lambda: 1.0 if obj.ExternalGear else 0.6,
)
ensure_property(
"App::PropertyFloat",
"DedendumCoefficient",
doc=QtCore.QT_TRANSLATE_NOOP(
"App::Property",
"The height of the tooth from the pitch circle down to its root, normalized by the module.",
),
default=1.25,
)
ensure_property(
"App::PropertyFloat",
"RootFilletCoefficient",
doc=QtCore.QT_TRANSLATE_NOOP(
"App::Property",
"The radius of the fillet at the root of the tooth, normalized by the module.",
),
default=lambda: 0.375 if is_restore else 0.38,
)
ensure_property(
"App::PropertyFloat",
"ProfileShiftCoefficient",
doc=QtCore.QT_TRANSLATE_NOOP(
"App::Property",
"The distance by which the reference profile is shifted outwards, normalized by the module.",
),
default=0.0,
)
def execute(self,obj):
def execute(self, obj):
w = fcgear.FCWireBuilder()
generator_func = involute.CreateExternalGear if obj.ExternalGear else involute.CreateInternalGear
generator_func(w, obj.Modules.Value, obj.NumberOfTeeth, obj.PressureAngle.Value,
split=obj.HighPrecision, addCoeff=obj.AddendumCoefficient, dedCoeff=obj.DedendumCoefficient,
filletCoeff=obj.RootFilletCoefficient, shiftCoeff=obj.ProfileShiftCoefficient)
generator_func = (
involute.CreateExternalGear if obj.ExternalGear else involute.CreateInternalGear
)
generator_func(
w,
obj.Modules.Value,
obj.NumberOfTeeth,
obj.PressureAngle.Value,
split=obj.HighPrecision,
addCoeff=obj.AddendumCoefficient,
dedCoeff=obj.DedendumCoefficient,
filletCoeff=obj.RootFilletCoefficient,
shiftCoeff=obj.ProfileShiftCoefficient,
)
gearw = Part.Wire([o.toShape() for o in w.wire])
obj.Shape = gearw
obj.positionBySupport()
@@ -142,7 +197,7 @@ class _InvoluteGear:
class _ViewProviderInvoluteGear:
"A View Provider for the InvoluteGear object"
def __init__(self,vobj):
def __init__(self, vobj):
vobj.Proxy = self
def getIcon(self):
@@ -152,62 +207,77 @@ class _ViewProviderInvoluteGear:
self.ViewObject = vobj
self.Object = vobj.Object
def setEdit(self,vobj,mode):
taskd = _InvoluteGearTaskPanel(self.Object,mode)
def setEdit(self, vobj, mode):
taskd = _InvoluteGearTaskPanel(self.Object, mode)
taskd.obj = vobj.Object
taskd.update()
FreeCADGui.Control.showDialog(taskd)
return True
def unsetEdit(self,vobj,mode):
def unsetEdit(self, vobj, mode):
FreeCADGui.Control.closeDialog()
return
def dumps(self):
return None
def loads(self,state):
def loads(self, state):
return None
class _InvoluteGearTaskPanel:
'''The editmode TaskPanel for InvoluteGear objects'''
def __init__(self,obj,mode):
"""The editmode TaskPanel for InvoluteGear objects"""
def __init__(self, obj, mode):
self.obj = obj
self.form=FreeCADGui.PySideUic.loadUi(str(pathlib.Path(__file__).with_suffix(".ui")))
self.form = FreeCADGui.PySideUic.loadUi(str(pathlib.Path(__file__).with_suffix(".ui")))
self.form.setWindowIcon(QtGui.QIcon(":/icons/PartDesign_InternalExternalGear.svg"))
self.assignToolTipsFromPropertyDocs()
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.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.form.doubleSpinBox_ProfileShift.valueChanged.connect(assignValue("ProfileShiftCoefficient"))
self.form.doubleSpinBox_RootFillet.valueChanged.connect(
assignValue("RootFilletCoefficient")
)
self.form.doubleSpinBox_ProfileShift.valueChanged.connect(
assignValue("ProfileShiftCoefficient")
)
self.update()
if mode == 0: # fresh created
if mode == 0: # fresh created
self.obj.Proxy.execute(self.obj) # calculate once
FreeCAD.Gui.SendMsgToActiveView("ViewFit")
@@ -226,8 +296,14 @@ class _InvoluteGearTaskPanel:
assign("ExternalGear", self.form.comboBox_ExternalGear, self.form.label_ExternalGear)
assign("AddendumCoefficient", self.form.doubleSpinBox_Addendum, self.form.label_Addendum)
assign("DedendumCoefficient", self.form.doubleSpinBox_Dedendum, self.form.label_Dedendum)
assign("RootFilletCoefficient", self.form.doubleSpinBox_RootFillet, self.form.label_RootFillet)
assign("ProfileShiftCoefficient", self.form.doubleSpinBox_ProfileShift, self.form.label_ProfileShift)
assign(
"RootFilletCoefficient", self.form.doubleSpinBox_RootFillet, self.form.label_RootFillet
)
assign(
"ProfileShiftCoefficient",
self.form.doubleSpinBox_ProfileShift,
self.form.label_ProfileShift,
)
def changeEvent(self, event):
if event == QtCore.QEvent.LanguageChange:
@@ -235,11 +311,15 @@ class _InvoluteGearTaskPanel:
def transferTo(self):
"Transfer from the dialog to the object"
self.obj.NumberOfTeeth = self.form.spinBox_NumberOfTeeth.value()
self.obj.Modules = self.form.Quantity_Modules.text()
self.obj.PressureAngle = self.form.Quantity_PressureAngle.text()
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.NumberOfTeeth = self.form.spinBox_NumberOfTeeth.value()
self.obj.Modules = self.form.Quantity_Modules.text()
self.obj.PressureAngle = self.form.Quantity_PressureAngle.text()
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()
@@ -258,15 +338,17 @@ class _InvoluteGearTaskPanel:
self.form.doubleSpinBox_ProfileShift.setValue(self.obj.ProfileShiftCoefficient)
def getStandardButtons(self):
return QtGui.QDialogButtonBox.Ok | QtGui.QDialogButtonBox.Cancel | QtGui.QDialogButtonBox.Apply
return (
QtGui.QDialogButtonBox.Ok | QtGui.QDialogButtonBox.Cancel | QtGui.QDialogButtonBox.Apply
)
def clicked(self,button):
def clicked(self, button):
if button == QtGui.QDialogButtonBox.Apply:
self.transferTo()
self.obj.Proxy.execute(self.obj)
def update(self):
'fills the widgets'
"fills the widgets"
self.transferFrom()
def accept(self):