diff --git a/freecad/gears/basegear.py b/freecad/gears/basegear.py index 96845e2..ca3d2d1 100644 --- a/freecad/gears/basegear.py +++ b/freecad/gears/basegear.py @@ -19,24 +19,21 @@ import os import sys -import FreeCAD as App +from freecad import app import Part import numpy as np import math from pygears import __version__ -from pygears.involute_tooth import InvoluteTooth, InvoluteRack -from pygears.cycloid_tooth import CycloidTooth -from pygears.bevel_tooth import BevelTooth from pygears._functions import arc_from_points_and_center def fcvec(x): if len(x) == 2: - return App.Vector(x[0], x[1], 0) + return app.Vector(x[0], x[1], 0) else: - return App.Vector(x[0], x[1], x[2]) + return app.Vector(x[0], x[1], x[2]) class ViewProviderGear(object): @@ -95,7 +92,7 @@ class BaseGear(object): # Needed to make this object "attachable", # aka able to attach parameterically to other objects # cf. https://wiki.freecadweb.org/Scripted_objects_with_attachment - if int(App.Version()[1]) >= 19: + if int(app.Version()[1]) >= 19: obj.addExtension("Part::AttachExtensionPython") else: obj.addExtension("Part::AttachExtensionPython", obj) @@ -146,7 +143,7 @@ class BaseGear(object): def part_arc_from_points_and_center(p_1, p_2, m): p_1, p_12, p_2 = arc_from_points_and_center(p_1, p_2, m) return Part.Arc( - App.Vector(*p_1, 0.0), App.Vector(*p_12, 0.0), App.Vector(*p_2, 0.0) + app.Vector(*p_1, 0.0), app.Vector(*p_12, 0.0), app.Vector(*p_2, 0.0) ) @@ -165,9 +162,9 @@ def helicalextrusion(face, height, angle, double_helix=False): direction = bool(angle < 0) if double_helix: spine = Part.makeHelix(pitch, height / 2.0, radius, cone_angle, direction) - spine.translate(App.Vector(0, 0, height / 2.0)) + spine.translate(app.Vector(0, 0, height / 2.0)) face = face.translated( - App.Vector(0, 0, height / 2.0) + app.Vector(0, 0, height / 2.0) ) # don't transform our argument else: spine = Part.makeHelix(pitch, height, radius, cone_angle, direction) @@ -193,8 +190,8 @@ def helicalextrusion(face, height, angle, double_helix=False): top_face = Part.Face(top_wires) shell_faces.append(top_face) if double_helix: - origin = App.Vector(0, 0, height / 2.0) - xy_normal = App.Vector(0, 0, 1) + origin = app.Vector(0, 0, height / 2.0) + xy_normal = app.Vector(0, 0, 1) mirror_xy = lambda f: f.mirror(origin, xy_normal) bottom_faces = list(map(mirror_xy, shell_faces)) shell_faces.extend(bottom_faces) @@ -244,7 +241,7 @@ def points_to_wire(pts): def rotate_tooth(base_tooth, num_teeth): - rot = App.Matrix() + rot = app.Matrix() rot.rotateZ(2 * np.pi / num_teeth) flat_shape = [base_tooth] for t in range(num_teeth - 1): @@ -258,7 +255,7 @@ def fillet_between_edges(edge_1, edge_2, radius): try: from Part import ChFi2d except ImportError: - App.Console.PrintWarning( + app.Console.PrintWarning( "Your freecad version has no python bindings for 2d-fillets" ) return [edge_1, edge_2] diff --git a/freecad/gears/bevelgear.py b/freecad/gears/bevelgear.py index 0916d6a..03ae55e 100644 --- a/freecad/gears/bevelgear.py +++ b/freecad/gears/bevelgear.py @@ -16,7 +16,7 @@ # * * # *************************************************************************** -import FreeCAD as App +from freecad import app import Part import numpy as np @@ -109,7 +109,7 @@ class BevelGear(BaseGear): fp.gear.pitch_angle = fp.pitch_angle.Value * np.pi / 180 max_height = fp.gear.module * fp.teeth / 2 / np.tan(fp.gear.pitch_angle) if fp.height >= max_height: - App.Console.PrintWarning( + app.Console.PrintWarning( "height must be smaller than {}".format(max_height) ) fp.gear.backlash = fp.backlash.Value @@ -158,7 +158,7 @@ class BevelGear(BaseGear): wires.append(make_bspline_wire(points)) shape = Part.makeLoft(wires, True) if fp.reset_origin: - mat = App.Matrix() + mat = app.Matrix() mat.A33 = -1 mat.move(fcvec([0, 0, scale_1])) shape = shape.transformGeometry(mat) diff --git a/freecad/gears/commands.py b/freecad/gears/commands.py index 157c34f..ca21e77 100644 --- a/freecad/gears/commands.py +++ b/freecad/gears/commands.py @@ -17,8 +17,8 @@ # *************************************************************************** import os -import FreeCAD -import FreeCADGui as Gui +from freecad import app +from freecad import gui from .basegear import ViewProviderGear, BaseGear @@ -48,33 +48,33 @@ class BaseCommand(object): pass def IsActive(self): - if FreeCAD.ActiveDocument is None: + if app.ActiveDocument is None: return False else: return True def Activated(self): - Gui.doCommandGui("import freecad.gears.commands") - Gui.doCommandGui( + gui.doCommandGui("import freecad.gears.commands") + gui.doCommandGui( "freecad.gears.commands.{}.create()".format(self.__class__.__name__) ) - FreeCAD.ActiveDocument.recompute() - Gui.SendMsgToActiveView("ViewFit") + app.ActiveDocument.recompute() + gui.SendMsgToActiveView("ViewFit") @classmethod def create(cls): - if FreeCAD.GuiUp: + if app.GuiUp: # borrowed from threaded profiles # puts the gear into an active container - body = Gui.ActiveDocument.ActiveView.getActiveObject("pdbody") - part = Gui.ActiveDocument.ActiveView.getActiveObject("part") + body = gui.ActiveDocument.ActiveView.getActiveObject("pdbody") + part = gui.ActiveDocument.ActiveView.getActiveObject("part") if body: - obj = FreeCAD.ActiveDocument.addObject( + obj = app.ActiveDocument.addObject( "PartDesign::FeaturePython", cls.NAME ) else: - obj = FreeCAD.ActiveDocument.addObject("Part::FeaturePython", cls.NAME) + obj = app.ActiveDocument.addObject("Part::FeaturePython", cls.NAME) ViewProviderGear(obj.ViewObject, cls.Pixmap) cls.GEAR_FUNCTION(obj) @@ -83,7 +83,7 @@ class BaseCommand(object): elif part: part.Group += [obj] else: - obj = FreeCAD.ActiveDocument.addObject("Part::FeaturePython", cls.NAME) + obj = app.ActiveDocument.addObject("Part::FeaturePython", cls.NAME) cls.GEAR_FUNCTION(obj) return obj @@ -199,17 +199,17 @@ class CreateGearConnector(BaseCommand): ToolTip = "Combine two gears" def Activated(self): - gear1 = Gui.Selection.getSelection()[0] + gear1 = gui.Selection.getSelection()[0] assert isinstance(gear1.Proxy, BaseGear) - gear2 = Gui.Selection.getSelection()[1] + gear2 = gui.Selection.getSelection()[1] assert isinstance(gear2.Proxy, BaseGear) # check if selected objects are beams - obj = FreeCAD.ActiveDocument.addObject("Part::FeaturePython", self.NAME) + obj = app.ActiveDocument.addObject("Part::FeaturePython", self.NAME) GearConnector(obj, gear1, gear2) ViewProviderGearConnector(obj.ViewObject) - FreeCAD.ActiveDocument.recompute() + app.ActiveDocument.recompute() return obj diff --git a/freecad/gears/connector.py b/freecad/gears/connector.py index c34bcf4..5a8042a 100644 --- a/freecad/gears/connector.py +++ b/freecad/gears/connector.py @@ -19,15 +19,17 @@ import os import sys import numpy as np -import FreeCAD + +from freecad import app + from pygears import __version__ +from pygears.computation import compute_shifted_gears from .involutegear import InvoluteGear from .internalinvolutegear import InternalInvoluteGear from .involutegearrack import InvoluteGearRack from .cycloidgear import CycloidGear from .cycloidgearrack import CycloidGearRack -from pygears.computation import compute_shifted_gears class ViewProviderGearConnector(object): @@ -108,16 +110,16 @@ class GearConnector(object): fp.slave_gear.shift, ) - mat0 = FreeCAD.Matrix() # unity matrix - trans = FreeCAD.Vector(dist) + mat0 = app.Matrix() # unity matrix + trans = app.Vector(dist) mat0.move(trans) - rot = FreeCAD.Rotation(FreeCAD.Vector(0, 0, 1), fp.angle1).toMatrix() + rot = app.Rotation(app.Vector(0, 0, 1), fp.angle1).toMatrix() angle2 = dw_master / dw_slave * fp.angle1.Value angle4 = dw_master / dw_slave * np.rad2deg(angle_master) - rot2 = FreeCAD.Rotation(FreeCAD.Vector(0, 0, 1), angle2).toMatrix() + rot2 = app.Rotation(app.Vector(0, 0, 1), angle2).toMatrix() angle3 = abs(fp.slave_gear.teeth % 2 - 1) * 180.0 / fp.slave_gear.teeth - rot3 = FreeCAD.Rotation(FreeCAD.Vector(0, 0, 1), angle3).toMatrix() - rot4 = FreeCAD.Rotation(FreeCAD.Vector(0, 0, 1), -angle4).toMatrix() + rot3 = app.Rotation(app.Vector(0, 0, 1), angle3).toMatrix() + rot4 = app.Rotation(app.Vector(0, 0, 1), -angle4).toMatrix() mat1 = rot * mat0 * rot2 * rot3 * rot4 mat1.move(fp.master_gear.Placement.Base) fp.slave_gear.Placement = mat1 @@ -141,16 +143,16 @@ class GearConnector(object): fp.slave_gear.shift, ) - mat0 = FreeCAD.Matrix() # unity matrix - trans = FreeCAD.Vector(dist) + mat0 = app.Matrix() # unity matrix + trans = app.Vector(dist) mat0.move(trans) - rot = FreeCAD.Rotation(FreeCAD.Vector(0, 0, 1), fp.angle1).toMatrix() + rot = app.Rotation(app.Vector(0, 0, 1), fp.angle1).toMatrix() angle2 = -dw_master / dw_slave * fp.angle1.Value angle4 = -dw_master / dw_slave * np.rad2deg(angle_master) - rot2 = FreeCAD.Rotation(FreeCAD.Vector(0, 0, 1), angle2).toMatrix() + rot2 = app.Rotation(app.Vector(0, 0, 1), angle2).toMatrix() angle3 = abs(fp.slave_gear.teeth % 2 - 1) * 180.0 / fp.slave_gear.teeth - rot3 = FreeCAD.Rotation(FreeCAD.Vector(0, 0, 1), angle3).toMatrix() - rot4 = FreeCAD.Rotation(FreeCAD.Vector(0, 0, 1), -angle4).toMatrix() + rot3 = app.Rotation(app.Vector(0, 0, 1), angle3).toMatrix() + rot4 = app.Rotation(app.Vector(0, 0, 1), -angle4).toMatrix() mat1 = rot * mat0 * rot2 * rot3 * rot4 mat1.move(fp.master_gear.Placement.Base) fp.slave_gear.Placement = mat1 @@ -168,15 +170,15 @@ class GearConnector(object): dw_master = fp.master_gear.dw.Value dw_slave = 0 dist = -(dw_master + dw_slave) / 2 - mat0 = FreeCAD.Matrix() # unity matrix - mat0.move(FreeCAD.Vector(dist, 0, 0)) - mat1 = FreeCAD.Matrix() - mat1.move(FreeCAD.Vector(0, np.deg2rad(fp.angle1.Value) * dw_master / 2, 0)) - mat2 = FreeCAD.Matrix() + mat0 = app.Matrix() # unity matrix + mat0.move(app.Vector(dist, 0, 0)) + mat1 = app.Matrix() + mat1.move(app.Vector(0, np.deg2rad(fp.angle1.Value) * dw_master / 2, 0)) + mat2 = app.Matrix() mat2.move( - FreeCAD.Vector(0, -np.deg2rad(fp.angle2.Value) * dw_master / 2, 0) + app.Vector(0, -np.deg2rad(fp.angle2.Value) * dw_master / 2, 0) ) - rot = FreeCAD.Rotation(FreeCAD.Vector(0, 0, 1), fp.angle1).toMatrix() + rot = app.Rotation(app.Vector(0, 0, 1), fp.angle1).toMatrix() mat3 = rot * mat2 * mat1 * mat0 mat3.move(fp.master_gear.Placement.Base) fp.slave_gear.Placement = mat3 @@ -190,16 +192,16 @@ class GearConnector(object): dw_master = fp.master_gear.dw dw_slave = fp.slave_gear.dw dist = (dw_master + dw_slave) / 2 - mat0 = FreeCAD.Matrix() # unity matrix - trans = FreeCAD.Vector(dist, 0, 0) + mat0 = app.Matrix() # unity matrix + trans = app.Vector(dist, 0, 0) mat0.move(trans) - rot = FreeCAD.Rotation(FreeCAD.Vector(0, 0, 1), fp.angle1).toMatrix() + rot = app.Rotation(app.Vector(0, 0, 1), fp.angle1).toMatrix() angle2 = dw_master / dw_slave * fp.angle1.Value angle4 = dw_master / dw_slave * np.rad2deg(angle_master) - rot2 = FreeCAD.Rotation(FreeCAD.Vector(0, 0, 1), angle2).toMatrix() + rot2 = app.Rotation(app.Vector(0, 0, 1), angle2).toMatrix() angle3 = abs(fp.slave_gear.teeth % 2 - 1) * 180.0 / fp.slave_gear.teeth - rot3 = FreeCAD.Rotation(FreeCAD.Vector(0, 0, 1), angle3).toMatrix() - rot4 = FreeCAD.Rotation(FreeCAD.Vector(0, 0, 1), -angle4).toMatrix() + rot3 = app.Rotation(app.Vector(0, 0, 1), angle3).toMatrix() + rot4 = app.Rotation(app.Vector(0, 0, 1), -angle4).toMatrix() mat1 = rot * mat0 * rot2 * rot3 * rot4 mat1.move(fp.master_gear.Placement.Base) fp.slave_gear.Placement = mat1 diff --git a/freecad/gears/crowngear.py b/freecad/gears/crowngear.py index 55ada9d..b64e9ad 100644 --- a/freecad/gears/crowngear.py +++ b/freecad/gears/crowngear.py @@ -19,7 +19,7 @@ import os import sys -import FreeCAD as App +from freecad import app import Part import numpy as np @@ -55,7 +55,7 @@ class CrownGear(BaseGear): self.obj = obj obj.Proxy = self - App.Console.PrintMessage( + app.Console.PrintMessage( "Gear module: Crown gear created, preview_mode = true for improved performance. " "Set preview_mode property to false when ready to cut teeth." ) @@ -112,7 +112,7 @@ class CrownGear(BaseGear): outer_circle = Part.Wire(Part.makeCircle(outer_diameter / 2.0)) inner_circle.reverse() face = Part.Face([outer_circle, inner_circle]) - solid = face.extrude(App.Vector([0.0, 0.0, -fp.thickness.Value])) + solid = face.extrude(app.Vector([0.0, 0.0, -fp.thickness.Value])) if fp.preview_mode: return solid @@ -134,7 +134,7 @@ class CrownGear(BaseGear): poly = Part.Wire(Part.makePolygon(list(map(fcvec, pts)))) polies.append(poly) loft = Part.makeLoft(polies, True) - rot = App.Matrix() + rot = app.Matrix() rot.rotateZ(2 * np.pi / t) cut_shapes = [] for _ in range(t): diff --git a/freecad/gears/cycloidgear.py b/freecad/gears/cycloidgear.py index 69a145d..848bc6d 100644 --- a/freecad/gears/cycloidgear.py +++ b/freecad/gears/cycloidgear.py @@ -16,7 +16,7 @@ # * * # *************************************************************************** -import FreeCAD as App +from freecad import app import Part import numpy as np @@ -185,7 +185,7 @@ class CycloidGear(BaseGear): return profile base = Part.Face(profile) if fp.beta.Value == 0: - return base.extrude(App.Vector(0, 0, fp.height.Value)) + return base.extrude(app.Vector(0, 0, fp.height.Value)) else: twist_angle = ( fp.height.Value * np.tan(fp.beta.Value * np.pi / 180) * 2 / fp.gear.d diff --git a/freecad/gears/cycloidgearrack.py b/freecad/gears/cycloidgearrack.py index 1ce459a..2650f13 100644 --- a/freecad/gears/cycloidgearrack.py +++ b/freecad/gears/cycloidgearrack.py @@ -19,7 +19,7 @@ import os import sys -import FreeCAD as App +from freecad import app import Part import numpy as np @@ -179,7 +179,7 @@ class CycloidGearRack(BaseGear): for i in range(obj.teeth - 1): tooth = tooth.copy() - tooth.translate(App.Vector(0, np.pi * m, 0)) + tooth.translate(app.Vector(0, np.pi * m, 0)) teeth.append(tooth) teeth[-1] = Part.Wire(teeth[-1].Edges[:-1]) @@ -187,7 +187,7 @@ class CycloidGearRack(BaseGear): if obj.add_endings: teeth = [Part.Wire(tooth_edges[0])] + teeth last_edge = tooth_edges[-1] - last_edge.translate(App.Vector(0, np.pi * m * (obj.teeth - 1), 0)) + last_edge.translate(app.Vector(0, np.pi * m * (obj.teeth - 1), 0)) teeth = teeth + [Part.Wire(last_edge)] p_start = np.array(teeth[0].Edges[0].firstVertex().Point[:-1]) diff --git a/freecad/gears/features.py b/freecad/gears/features.py index d2b40c5..c1a7283 100644 --- a/freecad/gears/features.py +++ b/freecad/gears/features.py @@ -17,7 +17,10 @@ # *************************************************************************** -# this file is only for backwards compatibility +# this file is only for backwards compatibility, and will be deleted in the future + +from warnings import warn +warn('This file is deprecated and will be deleted in the future', DeprecationWarning, stacklevel=2) from .timinggear_t import TimingGearT from .involutegear import InvoluteGear diff --git a/freecad/gears/hypocycloidgear.py b/freecad/gears/hypocycloidgear.py index cd4084f..92c33ad 100644 --- a/freecad/gears/hypocycloidgear.py +++ b/freecad/gears/hypocycloidgear.py @@ -19,9 +19,8 @@ import math import numpy as np -import scipy as sp -import FreeCAD as App +from freecad import app import Part from pygears.bevel_tooth import BevelTooth @@ -195,16 +194,16 @@ class HypoCycloidGear(BaseGear): minRadius = self.calc_pressure_limit(p, d, e, n, minAngle * math.pi / 180.0) maxRadius = self.calc_pressure_limit(p, d, e, n, maxAngle * math.pi / 180.0) # unused - # Part.Wire(Part.makeCircle(minRadius,App.Vector(-e, 0, 0))) - # Part.Wire(Part.makeCircle(maxRadius,App.Vector(-e, 0, 0))) + # Part.Wire(Part.makeCircle(minRadius, app.Vector(-e, 0, 0))) + # Part.Wire(Part.makeCircle(maxRadius, app.Vector(-e, 0, 0))) - App.Console.PrintMessage("Generating cam disk\r\n") + app.Console.PrintMessage("Generating cam disk\r\n") # generate the cam profile - note: shifted in -x by eccentricicy amount i = 0 x = self.calc_x(p, d, e, n, q * i / float(n)) y = self.calc_y(p, d, e, n, q * i / n) x, y = self.check_limit(x, y, maxRadius, minRadius, c) - points = [App.Vector(x - e, y, 0)] + points = [app.Vector(x - e, y, 0)] for i in range(0, s): x = self.calc_x(p, d, e, n, q * (i + 1) / n) y = self.calc_y(p, d, e, n, q * (i + 1) / n) @@ -213,10 +212,10 @@ class HypoCycloidGear(BaseGear): wi = make_bspline_wire([points]) wires = [] - mat = App.Matrix() - mat.move(App.Vector(e, 0.0, 0.0)) + mat = app.Matrix() + mat.move(app.Vector(e, 0.0, 0.0)) mat.rotateZ(2 * np.pi / n) - mat.move(App.Vector(-e, 0.0, 0.0)) + mat.move(app.Vector(-e, 0.0, 0.0)) for _ in range(n): wi = wi.transformGeometry(mat) wires.append(wi) @@ -225,7 +224,7 @@ class HypoCycloidGear(BaseGear): # add a circle in the center of the cam if fp.hole_radius.Value: centerCircle = Part.Face( - Part.Wire(Part.makeCircle(fp.hole_radius.Value, App.Vector(-e, 0, 0))) + Part.Wire(Part.makeCircle(fp.hole_radius.Value, app.Vector(-e, 0, 0))) ) cam = cam.cut(centerCircle) @@ -234,34 +233,34 @@ class HypoCycloidGear(BaseGear): if fp.disk_height.Value == 0: to_be_fused.append(cam) else: - to_be_fused.append(cam.extrude(App.Vector(0, 0, fp.disk_height.Value))) + to_be_fused.append(cam.extrude(app.Vector(0, 0, fp.disk_height.Value))) # secondary cam disk if fp.show_disk1 == True: - App.Console.PrintMessage("Generating secondary cam disk\r\n") + app.Console.PrintMessage("Generating secondary cam disk\r\n") second_cam = cam.copy() - mat = App.Matrix() + mat = app.Matrix() mat.rotateZ(np.pi) - mat.move(App.Vector(-e, 0, 0)) + mat.move(app.Vector(-e, 0, 0)) if n % 2 == 0: mat.rotateZ(np.pi / n) - mat.move(App.Vector(e, 0, 0)) + mat.move(app.Vector(e, 0, 0)) second_cam = second_cam.transformGeometry(mat) if fp.disk_height.Value == 0: to_be_fused.append(second_cam) else: to_be_fused.append( - second_cam.extrude(App.Vector(0, 0, -fp.disk_height.Value)) + second_cam.extrude(app.Vector(0, 0, -fp.disk_height.Value)) ) # pins if fp.show_pins == True: - App.Console.PrintMessage("Generating pins\r\n") + app.Console.PrintMessage("Generating pins\r\n") pins = [] for i in range(0, n + 1): x = p * n * math.cos(2 * math.pi / (n + 1) * i) y = p * n * math.sin(2 * math.pi / (n + 1) * i) - pins.append(Part.Wire(Part.makeCircle(d / 2, App.Vector(x, y, 0)))) + pins.append(Part.Wire(Part.makeCircle(d / 2, app.Vector(x, y, 0)))) pins = Part.Face(pins) @@ -273,9 +272,9 @@ class HypoCycloidGear(BaseGear): z_offset += -fp.disk_height.Value / 2 # extrude if z_offset != 0: - pins.translate(App.Vector(0, 0, z_offset)) + pins.translate(app.Vector(0, 0, z_offset)) if fp.pin_height != 0: - pins = pins.extrude(App.Vector(0, 0, fp.pin_height.Value)) + pins = pins.extrude(app.Vector(0, 0, fp.pin_height.Value)) to_be_fused.append(pins) diff --git a/freecad/gears/init_gui.py b/freecad/gears/init_gui.py index 1813904..fdfc65a 100644 --- a/freecad/gears/init_gui.py +++ b/freecad/gears/init_gui.py @@ -18,21 +18,11 @@ import os import sys -import FreeCADGui as Gui -import FreeCAD as App +from freecad import app +from freecad import gui __dirname__ = os.path.dirname(__file__) -try: - from FreeCADGui import Workbench -except ImportError as e: - App.Console.PrintWarning( - "you are using the GearWorkbench with an old version of FreeCAD (<0.16)" - ) - App.Console.PrintWarning( - "the class Workbench is loaded, although not imported: magic" - ) - if sys.version_info[0] == 3 and sys.version_info[1] >= 11: # only works with 0.21.2 and above @@ -43,8 +33,8 @@ if sys.version_info[0] == 3 and sys.version_info[1] >= 11: FC_COMMIT_REQUIRED = 33772 # Check FreeCAD version - App.Console.PrintLog("Checking FreeCAD version\n") - ver = App.Version() + app.Console.PrintLog("Checking FreeCAD version\n") + ver = app.Version() major_ver = int(ver[0]) minor_vers = ver[1].split(".") minor_ver = int(minor_vers[0]) @@ -77,7 +67,7 @@ if sys.version_info[0] == 3 and sys.version_info[1] >= 11: ) ) ): - App.Console.PrintWarning( + app.Console.PrintWarning( "FreeCAD version (currently {}.{}.{} ({})) must be at least {}.{}.{} ({}) in order to work with Python 3.11 and above\n".format( int(ver[0]), minor_ver, @@ -91,7 +81,7 @@ if sys.version_info[0] == 3 and sys.version_info[1] >= 11: ) -class GearWorkbench(Workbench): +class GearWorkbench(gui.Workbench): """A freecad workbench aiming at gear design""" MenuText = "Gear" @@ -135,19 +125,19 @@ class GearWorkbench(Workbench): self.appendToolbar("Gear", self.commands) self.appendMenu("Gear", self.commands) - Gui.addCommand("CreateInvoluteGear", CreateInvoluteGear()) - Gui.addCommand("CreateInternalInvoluteGear", CreateInternalInvoluteGear()) - Gui.addCommand("CreateCycloidGear", CreateCycloidGear()) - Gui.addCommand("CreateCycloidRack", CreateCycloidRack()) - Gui.addCommand("CreateBevelGear", CreateBevelGear()) - Gui.addCommand("CreateInvoluteRack", CreateInvoluteRack()) - Gui.addCommand("CreateCrownGear", CreateCrownGear()) - Gui.addCommand("CreateWormGear", CreateWormGear()) - Gui.addCommand("CreateTimingGearT", CreateTimingGearT()) - Gui.addCommand("CreateTimingGear", CreateTimingGear()) - Gui.addCommand("CreateLanternGear", CreateLanternGear()) - Gui.addCommand("CreateHypoCycloidGear", CreateHypoCycloidGear()) - Gui.addCommand("CreateGearConnector", CreateGearConnector()) + gui.addCommand("CreateInvoluteGear", CreateInvoluteGear()) + gui.addCommand("CreateInternalInvoluteGear", CreateInternalInvoluteGear()) + gui.addCommand("CreateCycloidGear", CreateCycloidGear()) + gui.addCommand("CreateCycloidRack", CreateCycloidRack()) + gui.addCommand("CreateBevelGear", CreateBevelGear()) + gui.addCommand("CreateInvoluteRack", CreateInvoluteRack()) + gui.addCommand("CreateCrownGear", CreateCrownGear()) + gui.addCommand("CreateWormGear", CreateWormGear()) + gui.addCommand("CreateTimingGearT", CreateTimingGearT()) + gui.addCommand("CreateTimingGear", CreateTimingGear()) + gui.addCommand("CreateLanternGear", CreateLanternGear()) + gui.addCommand("CreateHypoCycloidGear", CreateHypoCycloidGear()) + gui.addCommand("CreateGearConnector", CreateGearConnector()) def Activated(self): pass @@ -156,4 +146,4 @@ class GearWorkbench(Workbench): pass -Gui.addWorkbench(GearWorkbench()) +gui.addWorkbench(GearWorkbench()) diff --git a/freecad/gears/internalinvolutegear.py b/freecad/gears/internalinvolutegear.py index 18f4602..20a4e41 100644 --- a/freecad/gears/internalinvolutegear.py +++ b/freecad/gears/internalinvolutegear.py @@ -16,10 +16,11 @@ # * * # *************************************************************************** -import FreeCAD as App +import numpy as np + +from freecad import app import Part -import numpy as np from pygears.involute_tooth import InvoluteTooth from pygears._functions import rotation @@ -235,7 +236,7 @@ class InternalInvoluteGear(BaseGear): return Part.makeCompound([outer_circle, profile]) base = Part.Face([outer_circle, profile]) if fp.beta.Value == 0: - return base.extrude(App.Vector(0, 0, fp.height.Value)) + return base.extrude(app.Vector(0, 0, fp.height.Value)) else: twist_angle = fp.height.Value * np.tan(fp.gear.beta) * 2 / fp.gear.d return helicalextrusion( @@ -245,4 +246,4 @@ class InternalInvoluteGear(BaseGear): inner_circle = Part.Wire(Part.makeCircle(fp.dw / 2.0)) inner_circle.reverse() base = Part.Face([outer_circle, inner_circle]) - return base.extrude(App.Vector(0, 0, fp.height.Value)) + return base.extrude(app.Vector(0, 0, fp.height.Value)) diff --git a/freecad/gears/involutegear.py b/freecad/gears/involutegear.py index cf15ecf..f4b2f22 100644 --- a/freecad/gears/involutegear.py +++ b/freecad/gears/involutegear.py @@ -16,10 +16,11 @@ # * * # *************************************************************************** -import FreeCAD as App +import numpy as np + +from freecad import app import Part -import numpy as np from pygears.involute_tooth import InvoluteTooth from pygears._functions import rotation @@ -217,7 +218,7 @@ class InvoluteGear(BaseGear): r_root = float(obj.root_fillet * obj.module) if obj.undercut and r_root != 0.0: r_root = 0.0 - App.Console.PrintWarning( + app.Console.PrintWarning( "root fillet is not allowed if undercut is computed" ) if len(tooth.Edges) == 11: @@ -253,7 +254,7 @@ class InvoluteGear(BaseGear): return profile base = Part.Face(profile) if obj.beta.Value == 0: - return base.extrude(App.Vector(0, 0, obj.height.Value)) + return base.extrude(app.Vector(0, 0, obj.height.Value)) else: twist_angle = obj.height.Value * np.tan(obj.gear.beta) * 2 / obj.gear.d return helicalextrusion( diff --git a/freecad/gears/involutegearrack.py b/freecad/gears/involutegearrack.py index 58a48d8..be41176 100644 --- a/freecad/gears/involutegearrack.py +++ b/freecad/gears/involutegearrack.py @@ -16,13 +16,12 @@ # * * # *************************************************************************** +import numpy as np -import FreeCAD as App +from freecad import app import Part -import numpy as np from pygears.involute_tooth import InvoluteRack - from .basegear import BaseGear, fcvec, points_to_wire, insert_fillet @@ -192,7 +191,7 @@ class InvoluteGearRack(BaseGear): for i in range(obj.teeth - 1): tooth = tooth.copy() - tooth.translate(App.Vector(0, np.pi * m, 0)) + tooth.translate(app.Vector(0, np.pi * m, 0)) teeth.append(tooth) teeth[-1] = Part.Wire(teeth[-1].Edges[:-1]) @@ -200,7 +199,7 @@ class InvoluteGearRack(BaseGear): if obj.add_endings: teeth = [Part.Wire(tooth_edges[0])] + teeth last_edge = tooth_edges[-1] - last_edge.translate(App.Vector(0, np.pi * m * (obj.teeth - 1), 0)) + last_edge.translate(app.Vector(0, np.pi * m * (obj.teeth - 1), 0)) teeth = teeth + [Part.Wire(last_edge)] p_start = np.array(teeth[0].Edges[0].firstVertex().Point[:-1]) diff --git a/freecad/gears/lanterngear.py b/freecad/gears/lanterngear.py index c36b671..295ff29 100644 --- a/freecad/gears/lanterngear.py +++ b/freecad/gears/lanterngear.py @@ -16,12 +16,12 @@ # * * # *************************************************************************** -import FreeCAD as App -import Part - import numpy as np import scipy as sp +from freecad import app +import Part + from pygears.bevel_tooth import BevelTooth from pygears._functions import rotation @@ -109,7 +109,7 @@ class LanternGear(BaseGear): p_12 = np.array([r_0 - r_r, 0.0]) arc = Part.Arc( - App.Vector(*p_1, 0.0), App.Vector(*p_12, 0.0), App.Vector(*p_2, 0.0) + app.Vector(*p_1, 0.0), app.Vector(*p_12, 0.0), app.Vector(*p_2, 0.0) ).toShape() rot = rotation(-np.pi * 2 / teeth) @@ -121,7 +121,7 @@ class LanternGear(BaseGear): w = Part.Wire([w_2, arc, w_1, l]) wires = [w] - rot = App.Matrix() + rot = app.Matrix() for _ in range(teeth - 1): rot.rotateZ(np.pi * 2 / teeth) wires.append(w.transformGeometry(rot)) @@ -130,4 +130,4 @@ class LanternGear(BaseGear): if fp.height.Value == 0: return wi else: - return Part.Face(wi).extrude(App.Vector(0, 0, fp.height)) + return Part.Face(wi).extrude(app.Vector(0, 0, fp.height)) diff --git a/freecad/gears/timinggear.py b/freecad/gears/timinggear.py index 4444801..a248045 100644 --- a/freecad/gears/timinggear.py +++ b/freecad/gears/timinggear.py @@ -16,10 +16,11 @@ # * * # *************************************************************************** -import FreeCAD as App +import numpy as np + +from freecad import app import Part -import numpy as np from pygears._functions import reflection from .basegear import BaseGear, part_arc_from_points_and_center @@ -176,9 +177,9 @@ class TimingGear(BaseGear): arcs.append(part_arc_from_points_and_center(xn4, xn2, mn_34).toShape()) arcs.append( Part.Arc( - App.Vector(*xn2, 0.0), - App.Vector(0, rp - h, 0.0), - App.Vector(*x2, 0.0), + app.Vector(*xn2, 0.0), + app.Vector(0, rp - h, 0.0), + app.Vector(*x2, 0.0), ).toShape() ) arcs.append(part_arc_from_points_and_center(x2, x4, m_34).toShape()) @@ -272,7 +273,7 @@ class TimingGear(BaseGear): wire = Part.Wire(arcs) wires = [wire] - rot = App.Matrix() + rot = app.Matrix() rot.rotateZ(np.pi * 2 / fp.teeth) for _ in range(fp.teeth - 1): wire = wire.transformGeometry(rot) @@ -282,4 +283,4 @@ class TimingGear(BaseGear): if fp.height.Value == 0: return wi else: - return Part.Face(wi).extrude(App.Vector(0, 0, fp.height)) + 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 674aa32..fca209f 100644 --- a/freecad/gears/timinggear_t.py +++ b/freecad/gears/timinggear_t.py @@ -20,7 +20,7 @@ import numpy as np import scipy as sp -import FreeCAD as App +from freecad import app import Part from pygears._functions import rotation, reflection @@ -103,7 +103,7 @@ class TimingGearT(BaseGear): w = Part.Wire([l1, l2, l3, l4]) # now using a FreeCAD Matrix (this will turn in the right direction) - rot = App.Matrix() + rot = app.Matrix() rot.rotateZ(gamma_0) wires = [] for i in range(teeth): @@ -114,4 +114,4 @@ class TimingGearT(BaseGear): return contour else: face = Part.Face(Part.Wire(wires)) - return face.extrude(App.Vector(0.0, 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 df89f0e..4e8286c 100644 --- a/freecad/gears/wormgear.py +++ b/freecad/gears/wormgear.py @@ -16,10 +16,11 @@ # * * # *************************************************************************** -import FreeCAD as App +import numpy as np + +from freecad import app import Part -import numpy as np from pygears.involute_tooth import InvoluteTooth from pygears._functions import rotation @@ -102,8 +103,8 @@ class WormGear(BaseGear): phi_1 = 2 * z_1 / m / t c1 = Part.makeCircle( r_1, - App.Vector(0, 0, 0), - App.Vector(0, 0, 1), + app.Vector(0, 0, 0), + app.Vector(0, 0, 1), np.rad2deg(phi_0), np.rad2deg(phi_1), ) @@ -121,8 +122,8 @@ class WormGear(BaseGear): phi_3 = 2 * z_3 / m / t c2 = Part.makeCircle( r_2, - App.Vector(0, 0, 0), - App.Vector(0, 0, 1), + app.Vector(0, 0, 0), + app.Vector(0, 0, 1), np.rad2deg(phi_2), np.rad2deg(phi_3), ) @@ -138,7 +139,7 @@ class WormGear(BaseGear): wire = Part.Wire([c1, bsp1, c2, bsp2]) w_all = [wire] - rot = App.Matrix() + rot = app.Matrix() rot.rotateZ(2 * np.pi / t) for i in range(1, t): w_all.append(w_all[-1].transformGeometry(rot))