@@ -434,6 +434,9 @@ MainWindow::MainWindow(const QStringList& filenames)
434434 autoReloadTimer->setInterval (autoReloadPollingPeriodMS);
435435 connect (autoReloadTimer, SIGNAL (timeout ()), this , SLOT (checkAutoReload ()));
436436
437+ this ->exportformat_mapper = new QSignalMapper (this );
438+ connect (this ->exportformat_mapper , SIGNAL (mapped (int )), this , SLOT (actionExportFileFormat (int ))) ;
439+
437440 waitAfterReloadTimer = new QTimer (this );
438441 waitAfterReloadTimer->setSingleShot (true );
439442 waitAfterReloadTimer->setInterval (autoReloadPollingPeriodMS);
@@ -509,18 +512,27 @@ MainWindow::MainWindow(const QStringList& filenames)
509512 connect (this ->designActionDisplayAST , SIGNAL (triggered ()), this , SLOT (actionDisplayAST ()));
510513 connect (this ->designActionDisplayCSGTree , SIGNAL (triggered ()), this , SLOT (actionDisplayCSGTree ()));
511514 connect (this ->designActionDisplayCSGProducts , SIGNAL (triggered ()), this , SLOT (actionDisplayCSGProducts ()));
512- connect (this ->fileActionExportSTL , SIGNAL (triggered ()), this , SLOT (actionExportSTL ()));
513- connect (this ->fileActionExport3MF , SIGNAL (triggered ()), this , SLOT (actionExport3MF ()));
514- connect (this ->fileActionExportOBJ , SIGNAL (triggered ()), this , SLOT (actionExportOBJ ()));
515- connect (this ->fileActionExportOFF , SIGNAL (triggered ()), this , SLOT (actionExportOFF ()));
516- connect (this ->fileActionExportWRL , SIGNAL (triggered ()), this , SLOT (actionExportWRL ()));
517- connect (this ->fileActionExportPOV , SIGNAL (triggered ()), this , SLOT (actionExportPOV ()));
518- connect (this ->fileActionExportAMF , SIGNAL (triggered ()), this , SLOT (actionExportAMF ()));
519- connect (this ->fileActionExportDXF , SIGNAL (triggered ()), this , SLOT (actionExportDXF ()));
520- connect (this ->fileActionExportSVG , SIGNAL (triggered ()), this , SLOT (actionExportSVG ()));
521- connect (this ->fileActionExportPDF , SIGNAL (triggered ()), this , SLOT (actionExportPDF ()));
522- connect (this ->fileActionExportCSG , SIGNAL (triggered ()), this , SLOT (actionExportCSG ()));
523- connect (this ->fileActionExportImage , SIGNAL (triggered ()), this , SLOT (actionExportImage ()));
515+
516+ std::unordered_map<QObject*, FileFormat> export_map = {
517+ {this ->fileActionExportSTL , FileFormat::BINARY_STL},
518+ {this ->fileActionExport3MF , FileFormat::_3MF},
519+ {this ->fileActionExportOBJ , FileFormat::OBJ},
520+ {this ->fileActionExportOFF , FileFormat::OFF},
521+ {this ->fileActionExportWRL , FileFormat::WRL},
522+ {this ->fileActionExportPOV , FileFormat::POV},
523+ {this ->fileActionExportAMF , FileFormat::AMF},
524+ {this ->fileActionExportDXF , FileFormat::DXF},
525+ {this ->fileActionExportSVG , FileFormat::SVG},
526+ {this ->fileActionExportPDF , FileFormat::PDF},
527+ {this ->fileActionExportCSG , FileFormat::CSG},
528+ {this ->fileActionExportImage , FileFormat::PNG}
529+ };
530+
531+ for (auto &pair : export_map ) {
532+ connect (pair.first , SIGNAL (triggered ()), this ->exportformat_mapper , SLOT (map ()));
533+ this ->exportformat_mapper ->setMapping (pair.first , (int )pair.second );
534+ }
535+
524536 connect (this ->designActionFlushCaches , SIGNAL (triggered ()), this , SLOT (actionFlushCaches ()));
525537
526538#ifndef ENABLE_LIB3MF
@@ -2805,56 +2817,20 @@ void MainWindow::actionExport(FileFormat format, const char *type_name, const ch
28052817 clearCurrentOutput ();
28062818}
28072819
2808- void MainWindow::actionExportSTL ()
2809- {
2810- if (Settings::Settings::exportUseAsciiSTL.value ()) {
2811- actionExport (FileFormat::ASCII_STL, " ASCIISTL" , " .stl" , 3 );
2812- } else {
2813- actionExport (FileFormat::BINARY_STL, " STL" , " .stl" , 3 );
2814- }
2815- }
2816-
2817- void MainWindow::actionExport3MF ()
2820+ void MainWindow::actionExportFileFormat (int fmt_)
28182821{
2819- actionExport (FileFormat::_3MF, " 3MF" , " .3mf" , 3 );
2820- }
2821-
2822- void MainWindow::actionExportOBJ ()
2823- {
2824- actionExport (FileFormat::OBJ, " OBJ" , " .obj" , 3 );
2825- }
2826-
2827- void MainWindow::actionExportOFF ()
2828- {
2829- actionExport (FileFormat::OFF, " OFF" , " .off" , 3 );
2830- }
2831-
2832- void MainWindow::actionExportWRL ()
2833- {
2834- actionExport (FileFormat::WRL, " WRL" , " .wrl" , 3 );
2835- }
2836-
2837- void MainWindow::actionExportPOV ()
2838- {
2839- actionExport (FileFormat::POV, " POV" , " .pov" , 3 );
2840- }
2841-
2842- void MainWindow::actionExportAMF ()
2843- {
2844- actionExport (FileFormat::AMF, " AMF" , " .amf" , 3 );
2845- }
2846-
2847- void MainWindow::actionExportDXF ()
2848- {
2849- actionExport (FileFormat::DXF, " DXF" , " .dxf" , 2 );
2850- }
2851-
2852- void MainWindow::actionExportSVG ()
2853- {
2854- actionExport (FileFormat::SVG, " SVG" , " .svg" , 2 );
2855- }
2856-
2857- void MainWindow::actionExportPDF ()
2822+ FileFormat fmt = (FileFormat) fmt_;
2823+ FileFormatInfo info = fileformat::info (fmt);
2824+ const std::string suffix = " ." +info.suffix ;
2825+ switch (fmt) {
2826+ case FileFormat::BINARY_STL:
2827+ if (Settings::Settings::exportUseAsciiSTL.value ()) {
2828+ actionExport (FileFormat::ASCII_STL, info.description .c_str (), suffix.c_str (), 3 );
2829+ } else {
2830+ actionExport (FileFormat::BINARY_STL, info.description .c_str (), suffix.c_str (), 3 );
2831+ }
2832+ break ;
2833+ case FileFormat::PDF:
28582834{
28592835
28602836 ExportPdfOptions exportPdfOptions;
@@ -2899,8 +2875,8 @@ void MainWindow::actionExportPDF()
28992875 actionExport (FileFormat::PDF, " PDF" , " .pdf" , 2 , &exportPdfOptions);
29002876
29012877}
2902-
2903- void MainWindow::actionExportCSG ()
2878+ break ;
2879+ case FileFormat::CSG:
29042880{
29052881 setCurrentOutput ();
29062882
@@ -2929,9 +2905,8 @@ void MainWindow::actionExportCSG()
29292905 }
29302906
29312907 clearCurrentOutput ();
2932- }
2933-
2934- void MainWindow::actionExportImage ()
2908+ } break ;
2909+ case FileFormat::PNG:
29352910{
29362911 // Grab first to make sure dialog box isn't part of the grabbed image
29372912 qglview->grabFrame ();
@@ -2950,6 +2925,11 @@ void MainWindow::actionExportImage()
29502925 }
29512926 }
29522927}
2928+ break ;
2929+ default :
2930+ actionExport (info.format , info.description .c_str (), suffix.c_str (), fileformat::is3D (fmt) ? 3 : fileformat::is2D (fmt) ? 2 : 0 );
2931+ }
2932+ }
29532933
29542934void MainWindow::copyText ()
29552935{
0 commit comments