@@ -2147,25 +2147,6 @@ void MainWindow::action3DPrint()
21472147#endif // ifdef ENABLE_3D_PRINTING
21482148}
21492149
2150- namespace {
2151-
2152- ExportInfo createExportInfo (FileFormat format, const QString& exportFilename, const QString& sourceFilePath)
2153- {
2154- const QFileInfo info (sourceFilePath);
2155-
2156- ExportInfo exportInfo;
2157- exportInfo.format = format;
2158- exportInfo.fileName = exportFilename.toLocal8Bit ().constData ();
2159- exportInfo.displayName = exportFilename.toUtf8 ().toStdString ();
2160- exportInfo.sourceFilePath = sourceFilePath.toUtf8 ().toStdString ();
2161- exportInfo.sourceFileName = info.fileName ().toUtf8 ().toStdString ();
2162- exportInfo.useStdOut = false ;
2163- exportInfo.options = nullptr ;
2164- return exportInfo;
2165- }
2166-
2167- }
2168-
21692150void MainWindow::sendToOctoPrint ()
21702151{
21712152#ifdef ENABLE_3D_PRINTING
@@ -2176,20 +2157,22 @@ void MainWindow::sendToOctoPrint()
21762157 return ;
21772158 }
21782159
2160+ // FIXME: To make this cleaner, we could define which formats are supported by OctoPrint separately,
2161+ // then using fileformat::fromIdentifier() to convert.
21792162 const QString fileFormat = QString::fromStdString (Settings::Settings::octoPrintFileFormat.value ());
2180- FileFormat exportFileFormat{FileFormat::STL };
2163+ FileFormat exportFileFormat{FileFormat::BINARY_STL };
21812164 if (fileFormat == " OBJ" ) {
21822165 exportFileFormat = FileFormat::OBJ;
21832166 } else if (fileFormat == " OFF" ) {
21842167 exportFileFormat = FileFormat::OFF;
21852168 } else if (fileFormat == " ASCIISTL" ) {
2186- exportFileFormat = FileFormat::ASCIISTL ;
2169+ exportFileFormat = FileFormat::ASCII_STL ;
21872170 } else if (fileFormat == " AMF" ) {
21882171 exportFileFormat = FileFormat::AMF;
21892172 } else if (fileFormat == " 3MF" ) {
21902173 exportFileFormat = FileFormat::_3MF;
21912174 } else {
2192- exportFileFormat = FileFormat::STL ;
2175+ exportFileFormat = FileFormat::BINARY_STL ;
21932176 }
21942177
21952178 QTemporaryFile exportFile{QDir::temp ().filePath (" OpenSCAD.XXXXXX." + fileFormat.toLower ())};
@@ -2208,8 +2191,8 @@ void MainWindow::sendToOctoPrint()
22082191 userFileName = fileInfo.baseName () + " ." + fileFormat.toLower ();
22092192 }
22102193
2211- ExportInfo exportInfo = createExportInfo ( exportFileFormat, exportFileName, activeEditor->filepath ) ;
2212- exportFileByName (this ->root_geom , exportInfo);
2194+ ExportInfo exportInfo = {. format = exportFileFormat, . sourceFilePath = activeEditor->filepath . toStdString ()} ;
2195+ exportFileByName (this ->root_geom , exportFileName. toStdString (), exportInfo);
22132196
22142197 try {
22152198 this ->progresswidget = new ProgressWidget (this );
@@ -2239,25 +2222,13 @@ void MainWindow::sendToLocalSlicer()
22392222#ifdef ENABLE_3D_PRINTING
22402223 const QString slicer = QString::fromStdString (Settings::Settings::localSlicerExecutable.value ());
22412224
2242- const QString fileFormat = QString::fromStdString (Settings::Settings::localSlicerFileFormat.value ());
2243- FileFormat exportFileFormat{FileFormat::STL};
2244- if (fileFormat == " OBJ" ) {
2245- exportFileFormat = FileFormat::OBJ;
2246- } else if (fileFormat == " OFF" ) {
2247- exportFileFormat = FileFormat::OFF;
2248- } else if (fileFormat == " ASCIISTL" ) {
2249- exportFileFormat = FileFormat::ASCIISTL;
2250- } else if (fileFormat == " AMF" ) {
2251- exportFileFormat = FileFormat::AMF;
2252- } else if (fileFormat == " 3MF" ) {
2253- exportFileFormat = FileFormat::_3MF;
2254- } else if (fileFormat == " POV" ) {
2255- exportFileFormat = FileFormat::POV;
2256- } else {
2257- exportFileFormat = FileFormat::STL;
2225+ const QString fileFormat = QString::fromStdString (Settings::Settings::localSlicerFileFormat.value ()).toLower ();
2226+ FileFormat exportFileFormat = FileFormat::BINARY_STL;
2227+ if (!fileformat::fromIdentifier (fileFormat.toStdString (), exportFileFormat)) {
2228+ LOG (" Invalid suffix %1$s. Defaulting to binary STL." , fileFormat.toStdString ());
22582229 }
22592230
2260- const auto tmpPath = QDir::temp ().filePath (" OpenSCAD.XXXXXX." +fileFormat. toLower () );
2231+ const auto tmpPath = QDir::temp ().filePath (" OpenSCAD.XXXXXX." +fileFormat);
22612232 auto exportFile = std::make_unique<QTemporaryFile>(tmpPath);
22622233 if (!exportFile->open ()) {
22632234 LOG (message_group::Error, " Could not open temporary file '%1$s'." , tmpPath.toStdString ());
@@ -2272,11 +2243,11 @@ void MainWindow::sendToLocalSlicer()
22722243 userFileName = exportFileName;
22732244 } else {
22742245 QFileInfo fileInfo{activeEditor->filepath };
2275- userFileName = fileInfo.baseName () + fileFormat. toLower () ;
2246+ userFileName = fileInfo.baseName () + fileFormat;
22762247 }
22772248
2278- ExportInfo exportInfo = createExportInfo ( exportFileFormat, exportFileName, activeEditor->filepath ) ;
2279- exportFileByName (this ->root_geom , exportInfo);
2249+ ExportInfo exportInfo = {. format = exportFileFormat, . sourceFilePath = activeEditor->filepath . toStdString ()} ;
2250+ exportFileByName (this ->root_geom , exportFileName. toStdString (), exportInfo);
22802251
22812252 QProcess process (this );
22822253 process.setProcessChannelMode (QProcess::MergedChannels);
@@ -2310,8 +2281,8 @@ void MainWindow::sendToPrintService()
23102281 const QString exportFilename = exportFile.fileName ();
23112282
23122283 // Render the stl to a temporary file:
2313- ExportInfo exportInfo = createExportInfo ( FileFormat::STL, exportFilename, activeEditor->filepath ) ;
2314- exportFileByName (this ->root_geom , exportInfo);
2284+ ExportInfo exportInfo = {. format = FileFormat::BINARY_STL, . sourceFilePath = activeEditor->filepath . toStdString ()} ;
2285+ exportFileByName (this ->root_geom , exportFilename. toStdString (), exportInfo);
23152286
23162287 // Create a name that the order process will use to refer to the file. Base it off of the project name
23172288 QString userFacingName = " unsaved.stl" ;
@@ -2942,11 +2913,11 @@ void MainWindow::actionExport(FileFormat format, const char *type_name, const ch
29422913 }
29432914 this ->export_paths [suffix] = exportFilename;
29442915
2945- ExportInfo exportInfo = createExportInfo ( format, exportFilename, activeEditor->filepath ) ;
2916+ ExportInfo exportInfo = {. format = format, . sourceFilePath = activeEditor->filepath . toStdString ()} ;
29462917 // Add options
29472918 exportInfo.options = options;
29482919
2949- bool exportResult = exportFileByName (this ->root_geom , exportInfo);
2920+ bool exportResult = exportFileByName (this ->root_geom , exportFilename. toStdString (), exportInfo);
29502921
29512922 if (exportResult) fileExportedMessage (type_name, exportFilename);
29522923 clearCurrentOutput ();
@@ -2955,9 +2926,9 @@ void MainWindow::actionExport(FileFormat format, const char *type_name, const ch
29552926void MainWindow::actionExportSTL ()
29562927{
29572928 if (Settings::Settings::exportUseAsciiSTL.value ()) {
2958- actionExport (FileFormat::ASCIISTL , " ASCIISTL" , " .stl" , 3 );
2929+ actionExport (FileFormat::ASCII_STL , " ASCIISTL" , " .stl" , 3 );
29592930 } else {
2960- actionExport (FileFormat::STL , " STL" , " .stl" , 3 );
2931+ actionExport (FileFormat::BINARY_STL , " STL" , " .stl" , 3 );
29612932 }
29622933}
29632934
@@ -3016,7 +2987,7 @@ void MainWindow::actionExportPDF()
30162987 QString::fromStdString (paperSizeStrings[static_cast <int >(exportPdfOptions.paperSize )])).toString ())); // enum map
30172988 exportPdfDialog->setOrientation (orientationsString2Enum (settings.value (" exportPdfOpts/orientation" ,
30182989 QString::fromStdString (paperOrientationsStrings[static_cast <int >(exportPdfOptions.Orientation )])).toString ())); // enum map
3019- exportPdfDialog->setShowDsnFn (settings.value (" exportPdfOpts/showDsgnFN" , exportPdfOptions.showDsgnFN ).toBool ());
2990+ exportPdfDialog->setShowDesignFilename (settings.value (" exportPdfOpts/showDsgnFN" , exportPdfOptions.showDesignFilename ).toBool ());
30202991 exportPdfDialog->setShowScale (settings.value (" exportPdfOpts/showScale" , exportPdfOptions.showScale ).toBool ());
30212992 exportPdfDialog->setShowScaleMsg (settings.value (" exportPdfOpts/showScaleMsg" , exportPdfOptions.showScaleMsg ).toBool ());
30222993 exportPdfDialog->setShowGrid (settings.value (" exportPdfOpts/showGrid" , exportPdfOptions.showGrid ).toBool ());
@@ -3029,15 +3000,15 @@ void MainWindow::actionExportPDF()
30293000
30303001 exportPdfOptions.paperSize = exportPdfDialog->getPaperSize ();
30313002 exportPdfOptions.Orientation = exportPdfDialog->getOrientation ();
3032- exportPdfOptions.showDsgnFN = exportPdfDialog->getShowDsnFn ();
3003+ exportPdfOptions.showDesignFilename = exportPdfDialog->getShowDesignFilename ();
30333004 exportPdfOptions.showScale = exportPdfDialog->getShowScale ();
30343005 exportPdfOptions.showScaleMsg = exportPdfDialog->getShowScaleMsg ();
30353006 exportPdfOptions.showGrid = exportPdfDialog->getShowGrid ();
30363007 exportPdfOptions.gridSize = exportPdfDialog->getGridSize ();
30373008
30383009 settings.setValue (" exportPdfOpts/paperSize" , QString::fromStdString (paperSizeStrings[static_cast <int >(exportPdfDialog->getPaperSize ())]));
30393010 settings.setValue (" exportPdfOpts/orientation" , QString::fromStdString (paperOrientationsStrings[static_cast <int >(exportPdfDialog->getOrientation ())]));
3040- settings.setValue (" exportPdfOpts/showDsgnFN" , exportPdfDialog->getShowDsnFn ());
3011+ settings.setValue (" exportPdfOpts/showDsgnFN" , exportPdfDialog->getShowDesignFilename ());
30413012 settings.setValue (" exportPdfOpts/showScale" , exportPdfDialog->getShowScale ());
30423013 settings.setValue (" exportPdfOpts/showScaleMsg" , exportPdfDialog->getShowScaleMsg ());
30433014 settings.setValue (" exportPdfOpts/showGrid" , exportPdfDialog->getShowGrid ());
0 commit comments