RacerEditorApp.cpp

Go to the documentation of this file.
00001 
00005 /* Copyright © 2009, 2010 James Legg.
00006     This program is free software: you can redistribute it and/or modify
00007     it under the terms of the GNU General Public License as published by
00008     the Free Software Foundation, either version 3 of the License, or
00009     (at your option) any later version.
00010 */
00011 #include "RacerEditorApp.h"
00012 
00013 #include <gtkmm/main.h>
00014 #include <gtkglmm.h>
00015 #include "EditorWindow.h"
00016 #include <libtrack/DataCheck.h>
00017 #include <boost/program_options.hpp>
00018 #include <iostream>
00019 #include <fstream>
00020 
00021 RacerEditorApp::RacerEditorApp(int argc, char **argv)
00022 {
00023     try
00024     {
00025         Track::DataCheck();
00026     }
00027     catch (Track::DataCheck::FileMissingError e)
00028     {
00029         std::cerr << "Cannot find data file: " << e.filename << std::endl;
00030         std::cerr << "Please run from the directory all the data files accessible." << std::endl;
00031         return;
00032     }
00033     // initialise gtkmm
00034     Gtk::Main kit(argc, argv);
00035     // initalise gtkglmm
00036     Gtk::GL::init(argc, argv);
00037     
00038     // program options allowed only on the command line.
00039     boost::program_options::options_description generic("Generic options");
00040     generic.add_options()
00041         ("help,h", "Show this help message")
00042     ;
00043     // program options allowed on both the command line and configuration file.
00044     boost::program_options::options_description config("Configuration");
00045     config.add_options()
00046         ("show-guide", boost::program_options::value<bool>(&m_show_guide)->default_value(true), "Show the usage guide above the track view.")
00047     ;
00048     // hidden program options allowed only in the command line.
00049     boost::program_options::options_description hidden("Hidden");
00050     hidden.add_options()
00051         ("input-file", boost::program_options::value<std::string>(), "Load the specified file. Relative paths are taken to mean from racer's data directory. For example data/tracks/0")
00052     ;
00053     // 'file' on its own means the same as --input-file='file'.
00054     boost::program_options::positional_options_description p;
00055     p.add("input-file", -1);
00056     
00057     // combine for command line arguments.
00058     boost::program_options::options_description cmdline_options;
00059     cmdline_options.add(generic).add(config).add(hidden);
00060     // combine for visible command line arguments.
00061     boost::program_options::options_description visible_options;
00062     visible_options.add(generic).add(config);
00063     
00064     // load the variables from the command line and configuration file.
00065     boost::program_options::variables_map vm;
00066     boost::program_options::store(boost::program_options::command_line_parser(argc, argv).
00067           options(cmdline_options).positional(p).run(), vm);
00068     std::string config_filename = Glib::get_user_config_dir() + "/racer-editor.config";
00069     DEBUG_MESSAGE("Loading configuration from " << config_filename);
00070     std::ifstream config_file(config_filename.c_str());
00071     boost::program_options::store(boost::program_options::parse_config_file(config_file, config), vm);
00072     boost::program_options::notify(vm);
00073     
00074     // Show help?
00075     if (vm.count("help"))
00076     {
00077         std::cout << "Usage: " << argv[0] << " [options] [trackfile]" << std::endl;
00078         std::cout << visible_options << std::endl;
00079         return;
00080     }
00081     
00082     // Start editor.
00083     std::string filename;
00084     if (vm.count("input-file"))
00085     {
00086         filename = vm["input-file"].as<std::string>();
00087     }
00088     EditorWindow window(m_show_guide, filename);
00089     Gtk::Main::run(window);
00090 }
00091 
00092 RacerEditorApp::~RacerEditorApp()
00093 {
00094 }

Get Racer at SourceForge.net. Fast, secure and Free Open Source software downloads

Generated at Mon Sep 6 00:41:13 2010 by Doxygen version 1.4.7 for Racer version svn335.