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 <string_utils.h>
#include <kiway.h>
#include <macros.h>
#include <pcb_edit_frame.h>
#include <pcb_group.h>
#include <pcbnew_settings.h>
#include <project.h>
#include <widgets/wx_html_report_panel.h>
#include <wx/log.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, bool *aUpdated)
 
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 449 of file dialog_exchange_footprints.cpp.

450{
451 std::vector<FP_TEXT*> candidates;
452
453 for( BOARD_ITEM* item : aFootprint->GraphicalItems() )
454 {
455 FP_TEXT* candidate = dyn_cast<FP_TEXT*>( item );
456
457 if( candidate && candidate->GetText() == aRefItem->GetText() )
458 candidates.push_back( candidate );
459 }
460
461 if( candidates.size() == 0 )
462 return nullptr;
463
464 if( candidates.size() == 1 )
465 return candidates[0];
466
467 // Try refining the match by layer
468 std::vector<FP_TEXT*> candidatesOnSameLayer;
469
470 for( FP_TEXT* candidate : candidates )
471 {
472 if( candidate->GetLayer() == aRefItem->GetLayer() )
473 candidatesOnSameLayer.push_back( candidate );
474 }
475
476 if( candidatesOnSameLayer.size() == 1 )
477 return candidatesOnSameLayer[0];
478
479 // Last ditch effort: refine by position
480 std::vector<FP_TEXT*> candidatesAtSamePos;
481
482 for( FP_TEXT* candidate : candidatesOnSameLayer.size() ? candidatesOnSameLayer : candidates )
483 {
484 if( candidate->GetPos0() == aRefItem->GetPos0() )
485 candidatesAtSamePos.push_back( candidate );
486 }
487
488 if( candidatesAtSamePos.size() > 0 )
489 return candidatesAtSamePos[0];
490 else if( candidatesOnSameLayer.size() > 0 )
491 return candidatesOnSameLayer[0];
492 else
493 return candidates[0];
494}
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:58
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
Definition: board_item.h:180
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:87
DRAWINGS & GraphicalItems()
Definition: footprint.h:173
const VECTOR2I & GetPos0() const
Definition: fp_text.h:124

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,
bool *  aUpdated 
)

Definition at line 407 of file dialog_exchange_footprints.cpp.

410{
411 if( resetText )
412 *aUpdated |= aSrc.GetText() != aDest.GetText();
413 else
414 aDest.SetText( aSrc.GetText() );
415
416 if( resetTextLayers )
417 {
418 *aUpdated |= aSrc.GetLayer() != aDest.GetLayer();
419 *aUpdated |= aSrc.IsVisible() != aDest.IsVisible();
420 }
421 else
422 {
423 aDest.SetLayer( aSrc.GetLayer() );
424 aDest.SetVisible( aSrc.IsVisible() );
425 }
426
427 if( resetTextEffects )
428 {
429 *aUpdated |= aSrc.GetHorizJustify() != aDest.GetHorizJustify();
430 *aUpdated |= aSrc.GetVertJustify() != aDest.GetVertJustify();
431 *aUpdated |= aSrc.GetTextSize() != aDest.GetTextSize();
432 *aUpdated |= aSrc.GetTextThickness() != aDest.GetTextThickness();
433 *aUpdated |= aSrc.GetTextAngle() != aDest.GetTextAngle();
434 *aUpdated |= aSrc.GetPos0() != aDest.GetPos0();
435 }
436 else
437 {
438 // Careful: the visible bit and position are also set by SetAttributes()
439 bool visible = aDest.IsVisible();
440 aDest.SetAttributes( aSrc );
441 aDest.SetVisible( visible );
442 aDest.SetPos0( aSrc.GetPos0() );
443 }
444
445 aDest.SetLocked( aSrc.IsLocked() );
446}
virtual void SetLocked(bool aLocked)
Definition: board_item.h:254
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
Definition: board_item.h:214
virtual bool IsLocked() const
Definition: board_item.cpp:71
const EDA_ANGLE & GetTextAngle() const
Definition: eda_text.h:120
void SetAttributes(const EDA_TEXT &aSrc)
Set the text attributes from another instance.
Definition: eda_text.cpp:264
virtual bool IsVisible() const
Definition: eda_text.h:136
GR_TEXT_H_ALIGN_T GetHorizJustify() const
Definition: eda_text.h:149
virtual void SetVisible(bool aVisible)
Definition: eda_text.cpp:217
GR_TEXT_V_ALIGN_T GetVertJustify() const
Definition: eda_text.h:152
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:163
int GetTextThickness() const
Definition: eda_text.h:112
VECTOR2I GetTextSize() const
Definition: eda_text.h:196
void SetPos0(const VECTOR2I &aPos)
Definition: fp_text.h:123

References EDA_TEXT::GetHorizJustify(), BOARD_ITEM::GetLayer(), FP_TEXT::GetPos0(), EDA_TEXT::GetText(), EDA_TEXT::GetTextAngle(), EDA_TEXT::GetTextSize(), EDA_TEXT::GetTextThickness(), EDA_TEXT::GetVertJustify(), BOARD_ITEM::IsLocked(), EDA_TEXT::IsVisible(), EDA_TEXT::SetAttributes(), BOARD_ITEM::SetLayer(), BOARD_ITEM::SetLocked(), FP_TEXT::SetPos0(), 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 }