KiCad PCB EDA Suite
Loading...
Searching...
No Matches
footprint_editor_control.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2014-2019 CERN
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 * @author Maciej Suminski <[email protected]>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, you may find one here:
20 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21 * or you may search the http://www.gnu.org website for the version 2 license,
22 * or you may write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 */
25
26#include <advanced_config.h>
27#include <string_utils.h>
28#include <pgm_base.h>
29#include <tool/tool_manager.h>
31#include <tools/pcb_actions.h>
32#include <eda_doc.h>
35#include <pcbnew_id.h>
36#include <confirm.h>
37#include <kidialog.h>
38#include <wx/filename.h>
40#include <launch_ext.h> // To default when file manager setting is empty
41#include <gestfich.h> // To open with a text editor
42#include <widgets/wx_infobar.h>
43#include <footprint.h>
44#include <pad.h>
45#include <pcb_group.h>
46#include <zone.h>
47#include <fp_lib_table.h>
51#include <kiway.h>
52#include <project_pcb.h>
53#include <view/view_controls.h>
54
55#include <memory>
56
58
59
61 PCB_TOOL_BASE( "pcbnew.ModuleEditor" ),
62 m_frame( nullptr ),
63 m_checkerDialog( nullptr )
64{
65}
66
67
69{
70 m_frame = getEditFrame<FOOTPRINT_EDIT_FRAME>();
71
72 if( m_checkerDialog )
74}
75
76
78{
80
81 // Build a context menu for the footprint tree
82 //
83 CONDITIONAL_MENU& ctxMenu = m_menu->GetMenu();
84
85 auto libSelectedCondition =
86 [ this ]( const SELECTION& aSel )
87 {
89 return !sel.GetLibNickname().empty() && sel.GetLibItemName().empty();
90 };
91
92 // The libInferredCondition allows you to do things like New Symbol and Paste with a
93 // symbol selected (in other words, when we know the library context even if the library
94 // itself isn't selected.
95 auto libInferredCondition =
96 [ this ]( const SELECTION& aSel )
97 {
99 return !sel.GetLibNickname().empty();
100 };
101
102 auto fpSelectedCondition =
103 [ this ]( const SELECTION& aSel )
104 {
106 return !sel.GetLibNickname().empty() && !sel.GetLibItemName().empty();
107 };
108
109 auto fpExportCondition =
110 [ this ]( const SELECTION& aSel )
111 {
113 return fp != nullptr;
114 };
115
116 auto canOpenExternally =
117 [ this ]( const SELECTION& aSel )
118 {
119 // The option is shown if the editor has no current edits,
120 // dumb/simple guard against opening a new file that does not exist on disk
121 bool ret = !m_frame->IsContentModified();
122 return ret;
123 };
124
125// clang-format off
126 ctxMenu.AddItem( PCB_ACTIONS::newFootprint, libSelectedCondition, 10 );
127 ctxMenu.AddItem( PCB_ACTIONS::createFootprint, libSelectedCondition, 10 );
128
129 ctxMenu.AddSeparator( 10 );
130 ctxMenu.AddItem( ACTIONS::save, SELECTION_CONDITIONS::ShowAlways, 10 );
131 ctxMenu.AddItem( ACTIONS::saveAs, libSelectedCondition || fpSelectedCondition, 10 );
132 ctxMenu.AddItem( ACTIONS::revert, libSelectedCondition || libInferredCondition, 10 );
133
134 ctxMenu.AddSeparator( 10 );
135 ctxMenu.AddItem( PCB_ACTIONS::cutFootprint, fpSelectedCondition, 10 );
136 ctxMenu.AddItem( PCB_ACTIONS::copyFootprint, fpSelectedCondition, 10 );
137 ctxMenu.AddItem( PCB_ACTIONS::pasteFootprint, libInferredCondition, 10 );
138 ctxMenu.AddItem( PCB_ACTIONS::duplicateFootprint, fpSelectedCondition, 10 );
139 ctxMenu.AddItem( PCB_ACTIONS::renameFootprint, fpSelectedCondition, 10 );
140 ctxMenu.AddItem( PCB_ACTIONS::deleteFootprint, fpSelectedCondition, 10 );
141
142 ctxMenu.AddSeparator( 100 );
143 ctxMenu.AddItem( PCB_ACTIONS::importFootprint, libInferredCondition, 100 );
144 ctxMenu.AddItem( PCB_ACTIONS::exportFootprint, fpExportCondition, 100 );
145
147 {
148 ctxMenu.AddSeparator( 200 );
149 ctxMenu.AddItem( ACTIONS::openWithTextEditor, canOpenExternally && fpSelectedCondition, 200 );
150 }
151
153 {
154 ctxMenu.AddSeparator( 200 );
155 ctxMenu.AddItem( ACTIONS::openDirectory, canOpenExternally && ( libSelectedCondition || fpSelectedCondition ), 200 );
156 }
157// clang-format on
158
159 libraryTreeTool->AddContextMenuItems( &ctxMenu );
160
161 return true;
162}
163
164
166 const LIB_ID& aTargetLib )
167{
168 const wxString libraryName = aTargetLib.GetUniStringLibNickname();
169
170 if( aTargetLib.GetLibNickname().empty() )
171 {
172 // Do nothing - the footprint will need to be saved manually to assign
173 // to a library.
174 }
175 else
176 {
178
179 if( !libTable.IsFootprintLibWritable( libraryName ) )
180 {
181 // If the library is not writeable, we'll give the user a
182 // footprint not in a library. But add a warning to let them know
183 // they didn't quite get what they wanted.
185 wxString::Format(
186 _( "The footprint could not be added to the selected library ('%s'). "
187 "This library is read-only." ),
188 libraryName ),
189 false );
190 // And the footprint will need to be saved manually
191 }
192 else
193 {
194 // Go ahead and save it to the library
195 LIB_ID fpid = aFootprint.GetFPID();
196 fpid.SetLibNickname( aTargetLib.GetLibNickname() );
197 aFootprint.SetFPID( fpid );
198 m_frame->SaveFootprint( &aFootprint );
200 }
201 }
202}
203
204
206{
207 const LIB_ID selected = m_frame->GetTargetFPID();
208 const wxString libraryName = selected.GetUniStringLibNickname();
209 FOOTPRINT* newFootprint = m_frame->CreateNewFootprint( wxEmptyString, libraryName );
210
211 if( !newFootprint )
212 return 0;
213
214 if( !m_frame->Clear_Pcb( true ) )
215 return 0;
216
218 m_frame->AddFootprintToBoard( newFootprint );
219
220 // Initialize data relative to nets and netclasses (for a new footprint the defaults are
221 // used). This is mandatory to handle and draw pads.
223 newFootprint->SetPosition( VECTOR2I( 0, 0 ) );
224 newFootprint->ClearFlags();
225
226 m_frame->Zoom_Automatique( false );
228
229 tryToSaveFootprintInLibrary( *newFootprint, selected );
230
233 m_frame->Update3DView( true, true );
234
235 m_frame->SyncLibraryTree( false );
236 return 0;
237}
238
239
241{
242 LIB_ID selected = m_frame->GetLibTree()->GetSelectedLibId();
243 wxString libraryName = selected.GetUniStringLibNickname();
244
246 {
247 if( !HandleUnsavedChanges( m_frame, _( "The current footprint has been modified. "
248 "Save changes?" ),
249 [&]() -> bool
250 {
251 return m_frame->SaveFootprint( footprint() );
252 } ) )
253 {
254 return 0;
255 }
256 }
257
259 {
260 FOOTPRINT_WIZARD_FRAME* wizard = static_cast<FOOTPRINT_WIZARD_FRAME*>( frame );
261
262 if( wizard->ShowModal( nullptr, m_frame ) )
263 {
264 // Creates the new footprint from python script wizard
265 FOOTPRINT* newFootprint = wizard->GetBuiltFootprint();
266
267 if( newFootprint ) // i.e. if create footprint command is OK
268 {
269 m_frame->Clear_Pcb( false );
270
272 // Add the new object to board
273 m_frame->AddFootprintToBoard( newFootprint );
274
275 // Initialize data relative to nets and netclasses (for a new footprint the
276 // defaults are used). This is mandatory to handle and draw pads.
278 newFootprint->SetPosition( VECTOR2I( 0, 0 ) );
279 newFootprint->ClearFlags();
280
281 m_frame->Zoom_Automatique( false );
283 m_frame->OnModify();
284
285 tryToSaveFootprintInLibrary( *newFootprint, selected );
286
288 canvas()->Refresh();
289 m_frame->Update3DView( true, true );
290
291 m_frame->SyncLibraryTree( false );
292 }
293 }
294
295 wizard->Destroy();
296 }
297
298 return 0;
299}
300
301
303{
304 if( !footprint() ) // no loaded footprint
305 return 0;
306
308 {
310 {
311 view()->Update( footprint() );
312
313 canvas()->ForceRefresh();
316 }
317 }
318
320 return 0;
321}
322
323
325{
327 {
328 // Save Library As
329 const wxString& src_libNickname = m_frame->GetTargetFPID().GetLibNickname();
330 wxString src_libFullName = PROJECT_PCB::PcbFootprintLibs( &m_frame->Prj() )->GetFullURI( src_libNickname );
331
332 if( m_frame->SaveLibraryAs( src_libFullName ) )
333 m_frame->SyncLibraryTree( true );
334 }
335 else if( m_frame->GetTargetFPID() == m_frame->GetLoadedFPID() )
336 {
337 // Save Footprint As
339 {
340 view()->Update( footprint() );
342
343 // Get rid of the save-will-update-board-only (or any other dismissable warning)
344 WX_INFOBAR* infobar = m_frame->GetInfoBar();
345
346 if( infobar->IsShownOnScreen() && infobar->HasCloseButton() )
347 infobar->Dismiss();
348
349 canvas()->ForceRefresh();
350 m_frame->SyncLibraryTree( true );
351 }
352 }
353 else
354 {
355 // Save Selected Footprint As
357
359 {
360 m_frame->SyncLibraryTree( true );
362 }
363 }
364
366 return 0;
367}
368
369
371{
372 getEditFrame<FOOTPRINT_EDIT_FRAME>()->RevertFootprint();
373 return 0;
374}
375
376
378{
380
381 if( fpID == m_frame->GetLoadedFPID() )
382 {
383 m_copiedFootprint = std::make_unique<FOOTPRINT>( *m_frame->GetBoard()->GetFirstFootprint() );
384 m_copiedFootprint->SetParent( nullptr );
385 }
386 else
387 {
388 m_copiedFootprint.reset( m_frame->LoadFootprint( fpID ) );
389 }
390
391 if( aEvent.IsAction( &PCB_ACTIONS::cutFootprint ) )
392 DeleteFootprint( aEvent );
393
394 return 0;
395}
396
397
399{
401 {
402 wxString newLib = m_frame->GetLibTree()->GetSelectedLibId().GetLibNickname();
403 wxString newName = m_copiedFootprint->GetFPID().GetLibItemName();
404
405 while( PROJECT_PCB::PcbFootprintLibs( &m_frame->Prj() )->FootprintExists( newLib, newName ) )
406 newName += _( "_copy" );
407
408 m_copiedFootprint->SetFPID( LIB_ID( newLib, newName ) );
410
411 m_frame->SyncLibraryTree( true );
415 }
416
417 return 0;
418}
419
420
422{
425
426 if( fpID == m_frame->GetLoadedFPID() )
428 else
430
432 {
433 m_frame->SyncLibraryTree( true );
437 }
438
439 return 0;
440}
441
442
444{
447
449 wxString libraryName = fpID.GetLibNickname();
450 wxString oldName = fpID.GetLibItemName();
451 wxString newName;
452 wxString msg;
453
454 if( !libTool->RenameLibrary( _( "Change Footprint Name" ), oldName,
455 [&]( const wxString& aNewName )
456 {
457 newName = aNewName;
458
459 if( newName.IsEmpty() )
460 {
461 wxMessageBox( _( "Footprint must have a name." ) );
462 return false;
463 }
464
465 // If no change, accept it without prompting
466 if( oldName != newName && tbl->FootprintExists( libraryName, newName ) )
467 {
468 msg = wxString::Format( _( "Footprint '%s' already exists in library '%s'." ),
469 newName, libraryName );
470
471 KIDIALOG errorDlg( m_frame, msg, _( "Confirmation" ),
472 wxOK | wxCANCEL | wxICON_WARNING );
473 errorDlg.SetOKLabel( _( "Overwrite" ) );
474
475 return errorDlg.ShowModal() == wxID_OK;
476 }
477
478 return true;
479 } ) )
480 {
481 return 0; // canceled by user
482 }
483
484 if( newName == oldName )
485 return 0;
486
487 FOOTPRINT* footprint = nullptr;
488
489 if( fpID == m_frame->GetLoadedFPID() )
490 {
492
493 if( footprint )
494 {
495 footprint->SetFPID( LIB_ID( libraryName, newName ) );
496
497 if( footprint->GetValue() == oldName )
498 footprint->SetValue( newName );
499
500 m_frame->OnModify();
502 }
503 }
504 else
505 {
507
508 if( footprint )
509 {
510 try
511 {
512 footprint->SetFPID( LIB_ID( libraryName, newName ) );
513
514 if( footprint->GetValue() == oldName )
515 footprint->SetValue( newName );
516
518
519 PROJECT_PCB::PcbFootprintLibs( &m_frame->Prj() )->FootprintDelete( libraryName, oldName );
520 }
521 catch( const IO_ERROR& ioe )
522 {
523 DisplayErrorMessage( m_frame, _( "Error renaming footprint" ), ioe.What() );
524 }
525 catch( ... )
526 {
527 // Best efforts...
528 }
529 }
530 }
531
532 wxDataViewItem treeItem = m_frame->GetLibTreeAdapter()->FindItem( fpID );
533
534 if( footprint )
535 {
536 m_frame->UpdateLibraryTree( treeItem, footprint );
537 m_frame->FocusOnLibID( LIB_ID( libraryName, newName ) );
538 }
539
540 return 0;
541}
542
543
545{
546 FOOTPRINT_EDIT_FRAME* frame = getEditFrame<FOOTPRINT_EDIT_FRAME>();
547
548 if( frame->DeleteFootprintFromLibrary( frame->GetTargetFPID(), true ) )
549 {
550 if( frame->GetTargetFPID() == frame->GetLoadedFPID() )
551 frame->Clear_Pcb( false );
552
553 frame->SyncLibraryTree( true );
554 }
555
556 return 0;
557}
558
559
561{
562 bool is_last_fp_from_brd = m_frame->IsCurrentFPFromBoard();
563
564 if( !m_frame->Clear_Pcb( true ) )
565 return -1; // this command is aborted
566
569
572
573 frame()->ClearUndoRedoList();
574
575 // Update the save items if needed.
576 if( is_last_fp_from_brd )
577 {
580 }
581
583 m_frame->OnModify();
584 return 0;
585}
586
587
589{
592
593 return 0;
594}
595
596
598{
599 // No check for multi selection since the context menu option must be hidden in that case
600 FP_LIB_TABLE* globalTable = dynamic_cast<FP_LIB_TABLE*>( &GFootprintTable );
602 LIB_ID libId = m_frame->GetTargetFPID();
603
604 wxString libName = libId.GetLibNickname();
605 wxString libItemName = libId.GetLibItemName();
606 wxString path = wxEmptyString;
607
608 for( FP_LIB_TABLE* table : { globalTable, projectTable } )
609 {
610 if( !table )
611 break;
612
613 try
614 {
615 path = table->FindRow( libName, true )->GetFullURI( true );
616 }
617 catch( IO_ERROR& )
618 {
619 // Do nothing: libName can be not found in globalTable if libName is in projectTable
620 }
621
622 if( !path.IsEmpty() )
623 break;
624 }
625
626 wxString fileExt = wxEmptyString;
627
628 // If selection is footprint
629 if( !libItemName.IsEmpty() )
631
632 wxFileName fileName( path, libItemName, fileExt );
633
635
636 wxString explCommand = cfg->m_System.file_explorer;
637
638 if( explCommand.IsEmpty() )
639 {
640 path = fileName.GetFullPath().BeforeLast( wxFileName::GetPathSeparator() );
641
642 if( !path.IsEmpty() && wxDirExists( path ) )
644
645 return 0;
646 }
647
648 if( !explCommand.EndsWith( "%F" ) )
649 {
650 wxMessageBox( _( "Missing/malformed file explorer argument '%F' in common settings." ) );
651 return 0;
652 }
653
654 wxString escapedFilePath = fileName.GetFullPath();
655 escapedFilePath.Replace( wxS( "\"" ), wxS( "_" ) );
656
657 wxString fileArg = wxEmptyString;
658 fileArg << '"' << escapedFilePath << '"';
659
660 explCommand.Replace( wxT( "%F" ), fileArg );
661
662 if( !explCommand.IsEmpty() )
663 wxExecute( explCommand );
664
665 return 0;
666}
667
668
670{
671 wxString fullEditorName = Pgm().GetTextEditor();
672
673 if( fullEditorName.IsEmpty() )
674 {
675 wxMessageBox( _( "No text editor selected in KiCad. Please choose one." ) );
676 return 0;
677 }
678
679 // No check for multi selection since the context menu option must be hidden in that case
680 FP_LIB_TABLE* globalTable = dynamic_cast<FP_LIB_TABLE*>( &GFootprintTable );
683
684 wxString libName = libId.GetLibNickname();
685 wxString libItemName = wxEmptyString;
686
687 for( FP_LIB_TABLE* table : { globalTable, projectTable } )
688 {
689 if( !table )
690 break;
691
692 try
693 {
694 libItemName = table->FindRow( libName, true )->GetFullURI( true );
695 }
696 catch( IO_ERROR& )
697 {
698 // Do nothing: libName can be not found in globalTable if libName is in projectTable
699 }
700
701 if( !libItemName.IsEmpty() )
702 break;
703 }
704
705 libItemName << wxFileName::GetPathSeparator();
706 libItemName << libId.GetLibItemName();
707 libItemName << '.' + FILEEXT::KiCadFootprintFileExtension;
708
709 if( !wxFileName::FileExists( libItemName ) )
710 return 0;
711
712 ExecuteFile( fullEditorName, libItemName.wc_str(), nullptr, false );
713
714 return 0;
715}
716
717
719{
721 {
722 std::optional<wxString> url = GetFootprintDocumentationURL( *footprint );
723
724 if( !url.has_value() )
725 {
726 frame()->ShowInfoBarMsg( _( "No datasheet found in the footprint." ) );
727 }
728 else
729 {
730 // Only absolute URLs are supported
731 SEARCH_STACK* searchStack = nullptr;
732 GetAssociatedDocument( m_frame, *url, &m_frame->Prj(), searchStack,
733 { m_frame->GetBoard(), footprint } );
734 }
735 }
736 return 0;
737}
738
739
741{
743 return 0;
744}
745
746
748{
750
752 {
753 wxBell();
754 return 0;
755 }
756
758
761
762 return 0;
763}
764
765
767{
769 return 0;
770}
771
772
774{
776 return 0;
777}
778
779
781{
783 {
784 getEditFrame<FOOTPRINT_EDIT_FRAME>()->OnEditItemRequest( footprint );
786 }
787
788 return 0;
789}
790
791
793{
794 getEditFrame<FOOTPRINT_EDIT_FRAME>()->ShowPadPropertiesDialog( nullptr );
795 return 0;
796}
797
798
800{
801 FOOTPRINT_EDIT_FRAME* editFrame = getEditFrame<FOOTPRINT_EDIT_FRAME>();
802 DIALOG_CLEANUP_GRAPHICS dlg( editFrame, true );
803
804 dlg.ShowModal();
805 return 0;
806}
807
808
810{
811 if( !m_checkerDialog )
812 {
814 m_checkerDialog->Show( true );
815 }
816 else // The dialog is just not visible (because the user has double clicked on an error item)
817 {
818 m_checkerDialog->Show( true );
819 }
820
821 return 0;
822}
823
824
826{
827 if( !m_checkerDialog )
829
830 if( !m_checkerDialog->IsShownOnScreen() )
831 m_checkerDialog->Show( true );
832
833 m_checkerDialog->SelectMarker( aMarker );
834}
835
836
838{
839 if( m_checkerDialog )
840 {
841 m_checkerDialog->Destroy();
842 m_checkerDialog = nullptr;
843 }
844}
845
846
848{
849 FOOTPRINT* footprint = board()->Footprints().front();
850 int errors = 0;
851 wxString details;
852
853 // Repair duplicate IDs and missing nets.
854 std::set<KIID> ids;
855 int duplicates = 0;
856
857 auto processItem =
858 [&]( EDA_ITEM* aItem )
859 {
860 if( ids.count( aItem->m_Uuid ) )
861 {
862 duplicates++;
863 const_cast<KIID&>( aItem->m_Uuid ) = KIID();
864 }
865
866 ids.insert( aItem->m_Uuid );
867 };
868
869 // Footprint IDs are the most important, so give them the first crack at "claiming" a
870 // particular KIID.
871
872 processItem( footprint );
873
874 // After that the principal use is for DRC marker pointers, which are most likely to pads.
875
876 for( PAD* pad : footprint->Pads() )
877 processItem( pad );
878
879 // From here out I don't think order matters much.
880
881 processItem( &footprint->Reference() );
882 processItem( &footprint->Value() );
883
884 for( BOARD_ITEM* item : footprint->GraphicalItems() )
885 processItem( item );
886
887 for( ZONE* zone : footprint->Zones() )
888 processItem( zone );
889
890 for( PCB_GROUP* group : footprint->Groups() )
891 processItem( group );
892
893 if( duplicates )
894 {
895 errors += duplicates;
896 details += wxString::Format( _( "%d duplicate IDs replaced.\n" ), duplicates );
897 }
898
899 if( errors )
900 {
901 m_frame->OnModify();
902
903 wxString msg = wxString::Format( _( "%d potential problems repaired." ), errors );
904 DisplayInfoMessage( m_frame, msg, details );
905 }
906 else
907 {
908 DisplayInfoMessage( m_frame, _( "No footprint problems found." ) );
909 }
910
911 return 0;
912}
913
914
916{
917 // clang-format off
926
932
935
939
942
945
950 // clang-format on
951}
static TOOL_ACTION openWithTextEditor
Definition: actions.h:68
static TOOL_ACTION revert
Definition: actions.h:62
static TOOL_ACTION saveAs
Definition: actions.h:59
static TOOL_ACTION openDirectory
Definition: actions.h:69
static TOOL_ACTION showDatasheet
Definition: actions.h:264
static TOOL_ACTION save
Definition: actions.h:58
static TOOL_ACTION zoomFitScreen
Definition: actions.h:141
static TOOL_ACTION showProperties
Definition: actions.h:263
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
void SetContentModified(bool aModified=true)
Definition: base_screen.h:59
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:79
void BuildListOfNets()
Definition: board.h:897
FOOTPRINT * GetFirstFootprint() const
Get the first footprint on the board or nullptr.
Definition: board.h:489
const FOOTPRINTS & Footprints() const
Definition: board.h:358
void SelectMarker(const PCB_MARKER *aMarker)
bool Show(bool show) override
int ShowModal() override
void ShowInfoBarWarning(const wxString &aWarningMsg, bool aShowCloseButton=false)
Show the WX_INFOBAR displayed on the top of the canvas with a message and a warning icon on the left ...
void ReCreateMenuBar()
Recreate the menu bar.
WX_INFOBAR * GetInfoBar()
virtual void ReCreateHToolbar()
virtual void Zoom_Automatique(bool aWarpPointer)
Redraw the screen with best zoom level and the best centering that shows all the page or the board.
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
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:98
void ClearFlags(EDA_ITEM_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: eda_item.h:144
int Revert(const TOOL_EVENT &aEvent)
int OpenWithTextEditor(const TOOL_EVENT &aEvent)
int PasteFootprint(const TOOL_EVENT &aEvent)
DIALOG_FOOTPRINT_CHECKER * m_checkerDialog
int CutCopyFootprint(const TOOL_EVENT &aEvent)
int EditFootprint(const TOOL_EVENT &aEvent)
int ToggleProperties(const TOOL_EVENT &aEvent)
int Save(const TOOL_EVENT &aEvent)
int OpenDirectory(const TOOL_EVENT &aEvent)
void Reset(RESET_REASON aReason) override
Bring the tool to a known, initial state.
int CreateFootprint(const TOOL_EVENT &aEvent)
FOOTPRINT_EDIT_FRAME * m_frame
int NewFootprint(const TOOL_EVENT &aEvent)
int DefaultPadProperties(const TOOL_EVENT &aEvent)
Edit the properties used for new pad creation.
void CrossProbe(const PCB_MARKER *aMarker)
int ImportFootprint(const TOOL_EVENT &aEvent)
int CleanupGraphics(const TOOL_EVENT &aEvent)
int ShowDatasheet(const TOOL_EVENT &aEvent)
void tryToSaveFootprintInLibrary(FOOTPRINT &aFootprint, const LIB_ID &aLibId)
Try to save the footprint in the library, if it is valid and writable.
int Properties(const TOOL_EVENT &aEvent)
int ToggleLayersManager(const TOOL_EVENT &aEvent)
int RepairFootprint(const TOOL_EVENT &aEvent)
int RenameFootprint(const TOOL_EVENT &aEvent)
int DuplicateFootprint(const TOOL_EVENT &aEvent)
std::unique_ptr< FOOTPRINT > m_copiedFootprint
bool Init() override
Init() is called once upon a registration of the tool.
int ExportFootprint(const TOOL_EVENT &aEvent)
int EditLibraryFootprint(const TOOL_EVENT &aEvent)
int DeleteFootprint(const TOOL_EVENT &aEvent)
int SaveAs(const TOOL_EVENT &aEvent)
void setTransitions() override
< Set up handlers for various events.
int CheckFootprint(const TOOL_EVENT &aEvent)
void UpdateLibraryTree(const wxDataViewItem &treeItem, FOOTPRINT *aFootprint)
Update a single node in the library tree.
void SyncLibraryTree(bool aProgress)
Synchronize the footprint library tree to the current state of the footprint library table.
bool SaveFootprintInLibrary(FOOTPRINT *aFootprint, const wxString &aLibraryName)
bool SaveLibraryAs(const wxString &aLibraryPath)
Save a library to a new name and/or library type.
bool SaveFootprintAs(FOOTPRINT *aFootprint)
bool DuplicateFootprint(FOOTPRINT *aFootprint)
void ToggleLibraryTree() override
LIB_TREE * GetLibTree() const override
void ExportFootprint(FOOTPRINT *aFootprint)
Create a file containing only one footprint.
LIB_ID GetTargetFPID() const
Return the LIB_ID of the part selected in the footprint tree, or the loaded part if there is no selec...
LIB_ID GetLoadedFPID() const
Return the LIB_ID of the part being edited.
bool SaveFootprint(FOOTPRINT *aFootprint)
Save in an existing library a given footprint.
void LoadFootprintFromLibrary(LIB_ID aFPID)
wxObjectDataPtr< LIB_TREE_MODEL_ADAPTER > & GetLibTreeAdapter()
Return the adapter object that provides the stored data.
FOOTPRINT * ImportFootprint(const wxString &aName=wxT(""))
Read a file containing only one footprint.
bool IsContentModified() const override
Get if any footprints or libraries have been modified but not saved.
bool IsLibraryTreeShown() const override
bool Clear_Pcb(bool doAskAboutUnsavedChanges)
Delete all and reinitialize the current board.
Definition: initpcb.cpp:108
void AddFootprintToBoard(FOOTPRINT *aFootprint) override
Override from PCB_BASE_EDIT_FRAME which adds a footprint to the editor's dummy board,...
void OnModify() override
Must be called after a footprint change in order to set the "modify" flag of the current screen and p...
void FocusOnLibID(const LIB_ID &aLibID)
void RefreshLibraryTree()
Redisplay the library tree.
void SetPosition(const VECTOR2I &aPos) override
Definition: footprint.cpp:2513
void SetFPID(const LIB_ID &aFPID)
Definition: footprint.h:252
ZONES & Zones()
Definition: footprint.h:215
PCB_FIELD & Value()
read/write accessors:
Definition: footprint.h:663
std::deque< PAD * > & Pads()
Definition: footprint.h:209
const LIB_ID & GetFPID() const
Definition: footprint.h:251
void SetValue(const wxString &aValue)
Definition: footprint.h:654
PCB_FIELD & Reference()
Definition: footprint.h:664
GROUPS & Groups()
Definition: footprint.h:218
const wxString & GetValue() const
Definition: footprint.h:649
DRAWINGS & GraphicalItems()
Definition: footprint.h:212
void FootprintDelete(const wxString &aNickname, const wxString &aFootprintName)
Delete the aFootprintName from the library given by aNickname.
bool FootprintExists(const wxString &aNickname, const wxString &aFootprintName)
Indicates whether or not the given footprint already exists in the given library.
bool IsFootprintLibWritable(const wxString &aNickname)
Return true if the library given by aNickname is writable.
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
Definition: ki_exception.h:77
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:30
virtual void Update(const VIEW_ITEM *aItem, int aUpdateFlags) const override
For dynamic VIEWs, inform the associated VIEW that the graphical representation of this item has chan...
Definition: pcb_view.cpp:91
virtual void SetCrossHairCursorPosition(const VECTOR2D &aPosition, bool aWarpView=true)=0
Move the graphic crosshair cursor to the requested position expressed in world coordinates.
Definition: kiid.h:49
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.
Definition: kiway_holder.h:55
A wxFrame capable of the OpenProjectFiles function, meaning it can load a portion of a KiCad project.
Definition: kiway_player.h:65
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.
Definition: kiway.cpp:395
Module editor specific tools.
bool RenameLibrary(const wxString &aTitle, const wxString &aName, std::function< bool(const wxString &aNewName)> aValidator)
void AddContextMenuItems(CONDITIONAL_MENU *aMenu)
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:49
int SetLibNickname(const UTF8 &aLibNickname)
Override the logical library name portion of the LIB_ID to aLibNickname.
Definition: lib_id.cpp:100
const wxString GetUniStringLibNickname() const
Definition: lib_id.h:88
const UTF8 & GetLibItemName() const
Definition: lib_id.h:102
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
Definition: lib_id.h:87
wxString GetFullURI(const wxString &aLibNickname, bool aExpandEnvVars=true) const
Return the full URI of the library mapped to aLibNickname.
LIB_ID GetSelectedLibId(int *aUnit=nullptr) const
For multi-unit symbols, if the user selects the symbol itself rather than picking an individual unit,...
Definition: lib_tree.cpp:314
Definition: pad.h:54
static TOOL_ACTION deleteFootprint
Definition: pcb_actions.h:480
static TOOL_ACTION renameFootprint
Definition: pcb_actions.h:479
static TOOL_ACTION showLayersManager
Definition: pcb_actions.h:451
static TOOL_ACTION createFootprint
Definition: pcb_actions.h:475
static TOOL_ACTION editFootprint
Definition: pcb_actions.h:477
static TOOL_ACTION exportFootprint
Definition: pcb_actions.h:485
static TOOL_ACTION editTextAndGraphics
Definition: pcb_actions.h:434
static TOOL_ACTION newFootprint
Definition: pcb_actions.h:472
static TOOL_ACTION defaultPadProperties
Definition: pcb_actions.h:488
static TOOL_ACTION importFootprint
Definition: pcb_actions.h:484
static TOOL_ACTION pasteFootprint
Definition: pcb_actions.h:483
static TOOL_ACTION footprintProperties
Definition: pcb_actions.h:487
static TOOL_ACTION checkFootprint
Definition: pcb_actions.h:490
static TOOL_ACTION editLibFpInFpEditor
Definition: pcb_actions.h:449
static TOOL_ACTION duplicateFootprint
Definition: pcb_actions.h:478
static TOOL_ACTION cutFootprint
Definition: pcb_actions.h:481
static TOOL_ACTION repairFootprint
Definition: pcb_actions.h:557
static TOOL_ACTION copyFootprint
Definition: pcb_actions.h:482
static TOOL_ACTION cleanupGraphics
Definition: pcb_actions.h:438
void ToggleProperties() override
FOOTPRINT * CreateNewFootprint(wxString aFootprintName, const wxString &aLibName)
Create a new footprint at position 0,0.
FOOTPRINT * LoadFootprint(const LIB_ID &aFootprintId)
Attempt to load aFootprintId from the footprint library table.
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
PCB_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
BOARD * GetBoard() const
virtual void Update3DView(bool aMarkDirty, bool aRefresh, const wxString *aTitle=nullptr)
Update the 3D view, if the viewer is opened by this frame.
A set of BOARD_ITEMs (i.e., without duplicates).
Definition: pcb_group.h:53
T * frame() const
KIGFX::PCB_VIEW * view() const
BOARD * board() const
PCB_DRAW_PANEL_GAL * canvas() const
FOOTPRINT * footprint() const
virtual COMMON_SETTINGS * GetCommonSettings() const
Definition: pgm_base.cpp:565
virtual const wxString & GetTextEditor(bool aCanShowFileChooser=true)
Return the path to the preferred text editor application.
Definition: pgm_base.cpp:197
static FP_LIB_TABLE * PcbFootprintLibs(PROJECT *aProject)
Return the table of footprint libraries without Kiway.
Definition: project_pcb.cpp:37
Look for files in a number of paths.
Definition: search_stack.h:43
static bool ShowAlways(const SELECTION &aSelection)
The default condition function (always returns true).
KIGFX::VIEW_CONTROLS * getViewControls() const
Return the instance of VIEW_CONTROLS object used in the application.
Definition: tool_base.cpp:44
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:220
RESET_REASON
Determine the reason of reset for a tool.
Definition: tool_base.h:78
Generic, UI-independent tool event.
Definition: tool_event.h:168
bool IsAction(const TOOL_ACTION *aAction) const
Test if the event contains an action issued upon activation of the given TOOL_ACTION.
Definition: tool_event.cpp:82
void Go(int(T::*aStateFunc)(const TOOL_EVENT &), const TOOL_EVENT_LIST &aConditions=TOOL_EVENT(TC_ANY, TA_ANY))
Define which state (aStateFunc) to go when a certain event arrives (aConditions).
std::unique_ptr< TOOL_MENU > m_menu
The functions below are not yet implemented - their interface may change.
bool RunAction(const std::string &aActionName, T aParam)
Run the specified action immediately, pausing the current action to run the new one.
Definition: tool_manager.h:150
bool empty() const
Definition: utf8.h:110
A modified version of the wxInfoBar class that allows us to:
Definition: wx_infobar.h:76
bool HasCloseButton() const
Definition: wx_infobar.cpp:395
void Dismiss() override
Dismisses the infobar and updates the containing layout and AUI manager (if one is provided).
Definition: wx_infobar.cpp:192
Handle a list of polygons defining a copper zone.
Definition: zone.h:74
void DisplayInfoMessage(wxWindow *aParent, const wxString &aMessage, const wxString &aExtraInfo)
Display an informational message box with aMessage.
Definition: confirm.cpp:222
bool HandleUnsavedChanges(wxWindow *aParent, const wxString &aMessage, const std::function< bool()> &aSaveFunction)
Display a dialog with Save, Cancel and Discard Changes buttons.
Definition: confirm.cpp:129
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition: confirm.cpp:194
This file is part of the common library.
FP_LIB_TABLE GFootprintTable
The global footprint library table.
Definition: cvpcb.cpp:150
#define _(s)
bool GetAssociatedDocument(wxWindow *aParent, const wxString &aDocName, PROJECT *aProject, SEARCH_STACK *aPaths, std::vector< EMBEDDED_FILES * > aFilesStack)
Open a document (file) with the suitable browser.
Definition: eda_doc.cpp:62
This file is part of the common library.
@ FRAME_FOOTPRINT_WIZARD
Definition: frame_type.h:46
std::optional< wxString > GetFootprintDocumentationURL(const FOOTPRINT &aFootprint)
Get a URL to the documentation for a LIB_ID in a FP_LIB_TABLE.
int ExecuteFile(const wxString &aEditorName, const wxString &aFileName, wxProcess *aCallback, bool aFileForKicad)
Call the executable file aEditorName with the parameter aFileName.
Definition: gestfich.cpp:143
bool m_EnableLibDir
Enable option to open lib file directory.
bool m_EnableLibWithText
Enable option to load lib files with text editor.
static const std::string KiCadFootprintFileExtension
This file is part of the common library.
bool LaunchExternal(const wxString &aPath)
Launches the given file or folder in the host OS.
Definition: launch_ext.cpp:25
Class to handle a set of BOARD_ITEMs.
PGM_BASE & Pgm()
The global program "get" accessor.
Definition: pgm_base.cpp:902
see class PGM_BASE
VECTOR2< int32_t > VECTOR2I
Definition: vector2d.h:695
VECTOR2< double > VECTOR2D
Definition: vector2d.h:694
Definition of file extensions used in Kicad.