KiCad PCB EDA Suite
pcbnew_control.cpp File Reference
#include <cstdint>
#include "pcbnew_control.h"
#include "pcb_actions.h"
#include "selection_tool.h"
#include "picker_tool.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 <pcbnew_id.h>
#include <wxPcbStruct.h>
#include <pcb_draw_panel_gal.h>
#include <ratsnest_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 <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 85 of file pcbnew/files.cpp.

References DIM, IO_MGR::EAGLE, EaglePcbFileWildcard, fileFilters, IO_MGR::KICAD, KICTL_EAGLE_BRD, IO_MGR::LEGACY, LegacyPcbFileWildcard, IO_MGR::PCAD, PCadPcbFileWildcard, and PcbFileWildcard.

Referenced by PCBNEW_CONTROL::AppendBoard(), PCB_EDIT_FRAME::Files_io_from_id(), and PCB_EDIT_FRAME::OnFileHistory().

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

Definition at line 737 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().

738 {
739  SELECTION_TOOL* selectionTool = aToolMgr->GetTool<SELECTION_TOOL>();
740  assert( selectionTool );
741 
742  aToolMgr->RunAction( PCB_ACTIONS::selectionClear, true );
743  aToolMgr->RunAction( PCB_ACTIONS::selectionCursor, true );
744  selectionTool->SanitizeSelection();
745 
746  const SELECTION& selection = selectionTool->GetSelection();
747 
748  if( selection.Empty() )
749  return true;
750 
751  bool canBeRemoved = ( selection.Front()->Type() != PCB_MODULE_T );
752 
753  if( canBeRemoved || IsOK( aToolMgr->GetEditFrame(), _( "Are you sure you want to delete item?" ) ) )
754  aToolMgr->RunAction( PCB_ACTIONS::remove, true );
755  else
756  aToolMgr->RunAction( PCB_ACTIONS::selectionClear, true );
757 
758  return true;
759 }
static TOOL_ACTION selectionClear
Clears the current selection.
Definition: pcb_actions.h:53
KICAD_T Type() const
Function Type()
Definition: base_struct.h:198
bool Empty() const
Checks if there is anything selected.
Definition: selection.h:106
Class SELECTION_TOOL.
wxWindow * GetEditFrame() const
Definition: tool_manager.h:258
EDA_ITEM * Front() const
Definition: selection.h:137
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:114
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:111
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 372 of file pcbnew/files.cpp.

References backupSuffix, IO_MGR::EAGLE, IO_MGR::GetFileExtension(), IO_MGR::KICAD, KICTL_EAGLE_BRD, IO_MGR::LEGACY, and IO_MGR::PCAD.

Referenced by PCBNEW_CONTROL::AppendBoard(), and PCB_EDIT_FRAME::OpenProjectFiles().

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

652 {
653  aFrame->SetGridOrigin( wxPoint( aPoint.x, aPoint.y ) );
654  aView->GetGAL()->SetGridOrigin( aPoint );
655  aItem->SetPosition( aPoint );
656  aView->MarkDirty();
657 
658  return true;
659 }
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:601