diff --git a/common/lc_application.cpp b/common/lc_application.cpp index f009232e..e8bcfa17 100644 --- a/common/lc_application.cpp +++ b/common/lc_application.cpp @@ -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 : Export the model to Wavefront OBJ format.\n"); Options.StdOut += tr(" -3ds, --export-3ds : Export the model to 3D Studio 3DS format.\n"); Options.StdOut += tr(" -dae, --export-collada : Export the model to COLLADA DAE format.\n"); + Options.StdOut += tr(" -csv, --export-csv : Export the list of parts used in csv format.\n"); Options.StdOut += tr(" -html, --export-html : 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>& 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>& 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); diff --git a/common/lc_application.h b/common/lc_application.h index fb1a8f83..6dd1cf89 100644 --- a/common/lc_application.h +++ b/common/lc_application.h @@ -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> LibraryPaths; QString StdOut; diff --git a/common/lc_mainwindow.cpp b/common/lc_mainwindow.cpp index d34e1272..622da8f2 100644 --- a/common/lc_mainwindow.cpp +++ b/common/lc_mainwindow.cpp @@ -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: diff --git a/common/project.cpp b/common/project.cpp index 8a4cdcaf..48d47f10 100644 --- a/common/project.cpp +++ b/common/project.cpp @@ -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() diff --git a/common/project.h b/common/project.h index 3f8eed24..e40efdcf 100644 --- a/common/project.h +++ b/common/project.h @@ -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);