Commit 43413ed2 authored by sumpfralle's avatar sumpfralle

some more improvements for the commandline handler (not ready, yet)


git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@468 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent 9cf25fa2
...@@ -31,6 +31,7 @@ import pycam.Gui.common as GuiCommon ...@@ -31,6 +31,7 @@ import pycam.Gui.common as GuiCommon
import pycam.Gui.Settings import pycam.Gui.Settings
import pycam.Importers.STLImporter import pycam.Importers.STLImporter
import pycam.Importers.TestModel import pycam.Importers.TestModel
import pycam.Exporters.SimpleGCodeExporter
import pycam.Toolpath.Generator import pycam.Toolpath.Generator
import pycam.Toolpath import pycam.Toolpath
from pycam import VERSION from pycam import VERSION
...@@ -98,9 +99,17 @@ def get_default_model(): ...@@ -98,9 +99,17 @@ def get_default_model():
# check if we were started as a separate program # check if we were started as a separate program
if __name__ == "__main__": if __name__ == "__main__":
parser = OptionParser( parser = OptionParser( prog="PyCAM", version="PyCAM v%s" % VERSION,
usage="usage: %prog [options] [inputfile]", usage="usage: %prog [options] [inputfile]\n\n" \
version="PyCAM v%s" % VERSION) + "Use any of the '--export-???' parameters to disable " \
+ "the graphical user interface (GUI).\n" \
+ "When starting the GUI (default) all arguments except " \
+ "'inputfile' are ignored.\n" \
+ "'inputfile' may be an STL or DXF file.",
epilog="Use any of the '--export-???' parameters to enable " \
+ "non-interactive mode. Otherwise all options (except " \
+ "'inputfile') are silently ignored and the GUI is " \
+ "started.")
group_general = parser.add_option_group("General options") group_general = parser.add_option_group("General options")
group_export = parser.add_option_group("Export formats", group_export = parser.add_option_group("Export formats",
"Export the resulting toolpath or meta-data in various formats. " \ "Export the resulting toolpath or meta-data in various formats. " \
...@@ -134,9 +143,18 @@ if __name__ == "__main__": ...@@ -134,9 +143,18 @@ if __name__ == "__main__":
default="mm", action="store", type="choice", default="mm", action="store", type="choice",
choices=["mm", "inch"], help="choose 'mm' or 'inch' for all " \ choices=["mm", "inch"], help="choose 'mm' or 'inch' for all " \
+ "numbers. By default 'mm' is assumed.") + "numbers. By default 'mm' is assumed.")
group_general.add_option("", "--disable-ode", dest="ode_disabled", group_general.add_option("", "--collision-engine", dest="collision_engine",
default=False, action="store_true", default="triangles", action="store", type="choice",
help="disable experimental ODE collision detection") choices=["triangles", "ode", "help"],
help="choose a specific collision detection engine. The default " \
+ "is 'triangles'. Use 'help' to get a list of possible " \
+ "engines.")
group_general.add_option("", "--boundary-mode", dest="boundary_mode",
default="along", action="store", type="choice",
choices=["inside", "along", "outside"],
help="specify if the mill tool (including its radius) should " \
+ "move completely 'inside', 'along' or 'outside' the " \
+ "defined processing boundary.")
group_export.add_option("", "--export-gcode", dest="export_gcode", group_export.add_option("", "--export-gcode", dest="export_gcode",
default=None, action="store", type="string", default=None, action="store", type="string",
help="export the generated toolpaths to a file") help="export the generated toolpaths to a file")
...@@ -206,18 +224,18 @@ if __name__ == "__main__": ...@@ -206,18 +224,18 @@ if __name__ == "__main__":
group_bounds.add_option("", "--bounds-lower", dest="bounds_lower", group_bounds.add_option("", "--bounds-lower", dest="bounds_lower",
default="", action="store", type="string", default="", action="store", type="string",
help="comma-separated x/y/z combination of the lower boundary " \ help="comma-separated x/y/z combination of the lower boundary " \
+ "(e.g. '12,5.5,0')") + "(e.g. '4,4,-0.5')")
group_bounds.add_option("", "--bounds-upper", dest="bounds_upper", group_bounds.add_option("", "--bounds-upper", dest="bounds_upper",
default="", action="store", type="string", default="", action="store", type="string",
help="comma-separated x/y/z combination of the upper boundary " \ help="comma-separated x/y/z combination of the upper boundary " \
+ "(e.g. '4,4,-0.5')") + "(e.g. '12,5.5,0')")
group_support_grid.add_option("", "--enable-support-grid", group_support_grid.add_option("", "--enable-support-grid",
dest="support_grid_enabled", default=False, action="store_true", dest="support_grid_enabled", default=False, action="store_true",
help="enable the support grid") help="enable the support grid")
group_support_grid.add_option("", "--support-grid-distance", group_support_grid.add_option("", "--support-grid-distance",
dest="support_grid_distance", default=10.0, action="store", dest="support_grid_distance", default=10.0, action="store",
type="float", help="how far apart should two adjacent parallel " \ type="float", help="horizontal and vertical distance between two " \
+ "lines of the support grid pattern be") + "adjacent parallel lines of the support grid pattern")
group_support_grid.add_option("", "--support-grid-height", group_support_grid.add_option("", "--support-grid-height",
dest="support_grid_height", default=2.0, action="store", dest="support_grid_height", default=2.0, action="store",
type="float", help="height of the support grid profile") type="float", help="height of the support grid profile")
...@@ -231,9 +249,6 @@ if __name__ == "__main__": ...@@ -231,9 +249,6 @@ if __name__ == "__main__":
else: else:
inputfile = None inputfile = None
if opts.ode_disabled:
override_ode_availability(False)
if not opts.export_gcode and not opts.export_task_config: if not opts.export_gcode and not opts.export_task_config:
show_gui(inputfile, opts.config_file) show_gui(inputfile, opts.config_file)
else: else:
...@@ -248,7 +263,7 @@ if __name__ == "__main__": ...@@ -248,7 +263,7 @@ if __name__ == "__main__":
if opts.support_grid_enabled: if opts.support_grid_enabled:
tps.set_support_grid(opts.support_grid_distance, tps.set_support_grid(opts.support_grid_distance,
opts.support_grid_thickness, opts.support_grid_height) opts.support_grid_thickness, opts.support_grid_height)
if not opts.ode_disabled: if opts.collision_engine == "ode":
tps.set_calculation_backend("ODE") tps.set_calculation_backend("ODE")
tps.set_unit_size(opts.unit_size) tps.set_unit_size(opts.unit_size)
path_generator = {"layer": "PushCutter", path_generator = {"layer": "PushCutter",
...@@ -307,10 +322,42 @@ if __name__ == "__main__": ...@@ -307,10 +322,42 @@ if __name__ == "__main__":
else: else:
# both lower and upper bounds were specified # both lower and upper bounds were specified
bounds.set_bounds(bounds_lower_nums, bounds_upper_nums) bounds.set_bounds(bounds_lower_nums, bounds_upper_nums)
# adjust the bounding box according to the "boundary_mode"
# TODO: inside/along/outside boundary (currently: along) if opts.boundary_mode == "along":
tps.set_bounds(bounds) offset = (0, 0, 0)
elif opts.boundary_mode == "inside":
offset = (-opts.tool_radius, -opts.tool_radius, 0)
else:
# "outside"
offset = (opts.tool_radius, opts.tool_radius, 0)
process_bounds = Bounds(Bounds.TYPE_FIXED_MARGIN, offset, offset)
process_bounds.set_reference(bounds)
tps.set_bounds(process_bounds)
if opts.export_gcode:
# generate the toolpath
tp = pycam.Toolpath.Generator.generate_toolpath_from_settings(model, tps) tp = pycam.Toolpath.Generator.generate_toolpath_from_settings(model, tps)
# write result # write result
print tp if isinstance(tp, basestring):
# an error occoured
log.error(tp)
else:
start_pos = tp.get_start_position()
meta_data = os.linesep.join(tp.get_meta_data())
if opts.export_gcode == "-":
destination = sys.stdout
close_destination = False
else:
destination = open(opts.export_gcode, "w")
close_destination = True
pycam.Exporters.SimpleGCodeExporter.ExportPathList(destination,
tp.get_path(), opts.unit_size, start_pos.x,
start_pos.y, start_pos.z, opts.tool_feedrate,
opts.tool_speed, safety_height=opts.safety_height,
max_skip_safety_distance=2*opts.tool_radius,
comment=meta_data)
if close_destination:
destination.close()
if opts.export_task_config:
raise NotImplementedError("Export of task config is not " \
+ "implemented, yet!")
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment