KiCad PCB EDA Suite
pcb_control.cpp File Reference
#include <tools/edit_tool.h>
#include <tools/board_inspection_tool.h>
#include <router/router_tool.h>
#include <pgm_base.h>
#include <tools/pcb_actions.h>
#include <tools/pcb_control.h>
#include <tools/pcb_picker_tool.h>
#include <tools/pcb_selection_tool.h>
#include <tools/board_reannotate_tool.h>
#include <3d_viewer/eda_3d_viewer_frame.h>
#include <board_commit.h>
#include <board.h>
#include <board_design_settings.h>
#include <board_item.h>
#include <dialogs/dialog_paste_special.h>
#include <pcb_dimension.h>
#include <footprint.h>
#include <pcb_group.h>
#include <pcb_textbox.h>
#include <pcb_track.h>
#include <zone.h>
#include <fp_shape.h>
#include <fp_textbox.h>
#include <confirm.h>
#include <connectivity/connectivity_data.h>
#include <core/kicad_algo.h>
#include <kicad_clipboard.h>
#include <origin_viewitem.h>
#include <pcb_edit_frame.h>
#include <pcb_painter.h>
#include <properties.h>
#include <settings/color_settings.h>
#include <tool/tool_manager.h>
#include <widgets/wx_progress_reporters.h>
#include <widgets/infobar.h>
#include <wx/hyperlink.h>

Go to the source code of this file.

Macros

#define ALPHA_MIN   0.20
 
#define ALPHA_MAX   1.00
 
#define ALPHA_STEP   0.05
 
#define HITTEST_THRESHOLD_PIXELS   5
 

Functions

bool AskLoadBoardFileName (PCB_EDIT_FRAME *aParent, int *aCtl, wxString *aFileName, bool aKicadFilesOnly=false)
 Show a wxFileDialog asking for a BOARD filename to open. More...
 
IO_MGR::PCB_FILE_T plugin_type (const wxString &aFileName, int aCtl)
 
template<class T >
void Flip (T &aValue)
 
static void pasteFootprintItemsToFootprintEditor (FOOTPRINT *aClipFootprint, BOARD *aBoard, std::vector< BOARD_ITEM * > &aPastedItems)
 
template<typename T >
static void moveUnflaggedItems (std::deque< T > &aList, std::vector< BOARD_ITEM * > &aTarget, bool aIsNew)
 
static void moveUnflaggedItems (ZONES &aList, std::vector< BOARD_ITEM * > &aTarget, bool aIsNew)
 

Macro Definition Documentation

◆ ALPHA_MAX

#define ALPHA_MAX   1.00

Definition at line 416 of file pcb_control.cpp.

◆ ALPHA_MIN

#define ALPHA_MIN   0.20

Definition at line 415 of file pcb_control.cpp.

◆ ALPHA_STEP

#define ALPHA_STEP   0.05

Definition at line 417 of file pcb_control.cpp.

◆ HITTEST_THRESHOLD_PIXELS

#define HITTEST_THRESHOLD_PIXELS   5

Definition at line 534 of file pcb_control.cpp.

Function Documentation

◆ AskLoadBoardFileName()

bool AskLoadBoardFileName ( PCB_EDIT_FRAME aParent,
int *  aCtl,
wxString *  aFileName,
bool  aKicadFilesOnly 
)

Show a wxFileDialog asking for a BOARD filename to open.

Parameters
aParentis a wxFrame passed to wxFileDialog.
aCtlis where to put the OpenProjectFiles() control bits.
aFileNameon entry is a probable choice, on return is the chosen filename.
aKicadFilesOnlytrue to list KiCad pcb files plugins only, false to list import plugins.
Returns
true if chosen, else false if user aborted.

Definition at line 87 of file pcbnew/files.cpp.

89{
90 // This is a subset of all PLUGINs which are trusted to be able to
91 // load a BOARD. User may occasionally use the wrong plugin to load a
92 // *.brd file (since both legacy and eagle use *.brd extension),
93 // but eventually *.kicad_pcb will be more common than legacy *.brd files.
94
95 // clang-format off
96 static const struct
97 {
98 const wxString& filter;
99 IO_MGR::PCB_FILE_T pluginType;
100 } loaders[] =
101 {
102 // Current Kicad board files.
104
105 // Old Kicad board files.
107
108 // Import Altium Circuit Maker board files.
110
111 // Import Altium Circuit Studio board files.
113
114 // Import Altium Designer board files.
116
117 // Import Cadstar PCB Archive board files.
119
120 // Import Eagle board files.
122
123 // Import PCAD board files.
125
126 // Import Fabmaster board files.
128 };
129 // clang-format on
130
131 wxFileName fileName( *aFileName );
132 wxString fileFilters;
133
134 if( aKicadFilesOnly )
135 {
136 std::vector<std::string> fileExtensions;
137
138 for( unsigned ii = 0; ii < 2; ++ii )
139 {
140 if( !fileFilters.IsEmpty() )
141 fileFilters += wxChar( '|' );
142
143 fileFilters += wxGetTranslation( loaders[ii].filter );
144
145 PLUGIN::RELEASER plugin( IO_MGR::PluginFind( loaders[ii].pluginType ) );
146 wxCHECK( plugin, false );
147 fileExtensions.push_back( plugin->GetFileExtension().ToStdString() );
148 }
149
150 fileFilters = _( "All KiCad Board Files" ) + AddFileExtListToFilter( fileExtensions )
151 + wxT( "|" ) + fileFilters;
152 }
153 else
154 {
155 wxString allWildcards;
156
157 for( unsigned ii = 2; ii < arrayDim( loaders ); ++ii )
158 {
159 if( !fileFilters.IsEmpty() )
160 fileFilters += wxChar( '|' );
161
162 fileFilters += wxGetTranslation( loaders[ii].filter );
163
164 PLUGIN::RELEASER plugin( IO_MGR::PluginFind( loaders[ii].pluginType ) );
165 wxCHECK( plugin, false );
166 allWildcards += wxT( "*." ) + formatWildcardExt( plugin->GetFileExtension() ) + wxT( ";" );
167 }
168
169 fileFilters = _( "All supported formats|" ) + allWildcards + wxT( "|" ) + fileFilters;
170 }
171
172
173 wxString path;
174 wxString name;
175
176 if( fileName.FileExists() )
177 {
178 path = fileName.GetPath();
179 name = fileName.GetFullName();
180 }
181 else
182 {
183 path = aParent->GetMruPath();
184
185 if( path.IsEmpty() )
187 // leave name empty
188 }
189
190 wxFileDialog dlg( aParent,
191 aKicadFilesOnly ? _( "Open Board File" ) : _( "Import Non KiCad Board File" ),
192 path, name, fileFilters, wxFD_OPEN | wxFD_FILE_MUST_EXIST );
193
194 if( dlg.ShowModal() == wxID_OK )
195 {
196 // For import option, if Eagle (*.brd files), tell OpenProjectFiles() to use Eagle plugin.
197 // It's the only special case because of the duplicate use of the *.brd file extension.
198 // Other cases are clear because of unique file extensions.
199 *aCtl = aKicadFilesOnly ? 0 : KICTL_EAGLE_BRD;
200 *aFileName = dlg.GetPath();
201 aParent->SetMruPath( wxFileName( dlg.GetPath() ).GetPath() );
202 return true;
203 }
204 else
205 {
206 return false;
207 }
208}
const char * name
Definition: DXF_plotter.cpp:56
constexpr std::size_t arrayDim(T const (&)[N]) noexcept
Returns # of elements in an array.
Definition: arraydim.h:31
wxString GetMruPath() const
void SetMruPath(const wxString &aPath)
PCB_FILE_T
The set of file types that the IO_MGR knows about, and for which there has been a plugin written.
Definition: io_mgr.h:54
@ LEGACY
Legacy Pcbnew file formats prior to s-expression.
Definition: io_mgr.h:55
@ ALTIUM_DESIGNER
Definition: io_mgr.h:60
@ KICAD_SEXP
S-expression Pcbnew file format.
Definition: io_mgr.h:56
@ ALTIUM_CIRCUIT_MAKER
Definition: io_mgr.h:62
@ PCAD
Definition: io_mgr.h:58
@ EAGLE
Definition: io_mgr.h:57
@ CADSTAR_PCB_ARCHIVE
Definition: io_mgr.h:63
@ FABMASTER
Definition: io_mgr.h:59
@ ALTIUM_CIRCUIT_STUDIO
Definition: io_mgr.h:61
static PLUGIN * PluginFind(PCB_FILE_T aFileType)
Return a PLUGIN which the caller can use to import, export, save, or load design documents.
Definition: io_mgr.cpp:58
static wxString GetDefaultUserProjectsPath()
Gets the default path we point users to create projects.
Definition: paths.cpp:139
Releases a PLUGIN in the context of a potential thrown exception through its destructor.
Definition: io_mgr.h:564
#define _(s)
wxString AddFileExtListToFilter(const std::vector< std::string > &aExts)
Build the wildcard extension file dialog wildcard filter to add to the base message dialog.
wxString formatWildcardExt(const wxString &aWildcard)
Format wildcard extension to support case sensitive file dialogs.
wxString LegacyPcbFileWildcard()
wxString CadstarPcbArchiveFileWildcard()
wxString AltiumDesignerPcbFileWildcard()
wxString PCadPcbFileWildcard()
wxString EaglePcbFileWildcard()
wxString FabmasterPcbFileWildcard()
wxString AltiumCircuitMakerPcbFileWildcard()
wxString AltiumCircuitStudioPcbFileWildcard()
wxString PcbFileWildcard()
#define KICTL_EAGLE_BRD
chosen *.brd file is Eagle according to user.
Definition: kiway_player.h:81

References _, AddFileExtListToFilter(), IO_MGR::ALTIUM_CIRCUIT_MAKER, IO_MGR::ALTIUM_CIRCUIT_STUDIO, IO_MGR::ALTIUM_DESIGNER, AltiumCircuitMakerPcbFileWildcard(), AltiumCircuitStudioPcbFileWildcard(), AltiumDesignerPcbFileWildcard(), arrayDim(), IO_MGR::CADSTAR_PCB_ARCHIVE, CadstarPcbArchiveFileWildcard(), IO_MGR::EAGLE, EaglePcbFileWildcard(), IO_MGR::FABMASTER, FabmasterPcbFileWildcard(), filter, formatWildcardExt(), PATHS::GetDefaultUserProjectsPath(), PLUGIN::GetFileExtension(), EDA_BASE_FRAME::GetMruPath(), IO_MGR::KICAD_SEXP, KICTL_EAGLE_BRD, IO_MGR::LEGACY, LegacyPcbFileWildcard(), name, path, IO_MGR::PCAD, PCadPcbFileWildcard(), PcbFileWildcard(), IO_MGR::PluginFind(), and EDA_BASE_FRAME::SetMruPath().

Referenced by PCB_CONTROL::AppendBoardFromFile(), PCB_EDIT_FRAME::Files_io_from_id(), and PCB_EDIT_FRAME::OnFileHistory().

◆ Flip()

template<class T >
void Flip ( T &  aValue)

Definition at line 121 of file pcb_control.cpp.

122{
123 aValue = !aValue;
124}

Referenced by PCB_CONTROL::ToggleRatsnest(), PCB_CONTROL::TrackDisplayMode(), and PCB_CONTROL::ViaDisplayMode().

◆ moveUnflaggedItems() [1/2]

template<typename T >
static void moveUnflaggedItems ( std::deque< T > &  aList,
std::vector< BOARD_ITEM * > &  aTarget,
bool  aIsNew 
)
static

Definition at line 874 of file pcb_control.cpp.

876{
877 std::copy_if( aList.begin(), aList.end(), std::back_inserter( aTarget ),
878 [aIsNew]( T aItem )
879 {
880 bool doCopy = ( aItem->GetFlags() & SKIP_STRUCT ) == 0;
881
882 aItem->ClearFlags( SKIP_STRUCT );
883 aItem->SetFlags( aIsNew ? IS_NEW : 0 );
884
885 return doCopy;
886 } );
887
888 if( aIsNew )
889 aList.clear();
890}

Referenced by PCB_CONTROL::placeBoardItems().

◆ moveUnflaggedItems() [2/2]

static void moveUnflaggedItems ( ZONES aList,
std::vector< BOARD_ITEM * > &  aTarget,
bool  aIsNew 
)
static

Definition at line 893 of file pcb_control.cpp.

894{
895 if( aList.size() == 0 )
896 return;
897
898 auto obj = aList.front();
899 int idx = 0;
900
901 if( aIsNew )
902 {
903 obj = aList.back();
904 aList.pop_back();
905 }
906
907 for( ; obj ; )
908 {
909 if( obj->HasFlag( SKIP_STRUCT ) )
910 obj->ClearFlags( SKIP_STRUCT );
911 else
912 aTarget.push_back( obj );
913
914 if( aIsNew )
915 {
916 if( aList.size() )
917 {
918 obj = aList.back();
919 aList.pop_back();
920 }
921 else
922 {
923 obj = nullptr;
924 }
925 }
926 else
927 {
928 obj = idx < int(aList.size()-1) ? aList[++idx] : nullptr;
929 }
930 }
931}
#define SKIP_STRUCT
flag indicating that the structure should be ignored

References SKIP_STRUCT.

◆ pasteFootprintItemsToFootprintEditor()

static void pasteFootprintItemsToFootprintEditor ( FOOTPRINT aClipFootprint,
BOARD aBoard,
std::vector< BOARD_ITEM * > &  aPastedItems 
)
static

Definition at line 634 of file pcb_control.cpp.

636{
637 FOOTPRINT* editorFootprint = aBoard->GetFirstFootprint();
638
639 aClipFootprint->SetParent( aBoard );
640
641 for( PAD* pad : aClipFootprint->Pads() )
642 {
643 pad->SetParent( editorFootprint );
644 aPastedItems.push_back( pad );
645 }
646
647 aClipFootprint->Pads().clear();
648
649 // Not all graphic items can be added to the current footprint:
650 // Reference and value are already existing in the current footprint, and
651 // must be unique.
652 // So they will be skipped
653 for( BOARD_ITEM* item : aClipFootprint->GraphicalItems() )
654 {
655 if( item->Type() == PCB_FP_SHAPE_T || item->Type() == PCB_FP_TEXTBOX_T )
656 {
657 FP_SHAPE* shape = static_cast<FP_SHAPE*>( item );
658
659 shape->SetParent( nullptr );
660 shape->SetLocalCoord();
661 }
662 else if( item->Type() == PCB_FP_TEXT_T )
663 {
664 FP_TEXT* text = static_cast<FP_TEXT*>( item );
665
666 if( text->GetType() != FP_TEXT::TEXT_is_DIVERS )
667 continue;
668
669 text->SetTextAngle( text->GetTextAngle() + aClipFootprint->GetOrientation() );
670
671 text->SetParent( nullptr );
672 text->SetLocalCoord();
673 }
674
675 item->SetParent( editorFootprint );
676 aPastedItems.push_back( item );
677 }
678
679 aClipFootprint->GraphicalItems().clear();
680
681 for( FP_ZONE* zone : aClipFootprint->Zones() )
682 {
683 zone->SetParent( editorFootprint );
684 aPastedItems.push_back( zone );
685 }
686
687 aClipFootprint->Zones().clear();
688
689 for( PCB_GROUP* group : aClipFootprint->Groups() )
690 {
691 group->SetParent( editorFootprint );
692 aPastedItems.push_back( group );
693 }
694
695 aClipFootprint->Groups().clear();
696}
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:53
FOOTPRINT * GetFirstFootprint() const
Get the first footprint on the board or nullptr.
Definition: board.h:372
virtual void SetParent(EDA_ITEM *aParent)
Definition: eda_item.h:115
EDA_ANGLE GetOrientation() const
Definition: footprint.h:196
FP_GROUPS & Groups()
Definition: footprint.h:184
PADS & Pads()
Definition: footprint.h:175
FP_ZONES & Zones()
Definition: footprint.h:181
DRAWINGS & GraphicalItems()
Definition: footprint.h:178
virtual void SetLocalCoord()
Set relative coordinates from draw coordinates.
Definition: fp_shape.cpp:52
@ TEXT_is_DIVERS
Definition: fp_text.h:52
A specialization of ZONE for use in footprints.
Definition: zone.h:920
Definition: pad.h:59
A set of BOARD_ITEMs (i.e., without duplicates).
Definition: pcb_group.h:51
@ PCB_FP_SHAPE_T
class FP_SHAPE, a footprint edge
Definition: typeinfo.h:96
@ PCB_FP_TEXTBOX_T
class FP_TEXTBOX, wrapped text in a footprint
Definition: typeinfo.h:95
@ PCB_FP_TEXT_T
class FP_TEXT, text in a footprint
Definition: typeinfo.h:94

References BOARD::GetFirstFootprint(), FOOTPRINT::GetOrientation(), FOOTPRINT::GraphicalItems(), group, FOOTPRINT::Groups(), pad, FOOTPRINT::Pads(), PCB_FP_SHAPE_T, PCB_FP_TEXT_T, PCB_FP_TEXTBOX_T, FP_SHAPE::SetLocalCoord(), EDA_ITEM::SetParent(), text, FP_TEXT::TEXT_is_DIVERS, and FOOTPRINT::Zones().

Referenced by PCB_CONTROL::Paste().

◆ plugin_type()

IO_MGR::PCB_FILE_T plugin_type ( const wxString &  aFileName,
int  aCtl 
)

Definition at line 470 of file pcbnew/files.cpp.

471{
472 IO_MGR::PCB_FILE_T pluginType;
473
474 wxFileName fn = aFileName;
475
476 // Note: file extensions are expected to be in lower case.
477 // This is not always true, especially when importing files, so the string
478 // comparisons are case insensitive to try to find the suitable plugin.
479
480 if( fn.GetExt().CmpNoCase( IO_MGR::GetFileExtension( IO_MGR::LEGACY ) ) == 0 )
481 {
482 // both legacy and eagle share a common file extension.
483 pluginType = ( aCtl & KICTL_EAGLE_BRD ) ? IO_MGR::EAGLE : IO_MGR::LEGACY;
484 }
485 else if( fn.GetExt().CmpNoCase( IO_MGR::GetFileExtension( IO_MGR::PCAD ) ) == 0 )
486 {
487 pluginType = IO_MGR::PCAD;
488 }
489 else if( fn.GetExt().CmpNoCase( IO_MGR::GetFileExtension( IO_MGR::ALTIUM_DESIGNER ) ) == 0 )
490 {
491 pluginType = IO_MGR::ALTIUM_DESIGNER;
492 }
493 else if( fn.GetExt().CmpNoCase( IO_MGR::GetFileExtension( IO_MGR::ALTIUM_CIRCUIT_STUDIO ) ) == 0 )
494 {
496 }
497 else if( fn.GetExt().CmpNoCase( IO_MGR::GetFileExtension( IO_MGR::ALTIUM_CIRCUIT_MAKER ) ) == 0 )
498 {
499 pluginType = IO_MGR::ALTIUM_CIRCUIT_MAKER;
500 }
501 else if( fn.GetExt().CmpNoCase( IO_MGR::GetFileExtension( IO_MGR::CADSTAR_PCB_ARCHIVE ) ) == 0 )
502 {
503 pluginType = IO_MGR::CADSTAR_PCB_ARCHIVE;
504 }
505 else if( fn.GetExt().CmpNoCase( IO_MGR::GetFileExtension( IO_MGR::FABMASTER ) ) == 0 )
506 {
507 pluginType = IO_MGR::FABMASTER;
508 }
509 else
510 {
511 pluginType = IO_MGR::KICAD_SEXP;
512 }
513
514 return pluginType;
515}
static const wxString GetFileExtension(PCB_FILE_T aFileType)
Return the file extension for aFileType.
Definition: io_mgr.cpp:109

References IO_MGR::ALTIUM_CIRCUIT_MAKER, IO_MGR::ALTIUM_CIRCUIT_STUDIO, IO_MGR::ALTIUM_DESIGNER, IO_MGR::CADSTAR_PCB_ARCHIVE, IO_MGR::EAGLE, IO_MGR::FABMASTER, IO_MGR::GetFileExtension(), IO_MGR::KICAD_SEXP, KICTL_EAGLE_BRD, IO_MGR::LEGACY, and IO_MGR::PCAD.

Referenced by PCB_CONTROL::AppendBoardFromFile(), and PCB_EDIT_FRAME::OpenProjectFiles().