OpenFlipper.cc 19.5 KB
Newer Older
Jan Möbius's avatar
Jan Möbius committed
1 2 3
/*===========================================================================*\
*                                                                            *
*                              OpenFlipper                                   *
Martin Schultz's avatar
Martin Schultz committed
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
 *           Copyright (c) 2001-2015, RWTH-Aachen University                 *
 *           Department of Computer Graphics and Multimedia                  *
 *                          All rights reserved.                             *
 *                            www.openflipper.org                            *
 *                                                                           *
 *---------------------------------------------------------------------------*
 * This file is part of OpenFlipper.                                         *
 *---------------------------------------------------------------------------*
 *                                                                           *
 * Redistribution and use in source and binary forms, with or without        *
 * modification, are permitted provided that the following conditions        *
 * are met:                                                                  *
 *                                                                           *
 * 1. Redistributions of source code must retain the above copyright notice, *
 *    this list of conditions and the following disclaimer.                  *
 *                                                                           *
 * 2. Redistributions in binary form must reproduce the above copyright      *
 *    notice, this list of conditions and the following disclaimer in the    *
 *    documentation and/or other materials provided with the distribution.   *
 *                                                                           *
 * 3. Neither the name of the copyright holder nor the names of its          *
 *    contributors may be used to endorse or promote products derived from   *
 *    this software without specific prior written permission.               *
 *                                                                           *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS       *
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A           *
 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,  *
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,       *
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR        *
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF    *
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING      *
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS        *
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.              *
Jan Möbius's avatar
Jan Möbius committed
39 40
*                                                                            *
\*===========================================================================*/
Jan Möbius's avatar
 
Jan Möbius committed
41

Jan Möbius's avatar
Jan Möbius committed
42 43 44 45 46 47 48
/*===========================================================================*\
*                                                                            *
*   $Revision$                                                       *
*   $LastChangedBy$                                                *
*   $Date$                     *
*                                                                            *
\*===========================================================================*/
Jan Möbius's avatar
 
Jan Möbius committed
49 50 51 52 53 54



// Mainwindow

#include "OpenFlipper/Core/Core.hh"
Hans-Christian Ebke's avatar
Hans-Christian Ebke committed
55
#include "common/glew_wrappers.hh"
Jan Möbius's avatar
 
Jan Möbius committed
56 57 58 59 60 61

// Qt
#include <qgl.h>

// stdc++
#include <csignal>
62
#include <regex>
63 64

#include <QCommandLineParser>
Jan Möbius's avatar
 
Jan Möbius committed
65

Matthias Möller's avatar
Matthias Möller committed
66
#if ( defined(WIN32))
Mike Kremer's avatar
Mike Kremer committed
67 68 69 70
  #define NO_EXECINFO
#endif

#ifndef NO_EXECINFO
71
#include <execinfo.h>
Jan Möbius's avatar
 
Jan Möbius committed
72 73 74 75 76
#endif

#ifdef USE_OPENMP
#endif

77 78 79 80 81 82 83 84
/* ==========================================================
 *
 * Stackwalker code. Used to get a backtrace if OpenFlipper
 * crashes under windows
 *
 * ==========================================================*/


85 86
#ifdef WIN32
  #include "StackWalker/StackWalker.hh"
87
  #include <fstream>
88 89 90 91 92 93

  class StackWalkerToConsole : public StackWalker
  {
  protected:
	  virtual void OnOutput(LPCSTR szText)
    	{
94 95 96
			// Writes crash dump to .OpenFlipper config directory
			std::ofstream crashFile;
			QString crashName = OpenFlipper::Options::configDirStr() + QDir::separator() + "CrashDump.txt";
Jan Möbius's avatar
Jan Möbius committed
97
			crashFile.open(crashName.toLatin1(),std::ios::out | std::ios::app);
98 99
			crashFile << szText;
			crashFile.close();
100 101 102 103
	  }
  };
#endif

104 105 106 107 108 109 110 111 112

/* ==========================================================
 *
 * Console for Windows to get additional output written via
 * cerr, cout, ... that is not forwarded to log window
 *
 * ==========================================================*/

#ifdef WIN32
113

Martin Schultz's avatar
Martin Schultz committed
114
  void attachConsole()
Jan Möbius's avatar
Jan Möbius committed
115 116 117 118 119 120 121 122 123
   {
     //try to attach the console of the parent process
     if (AttachConsole(-1))
     {
       //if the console was attached change stdinput and output
       FILE* check = freopen("CONIN$", "r", stdin);
       if (check) {
         std::cerr << "Error reopening stdin" << std::endl;
       }
Jan Möbius's avatar
Typo  
Jan Möbius committed
124
       check = freopen("CONOUT$", "w", stdout);
Jan Möbius's avatar
Jan Möbius committed
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
       if (check) {
         std::cerr << "Error reopening stdout" << std::endl;
       }
       check = freopen("CONOUT$", "w", stderr);
       if (check) {
         std::cerr << "Error reopening stderr" << std::endl;
       }
     }
     else
     {
       //create and attach a new console if needed
 #ifndef NDEBUG
       //always open a console in debug mode
       AllocConsole();

       FILE* check = freopen("CONIN$", "r", stdin);
       if (check) {
         std::cerr << "Error reopening stdin" << std::endl;
       }
tenter's avatar
tenter committed
144
       check = freopen("CONOUT$", "w", stdout);
Jan Möbius's avatar
Jan Möbius committed
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
       if (check) {
         std::cerr << "Error reopening stdout" << std::endl;
       }
       check = freopen("CONOUT$", "w", stderr);
       if (check) {
         std::cerr << "Error reopening stderr" << std::endl;
       }
       return;
 #endif
       if (OpenFlipper::Options::logToConsole())
       {
         AllocConsole();

         FILE* check = freopen("CONIN$", "r", stdin);
         if (check) {
           std::cerr << "Error reopening stdin" << std::endl;
         }
Jan Möbius's avatar
Typo  
Jan Möbius committed
162
         check = freopen("CONOUT$", "w", stdout);
Jan Möbius's avatar
Jan Möbius committed
163 164 165 166 167 168 169 170 171 172
         if (check) {
           std::cerr << "Error reopening stdout" << std::endl;
         }
         check = freopen("CONOUT$", "w", stderr);
         if (check) {
           std::cerr << "Error reopening stderr" << std::endl;
         }
       }
     }
   }
173

174 175 176 177 178 179 180 181
#endif

/* ==========================================================
 *
 * Linux function printing a full stack trace to the console
 *
 * ==========================================================*/
#ifndef NO_EXECINFO
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206

#if defined(__GLIBCXX__) || defined(__GLIBCPP__)
// GCC: implement demangling using cxxabi
#include <cxxabi.h>
std::string demangle(const std::string& _symbol)
{
    int status;
    char* demangled = abi::__cxa_demangle(_symbol.c_str(), nullptr, nullptr, &status);
    if (demangled) {
        std::string result{demangled};
        free(demangled);
        if (status == 0) {
            return result;
        }
        else {
            return _symbol;
        }
    }
    else {
        return _symbol;
    }
}
#else
// other compiler environment: no demangling
std::string demangle(const std::string& _symbol)
207
{
208 209 210
    return _symbol;
}
#endif
211

212 213 214 215
void backtrace()
{
    void *addresses[20];
    char **strings;
Jan Möbius's avatar
Jan Möbius committed
216

217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240
    int size = backtrace(addresses, 20);
    strings = backtrace_symbols(addresses, size);
    std::cerr << "Stack frames: " << size << std::endl;
    // line format:
    // <path>(<mangled_name>+<offset>) [<address>]
    std::regex line_format{R"(^\s*(.+)\((([^()]+)?\+(0x[0-9a-f]+))?\)\s+\[(0x[0-9a-f]+)\]\s*$)"};
    for(int i = 0; i < size; i++) {
        std::string line{strings[i]};
        std::smatch match;
        std::regex_match(line, match, line_format);
        if (!match.empty()) {
            auto file_name = match[1].str();
            auto symbol = demangle(match[3].str());
            auto offset = match[4].str();
            auto address = match[5].str();
            std::cerr << i << ":";
            if (!file_name.empty()) std::cerr << " " << file_name << " ::";
            if (!symbol.empty()) std::cerr << " " << symbol;
            if (!offset.empty()) std::cerr << " (+" << offset << ")";
            if (!address.empty()) std::cerr << " [" << address << "]";
            std::cerr << std::endl;
        }
    }
    free(strings);
241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279
}
#endif

/* ==========================================================
 *
 * General segfault handler. This function is called if OpenFlipper
 * crashes
 *
 * ==========================================================*/
void segfaultHandling (int) {

  // prevent infinite recursion if segfaultHandling() causes another segfault
  std::signal(SIGSEGV, SIG_DFL);


  std::cerr << "\n" << std::endl;
  std::cerr << "\n" << std::endl;
  std::cerr << "\33[31m" << "=====================================================" << std::endl;
  std::cerr << "\33[31m" << "OpenFlipper or one of its plugins caused a Segfault." << std::endl;
  std::cerr << "\33[31m" << "This should not happen,... Sorry :-(" << std::endl;
  std::cerr << "\33[31m" << "=====================================================" << std::endl;
  std::cerr << "\n" << std::endl;

  // Linux Handler
#ifndef NO_EXECINFO
  std::cerr << "\33[0m"  << "Trying a backtrace to show what happened last: " << std::endl;
  backtrace();

  std::cerr << "\n" << std::endl;
  std::cerr << "Backtrace completed, trying to abort now ..." << std::endl;
#endif

  // Windows handler via StackWalker
#ifdef WIN32
  StackWalkerToConsole sw;
  sw.ShowCallstack();
#endif


Jan Möbius's avatar
Jan Möbius committed
280 281 282 283 284 285 286 287
  std::cerr << "Trying to get additional information (This might fail if the memory is corrupted)." << std::endl;

  if (OpenFlipper::Options::gui()) {
    for ( unsigned int i = 0 ; i <  4 ; ++i) {
      std::cerr << "DrawMode Viewer "<<  i << " " << PluginFunctions::drawMode(i).description() << std::endl;
    }
  }

288 289
  std::abort();
}
290

291 292 293 294 295 296
enum CommandLineParseResult
{
    CommandLineOk,
    CommandLineError,
    CommandLineVersionRequested,
    CommandLineHelpRequested
Jan Möbius's avatar
 
Jan Möbius committed
297 298
};

299

300 301
bool openPolyMeshes = false;
bool remoteControl  = false;
302

303 304
// Parse all options
CommandLineParseResult parseCommandLine(QCommandLineParser &parser, QString *errorMessage) {
305

306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362
  #ifndef WIN32
  #ifndef __APPLE__
    //workaround for bug with stereo mode on Qt5.7.0 and Qt5.7.1 on Linux
    int QtVersionMajor, QtVersionMinor, QtVersionPatch;
    if(sscanf(qVersion(),"%1d.%1d.%1d",&QtVersionMajor, &QtVersionMinor, &QtVersionPatch) == 3)
    {
      if(QtVersionMajor == 5 && QtVersionMinor >= 7)
      {
        if(QtVersionPatch < 2)
        {
          std::cerr << "The used Qt Version does not support stereo mode. Disabling stereo mode." << std::endl;
          OpenFlipper::Options::stereo(false);
        }
        else
          std::cerr << "Stereo Mode has not been tested for the used Qt Version." << std::endl;
      }
    }
  #endif
  #endif


 parser.setSingleDashWordOptionMode(QCommandLineParser::ParseAsLongOptions);

 parser.addOptions({
        {{"d", "debug"},
            QCoreApplication::translate("main", "Enable debugging mode")},
        {"disable-stereo",
            QCoreApplication::translate("main", "Disable stereo mode")},
        {{"b", "batch"},
            QCoreApplication::translate("main", "Batch mode, you have to provide a script for execution")},
        {{"c", "log-to-console"},
            QCoreApplication::translate("main", "Write logger window contents to console")},
        {"remote-control",
            QCoreApplication::translate("main", "Batch mode accepting remote connections")},
        {{"f", "fullscreen"},
            QCoreApplication::translate("main", "Start in fulscreen mode")},
        {{"l", "hide-logger"},
            QCoreApplication::translate("main", "Start with hidden log window")},
        {{"t", "hide-toolbox"},
            QCoreApplication::translate("main", "Start with hidden toolbox")},
        {"no-splash",
            QCoreApplication::translate("main", "Hide splash screen")},
        {"p",
            QCoreApplication::translate("main", "Open files as PolyMeshes")},
        {"remote-port",
            QCoreApplication::translate("main", "Remote port"),"portnumber"},
  });

  const QCommandLineOption helpOption = parser.addHelpOption();
  const QCommandLineOption versionOption = parser.addVersionOption();


  // Now parse the command line
  if (!parser.parse(QCoreApplication::arguments())) {
    *errorMessage = parser.errorText();
    return CommandLineError;
  }
363

364 365
  if (parser.isSet(helpOption))
      return CommandLineHelpRequested;
366

367 368
  if (parser.isSet(versionOption))
      return CommandLineVersionRequested;
Jan Möbius's avatar
 
Jan Möbius committed
369

370 371 372
  if (parser.isSet("debug")) {
    OpenFlipper::Options::debug(true);
  }
Jan Möbius's avatar
 
Jan Möbius committed
373

374 375 376
  if (parser.isSet("disable-stereo")) {
    OpenFlipper::Options::stereo(false);
  }
377

378 379 380
  if (parser.isSet("batch")) {
    OpenFlipper::Options::nogui(true);
  }
381

382 383 384
  if (parser.isSet("log-to-console")) {
    OpenFlipper::Options::logToConsole(true);
  }
385

386 387 388
  if (parser.isSet("remote-control")) {
    OpenFlipper::Options::remoteControl(true);
  }
389

390 391 392
  if (parser.isSet("fullscreen")) {
    OpenFlipperSettings().setValue("Core/Gui/fullscreen",true);
  }
393

394 395 396
  if (parser.isSet("hide-logger")) {
    OpenFlipper::Options::loggerState(OpenFlipper::Options::Hidden);
  }
397

398 399 400
  if (parser.isSet("hide-toolbox")) {
    OpenFlipperSettings().setValue("Core/Gui/ToolBoxes/hidden",true);
  }
401

402 403
  if (parser.isSet("no-splash")) {
    OpenFlipperSettings().setValue("Core/Gui/splash",false);
404
  }
405

406 407 408
  if (parser.isSet("p")) {
    openPolyMeshes = true;
  }
Dirk Wilden's avatar
Dirk Wilden committed
409

410
  if (parser.isSet("remote-port")) {
Jan Möbius's avatar
Jan Möbius committed
411
    const QString port = parser.value("remote-port");
412 413
    std::cerr << "Got port option : " << port.toStdString() << std::endl;
    OpenFlipper::Options::remoteControl(port.toInt());
Dirk Wilden's avatar
Dirk Wilden committed
414

Jan Möbius's avatar
 
Jan Möbius committed
415
  }
416 417

  return CommandLineOk;
Dirk Wilden's avatar
Dirk Wilden committed
418 419 420 421
}

int main(int argc, char **argv)
{
422

423 424
  // Remove -psn_0_xxxxx argument which is automatically
  // attached by MacOSX
Mike Kremer's avatar
 
Mike Kremer committed
425
  for (int i = 0; i < argc; i++) {
426 427 428 429 430
    if(strlen(argv[i]) > 4) {
      if( ( (argv[i])[0] == '-' ) &&
        ( (argv[i])[1] == 'p' ) &&
        ( (argv[i])[2] == 's' ) &&
        ( (argv[i])[3] == 'n' ) ) {
Jan Möbius's avatar
Jan Möbius committed
431 432
        argc--;
        argv[i] = (char *)"";
433 434 435
      }
    }
  }
Jan Möbius's avatar
Jan Möbius committed
436

Dirk Wilden's avatar
Dirk Wilden committed
437 438 439
  OpenFlipper::Options::argc(&argc);
  OpenFlipper::Options::argv(&argv);

440 441 442 443 444 445 446 447 448 449 450
  // Ugly command line parse to check if we run in batch mode or not.
  // Qt parser needs either QApplication or QCoreApplication to work.
  // But we need that option to decide which one to choose so ...
  for (int i = 1; i < argc; i++) {
     QString option = QString(argv[i]);
     if (option.contains("batch") || option.contains("-b") ||
         option.contains("--batch") || option.contains("/b") ||
         option.contains("/batch" )) {
       std::cerr << "Batch Mode started" << std::endl;
       OpenFlipper::Options::nogui(true);
     }
Dirk Wilden's avatar
Dirk Wilden committed
451

452 453 454 455
   }

  QCommandLineParser parser;
  QString errorMessage;
Dirk Wilden's avatar
Dirk Wilden committed
456

Dirk Wilden's avatar
Dirk Wilden committed
457

458
#ifndef NO_CATCH_SIGSEGV
Dirk Wilden's avatar
Dirk Wilden committed
459 460
  // Set a handler for segfaults
  std::signal(SIGSEGV, segfaultHandling);
461
#endif
Dirk Wilden's avatar
Dirk Wilden committed
462

Jan Möbius's avatar
Jan Möbius committed
463
  OpenFlipper::Options::windowTitle(TOSTRING(PRODUCT_STRING)" v" + OpenFlipper::Options::coreVersion());
464

Jan Möbius's avatar
 
Jan Möbius committed
465
  if ( !OpenFlipper::Options::nogui() ) {
466

Jan Möbius's avatar
 
Jan Möbius committed
467 468 469
    // OpenGL check
    QApplication::setColorSpec( QApplication::CustomColor );
    QApplication app(argc,argv);
470

471
#ifdef __APPLE__
Mike Kremer's avatar
Mike Kremer committed
472
    // Set organization and application names
473 474 475 476
    QCoreApplication::setOrganizationName("rwth-aachen.de");
    QCoreApplication::setApplicationName("graphics.openflipper");
#endif

Jan Möbius's avatar
 
Jan Möbius committed
477 478 479 480
    if ( !QGLFormat::hasOpenGL() ) {
      std::cerr << "This system has no OpenGL support.\n";
      return -1;
    }
481

482
#ifndef __APPLE__
Jan Möbius's avatar
 
Jan Möbius committed
483
    glutInit(&argc,argv);
484
#endif
485

Jan Möbius's avatar
 
Jan Möbius committed
486 487
    // create core ( this also reads the ini files )
    Core * w = new Core( );
488

489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505

    switch (parseCommandLine(parser, &errorMessage)) {
      case CommandLineOk:
        break;
      case CommandLineError:
        fputs(qPrintable(errorMessage), stderr);
        fputs("\n\n", stderr);
        fputs(qPrintable(parser.helpText()), stderr);
        delete w;
        return 1;
      case CommandLineVersionRequested:
        printf("%s %s\n", qPrintable(QCoreApplication::applicationName()),
            qPrintable(QCoreApplication::applicationVersion()));
        return 0;
      case CommandLineHelpRequested:
        parser.showHelp();
        Q_UNREACHABLE();
Jan Möbius's avatar
Jan Möbius committed
506
    }
507

Marti's avatar
Marti committed
508
#ifdef WIN32
509
	//attach a console if necessary
Martin Schultz's avatar
Martin Schultz committed
510
	attachConsole();
Marti's avatar
Marti committed
511
#endif
Dirk Wilden's avatar
Dirk Wilden committed
512

513
    QString tLang = OpenFlipperSettings().value("Core/Language/Translation","en_US").toString();
514 515 516 517

    if (tLang == "locale")
      tLang = QLocale::system().name();

518 519
    // Install translator for qt internals
    QTranslator qtTranslator;
Jan Möbius's avatar
Jan Möbius committed
520 521 522 523 524 525 526
//     std::cerr << "Loading qt translations from: " << QLibraryInfo::location(QLibraryInfo::TranslationsPath).toStdString() << std::endl;
//     if ( qtTranslator.load("qt_" + tLang, QLibraryInfo::location(QLibraryInfo::TranslationsPath)) )
//       std::cerr << "Loaded" << std::endl;
//     std::cerr << "Loading qt translations from: " << QLibraryInfo::location(QLibraryInfo::TranslationsPath).toStdString() << std::endl;
    qtTranslator.load("qt_" + tLang, QLibraryInfo::location(QLibraryInfo::TranslationsPath));
//       std::cerr << "Loaded" << std::endl;

527 528 529
    app.installTranslator(&qtTranslator);
    
    // install translator for Core Application
Dirk Wilden's avatar
Dirk Wilden committed
530
    QString translationDir = OpenFlipper::Options::translationsDirStr() + QDir::separator();
531

Jan Möbius's avatar
Jan Möbius committed
532
//     std::cerr << "Loading own translations from: " << QString(translationDir + " (" + tLang + ")").toStdString() << std::endl;
Dirk Wilden's avatar
Dirk Wilden committed
533 534 535 536 537 538 539 540 541 542 543 544 545

    QDir dir(translationDir);
    dir.setFilter(QDir::Files);

    QFileInfoList list = dir.entryInfoList();

    for (int i = 0; i < list.size(); ++i) {
      QFileInfo fileInfo = list.at(i);

      if ( fileInfo.baseName().contains(tLang) ){
        QTranslator* myAppTranslator = new QTranslator();

        if ( myAppTranslator->load( fileInfo.filePath() ) ){
Jan Möbius's avatar
Jan Möbius committed
546
//           std::cerr << "Loaded " << fileInfo.fileName().toStdString() << std::endl;
547
    
Dirk Wilden's avatar
Dirk Wilden committed
548
          app.installTranslator(myAppTranslator);
Jan Möbius's avatar
Jan Möbius committed
549 550
        } else {
  	  delete myAppTranslator;
Dirk Wilden's avatar
Dirk Wilden committed
551 552 553
        }
      }
     }
Jan's avatar
Jan committed
554
    
555
    // After setting all Options from command line, build the real gui
Jan's avatar
Jan committed
556 557 558 559 560
    w->init();

    #ifndef __APPLE__
    initGlew();
    #endif
Jan Möbius's avatar
Jan Möbius committed
561
 
562 563 564 565 566
    const QStringList positionalArguments = parser.positionalArguments();

    for ( auto file: positionalArguments ) {
      w->commandLineOpen(file, openPolyMeshes);
    }
567

Jan Möbius's avatar
 
Jan Möbius committed
568
    return app.exec();
569

Jan Möbius's avatar
 
Jan Möbius committed
570
  } else {
571

Jan Möbius's avatar
 
Jan Möbius committed
572
    QCoreApplication app(argc,argv);
573

574
#ifdef __APPLE__
Mike Kremer's avatar
Mike Kremer committed
575
    // Set organization and application names
576 577 578 579
    QCoreApplication::setOrganizationName("rwth-aachen.de");
    QCoreApplication::setApplicationName("graphics.openflipper");
#endif

Jan Möbius's avatar
 
Jan Möbius committed
580 581
    // create widget ( this also reads the ini files )
    Core * w = new Core( );
582

583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598
    switch (parseCommandLine(parser, &errorMessage)) {
      case CommandLineOk:
        break;
      case CommandLineError:
        fputs(qPrintable(errorMessage), stderr);
        fputs("\n\n", stderr);
        fputs(qPrintable(parser.helpText()), stderr);
        delete w;
        return 1;
      case CommandLineVersionRequested:
        printf("%s %s\n", qPrintable(QCoreApplication::applicationName()),
            qPrintable(QCoreApplication::applicationVersion()));
        return 0;
      case CommandLineHelpRequested:
        parser.showHelp();
        Q_UNREACHABLE();
Jan Möbius's avatar
Jan Möbius committed
599
    }
Dirk Wilden's avatar
Dirk Wilden committed
600

Jan Möbius's avatar
 
Jan Möbius committed
601 602
    // After setting all Options from command line, build the real gui
    w->init();
603

604 605 606 607 608
    const QStringList positionalArguments = parser.positionalArguments();

    for ( auto file: positionalArguments ) {
      w->commandLineOpen(file, openPolyMeshes);
    }
609

Dirk Wilden's avatar
Dirk Wilden committed
610
    return app.exec();
Jan Möbius's avatar
 
Jan Möbius committed
611 612 613 614
  }

  return 0;
}