From 345778ac3aa88b0f9bd4ab1a4903f83ecf651dfb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20B=C3=A4hr?= Date: Sun, 9 Mar 2025 14:48:56 +0100 Subject: [PATCH 1/2] CAM: Refactor schema warning at job creation This is a pure refactoring to clean up the code for upcomming changes. It does not change any functionality or UI messages. --- src/Mod/CAM/Path/Main/Gui/JobDlg.py | 62 ++++++++++++++++++----------- 1 file changed, 39 insertions(+), 23 deletions(-) diff --git a/src/Mod/CAM/Path/Main/Gui/JobDlg.py b/src/Mod/CAM/Path/Main/Gui/JobDlg.py index 07cdc13661..58be646e52 100644 --- a/src/Mod/CAM/Path/Main/Gui/JobDlg.py +++ b/src/Mod/CAM/Path/Main/Gui/JobDlg.py @@ -56,29 +56,7 @@ class JobCreate: DataObject = QtCore.Qt.ItemDataRole.UserRole def __init__(self, parent=None, sel=None): - # Warn user if current schema doesn't use minute for time in velocity - if not Path.Preferences.suppressVelocity(): - schemes = FreeCAD.Units.listSchemas() - for idx, val in enumerate(schemes): - if FreeCAD.ActiveDocument.UnitSystem == FreeCAD.Units.listSchemas(idx): - current_schema = FreeCAD.Units.listSchemas(idx) - if idx not in [2, 3, 6]: - msg = translate( - "CAM_Job", - "The currently selected unit schema: \n '{}' for this document\n Does not use 'minutes' for velocity values. \n \nCNC machines require feed rate to be expressed in \nunit/minute. To ensure correct G-code: \nSelect a minute-based schema in preferences.\nFor example:\n 'Metric, Small Parts & CNC'\n 'US Customary'\n 'Imperial Decimal'", - ).format(current_schema) - header = translate("CAM_Job", "Warning") - msgbox = QtGui.QMessageBox(QtGui.QMessageBox.Warning, header, msg) - - msgbox.addButton(translate("CAM_Job", "Ok"), QtGui.QMessageBox.AcceptRole) - msgbox.addButton( - translate("CAM_Job", "Don't Show This Anymore"), - QtGui.QMessageBox.ActionRole, - ) - if msgbox.exec_() == 1: - from Path.Preferences import preferences - - preferences().SetBool("WarningSuppressVelocity", True) + self._warnUserIfNotUsingMinutes() self.dialog = FreeCADGui.PySideUic.loadUi(":/panels/DlgJobCreate.ui") self.itemsSolid = QtGui.QStandardItem(translate("CAM_Job", "Solids")) @@ -86,12 +64,50 @@ class JobCreate: self.itemsJob = QtGui.QStandardItem(translate("CAM_Job", "Jobs")) self.dialog.templateGroup.hide() self.dialog.modelGroup.hide() + # debugging support self.candidates = None self.delegate = None self.index = None self.model = None + def _warnUserIfNotUsingMinutes(self): + # Warn user if current schema doesn't use minute for time in velocity + if Path.Preferences.suppressVelocity(): + return + + minute_based_schemes = map(FreeCAD.Units.listSchemas, [2, 3, 6]) + if FreeCAD.ActiveDocument.UnitSystem in minute_based_schemes: + return + + msg = translate( + "CAM_Job", + ( + "The currently selected unit schema: \n" + " '{}' for this document\n" + " Does not use 'minutes' for velocity values. \n" + " \n" + "CNC machines require feed rate to be expressed in \n" + "unit/minute. To ensure correct G-code: \n" + "Select a minute-based schema in preferences.\n" + "For example:\n" + " 'Metric, Small Parts & CNC'\n" + " 'US Customary'\n" + " 'Imperial Decimal'" + ), + ).format(FreeCAD.ActiveDocument.UnitSystem) + header = translate("CAM_Job", "Warning") + msgbox = QtGui.QMessageBox(QtGui.QMessageBox.Warning, header, msg) + msgbox.addButton(translate("CAM_Job", "Ok"), QtGui.QMessageBox.AcceptRole) + dont_show_again_button = msgbox.addButton( + translate("CAM_Job", "Don't Show This Anymore"), + QtGui.QMessageBox.ActionRole, + ) + + msgbox.exec_() + if msgbox.clickedButton() == dont_show_again_button: + Path.Preferences.preferences().SetBool(Path.Preferences.WarningSuppressVelocity, True) + def setupTitle(self, title): self.dialog.setWindowTitle(title) From b0947a7a64c5404fb8d73a7e75ebbb5699a69e2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20B=C3=A4hr?= Date: Sun, 16 Feb 2025 22:27:25 +0100 Subject: [PATCH 2/2] CAM: Improve warning text for improper unit scheme The previous text suggested to change the scheme in the preferences, however, the preferences only take effect for new documents. Now, that we have the "ProjectUnitSystem" in place, the setting for the current document needs to be changed. The text is restructured accodring to the UX pattern for warnings: - What is the problem - How can I fix it - What happens if I don't and includes a link to the wiki for further details. In addition, the 'US Customary' was removed from the proposed schemes as suggested during review. Finally, the button text was decapitalized and aligned with the style used in other parts of FreeCAD, e.g. the Start page. --- src/Mod/CAM/Path/Main/Gui/JobDlg.py | 49 +++++++++++++++++++---------- 1 file changed, 32 insertions(+), 17 deletions(-) diff --git a/src/Mod/CAM/Path/Main/Gui/JobDlg.py b/src/Mod/CAM/Path/Main/Gui/JobDlg.py index 58be646e52..439f934b0f 100644 --- a/src/Mod/CAM/Path/Main/Gui/JobDlg.py +++ b/src/Mod/CAM/Path/Main/Gui/JobDlg.py @@ -76,31 +76,46 @@ class JobCreate: if Path.Preferences.suppressVelocity(): return - minute_based_schemes = map(FreeCAD.Units.listSchemas, [2, 3, 6]) + # schemas in order of preference -- the first ones get proposed to the user + minute_based_schemes = list(map(FreeCAD.Units.listSchemas, [6, 3, 2])) if FreeCAD.ActiveDocument.UnitSystem in minute_based_schemes: return - msg = translate( + # NB: On macOS the header is ignored as per its UI guidelines. + header = translate("CAM_Job", "Warning: Incompatible Unit Schema") + info = translate( "CAM_Job", ( - "The currently selected unit schema: \n" - " '{}' for this document\n" - " Does not use 'minutes' for velocity values. \n" - " \n" - "CNC machines require feed rate to be expressed in \n" - "unit/minute. To ensure correct G-code: \n" - "Select a minute-based schema in preferences.\n" - "For example:\n" - " 'Metric, Small Parts & CNC'\n" - " 'US Customary'\n" - " 'Imperial Decimal'" + "This document uses an improper unit schema " + "which can result in dangerous situations and machine crashes!" ), - ).format(FreeCAD.ActiveDocument.UnitSystem) - header = translate("CAM_Job", "Warning") - msgbox = QtGui.QMessageBox(QtGui.QMessageBox.Warning, header, msg) + ) + details = translate( + "CAM_Job", + ( + "

This document's unit schema, '{}', " + "expresses velocity in values per second." + "\n" + "

Please change the unit schema in the document properties " + "to one that expresses feed rates per minute instead. " + "\n" + "For example: \n" + "

\n" + "\n" + "

Keeping the current unit schema can result in dangerous G-code errors. " + "For details please refer to the " + "Units section " + "of the CAM Workbench's wiki page." + ), + ).format(FreeCAD.ActiveDocument.UnitSystem, *minute_based_schemes[:2]) + msgbox = QtGui.QMessageBox(QtGui.QMessageBox.Warning, header, info) + msgbox.setInformativeText(details) msgbox.addButton(translate("CAM_Job", "Ok"), QtGui.QMessageBox.AcceptRole) dont_show_again_button = msgbox.addButton( - translate("CAM_Job", "Don't Show This Anymore"), + translate("CAM_Job", "Don't show this warning again"), QtGui.QMessageBox.ActionRole, )