72#include <wx/srchctrl.h>
73#include <wx/tokenzr.h>
75#include <wx/hyperlink.h>
79using namespace std::placeholders;
109 m_aboutTitle =
_HKI(
"KiCad Footprint Library Browser" );
114 m_magneticItems.graphics =
true;
126 m_libListWidth = 200;
129 wxPanel* libPanel =
new wxPanel(
this );
130 wxSizer* libSizer =
new wxBoxSizer( wxVERTICAL );
133 wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER );
134 m_libFilter->SetDescriptiveText(
_(
"Filter" ) );
135 libSizer->Add( m_libFilter, 0, wxEXPAND, 5 );
138 0,
nullptr, wxLB_HSCROLL | wxNO_BORDER );
139 libSizer->Add( m_libList, 1, wxEXPAND, 5 );
141 libPanel->SetSizer( libSizer );
144 wxPanel* fpPanel =
new wxPanel(
this );
145 wxSizer* fpSizer =
new wxBoxSizer( wxVERTICAL );
148 wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER );
149 m_fpFilter->SetDescriptiveText(
_(
"Filter" ) );
150 m_fpFilter->SetToolTip(
151 _(
"Filter on footprint name, keywords, description and pad count.\n"
152 "Search terms are separated by spaces. All search terms must match.\n"
153 "A term which is a number will also match against the pad count." ) );
154 fpSizer->Add( m_fpFilter, 0, wxEXPAND, 5 );
159 m_libFilter->SetMinSize( wxSize( -1, GetTextExtent( wxT(
"qb" ) ).y + 10 ) );
160 m_fpFilter->SetMinSize( wxSize( -1, GetTextExtent( wxT(
"qb" ) ).y + 10 ) );
164 0,
nullptr, wxLB_HSCROLL | wxNO_BORDER );
166 m_fpList->Connect( wxEVT_LEFT_DCLICK,
169 fpSizer->Add( m_fpList, 1, wxEXPAND, 5 );
171 fpPanel->SetSizer( fpSizer );
175 m_canvasType = loadCanvasTypeSetting();
178 GetGalDisplayOptions(), m_canvasType );
179 SetCanvas( drawPanel );
181 SetBoard(
new BOARD() );
197 SetScreen(
new PCB_SCREEN( GetPageSizeIU() ) );
199 GetScreen()->m_Center =
true;
201 GetGalDisplayOptions().m_axesEnabled =
true;
216 m_toolManager->RegisterTool(
new ZOOM_TOOL );
221 m_toolManager->InitTools();
222 m_toolManager->InvokeTool(
"common.InteractiveSelection" );
231 ReCreateLibraryList();
238 if( getCurNickname().size() && getCurFootprintName().size() )
243 id.SetLibItemName( getCurFootprintName() );
245 FOOTPRINT* footprint = loadFootprint(
id );
250 setFPWatcher( footprint );
258 m_auimgr.SetManagedWindow(
this );
261 m_auimgr.AddPane( m_tbTopMain,
EDA_PANE().VToolbar().Name(
"TopMainToolbar" ).Top().Layer(6) );
262 m_auimgr.AddPane( m_tbLeft,
EDA_PANE().VToolbar().Name(
"LeftToolbar" ).
Left().Layer(3) );
263 m_auimgr.AddPane( m_messagePanel,
EDA_PANE().Messages().Name(
"MsgPanel" ).Bottom().Layer(6) );
266 m_auimgr.AddPane( libPanel,
EDA_PANE().Palette().Name(
"Libraries" ).
Left().Layer(2)
267 .CaptionVisible(
false ).MinSize( 100, -1 ).BestSize( 200, -1 ) );
268 m_auimgr.AddPane( fpPanel,
EDA_PANE().Palette().Name(
"Footprints" ).
Left().Layer(1)
269 .CaptionVisible(
false ).MinSize( 100, -1 ).BestSize( 300, -1 ) );
271 m_auimgr.AddPane( GetCanvas(),
EDA_PANE().Canvas().Name(
"DrawFrame" ).
Center() );
276 if( m_libListWidth > 0 )
277 SetAuiPaneSize( m_auimgr, m_auimgr.GetPane(
"Libraries" ), m_libListWidth, -1 );
279 if( m_fpListWidth > 0 )
280 SetAuiPaneSize( m_auimgr, m_auimgr.GetPane(
"Footprints" ), m_fpListWidth, -1 );
283 GetCanvas()->SetCanFocus(
false );
284 GetCanvas()->GetGAL()->SetAxesEnabled(
true );
289 GetCanvas()->GetView()->SetScale( cfg->m_FootprintViewerZoom );
294 ReCreateFootprintList();
309 GetCanvas()->SetEvtHandlerEnabled(
false );
310 m_fpList->Disconnect( wxEVT_LEFT_DCLICK,
329 std::vector<MSG_PANEL_ITEM> msgItems;
330 fp->GetMsgPanelInfo(
this, msgItems );
345 auto addToBoardCond =
348 return (
GetBoard()->GetFirstFootprint() !=
nullptr );
351#define ENABLE( x ) ACTION_CONDITIONS().Enable( x )
352#define CHECK( x ) ACTION_CONDITIONS().Check( x )
410 std::vector<wxString> pinnedMatches;
411 std::vector<wxString> otherMatches;
414 [&](
const wxString& aNickname )
419 pinnedMatches.push_back( aNickname );
423 otherMatches.push_back( aNickname );
429 for(
const wxString& nickname : nicknames )
434 wxStringTokenizer tokenizer(
m_libFilter->GetValue(),
" \t\r\n", wxTOKEN_STRTOK );
436 while( tokenizer.HasMoreTokens() )
438 const wxString term = tokenizer.GetNextToken().Lower();
441 for(
const wxString& nickname : nicknames )
443 if( matcher.
Find( nickname.Lower() ) )
449 for(
const wxString& nickname : pinnedMatches )
452 for(
const wxString& nickname : otherMatches )
458 if(
index == wxNOT_FOUND )
463 wxCommandEvent
dummy;
475 wxCommandEvent
dummy;
496 std::vector<FOOTPRINT*> footprints = adapter->
GetFootprints( nickname,
true );
498 if( footprints.empty() )
501 std::set<wxString> excludes;
505 wxStringTokenizer tokenizer(
m_fpFilter->GetValue(),
" \t\r\n", wxTOKEN_STRTOK );
507 while( tokenizer.HasMoreTokens() )
509 const wxString filterTerm = tokenizer.GetNextToken().Lower();
514 std::vector<SEARCH_TERM> searchTerms = footprint->
GetSearchTerms();
515 int matched = matcher.
ScoreTerms( searchTerms );
530 if( !excludes.count( fpName ) )
534 int index = wxNOT_FOUND;
539 if(
index == wxNOT_FOUND )
546 wxCommandEvent
dummy;
559 wxCommandEvent
dummy;
587 if( aEvent.GetKeyCode() == WXK_UP )
594 else if( aEvent.GetKeyCode() == WXK_DOWN )
601 else if( aEvent.GetKeyCode() == WXK_TAB &&
m_libFilter->HasFocus() )
603 if( !aEvent.ShiftDown() )
608 else if( aEvent.GetKeyCode() == WXK_TAB &&
m_fpFilter->HasFocus() )
610 if( aEvent.ShiftDown() )
615 else if( ( aEvent.GetKeyCode() == WXK_RETURN || aEvent.GetKeyCode() == WXK_NUMPAD_ENTER )
629 int prev = aListBox->GetSelection() - 1;
633 aListBox->SetSelection( prev );
634 aListBox->EnsureVisible( prev );
636 wxCommandEvent
dummy;
648 int next = aListBox->GetSelection() + 1;
650 if(
next < (
int)aListBox->GetCount() )
652 aListBox->SetSelection(
next );
653 aListBox->EnsureVisible(
next );
655 wxCommandEvent
dummy;
718 pad->SetNet( netinfo );
736 if(
GetBoard()->GetFirstFootprint() )
740 if( pcbframe ==
nullptr )
751 DisplayError(
this,
_(
"Previous footprint placement still in progress." ) );
757 if( blocking_dialog )
758 blocking_dialog->Close(
true );
775 pad->SetNetCode( 0 );
786 commit.
Add( newFootprint );
792 commit.
Push(
_(
"Insert Footprint" ) );
822 int maxWidth = cfg->m_FootprintViewer.state.size_x - 80;
855 return &cfg->m_FootprintViewer;
857 wxFAIL_MSG( wxT(
"FOOTPRINT_CHOOSER not running with PCBNEW_SETTINGS" ) );
906 if( event.GetActive() )
912 if( libNicknames.size() !=
m_libList->GetCount() )
916 for(
unsigned ii = 0; ii < libNicknames.size(); ii++ )
918 if( libNicknames[ii] !=
m_libList->GetBaseString( ii ) )
989 title =
_(
"[no library selected]" );
993 title =
_(
"[no library selected]" );
996 title += wxT(
" \u2014 " ) +
_(
"Footprint Library Browser" );
1011 if( selection != wxNOT_FOUND && selection < (
int)
m_fpList->GetCount() - 1 )
1017 if( selection != wxNOT_FOUND && selection > 0 )
1021 if( selection != wxNOT_FOUND )
1023 m_fpList->SetSelection( selection );
1024 m_fpList->EnsureVisible( selection );
1030 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.
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.
MAIL_T Command()
Returns the MAIL_T associated with this mail.
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.