translation cleanup

This commit is contained in:
sliptonic
2022-01-22 08:51:42 -06:00
parent ab51e26196
commit 2cbc0b333c
7 changed files with 219 additions and 113 deletions

View File

@@ -62,26 +62,6 @@
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Specify if the facing should be restricted by the actual shape of the selected face (or the part if no face is selected), or if the bounding box should be faced off.&lt;/p&gt;&lt;p&gt;The latter can be used to face of the entire stock area to ensure uniform heights for the following operations.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<item>
<property name="text">
<string>Boundbox</string>
</property>
</item>
<item>
<property name="text">
<string>Face Region</string>
</property>
</item>
<item>
<property name="text">
<string>Perimeter</string>
</property>
</item>
<item>
<property name="text">
<string>Stock</string>
</property>
</item>
</widget>
</item>
<item row="0" column="0">

View File

@@ -26,8 +26,7 @@ import FreeCAD
import PathScripts.PathLog as PathLog
import PathScripts.PathPocketBase as PathPocketBase
import PathScripts.PathUtils as PathUtils
from PySide import QtCore
from PySide.QtCore import QT_TRANSLATE_NOOP
import numpy
# lazily loaded modules
@@ -42,33 +41,66 @@ __doc__ = "Class and implementation of Mill Facing operation."
__contributors__ = "russ4262 (Russell Johnson)"
PathLog.setLevel(PathLog.Level.INFO, PathLog.thisModule())
# PathLog.trackModule()
if False:
PathLog.setLevel(PathLog.Level.DEBUG, PathLog.thisModule())
PathLog.trackModule(PathLog.thisModule())
else:
PathLog.setLevel(PathLog.Level.INFO, PathLog.thisModule())
# Qt translation handling
def translate(context, text, disambig=None):
return QtCore.QCoreApplication.translate(context, text, disambig)
translate = FreeCAD.Qt.translate
class ObjectFace(PathPocketBase.ObjectPocket):
"""Proxy object for Mill Facing operation."""
@classmethod
def propertyEnumerations(self, dataType="data"):
"""helixOpPropertyEnumerations(dataType="data")... return property enumeration lists of specified dataType.
Args:
dataType = 'data', 'raw', 'translated'
Notes:
'data' is list of internal string literals used in code
'raw' is list of (translated_text, data_string) tuples
'translated' is list of translated string literals
"""
enums = {
"BoundaryShape": [
(translate("Path_Pocket", "Boundbox"), "Boundbox"),
(translate("Path_Pocket", "Face Region"), "Face Region"),
(translate("Path_Pocket", "Perimeter"), "Perimeter"),
(translate("Path_Pocket", "Stock"), "Stock"),
],
}
if dataType == "raw":
return enums
data = list()
idx = 0 if dataType == "translated" else 1
PathLog.debug(enums)
for k, v in enumerate(enums):
data.append((v, [tup[idx] for tup in enums[v]]))
PathLog.debug(data)
return data
def initPocketOp(self, obj):
PathLog.track()
"""initPocketOp(obj) ... create facing specific properties"""
obj.addProperty(
"App::PropertyEnumeration",
"BoundaryShape",
"Face",
QtCore.QT_TRANSLATE_NOOP(
"App::Property", "Shape to use for calculating Boundary"
),
QT_TRANSLATE_NOOP("App::Property", "Shape to use for calculating Boundary"),
)
obj.addProperty(
"App::PropertyBool",
"ClearEdges",
"Face",
QtCore.QT_TRANSLATE_NOOP(
QT_TRANSLATE_NOOP(
"App::Property", "Clear edges of surface (Only applicable to BoundBox)"
),
)
@@ -77,12 +109,13 @@ class ObjectFace(PathPocketBase.ObjectPocket):
"App::PropertyBool",
"ExcludeRaisedAreas",
"Face",
QtCore.QT_TRANSLATE_NOOP(
QT_TRANSLATE_NOOP(
"App::Property", "Exclude milling raised areas inside the face."
),
)
obj.BoundaryShape = ["Boundbox", "Face Region", "Perimeter", "Stock"]
for n in self.propertyEnumerations():
setattr(obj, n[0], n[1])
def pocketInvertExtraOffset(self):
return True

View File

@@ -20,22 +20,64 @@
# * *
# ***************************************************************************
from PySide.QtCore import QT_TRANSLATE_NOOP
import FreeCAD
import PathScripts.PathLog as PathLog
import PathScripts.PathMillFace as PathMillFace
import PathScripts.PathOpGui as PathOpGui
import PathScripts.PathPocketBaseGui as PathPocketBaseGui
from PySide import QtCore
import PathScripts.PathPocketShape as PathPocketShape
import FreeCADGui
__title__ = "Path Face Mill Operation UI"
__author__ = "sliptonic (Brad Collette)"
__url__ = "https://www.freecadweb.org"
__doc__ = "Face Mill operation page controller and command implementation."
if False:
PathLog.setLevel(PathLog.Level.DEBUG, PathLog.thisModule())
PathLog.trackModule(PathLog.thisModule())
else:
PathLog.setLevel(PathLog.Level.INFO, PathLog.thisModule())
class TaskPanelOpPage(PathPocketBaseGui.TaskPanelOpPage):
"""Page controller class for the face milling operation."""
def getForm(self):
PathLog.track()
"""getForm() ... return UI"""
form = FreeCADGui.PySideUic.loadUi(":/panels/PageOpPocketFullEdit.ui")
comboToPropertyMap = [
("cutMode", "CutMode"),
("offsetPattern", "OffsetPattern"),
("boundaryShape", "BoundaryShape"),
]
enumTups = PathMillFace.ObjectFace.propertyEnumerations(dataType="raw")
enumTups.update(
PathPocketShape.ObjectPocket.pocketPropertyEnumerations(dataType="raw")
)
self.populateCombobox(form, enumTups, comboToPropertyMap)
return form
def populateCombobox(self, form, enumTups, comboBoxesPropertyMap):
"""fillComboboxes(form, comboBoxesPropertyMap) ... populate comboboxes with translated enumerations
** comboBoxesPropertyMap will be unnecessary if UI files use strict combobox naming protocol.
Args:
form = UI form
enumTups = list of (translated_text, data_string) tuples
comboBoxesPropertyMap = list of (translated_text, data_string) tuples
"""
# Load appropriate enumerations in each combobox
for cb, prop in comboBoxesPropertyMap:
box = getattr(form, cb) # Get the combobox
box.clear() # clear the combobox
for text, data in enumTups[prop]: # load enumerations
box.addItem(text, data)
def pocketFeatures(self):
"""pocketFeatures() ... return FeatureFacing (see PathPocketBaseGui)"""
return PathPocketBaseGui.FeatureFacing
@@ -46,9 +88,9 @@ Command = PathOpGui.SetupOperation(
PathMillFace.Create,
TaskPanelOpPage,
"Path_Face",
QtCore.QT_TRANSLATE_NOOP("Path_Face", "Face"),
QtCore.QT_TRANSLATE_NOOP(
"Path_Face", "Create a Facing Operation from a model or face"
QT_TRANSLATE_NOOP("Path_MillFace", "Face"),
QT_TRANSLATE_NOOP(
"Path_MillFace", "Create a Facing Operation from a model or face"
),
PathMillFace.SetupProperties,
)

View File

@@ -21,29 +21,75 @@
# * *
# ***************************************************************************
import FreeCAD
from PySide.QtCore import QT_TRANSLATE_NOOP
import PathScripts.PathAreaOp as PathAreaOp
import PathScripts.PathLog as PathLog
import PathScripts.PathOp as PathOp
from PySide import QtCore
__title__ = "Base Path Pocket Operation"
__author__ = "sliptonic (Brad Collette)"
__url__ = "https://www.freecadweb.org"
__doc__ = "Base class and implementation for Path pocket operations."
PathLog.setLevel(PathLog.Level.INFO, PathLog.thisModule())
# PathLog.trackModule(PathLog.thisModule())
if False:
PathLog.setLevel(PathLog.Level.DEBUG, PathLog.thisModule())
PathLog.trackModule(PathLog.thisModule())
else:
PathLog.setLevel(PathLog.Level.INFO, PathLog.thisModule())
# Qt translation handling
def translate(context, text, disambig=None):
return QtCore.QCoreApplication.translate(context, text, disambig)
translate = FreeCAD.Qt.translate
class ObjectPocket(PathAreaOp.ObjectOp):
"""Base class for proxy objects of all pocket operations."""
@classmethod
def pocketPropertyEnumerations(self, dataType="data"):
"""helixOpPropertyEnumerations(dataType="data")... return property enumeration lists of specified dataType.
Args:
dataType = 'data', 'raw', 'translated'
Notes:
'data' is list of internal string literals used in code
'raw' is list of (translated_text, data_string) tuples
'translated' is list of translated string literals
"""
enums = {
"CutMode": [
(translate("Path_Pocket", "Climb"), "Climb"),
(translate("Path_Pocket", "Conventional"), "Conventional"),
], # this is the direction that the profile runs
"StartAt": [
(translate("Path_Pocket", "Center"), "Center"),
(translate("Path_Pocket", "Edge"), "Edge"),
],
"OffsetPattern": [
(translate("Path_Pocket", "ZigZag"), "ZigZag"),
(translate("Path_Pocket", "Offset"), "Offset"),
(translate("Path_Pocket", "Spiral"), "Spiral"),
(translate("Path_Pocket", "ZigZagOffset"), "ZigZagOffset"),
(translate("Path_Pocket", "Line"), "Line"),
(translate("Path_Pocket", "Grid"), "Grid"),
(translate("Path_Pocket", "Triangle"), "Triangle"),
], # Fill Pattern
}
if dataType == "raw":
return enums
data = list()
idx = 0 if dataType == "translated" else 1
PathLog.debug(enums)
for k, v in enumerate(enums):
data.append((v, [tup[idx] for tup in enums[v]]))
PathLog.debug(data)
return data
def areaOpFeatures(self, obj):
"""areaOpFeatures(obj) ... Pockets have a FinishDepth and work on Faces"""
return (
@@ -76,7 +122,7 @@ class ObjectPocket(PathAreaOp.ObjectOp):
"App::PropertyEnumeration",
"CutMode",
"Pocket",
QtCore.QT_TRANSLATE_NOOP(
QT_TRANSLATE_NOOP(
"App::Property",
"The direction that the toolpath should go around the part ClockWise (CW) or CounterClockWise (CCW)",
),
@@ -85,7 +131,7 @@ class ObjectPocket(PathAreaOp.ObjectOp):
"App::PropertyDistance",
"ExtraOffset",
"Pocket",
QtCore.QT_TRANSLATE_NOOP(
QT_TRANSLATE_NOOP(
"App::Property",
"Extra offset to apply to the operation. Direction is operation dependent.",
),
@@ -94,15 +140,13 @@ class ObjectPocket(PathAreaOp.ObjectOp):
"App::PropertyEnumeration",
"StartAt",
"Pocket",
QtCore.QT_TRANSLATE_NOOP(
"App::Property", "Start pocketing at center or boundary"
),
QT_TRANSLATE_NOOP("App::Property", "Start pocketing at center or boundary"),
)
obj.addProperty(
"App::PropertyPercent",
"StepOver",
"Pocket",
QtCore.QT_TRANSLATE_NOOP(
QT_TRANSLATE_NOOP(
"App::Property", "Percent of cutter diameter to step over on each pass"
),
)
@@ -110,40 +154,31 @@ class ObjectPocket(PathAreaOp.ObjectOp):
"App::PropertyFloat",
"ZigZagAngle",
"Pocket",
QtCore.QT_TRANSLATE_NOOP("App::Property", "Angle of the zigzag pattern"),
QT_TRANSLATE_NOOP("App::Property", "Angle of the zigzag pattern"),
)
obj.addProperty(
"App::PropertyEnumeration",
"OffsetPattern",
"Face",
QtCore.QT_TRANSLATE_NOOP("App::Property", "Clearing pattern to use"),
QT_TRANSLATE_NOOP("App::Property", "Clearing pattern to use"),
)
obj.addProperty(
"App::PropertyBool",
"MinTravel",
"Pocket",
QtCore.QT_TRANSLATE_NOOP("App::Property", "Use 3D Sorting of Path"),
QT_TRANSLATE_NOOP("App::Property", "Use 3D Sorting of Path"),
)
obj.addProperty(
"App::PropertyBool",
"KeepToolDown",
"Pocket",
QtCore.QT_TRANSLATE_NOOP(
QT_TRANSLATE_NOOP(
"App::Property", "Attempts to avoid unnecessary retractions."
),
)
obj.CutMode = ["Climb", "Conventional"]
obj.StartAt = ["Center", "Edge"]
obj.OffsetPattern = [
"ZigZag",
"Offset",
"Spiral",
"ZigZagOffset",
"Line",
"Grid",
"Triangle",
]
for n in self.pocketPropertyEnumerations():
setattr(obj, n[0], n[1])
self.initPocketOp(obj)

View File

@@ -25,18 +25,21 @@ import FreeCADGui
import PathGui as PGui # ensure Path/Gui/Resources are loaded
import PathScripts.PathGui as PathGui
import PathScripts.PathOpGui as PathOpGui
from PySide import QtCore # , QtGui
import PathScripts.PathPocket as PathPocket
import PathScripts.PathLog as PathLog
__title__ = "Path Pocket Base Operation UI"
__author__ = "sliptonic (Brad Collette)"
__url__ = "https://www.freecadweb.org"
__doc__ = "Base page controller and command implementation for path pocket operations."
if False:
PathLog.setLevel(PathLog.Level.DEBUG, PathLog.thisModule())
PathLog.trackModule(PathLog.thisModule())
else:
PathLog.setLevel(PathLog.Level.INFO, PathLog.thisModule())
def translate(context, text, disambig=None):
return QtCore.QCoreApplication.translate(context, text, disambig)
translate = FreeCAD.Qt.translate
FeaturePocket = 0x01
FeatureFacing = 0x02
@@ -62,6 +65,14 @@ class TaskPanelOpPage(PathOpGui.TaskPanelPage):
"""getForm() ... returns UI, adapted to the results from pocketFeatures()"""
form = FreeCADGui.PySideUic.loadUi(":/panels/PageOpPocketFullEdit.ui")
comboToPropertyMap = [
("cutMode", "CutMode"),
("offsetPattern", "OffsetPattern"),
]
enumTups = PathPocket.ObjectPocket.pocketPropertyEnumerations(dataType="raw")
self.populateCombobox(form, enumTups, comboToPropertyMap)
if not FeatureFacing & self.pocketFeatures():
form.facingWidget.hide()
form.clearEdges.hide()
@@ -84,6 +95,21 @@ class TaskPanelOpPage(PathOpGui.TaskPanelPage):
return form
def populateCombobox(self, form, enumTups, comboBoxesPropertyMap):
"""fillComboboxes(form, comboBoxesPropertyMap) ... populate comboboxes with translated enumerations
** comboBoxesPropertyMap will be unnecessary if UI files use strict combobox naming protocol.
Args:
form = UI form
enumTups = list of (translated_text, data_string) tuples
comboBoxesPropertyMap = list of (translated_text, data_string) tuples
"""
# Load appropriate enumerations in each combobox
for cb, prop in comboBoxesPropertyMap:
box = getattr(form, cb) # Get the combobox
box.clear() # clear the combobox
for text, data in enumTups[prop]: # load enumerations
box.addItem(text, data)
def updateMinTravel(self, obj, setModel=True):
if obj.UseStartPoint:
self.form.minTravel.setEnabled(True)
@@ -105,12 +131,12 @@ class TaskPanelOpPage(PathOpGui.TaskPanelPage):
def getFields(self, obj):
"""getFields(obj) ... transfers values from UI to obj's proprties"""
if obj.CutMode != str(self.form.cutMode.currentText()):
obj.CutMode = str(self.form.cutMode.currentText())
if obj.CutMode != str(self.form.cutMode.currentData()):
obj.CutMode = str(self.form.cutMode.currentData())
if obj.StepOver != self.form.stepOverPercent.value():
obj.StepOver = self.form.stepOverPercent.value()
if obj.OffsetPattern != str(self.form.offsetPattern.currentText()):
obj.OffsetPattern = str(self.form.offsetPattern.currentText())
if obj.OffsetPattern != str(self.form.offsetPattern.currentData()):
obj.OffsetPattern = str(self.form.offsetPattern.currentData())
PathGui.updateInputField(obj, "ExtraOffset", self.form.extraOffset)
self.updateToolController(obj, self.form.toolController)
@@ -127,8 +153,11 @@ class TaskPanelOpPage(PathOpGui.TaskPanelPage):
self.updateMinTravel(obj)
if FeatureFacing & self.pocketFeatures():
if obj.BoundaryShape != str(self.form.boundaryShape.currentText()):
obj.BoundaryShape = str(self.form.boundaryShape.currentText())
print(obj.BoundaryShape)
print(self.form.boundaryShape.currentText())
print(self.form.boundaryShape.currentData())
if obj.BoundaryShape != str(self.form.boundaryShape.currentData()):
obj.BoundaryShape = str(self.form.boundaryShape.currentData())
if obj.ClearEdges != self.form.clearEdges.isChecked():
obj.ClearEdges = self.form.clearEdges.isChecked()

View File

@@ -20,13 +20,13 @@
# * *
# ***************************************************************************
from PySide.QtCore import QT_TRANSLATE_NOOP
import FreeCAD
import PathScripts.PathGeom as PathGeom
import PathScripts.PathLog as PathLog
import PathScripts.PathOp as PathOp
import PathScripts.PathPocketBase as PathPocketBase
from PySide import QtCore
# lazily loaded modules
from lazy_loader.lazy_loader import LazyLoader
@@ -46,13 +46,11 @@ __url__ = "https://www.freecadweb.org"
__doc__ = "Class and implementation of shape based Pocket operation."
PathLog.setLevel(PathLog.Level.INFO, PathLog.thisModule())
# PathLog.trackModule(PathLog.thisModule())
# Qt translation handling
def translate(context, text, disambig=None):
return QtCore.QCoreApplication.translate(context, text, disambig)
if False:
PathLog.setLevel(PathLog.Level.DEBUG, PathLog.thisModule())
PathLog.trackModule(PathLog.thisModule())
else:
PathLog.setLevel(PathLog.Level.INFO, PathLog.thisModule())
class ObjectPocket(PathPocketBase.ObjectPocket):
@@ -68,8 +66,8 @@ class ObjectPocket(PathPocketBase.ObjectPocket):
"App::PropertyBool",
"UseOutline",
"Pocket",
QtCore.QT_TRANSLATE_NOOP(
"PathPocketShape", "Uses the outline of the base geometry."
QT_TRANSLATE_NOOP(
"App::Property", "Uses the outline of the base geometry."
),
)
@@ -113,10 +111,9 @@ class ObjectPocket(PathPocketBase.ObjectPocket):
if "Face" in sub:
if sub not in avoidFeatures and not self.clasifySub(base, sub):
PathLog.error(
translate(
"PathPocket", "Pocket does not support shape %s.%s"
"Pocket does not support shape {}.{}".format(
base.Label, sub
)
% (base.Label, sub)
)
# Convert horizontal faces to use outline only if requested
@@ -136,12 +133,7 @@ class ObjectPocket(PathPocketBase.ObjectPocket):
face = Part.Face(w)
# face.tessellate(0.1)
if PathGeom.isRoughly(face.Area, 0):
PathLog.error(
translate(
"PathPocket",
"Vertical faces do not form a loop - ignoring",
)
)
PathLog.error("Vertical faces do not form a loop - ignoring")
else:
self.horiz.append(face)
@@ -271,11 +263,7 @@ class ObjectPocket(PathPocketBase.ObjectPocket):
self.vert.append(face)
return True
else:
PathLog.error(
translate(
"Path", "Failed to identify vertical face from {}.".format(sub)
)
)
PathLog.error("Failed to identify vertical face from {}".format(sub))
else:
PathLog.debug(" -type(face.Surface): {}".format(type(face.Surface)))

View File

@@ -26,8 +26,7 @@ import PathScripts.PathOpGui as PathOpGui
import PathScripts.PathPocketShape as PathPocketShape
import PathScripts.PathPocketBaseGui as PathPocketBaseGui
import PathScripts.PathFeatureExtensionsGui as PathFeatureExtensionsGui
from PySide import QtCore
from PySide.QtCore import QT_TRANSLATE_NOOP
# lazily loaded modules
from lazy_loader.lazy_loader import LazyLoader
@@ -39,13 +38,13 @@ __author__ = "sliptonic (Brad Collette)"
__url__ = "https://www.freecadweb.org"
__doc__ = "Pocket Shape operation page controller and command implementation."
if False:
PathLog.setLevel(PathLog.Level.DEBUG, PathLog.thisModule())
PathLog.trackModule(PathLog.thisModule())
else:
PathLog.setLevel(PathLog.Level.INFO, PathLog.thisModule())
def translate(context, text, disambig=None):
return QtCore.QCoreApplication.translate(context, text, disambig)
PathLog.setLevel(PathLog.Level.INFO, PathLog.thisModule())
# PathLog.trackModule(PathLog.thisModule())
translate = FreeCAD.Qt.translate
class TaskPanelOpPage(PathPocketBaseGui.TaskPanelOpPage):
@@ -68,9 +67,9 @@ Command = PathOpGui.SetupOperation(
PathPocketShape.Create,
TaskPanelOpPage,
"Path_Pocket",
QtCore.QT_TRANSLATE_NOOP("Path_Pocket", "Pocket Shape"),
QtCore.QT_TRANSLATE_NOOP(
"Path_Pocket", "Creates a Path Pocket object from a face or faces"
QT_TRANSLATE_NOOP("Path_Pocket_Shape", "Pocket Shape"),
QT_TRANSLATE_NOOP(
"Path_Pocket_Shape", "Creates a Path Pocket object from a face or faces"
),
PathPocketShape.SetupProperties,
)