KiCad PCB EDA Suite
dialog_exchange_footprints.cpp File Reference
#include <bitmaps.h>
#include <board_commit.h>
#include <board.h>
#include <footprint.h>
#include <dialog_exchange_footprints.h>
#include <kicad_string.h>
#include <kiway.h>
#include <macros.h>
#include <pcb_edit_frame.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 41 of file dialog_exchange_footprints.cpp.

◆ ID_MATCH_FP_ID

#define ID_MATCH_FP_ID   4204

Definition at line 45 of file dialog_exchange_footprints.cpp.

◆ ID_MATCH_FP_REF

#define ID_MATCH_FP_REF   4202

Definition at line 43 of file dialog_exchange_footprints.cpp.

◆ ID_MATCH_FP_SELECTED

#define ID_MATCH_FP_SELECTED   4201

Definition at line 42 of file dialog_exchange_footprints.cpp.

◆ ID_MATCH_FP_VAL

#define ID_MATCH_FP_VAL   4203

Definition at line 44 of file dialog_exchange_footprints.cpp.

Function Documentation

◆ getMatchingTextItem()

FP_TEXT* getMatchingTextItem ( FP_TEXT aRefItem,
FOOTPRINT aFootprint 
)

Definition at line 435 of file dialog_exchange_footprints.cpp.

436 {
437  std::vector<FP_TEXT*> candidates;
438 
439  for( BOARD_ITEM* item : aFootprint->GraphicalItems() )
440  {
441  FP_TEXT* candidate = dyn_cast<FP_TEXT*>( item );
442 
443  if( candidate && candidate->GetText() == aRefItem->GetText() )
444  candidates.push_back( candidate );
445  }
446 
447  if( candidates.size() == 0 )
448  return nullptr;
449 
450  if( candidates.size() == 1 )
451  return candidates[0];
452 
453  // Try refining the match by layer
454  std::vector<FP_TEXT*> candidatesOnSameLayer;
455 
456  for( FP_TEXT* candidate : candidates )
457  {
458  if( candidate->GetLayer() == aRefItem->GetLayer() )
459  candidatesOnSameLayer.push_back( candidate );
460  }
461 
462  if( candidatesOnSameLayer.size() == 1 )
463  return candidatesOnSameLayer[0];
464 
465  // Last ditch effort: refine by position
466  std::vector<FP_TEXT*> candidatesAtSamePos;
467 
468  for( FP_TEXT* candidate : candidatesOnSameLayer.size() ? candidatesOnSameLayer : candidates )
469  {
470  if( candidate->GetPos0() == aRefItem->GetPos0() )
471  candidatesAtSamePos.push_back( candidate );
472  }
473 
474  if( candidatesAtSamePos.size() > 0 )
475  return candidatesAtSamePos[0];
476  else if( candidatesOnSameLayer.size() > 0 )
477  return candidatesOnSameLayer[0];
478  else
479  return candidates[0];
480 }
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:82
DRAWINGS & GraphicalItems()
Definition: footprint.h:167
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:173
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 411 of file dialog_exchange_footprints.cpp.

413 {
414  if( !resetText )
415  aDest.SetText( aSrc.GetText() );
416 
417  if( !resetTextLayers )
418  {
419  aDest.SetLayer( aSrc.GetLayer() );
420  aDest.SetVisible( aSrc.IsVisible() );
421  }
422 
423  if( !resetTextEffects )
424  {
425  // Careful: the visible bit is also in Effects
426  bool visible = aDest.IsVisible();
427  aDest.SetEffects( aSrc );
428  aDest.SetVisible( visible );
429  }
430 
431  aDest.SetLocked( aSrc.IsLocked() );
432 }
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
Definition: board_item.h:194
bool IsVisible() const
Definition: eda_text.h:193
void SetVisible(bool aVisible)
Definition: eda_text.h:192
virtual void SetLocked(bool aLocked)
Modify the 'lock' status for of the item.
Definition: board_item.h:257
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:121
void SetEffects(const FP_TEXT &aSrc)
Set the text effects from another instance.
Definition: fp_text.h:146
virtual bool IsLocked() const
Definition: board_item.h:249
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
Definition: board_item.h:173
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 }