int NumericEdit::PrecisionForValue( int precision, double value ) { value = Abs( value ); if ( value < 10 ) return precision; return Max( 0, precision - Max( 0, TruncInt( Log( value ) ) ) ); }
void NumericControl::ValueUpdated( Slider& sender, int v ) { int i0, i1; sender.GetRange( i0, i1 ); double d = i1 - i0; double newValue = Round( m_lowerBound + (m_upperBound - m_lowerBound)*((v - i0)/d), m_real ? Max( 0, TruncInt( Log( d ) ) ) : 0 ); if ( newValue != m_value ) { m_value = newValue; edit.SetText( ValueAsString() ); if ( !m_handlers.IsNull() ) if ( m_handlers->onValueUpdated != nullptr ) (m_handlers->onValueUpdatedReceiver->*m_handlers->onValueUpdated)( *this, m_value ); } }
int MaskedStretchProcess::ProcessCommandLine( const StringList& argv ) const { ArgumentList arguments = ExtractArguments( argv, ArgumentItemMode::AsViews, ArgumentOption::AllowWildcards ); MaskedStretchInstance instance( this ); bool launchInterface = false; int count = 0; for ( ArgumentList::const_iterator i = arguments.Begin(); i != arguments.End(); ++i ) { const Argument& arg = *i; if ( arg.IsNumeric() ) { if ( arg.Id() == "b" || arg.Id() == "-background" ) { double b = arg.NumericValue(); if ( b < TheMSTargetBackgroundParameter->MinimumValue() || b > TheMSTargetBackgroundParameter->MaximumValue() ) throw Error( "Target background parameter out of range" ); instance.p_targetBackground = b; } else if ( arg.Id() == "n" || arg.Id() == "-iterations" ) { int n = TruncInt( arg.NumericValue() ); if ( n < int( TheMSNumberOfIterationsParameter->MinimumValue() ) || n > int( TheMSNumberOfIterationsParameter->MaximumValue() ) ) throw Error( "Number of iterations parameter out of range" ); instance.p_numberOfIterations = n; } else throw Error( "Unknown numeric argument: " + arg.Token() ); } else if ( arg.IsString() ) { if ( arg.Id() == "m" || arg.Id() == "-mask-type" ) { if ( arg.StringValue() == "I" || arg.StringValue() == "intensity" ) instance.p_maskType = MSMaskType::Intensity; else if ( arg.StringValue() == "V" || arg.StringValue() == "value" ) instance.p_maskType = MSMaskType::Value; } else throw Error( "Unknown string argument: " + arg.Token() ); } else if ( arg.IsSwitch() ) { throw Error( "Unknown switch argument: " + arg.Token() ); } else if ( arg.IsLiteral() ) { if ( arg.Id() == "-interface" ) launchInterface = true; else if ( arg.Id() == "-help" ) { ShowHelp(); return 0; } else throw Error( "Unknown argument: " + arg.Token() ); } else if ( arg.IsItemList() ) { ++count; if ( arg.Items().IsEmpty() ) { Console().WriteLn( "No view(s) found: " + arg.Token() ); continue; } for ( StringList::const_iterator j = arg.Items().Begin(); j != arg.Items().End(); ++j ) { View v = View::ViewById( *j ); if ( v.IsNull() ) throw Error( "No such view: " + *j ); instance.LaunchOn( v ); } } } if ( launchInterface ) instance.LaunchInterface(); else if ( count == 0 ) { if ( ImageWindow::ActiveWindow().IsNull() ) throw Error( "There is no active image window." ); instance.LaunchOnCurrentView(); } return 0; }