Refactored command line parsing.

This commit is contained in:
Leonardo Zide 2021-01-10 17:45:28 -08:00
parent 5ca460c0bf
commit f13e4ad056
3 changed files with 373 additions and 358 deletions

View file

@ -313,142 +313,136 @@ bool lcApplication::LoadPartsLibrary(const QList<QPair<QString, bool>>& LibraryP
return false; return false;
} }
lcStartupMode lcApplication::Initialize(QList<QPair<QString, bool>>& LibraryPaths) lcCommandLineOptions lcApplication::ParseCommandLineOptions()
{ {
bool OnlyUseLibraryPaths = false; lcCommandLineOptions Options;
bool SaveImage = false;
bool SaveWavefront = false; Options.ParseOK = true;
bool Save3DS = false; Options.Exit = false;
bool SaveCOLLADA = false; Options.SaveImage = false;
bool SaveHTML = false; Options.SaveWavefront = false;
bool SetCameraAngles = false; Options.Save3DS = false;
bool SetCameraPosition = false; Options.SaveCOLLADA = false;
bool Orthographic = false; Options.SaveHTML = false;
bool SetFoV = false; Options.SetCameraAngles = false;
bool SetZPlanes = false; Options.SetCameraPosition = false;
bool SetFadeStepsColor = false; Options.Orthographic = false;
bool SetHighlightColor = false; Options.SetFoV = false;
bool FadeSteps = mPreferences.mFadeSteps; Options.SetZPlanes = false;
bool ImageHighlight = mPreferences.mHighlightNewParts; Options.SetFadeStepsColor = false;
int ImageWidth = lcGetProfileInt(LC_PROFILE_IMAGE_WIDTH); Options.SetHighlightColor = false;
int ImageHeight = lcGetProfileInt(LC_PROFILE_IMAGE_HEIGHT); Options.FadeSteps = mPreferences.mFadeSteps;
int AASamples = lcGetProfileInt(LC_PROFILE_ANTIALIASING_SAMPLES); Options.ImageHighlight = mPreferences.mHighlightNewParts;
int StudLogo = lcGetProfileInt(LC_PROFILE_STUD_LOGO); Options.ImageWidth = lcGetProfileInt(LC_PROFILE_IMAGE_WIDTH);
int ImageStart = 0; Options.ImageHeight = lcGetProfileInt(LC_PROFILE_IMAGE_HEIGHT);
int ImageEnd = 0; Options.AASamples = lcGetProfileInt(LC_PROFILE_ANTIALIASING_SAMPLES);
lcVector3 CameraPosition[3] = {}; Options.StudLogo = lcGetProfileInt(LC_PROFILE_STUD_LOGO);
float CameraLatLon[2] = {0.0f, 0.0f}; Options.ImageStart = 0;
float FoV = 0.0f; Options.ImageEnd = 0;
float ZPlanes[2] = {0.0f, 0.0f}; Options.CameraPosition[0] = lcVector3(0.0f, 0.0f, 0.0f);
lcViewpoint Viewpoint = lcViewpoint::Count; Options.CameraPosition[1] = lcVector3(0.0f, 0.0f, 0.0f);
quint32 FadeStepsColor = mPreferences.mFadeStepsColor; Options.CameraPosition[2] = lcVector3(0.0f, 0.0f, 0.0f);
quint32 HighlightColor = mPreferences.mHighlightNewPartsColor; Options.CameraLatLon = lcVector2(0.0f, 0.0f);
QString ImageName; Options.FoV = 0.0f;
QString ModelName; Options.ZPlanes = lcVector2(0.0f, 0.0f);
QString CameraName; Options.Viewpoint = lcViewpoint::Count;
QString ProjectName; Options.FadeStepsColor = mPreferences.mFadeStepsColor;
QString SaveWavefrontName; Options.HighlightColor = mPreferences.mHighlightNewPartsColor;
QString Save3DSName;
QString SaveCOLLADAName;
QString SaveHTMLName;
QStringList Arguments = arguments(); QStringList Arguments = arguments();
const int NumArguments = Arguments.size();
bool ParseOK = true;
for (int ArgIdx = 1; ArgIdx < NumArguments; ArgIdx++) if (Arguments.isEmpty())
return Options;
Arguments.removeFirst();
while (!Arguments.isEmpty())
{ {
const QString& Param = Arguments[ArgIdx]; QString Option = Arguments.takeFirst();
if (Param.isEmpty()) if (Option.isEmpty())
continue; continue;
if (Param[0] != '-') auto ParseString = [&Option, &Arguments, &Options](QString& Value, bool Required)
{ {
ProjectName = Param; if (!Arguments.isEmpty() && Arguments.front()[0] != '-')
// TODO: check file is readable
continue;
}
auto ParseString = [&ArgIdx, &Arguments, NumArguments, &ParseOK](QString& Value, bool Required)
{
if (ArgIdx < NumArguments - 1 && Arguments[ArgIdx + 1][0] != '-')
{ {
ArgIdx++; QString Parameter = Arguments.takeFirst();
Value = Arguments[ArgIdx]; Value = Parameter;
} }
else if (Required) else if (Required)
{ {
printf("Not enough parameters for the '%s' option.\n", Arguments[ArgIdx].toLatin1().constData()); Options.Output += QString("Not enough parameters for the '%1' option.\n").arg(Option);
ParseOK = false; Options.ParseOK = false;
return false; return false;
} }
return true; return true;
}; };
auto ParseInteger = [&ArgIdx, &Arguments, NumArguments, &ParseOK](int& Value) auto ParseInteger = [&Option, &Arguments, &Options](int& Value, int Min, int Max)
{ {
if (ArgIdx < NumArguments - 1 && Arguments[ArgIdx + 1][0] != '-') if (!Arguments.isEmpty() && Arguments.front()[0] != '-')
{ {
bool Ok = false; bool Ok = false;
ArgIdx++; QString Parameter = Arguments.takeFirst();
int NewValue = Arguments[ArgIdx].toInt(&Ok); int NewValue = Parameter.toInt(&Ok);
if (Ok) if (Ok && NewValue >= Min && NewValue <= Max)
{ {
Value = NewValue; Value = NewValue;
return true; return true;
} }
else else
printf("Invalid parameter value specified for the '%s' option: '%s'.\n", Arguments[ArgIdx - 1].toLatin1().constData(), Arguments[ArgIdx].toLatin1().constData()); Options.Output += QString("Invalid parameter value specified for the '%1' option: '%2'.\n").arg(Option, Parameter);
} }
else else
printf("Not enough parameters for the '%s' option.\n", Arguments[ArgIdx].toLatin1().constData()); Options.Output += QString("Not enough parameters for the '%1' option.\n").arg(Option);
ParseOK = false; Options.ParseOK = false;
return false; return false;
}; };
auto ParseFloat = [&ArgIdx, &Arguments, NumArguments, &ParseOK](float& Value) auto ParseFloat = [&Option, &Arguments, &Options](float& Value, float Min, float Max)
{ {
if (ArgIdx < NumArguments - 1 && Arguments[ArgIdx + 1][0] != '-') if (!Arguments.isEmpty() && Arguments.front()[0] != '-')
{ {
bool Ok = false; bool Ok = false;
ArgIdx++; QString Parameter = Arguments.takeFirst();
float NewValue = Arguments[ArgIdx].toFloat(&Ok); float NewValue = Parameter.toFloat(&Ok);
if (Ok) if (Ok && NewValue >= Min && NewValue <= Max)
{ {
Value = NewValue; Value = NewValue;
return true; return true;
} }
else else
printf("Invalid parameter value specified for the '%s' option: '%s'.\n", Arguments[ArgIdx - 1].toLatin1().constData(), Arguments[ArgIdx].toLatin1().constData()); Options.Output += QString("Invalid parameter value specified for the '%1' option: '%2'.\n").arg(Option, Parameter);
} }
else else
printf("Not enough parameters for the '%s' option.\n", Arguments[ArgIdx].toLatin1().constData()); Options.Output += QString("Not enough parameters for the '%1' option.\n").arg(Option);
ParseOK = false; Options.ParseOK = false;
return false; return false;
}; };
auto ParseFloatArray = [&ArgIdx, &Arguments, NumArguments, &ParseOK](int Count, float* ValueArray, bool NegativesValid) auto ParseFloatArray = [&Option, &Arguments, &Options](int Count, float* ValueArray, bool NegativesValid)
{ {
if (ArgIdx + Count >= NumArguments) if (Arguments.size() < Count)
{ {
printf("Not enough parameters for the '%s' option.\n", Arguments[ArgIdx].toLatin1().constData()); Options.Output += QString("Not enough parameters for the '%1' option.\n").arg(Option);
ArgIdx += Count; Arguments.clear();
ParseOK = false; Options.ParseOK = false;
return false; return false;
} }
for (int ParseIndex = 0; ParseIndex < Count; ParseIndex++) for (int ParseIndex = 0; ParseIndex < Count; ParseIndex++)
{ {
if (NegativesValid || Arguments[ArgIdx+ParseIndex+1][0] != '-') if (NegativesValid || Arguments.front()[0] != '-')
{ {
bool Ok = false; bool Ok = false;
float NewValue = Arguments[ArgIdx+ParseIndex+1].toFloat(&Ok); QString Parameter = Arguments.takeFirst();
float NewValue = Parameter.toFloat(&Ok);
if (Ok) if (Ok)
{ {
@ -456,180 +450,156 @@ lcStartupMode lcApplication::Initialize(QList<QPair<QString, bool>>& LibraryPath
continue; continue;
} }
printf("Invalid parameter value specified for the '%s' option: '%s'.\n", Arguments[ArgIdx].toLatin1().constData(), Arguments[ArgIdx+ParseIndex+1].toLatin1().constData()); Options.Output += QString("Invalid parameter value specified for the '%1' option: '%2'.\n").arg(Option, Parameter);
} }
else else
printf("Not enough parameters for the '%s' option.\n", Arguments[ArgIdx].toLatin1().constData()); Options.Output += QString("Not enough parameters for the '%1' option.\n").arg(Option);
ArgIdx += ParseIndex; Options.ParseOK = false;
ParseOK = false;
return false; return false;
} }
ArgIdx += Count;
return true; return true;
}; };
auto ParseColor = [&ArgIdx, &Arguments, NumArguments, &ParseOK](quint32& Color) auto ParseColor = [&Option, &Arguments, &Options](quint32& Color)
{ {
if (ArgIdx < NumArguments - 1 && Arguments[ArgIdx + 1][0] != '-') if (!Arguments.isEmpty() && Arguments.front()[0] != '-')
{ {
ArgIdx++; QString Parameter = Arguments.takeFirst();
QColor ParsedColor = QColor(Arguments[ArgIdx]); QColor ParsedColor = QColor(Parameter);
if (ParsedColor.isValid()) if (ParsedColor.isValid())
{ {
Color = LC_RGBA(ParsedColor.red(), ParsedColor.green(), ParsedColor.blue(), ParsedColor.alpha()); Color = LC_RGBA(ParsedColor.red(), ParsedColor.green(), ParsedColor.blue(), ParsedColor.alpha());
return true; return true;
} }
else else
printf("Invalid parameter value specified for the '%s' option: '%s'.\n", Arguments[ArgIdx - 1].toLatin1().constData(), Arguments[ArgIdx].toLatin1().constData()); Options.Output += QString("Invalid parameter value specified for the '%1' option: '%2'.\n").arg(Option, Parameter);
} }
else else
printf("Not enough parameters for the '%s' option.\n", Arguments[ArgIdx].toLatin1().constData()); Options.Output += QString("Not enough parameters for the '%1' option.\n").arg(Option);
ParseOK = false; Options.ParseOK = false;
return false; return false;
}; };
if (Param == QLatin1String("-l") || Param == QLatin1String("--libpath")) if (Option[0] != '-')
{
if (QFileInfo(Option).isReadable())
Options.ProjectName = Option;
else
Options.Output += QString("The file '%1' is not readable.\n").arg(Option);
continue;
}
if (Option == QLatin1String("-l") || Option == QLatin1String("--libpath"))
{ {
QString LibPath; QString LibPath;
ParseString(LibPath, true);
if (!LibPath.isEmpty()) if (ParseString(LibPath, true))
{ Options.LibraryPaths += qMakePair<QString, bool>(LibPath, false);
LibraryPaths.clear();
LibraryPaths += qMakePair<QString, bool>(LibPath, false);
OnlyUseLibraryPaths = true;
}
} }
else if (Param == QLatin1String("-i") || Param == QLatin1String("--image")) else if (Option == QLatin1String("-i") || Option == QLatin1String("--image"))
{ {
SaveImage = true; Options.SaveImage = true;
ParseString(ImageName, false); ParseString(Options.ImageName, false);
} }
else if (Param == QLatin1String("-w") || Param == QLatin1String("--width")) else if (Option == QLatin1String("-w") || Option == QLatin1String("--width"))
{ ParseInteger(Options.ImageWidth, 1, INT_MAX);
if (ParseInteger(ImageWidth) && ImageWidth <= 0) else if (Option == QLatin1String("-h") || Option == QLatin1String("--height"))
{ ParseInteger(Options.ImageHeight, 1, INT_MAX);
printf("Invalid parameter value specified for the '%s' option: '%s'.\n", Param.toLatin1().constData(), Arguments[ArgIdx].toLatin1().constData()); else if (Option == QLatin1String("-f") || Option == QLatin1String("--from"))
ParseOK = false; ParseInteger(Options.ImageStart, 1, LC_STEP_MAX);
} else if (Option == QLatin1String("-t") || Option == QLatin1String("--to"))
} ParseInteger(Options.ImageEnd, 1, LC_STEP_MAX);
else if (Param == QLatin1String("-h") || Param == QLatin1String("--height")) else if (Option == QLatin1String("-s") || Option == QLatin1String("--submodel"))
{ ParseString(Options.ModelName, true);
if (ParseInteger(ImageHeight) && ImageWidth <= 0) else if (Option == QLatin1String("-c") || Option == QLatin1String("--camera"))
{ ParseString(Options.CameraName, true);
printf("Invalid parameter value specified for the '%s' option: '%s'.\n", Param.toLatin1().constData(), Arguments[ArgIdx].toLatin1().constData()); else if (Option == QLatin1String("--viewpoint"))
ParseOK = false;
}
}
else if (Param == QLatin1String("-f") || Param == QLatin1String("--from"))
{
if (ParseInteger(ImageStart) && ImageStart <= 0)
{
printf("Invalid parameter value specified for the '%s' option: '%s'.\n", Param.toLatin1().constData(), Arguments[ArgIdx].toLatin1().constData());
ParseOK = false;
}
}
else if (Param == QLatin1String("-t") || Param == QLatin1String("--to"))
{
if (ParseInteger(ImageEnd) && (ImageEnd <= 0 || (ImageStart && ImageStart > ImageEnd)))
{
printf("Invalid parameter value specified for the '%s' option: '%s'.\n", Param.toLatin1().constData(), Arguments[ArgIdx].toLatin1().constData());
ParseOK = false;
}
}
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"))
{ {
QString ViewpointName; QString ViewpointName;
if (ParseString(ViewpointName, true)) if (ParseString(ViewpointName, true))
{ {
Viewpoint = lcCamera::GetViewpoint(ViewpointName); Options.Viewpoint = lcCamera::GetViewpoint(ViewpointName);
if (Viewpoint == lcViewpoint::Count) if (Options.Viewpoint == lcViewpoint::Count)
{ {
printf("Invalid parameter value specified for the '%s' option: '%s'.\n", Param.toLatin1().constData(), Arguments[ArgIdx].toLatin1().constData()); Options.Output += QString("Invalid parameter value specified for the '%1' option: '%2'.\n").arg(Option, ViewpointName);
ParseOK = false; Options.ParseOK = false;
} }
} }
} }
else if (Param == QLatin1String("--camera-angles")) else if (Option == QLatin1String("--camera-angles"))
{ {
if ((SetCameraAngles = ParseFloatArray(2, CameraLatLon, true)) && (fabsf(CameraLatLon[0]) > 360.0f || fabsf(CameraLatLon[1]) > 360.0f)) if ((Options.SetCameraAngles = ParseFloatArray(2, Options.CameraLatLon, true)) && (fabsf(Options.CameraLatLon[0]) > 360.0f || fabsf(Options.CameraLatLon[1]) > 360.0f))
{ {
printf("Invalid parameter value(s) specified for the '%s' option: limits are +/- 360\n", Param.toLatin1().constData()); Options.Output += QString("Invalid parameter value(s) specified for the '%1' option: limits are +/- 360\n").arg(Option);
ParseOK = false; Options.ParseOK = false;
} }
} }
else if (Param == QLatin1String("--camera-position") || Param == QLatin1String("--camera-position-ldraw")) else if (Option == QLatin1String("--camera-position") || Option == QLatin1String("--camera-position-ldraw"))
{ {
if((SetCameraPosition = ParseFloatArray(9, CameraPosition[0], true))) if ((Options.SetCameraPosition = ParseFloatArray(9, Options.CameraPosition[0], true)))
{ {
lcVector3 Front = CameraPosition[1] - CameraPosition[0]; lcVector3 Front = Options.CameraPosition[1] - Options.CameraPosition[0];
if (Front.LengthSquared() < 1.0f || CameraPosition[2].LengthSquared() < 1.0f || fabsf(lcDot(lcNormalize(Front), lcNormalize(CameraPosition[2]))) > 0.99f) if (Front.LengthSquared() < 1.0f || Options.CameraPosition[2].LengthSquared() < 1.0f || fabsf(lcDot(lcNormalize(Front), lcNormalize(Options.CameraPosition[2]))) > 0.99f)
{ {
printf("Invalid parameter value(s) specified for the '%s' option.\n", Param.toLatin1().constData()); Options.Output += QString("Invalid parameter value(s) specified for the '%1' option.\n").arg(Option);
ParseOK = false; Options.ParseOK = false;
} }
else if (Param == QLatin1String("--camera-position-ldraw")) else if (Option == QLatin1String("--camera-position-ldraw"))
{ {
CameraPosition[0] = lcVector3LDrawToLeoCAD(CameraPosition[0]); Options.CameraPosition[0] = lcVector3LDrawToLeoCAD(Options.CameraPosition[0]);
CameraPosition[1] = lcVector3LDrawToLeoCAD(CameraPosition[1]); Options.CameraPosition[1] = lcVector3LDrawToLeoCAD(Options.CameraPosition[1]);
CameraPosition[2] = lcVector3LDrawToLeoCAD(CameraPosition[2]); Options.CameraPosition[2] = lcVector3LDrawToLeoCAD(Options.CameraPosition[2]);
} }
} }
} }
else if (Param == QLatin1String("--orthographic")) else if (Option == QLatin1String("--orthographic"))
Orthographic = true; Options.Orthographic = true;
else if (Param == QLatin1String("--fov")) else if (Option == QLatin1String("--fov"))
Options.SetFoV = ParseFloat(Options.FoV, 1.0f, 180.0f);
else if (Option == QLatin1String("--zplanes"))
{ {
if ((SetFoV = ParseFloat(FoV)) && fabsf(FoV) >= 180) if ((Options.SetZPlanes = ParseFloatArray(2, Options.ZPlanes, false)) && (Options.ZPlanes[0] < 1.0 || Options.ZPlanes[0] >= Options.ZPlanes[1]))
{ {
printf("Invalid parameter value specified for the '%s' option: '%s'.\n", Param.toLatin1().constData(), Arguments[ArgIdx].toLatin1().constData()); Options.Output += QString("Invalid parameter value(s) specified for the '%1' option: requirements are: 1 <= <near> < <far>\n").arg(Option);
ParseOK = false; Options.ParseOK = false;
} }
} }
else if (Param == QLatin1String("--zplanes")) else if (Option == QLatin1String("--fade-steps"))
Options.FadeSteps = true;
else if (Option == QLatin1String("--no-fade-steps"))
Options.FadeSteps = false;
else if (Option == QLatin1String("--fade-steps-color"))
{ {
if ((SetZPlanes = ParseFloatArray(2, ZPlanes, false)) && (ZPlanes[0] < 1.0 || ZPlanes[0] >= ZPlanes[1])) if (ParseColor(Options.FadeStepsColor))
{ {
printf("Invalid parameter value(s) specified for the '%s' option: requirements are: 1 <= <near> < <far>\n", Param.toLatin1().constData()); Options.SetFadeStepsColor = true;
ParseOK = false; Options.FadeSteps = true;
} }
} }
else if (Param == QLatin1String("--fade-steps")) else if (Option == QLatin1String("--highlight"))
FadeSteps = true; Options.ImageHighlight = true;
else if (Param == QLatin1String("--no-fade-steps")) else if (Option == QLatin1String("--no-highlight"))
FadeSteps = false; Options.ImageHighlight = false;
else if (Param == QLatin1String("--fade-steps-color")) else if (Option == QLatin1String("--highlight-color"))
{ {
if (ParseColor(FadeStepsColor)) if (ParseColor(Options.HighlightColor))
{ {
SetFadeStepsColor = true; Options.SetHighlightColor = true;
FadeSteps = true; Options.ImageHighlight = true;
} }
} }
else if (Param == QLatin1String("--highlight")) else if (Option == QLatin1String("--shading"))
ImageHighlight = true;
else if (Param == QLatin1String("--no-highlight"))
ImageHighlight = false;
else if (Param == QLatin1String("--highlight-color"))
{
if (ParseColor(HighlightColor))
{
SetHighlightColor = true;
ImageHighlight = true;
}
}
else if (Param == QLatin1String("--shading"))
{ {
QString ShadingString; QString ShadingString;
if (ParseString(ShadingString, true)) if (ParseString(ShadingString, true))
{ {
if (ShadingString == QLatin1String("wireframe")) if (ShadingString == QLatin1String("wireframe"))
@ -642,118 +612,127 @@ lcStartupMode lcApplication::Initialize(QList<QPair<QString, bool>>& LibraryPath
mPreferences.mShadingMode = lcShadingMode::Full; mPreferences.mShadingMode = lcShadingMode::Full;
else else
{ {
printf("Invalid parameter value specified for the '%s' option: '%s'\n", Param.toLatin1().constData(), Arguments[ArgIdx].toLatin1().constData()); Options.Output += QString("Invalid parameter value specified for the '%1' option: '%2'\n").arg(Option, ShadingString);
ParseOK = false; Options.ParseOK = false;
} }
} }
} }
else if (Param == QLatin1String("--line-width")) else if (Option == QLatin1String("--line-width"))
ParseFloat(mPreferences.mLineWidth); ParseFloat(mPreferences.mLineWidth, 0.0f, 10.0f);
else if (Param == QLatin1String("--aa-samples")) else if (Option == QLatin1String("--aa-samples"))
{ {
if (ParseInteger(AASamples) && AASamples != 1 && AASamples != 2 && AASamples != 4 && AASamples != 8) if (ParseInteger(Options.AASamples, 1, 8) && Options.AASamples != 1 && Options.AASamples != 2 && Options.AASamples != 4 && Options.AASamples != 8)
{ {
printf("Invalid parameter value specified for the '%s' option: '%s'.\n", Param.toLatin1().constData(), Arguments[ArgIdx].toLatin1().constData()); Options.Output += QString("Invalid parameter value specified for the '%1' option: '%2'.\n").arg(Option, QString::number(Options.AASamples));
ParseOK = false; Options.ParseOK = false;
} }
} }
else if (Param == QLatin1String("-sl") || Param == QLatin1String("--stud-logo")) else if (Option == QLatin1String("-sl") || Option == QLatin1String("--stud-logo"))
{ {
ParseInteger(StudLogo); ParseInteger(Options.StudLogo, 0, 5);
if (StudLogo != lcGetProfileInt(LC_PROFILE_STUD_LOGO))
{ if (Options.StudLogo != lcGetProfileInt(LC_PROFILE_STUD_LOGO))
lcGetPiecesLibrary()->SetStudLogo(StudLogo, false); lcGetPiecesLibrary()->SetStudLogo(Options.StudLogo, false);
}
} }
else if (Param == QLatin1String("-obj") || Param == QLatin1String("--export-wavefront")) else if (Option == QLatin1String("-obj") || Option == QLatin1String("--export-wavefront"))
{ {
SaveWavefront = true; Options.SaveWavefront = true;
ParseString(SaveWavefrontName, false); ParseString(Options.SaveWavefrontName, false);
} }
else if (Param == QLatin1String("-3ds") || Param == QLatin1String("--export-3ds")) else if (Option == QLatin1String("-3ds") || Option == QLatin1String("--export-3ds"))
{ {
Save3DS = true; Options.Save3DS = true;
ParseString(Save3DSName, false); ParseString(Options.Save3DSName, false);
} }
else if (Param == QLatin1String("-dae") || Param == QLatin1String("--export-collada")) else if (Option == QLatin1String("-dae") || Option == QLatin1String("--export-collada"))
{ {
SaveCOLLADA = true; Options.SaveCOLLADA = true;
ParseString(SaveCOLLADAName, false); ParseString(Options.SaveCOLLADAName, false);
} }
else if (Param == QLatin1String("-html") || Param == QLatin1String("--export-html")) else if (Option == QLatin1String("-html") || Option == QLatin1String("--export-html"))
{ {
SaveHTML = true; Options.SaveHTML = true;
ParseString(SaveHTMLName, false); ParseString(Options.SaveHTMLName, false);
} }
else if (Param == QLatin1String("-v") || Param == QLatin1String("--version")) else if (Option == QLatin1String("-v") || Option == QLatin1String("--version"))
{ {
#ifdef LC_CONTINUOUS_BUILD #ifdef LC_CONTINUOUS_BUILD
printf("LeoCAD Continuous Build " QT_STRINGIFY(LC_CONTINUOUS_BUILD) "\n"); Options.Output += QLatin1String("LeoCAD Continuous Build " QT_STRINGIFY(LC_CONTINUOUS_BUILD) "\n");
#else #else
printf("LeoCAD Version " LC_VERSION_TEXT "\n"); Options.Output += QLatin1String("LeoCAD Version " LC_VERSION_TEXT "\n");
#endif #endif
printf("Compiled " __DATE__ "\n"); Options.Output += QLatin1String("Compiled " __DATE__ "\n");
Options.Exit = true;
return lcStartupMode::Success;
} }
else if (Param == QLatin1String("-?") || Param == QLatin1String("--help")) else if (Option == QLatin1String("-?") || Option == QLatin1String("--help"))
{ {
printf("Usage: leocad [options] [file]\n"); Options.Output += QLatin1String("Usage: leocad [options] [file]\n");
printf(" [options] can be:\n"); Options.Output += QLatin1String(" [options] can be:\n");
printf(" -l, --libpath <path>: Set the Parts Library location to path.\n"); Options.Output += QLatin1String(" -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 and exit.\n"); Options.Output += QLatin1String(" -i, --image <outfile.ext>: Save a picture in the format specified by ext and exit.\n");
printf(" -w, --width <width>: Set the picture width.\n"); Options.Output += QLatin1String(" -w, --width <width>: Set the picture width.\n");
printf(" -h, --height <height>: Set the picture height.\n"); Options.Output += QLatin1String(" -h, --height <height>: Set the picture height.\n");
printf(" -f, --from <step>: Set the first step to save pictures.\n"); Options.Output += QLatin1String(" -f, --from <step>: Set the first step to save pictures.\n");
printf(" -t, --to <step>: Set the last step to save pictures.\n"); Options.Output += QLatin1String(" -t, --to <step>: Set the last step to save pictures.\n");
printf(" -s, --submodel <submodel>: Set the active submodel.\n"); Options.Output += QLatin1String(" -s, --submodel <submodel>: Set the active submodel.\n");
printf(" -c, --camera <camera>: Set the active camera.\n"); Options.Output += QLatin1String(" -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"); Options.Output += QLatin1String(" -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"); Options.Output += QLatin1String(" --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"); Options.Output += QLatin1String(" --camera-angles <latitude> <longitude>: Set the camera angles in degrees around the model.\n");
printf(" --camera-position <x> <y> <z> <tx> <ty> <tz> <ux> <uy> <uz>: Set the camera position, target and up vector.\n"); Options.Output += QLatin1String(" --camera-position <x> <y> <z> <tx> <ty> <tz> <ux> <uy> <uz>: Set the camera position, target and up vector.\n");
printf(" --camera-position-ldraw <x> <y> <z> <tx> <ty> <tz> <ux> <uy> <uz>: Set the camera position, target and up vector using LDraw coordinates.\n"); Options.Output += QLatin1String(" --camera-position-ldraw <x> <y> <z> <tx> <ty> <tz> <ux> <uy> <uz>: Set the camera position, target and up vector using LDraw coordinates.\n");
printf(" --orthographic: Render images using an orthographic projection.\n"); Options.Output += QLatin1String(" --orthographic: Render images using an orthographic projection.\n");
printf(" --fov <degrees>: Set the vertical field of view used to render images (< 180).\n"); Options.Output += QLatin1String(" --fov <degrees>: Set the vertical field of view used to render images (< 180).\n");
printf(" --zplanes <near> <far>: Set the near and far clipping planes used to render images (1 <= <near> < <far>).\n"); Options.Output += QLatin1String(" --zplanes <near> <far>: Set the near and far clipping planes used to render images (1 <= <near> < <far>).\n");
printf(" --fade-steps: Render parts from prior steps faded.\n"); Options.Output += QLatin1String(" --fade-steps: Render parts from prior steps faded.\n");
printf(" --no-fade-steps: Do not render parts from prior steps faded.\n"); Options.Output += QLatin1String(" --no-fade-steps: Do not render parts from prior steps faded.\n");
printf(" --fade-steps-color <rgba>: Renderinng color for prior step parts (#AARRGGBB).\n"); Options.Output += QLatin1String(" --fade-steps-color <rgba>: Renderinng color for prior step parts (#AARRGGBB).\n");
printf(" --highlight: Highlight parts in the steps they appear.\n"); Options.Output += QLatin1String(" --highlight: Highlight parts in the steps they appear.\n");
printf(" --no-highlight: Do not highlight parts in the steps they appear.\n"); Options.Output += QLatin1String(" --no-highlight: Do not highlight parts in the steps they appear.\n");
printf(" --highlight-color: Renderinng color for highlighted parts (#AARRGGBB).\n"); Options.Output += QLatin1String(" --highlight-color: Renderinng color for highlighted parts (#AARRGGBB).\n");
printf(" --shading <wireframe|flat|default|full>: Select shading mode for rendering.\n"); Options.Output += QLatin1String(" --shading <wireframe|flat|default|full>: Select shading mode for rendering.\n");
printf(" --line-width <width>: Set the with of the edge lines.\n"); Options.Output += QLatin1String(" --line-width <width>: Set the with of the edge lines.\n");
printf(" --aa-samples <count>: AntiAliasing sample size (1, 2, 4, or 8).\n"); Options.Output += QLatin1String(" --aa-samples <count>: AntiAliasing sample size (1, 2, 4, or 8).\n");
printf(" -obj, --export-wavefront <outfile.obj>: Export the model to Wavefront OBJ format.\n"); Options.Output += QLatin1String(" -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"); Options.Output += QLatin1String(" -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"); Options.Output += QLatin1String(" -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"); Options.Output += QLatin1String(" -html, --export-html <folder>: Create an HTML page for the model.\n");
printf(" -v, --version: Output version information and exit.\n"); Options.Output += QLatin1String(" -v, --version: Output version information and exit.\n");
printf(" -?, --help: Display this help message and exit.\n"); Options.Output += QLatin1String(" -?, --help: Display this help message and exit.\n");
printf(" \n"); Options.Output += QLatin1String("\n");
Options.Exit = true;
return lcStartupMode::Success;
} }
else else
{ {
printf("Unknown option: '%s'\n", Param.toLatin1().constData()); Options.Output += QString("Unknown option: '%1'\n").arg(Option);
ParseOK = false; Options.ParseOK = false;
} }
} }
if (!ParseOK) return Options;
}
lcStartupMode lcApplication::Initialize(const QList<QPair<QString, bool>>& LibraryPaths)
{
lcCommandLineOptions Options = ParseCommandLineOptions();
QTextStream(stdout, QIODevice::WriteOnly) << Options.Output;
if (Options.Exit)
return lcStartupMode::Success;
if (!Options.ParseOK)
return lcStartupMode::Error; return lcStartupMode::Error;
const bool SaveAndExit = (SaveImage || SaveWavefront || Save3DS || SaveCOLLADA || SaveHTML); const bool SaveAndExit = (Options.SaveImage || Options.SaveWavefront || Options.Save3DS || Options.SaveCOLLADA || Options.SaveHTML);
if (SaveAndExit && ProjectName.isEmpty()) if (SaveAndExit && Options.ProjectName.isEmpty())
{ {
printf("No file name specified.\n"); printf("No file name specified.\n");
return lcStartupMode::Error; return lcStartupMode::Error;
} }
if (!InitializeRenderer(AASamples)) if (!InitializeRenderer())
return lcStartupMode::Error; return lcStartupMode::Error;
if (!SaveAndExit) if (!SaveAndExit)
@ -766,7 +745,7 @@ lcStartupMode lcApplication::Initialize(QList<QPair<QString, bool>>& LibraryPath
lcLoadDefaultMouseShortcuts(); lcLoadDefaultMouseShortcuts();
} }
if (!LoadPartsLibrary(LibraryPaths, OnlyUseLibraryPaths, !SaveAndExit)) if (!LoadPartsLibrary(Options.LibraryPaths.isEmpty() ? LibraryPaths : Options.LibraryPaths, !Options.LibraryPaths.isEmpty(), !SaveAndExit))
{ {
QString Message; QString Message;
@ -787,20 +766,20 @@ lcStartupMode lcApplication::Initialize(QList<QPair<QString, bool>>& LibraryPath
Project* NewProject = new Project(); Project* NewProject = new Project();
SetProject(NewProject); SetProject(NewProject);
if (!SaveAndExit && ProjectName.isEmpty() && lcGetProfileInt(LC_PROFILE_AUTOLOAD_MOSTRECENT)) if (!SaveAndExit && Options.ProjectName.isEmpty() && lcGetProfileInt(LC_PROFILE_AUTOLOAD_MOSTRECENT))
ProjectName = lcGetProfileString(LC_PROFILE_RECENT_FILE1); Options.ProjectName = lcGetProfileString(LC_PROFILE_RECENT_FILE1);
bool ProjectLoaded = false; bool ProjectLoaded = false;
if (!ProjectName.isEmpty()) if (!Options.ProjectName.isEmpty())
{ {
if (gMainWindow) if (gMainWindow)
gMainWindow->OpenProject(ProjectName); gMainWindow->OpenProject(Options.ProjectName);
else else
{ {
Project* LoadedProject = new Project(); Project* LoadedProject = new Project();
if (LoadedProject->Load(ProjectName)) if (LoadedProject->Load(Options.ProjectName))
{ {
SetProject(LoadedProject); SetProject(LoadedProject);
ProjectLoaded = true; ProjectLoaded = true;
@ -814,22 +793,22 @@ lcStartupMode lcApplication::Initialize(QList<QPair<QString, bool>>& LibraryPath
if (ProjectLoaded) if (ProjectLoaded)
{ {
if (!ModelName.isEmpty()) if (!Options.ModelName.isEmpty())
mProject->SetActiveModel(ModelName); mProject->SetActiveModel(Options.ModelName);
std::unique_ptr<lcView> ActiveView; std::unique_ptr<lcView> ActiveView;
if (SaveImage) if (Options.SaveImage)
{ {
lcModel* Model; lcModel* Model;
if (!ModelName.isEmpty()) if (!Options.ModelName.isEmpty())
{ {
Model = mProject->GetModel(ModelName); Model = mProject->GetModel(Options.ModelName);
if (!Model) if (!Model)
{ {
printf("Error: model '%s' does not exist.\n", ModelName.toLatin1().constData()); printf("Error: model '%s' does not exist.\n", Options.ModelName.toLatin1().constData());
return lcStartupMode::Error; return lcStartupMode::Error;
} }
} }
@ -842,122 +821,122 @@ lcStartupMode lcApplication::Initialize(QList<QPair<QString, bool>>& LibraryPath
ActiveView->MakeCurrent(); ActiveView->MakeCurrent();
} }
if (SaveImage) if (Options.SaveImage)
ActiveView->SetSize(ImageWidth, ImageHeight); ActiveView->SetSize(Options.ImageWidth, Options.ImageHeight);
if (ActiveView) if (ActiveView)
{ {
if (!CameraName.isEmpty()) if (!Options.CameraName.isEmpty())
{ {
ActiveView->SetCamera(CameraName); ActiveView->SetCamera(Options.CameraName);
if (Viewpoint != lcViewpoint::Count) if (Options.Viewpoint != lcViewpoint::Count)
printf("Warning: --viewpoint is ignored when --camera is set.\n"); printf("Warning: --viewpoint is ignored when --camera is set.\n");
if (Orthographic) if (Options.Orthographic)
printf("Warning: --orthographic is ignored when --camera is set.\n"); printf("Warning: --orthographic is ignored when --camera is set.\n");
if (SetCameraAngles) if (Options.SetCameraAngles)
printf("Warning: --camera-angles is ignored when --camera is set.\n"); printf("Warning: --camera-angles is ignored when --camera is set.\n");
if (SetCameraPosition) if (Options.SetCameraPosition)
printf("Warning: --camera-position is ignored when --camera is set.\n"); printf("Warning: --camera-position is ignored when --camera is set.\n");
} }
else else
{ {
ActiveView->SetProjection(Orthographic); ActiveView->SetProjection(Options.Orthographic);
if (SetFoV) if (Options.SetFoV)
ActiveView->GetCamera()->m_fovy = FoV; ActiveView->GetCamera()->m_fovy = Options.FoV;
if (SetZPlanes) if (Options.SetZPlanes)
{ {
lcCamera* Camera = ActiveView->GetCamera(); lcCamera* Camera = ActiveView->GetCamera();
Camera->m_zNear = ZPlanes[0]; Camera->m_zNear = Options.ZPlanes[0];
Camera->m_zFar = ZPlanes[1]; Camera->m_zFar = Options.ZPlanes[1];
} }
if (Viewpoint != lcViewpoint::Count) if (Options.Viewpoint != lcViewpoint::Count)
{ {
ActiveView->SetViewpoint(Viewpoint); ActiveView->SetViewpoint(Options.Viewpoint);
if (SetCameraAngles) if (Options.SetCameraAngles)
printf("Warning: --camera-angles is ignored when --viewpoint is set.\n"); printf("Warning: --camera-angles is ignored when --viewpoint is set.\n");
if (SetCameraPosition) if (Options.SetCameraPosition)
printf("Warning: --camera-position is ignored when --viewpoint is set.\n"); printf("Warning: --camera-position is ignored when --viewpoint is set.\n");
} }
else if (SetCameraAngles) else if (Options.SetCameraAngles)
{ {
ActiveView->SetCameraAngles(CameraLatLon[0], CameraLatLon[1]); ActiveView->SetCameraAngles(Options.CameraLatLon[0], Options.CameraLatLon[1]);
if (SetCameraPosition) if (Options.SetCameraPosition)
printf("Warning: --camera-position is ignored when --camera-angles is set.\n"); printf("Warning: --camera-position is ignored when --camera-angles is set.\n");
} }
else if (SetCameraPosition) else if (Options.SetCameraPosition)
{ {
ActiveView->SetViewpoint(CameraPosition[0], CameraPosition[1], CameraPosition[2]); ActiveView->SetViewpoint(Options.CameraPosition[0], Options.CameraPosition[1], Options.CameraPosition[2]);
} }
} }
} }
if (SaveImage) if (Options.SaveImage)
{ {
lcModel* ActiveModel = ActiveView->GetModel(); lcModel* ActiveModel = ActiveView->GetModel();
if (ImageName.isEmpty()) if (Options.ImageName.isEmpty())
ImageName = mProject->GetImageFileName(true); Options.ImageName = mProject->GetImageFileName(true);
if (ImageEnd < ImageStart) if (Options.ImageEnd < Options.ImageStart)
ImageEnd = ImageStart; Options.ImageEnd = Options.ImageStart;
else if (ImageStart > ImageEnd) else if (Options.ImageStart > Options.ImageEnd)
ImageStart = ImageEnd; Options.ImageStart = Options.ImageEnd;
if ((ImageStart == 0) && (ImageEnd == 0)) if ((Options.ImageStart == 0) && (Options.ImageEnd == 0))
ImageStart = ImageEnd = ActiveModel->GetCurrentStep(); Options.ImageStart = Options.ImageEnd = ActiveModel->GetCurrentStep();
else if ((ImageStart == 0) && (ImageEnd != 0)) else if ((Options.ImageStart == 0) && (Options.ImageEnd != 0))
ImageStart = ImageEnd; Options.ImageStart = Options.ImageEnd;
else if ((ImageStart != 0) && (ImageEnd == 0)) else if ((Options.ImageStart != 0) && (Options.ImageEnd == 0))
ImageEnd = ImageStart; Options.ImageEnd = Options.ImageStart;
if (ImageStart > 255) if (Options.ImageStart > 255)
ImageStart = 255; Options.ImageStart = 255;
if (ImageEnd > 255) if (Options.ImageEnd > 255)
ImageEnd = 255; Options.ImageEnd = 255;
QString Frame; QString Frame;
if (ImageStart != ImageEnd) if (Options.ImageStart != Options.ImageEnd)
{ {
QString Extension = QFileInfo(ImageName).suffix(); QString Extension = QFileInfo(Options.ImageName).suffix();
Frame = ImageName.left(ImageName.length() - Extension.length() - 1) + QLatin1String("%1.") + Extension; Frame = Options.ImageName.left(Options.ImageName.length() - Extension.length() - 1) + QLatin1String("%1.") + Extension;
} }
else else
Frame = ImageName; Frame = Options.ImageName;
mPreferences.mFadeSteps = FadeSteps; mPreferences.mFadeSteps = Options.FadeSteps;
if (SetFadeStepsColor) if (Options.SetFadeStepsColor)
mPreferences.mFadeStepsColor = FadeStepsColor; mPreferences.mFadeStepsColor = Options.FadeStepsColor;
mPreferences.mHighlightNewParts = ImageHighlight; mPreferences.mHighlightNewParts = Options.ImageHighlight;
if (SetHighlightColor) if (Options.SetHighlightColor)
mPreferences.mHighlightNewPartsColor = HighlightColor; mPreferences.mHighlightNewPartsColor = Options.HighlightColor;
if (CameraName.isEmpty() && !SetCameraPosition) if (Options.CameraName.isEmpty() && !Options.SetCameraPosition)
ActiveView->ZoomExtents(); ActiveView->ZoomExtents();
ActiveView->SaveStepImages(Frame, ImageStart != ImageEnd, ImageStart, ImageEnd); ActiveView->SaveStepImages(Frame, Options.ImageStart != Options.ImageEnd, Options.ImageStart, Options.ImageEnd);
} }
if (SaveWavefront) if (Options.SaveWavefront)
{ {
QString FileName; QString FileName;
if (!SaveWavefrontName.isEmpty()) if (!Options.SaveWavefrontName.isEmpty())
FileName = SaveWavefrontName; FileName = Options.SaveWavefrontName;
else else
FileName = ProjectName; FileName = Options.ProjectName;
QString Extension = QFileInfo(FileName).suffix().toLower(); QString Extension = QFileInfo(FileName).suffix().toLower();
@ -974,14 +953,14 @@ lcStartupMode lcApplication::Initialize(QList<QPair<QString, bool>>& LibraryPath
mProject->ExportWavefront(FileName); mProject->ExportWavefront(FileName);
} }
if (Save3DS) if (Options.Save3DS)
{ {
QString FileName; QString FileName;
if (!Save3DSName.isEmpty()) if (!Options.Save3DSName.isEmpty())
FileName = Save3DSName; FileName = Options.Save3DSName;
else else
FileName = ProjectName; FileName = Options.ProjectName;
QString Extension = QFileInfo(FileName).suffix().toLower(); QString Extension = QFileInfo(FileName).suffix().toLower();
@ -998,14 +977,14 @@ lcStartupMode lcApplication::Initialize(QList<QPair<QString, bool>>& LibraryPath
mProject->Export3DStudio(FileName); mProject->Export3DStudio(FileName);
} }
if (SaveCOLLADA) if (Options.SaveCOLLADA)
{ {
QString FileName; QString FileName;
if (!SaveCOLLADAName.isEmpty()) if (!Options.SaveCOLLADAName.isEmpty())
FileName = SaveCOLLADAName; FileName = Options.SaveCOLLADAName;
else else
FileName = ProjectName; FileName = Options.ProjectName;
QString Extension = QFileInfo(FileName).suffix().toLower(); QString Extension = QFileInfo(FileName).suffix().toLower();
@ -1022,14 +1001,14 @@ lcStartupMode lcApplication::Initialize(QList<QPair<QString, bool>>& LibraryPath
mProject->ExportCOLLADA(FileName); mProject->ExportCOLLADA(FileName);
} }
if (SaveHTML) if (Options.SaveHTML)
{ {
lcHTMLExportOptions Options(mProject); lcHTMLExportOptions HTMLOptions(mProject);
if (!SaveHTMLName.isEmpty()) if (!Options.SaveHTMLName.isEmpty())
Options.PathName = SaveHTMLName; HTMLOptions.PathName = Options.SaveHTMLName;
mProject->ExportHTML(Options); mProject->ExportHTML(HTMLOptions);
} }
} }
@ -1058,17 +1037,8 @@ void lcApplication::Shutdown()
ShutdownRenderer(); ShutdownRenderer();
} }
bool lcApplication::InitializeRenderer(int AASamples) bool lcApplication::InitializeRenderer()
{ {
QSurfaceFormat Format = QSurfaceFormat::defaultFormat();
const int FormatSamples = Format.samples() > 1 ? Format.samples() : 1;
if (AASamples != FormatSamples)
{
Format.setSamples(AASamples);
QSurfaceFormat::setDefaultFormat(Format);
}
if (!lcContext::CreateOffscreenContext()) if (!lcContext::CreateOffscreenContext())
return false; return false;

View file

@ -1,6 +1,7 @@
#pragma once #pragma once
#include "lc_array.h" #include "lc_array.h"
#include "lc_math.h"
class Project; class Project;
class lcPiecesLibrary; class lcPiecesLibrary;
@ -72,6 +73,49 @@ public:
int mDrawPreviewAxis; int mDrawPreviewAxis;
}; };
struct lcCommandLineOptions
{
bool ParseOK;
bool Exit;
bool SaveImage;
bool SaveWavefront;
bool Save3DS;
bool SaveCOLLADA;
bool SaveHTML;
bool SetCameraAngles;
bool SetCameraPosition;
bool Orthographic;
bool SetFoV;
bool SetZPlanes;
bool SetFadeStepsColor;
bool SetHighlightColor;
bool FadeSteps;
bool ImageHighlight;
int ImageWidth;
int ImageHeight;
int AASamples;
int StudLogo;
int ImageStart;
int ImageEnd;
lcVector3 CameraPosition[3];
lcVector2 CameraLatLon;
float FoV;
lcVector2 ZPlanes;
lcViewpoint Viewpoint;
quint32 FadeStepsColor;
quint32 HighlightColor;
QString ImageName;
QString ModelName;
QString CameraName;
QString ProjectName;
QString SaveWavefrontName;
QString Save3DSName;
QString SaveCOLLADAName;
QString SaveHTMLName;
QList<QPair<QString, bool>> LibraryPaths;
QString Output;
};
enum class lcStartupMode enum class lcStartupMode
{ {
ShowWindow, ShowWindow,
@ -88,7 +132,8 @@ public:
~lcApplication(); ~lcApplication();
void SetProject(Project* Project); void SetProject(Project* Project);
lcStartupMode Initialize(QList<QPair<QString, bool>>& LibraryPaths); lcCommandLineOptions ParseCommandLineOptions();
lcStartupMode Initialize(const QList<QPair<QString, bool>>& LibraryPaths);
void Shutdown(); void Shutdown();
void ShowPreferencesDialog(); void ShowPreferencesDialog();
void SaveTabLayout() const; void SaveTabLayout() const;
@ -104,7 +149,7 @@ public:
QByteArray mClipboard; QByteArray mClipboard;
protected: protected:
bool InitializeRenderer(int AASamples); bool InitializeRenderer();
void ShutdownRenderer(); void ShutdownRenderer();
void UpdateStyle(); void UpdateStyle();
QString GetTabLayoutKey() const; QString GetTabLayoutKey() const;

View file

@ -124,12 +124,12 @@ static void lcRegisterShellFileTypes()
static void lcInitializeSurfaceFormat(int argc, char* argv[]) static void lcInitializeSurfaceFormat(int argc, char* argv[])
{ {
lcApplication Application(argc, argv); lcApplication Application(argc, argv);
const int AASamples = lcGetProfileInt(LC_PROFILE_ANTIALIASING_SAMPLES); const lcCommandLineOptions Options = Application.ParseCommandLineOptions();
if (AASamples > 1) if (Options.ParseOK && Options.AASamples > 1)
{ {
QSurfaceFormat Format = QSurfaceFormat::defaultFormat(); QSurfaceFormat Format = QSurfaceFormat::defaultFormat();
Format.setSamples(AASamples); Format.setSamples(Options.AASamples);
QSurfaceFormat::setDefaultFormat(Format); QSurfaceFormat::setDefaultFormat(Format);
} }
} }