diff --git a/src/Mod/Path/PathScripts/PathJob.py b/src/Mod/Path/PathScripts/PathJob.py index 2225c2fa9f..463a36deab 100644 --- a/src/Mod/Path/PathScripts/PathJob.py +++ b/src/Mod/Path/PathScripts/PathJob.py @@ -30,7 +30,7 @@ import PathScripts.PathSetupSheet as PathSetupSheet import PathScripts.PathStock as PathStock import PathScripts.PathToolController as PathToolController import PathScripts.PathUtil as PathUtil -import json +import json, time # lazily loaded modules from lazy_loader.lazy_loader import LazyLoader @@ -99,6 +99,8 @@ class ObjectJob: obj.addProperty("App::PropertyString", "PostProcessorArgs", "Output", QtCore.QT_TRANSLATE_NOOP("PathJob", "Arguments for the Post Processor (specific to the script)")) obj.addProperty("App::PropertyString", "Description", "Path", QtCore.QT_TRANSLATE_NOOP("PathJob","An optional description for this job")) + obj.addProperty("App::PropertyString", "CycleTime", "Path", QtCore.QT_TRANSLATE_NOOP("PathOp", "Operations Cycle Time Estimation")) + obj.setEditorMode('CycleTime', 1) # read-only obj.addProperty("App::PropertyDistance", "GeometryTolerance", "Geometry", QtCore.QT_TRANSLATE_NOOP("PathJob", "For computing Paths; smaller increases accuracy, but slows down computation")) obj.addProperty("App::PropertyLink", "Stock", "Base", QtCore.QT_TRANSLATE_NOOP("PathJob", "Solid object to be used as stock.")) @@ -110,7 +112,7 @@ class ObjectJob: obj.addProperty("App::PropertyStringList", "Fixtures", "WCS", QtCore.QT_TRANSLATE_NOOP("PathJob", "The Work Coordinate Systems for the Job")) obj.OrderOutputBy = ['Fixture', 'Tool', 'Operation'] obj.Fixtures = ['G54'] - + obj.PostProcessorOutputFile = PathPreferences.defaultOutputFile() #obj.setEditorMode("PostProcessorOutputFile", 0) # set to default mode obj.PostProcessor = postProcessors = PathPreferences.allEnabledPostProcessors() @@ -252,6 +254,10 @@ class ObjectJob: obj.setEditorMode('Operations', 2) # hide obj.setEditorMode('Placement', 2) + if not hasattr(obj, 'CycleTime'): + obj.addProperty("App::PropertyString", "CycleTime", "Path", QtCore.QT_TRANSLATE_NOOP("PathOp", "Operations Cycle Time Estimation")) + obj.setEditorMode('CycleTime', 1) # read-only + def onChanged(self, obj, prop): if prop == "PostProcessor" and obj.PostProcessor: processor = PostProcessor.load(obj.PostProcessor) @@ -342,6 +348,37 @@ class ObjectJob: def execute(self, obj): obj.Path = obj.Operations.Path + self.getCycleTime() + + def getCycleTime(self): + seconds = 0 + for op in self.obj.Operations.Group: + + # Skip inactive operations + if PathUtil.opProperty(op, 'Active') is False: + continue + + # Skip operations that don't have a cycletime attribute + if not PathUtil.opProperty(op, 'CycleTime') or PathUtil.opProperty(op, 'CycleTime') is None: + continue + + formattedCycleTime = PathUtil.opProperty(op, 'CycleTime') + try: + ## convert the formatted time from HH:MM:SS to just seconds + opCycleTime = sum(x * int(t) for x, t in zip([1, 60, 3600], reversed(formattedCycleTime.split(":")))) + except: + FreeCAD.Console.PrintWarning("Error converting the operations cycle time. Job Cycle time may be innacturate\n") + continue + + if opCycleTime > 0: + seconds = seconds + opCycleTime + + if seconds > 0: + cycleTimeString = time.strftime("%H:%M:%S", time.gmtime(seconds)) + else: + cycleTimeString = translate('PathGui', 'Cycle Time Error') + + self.obj.CycleTime = cycleTimeString def addOperation(self, op, before = None, removeBefore = False): group = self.obj.Operations.Group