Skip to content

Commit

Permalink
Add CycleTime Attribute to PathJob
Browse files Browse the repository at this point in the history
  • Loading branch information
dubstar-04 committed Apr 22, 2020
1 parent ca35d67 commit be14fb8
Showing 1 changed file with 39 additions and 2 deletions.
41 changes: 39 additions & 2 deletions src/Mod/Path/PathScripts/PathJob.py
Expand Up @@ -30,7 +30,7 @@
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
Expand Down Expand Up @@ -99,6 +99,8 @@ def __init__(self, obj, models, templateFile = None):
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."))
Expand All @@ -110,7 +112,7 @@ def __init__(self, obj, models, templateFile = None):
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()
Expand Down Expand Up @@ -252,6 +254,10 @@ def onDocumentRestored(self, obj):
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)
Expand Down Expand Up @@ -342,6 +348,37 @@ def __setstate__(self, state):

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
Expand Down

0 comments on commit be14fb8

Please sign in to comment.