29#include <../sim/simulator_frame.h>
34 std::map<int, wxString>* aSignals ) :
37 m_signals( aSignals ),
38 m_helpWindow( nullptr )
42 wxGridCellAttr* attr =
new wxGridCellAttr;
44 m_grid->SetColAttr( 1, attr );
46 for(
const auto& [
id, signal ] : *
m_signals )
63 m_grid->PopEventHandler(
true );
72 if( !wxDialog::TransferDataToWindow() )
81 int row =
m_grid->GetNumberRows();
84 m_grid->SetCellValue( row, 0, aText );
85 m_grid->SetCellValue( row, 1, wxString::Format( wxS(
"%d" ), aId ) );
87 wxGridCellAttr* attr =
new wxGridCellAttr;
94 m_grid->SetAttr( row, 0, attr );
105 for(
int ii = 0; ii <
m_grid->GetNumberRows(); ++ii )
108 m_grid->GetCellValue( ii, 1 ).ToLong( &usedId );
116 m_grid->MakeCellVisible(
m_grid->GetNumberRows() - 1, 0 );
117 m_grid->SetGridCursor(
m_grid->GetNumberRows() - 1, 0 );
119 m_grid->EnableCellEditControl(
true );
120 m_grid->ShowCellEditControl();
126 int curRow =
m_grid->GetGridCursorRow();
128 if( curRow < 0 || m_grid->GetNumberRows() <= curRow )
132 m_grid->DeleteRows( curRow, 1 );
134 m_grid->MakeCellVisible( std::max( 0, curRow-1 ),
m_grid->GetGridCursorCol() );
135 m_grid->SetGridCursor( std::max( 0, curRow-1 ),
m_grid->GetGridCursorCol() );
142 wxStyledTextCtrl* textCtrl = aTricks->
Scintilla();
143 wxArrayString tokens;
146 tokens.push_back( signal );
148 tokens.push_back( wxS(
"sqrt(x)" ) );
149 tokens.push_back( wxS(
"sin(x)" ) );
150 tokens.push_back( wxS(
"cos(x)" ) );
151 tokens.push_back( wxS(
"tan(x)" ) );
152 tokens.push_back( wxS(
"sinh(x)" ) );
153 tokens.push_back( wxS(
"cosh(x)" ) );
154 tokens.push_back( wxS(
"tanh(x)" ) );
155 tokens.push_back( wxS(
"asin(x)" ) );
156 tokens.push_back( wxS(
"acos(x)" ) );
157 tokens.push_back( wxS(
"atan(x)" ) );
158 tokens.push_back( wxS(
"asinh(x)" ) );
159 tokens.push_back( wxS(
"acosh(x)" ) );
160 tokens.push_back( wxS(
"atanh(x)" ) );
161 tokens.push_back( wxS(
"arctan(x)" ) );
162 tokens.push_back( wxS(
"exp(x)" ) );
163 tokens.push_back( wxS(
"ln(x)" ) );
164 tokens.push_back( wxS(
"log(x)" ) );
165 tokens.push_back( wxS(
"abs(x)" ) );
166 tokens.push_back( wxS(
"nint(x)" ) );
167 tokens.push_back( wxS(
"int(x)" ) );
168 tokens.push_back( wxS(
"floor(x)" ) );
169 tokens.push_back( wxS(
"ceil(x)" ) );
170 tokens.push_back( wxS(
"pow(x,y)" ) );
171 tokens.push_back( wxS(
"pwr(x,y)" ) );
172 tokens.push_back( wxS(
"min(x,y)" ) );
173 tokens.push_back( wxS(
"max(x,y)" ) );
174 tokens.push_back( wxS(
"sgn(x)" ) );
175 tokens.push_back( wxS(
"ternary_fcn(x,y,z)" ) );
176 tokens.push_back( wxS(
"gauss(nom,rvar,sigma)" ) );
177 tokens.push_back( wxS(
"agauss(nom,avar,sigma)" ) );
178 tokens.push_back( wxS(
"unif(nom,rvar)" ) );
179 tokens.push_back( wxS(
"aunif(nom,avar)" ) );
180 tokens.push_back( wxS(
"limit(nom,avar)" ) );
182 int text_pos = textCtrl->GetCurrentPos();
183 int start = textCtrl->WordStartPosition( text_pos,
true );
186 for( start = text_pos - 1; start > 0; start-- )
188 wxUniChar c = textCtrl->GetCharAt( start );
202 else if( wxIsalpha( c ) && parenCount )
206 else if( !wxIsalnum( c ) && c !=
'/' )
213 wxString partial = textCtrl->GetRange( start, text_pos );
216 textCtrl->SetFocus();
222 if( !wxDialog::TransferDataFromWindow() )
230 for(
int ii = 0; ii <
m_grid->GetNumberRows(); ++ii )
232 wxString signal =
m_grid->GetCellValue( ii, 0 );
234 if( !signal.IsEmpty() )
237 m_grid->GetCellValue( ii, 1 ).ToLong( &
id );
238 (*m_signals)[ (int)
id ] = signal;
wxBitmap KiBitmap(BITMAPS aBitmap, int aHeightTag)
Construct a wxBitmap from an image identifier Returns the image from the active theme if the image ha...
void SetupStandardButtons(std::map< int, wxString > aLabels={})
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
Class DIALOG_USER_DEFINED_SIGNALS_BASE.
STD_BITMAP_BUTTON * m_addButton
STD_BITMAP_BUTTON * m_deleteButton
void onAddSignal(wxCommandEvent &event) override
DIALOG_USER_DEFINED_SIGNALS(SIMULATOR_FRAME *parent, std::map< int, wxString > *aSignals)
bool TransferDataToWindow() override
void onDeleteSignal(wxCommandEvent &event) override
bool TransferDataFromWindow() override
SIMULATOR_FRAME * m_frame
HTML_MESSAGE_BOX * m_helpWindow
void addGridRow(const wxString &aValue, int aId)
void onScintillaCharAdded(wxStyledTextEvent &aEvent, SCINTILLA_TRICKS *aTricks)
~DIALOG_USER_DEFINED_SIGNALS()
std::map< int, wxString > * m_signals
void OnFormattingHelp(wxHyperlinkEvent &aEvent) override
Add mouse and command handling (such as cut, copy, and paste) to a WX_GRID instance.
static HTML_MESSAGE_BOX * ShowSyntaxHelp(wxWindow *aParentWindow)
Add cut/copy/paste, dark theme, autocomplete and brace highlighting to a wxStyleTextCtrl instance.
wxStyledTextCtrl * Scintilla() const
void DoAutocomplete(const wxString &aPartial, const wxArrayString &aTokens)
The SIMULATOR_FRAME holds the main user-interface for running simulations.
const std::vector< wxString > & Signals()
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.