Commit 8e109c0d authored by Christopher Tenter's avatar Christopher Tenter
Browse files

Merge branch 'master' into splatcloud_rendering

parents 8df0e672 05a7d830
......@@ -59,7 +59,7 @@ echo "CPPCHECK Summary"
echo "=============================================================================="
echo -e "${NC}"
MAX_ERROR=105
MAX_ERROR=100
if [ $COUNT -gt $MAX_ERROR ]; then
echo -e ${WARNING}
......
......@@ -835,7 +835,7 @@ private slots:
* the current path will be prepended.
* @param _asPolyMesh Load as a polymesh ( yes/no)
*/
void commandLineOpen(const char* _filename, bool _asPolyMesh );
void commandLineOpen(const QString& _filename, bool _asPolyMesh );
/** \brief Load a script from the commandline on application start
*
......@@ -847,7 +847,7 @@ private slots:
* @param _filename filename of the script to be opened. If it does not contain a full path,
* the current path will be prepended.
*/
void commandLineScript(const char* _filename );
void commandLineScript(const QString& _filename );
private slots:
......@@ -861,10 +861,10 @@ private slots:
private:
/// Vector storing filenames from commandline to be opened after application startup (objects)
std::vector< std::pair < std::string , bool > > commandLineFileNames_;
std::vector< std::pair < QString , bool > > commandLineFileNames_;
/// Vector storing filenames from commandline to be opened after application startup (script files)
std::vector< std::string > commandLineScriptNames_;
std::vector< QString > commandLineScriptNames_;
public:
......
......@@ -99,9 +99,9 @@ void Core::slotGetAllFilters ( QStringList& _list){
}
}
void Core::commandLineOpen(const char* _filename, bool _asPolyMesh ){
void Core::commandLineOpen(const QString& _filename, bool _asPolyMesh ){
QString file(_filename);
QString file = _filename;
// Modify filename to contain full paths if they were given as relative paths
if ( !file.startsWith("/") && !file.contains(":") ) {
......@@ -111,12 +111,12 @@ void Core::commandLineOpen(const char* _filename, bool _asPolyMesh ){
}
// Add to the open list
commandLineFileNames_.push_back(std::pair< std::string , bool >(file.toStdString(), _asPolyMesh));
commandLineFileNames_.push_back(std::pair< QString , bool >(file, _asPolyMesh));
}
void Core::commandLineScript(const char* _filename ) {
void Core::commandLineScript(const QString& _filename ) {
QString file(_filename);
QString file = _filename;
// Modify filename to contain full paths if they were given as relative paths
if ( !file.startsWith("/") && !file.contains(":") ) {
......@@ -126,7 +126,7 @@ void Core::commandLineScript(const char* _filename ) {
}
// Add to the open list
commandLineScriptNames_.push_back(file.toStdString());
commandLineScriptNames_.push_back(file);
}
void Core::slotExecuteAfterStartup() {
......@@ -168,7 +168,7 @@ void Core::slotExecuteAfterStartup() {
for ( uint i = 0 ; i < commandLineFileNames_.size() ; ++i ) {
// Skip scripts here as they will be handled by a different function
QString tmp = QString::fromStdString(commandLineFileNames_[i].first);
QString tmp = commandLineFileNames_[i].first;
if ( tmp.endsWith("ofs",Qt::CaseInsensitive) ) {
commandLineScriptNames_.push_back(commandLineFileNames_[i].first);
continue;
......@@ -176,9 +176,9 @@ void Core::slotExecuteAfterStartup() {
// If the file was given with the polymesh option, open them as polymeshes.
if (commandLineFileNames_[i].second)
loadObject(typeId("PolyMesh"), QString::fromStdString(commandLineFileNames_[i].first));
loadObject(typeId("PolyMesh"), commandLineFileNames_[i].first);
else {
loadObject(QString::fromStdString(commandLineFileNames_[i].first));
loadObject(commandLineFileNames_[i].first);
}
}
......@@ -190,7 +190,7 @@ void Core::slotExecuteAfterStartup() {
// If we have scripting support, execute the scripts given at the commandline.
if ( scriptingSupport )
for ( uint i = 0 ; i < commandLineScriptNames_.size() ; ++i ) {
emit executeFileScript(QString::fromStdString(commandLineScriptNames_[i]));
emit executeFileScript(commandLineScriptNames_[i]);
}
// If we don't have a gui and we are not under remote control,
......
......@@ -54,7 +54,6 @@ set (directories
../Scripting
../Scripting/scriptPrototypes
../Scripting/scriptWrappers
../SimpleOpt
../widgets/aboutWidget
../widgets/addEmptyWidget
../widgets/loggerWidget
......
......@@ -60,7 +60,8 @@
// stdc++
#include <csignal>
#include <regex>
#include <OpenFlipper/SimpleOpt/SimpleOpt.h>
#include <QCommandLineParser>
#if ( defined(WIN32))
#define NO_EXECINFO
......@@ -110,62 +111,44 @@
#ifdef WIN32
void connect_console()
{
FILE* check = freopen("CONIN$", "r", stdin);
if (check) {
std::cerr << "Error reopening stdin" << std::endl;
}
check = freopen("CONOUT$", "w", stdout);
if (check) {
std::cerr << "Error reopening stdout" << std::endl;
}
check = freopen("CONOUT$", "w", stderr);
if (check) {
std::cerr << "Error reopening stderr" << std::endl;
}
}
void attachConsole()
{
//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;
}
check = freopen("CONOUT$", "w", stdout);
if (check) {
std::cerr << "Error reopening stdout" << std::endl;
}
check = freopen("CONOUT$", "w", stderr);
if (check) {
std::cerr << "Error reopening stderr" << std::endl;
}
connect_console();
}
else
{
//create and attach a new console if needed
#ifndef NDEBUG
//always open a console in debug mode
AllocConsole();
AllocConsole();
connect_console();
FILE* check = freopen("CONIN$", "r", stdin);
if (check) {
std::cerr << "Error reopening stdin" << std::endl;
}
check = freopen("CONOUT$", "w", stdout);
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;
}
check = freopen("CONOUT$", "w", stdout);
if (check) {
std::cerr << "Error reopening stdout" << std::endl;
}
check = freopen("CONOUT$", "w", stderr);
if (check) {
std::cerr << "Error reopening stderr" << std::endl;
}
connect_console();
}
}
}
......@@ -287,145 +270,142 @@ void segfaultHandling (int) {
std::abort();
}
enum {OPT_HELP , OPT_STEREO, OPT_BATCH ,OPT_CONSOLE_LOG , OPT_DEBUGGING, OPT_FULLSCREEN,
OPT_HIDDDEN_LOGGER , OPT_NOSPLASH ,OPT_HIDDDEN_TOOLBOX , OPT_LOAD_POLYMESHES,
OPT_REMOTE, OPT_REMOTE_PORT};
CSimpleOpt::SOption g_rgOptions[] = {
{ OPT_DEBUGGING , (char*) "--debug" , SO_NONE },
{ OPT_HELP , (char*) "-?" , SO_NONE },
{ OPT_HELP , (char*) "--help" , SO_NONE },
{ OPT_HELP , (char*) "-h" , SO_NONE },
{ OPT_STEREO , (char*) "--disable-stereo" , SO_NONE },
{ OPT_BATCH , (char*) "-b" , SO_NONE },
{ OPT_CONSOLE_LOG , (char*) "-c" , SO_NONE },
{ OPT_CONSOLE_LOG , (char*) "--log-to-console" , SO_NONE },
{ OPT_FULLSCREEN , (char*) "-f" , SO_NONE },
{ OPT_HIDDDEN_LOGGER , (char*) "-l" , SO_NONE },
{ OPT_NOSPLASH , (char*) "--no-splash" , SO_NONE },
{ OPT_HIDDDEN_TOOLBOX , (char*) "-t" , SO_NONE },
{ OPT_LOAD_POLYMESHES , (char*) "-p" , SO_NONE },
{ OPT_REMOTE , (char*) "--remote-control" , SO_NONE },
{ OPT_REMOTE_PORT , (char*) "--remote-port" , SO_REQ_SEP },
SO_END_OF_OPTIONS // END
enum CommandLineParseResult
{
CommandLineOk,
CommandLineError,
CommandLineVersionRequested,
CommandLineHelpRequested
};
void showHelp() {
std::cerr << "OpenFlipper [Options] <filenames> " << std::endl << std::endl;;
std::cerr << "Possible Options : " << std::endl;
std::cerr << std::endl;
std::cerr << "Load/Save Options:" << std::endl;
std::cerr << " -p \t: Open files as PolyMeshes" << std::endl;
std::cerr << std::endl;
bool openPolyMeshes = false;
bool remoteControl = false;
std::cerr << "Gui Options:" << std::endl;
std::cerr << " -f \t\t: Start Fullscreen" << std::endl;
std::cerr << " -l \t\t: Start with hidden logger" << std::endl;
std::cerr << " -t \t\t: Start with hidden Toolbox" << std::endl;
std::cerr << " --no-splash \t: Disable splash screen" << std::endl;
// Parse all options
CommandLineParseResult parseCommandLine(QCommandLineParser &parser, QString *errorMessage) {
std::cerr << " --disable-stereo \t: Disable Stereo Mode" << std::endl;
std::cerr << std::endl;
#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
std::cerr << "Log options:" << std::endl;
std::cerr << " --log-to-console ( -c ) \t: Write logger window contents to console" << std::endl;
std::cerr << std::endl;
std::cerr << "Other options:" << std::endl;
std::cerr << " -b \t: Batch mode, you have to provide a script for execution" << std::endl;
std::cerr << " --remote-control \t: Batch mode accepting remote connections" << std::endl;
parser.setSingleDashWordOptionMode(QCommandLineParser::ParseAsLongOptions);
std::cerr << std::endl;
QCommandLineOption debugOption(QStringList() << "d" << "debug",QCoreApplication::translate("main", "Enable debugging mode"));
parser.addOption(debugOption);
std::cerr << " -h \t: This help" << std::endl;
}
QCommandLineOption stereoOption("disable-stereo",QCoreApplication::translate("main", "Disable stereo mode"));
parser.addOption(stereoOption);
QCommandLineOption batchOption(QStringList() << "b" << "batch",QCoreApplication::translate("main", "Batch mode, you have to provide a script for execution"));
parser.addOption(batchOption);
QCommandLineOption logConsoleOption(QStringList() << "c" << "log-to-console",QCoreApplication::translate("main", "Write logger window contents to console"));
parser.addOption(logConsoleOption);
QCommandLineOption remoteControlOption("remote-control",QCoreApplication::translate("main", "Batch mode accepting remote connections"));
parser.addOption(remoteControlOption);
QCommandLineOption fulscreenOption(QStringList() << "f" << "fullscreen",QCoreApplication::translate("main", "Start in fullscreen mode"));
parser.addOption(fulscreenOption);
QCommandLineOption hideLoggerOption(QStringList() << "l" << "hide-logger",QCoreApplication::translate("main", "Start with hidden log window"));
parser.addOption(hideLoggerOption);
bool openPolyMeshes = false;
bool remoteControl = false;
QCommandLineOption hideToolboxOption(QStringList() << "t" << "hide-toolbox",QCoreApplication::translate("main", "Start with hidden toolbox"));
parser.addOption(hideToolboxOption);
bool parseCommandLineOptions(CSimpleOpt& args){
QCommandLineOption noSplashOption("no-splash",QCoreApplication::translate("main", "Hide splash screen"));
parser.addOption(noSplashOption);
QString port;
QCommandLineOption polyMeshOption("p",QCoreApplication::translate("main", "Open files as PolyMeshes"));
parser.addOption(polyMeshOption);
#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
QCommandLineOption remotePortOption("remote-port",QCoreApplication::translate("main", "Remote port"),"portnumber");
parser.addOption(remotePortOption);
// while there are arguments left to process
while (args.Next()) {
const QCommandLineOption helpOption = parser.addHelpOption();
const QCommandLineOption versionOption = parser.addVersionOption();
if (args.LastError() == SO_SUCCESS) {
switch (args.OptionId() ) {
case OPT_BATCH:
OpenFlipper::Options::nogui(true);
break;
case OPT_CONSOLE_LOG:
OpenFlipper::Options::logToConsole(true);
break;
case OPT_DEBUGGING:
OpenFlipper::Options::debug(true);
break;
case OPT_STEREO:
OpenFlipper::Options::stereo(false);
break;
case OPT_HIDDDEN_TOOLBOX:
OpenFlipperSettings().setValue("Core/Gui/ToolBoxes/hidden",true);
break;
case OPT_HIDDDEN_LOGGER:
OpenFlipper::Options::loggerState(OpenFlipper::Options::Hidden);
break;
case OPT_FULLSCREEN:
OpenFlipperSettings().setValue("Core/Gui/fullscreen",false);
break;
case OPT_LOAD_POLYMESHES:
openPolyMeshes = true;
break;
case OPT_NOSPLASH:
OpenFlipperSettings().setValue("Core/Gui/splash",false);
break;
case OPT_REMOTE:
OpenFlipper::Options::remoteControl(true);
break;
case OPT_REMOTE_PORT:
port = args.OptionArg();
std::cerr << "Got option : " << port.toStdString() << std::endl;
OpenFlipper::Options::remoteControl(port.toInt());
break;
case OPT_HELP:
showHelp();
return 0;
}
} else {
std::cerr << "Invalid argument: " << args.OptionText() << std::endl;
showHelp();
return false;
}
}
return true;
// Now parse the command line
if (!parser.parse(QCoreApplication::arguments())) {
*errorMessage = parser.errorText();
return CommandLineError;
}
if (parser.isSet(helpOption))
return CommandLineHelpRequested;
if (parser.isSet(versionOption))
return CommandLineVersionRequested;
if (parser.isSet(debugOption)) {
OpenFlipper::Options::debug(true);
}
if (parser.isSet(stereoOption)) {
OpenFlipper::Options::stereo(false);
}
if (parser.isSet(batchOption)) {
OpenFlipper::Options::nogui(true);
}
if (parser.isSet(logConsoleOption)) {
OpenFlipper::Options::logToConsole(true);
}
if (parser.isSet(remoteControlOption)) {
OpenFlipper::Options::remoteControl(true);
}
if (parser.isSet(fulscreenOption)) {
OpenFlipperSettings().setValue("Core/Gui/fullscreen",true);
}
if (parser.isSet(hideLoggerOption)) {
OpenFlipper::Options::loggerState(OpenFlipper::Options::Hidden);
}
if (parser.isSet(hideToolboxOption)) {
OpenFlipperSettings().setValue("Core/Gui/ToolBoxes/hidden",true);
}
if (parser.isSet(noSplashOption)) {
OpenFlipperSettings().setValue("Core/Gui/splash",false);
}
if (parser.isSet(polyMeshOption)) {
openPolyMeshes = true;
}
if (parser.isSet(remotePortOption)) {
const QString port = parser.value("remote-port");
std::cerr << "Got port option : " << port.toStdString() << std::endl;
OpenFlipper::Options::remoteControl(port.toInt());
}
return CommandLineOk;
}
int main(int argc, char **argv)
......@@ -448,16 +428,26 @@ int main(int argc, char **argv)
OpenFlipper::Options::argc(&argc);
OpenFlipper::Options::argv(&argv);
CSimpleOpt argBatch(argc, argv, g_rgOptions);
// 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")) {
std::cerr << "Batch Mode started" << std::endl;
OpenFlipper::Options::nogui(true);
}
//check only batchMode before the core is created
while (argBatch.Next())
if (argBatch.OptionId() == OPT_BATCH ){
OpenFlipper::Options::nogui(true);
break;
}
}
CSimpleOpt args(argc, argv, g_rgOptions);
QCommandLineParser parser;
QString errorMessage;
#ifdef WIN32
//attach a console if necessary
attachConsole();
#endif
#ifndef NO_CATCH_SIGSEGV
// Set a handler for segfaults
......@@ -472,11 +462,10 @@ int main(int argc, char **argv)
QApplication::setColorSpec( QApplication::CustomColor );
QApplication app(argc,argv);
#ifdef __APPLE__
// Set organization and application names
QCoreApplication::setOrganizationName("rwth-aachen.de");
QCoreApplication::setApplicationName("graphics.openflipper");
#endif
QCoreApplication::setApplicationName(TOSTRING(PRODUCT_STRING));
QCoreApplication::setApplicationVersion(OpenFlipper::Options::coreVersion());
if ( !QGLFormat::hasOpenGL() ) {
std::cerr << "This system has no OpenGL support.\n";
......@@ -490,15 +479,24 @@ int main(int argc, char **argv)
// create core ( this also reads the ini files )
Core * w = new Core( );
if ( !parseCommandLineOptions(args) ) {
delete w;
return 1;
}
#ifdef WIN32
//attach a console if necessary
attachConsole();
#endif
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();
}
QString tLang = OpenFlipperSettings().value("Core/Language/Translation","en_US").toString();
......@@ -549,8 +547,11 @@ int main(int argc, char **argv)
initGlew();
#endif
for ( int i = 0 ; i < args.FileCount(); ++i )
w->commandLineOpen(args.File(i), openPolyMeshes);
const QStringList positionalArguments = parser.positionalArguments();
for ( auto file: positionalArguments ) {
w->commandLineOpen(file, openPolyMeshes);
}
return app.exec();
......@@ -558,25 +559,40 @@ int main(int argc, char **argv)
QCoreApplication app(argc,argv);
#ifdef __APPLE__
// Set organization and application names
QCoreApplication::setOrganizationName("rwth-aachen.de");
QCoreApplication::setApplicationName("graphics.openflipper");
#endif
QCoreApplication::setApplicationName(TOSTRING(PRODUCT_STRING));
QCoreApplication::setApplicationVersion(OpenFlipper::Options::coreVersion());
// create widget ( this also reads the ini files )
Core * w = new Core( );
if ( !parseCommandLineOptions(args) ) {
delete w;
return 1;
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();
}
// After setting all Options from command line, build the real gui
w->init();
for ( int i = 0 ; i < args.FileCount(); ++i )
w->commandLineScript(args.File(i));
const QStringList positionalArguments = parser.positionalArguments();
for ( auto file: positionalArguments ) {
w->commandLineOpen(file, openPolyMeshes);
}
return app.exec();
}
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.