Switched job assignments to be empty which uses the default from the prefrences - if no preferences can't be found the user is prompted.
This commit is contained in:
parent
e1a5b9a9e1
commit
18791037be
|
@ -69,6 +69,7 @@ SET(PathScripts_SRCS
|
|||
PathScripts/PathToolLibraryManager.py
|
||||
PathScripts/DogboneDressup.py
|
||||
PathScripts/PathPreferencesPathJob.py
|
||||
PathScripts/PathPreferences.py
|
||||
)
|
||||
|
||||
SET(PathScripts_NC_SRCS
|
||||
|
|
|
@ -86,6 +86,7 @@
|
|||
<file>panels/ContourEdit.ui</file>
|
||||
<file>panels/ProfileEdgesEdit.ui</file>
|
||||
<file>panels/DogboneEdit.ui</file>
|
||||
<file>panels/DlgSelectPostProcessor.ui</file>
|
||||
<file>preferences/PathJob.ui</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
|
81
src/Mod/Path/Gui/Resources/panels/DlgSelectPostProcessor.ui
Normal file
81
src/Mod/Path/Gui/Resources/panels/DlgSelectPostProcessor.ui
Normal file
|
@ -0,0 +1,81 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>Dialog</class>
|
||||
<widget class="QDialog" name="Dialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>300</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Post Processor</string>
|
||||
</property>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>30</x>
|
||||
<y>240</y>
|
||||
<width>341</width>
|
||||
<height>32</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QListWidget" name="lwPostProcessor">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>20</x>
|
||||
<y>30</y>
|
||||
<width>351</width>
|
||||
<height>191</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string><html><head/><body><p>Select one of the post processors.</p><p>FreeCAD comes with several post processors pre-installed, please make sure at least one of them is enabled in your preferences.</p></body></html></string>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>Dialog</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>248</x>
|
||||
<y>254</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>157</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>Dialog</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>316</x>
|
||||
<y>260</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>286</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
|
@ -35,15 +35,15 @@
|
|||
</sizepolicy>
|
||||
</property>
|
||||
<property name="currentIndex">
|
||||
<number>2</number>
|
||||
<number>0</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="General">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>378</width>
|
||||
<height>409</height>
|
||||
<width>363</width>
|
||||
<height>443</height>
|
||||
</rect>
|
||||
</property>
|
||||
<attribute name="icon">
|
||||
|
@ -146,7 +146,7 @@
|
|||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>378</width>
|
||||
<height>409</height>
|
||||
<height>391</height>
|
||||
</rect>
|
||||
</property>
|
||||
<attribute name="icon">
|
||||
|
@ -215,8 +215,8 @@
|
|||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>378</width>
|
||||
<height>409</height>
|
||||
<width>424</width>
|
||||
<height>376</height>
|
||||
</rect>
|
||||
</property>
|
||||
<attribute name="icon">
|
||||
|
@ -283,7 +283,7 @@
|
|||
</property>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Use default</string>
|
||||
<string></string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
|
|
|
@ -62,7 +62,7 @@
|
|||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="browseFileSystem">
|
||||
<widget class="QPushButton" name="pbBrowseFileSystem">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
|
|
|
@ -25,11 +25,11 @@
|
|||
import FreeCAD
|
||||
import Path
|
||||
from PySide import QtCore, QtGui
|
||||
from PathScripts.PathPostProcessor import PostProcessor
|
||||
from PathScripts.PathPreferences import PathPreferences
|
||||
import Draft
|
||||
import os
|
||||
import glob
|
||||
from PathScripts.PathPostProcessor import PostProcessor
|
||||
from PathScripts.PathPost import CommandPathPost as PathPost
|
||||
import Draft
|
||||
|
||||
|
||||
FreeCADGui = None
|
||||
|
@ -49,7 +49,7 @@ except AttributeError:
|
|||
return QtGui.QApplication.translate(context, text, disambig)
|
||||
|
||||
class OutputPolicy:
|
||||
Default = 'Use default'
|
||||
Default = ''
|
||||
Dialog = 'Open File Dialog'
|
||||
DialogOnConflict = 'Open File Dialog on conflict'
|
||||
Overwrite = 'Overwrite existing file'
|
||||
|
@ -61,7 +61,7 @@ class ObjectPathJob:
|
|||
def __init__(self, obj):
|
||||
# obj.addProperty("App::PropertyFile", "PostProcessor", "CodeOutput", "Select the Post Processor file for this project")
|
||||
obj.addProperty("App::PropertyFile", "OutputFile", "CodeOutput", QtCore.QT_TRANSLATE_NOOP("App::Property","The NC output file for this project"))
|
||||
obj.OutputFile = PathPost.defaultOutputFile()
|
||||
obj.OutputFile = ''
|
||||
obj.setEditorMode("OutputFile", 0) # set to default mode
|
||||
obj.addProperty("App::PropertyEnumeration", "OutputPolicy", "CodeOutput", QtCore.QT_TRANSLATE_NOOP("App::Property","The policy on how to save output files and resolve name conflicts"))
|
||||
obj.OutputPolicy = OutputPolicy.All
|
||||
|
@ -69,10 +69,10 @@ class ObjectPathJob:
|
|||
|
||||
obj.addProperty("App::PropertyString", "Description", "Path", QtCore.QT_TRANSLATE_NOOP("App::Property","An optional description for this job"))
|
||||
obj.addProperty("App::PropertyEnumeration", "PostProcessor", "Output", QtCore.QT_TRANSLATE_NOOP("App::Property","Select the Post Processor"))
|
||||
obj.PostProcessor = PostProcessor.allEnabled()
|
||||
obj.PostProcessor = 'dumper'
|
||||
obj.PostProcessor = PathPreferences.allEnabledPostProcessors([''])
|
||||
obj.PostProcessor = ''
|
||||
obj.addProperty("App::PropertyString", "PostProcessorArgs", "Output", QtCore.QT_TRANSLATE_NOOP("App::Property", "Arguments for the Post Processor (specific to the script)"))
|
||||
obj.PostProcessorArgs = ""
|
||||
obj.PostProcessorArgs = ''
|
||||
obj.addProperty("App::PropertyString", "MachineName", "Output", QtCore.QT_TRANSLATE_NOOP("App::Property","Name of the Machine that will use the CNC program"))
|
||||
|
||||
obj.addProperty("Path::PropertyTooltable", "Tooltable", "Base", QtCore.QT_TRANSLATE_NOOP("App::Property","The tooltable used for this CNC program"))
|
||||
|
@ -92,11 +92,6 @@ class ObjectPathJob:
|
|||
|
||||
obj.Proxy = self
|
||||
|
||||
defaultPostProcessor = PostProcessor.default()
|
||||
if defaultPostProcessor:
|
||||
obj.PostProcessor = defaultPostProcessor
|
||||
obj.PostProcessorArgs = PostProcessor.defaultArgs()
|
||||
|
||||
if FreeCAD.GuiUp:
|
||||
ViewProviderJob(obj.ViewObject)
|
||||
|
||||
|
@ -111,7 +106,7 @@ class ObjectPathJob:
|
|||
mode = 2
|
||||
obj.setEditorMode('Placement', mode)
|
||||
|
||||
if prop == "PostProcessor":
|
||||
if prop == "PostProcessor" and obj.PostProcessor:
|
||||
processor = PostProcessor.load(obj.PostProcessor)
|
||||
if processor.units:
|
||||
obj.MachineUnits = processor.units
|
||||
|
@ -236,7 +231,7 @@ class TaskPanel:
|
|||
self.form = FreeCADGui.PySideUic.loadUi(":/panels/JobEdit.ui")
|
||||
#self.form = FreeCADGui.PySideUic.loadUi(FreeCAD.getHomePath() + "Mod/Path/JobEdit.ui")
|
||||
|
||||
for post in PostProcessor.allEnabled():
|
||||
for post in PathPreferences.allEnabledPostProcessors(['']):
|
||||
self.form.cboPostProcessor.addItem(post)
|
||||
self.updating = False
|
||||
|
||||
|
@ -341,7 +336,7 @@ class TaskPanel:
|
|||
|
||||
def setFile(self):
|
||||
filename = QtGui.QFileDialog.getSaveFileName(self.form, translate("PathJob", "Select Output File", None), None, translate("Path Job", "All Files (*.*)", None))
|
||||
if filename:
|
||||
if filename and filename[0]:
|
||||
self.obj.OutputFile = str(filename[0])
|
||||
self.setFields()
|
||||
|
||||
|
|
|
@ -24,10 +24,12 @@
|
|||
''' Post Process command that will make use of the Output File and Post Processor entries in PathJob '''
|
||||
import FreeCAD
|
||||
import FreeCADGui
|
||||
from PySide import QtCore, QtGui
|
||||
from PathScripts import PathUtils
|
||||
from PathScripts.PathPreferences import PathPreferences
|
||||
from PathScripts.PathPostProcessor import PostProcessor
|
||||
import os
|
||||
import sys
|
||||
from PySide import QtCore, QtGui
|
||||
|
||||
# Qt tanslation handling
|
||||
try:
|
||||
|
@ -39,30 +41,44 @@ except AttributeError:
|
|||
def translate(context, text, disambig=None):
|
||||
return QtGui.QApplication.translate(context, text, disambig)
|
||||
|
||||
class DlgSelectPostProcessor:
|
||||
|
||||
def __init__(self, parent=None):
|
||||
self.dialog = FreeCADGui.PySideUic.loadUi(":/panels/DlgSelectPostProcessor.ui")
|
||||
for post in PathPreferences.allEnabledPostProcessors():
|
||||
item = QtGui.QListWidgetItem(post)
|
||||
item.setFlags(QtCore.Qt.ItemFlag.ItemIsSelectable | QtCore.Qt.ItemFlag.ItemIsEnabled)
|
||||
self.dialog.lwPostProcessor.addItem(item)
|
||||
self.tooltips = {}
|
||||
self.dialog.buttonBox.button(QtGui.QDialogButtonBox.Ok).setEnabled(False)
|
||||
self.dialog.lwPostProcessor.itemDoubleClicked.connect(self.dialog.accept)
|
||||
self.dialog.lwPostProcessor.itemSelectionChanged.connect(self.enableOkButton)
|
||||
self.dialog.lwPostProcessor.setMouseTracking(True)
|
||||
self.dialog.lwPostProcessor.itemEntered.connect(self.updateTooltip)
|
||||
|
||||
def enableOkButton(self):
|
||||
self.dialog.buttonBox.button(QtGui.QDialogButtonBox.Ok).setEnabled(True)
|
||||
|
||||
def updateTooltip(self, item):
|
||||
if item.text() in self.tooltips.keys():
|
||||
tooltip = self.tooltips[item.text()]
|
||||
else:
|
||||
processor = PostProcessor.load(item.text())
|
||||
self.tooltips[item.text()] = processor.tooltip
|
||||
tooltip = processor.tooltip
|
||||
self.dialog.lwPostProcessor.setToolTip(tooltip)
|
||||
|
||||
def exec_(self):
|
||||
if self.dialog.exec_() == 1:
|
||||
posts = self.dialog.lwPostProcessor.selectedItems()
|
||||
return posts[0].text()
|
||||
return None
|
||||
|
||||
class CommandPathPost:
|
||||
|
||||
DefaultOutputFile = "DefaultOutputFile"
|
||||
DefaultOutputPolicy = "DefaultOutputPolicy"
|
||||
|
||||
@classmethod
|
||||
def saveDefaults(cls, path, policy):
|
||||
preferences = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Path")
|
||||
preferences.SetString(cls.DefaultOutputFile, path)
|
||||
preferences.SetString(cls.DefaultOutputPolicy, policy)
|
||||
|
||||
@classmethod
|
||||
def defaultOutputFile(cls):
|
||||
preferences = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Path")
|
||||
return preferences.GetString(cls.DefaultOutputFile, "")
|
||||
|
||||
@classmethod
|
||||
def defaultOutputPolicy(cls):
|
||||
preferences = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Path")
|
||||
return preferences.GetString(cls.DefaultOutputPolicy, "")
|
||||
|
||||
def resolveFileName(self, job):
|
||||
path = "tmp.tap"
|
||||
print("resolveFileName(%s)" % job.Label)
|
||||
path = PathPreferences.defaultOutputFile()
|
||||
if job.OutputFile:
|
||||
path = job.OutputFile
|
||||
filename = path
|
||||
|
@ -89,8 +105,8 @@ class CommandPathPost:
|
|||
filename = filename.replace('%M', M)
|
||||
|
||||
policy = job.OutputPolicy
|
||||
if not policy or policy == 'Use default':
|
||||
policy = self.defaultOutputPolicy()
|
||||
if not policy or policy == '':
|
||||
policy = PathPreferences.defaultOutputPolicy()
|
||||
|
||||
openDialog = policy == 'Open File Dialog'
|
||||
if os.path.isdir(filename) or not os.path.isdir(os.path.dirname(filename)):
|
||||
|
@ -118,9 +134,20 @@ class CommandPathPost:
|
|||
else:
|
||||
filename = None
|
||||
|
||||
#print("resolveFileName(%s, %s) -> '%s'" % (path, policy, filename))
|
||||
print("resolveFileName(%s, %s) -> '%s'" % (path, policy, filename))
|
||||
return filename
|
||||
|
||||
def resolvePostProcessor(self, job):
|
||||
if hasattr(job, "PostProcessor"):
|
||||
post = PathPreferences.defaultPostProcessor()
|
||||
if job.PostProcessor:
|
||||
post = job.PostProcessor
|
||||
if post and PostProcessor.exists(post):
|
||||
return post
|
||||
dlg = DlgSelectPostProcessor()
|
||||
return dlg.exec_()
|
||||
|
||||
|
||||
def GetResources(self):
|
||||
return {'Pixmap': 'Path-Post',
|
||||
'MenuText': QtCore.QT_TRANSLATE_NOOP("Path_Post", "Post Process"),
|
||||
|
@ -129,8 +156,9 @@ class CommandPathPost:
|
|||
|
||||
def IsActive(self):
|
||||
if FreeCAD.ActiveDocument is not None:
|
||||
for o in FreeCAD.ActiveDocument.Objects:
|
||||
if o.Name[:3] == "Job":
|
||||
if FreeCADGui.Selection.getCompleteSelection():
|
||||
for o in FreeCAD.ActiveDocument.Objects:
|
||||
if o.Name[:3] == "Job":
|
||||
return True
|
||||
return False
|
||||
|
||||
|
@ -139,41 +167,45 @@ class CommandPathPost:
|
|||
translate("Path_Post", "Post Process the Selected path(s)"))
|
||||
FreeCADGui.addModule("PathScripts.PathPost")
|
||||
# select the Path Job that you want to post output from
|
||||
obj = FreeCADGui.Selection.getCompleteSelection()
|
||||
selected = FreeCADGui.Selection.getCompleteSelection()
|
||||
print "in activated %s" %(selected)
|
||||
|
||||
# default to the dumper post and default .tap file
|
||||
postname = "dumper"
|
||||
postArgs = ""
|
||||
|
||||
print "in activated %s" %(obj)
|
||||
|
||||
# check if the user has a project and has set the default post and
|
||||
# output filename
|
||||
if hasattr(obj[0], "Group") and hasattr(obj[0], "Path"):
|
||||
# # Check for a selected post post processor if it's set
|
||||
job = obj[0]
|
||||
|
||||
if hasattr(obj[0], "PostProcessor"):
|
||||
postobj = obj[0]
|
||||
|
||||
# need to check for existance of these: obj.PostProcessor,
|
||||
# obj.OutputFile
|
||||
if postobj and postobj.PostProcessor:
|
||||
sys.path.append(os.path.split(postobj.PostProcessor)[0])
|
||||
lessextn = os.path.splitext(postobj.PostProcessor)[0]
|
||||
postname = os.path.split(lessextn)[1]
|
||||
|
||||
if hasattr(postobj, "PostProcessorArgs"):
|
||||
postArgs = postobj.PostProcessorArgs
|
||||
|
||||
filename = self.resolveFileName(job)
|
||||
if filename:
|
||||
processor = PostProcessor.load(postname)
|
||||
processor.export(obj, filename, postArgs)
|
||||
|
||||
FreeCAD.ActiveDocument.commitTransaction()
|
||||
else:
|
||||
# try to find the job, if it's not directly selected ...
|
||||
jobs = set()
|
||||
for obj in selected:
|
||||
if hasattr(obj, 'OutputFile') or hasattr(obj, 'PostProcessor'):
|
||||
jobs.add(obj)
|
||||
elif hasattr(obj, 'Path') or hasattr(obj, 'ToolNumber'):
|
||||
job = PathUtils.findParentJob(obj)
|
||||
if job:
|
||||
jobs.add(job)
|
||||
if len(jobs) != 1:
|
||||
FreeCAD.Console.PrintError("Please select a single job or other path object\n")
|
||||
FreeCAD.ActiveDocument.abortTransaction()
|
||||
else:
|
||||
job = jobs.pop()
|
||||
print("Job for selected objects = %s" % job.Name)
|
||||
|
||||
# check if the user has a project and has set the default post and
|
||||
# output filename
|
||||
postArgs = PathPreferences.defaultPostProcessorArgs()
|
||||
if hasattr(job, "PostProcessorArgs") and job.PostProcessorArgs:
|
||||
postArgs = job.PostProcessorArgs
|
||||
elif hasattr(job, "PostProcessor") and job.PostProcessor:
|
||||
postArgs = ''
|
||||
|
||||
postname = self.resolvePostProcessor(job)
|
||||
if postname:
|
||||
filename = self.resolveFileName(job)
|
||||
|
||||
if postname and filename:
|
||||
print("post: %s(%s, %s)" % (postname, filename, postArgs))
|
||||
processor = PostProcessor.load(postname)
|
||||
processor.export(selected, filename, postArgs)
|
||||
|
||||
FreeCAD.ActiveDocument.commitTransaction()
|
||||
else:
|
||||
FreeCAD.ActiveDocument.abortTransaction()
|
||||
FreeCAD.ActiveDocument.recompute()
|
||||
|
||||
if FreeCAD.GuiUp:
|
||||
|
|
|
@ -23,60 +23,13 @@
|
|||
# ***************************************************************************
|
||||
|
||||
import FreeCAD
|
||||
import os
|
||||
import glob
|
||||
|
||||
from PathScripts.PathPreferences import PathPreferences
|
||||
|
||||
class PostProcessor:
|
||||
|
||||
Default = "PostProcessorDefault"
|
||||
DefaultArgs = "PostProcessorDefaultArgs"
|
||||
Blacklist = "PostProcessorBlacklist"
|
||||
|
||||
@classmethod
|
||||
def all(cls):
|
||||
path = FreeCAD.getHomePath() + ("Mod/Path/PathScripts/")
|
||||
posts = glob.glob(path + '/*_post.py')
|
||||
allposts = [ str(os.path.split(os.path.splitext(p)[0])[1][:-5]) for p in posts]
|
||||
|
||||
grp = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Macro")
|
||||
path = grp.GetString("MacroPath", FreeCAD.getUserAppDataDir())
|
||||
posts = glob.glob(path + '/*_post.py')
|
||||
|
||||
allposts.extend([ str(os.path.split(os.path.splitext(p)[0])[1][:-5]) for p in posts])
|
||||
allposts.sort()
|
||||
return allposts
|
||||
|
||||
@classmethod
|
||||
def allEnabled(cls):
|
||||
blacklist = cls.blacklist()
|
||||
return [processor for processor in cls.all() if not processor in blacklist]
|
||||
|
||||
|
||||
@classmethod
|
||||
def default(cls):
|
||||
preferences = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Path")
|
||||
return preferences.GetString(cls.Default, "")
|
||||
|
||||
@classmethod
|
||||
def defaultArgs(cls):
|
||||
preferences = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Path")
|
||||
return preferences.GetString(cls.DefaultArgs, "")
|
||||
|
||||
@classmethod
|
||||
def blacklist(cls):
|
||||
preferences = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Path")
|
||||
blacklist = preferences.GetString(cls.Blacklist, "")
|
||||
if not blacklist:
|
||||
return []
|
||||
return eval(blacklist)
|
||||
|
||||
@classmethod
|
||||
def saveDefaults(cls, processor, args, blacklist):
|
||||
preferences = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Path")
|
||||
preferences.SetString(cls.Default, processor)
|
||||
preferences.SetString(cls.DefaultArgs, args)
|
||||
preferences.SetString(cls.Blacklist, "%s" % (blacklist))
|
||||
def exists(cls, processor):
|
||||
return processor in PathPreferences.allAvailablePostProcessors()
|
||||
|
||||
@classmethod
|
||||
def load(cls, processor):
|
||||
|
|
101
src/Mod/Path/PathScripts/PathPreferences.py
Normal file
101
src/Mod/Path/PathScripts/PathPreferences.py
Normal file
|
@ -0,0 +1,101 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# ***************************************************************************
|
||||
# * *
|
||||
# * Copyright (c) 2014 Yorik van Havre <yorik@uncreated.net> *
|
||||
# * *
|
||||
# * This program is free software; you can redistribute it and/or modify *
|
||||
# * it under the terms of the GNU Lesser General Public License (LGPL) *
|
||||
# * as published by the Free Software Foundation; either version 2 of *
|
||||
# * the License, or (at your option) any later version. *
|
||||
# * for detail see the LICENCE text file. *
|
||||
# * *
|
||||
# * This program is distributed in the hope that it will be useful, *
|
||||
# * but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
# * GNU Library General Public License for more details. *
|
||||
# * *
|
||||
# * You should have received a copy of the GNU Library General Public *
|
||||
# * License along with this program; if not, write to the Free Software *
|
||||
# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
|
||||
# * USA *
|
||||
# * *
|
||||
# ***************************************************************************
|
||||
|
||||
import FreeCAD
|
||||
import os
|
||||
import glob
|
||||
|
||||
class PathPreferences:
|
||||
PostProcessorDefault = "PostProcessorDefault"
|
||||
PostProcessorDefaultArgs = "PostProcessorDefaultArgs"
|
||||
PostProcessorBlacklist = "PostProcessorBlacklist"
|
||||
|
||||
@classmethod
|
||||
def allAvailablePostProcessors(cls):
|
||||
path = FreeCAD.getHomePath() + ("Mod/Path/PathScripts/")
|
||||
posts = glob.glob(path + '/*_post.py')
|
||||
allposts = [ str(os.path.split(os.path.splitext(p)[0])[1][:-5]) for p in posts]
|
||||
|
||||
grp = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Macro")
|
||||
path = grp.GetString("MacroPath", FreeCAD.getUserAppDataDir())
|
||||
posts = glob.glob(path + '/*_post.py')
|
||||
|
||||
allposts.extend([ str(os.path.split(os.path.splitext(p)[0])[1][:-5]) for p in posts])
|
||||
allposts.sort()
|
||||
return allposts
|
||||
|
||||
@classmethod
|
||||
def allEnabledPostProcessors(cls, include = None):
|
||||
blacklist = cls.postProcessorBlacklist()
|
||||
enabled = [processor for processor in cls.allAvailablePostProcessors() if not processor in blacklist]
|
||||
if include:
|
||||
include.extend(enabled)
|
||||
return include
|
||||
return enabled
|
||||
|
||||
|
||||
@classmethod
|
||||
def defaultPostProcessor(cls):
|
||||
preferences = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Path")
|
||||
return preferences.GetString(cls.PostProcessorDefault, "")
|
||||
|
||||
@classmethod
|
||||
def defaultPostProcessorArgs(cls):
|
||||
preferences = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Path")
|
||||
return preferences.GetString(cls.PostProcessorDefaultArgs, "")
|
||||
|
||||
@classmethod
|
||||
def postProcessorBlacklist(cls):
|
||||
preferences = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Path")
|
||||
blacklist = preferences.GetString(cls.PostProcessorBlacklist, "")
|
||||
if not blacklist:
|
||||
return []
|
||||
return eval(blacklist)
|
||||
|
||||
@classmethod
|
||||
def savePostProcessorDefaults(cls, processor, args, blacklist):
|
||||
preferences = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Path")
|
||||
preferences.SetString(cls.PostProcessorDefault, processor)
|
||||
preferences.SetString(cls.PostProcessorDefaultArgs, args)
|
||||
preferences.SetString(cls.PostProcessorBlacklist, "%s" % (blacklist))
|
||||
|
||||
|
||||
DefaultOutputFile = "DefaultOutputFile"
|
||||
DefaultOutputPolicy = "DefaultOutputPolicy"
|
||||
|
||||
@classmethod
|
||||
def saveOutputFileDefaults(cls, file, policy):
|
||||
preferences = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Path")
|
||||
preferences.SetString(cls.DefaultOutputFile, file)
|
||||
preferences.SetString(cls.DefaultOutputPolicy, policy)
|
||||
|
||||
@classmethod
|
||||
def defaultOutputFile(cls):
|
||||
preferences = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Path")
|
||||
return preferences.GetString(cls.DefaultOutputFile, "")
|
||||
|
||||
@classmethod
|
||||
def defaultOutputPolicy(cls):
|
||||
preferences = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Path")
|
||||
return preferences.GetString(cls.DefaultOutputPolicy, "")
|
|
@ -25,8 +25,8 @@
|
|||
import FreeCAD
|
||||
import FreeCADGui
|
||||
from PySide import QtCore, QtGui
|
||||
from PathScripts.PathPreferences import PathPreferences
|
||||
from PathScripts.PathPostProcessor import PostProcessor
|
||||
from PathScripts.PathPost import CommandPathPost as PathPost
|
||||
|
||||
|
||||
class Page:
|
||||
|
@ -45,11 +45,11 @@ class Page:
|
|||
item = self.form.postProcessorList.item(i)
|
||||
if item.checkState() == QtCore.Qt.CheckState.Unchecked:
|
||||
blacklist.append(item.text())
|
||||
PostProcessor.saveDefaults(processor, args, blacklist)
|
||||
PathPreferences.savePostProcessorDefaults(processor, args, blacklist)
|
||||
|
||||
path = str(self.form.leOutputFile.text())
|
||||
policy = str(self.form.cboOutputPolicy.currentText())
|
||||
PathPost.saveDefaults(path, policy)
|
||||
PathPreferences.saveOutputFileDefaults(path, policy)
|
||||
|
||||
def selectComboEntry(self, widget, text):
|
||||
index = widget.findText(text, QtCore.Qt.MatchFixedString)
|
||||
|
@ -60,8 +60,8 @@ class Page:
|
|||
|
||||
def loadSettings(self):
|
||||
self.form.defaultPostProcessor.addItem("")
|
||||
blacklist = PostProcessor.blacklist()
|
||||
for processor in PostProcessor.all():
|
||||
blacklist = PathPreferences.postProcessorBlacklist()
|
||||
for processor in PathPreferences.allAvailablePostProcessors():
|
||||
self.form.defaultPostProcessor.addItem(processor)
|
||||
item = QtGui.QListWidgetItem(processor)
|
||||
if processor in blacklist:
|
||||
|
@ -70,15 +70,15 @@ class Page:
|
|||
item.setCheckState(QtCore.Qt.CheckState.Checked)
|
||||
item.setFlags( QtCore.Qt.ItemFlag.ItemIsSelectable | QtCore.Qt.ItemFlag.ItemIsEnabled | QtCore.Qt.ItemFlag.ItemIsUserCheckable)
|
||||
self.form.postProcessorList.addItem(item)
|
||||
self.selectComboEntry(self.form.defaultPostProcessor, PostProcessor.default())
|
||||
self.selectComboEntry(self.form.defaultPostProcessor, PathPreferences.defaultPostProcessor())
|
||||
|
||||
self.form.defaultPostProcessorArgs.setText(PostProcessor.defaultArgs())
|
||||
self.form.leOutputFile.setText(PathPost.defaultOutputFile())
|
||||
self.selectComboEntry(self.form.cboOutputPolicy, PathPost.defaultOutputPolicy())
|
||||
self.form.defaultPostProcessorArgs.setText(PathPreferences.defaultPostProcessorArgs())
|
||||
self.form.leOutputFile.setText(PathPreferences.defaultOutputFile())
|
||||
self.selectComboEntry(self.form.cboOutputPolicy, PathPreferences.defaultOutputPolicy())
|
||||
|
||||
self.form.postProcessorList.itemEntered.connect(self.setProcessorListTooltip)
|
||||
self.form.defaultPostProcessor.currentIndexChanged.connect(self.updateDefaultPostProcessorToolTip)
|
||||
self.form.browseFileSystem.clicked.connect(self.browseFileSystem)
|
||||
self.form.pbBrowseFileSystem.clicked.connect(self.browseFileSystem)
|
||||
|
||||
def getPostProcessor(self, name):
|
||||
if not name in self.processor.keys():
|
||||
|
@ -111,6 +111,6 @@ class Page:
|
|||
self.form.defaultPostProcessorArgs.setToolTip(self.postProcessorArgsDefaultTooltip)
|
||||
|
||||
def browseFileSystem(self):
|
||||
foo = QtGui.QFileDialog.getExistingDirectory(QtGui.qApp.activeWindow(), "Path - Output File/Directory", self.form.defaultOutputPath.text())
|
||||
foo = QtGui.QFileDialog.getExistingDirectory(QtGui.qApp.activeWindow(), "Path - Output File/Directory", self.form.leOutputFile.text())
|
||||
if foo:
|
||||
self.form.defaultOutputPath.setText(foo)
|
||||
self.form.leOutputFile.setText(foo)
|
||||
|
|
Loading…
Reference in New Issue
Block a user