From 07c774b872cba418c3164446a80c4b1cf854bd95 Mon Sep 17 00:00:00 2001 From: tarman3 Date: Mon, 26 May 2025 12:13:03 +0300 Subject: [PATCH] CAM: Added property CycleTime to old Array --- src/Mod/CAM/Path/Op/Base.py | 87 ++++++++++++++++---------------- src/Mod/CAM/Path/Op/Gui/Array.py | 38 ++++++++++---- 2 files changed, 71 insertions(+), 54 deletions(-) diff --git a/src/Mod/CAM/Path/Op/Base.py b/src/Mod/CAM/Path/Op/Base.py index 25bdb9afd6..0961f80c8b 100644 --- a/src/Mod/CAM/Path/Op/Base.py +++ b/src/Mod/CAM/Path/Op/Base.py @@ -793,53 +793,10 @@ class ObjectOp(object): path = Path.Path(self.commandlist) obj.Path = path - obj.CycleTime = self.getCycleTimeEstimate(obj) + obj.CycleTime = getCycleTimeEstimate(obj) self.job.Proxy.getCycleTime() return result - def getCycleTimeEstimate(self, obj): - - tc = obj.ToolController - - if tc is None or tc.ToolNumber == 0: - Path.Log.error(translate("CAM", "No Tool Controller selected.")) - return translate("CAM", "Tool Error") - - hFeedrate = tc.HorizFeed.Value - vFeedrate = tc.VertFeed.Value - hRapidrate = tc.HorizRapid.Value - vRapidrate = tc.VertRapid.Value - - if (hFeedrate == 0 or vFeedrate == 0) and not Path.Preferences.suppressAllSpeedsWarning(): - Path.Log.warning( - translate( - "CAM", - "Tool Controller feedrates required to calculate the cycle time.", - ) - ) - return translate("CAM", "Feedrate Error") - - if ( - hRapidrate == 0 or vRapidrate == 0 - ) and not Path.Preferences.suppressRapidSpeedsWarning(): - Path.Log.warning( - translate( - "CAM", - "Add Tool Controller Rapid Speeds on the SetupSheet for more accurate cycle times.", - ) - ) - - # Get the cycle time in seconds - seconds = obj.Path.getCycleTime(hFeedrate, vFeedrate, hRapidrate, vRapidrate) - - if not seconds or math.isnan(seconds): - return translate("CAM", "Cycletime Error") - - # Convert the cycle time to a HH:MM:SS format - cycleTime = time.strftime("%H:%M:%S", time.gmtime(seconds)) - - return cycleTime - def addBase(self, obj, base, sub): Path.Log.track(obj, base, sub) base = PathUtil.getPublicObject(base) @@ -876,3 +833,45 @@ class ObjectOp(object): This function can safely be overwritten by subclasses.""" return True + + +def getCycleTimeEstimate(obj): + tc = obj.ToolController + + if tc is None or tc.ToolNumber == 0: + Path.Log.error(translate("CAM", "No Tool Controller selected.")) + return translate("CAM", "Tool Error") + + hFeedrate = tc.HorizFeed.Value + vFeedrate = tc.VertFeed.Value + hRapidrate = tc.HorizRapid.Value + vRapidrate = tc.VertRapid.Value + + if hFeedrate == 0 or vFeedrate == 0: + if not Path.Preferences.suppressAllSpeedsWarning(): + Path.Log.warning( + translate( + "CAM", + "Tool Controller feedrates required to calculate the cycle time.", + ) + ) + return translate("CAM", "Tool Feedrate Error") + + if (hRapidrate == 0 or vRapidrate == 0) and not Path.Preferences.suppressRapidSpeedsWarning(): + Path.Log.warning( + translate( + "CAM", + "Add Tool Controller Rapid Speeds on the SetupSheet for more accurate cycle times.", + ) + ) + + # Get the cycle time in seconds + seconds = obj.Path.getCycleTime(hFeedrate, vFeedrate, hRapidrate, vRapidrate) + + if math.isnan(seconds): + return translate("CAM", "Cycletime Error") + + # Convert the cycle time to a HH:MM:SS format + cycleTime = time.strftime("%H:%M:%S", time.gmtime(seconds)) + + return cycleTime diff --git a/src/Mod/CAM/Path/Op/Gui/Array.py b/src/Mod/CAM/Path/Op/Gui/Array.py index bde38cde18..8a33d58280 100644 --- a/src/Mod/CAM/Path/Op/Gui/Array.py +++ b/src/Mod/CAM/Path/Op/Gui/Array.py @@ -23,14 +23,15 @@ import FreeCAD import FreeCADGui import Path +import Path.Op.Base as PathOp import PathScripts import PathScripts.PathUtils as PathUtils from Path.Dressup.Utils import toolController from PySide import QtCore from PySide import QtGui -import math import random + from PySide.QtCore import QT_TRANSLATE_NOOP __doc__ = """CAM Array object and FreeCAD command""" @@ -139,7 +140,14 @@ class ObjectArray: "Path", QT_TRANSLATE_NOOP("PathOp", "Make False, to prevent operation from generating code"), ) + obj.addProperty( + "App::PropertyString", + "CycleTime", + "Path", + QT_TRANSLATE_NOOP("App::Property", "Operations Cycle Time Estimation"), + ) + obj.setEditorMode("CycleTime", 1) # read-only obj.Active = True obj.Type = ["Linear1D", "Linear2D", "Polar"] @@ -165,15 +173,6 @@ class ObjectArray: angleMode = copiesMode = centreMode = 0 copiesXMode = copiesYMode = offsetMode = swapDirectionMode = 2 - if not hasattr(obj, "JitterSeed"): - obj.addProperty( - "App::PropertyInteger", - "JitterSeed", - "Path", - QtCore.QT_TRANSLATE_NOOP("App::Property", "Seed value for jitter randomness"), - ) - obj.JitterSeed = 0 - obj.setEditorMode("Angle", angleMode) obj.setEditorMode("Copies", copiesMode) obj.setEditorMode("Centre", centreMode) @@ -204,6 +203,24 @@ class ObjectArray: ) obj.Active = True + if not hasattr(obj, "JitterSeed"): + obj.addProperty( + "App::PropertyInteger", + "JitterSeed", + "Path", + QtCore.QT_TRANSLATE_NOOP("App::Property", "Seed value for jitter randomness"), + ) + obj.JitterSeed = 0 + + if not hasattr(obj, "CycleTime"): + obj.addProperty( + "App::PropertyString", + "CycleTime", + "Path", + QT_TRANSLATE_NOOP("App::Property", "Operations Cycle Time Estimation"), + ) + obj.CycleTime = self.getCycleTimeEstimate(obj) + self.setEditorModes(obj) self.FirstRun = True @@ -261,6 +278,7 @@ class ObjectArray: ) obj.Path = pa.getPath() + obj.CycleTime = PathOp.getCycleTimeEstimate(obj) class PathArray: