@@ -77,7 +77,7 @@ namespace
7777      case  SaveSpectrumAsType::ExploraniumGr135v2: return  " GR135 DAT" 
7878      case  SaveSpectrumAsType::SpeIaea:            return  " IAEA SPE" 
7979      case  SaveSpectrumAsType::Cnf:                return  " Canberra CNF" 
80-       case  SaveSpectrumAsType::Tka:                return  " TKA" 
80+       case  SaveSpectrumAsType::Tka:                return  " Canberra  TKA" 
8181#if ( SpecUtils_ENABLE_D3_CHART )
8282      case  SaveSpectrumAsType::HtmlD3:             return  " HTML" 
8383#endif 
@@ -211,9 +211,9 @@ BatchConvertDialog::BatchConvertDialog( QWidget * parent, Qt::WindowFlags f )
211211
212212  QSettings settings;
213213  QVariant var = settings.value ( " SaveFileDir" 
214-   const  QString val = var.isValid () ? var.toString () : QString (" " 
215-   if ( val.size ()>2  && QDir (val).exists () )
216- 	m_saveToPath->setText ( val );
214+   // const QString val = var.isValid() ? var.toString() : QString("");
215+   // if( val.size()>2 && QDir(val).exists() )
216+ 	// m_saveToPath->setText( val );
217217
218218
219219  QPushButton *browse = new  QPushButton ( " Browse..." 
@@ -336,6 +336,9 @@ void BatchConvertDialog::setDirectory( const QString &path )
336336    selectionmodel->select ( index, QItemSelectionModel::Select );
337337    m_filesystemView->scrollTo ( index, QAbstractItemView::EnsureVisible );
338338  }
339+ 
340+   if ( dir.exists () )
341+     m_saveToPath->setText ( dir.absolutePath () );
339342}// void setDirectory( const QString &path )
340343
341344
@@ -354,12 +357,36 @@ void BatchConvertDialog::setFiles( const QList<QString> &files )
354357    m_filesystemView->scrollTo ( index, QAbstractItemView::EnsureVisible );
355358  }
356359
357-   QDir savedir ( m_saveToPath->text () );
358-   if ( files.size () && (!savedir.exists () || !savedir.isReadable ()) )
360+   
361+   // Set the save path to be the same as the input files.
362+   if ( m_saveToPath->text ().isEmpty () )
359363  {
360-     QFileInfo info ( files[files.size ()-1 ] );
361-     m_saveToPath->setText ( info.path () );
362-   }// if( files.size() )
364+     std::set<QString> paths;
365+     for ( int  i = 0 ; i < files.size (); ++i )
366+     {
367+       QFileInfo info ( files[i] );
368+       if ( info.exists () )
369+         paths.insert ( info.path () );
370+     }
371+     if ( paths.size () == 1  )
372+     {
373+       //   \TODO: check if parent directory is a sub-path of m_saveToPath->text(), and if so, dont change things
374+       m_saveToPath->setText ( *paths.begin () );
375+     }else 
376+     {
377+       QSettings settings;
378+       QVariant var = settings.value ( " SaveFileDir" 
379+       const  QString val = var.isValid () ? var.toString () : QString ( " " 
380+       if ( val.size () > 2  && QDir ( val ).exists () )
381+       {
382+         m_saveToPath->setText ( val );
383+       }else  if ( files.size () )
384+       {
385+         QFileInfo info ( files[files.size () - 1 ] );
386+         m_saveToPath->setText ( info.path () );
387+       }
388+     }// if( all input files have one parent path ) / else
389+   }// if( m_saveToPath->text().isEmpty() )
363390}// void setFiles( const QList<QString> &files )
364391
365392
@@ -518,6 +545,12 @@ void BatchConvertDialog::convert()
518545        auto  output = open_output_file ( outname );
519546        if ( output )
520547          ok = meas.write_txt ( *output );
548+ 
549+         if ( !ok )
550+           failed.push_back ( " Possibly failed writing '" " '" 
551+         else 
552+           converted.push_back ( out );
553+ 
521554        break ;
522555      }// case SpecUtils::SaveSpectrumAsType::Txt:
523556
@@ -526,6 +559,12 @@ void BatchConvertDialog::convert()
526559        auto  output = open_output_file ( outname );
527560        if ( output )
528561          ok = meas.write_csv ( *output );
562+ 
563+         if ( !ok )
564+           failed.push_back ( " Possibly failed writing '" " '" 
565+         else 
566+           converted.push_back ( out );
567+ 
529568        break ;
530569      }// case SpecUtils::SaveSpectrumAsType::Csv:
531570
@@ -534,6 +573,12 @@ void BatchConvertDialog::convert()
534573        auto  output = open_output_file ( outname );
535574        if ( output )
536575          ok = meas.write_pcf ( *output );
576+ 
577+         if ( !ok )
578+           failed.push_back ( " Possibly failed writing '" " '" 
579+         else 
580+           converted.push_back ( out );
581+ 
537582        break ;
538583      }// case SpecUtils::SaveSpectrumAsType::Pcf:
539584
@@ -542,6 +587,12 @@ void BatchConvertDialog::convert()
542587        auto  output = open_output_file ( outname );
543588        if ( output )
544589          ok = meas.write_2006_N42 ( *output );
590+ 
591+         if ( !ok )
592+           failed.push_back ( " Possibly failed writing '" " '" 
593+         else 
594+           converted.push_back ( out );
595+ 
545596        break ;
546597      }// case SpecUtils::SaveSpectrumAsType::N42_2006:
547598
@@ -550,6 +601,12 @@ void BatchConvertDialog::convert()
550601        auto  output = open_output_file ( outname );
551602        if ( output )
552603          ok = meas.write_2012_N42 ( *output );
604+ 
605+         if ( !ok )
606+           failed.push_back ( " Possibly failed writing '" " '" 
607+         else 
608+           converted.push_back ( out );
609+ 
553610        break ;
554611      }// case SpecUtils::SaveSpectrumAsType::N42_2012:
555612
@@ -558,6 +615,12 @@ void BatchConvertDialog::convert()
558615        auto  output = open_output_file ( outname );
559616        if ( output )
560617          ok = meas.write_binary_exploranium_gr130v0 ( *output );
618+ 
619+         if ( !ok )
620+           failed.push_back ( " Possibly failed writing '" " '" 
621+         else 
622+           converted.push_back ( out );
623+ 
561624        break ;
562625      }// case SpecUtils::SaveSpectrumAsType::ExploraniumGr130v0:
563626
@@ -566,6 +629,12 @@ void BatchConvertDialog::convert()
566629        auto  output = open_output_file ( outname );
567630        if ( output )
568631          ok = meas.write_binary_exploranium_gr135v2 ( *output );
632+ 
633+         if ( !ok )
634+           failed.push_back ( " Possibly failed writing '" " '" 
635+         else 
636+           converted.push_back ( out );
637+ 
569638        break ;
570639      }// case SpecUtils::SaveSpectrumAsType::ExploraniumGr135v2:
571640
@@ -598,7 +667,11 @@ void BatchConvertDialog::convert()
598667                                   - std::begin (detnums);
599668            std::vector<std::string> detname ( 1 , detnames[detnumpos] );
600669
601-             
670+             //  Make sure we actually have this measurement, before continuing
671+             auto  m = meas.measurement ( sample, detnames[detnumpos] );
672+             if ( !m )
673+               continue ;
674+ 
602675            QString extention;
603676            QString outname = out;
604677
@@ -662,10 +735,6 @@ void BatchConvertDialog::convert()
662735        break ;
663736    }// switch( type )
664737
665-     if ( !ok )
666-       failed.push_back ( " Possibly failed writing '" " '" 
667-     else 
668-       converted.push_back ( out );
669738
670739	if ( progress.wasCanceled () )
671740	  break ;
0 commit comments