Skip to content

Commit

Permalink
Fix parsing activity uncertainty and distance from SrcLibLineInfo, …
Browse files Browse the repository at this point in the history
…for some input strings.

Also, hopefully improved popup menu allowing you to select source info from the database.
Also, added some smoke tests for parsing source information from these files.
  • Loading branch information
wcjohns committed Aug 2, 2024
1 parent 6bd0c8a commit 4e2f631
Show file tree
Hide file tree
Showing 4 changed files with 326 additions and 9 deletions.
4 changes: 4 additions & 0 deletions InterSpec/MakeDrfSrcDef.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include <Wt/WContainerWidget>

class MaterialDB;
class PopupDivMenu;
class ShieldingSelect;

namespace Wt
Expand Down Expand Up @@ -359,6 +360,9 @@ class MakeDrfSrcDef : public Wt::WContainerWidget
/** Button that lets you select sources that might be in Source.lib files */
Wt::WPushButton *m_lib_src_btn;

/** Menu that pops up when `m_lib_src_btn` is clicked. */
PopupDivMenu *m_lib_src_menu;

Wt::Signal<> m_updated;
};//MakeDrfSrcDef

Expand Down
46 changes: 37 additions & 9 deletions src/MakeDrfSrcDef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
#include "SandiaDecay/SandiaDecay.h"

#include "InterSpec/PeakDef.h"
#include "InterSpec/PopupDiv.h"
#include "InterSpec/InterSpec.h"
#include "InterSpec/MaterialDB.h"
#include "InterSpec/HelpSystem.h"
Expand Down Expand Up @@ -141,7 +142,11 @@ vector<SrcLibLineInfo> SrcLibLineInfo::sources_in_lib( std::istream &file )
SpecUtils::trim( line );

vector<string> fields;
SpecUtils::split( fields, line, " \t" );
// We will allow for a space, a tab, or the U+2002 (Unicode En Space) character to separate fields
boost::algorithm::split( fields, line,
boost::is_any_of(" \t") || boost::is_any_of("\xe2\x80\x82"),
boost::token_compress_on );

if( fields.size() < 3 )
continue;

Expand Down Expand Up @@ -199,12 +204,13 @@ vector<SrcLibLineInfo> SrcLibLineInfo::sources_in_lib( std::istream &file )
}//if( std::regex_match( remark, dist_mtch, dist_expr ) )

std::smatch act_uncert_mtch;
std::regex act_uncert_expr( string(".+([ActivityUncertainty|ActivityUncert]\\s*\\=\\s*(")
+ PhysicalUnits::sm_positiveDecimalRegex
+ ")).*?", std::regex::icase );
const string act_uncert_expr_str = string(".*((Act|Activity)(Uncert|Uncertainty)\\s*[\\=:]\\s*(")
+ PhysicalUnits::sm_positiveDecimalRegex + ")).*?";

std::regex act_uncert_expr( act_uncert_expr_str, std::regex::icase );
if( std::regex_match( src_info.m_comments, act_uncert_mtch, act_uncert_expr ) )
{
string strval = act_uncert_mtch[2].str();
string strval = act_uncert_mtch[4].str();
if( !SpecUtils::parse_double( strval.c_str(), strval.size(), src_info.m_activity_uncert ) )
src_info.m_activity_uncert = -1.0;
}//if( std::regex_match( remark, dist_mtch, dist_expr ) )
Expand Down Expand Up @@ -339,6 +345,7 @@ MakeDrfSrcDef::MakeDrfSrcDef( const SandiaDecay::Nuclide *nuc,
m_useShielding( nullptr ),
m_shieldingSelect( nullptr ),
m_lib_src_btn( nullptr ),
m_lib_src_menu( nullptr ),
m_lib_srcs_for_nuc{},
m_lib_srcs_from_file{},
m_lib_srcs_added{},
Expand All @@ -362,6 +369,11 @@ MakeDrfSrcDef::MakeDrfSrcDef( const SandiaDecay::Nuclide *nuc,

MakeDrfSrcDef::~MakeDrfSrcDef()
{
#if( WT_VERSION >= 0x3070000 )
if( m_lib_src_menu )
delete m_lib_src_menu;
m_lib_src_menu = nullptr;
#endif
}


Expand Down Expand Up @@ -409,7 +421,7 @@ void MakeDrfSrcDef::updateSourceLibNuclides()
if( m_lib_src_btn )
m_lib_src_btn->setHidden( m_lib_srcs_for_nuc.empty() );

WPopupMenu *menu = m_lib_src_btn ? m_lib_src_btn->menu() : nullptr;
WPopupMenu *menu = m_lib_src_menu;
if( menu )
{
const vector<WMenuItem *> old_items = menu->items();
Expand Down Expand Up @@ -632,9 +644,25 @@ void MakeDrfSrcDef::create()
m_lib_src_btn->setIcon( "InterSpec_resources/images/db_small.png" );
m_lib_src_btn->setStyleClass( "LinkBtn DownloadBtn DialogFooterQrBtn" );
m_lib_src_btn->setFloatSide( Wt::Left );
WPopupMenu *menu = new WPopupMenu();
menu->setAutoHide( true );
m_lib_src_btn->setMenu( menu );

#if( WT_VERSION < 0x3070000 )
m_lib_src_menu = new PopupDivMenu( m_lib_src_btn, PopupDivMenu::TransientMenu );
m_lib_src_menu->setJavaScriptMember("wtNoReparent", "true");
#else
// If we have the button own the popup menu, the menu will be placed in our current div holding
// all src info, that may have a significant amount of scroll in it, so we will then have to
// scroll this div, to see all the menu items, which is annoying.
// So instead we'll make the menu a global widget, and just pop it up at the clicked location.
// This is a little less than optimal, and make auto-hide of menu not quite as good, but maybe
// better than the alternative.
m_lib_src_menu = new PopupDivMenu( nullptr, PopupDivMenu::TransientMenu );
m_lib_src_menu->setMaximumSize( WLength::Auto, WLength(15, WLength::FontEm) );
m_lib_src_btn->clicked().connect( boost::bind(
static_cast<void (WPopupMenu::*)(const WMouseEvent &)>(&WPopupMenu::popup),
m_lib_src_menu, boost::placeholders::_1 ) );
#endif

m_lib_src_menu->setAutoHide( true, 2500 );

const bool showToolTips = InterSpecUser::preferenceValue<bool>( "ShowTooltips", InterSpec::instance() );
const char *tooltip = "Sources defined in Source.lib file in your users data directory.<br/>"
Expand Down
8 changes: 8 additions & 0 deletions target/testing/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,14 @@ add_test( NAME TShieldingSourceFitCalc
)


add_executable( test_MakeDrfSrcDef test_MakeDrfSrcDef.cpp )
target_link_libraries( test_MakeDrfSrcDef PRIVATE InterSpecLib )
add_test( NAME TMakeDrfSrcDef
COMMAND $<TARGET_FILE:test_MakeDrfSrcDef> ${BOOST_TEST_CL_ARGS} -- ${DATA_DIR_ARGS}
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
)


# ./test_offlineAnalysis.cpp
#target_link_libraries(test_offlineAnalysis PUBLIC
# debug "${Wt_TEST_DEBUG_LIBRARY}"
Expand Down
Loading

0 comments on commit 4e2f631

Please sign in to comment.