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 <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_id.h>
#include <properties.h>
#include <tool/tool_manager.h>
#include <view/view_controls.h>
#include <functional>
#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)
 
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 356 of file pcbnew_control.cpp.

◆ ALPHA_MIN

#define ALPHA_MIN   0.20

Definition at line 355 of file pcbnew_control.cpp.

◆ ALPHA_STEP

#define ALPHA_STEP   0.05

Definition at line 357 of file pcbnew_control.cpp.

◆ HITTEST_THRESHOLD_PIXELS

#define HITTEST_THRESHOLD_PIXELS   5

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

74 {
75  // This is a subset of all PLUGINs which are trusted to be able to
76  // load a BOARD. User may occasionally use the wrong plugin to load a
77  // *.brd file (since both legacy and eagle use *.brd extension),
78  // but eventually *.kicad_pcb will be more common than legacy *.brd files.
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 board files
88  { PCadPcbFileWildcard(), IO_MGR::PCAD }, // Import board files
89  };
90 
91  wxFileName fileName( *aFileName );
92  wxString fileFilters;
93 
94  if( aKicadFilesOnly )
95  {
96  for( unsigned ii = 0; ii < 2; ++ii )
97  {
98  if( !fileFilters.IsEmpty() )
99  fileFilters += wxChar( '|' );
100 
101  fileFilters += wxGetTranslation( loaders[ii].filter );
102  }
103  }
104  else
105  {
106  for( unsigned ii = 2; ii < arrayDim( loaders ); ++ii )
107  {
108  if( !fileFilters.IsEmpty() )
109  fileFilters += wxChar( '|' );
110 
111  fileFilters += wxGetTranslation( loaders[ii].filter );
112  }
113  }
114 
115  wxString path;
116  wxString name;
117 
118  if( fileName.FileExists() )
119  {
120  path = fileName.GetPath();
121  name = fileName.GetFullName();
122  }
123  else
124  {
125  path = wxStandardPaths::Get().GetDocumentsDir();
126  // leave name empty
127  }
128 
129  wxFileDialog dlg( aParent,
130  aKicadFilesOnly ? _( "Open Board File" ) : _( "Import Non KiCad Board File" ),
131  path, name, fileFilters,
132  wxFD_OPEN | wxFD_FILE_MUST_EXIST );
133 
134  if( dlg.ShowModal() == wxID_OK )
135  {
136  // For import option, if Eagle (*.brd files), tell OpenProjectFiles() to use Eagle plugin.
137  // It's the only special case because of the duplicate use of the *.brd file extension.
138  // Other cases are clear because of unique file extensions.
139  *aCtl = aKicadFilesOnly ? 0 : KICTL_EAGLE_BRD;
140  *aFileName = dlg.GetPath();
141  return true;
142  }
143  else
144  return false;
145 }
wxString EaglePcbFileWildcard()
#define KICTL_EAGLE_BRD
chosen *.brd file is Eagle according to user.
Definition: kiway_player.h:78
wxString LegacyPcbFileWildcard()
#define _(s)
constexpr std::size_t arrayDim(T const (&)[N]) noexcept
Definition: macros.h:108
static const struct @8 fileFilters[FILTER_COUNT]
Legacy Pcbnew file formats prior to s-expression.
Definition: io_mgr.h:56
const char * name
Definition: DXF_plotter.cpp:61
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 _, arrayDim(), IO_MGR::EAGLE, EaglePcbFileWildcard(), fileFilters, 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()

◆ moveNoFlagToVector() [1/2]

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

Definition at line 682 of file pcbnew_control.cpp.

683 {
684  std::copy_if( aList.begin(), aList.end(), std::back_inserter( aTarget ),
685  [](T aItem)
686  {
687  bool retval = ( aItem->GetFlags() & FLAG0 ) == 0;
688  aItem->ClearFlags( FLAG0 );
689  return retval;
690  } );
691 
692  if( aIsNew )
693  aList.clear();
694 }
#define FLAG0
Pcbnew: flag used in local computations.
Definition: base_struct.h:137

References FLAG0.

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 697 of file pcbnew_control.cpp.

698 {
699  if( aList.size() == 0 )
700  return;
701 
702  auto obj = aList.front();
703  int idx = 0;
704 
705  if( aIsNew )
706  {
707  obj = aList.back();
708  aList.pop_back();
709  }
710 
711  for( ; obj ; )
712  {
713  if( obj->HasFlag( FLAG0 ) )
714  obj->ClearFlags( FLAG0 );
715  else
716  aTarget.push_back( obj );
717 
718  if( aIsNew )
719  {
720  if( aList.size() )
721  {
722  obj = aList.back();
723  aList.pop_back();
724  }
725  else
726  obj = nullptr;
727  }
728  else
729  obj = idx < int(aList.size()-1) ? aList[++idx] : nullptr;
730  }
731 }
#define FLAG0
Pcbnew: flag used in local computations.
Definition: base_struct.h:137

References FLAG0.

◆ plugin_type()

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

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

331 {
332  IO_MGR::PCB_FILE_T pluginType;
333 
334  wxFileName fn = aFileName;
335 
336  // Note: file extensions are expected to be in ower case.
337  // This is not always true, especially when importing files, so the string
338  // comparisons are case insensitive to try to find the suitable plugin.
339 
340  if( fn.GetExt().CmpNoCase( IO_MGR::GetFileExtension( IO_MGR::LEGACY ) ) == 0 )
341  {
342  // both legacy and eagle share a common file extension.
343  pluginType = ( aCtl & KICTL_EAGLE_BRD ) ? IO_MGR::EAGLE : IO_MGR::LEGACY;
344  }
345  else if( fn.GetExt().CmpNoCase( IO_MGR::GetFileExtension( IO_MGR::PCAD ) ) == 0 )
346  {
347  pluginType = IO_MGR::PCAD;
348  }
349  else
350  {
351  pluginType = IO_MGR::KICAD_SEXP;
352  }
353 
354  return pluginType;
355 }
#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:109

References 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().