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
120 #ifdef WIN_GET_DEBUG_CONSOLE
125 HANDLE ConsoleOutput = GetStdHandle(STD_OUTPUT_HANDLE);
126 int SystemOutput = _open_osfhandle(intptr_t(ConsoleOutput), _O_TEXT);
127 FILE *COutputHandle = _fdopen(SystemOutput,
"w" );
128 *stdout = *COutputHandle;
129 setvbuf(stdout, NULL, _IONBF, 0);
131 HANDLE ConsoleError = GetStdHandle(STD_ERROR_HANDLE);
132 int SystemError = _open_osfhandle(intptr_t(ConsoleError), _O_TEXT);
133 FILE *CErrorHandle = _fdopen(SystemError,
"w" );
134 *stderr = *CErrorHandle;
135 setvbuf(stderr, NULL, _IONBF, 0);
137 HANDLE ConsoleInput = GetStdHandle(STD_INPUT_HANDLE);
138 int SystemInput = _open_osfhandle(intptr_t(ConsoleInput), _O_TEXT);
139 FILE *CInputHandle = _fdopen(SystemInput,
"r" );
140 *stdin = *CInputHandle;
141 setvbuf(stdin, NULL, _IONBF, 0);
157 int size = backtrace(addresses, 20);
158 strings = backtrace_symbols(addresses, size);
159 std::cerr <<
"Stack frames: " << size << std::endl;
160 for(
int i = 0; i < size; i++)
161 std::cerr << i <<
": " << strings[i] << std::endl;
173 void segfaultHandling (
int) {
176 std::signal(SIGSEGV, SIG_DFL);
179 std::cerr <<
"\n" << std::endl;
180 std::cerr <<
"\n" << std::endl;
181 std::cerr <<
"\33[31m" <<
"=====================================================" << std::endl;
182 std::cerr <<
"\33[31m" <<
"OpenFlipper or one of its plugins caused a Segfault." << std::endl;
183 std::cerr <<
"\33[31m" <<
"This should not happen,... Sorry :-(" << std::endl;
184 std::cerr <<
"\33[31m" <<
"=====================================================" << std::endl;
185 std::cerr <<
"\n" << std::endl;
189 std::cerr <<
"\33[0m" <<
"Trying a backtrace to show what happened last: " << std::endl;
192 std::cerr <<
"\n" << std::endl;
193 std::cerr <<
"Backtrace completed, trying to abort now ..." << std::endl;
198 StackWalkerToConsole sw;
203 std::cerr <<
"Trying to get additional information (This might fail if the memory is corrupted)." << std::endl;
205 if (OpenFlipper::Options::gui()) {
206 for (
unsigned int i = 0 ; i < 4 ; ++i) {
214 enum {OPT_HELP , OPT_STEREO, OPT_BATCH ,OPT_CONSOLE_LOG , OPT_DEBUGGING, OPT_FULLSCREEN,
215 OPT_HIDDDEN_LOGGER , OPT_NOSPLASH ,OPT_HIDDDEN_TOOLBOX , OPT_LOAD_POLYMESHES,
216 OPT_REMOTE, OPT_REMOTE_PORT};
218 CSimpleOpt::SOption g_rgOptions[] = {
219 { OPT_DEBUGGING , (
char*)
"--debug" , SO_NONE },
220 { OPT_HELP , (
char*)
"-?" , SO_NONE },
221 { OPT_HELP , (
char*)
"--help" , SO_NONE },
222 { OPT_HELP , (
char*)
"-h" , SO_NONE },
223 { OPT_STEREO , (
char*)
"--disable-stereo" , SO_NONE },
224 { OPT_BATCH , (
char*)
"-b" , SO_NONE },
225 { OPT_CONSOLE_LOG , (
char*)
"-c" , SO_NONE },
226 { OPT_CONSOLE_LOG , (
char*)
"--log-to-console" , SO_NONE },
227 { OPT_FULLSCREEN , (
char*)
"-f" , SO_NONE },
228 { OPT_HIDDDEN_LOGGER , (
char*)
"-l" , SO_NONE },
229 { OPT_NOSPLASH , (
char*)
"--no-splash" , SO_NONE },
230 { OPT_HIDDDEN_TOOLBOX , (
char*)
"-t" , SO_NONE },
231 { OPT_LOAD_POLYMESHES , (
char*)
"-p" , SO_NONE },
232 { OPT_REMOTE , (
char*)
"--remote-control" , SO_NONE },
233 { OPT_REMOTE_PORT , (
char*)
"--remote-port" , SO_REQ_SEP },
238 std::cerr <<
"OpenFlipper [Options] <filenames> " << std::endl << std::endl;;
239 std::cerr <<
"Possible Options : " << std::endl;
240 std::cerr << std::endl;
242 std::cerr <<
"Load/Save Options:" << std::endl;
243 std::cerr <<
" -p \t: Open files as PolyMeshes" << std::endl;
244 std::cerr << std::endl;
246 std::cerr <<
"Gui Options:" << std::endl;
247 std::cerr <<
" -f \t\t: Start Fullscreen" << std::endl;
248 std::cerr <<
" -l \t\t: Start with hidden logger" << std::endl;
249 std::cerr <<
" -t \t\t: Start with hidden Toolbox" << std::endl;
250 std::cerr <<
" --no-splash \t: Disable splash screen" << std::endl;
252 std::cerr <<
" --disable-stereo \t: Disable Stereo Mode" << std::endl;
253 std::cerr << std::endl;
255 std::cerr <<
"Log options:" << std::endl;
256 std::cerr <<
" --log-to-console ( -c ) \t: Write logger window contents to console" << std::endl;
257 std::cerr << std::endl;
259 std::cerr <<
"Other options:" << std::endl;
260 std::cerr <<
" -b \t: Batch mode, you have to provide a script for execution" << std::endl;
261 std::cerr <<
" --remote-control \t: Batch mode accepting remote connections" << std::endl;
263 std::cerr << std::endl;
266 std::cerr <<
" -h \t: This help" << std::endl;
274 bool openPolyMeshes =
false;
275 bool remoteControl =
false;
277 bool parseCommandLineOptions(CSimpleOpt& args){
282 while (args.Next()) {
284 if (args.LastError() == SO_SUCCESS) {
286 switch (args.OptionId() ) {
288 OpenFlipper::Options::nogui(
true);
290 case OPT_CONSOLE_LOG:
291 OpenFlipper::Options::logToConsole(
true);
294 OpenFlipper::Options::debug(
true);
297 OpenFlipper::Options::stereo(
false);
299 case OPT_HIDDDEN_TOOLBOX:
302 case OPT_HIDDDEN_LOGGER:
303 OpenFlipper::Options::loggerState(OpenFlipper::Options::Hidden);
308 case OPT_LOAD_POLYMESHES:
309 openPolyMeshes =
true;
315 OpenFlipper::Options::remoteControl(
true);
317 case OPT_REMOTE_PORT:
318 port = args.OptionArg();
319 std::cerr <<
"Got option : " << port.toStdString() << std::endl;
320 OpenFlipper::Options::remoteControl(port.toInt());
327 std::cerr <<
"Invalid argument: " << args.OptionText() << std::endl;
335 int main(
int argc,
char **argv)
340 for (
int i = 0; i < argc; i++) {
341 if(strlen(argv[i]) > 4) {
342 if( ( (argv[i])[0] ==
'-' ) &&
343 ( (argv[i])[1] ==
'p' ) &&
344 ( (argv[i])[2] ==
's' ) &&
345 ( (argv[i])[3] ==
'n' ) ) {
347 argv[i] = (
char *)
"";
352 OpenFlipper::Options::argc(&argc);
353 OpenFlipper::Options::argv(&argv);
355 CSimpleOpt argBatch(argc, argv, g_rgOptions);
358 while (argBatch.Next())
359 if (argBatch.OptionId() == OPT_BATCH ){
360 OpenFlipper::Options::nogui(
true);
364 CSimpleOpt args(argc, argv, g_rgOptions);
366 #ifndef NO_CATCH_SIGSEGV
368 std::signal(SIGSEGV, segfaultHandling);
371 OpenFlipper::Options::windowTitle(
TOSTRING(PRODUCT_STRING)
" v" + OpenFlipper::Options::coreVersion());
374 #ifdef WIN_GET_DEBUG_CONSOLE
379 if ( !OpenFlipper::Options::nogui() ) {
382 QApplication::setColorSpec( QApplication::CustomColor );
383 QApplication app(argc,argv);
387 QCoreApplication::setOrganizationName(
"rwth-aachen.de");
388 QCoreApplication::setApplicationName(
"graphics.openflipper");
391 if ( !QGLFormat::hasOpenGL() ) {
392 std::cerr <<
"This system has no OpenGL support.\n";
397 glutInit(&argc,argv);
403 if ( !parseCommandLineOptions(args) ) {
410 if (tLang ==
"locale")
411 tLang = QLocale::system().name();
414 QTranslator qtTranslator;
419 qtTranslator.load(
"qt_" + tLang, QLibraryInfo::location(QLibraryInfo::TranslationsPath));
422 app.installTranslator(&qtTranslator);
425 QString translationDir = OpenFlipper::Options::translationsDirStr() + QDir::separator();
429 QDir dir(translationDir);
430 dir.setFilter(QDir::Files);
432 QFileInfoList list = dir.entryInfoList();
434 for (
int i = 0; i < list.size(); ++i) {
435 QFileInfo fileInfo = list.at(i);
437 if ( fileInfo.baseName().contains(tLang) ){
438 QTranslator* myAppTranslator =
new QTranslator();
440 if ( myAppTranslator->load( fileInfo.filePath() ) ){
443 app.installTranslator(myAppTranslator);
445 delete myAppTranslator;
457 for (
int i = 0 ; i < args.FileCount(); ++i )
464 QCoreApplication app(argc,argv);
468 QCoreApplication::setOrganizationName(
"rwth-aachen.de");
469 QCoreApplication::setApplicationName(
"graphics.openflipper");
475 if ( !parseCommandLineOptions(args) ) {
483 for (
int i = 0 ; i < args.FileCount(); ++i )
DLLEXPORT OpenFlipperQSettings & OpenFlipperSettings()
QSettings object containing all program settings of OpenFlipper.
ACG::SceneGraph::DrawModes::DrawMode drawMode(int _viewer)
Get the current draw Mode of a Viewer.
void init()
Second initialization stage.
void commandLineOpen(const char *_filename, bool _asPolyMesh)
Load an object from the commandline on application start.
std::string description() const
#define TOSTRING(x)
QSettings object containing all program settings of OpenFlipper.
QVariant value(const QString &key, const QVariant &defaultValue=QVariant()) const
void commandLineScript(const char *_filename)
Load a script from the commandline on application start.
void setValue(const QString &key, const QVariant &value)
Wrapper function which makes it possible to enable Debugging output with -DOPENFLIPPER_SETTINGS_DEBUG...