Filter Library Camera Interface Physics

ControlRealEdit.h

00001 /*
00002  * ControlRealEdit.h - a real entry field.
00003  *
00004  * This file is part of the Camera Filter Library.
00005  * Computer Aided Measurement Environment for Realtime Atomic imaging (Camera)
00006  *
00007  * Copyright (C) 2004, Leiden Probe Microscopy.
00008  * Copyright (C) 2004, Universiteit Leiden.
00009  *
00010  * Authors: Martin J. Moene (original)
00011  *
00012  * $Id: ControlRealEdit.h 202 2005-05-12 11:00:48Z moene $
00013  */
00014 
00015 #ifndef CFL_CONTROLREALEDIT_H
00016 #define CFL_CONTROLREALEDIT_H
00017 
00018 #if _MSC_VER > 1000
00019 #pragma once
00020 #endif // _MSC_VER > 1000
00021 
00022 #include <cfl/ControlFilterEdit.h>      // for base class CFilterEdit
00023 
00024 /**
00025  * \addtogroup cfl_controlnumedit Numeric Edit Control
00026  * \brief numeric edit control.
00027  *
00028  * @{
00029  */
00030 
00031 DECLARE_CLASS( CRealEdit );             // declare various types for class
00032 
00033 /**
00034  * Class CRealEdit is a text edit field for real number entry and validation.
00035  *
00036  * Class CRealEdit provides the following facilities:
00037  * - accept signed or unsigned numbers (also settable in the constructor), SetSigned()
00038  * - obtain the current value, GetValue(), operator real()
00039  * - specify a new value, SetValue(), operator=()
00040  * - specify the format to display the number in, SetFormat()
00041  */
00042 
00043 class CRealEdit : public CFilterEdit
00044 {
00045    DECLARE_DYNAMIC( CRealEdit )
00046 
00047    typedef CRealEdit self;              ///< this type
00048 
00049 public:
00050    typedef double real;                 ///< the real number type
00051 
00052    ///
00053    /// \name Construction
00054    /// @{
00055 
00056    virtual ~CRealEdit();
00057    CRealEdit ( bool bSigned = true );
00058 
00059    /// @}
00060    /// \name Operators
00061    /// @{
00062 
00063    operator   real () const;
00064 
00065    self& operator= ( real value );
00066 
00067    /// @}
00068    /// \name Predicates
00069    /// @{
00070 
00071    /// @}
00072    /// \name Accessors
00073    /// @{
00074 
00075    real    GetValue() const;
00076 
00077    /// @}
00078    /// \name Mutators
00079    /// @{
00080 
00081    void    SetValue ( real value );
00082 
00083    void    SetSigned( bool bSigned  = true );
00084    void    SetFormat( const char* fmt = "%g" );
00085 
00086    /// @} 
00087 
00088 protected:
00089    virtual bool Check( const CString &csText ) ;
00090    virtual bool Match( const CString &csText ) ;
00091 
00092 private:
00093    bool    m_bSigned;                   ///< accept signed numbers
00094    CString m_csFormat;                  ///< display format
00095 };
00096 
00097 /// @} cfl_controlnumedit
00098 
00099 /**
00100  * destructor.
00101  */
00102 
00103 inline CRealEdit::~CRealEdit()
00104 {
00105    ; // do nothing
00106 }
00107 
00108 /**
00109  * (default) constructor.
00110  */
00111 
00112 inline CRealEdit::CRealEdit ( bool bSigned /* = true */ ) :
00113    CFilterEdit(), m_bSigned( bSigned ), m_csFormat( "%g" )
00114 {
00115    ; // do nothing
00116 }
00117 
00118 /**
00119  * convert to real type.
00120  */
00121 
00122 inline CRealEdit::operator CRealEdit::real() const
00123 {
00124    return GetValue();
00125 }
00126 
00127 /**
00128  * assign real value.
00129  */
00130 
00131 inline CRealEdit::self& CRealEdit::operator= ( real value )
00132 {
00133    SetValue( value );
00134    return *this;
00135 }
00136 
00137 /**
00138  * get real value.
00139  */
00140 
00141 inline CRealEdit::real CRealEdit::GetValue() const
00142 {
00143    return _tcstod( c_str_ptr( *this ), NULL );
00144 }
00145 
00146 /**
00147  * set real value.
00148  */
00149 
00150 inline void CRealEdit::SetValue( real value )
00151 {
00152    CString txt;
00153    txt.Format( m_csFormat, value );
00154    SetWindowText ( txt );
00155 }
00156 
00157 /**
00158  * set number to unsigned, signed (default).
00159  */
00160 
00161 inline void CRealEdit::SetSigned ( bool bSigned /* = true */ )
00162 {
00163    m_bSigned = bSigned;
00164 }
00165 
00166 /**
00167  * set the presentation format [\%g].
00168  */
00169 
00170 inline void CRealEdit::SetFormat( const char* format /* = "%g" */ )
00171 {
00172    m_csFormat = format;
00173 }
00174 
00175 #endif // CFL_CONTROLREALEDIT_H
00176 
00177 /*
00178  * end of file
00179  */

Camera Filter Library documentation © 2004-2007 by Leiden Probe Microscopy