38
38
#include <wx/tooltip.h>
39
39
#include <claw/logger.hpp>
40
#include <claw/exception.hpp>
41
42
/*----------------------------------------------------------------------------*/
43
44
* \brief Constructor.
45
46
bf::model_editor::model_editor()
46
: m_locale( wxLocale::GetSystemLanguage() ), m_main_frame(NULL)
48
claw::logger.set( new claw::console_logger() );
49
claw::logger.set_level( claw::log_verbose );
51
m_locale.AddCatalog( wxT("bear-factory") );
52
50
} // model_editor::model_editor()
54
52
/*----------------------------------------------------------------------------*/
58
bf::model_editor::~model_editor()
60
// frames are deleted by wxWidgets
63
} // model_editor::~model_editor()
65
/*----------------------------------------------------------------------------*/
67
* \brief Method called when the application is initializing.
69
bool bf::model_editor::OnInit()
74
if ( !show_version() )
76
if ( find_and_erase_option( wxT("--compile"), wxT("-c") ) )
86
} // model_editor::OnInit()
88
/*----------------------------------------------------------------------------*/
90
54
* \brief Initialize the application.
92
void bf::model_editor::init_app()
56
bool bf::model_editor::do_init_app()
94
wxToolTip::Enable(true);
96
58
m_main_frame = new main_frame;
97
59
m_main_frame->Show();
99
61
for (int i=1; i<argc; ++i)
100
62
if ( wxString(argv[i]) != wxT("--") )
101
m_main_frame->load_model( argv[i] );
65
m_main_frame->load_model( argv[i] );
67
catch( std::ios_base::failure& e )
69
claw::logger << claw::log_error << e.what()
70
<< "\nCreating a new model." << std::endl;
71
m_main_frame->new_model( argv[i] );
73
catch( std::exception& e )
75
claw::logger << claw::log_error << e.what() << std::endl;
102
79
} // model_editor::init_app()
104
81
/*----------------------------------------------------------------------------*/
106
* \brief Compile the models and exit.
108
bool bf::model_editor::compile_arguments()
112
for (int i=1; i<argc; ++i)
113
if ( wxString(argv[i]) != wxT("--") )
120
xml::model_file reader;
121
mdl = reader.load(argv[i]);
123
if ( check_model(*mdl) )
124
ok = compile_model(*mdl, argv[i]);
133
std::cerr << "Error when processing '" << argv[i] << '\''
140
} // model_editor::compile_arguments()
83
* \brief Compile a model.
84
* \param path The path to the model file.
86
void bf::model_editor::compile( const wxString& path ) const
92
xml::model_file reader;
93
mdl = reader.load(path);
95
if ( check_model(*mdl) )
97
compile_model(*mdl, path);
103
CLAW_EXCEPTION("Invalid model.");
111
} // model_editor::compile()
113
/*----------------------------------------------------------------------------*/
115
* \brief Update a model.
116
* \param path The path to the model file.
118
void bf::model_editor::update( const wxString& path ) const
120
gui_model* mdl(NULL);
127
std::ofstream f( wx_to_std_string(path).c_str() );
137
} // model_editor::update()
142
139
/*----------------------------------------------------------------------------*/
144
141
* \brief Check if a model is valid.
145
142
* \param mdl The model to check.
147
bool bf::model_editor::check_model( const model& mdl )
144
bool bf::model_editor::check_model( const model& mdl ) const
149
146
bool result(true);
150
147
model::const_action_iterator it;
152
149
for ( it=mdl.action_begin(); it!=mdl.action_end(); ++it )
153
if ( !it->get_auto_next().empty() )
150
if ( !it->get_auto_next().empty() )
154
151
if ( !mdl.has_action( it->get_auto_next() ) )
157
std::cerr << "Unknown action '" << it->get_auto_next() << '\''
154
claw::logger << claw::log_error << "Unknown action '"
155
<< it->get_auto_next() << '\'' << std::endl;
199
196
} // model_editor::compile_model()
201
/*----------------------------------------------------------------------------*/
203
* \brief Show the command line usage.
204
* \return true if the usage has been shown.
206
bool bf::model_editor::show_help()
208
if ( find_and_erase_option(wxT("--help"), wxT("-h")) )
210
std::cout << "usage:\n" << wx_to_std_string(argv[0])
211
<< " [option] [file...]\n"
212
"Where the options are:\n\n"
213
"\t--compile, -c\tCompile the models and exit,\n"
214
"\t--help, -h\tDisplay this help and exit,\n"
215
"\t--version, -v\tDisplay the version of the program and exit."
221
} // model_editor::show_help()
223
/*----------------------------------------------------------------------------*/
225
* \brief Show the version of the program
226
* \return true if the version has been shown.
228
bool bf::model_editor::show_version()
230
if ( find_and_erase_option(wxT("--version"), wxT("-v")) )
232
std::cout << BF_VERSION_STRING << std::endl;
237
} // model_editor::show_version()
239
/*----------------------------------------------------------------------------*/
241
* \brief Check if an option is present on the command line and remove it.
242
* \param long_name The long name of the option.
243
* \param show_name The short name of the option.
245
bool bf::model_editor::find_and_erase_option
246
( const wxString& long_name, const wxString& short_name )
251
for (int i=1; !stop && (index==0) && (i<argc); ++i)
252
if ( (argv[i] == long_name) || (argv[i] == short_name))
255
stop = wxString(argv[i]) == wxT("--");
259
for ( int i=index; (i+1 != argc); ++i )
267
} // model_editor::find_and_erase_option()