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

Add translation support #139

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
*.pyc
*.md
*.fcstd1
*.FCBak
/docFiles/
25 changes: 14 additions & 11 deletions freecad/Curves/BSplineAlgorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from math import pi
from freecad.Curves.BSplineApproxInterp import BSplineApproxInterp

translate = FreeCAD.Qt.translate
vec2d = Base.Vector2d
DEBUG = False

Expand All @@ -18,27 +19,29 @@ def debug(o):
if not DEBUG:
return
if isinstance(o, Part.BSplineCurve):
FreeCAD.Console.PrintWarning("\nBSplineCurve\n")
FreeCAD.Console.PrintWarning("Degree: {}\n".format(o.Degree))
FreeCAD.Console.PrintWarning("NbPoles: {}\n".format(o.NbPoles))
FreeCAD.Console.PrintWarning("Knots: {} ({:0.2f} - {:0.2f})\n".format(o.NbKnots, o.FirstParameter, o.LastParameter))
FreeCAD.Console.PrintWarning("Mults: {}\n".format(o.getMultiplicities()))
FreeCAD.Console.PrintWarning("Periodic: {}\n".format(o.isPeriodic()))
FreeCAD.Console.PrintWarning(translate("Log", "\nBSplineCurve\n"))
FreeCAD.Console.PrintWarning(translate("Log", "Degree: {}\n")).format(o.Degree)
FreeCAD.Console.PrintWarning(translate("Log", "NbPoles: {}\n")).format(o.NbPoles)
FreeCAD.Console.PrintWarning(translate("Log", "Knots: {} ({:0.2f} - {:0.2f})\n")).format(
o.NbKnots, o.FirstParameter, o.LastParameter
)
FreeCAD.Console.PrintWarning(translate("Log", "Mults: {}\n")).format(o.getMultiplicities())
FreeCAD.Console.PrintWarning(translate("Log", "Periodic: {}\n")).format(o.isPeriodic())
elif isinstance(o, Part.BSplineSurface):
FreeCAD.Console.PrintWarning("\nBSplineSurface\n************\n")
FreeCAD.Console.PrintWarning(translate("Log", "\nBSplineSurface\n************\n"))
try:
u = o.uIso(o.getUKnot(1))
debug(u)
except Part.OCCError:
FreeCAD.Console.PrintError("Failed to compute uIso curve\n")
FreeCAD.Console.PrintError(translate("Log", "Failed to compute uIso curve\n"))
try:
v = o.vIso(o.getVKnot(1))
debug(v)
except Part.OCCError:
FreeCAD.Console.PrintError("Failed to compute vIso curve\n")
FreeCAD.Console.PrintWarning("************\n")
FreeCAD.Console.PrintError(translate("Log", "Failed to compute vIso curve\n"))
FreeCAD.Console.PrintWarning(translate("Log", "************\n"))
else:
FreeCAD.Console.PrintMessage("{}\n".format(str(o)))
FreeCAD.Console.PrintMessage(translate("Log", "{}\n")).format(str(o))


def IsInsideTolerance(array, value, tolerance=1e-15):
Expand Down
25 changes: 14 additions & 11 deletions freecad/Curves/BSplineApproxInterp.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,37 @@
from freecad.Curves import nurbs_tools
# from math import pi

translate = FreeCAD.Qt.translate
DEBUG = False


def debug(o):
if not DEBUG:
return
if isinstance(o, Part.BSplineCurve):
FreeCAD.Console.PrintWarning("\nBSplineCurve\n")
FreeCAD.Console.PrintWarning("Degree: {}\n".format(o.Degree))
FreeCAD.Console.PrintWarning("NbPoles: {}\n".format(o.NbPoles))
FreeCAD.Console.PrintWarning("Knots: {} ({:0.2f} - {:0.2f})\n".format(o.NbKnots, o.FirstParameter, o.LastParameter))
FreeCAD.Console.PrintWarning("Mults: {}\n".format(o.getMultiplicities()))
FreeCAD.Console.PrintWarning("Periodic: {}\n".format(o.isPeriodic()))
FreeCAD.Console.PrintWarning(translate("Log", "\nBSplineCurve\n"))
FreeCAD.Console.PrintWarning(translate("Log", "Degree: {}\n")).format(o.Degree)
FreeCAD.Console.PrintWarning(translate("Log", "NbPoles: {}\n")).format(o.NbPoles)
FreeCAD.Console.PrintWarning(translate("Log", "Knots: {} ({:0.2f} - {:0.2f})\n")).format(
o.NbKnots, o.FirstParameter, o.LastParameter
)
FreeCAD.Console.PrintWarning(translate("Log", "Mults: {}\n")).format(o.getMultiplicities())
FreeCAD.Console.PrintWarning(translate("Log", "Periodic: {}\n")).format(o.isPeriodic())
elif isinstance(o, Part.BSplineSurface):
FreeCAD.Console.PrintWarning("\nBSplineSurface\n************\n")
FreeCAD.Console.PrintWarning(translate("Log", "\nBSplineSurface\n************\n"))
try:
u = o.uIso(o.UKnotSequence[0])
debug(u)
except Part.OCCError:
FreeCAD.Console.PrintError("Failed to compute uIso curve\n")
FreeCAD.Console.PrintError(translate("Log", "Failed to compute uIso curve\n"))
try:
v = o.vIso(o.VKnotSequence[0])
debug(v)
except Part.OCCError:
FreeCAD.Console.PrintError("Failed to compute vIso curve\n")
FreeCAD.Console.PrintWarning("************\n")
FreeCAD.Console.PrintError(translate("Log", "Failed to compute vIso curve\n"))
FreeCAD.Console.PrintWarning(translate("Log", "************\n"))
else:
FreeCAD.Console.PrintMessage("{}\n".format(str(o)))
FreeCAD.Console.PrintMessage(translate("Log", "{}\n")).format(str(o))


def square_distance(v1, v2):
Expand Down
4 changes: 3 additions & 1 deletion freecad/Curves/Blending/smooth_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
from .. import curves_to_surface
from ..nurbs_tools import nurbs_quad

translate = FreeCAD.Qt.translate


def printError(string):
FreeCAD.Console.PrintError(str(string) + "\n")
Expand Down Expand Up @@ -1215,7 +1217,7 @@ def get_offset_curve2d(self, dist=0.1):
if len(c) == 3:
cos.append(c[0].toBSpline(c[1], c[2]))
else:
FreeCAD.Console.PrintError("failed to extract 2D geometry")
FreeCAD.Console.PrintError(translate("Log", "failed to extract 2D geometry"))
if e.isPartner(self._edge):
idx = n

Expand Down
140 changes: 111 additions & 29 deletions freecad/Curves/Discretize.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
# -*- coding: utf-8 -*-

__title__ = "Discretize"
import FreeCAD

translate = FreeCAD.Qt.translate
QT_TRANSLATE_NOOP = FreeCAD.Qt.QT_TRANSLATE_NOOP

__title__ = QT_TRANSLATE_NOOP("Curves_Discretize", "Discretize")
__author__ = "Christophe Grellier (Chris_G)"
__license__ = "LGPL 2.1"
__doc__ = "Discretize an edge or a wire."
__usage__ = """Select an edge in the 3D View
__doc__ = translate("Curves_Discretize", "Discretize an edge or a wire.")
__usage__ = translate(
"Curves_Discretize",
"""Select an edge in the 3D View
Activate tool
It will generate some points along the edge, following various methods"""
It will generate some points along the edge, following various methods""",
)

import os
import FreeCAD
import FreeCADGui
import Part
from . import _utils
Expand All @@ -24,22 +31,91 @@
class Discretization:
def __init__(self, obj, edge):
debug("Discretization class Init")
obj.addProperty("App::PropertyLinkSub", "Edge", "Discretization", "Edge").Edge = edge
obj.addProperty("App::PropertyEnumeration", "Target", "Discretization", "Tool target").Target=["Edge","Wire"]
obj.addProperty("App::PropertyEnumeration", "Algorithm", "Method", "Discretization Method").Algorithm=["Number","QuasiNumber","Distance","Deflection","QuasiDeflection","Angular-Curvature"]
obj.addProperty("App::PropertyInteger", "Number", "Method", "Number of edge points").Number = 100
obj.addProperty("App::PropertyFloat", "Distance", "Method", "Distance between edge points").Distance=1.0
obj.addProperty("App::PropertyFloat", "Deflection","Method", "Distance for deflection Algorithm").Deflection=1.0
obj.addProperty("App::PropertyFloat", "Angular", "Method", "Angular value for Angular-Curvature Algorithm").Angular=0.1
obj.addProperty("App::PropertyFloat", "Curvature", "Method", "Curvature value for Angular-Curvature Algorithm").Curvature=0.1
obj.addProperty("App::PropertyInteger", "Minimum", "Method", "Minimum Number of points").Minimum = 2
obj.addProperty("App::PropertyFloat", "ParameterFirst", "Parameters", "Start parameter")
obj.addProperty("App::PropertyFloat", "ParameterLast", "Parameters", "End parameter")
obj.addProperty("App::PropertyVectorList", "Points", "Discretization", "Points")
obj.addProperty("App::PropertyFloatList",
"NormalizedParameters",
"Output",
"Normalized parameters list")
obj.addProperty(
"App::PropertyLinkSub",
"Edge",
"Discretization",
QT_TRANSLATE_NOOP("App::Property", "Edge"),
).Edge = edge
obj.addProperty(
"App::PropertyEnumeration",
"Target",
"Discretization",
QT_TRANSLATE_NOOP("App::Property", "Tool target"),
).Target = ["Edge", "Wire"]
obj.addProperty(
"App::PropertyEnumeration",
"Algorithm",
"Method",
QT_TRANSLATE_NOOP("App::Property", "Discretization Method"),
).Algorithm = [
"Number",
"QuasiNumber",
"Distance",
"Deflection",
"QuasiDeflection",
"Angular-Curvature",
]
obj.addProperty(
"App::PropertyInteger",
"Number",
"Method",
QT_TRANSLATE_NOOP("App::Property", "Number of edge points"),
).Number = 100
obj.addProperty(
"App::PropertyFloat",
"Distance",
"Method",
QT_TRANSLATE_NOOP("App::Property", "Distance between edge points"),
).Distance = 1.0
obj.addProperty(
"App::PropertyFloat",
"Deflection",
"Method",
QT_TRANSLATE_NOOP("App::Property", "Distance for deflection Algorithm"),
).Deflection = 1.0
obj.addProperty(
"App::PropertyFloat",
"Angular",
"Method",
QT_TRANSLATE_NOOP("App::Property", "Angular value for Angular-Curvature Algorithm"),
).Angular = 0.1
obj.addProperty(
"App::PropertyFloat",
"Curvature",
"Method",
QT_TRANSLATE_NOOP("App::Property", "Curvature value for Angular-Curvature Algorithm"),
).Curvature = 0.1
obj.addProperty(
"App::PropertyInteger",
"Minimum",
"Method",
QT_TRANSLATE_NOOP("App::Property", "Minimum Number of points"),
).Minimum = 2
obj.addProperty(
"App::PropertyFloat",
"ParameterFirst",
"Parameters",
QT_TRANSLATE_NOOP("App::Property", "Start parameter"),
)
obj.addProperty(
"App::PropertyFloat",
"ParameterLast",
"Parameters",
QT_TRANSLATE_NOOP("App::Property", "End parameter"),
)
obj.addProperty(
"App::PropertyVectorList",
"Points",
"Discretization",
QT_TRANSLATE_NOOP("App::Property", "Points"),
)
obj.addProperty(
"App::PropertyFloatList",
"NormalizedParameters",
"Output",
QT_TRANSLATE_NOOP("App::Property", "Normalized parameters list"),
)
obj.setEditorMode("NormalizedParameters", 1)
obj.Proxy = self
obj.Algorithm = "Number"
Expand Down Expand Up @@ -256,7 +332,7 @@ def onDelete(self, feature, subelements):
try:
self.Object.Edge[0].ViewObject.Visibility = True
except Exception as err:
FreeCAD.Console.PrintError("Error in onDelete: {0} \n".format(err))
FreeCAD.Console.PrintError(translate("Log", "Error in onDelete: {0} \n")).format(err)
return True


Expand All @@ -276,7 +352,7 @@ def Activated(self):
s = FreeCADGui.Selection.getSelectionEx()
edges = self.parseSel(s)
if not edges:
FreeCAD.Console.PrintError("{} :\n{}\n".format(__title__, __usage__))
FreeCAD.Console.PrintError(translate("Log", "{} :\n{}\n")).format(__title__, __usage__)
FreeCADGui.doCommand("from freecad.Curves import Discretize")
for e in edges:
FreeCADGui.doCommand('obj = FreeCAD.ActiveDocument.addObject("Part::FeaturePython","Discretized_Edge")')
Expand All @@ -296,9 +372,15 @@ def IsActive(self):
return False

def GetResources(self):
return {'Pixmap': TOOL_ICON,
'MenuText': __title__,
'ToolTip': "{}<br><br><b>Usage :</b><br>{}".format(__doc__, "<br>".join(__usage__.splitlines()))}


FreeCADGui.addCommand('Discretize', discretize())
return {
"Pixmap": TOOL_ICON,
"MenuText": __title__,
"ToolTip": "{}<br><br><b>{} :</b><br>{}".format(
__doc__,
translate("Curves_Discretize", "Usage"),
"<br>".join(__usage__.splitlines()),
),
}


FreeCADGui.addCommand("Curves_Discretize", discretize())
Loading