From 4076e566c0bcdf10383bec045c65995e03853866 Mon Sep 17 00:00:00 2001 From: looooo Date: Tue, 2 Jan 2024 01:28:04 +0100 Subject: [PATCH] ruff formating --- freecad/gears/bevelgear.py | 3 +- freecad/gears/connector.py | 5 +-- freecad/gears/cycloidgear.py | 13 ++++--- freecad/gears/cycloidgearrack.py | 7 +--- freecad/gears/features.py | 5 ++- freecad/gears/hypocycloidgear.py | 3 +- freecad/gears/init_gui.py | 3 +- freecad/gears/internalinvolutegear.py | 13 ++++--- freecad/gears/involutegear.py | 12 +++---- freecad/gears/involutegearrack.py | 10 ++---- freecad/gears/lanterngear.py | 7 ++-- freecad/gears/timinggear.py | 7 +--- freecad/gears/timinggear_t.py | 52 ++++++++++++++------------- freecad/gears/wormgear.py | 1 - 14 files changed, 64 insertions(+), 77 deletions(-) diff --git a/freecad/gears/bevelgear.py b/freecad/gears/bevelgear.py index 86b6abd..c26e1e9 100644 --- a/freecad/gears/bevelgear.py +++ b/freecad/gears/bevelgear.py @@ -1,4 +1,3 @@ - # -*- coding: utf-8 -*- # *************************************************************************** # * * @@ -26,6 +25,7 @@ from pygears._functions import rotation3D from .features import BaseGear, fcvec, make_bspline_wire + class BevelGear(BaseGear): """parameters: @@ -204,4 +204,3 @@ class BevelGear(BaseGear): def spherical_rot(self, point, phi): new_phi = np.sqrt(np.linalg.norm(point)) * phi return rotation3D(new_phi)(point) - diff --git a/freecad/gears/connector.py b/freecad/gears/connector.py index 578acb7..c34bcf4 100644 --- a/freecad/gears/connector.py +++ b/freecad/gears/connector.py @@ -42,14 +42,16 @@ class ViewProviderGearConnector(object): def getIcon(self): return self.icon_fn - + if sys.version_info[0] == 3 and sys.version_info[1] >= 11: + def dumps(self): return {"icon_fn": self.icon_fn} def loads(self, state): self.icon_fn = state["icon_fn"] else: + def __getstate__(self): return {"icon_fn": self.icon_fn} @@ -57,7 +59,6 @@ class ViewProviderGearConnector(object): self.icon_fn = state["icon_fn"] - class GearConnector(object): def __init__(self, obj, master_gear, slave_gear): obj.addProperty( diff --git a/freecad/gears/cycloidgear.py b/freecad/gears/cycloidgear.py index 89c58a5..174f437 100644 --- a/freecad/gears/cycloidgear.py +++ b/freecad/gears/cycloidgear.py @@ -1,4 +1,3 @@ - # -*- coding: utf-8 -*- # *************************************************************************** # * * @@ -25,11 +24,12 @@ from pygears.cycloid_tooth import CycloidTooth from pygears._functions import rotation from .features import ( - BaseGear, - points_to_wire, - insert_fillet, - helicalextrusion, - rotate_tooth) + BaseGear, + points_to_wire, + insert_fillet, + helicalextrusion, + rotate_tooth, +) class CycloidGear(BaseGear): @@ -191,4 +191,3 @@ class CycloidGear(BaseGear): fp.height.Value * np.tan(fp.beta.Value * np.pi / 180) * 2 / fp.gear.d ) return helicalextrusion(base, fp.height.Value, twist_angle, fp.double_helix) - diff --git a/freecad/gears/cycloidgearrack.py b/freecad/gears/cycloidgearrack.py index e5f2dff..944e94e 100644 --- a/freecad/gears/cycloidgearrack.py +++ b/freecad/gears/cycloidgearrack.py @@ -25,12 +25,7 @@ import Part import numpy as np from pygears._functions import reflection -from .features import ( - BaseGear, - fcvec, - points_to_wire, - insert_fillet - ) +from .features import BaseGear, fcvec, points_to_wire, insert_fillet class CycloidGearRack(BaseGear): diff --git a/freecad/gears/features.py b/freecad/gears/features.py index 61d3a22..67648fc 100644 --- a/freecad/gears/features.py +++ b/freecad/gears/features.py @@ -36,7 +36,6 @@ from pygears._functions import ( ) - def fcvec(x): if len(x) == 2: return App.Vector(x[0], x[1], 0) @@ -69,6 +68,7 @@ class ViewProviderGear(object): return self.icon_fn if sys.version_info[0] == 3 and sys.version_info[1] >= 11: + def dumps(self): self._check_attr() return {"icon_fn": self.icon_fn} @@ -77,6 +77,7 @@ class ViewProviderGear(object): if state and "icon_fn" in state: self.icon_fn = state["icon_fn"] else: + def __getstate__(self): self._check_attr() return {"icon_fn": self.icon_fn} @@ -131,12 +132,14 @@ class BaseGear(object): raise NotImplementedError("generate_gear_shape not implemented") if sys.version_info[0] == 3 and sys.version_info[1] >= 11: + def loads(self, state): pass def dumps(self): pass else: + def __setstate__(self, state): pass diff --git a/freecad/gears/hypocycloidgear.py b/freecad/gears/hypocycloidgear.py index c0c5e1a..d6955d9 100644 --- a/freecad/gears/hypocycloidgear.py +++ b/freecad/gears/hypocycloidgear.py @@ -1,4 +1,3 @@ - # -*- coding: utf-8 -*- # *************************************************************************** # * * @@ -30,6 +29,7 @@ from pygears._functions import rotation from .features import BaseGear, make_bspline_wire + class HypoCycloidGear(BaseGear): """parameters: @@ -281,4 +281,3 @@ class HypoCycloidGear(BaseGear): if to_be_fused: return Part.makeCompound(to_be_fused) - diff --git a/freecad/gears/init_gui.py b/freecad/gears/init_gui.py index 6f3a8d7..1813904 100644 --- a/freecad/gears/init_gui.py +++ b/freecad/gears/init_gui.py @@ -90,6 +90,7 @@ if sys.version_info[0] == 3 and sys.version_info[1] >= 11: ) ) + class GearWorkbench(Workbench): """A freecad workbench aiming at gear design""" @@ -129,7 +130,7 @@ class GearWorkbench(Workbench): CreateLanternGear, CreateHypoCycloidGear, CreateCycloidRack, - CreateGearConnector + CreateGearConnector, ) self.appendToolbar("Gear", self.commands) diff --git a/freecad/gears/internalinvolutegear.py b/freecad/gears/internalinvolutegear.py index 78d169f..dbfc678 100644 --- a/freecad/gears/internalinvolutegear.py +++ b/freecad/gears/internalinvolutegear.py @@ -1,4 +1,3 @@ - # -*- coding: utf-8 -*- # *************************************************************************** # * * @@ -25,11 +24,12 @@ from pygears.involute_tooth import InvoluteTooth from pygears._functions import rotation from .features import ( - BaseGear, - points_to_wire, - insert_fillet, - helicalextrusion, - rotate_tooth) + BaseGear, + points_to_wire, + insert_fillet, + helicalextrusion, + rotate_tooth, +) class InternalInvoluteGear(BaseGear): @@ -246,4 +246,3 @@ class InternalInvoluteGear(BaseGear): inner_circle.reverse() base = Part.Face([outer_circle, inner_circle]) return base.extrude(App.Vector(0, 0, fp.height.Value)) - diff --git a/freecad/gears/involutegear.py b/freecad/gears/involutegear.py index 480ae08..2158b40 100644 --- a/freecad/gears/involutegear.py +++ b/freecad/gears/involutegear.py @@ -1,4 +1,3 @@ - # -*- coding: utf-8 -*- # *************************************************************************** # * * @@ -25,11 +24,12 @@ from pygears.involute_tooth import InvoluteTooth from pygears._functions import rotation from .features import ( - BaseGear, - points_to_wire, - insert_fillet, - helicalextrusion, - rotate_tooth) + BaseGear, + points_to_wire, + insert_fillet, + helicalextrusion, + rotate_tooth, +) class InvoluteGear(BaseGear): diff --git a/freecad/gears/involutegearrack.py b/freecad/gears/involutegearrack.py index 24325b9..7d54c12 100644 --- a/freecad/gears/involutegearrack.py +++ b/freecad/gears/involutegearrack.py @@ -1,4 +1,3 @@ - # -*- coding: utf-8 -*- # *************************************************************************** # * * @@ -24,12 +23,8 @@ import Part import numpy as np from pygears.involute_tooth import InvoluteRack -from .features import ( - BaseGear, - fcvec, - points_to_wire, - insert_fillet - ) +from .features import BaseGear, fcvec, points_to_wire, insert_fillet + class InvoluteGearRack(BaseGear): @@ -242,4 +237,3 @@ class InvoluteGearRack(BaseGear): fcvec([0.0, np.tan(beta) * obj.height.Value, obj.height.Value]) ) return Part.makeLoft([pol, pol2], True) - diff --git a/freecad/gears/lanterngear.py b/freecad/gears/lanterngear.py index ad2fcd0..3c6c7a8 100644 --- a/freecad/gears/lanterngear.py +++ b/freecad/gears/lanterngear.py @@ -1,4 +1,3 @@ - # -*- coding: utf-8 -*- # *************************************************************************** # * * @@ -85,8 +84,9 @@ class LanternGear(BaseGear): + 2 * r_r * np.sin(phi_min) ) - phi_min = sp.optimize.root( - find_phi_min, (phi_max + r_r / r_0 * 4) / 5).x[0] # , r_r / r_0, phi_max) + phi_min = sp.optimize.root(find_phi_min, (phi_max + r_r / r_0 * 4) / 5).x[ + 0 + ] # , r_r / r_0, phi_max) # phi_min = 0 # r_r / r_0 phi = np.linspace(phi_min, phi_max, fp.num_profiles) @@ -131,4 +131,3 @@ class LanternGear(BaseGear): return wi else: return Part.Face(wi).extrude(App.Vector(0, 0, fp.height)) - diff --git a/freecad/gears/timinggear.py b/freecad/gears/timinggear.py index c30cbc2..615a473 100644 --- a/freecad/gears/timinggear.py +++ b/freecad/gears/timinggear.py @@ -1,4 +1,3 @@ - # -*- coding: utf-8 -*- # *************************************************************************** # * * @@ -23,10 +22,7 @@ import Part import numpy as np from pygears._functions import reflection -from .features import ( - BaseGear, - part_arc_from_points_and_center -) +from .features import BaseGear, part_arc_from_points_and_center class TimingGear(BaseGear): @@ -287,4 +283,3 @@ class TimingGear(BaseGear): return wi else: return Part.Face(wi).extrude(App.Vector(0, 0, fp.height)) - diff --git a/freecad/gears/timinggear_t.py b/freecad/gears/timinggear_t.py index 4eded90..12898bb 100644 --- a/freecad/gears/timinggear_t.py +++ b/freecad/gears/timinggear_t.py @@ -23,10 +23,7 @@ import scipy as sp import FreeCAD as App import Part -from pygears._functions import ( - rotation, - reflection -) +from pygears._functions import rotation, reflection from .features import BaseGear, fcvec @@ -36,8 +33,15 @@ class TimingGearT(BaseGear): print("hello gear") obj.addProperty("App::PropertyLength", "pitch", "base", "pitch of gear") obj.addProperty("App::PropertyInteger", "teeth", "base", "number of teeth") - obj.addProperty("App::PropertyLength", "tooth_height", "base", "radial height of tooth") - obj.addProperty("App::PropertyLength", "u", "base", "radial distance from tooth-head to pitch circle") + obj.addProperty( + "App::PropertyLength", "tooth_height", "base", "radial height of tooth" + ) + obj.addProperty( + "App::PropertyLength", + "u", + "base", + "radial distance from tooth-head to pitch circle", + ) obj.addProperty("App::PropertyAngle", "alpha", "base", "angle of tooth flanks") obj.addProperty("App::PropertyLength", "height", "base", "extrusion height") obj.pitch = "5. mm" @@ -48,30 +52,30 @@ class TimingGearT(BaseGear): obj.height = "5 mm" self.obj = obj obj.Proxy = self - + def generate_gear_shape(self, fp): print("generate gear shape") pitch = fp.pitch.Value teeth = fp.teeth u = fp.u.Value tooth_height = fp.tooth_height.Value - alpha = fp.alpha.Value / 180. * np.pi # we need radiant + alpha = fp.alpha.Value / 180.0 * np.pi # we need radiant height = fp.height.Value - r_p = pitch * teeth / 2. / np.pi + r_p = pitch * teeth / 2.0 / np.pi gamma_0 = pitch / r_p gamma_1 = gamma_0 / 4 - p_A = np.array([ - np.cos(-gamma_1), - np.sin(-gamma_1) - ]) * (r_p - u - tooth_height / 2) - + p_A = np.array([np.cos(-gamma_1), np.sin(-gamma_1)]) * ( + r_p - u - tooth_height / 2 + ) + def line(s): - p = p_A + np.array([ - np.cos(alpha / 2 - gamma_1), - np.sin(alpha / 2 - gamma_1) - ]) * s + p = ( + p_A + + np.array([np.cos(alpha / 2 - gamma_1), np.sin(alpha / 2 - gamma_1)]) + * s + ) return p def dist_p1(s): @@ -79,14 +83,14 @@ class TimingGearT(BaseGear): def dist_p2(s): return (np.linalg.norm(line(s)) - (r_p - u)) ** 2 - - s1 = sp.optimize.minimize(dist_p1, 0.).x - s2 = sp.optimize.minimize(dist_p2, 0.).x + + s1 = sp.optimize.minimize(dist_p1, 0.0).x + s2 = sp.optimize.minimize(dist_p2, 0.0).x p_1 = line(s1) p_2 = line(s2) - mirror = reflection(0.) # reflect the points at the x-axis + mirror = reflection(0.0) # reflect the points at the x-axis p_3, p_4 = mirror(np.array([p_2, p_1])) rot = rotation(-gamma_0) # why is the rotation in wrong direction ??? @@ -97,7 +101,7 @@ class TimingGearT(BaseGear): l3 = Part.LineSegment(fcvec(p_3), fcvec(p_4)).toShape() l4 = Part.LineSegment(fcvec(p_4), fcvec(p_5)).toShape() w = Part.Wire([l1, l2, l3, l4]) - + # now using a FreeCAD Matrix (this will turn in the right direction) rot = App.Matrix() rot.rotateZ(gamma_0) @@ -110,4 +114,4 @@ class TimingGearT(BaseGear): return contour else: face = Part.Face(Part.Wire(wires)) - return face.extrude(App.Vector(0., 0., height)) + return face.extrude(App.Vector(0.0, 0.0, height)) diff --git a/freecad/gears/wormgear.py b/freecad/gears/wormgear.py index 3a9600e..f289e29 100644 --- a/freecad/gears/wormgear.py +++ b/freecad/gears/wormgear.py @@ -1,4 +1,3 @@ - # -*- coding: utf-8 -*- # *************************************************************************** # * *