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 <class_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 <wxPcbStruct.h>
#include <pcb_draw_panel_gal.h>
#include <connectivity.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.

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)
 
static bool setOrigin (KIGFX::VIEW *aView, PCB_BASE_FRAME *aFrame, KIGFX::ORIGIN_VIEWITEM *aItem, const VECTOR2D &aPoint)
 
static bool deleteItem (TOOL_MANAGER *aToolMgr, const VECTOR2D &aPosition)
 

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

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

Definition at line 698 of file pcbnew_control.cpp.

References SELECTION::Empty(), SELECTION::Front(), TOOL_MANAGER::GetEditFrame(), SELECTION_TOOL::GetSelection(), TOOL_MANAGER::GetTool(), IsOK(), PCB_MODULE_T, PCB_ACTIONS::remove, TOOL_MANAGER::RunAction(), SELECTION_TOOL::SanitizeSelection(), PCB_ACTIONS::selectionClear, PCB_ACTIONS::selectionCursor, and EDA_ITEM::Type().

Referenced by PCBNEW_CONTROL::DeleteItemCursor().

699 {
700  SELECTION_TOOL* selectionTool = aToolMgr->GetTool<SELECTION_TOOL>();
701  assert( selectionTool );
702 
703  aToolMgr->RunAction( PCB_ACTIONS::selectionClear, true );
704  aToolMgr->RunAction( PCB_ACTIONS::selectionCursor, true );
705  selectionTool->SanitizeSelection();
706 
707  const SELECTION& selection = selectionTool->GetSelection();
708 
709  if( selection.Empty() )
710  return true;
711 
712  bool canBeRemoved = ( selection.Front()->Type() != PCB_MODULE_T );
713 
714  if( canBeRemoved || IsOK( aToolMgr->GetEditFrame(), _( "Are you sure you want to delete item?" ) ) )
715  aToolMgr->RunAction( PCB_ACTIONS::remove, true );
716  else
717  aToolMgr->RunAction( PCB_ACTIONS::selectionClear, true );
718 
719  return true;
720 }
static TOOL_ACTION selectionClear
Clears the current selection.
Definition: pcb_actions.h:53
KICAD_T Type() const
Function Type()
Definition: base_struct.h:212
bool Empty() const
Checks if there is anything selected.
Definition: selection.h:106
Class SELECTION_TOOL.
wxWindow * GetEditFrame() const
Definition: tool_manager.h:267
EDA_ITEM * Front() const
Definition: selection.h:144
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:125
class MODULE, a footprint
Definition: typeinfo.h:101
SELECTION & GetSelection()
Function GetSelection()
static TOOL_ACTION remove
Deleting a BOARD_ITEM.
Definition: pcb_actions.h:123
bool SanitizeSelection()
Makes sure a group selection does not contain items that would cause conflicts when moving/rotating t...
bool IsOK(wxWindow *aParent, const wxString &aMessage)
Function IsOK displays a yes/no dialog with aMessage and returns the user response.
Definition: confirm.cpp:129
static TOOL_ACTION selectionCursor
Select a single item under the cursor position.
Definition: pcb_actions.h:50
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:53
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:51
S-expression Pcbnew file format.
Definition: io_mgr.h:54
static const wxString GetFileExtension(PCB_FILE_T aFileType)
Function GetFileExtension returns the file extension for aFileType.
Definition: io_mgr.cpp:167
static bool setOrigin ( KIGFX::VIEW aView,
PCB_BASE_FRAME aFrame,
KIGFX::ORIGIN_VIEWITEM aItem,
const VECTOR2D aPoint 
)
static

Definition at line 611 of file pcbnew_control.cpp.

References KIGFX::VIEW::GetGAL(), KIGFX::VIEW::MarkDirty(), PCB_BASE_FRAME::SetGridOrigin(), KIGFX::GAL::SetGridOrigin(), KIGFX::ORIGIN_VIEWITEM::SetPosition(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by PCBNEW_CONTROL::GridSetOrigin().

613 {
614  aFrame->SetGridOrigin( wxPoint( aPoint.x, aPoint.y ) );
615  aView->GetGAL()->SetGridOrigin( aPoint );
616  aItem->SetPosition( aPoint );
617  aView->MarkDirty();
618 
619  return true;
620 }
void SetGridOrigin(const wxPoint &aPoint) override
void SetGridOrigin(const VECTOR2D &aGridOrigin)
Set the origin point for the grid.
GAL * GetGAL() const
Function GetGAL() Returns the GAL this view is using to draw graphical primitives.
Definition: view.h:177
void SetPosition(const VECTOR2D &aPosition)
void MarkDirty()
Function MarkDirty() Forces redraw of view on the next rendering.
Definition: view.h:594