108108#include " InterSpec/HelpSystem.h"
109109#include " SpecUtils/Filesystem.h"
110110#include " SpecUtils/StringAlgo.h"
111+ #include " InterSpec/DetectorEdit.h"
111112#include " InterSpec/SimpleDialog.h"
112113#include " InterSpec/InterSpecApp.h"
113114#include " InterSpec/DataBaseUtils.h"
@@ -1273,35 +1274,16 @@ bool SpecMeasManager::handleNonSpectrumFile( const std::string &displayName,
12731274 return (pos != char_end);
12741275 };// header_contains lambda
12751276
1276- #define USE_SIMPLE_DIALOG_FOR_NOT_SPEC 1
12771277
1278- #if ( USE_SIMPLE_DIALOG_FOR_NOT_SPEC )
12791278 SimpleDialog *dialog = new SimpleDialog ();
1280- dialog->addButton ( " Close" );
1279+ WPushButton *closeButton = dialog->addButton ( " Close" );
12811280 WGridLayout *stretcher = new WGridLayout ();
12821281 stretcher->setContentsMargins ( 0 , 0 , 0 , 0 );
12831282 dialog->contents ()->setLayout ( stretcher );
12841283 WText *title = new WText ( " Not a spectrum file" );
12851284 title->addStyleClass ( " title" );
12861285 stretcher->addWidget ( title, 0 , 0 );
12871286
1288- #else
1289-
1290- AuxWindow *w = new AuxWindow ( " Not a spectrum file" ,
1291- (Wt::WFlags<AuxWindowProperties>(AuxWindowProperties::IsModal)
1292- | AuxWindowProperties::TabletNotFullScreen
1293- | AuxWindowProperties::SetCloseable
1294- | AuxWindowProperties::DisableCollapse) );
1295- w->centerWindow ();
1296- w->rejectWhenEscapePressed ( true );
1297- WPushButton *b = w->addCloseButtonToFooter ();
1298- b->clicked ().connect ( w, &AuxWindow::hide );
1299- w->finished ().connect ( boost::bind ( &AuxWindow::deleteAuxWindow, w ) );
1300- WGridLayout *stretcher = w->stretcher ();
1301- if ( !m_viewer->isMobile () && m_viewer->renderedWidth () > 400 && m_viewer->renderedHeight () > 250 )
1302- w->resize ( 400 , 250 );
1303- #endif
1304-
13051287 // const string filename = SpecUtils::filename(displayName);
13061288
13071289 // Check if ICD2 file
@@ -1322,11 +1304,8 @@ bool SpecMeasManager::handleNonSpectrumFile( const std::string &displayName,
13221304 " If you believe this to be a legitimate spectrum file, please email it to <a href=\" mailto:interspec@sandia.gov\" target=\" _blank\" >interspec@sandia.gov</a> to support this file type." );
13231305 stretcher->addWidget ( t, stretcher->rowCount (), 0 , AlignCenter | AlignMiddle );
13241306 t->setTextAlignment ( Wt::AlignCenter );
1325- #if ( USE_SIMPLE_DIALOG_FOR_NOT_SPEC )
13261307 dialog->show ();
1327- #else
1328- w->show ();
1329- #endif
1308+
13301309 return true ;
13311310 }
13321311 }// if( might be ICD2 )
@@ -1396,9 +1375,6 @@ bool SpecMeasManager::handleNonSpectrumFile( const std::string &displayName,
13961375 WText *t = new WText ( msg );
13971376 stretcher->addWidget ( t, stretcher->rowCount (), 0 , AlignCenter | AlignMiddle );
13981377 t->setTextAlignment ( Wt::AlignCenter );
1399- #if ( !USE_SIMPLE_DIALOG_FOR_NOT_SPEC )
1400- w->show ();
1401- #endif
14021378
14031379 return true ;
14041380 }// if( iszip )
@@ -1413,9 +1389,6 @@ bool SpecMeasManager::handleNonSpectrumFile( const std::string &displayName,
14131389 WText *t = new WText ( msg );
14141390 stretcher->addWidget ( t, stretcher->rowCount (), 0 , AlignCenter | AlignMiddle );
14151391 t->setTextAlignment ( Wt::AlignCenter );
1416- #if ( !USE_SIMPLE_DIALOG_FOR_NOT_SPEC )
1417- w->show ();
1418- #endif
14191392
14201393 return true ;
14211394 }// if( israr || istar || iszip7 || isgz )
@@ -1427,9 +1400,6 @@ bool SpecMeasManager::handleNonSpectrumFile( const std::string &displayName,
14271400 WText *t = new WText ( msg );
14281401 stretcher->addWidget ( t, stretcher->rowCount (), 0 , AlignCenter | AlignMiddle );
14291402 t->setTextAlignment ( Wt::AlignCenter );
1430- #if ( !USE_SIMPLE_DIALOG_FOR_NOT_SPEC )
1431- w->show ();
1432- #endif
14331403
14341404 return true ;
14351405 }// if( ispdf | isps | istif )
@@ -1458,24 +1428,15 @@ bool SpecMeasManager::handleNonSpectrumFile( const std::string &displayName,
14581428 vector<uint8_t > totaldata ( filesize );
14591429 const bool success = infile.read ( (char *)&(totaldata[0 ]), filesize ).good ();
14601430
1461- if ( !m_viewer->isMobile () )
1462- {
1463- #if ( !USE_SIMPLE_DIALOG_FOR_NOT_SPEC )
1464- w->resize ( WLength::Auto, WLength::Auto );
1465- w->setMaximumSize ( 0.6 *m_viewer->renderedWidth (), 0.8 *m_viewer->renderedHeight () );
1466- #endif
1467- }
14681431
14691432 if ( success )
14701433 {
14711434 resource->setData ( totaldata );
14721435 image->setImageLink ( WLink (resource) );
1473- #if ( USE_SIMPLE_DIALOG_FOR_NOT_SPEC )
14741436 const int ww = m_viewer->renderedWidth ();
14751437 const int wh = m_viewer->renderedHeight ();
14761438 if ( (ww > 120 ) && (wh > 120 ) )
14771439 image->setMaximumSize ( WLength (0.45 *ww,WLength::Unit::Pixel), WLength (wh - 120 , WLength::Unit::Pixel) );
1478- #endif
14791440 stretcher->addWidget ( image.release (), stretcher->rowCount (), 0 , AlignCenter | AlignMiddle );
14801441 }else
14811442 {
@@ -1489,13 +1450,7 @@ bool SpecMeasManager::handleNonSpectrumFile( const std::string &displayName,
14891450 errort->setTextAlignment ( Wt::AlignCenter );
14901451 stretcher->addWidget ( errort, stretcher->rowCount (), 0 , AlignCenter | AlignMiddle );
14911452 }// if( filesize < max_disp_size ) / else
1492-
1493- #if ( !USE_SIMPLE_DIALOG_FOR_NOT_SPEC )
1494- w->show ();
1495- w->resizeToFitOnScreen ();
1496- w->centerWindowHeavyHanded ();
1497- #endif
1498-
1453+
14991454 return true ;
15001455 }// if( isgif || isjpg || ispng || isbmp )
15011456
@@ -1520,11 +1475,8 @@ bool SpecMeasManager::handleNonSpectrumFile( const std::string &displayName,
15201475 orig_peaks, PeakSearchGuiUtils::PeakTemplateFitSrc::CsvFile, seessionid );
15211476 } ) );
15221477
1523- #if ( USE_SIMPLE_DIALOG_FOR_NOT_SPEC )
15241478 delete dialog;
1525- #else
1526- delete w;
1527- #endif
1479+
15281480 return true ;
15291481 }catch ( exception &e )
15301482 {
@@ -1537,38 +1489,55 @@ bool SpecMeasManager::handleNonSpectrumFile( const std::string &displayName,
15371489 errort->setTextAlignment ( Wt::AlignCenter );
15381490 stretcher->addWidget ( errort, stretcher->rowCount (), 0 , AlignCenter | AlignMiddle );
15391491
1540- #if ( !USE_SIMPLE_DIALOG_FOR_NOT_SPEC )
1541- w->show ();
1542- w->resizeToFitOnScreen ();
1543- w->centerWindowHeavyHanded ();
1544- #endif
1545-
15461492 return true ;
15471493 }// try / catch get candidate peaks )
15481494 }// if( we could possible care about propagating peaks from a CSV file )
15491495
15501496
1551- /*
15521497 // Check if this is an InterSpec exported DRF CSV
15531498 if ( header_contains ( " # Detector Response Function" ) )
15541499 {
1555- auto det = DetectorEdit::checkIfFileIsRelEff ( fileLocation );
1500+ shared_ptr<DetectorPeakResponse> det = DetectorEdit::parseRelEffCsvFile ( fileLocation );
15561501
1557- if( det )
1502+ if ( det && det-> isValid () )
15581503 {
1559- // Generate a eff plot, and basic info, and display.
1560- // Then ask user if they want to use DRF; if so save to `InterSpec::writableDataDirectory() + "UploadedDrfs"`
1504+ // TODO: generate a eff plot, and basic info, and display; probably by refactoring DetectorEdit::updateChart()
1505+ // TODO: Ask user if they want to use DRF; if so save to `InterSpec::writableDataDirectory() + "UploadedDrfs"`
1506+ // TODO: handle CSV/TSV files that have multiple DRFs
1507+ // TODO: handle GADRAS style Efficiency.csv files
1508+ // TODO: allow users to rename the DRF.
15611509
1562- #if( USE_SIMPLE_DIALOG_FOR_NOT_SPEC )
1563- delete dialog;
1564- #else
1565- delete w;
1566- #endif
1510+ const string name = Wt::Utils::htmlEncode ( det->name () );
1511+
1512+ string msg = " <p style=\" white-space: nowrap;\" >"
1513+ " This file looks to be a Detector Response Function."
1514+ " </p>"
1515+ " <p style=\" text-align: left; white-space: nowrap;\" >"
1516+ " Name: " + name +
1517+ " </p>"
1518+ " <p>Would you like to use this DRF?</p>"
1519+ ;
1520+
1521+ WText *t = new WText ( WString::fromUTF8 (msg) );
1522+ stretcher->addWidget ( t, stretcher->rowCount (), 0 , AlignCenter | AlignMiddle );
1523+ t->setTextAlignment ( Wt::AlignCenter );
1524+
1525+ dialog->addButton ( " No" ); // no further action necessary if user clicks no; dialog will close
1526+ closeButton->setText ( " Yes" );
1527+ closeButton->clicked ().connect ( std::bind ( [det](){
1528+ InterSpec *interspec = InterSpec::instance ();
1529+ if ( interspec )
1530+ {
1531+ auto sql = interspec->sql ();
1532+ auto user = interspec->m_user ;
1533+ DetectorEdit::updateLastUsedTimeOrAddToDb ( det, user.id (), sql );
1534+ interspec->detectorChanged ().emit ( det ); // This loads it to the foreground spectrum file
1535+ }
1536+ } ) );
15671537
15681538 return true ;
15691539 }
15701540 }// if( maybe a drf )
1571- */
15721541
15731542
15741543 /*
@@ -1600,12 +1569,7 @@ bool SpecMeasManager::handleNonSpectrumFile( const std::string &displayName,
16001569 }//if( header_contains( "Relative Eff" ) && header_contains( "#credit" ) )
16011570 */
16021571
1603-
1604- #if ( USE_SIMPLE_DIALOG_FOR_NOT_SPEC )
16051572 delete dialog;
1606- #else
1607- delete w;
1608- #endif
16091573
16101574 return false ;
16111575}// void handleNonSpectrumFile(...)
0 commit comments