Added --export-csv command line option.

This commit is contained in:
Leonardo Zide 2022-10-30 14:12:34 -07:00
parent 37dd02ee08
commit 3abe683d2b
5 changed files with 61 additions and 40 deletions

View file

@ -354,20 +354,6 @@ lcCommandLineOptions lcApplication::ParseCommandLineOptions()
lcCommandLineOptions Options;
Options.ParseOK = true;
Options.Exit = false;
Options.SaveImage = false;
Options.SaveWavefront = false;
Options.Save3DS = false;
Options.SaveCOLLADA = false;
Options.SaveHTML = false;
Options.SetCameraAngles = false;
Options.SetCameraPosition = false;
Options.Orthographic = false;
Options.SetFoV = false;
Options.SetZPlanes = false;
Options.SetFadeStepsColor = false;
Options.SetHighlightColor = false;
Options.FadeSteps = Preferences.mFadeSteps;
Options.ImageHighlight = Preferences.mHighlightNewParts;
Options.ImageWidth = lcGetProfileInt(LC_PROFILE_IMAGE_WIDTH);
@ -788,6 +774,11 @@ lcCommandLineOptions lcApplication::ParseCommandLineOptions()
Options.SaveCOLLADA = true;
ParseString(Options.SaveCOLLADAName, false);
}
else if (Option == QLatin1String("-csv") || Option == QLatin1String("--export-csv"))
{
Options.SaveCSV = true;
ParseString(Options.SaveCSVName, false);
}
else if (Option == QLatin1String("-html") || Option == QLatin1String("--export-html"))
{
Options.SaveHTML = true;
@ -842,6 +833,7 @@ lcCommandLineOptions lcApplication::ParseCommandLineOptions()
Options.StdOut += tr(" -obj, --export-wavefront <outfile.obj>: Export the model to Wavefront OBJ format.\n");
Options.StdOut += tr(" -3ds, --export-3ds <outfile.3ds>: Export the model to 3D Studio 3DS format.\n");
Options.StdOut += tr(" -dae, --export-collada <outfile.dae>: Export the model to COLLADA DAE format.\n");
Options.StdOut += tr(" -csv, --export-csv <outfile.csv>: Export the list of parts used in csv format.\n");
Options.StdOut += tr(" -html, --export-html <folder>: Create an HTML page for the model.\n");
Options.StdOut += tr(" -v, --version: Output version information and exit.\n");
Options.StdOut += tr(" -?, --help: Display this help message and exit.\n");
@ -888,7 +880,7 @@ lcCommandLineOptions lcApplication::ParseCommandLineOptions()
Options.StdErr += tr("--camera-position is ignored when --camera-angles is set.\n");
}
const bool SaveAndExit = (Options.SaveImage || Options.SaveWavefront || Options.Save3DS || Options.SaveCOLLADA || Options.SaveHTML);
const bool SaveAndExit = (Options.SaveImage || Options.SaveWavefront || Options.Save3DS || Options.SaveCOLLADA || Options.SaveCSV || Options.SaveHTML);
if (SaveAndExit && Options.ProjectName.isEmpty())
{
@ -929,7 +921,7 @@ lcStartupMode lcApplication::Initialize(const QList<QPair<QString, bool>>& Libra
return lcStartupMode::Error;
}
const bool SaveAndExit = (Options.SaveImage || Options.SaveWavefront || Options.Save3DS || Options.SaveCOLLADA || Options.SaveHTML);
const bool SaveAndExit = (Options.SaveImage || Options.SaveWavefront || Options.Save3DS || Options.SaveCOLLADA || Options.SaveCSV || Options.SaveHTML);
if (!SaveAndExit)
{
@ -1191,6 +1183,31 @@ lcStartupMode lcApplication::Initialize(const QList<QPair<QString, bool>>& Libra
StdOut << tr("Saved '%1'.\n").arg(FileName);
}
if (Options.SaveCSV)
{
QString FileName;
if (!Options.SaveCSVName.isEmpty())
FileName = Options.SaveCSVName;
else
FileName = Options.ProjectName;
QString Extension = QFileInfo(FileName).suffix().toLower();
if (Extension.isEmpty())
{
FileName += ".csv";
}
else if (Extension != "csv")
{
FileName = FileName.left(FileName.length() - Extension.length() - 1);
FileName += ".csv";
}
if (mProject->ExportCSV(FileName))
StdOut << tr("Saved '%1'.\n").arg(FileName);
}
if (Options.SaveHTML)
{
lcHTMLExportOptions HTMLOptions(mProject);

View file

@ -101,23 +101,24 @@ public:
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;
bool AutomateEdgeColor;
bool ParseOK = true;
bool Exit = false;
bool SaveImage = false;
bool SaveWavefront = false;
bool Save3DS = false;
bool SaveCOLLADA = false;
bool SaveCSV = false;
bool SaveHTML = false;
bool SetCameraAngles = false;
bool SetCameraPosition = false;
bool Orthographic = false;
bool SetFoV = false;
bool SetZPlanes = false;
bool SetFadeStepsColor = false;
bool SetHighlightColor = false;
bool FadeSteps = false;
bool ImageHighlight = false;
bool AutomateEdgeColor = false;
int ImageWidth;
int ImageHeight;
int AASamples;
@ -146,6 +147,7 @@ struct lcCommandLineOptions
QString SaveWavefrontName;
QString Save3DSName;
QString SaveCOLLADAName;
QString SaveCSVName;
QString SaveHTMLName;
QList<QPair<QString, bool>> LibraryPaths;
QString StdOut;

View file

@ -2590,7 +2590,7 @@ void lcMainWindow::HandleCommand(lcCommandId CommandId)
break;
case LC_FILE_EXPORT_CSV:
lcGetActiveProject()->ExportCSV();
lcGetActiveProject()->ExportCSV(QString());
break;
case LC_FILE_EXPORT_POVRAY:

View file

@ -1428,7 +1428,7 @@ bool Project::ExportCOLLADA(const QString& FileName)
return true;
}
void Project::ExportCSV()
bool Project::ExportCSV(const QString& FileName)
{
lcPartsList PartsList;
@ -1438,13 +1438,13 @@ void Project::ExportCSV()
if (PartsList.empty())
{
QMessageBox::information(gMainWindow, tr("LeoCAD"), tr("Nothing to export."));
return;
return false;
}
QString SaveFileName = GetExportFileName(QString(), "csv", tr("Export CSV"), tr("CSV Files (*.csv);;All Files (*.*)"));
QString SaveFileName = GetExportFileName(FileName, "csv", tr("Export CSV"), tr("CSV Files (*.csv);;All Files (*.*)"));
if (SaveFileName.isEmpty())
return;
return false;
lcDiskFile CSVFile(SaveFileName);
char Line[1024];
@ -1452,7 +1452,7 @@ void Project::ExportCSV()
if (!CSVFile.Open(QIODevice::WriteOnly))
{
QMessageBox::warning(gMainWindow, tr("LeoCAD"), tr("Could not open file '%1' for writing.").arg(SaveFileName));
return;
return false;
}
CSVFile.WriteLine("Part Name,Color,Quantity,Part ID,Color Code\n");
@ -1467,6 +1467,8 @@ void Project::ExportCSV()
CSVFile.WriteLine(Line);
}
}
return true;
}
lcInstructions* Project::GetInstructions()

View file

@ -93,7 +93,7 @@ public:
bool Export3DStudio(const QString& FileName);
void ExportBrickLink();
bool ExportCOLLADA(const QString& FileName);
void ExportCSV();
bool ExportCSV(const QString& FileName);
void ExportHTML(const lcHTMLExportOptions& Options);
bool ExportPOVRay(const QString& FileName);
bool ExportWavefront(const QString& FileName);