Skip to content

Commit

Permalink
Get rid of erroneous error messages when distance units arent include…
Browse files Browse the repository at this point in the history
…d in user input of shielding thicknesses.

Now explicitly append " cm" when no units are seen, before trying to get thickness.
  • Loading branch information
wcjohns committed Sep 4, 2024
1 parent bc82f63 commit e49070a
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 2 deletions.
3 changes: 3 additions & 0 deletions InterSpec/ShieldingSelect.h
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,9 @@ class ShieldingSelect : public Wt::WContainerWidget

const Wt::WLineEdit *materialEdit() const;
const Wt::WLineEdit *thicknessEdit() const;

/** Returns all thickness edits, for the current geometry. */
std::vector<Wt::WLineEdit *> distanceEdits();

/** Sets the spherical thickness value.
Expand Down
1 change: 1 addition & 0 deletions src/DoseCalcWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,7 @@ void DoseCalcWidget::init()
HelpSystem::attachToolTipOn( m_distanceEnter, WString::tr("dcw-tt-distance"), showToolTips );

m_distanceEnter->changed().connect( boost::bind( &DoseCalcWidget::updateResult, this ) );
m_distanceEnter->blurred().connect( boost::bind( &DoseCalcWidget::updateResult, this ) );
m_distanceEnter->enterPressed().connect( boost::bind( &DoseCalcWidget::updateResult, this ) );

m_enterWidgets[i]->addWidget( m_distanceEnter );
Expand Down
35 changes: 34 additions & 1 deletion src/ShieldingSelect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,13 @@ double distance_of_input_text( const WLineEdit *edit )
return PhysicalUnits::stringToDistance( text );
}catch( std::exception & )
{

}

throw runtime_error( "Error converting '" + text + "' to a distance" );

return 0.0;
}//distance_of_input_text(...)

}//namespace


Expand Down Expand Up @@ -1700,6 +1700,39 @@ const Wt::WLineEdit *ShieldingSelect::thicknessEdit() const
return m_thicknessEdit;
}


vector<WLineEdit *> ShieldingSelect::distanceEdits()
{
vector<WLineEdit *> answer;

switch( m_geometry )
{
case GeometryType::Spherical:
answer.push_back( m_thicknessEdit );
break;

case GeometryType::CylinderEndOn:
case GeometryType::CylinderSideOn:
answer.push_back( m_cylRadiusEdit );
answer.push_back( m_cylLengthEdit );
break;

case GeometryType::Rectangular:
answer.push_back( m_rectWidthEdit );
answer.push_back( m_rectHeightEdit );
answer.push_back( m_rectDepthEdit );
break;

case GeometryType::NumGeometryType:
assert(0);
throw runtime_error("shieldingVolume(): invalid geometry");
break;
}//switch( m_geometry )

return answer;
}//vector<WLineEdit *> distanceEdits()


void ShieldingSelect::setSphericalThickness( const double thickness )
{
checkIsCorrectCurrentGeometry( GeometryType::Spherical, __func__ );
Expand Down
24 changes: 23 additions & 1 deletion src/ShieldingSourceDisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,26 @@ using GammaInteractionCalc::TraceActivityType;
namespace
{
const std::string ns_no_uncert_info_txt = "Perform model fit to update and get uncertainties.";
}

/** If a distance WLineEdit has a number, but no distance units, will add a " cm" to the text value. */
void make_sure_distance_units_present( Wt::WLineEdit *edit )
{
if( !edit )
return;

string diststr = edit->text().toUTF8();
SpecUtils::trim( diststr );

if( diststr.empty() )
return;

if( diststr.find_first_not_of( " \t0123456789.eE+-\n" ) == string::npos )
{
diststr += " cm";
edit->setText( diststr );
}
}//void make_sure_distance_units_present( Wt::WLineEdit *edit )
}//namespace


WT_DECLARE_WT_MEMBER
Expand Down Expand Up @@ -5227,6 +5246,9 @@ void ShieldingSourceDisplay::checkDistanceAndThicknessConsistent()
if( type != select->geometry() )
throw runtime_error( "A shieldings geometry didnt match expected." );

for( WLineEdit *edit : select->distanceEdits() )
make_sure_distance_units_present( edit );

// Check to make sure this shielding is larger than all shielding it contains
switch( type )
{
Expand Down

0 comments on commit e49070a

Please sign in to comment.