46#include <wx/settings.h>
60#define DEFAULT_FONT_NAME _( "Default Font" )
76 if( !fpFilters.IsEmpty() )
113 m_part( aSymbol->GetLibSymbolRef().get() ),
114 m_symbolNetlist(
netList( aSymbol, aFrame->GetCurrentSheet() ) ),
153 m_mandatoryFieldCount( aLabel->GetMandatoryFieldCount() ),
156 m_referenceValidator( 0 ),
157 m_valueValidator( 0 ),
160 m_filepathValidator( 0 )
173 m_readOnlyAttr =
new wxGridCellAttr;
174 m_readOnlyAttr->SetReadOnly(
true );
176 m_fieldNameAttr =
new wxGridCellAttr;
179 m_fieldNameAttr->SetEditor( nameEditor );
181 m_referenceAttr =
new wxGridCellAttr;
184 m_referenceAttr->SetEditor( referenceEditor );
186 m_valueAttr =
new wxGridCellAttr;
188 if constexpr ( std::is_same_v<T, SCH_FIELD> )
196 m_valueAttr->SetEditor( valueEditor );
202 m_valueAttr->SetEditor( valueEditor );
205 m_footprintAttr =
new wxGridCellAttr;
207 fpIdEditor->SetValidator( m_nonUrlValidator );
208 m_footprintAttr->SetEditor( fpIdEditor );
210 m_urlAttr =
new wxGridCellAttr;
212 urlEditor->SetValidator( m_urlValidator );
213 m_urlAttr->SetEditor( urlEditor );
215 m_nonUrlAttr =
new wxGridCellAttr;
218 m_nonUrlAttr->SetEditor( nonUrlEditor );
220 m_curdir = m_frame->Prj().GetProjectPath();
221 m_filepathAttr =
new wxGridCellAttr;
224 wxString wildCard(
_(
"Schematic Files" ) );
225 std::vector<std::string> exts;
230 filepathEditor->SetValidator( m_filepathValidator );
231 m_filepathAttr->SetEditor( filepathEditor );
233 m_boolAttr =
new wxGridCellAttr;
234 m_boolAttr->SetRenderer(
new wxGridCellBoolRenderer() );
235 m_boolAttr->SetEditor(
new wxGridCellBoolEditor() );
236 m_boolAttr->SetAlignment( wxALIGN_CENTER, wxALIGN_CENTER );
238 wxArrayString vAlignNames;
239 vAlignNames.Add(
_(
"Top" ) );
240 vAlignNames.Add(
_(
"Center" ) );
241 vAlignNames.Add(
_(
"Bottom" ) );
242 m_vAlignAttr =
new wxGridCellAttr;
243 m_vAlignAttr->SetEditor(
new wxGridCellChoiceEditor( vAlignNames ) );
244 m_vAlignAttr->SetAlignment( wxALIGN_CENTER, wxALIGN_CENTER );
246 wxArrayString hAlignNames;
247 hAlignNames.Add(
_(
"Left" ) );
248 hAlignNames.Add(
_(
"Center" ) );
249 hAlignNames.Add(
_(
"Right" ) );
250 m_hAlignAttr =
new wxGridCellAttr;
251 m_hAlignAttr->SetEditor(
new wxGridCellChoiceEditor( hAlignNames ) );
252 m_hAlignAttr->SetAlignment( wxALIGN_CENTER, wxALIGN_CENTER );
254 wxArrayString orientationNames;
255 orientationNames.Add(
_(
"Horizontal" ) );
256 orientationNames.Add(
_(
"Vertical" ) );
257 m_orientationAttr =
new wxGridCellAttr;
258 m_orientationAttr->SetEditor(
new wxGridCellChoiceEditor( orientationNames ) );
259 m_orientationAttr->SetAlignment( wxALIGN_CENTER, wxALIGN_CENTER );
262 wxArrayString existingNetclasses;
268 const std::shared_ptr<NET_SETTINGS>& settings = projectFile.
NetSettings();
270 existingNetclasses.push_back( settings->m_DefaultNetClass->GetName() );
272 for(
const auto& [
name, netclass ] : settings->m_NetClasses )
273 existingNetclasses.push_back(
name );
276 m_netclassAttr =
new wxGridCellAttr;
280 std::vector<std::string> fontNames;
281 Fontconfig()->ListFonts( fontNames, std::string(
Pgm().GetLanguageTag().utf8_str() ) );
283 for(
const std::string&
name : fontNames )
290 m_fontAttr =
new wxGridCellAttr;
293 m_colorAttr =
new wxGridCellAttr;
297 m_eval = std::make_unique<NUMERIC_EVALUATOR>( m_frame->GetUserUnits() );
306 m_readOnlyAttr->DecRef();
307 m_fieldNameAttr->DecRef();
308 m_boolAttr->DecRef();
309 m_referenceAttr->DecRef();
310 m_valueAttr->DecRef();
311 m_footprintAttr->DecRef();
313 m_nonUrlAttr->DecRef();
314 m_filepathAttr->DecRef();
315 m_vAlignAttr->DecRef();
316 m_hAlignAttr->DecRef();
317 m_orientationAttr->DecRef();
318 m_netclassAttr->DecRef();
319 m_fontAttr->DecRef();
320 m_colorAttr->DecRef();
330 GetView()->ForceRefresh();
356 default: wxFAIL;
return wxEmptyString;
376 return aTypeName == wxGRID_VALUE_STRING;
383 return aTypeName == wxGRID_VALUE_BOOL;
395 return CanGetValueAs( aRow, aCol, aTypeName );
407 if( aRow < m_mandatoryFieldCount )
409 tmp = m_fieldNameAttr->Clone();
410 tmp->SetReadOnly(
true );
415 m_fieldNameAttr->IncRef();
416 return m_fieldNameAttr;
422 m_referenceAttr->IncRef();
423 return m_referenceAttr;
427 m_valueAttr->IncRef();
432 m_footprintAttr->IncRef();
433 return m_footprintAttr;
442 m_referenceAttr->IncRef();
443 return m_referenceAttr;
447 m_filepathAttr->IncRef();
448 return m_filepathAttr;
451 && this->at( (
size_t) aRow ).GetCanonicalName() == wxT(
"Netclass" ) )
453 m_netclassAttr->IncRef();
454 return m_netclassAttr;
458 wxString fn = GetValue( aRow,
FDC_NAME );
465 if( templateFn && templateFn->
m_URL )
472 m_nonUrlAttr->IncRef();
483 m_hAlignAttr->IncRef();
487 m_vAlignAttr->IncRef();
491 m_orientationAttr->IncRef();
492 return m_orientationAttr;
499 m_boolAttr->IncRef();
503 m_fontAttr->IncRef();
507 m_colorAttr->IncRef();
520 wxCHECK( aRow < GetNumberRows(), wxEmptyString );
522 wxGrid*
grid = GetView();
523 const T& field = this->at( (
size_t) aRow );
525 if(
grid->GetGridCursorRow() == aRow &&
grid->GetGridCursorCol() == aCol
526 &&
grid->IsCellEditControlShown() )
528 auto it = m_evalOriginal.find( { aRow, aCol } );
530 if( it != m_evalOriginal.end() )
541 if( aRow < m_mandatoryFieldCount )
544 return field.GetName(
false );
548 if( aRow < m_mandatoryFieldCount )
551 return field.GetName(
false );
559 wxFAIL_MSG( wxS(
"Unhandled field owner type." ) );
560 return field.GetName(
false );
567 return StringFromBool( field.IsVisible() );
570 return StringFromBool( field.IsNameShown() );
573 switch ( field.GetEffectiveHorizJustify() )
583 switch ( field.GetEffectiveVertJustify() )
593 return StringFromBool( field.IsItalic() );
596 return StringFromBool( field.IsBold() );
599 return m_frame->StringFromValue( field.GetTextHeight(),
true );
602 if( field.GetTextAngle().IsHorizontal() )
603 return _(
"Horizontal" );
605 return _(
"Vertical" );
608 return m_frame->StringFromValue( field.GetTextPos().x,
true );
611 return m_frame->StringFromValue( field.GetTextPos().y,
true );
614 if( field.GetFont() )
615 return field.GetFont()->GetName();
620 return field.GetTextColor().ToCSSString();
623 return StringFromBool( field.CanAutoplace() );
631 return wxT(
"bad wxWidgets!" );
638 wxCHECK( aRow < GetNumberRows(),
false );
639 const T& field = this->at( (
size_t) aRow );
643 case FDC_SHOWN:
return field.IsVisible();
646 case FDC_BOLD:
return field.IsBold();
649 wxFAIL_MSG( wxString::Format( wxT(
"column %d doesn't hold a bool value" ), aCol ) );
658 wxCHECK( aRow < GetNumberRows(), );
659 T& field = this->at( (
size_t) aRow );
661 wxString value = aValue;
668 m_eval->SetDefaultUnits( m_frame->GetUserUnits() );
670 if( m_eval->Process( value ) )
672 m_evalOriginal[ { aRow, aCol } ] = value;
673 value = m_eval->Result();
685 field.SetName( value );
704 field.SetVisible( BoolFromString( value ) );
708 field.SetNameShown( BoolFromString( value ) );
715 if( value ==
_(
"Left" ) )
717 else if( value ==
_(
"Center" ) )
719 else if( value ==
_(
"Right" ) )
722 wxFAIL_MSG( wxT(
"unknown horizontal alignment: " ) + value );
727 field.SetHorizJustify( horizontalJustification );
729 if( field.IsHorizJustifyFlipped() )
739 if( value ==
_(
"Top" ) )
741 else if( value ==
_(
"Center" ) )
743 else if( value ==
_(
"Bottom" ) )
746 wxFAIL_MSG( wxT(
"unknown vertical alignment: " ) + value);
751 field.SetVertJustify( verticalJustification );
753 if( field.IsVertJustifyFlipped() )
760 field.SetItalic( BoolFromString( value ) );
764 field.SetBold( BoolFromString( value ) );
768 field.SetTextSize(
VECTOR2I( m_frame->ValueFromString( value ),
769 m_frame->ValueFromString( value ) ) );
773 if( value ==
_(
"Horizontal" ) )
775 else if( value ==
_(
"Vertical" ) )
778 wxFAIL_MSG( wxT(
"unknown orientation: " ) + value );
784 pos = field.GetTextPos();
787 pos.
x = m_frame->ValueFromString( value );
789 pos.
y = m_frame->ValueFromString( value );
791 field.SetTextPos( pos );
796 field.SetFont(
nullptr );
799 field.IsItalic() ) );
806 field.SetTextColor( wxColor( value ) );
810 field.SetCanAutoplace( BoolFromString( value ) );
814 wxFAIL_MSG( wxString::Format( wxT(
"column %d doesn't hold a string value" ), aCol ) );
818 m_dialog->OnModify();
820 GetView()->Refresh();
827 wxCHECK( aRow < GetNumberRows(), );
828 T& field = this->at( (
size_t) aRow );
833 field.SetVisible( aValue );
837 field.SetNameShown( aValue );
841 field.SetItalic( aValue );
845 field.SetBold( aValue );
849 field.SetCanAutoplace( aValue );
853 wxFAIL_MSG( wxString::Format( wxT(
"column %d doesn't hold a bool value" ), aCol ) );
857 m_dialog->OnModify();
872 _(
"Browse for footprint" ) );
873 menu.AppendSeparator();
879 _(
"Show datasheet in browser" ) );
880 menu.AppendSeparator();
926 if( aValue == wxS(
"1" ) )
930 else if( aValue == wxS(
"0" ) )
936 wxFAIL_MSG( wxString::Format(
"string '%s' can't be converted to boolean correctly and "
937 "will be perceived as FALSE", aValue ) );
Dialog helper object to sit in the inheritance tree between wxDialog and any class written by wxFormB...
static GR_TEXT_H_ALIGN_T MapHorizJustify(int aHorizJustify)
static GR_TEXT_V_ALIGN_T MapVertJustify(int aVertJustify)
wxString GetValue(int aRow, int aCol) override
bool CanSetValueAs(int aRow, int aCol, const wxString &aTypeName) override
bool GetValueAsBool(int aRow, int aCol) override
void onUnitsChanged(wxCommandEvent &aEvent)
wxString GetColLabelValue(int aCol) override
void SetValue(int aRow, int aCol, const wxString &aValue) override
bool CanGetValueAs(int aRow, int aCol, const wxString &aTypeName) override
FIELDS_GRID_TABLE(DIALOG_SHIM *aDialog, SCH_BASE_FRAME *aFrame, WX_GRID *aGrid, LIB_SYMBOL *aSymbol)
wxGridCellAttr * GetAttr(int row, int col, wxGridCellAttr::wxAttrKind kind) override
wxString StringFromBool(bool aValue) const
void SetValueAsBool(int aRow, int aCol, bool aValue) override
bool BoolFromString(wxString aValue) const
void initGrid(WX_GRID *aGrid)
virtual void showPopupMenu(wxMenu &menu, wxGridEvent &aEvent) override
virtual void doPopupSelection(wxCommandEvent &event) override
Editor for wxGrid cells that adds a file/folder browser to the grid input field.
This class works around a bug in wxGrid where the first keystroke doesn't get sent through the valida...
virtual void SetValidator(const wxValidator &validator) override
virtual void doPopupSelection(wxCommandEvent &event)
virtual void showPopupMenu(wxMenu &menu, wxGridEvent &aEvent)
WX_GRID * m_grid
I don't own the grid, but he owns me.
static FONT * GetFont(const wxString &aFontName=wxEmptyString, bool aBold=false, bool aItalic=false)
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
KIWAY & Kiway() const
Return a reference to the KIWAY that this object has an opportunity to participate in.
A wxFrame capable of the OpenProjectFiles function, meaning it can load a portion of a KiCad project.
virtual bool ShowModal(wxString *aResult=nullptr, wxWindow *aResultantFocusWindow=nullptr)
Show this wxFrame as if it were a modal dialog, with all other instantiated wxFrames disabled until t...
bool Destroy() override
Our version of Destroy() which is virtual from wxWidgets.
virtual KIWAY_PLAYER * Player(FRAME_T aFrameType, bool doCreate=true, wxTopLevelWindow *aParent=nullptr)
Return the KIWAY_PLAYER* given a FRAME_T.
Define a library symbol object.
The backing store for a PROJECT, in JSON format.
std::shared_ptr< NET_SETTINGS > & NetSettings()
static SEARCH_STACK * SchSearchS(PROJECT *aProject)
Accessor for Eeschema search stack.
virtual PROJECT_FILE & GetProjectFile() const
These settings were stored in SCH_BASE_FRAME previously.
TEMPLATES m_TemplateFieldNames
A shim class between EDA_DRAW_FRAME and several derived classes: SYMBOL_EDIT_FRAME,...
Schematic editor (Eeschema) main window.
Instances are attached to a symbol or sheet and provide a place for the symbol's value,...
void OnScintillaCharAdded(SCINTILLA_TRICKS *aScintillaTricks, wxStyledTextEvent &aEvent) const
static const wxString GetDefaultFieldName(const wxString &aName, bool aUseDefaultName)
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
static const wxString GetDefaultFieldName(int aFieldNdx, bool aTranslated=true)
std::unique_ptr< LIB_SYMBOL > & GetLibSymbolRef()
Add cut/copy/paste, dark theme, autocomplete and brace highlighting to a wxStyleTextCtrl instance.
const TEMPLATE_FIELDNAME * GetFieldName(const wxString &aName)
Search for aName in the template field name list.
wxString EnsureFileExtension(const wxString &aFilename, const wxString &aExtension)
It's annoying to throw up nag dialogs when the extension isn't right.
static constexpr EDA_ANGLE & ANGLE_HORIZONTAL
static constexpr EDA_ANGLE & ANGLE_VERTICAL
bool GetAssociatedDocument(wxWindow *aParent, const wxString &aDocName, PROJECT *aProject, SEARCH_STACK *aPaths)
Open a document (file) with the suitable browser.
This file is part of the common library.
#define DEFAULT_FONT_NAME
static wxString netList(SCH_SYMBOL *aSymbol, SCH_SHEET_PATH &aSheetPath)
FONTCONFIG * Fontconfig()
@ FRAME_FOOTPRINT_CHOOSER
@ GRIDTRICKS_FIRST_CLIENT_ID
wxString AddFileExtListToFilter(const std::vector< std::string > &aExts)
Build the wildcard extension file dialog wildcard filter to add to the base message dialog.
const std::string KiCadSchematicFileExtension
@ SHEET_MANDATORY_FIELDS
The first 2 are mandatory, and must be instantiated in SCH_SHEET.
Definitions of control validators for schematic dialogs.
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
wxString UnescapeString(const wxString &aSource)
wxString EscapeString(const wxString &aSource, ESCAPE_CONTEXT aContext)
The Escape/Unescape routines use HTML-entity-reference-style encoding to handle characters which are:...
Hold a name of a symbol's field, field value, and default visibility.
static const wxString GetDefaultFieldName(int aFieldNdx, bool aTranslateForHI=false)
Return a default symbol field name for field aFieldNdx for all components.
Definition for symbol library class.
@ DATASHEET_FIELD
name of datasheet
@ FOOTPRINT_FIELD
Field Name Module PCB, i.e. "16DIP300".
@ VALUE_FIELD
Field Value of part, i.e. "3.3K".
@ MANDATORY_FIELDS
The first 5 are mandatory, and must be instantiated in SCH_COMPONENT and LIB_PART constructors.
@ REFERENCE_FIELD
Field Reference of part, i.e. "IC21".
Custom text control validator definitions.
Definition of file extensions used in Kicad.