55 #include "common/glew_wrappers.hh" 63 #include <OpenFlipper/SimpleOpt/SimpleOpt.h> 85 #include "StackWalker/StackWalker.hh" 91 virtual void OnOutput(LPCSTR szText)
94 std::ofstream crashFile;
95 QString crashName = OpenFlipper::Options::configDirStr() + QDir::separator() +
"CrashDump.txt";
96 crashFile.open(crashName.toLatin1(),std::ios::out | std::ios::app);
113 #ifdef WIN_GET_DEBUG_CONSOLE 124 if (AttachConsole(-1))
127 freopen(
"CONIN$",
"r", stdin);
128 freopen(
"CONOUT$",
"w", stdout);
129 freopen(
"CONOUT$",
"w", stderr);
134 if (OpenFlipper::Options::logToConsole())
137 freopen(
"CONIN$",
"r", stdin);
138 freopen(
"CONOUT$",
"w", stdout);
139 freopen(
"CONOUT$",
"w", stderr);
143 #ifdef WIN_GET_DEBUG_CONSOLE 148 HANDLE ConsoleOutput = GetStdHandle(STD_OUTPUT_HANDLE);
149 int SystemOutput = _open_osfhandle(intptr_t(ConsoleOutput), _O_TEXT);
150 FILE *COutputHandle = _fdopen(SystemOutput,
"w" );
151 *stdout = *COutputHandle;
152 setvbuf(stdout, NULL, _IONBF, 0);
154 HANDLE ConsoleError = GetStdHandle(STD_ERROR_HANDLE);
155 int SystemError = _open_osfhandle(intptr_t(ConsoleError), _O_TEXT);
156 FILE *CErrorHandle = _fdopen(SystemError,
"w" );
157 *stderr = *CErrorHandle;
158 setvbuf(stderr, NULL, _IONBF, 0);
160 HANDLE ConsoleInput = GetStdHandle(STD_INPUT_HANDLE);
161 int SystemInput = _open_osfhandle(intptr_t(ConsoleInput), _O_TEXT);
162 FILE *CInputHandle = _fdopen(SystemInput,
"r" );
163 *stdin = *CInputHandle;
164 setvbuf(stdin, NULL, _IONBF, 0);
180 int size = backtrace(addresses, 20);
181 strings = backtrace_symbols(addresses, size);
182 std::cerr <<
"Stack frames: " << size << std::endl;
183 for(
int i = 0; i < size; i++)
184 std::cerr << i <<
": " << strings[i] << std::endl;
196 void segfaultHandling (
int) {
199 std::signal(SIGSEGV, SIG_DFL);
202 std::cerr <<
"\n" << std::endl;
203 std::cerr <<
"\n" << std::endl;
204 std::cerr <<
"\33[31m" <<
"=====================================================" << std::endl;
205 std::cerr <<
"\33[31m" <<
"OpenFlipper or one of its plugins caused a Segfault." << std::endl;
206 std::cerr <<
"\33[31m" <<
"This should not happen,... Sorry :-(" << std::endl;
207 std::cerr <<
"\33[31m" <<
"=====================================================" << std::endl;
208 std::cerr <<
"\n" << std::endl;
212 std::cerr <<
"\33[0m" <<
"Trying a backtrace to show what happened last: " << std::endl;
215 std::cerr <<
"\n" << std::endl;
216 std::cerr <<
"Backtrace completed, trying to abort now ..." << std::endl;
221 StackWalkerToConsole sw;
226 std::cerr <<
"Trying to get additional information (This might fail if the memory is corrupted)." << std::endl;
228 if (OpenFlipper::Options::gui()) {
229 for (
unsigned int i = 0 ; i < 4 ; ++i) {
237 enum {OPT_HELP , OPT_STEREO, OPT_BATCH ,OPT_CONSOLE_LOG , OPT_DEBUGGING, OPT_FULLSCREEN,
238 OPT_HIDDDEN_LOGGER , OPT_NOSPLASH ,OPT_HIDDDEN_TOOLBOX , OPT_LOAD_POLYMESHES,
239 OPT_REMOTE, OPT_REMOTE_PORT};
241 CSimpleOpt::SOption g_rgOptions[] = {
242 { OPT_DEBUGGING , (
char*)
"--debug" , SO_NONE },
243 { OPT_HELP , (
char*)
"-?" , SO_NONE },
244 { OPT_HELP , (
char*)
"--help" , SO_NONE },
245 { OPT_HELP , (
char*)
"-h" , SO_NONE },
246 { OPT_STEREO , (
char*)
"--disable-stereo" , SO_NONE },
247 { OPT_BATCH , (
char*)
"-b" , SO_NONE },
248 { OPT_CONSOLE_LOG , (
char*)
"-c" , SO_NONE },
249 { OPT_CONSOLE_LOG , (
char*)
"--log-to-console" , SO_NONE },
250 { OPT_FULLSCREEN , (
char*)
"-f" , SO_NONE },
251 { OPT_HIDDDEN_LOGGER , (
char*)
"-l" , SO_NONE },
252 { OPT_NOSPLASH , (
char*)
"--no-splash" , SO_NONE },
253 { OPT_HIDDDEN_TOOLBOX , (
char*)
"-t" , SO_NONE },
254 { OPT_LOAD_POLYMESHES , (
char*)
"-p" , SO_NONE },
255 { OPT_REMOTE , (
char*)
"--remote-control" , SO_NONE },
256 { OPT_REMOTE_PORT , (
char*)
"--remote-port" , SO_REQ_SEP },
261 std::cerr <<
"OpenFlipper [Options] <filenames> " << std::endl << std::endl;;
262 std::cerr <<
"Possible Options : " << std::endl;
263 std::cerr << std::endl;
265 std::cerr <<
"Load/Save Options:" << std::endl;
266 std::cerr <<
" -p \t: Open files as PolyMeshes" << std::endl;
267 std::cerr << std::endl;
269 std::cerr <<
"Gui Options:" << std::endl;
270 std::cerr <<
" -f \t\t: Start Fullscreen" << std::endl;
271 std::cerr <<
" -l \t\t: Start with hidden logger" << std::endl;
272 std::cerr <<
" -t \t\t: Start with hidden Toolbox" << std::endl;
273 std::cerr <<
" --no-splash \t: Disable splash screen" << std::endl;
275 std::cerr <<
" --disable-stereo \t: Disable Stereo Mode" << std::endl;
276 std::cerr << std::endl;
278 std::cerr <<
"Log options:" << std::endl;
279 std::cerr <<
" --log-to-console ( -c ) \t: Write logger window contents to console" << std::endl;
280 std::cerr << std::endl;
282 std::cerr <<
"Other options:" << std::endl;
283 std::cerr <<
" -b \t: Batch mode, you have to provide a script for execution" << std::endl;
284 std::cerr <<
" --remote-control \t: Batch mode accepting remote connections" << std::endl;
286 std::cerr << std::endl;
289 std::cerr <<
" -h \t: This help" << std::endl;
297 bool openPolyMeshes =
false;
298 bool remoteControl =
false;
300 bool parseCommandLineOptions(CSimpleOpt& args){
305 while (args.Next()) {
307 if (args.LastError() == SO_SUCCESS) {
309 switch (args.OptionId() ) {
311 OpenFlipper::Options::nogui(
true);
313 case OPT_CONSOLE_LOG:
314 OpenFlipper::Options::logToConsole(
true);
317 OpenFlipper::Options::debug(
true);
320 OpenFlipper::Options::stereo(
false);
322 case OPT_HIDDDEN_TOOLBOX:
325 case OPT_HIDDDEN_LOGGER:
326 OpenFlipper::Options::loggerState(OpenFlipper::Options::Hidden);
331 case OPT_LOAD_POLYMESHES:
332 openPolyMeshes =
true;
338 OpenFlipper::Options::remoteControl(
true);
340 case OPT_REMOTE_PORT:
341 port = args.OptionArg();
342 std::cerr <<
"Got option : " << port.toStdString() << std::endl;
343 OpenFlipper::Options::remoteControl(port.toInt());
350 std::cerr <<
"Invalid argument: " << args.OptionText() << std::endl;
358 int main(
int argc,
char **argv)
363 for (
int i = 0; i < argc; i++) {
364 if(strlen(argv[i]) > 4) {
365 if( ( (argv[i])[0] ==
'-' ) &&
366 ( (argv[i])[1] ==
'p' ) &&
367 ( (argv[i])[2] ==
's' ) &&
368 ( (argv[i])[3] ==
'n' ) ) {
370 argv[i] = (
char *)
"";
375 OpenFlipper::Options::argc(&argc);
376 OpenFlipper::Options::argv(&argv);
378 CSimpleOpt argBatch(argc, argv, g_rgOptions);
381 while (argBatch.Next())
382 if (argBatch.OptionId() == OPT_BATCH ){
383 OpenFlipper::Options::nogui(
true);
387 CSimpleOpt args(argc, argv, g_rgOptions);
389 #ifndef NO_CATCH_SIGSEGV 391 std::signal(SIGSEGV, segfaultHandling);
394 OpenFlipper::Options::windowTitle(
TOSTRING(PRODUCT_STRING)
" v" + OpenFlipper::Options::coreVersion());
397 #ifdef WIN_GET_DEBUG_CONSOLE 402 if ( !OpenFlipper::Options::nogui() ) {
405 QApplication::setColorSpec( QApplication::CustomColor );
406 QApplication app(argc,argv);
410 QCoreApplication::setOrganizationName(
"rwth-aachen.de");
411 QCoreApplication::setApplicationName(
"graphics.openflipper");
414 if ( !QGLFormat::hasOpenGL() ) {
415 std::cerr <<
"This system has no OpenGL support.\n";
420 glutInit(&argc,argv);
426 if ( !parseCommandLineOptions(args) ) {
431 #ifndef WIN_GET_DEBUG_CONSOLE //only attach to parent console if no separate debug console is requested 438 if (tLang ==
"locale")
439 tLang = QLocale::system().name();
442 QTranslator qtTranslator;
447 qtTranslator.load(
"qt_" + tLang, QLibraryInfo::location(QLibraryInfo::TranslationsPath));
450 app.installTranslator(&qtTranslator);
453 QString translationDir = OpenFlipper::Options::translationsDirStr() + QDir::separator();
457 QDir dir(translationDir);
458 dir.setFilter(QDir::Files);
460 QFileInfoList list = dir.entryInfoList();
462 for (
int i = 0; i < list.size(); ++i) {
463 QFileInfo fileInfo = list.at(i);
465 if ( fileInfo.baseName().contains(tLang) ){
466 QTranslator* myAppTranslator =
new QTranslator();
468 if ( myAppTranslator->load( fileInfo.filePath() ) ){
471 app.installTranslator(myAppTranslator);
473 delete myAppTranslator;
485 for (
int i = 0 ; i < args.FileCount(); ++i )
492 QCoreApplication app(argc,argv);
496 QCoreApplication::setOrganizationName(
"rwth-aachen.de");
497 QCoreApplication::setApplicationName(
"graphics.openflipper");
503 if ( !parseCommandLineOptions(args) ) {
511 for (
int i = 0 ; i < args.FileCount(); ++i )
std::string description() const
DLLEXPORT OpenFlipperQSettings & OpenFlipperSettings()
QSettings object containing all program settings of OpenFlipper.
void init()
Second initialization stage.
void setValue(const QString &key, const QVariant &value)
Wrapper function which makes it possible to enable Debugging output with -DOPENFLIPPER_SETTINGS_DEBUG...
QVariant value(const QString &key, const QVariant &defaultValue=QVariant()) const
void commandLineOpen(const char *_filename, bool _asPolyMesh)
Load an object from the commandline on application start.
ACG::SceneGraph::DrawModes::DrawMode drawMode(int _viewer)
Get the current draw Mode of a Viewer.
void commandLineScript(const char *_filename)
Load a script from the commandline on application start.
#define TOSTRING(x)
QSettings object containing all program settings of OpenFlipper.