chiark / gitweb /
Merge branch 'SteamEngine' of github.com:daid/Cura into SteamEngine
[cura.git] / Cura / cura.py
1 #!/usr/bin/python
2 """
3 This page is in the table of contents.
4 ==Overview==
5 ===Introduction===
6 Cura is a AGPL tool chain to generate a GCode path for 3D printing. Older versions of Cura where based on Skeinforge.
7 Versions up from 13.05 are based on a C++ engine called CuraEngine.
8 """
9 __copyright__ = "Copyright (C) 2013 David Braam - Released under terms of the AGPLv3 License"
10
11 from optparse import OptionParser
12
13 from Cura.util import profile
14
15 def main():
16         parser = OptionParser(usage="usage: %prog [options] <filename>.stl")
17         parser.add_option("-i", "--ini", action="store", type="string", dest="profileini",
18                 help="Load settings from a profile ini file")
19         parser.add_option("-r", "--print", action="store", type="string", dest="printfile",
20                 help="Open the printing interface, instead of the normal cura interface.")
21         parser.add_option("-p", "--profile", action="store", type="string", dest="profile",
22                 help="Internal option, do not use!")
23         parser.add_option("-s", "--slice", action="store_true", dest="slice",
24                 help="Slice the given files instead of opening them in Cura")
25         parser.add_option("-o", "--output", action="store", type="string", dest="output",
26                 help="path to write sliced file to")
27
28         (options, args) = parser.parse_args()
29
30         print "load preferences from " + profile.getPreferencePath()
31         profile.loadPreferences(profile.getPreferencePath())
32
33         if options.profile is not None:
34                 profile.setProfileFromString(options.profile)
35         elif options.profileini is not None:
36                 profile.loadProfile(options.profileini)
37         else:
38                 profile.loadProfile(profile.getDefaultProfilePath())
39
40         if options.printfile is not None:
41                 from Cura.gui import printWindow
42                 printWindow.startPrintInterface(options.printfile)
43         elif options.slice is not None:
44                 from Cura.util import sliceEngine
45                 from Cura.util import objectScene
46                 from Cura.util import meshLoader
47                 import shutil
48
49                 def commandlineProgressCallback(progress, ready):
50                         if progress >= 0 and not ready:
51                                 print 'Preparing: %d%%' % (progress * 100)
52                 scene = objectScene.Scene()
53                 scene.updateMachineDimensions()
54                 slicer = sliceEngine.Slicer(commandlineProgressCallback)
55                 for m in meshLoader.loadMeshes(args[0]):
56                         scene.add(m)
57                 slicer.runSlicer(scene)
58                 slicer.wait()
59                 profile.replaceGCodeTagsFromSlicer(slicer.getGCodeFilename(), slicer)
60
61                 if options.output:
62                         shutil.copyfile(slicer.getGCodeFilename(), options.output)
63                         print 'GCode file saved : %s' % options.output
64                 else:
65                         shutil.copyfile(slicer.getGCodeFilename(), args[0] + '.gcode')
66                         print 'GCode file saved as: %s' % (args[0] + '.gcode')
67
68                 slicer.cleanup()
69         else:
70                 from Cura.gui import app
71                 app.CuraApp(args).MainLoop()
72
73 if __name__ == '__main__':
74         main()