KiCad PCB EDA Suite
pcbnew_control.cpp File Reference
#include "edit_tool.h"
#include "pcb_actions.h"
#include "pcbnew_control.h"
#include "pcbnew_picker_tool.h"
#include "selection_tool.h"
#include <3d_viewer/eda_3d_viewer.h>
#include <bitmaps.h>
#include <board_commit.h>
#include <class_board.h>
#include <class_board_item.h>
#include <class_module.h>
#include <class_track.h>
#include <class_zone.h>
#include <class_edge_mod.h>
#include <confirm.h>
#include <connectivity/connectivity_data.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 <view/view_controls.h>
#include <footprint_viewer_frame.h>
#include <footprint_edit_frame.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 (wxWindow *aParent, int *aCtl, wxString *aFileName, bool aKicadFilesOnly=false)
 Function AskLoadBoardFileName puts up 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)
 
void pasteModuleItemsToModEdit (MODULE *aClipModule, 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 (ZONE_CONTAINERS &aList, std::vector< BOARD_ITEM * > &aTarget, bool aIsNew)
 

Macro Definition Documentation

◆ ALPHA_MAX

#define ALPHA_MAX   1.00

Definition at line 336 of file pcbnew_control.cpp.

◆ ALPHA_MIN

#define ALPHA_MIN   0.20

Definition at line 335 of file pcbnew_control.cpp.

◆ ALPHA_STEP

#define ALPHA_STEP   0.05

Definition at line 337 of file pcbnew_control.cpp.

◆ HITTEST_THRESHOLD_PIXELS

#define HITTEST_THRESHOLD_PIXELS   5

Definition at line 447 of file pcbnew_control.cpp.

Function Documentation

◆ AskLoadBoardFileName()

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

Function AskLoadBoardFileName puts up 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 kiacad pcb files plugins only, false to list import plugins.
Returns
bool - true if chosen, else false if user aborted.

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

79 {
80  // This is a subset of all PLUGINs which are trusted to be able to
81  // load a BOARD. User may occasionally use the wrong plugin to load a
82  // *.brd file (since both legacy and eagle use *.brd extension),
83  // but eventually *.kicad_pcb will be more common than legacy *.brd files.
84 
85  // clang-format off
86  static const struct
87  {
88  const wxString& filter;
89  IO_MGR::PCB_FILE_T pluginType;
90  } loaders[] =
91  {
92  { PcbFileWildcard(), IO_MGR::KICAD_SEXP }, // Current Kicad board files
93  { LegacyPcbFileWildcard(), IO_MGR::LEGACY }, // Old Kicad board files
94  { EaglePcbFileWildcard(), IO_MGR::EAGLE }, // Import Eagle board files
95  { PCadPcbFileWildcard(), IO_MGR::PCAD }, // Import PCAD board files
96  { AltiumDesignerPcbFileWildcard(), IO_MGR::ALTIUM_DESIGNER }, // Import Altium Designer board files
97  { AltiumCircuitStudioPcbFileWildcard(), IO_MGR::ALTIUM_CIRCUIT_STUDIO }, // Import Altium Circuit Studio board files
98  { AltiumCircuitMakerPcbFileWildcard(), IO_MGR::ALTIUM_CIRCUIT_MAKER }, // Import Altium Circuit Maker board files
99  };
100  // clang-format on
101 
102  wxFileName fileName( *aFileName );
103  wxString fileFilters;
104 
105  if( aKicadFilesOnly )
106  {
107  for( unsigned ii = 0; ii < 2; ++ii )
108  {
109  if( !fileFilters.IsEmpty() )
110  fileFilters += wxChar( '|' );
111 
112  fileFilters += wxGetTranslation( loaders[ii].filter );
113  }
114  }
115  else
116  {
117  for( unsigned ii = 2; ii < arrayDim( loaders ); ++ii )
118  {
119  if( !fileFilters.IsEmpty() )
120  fileFilters += wxChar( '|' );
121 
122  fileFilters += wxGetTranslation( loaders[ii].filter );
123  }
124  }
125 
126  wxString path;
127  wxString name;
128 
129  if( fileName.FileExists() )
130  {
131  path = fileName.GetPath();
132  name = fileName.GetFullName();
133  }
134  else
135  {
136  path = wxStandardPaths::Get().GetDocumentsDir();
137  // leave name empty
138  }
139 
140  wxFileDialog dlg( aParent,
141  aKicadFilesOnly ? _( "Open Board File" ) : _( "Import Non KiCad Board File" ),
142  path, name, fileFilters,
143  wxFD_OPEN | wxFD_FILE_MUST_EXIST );
144 
145  if( dlg.ShowModal() == wxID_OK )
146  {
147  // For import option, if Eagle (*.brd files), tell OpenProjectFiles() to use Eagle plugin.
148  // It's the only special case because of the duplicate use of the *.brd file extension.
149  // Other cases are clear because of unique file extensions.
150  *aCtl = aKicadFilesOnly ? 0 : KICTL_EAGLE_BRD;
151  *aFileName = dlg.GetPath();
152  return true;
153  }
154  else
155  return false;
156 }
wxString EaglePcbFileWildcard()
#define KICTL_EAGLE_BRD
chosen *.brd file is Eagle according to user.
Definition: kiway_player.h:78
wxString AltiumCircuitMakerPcbFileWildcard()
wxString LegacyPcbFileWildcard()
wxString AltiumDesignerPcbFileWildcard()
constexpr std::size_t arrayDim(T const (&)[N]) noexcept
Definition: macros.h:160
wxString AltiumCircuitStudioPcbFileWildcard()
Legacy Pcbnew file formats prior to s-expression.
Definition: io_mgr.h:56
const char * name
Definition: DXF_plotter.cpp:60
#define _(s)
Definition: 3d_actions.cpp:33
wxString PcbFileWildcard()
PCB_FILE_T
Enum PCB_FILE_T is a set of file types that the IO_MGR knows about, and for which there has been a pl...
Definition: io_mgr.h:54
wxString PCadPcbFileWildcard()
S-expression Pcbnew file format.
Definition: io_mgr.h:57

References _, IO_MGR::ALTIUM_CIRCUIT_MAKER, IO_MGR::ALTIUM_CIRCUIT_STUDIO, IO_MGR::ALTIUM_DESIGNER, AltiumCircuitMakerPcbFileWildcard(), AltiumCircuitStudioPcbFileWildcard(), AltiumDesignerPcbFileWildcard(), arrayDim(), IO_MGR::EAGLE, EaglePcbFileWildcard(), IO_MGR::KICAD_SEXP, KICTL_EAGLE_BRD, IO_MGR::LEGACY, LegacyPcbFileWildcard(), name, IO_MGR::PCAD, PCadPcbFileWildcard(), and PcbFileWildcard().

Referenced by PCBNEW_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 111 of file pcbnew_control.cpp.

112 {
113  aValue = !aValue;
114 }

Referenced by PCBNEW_CONTROL::ToggleRatsnest(), PCBNEW_CONTROL::TrackDisplayMode(), and PCBNEW_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 755 of file pcbnew_control.cpp.

757 {
758  std::copy_if( aList.begin(), aList.end(), std::back_inserter( aTarget ),
759  [aIsNew]( T aItem )
760  {
761  bool doCopy = ( aItem->GetFlags() & SKIP_STRUCT ) == 0;
762 
763  aItem->ClearFlags( SKIP_STRUCT );
764  aItem->SetFlags( aIsNew ? IS_NEW : 0 );
765 
766  return doCopy;
767  } );
768 
769  if( aIsNew )
770  aList.clear();
771 }
#define SKIP_STRUCT
flag indicating that the structure should be ignored
Definition: base_struct.h:128
T
enum T contains all this lexer's tokens.
#define IS_NEW
New item, just created.
Definition: base_struct.h:117

References IS_NEW, and SKIP_STRUCT.

Referenced by PCBNEW_CONTROL::placeBoardItems().

◆ moveUnflaggedItems() [2/2]

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

Definition at line 774 of file pcbnew_control.cpp.

776 {
777  if( aList.size() == 0 )
778  return;
779 
780  auto obj = aList.front();
781  int idx = 0;
782 
783  if( aIsNew )
784  {
785  obj = aList.back();
786  aList.pop_back();
787  }
788 
789  for( ; obj ; )
790  {
791  if( obj->HasFlag( SKIP_STRUCT ) )
792  obj->ClearFlags( SKIP_STRUCT );
793  else
794  aTarget.push_back( obj );
795 
796  if( aIsNew )
797  {
798  if( aList.size() )
799  {
800  obj = aList.back();
801  aList.pop_back();
802  }
803  else
804  obj = nullptr;
805  }
806  else
807  obj = idx < int(aList.size()-1) ? aList[++idx] : nullptr;
808  }
809 }
#define SKIP_STRUCT
flag indicating that the structure should be ignored
Definition: base_struct.h:128

References SKIP_STRUCT.

◆ pasteModuleItemsToModEdit()

void pasteModuleItemsToModEdit ( MODULE aClipModule,
BOARD aBoard,
std::vector< BOARD_ITEM * > &  aPastedItems 
)

Definition at line 542 of file pcbnew_control.cpp.

544 {
545  MODULE* editModule = aBoard->GetFirstModule();
546 
547  aClipModule->SetParent( aBoard );
548 
549  for( D_PAD* pad : aClipModule->Pads() )
550  {
551  pad->SetParent( editModule );
552  aPastedItems.push_back( pad );
553  }
554 
555  aClipModule->Pads().clear();
556 
557  for( BOARD_ITEM* item : aClipModule->GraphicalItems() )
558  {
559  if( item->Type() == PCB_MODULE_EDGE_T )
560  {
561  EDGE_MODULE* edge = static_cast<EDGE_MODULE*>( item );
562 
563  edge->SetParent( nullptr );
564  edge->SetLocalCoord();
565  }
566  else if( item->Type() == PCB_MODULE_TEXT_T )
567  {
568  TEXTE_MODULE* text = static_cast<TEXTE_MODULE*>( item );
569 
570  if( text->GetType() != TEXTE_MODULE::TEXT_is_DIVERS )
572 
573  if( text->GetText() == "${VALUE}" )
574  text->SetText( aClipModule->GetValue() );
575  else if( text->GetText() == "${REFERENCE}" )
576  text->SetText( aClipModule->GetReference() );
577 
578  text->SetTextAngle( aClipModule->GetOrientation() );
579 
580  text->SetParent( nullptr );
581  text->SetLocalCoord();
582  }
583 
584  item->SetParent( editModule );
585  aPastedItems.push_back( item );
586  }
587 
588  aClipModule->GraphicalItems().clear();
589 
590  if( !aClipModule->GetReference().IsEmpty() )
591  {
592  TEXTE_MODULE* text = new TEXTE_MODULE( aClipModule->Reference() );
594  text->SetTextAngle( aClipModule->GetOrientation() );
595 
596  text->SetParent( nullptr );
597  text->SetLocalCoord();
598 
599  text->SetParent( editModule );
600  aPastedItems.push_back( text );
601  }
602 
603  if( !aClipModule->GetValue().IsEmpty() )
604  {
605  TEXTE_MODULE* text = new TEXTE_MODULE( aClipModule->Value() );
607  text->SetTextAngle( aClipModule->GetOrientation() );
608 
609  text->SetParent( nullptr );
610  text->SetLocalCoord();
611 
612  text->SetParent( editModule );
613  aPastedItems.push_back( text );
614  }
615 }
double GetOrientation() const
Definition: class_module.h:221
TEXTE_MODULE & Reference()
Definition: class_module.h:485
BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
PADS & Pads()
Definition: class_module.h:173
const wxString GetValue() const
Function GetValue.
Definition: class_module.h:469
DRAWINGS & GraphicalItems()
Definition: class_module.h:183
class EDGE_MODULE, a footprint edge
Definition: typeinfo.h:94
virtual void SetParent(EDA_ITEM *aParent)
Definition: base_struct.h:196
const wxString GetReference() const
Function GetReference.
Definition: class_module.h:444
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:121
TEXTE_MODULE & Value()
read/write accessors:
Definition: class_module.h:484
TEXT_TYPE GetType() const
MODULE * GetFirstModule() const
Gets the first module in the list (used in footprint viewer/editor) or NULL if none.
Definition: class_board.h:330
void SetTextAngle(double aAngle) override
void SetType(TEXT_TYPE aType)
class TEXTE_MODULE, text in a footprint
Definition: typeinfo.h:93
void SetLocalCoord()
Set relative coordinates from draw coordinates.
void SetLocalCoord()
Set relative coordinates.
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:127

References BOARD::GetFirstModule(), MODULE::GetOrientation(), MODULE::GetReference(), EDA_TEXT::GetText(), TEXTE_MODULE::GetType(), MODULE::GetValue(), MODULE::GraphicalItems(), MODULE::Pads(), PCB_MODULE_EDGE_T, PCB_MODULE_TEXT_T, MODULE::Reference(), EDGE_MODULE::SetLocalCoord(), TEXTE_MODULE::SetLocalCoord(), EDA_ITEM::SetParent(), EDA_TEXT::SetText(), TEXTE_MODULE::SetTextAngle(), TEXTE_MODULE::SetType(), TEXTE_MODULE::TEXT_is_DIVERS, and MODULE::Value().

Referenced by PCBNEW_CONTROL::Paste().

◆ plugin_type()

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

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

372 {
373  IO_MGR::PCB_FILE_T pluginType;
374 
375  wxFileName fn = aFileName;
376 
377  // Note: file extensions are expected to be in lower case.
378  // This is not always true, especially when importing files, so the string
379  // comparisons are case insensitive to try to find the suitable plugin.
380 
381  if( fn.GetExt().CmpNoCase( IO_MGR::GetFileExtension( IO_MGR::LEGACY ) ) == 0 )
382  {
383  // both legacy and eagle share a common file extension.
384  pluginType = ( aCtl & KICTL_EAGLE_BRD ) ? IO_MGR::EAGLE : IO_MGR::LEGACY;
385  }
386  else if( fn.GetExt().CmpNoCase( IO_MGR::GetFileExtension( IO_MGR::PCAD ) ) == 0 )
387  {
388  pluginType = IO_MGR::PCAD;
389  }
390  else if( fn.GetExt().CmpNoCase( IO_MGR::GetFileExtension( IO_MGR::ALTIUM_DESIGNER ) ) == 0 )
391  {
392  pluginType = IO_MGR::ALTIUM_DESIGNER;
393  }
394  else if( fn.GetExt().CmpNoCase( IO_MGR::GetFileExtension( IO_MGR::ALTIUM_CIRCUIT_STUDIO ) ) == 0 )
395  {
396  pluginType = IO_MGR::ALTIUM_CIRCUIT_STUDIO;
397  }
398  else if( fn.GetExt().CmpNoCase( IO_MGR::GetFileExtension( IO_MGR::ALTIUM_CIRCUIT_MAKER ) ) == 0 )
399  {
400  pluginType = IO_MGR::ALTIUM_CIRCUIT_MAKER;
401  }
402  else
403  {
404  pluginType = IO_MGR::KICAD_SEXP;
405  }
406 
407  return pluginType;
408 }
#define KICTL_EAGLE_BRD
chosen *.brd file is Eagle according to user.
Definition: kiway_player.h:78
Legacy Pcbnew file formats prior to s-expression.
Definition: io_mgr.h:56
PCB_FILE_T
Enum PCB_FILE_T is a set of file types that the IO_MGR knows about, and for which there has been a pl...
Definition: io_mgr.h:54
S-expression Pcbnew file format.
Definition: io_mgr.h:57
static const wxString GetFileExtension(PCB_FILE_T aFileType)
Function GetFileExtension returns the file extension for aFileType.
Definition: io_mgr.cpp:112

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

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