Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade translation support #176

Merged
merged 3 commits into from
Oct 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions freecad/gears/basegear.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@
from freecad import app
from freecad import part

from .translateutils import translate
from pygears import __version__
from pygears._functions import arc_from_points_and_center

QT_TRANSLATE_NOOP = app.Qt.QT_TRANSLATE_NOOP


def fcvec(x):
"""tranforms a list or numpy array to a FreeCAD Vector which is
Expand Down Expand Up @@ -100,7 +101,7 @@ def __init__(self, obj):
"App::PropertyString",
"version",
"version",
translate("BaseGear", "freecad.gears-version"),
QT_TRANSLATE_NOOP("App::Property", "freecad.gears-version"),
1,
)
obj.version = __version__
Expand Down
36 changes: 19 additions & 17 deletions freecad/gears/bevelgear.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@
from freecad import part

import numpy as np
from .translateutils import translate

from pygears.bevel_tooth import BevelTooth
from pygears._functions import rotation3D

from .basegear import BaseGear, fcvec, make_bspline_wire

QT_TRANSLATE_NOOP = app.Qt.QT_TRANSLATE_NOOP


class BevelGear(BaseGear):
"""parameters:
Expand All @@ -40,79 +42,79 @@ def __init__(self, obj):
"App::PropertyInteger",
"num_teeth",
"base",
translate("BevelGear", "number of teeth"),
QT_TRANSLATE_NOOP("App::Property", "number of teeth"),
)
obj.addProperty(
"App::PropertyLength",
"height",
"base",
translate("BevelGear", "height"),
QT_TRANSLATE_NOOP("App::Property", "height"),
)
obj.addProperty(
"App::PropertyAngle",
"pitch_angle",
"involute",
translate("BevelGear", "pitch_angle"),
QT_TRANSLATE_NOOP("App::Property", "pitch_angle"),
)
obj.addProperty(
"App::PropertyAngle",
"pressure_angle",
"involute_parameter",
translate("BevelGear", "pressure_angle"),
QT_TRANSLATE_NOOP("App::Property", "pressure_angle"),
)
obj.addProperty(
"App::PropertyLength",
"module",
"base",
translate("BevelGear", "module"),
QT_TRANSLATE_NOOP("App::Property", "module"),
)
obj.addProperty(
"App::PropertyFloat",
"clearance",
"tolerance",
translate("BevelGear", "clearance"),
QT_TRANSLATE_NOOP("App::Property", "clearance"),
)
obj.addProperty(
"App::PropertyInteger",
"numpoints",
"precision",
translate("BevelGear", "number of points for spline"),
QT_TRANSLATE_NOOP("App::Property", "number of points for spline"),
)
obj.addProperty(
"App::PropertyBool",
"reset_origin",
"base",
translate(
"BevelGear",
QT_TRANSLATE_NOOP(
"App::Property",
"if value is true the gears outer face will match the z=0 plane",
),
)
obj.addProperty(
"App::PropertyLength",
"backlash",
"tolerance",
translate(
"BevelGear",
QT_TRANSLATE_NOOP(
"App::Property",
"The arc length on the pitch circle by which the tooth thicknes is reduced.",
),
)
obj.addProperty(
"App::PropertyPythonObject",
"gear",
"base",
translate("BevelGear", "test"),
QT_TRANSLATE_NOOP("App::Property", "test"),
)
obj.addProperty(
"App::PropertyAngle",
"beta",
"helical",
translate("BevelGear", "angle used for spiral bevel-gears"),
QT_TRANSLATE_NOOP("App::Property", "angle used for spiral bevel-gears"),
)
obj.addProperty(
"App::PropertyLength",
"dw",
"computed",
translate("BevelGear", "The pitch diameter."),
QT_TRANSLATE_NOOP("App::Property", "The pitch diameter."),
)
obj.setExpression(
"dw", "num_teeth * module"
Expand All @@ -124,8 +126,8 @@ def __init__(self, obj):
"App::PropertyAngle",
"angular_backlash",
"computed",
translate(
"BevelGear",
QT_TRANSLATE_NOOP(
"App::Property",
"The angle by which this gear can turn without moving the mating gear.",
),
)
Expand Down
72 changes: 42 additions & 30 deletions freecad/gears/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
from freecad import app
from freecad import gui

from .translateutils import translate

from .basegear import ViewProviderGear, BaseGear

from .timinggear_t import TimingGearT
Expand All @@ -40,6 +38,8 @@

from .connector import GearConnector, ViewProviderGearConnector

QT_TRANSLATE_NOOP = app.Qt.QT_TRANSLATE_NOOP


class BaseCommand(object):
NAME = ""
Expand Down Expand Up @@ -101,115 +101,127 @@ class CreateInvoluteGear(BaseCommand):
NAME = "InvoluteGear"
GEAR_FUNCTION = InvoluteGear
Pixmap = os.path.join(BaseCommand.ICONDIR, "involutegear.svg")
MenuText = translate("Commands", "Involute Gear")
ToolTip = translate("Commands", "Create an external involute gear")
MenuText = QT_TRANSLATE_NOOP("FCGear_InvoluteGear", "Involute Gear")
ToolTip = QT_TRANSLATE_NOOP(
"FCGear_InvoluteGear", "Create an external involute gear"
)


class CreateInternalInvoluteGear(BaseCommand):
NAME = "InternalInvoluteGear"
GEAR_FUNCTION = InternalInvoluteGear
Pixmap = os.path.join(BaseCommand.ICONDIR, "internalinvolutegear.svg")
MenuText = translate("Commands", "Internal Involute Gear")
ToolTip = translate("Commands", "Create an internal involute gear")
MenuText = QT_TRANSLATE_NOOP(
"FCGear_InternalInvoluteGear", "Internal Involute Gear"
)
ToolTip = QT_TRANSLATE_NOOP(
"FCGear_InternalInvoluteGear", "Create an internal involute gear"
)


class CreateInvoluteRack(BaseCommand):
NAME = "InvoluteRack"
GEAR_FUNCTION = InvoluteGearRack
Pixmap = os.path.join(BaseCommand.ICONDIR, "involuterack.svg")
MenuText = translate("Commands", "Involute Rack")
ToolTip = translate("Commands", "Create an Involute rack")
MenuText = QT_TRANSLATE_NOOP("FCGear_InvoluteRack", "Involute Rack")
ToolTip = QT_TRANSLATE_NOOP("FCGear_InvoluteRack", "Create an Involute rack")


class CreateCycloidRack(BaseCommand):
NAME = "CycloidRack"
GEAR_FUNCTION = CycloidGearRack
Pixmap = os.path.join(BaseCommand.ICONDIR, "cycloidrack.svg")
MenuText = translate("Commands", "Cycloid Rack")
ToolTip = translate("Commands", "Create an Cycloid rack")
MenuText = QT_TRANSLATE_NOOP("FCGear_CycloidRack", "Cycloid Rack")
ToolTip = QT_TRANSLATE_NOOP("FCGear_CycloidRack", "Create an Cycloid rack")


class CreateCrownGear(BaseCommand):
NAME = "CrownGear"
GEAR_FUNCTION = CrownGear
Pixmap = os.path.join(BaseCommand.ICONDIR, "crowngear.svg")
MenuText = translate("Commands", "Crown Gear")
ToolTip = translate("Commands", "Create a Crown gear")
MenuText = QT_TRANSLATE_NOOP("FCGear_CrownGear", "Crown Gear")
ToolTip = QT_TRANSLATE_NOOP("FCGear_CrownGear", "Create a Crown gear")


class CreateCycloidGear(BaseCommand):
NAME = "CycloidGear"
GEAR_FUNCTION = CycloidGear
Pixmap = os.path.join(BaseCommand.ICONDIR, "cycloidgear.svg")
MenuText = translate("Commands", "Cycloid Gear")
ToolTip = translate("Commands", "Create a Cycloid gear")
MenuText = QT_TRANSLATE_NOOP("FCGear_CycloidGear", "Cycloid Gear")
ToolTip = QT_TRANSLATE_NOOP("FCGear_CycloidGear", "Create a Cycloid gear")


class CreateBevelGear(BaseCommand):
NAME = "BevelGear"
GEAR_FUNCTION = BevelGear
Pixmap = os.path.join(BaseCommand.ICONDIR, "bevelgear.svg")
MenuText = translate("Commands", "Bevel Gear")
ToolTip = translate("Commands", "Create a Bevel gear")
MenuText = QT_TRANSLATE_NOOP("FCGear_BevelGear", "Bevel Gear")
ToolTip = QT_TRANSLATE_NOOP("FCGear_BevelGear", "Create a Bevel gear")


class CreateHypoCycloidGear(BaseCommand):
NAME = "HypocycloidGear"
GEAR_FUNCTION = HypoCycloidGear
Pixmap = os.path.join(BaseCommand.ICONDIR, "hypocycloidgear.svg")
MenuText = translate("Commands", "HypoCycloid Gear")
ToolTip = translate("Commands", "Create a HypoCycloid gear with its pins")
MenuText = QT_TRANSLATE_NOOP("FCGear_HypoCycloidGear", "HypoCycloid Gear")
ToolTip = QT_TRANSLATE_NOOP(
"FCGear_HypoCycloidGear", "Create a HypoCycloid gear with its pins"
)


class CreateWormGear(BaseCommand):
NAME = "WormGear"
GEAR_FUNCTION = WormGear
Pixmap = os.path.join(BaseCommand.ICONDIR, "wormgear.svg")
MenuText = translate("Commands", "Worm Gear")
ToolTip = translate("Commands", "Create a Worm gear")
MenuText = QT_TRANSLATE_NOOP("FCGear_WormGear", "Worm Gear")
ToolTip = QT_TRANSLATE_NOOP("FCGear_WormGear", "Create a Worm gear")


class CreateTimingGearT(BaseCommand):
NAME = "TimingGearT"
GEAR_FUNCTION = TimingGearT
Pixmap = os.path.join(BaseCommand.ICONDIR, "timinggear_t.svg")
MenuText = translate("Commands", "Timing Gear T-shape")
ToolTip = translate("Commands", "Create a Timing gear T-shape")
MenuText = QT_TRANSLATE_NOOP("FCGear_TimingGearT", "Timing Gear T-shape")
ToolTip = QT_TRANSLATE_NOOP("FCGear_TimingGearT", "Create a Timing gear T-shape")


class CreateTimingGear(BaseCommand):
NAME = "TimingGear"
GEAR_FUNCTION = TimingGear
Pixmap = os.path.join(BaseCommand.ICONDIR, "timinggear.svg")
MenuText = translate("Commands", "Timing Gear")
ToolTip = translate("Commands", "Create a Timing gear")
MenuText = QT_TRANSLATE_NOOP("FCGear_TimingGear", "Timing Gear")
ToolTip = QT_TRANSLATE_NOOP("FCGear_TimingGear", "Create a Timing gear")


class CreateLanternGear(BaseCommand):
NAME = "LanternGear"
GEAR_FUNCTION = LanternGear
Pixmap = os.path.join(BaseCommand.ICONDIR, "lanterngear.svg")
MenuText = translate("Commands", "Lantern Gear")
ToolTip = translate("Commands", "Create a Lantern gear")
MenuText = QT_TRANSLATE_NOOP("FCGear_LanternGear", "Lantern Gear")
ToolTip = QT_TRANSLATE_NOOP("FCGear_LanternGear", "Create a Lantern gear")


class CreateGearConnector(BaseCommand):
NAME = "GearConnector"
GEAR_FUNCTION = GearConnector
Pixmap = os.path.join(BaseCommand.ICONDIR, "gearconnector.svg")
MenuText = translate("Commands", "Combine two gears")
ToolTip = translate("Commands", "Combine two gears")
MenuText = QT_TRANSLATE_NOOP("FCGear_GearConnector", "Combine two gears")
ToolTip = QT_TRANSLATE_NOOP("FCGear_GearConnector", "Combine two gears")

def Activated(self):
try:
selection = gui.Selection.getSelection()

if len(selection) != 2:
raise ValueError("Please select two gear objects.")
raise ValueError(
app.Qt.translate("Log", "Please select two gear objects.")
)

for obj in selection:
if not isinstance(obj.Proxy, BaseGear):
raise TypeError("Selected object is not a gear.")
raise TypeError(
app.Qt.translate("Log", "Selected object is not a gear.")
)

obj = app.ActiveDocument.addObject("Part::FeaturePython", self.NAME)
GearConnector(obj, selection[0], selection[1])
Expand Down
13 changes: 7 additions & 6 deletions freecad/gears/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@
from pygears import __version__
from pygears.computation import compute_shifted_gears

from .translateutils import translate
from .involutegear import InvoluteGear
from .internalinvolutegear import InternalInvoluteGear
from .involutegearrack import InvoluteGearRack
from .cycloidgear import CycloidGear
from .cycloidgearrack import CycloidGearRack

QT_TRANSLATE_NOOP = app.Qt.QT_TRANSLATE_NOOP


class ViewProviderGearConnector(object):
def __init__(self, vobj, icon_fn=None):
Expand Down Expand Up @@ -68,35 +69,35 @@ def __init__(self, obj, master_gear, slave_gear):
"App::PropertyString",
"version",
"version",
translate("GearConnector", "freecad.gears-version"),
QT_TRANSLATE_NOOP("App::Property", "freecad.gears-version"),
1,
)
obj.addProperty(
"App::PropertyLink",
"master_gear",
"gear",
translate("GearConnector", "master gear"),
QT_TRANSLATE_NOOP("App::Property", "master gear"),
1,
)
obj.addProperty(
"App::PropertyLink",
"slave_gear",
"gear",
translate("GearConnector", "slave gear"),
QT_TRANSLATE_NOOP("App::Property", "slave gear"),
1,
)
obj.addProperty(
"App::PropertyAngle",
"angle1",
"gear",
translate("GearConnector", "angle at which second gear is placed"),
QT_TRANSLATE_NOOP("App::Property", "angle at which second gear is placed"),
0,
)
obj.addProperty(
"App::PropertyAngle",
"angle2",
"gear",
translate("GearConnector", "angle at which second gear is placed"),
QT_TRANSLATE_NOOP("App::Property", "angle at which second gear is placed"),
1,
)
obj.version = __version__
Expand Down
Loading