From e96e32580e02043ea79107a1094f53bf71c5973d Mon Sep 17 00:00:00 2001 From: Markus Lampert Date: Sun, 21 Jan 2018 17:42:53 -0800 Subject: [PATCH] Fixed template-export menu activation. --- src/Mod/Path/PathScripts/PathJob.py | 6 ++++++ src/Mod/Path/PathScripts/PathJobCmd.py | 19 +++++++++++++++++-- src/Mod/Path/PathScripts/PathUtils.py | 18 +++++------------- 3 files changed, 28 insertions(+), 15 deletions(-) diff --git a/src/Mod/Path/PathScripts/PathJob.py b/src/Mod/Path/PathScripts/PathJob.py index 2b788c2eb8..8dd9ecf29e 100644 --- a/src/Mod/Path/PathScripts/PathJob.py +++ b/src/Mod/Path/PathScripts/PathJob.py @@ -312,6 +312,12 @@ class ObjectJob: '''Answer true if the given object can be used as a Base for a job.''' return PathUtil.isValidBaseObject(obj) or isArchPanelSheet(obj) +def Instances(): + '''Instances() ... Return all Jobs in the current active document.''' + if FreeCAD.ActiveDocument: + return [job for job in FreeCAD.ActiveDocument.Objects if hasattr(job, 'Proxy') and isinstance(job.Proxy, ObjectJob)] + return [] + def Create(name, base, templateFile = None): '''Create(name, base, templateFile=None) ... creates a new job and all it's resources. If a template file is specified the new job is initialized with the values from the template.''' diff --git a/src/Mod/Path/PathScripts/PathJobCmd.py b/src/Mod/Path/PathScripts/PathJobCmd.py index a9bc7e4c4b..0f9c21e786 100644 --- a/src/Mod/Path/PathScripts/PathJobCmd.py +++ b/src/Mod/Path/PathScripts/PathJobCmd.py @@ -224,11 +224,26 @@ class CommandJobTemplateExport: 'MenuText': QtCore.QT_TRANSLATE_NOOP("Path_Job", "Export Template"), 'ToolTip': QtCore.QT_TRANSLATE_NOOP("Path_Job", "Exports Path Job as a template to be used for other jobs")} + def GetJob(self): + # if there's only one Job in the document ... + jobs = PathJob.Instances() + if not jobs: + return None + if len(jobs) == 1: + return jobs[0] + # more than one job, is one of them selected? + sel = FreeCADGui.Selection.getSelection() + if len(sel) == 1: + job = sel[0] + return hasattr(job, 'Proxy') and isinstance(job.Proxy, PathJob.ObjectJob) + return None + + def IsActive(self): - return FreeCAD.ActiveDocument is not None + return self.GetJob() is not None def Activated(self): - job = FreeCADGui.Selection.getSelection()[0] + job = self.GetJob() dialog = DlgJobTemplateExport(job) if dialog.exec_() == 1: foo = QtGui.QFileDialog.getSaveFileName(QtGui.qApp.activeWindow(), diff --git a/src/Mod/Path/PathScripts/PathUtils.py b/src/Mod/Path/PathScripts/PathUtils.py index abd847493c..18913dbfbf 100644 --- a/src/Mod/Path/PathScripts/PathUtils.py +++ b/src/Mod/Path/PathScripts/PathUtils.py @@ -486,22 +486,15 @@ def findParentJob(obj): def GetJobs(jobname=None): '''returns all jobs in the current document. If name is given, returns that job''' - PathLog.track() - jobs = [] - for o in FreeCAD.ActiveDocument.Objects: - if hasattr(o, 'Proxy') and isinstance(o.Proxy, PathJob.ObjectJob): - if jobname is not None: - if o.Name == jobname: - jobs.append(o) - else: - jobs.append(o) - return jobs + if jobname: + return [job for job in PathJob.Instances() if job.Name == jobname] + return PathJob.Instances() def addToJob(obj, jobname=None): '''adds a path object to a job obj = obj jobname = None''' - PathLog.track() + PathLog.track(jobname) if jobname is not None: jobs = GetJobs(jobname) if len(jobs) == 1: @@ -513,7 +506,6 @@ def addToJob(obj, jobname=None): jobs = GetJobs() if len(jobs) == 0: job = PathJobCmd.CommandJobCreate().Activated() - elif len(jobs) == 1: job = jobs[0] else: @@ -528,7 +520,7 @@ def addToJob(obj, jobname=None): print(form.cboProject.currentText()) job = [i for i in jobs if i.Label == form.cboProject.currentText()][0] - if obj: + if obj and job: job.Proxy.addOperation(obj) return job