23#include <api/common/commands/cross_probe_commands.pb.h>
63#include <wx/statline.h>
64#include <wx/stattext.h>
93 SetAutoLayout(
true );
121 .Caption(
_(
"Footprint Libraries" ) )
125 .Caption(
_(
"Symbol : Footprint Assignments" ) ) );
128 .Caption(
_(
"Filtered Footprints" ) )
132 auto bottomPanel =
new wxPanel(
this );
133 auto panelSizer =
new wxBoxSizer( wxVERTICAL );
135 wxFlexGridSizer* fgSizerStatus =
new wxFlexGridSizer( 3, 1, 0, 0 );
136 fgSizerStatus->SetFlexibleDirection( wxBOTH );
137 fgSizerStatus->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED );
139 m_statusLine1 =
new wxStaticText( bottomPanel, wxID_ANY, wxEmptyString );
142 m_statusLine2 =
new wxStaticText( bottomPanel, wxID_ANY, wxEmptyString );
145 m_statusLine3 =
new wxStaticText( bottomPanel, wxID_ANY, wxEmptyString );
148 panelSizer->Add( fgSizerStatus, 1, wxEXPAND|wxLEFT, 2 );
155 auto buttonsSizer =
new wxBoxSizer( wxHORIZONTAL );
156 auto sdbSizer =
new wxStdDialogButtonSizer();
158 m_saveAndContinue =
new wxButton( bottomPanel, wxID_ANY,
_(
"Apply, Save Schematic && Continue" ) );
161 auto sdbSizerOK =
new wxButton( bottomPanel, wxID_OK );
162 sdbSizer->AddButton( sdbSizerOK );
163 auto sdbSizerCancel =
new wxButton( bottomPanel, wxID_CANCEL );
164 sdbSizer->AddButton( sdbSizerCancel );
167 buttonsSizer->Add( sdbSizer, 0, 0, 5 );
168 panelSizer->Add( buttonsSizer, 0, wxALIGN_RIGHT|wxALL, 5 );
170 bottomPanel->SetSizer( panelSizer );
173 sdbSizerOK->SetDefault();
176 m_auimgr.AddPane( bottomPanel,
EDA_PANE().HToolbar().Name(
"Buttons" ).Bottom().Layer(6) );
182 [
this]( wxAuiPaneInfo& pane,
int width )
186 pane.MinSize( width, -1 );
187 pane.BestSize( width, -1 );
188 pane.MaxSize( width, -1 );
193 pane.MinSize( 20, -1 );
202 if( cfg->m_LibrariesWidth > 0 )
203 setPaneWidth(
m_auimgr.GetPane(
"Libraries" ), cfg->m_LibrariesWidth );
205 if( cfg->m_FootprintsWidth > 0 )
206 setPaneWidth(
m_auimgr.GetPane(
"Footprints" ), cfg->m_FootprintsWidth );
295#define ENABLE( x ) ACTION_CONDITIONS().Enable( x )
296#define CHECK( x ) ACTION_CONDITIONS().Check( x )
334 [
this]( wxMouseEvent& )
340 [
this]( wxMouseEvent& )
347 [
this]( wxCommandEvent& )
355 [
this]( wxCommandEvent& )
363 [
this]( wxCommandEvent& )
370 [
this]( wxCommandEvent& )
375 [
this]( wxCommandEvent& )
382 []( wxSizeEvent& aEvent )
526 if( footprintListHasFocus )
528 else if( symbolListHasFocus )
567 for(
const auto& assoc : curEntry )
570 redoEntries.emplace_back( assoc.Reverse() );
587 bool firstAssoc =
true;
589 for(
const auto& assoc : curEntry )
598 const wxString& aValue,
const wxString& aFootprint )
602 wxString desc = wxString::Format( wxT(
"%3d " ), idx );
604 for(
int ii = aReference.Length(); ii < 8; ++ii )
607 desc += aReference + wxT(
" - " );
609 for(
int ii = aValue.Length(); ii < 16; ++ii )
612 desc += aValue + wxT(
" : " ) + aFootprint;
619 bool aNewEntry,
bool aAddUndoItem )
626 if( symbol ==
nullptr )
635 wxString msg = wxString::Format(
_(
"'%s' is not a valid footprint." ),
647 const std::vector<KIID>& kiids = candidate->
GetKIIDs();
649 if( std::find( kiids.begin(), kiids.end(),
id ) != kiids.end() )
712 if( aSymbol ==
nullptr )
731 wxString candidateName;
735 candidateName = msg.AfterFirst( wxChar(
' ' ) );
737 if( footprintName.Cmp( candidateName ) == 0 )
753 int option = aFilter;
794 filters += wxString::Format( wxT(
" (%s)" ), msg );
804 wxLogTrace(
"CVPCB_PINCOUNT", wxT(
"DisplayStatus: selected '%s' pinCount=%d" ),
806 msg = wxString::Format( wxT(
"%i" ), pc );
815 filters += wxString::Format( wxT(
" (%s)" ), msg );
828 filters += wxString::Format( wxT(
" (%s)" ), msg );
833 if( !textFilter.IsEmpty() )
838 filters +=
_(
"Search Text" ) + wxString::Format( wxT(
" (%s)" ), textFilter );
842 msg =
_(
"No Filtering" );
844 msg.Printf(
_(
"Filtered by %s" ),
filters );
846 msg += wxString::Format(
_(
": %i matching footprints" ),
m_footprintListBox->GetCount() );
858 msg = wxString::Format(
_(
"Description: %s; Keywords: %s" ),
889 if( std::optional<LIBRARY_TABLE_ROW*> optRow = adapter->
GetRow( lib ); optRow )
901 if( !adapter || !adapter->
Rows().size() )
903 wxMessageBox(
_(
"No PCB footprint libraries are listed in the current footprint "
904 "library table." ),
_(
"Configuration Error" ), wxOK | wxICON_ERROR );
910 m_FootprintsList->ReadFootprintFiles( adapter,
nullptr, &progressReporter );
915 statusBar->AddWarningMessages(
"load",
m_FootprintsList->GetErrorMessages() );
924 if(
m_netlist.IsEmpty() && !aClearSelectionOnly )
927 kiapi::common::commands::SyncSelection sync;
929 if( !aClearSelectionOnly )
936 if(
m_netlist.GetComponent( selection ) ==
nullptr )
940 wxString ref =
m_netlist.GetComponent( selection )->GetReference();
942 sync.set_mode( kiapi::common::commands::SSM_ITEMS_ONLY );
943 sync.add_items()->mutable_footprint()->set_reference( ref.ToUTF8() );
967 wxLogTrace(
"CVPCB_PINCOUNT",
968 wxT(
"readSchematicNetlist: payload size=%zu has_libparts=%d has_libpart=%d" ),
969 aNetlist.size(), aNetlist.find(
"(libparts" ) != std::string::npos,
970 aNetlist.find(
"(libpart" ) != std::string::npos );
978 wxString msg = wxString::Format(
_(
"Error loading schematic.\n%s" ),
979 ioe.
What().GetData() );
980 wxMessageBox( msg,
_(
"Load Error" ), wxOK | wxICON_ERROR );
986 for(
unsigned ii = 0; ii <
m_netlist.GetCount(); ii++ )
988 if(
m_netlist.GetComponent( ii )->GetFPID().GetLibItemName() == std::string(
"$noname" ) )
1016 bool operator()(
const wxString& lhs,
const wxString& rhs )
const
1022 std::set<wxString, library_sort> pinnedMatches;
1023 std::set<wxString, library_sort> otherMatches;
1028 [&](
const wxString& aNickname )
1033 pinnedMatches.insert( aNickname );
1037 otherMatches.insert( aNickname );
1046 for(
const wxString& libNickName : libNickNames )
1050 for(
const wxString& nickname : pinnedMatches )
1053 for(
const wxString& nickname : otherMatches )
1064 if( selection >= 0 && selection < (
int)
m_netlist.GetCount() )
1065 return m_netlist.GetComponent( selection );
1079 else if( aIndex < m_symbolsListBox->GetCount() )
1090std::vector<unsigned int>
1093 std::vector<unsigned int> idx;
1104 std::iota( idx.begin(), idx.end(), 0 );
1114 idx.emplace_back( lastIdx );
1117 while( lastIdx > 0 )
1119 idx.emplace_back( lastIdx );
1125 for(
unsigned int i = 0; i <
m_netlist.GetCount(); i++ )
1127 if(
m_netlist.GetComponent( i )->GetFPID().empty() )
1128 idx.emplace_back( i );
1133 for(
unsigned int i = 0; i <
m_netlist.GetCount(); i++ )
1135 if( !
m_netlist.GetComponent( i )->GetFPID().empty() )
1136 idx.emplace_back( i );
1141 wxASSERT_MSG(
false,
"Invalid symbol selection criteria" );
1198 default: wxFAIL_MSG( wxT(
"Invalid status row number" ) );
break;
1213 const std::string& payload = mail.
GetPayload();
constexpr EDA_IU_SCALE unityScale
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
wxBitmap KiBitmap(BITMAPS aBitmap, int aHeightTag)
Construct a wxBitmap from an image identifier Returns the image from the active theme if the image ha...
Manage TOOL_ACTION objects.
void SetConditions(const TOOL_ACTION &aAction, const ACTION_CONDITIONS &aConditions)
Set the conditions the UI elements for activating a specific tool action should use for determining t...
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
Handle actions that are shared between different applications.
Store all of the related component information found in a netlist.
const wxString & GetReference() const
const wxString & GetValue() const
void SetFPID(const LIB_ID &aFPID)
const wxArrayString & GetFootprintFilters() const
const std::vector< KIID > & GetKIIDs() const
const LIB_ID & GetFPID() const
static bool SendToFrame(FRAME_T aTarget, const google::protobuf::Message &aRequest)
Gather all the actions that are shared by tools.
static TOOL_ACTION saveAssociationsToFile
static TOOL_ACTION FilterFPbyLibrary
static TOOL_ACTION filterFPbyPin
static TOOL_ACTION deleteAssoc
static TOOL_ACTION FilterFPbyFPFilters
Footprint Filtering actions.
static TOOL_ACTION saveAssociationsToSchematic
Management actions.
static TOOL_ACTION showFootprintViewer
Open the footprint viewer.
A class to define a footprint association to be made in cvpcb.
unsigned int GetComponentIndex() const
Get the index of the component to modify the association of.
LIB_ID GetNewFootprint() const
Get the new footprint to associate to the component.
Handles actions in main CvPcb window.
bool readNetListAndFpFiles(const std::string &aNetlist)
Load the netlist file built on the fly by Eeschema and loads footprint libraries from fp lib tables.
void SaveSettings(APP_SETTINGS_BASE *aCfg) override
Save common frame parameters to a configuration data file.
void ShowChangedLanguage() override
void SendComponentSelectionToSch(bool aClearSelectionOnly=false)
Send a remote command to Eeschema via a socket,.
bool OpenProjectFiles(const std::vector< wxString > &aFileSet, int aCtl=0) override
Open a project or set of files given by aFileList.
void doCloseWindow() override
CVPCB_UNDO_REDO_LIST m_redoList
ACTION_MENU * m_symbolsContextMenu
wxStaticText * m_statusLine3
CVPCB_MAINFRAME::CONTROL_TYPE GetFocusedControl() const
Find out which control currently has focus.
CVPCB_FILTER_ACTION
The action to apply to a footprint filter when it is modified.
@ FILTER_DISABLE
Turn off the filter.
@ FILTER_ENABLE
Turn on the filter.
@ FILTER_TOGGLE
Toggle the filter state.
void onTextFilterChangedTimer(wxTimerEvent &aEvent)
void onTextFilterChanged(wxCommandEvent &event)
LIBRARY_LISTBOX * m_librariesListBox
void setupTools()
Setup the tool system for the CVPCB main frame.
DISPLAY_FOOTPRINTS_FRAME * GetFootprintViewerFrame() const
wxButton * m_saveAndContinue
void RedoAssociation()
Redo the most recently undone association.
void BuildFootprintsList()
bool LoadFootprintFiles()
Read the list of footprint (*.mod files) and generate the list of footprints.
void SetStatusText(const wxString &aText, int aNumber=0) override
wxString GetSelectedFootprint()
void LoadSettings(APP_SETTINGS_BASE *aCfg) override
Load common frame parameters from a configuration file.
CVPCB_MAINFRAME(KIWAY *aKiway, wxWindow *aParent)
void SetFootprintFilter(FOOTPRINTS_LISTBOX::FP_FILTER_T aFilter, CVPCB_MAINFRAME::CVPCB_FILTER_ACTION aAction)
Set a filter criteria to either on/off or toggle the criteria.
wxStaticText * m_statusLine1
void setupEventHandlers()
Setup event handlers.
void setupUIConditions() override
Setup the UI conditions for the various actions and their controls in this frame.
void SetSelectedComponent(int aIndex, bool aSkipUpdate=false)
Set the currently selected component in the components listbox.
ACTION_MENU * m_footprintContextMenu
CONTROL_TYPE
The type of the controls present in the application.
@ CONTROL_NONE
No controls have focus.
@ CONTROL_LIBRARY
Library listbox.
@ CONTROL_FOOTPRINT
Footprint listbox.
@ CONTROL_COMPONENT
Component listbox.
bool m_skipComponentSelect
wxString formatSymbolDesc(int idx, const wxString &aReference, const wxString &aValue, const wxString &aFootprint)
void SetFocusedControl(CVPCB_MAINFRAME::CONTROL_TYPE aControl)
Set the focus to a specific control.
void OnSelectComponent(wxListEvent &event)
Called when clicking on a component in component list window:
void UndoAssociation()
Undo the most recent associations that were performed.
void BuildLibrariesList()
void DisplayStatus()
Update the information displayed on the status bar at bottom of the main frame.
void KiwayMailIn(KIWAY_MAIL_EVENT &aEvent) override
Receive KIWAY_MAIL_EVENT messages from other players.
void RefreshFootprintViewer()
CVPCB_UNDO_REDO_LIST m_undoList
bool canCloseWindow(wxCloseEvent &aCloseEvent) override
FOOTPRINT_LIST * m_FootprintsList
wxWindow * GetToolCanvas() const override
Canvas access.
std::vector< unsigned int > GetComponentIndices(CVPCB_MAINFRAME::CRITERIA aCriteria=CVPCB_MAINFRAME::ALL_COMPONENTS)
Get the indices for all the components meeting the specified criteria in the components listbox.
void AssociateFootprint(const CVPCB_ASSOCIATION &aAssociation, bool aNewEntry=true, bool aAddUndoItem=true)
Associate a footprint with a specific component in the list.
void configureToolbars() override
bool m_viewerPendingUpdate
void updateFootprintViewerOnIdle(wxIdleEvent &aEvent)
void refreshAfterSymbolSearch(COMPONENT *aSymbol)
wxStaticText * m_statusLine2
FOOTPRINTS_LISTBOX * m_footprintListBox
CRITERIA
Criteria to use to identify sets of components.
@ ALL_COMPONENTS
All components.
@ NA_COMPONENTS
Not associated components.
@ SEL_COMPONENTS
Selected components.
@ ASSOC_COMPONENTS
Associated components.
SYMBOLS_LISTBOX * m_symbolsListBox
TOOL_DISPATCHER * m_toolDispatcher
int readSchematicNetlist(const std::string &aNetlist)
Read the netlist (.net) file built on the fly by Eeschema.
bool SaveFootprintAssociation(bool doSaveSchematic)
Save the edits that the user has done by sending them back to Eeschema via the kiway.
wxTextCtrl * m_tcFilterString
COMPONENT * GetSelectedComponent()
Get the selected component from the component listbox.
virtual APP_SETTINGS_BASE * config() const
Return the settings object used in SaveSettings(), and is overloaded in KICAD_MANAGER_FRAME.
void ShowChangedLanguage() override
Redraw the menus and what not in current language.
virtual void setupUIConditions()
Setup the UI conditions for the various actions and their controls in this frame.
TOOLBAR_SETTINGS * m_toolbarSettings
virtual void RecreateToolbars()
virtual void LoadSettings(APP_SETTINGS_BASE *aCfg)
Load common frame parameters from a configuration file.
virtual void SaveSettings(APP_SETTINGS_BASE *aCfg)
Save common frame parameters to a configuration data file.
ACTION_TOOLBAR * m_tbTopMain
void ReCreateMenuBar()
Recreate the menu bar.
Specialization of the wxAuiPaneInfo class for KiCad panels.
Class that groups generic conditions for editor states.
SELECTION_CONDITION RedoAvailable()
Create a functor that tests if there are any items in the redo queue.
virtual SELECTION_CONDITION UndoAvailable()
Create a functor that tests if there are any items in the undo queue.
SELECTION_CONDITION ContentModified()
Create a functor that tests if the content of the frame is modified.
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
virtual const wxString What() const
A composite of Problem() and Where()
Read the new s-expression based KiCad netlist format.
virtual void LoadNetlist() override
Load the contents of the netlist file into aNetlist.
KISTATUSBAR is a wxStatusBar suitable for Kicad manager.
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.
Carry a payload from one KIWAY_PLAYER to another within a PROJECT.
std::string & GetPayload()
Return the payload, which can be any text but it typically self identifying s-expression.
MAIL_T Command()
Returns the MAIL_T associated with this mail.
KIWAY_PLAYER(KIWAY *aKiway, wxWindow *aParent, FRAME_T aFrameType, const wxString &aTitle, const wxPoint &aPos, const wxSize &aSize, long aStyle, const wxString &aFrameName, const EDA_IU_SCALE &aIuScale)
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
virtual void ExpressMail(FRAME_T aDestination, MAIL_T aCommand, std::string &aPayload, wxWindow *aSource=nullptr, bool aFromOtherThread=false)
Send aPayload to aDestination from aSource.
virtual PROJECT & Prj() const
Return the PROJECT associated with this KIWAY.
std::vector< LIBRARY_TABLE_ROW * > Rows(LIBRARY_TABLE_SCOPE aScope=LIBRARY_TABLE_SCOPE::BOTH, bool aIncludeInvalid=false) const
Like LIBRARY_MANAGER::Rows but filtered to the LIBRARY_TABLE_TYPE of this adapter.
std::optional< LIBRARY_TABLE_ROW * > GetRow(const wxString &aNickname, LIBRARY_TABLE_SCOPE aScope=LIBRARY_TABLE_SCOPE::BOTH) const
Like LIBRARY_MANAGER::GetRow but filtered to the LIBRARY_TABLE_TYPE of this adapter.
std::vector< wxString > GetLibraryNames() const
Returns a list of library nicknames that are available (skips any that failed to load)
std::optional< wxString > GetFullURI(LIBRARY_TABLE_TYPE aType, const wxString &aNickname, bool aSubstituted=false)
Return the full location specifying URI for the LIB, either in original UI form or in environment var...
A logical library item identifier and consists of various portions much like a URI.
bool IsValid() const
Check if this LID_ID is valid.
const wxString GetUniStringLibNickname() const
static const wxString GetPinningSymbol()
virtual COMMON_SETTINGS * GetCommonSettings() const
virtual SETTINGS_MANAGER & GetSettingsManager() const
The backing store for a PROJECT, in JSON format.
static FOOTPRINT_LIBRARY_ADAPTER * FootprintLibAdapter(PROJECT *aProject)
virtual PROJECT_FILE & GetProjectFile() const
T * GetToolbarSettings(const wxString &aFilename)
Return a handle to the given toolbar settings.
Is a LINE_READER that reads from a multiline 8 bit wide std::string.
const char * c_str() const
Multi-thread safe progress reporter dialog, intended for use of tasks that parallel reporting back of...
bool HandleUnsavedChanges(wxWindow *aParent, const wxString &aMessage, const std::function< bool()> &aSaveFunction)
Display a dialog with Save, Cancel and Discard Changes buttons.
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
This file is part of the common library.
@ ID_CVPCB_FOOTPRINT_LIST
@ ID_CVPCB_COMPONENT_LIST
std::vector< CVPCB_ASSOCIATION > CVPCB_UNDO_REDO_ENTRIES
#define KICAD_DEFAULT_DRAWFRAME_STYLE
static wxString From_UTF8(const char *cstring)
Convert a UTF8 encoded C string to a wxString for all wxWidgets build modes.
KICOMMON_API wxFont GetStatusFont(wxWindow *aWindow)
KICOMMON_API wxFont GetMonospacedUIFont(int aRelativeSize=0)
bool contains(const _Container &__container, _Value __value)
Returns true if the container contains the given value.
KICOMMON_API bool PackKiwayApiMessage(const google::protobuf::Message &aMessage, std::string &aBytes)
static PGM_BASE * process
PGM_BASE & Pgm()
The global program "get" accessor.
static const std::vector< std::string > filters
int StrNumCmp(const wxString &aString1, const wxString &aString2, bool aIgnoreCase)
Compare two strings with alphanumerical content.
std::vector< wxString > pinned_fp_libs