diff --git a/common/lc_application.cpp b/common/lc_application.cpp index fbb07867..81530ea4 100644 --- a/common/lc_application.cpp +++ b/common/lc_application.cpp @@ -9,7 +9,7 @@ #include "lc_shortcuts.h" #include "view.h" -lcApplication* g_App; +lcApplication* gApplication; void lcPreferences::LoadDefaults() { @@ -41,11 +41,21 @@ void lcPreferences::SaveDefaults() lcSetProfileInt(LC_PROFILE_GRID_LINE_COLOR, mGridLineColor); } -lcApplication::lcApplication() +lcApplication::lcApplication(int Argc, char** Argv) + : QApplication(Argc, Argv) { +#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) + setApplicationDisplayName("LeoCAD"); +#endif + + setOrganizationDomain("leocad.org"); + setOrganizationName("LeoCAD Software"); + setApplicationName("LeoCAD"); + setApplicationVersion(LC_VERSION_TEXT); + + gApplication = this; mProject = nullptr; mLibrary = nullptr; - mClipboard = nullptr; mPreferences.LoadDefaults(); } @@ -54,6 +64,7 @@ lcApplication::~lcApplication() { delete mProject; delete mLibrary; + gApplication = nullptr; } void lcApplication::SetProject(Project* Project) @@ -115,44 +126,8 @@ bool lcApplication::LoadPartsLibrary(const QList>& LibraryP return false; } -void lcApplication::ParseIntegerArgument(int* CurArg, int argc, char* argv[], int* Value) const +bool lcApplication::Initialize(QList>& LibraryPaths, bool& ShowWindow) { - if (argc > (*CurArg + 1)) - { - (*CurArg)++; - int val; - - if ((sscanf(argv[(*CurArg)], "%d", &val) == 1) && (val > 0)) - *Value = val; - else - { - *Value = 0; - printf("Invalid value specified for the %s argument.\n", argv[(*CurArg) - 1]); - } - } - else - { - *Value = 0; - printf("Not enough parameters for the %s argument.\n", argv[(*CurArg)]); - } -} - -void lcApplication::ParseStringArgument(int* CurArg, int argc, char* argv[], const char** Value) const -{ - if (argc > (*CurArg + 1)) - { - (*CurArg)++; - *Value = argv[(*CurArg)]; - } - else - { - printf("No path specified after the %s argument.\n", argv[(*CurArg)]); - } -} - -bool lcApplication::Initialize(int argc, char* argv[], QList>& LibraryPaths, bool& ShowWindow) -{ - // todo: parse command line using Qt to handle multibyte strings. bool OnlyUseLibraryPaths = false; bool SaveImage = false; bool SaveWavefront = false; @@ -162,162 +137,142 @@ bool lcApplication::Initialize(int argc, char* argv[], QList(LibPath, false); - OnlyUseLibraryPaths = true; - } - } - else if ((strcmp(Param, "-i") == 0) || (strcmp(Param, "--image") == 0)) - { - SaveImage = true; - - if ((argc > (i+1)) && (argv[i+1][0] != '-')) - { - i++; - ImageName = argv[i]; - } - } - else if ((strcmp(Param, "-w") == 0) || (strcmp(Param, "--width") == 0)) - { - ParseIntegerArgument(&i, argc, argv, &ImageWidth); - } - else if ((strcmp(Param, "-h") == 0) || (strcmp(Param, "--height") == 0)) - { - ParseIntegerArgument(&i, argc, argv, &ImageHeight); - } - else if ((strcmp(Param, "-f") == 0) || (strcmp(Param, "--from") == 0)) - { - int Step; - ParseIntegerArgument(&i, argc, argv, &Step); - ImageStart = Step; - } - else if ((strcmp(Param, "-t") == 0) || (strcmp(Param, "--to") == 0)) - { - int Step; - ParseIntegerArgument(&i, argc, argv, &Step); - ImageEnd = Step; - } - else if ((strcmp(Param, "-m") == 0) || (strcmp(Param, "--model") == 0)) - { - if ((argc > (i+1)) && (argv[i+1][0] != '-')) - { - i++; - ModelName = argv[i]; - } - } - else if ((strcmp(Param, "-c") == 0) || (strcmp(Param, "--camera") == 0)) - { - if ((argc > (i+1)) && (argv[i+1][0] != '-')) - { - i++; - CameraName = argv[i]; - } - } - else if (strcmp(Param, "--viewpoint") == 0) - { - if ((argc > (i+1)) && (argv[i+1][0] != '-')) - { - i++; - Viewpoint = argv[i]; - } - } - else if (strcmp(Param, "--orthographic") == 0) - Orthographic = true; - else if (strcmp(Param, "--highlight") == 0) - ImageHighlight = true; - else if ((strcmp(Param, "-obj") == 0) || (strcmp(Param, "--export-wavefront") == 0)) - { - SaveWavefront = true; - - if ((argc > (i+1)) && (argv[i+1][0] != '-')) - { - i++; - SaveWavefrontName = argv[i]; - } - } - else if ((strcmp(Param, "-3ds") == 0) || (strcmp(Param, "--export-3ds") == 0)) - { - Save3DS = true; - - if ((argc > (i+1)) && (argv[i+1][0] != '-')) - { - i++; - Save3DSName = argv[i]; - } - } - else if ((strcmp(Param, "-dae") == 0) || (strcmp(Param, "--export-collada") == 0)) - { - SaveCOLLADA = true; - - if ((argc > (i+1)) && (argv[i+1][0] != '-')) - { - i++; - SaveCOLLADAName = argv[i]; - } - } - else if ((strcmp(Param, "-v") == 0) || (strcmp(Param, "--version") == 0)) - { - printf("LeoCAD Version " LC_VERSION_TEXT "\n"); - printf("Compiled " __DATE__ "\n"); - - ShowWindow = false; - return true; - } - else if ((strcmp(Param, "-?") == 0) || (strcmp(Param, "--help") == 0)) - { - printf("Usage: leocad [options] [file]\n"); - printf(" [options] can be:\n"); - printf(" -l, --libpath : Loads the Pieces Library from path.\n"); - printf(" -i, --image : Saves a picture in the format specified by ext.\n"); - printf(" -w, --width : Sets the picture width.\n"); - printf(" -h, --height : Sets the picture height.\n"); - printf(" -f, --from