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 if( !wxDialog::TransferDataToWindow() )
82 int row =
m_grid->GetNumberRows();
85 m_grid->SetCellValue( row, 0, aText );
86 m_grid->SetCellValue( row, 1, wxString::Format( wxS(
"%d" ), aId ) );
88 wxGridCellAttr* attr =
new wxGridCellAttr;
89#if defined( __WXMSW__ )
102 m_grid->SetAttr( row, 0, attr );
113 for(
int ii = 0; ii <
m_grid->GetNumberRows(); ++ii )
116 m_grid->GetCellValue( ii, 1 ).ToLong( &usedId );
118 if( usedId >= newId )
124 m_grid->MakeCellVisible(
m_grid->GetNumberRows() - 1, 0 );
125 m_grid->SetGridCursor(
m_grid->GetNumberRows() - 1, 0 );
127 m_grid->EnableCellEditControl(
true );
128 m_grid->ShowCellEditControl();
134 int curRow =
m_grid->GetGridCursorRow();
136 if( curRow < 0 || m_grid->GetNumberRows() <= curRow )
140 m_grid->DeleteRows( curRow, 1 );
142 m_grid->MakeCellVisible( std::max( 0, curRow-1 ),
m_grid->GetGridCursorCol() );
143 m_grid->SetGridCursor( std::max( 0, curRow-1 ),
m_grid->GetGridCursorCol() );
150 wxStyledTextCtrl* textCtrl = aTricks->
Scintilla();
151 wxArrayString tokens;
154 tokens.push_back( signal );
156 tokens.push_back( wxS(
"sqrt(x)" ) );
157 tokens.push_back( wxS(
"sin(x)" ) );
158 tokens.push_back( wxS(
"cos(x)" ) );
159 tokens.push_back( wxS(
"tan(x)" ) );
160 tokens.push_back( wxS(
"sinh(x)" ) );
161 tokens.push_back( wxS(
"cosh(x)" ) );
162 tokens.push_back( wxS(
"tanh(x)" ) );
163 tokens.push_back( wxS(
"asin(x)" ) );
164 tokens.push_back( wxS(
"acos(x)" ) );
165 tokens.push_back( wxS(
"atan(x)" ) );
166 tokens.push_back( wxS(
"asinh(x)" ) );
167 tokens.push_back( wxS(
"acosh(x)" ) );
168 tokens.push_back( wxS(
"atanh(x)" ) );
169 tokens.push_back( wxS(
"arctan(x)" ) );
170 tokens.push_back( wxS(
"exp(x)" ) );
171 tokens.push_back( wxS(
"ln(x)" ) );
172 tokens.push_back( wxS(
"log(x)" ) );
173 tokens.push_back( wxS(
"abs(x)" ) );
174 tokens.push_back( wxS(
"nint(x)" ) );
175 tokens.push_back( wxS(
"int(x)" ) );
176 tokens.push_back( wxS(
"floor(x)" ) );
177 tokens.push_back( wxS(
"ceil(x)" ) );
178 tokens.push_back( wxS(
"pow(x,y)" ) );
179 tokens.push_back( wxS(
"pwr(x,y)" ) );
180 tokens.push_back( wxS(
"min(x,y)" ) );
181 tokens.push_back( wxS(
"max(x,y)" ) );
182 tokens.push_back( wxS(
"sgn(x)" ) );
183 tokens.push_back( wxS(
"ternary_fcn(x,y,z)" ) );
184 tokens.push_back( wxS(
"gauss(nom,rvar,sigma)" ) );
185 tokens.push_back( wxS(
"agauss(nom,avar,sigma)" ) );
186 tokens.push_back( wxS(
"unif(nom,rvar)" ) );
187 tokens.push_back( wxS(
"aunif(nom,avar)" ) );
188 tokens.push_back( wxS(
"limit(nom,avar)" ) );
190 int text_pos = textCtrl->GetCurrentPos();
191 int start = textCtrl->WordStartPosition( text_pos,
true );
194 for( start = text_pos - 1; start > 0; start-- )
196 wxUniChar c = textCtrl->GetCharAt( start );
210 else if( wxIsalpha( c ) && parenCount )
214 else if( !wxIsalnum( c ) && c !=
'/' )
221 wxString partial = textCtrl->GetRange( start, text_pos );
224 textCtrl->SetFocus();
230 if( !wxDialog::TransferDataFromWindow() )
238 for(
int ii = 0; ii <
m_grid->GetNumberRows(); ++ii )
240 wxString signal =
m_grid->GetCellValue( ii, 0 );
242 if( !signal.IsEmpty() )
245 m_grid->GetCellValue( ii, 1 ).ToLong( &
id );
246 (*m_signals)[ (int)
id ] = signal;
257#include "../sim/user_defined_signals_help_md.h"
262 wxSize sz( 320, 320 );
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap)
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
This class works around a bug in wxGrid where the first keystroke doesn't get sent through the valida...
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()
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
void ConvertMarkdown2Html(const wxString &aMarkdownInput, wxString &aHtmlOutput)