Last active
April 4, 2019 17:42
-
-
Save lava/84a58f84f811fbdab063d7cb5ea5148b to your computer and use it in GitHub Desktop.
Postprocessing script to make FreeCAD paths importible by Easel (WIP)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # *************************************************************************** | |
| # * (c) Benno Evers (bennoe@apache.org) 2019 * | |
| # * * | |
| # * This file is part of the FreeCAD CAx development system. * | |
| # * * | |
| # * 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. * | |
| # * * | |
| # * FreeCAD 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 Lesser General Public License for more details. * | |
| # * * | |
| # * You should have received a copy of the GNU Library General Public * | |
| # * License along with FreeCAD; if not, write to the Free Software * | |
| # * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * | |
| # * USA * | |
| # * * | |
| # ***************************************************************************/ | |
| from __future__ import print_function | |
| TOOLTIP=''' | |
| This is a post-processor for the Easel WebUI which can control various | |
| models of CNC mills, i.e. Carvey, X-Carve and ShapeOko 1/2. | |
| Note that it has only been tested with the Carvey. | |
| Its main task is to linearize any arcs, since Easel only | |
| supports linear movements. | |
| ''' | |
| import datetime | |
| # TODO(bevers): Stuff below was in the original example code, but I don't | |
| # see why it is needed. | |
| # | |
| # to distinguish python built-in open function from the one declared below | |
| #if open.__module__ in ['__builtin__','io']: | |
| # pythonopen = open | |
| def export(objectslist, filename, argstring): | |
| "Called when freecad exports a list of objects" | |
| # TODO(bevers): Support multiple paths by concatenating them together. | |
| if len(objectslist) > 1: | |
| print("This script is unable to write more than one Path object") | |
| return | |
| obj = objectslist[0] | |
| if not hasattr(obj, "Path"): | |
| print("the given object is not a path") | |
| # The `Path.toGCode()` function returns a string formatted in the FreeCAD | |
| # internal GCode dialect | |
| #freecad_gcode = obj.Path.toGCode() | |
| easel_gcode = postprocess(obj.Path.Commands) | |
| dia = PostUtils.GCodeEditorDialog() | |
| dia.editor.setText(easel_gcode) | |
| result = dia.exec_() | |
| #gfile = open(filename, "w") | |
| #gfile.write(easel_gcode) | |
| #gfile.close() | |
| return result | |
| # `gcode`: [string] | |
| def postprocess(commands): | |
| output = "" | |
| for cmd in commands: | |
| output += str(print(cmd.Name)) + "\n" | |
| output += str(dir(cmd)) + "\n" | |
| return output | |
| print(__name__ + " gcode postprocessor loaded.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment