1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
$Id$
Copyright 2010 Lars Kruse <devel@sumpfralle.de>
Copyright 2008-2009 Lode Leroy
This file is part of PyCAM.
PyCAM is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
PyCAM 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with PyCAM. If not, see <http://www.gnu.org/licenses/>.
"""
from pycam.Physics.ode_physics import override_ode_availability
import pycam.Gui.common as GuiCommon
from optparse import OptionParser
import sys
import os
# check if we were started as a separate program
if __name__ == "__main__":
inputfile = None
outputfile = None
parser = OptionParser(usage="usage: %prog [options] [inputfile [outputfile]]")
parser.add_option("", "--gui", dest="display",
action="store_true", default=False,
help="don't create the outputfile on the fly - just preset the output filename and show the GUI")
parser.add_option("", "--gtk", dest="gtk_gui",
action="store_true", default=True,
help="use the new GTK interface (default)")
parser.add_option("", "--tk", dest="gtk_gui",
action="store_false",
help="use the (old) Tk interface")
parser.add_option("-c", "--config", dest="config_file",
default=None, action="store", type="string",
help="load a task settings file (requires the GTK interface)")
parser.add_option("", "--task", dest="task",
default=None, action="store", type="int",
help="choose a specific task from task settings by number (requires the GTK interface)")
parser.add_option("", "--disable-ode", dest="ode_disabled",
default=False, action="store_true", help="disable experimental ODE collision detection")
(options, args) = parser.parse_args()
if len(args) > 0:
inputfile = args[0]
if len(args) > 1:
outputfile = args[1]
if len(args) > 2:
parser.error("too many arguments given (%d instead of %d)" % (len(args), 2))
# try the configured interface first and then try to fall back to the alternative, if necessary
deps_gtk = GuiCommon.dependency_details_gtk()
deps_tk = GuiCommon.dependency_details_tk()
report_gtk = GuiCommon.get_dependency_report(deps_gtk, prefix="\t")
report_tk = GuiCommon.get_dependency_report(deps_tk, prefix="\t")
if options.gtk_gui:
if GuiCommon.check_dependencies(deps_gtk):
from pycam.Gui.Project import ProjectGui
gui_class = ProjectGui
else:
print >> sys.stderr, "Error: Failed to load the GTK interface."
print >> sys.stderr, "Details:"
print >> sys.stderr, report_gtk
print >> sys.stderr, "I will try to use the alternative Tk interface now ..."
if GuiCommon.check_dependencies(deps_tk):
from pycam.Gui.SimpleGui import SimpleGui
gui_class = SimpleGui
options.gtk_gui = False
else:
gui_class = None
else:
if GuiCommon.check_dependencies(deps_tk):
from pycam.Gui.SimpleGui import SimpleGui
gui_class = SimpleGui
else:
print >> sys.stderr, "Error: Failed to load the Tk interface."
print >> sys.stderr, "Details:"
print >> sys.stderr, report_tk
print >> sys.stderr, "I will try to use the alternative GTK interface now ..."
if GuiCommon.check_dependencies(deps_gtk):
from pycam.Gui.Project import ProjectGui
gui_class = ProjectGui
options.gtk_gui = True
else:
gui_class = None
# exit if no interface is found
if gui_class is None:
full_report = []
full_report.append("Neither the GTK nor the Tk interface is available. Please install the corresponding packages!")
full_report.append("")
full_report.append("Dependency report for GTK interface:")
full_report.append(report_gtk)
full_report.append("")
full_report.append("Dependency report for Tk interface:")
full_report.append(report_tk)
full_report.append("")
full_report.append("Detailed list of requirements: %s" % GuiCommon.REQUIREMENTS_LINK)
full_report.append("")
GuiCommon.EmergencyDialog("PyCAM dependency problem", os.linesep.join(full_report))
sys.exit(1)
if options.ode_disabled:
override_ode_availability(False)
if outputfile and not options.display:
gui = gui_class(no_dialog=True)
else:
gui = gui_class()
if not inputfile:
from pycam.Importers.TestModel import TestModel
gui.load_model(TestModel())
else:
gui.open(inputfile)
# load task settings file
# only available for the GTK interface
if options.gtk_gui:
if options.config_file:
gui.open_task_settings_file(options.config_file)
if outputfile and not options.display:
# an output filename is given and no gui is explicitly requested
if options.gtk_gui:
if not options.task is None:
gui.process_one_task(options.task)
else:
gui.process_multiple_tasks()
else:
gui.generateToolpath()
if outputfile:
gui.save_toolpath(outputfile)
else:
# the gui should be shown
if outputfile:
gui.setOutputFilename(outputfile)
gui.mainloop()