KiCad PCB EDA Suite
pcb_control.cpp File Reference
#include "edit_tool.h"
#include <pgm_base.h>
#include "pcb_actions.h"
#include "pcb_control.h"
#include "pcb_picker_tool.h"
#include "pcb_selection_tool.h"
#include "board_reannotate_tool.h"
#include <3d_viewer/eda_3d_viewer_frame.h>
#include <bitmaps.h>
#include <board_commit.h>
#include <board.h>
#include <board_design_settings.h>
#include <board_item.h>
#include <dialogs/dialog_paste_special.h>
#include <pcb_dimension.h>
#include <footprint.h>
#include <pcb_group.h>
#include <pcb_track.h>
#include <zone.h>
#include <fp_shape.h>
#include <confirm.h>
#include <connectivity/connectivity_data.h>
#include <core/kicad_algo.h>
#include <kicad_clipboard.h>
#include <origin_viewitem.h>
#include <pcb_edit_frame.h>
#include <pcb_painter.h>
#include <properties.h>
#include <settings/color_settings.h>
#include <tool/tool_manager.h>
#include <footprint_viewer_frame.h>
#include <footprint_edit_frame.h>
#include <widgets/wx_progress_reporters.h>
#include <widgets/infobar.h>
#include <wx/hyperlink.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 (PCB_EDIT_FRAME *aParent, int *aCtl, wxString *aFileName, bool aKicadFilesOnly=false)
 Show 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 void pasteFootprintItemsToFootprintEditor (FOOTPRINT *aClipFootprint, BOARD *aBoard, std::vector< BOARD_ITEM * > &aPastedItems)
 
template<typename T >
static void moveUnflaggedItems (std::deque< T > &aList, std::vector< BOARD_ITEM * > &aTarget, bool aIsNew)
 
static void moveUnflaggedItems (ZONES &aList, std::vector< BOARD_ITEM * > &aTarget, bool aIsNew)
 

Macro Definition Documentation

◆ ALPHA_MAX

#define ALPHA_MAX   1.00

Definition at line 436 of file pcb_control.cpp.

◆ ALPHA_MIN

#define ALPHA_MIN   0.20

Definition at line 435 of file pcb_control.cpp.

◆ ALPHA_STEP

#define ALPHA_STEP   0.05

Definition at line 437 of file pcb_control.cpp.

◆ HITTEST_THRESHOLD_PIXELS

#define HITTEST_THRESHOLD_PIXELS   5

Definition at line 558 of file pcb_control.cpp.

Function Documentation

◆ AskLoadBoardFileName()

bool AskLoadBoardFileName ( PCB_EDIT_FRAME aParent,
int *  aCtl,
wxString *  aFileName,
bool  aKicadFilesOnly 
)

Show 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 KiCad pcb files plugins only, false to list import plugins.
Returns
true if chosen, else false if user aborted.Helper widget to select whether a new project should be created for a file when saving

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

References _, AddFileExtListToFilter(), IO_MGR::ALTIUM_CIRCUIT_MAKER, IO_MGR::ALTIUM_CIRCUIT_STUDIO, IO_MGR::ALTIUM_DESIGNER, AltiumCircuitMakerPcbFileWildcard(), AltiumCircuitStudioPcbFileWildcard(), AltiumDesignerPcbFileWildcard(), arrayDim(), IO_MGR::CADSTAR_PCB_ARCHIVE, CadstarPcbArchiveFileWildcard(), IO_MGR::EAGLE, EaglePcbFileWildcard(), IO_MGR::FABMASTER, FabmasterPcbFileWildcard(), filter, formatWildcardExt(), PATHS::GetDefaultUserProjectsPath(), EDA_BASE_FRAME::GetMruPath(), IO_MGR::KICAD_SEXP, KICTL_EAGLE_BRD, IO_MGR::LEGACY, LegacyPcbFileWildcard(), name, path, IO_MGR::PCAD, PCadPcbFileWildcard(), PcbFileWildcard(), IO_MGR::PluginFind(), and EDA_BASE_FRAME::SetMruPath().

Referenced by PCB_CONTROL::AppendBoardFromFile(), PCB_EDIT_FRAME::Files_io_from_id(), and PCB_EDIT_FRAME::OnFileHistory().

◆ Flip()

template<class T >
void Flip ( T &  aValue)

Definition at line 120 of file pcb_control.cpp.

121 {
122  aValue = !aValue;
123 }

Referenced by PCB_CONTROL::ToggleRatsnest(), PCB_CONTROL::TrackDisplayMode(), and PCB_CONTROL::ViaDisplayMode().

◆ moveUnflaggedItems() [1/2]

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

Definition at line 890 of file pcb_control.cpp.

892 {
893  std::copy_if( aList.begin(), aList.end(), std::back_inserter( aTarget ),
894  [aIsNew]( T aItem )
895  {
896  bool doCopy = ( aItem->GetFlags() & SKIP_STRUCT ) == 0;
897 
898  aItem->ClearFlags( SKIP_STRUCT );
899  aItem->SetFlags( aIsNew ? IS_NEW : 0 );
900 
901  return doCopy;
902  } );
903 
904  if( aIsNew )
905  aList.clear();
906 }
#define IS_NEW
New item, just created.
#define SKIP_STRUCT
flag indicating that the structure should be ignored

References IS_NEW, and SKIP_STRUCT.

Referenced by PCB_CONTROL::placeBoardItems().

◆ moveUnflaggedItems() [2/2]

static void moveUnflaggedItems ( ZONES aList,
std::vector< BOARD_ITEM * > &  aTarget,
bool  aIsNew 
)
static

Definition at line 909 of file pcb_control.cpp.

910 {
911  if( aList.size() == 0 )
912  return;
913 
914  auto obj = aList.front();
915  int idx = 0;
916 
917  if( aIsNew )
918  {
919  obj = aList.back();
920  aList.pop_back();
921  }
922 
923  for( ; obj ; )
924  {
925  if( obj->HasFlag( SKIP_STRUCT ) )
926  obj->ClearFlags( SKIP_STRUCT );
927  else
928  aTarget.push_back( obj );
929 
930  if( aIsNew )
931  {
932  if( aList.size() )
933  {
934  obj = aList.back();
935  aList.pop_back();
936  }
937  else
938  {
939  obj = nullptr;
940  }
941  }
942  else
943  {
944  obj = idx < int(aList.size()-1) ? aList[++idx] : nullptr;
945  }
946  }
947 }
#define SKIP_STRUCT
flag indicating that the structure should be ignored

References SKIP_STRUCT.

◆ pasteFootprintItemsToFootprintEditor()

static void pasteFootprintItemsToFootprintEditor ( FOOTPRINT aClipFootprint,
BOARD aBoard,
std::vector< BOARD_ITEM * > &  aPastedItems 
)
static

Definition at line 661 of file pcb_control.cpp.

663 {
664  FOOTPRINT* editorFootprint = aBoard->GetFirstFootprint();
665 
666  aClipFootprint->SetParent( aBoard );
667 
668  for( PAD* pad : aClipFootprint->Pads() )
669  {
670  pad->SetParent( editorFootprint );
671  aPastedItems.push_back( pad );
672  }
673 
674  aClipFootprint->Pads().clear();
675 
676  // Not all graphic items can be added to the current footprint:
677  // Reference and value are already existing in the current footprint, and
678  // must be unique.
679  // So they will be skipped
680  for( BOARD_ITEM* item : aClipFootprint->GraphicalItems() )
681  {
682  if( item->Type() == PCB_FP_SHAPE_T )
683  {
684  FP_SHAPE* shape = static_cast<FP_SHAPE*>( item );
685 
686  shape->SetParent( nullptr );
687  shape->SetLocalCoord();
688  }
689  else if( item->Type() == PCB_FP_TEXT_T )
690  {
691  FP_TEXT* text = static_cast<FP_TEXT*>( item );
692 
693  if( text->GetType() != FP_TEXT::TEXT_is_DIVERS )
694  continue;
695 
696  text->SetTextAngle( text->GetTextAngle() + aClipFootprint->GetOrientation() );
697 
698  text->SetParent( nullptr );
699  text->SetLocalCoord();
700  }
701 
702  item->SetParent( editorFootprint );
703  aPastedItems.push_back( item );
704  }
705 
706  aClipFootprint->GraphicalItems().clear();
707 
708  for( FP_ZONE* zone : aClipFootprint->Zones() )
709  {
710  zone->SetParent( editorFootprint );
711  aPastedItems.push_back( zone );
712  }
713 
714  aClipFootprint->Zones().clear();
715 
716  for( PCB_GROUP* group : aClipFootprint->Groups() )
717  {
718  group->SetParent( editorFootprint );
719  aPastedItems.push_back( group );
720  }
721 
722  aClipFootprint->Groups().clear();
723 }
class FP_TEXT, text in a footprint
Definition: typeinfo.h:92
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:49
A set of BOARD_ITEMs (i.e., without duplicates).
Definition: pcb_group.h:50
double GetOrientation() const
Definition: footprint.h:190
class FP_SHAPE, a footprint edge
Definition: typeinfo.h:93
virtual void SetParent(EDA_ITEM *aParent)
Definition: eda_item.h:116
PADS & Pads()
Definition: footprint.h:168
FP_ZONES & Zones()
Definition: footprint.h:174
FOOTPRINT * GetFirstFootprint() const
Get the first footprint on the board or nullptr.
Definition: board.h:317
DRAWINGS & GraphicalItems()
Definition: footprint.h:171
FP_GROUPS & Groups()
Definition: footprint.h:177
void SetLocalCoord()
Set relative coordinates from draw coordinates.
Definition: fp_shape.cpp:52
Definition: pad.h:57
A specialization of ZONE for use in footprints.
Definition: zone.h:946

References BOARD::GetFirstFootprint(), FOOTPRINT::GetOrientation(), FOOTPRINT::GraphicalItems(), group, FOOTPRINT::Groups(), pad, FOOTPRINT::Pads(), PCB_FP_SHAPE_T, PCB_FP_TEXT_T, FP_SHAPE::SetLocalCoord(), EDA_ITEM::SetParent(), text, FP_TEXT::TEXT_is_DIVERS, and FOOTPRINT::Zones().

Referenced by PCB_CONTROL::Paste().

◆ plugin_type()

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

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

466 {
467  IO_MGR::PCB_FILE_T pluginType;
468 
469  wxFileName fn = aFileName;
470 
471  // Note: file extensions are expected to be in lower case.
472  // This is not always true, especially when importing files, so the string
473  // comparisons are case insensitive to try to find the suitable plugin.
474 
475  if( fn.GetExt().CmpNoCase( IO_MGR::GetFileExtension( IO_MGR::LEGACY ) ) == 0 )
476  {
477  // both legacy and eagle share a common file extension.
478  pluginType = ( aCtl & KICTL_EAGLE_BRD ) ? IO_MGR::EAGLE : IO_MGR::LEGACY;
479  }
480  else if( fn.GetExt().CmpNoCase( IO_MGR::GetFileExtension( IO_MGR::PCAD ) ) == 0 )
481  {
482  pluginType = IO_MGR::PCAD;
483  }
484  else if( fn.GetExt().CmpNoCase( IO_MGR::GetFileExtension( IO_MGR::ALTIUM_DESIGNER ) ) == 0 )
485  {
486  pluginType = IO_MGR::ALTIUM_DESIGNER;
487  }
488  else if( fn.GetExt().CmpNoCase( IO_MGR::GetFileExtension( IO_MGR::ALTIUM_CIRCUIT_STUDIO ) ) == 0 )
489  {
490  pluginType = IO_MGR::ALTIUM_CIRCUIT_STUDIO;
491  }
492  else if( fn.GetExt().CmpNoCase( IO_MGR::GetFileExtension( IO_MGR::ALTIUM_CIRCUIT_MAKER ) ) == 0 )
493  {
494  pluginType = IO_MGR::ALTIUM_CIRCUIT_MAKER;
495  }
496  else if( fn.GetExt().CmpNoCase( IO_MGR::GetFileExtension( IO_MGR::CADSTAR_PCB_ARCHIVE ) ) == 0 )
497  {
498  pluginType = IO_MGR::CADSTAR_PCB_ARCHIVE;
499  }
500  else if( fn.GetExt().CmpNoCase( IO_MGR::GetFileExtension( IO_MGR::FABMASTER ) ) == 0 )
501  {
502  pluginType = IO_MGR::FABMASTER;
503  }
504  else
505  {
506  pluginType = IO_MGR::KICAD_SEXP;
507  }
508 
509  return pluginType;
510 }
#define KICTL_EAGLE_BRD
chosen *.brd file is Eagle according to user.
Definition: kiway_player.h:81
Legacy Pcbnew file formats prior to s-expression.
Definition: io_mgr.h:55
PCB_FILE_T
The set of file types that the IO_MGR knows about, and for which there has been a plugin written.
Definition: io_mgr.h:53
S-expression Pcbnew file format.
Definition: io_mgr.h:56
static const wxString GetFileExtension(PCB_FILE_T aFileType)
Return the file extension for aFileType.
Definition: io_mgr.cpp:109

References IO_MGR::ALTIUM_CIRCUIT_MAKER, IO_MGR::ALTIUM_CIRCUIT_STUDIO, IO_MGR::ALTIUM_DESIGNER, IO_MGR::CADSTAR_PCB_ARCHIVE, IO_MGR::EAGLE, IO_MGR::FABMASTER, IO_MGR::GetFileExtension(), IO_MGR::KICAD_SEXP, KICTL_EAGLE_BRD, IO_MGR::LEGACY, and IO_MGR::PCAD.

Referenced by PCB_CONTROL::AppendBoardFromFile(), and PCB_EDIT_FRAME::OpenProjectFiles().