#include "lc_global.h" #include #include "lc_application.h" #include "lc_library.h" #include "lc_profile.h" #include "project.h" #include "lc_mainwindow.h" #include "lc_shortcuts.h" #include "view.h" lcApplication* g_App; void lcPreferences::LoadDefaults() { mFixedAxes = lcGetProfileInt(LC_PROFILE_FIXED_AXES); mMouseSensitivity = lcGetProfileInt(LC_PROFILE_MOUSE_SENSITIVITY); mShadingMode = (lcShadingMode)lcGetProfileInt(LC_PROFILE_SHADING_MODE); mDrawAxes = lcGetProfileInt(LC_PROFILE_DRAW_AXES); mDrawEdgeLines = lcGetProfileInt(LC_PROFILE_DRAW_EDGE_LINES); mLineWidth = lcGetProfileFloat(LC_PROFILE_LINE_WIDTH); mDrawGridStuds = lcGetProfileInt(LC_PROFILE_GRID_STUDS); mGridStudColor = lcGetProfileInt(LC_PROFILE_GRID_STUD_COLOR); mDrawGridLines = lcGetProfileInt(LC_PROFILE_GRID_LINES); mGridLineSpacing = lcGetProfileInt(LC_PROFILE_GRID_LINE_SPACING); mGridLineColor = lcGetProfileInt(LC_PROFILE_GRID_LINE_COLOR); } void lcPreferences::SaveDefaults() { lcSetProfileInt(LC_PROFILE_FIXED_AXES, mFixedAxes); lcSetProfileInt(LC_PROFILE_MOUSE_SENSITIVITY, mMouseSensitivity); lcSetProfileInt(LC_PROFILE_SHADING_MODE, mShadingMode); lcSetProfileInt(LC_PROFILE_DRAW_AXES, mDrawAxes); lcSetProfileInt(LC_PROFILE_DRAW_EDGE_LINES, mDrawEdgeLines); lcSetProfileFloat(LC_PROFILE_LINE_WIDTH, mLineWidth); lcSetProfileInt(LC_PROFILE_GRID_STUDS, mDrawGridStuds); lcSetProfileInt(LC_PROFILE_GRID_STUD_COLOR, mGridStudColor); lcSetProfileInt(LC_PROFILE_GRID_LINES, mDrawGridLines); lcSetProfileInt(LC_PROFILE_GRID_LINE_SPACING, mGridLineSpacing); lcSetProfileInt(LC_PROFILE_GRID_LINE_COLOR, mGridLineColor); } lcApplication::lcApplication() { mProject = nullptr; mLibrary = nullptr; mClipboard = nullptr; mPreferences.LoadDefaults(); } lcApplication::~lcApplication() { delete mProject; delete mLibrary; } void lcApplication::SetProject(Project* Project) { delete mProject; mProject = Project; gMainWindow->RemoveAllModelTabs(); Project->SetActiveModel(0); lcGetPiecesLibrary()->RemoveTemporaryPieces(); } void lcApplication::SetClipboard(const QByteArray& Clipboard) { mClipboard = Clipboard; gMainWindow->UpdatePaste(!mClipboard.isEmpty()); } void lcApplication::ExportClipboard(const QByteArray& Clipboard) { QMimeData* MimeData = new QMimeData(); MimeData->setData("application/vnd.leocad-clipboard", Clipboard); QApplication::clipboard()->setMimeData(MimeData); SetClipboard(Clipboard); } bool lcApplication::LoadPiecesLibrary(const QList>& LibraryPaths) { if (mLibrary == nullptr) mLibrary = new lcPiecesLibrary(); char* EnvPath = getenv("LEOCAD_LIB"); if (EnvPath && EnvPath[0]) return mLibrary->Load(EnvPath); QString CustomPath = lcGetProfileString(LC_PROFILE_PARTS_LIBRARY); if (!CustomPath.isEmpty()) return mLibrary->Load(CustomPath); for (const QPair& LibraryPathEntry : LibraryPaths) { if (mLibrary->Load(LibraryPathEntry.first)) { if (LibraryPathEntry.second) mLibrary->SetOfficialPieces(); return true; } } return false; } void lcApplication::ParseIntegerArgument(int* CurArg, int argc, char* argv[], int* Value) const { 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 SaveImage = false; bool SaveWavefront = false; bool Save3DS = false; bool SaveCOLLADA = false; bool Orthographic = false; bool ImageHighlight = false; int ImageWidth = lcGetProfileInt(LC_PROFILE_IMAGE_WIDTH); int ImageHeight = lcGetProfileInt(LC_PROFILE_IMAGE_HEIGHT); lcStep ImageStart = 0; lcStep ImageEnd = 0; char* ImageName = nullptr; char* ModelName = nullptr; char* CameraName = nullptr; char* Viewpoint = nullptr; char* ProjectName = nullptr; char* SaveWavefrontName = nullptr; char* Save3DSName = nullptr; char* SaveCOLLADAName = nullptr; for (int i = 1; i < argc; i++) { char* Param = argv[i]; if (Param[0] == '-') { if ((strcmp(Param, "-l") == 0) || (strcmp(Param, "--libpath") == 0)) { const char* LibPath = nullptr; ParseStringArgument(&i, argc, argv, &LibPath); if (LibPath && LibPath[0]) { LibraryPaths.clear(); LibraryPaths += qMakePair(LibPath, false); } } 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