KiCad PCB EDA Suite
dialog_exchange_footprints.cpp File Reference
#include <bitmaps.h>
#include <board_commit.h>
#include <board.h>
#include <footprint.h>
#include <pad.h>
#include <dialog_exchange_footprints.h>
#include <kicad_string.h>
#include <kiway.h>
#include <macros.h>
#include <pcb_edit_frame.h>
#include <pcb_group.h>
#include <pcbnew_settings.h>
#include <project.h>
#include <wx_html_report_panel.h>

Go to the source code of this file.

Macros

#define ID_MATCH_FP_ALL   4200
 
#define ID_MATCH_FP_SELECTED   4201
 
#define ID_MATCH_FP_REF   4202
 
#define ID_MATCH_FP_VAL   4203
 
#define ID_MATCH_FP_ID   4204
 

Functions

void processTextItem (const FP_TEXT &aSrc, FP_TEXT &aDest, bool resetText, bool resetTextLayers, bool resetTextEffects)
 
FP_TEXTgetMatchingTextItem (FP_TEXT *aRefItem, FOOTPRINT *aFootprint)
 

Variables

int g_matchModeForUpdate = ID_MATCH_FP_ALL
 
int g_matchModeForUpdateSelected = ID_MATCH_FP_SELECTED
 
int g_matchModeForExchange = ID_MATCH_FP_REF
 
int g_matchModeForExchangeSelected = ID_MATCH_FP_SELECTED
 
bool g_removeExtraTextItems [2] = { false, false }
 
bool g_resetTextItemLayers [2] = { false, true }
 
bool g_resetTextItemEffects [2] = { false, true }
 
bool g_resetFabricationAttrs [2] = { false, true }
 
bool g_reset3DModels [2] = { true, true }
 

Macro Definition Documentation

◆ ID_MATCH_FP_ALL

#define ID_MATCH_FP_ALL   4200

Definition at line 43 of file dialog_exchange_footprints.cpp.

◆ ID_MATCH_FP_ID

#define ID_MATCH_FP_ID   4204

Definition at line 47 of file dialog_exchange_footprints.cpp.

◆ ID_MATCH_FP_REF

#define ID_MATCH_FP_REF   4202

Definition at line 45 of file dialog_exchange_footprints.cpp.

◆ ID_MATCH_FP_SELECTED

#define ID_MATCH_FP_SELECTED   4201

Definition at line 44 of file dialog_exchange_footprints.cpp.

◆ ID_MATCH_FP_VAL

#define ID_MATCH_FP_VAL   4203

Definition at line 46 of file dialog_exchange_footprints.cpp.

Function Documentation

◆ getMatchingTextItem()

FP_TEXT* getMatchingTextItem ( FP_TEXT aRefItem,
FOOTPRINT aFootprint 
)

Definition at line 437 of file dialog_exchange_footprints.cpp.

438 {
439  std::vector<FP_TEXT*> candidates;
440 
441  for( BOARD_ITEM* item : aFootprint->GraphicalItems() )
442  {
443  FP_TEXT* candidate = dyn_cast<FP_TEXT*>( item );
444 
445  if( candidate && candidate->GetText() == aRefItem->GetText() )
446  candidates.push_back( candidate );
447  }
448 
449  if( candidates.size() == 0 )
450  return nullptr;
451 
452  if( candidates.size() == 1 )
453  return candidates[0];
454 
455  // Try refining the match by layer
456  std::vector<FP_TEXT*> candidatesOnSameLayer;
457 
458  for( FP_TEXT* candidate : candidates )
459  {
460  if( candidate->GetLayer() == aRefItem->GetLayer() )
461  candidatesOnSameLayer.push_back( candidate );
462  }
463 
464  if( candidatesOnSameLayer.size() == 1 )
465  return candidatesOnSameLayer[0];
466 
467  // Last ditch effort: refine by position
468  std::vector<FP_TEXT*> candidatesAtSamePos;
469 
470  for( FP_TEXT* candidate : candidatesOnSameLayer.size() ? candidatesOnSameLayer : candidates )
471  {
472  if( candidate->GetPos0() == aRefItem->GetPos0() )
473  candidatesAtSamePos.push_back( candidate );
474  }
475 
476  if( candidatesAtSamePos.size() > 0 )
477  return candidatesAtSamePos[0];
478  else if( candidatesOnSameLayer.size() > 0 )
479  return candidatesOnSameLayer[0];
480  else
481  return candidates[0];
482 }
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:80
DRAWINGS & GraphicalItems()
Definition: footprint.h:162
const wxPoint & GetPos0() const
Definition: fp_text.h:166
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
Definition: board_item.h:171
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:133

References BOARD_ITEM::GetLayer(), FP_TEXT::GetPos0(), EDA_TEXT::GetText(), and FOOTPRINT::GraphicalItems().

Referenced by PCB_EDIT_FRAME::ExchangeFootprint().

◆ processTextItem()

void processTextItem ( const FP_TEXT aSrc,
FP_TEXT aDest,
bool  resetText,
bool  resetTextLayers,
bool  resetTextEffects 
)

Definition at line 413 of file dialog_exchange_footprints.cpp.

415 {
416  if( !resetText )
417  aDest.SetText( aSrc.GetText() );
418 
419  if( !resetTextLayers )
420  {
421  aDest.SetLayer( aSrc.GetLayer() );
422  aDest.SetVisible( aSrc.IsVisible() );
423  }
424 
425  if( !resetTextEffects )
426  {
427  // Careful: the visible bit is also in Effects
428  bool visible = aDest.IsVisible();
429  aDest.SetEffects( aSrc );
430  aDest.SetVisible( visible );
431  }
432 
433  aDest.SetLocked( aSrc.IsLocked() );
434 }
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
Definition: board_item.h:192
virtual void SetLocked(bool aLocked)
Modify the 'lock' status for of the item.
Definition: board_item.h:252
virtual bool IsLocked() const
Definition: board_item.cpp:65
virtual void SetVisible(bool aVisible)
Definition: eda_text.h:185
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:114
virtual bool IsVisible() const
Definition: eda_text.h:186
void SetEffects(const FP_TEXT &aSrc)
Set the text effects from another instance.
Definition: fp_text.h:146
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
Definition: board_item.h:171
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:133

References BOARD_ITEM::GetLayer(), EDA_TEXT::GetText(), BOARD_ITEM::IsLocked(), EDA_TEXT::IsVisible(), FP_TEXT::SetEffects(), BOARD_ITEM::SetLayer(), BOARD_ITEM::SetLocked(), EDA_TEXT::SetText(), and EDA_TEXT::SetVisible().

Referenced by PCB_EDIT_FRAME::ExchangeFootprint().

Variable Documentation

◆ g_matchModeForExchange

int g_matchModeForExchange = ID_MATCH_FP_REF

◆ g_matchModeForExchangeSelected

int g_matchModeForExchangeSelected = ID_MATCH_FP_SELECTED

◆ g_matchModeForUpdate

int g_matchModeForUpdate = ID_MATCH_FP_ALL

◆ g_matchModeForUpdateSelected

int g_matchModeForUpdateSelected = ID_MATCH_FP_SELECTED

◆ g_removeExtraTextItems

bool g_removeExtraTextItems[2] = { false, false }

◆ g_reset3DModels

◆ g_resetFabricationAttrs

bool g_resetFabricationAttrs[2] = { false, true }

◆ g_resetTextItemEffects

bool g_resetTextItemEffects[2] = { false, true }

◆ g_resetTextItemLayers

bool g_resetTextItemLayers[2] = { false, true }