70#include <wx/srchctrl.h>
71#include <wx/tokenzr.h>
73#include <wx/hyperlink.h>
77using namespace std::placeholders;
107 m_aboutTitle =
_HKI(
"KiCad Footprint Library Browser" );
112 m_magneticItems.graphics =
true;
124 m_libListWidth = 200;
127 wxPanel* libPanel =
new wxPanel(
this );
128 wxSizer* libSizer =
new wxBoxSizer( wxVERTICAL );
131 wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER );
132 m_libFilter->SetDescriptiveText(
_(
"Filter" ) );
133 libSizer->Add( m_libFilter, 0, wxEXPAND, 5 );
136 0,
nullptr, wxLB_HSCROLL | wxNO_BORDER );
137 libSizer->Add( m_libList, 1, wxEXPAND, 5 );
139 libPanel->SetSizer( libSizer );
142 wxPanel* fpPanel =
new wxPanel(
this );
143 wxSizer* fpSizer =
new wxBoxSizer( wxVERTICAL );
146 wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER );
147 m_fpFilter->SetDescriptiveText(
_(
"Filter" ) );
148 m_fpFilter->SetToolTip(
149 _(
"Filter on footprint name, keywords, description and pad count.\n"
150 "Search terms are separated by spaces. All search terms must match.\n"
151 "A term which is a number will also match against the pad count." ) );
152 fpSizer->Add( m_fpFilter, 0, wxEXPAND, 5 );
157 m_libFilter->SetMinSize( wxSize( -1, GetTextExtent( wxT(
"qb" ) ).y + 10 ) );
158 m_fpFilter->SetMinSize( wxSize( -1, GetTextExtent( wxT(
"qb" ) ).y + 10 ) );
162 0,
nullptr, wxLB_HSCROLL | wxNO_BORDER );
164 m_fpList->Connect( wxEVT_LEFT_DCLICK,
167 fpSizer->Add( m_fpList, 1, wxEXPAND, 5 );
169 fpPanel->SetSizer( fpSizer );
173 m_canvasType = loadCanvasTypeSetting();
176 GetGalDisplayOptions(), m_canvasType );
177 SetCanvas( drawPanel );
179 SetBoard(
new BOARD() );
195 SetScreen(
new PCB_SCREEN( GetPageSizeIU() ) );
197 GetScreen()->m_Center =
true;
199 GetGalDisplayOptions().m_axesEnabled =
true;
214 m_toolManager->RegisterTool(
new ZOOM_TOOL );
219 m_toolManager->InitTools();
220 m_toolManager->InvokeTool(
"common.InteractiveSelection" );
229 ReCreateLibraryList();
236 if( getCurNickname().size() && getCurFootprintName().size() )
241 id.SetLibItemName( getCurFootprintName() );
243 FOOTPRINT* footprint = loadFootprint(
id );
248 setFPWatcher( footprint );
256 m_auimgr.SetManagedWindow(
this );
259 m_auimgr.AddPane( m_tbTopMain,
EDA_PANE().VToolbar().Name(
"TopMainToolbar" ).Top().Layer(6) );
260 m_auimgr.AddPane( m_tbLeft,
EDA_PANE().VToolbar().Name(
"LeftToolbar" ).
Left().Layer(3) );
261 m_auimgr.AddPane( m_messagePanel,
EDA_PANE().Messages().Name(
"MsgPanel" ).Bottom().Layer(6) );
264 m_auimgr.AddPane( libPanel,
EDA_PANE().Palette().Name(
"Libraries" ).
Left().Layer(2)
265 .CaptionVisible(
false ).MinSize( 100, -1 ).BestSize( 200, -1 ) );
266 m_auimgr.AddPane( fpPanel,
EDA_PANE().Palette().Name(
"Footprints" ).
Left().Layer(1)
267 .CaptionVisible(
false ).MinSize( 100, -1 ).BestSize( 300, -1 ) );
269 m_auimgr.AddPane( GetCanvas(),
EDA_PANE().Canvas().Name(
"DrawFrame" ).
Center() );
274 if( m_libListWidth > 0 )
275 SetAuiPaneSize( m_auimgr, m_auimgr.GetPane(
"Libraries" ), m_libListWidth, -1 );
277 if( m_fpListWidth > 0 )
278 SetAuiPaneSize( m_auimgr, m_auimgr.GetPane(
"Footprints" ), m_fpListWidth, -1 );
281 GetCanvas()->SetCanFocus(
false );
282 GetCanvas()->GetGAL()->SetAxesEnabled(
true );
287 GetCanvas()->GetView()->SetScale( cfg->m_FootprintViewerZoom );
292 ReCreateFootprintList();
307 GetCanvas()->SetEvtHandlerEnabled(
false );
308 m_fpList->Disconnect( wxEVT_LEFT_DCLICK,
327 std::vector<MSG_PANEL_ITEM> msgItems;
328 fp->GetMsgPanelInfo(
this, msgItems );
343 auto addToBoardCond =
346 return (
GetBoard()->GetFirstFootprint() !=
nullptr );
349#define ENABLE( x ) ACTION_CONDITIONS().Enable( x )
350#define CHECK( x ) ACTION_CONDITIONS().Check( x )
408 std::vector<wxString> pinnedMatches;
409 std::vector<wxString> otherMatches;
412 [&](
const wxString& aNickname )
417 pinnedMatches.push_back( aNickname );
421 otherMatches.push_back( aNickname );
427 for(
const wxString& nickname : nicknames )
432 wxStringTokenizer tokenizer(
m_libFilter->GetValue(),
" \t\r\n", wxTOKEN_STRTOK );
434 while( tokenizer.HasMoreTokens() )
436 const wxString term = tokenizer.GetNextToken().Lower();
439 for(
const wxString& nickname : nicknames )
441 if( matcher.
Find( nickname.Lower() ) )
447 for(
const wxString& nickname : pinnedMatches )
450 for(
const wxString& nickname : otherMatches )
456 if(
index == wxNOT_FOUND )
461 wxCommandEvent
dummy;
473 wxCommandEvent
dummy;
494 if( fp_info_list->GetErrorCount() )
497 statusBar->SetLoadWarningMessages( fp_info_list->GetErrorMessages() );
501 if( fp_info_list->GetList().empty() )
505 std::set<wxString> excludes;
509 wxStringTokenizer tokenizer(
m_fpFilter->GetValue(),
" \t\r\n", wxTOKEN_STRTOK );
511 while( tokenizer.HasMoreTokens() )
513 const wxString filterTerm = tokenizer.GetNextToken().Lower();
516 for(
const std::unique_ptr<FOOTPRINT_INFO>& footprint : fp_info_list->GetList() )
518 std::vector<SEARCH_TERM> searchTerms = footprint->GetSearchTerms();
519 int matched = matcher.
ScoreTerms( searchTerms );
521 if( filterTerm.IsNumber() && wxAtoi( filterTerm ) == (
int)footprint->
GetPadCount() )
525 excludes.insert( footprint->GetFootprintName() );
530 for(
const std::unique_ptr<FOOTPRINT_INFO>& footprint : fp_info_list->GetList() )
532 if( !excludes.count( footprint->GetFootprintName() ) )
533 m_fpList->Append( footprint->GetFootprintName() );
536 int index = wxNOT_FOUND;
541 if(
index == wxNOT_FOUND )
548 wxCommandEvent
dummy;
561 wxCommandEvent
dummy;
589 if( aEvent.GetKeyCode() == WXK_UP )
596 else if( aEvent.GetKeyCode() == WXK_DOWN )
603 else if( aEvent.GetKeyCode() == WXK_TAB &&
m_libFilter->HasFocus() )
605 if( !aEvent.ShiftDown() )
610 else if( aEvent.GetKeyCode() == WXK_TAB &&
m_fpFilter->HasFocus() )
612 if( aEvent.ShiftDown() )
617 else if( ( aEvent.GetKeyCode() == WXK_RETURN || aEvent.GetKeyCode() == WXK_NUMPAD_ENTER )
631 int prev = aListBox->GetSelection() - 1;
635 aListBox->SetSelection( prev );
636 aListBox->EnsureVisible( prev );
638 wxCommandEvent
dummy;
650 int next = aListBox->GetSelection() + 1;
652 if(
next < (
int)aListBox->GetCount() )
654 aListBox->SetSelection(
next );
655 aListBox->EnsureVisible(
next );
657 wxCommandEvent
dummy;
720 pad->SetNet( netinfo );
738 if(
GetBoard()->GetFirstFootprint() )
742 if( pcbframe ==
nullptr )
753 DisplayError(
this,
_(
"Previous footprint placement still in progress." ) );
759 if( blocking_dialog )
760 blocking_dialog->Close(
true );
777 pad->SetNetCode( 0 );
788 commit.
Add( newFootprint );
794 commit.
Push(
_(
"Insert Footprint" ) );
824 int maxWidth = cfg->m_FootprintViewer.state.size_x - 80;
857 return &cfg->m_FootprintViewer;
859 wxFAIL_MSG( wxT(
"FOOTPRINT_CHOOSER not running with PCBNEW_SETTINGS" ) );
908 if( event.GetActive() )
914 if( libNicknames.size() !=
m_libList->GetCount() )
918 for(
unsigned ii = 0; ii < libNicknames.size(); ii++ )
920 if( libNicknames[ii] !=
m_libList->GetBaseString( ii ) )
991 title =
_(
"[no library selected]" );
995 title =
_(
"[no library selected]" );
998 title += wxT(
" \u2014 " ) +
_(
"Footprint Library Browser" );
1013 if( selection != wxNOT_FOUND && selection < (
int)
m_fpList->GetCount() - 1 )
1019 if( selection != wxNOT_FOUND && selection > 0 )
1023 if( selection != wxNOT_FOUND )
1025 m_fpList->SetSelection( selection );
1026 m_fpList->EnsureVisible( selection );
1032 selectionTool->ClearSelection(
true );
wxBitmap KiBitmap(BITMAPS aBitmap, int aHeightTag)
Construct a wxBitmap from an image identifier Returns the image from the active theme if the image ha...
static TOOL_ACTION toggleGrid
static TOOL_ACTION cursorSmallCrosshairs
static TOOL_ACTION toggleBoundingBoxes
static TOOL_ACTION centerContents
static TOOL_ACTION measureTool
static TOOL_ACTION selectionTool
static TOOL_ACTION zoomFitScreen
static TOOL_ACTION zoomTool
static TOOL_ACTION selectionClear
Clear the current selection.
static TOOL_ACTION cursor45Crosshairs
static TOOL_ACTION cursorFullCrosshairs
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.
wxString m_ColorTheme
Active color theme name.
virtual void Push(const wxString &aMessage=wxEmptyString, int aCommitFlags=0) override
Execute the changes.
std::shared_ptr< NET_SETTINGS > m_NetSettings
int m_SolderMaskExpansion
Handle actions specific to the board editor in PcbNew.
bool PlacingFootprint() const
Re-entrancy checker for above.
Abstract interface for BOARD_ITEMs capable of storing other items inside.
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT, bool aSkipConnectivity=false) override
Removes an item from the container.
void SetBoardUse(BOARD_USE aUse)
Set what the board is going to be used for.
FOOTPRINT * GetFirstFootprint() const
Get the first footprint on the board or nullptr.
void SetVisibleAlls()
Change the bit-mask of visible element categories and layers.
void RemoveUnusedNets(BOARD_COMMIT *aCommit)
void DeleteAllFootprints()
Remove all footprints from the deque and free the memory associated with them.
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Color settings are a bit different than most of the settings objects in that there can be more than o...
COLOR4D GetColor(int aLayer) const
COMMIT & Add(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Add a new item to the model.
Handle actions that are shared between different applications.
Used to store the component pin name to net name (and pin function) associations stored in a netlist.
const wxString & GetPinFunction() const
virtual APP_SETTINGS_BASE * config() const
Return the settings object used in SaveSettings(), and is overloaded in KICAD_MANAGER_FRAME.
virtual void setupUIConditions()
Setup the UI conditions for the various actions and their controls in this frame.
ACTION_TOOLBAR * m_tbTopMain
int ScoreTerms(std::vector< SEARCH_TERM > &aWeightedTerms)
bool Find(const wxString &aTerm, int &aMatchersTriggered, int &aPosition)
Look in all existing matchers, return the earliest match of any of the existing.
void OnSelectGrid(wxCommandEvent &event)
Command event handler for selecting grid sizes.
void SetMsgPanel(const std::vector< MSG_PANEL_ITEM > &aList)
Clear the message panel and populates it with the contents of aList.
virtual void OnSelectZoom(wxCommandEvent &event)
Set the zoom factor when selected by the zoom list box in the main tool bar.
GAL_DISPLAY_OPTIONS_IMPL & GetGalDisplayOptions()
Return a reference to the gal rendering options used by GAL for rendering.
virtual void UpdateMsgPanel()
Redraw the message panel.
void StopDrawing()
Prevent the GAL canvas from further drawing until it is recreated or StartDrawing() is called.
KIGFX::VIEW_CONTROLS * GetViewControls() const
Return a pointer to the #VIEW_CONTROLS instance used in the panel.
void ForceRefresh()
Force a redraw.
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=nullptr) override
void SetEventDispatcher(TOOL_DISPATCHER *aEventDispatcher)
Set a dispatcher that processes events and forwards them to tools.
void SetFlags(EDA_ITEM_FLAGS aMask)
void ClearFlags(EDA_ITEM_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
virtual void SetParent(EDA_ITEM *aParent)
Specialization of the wxAuiPaneInfo class for KiCad panels.
SELECTION_CONDITION BoundingBoxes()
SELECTION_CONDITION CurrentTool(const TOOL_ACTION &aTool)
Create a functor testing if the specified tool is the current active tool in the frame.
SELECTION_CONDITION CursorSmallCrosshairs()
Create a functor testing if the cursor is full screen in a frame.
SELECTION_CONDITION GridVisible()
Create a functor testing if the grid is visible in a frame.
SELECTION_CONDITION Cursor45Crosshairs()
SELECTION_CONDITION CursorFullCrosshairs()
void ReadWindowSettings(WINDOW_SETTINGS &aCfg)
Read GAL config options from application-level config.
A color representation with 4 components: red, green, blue, alpha.
bool m_axesEnabled
Crosshair drawing mode.
An interface for classes handling user events controlling the view behavior such as zooming,...
virtual void SetCrossHairCursorPosition(const VECTOR2D &aPosition, bool aWarpView=true)=0
Move the graphic crosshair cursor to the requested position expressed in world coordinates.
VECTOR2D GetCursorPosition() const
Return the current cursor position in world coordinates.
void Clear()
Remove all items from the view.
Carry a payload from one KIWAY_PLAYER to another within a PROJECT.
MAIL_T Command()
Returns the MAIL_T associated with this mail.
KIWAY & Kiway() const
Return a reference to the KIWAY that this object has an opportunity to participate in.
bool Destroy() override
Our version of Destroy() which is virtual from wxWidgets.
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
virtual KIWAY_PLAYER * Player(FRAME_T aFrameType, bool doCreate=true, wxTopLevelWindow *aParent=nullptr)
Return the KIWAY_PLAYER* given a FRAME_T.
wxWindow * GetBlockingDialog()
Gets the window pointer to the blocking dialog (to send it signals)
virtual PROJECT & Prj() const
Return the PROJECT associated with this KIWAY.
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) const
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.
int SetLibNickname(const UTF8 &aLibNickname)
Override the logical library name portion of the LIB_ID to aLibNickname.
const UTF8 & GetLibItemName() const
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
static const wxString GetPinningSymbol()
void SetClearance(int aClearance)
Handle the data for a net.
void SetNetname(const wxString &aNewName)
Set the long netname to aNetName, the short netname to the last token in the long netname's path,...
std::shared_ptr< NETCLASS > GetDefaultNetclass()
Gets the default netclass for the project.
DISPLAY_OPTIONS m_Display
FLIP_DIRECTION m_FlipDirection
int m_FootprintViewerFPListWidth
int m_FootprintViewerLibListWidth
Gather all the actions that are shared by tools.
static TOOL_ACTION padDisplayMode
static TOOL_ACTION rehatchShapes
static TOOL_ACTION graphicsOutlines
Display footprint graphics as outlines.
static TOOL_ACTION fpAutoZoom
static TOOL_ACTION textOutlines
Display texts as lines.
static TOOL_ACTION showPadNumbers
static TOOL_ACTION placeFootprint
static TOOL_ACTION saveFpToBoard
Base PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
void LoadSettings(APP_SETTINGS_BASE *aCfg) override
Load common frame parameters from a configuration file.
void setFPWatcher(FOOTPRINT *aFootprint)
Create or removes a watcher on the specified footprint.
PCBNEW_SETTINGS * GetPcbNewSettings() const
PCB_BASE_FRAME(KIWAY *aKiway, wxWindow *aParent, FRAME_T aFrameType, const wxString &aTitle, const wxPoint &aPos, const wxSize &aSize, long aStyle, const wxString &aFrameName)
void CommonSettingsChanged(int aFlags) override
Notification event that some of the common (suite-wide) settings have changed.
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
void SaveSettings(APP_SETTINGS_BASE *aCfg) override
Save common frame parameters to a configuration data file.
PCB_DISPLAY_OPTIONS m_displayOptions
void PlaceFootprint(FOOTPRINT *aFootprint, bool aRecreateRatsnest=true, std::optional< VECTOR2I > aPosition=std::nullopt)
Place aFootprint at the current cursor position (or provided one) and updates footprint coordinates w...
virtual void Update3DView(bool aMarkDirty, bool aRefresh, const wxString *aTitle=nullptr)
Update the 3D view, if the viewer is opened by this frame.
Handle actions that are shared between different frames in PcbNew.
void UpdateColors()
Update the color settings in the painter and GAL.
virtual KIGFX::PCB_VIEW * GetView() const override
Return a pointer to the #VIEW instance used in the panel.
void DisplayBoard(BOARD *aBoard, PROGRESS_REPORTER *aReporter=nullptr)
Add all items from the current board to the VIEW, so they can be displayed by GAL.
Group generic conditions for PCB editor states.
SELECTION_CONDITION PadFillDisplay()
Create a functor that tests if the frame fills the pads.
SELECTION_CONDITION GraphicsFillDisplay()
Create a functor that tests if the frame fills graphics items.
SELECTION_CONDITION FootprintViewerAutoZoom()
Create a functor that tests if the footprint viewer should auto zoom on new footprints.
SELECTION_CONDITION PadNumbersDisplay()
Create a functor that tests if the pad numbers are displayed.
SELECTION_CONDITION TextFillDisplay()
Create a functor that tests if the frame fills text items.
The main frame for Pcbnew.
bool m_FootprintViewerAutoZoomOnSelect
true to use automatic zoom on fp selection
double m_FootprintViewerZoom
The last zoom level used (0 for auto)
virtual COMMON_SETTINGS * GetCommonSettings() const
virtual LIBRARY_MANAGER & GetLibraryManager() const
The backing store for a PROJECT, in JSON format.
static FOOTPRINT_LIBRARY_ADAPTER * FootprintLibAdapter(PROJECT *aProject)
@ PCB_FOOTPRINT_VIEWER_FP_NAME
@ PCB_FOOTPRINT_VIEWER_LIB_NICKNAME
virtual PROJECT_FILE & GetProjectFile() const
virtual void SetRString(RSTRING_T aStringId, const wxString &aString)
Store a "retained string", which is any session and project specific string identified in enum RSTRIN...
virtual const wxString & GetRString(RSTRING_T aStringId)
Return a "retained string", which is any session and project specific string identified in enum RSTRI...
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
void DisplayError(wxWindow *aParent, const wxString &aText)
Display an error or warning message box with aMessage.
This file is part of the common library.
Declaration of the eda_3d_viewer class.
#define KICAD_DEFAULT_DRAWFRAME_STYLE
#define FOOTPRINT_VIEWER_FRAME_NAME
#define IGNORE_PARENT_GROUP
#define IS_NEW
New item, just created.
Abstract pattern-matching tool and implementations.
Message panel definition file.
bool contains(const _Container &__container, _Value __value)
Returns true if the container contains the given value.
@ ID_MODVIEW_FOOTPRINT_LIST
@ ID_MODVIEW_FOOTPRINT_FILTER
static PGM_BASE * process
PGM_BASE & Pgm()
The global program "get" accessor.
T * GetToolbarSettings(const wxString &aFilename)
T * GetAppSettings(const char *aFilename)
KIWAY Kiway(KFCTL_STANDALONE)
std::vector< FAB_LAYER_COLOR > dummy
std::vector< wxString > pinned_fp_libs
bool m_ShowGlobalRatsnest
Store the common settings that are saved and loaded for each window / frame.
VECTOR2< int32_t > VECTOR2I
VECTOR2< double > VECTOR2D
Definition of file extensions used in Kicad.
void SetAuiPaneSize(wxAuiManager &aManager, wxAuiPaneInfo &aPane, int aWidth, int aHeight)
Sets the size of an AUI pane, working around http://trac.wxwidgets.org/ticket/13180.