Refactored post processor into its own class, concentrating all post processor script operations.
This commit is contained in:
128
src/Mod/Path/PathScripts/PathPostProcessor.py
Normal file
128
src/Mod/Path/PathScripts/PathPostProcessor.py
Normal file
@@ -0,0 +1,128 @@
|
||||
# -*- 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 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))
|
||||
|
||||
@classmethod
|
||||
def load(cls, processor):
|
||||
postname = processor + "_post"
|
||||
|
||||
exec "import %s as current_post" % postname
|
||||
# make sure the script is reloaded if it was previously loaded
|
||||
# should the script have been imported for the first time above
|
||||
# then the initialization code of the script gets executed twice
|
||||
# resulting in 2 load messages if the script outputs one of those.
|
||||
exec "reload(%s)" % 'current_post'
|
||||
|
||||
instance = PostProcessor(current_post)
|
||||
instance.units = None
|
||||
if hasattr(current_post, "UNITS"):
|
||||
if current_post.UNITS == "G21":
|
||||
instance.units = "Metric"
|
||||
else:
|
||||
instance.units = "Inch"
|
||||
|
||||
instance.machineName = None
|
||||
if hasattr(current_post, "MACHINE_NAME"):
|
||||
instance.machineName = current_post.MACHINE_NAME
|
||||
|
||||
instance.cornerMax = None
|
||||
if hasattr(current_post, "CORNER_MAX"):
|
||||
instance.cornerMax = {'x': current_post.CORNER_MAX['x'],
|
||||
'y': current_post.CORNER_MAX['y'],
|
||||
'z': current_post.CORNER_MAX['z']}
|
||||
|
||||
instance.cornerMin = None
|
||||
if hasattr(current_post, "CORNER_MIN"):
|
||||
instance.cornerMin = {'x': current_post.CORNER_MIN['x'],
|
||||
'y': current_post.CORNER_MIN['y'],
|
||||
'z': current_post.CORNER_MIN['z']}
|
||||
|
||||
instance.tooltip = None
|
||||
instance.tooltipArgs = None
|
||||
if hasattr(current_post, "TOOLTIP"):
|
||||
instance.tooltip = current_post.TOOLTIP
|
||||
if hasattr(current_post, "TOOLTIP_ARGS"):
|
||||
instance.tooltipArgs = current_post.TOOLTIP_ARGS
|
||||
return instance
|
||||
|
||||
def __init__(self, script):
|
||||
self.script = script
|
||||
|
||||
def export(self, obj, filename, args):
|
||||
self.script.export(obj, filename, args)
|
||||
Reference in New Issue
Block a user