KiCad PCB EDA Suite
pcbnew_control.cpp File Reference
#include <cstdint>
#include "pcbnew_control.h"
#include "pcb_actions.h"
#include "selection_tool.h"
#include "edit_tool.h"
#include "picker_tool.h"
#include "pcb_editor_control.h"
#include "grid_helper.h"
#include <class_board.h>
#include <class_module.h>
#include <class_track.h>
#include <class_zone.h>
#include <pcb_screen.h>
#include <confirm.h>
#include <hotkeys.h>
#include <properties.h>
#include <io_mgr.h>
#include <kicad_plugin.h>
#include <kicad_clipboard.h>
#include <pcbnew_id.h>
#include <pcb_edit_frame.h>
#include <pcb_draw_panel_gal.h>
#include <connectivity/connectivity_data.h>
#include <tool/tool_manager.h>
#include <gal/graphics_abstraction_layer.h>
#include <view/view_controls.h>
#include <pcb_painter.h>
#include <origin_viewitem.h>
#include <board_commit.h>
#include <bitmaps.h>
#include <functional>

Go to the source code of this file.

Macros

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

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)
 
static bool deleteItem (TOOL_MANAGER *aToolMgr, const VECTOR2D &aPosition)
 
template<typename T >
static void moveNoFlagToVector (DLIST< 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 486 of file pcbnew_control.cpp.

◆ ALPHA_MIN

#define ALPHA_MIN   0.20

Definition at line 485 of file pcbnew_control.cpp.

◆ ALPHA_STEP

#define ALPHA_STEP   0.05

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

78 {
79  // This is a subset of all PLUGINs which are trusted to be able to
80  // load a BOARD. User may occasionally use the wrong plugin to load a
81  // *.brd file (since both legacy and eagle use *.brd extension),
82  // but eventually *.kicad_pcb will be more common than legacy *.brd files.
83  static const struct
84  {
85  const wxString& filter;
86  IO_MGR::PCB_FILE_T pluginType;
87  } loaders[] =
88  {
89  { PcbFileWildcard(), IO_MGR::KICAD_SEXP }, // Current Kicad board files
90  { LegacyPcbFileWildcard(), IO_MGR::LEGACY }, // Old Kicad board files
91  { EaglePcbFileWildcard(), IO_MGR::EAGLE }, // Import board files
92  { PCadPcbFileWildcard(), IO_MGR::PCAD }, // Import board files
93  };
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:139
wxString LegacyPcbFileWildcard()
constexpr std::size_t arrayDim(T const (&)[N]) noexcept
Definition: macros.h:99
Legacy Pcbnew file formats prior to s-expression.
Definition: io_mgr.h:56
const char * name
Definition: DXF_plotter.cpp:61
wxString PcbFileWildcard()
static const struct @9 fileFilters[FILTER_COUNT]
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().

◆ deleteItem()

static bool deleteItem ( TOOL_MANAGER aToolMgr,
const VECTOR2D aPosition 
)
static

Definition at line 656 of file pcbnew_control.cpp.

657 {
658  SELECTION_TOOL* selectionTool = aToolMgr->GetTool<SELECTION_TOOL>();
659  wxCHECK( selectionTool, false );
660 
661  aToolMgr->RunAction( PCB_ACTIONS::selectionClear, true );
662 
663  const SELECTION& selection = selectionTool->RequestSelection(
664  []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector )
665  { EditToolSelectionFilter( aCollector, EXCLUDE_LOCKED ); } );
666 
667  if( selection.Empty() )
668  return true;
669 
670  aToolMgr->RunAction( PCB_ACTIONS::remove, true );
671 
672  return true;
673 }
static TOOL_ACTION selectionClear
Clears the current selection.
Definition: pcb_actions.h:53
SELECTION & RequestSelection(CLIENT_SELECTION_FILTER aClientFilter, std::vector< BOARD_ITEM * > *aFiltered=NULL, bool aConfirmLockedItems=false)
Function RequestSelection()
Class SELECTION_TOOL.
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:125
bool Empty() const
Checks if there is anything selected.
Definition: selection.h:116
Used when the right click button is pressed, or when the select tool is in effect.
Definition: collectors.h:245
#define EXCLUDE_LOCKED
Function EditToolSelectionFilter.
Definition: edit_tool.h:46
static TOOL_ACTION remove
Deleting a BOARD_ITEM.
Definition: pcb_actions.h:132
void EditToolSelectionFilter(GENERAL_COLLECTOR &aCollector, int aFlags)
Definition: edit_tool.cpp:173

References EditToolSelectionFilter(), SELECTION::Empty(), EXCLUDE_LOCKED, TOOL_MANAGER::GetTool(), PCB_ACTIONS::remove, SELECTION_TOOL::RequestSelection(), TOOL_MANAGER::RunAction(), and PCB_ACTIONS::selectionClear.

Referenced by PCBNEW_CONTROL::DeleteItemCursor().

◆ Flip()

◆ moveNoFlagToVector() [1/2]

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

Definition at line 799 of file pcbnew_control.cpp.

800 {
801  for( auto obj = aIsNew ? aList.PopFront() : aList.GetFirst(); obj;
802  obj = aIsNew ? aList.PopFront() : obj->Next() )
803  {
804  if( obj->GetFlags() & FLAG0 )
805  obj->ClearFlags( FLAG0 );
806  else
807  aTarget.push_back( obj );
808  }
809 }
T * GetFirst() const
Function GetFirst returns the first T* in the list without removing it, or NULL if the list is empty.
Definition: dlist.h:163
#define FLAG0
Pcbnew: flag used in local computations.
Definition: base_struct.h:132
T * PopFront()
Definition: dlist.h:221

References FLAG0, DLIST< T >::GetFirst(), and DLIST< T >::PopFront().

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

812 {
813  if( aList.size() == 0 )
814  return;
815 
816  auto obj = aList.front();
817  int idx = 0;
818 
819  if( aIsNew )
820  {
821  obj = aList.back();
822  aList.pop_back();
823  }
824 
825  for( ; obj ; )
826  {
827  if( obj->GetFlags() & FLAG0 )
828  obj->ClearFlags( FLAG0 );
829  else
830  aTarget.push_back( obj );
831 
832  if( aIsNew )
833  {
834  if( aList.size() )
835  {
836  obj = aList.back();
837  aList.pop_back();
838  }
839  else
840  obj = nullptr;
841  }
842  else
843  obj = idx < int(aList.size()-1) ? aList[++idx] : nullptr;
844  }
845 }
#define FLAG0
Pcbnew: flag used in local computations.
Definition: base_struct.h:132

References FLAG0.

◆ plugin_type()

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

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

360 {
361  IO_MGR::PCB_FILE_T pluginType;
362 
363  wxFileName fn = aFileName;
364 
365  // Note: file extensions are expected to be in ower case.
366  // This is not always true, especially when importing files, so the string
367  // comparisons are case insensitive to try to find the suitable plugin.
368 
369  if( fn.GetExt().CmpNoCase( IO_MGR::GetFileExtension( IO_MGR::LEGACY ) ) == 0 )
370  {
371  // both legacy and eagle share a common file extension.
372  pluginType = ( aCtl & KICTL_EAGLE_BRD ) ? IO_MGR::EAGLE : IO_MGR::LEGACY;
373  }
374  else if( fn.GetExt().CmpNoCase( IO_MGR::GetFileExtension( IO_MGR::PCAD ) ) == 0 )
375  {
376  pluginType = IO_MGR::PCAD;
377  }
378  else
379  {
380  pluginType = IO_MGR::KICAD_SEXP;
381  }
382 
383  return pluginType;
384 }
#define KICTL_EAGLE_BRD
chosen *.brd file is Eagle according to user.
Definition: kiway_player.h:139
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().