leocad/common/lc_application.cpp

761 lines
23 KiB
C++
Raw Normal View History

2013-08-09 06:57:18 +02:00
#include "lc_global.h"
#include <stdio.h>
#include "lc_application.h"
#include "lc_library.h"
#include "lc_profile.h"
#include "project.h"
2013-08-16 03:25:51 +02:00
#include "lc_mainwindow.h"
2017-12-11 03:12:31 +01:00
#include "lc_qpreferencesdialog.h"
#include "lc_partselectionwidget.h"
2013-08-09 06:57:18 +02:00
#include "lc_shortcuts.h"
#include "view.h"
2013-08-09 06:57:18 +02:00
lcApplication* gApplication;
2013-08-09 06:57:18 +02:00
void lcPreferences::LoadDefaults()
{
2014-10-05 07:21:51 +02:00
mFixedAxes = lcGetProfileInt(LC_PROFILE_FIXED_AXES);
mMouseSensitivity = lcGetProfileInt(LC_PROFILE_MOUSE_SENSITIVITY);
2020-03-22 21:44:20 +01:00
mShadingMode = static_cast<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);
2019-11-28 22:52:06 +01:00
mAllowLOD = lcGetProfileInt(LC_PROFILE_ALLOW_LOD);
2020-01-02 02:06:17 +01:00
mFadeSteps = lcGetProfileInt(LC_PROFILE_FADE_STEPS);
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);
2020-01-05 20:38:24 +01:00
mViewSphereEnabled = lcGetProfileInt(LC_PROFILE_VIEW_SPHERE_ENABLED);
2020-03-22 21:44:20 +01:00
mViewSphereLocation = static_cast<lcViewSphereLocation>(lcGetProfileInt(LC_PROFILE_VIEW_SPHERE_LOCATION));
2018-10-29 01:59:01 +01:00
mViewSphereSize = lcGetProfileInt(LC_PROFILE_VIEW_SPHERE_SIZE);
2019-01-20 20:59:18 +01:00
mViewSphereColor = lcGetProfileInt(LC_PROFILE_VIEW_SPHERE_COLOR);
mViewSphereTextColor = lcGetProfileInt(LC_PROFILE_VIEW_SPHERE_TEXT_COLOR);
mViewSphereHighlightColor = lcGetProfileInt(LC_PROFILE_VIEW_SPHERE_HIGHLIGHT_COLOR);
2019-03-10 01:38:54 +01:00
mAutoLoadMostRecent = lcGetProfileInt(LC_PROFILE_AUTOLOAD_MOSTRECENT);
2020-01-02 02:06:17 +01:00
mRestoreTabLayout = lcGetProfileInt(LC_PROFILE_RESTORE_TAB_LAYOUT);
}
void lcPreferences::SaveDefaults()
{
2014-10-05 07:21:51 +02:00
lcSetProfileInt(LC_PROFILE_FIXED_AXES, mFixedAxes);
lcSetProfileInt(LC_PROFILE_MOUSE_SENSITIVITY, mMouseSensitivity);
2020-03-22 21:44:20 +01:00
lcSetProfileInt(LC_PROFILE_SHADING_MODE, static_cast<int>(mShadingMode));
lcSetProfileInt(LC_PROFILE_DRAW_AXES, mDrawAxes);
lcSetProfileInt(LC_PROFILE_DRAW_EDGE_LINES, mDrawEdgeLines);
lcSetProfileFloat(LC_PROFILE_LINE_WIDTH, mLineWidth);
lcSetProfileInt(LC_PROFILE_ALLOW_LOD, mAllowLOD);
2020-01-02 02:06:17 +01:00
lcSetProfileInt(LC_PROFILE_FADE_STEPS, mFadeSteps);
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);
2020-01-05 20:38:24 +01:00
lcSetProfileInt(LC_PROFILE_VIEW_SPHERE_ENABLED, mViewSphereSize ? 1 : 0);
2018-10-29 01:59:01 +01:00
lcSetProfileInt(LC_PROFILE_VIEW_SPHERE_LOCATION, (int)mViewSphereLocation);
lcSetProfileInt(LC_PROFILE_VIEW_SPHERE_SIZE, mViewSphereSize);
2019-01-20 20:59:18 +01:00
lcSetProfileInt(LC_PROFILE_VIEW_SPHERE_COLOR, mViewSphereColor);
lcSetProfileInt(LC_PROFILE_VIEW_SPHERE_TEXT_COLOR, mViewSphereTextColor);
lcSetProfileInt(LC_PROFILE_VIEW_SPHERE_HIGHLIGHT_COLOR, mViewSphereHighlightColor);
2019-03-10 01:38:54 +01:00
lcSetProfileInt(LC_PROFILE_AUTOLOAD_MOSTRECENT, mAutoLoadMostRecent);
2020-01-02 02:06:17 +01:00
lcSetProfileInt(LC_PROFILE_RESTORE_TAB_LAYOUT, mRestoreTabLayout);
}
lcApplication::lcApplication(int& Argc, char** Argv)
: QApplication(Argc, Argv)
2013-08-09 06:57:18 +02:00
{
#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;
mPreferences.LoadDefaults();
2013-08-09 06:57:18 +02:00
}
lcApplication::~lcApplication()
{
delete mProject;
delete mLibrary;
gApplication = nullptr;
2013-08-09 06:57:18 +02:00
}
void lcApplication::SaveTabLayout() const
{
if (!mProject || mProject->GetFileName().isEmpty())
return;
QSettings Settings;
QByteArray TabLayout = gMainWindow->GetTabLayout();
Settings.setValue(GetTabLayoutKey(), TabLayout);
}
QString lcApplication::GetTabLayoutKey() const
{
if (mProject)
{
QString FileName = mProject->GetFileName();
if (!FileName.isEmpty())
{
FileName.replace('\\', '?');
FileName.replace('/', '?');
return QString("TabLayouts/%1").arg(FileName);
}
}
return QString();
}
2014-12-04 02:47:28 +01:00
void lcApplication::SetProject(Project* Project)
{
SaveTabLayout();
gMainWindow->RemoveAllModelTabs();
2014-12-04 02:47:28 +01:00
delete mProject;
mProject = Project;
2015-03-14 20:07:07 +01:00
Project->SetActiveModel(0);
lcGetPiecesLibrary()->RemoveTemporaryPieces();
if (mProject && !mProject->GetFileName().isEmpty() && mPreferences.mRestoreTabLayout)
{
QSettings Settings;
QByteArray TabLayout = Settings.value(GetTabLayoutKey()).toByteArray();
gMainWindow->RestoreTabLayout(TabLayout);
}
2014-12-04 02:47:28 +01:00
}
2014-12-16 00:55:17 +01:00
void lcApplication::SetClipboard(const QByteArray& Clipboard)
2013-08-09 06:57:18 +02:00
{
mClipboard = Clipboard;
2014-12-16 00:55:17 +01:00
gMainWindow->UpdatePaste(!mClipboard.isEmpty());
2013-08-09 06:57:18 +02:00
}
2015-01-31 21:38:53 +01:00
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::LoadPartsLibrary(const QList<QPair<QString, bool>>& LibraryPaths, bool OnlyUsePaths, bool ShowProgress)
2013-08-09 06:57:18 +02:00
{
if (mLibrary == nullptr)
mLibrary = new lcPiecesLibrary();
2013-08-09 06:57:18 +02:00
if (!OnlyUsePaths)
{
char* EnvPath = getenv("LEOCAD_LIB");
if (EnvPath && EnvPath[0])
return mLibrary->Load(EnvPath, ShowProgress);
2013-08-09 06:57:18 +02:00
QString CustomPath = lcGetProfileString(LC_PROFILE_PARTS_LIBRARY);
2013-08-09 06:57:18 +02:00
if (!CustomPath.isEmpty())
return mLibrary->Load(CustomPath, ShowProgress);
}
2013-08-09 06:57:18 +02:00
2017-08-29 04:13:17 +02:00
for (const QPair<QString, bool>& LibraryPathEntry : LibraryPaths)
{
if (mLibrary->Load(LibraryPathEntry.first, ShowProgress))
{
2017-08-29 04:13:17 +02:00
if (LibraryPathEntry.second)
mLibrary->SetOfficialPieces();
return true;
2017-08-29 04:13:17 +02:00
}
}
2013-08-09 06:57:18 +02:00
return false;
}
bool lcApplication::Initialize(QList<QPair<QString, bool>>& LibraryPaths, bool& ShowWindow)
2013-08-09 06:57:18 +02:00
{
bool OnlyUseLibraryPaths = false;
2013-08-09 06:57:18 +02:00
bool SaveImage = false;
bool SaveWavefront = false;
bool Save3DS = false;
bool SaveCOLLADA = false;
bool SaveHTML = false;
bool SetCameraAngles = false;
bool Orthographic = false;
bool ImageHighlight = false;
2013-08-09 06:57:18 +02:00
int ImageWidth = lcGetProfileInt(LC_PROFILE_IMAGE_WIDTH);
int ImageHeight = lcGetProfileInt(LC_PROFILE_IMAGE_HEIGHT);
int StudLogo = lcGetProfileInt(LC_PROFILE_STUD_LOGO);
int ImageStart = 0;
int ImageEnd = 0;
2019-02-28 15:47:09 +01:00
float CameraLatitude = 0.0f, CameraLongitude = 0.0f;
QString ImageName;
QString ModelName;
QString CameraName;
QString ViewpointName;
2019-03-10 21:41:21 +01:00
QString ProjectName;
QString SaveWavefrontName;
QString Save3DSName;
QString SaveCOLLADAName;
QString SaveHTMLName;
QStringList Arguments = arguments();
const int NumArguments = Arguments.size();
for (int ArgIdx = 1; ArgIdx < NumArguments; ArgIdx++)
2013-08-09 06:57:18 +02:00
{
const QString& Param = Arguments[ArgIdx];
2013-08-09 06:57:18 +02:00
if (Param.isEmpty())
continue;
if (Param[0] != '-')
2013-08-09 06:57:18 +02:00
{
ProjectName = Param;
continue;
}
2013-08-09 06:57:18 +02:00
auto ParseString = [&ArgIdx, &Arguments, NumArguments](QString& Value, bool Required)
{
if (ArgIdx < NumArguments - 1 && Arguments[ArgIdx + 1][0] != '-')
{
ArgIdx++;
Value = Arguments[ArgIdx];
}
else if (Required)
printf("Not enough parameters for the '%s' argument.\n", Arguments[ArgIdx].toLatin1().constData());
};
auto ParseInteger = [&ArgIdx, &Arguments, NumArguments](int& Value)
{
if (ArgIdx < NumArguments - 1 && Arguments[ArgIdx + 1][0] != '-')
{
bool Ok = false;
ArgIdx++;
int NewValue = Arguments[ArgIdx].toInt(&Ok);
if (Ok)
Value = NewValue;
else
printf("Invalid value specified for the '%s' argument.\n", Arguments[ArgIdx - 1].toLatin1().constData());
}
else
printf("Not enough parameters for the '%s' argument.\n", Arguments[ArgIdx].toLatin1().constData());
};
2013-08-09 06:57:18 +02:00
auto ParseFloat = [&ArgIdx, &Arguments, NumArguments](float& Value)
{
if (ArgIdx < NumArguments - 1 && Arguments[ArgIdx + 1][0] != '-')
{
bool Ok = false;
ArgIdx++;
int NewValue = Arguments[ArgIdx].toFloat(&Ok);
if (Ok)
Value = NewValue;
else
printf("Invalid value specified for the '%s' argument.\n", Arguments[ArgIdx - 1].toLatin1().constData());
}
else
printf("Not enough parameters for the '%s' argument.\n", Arguments[ArgIdx].toLatin1().constData());
};
auto ParseVector2 = [&ArgIdx, &Arguments, NumArguments](float& Value1, float& Value2)
{
if (ArgIdx < NumArguments - 2 && Arguments[ArgIdx + 1][0] != '-' && Arguments[ArgIdx + 2][0] != '-')
{
bool Ok1 = false, Ok2 = false;
ArgIdx++;
float NewValue1 = Arguments[ArgIdx].toFloat(&Ok1);
ArgIdx++;
float NewValue2 = Arguments[ArgIdx].toFloat(&Ok2);
if (Ok1 && Ok2)
{
Value1 = NewValue1;
Value2 = NewValue2;
return true;
}
else
printf("Invalid value specified for the '%s' argument.\n", Arguments[ArgIdx - 2].toLatin1().constData());
}
else
printf("Not enough parameters for the '%s' argument.\n", Arguments[ArgIdx].toLatin1().constData());
return false;
};
if (Param == QLatin1String("-l") || Param == QLatin1String("--libpath"))
{
QString LibPath;
ParseString(LibPath, true);
if (!LibPath.isEmpty())
2013-08-09 06:57:18 +02:00
{
LibraryPaths.clear();
LibraryPaths += qMakePair<QString, bool>(LibPath, false);
OnlyUseLibraryPaths = true;
2013-08-09 06:57:18 +02:00
}
}
else if (Param == QLatin1String("-i") || Param == QLatin1String("--image"))
2013-08-09 06:57:18 +02:00
{
SaveImage = true;
ParseString(ImageName, false);
}
else if (Param == QLatin1String("-w") || Param == QLatin1String("--width"))
ParseInteger(ImageWidth);
else if (Param == QLatin1String("-h") || Param == QLatin1String("--height"))
ParseInteger(ImageHeight);
else if (Param == QLatin1String("-f") || Param == QLatin1String("--from"))
ParseInteger(ImageStart);
else if (Param == QLatin1String("-t") || Param == QLatin1String("--to"))
ParseInteger(ImageEnd);
else if (Param == QLatin1String("-s") || Param == QLatin1String("--submodel"))
ParseString(ModelName, true);
else if (Param == QLatin1String("-c") || Param == QLatin1String("--camera"))
ParseString(CameraName, true);
else if (Param == QLatin1String("--viewpoint"))
ParseString(ViewpointName, true);
else if (Param == QLatin1String("--camera-angles"))
SetCameraAngles = ParseVector2(CameraLatitude, CameraLongitude);
else if (Param == QLatin1String("--orthographic"))
Orthographic = true;
else if (Param == QLatin1String("--highlight"))
ImageHighlight = true;
else if (Param == QLatin1String("--shading"))
{
QString ShadingString;
ParseString(ShadingString, true);
if (ShadingString == QLatin1String("wireframe"))
2020-03-22 21:44:20 +01:00
mPreferences.mShadingMode = lcShadingMode::Wireframe;
else if (ShadingString == QLatin1String("flat"))
2020-03-22 21:44:20 +01:00
mPreferences.mShadingMode = lcShadingMode::Flat;
else if (ShadingString == QLatin1String("default"))
2020-03-22 21:44:20 +01:00
mPreferences.mShadingMode = lcShadingMode::DefaultLights;
else if (ShadingString == QLatin1String("full"))
2020-03-22 21:44:20 +01:00
mPreferences.mShadingMode = lcShadingMode::Full;
}
else if (Param == QLatin1String("--line-width"))
ParseFloat(mPreferences.mLineWidth);
else if (Param == QLatin1String("-sl") || Param == QLatin1String("--stud-logo"))
{
ParseInteger(StudLogo);
if (StudLogo != lcGetProfileInt(LC_PROFILE_STUD_LOGO))
{
2019-09-24 01:55:24 +02:00
lcGetPiecesLibrary()->SetStudLogo(StudLogo, false);
}
}
else if (Param == QLatin1String("-obj") || Param == QLatin1String("--export-wavefront"))
{
SaveWavefront = true;
ParseString(SaveWavefrontName, false);
}
else if (Param == QLatin1String("-3ds") || Param == QLatin1String("--export-3ds"))
{
Save3DS = true;
ParseString(Save3DSName, false);
}
else if (Param == QLatin1String("-dae") || Param == QLatin1String("--export-collada"))
{
SaveCOLLADA = true;
ParseString(SaveCOLLADAName, false);
2013-08-09 06:57:18 +02:00
}
else if (Param == QLatin1String("-html") || Param == QLatin1String("--export-html"))
{
SaveHTML = true;
ParseString(SaveHTMLName, false);
}
else if (Param == QLatin1String("-v") || Param == QLatin1String("--version"))
{
#ifdef LC_CONTINUOUS_BUILD
printf("LeoCAD Continuous Build " QT_STRINGIFY(LC_CONTINUOUS_BUILD) "\n");
#else
printf("LeoCAD Version " LC_VERSION_TEXT "\n");
#endif
printf("LeoCAD Version " LC_VERSION_TEXT "\n");
printf("Compiled " __DATE__ "\n");
ShowWindow = false;
return true;
}
else if (Param == QLatin1String("-?") || Param == QLatin1String("--help"))
{
printf("Usage: leocad [options] [file]\n");
printf(" [options] can be:\n");
printf(" -l, --libpath <path>: Set the Parts Library location to path.\n");
printf(" -i, --image <outfile.ext>: Save a picture in the format specified by ext.\n");
printf(" -w, --width <width>: Set the picture width.\n");
printf(" -h, --height <height>: Set the picture height.\n");
printf(" -f, --from <time>: Set the first step to save pictures.\n");
printf(" -t, --to <time>: Set the last step to save pictures.\n");
printf(" -s, --submodel <submodel>: Set the active submodel.\n");
printf(" -c, --camera <camera>: Set the active camera.\n");
printf(" -sl --stud-logo <type>: Set the stud logo type 0 - 5, 0 is no logo.\n");
printf(" --viewpoint <front|back|left|right|top|bottom|home>: Set the viewpoint.\n");
printf(" --camera-angles <latitude> <longitude>: Set the camera angles in degrees around the model.\n");
printf(" --orthographic: Make the view orthographic.\n");
printf(" --highlight: Highlight pieces in the steps they appear.\n");
printf(" --shading <wireframe|flat|default|full>: Select shading mode for rendering.\n");
printf(" --line-width <width>: Set the with of the edge lines.\n");
printf(" -obj, --export-wavefront <outfile.obj>: Export the model to Wavefront OBJ format.\n");
printf(" -3ds, --export-3ds <outfile.3ds>: Export the model to 3D Studio 3DS format.\n");
printf(" -dae, --export-collada <outfile.dae>: Export the model to COLLADA DAE format.\n");
printf(" -html, --export-html <folder>: Create an HTML page for the model.\n");
printf(" -v, --version: Output version information and exit.\n");
printf(" -?, --help: Display this help message and exit.\n");
printf(" \n");
ShowWindow = false;
return true;
}
else
printf("Unknown parameter: '%s'\n", Param.toLatin1().constData());
2013-08-09 06:57:18 +02:00
}
gMainWindow = new lcMainWindow();
lcLoadDefaultKeyboardShortcuts();
2016-04-23 02:17:33 +02:00
lcLoadDefaultMouseShortcuts();
ShowWindow = !SaveImage && !SaveWavefront && !Save3DS && !SaveCOLLADA && !SaveHTML;
if (!LoadPartsLibrary(LibraryPaths, OnlyUseLibraryPaths, ShowWindow))
2013-08-09 06:57:18 +02:00
{
QString Message;
2013-08-09 06:57:18 +02:00
2014-09-11 21:55:34 +02:00
if (mLibrary->LoadBuiltinPieces())
2018-03-22 00:47:00 +01:00
Message = tr("LeoCAD could not find a compatible Parts Library so only a small number of parts will be available.\n\nPlease visit https://www.leocad.org for information on how to download and install a library.");
2014-09-11 21:55:34 +02:00
else
2018-03-22 00:47:00 +01:00
Message = tr("LeoCAD could not load Parts Library.\n\nPlease visit https://www.leocad.org for information on how to download and install a library.");
if (ShowWindow)
QMessageBox::information(gMainWindow, tr("LeoCAD"), Message);
else
2016-12-16 21:52:36 +01:00
fprintf(stderr, "%s", Message.toLatin1().constData());
2013-08-09 06:57:18 +02:00
}
2015-01-26 00:04:39 +01:00
gMainWindow->CreateWidgets();
Project* NewProject = new Project();
SetProject(NewProject);
2013-08-09 06:57:18 +02:00
2019-03-10 21:41:21 +01:00
if (ShowWindow && ProjectName.isEmpty() && lcGetProfileInt(LC_PROFILE_AUTOLOAD_MOSTRECENT))
ProjectName = lcGetProfileString(LC_PROFILE_RECENT_FILE1);
if (!ProjectName.isEmpty() && gMainWindow->OpenProject(ProjectName))
2013-08-09 06:57:18 +02:00
{
if (!ModelName.isEmpty())
2017-12-27 22:55:37 +01:00
mProject->SetActiveModel(ModelName);
View* ActiveView = gMainWindow->GetActiveView();
if (!CameraName.isEmpty())
{
ActiveView->SetCamera(CameraName.toLatin1()); // todo: qstring
if (!ViewpointName.isEmpty())
printf("Warning: --viewpoint is ignored when --camera is set.\n");
if (Orthographic)
printf("Warning: --orthographic is ignored when --camera is set.\n");
if (SetCameraAngles)
printf("Warning: --camera-angles is ignored when --camera is set.\n");
}
else
{
if (!ViewpointName.isEmpty())
{
if (ViewpointName == QLatin1String("front"))
ActiveView->SetViewpoint(LC_VIEWPOINT_FRONT);
else if (ViewpointName == QLatin1String("back"))
ActiveView->SetViewpoint(LC_VIEWPOINT_BACK);
else if (ViewpointName == QLatin1String("top"))
ActiveView->SetViewpoint(LC_VIEWPOINT_TOP);
else if (ViewpointName == QLatin1String("bottom"))
ActiveView->SetViewpoint(LC_VIEWPOINT_BOTTOM);
else if (ViewpointName == QLatin1String("left"))
ActiveView->SetViewpoint(LC_VIEWPOINT_LEFT);
else if (ViewpointName == QLatin1String("right"))
ActiveView->SetViewpoint(LC_VIEWPOINT_RIGHT);
else if (ViewpointName == QLatin1String("home"))
ActiveView->SetViewpoint(LC_VIEWPOINT_HOME);
else
printf("Unknown viewpoint: '%s'\n", ViewpointName.toLatin1().constData());
if (SetCameraAngles)
printf("Warning: --camera-angles is ignored when --viewpoint is set.\n");
}
else if (SetCameraAngles)
ActiveView->SetCameraAngles(CameraLatitude, CameraLongitude);
ActiveView->SetProjection(Orthographic);
}
if (SaveImage)
{
lcModel* ActiveModel;
if (ModelName.isEmpty())
ActiveModel = mProject->GetMainModel();
else
ActiveModel = mProject->GetActiveModel();
2017-12-27 22:55:37 +01:00
if (ImageName.isEmpty())
ImageName = mProject->GetImageFileName(true);
2013-08-09 06:57:18 +02:00
if (ImageEnd < ImageStart)
ImageEnd = ImageStart;
else if (ImageStart > ImageEnd)
ImageStart = ImageEnd;
if ((ImageStart == 0) && (ImageEnd == 0))
ImageStart = ImageEnd = ActiveModel->GetCurrentStep();
else if ((ImageStart == 0) && (ImageEnd != 0))
ImageStart = ImageEnd;
else if ((ImageStart != 0) && (ImageEnd == 0))
ImageEnd = ImageStart;
2013-08-09 06:57:18 +02:00
if (ImageStart > 255)
ImageStart = 255;
2013-08-09 06:57:18 +02:00
if (ImageEnd > 255)
ImageEnd = 255;
2013-08-09 06:57:18 +02:00
QString Frame;
2013-08-09 06:57:18 +02:00
if (ImageStart != ImageEnd)
{
2017-12-27 22:55:37 +01:00
QString Extension = QFileInfo(ImageName).suffix();
Frame = ImageName.left(ImageName.length() - Extension.length() - 1) + QLatin1String("%1.") + Extension;
}
else
2017-12-27 22:55:37 +01:00
Frame = ImageName;
2013-08-09 06:57:18 +02:00
ActiveModel->SaveStepImages(Frame, ImageStart != ImageEnd, CameraName == nullptr, ImageHighlight, ImageWidth, ImageHeight, ImageStart, ImageEnd);
}
2013-08-09 06:57:18 +02:00
if (SaveWavefront)
2013-08-09 06:57:18 +02:00
{
QString FileName;
if (!SaveWavefrontName.isEmpty())
FileName = SaveWavefrontName;
else
FileName = ProjectName;
2013-08-09 06:57:18 +02:00
QString Extension = QFileInfo(FileName).suffix().toLower();
2013-08-09 06:57:18 +02:00
if (Extension.isEmpty())
{
FileName += ".obj";
}
else if (Extension != "obj")
{
FileName = FileName.left(FileName.length() - Extension.length() - 1);
FileName += ".obj";
}
mProject->ExportWavefront(FileName);
}
if (Save3DS)
{
QString FileName;
if (!Save3DSName.isEmpty())
FileName = Save3DSName;
else
FileName = ProjectName;
QString Extension = QFileInfo(FileName).suffix().toLower();
if (Extension.isEmpty())
{
FileName += ".3ds";
}
else if (Extension != "3ds")
{
FileName = FileName.left(FileName.length() - Extension.length() - 1);
FileName += ".3ds";
}
mProject->Export3DStudio(FileName);
}
if (SaveCOLLADA)
{
QString FileName;
if (!SaveCOLLADAName.isEmpty())
FileName = SaveCOLLADAName;
else
FileName = ProjectName;
QString Extension = QFileInfo(FileName).suffix().toLower();
if (Extension.isEmpty())
{
FileName += ".dae";
}
else if (Extension != "dae")
{
FileName = FileName.left(FileName.length() - Extension.length() - 1);
FileName += ".dae";
}
mProject->ExportCOLLADA(FileName);
}
if (SaveHTML)
{
lcHTMLExportOptions Options(mProject);
if (!SaveHTMLName.isEmpty())
Options.PathName = SaveHTMLName;
mProject->ExportHTML(Options);
}
2013-08-09 06:57:18 +02:00
}
if (ShowWindow)
{
gMainWindow->SetColorIndex(lcGetColorIndex(4));
gMainWindow->GetPartSelectionWidget()->SetDefaultPart();
gMainWindow->UpdateRecentFiles();
gMainWindow->show();
}
2013-08-09 06:57:18 +02:00
return true;
}
void lcApplication::Shutdown()
{
delete mLibrary;
mLibrary = nullptr;
2013-08-09 06:57:18 +02:00
}
void lcApplication::ShowPreferencesDialog()
{
lcPreferencesDialogOptions Options;
int CurrentAASamples = lcGetProfileInt(LC_PROFILE_ANTIALIASING_SAMPLES);
int CurrentStudLogo = lcGetProfileInt(LC_PROFILE_STUD_LOGO);
Options.Preferences = mPreferences;
2015-01-31 22:44:57 +01:00
Options.LibraryPath = lcGetProfileString(LC_PROFILE_PARTS_LIBRARY);
Options.MinifigSettingsPath = lcGetProfileString(LC_PROFILE_MINIFIG_SETTINGS);
Options.ColorConfigPath = lcGetProfileString(LC_PROFILE_COLOR_CONFIG);
2015-01-31 22:44:57 +01:00
Options.POVRayPath = lcGetProfileString(LC_PROFILE_POVRAY_PATH);
Options.LGEOPath = lcGetProfileString(LC_PROFILE_POVRAY_LGEO_PATH);
Options.DefaultAuthor = lcGetProfileString(LC_PROFILE_DEFAULT_AUTHOR_NAME);
2019-11-28 22:52:06 +01:00
Options.Language = lcGetProfileString(LC_PROFILE_LANGUAGE);
Options.CheckForUpdates = lcGetProfileInt(LC_PROFILE_CHECK_UPDATES);
Options.AASamples = CurrentAASamples;
Options.StudLogo = CurrentStudLogo;
Options.Categories = gCategories;
Options.CategoriesModified = false;
Options.CategoriesDefault = false;
Options.KeyboardShortcuts = gKeyboardShortcuts;
2016-04-25 07:26:34 +02:00
Options.KeyboardShortcutsModified = false;
Options.KeyboardShortcutsDefault = false;
Options.MouseShortcuts = gMouseShortcuts;
Options.MouseShortcutsModified = false;
Options.MouseShortcutsDefault = false;
2017-12-11 03:12:31 +01:00
lcQPreferencesDialog Dialog(gMainWindow, &Options);
if (Dialog.exec() != QDialog::Accepted)
return;
2019-11-28 22:52:06 +01:00
bool LanguageChanged = Options.Language != lcGetProfileString(LC_PROFILE_LANGUAGE);
2015-01-31 22:44:57 +01:00
bool LibraryChanged = Options.LibraryPath != lcGetProfileString(LC_PROFILE_PARTS_LIBRARY);
bool ColorsChanged = Options.ColorConfigPath != lcGetProfileString(LC_PROFILE_COLOR_CONFIG);
bool AAChanged = CurrentAASamples != Options.AASamples;
bool StudLogoChanged = CurrentStudLogo != Options.StudLogo;
mPreferences = Options.Preferences;
mPreferences.SaveDefaults();
lcSetProfileString(LC_PROFILE_DEFAULT_AUTHOR_NAME, Options.DefaultAuthor);
lcSetProfileString(LC_PROFILE_PARTS_LIBRARY, Options.LibraryPath);
lcSetProfileString(LC_PROFILE_COLOR_CONFIG, Options.ColorConfigPath);
lcSetProfileString(LC_PROFILE_MINIFIG_SETTINGS, Options.MinifigSettingsPath);
lcSetProfileString(LC_PROFILE_POVRAY_PATH, Options.POVRayPath);
lcSetProfileString(LC_PROFILE_POVRAY_LGEO_PATH, Options.LGEOPath);
2019-11-28 22:52:06 +01:00
lcSetProfileString(LC_PROFILE_LANGUAGE, Options.Language);
lcSetProfileInt(LC_PROFILE_CHECK_UPDATES, Options.CheckForUpdates);
lcSetProfileInt(LC_PROFILE_ANTIALIASING_SAMPLES, Options.AASamples);
lcSetProfileInt(LC_PROFILE_STUD_LOGO, Options.StudLogo);
2019-11-28 22:52:06 +01:00
if (LanguageChanged || LibraryChanged || ColorsChanged || AAChanged)
QMessageBox::information(gMainWindow, tr("LeoCAD"), tr("Some changes will only take effect the next time you start LeoCAD."));
if (Options.CategoriesModified)
{
if (Options.CategoriesDefault)
lcResetDefaultCategories();
else
{
gCategories = Options.Categories;
lcSaveDefaultCategories();
}
gMainWindow->UpdateCategories();
}
2016-04-25 07:26:34 +02:00
if (Options.KeyboardShortcutsModified)
{
2016-04-25 07:26:34 +02:00
if (Options.KeyboardShortcutsDefault)
lcResetDefaultKeyboardShortcuts();
else
{
gKeyboardShortcuts = Options.KeyboardShortcuts;
lcSaveDefaultKeyboardShortcuts();
}
gMainWindow->UpdateShortcuts();
}
2016-04-25 07:26:34 +02:00
if (Options.MouseShortcutsModified)
{
if (Options.MouseShortcutsDefault)
lcResetDefaultMouseShortcuts();
else
{
gMouseShortcuts = Options.MouseShortcuts;
lcSaveDefaultMouseShortcuts();
}
}
2019-09-24 01:55:24 +02:00
if (StudLogoChanged)
{
2019-09-24 01:55:24 +02:00
lcSetProfileInt(LC_PROFILE_STUD_LOGO, Options.StudLogo);
lcGetPiecesLibrary()->SetStudLogo(Options.StudLogo, true);
}
// TODO: printing preferences
/*
strcpy(opts.strFooter, m_strFooter);
strcpy(opts.strHeader, m_strHeader);
*/
gMainWindow->SetShadingMode(Options.Preferences.mShadingMode);
2014-05-03 23:16:48 +02:00
gMainWindow->UpdateAllViews();
}