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_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

#define ALPHA_MAX   1.00

Definition at line 521 of file pcbnew_control.cpp.

Referenced by PCBNEW_CONTROL::LayerAlphaInc().

#define ALPHA_MIN   0.20

Definition at line 520 of file pcbnew_control.cpp.

Referenced by PCBNEW_CONTROL::LayerAlphaDec().

#define ALPHA_STEP   0.05

Function Documentation

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

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

87 {
88  // This is a subset of all PLUGINs which are trusted to be able to
89  // load a BOARD. User may occasionally use the wrong plugin to load a
90  // *.brd file (since both legacy and eagle use *.brd extension),
91  // but eventually *.kicad_pcb will be more common than legacy *.brd files.
92  static const struct
93  {
94  const wxString& filter;
95  IO_MGR::PCB_FILE_T pluginType;
96  } loaders[] =
97  {
98  { PcbFileWildcard(), IO_MGR::KICAD_SEXP }, // Current Kicad board files
99  { LegacyPcbFileWildcard(), IO_MGR::LEGACY }, // Old Kicad board files
100  { EaglePcbFileWildcard(), IO_MGR::EAGLE }, // Import board files
101  { PCadPcbFileWildcard(), IO_MGR::PCAD }, // Import board files
102  };
103 
104  wxFileName fileName( *aFileName );
105  wxString fileFilters;
106 
107  if( aKicadFilesOnly )
108  {
109  for( unsigned ii = 0; ii < 2; ++ii )
110  {
111  if( !fileFilters.IsEmpty() )
112  fileFilters += wxChar( '|' );
113 
114  fileFilters += wxGetTranslation( loaders[ii].filter );
115  }
116  }
117  else
118  {
119  for( unsigned ii = 2; ii < DIM( loaders ); ++ii )
120  {
121  if( !fileFilters.IsEmpty() )
122  fileFilters += wxChar( '|' );
123 
124  fileFilters += wxGetTranslation( loaders[ii].filter );
125  }
126  }
127 
128  wxString path;
129  wxString name;
130 
131  if( fileName.FileExists() )
132  {
133  path = fileName.GetPath();
134  name = fileName.GetFullName();
135  }
136  else
137  {
138  path = wxStandardPaths::Get().GetDocumentsDir();
139  // leave name empty
140  }
141 
142  wxFileDialog dlg( aParent,
143  aKicadFilesOnly ? _( "Open Board File" ) : _( "Import Non KiCad Board File" ),
144  path, name, fileFilters,
145  wxFD_OPEN | wxFD_FILE_MUST_EXIST );
146 
147  if( dlg.ShowModal() == wxID_OK )
148  {
149  // For import option, if Eagle (*.brd files), tell OpenProjectFiles() to use Eagle plugin.
150  // It's the only special case because of the duplicate use of the *.brd file extension.
151  // Other cases are clear because of unique file extensions.
152  *aCtl = aKicadFilesOnly ? 0 : KICTL_EAGLE_BRD;
153  *aFileName = dlg.GetPath();
154  return true;
155  }
156  else
157  return false;
158 }
#define DIM(x)
of elements in an array
Definition: macros.h:98
wxString EaglePcbFileWildcard()
#define KICTL_EAGLE_BRD
chosen *.brd file is Eagle according to user.
Definition: kiway_player.h:130
wxString LegacyPcbFileWildcard()
static const struct @6 fileFilters[FILTER_COUNT]
Legacy Pcbnew file formats prior to s-expression.
Definition: io_mgr.h:54
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:52
wxString PCadPcbFileWildcard()
S-expression Pcbnew file format.
Definition: io_mgr.h:55
static bool deleteItem ( TOOL_MANAGER aToolMgr,
const VECTOR2D aPosition 
)
static

Definition at line 794 of file pcbnew_control.cpp.

References SELECTION::Empty(), SELECTION_TOOL::GetSelection(), TOOL_MANAGER::GetTool(), PCB_ACTIONS::remove, TOOL_MANAGER::RunAction(), SELECTION_TOOL::SanitizeSelection(), PCB_TOOL::selection(), PCB_ACTIONS::selectionClear, and PCB_ACTIONS::selectionCursor.

Referenced by PCBNEW_CONTROL::DeleteItemCursor().

795 {
796  SELECTION_TOOL* selectionTool = aToolMgr->GetTool<SELECTION_TOOL>();
797  wxCHECK( selectionTool, false );
798 
799  aToolMgr->RunAction( PCB_ACTIONS::selectionClear, true );
800  aToolMgr->RunAction( PCB_ACTIONS::selectionCursor, true );
801  selectionTool->SanitizeSelection();
802 
803  const SELECTION& selection = selectionTool->GetSelection();
804 
805  if( selection.Empty() )
806  return true;
807 
808  aToolMgr->RunAction( PCB_ACTIONS::remove, true );
809 
810  return true;
811 }
static TOOL_ACTION selectionClear
Clears the current selection.
Definition: pcb_actions.h:53
bool Empty() const
Checks if there is anything selected.
Definition: selection.h:109
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
SELECTION & GetSelection()
Function GetSelection()
static TOOL_ACTION remove
Deleting a BOARD_ITEM.
Definition: pcb_actions.h:129
bool SanitizeSelection()
Makes sure a group selection does not contain items that would cause conflicts when moving/rotating t...
static TOOL_ACTION selectionCursor
Select a single item under the cursor position.
Definition: pcb_actions.h:50
template<typename T >
static void moveNoFlagToVector ( DLIST< T > &  aList,
std::vector< BOARD_ITEM * > &  aTarget,
bool  aIsNew 
)
static

Definition at line 937 of file pcbnew_control.cpp.

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

Referenced by PCBNEW_CONTROL::placeBoardItems().

938 {
939  for( auto obj = aIsNew ? aList.PopFront() : aList.GetFirst(); obj;
940  obj = aIsNew ? aList.PopFront() : obj->Next() )
941  {
942  if( obj->GetFlags() & FLAG0 )
943  obj->ClearFlags( FLAG0 );
944  else
945  aTarget.push_back( obj );
946  }
947 }
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:127
T * PopFront()
Definition: dlist.h:221
static void moveNoFlagToVector ( ZONE_CONTAINERS &  aList,
std::vector< BOARD_ITEM * > &  aTarget,
bool  aIsNew 
)
static

Definition at line 949 of file pcbnew_control.cpp.

References FLAG0.

950 {
951  if( aList.size() == 0 )
952  return;
953 
954  auto obj = aList.front();
955  int idx = 0;
956 
957  if( aIsNew )
958  {
959  obj = aList.back();
960  aList.pop_back();
961  }
962 
963  for( ; obj ; )
964  {
965  if( obj->GetFlags() & FLAG0 )
966  obj->ClearFlags( FLAG0 );
967  else
968  aTarget.push_back( obj );
969 
970  if( aIsNew )
971  {
972  if( aList.size() )
973  {
974  obj = aList.back();
975  aList.pop_back();
976  }
977  else
978  obj = nullptr;
979  }
980  else
981  obj = idx < int(aList.size()-1) ? aList[++idx] : nullptr;
982  }
983 }
#define FLAG0
Pcbnew: flag used in local computations.
Definition: base_struct.h:127
IO_MGR::PCB_FILE_T plugin_type ( const wxString &  aFileName,
int  aCtl 
)

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

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

375 {
376  IO_MGR::PCB_FILE_T pluginType;
377 
378  wxFileName fn = aFileName;
379 
380  // Note: file extensions are expected to be in ower case.
381  // This is not always true, especially when importing files, so the string
382  // comparisons are case insensitive to try to find the suitable plugin.
383 
384  if( fn.GetExt().CmpNoCase( IO_MGR::GetFileExtension( IO_MGR::LEGACY ) ) == 0 )
385  {
386  // both legacy and eagle share a common file extension.
387  pluginType = ( aCtl & KICTL_EAGLE_BRD ) ? IO_MGR::EAGLE : IO_MGR::LEGACY;
388  }
389  else if( fn.GetExt().CmpNoCase( IO_MGR::GetFileExtension( IO_MGR::LEGACY ) + backupSuffix ) == 0 )
390  {
391  pluginType = IO_MGR::LEGACY;
392  }
393  else if( fn.GetExt().CmpNoCase( IO_MGR::GetFileExtension( IO_MGR::PCAD ) ) == 0 )
394  {
395  pluginType = IO_MGR::PCAD;
396  }
397  else
398  {
399  pluginType = IO_MGR::KICAD_SEXP;
400  }
401 
402  return pluginType;
403 }
#define KICTL_EAGLE_BRD
chosen *.brd file is Eagle according to user.
Definition: kiway_player.h:130
static const wxChar backupSuffix[]
Legacy Pcbnew file formats prior to s-expression.
Definition: io_mgr.h:54
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:52
S-expression Pcbnew file format.
Definition: io_mgr.h:55
static const wxString GetFileExtension(PCB_FILE_T aFileType)
Function GetFileExtension returns the file extension for aFileType.
Definition: io_mgr.cpp:109