KiCad PCB EDA Suite
TEXT_CTRL_EVAL Class Reference

wxTextCtrl wrapper to handle math expression evaluation. More...

#include <text_ctrl_eval.h>

Inheritance diagram for TEXT_CTRL_EVAL:

Public Member Functions

 TEXT_CTRL_EVAL (wxWindow *aParent, wxWindowID aId, const wxString &aValue=wxEmptyString, const wxPoint &aPos=wxDefaultPosition, const wxSize &aSize=wxDefaultSize, long aStyle=0, const wxValidator &aValidator=wxDefaultValidator, const wxString &aName=wxTextCtrlNameStr)
 
virtual ~TEXT_CTRL_EVAL ()
 
void SetValue (const wxString &aValue) override
 Set a new value in evaluator buffer, and display it in the wxTextCtrl. More...
 

Protected Member Functions

void onTextFocusGet (wxFocusEvent &aEvent)
 
void onTextFocusLost (wxFocusEvent &aEvent)
 
void onTextEnter (wxCommandEvent &aEvent)
 
void evaluate ()
 

Protected Attributes

NUMERIC_EVALUATOR m_eval
 

Numeric expression evaluator

More...
 

Detailed Description

wxTextCtrl wrapper to handle math expression evaluation.

Expressions are evaluated after the text control loses the focus. If user decides to modify the expression, he will get the original expression to modify.

Definition at line 38 of file text_ctrl_eval.h.

Constructor & Destructor Documentation

◆ TEXT_CTRL_EVAL()

TEXT_CTRL_EVAL::TEXT_CTRL_EVAL ( wxWindow *  aParent,
wxWindowID  aId,
const wxString &  aValue = wxEmptyString,
const wxPoint &  aPos = wxDefaultPosition,
const wxSize &  aSize = wxDefaultSize,
long  aStyle = 0,
const wxValidator &  aValidator = wxDefaultValidator,
const wxString &  aName = wxTextCtrlNameStr 
)

Definition at line 27 of file text_ctrl_eval.cpp.

30  : wxTextCtrl( aParent, aId, aValue, aPos, aSize, aStyle | wxTE_PROCESS_ENTER, aValidator, aName ),
32 {
33  Connect( wxEVT_SET_FOCUS,
34  wxFocusEventHandler( TEXT_CTRL_EVAL::onTextFocusGet ), NULL, this );
35  Connect( wxEVT_KILL_FOCUS,
36  wxFocusEventHandler( TEXT_CTRL_EVAL::onTextFocusLost ), NULL, this );
37  Connect( wxEVT_TEXT_ENTER,
38  wxCommandEventHandler( TEXT_CTRL_EVAL::onTextEnter ), NULL, this );
39 }
void onTextFocusGet(wxFocusEvent &aEvent)
void onTextFocusLost(wxFocusEvent &aEvent)
NUMERIC_EVALUATOR m_eval
Numeric expression evaluator
void onTextEnter(wxCommandEvent &aEvent)

References onTextEnter(), onTextFocusGet(), and onTextFocusLost().

◆ ~TEXT_CTRL_EVAL()

virtual TEXT_CTRL_EVAL::~TEXT_CTRL_EVAL ( )
inlinevirtual

Definition at line 46 of file text_ctrl_eval.h.

47  {
48  }

Member Function Documentation

◆ evaluate()

void TEXT_CTRL_EVAL::evaluate ( )
protected

Definition at line 77 of file text_ctrl_eval.cpp.

78 {
79  if( m_eval.Process( GetValue() ) )
80  SetValue( m_eval.Result() );
81 }
void SetValue(const wxString &aValue) override
Set a new value in evaluator buffer, and display it in the wxTextCtrl.
bool Process(const wxString &aString)
NUMERIC_EVALUATOR m_eval
Numeric expression evaluator
wxString Result() const

References m_eval, NUMERIC_EVALUATOR::Process(), NUMERIC_EVALUATOR::Result(), and SetValue().

Referenced by onTextEnter(), and onTextFocusLost().

◆ onTextEnter()

void TEXT_CTRL_EVAL::onTextEnter ( wxCommandEvent &  aEvent)
protected

Definition at line 67 of file text_ctrl_eval.cpp.

68 {
69  evaluate();
70 
71  // Accept the changes and close the parent dialog
72  wxCommandEvent event( wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK );
73  wxPostEvent( GetParent(), event );
74 }

References evaluate().

Referenced by TEXT_CTRL_EVAL().

◆ onTextFocusGet()

void TEXT_CTRL_EVAL::onTextFocusGet ( wxFocusEvent &  aEvent)
protected

Definition at line 49 of file text_ctrl_eval.cpp.

50 {
51  wxString oldStr = m_eval.OriginalText();
52 
53  if( oldStr.length() )
54  SetValue( oldStr );
55 
56  aEvent.Skip();
57 }
wxString OriginalText() const
void SetValue(const wxString &aValue) override
Set a new value in evaluator buffer, and display it in the wxTextCtrl.
NUMERIC_EVALUATOR m_eval
Numeric expression evaluator

References m_eval, NUMERIC_EVALUATOR::OriginalText(), and SetValue().

Referenced by TEXT_CTRL_EVAL().

◆ onTextFocusLost()

void TEXT_CTRL_EVAL::onTextFocusLost ( wxFocusEvent &  aEvent)
protected

Definition at line 60 of file text_ctrl_eval.cpp.

61 {
62  evaluate();
63  aEvent.Skip();
64 }

References evaluate().

Referenced by TEXT_CTRL_EVAL().

◆ SetValue()

void TEXT_CTRL_EVAL::SetValue ( const wxString &  aValue)
override

Set a new value in evaluator buffer, and display it in the wxTextCtrl.

Parameters
aValueis the new value to store and display if aValue is empty, the value "0" is stored and displayed

Definition at line 42 of file text_ctrl_eval.cpp.

43 {
44  wxTextCtrl::SetValue( aValue );
45  m_eval.Clear();
46 }
NUMERIC_EVALUATOR m_eval
Numeric expression evaluator

References NUMERIC_EVALUATOR::Clear(), and m_eval.

Referenced by DIALOG_EXPORT_IDF3::DIALOG_EXPORT_IDF3(), DIALOG_EXPORT_STEP::DIALOG_EXPORT_STEP(), evaluate(), DIALOG_PAD_PROPERTIES::initValues(), onTextFocusGet(), DIALOG_PNS_LENGTH_TUNING_SETTINGS::TransferDataToWindow(), DIALOG_FOOTPRINT_FP_EDITOR::TransferDataToWindow(), and DIALOG_FOOTPRINT_BOARD_EDITOR::TransferDataToWindow().

Member Data Documentation

◆ m_eval

NUMERIC_EVALUATOR TEXT_CTRL_EVAL::m_eval
protected

Numeric expression evaluator

Definition at line 60 of file text_ctrl_eval.h.

Referenced by evaluate(), onTextFocusGet(), and SetValue().


The documentation for this class was generated from the following files: