FreeCAD/src/Mod/Path/PathScripts/example_pre.py
Yorik van Havre 3f4e55a474 Initial merge of Path module branch
authors: Yorik van Havre, Dan Falck, Brad Collette, Frederik Johansson, Dmitry Platonov,

eb4fd6c Path: moved colors preferences page to Path group
f4e5d70 a little more work on auto tool change
99a6e2f tied tool numbers in ops to last loaded tool
2d6fcda no need to select object for tooltable edit
b53eb15 Path: Fixed path bug #10 - Tooltableeditor
d6e996f Path: Fixed path bug #36 - Finish editing
16fe598 Path: Fixed path bug #37: labels in compound dialog
22dc594 Bugfix in pocket, was producing strange arcs due to a rounding error Path doesnt render values such as:-4.4408920985e-16 produced by python
9aae1d5 Make Gcode editor restore its size and position from last opened
b44e1d6 Move addToProject to PathUtils
71b727a Make all tools show its correct icon in the tree
86b32e0 Further simplify the code and fix issue in PathHop
e63b6b7 Simplify code and make automatic project creation more consistent across tools
261bfa3 Add ability to have external orocos-kdl library instead of the suplied in FreeCAD, used in Robot and Path workbenches
95efa27 Drilling-rapid to first location before moving Z
73537d6 I forgot to parse the SubObjects of the selection
044c23d improvements to drilling selection and properties
347fe62 small improvement to PathKurveUtils sorting
95ffe39 formatting
1003968 split full circles
27b19c2 added basic feedrate to PathKurveUtils
372ef57 Path: removed Path_rc and DemoParts from Cmake
98705ad using toBiarcs for paths based on splines
32663e5 slight startpt/endpt simplification
fd8f258 parametric start and end pts to PathKurve
b5e4761 still working on pathkurvetutils and points
01bf423 worked out clockwise profile paths
2825191 fixed typo
5a87872 still working on start and stop points for kurve
7fe77bc allowing points for start and stop of path
cb57d1b making ptlist consistant
3f2bf6c improvements to PathKurve
e3765a0 added libarea for pofile op-still much work to do
c882df2 small fix for adding arcs to edgelist
2cbac06 forgot Path_rc.py
45bf437 applied fix for windows icons not showing
61dbe07 PathUtils code cleanup
9d49cb8 Fix SortPath if no offset is specified
332eca0 split SortEdges and MakePath in prep for using kurve_funcs from HeeksCNC
799f1f1 tweaking visualization a bit
ba8eee6 small change back to way project holds toolpath for visualization
5ca4984 applied Werner's kdl patch
14c93be added units to tlo,revised centroid post
3c6341d Path: fixed spaces missing in file reading
10c20f9 removed editor button from project and post work
68ff118 removed stock command added small function to find last z value
0b71f92 tidying up profile a bit
fe8b4e9 moved the findtool function to PathUtils
4441695 Path: Exposed Command.transform() to python
09ed1d1 Path: Added a default empty preferences page
6ff0689 forgot to add the PathFromShape.py file
d6e3c4a added simple python proxy for PathShape So that it can be inserted into the Project tree automatically. Later, we can connect the base object to the shape so that it changes if the base shape is changed.
f5ca514 clean up of PathCopy.py
8336b96 moved Path from Shape to New Operation menu
7e73998 made PathCopy a child of the Project/Compound
7674b37 missed a modified file for unit handling
9aa1327 small change to account for pathcopy being InList
c35a109 PathPost doesn't barf now if the user rearranged the project.
09c4a1f working on Machine properties again
4bc32a4 more view property fixes
a453ad2 set defaults from post
3b051cb more property changes
ef5a015 reorganized properties.  Used PropertyLength/Distance in Drilling
311a059 made it so that the viewprovider settings would stick
e427303 fixed post function
3e528dc removed post processor file property from PathProject and added it to PathMachine
58a5339 added Machine object to hold post processor file name and tooltable information. Moved the cornermin,cornermax bounding box of machine to it. Haven't connected post processor file output from it yet, will do that next. Disconnected path output from Project object. It is really just a Group now that holds all the other path objects. Posts will now have to parse the objects inside it to get gcode. I think we are already doing that with the linuxcnc post and I plan on doing that with future posts. Removed a lot of view properties from lots of objects that don't need them. Use mode=2 and vobj.setEditorMode('LineWidth',mode) as an example of that. Removed placement property for things like PathComment because it doesn't make sense to try to alter placement of nongeometric things.
dd8b831 adding properties for using units
f84a2cc Multiple selection of points and circles for drilling.
f3d645a added viewprovider for drill icon in object tree
f564462 changed R plane behaviour for G81 drill cycle
85a056d added a few more drill/tap/bore cycles,changed z to R plane between drill cycles
9312ef9 Path: Added 3D representation of G81, G82 and G83 drill ops
0ed19d5 A stab at pathpocket with some reasonable properties and stepping down.
da9d6b5 forgot a quote mark
1c49c8d changed icon for optional stop
b7eb50e First bit of work on drilling.
4b3bc52 moved where comments and optional stops are located
3e9fbd7 added optional and mandatory stop commands
9e94269 added comment object
c3e44f5 removed a few properties
7cf86d7 automatic populating of tool numbers based on active ToolNumber
b607843 added tool length offset and load tool commands, made PathCompound accept objects that PathProject removed
8a93d54 reworked linuxcnc_post to use commands natively and not toGCode()
85f2cfd PathPost command now handles more cases including generic. Adds a simple dumper post to get raw commands.
aa827fa added G43 tool length offset
b1bf6d3 added new post, modded Profile for comments, fixed ZClearance in Profile
2fd5f2c added post process command and button
3cf6107 forgot about adding a file to cmake again
77f8a7f added new post, rearranged icons,modified PathProject
7e6adf3 added active property to PathPocket
d6b479a fixed stock, added active/inactive to a few ops
9a96b72 added pathplane and made fixture and pathprofile automatically populate or even create a project
d214281 forgot to add the actual script needed for stock
1adf36a added PathStock for material visualization
2ef30ea fixed bug in fixtures and changed icon
7b3e9dd made fixtures go inside a Path Project
6143c9a fixed JSON encoding error
c46cb2b added simple script to use the ToolTableEditor`
fc70a4d Turned Compound & Project into python objects
a1b9127 trying to fix segfualt
1bbf53e repaired fixture offsets
739e387 missing import. revised for new structure.  Creates multiple paths again.
38f2d25 added missing import
1837645 adding parameters to PathCompound
208bfdb Path: New pre/post interface
a252be1 rearranged and added some parameters to PathProject and PathCompound
9fa6278 Path: Added safe height property to project
de6812e made the icon a bit thicker
25beab0 merging Path-Copy with Path-Fixture
5cfffdc added icon for fixture offsets
af18281 Path: Added Path Copy object
89865ef pre support tool change and spindle speed (partially)
e9960f7 changes to opensbp post only.
421c12b Path: Fixed bug in paths with no move
272a11d added linuxcnc_post.py back to cmake
715c72b removed unused files
4ea4e18 added fixture offset script, removed unneeded scripts
855a3e0 fix for toolchange to get Tnumber to show
64f497c Path: Fixed unresponsive import/export dialogs
51c7a9e revert example post to simple form
5e25f3a Renamed pre_ and post_ scripts to _pre and _post
9837f3f first pass cleanup
9a42cee Path: Fixed scripts search path
3467a73 Path: search for pre & post scripts in user dir too - fixes #12
b46e527 Path: fixed precision bug - closes #25
c65fc05 added another post from sliptonic
718f499 Path: Enabled comments in Paths
ea0952f Path: Added preference color for machine extents
7578467 Path: Implemented machine properties  - issue yorikvanhavre/FreeCAD#8
1ae3a7d minor change to comment location
49f742d added Spindle Speed to profile
2a4374c added a second post processor example
5278d46 worked on sorting, reversing, sorting, and more sorting
7bc81bf separating selection function from PathUtils
64dd77c Path: small fix in absolute/relative coords
f435303 face selection works again
fa7074f rolled back and took another try at discretizing curves
ae1ff5b changed discretizing slightly
8e47d16 added discretizing of bezier curves to toolpaths
e85e087 fix for open wires/profiles worked on sorting again
a9a8a29 worked out arc segments over 180 degrees but not full circles yet
073a4a0 refactoring where sorting takes place
6723052 one more time on the sorting
050221c arc direction and path order-still problems but better
d7a79b1 I think I worked out backwards arc problem
a721aae corrected final depth on profile
4f07f01 I forgot to add the file for the previous commit
8eac175 combined ConvGcode and PathSelection into PathUtils
488a593 added some profile utility functions
4c4e0b2 worked on arc moves and reordering
cf04c3a Path: Added Hop tool and added arcs handlingin PathShape
417e9c7 Path: removed Tool number from dressup
4cedb9d Path: Fixed dressup
1b7e79f Path: Added UsePlacements property to compounds
8241513 Path: Added Dressup + fixed cmake + enabled python view provider
9721037 Path: Update bounding boxes when drawing path
9d8192e Path: Split compound into compound and project objects
250cdc7 Path: Added Drilling tool
8939e03 Path: Added translation file
466fe54 Path: Added an initial rapid move to FeatureShapes
7dfab6f Path: Added pocket tool
795f3c0 Path: added a ShowFirstRapid property to the path viewprovider
21e1272 Path: show number of tools in compound's task dialog
8dde2c5 Path: Added Profile tool
32b3fc1 Path: Added GUI import/export
fa1db60 Path: allow to import heeks tooltables and removed c++ workbench
e8c5a3a Path: Fixed tooltable editor
29fd0e4 Path: Allow pre scripts to return a list to create a compound
1eec4bd Path: Tooltable editor (BUGGY)
3ee661d Path: updated Path module dependencies in cmake
7137e04 Path: Added UI to reorder children of a path compound feature
3fb7073 Path: Added Path::FeatureShape feature
f496615 Path: added post editor
069b070 Path: Added structure for post scripts
bd0e669 Path: Added Path.insert() function
fcf1f18 Path: small bugfixes
09124e3 Path: Added spaces in (pseudo) Gcode output
efcb755 Path: Added pre script example
7a6a267 adding macro to find outer profile
274ff82 added a few macros
521d095 Path: Added FeatureCompound object
06eee1a adding python scripts and part files
42119ab added LGPL license
e8f0742 added demo parts and python experiments
c849734 Path: added tooltable property & Path.show() function
1886b4a Path: Added Path::FeaturePython object
b48b9d8 Path: correct placement behaviour and support for G90 and G91
00fe8a6 Path: Added support for G00
896c359 Path: Enabled different color for rapid moves
885a8d9 Path: small fix
a8d310b Path: improvements to the view provider
9fd88c5 Path: now removes comments when creating paths from gcode
dc0a0f1 Path: Fixed Z coordinate
ba6abc8 Path: Fixed color properties
8605629 Path: remember Z coord of last point if not specified
0d66fa9 Path: Misc upgrades to the view provider
f77c399 Path: Now supposes absolute positions instead of relative
a23b4e8 Path: Tooltable now behaves as a dicionary
eef5669 Path: simplified file saving/restoring
f15262f Path: enabled reading & writing of Path features
0a735ee More uniform caps system for enums, and added more materials
ad3f88e added a few more tools
ef62185 added more tools
f489758 removed whitespaces
5f906c6 added a few more tool definitions
84608dc minor changes to names
3ca1b5c Path: added Tool and Tooltable objects
d852a0b Path: extended path py object, enable coin representation in view provider
f7980b3 Path: extended the command object
a6205c4 Added Path Feature
dae6499 Path: Added Path object
693c0df Temporarily removed Gui from cmake
c2519e7 Path module: First commit
b3860d5 made a little progress- added ConvGcode to split and reverse paths
5761235 removed wire.reverse()- I couldn't get the hang of it
54a5482 added selection script along with parameters for profile
cecc1df Path: removed Tool number from dressup
7ca8e79 Path: Fixed dressup
d7d1a9b Path: Added UsePlacements property to compounds
a001d7c Path: Added Dressup + fixed cmake + enabled python view provider
5ff31b3 Path: Update bounding boxes when drawing path
946f26c Path: Split compound into compound and project objects
4c9fedd Path: Added Drilling tool
e88d431 Path: Added translation file
a989530 Path: Added an initial rapid move to FeatureShapes
8faab1e Path: Added pocket tool
e2dd1a4 Path: added a ShowFirstRapid property to the path viewprovider
5daa4ed Path: show number of tools in compound's task dialog
18bd973 Path: Added Profile tool
f613104 Path: Added GUI import/export
7e7bc79 Path: allow to import heeks tooltables and removed c++ workbench
a60325f Path: Fixed tooltable editor
802b413 Path: Allow pre scripts to return a list to create a compound
35fb2a1 Path: Tooltable editor (BUGGY)
3040bc1 Path: updated Path module dependencies in cmake
680d9a8 Path: Added UI to reorder children of a path compound feature
8ed321c Path: Added Path::FeatureShape feature
f81ccdd Path: added post editor
34d2cef Path: Added structure for post scripts
2ea3060 Path: Added Path.insert() function
e8561f4 Path: small bugfixes
ef6fe49 Path: Added spaces in (pseudo) Gcode output
909a944 Path: Added pre script example
58abd71 adding macro to find outer profile
a7415c5 added a few macros
51cd15b Path: Added FeatureCompound object
be6c10a adding python scripts and part files
30bde91 added LGPL license
93babeb added demo parts and python experiments
f69c9a9 Path: added tooltable property & Path.show() function
5796bea Path: Added Path::FeaturePython object
e6052bd Path: correct placement behaviour and support for G90 and G91
9f3977c Path: Added support for G00
1b95678 Path: Enabled different color for rapid moves
90bdc2c Path: small fix
6394ceb Path: improvements to the view provider
aa93f1e Path: now removes comments when creating paths from gcode
35a479b Path: Fixed Z coordinate
1947315 Path: Fixed color properties
987d8e3 Path: remember Z coord of last point if not specified
64da26c Path: Misc upgrades to the view provider
283df2b Path: Now supposes absolute positions instead of relative
b59a46d Path: Tooltable now behaves as a dicionary
b4c2edb Path: simplified file saving/restoring
8b36988 Path: enabled reading & writing of Path features
308bb20 More uniform caps system for enums, and added more materials
f9f129c added a few more tools
eb83a31 added more tools
bb40643 removed whitespaces
13cd406 added a few more tool definitions
6357082 minor changes to names
6a14580 Path: added Tool and Tooltable objects
bc14864 Path: extended path py object, enable coin representation in view provider
a8a19a0 Path: extended the command object
0174d04 Added Path Feature
a829a6c Path: Added Path object
ba7ca94 Temporarily removed Gui from cmake
3c9d77a Path module: First commit
2015-07-04 18:30:10 -03:00

102 lines
3.7 KiB
Python

#***************************************************************************
#* (c) Yorik van Havre (yorik@uncreated.net) 2014 *
#* *
#* 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 *
#* *
#***************************************************************************/
'''
This is an example preprocessor file for the Path workbench. Its aim is to
open a gcode file, parse its contents, and create the appropriate objects
in FreeCAD.
Read the Path Workbench documentation to know how to create Path objects
from GCode.
'''
import os, Path
import FreeCAD
# to distinguish python built-in open function from the one declared below
if open.__module__ == '__builtin__':
pythonopen = open
def open(filename):
"called when freecad opens a file."
docname = os.path.splitext(os.path.basename(filename))[0]
doc = FreeCAD.newDocument(docname)
insert(filename,doc.Name)
def insert(filename,docname):
"called when freecad imports a file"
gfile = pythonopen(filename)
gcode = gfile.read()
gfile.close()
gcode = parse(gcode)
doc = FreeCAD.getDocument(docname)
obj = doc.addObject("Path::Feature","Path")
path = Path.Path(gcode)
obj.Path = path
def parse(inputstring):
"parse(inputstring): returns a parsed output string"
print "preprocessing..."
# split the input by line
lines = inputstring.split("\n")
output = ""
lastcommand = None
for l in lines:
# remove any leftover trailing and preceding spaces
l = l.strip()
if not l:
# discard empty lines
continue
if l[0].upper() in ["N"]:
# remove line numbers
l = l.split(" ",1)[1]
if l[0] in ["(","%","#"]:
# discard comment and other non strictly gcode lines
continue
if l[0].upper() in ["G","M"]:
# found a G or M command: we store it
output += l + "\n"
last = l[0].upper()
for c in l[1:]:
if not c.isdigit():
break
else:
last += c
lastcommand = last
elif lastcommand:
# no G or M command: we repeat the last one
output += lastcommand + " " + l + "\n"
print "done preprocessing."
return output
print __name__ + " gcode preprocessor loaded."