chiark / gitweb /
d81f4aa1fa4d484e507167145ceb1c18195654cf
[cura.git] / Cura / newui / sliceRun.py
1 from __future__ import absolute_import
2
3 import platform, os, subprocess, sys
4
5 from skeinforge_application.skeinforge_utilities import skeinforge_craft
6 from newui import profile
7
8 def getPyPyExe():
9         "Return the path to the pypy executable if we can find it. Else return False"
10         if platform.system() == "Windows":
11                 exeName = "pypy.exe"
12                 pypyExe = os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), "../../pypy/pypy.exe"));
13         else:
14                 exeName = "pypy"
15                 pypyExe = os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), "../../pypy/bin/pypy"));
16         if os.path.exists(pypyExe):
17                 return pypyExe
18
19         path = os.environ['PATH']
20         paths = path.split(os.pathsep)
21         for p in paths:
22                 pypyExe = os.path.join(p, exeName)
23                 if os.path.exists(pypyExe):
24                         return pypyExe 
25         return False
26
27 def getSlic3rExe():
28         "Return the path to the pypy executable if we can find it. Else return False"
29         if platform.system() == "Windows":
30                 exeName = "slic3r.exe"
31                 slic3rExe = os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), "../../Slic3r/bin/slic3r.exe"));
32         else:
33                 exeName = "slic3r"
34                 slic3rExe = os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), "../../Slic3r/bin/slic3r"));
35         if os.path.exists(slic3rExe):
36                 return slic3rExe
37
38         path = os.environ['PATH']
39         paths = path.split(os.pathsep)
40         for p in paths:
41                 slic3rExe = os.path.join(p, exeName)
42                 if os.path.exists(slic3rExe):
43                         return slic3rExe
44         return False
45
46 def runSlice(fileNames):
47         "Run the slicer on the files. If we are running with PyPy then just do the slicing action. If we are running as Python, try to find pypy."
48         pypyExe = getPyPyExe()
49         for fileName in fileNames:
50                 if platform.python_implementation() == "PyPy":
51                         skeinforge_craft.writeOutput(fileName)
52                 elif pypyExe == False:
53                         print "************************************************"
54                         print "* Failed to find pypy, so slicing with python! *"
55                         print "************************************************"
56                         skeinforge_craft.writeOutput(fileName)
57                         print "************************************************"
58                         print "* Failed to find pypy, so sliced with python!  *"
59                         print "************************************************"
60                 else:
61                         subprocess.call([pypyExe, os.path.join(sys.path[0], sys.argv[0]), fileName])
62
63 def getSliceCommand(filename):
64         if profile.getPreference('slicer').startswith('Slic3r'):
65                 slic3rExe = getSlic3rExe()
66                 if slic3rExe == False:
67                         return False
68                 cmd = [slic3rExe,
69                         '--output-filename-format', '[input_filename_base]_export.gcode',
70                         '--nozzle-diameter', str(profile.calculateEdgeWidth()),
71                         '--print-center', '%s,%s' % (profile.getProfileSetting('machine_center_x'), profile.getProfileSetting('machine_center_y')),
72                         '--z-offset', '0',
73                         '--gcode-flavor', 'reprap',
74                         '--gcode-comments',
75                         '--filament-diameter', profile.getProfileSetting('filament_diameter'),
76                         '--extrusion-multiplier', str(1.0 / float(profile.getProfileSetting('filament_density'))),
77                         '--temperature', profile.getProfileSetting('print_temperature'),
78                         '--travel-speed', profile.getProfileSetting('travel_speed'),
79                         '--perimeter-speed', profile.getProfileSetting('print_speed'),
80                         '--small-perimeter-speed', profile.getProfileSetting('print_speed'),
81                         '--infill-speed', profile.getProfileSetting('print_speed'),
82                         '--solid-infill-speed', profile.getProfileSetting('print_speed'),
83                         '--bridge-speed', profile.getProfileSetting('print_speed'),
84                         '--bottom-layer-speed-ratio', str(float(profile.getProfileSetting('bottom_layer_speed')) / float(profile.getProfileSetting('print_speed'))),
85                         '--layer-height', profile.getProfileSetting('layer_height'),
86                         '--first-layer-height-ratio', '1.0',
87                         '--infill-every-layers', '1',
88                         '--perimeters', str(profile.calculateLineCount()),
89                         '--solid-layers', str(profile.calculateSolidLayerCount()),
90                         '--fill-density', str(float(profile.getProfileSetting('fill_density'))/100),
91                         '--fill-angle', '45',
92                         '--fill-pattern', 'rectilinear',
93                         '--solid-fill-pattern', 'rectilinear',
94                         '--start-gcode', profile.getAlterationFilePath('start.gcode'),
95                         '--end-gcode', profile.getAlterationFilePath('end.gcode'),
96                         '--retract-length', profile.getProfileSetting('retraction_amount'),
97                         '--retract-speed', str(int(float(profile.getProfileSetting('retraction_speed')))),
98                         '--retract-restart-extra', profile.getProfileSetting('retraction_extra'),
99                         '--retract-before-travel', profile.getProfileSetting('retraction_min_travel'),
100                         '--retract-lift', '0',
101                         '--slowdown-below-layer-time', profile.getProfileSetting('cool_min_layer_time'),
102                         '--min-print-speed', profile.getProfileSetting('cool_min_feedrate'),
103                         '--skirts', profile.getProfileSetting('skirt_line_count'),
104                         '--skirt-distance', str(int(float(profile.getProfileSetting('skirt_gap')))),
105                         '--skirt-height', '1',
106                         '--scale', profile.getProfileSetting('model_scale'),
107                         '--rotate', profile.getProfileSetting('model_rotate_base'),
108                         '--duplicate-x', profile.getProfileSetting('model_multiply_x'),
109                         '--duplicate-y', profile.getProfileSetting('model_multiply_y'),
110                         '--duplicate-distance', '10']
111                 if profile.getProfileSetting('support') != 'None':
112                         cmd.extend(['--support-material'])
113                 cmd.extend([filename])
114                 return cmd
115         else:
116                 pypyExe = getPyPyExe()
117                 if pypyExe == False:
118                         pypyExe = sys.executable
119                 return [pypyExe, os.path.join(sys.path[0], os.path.split(sys.argv[0])[1]), filename]
120