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 <gal/graphics_abstraction_layer.h>
#include <io_mgr.h>
#include <kicad_clipboard.h>
#include <kicad_plugin.h>
#include <kiway.h>
#include <origin_viewitem.h>
#include <pcb_edit_frame.h>
#include <pcb_painter.h>
#include <pcb_screen.h>
#include <pcbnew_settings.h>
#include <properties.h>
#include <settings/color_settings.h>
#include <tool/tool_manager.h>
#include <view/view_controls.h>
#include <functional>
#include <footprint_viewer_frame.h>
#include <footprint_edit_frame.h>
#include <math/util.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 moveNoFlagToVector (std::deque< T > &aList, std::vector< BOARD_ITEM * > &aTarget, bool aIsNew)
 
static void moveNoFlagToVector (ZONE_CONTAINERS &aList, std::vector< BOARD_ITEM * > &aTarget, bool aIsNew)
 

Macro Definition Documentation

◆ ALPHA_MAX

#define ALPHA_MAX   1.00

Definition at line 313 of file pcbnew_control.cpp.

◆ ALPHA_MIN

#define ALPHA_MIN   0.20

Definition at line 312 of file pcbnew_control.cpp.

◆ ALPHA_STEP

#define ALPHA_STEP   0.05

Definition at line 314 of file pcbnew_control.cpp.

◆ HITTEST_THRESHOLD_PIXELS

#define HITTEST_THRESHOLD_PIXELS   5

Definition at line 440 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 71 of file pcbnew/files.cpp.

72 {
73  // This is a subset of all PLUGINs which are trusted to be able to
74  // load a BOARD. User may occasionally use the wrong plugin to load a
75  // *.brd file (since both legacy and eagle use *.brd extension),
76  // but eventually *.kicad_pcb will be more common than legacy *.brd files.
77 
78  // clang-format off
79  static const struct
80  {
81  const wxString& filter;
82  IO_MGR::PCB_FILE_T pluginType;
83  } loaders[] =
84  {
85  { PcbFileWildcard(), IO_MGR::KICAD_SEXP }, // Current Kicad board files
86  { LegacyPcbFileWildcard(), IO_MGR::LEGACY }, // Old Kicad board files
87  { EaglePcbFileWildcard(), IO_MGR::EAGLE }, // Import Eagle board files
88  { PCadPcbFileWildcard(), IO_MGR::PCAD }, // Import PCAD board files
89  { AltiumDesignerPcbFileWildcard(), IO_MGR::ALTIUM_DESIGNER }, // Import Altium Designer board files
90  { AltiumCircuitStudioPcbFileWildcard(), IO_MGR::ALTIUM_CIRCUIT_STUDIO }, // Import Altium Circuit Studio board files
91  { AltiumCircuitMakerPcbFileWildcard(), IO_MGR::ALTIUM_CIRCUIT_MAKER }, // Import Altium Circuit Maker board files
92  };
93  // clang-format on
94 
95  wxFileName fileName( *aFileName );
96  wxString fileFilters;
97 
98  if( aKicadFilesOnly )
99  {
100  for( unsigned ii = 0; ii < 2; ++ii )
101  {
102  if( !fileFilters.IsEmpty() )
103  fileFilters += wxChar( '|' );
104 
105  fileFilters += wxGetTranslation( loaders[ii].filter );
106  }
107  }
108  else
109  {
110  for( unsigned ii = 2; ii < arrayDim( loaders ); ++ii )
111  {
112  if( !fileFilters.IsEmpty() )
113  fileFilters += wxChar( '|' );
114 
115  fileFilters += wxGetTranslation( loaders[ii].filter );
116  }
117  }
118 
119  wxString path;
120  wxString name;
121 
122  if( fileName.FileExists() )
123  {
124  path = fileName.GetPath();
125  name = fileName.GetFullName();
126  }
127  else
128  {
129  path = wxStandardPaths::Get().GetDocumentsDir();
130  // leave name empty
131  }
132 
133  wxFileDialog dlg( aParent,
134  aKicadFilesOnly ? _( "Open Board File" ) : _( "Import Non KiCad Board File" ),
135  path, name, fileFilters,
136  wxFD_OPEN | wxFD_FILE_MUST_EXIST );
137 
138  if( dlg.ShowModal() == wxID_OK )
139  {
140  // For import option, if Eagle (*.brd files), tell OpenProjectFiles() to use Eagle plugin.
141  // It's the only special case because of the duplicate use of the *.brd file extension.
142  // Other cases are clear because of unique file extensions.
143  *aCtl = aKicadFilesOnly ? 0 : KICTL_EAGLE_BRD;
144  *aFileName = dlg.GetPath();
145  return true;
146  }
147  else
148  return false;
149 }
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)

◆ moveNoFlagToVector() [1/2]

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

Definition at line 748 of file pcbnew_control.cpp.

749 {
750  std::copy_if( aList.begin(), aList.end(), std::back_inserter( aTarget ),
751  [aIsNew]( T aItem )
752  {
753  bool doCopy = ( aItem->GetFlags() & FLAG0 ) == 0;
754 
755  aItem->ClearFlags( FLAG0 );
756  aItem->SetFlags( aIsNew ? IS_NEW : 0 );
757 
758  return doCopy;
759  } );
760 
761  if( aIsNew )
762  aList.clear();
763 }
#define IS_NEW
New item, just created.
Definition: base_struct.h:117
#define FLAG0
Pcbnew: flag used in local computations.
Definition: base_struct.h:134

References FLAG0, and IS_NEW.

Referenced by PCBNEW_CONTROL::placeBoardItems().

◆ moveNoFlagToVector() [2/2]

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

Definition at line 766 of file pcbnew_control.cpp.

767 {
768  if( aList.size() == 0 )
769  return;
770 
771  auto obj = aList.front();
772  int idx = 0;
773 
774  if( aIsNew )
775  {
776  obj = aList.back();
777  aList.pop_back();
778  }
779 
780  for( ; obj ; )
781  {
782  if( obj->HasFlag( FLAG0 ) )
783  obj->ClearFlags( FLAG0 );
784  else
785  aTarget.push_back( obj );
786 
787  if( aIsNew )
788  {
789  if( aList.size() )
790  {
791  obj = aList.back();
792  aList.pop_back();
793  }
794  else
795  obj = nullptr;
796  }
797  else
798  obj = idx < int(aList.size()-1) ? aList[++idx] : nullptr;
799  }
800 }
#define FLAG0
Pcbnew: flag used in local computations.
Definition: base_struct.h:134

References FLAG0.

◆ pasteModuleItemsToModEdit()

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

Definition at line 535 of file pcbnew_control.cpp.

537 {
538  MODULE* editModule = aBoard->GetFirstModule();
539 
540  aClipModule->SetParent( aBoard );
541 
542  for( D_PAD* pad : aClipModule->Pads() )
543  {
544  pad->SetParent( editModule );
545  aPastedItems.push_back( pad );
546  }
547 
548  aClipModule->Pads().clear();
549 
550  for( BOARD_ITEM* item : aClipModule->GraphicalItems() )
551  {
552  if( item->Type() == PCB_MODULE_EDGE_T )
553  {
554  EDGE_MODULE* edge = static_cast<EDGE_MODULE*>( item );
555 
556  edge->SetParent( nullptr );
557  edge->SetLocalCoord();
558  }
559  else if( item->Type() == PCB_MODULE_TEXT_T )
560  {
561  TEXTE_MODULE* text = static_cast<TEXTE_MODULE*>( item );
562 
563  if( text->GetType() != TEXTE_MODULE::TEXT_is_DIVERS )
565 
566  if( text->GetText() == "${VALUE}" )
567  text->SetText( aClipModule->GetValue() );
568  else if( text->GetText() == "${REFERENCE}" )
569  text->SetText( aClipModule->GetReference() );
570 
571  text->SetTextAngle( aClipModule->GetOrientation() );
572 
573  text->SetParent( nullptr );
574  text->SetLocalCoord();
575  }
576 
577  item->SetParent( editModule );
578  aPastedItems.push_back( item );
579  }
580 
581  aClipModule->GraphicalItems().clear();
582 
583  if( !aClipModule->GetReference().IsEmpty() )
584  {
585  TEXTE_MODULE* text = new TEXTE_MODULE( aClipModule->Reference() );
587  text->SetTextAngle( aClipModule->GetOrientation() );
588 
589  text->SetParent( nullptr );
590  text->SetLocalCoord();
591 
592  text->SetParent( editModule );
593  aPastedItems.push_back( text );
594  }
595 
596  if( !aClipModule->GetValue().IsEmpty() )
597  {
598  TEXTE_MODULE* text = new TEXTE_MODULE( aClipModule->Value() );
600  text->SetTextAngle( aClipModule->GetOrientation() );
601 
602  text->SetParent( nullptr );
603  text->SetLocalCoord();
604 
605  text->SetParent( editModule );
606  aPastedItems.push_back( text );
607  }
608 }
double GetOrientation() const
Definition: class_module.h:211
TEXTE_MODULE & Reference()
Definition: class_module.h:469
BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
PADS & Pads()
Definition: class_module.h:169
const wxString GetValue() const
Function GetValue.
Definition: class_module.h:453
DRAWINGS & GraphicalItems()
Definition: class_module.h:179
class EDGE_MODULE, a footprint edge
Definition: typeinfo.h:94
virtual void SetParent(EDA_ITEM *aParent)
Definition: base_struct.h:200
const wxString GetReference() const
Function GetReference.
Definition: class_module.h:428
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:116
TEXTE_MODULE & Value()
read/write accessors:
Definition: class_module.h:468
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:310
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:126

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 360 of file pcbnew/files.cpp.

361 {
362  IO_MGR::PCB_FILE_T pluginType;
363 
364  wxFileName fn = aFileName;
365 
366  // Note: file extensions are expected to be in lower case.
367  // This is not always true, especially when importing files, so the string
368  // comparisons are case insensitive to try to find the suitable plugin.
369 
370  if( fn.GetExt().CmpNoCase( IO_MGR::GetFileExtension( IO_MGR::LEGACY ) ) == 0 )
371  {
372  // both legacy and eagle share a common file extension.
373  pluginType = ( aCtl & KICTL_EAGLE_BRD ) ? IO_MGR::EAGLE : IO_MGR::LEGACY;
374  }
375  else if( fn.GetExt().CmpNoCase( IO_MGR::GetFileExtension( IO_MGR::PCAD ) ) == 0 )
376  {
377  pluginType = IO_MGR::PCAD;
378  }
379  else if( fn.GetExt().CmpNoCase( IO_MGR::GetFileExtension( IO_MGR::ALTIUM_DESIGNER ) ) == 0 )
380  {
381  pluginType = IO_MGR::ALTIUM_DESIGNER;
382  }
383  else if( fn.GetExt().CmpNoCase( IO_MGR::GetFileExtension( IO_MGR::ALTIUM_CIRCUIT_STUDIO ) ) == 0 )
384  {
385  pluginType = IO_MGR::ALTIUM_CIRCUIT_STUDIO;
386  }
387  else if( fn.GetExt().CmpNoCase( IO_MGR::GetFileExtension( IO_MGR::ALTIUM_CIRCUIT_MAKER ) ) == 0 )
388  {
389  pluginType = IO_MGR::ALTIUM_CIRCUIT_MAKER;
390  }
391  else
392  {
393  pluginType = IO_MGR::KICAD_SEXP;
394  }
395 
396  return pluginType;
397 }
#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().