29#include <../sim/simulator_frame.h>
35 std::map<int, wxString>* aSignals ) :
38 m_signals( aSignals ),
39 m_helpWindow( nullptr )
43 wxGridCellAttr* attr =
new wxGridCellAttr;
45 m_grid->SetColAttr( 1, attr );
47 for(
const auto& [
id, signal ] : *
m_signals )
64 m_grid->PopEventHandler(
true );
73 int row =
m_grid->GetNumberRows();
76 m_grid->SetCellValue( row, 0, aText );
77 m_grid->SetCellValue( row, 1, wxString::Format( wxS(
"%d" ), aId ) );
79 wxGridCellAttr* attr =
new wxGridCellAttr;
85 m_grid->SetAttr( row, 0, attr );
92 [&]() -> std::pair<int, int>
96 for(
int ii = 0; ii <
m_grid->GetNumberRows(); ++ii )
99 m_grid->GetCellValue( ii, 1 ).ToLong( &usedId );
101 if( usedId >= newId )
106 return {
m_grid->GetNumberRows() - 1, 0 };
116 m_grid->DeleteRows( row, 1 );
123 wxStyledTextCtrl* textCtrl = aTricks->
Scintilla();
124 wxArrayString tokens;
127 tokens.push_back( signal );
129 tokens.push_back( wxS(
"sqrt(x)" ) );
130 tokens.push_back( wxS(
"sin(x)" ) );
131 tokens.push_back( wxS(
"cos(x)" ) );
132 tokens.push_back( wxS(
"tan(x)" ) );
133 tokens.push_back( wxS(
"sinh(x)" ) );
134 tokens.push_back( wxS(
"cosh(x)" ) );
135 tokens.push_back( wxS(
"tanh(x)" ) );
136 tokens.push_back( wxS(
"asin(x)" ) );
137 tokens.push_back( wxS(
"acos(x)" ) );
138 tokens.push_back( wxS(
"atan(x)" ) );
139 tokens.push_back( wxS(
"asinh(x)" ) );
140 tokens.push_back( wxS(
"acosh(x)" ) );
141 tokens.push_back( wxS(
"atanh(x)" ) );
142 tokens.push_back( wxS(
"arctan(x)" ) );
143 tokens.push_back( wxS(
"exp(x)" ) );
144 tokens.push_back( wxS(
"ln(x)" ) );
145 tokens.push_back( wxS(
"log(x)" ) );
146 tokens.push_back( wxS(
"abs(x)" ) );
147 tokens.push_back( wxS(
"nint(x)" ) );
148 tokens.push_back( wxS(
"int(x)" ) );
149 tokens.push_back( wxS(
"floor(x)" ) );
150 tokens.push_back( wxS(
"ceil(x)" ) );
151 tokens.push_back( wxS(
"pow(x,y)" ) );
152 tokens.push_back( wxS(
"pwr(x,y)" ) );
153 tokens.push_back( wxS(
"min(x,y)" ) );
154 tokens.push_back( wxS(
"max(x,y)" ) );
155 tokens.push_back( wxS(
"sgn(x)" ) );
156 tokens.push_back( wxS(
"ternary_fcn(x,y,z)" ) );
157 tokens.push_back( wxS(
"gauss(nom,rvar,sigma)" ) );
158 tokens.push_back( wxS(
"agauss(nom,avar,sigma)" ) );
159 tokens.push_back( wxS(
"unif(nom,rvar)" ) );
160 tokens.push_back( wxS(
"aunif(nom,avar)" ) );
161 tokens.push_back( wxS(
"limit(nom,avar)" ) );
163 int text_pos = textCtrl->GetCurrentPos();
164 int start = textCtrl->WordStartPosition( text_pos,
true );
167 for( start = text_pos - 1; start > 0; start-- )
169 wxUniChar c = textCtrl->GetCharAt( start );
183 else if( wxIsalpha( c ) && parenCount )
187 else if( !wxIsalnum( c ) && c !=
'/' )
196 wxString partial = textCtrl->GetRange( start, text_pos );
200 textCtrl->SetFocus();
206 if( !wxDialog::TransferDataFromWindow() )
214 for(
int ii = 0; ii <
m_grid->GetNumberRows(); ++ii )
216 wxString signal =
m_grid->GetCellValue( ii, 0 );
218 if( !signal.IsEmpty() )
221 m_grid->GetCellValue( ii, 1 ).ToLong( &
id );
222 (*m_signals)[ (int)
id ] = signal;
233#include "../sim/user_defined_signals_help_md.h"
238 wxSize sz( 320, 320 );
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap, int aMinHeight)
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)
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.
void SetDialogSizeInDU(int aWidth, int aHeight)
Set the dialog size, using a "logical" value.
void AddHTML_Text(const wxString &message)
Add HTML text (without any change) to message list.
void ShowModeless()
Show a modeless version of the dialog (without an OK button).
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 > SimPlotVectors()
void OnDeleteRows(const std::function< void(int row)> &aDeleter)
Handles a row deletion event.
void OnAddRow(const std::function< std::pair< int, int >()> &aAdder)
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
void ConvertMarkdown2Html(const wxString &aMarkdownInput, wxString &aHtmlOutput)