25#include <magic_enum.hpp>
29#include <unordered_set>
34#include <wx/tokenzr.h>
76#include <google/protobuf/any.pb.h>
77#include <api/board/board_types.pb.h>
99 void setter(
void* obj, wxAny& v )
override
103 if( !v.GetAs( &value ) )
109 wxString variantName;
114 if( !variantName.IsEmpty() )
125 footprint->
Add( newField );
133 wxAny
getter(
const void* obj )
const override
141 wxString variantName;
148 if( !variantName.IsEmpty() )
153 return wxAny(
text );
165 std::vector<wxString> padNumbers;
172 pad.Trim(
true ).Trim(
false );
175 padNumbers.push_back(
pad );
180 for( wxUniChar ch : aGroup )
187 else if( ch ==
'\\' )
299 std::map<EDA_ITEM*, EDA_ITEM*> ptrMap;
304 if( field->IsMandatory() )
306 PCB_FIELD* existingField = GetField( field->GetId() );
307 ptrMap[field] = existingField;
308 *existingField = *field;
311 existingField->SetUuidDirect( field->m_Uuid );
312 existingField->SetParent( this );
316 PCB_FIELD* newField = static_cast<PCB_FIELD*>( field->Clone() );
317 ptrMap[field] = newField;
323 for(
PAD*
pad : aFootprint.Pads() )
325 PAD* newPad = static_cast<PAD*>( pad->Clone() );
326 ptrMap[ pad ] = newPad;
327 Add( newPad, ADD_MODE::APPEND );
331 for(
ZONE* zone : aFootprint.Zones() )
333 ZONE* newZone = static_cast<ZONE*>( zone->Clone() );
334 ptrMap[ zone ] = newZone;
335 Add( newZone, ADD_MODE::APPEND );
341 newZone->SetNetCode( -1 );
345 for(
BOARD_ITEM* item : aFootprint.GraphicalItems() )
347 BOARD_ITEM* newItem = static_cast<BOARD_ITEM*>( item->Clone() );
348 ptrMap[ item ] = newItem;
349 Add( newItem, ADD_MODE::APPEND );
355 PCB_GROUP* newGroup = static_cast<PCB_GROUP*>( group->Clone() );
356 ptrMap[ group ] = newGroup;
357 Add( newGroup, ADD_MODE::APPEND );
365 for(
PCB_POINT* point : aFootprint.Points() )
367 PCB_POINT* newPoint = static_cast<PCB_POINT*>( point->Clone() );
368 ptrMap[ point ] = newPoint;
369 Add( newPoint, ADD_MODE::APPEND );
375 PCB_GROUP* newGroup = static_cast<PCB_GROUP*>( ptrMap[ group ] );
377 newGroup->GetItems().clear();
379 for( EDA_ITEM* member : group->GetItems() )
381 if( ptrMap.count( member ) )
382 newGroup->AddItem( ptrMap[ member ] );
396 *
this = std::move( aFootprint );
446 std::vector<PROPERTY_BASE*> props;
451 [&](
const wxString& aName )
457 auto prop = std::make_unique<PCB_FOOTPRINT_FIELD_PROPERTY>( aName );
461 return it->second.get();
466 if( !field->IsMandatory() )
469 if( !isFPedit && field->IsPrivate() )
472 const wxString&
name = field->GetUntranslatedName();
477 props.push_back( getOrCreate(
name ) );
480 std::vector<PCB_FIELD*> userFields;
484 if( field->IsMandatory() || ( !isFPedit && field->IsPrivate() ) )
487 userFields.push_back( field );
490 std::ranges::sort( userFields,
498 const wxString&
name = field->GetUntranslatedName();
499 props.push_back( getOrCreate(
name ) );
503 props.push_back( prop );
512 types::FootprintInstance footprint;
514 footprint.mutable_id()->set_value(
m_Uuid.AsStdString() );
515 footprint.mutable_position()->set_x_nm(
GetPosition().x );
516 footprint.mutable_position()->set_y_nm(
GetPosition().y );
519 footprint.set_locked(
IsLocked() ? kiapi::common::types::LockedState::LS_LOCKED
520 : kiapi::common::types::LockedState::LS_UNLOCKED );
523 footprint.mutable_parent()->set_value(
board->m_Uuid.AsStdString() );
530 types::FootprintAttributes* attrs = footprint.mutable_attributes();
537 attrs->set_do_not_populate(
IsDNP() );
541 attrs->set_mounting_style( types::FootprintMountingStyle::FMS_THROUGH_HOLE );
543 attrs->set_mounting_style( types::FootprintMountingStyle::FMS_SMD );
545 attrs->set_mounting_style( types::FootprintMountingStyle::FMS_UNSPECIFIED );
549 types::FootprintDesignRuleOverrides* overrides = footprint.mutable_overrides();
563 overrides->set_zone_connection(
568 footprint.set_symbol_sheet_name(
m_sheetname.ToUTF8() );
569 footprint.set_symbol_sheet_filename(
m_sheetfile.ToUTF8() );
570 footprint.set_symbol_footprint_filters(
m_filters.ToUTF8() );
576 for(
const auto& [variantName, variant] :
m_variants )
578 types::FootprintVariant* variantMsg = footprint.add_variants();
579 variantMsg->set_name( variantName.ToUTF8() );
580 variantMsg->set_do_not_populate( variant.GetDNP() );
581 variantMsg->set_exclude_from_bill_of_materials( variant.GetExcludedFromBOM() );
582 variantMsg->set_exclude_from_position_files( variant.GetExcludedFromPosFiles() );
583 variantMsg->set_exclude_from_simulation( variant.GetExcludedFromSim() );
585 for(
const auto& [fieldName, fieldValue] : variant.GetFields() )
587 variantMsg->mutable_fields()->insert( { std::string( fieldName.ToUTF8() ),
588 std::string( fieldValue.ToUTF8() ) } );
594 types::FootprintUnitInfo* unitMsg = footprint.add_symbol_units();
595 unitMsg->set_name( unit.m_unitName.ToUTF8() );
597 for(
const wxString& pinNumber : unit.m_pins )
598 unitMsg->add_pin_numbers( pinNumber.ToUTF8() );
601 if( !aContainer.PackFrom( footprint ) )
602 wxFAIL_MSG( wxT(
"Failed to pack FOOTPRINT" ) );
613 aOutput->mutable_attributes()->set_keywords(
GetKeywords().ToUTF8() );
619 types::NetTieDefinition* netTie = aOutput->add_net_ties();
622 netTie->add_pad_number( padNumber.ToUTF8() );
628 types::JumperSettings* jumpers = aOutput->mutable_jumpers();
633 types::JumperGroup* jumperGroup = jumpers->add_groups();
635 for(
const wxString& padName :
group.GetNames() )
636 jumperGroup->add_pad_names( padName.ToUTF8() );
644 if( item->IsMandatory() )
647 google::protobuf::Any* itemMsg = aOutput->add_items();
648 item->Serialize( *itemMsg );
651 for(
const PAD* item :
Pads() )
653 google::protobuf::Any* itemMsg = aOutput->add_items();
654 item->Serialize( *itemMsg );
659 google::protobuf::Any* itemMsg = aOutput->add_items();
660 item->Serialize( *itemMsg );
665 google::protobuf::Any* itemMsg = aOutput->add_items();
666 item->Serialize( *itemMsg );
671 google::protobuf::Any* itemMsg = aOutput->add_items();
672 item->Serialize( *itemMsg );
677 if( body->GetExtruded()->m_height > 0 )
679 google::protobuf::Any* itemMsg = aOutput->add_items();
680 body->Serialize( *itemMsg );
686 google::protobuf::Any* itemMsg = aOutput->add_items();
687 types::Footprint3DModel modelMsg;
688 modelMsg.set_filename(
model.m_Filename.ToUTF8() );
692 modelMsg.set_visible(
model.m_Show );
693 modelMsg.set_opacity(
model.m_Opacity );
695 if( !itemMsg->PackFrom( modelMsg ) )
696 wxFAIL_MSG( wxT(
"Failed to pack FP_3DMODEL" ) );
714 for(
const types::NetTieDefinition& netTieMsg : aInput.net_ties() )
718 for(
const std::string&
pad : netTieMsg.pad_number() )
720 wxString escaped = wxString::FromUTF8(
pad );
722 escaped.Replace( wxS(
"\\" ), wxS(
"\\\\" ) );
723 escaped.Replace( wxS(
"," ), wxS(
"\\," ) );
725 if( !
group.IsEmpty() )
726 group += wxS(
", " );
737 jumperGroups.
Clear();
739 for(
const types::JumperGroup& groupMsg : aInput.jumpers().groups() )
741 std::set<wxString> padNames;
743 for(
const std::string& padName : groupMsg.pad_names() )
744 padNames.insert( wxString::FromUTF8( padName ) );
746 jumperGroups.
Add( std::move( padNames ) );
751 for(
int layerMsg : aInput.private_layers() )
756 privateLayers.
set( layer );
767 if( !field->IsMandatory() )
773 board->UncacheChildrenById( *
this );
786 for(
const google::protobuf::Any& itemMsg : aInput.items() )
794 if( itemMsg.type_url() ==
"type.googleapis.com/kiapi.board.types.Footprint3DModel" )
796 types::Footprint3DModel modelMsg;
798 if( !itemMsg.UnpackTo( &modelMsg ) )
803 model.m_Filename = wxString::FromUTF8( modelMsg.filename() );
804 model.m_Show = modelMsg.visible();
805 model.m_Opacity = modelMsg.opacity();
814 wxLogTrace(
traceApi, wxString::Format( wxS(
"Attempting to unpack unknown type %s "
815 "from footprint message, skipping" ),
816 itemMsg.type_url() ) );
824 if( item && item->Deserialize( itemMsg ) )
835 types::FootprintInstance footprint;
837 if( !aContainer.UnpackTo( &footprint ) )
844 SetLocked( footprint.locked() == kiapi::common::types::LockedState::LS_LOCKED );
846 google::protobuf::Any buf;
847 types::Field mandatoryField;
849 if( footprint.has_reference_field() )
851 mandatoryField = footprint.reference_field();
854 if( !buf.PackFrom( mandatoryField ) )
855 wxFAIL_MSG( wxT(
"Failed to pack footprint reference field" ) );
860 if( footprint.has_value_field() )
862 mandatoryField = footprint.value_field();
865 if( !buf.PackFrom( mandatoryField ) )
866 wxFAIL_MSG( wxT(
"Failed to pack footpring value field" ) );
871 if( footprint.has_datasheet_field() )
873 mandatoryField = footprint.datasheet_field();
876 if( !buf.PackFrom( mandatoryField ) )
877 wxFAIL_MSG( wxT(
"Failed to pack footprint datasheet field" ) );
882 if( footprint.has_description_field() )
884 mandatoryField = footprint.description_field();
887 if( !buf.PackFrom( mandatoryField ) )
888 wxFAIL_MSG( wxT(
"Failed to pack footprint description field" ) );
895 switch( footprint.attributes().mounting_style() )
897 case types::FootprintMountingStyle::FMS_THROUGH_HOLE:
901 case types::FootprintMountingStyle::FMS_SMD:
909 SetBoardOnly( footprint.attributes().not_in_schematic() );
914 SetDNP( footprint.attributes().do_not_populate() );
920 const types::FootprintDesignRuleOverrides& overrides = footprint.overrides();
922 if( overrides.has_copper_clearance() )
927 if( overrides.has_solder_mask() && overrides.solder_mask().has_solder_mask_margin() )
932 if( overrides.has_solder_paste() )
934 const types::SolderPasteOverrides& pasteSettings = overrides.solder_paste();
936 if( pasteSettings.has_solder_paste_margin() )
941 if( pasteSettings.has_solder_paste_margin_ratio() )
950 m_sheetname = wxString::FromUTF8( footprint.symbol_sheet_name() );
951 m_sheetfile = wxString::FromUTF8( footprint.symbol_sheet_filename() );
952 m_filters = wxString::FromUTF8( footprint.symbol_footprint_filters() );
961 for(
const types::FootprintVariant& variantMsg : footprint.variants() )
963 wxString variantName = wxString::FromUTF8( variantMsg.name() );
969 variant.
SetName( variantName );
970 variant.
SetDNP( variantMsg.do_not_populate() );
975 for(
const auto& [fieldName, fieldValue] : variantMsg.fields() )
976 variant.
SetFieldValue( wxString::FromUTF8( fieldName ), wxString::FromUTF8( fieldValue ) );
981 for(
const types::FootprintUnitInfo& unitMsg : footprint.symbol_units() )
984 unit.
m_unitName = wxString::FromUTF8( unitMsg.name() );
986 for(
const std::string& pinNumber : unitMsg.pin_numbers() )
987 unit.
m_pins.emplace_back( wxString::FromUTF8( pinNumber ) );
1000 if( field->GetId() == aFieldType )
1015 if( field->GetId() == aFieldType )
1025 return GetField( aFieldName ) !=
nullptr;
1033 if( field->GetName() == aFieldName )
1049 if( !field->IsVisible() || field->GetText().IsEmpty() )
1053 aVector.push_back( field );
1056 std::sort( aVector.begin(), aVector.end(),
1059 return lhs->GetOrdinal() < rhs->GetOrdinal();
1065 std::vector<PCB_FIELD*>& aDetached )
1067 std::deque<PCB_FIELD*> updatedFieldSet;
1068 std::vector<wxString> assignedFields;
1075 *existingField = sourceField;
1078 updatedFieldSet.push_back( existingField );
1079 assignedFields.push_back( sourceField.GetName() );
1084 aAdded.push_back( destField );
1085 updatedFieldSet.push_back( destField );
1092 if( field.IsMandatory() )
1093 assignOrAdd(
const_cast<PCB_FIELD*
>( std::as_const( *this ).GetField( field.GetId() ) ), field );
1095 assignOrAdd(
GetField( field.GetName() ), field );
1100 if( !field->IsMandatory() && !
alg::contains( assignedFields, field->GetName() ) )
1101 aDetached.push_back( field );
1112 m_fields = std::move( updatedFieldSet );
1123 ordinal = std::max( ordinal, field->GetOrdinal() + 1 );
1130 bool aStyleShapes,
bool aStyleDimensions,
bool aStyleBarcodes )
1135 field->StyleFromSettings(
board.GetDesignSettings(),
true );
1140 switch( item->Type() )
1145 item->StyleFromSettings(
board.GetDesignSettings(),
true );
1150 if( aStyleShapes && !item->IsOnCopperLayer() )
1151 item->StyleFromSettings(
board.GetDesignSettings(),
true );
1160 if( aStyleDimensions )
1161 item->StyleFromSettings(
board.GetDesignSettings(),
true );
1166 if( aStyleBarcodes )
1167 item->StyleFromSettings(
board.GetDesignSettings(),
true );
1181 std::vector< BOARD_ITEM* > item_list;
1184 item_list.push_back( field );
1187 item_list.push_back(
pad );
1190 item_list.push_back( gr_item );
1195 item_list.push_back(
group );
1199 item_list.push_back( zone );
1203 item_list.push_back( point );
1205 bool changed =
false;
1211 item->ResetUuidDirect();
1249 board->UncacheChildrenById( *
this );
1257 for(
PCB_FIELD* field : aOther.m_fields )
1260 aOther.m_fields.clear();
1268 for(
PAD*
pad : aOther.Pads() )
1271 aOther.Pads().clear();
1279 for(
ZONE* item : aOther.Zones() )
1287 item->SetNetCode( -1 );
1290 aOther.Zones().clear();
1298 for(
BOARD_ITEM* item : aOther.GraphicalItems() )
1301 aOther.GraphicalItems().clear();
1312 aOther.Groups().clear();
1323 aOther.Constraints().clear();
1331 for(
PCB_POINT* point : aOther.Points() )
1334 aOther.Points().clear();
1348 aOther.m_componentClassCacheProxy->GetStaticComponentClass() );
1360 aOther.m_bodies.clear();
1361 aOther.m_fields.clear();
1362 aOther.Pads().clear();
1363 aOther.Zones().clear();
1364 aOther.GraphicalItems().clear();
1365 aOther.m_initial_comments =
nullptr;
1400 board->UncacheChildrenById( *
this );
1402 std::map<EDA_ITEM*, EDA_ITEM*> ptrMap;
1413 ptrMap[field] = newField;
1426 ptrMap[
pad ] = newPad;
1438 ZONE* newZone =
static_cast<ZONE*
>( zone->Clone() );
1439 ptrMap[ zone ] = newZone;
1458 ptrMap[ item ] = newItem;
1474 newGroup->
AddItem( ptrMap[ member ] );
1498 ptrMap[ point ] = newItem;
1535 *
this = *
static_cast<const FOOTPRINT*
>( aOther );
1562 if( aSheetPath.empty() )
1566 return m_path.size() >= aSheetPath.size() - 1
1567 && std::equal( aSheetPath.begin() + 1, aSheetPath.end(),
m_path.begin() );
1573 aVars->push_back( wxT(
"REFERENCE" ) );
1574 aVars->push_back( wxT(
"VALUE" ) );
1575 aVars->push_back( wxT(
"LAYER" ) );
1576 aVars->push_back( wxT(
"FOOTPRINT_LIBRARY" ) );
1577 aVars->push_back( wxT(
"FOOTPRINT_NAME" ) );
1578 aVars->push_back( wxT(
"SHORT_NET_NAME(<pad_number>)" ) );
1579 aVars->push_back( wxT(
"NET_NAME(<pad_number>)" ) );
1580 aVars->push_back( wxT(
"NET_CLASS(<pad_number>)" ) );
1581 aVars->push_back( wxT(
"PIN_NAME(<pad_number>)" ) );
1582 aVars->push_back( wxT(
"EXCLUDE_FROM_BOM" ) );
1583 aVars->push_back( wxT(
"EXCLUDE_FROM_BOARD" ) );
1584 aVars->push_back( wxT(
"EXCLUDE_FROM_SIM" ) );
1585 aVars->push_back( wxT(
"EXCLUDE_FROM_POS_FILES" ) );
1586 aVars->push_back( wxT(
"DNP" ) );
1606 wxString variant = aVariantName;
1608 if( token->IsSameAs( wxT(
"REFERENCE" ) ) )
1611 *token = reference->GetShownText( variant,
INTERNAL, aDepth + 1 );
1617 else if( token->IsSameAs( wxT(
"VALUE" ) ) )
1620 *token = value->GetShownText( variant,
INTERNAL, aDepth + 1 );
1626 else if( token->IsSameAs( wxT(
"LAYER" ) ) )
1631 else if( token->IsSameAs( wxT(
"FOOTPRINT_LIBRARY" ) ) )
1633 *token =
m_fpid.GetUniStringLibNickname();
1636 else if( token->IsSameAs( wxT(
"FOOTPRINT_NAME" ) ) )
1638 *token =
m_fpid.GetUniStringLibItemName();
1641 else if( token->StartsWith( wxT(
"SHORT_NET_NAME(" ) )
1642 || token->StartsWith( wxT(
"NET_NAME(" ) )
1643 || token->StartsWith( wxT(
"NET_CLASS(" ) )
1644 || token->StartsWith( wxT(
"PIN_NAME(" ) ) )
1646 wxString padNumber = token->AfterFirst(
'(' );
1647 padNumber = padNumber.BeforeLast(
')' );
1651 if(
pad->GetNumber() == padNumber )
1653 if( token->StartsWith( wxT(
"SHORT_NET_NAME" ) ) )
1654 *token =
pad->GetShortNetname();
1655 else if( token->StartsWith( wxT(
"NET_NAME" ) ) )
1656 *token =
pad->GetNetname();
1657 else if( token->StartsWith( wxT(
"NET_CLASS" ) ) )
1658 *token =
pad->GetNetClassName();
1660 *token =
pad->GetPinFunction();
1666 else if( token->IsSameAs( wxT(
"EXCLUDE_FROM_BOM" ) ) )
1668 *token = wxEmptyString;
1671 *token = wxS(
"Excluded from BOM" );
1675 else if( token->IsSameAs( wxT(
"EXCLUDE_FROM_POS_FILES" ) ) )
1677 *token = wxEmptyString;
1680 *token = wxS(
"Excluded from position files" );
1684 else if( token->IsSameAs( wxT(
"EXCLUDE_FROM_BOARD" ) ) )
1687 *token = wxEmptyString;
1690 else if( token->IsSameAs( wxT(
"EXCLUDE_FROM_SIM" ) ) )
1692 *token = wxEmptyString;
1695 *token = wxS(
"Excluded from simulation" );
1699 else if( token->IsSameAs( wxT(
"DNP" ) ) )
1701 *token = wxEmptyString;
1704 *token = wxS(
"DNP" );
1710 *token = field->GetShownText( variant,
INTERNAL, aDepth + 1 );
1714 else if( token->StartsWith( wxS(
"PROPERTY." ) ) )
1717 wxString propertyName = token->AfterFirst(
'.' );
1718 propertyName.Replace( wxS(
"_" ), wxS(
" " ) );
1724 if( !property || property->IsHiddenFromPropertiesManager() )
1754 return it !=
m_variants.end() ? &it->second :
nullptr;
1762 return it !=
m_variants.end() ? &it->second :
nullptr;
1768 if( aVariant.
GetName().IsEmpty()
1780 it->second = std::move( updated );
1790 if( aVariantName.IsEmpty()
1793 wxASSERT_MSG(
false, wxT(
"Variant name cannot be empty or default." ) );
1808 auto inserted =
m_variants.emplace( aVariantName, std::move( variant ) );
1809 return &inserted.first->second;
1821 if( aNewName.IsEmpty()
1832 auto existingIt =
m_variants.find( aNewName );
1834 if( existingIt !=
m_variants.end() && existingIt != it )
1837 if( it->first == aNewName )
1843 m_variants.emplace( aNewName, std::move( variant ) );
1862 return variant->
GetDNP();
1930 return field->GetText();
1954 switch( aBoardItem->
Type() )
1980 m_pads.push_back(
static_cast<PAD*
>( aBoardItem ) );
1982 m_pads.push_front(
static_cast<PAD*
>( aBoardItem ) );
1988 m_zones.push_back(
static_cast<ZONE*
>( aBoardItem ) );
2011 wxFAIL_MSG( wxT(
"FOOTPRINT::Add(): Markers go at the board level, even in the footprint editor" ) );
2015 wxFAIL_MSG( wxT(
"FOOTPRINT::Add(): Nested footprints not supported" ) );
2035 wxFAIL_MSG( wxString::Format( wxT(
"FOOTPRINT::Add(): BOARD_ITEM type (%d) not handled" ),
2036 aBoardItem->
Type() ) );
2048 board->CacheItemSubtreeById( *aBoardItem );
2052 board->noteDrillModelChange( aBoardItem );
2061 switch( aBoardItem->
Type() )
2066 if( *it == aBoardItem )
2068 const wxString fieldName = ( *it )->GetUntranslatedName();
2072 for(
auto& [variantName, footprintVariant] :
m_variants )
2073 footprintVariant.RemoveFieldValue( fieldName );
2094 if( *it == aBoardItem )
2104 for(
auto it =
m_pads.begin(); it !=
m_pads.end(); ++it )
2106 if( *it ==
static_cast<PAD*
>( aBoardItem ) )
2118 if( *it ==
static_cast<ZONE*
>( aBoardItem ) )
2142 if( *it ==
static_cast<PCB_GROUP*
>( aBoardItem ) )
2152 wxFAIL_MSG( wxT(
"FOOTPRINT::Remove(): Markers go at the board level, even in the footprint editor" ) );
2156 wxFAIL_MSG( wxT(
"FOOTPRINT::Remove(): Nested footprints not supported" ) );
2162 if( *it ==
static_cast<PCB_POINT*
>( aBoardItem ) )
2176 wxFAIL_MSG( wxString::Format( wxT(
"FOOTPRINT::Remove() needs work: BOARD_ITEM type (%d) not handled" ),
2177 aBoardItem->
Type() ) );
2183 if(
board->IsItemIndexedById(
this ) )
2185 board->UncacheItemSubtreeById( *aBoardItem );
2186 board->noteDrillModelChange( aBoardItem );
2189 board->IncrementTimeStamp();
2215 switch(
pad->GetProperty() )
2233 switch(
pad->GetAttribute() )
2240 if(
pad->IsOnCopperLayer() )
2270 return _(
"Through hole" );
2272 return _(
"Unspecified" );
2308 wxStringTokenizer keywordTokenizer(
GetKeywords(), wxS(
" \t\r\n" ), wxTOKEN_STRTOK );
2310 while( keywordTokenizer.HasMoreTokens() )
2331 if(
dummy.IsFlipped() )
2335 bbox.
Merge(
pad->GetBoundingBox() );
2385 std::vector<PCB_TEXT*> texts;
2386 bool isFPEdit =
board &&
board->IsFootprintHolder();
2407 texts.push_back(
static_cast<PCB_TEXT*
>( item ) );
2425 bbox.
Merge( item->GetBoundingBox() );
2431 if( field->IsReference() || field->IsValue() )
2434 texts.push_back( field );
2438 bbox.
Merge(
pad->GetBoundingBox() );
2441 bbox.
Merge( zone->GetBoundingBox() );
2444 bbox.
Merge( point->GetBoundingBox() );
2449 if( aIncludeText || noDrawItems )
2472 bool valueLayerIsVisible =
true;
2473 bool refLayerIsVisible =
true;
2483 valueLayerIsVisible =
board->IsLayerVisible( value->
GetLayer() )
2490 refLayerIsVisible =
board->IsLayerVisible( reference->
GetLayer() )
2497 if( value && ( ( value->
IsVisible() && valueLayerIsVisible ) || noDrawItems ) )
2500 if( reference && ( ( reference->
IsVisible() && refLayerIsVisible ) || noDrawItems ) )
2511 if( aIncludeText || noDrawItems )
2529 std::vector<PCB_TEXT*> texts;
2531 bool isFPEdit =
board &&
board->IsFootprintHolder();
2541 if( ( aLayers & item->GetLayerSet() ).none() )
2549 bbox.
Merge( item->GetBoundingBox() );
2554 if( ( aLayers &
pad->GetLayerSet() ).none() )
2557 bbox.
Merge(
pad->GetBoundingBox() );
2562 if( ( aLayers & zone->GetLayerSet() ).none() )
2565 bbox.
Merge( zone->GetBoundingBox() );
2573 if( ( aLayers & point->GetLayerSet() ).none() )
2576 bbox.
Merge( point->GetBoundingBox() );
2586 bool isFPEdit =
board &&
board->IsFootprintHolder();
2611 pad->Padstack().ForEachUniqueLayer(
2625 const SHAPE_POLY_SET& layerPoly = *zone->GetFilledPolysList( layer );
2641 const int halfsize =
pcbIUScale.mmToIU( 1.0 );
2652 std::vector<VECTOR2I> convex_hull;
2664 for(
const VECTOR2I& pt : convex_hull )
2678 bool isFPEdit =
board &&
board->IsFootprintHolder();
2688 if( item->IsOnLayer( aLayer ) )
2699 if(
pad->IsOnLayer( aLayer ) )
2705 if( zone->GetIsRuleArea() )
2708 if( zone->IsOnLayer( aLayer ) )
2710 const std::shared_ptr<SHAPE_POLY_SET>& layerPoly = zone->GetFilledPolysList( aLayer );
2712 for(
int ii = 0; ii < layerPoly->OutlineCount(); ii++ )
2713 rawPolys.
AddOutline( layerPoly->COutline( ii ) );
2717 std::vector<VECTOR2I> convex_hull;
2722 for(
const VECTOR2I& pt : convex_hull )
2735 variant =
board->GetCurrentVariant();
2748 aList.emplace_back(
_(
"Footprint Name" ),
GetFPID().GetLibItemName().wx_str() );
2753 wxString::Format(
_(
"Keywords: %s" ),
GetKeywords() ) );
2762 case F_Cu: aList.emplace_back(
_(
"Board Side" ),
_(
"Front" ) );
break;
2763 case B_Cu: aList.emplace_back(
_(
"Board Side" ),
_(
"Back (Flipped)" ) );
break;
2767 aList.emplace_back(
_(
"Rotation" ), wxString::Format( wxT(
"%.4g" ),
GetOrientation().AsDegrees() ) );
2769 auto addToken = []( wxString* aStr,
const wxString& aAttr )
2771 if( !aStr->IsEmpty() )
2772 *aStr += wxT(
", " );
2781 addToken( &status,
_(
"Locked" ) );
2784 addToken( &status,
_(
"autoplaced" ) );
2787 addToken( &attrs,
_(
"not in schematic" ) );
2790 addToken( &attrs,
_(
"exclude from pos files" ) );
2793 addToken( &attrs,
_(
"exclude from BOM" ) );
2796 addToken( &attrs,
_(
"exclude from simulation" ) );
2799 addToken( &attrs,
_(
"DNP" ) );
2801 aList.emplace_back(
_(
"Status: " ) + status,
_(
"Attributes:" ) + wxS(
" " ) + attrs );
2805 aList.emplace_back(
_(
"Component Class" ),
2809 msg.Printf(
_(
"Footprint: %s" ),
m_fpid.GetUniStringLibId() );
2811 aList.emplace_back( msg, msg2 );
2815 aList.emplace_back( msg, msg2 );
2823 if(
board->IsFootprintHolder() )
2855 return aItem->IsOnLayer( aLayer );
2858 return std::ranges::any_of(
m_pads, isOnLayer )
2859 || std::ranges::any_of(
m_zones, isOnLayer )
2860 || std::ranges::any_of(
m_fields, isOnLayer )
2861 || std::ranges::any_of(
m_drawings, isOnLayer );
2869 if(
pad->IsOnLayer( aLayer ) &&
pad->HitTest( aPosition, aAccuracy ) )
2875 if( zone->IsOnLayer( aLayer ) && zone->HitTest( aPosition, aAccuracy ) )
2881 if( item->Type() !=
PCB_TEXT_T && item->IsOnLayer( aLayer )
2882 && item->HitTest( aPosition, aAccuracy ) )
2894 std::vector<BOARD_ITEM*> items;
2898 if(
pad->IsOnLayer( aLayer ) )
2899 items.push_back(
pad );
2904 if( zone->IsOnLayer( aLayer ) )
2905 items.push_back( zone );
2910 if( item->Type() !=
PCB_TEXT_T && item->IsOnLayer( aLayer ) )
2911 items.push_back( item );
2920 if( !aContained && item->HitTest( aRect, aContained, aAccuracy ) )
2922 else if( aContained && !item->HitTest( aRect, aContained, aAccuracy ) )
2929 return !items.empty() && aContained;
2936 return rect.Inflate( aAccuracy ).Contains( aPosition );
2948 BOX2I arect = aRect;
2968 if(
pad->HitTest( arect,
false, 0 ) )
2974 if( zone->HitTest( arect,
false, 0 ) )
2980 if( point->HitTest( arect,
false, 0 ) )
2991 if( item->Type() !=
PCB_TEXT_T && item->HitTest( arect,
false, 0 ) )
3005 using std::ranges::all_of;
3006 using std::ranges::any_of;
3013 [&](
const auto* aItem )
3015 return aItem && aItem->HitTest( aPoly, aContained );
3021 auto drawings =
m_drawings | std::views::filter( [](
const auto* aItem )
3032 return all_of( drawings, hitTest )
3033 && all_of(
m_pads, hitTest )
3034 && all_of(
m_zones, hitTest );
3039 return any_of( drawings, hitTest )
3040 || any_of(
m_pads, hitTest )
3041 || any_of(
m_zones, hitTest );
3048 bool can_select = aSearchAfterMe ? false :
true;
3052 if( !can_select &&
pad == aSearchAfterMe )
3058 if( can_select &&
pad->GetNumber() == aPadNumber )
3070 if(
pad->m_Uuid == aUuid )
3083 if( !(
pad->GetLayerSet() & aLayerMask ).any() )
3086 if(
pad->HitTest( aPosition ) )
3096 std::vector<const PAD*> retv;
3100 if( ( aIgnore && aIgnore ==
pad ) || (
pad->GetNumber() != aPadNumber ) )
3103 retv.push_back(
pad );
3118 std::set<wxString> usedNumbers;
3130 if(
pad->GetNumber().IsEmpty() )
3133 usedNumbers.insert(
pad->GetNumber() );
3158 auto isElectricalPadNumber =
3159 [](
const wxString& num ) ->
bool
3166 while( i < num.size() && wxIsalpha( num[i] ) )
3174 if( i == num.size() )
3177 for(
size_t j = i; j < num.size(); ++j )
3179 if( !wxIsdigit( num[j] ) )
3186 std::set<wxString> counted;
3198 const wxString& num =
pad->GetNumber();
3200 if( isElectricalPadNumber( num ) )
3202 counted.insert( num );
3204 else if( num.Contains(
'_' ) )
3206 wxString first, second;
3207 first = num.BeforeFirst(
'_', &second );
3209 if( isElectricalPadNumber( first ) && isElectricalPadNumber( second ) )
3211 counted.insert( first );
3212 counted.insert( second );
3217 return static_cast<unsigned>( counted.size() );
3223 if(
nullptr == a3DModel )
3268 const std::vector<KICAD_T>& aScanTypes )
3270#if 0 && defined(DEBUG)
3271 std::cout <<
GetClass().mb_str() <<
' ';
3274 bool drawingsScanned =
false;
3276 for(
KICAD_T scanType : aScanTypes )
3315 if( !drawingsScanned )
3320 drawingsScanned =
true;
3368 if( reference.IsEmpty() )
3369 reference =
_(
"<no reference designator>" );
3371 return wxString::Format(
_(
"Footprint %s" ), reference );
3377 return wxString::Format( wxT(
"%s (%s)" ),
3415 aFunction( constraint );
3422 aFunction( drawing );
3428 catch( std::bad_function_call& )
3430 wxFAIL_MSG( wxT(
"Error running FOOTPRINT::RunOnChildren" ) );
3437 std::vector<int> layers;
3439 layers.reserve( 6 );
3445 wxASSERT_MSG(
false, wxT(
"Illegal layer" ) );
3462 bool f_silk =
false, b_silk =
false, non_silk =
false;
3466 if( item->GetLayer() ==
F_SilkS )
3468 else if( item->GetLayer() ==
B_SilkS )
3474 if( ( f_silk || b_silk ) && !non_silk &&
m_pads.empty() )
3515 constexpr double MINIMAL_ZOOM_LEVEL_FOR_VISIBILITY = 1.5;
3518 return MINIMAL_ZOOM_LEVEL_FOR_VISIBILITY;
3531 int biggest_clearance =
board->GetMaxClearanceValue();
3532 area.
Inflate( biggest_clearance );
3543 if( aName.find_first_of( invalids ) != std::string::npos )
3555 static const wxChar invalidCharsReadable[] = wxT(
"% $ < > 'tab' 'return' 'line feed' \\ \" / :");
3558 return invalidCharsReadable;
3560 return invalidChars.wc_str();
3566 if( aMoveVector.
x == 0 && aMoveVector.
y == 0 )
3587 field->KeepUpright();
3592 static_cast<PCB_TEXT*
>( item )->KeepUpright();
3599 wxASSERT( aLayer ==
F_Cu || aLayer ==
B_Cu );
3654 field->OnFootprintTransformed();
3657 pad->OnFootprintTransformed();
3660 zone->OnFootprintTransformed();
3668 item->OnFootprintTransformed();
3673 point->OnFootprintTransformed();
3687 body->Flip( pos, aFlipDirection );
3713 if( !std::isfinite( aScaleX ) || !std::isfinite( aScaleY ) || aScaleX <= 0.0 || aScaleY <= 0.0 )
3718 const double ratioX = aScaleX / oldSx;
3719 const double ratioY = aScaleY / oldSy;
3720 const double linearFactor = ( aScaleX + aScaleY ) / ( oldSx + oldSy );
3728 pad->OnFootprintRescaled( ratioX, ratioY, linearFactor,
anchor, parentRotate );
3731 field->OnFootprintRescaled( ratioX, ratioY, linearFactor,
anchor, parentRotate );
3734 item->OnFootprintRescaled( ratioX, ratioY, linearFactor,
anchor, parentRotate );
3737 zone->OnFootprintRescaled( ratioX, ratioY, linearFactor,
anchor, parentRotate );
3740 point->OnFootprintTransformed();
3768 field->OnFootprintTransformed();
3771 pad->OnFootprintTransformed();
3774 zone->OnFootprintTransformed();
3777 point->OnFootprintTransformed();
3785 item->OnFootprintTransformed();
3789 item->Move(
delta );
3829 field->Move( moveVector );
3833 pad->Move( moveVector );
3837 item->Move( moveVector );
3841 zone->Move( moveVector );
3845 point->Move( moveVector );
3884 field->OnFootprintTransformed();
3887 pad->OnFootprintTransformed();
3890 zone->OnFootprintTransformed();
3893 point->OnFootprintTransformed();
3901 item->OnFootprintTransformed();
3905 item->Rotate( rotationCenter, angleChange );
3932 std::map<KIID, KIID> idMap;
3939 idMap[oldId] = child->
m_Uuid;
3944 constraint->RemapKIIDs( idMap );
3951 const BOARD_ITEM* aItem,
bool addToFootprint )
3955 switch( aItem->
Type() )
3959 PAD* new_pad =
new PAD( *
static_cast<const PAD*
>( aItem ) );
3962 if( addToFootprint )
3963 m_pads.push_back( new_pad );
3971 ZONE* new_zone =
new ZONE( *
static_cast<const ZONE*
>( aItem ) );
3974 if( addToFootprint )
3975 m_zones.push_back( new_zone );
3977 new_item = new_zone;
3986 if( addToFootprint )
3989 new_item = new_point;
3998 switch(
static_cast<const PCB_FIELD*
>( aItem )->GetId() )
4006 if( addToFootprint )
4009 new_item = new_field;
4018 if( addToFootprint )
4021 new_item = new_text;
4030 if( addToFootprint )
4033 new_item = new_shape;
4042 if( addToFootprint )
4045 new_item = new_barcode;
4054 if( addToFootprint )
4057 new_item = new_image;
4066 if( addToFootprint )
4069 new_item = new_textbox;
4082 if( addToFootprint )
4085 new_item = dimension;
4091 new_item = aItem->
Duplicate( addToParentGroup, aCommit );
4093 if( addToFootprint )
4103 if( addToFootprint )
4105 group->RunOnChildren(
4125 wxFAIL_MSG( wxT(
"Duplication not supported for items of class " ) + aItem->
GetClass() );
4135 std::set<wxString> usedNumbers;
4139 usedNumbers.insert(
pad->GetNumber() );
4146 while( usedNumbers.count( wxString::Format( wxT(
"%s%d" ), prefix, num ) ) )
4149 return wxString::Format( wxT(
"%s%d" ), prefix, num );
4213 for(
int i = 0; i < aCollector.
GetCount(); ++i )
4217 switch( item->
Type() )
4249 double footprintRegionArea =
polygonArea( footprintRegion );
4250 double uncoveredRegionArea = footprintRegionArea -
polygonArea( coveredRegion );
4251 double coveredArea = footprintRegionArea - uncoveredRegionArea;
4254 if( footprintRegionArea == 0 )
4257 double ratio = coveredArea / footprintRegionArea;
4264 return std::min( ratio, 1.0 );
4271 std::shared_ptr<SHAPE_COMPOUND> shape = std::make_shared<SHAPE_COMPOUND>();
4292 shape->AddShape(
pad->GetEffectiveShape( aLayer, aFlash, aUsage )->Clone() );
4297 shape->AddShape( item->GetEffectiveShape( aLayer, aFlash, aUsage )->Clone() );
4299 shape->AddShape( item->GetEffectiveShape( aLayer, aFlash, aUsage )->Clone() );
4346 std::vector<PCB_SHAPE*> list_front;
4347 std::vector<PCB_SHAPE*> list_back;
4348 std::map<int, int> front_width_histogram;
4349 std::map<int, int> back_width_histogram;
4356 list_back.push_back( shape );
4363 list_front.push_back( shape );
4368 if( !list_front.size() && !list_back.size() )
4372 int chainingEpsilon =
pcbIUScale.mmToIU( 0.02 );
4375 true, aErrorHandler ) )
4385 auto max = std::max_element( front_width_histogram.begin(), front_width_histogram.end(),
4386 [](
const std::pair<int, int>& a,
const std::pair<int, int>& b )
4388 return a.second < b.second;
4391 if( max != front_width_histogram.end() )
4414 auto max = std::max_element( back_width_histogram.begin(), back_width_histogram.end(),
4415 [](
const std::pair<int, int>& a,
const std::pair<int, int>& b )
4417 return a.second < b.second;
4420 if( max != back_width_histogram.end() )
4443 std::map<PCB_LAYER_ID, std::vector<PCB_SHAPE*>> layer_shapes;
4449 if( item->Type() != PCB_SHAPE_T )
4452 for( PCB_LAYER_ID layer : item->GetLayerSet() )
4454 if( !IsCopperLayer( layer ) )
4457 if( board && !board->GetEnabledLayers().Contains( layer ) )
4460 layer_shapes[layer].push_back( static_cast<PCB_SHAPE*>( item ) );
4464 for(
size_t ii = 0; ii < m_pads.size(); ++ii )
4467 bool has_nettie =
false;
4469 auto it = map.find(
pad->GetNumber() );
4471 if( it == map.end() || it->second < 0 )
4474 for(
size_t jj = 0; jj < m_pads.size(); ++jj )
4479 PAD* other = m_pads[ jj ];
4481 auto it2 = map.find( other->
GetNumber() );
4483 if( it2 == map.end() || it2->second < 0 )
4486 if( it2->second == it->second )
4488 m_netTieCache[
pad].insert(
pad->GetNetCode() );
4490 m_netTieCache[other].insert( other->
GetNetCode() );
4491 m_netTieCache[other].insert(
pad->GetNetCode() );
4499 for(
auto& [ layer, shapes ] : layer_shapes )
4501 auto pad_shape =
pad->GetEffectiveShape( layer );
4503 for(
auto other_shape : shapes )
4505 auto shape = other_shape->GetEffectiveShape( layer );
4507 if( pad_shape->Collide( shape.get() ) )
4509 std::set<int>& nettie = m_netTieCache[
pad];
4510 m_netTieCache[other_shape].insert( nettie.begin(), nettie.end() );
4520 std::map<wxString, int> padNumberToGroupIdxMap;
4523 padNumberToGroupIdxMap[
pad->GetNumber() ] = -1;
4528 padNumberToGroupIdxMap[padNumber] = ii;
4531 return padNumberToGroupIdxMap;
4541 int groupIdx = padToNetTieGroupMap[ aPad->
GetNumber() ];
4542 std::vector<PAD*> otherPads;
4548 if( padToNetTieGroupMap[
pad->GetNumber() ] == groupIdx )
4549 otherPads.push_back(
pad );
4563 std::swap( *
this, *
image );
4572 image->RunOnChildren(
4602 return *
this == other;
4609 [](
const auto* aLeft,
const auto* aRight )
4611 return *aLeft == *aRight;
4614 if( !std::ranges::equal(
m_pads, aOther.
m_pads, equalItems ) )
4627 [](
const wxString& aLeft,
const wxString& aRight )
4629 return parseNetTiePadGroup( aLeft ) == parseNetTiePadGroup( aRight );
4648 std::vector<PCB_FIELD*> fields, otherFields;
4653 if( fields.size() != otherFields.size() )
4656 for(
size_t ii = 0; ii < fields.size(); ++ii )
4660 if( !( *fields[ii] == *otherFields[ii] ) )
4676 double similarity = 1.0;
4685 similarity *=
pad->Similarity( *otherPad );
4697 if( aPtA.
x != aPtB.
x )
4698 return aPtA.
x < aPtB.
x;
4700 if( aPtA.
y != aPtB.
y )
4701 return aPtA.
y < aPtB.
y;
4703 return std::nullopt;
4709 if( itemA->
Type() != itemB->
Type() )
4710 return itemA->
Type() < itemB->
Type();
4715 switch( itemA->
Type() )
4837 return itemA < itemB;
4849 std::optional<bool> padCopperMatches;
4852 const PAD* checkPad = aFirst;
4865 padCopperMatches = aFirst->
GetSize( aLayer ).
x < aSecond->
GetSize( aLayer ).
x;
4867 padCopperMatches = aFirst->
GetSize( aLayer ).
y < aSecond->
GetSize( aLayer ).
y;
4869 padCopperMatches = aFirst->
GetShape( aLayer ) < aSecond->
GetShape( aLayer );
4872 if( padCopperMatches.has_value() )
4873 return *padCopperMatches;
4881 return aFirst < aSecond;
4886bool FOOTPRINT::cmp_padstack::operator()(
const PAD* aFirst,
const PAD* aSecond )
const
4926 if( firstShape->VertexCount() != secondShape->VertexCount() )
4927 return firstShape->VertexCount() < secondShape->VertexCount();
4929 for(
int ii = 0; ii < firstShape->VertexCount(); ++ii )
4931 if( std::optional<bool> cmp =
cmp_points_opt( firstShape->CVertex( ii ), secondShape->CVertex( ii ) ) )
4965 return aFirst < aSecond;
4970 int aMaxError,
ERROR_LOC aErrorLoc )
const
4981 clearance.x +=
pad->GetSolderMaskExpansion( padLayer );
4982 clearance.y +=
pad->GetSolderMaskExpansion( padLayer );
5005 if( dummySize.
x <= 0 || dummySize.
y <= 0 )
5009 dummy.SetSize( padLayer, dummySize );
5010 dummy.TransformShapeToPolygon( aBuffer, padLayer, 0, aMaxError, aErrorLoc );
5014 pad->TransformShapeToPolygon( aBuffer, padLayer,
clearance.x, aMaxError, aErrorLoc );
5020 if( !
pad->FlashLayer( aLayer ) )
5025 pad->Padstack().ForEachUniqueLayer(
5028 processPad(
pad, l );
5033 processPad(
pad, aLayer );
5040 int aError,
ERROR_LOC aErrorLoc,
bool aIncludeText,
5041 bool aIncludeShapes,
bool aIncludePrivateItems )
const
5048 if( item->Type() ==
PCB_TEXT_T && aIncludeText )
5053 text->TransformTextToPolySet( aBuffer, aClearance, aError, aErrorLoc );
5064 textbox->PCB_SHAPE::TransformShapeToPolygon( aBuffer, aLayer, 0, aError, aErrorLoc );
5071 if( item->Type() ==
PCB_SHAPE_T && aIncludeShapes )
5092 if( ( aLayer ==
UNDEFINED_LAYER || field->GetLayer() == aLayer ) && field->IsVisible() )
5093 field->TransformTextToPolySet( aBuffer, aClearance, aError, aErrorLoc );
5103 std::set<KIFONT::OUTLINE_FONT*>
fonts;
5117 if( permission == PERMISSION::EDITABLE || permission == PERMISSION::INSTALLABLE )
5118 fonts.insert( outlineFont );
5124 processItem( item );
5127 processItem( field );
5141 wxLogTrace(
"EMBED",
"Failed to add font file: %s", font->GetFileName() );
5179 return wxEmptyString;
5184 const std::unordered_set<wxString>& aComponentClassNames )
5233 LSET padLayers =
pad->GetLayerSet();
5234 padLayers |= boardCopper;
5235 pad->SetLayerSet( padLayers );
5252 if( zcMap.
Choices().GetCount() == 0 )
5264 if( layerEnum.
Choices().GetCount() == 0 )
5272 wxPGChoices fpLayers;
5283 auto isNotFootprintHolder =
5289 return !
board->IsFootprintHolder();
5313 const wxString groupFields =
_HKI(
"Fields" );
5319 const wxString propertyFields =
_HKI(
"Footprint Properties" );
5342 const wxString groupAttributes =
_HKI(
"Attributes" );
5362 const wxString groupOverrides =
_HKI(
"Overrides" );
KICOMMON_API types::KiCadObjectType ToProtoEnum(KICAD_T aValue)
KICOMMON_API KICAD_T FromProtoEnum(types::KiCadObjectType aValue)
std::unique_ptr< EDA_ITEM > CreateItemForType(KICAD_T aType, EDA_ITEM *aContainer)
ERROR_LOC
When approximating an arc or circle, should the error be placed on the outside or inside of the curve...
constexpr EDA_IU_SCALE pcbIUScale
constexpr int ARC_LOW_DEF
BITMAPS
A list of all bitmap identifiers.
#define DEFAULT_COURTYARD_WIDTH
BASE_SET & set(size_t pos)
A base class derived from BOARD_ITEM for items that can be connected and have a net,...
Abstract interface for BOARD_ITEMs capable of storing other items inside.
BOARD_ITEM_CONTAINER(BOARD_ITEM *aParent, KICAD_T aType)
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
BOARD_ITEM(BOARD_ITEM *aParent, KICAD_T idtype, PCB_LAYER_ID aLayer=F_Cu)
void SetUuidDirect(const KIID &aUuid)
Raw UUID assignment.
virtual BOARD_ITEM * Duplicate(bool addToParentGroup, BOARD_COMMIT *aCommit=nullptr) const
Create a copy of this BOARD_ITEM.
void SetLocked(bool aLocked) override
PCB_LAYER_ID GetFlippedLayer(PCB_LAYER_ID aLayer) const
Return the layer paired with aLayer on the opposite side of the board.
static double polygonArea(SHAPE_POLY_SET &aPolySet)
Area of aPolySet with every contour closed first, holes subtracted.
bool IsLocked() const override
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
virtual void TransformShapeToPolygon(SHAPE_POLY_SET &aBuffer, PCB_LAYER_ID aLayer, int aClearance, int aError, ERROR_LOC aErrorLoc, bool ignoreLineWidth=false) const
Convert the item shape to a closed polygon.
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
virtual const BOARD * GetBoard() const
Return the BOARD in which this BOARD_ITEM resides, or NULL if none.
VECTOR2I GetFPRelativePosition() const
virtual void TransformShapeToPolySet(SHAPE_POLY_SET &aBuffer, PCB_LAYER_ID aLayer, int aClearance, int aError, ERROR_LOC aErrorLoc, KIGFX::RENDER_SETTINGS *aRenderSettings=nullptr) const
Convert the item shape to a polyset.
BOARD_ITEM & operator=(const BOARD_ITEM &aOther)
BOARD_ITEM_CONTAINER * GetParent() const
wxString GetLayerName() const
Return the name of the PCB layer on which the item resides.
Information pertinent to a Pcbnew printed circuit board.
bool IsFootprintHolder() const
Find out if the board is being used to hold a single footprint for editing/viewing.
int GetCopperLayerCount() const
wxString GetCurrentVariant() const
COMPONENT_CLASS_MANAGER & GetComponentClassManager()
Gets the component class manager.
constexpr BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Inflates the rectangle horizontally by dx and vertically by dy.
constexpr size_type GetWidth() const
constexpr BOX2< Vec > & Merge(const BOX2< Vec > &aRect)
Modify the position and size of the rectangle in order to contain aRect.
constexpr const Vec GetCenter() const
constexpr size_type GetHeight() const
constexpr bool Contains(const Vec &aPoint) const
constexpr coord_type GetTop() const
constexpr bool Intersects(const BOX2< Vec > &aRect) const
constexpr coord_type GetBottom() const
virtual int Accuracy() const =0
int GetCount() const
Return the number of objects in the list.
const COMPONENT_CLASS * GetStaticComponentClass() const
Gets the static component class.
COMPONENT_CLASS * GetEffectiveStaticComponentClass(const std::unordered_set< wxString > &classNames)
Computes and returns an effective component class for a (possibly empty) set of constituent class nam...
A lightweight representation of a component class.
int AsTenthsOfADegree() const
bool IsType(FRAME_T aType) const
The base class for create windows for drawing purpose.
std::unordered_set< EDA_ITEM * > & GetItems()
void AddItem(EDA_ITEM *aItem)
Add item to group.
virtual void ClearEditFlags()
void SetFlags(EDA_ITEM_FLAGS aMask)
std::vector< PROPERTY_BASE * > GetCustomPropertiesAsInspectables() const
KICAD_T Type() const
Returns the type of object.
void ClearFlags(EDA_ITEM_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
virtual bool Matches(const EDA_SEARCH_DATA &aSearchData, void *aAuxData) const
Compare the item against the search criteria in aSearchData.
static INSPECT_RESULT IterateForward(std::deque< T > &aList, INSPECTOR inspector, void *testData, const std::vector< KICAD_T > &scanTypes)
This changes first parameter to avoid the DList and use the main queue instead.
bool HasFlag(EDA_ITEM_FLAGS aFlag) const
virtual void SetParent(EDA_ITEM *aParent)
EDA_ITEM(EDA_ITEM *parent, KICAD_T idType, bool isSCH_ITEM=false, bool isBOARD_ITEM=false)
int GetEllipseMinorRadius() const
const VECTOR2I & GetEllipseCenter() const
EDA_ANGLE GetEllipseEndAngle() const
int GetEllipseMajorRadius() const
EDA_ANGLE GetEllipseRotation() const
EDA_ANGLE GetEllipseStartAngle() const
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
virtual const wxString & GetText() const
Return the string associated with the text object.
virtual bool IsVisible() const
void SetVertJustify(GR_TEXT_V_ALIGN_T aType)
virtual void SetVisible(bool aVisible)
double GetLineSpacing() const
virtual void SetText(const wxString &aText)
void SetHorizJustify(GR_TEXT_H_ALIGN_T aType)
EMBEDDED_FILES & operator=(EMBEDDED_FILES &&other) noexcept
EMBEDDED_FILE * AddFile(const wxFileName &aName, bool aOverwrite)
Load a file from disk and adds it to the collection.
bool m_embedFonts
If set, fonts will be embedded in the element on save.
ENUM_MAP & Map(T aValue, const wxString &aName)
static ENUM_MAP< T > & Instance()
ENUM_MAP & Undefined(T aValue)
wxString m_Filename
The 3D shape filename in 3D library.
Used when the right click button is pressed, or when the select tool is in effect.
const COLLECTORS_GUIDE * GetGuide() const
Class that other classes need to inherit from, in order to be inspectable.
wxAny Get(PROPERTY_BASE *aProperty) const
Represents an (ordered) list of JUMPER_GROUP objects.
void Add(JUMPER_GROUP aGroup)
Add a JUMPER_GROUP to the set.
Represents a group of jumper pins or pads, keyed by name.
A typed sum value used to carry the before/after of any single property.
wxString ToDisplayString() const
Human-readable representation with no unit context.
FONT is an abstract base class for both outline and stroke fonts.
virtual bool IsOutline() const
Implement outline font drawing.
EMBEDDING_PERMISSION GetEmbeddingPermission() const
virtual wxString GetClass() const =0
Return the class name.
static constexpr double LOD_HIDE
Return this constant from ViewGetLOD() to hide the item unconditionally.
static constexpr double LOD_SHOW
Return this constant from ViewGetLOD() to show the item unconditionally.
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
bool IsLayerVisible(int aLayer) const
Return information about visibility of a particular layer.
LSET is a set of PCB_LAYER_IDs.
static const LSET & AllCuMask()
return AllCuMask( MAX_CU_LAYERS );
static const LSET & SideSpecificMask()
LSEQ Seq(const LSEQ &aSequence) const
Return an LSEQ from the union of this LSET and a desired sequence.
static LSET AllCuMask(int aCuLayerCount)
Return a mask holding the requested number of Cu PCB_LAYER_IDs.
static const LSET & AllLayersMask()
static wxString Name(PCB_LAYER_ID aLayerId)
Return the fixed name association with aLayerId.
static const int ORPHANED
Constant that forces initialization of a netinfo item to the NETINFO_ITEM ORPHANED (typically -1) whe...
void ForEachUniqueLayer(const std::function< void(PCB_LAYER_ID)> &aMethod) const
Runs the given callable for each active unique copper layer in this padstack, meaning F_Cu for MODE::...
@ NORMAL
Shape is the same on all layers.
@ CUSTOM
Shapes can be defined on arbitrary layers.
@ FRONT_INNER_BACK
Up to three shapes can be defined (F_Cu, inner copper layers, B_Cu)
LSET GetLayerSet() const override
Return a std::bitset of all layers on which the item physically resides.
PAD_ATTRIB GetAttribute() const
const wxString & GetNumber() const
VECTOR2I GetDrillSize() const
PAD_SHAPE GetShape(PCB_LAYER_ID aLayer) const
int GetSolderMaskExpansion(PCB_LAYER_ID aLayer) const
VECTOR2I GetSize(PCB_LAYER_ID aLayer) const
const PADSTACK & Padstack() const
EDA_ANGLE GetOrientation() const
Return the rotation angle of the pad.
PAD_DRILL_SHAPE GetDrillShape() const
const std::shared_ptr< SHAPE_POLY_SET > & GetEffectivePolygon(PCB_LAYER_ID aLayer, ERROR_LOC aErrorLoc=ERROR_INSIDE) const
std::optional< int > GetLocalSolderMaskMargin() const
VECTOR2I GetSolderPasteMargin(PCB_LAYER_ID aLayer) const
Usually < 0 (mask shape smaller than pad)because the margin can be dependent on the pad size,...
A 3D body attached to a footprint (or, later, placed on a board).
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
A geometric constraint between board items (issue #2329).
wxString GetUntranslatedName() const
Get the untranslated field name for storage, variable look-up, etc.
void Serialize(google::protobuf::Any &aContainer) const override
Serializes this object to the given Any message.
bool Deserialize(const google::protobuf::Any &aContainer) override
Deserializes the given protobuf message into this object.
PCB_FIELD * CloneField() const
Same as Clone, but returns a PCB_FIELD item.
A set of BOARD_ITEMs (i.e., without duplicates).
A PCB_POINT is a 0-dimensional point that is used to mark a position on a PCB, or more usually a foot...
Object to handle a bitmap image that can be inserted in a PCB.
VECTOR2I GetLibraryBezierC1() const
int GetWidth() const override
void TransformShapeToPolySet(SHAPE_POLY_SET &aBuffer, PCB_LAYER_ID aLayer, int aClearance, int aError, ERROR_LOC aErrorLoc, KIGFX::RENDER_SETTINGS *aRenderSettings=nullptr) const override
Convert the item shape to a polyset.
VECTOR2I GetLibraryEnd() const
VECTOR2I GetLibraryStart() const
STROKE_PARAMS GetStroke() const override
SHAPE_POLY_SET GetLibraryPolyShape() const
VECTOR2I GetLibraryBezierC2() const
VECTOR2I GetLibraryArcMid() const
PCB_LAYER_ID GetLayer() const override
Return the primary layer this item is on.
bool IsBorderEnabled() const
Tests whether the border is disabled, as configured by the stroke.
void TransformTextToPolySet(SHAPE_POLY_SET &aBuffer, int aClearance, int aMaxError, ERROR_LOC aErrorLoc) const
Convert the text to a polygonSet describing the actual character strokes (one per segment).
EDA_ANGLE GetTextAngle() const override
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
int GetTextThickness() const override
void SetTextAngle(const EDA_ANGLE &aAngle) override
VECTOR2I GetTextSize() const override
PROPERTY_BASE & SetAvailableFunc(std::function< bool(INSPECTABLE *)> aFunc)
Set a callback function to determine whether an object provides this property.
PROPERTY_BASE(const wxString &aName, PROPERTY_DISPLAY aDisplay=PT_DEFAULT, ORIGIN_TRANSFORMS::COORD_TYPES_T aCoordType=ORIGIN_TRANSFORMS::NOT_A_COORD)
Used to generate unique IDs. Must come up front so it's initialized before ctor.
PROPERTY_BASE & SetGroup(const wxString &aGroup)
PROPERTY_BASE & SetIsCopyable(bool aIsCopyable=true)
virtual void SetChoices(const wxPGChoices &aChoices)
Set the possible values for for the property.
PROPERTY_BASE & SetIsHiddenFromLibraryEditors(bool aIsHidden=true)
void InheritsAfter(TYPE_ID aDerived, TYPE_ID aBase)
Declare an inheritance relationship between types.
static PROPERTY_MANAGER & Instance()
PROPERTY_BASE & AddProperty(PROPERTY_BASE *aProperty, const wxString &aGroup=wxEmptyString)
Register a property.
PROPERTY_BASE * GetProperty(TYPE_ID aType, const wxString &aProperty) const
Return a property for a specific type.
bool IsAvailableFor(TYPE_ID aItemClass, PROPERTY_BASE *aProp, INSPECTABLE *aItem)
Checks overriden availability and original availability of a property, returns false if the property ...
PROPERTY_BASE & ReplaceProperty(size_t aBase, const wxString &aName, PROPERTY_BASE *aNew, const wxString &aGroup=wxEmptyString)
Replace an existing property for a specific type.
void AddTypeCast(TYPE_CAST_BASE *aCast)
Register a type converter.
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
Represent a set of closed polygons.
int AddOutline(const SHAPE_LINE_CHAIN &aOutline)
Adds a new outline to the set and returns its index.
bool Collide(const SHAPE *aShape, int aClearance=0, int *aActual=nullptr, VECTOR2I *aLocation=nullptr) const override
Check if the boundary of shape (this) lies closer to the shape aShape than aClearance,...
int TotalVertices() const
Return total number of vertices stored in the set.
int FullPointCount() const
Return the number of points in the shape poly set.
int Append(int x, int y, int aOutline=-1, int aHole=-1, bool aAllowDuplication=false)
Appends a vertex at the end of the given outline/hole (default: the last outline)
SHAPE_LINE_CHAIN & Outline(int aIndex)
Return the reference to aIndex-th outline in the set.
int NewOutline()
Creates a new empty polygon in the set and returns its index.
void BooleanIntersection(const SHAPE_POLY_SET &b)
Perform boolean polyset intersection.
const VECTOR2I & CVertex(int aIndex, int aOutline, int aHole) const
Return the index-th vertex in a given hole outline within a given outline.
int OutlineCount() const
Return the number of outlines in the set.
const SHAPE_LINE_CHAIN & COutline(int aIndex) const
Represent a simple polygon consisting of a zero-thickness closed chain of connected line segments.
Handle a list of polygons defining a copper zone.
bool SetNetCode(int aNetCode, bool aNoAssert) override
Override that clamps the netcode to 0 when this zone is in copper-thieving fill mode.
virtual LSET GetLayerSet() const override
Return a std::bitset of all layers on which the item physically resides.
SHAPE_POLY_SET GetLibraryOutline() const
unsigned GetAssignedPriority() const
This file is part of the common library.
bool ConvertOutlineToPolygon(std::vector< PCB_SHAPE * > &aShapeList, SHAPE_POLY_SET &aPolygons, int aErrorMax, int aChainingEpsilon, bool aAllowDisjoint, OUTLINE_ERROR_HANDLER *aErrorHandler, bool aAllowUseArcsInPolygons)
Build a polygon set with holes from a PCB_SHAPE list.
const std::function< void(const wxString &msg, BOARD_ITEM *itemA, BOARD_ITEM *itemB, const VECTOR2I &pt)> OUTLINE_ERROR_HANDLER
void BuildConvexHull(std::vector< VECTOR2I > &aResult, const std::vector< VECTOR2I > &aPoly)
Calculate the convex hull of a list of points in counter-clockwise order.
@ CHAMFER_ACUTE_CORNERS
Acute angles are chamfered.
static constexpr EDA_ANGLE ANGLE_0
static constexpr EDA_ANGLE ANGLE_180
const INSPECTOR_FUNC & INSPECTOR
std::function passed to nested users by ref, avoids copying std::function.
#define COURTYARD_CONFLICT
temporary set when moving footprints having courtyard overlapping
#define MALFORMED_F_COURTYARD
#define MALFORMED_B_COURTYARD
#define STRUCT_DELETED
flag indication structures to be erased
#define MALFORMED_COURTYARDS
@ FRAME_FOOTPRINT_CHOOSER
a few functions useful in geometry calculations.
const wxChar *const traceApi
Flag to enable debug output related to the IPC API and its plugin system.
Some functions to handle hotkeys in KiCad.
FLASHING
Enum used during connectivity building to ensure we do not query connectivity while building the data...
bool IsBackLayer(PCB_LAYER_ID aLayerId)
Layer classification: check if it's a back layer.
@ LAYER_CONFLICTS_SHADOW
Shadow layer for items flagged conflicting.
@ LAYER_FOOTPRINTS_FR
Show footprints on front.
@ LAYER_FP_REFERENCES
Show footprints references (when texts are visible).
@ LAYER_FOOTPRINTS_BK
Show footprints on back.
@ LAYER_ANCHOR
Anchor of items having an anchor point (texts, footprints).
@ LAYER_FP_VALUES
Show footprints values (when texts are visible).
PCB_LAYER_ID
A quick note on layer IDs:
bool IsValidLayer(int aLayerId)
Test whether a given integer is a valid layer index, i.e.
const wxString & GetLibFilenameForbiddenChars()
Characters illegal in a footprint library filename.
This file contains miscellaneous commonly used macros and functions.
#define KI_FALLTHROUGH
The KI_FALLTHROUGH macro is to be used when switch statement cases should purposely fallthrough from ...
constexpr void MIRROR(T &aPoint, const T &aMirrorRef)
Updates aPoint with the mirror of aPoint relative to the aMirrorRef.
@ LEFT_RIGHT
Flip left to right (around the Y axis)
@ TOP_BOTTOM
Flip top to bottom (around the X axis)
DIFF_VALUE WxAnyToDiffValue(const wxAny &aValue, PROPERTY_BASE *aProperty)
Convert a wxAny value read from a PROPERTY_BASE getter into a DIFF_VALUE that the engine can store,...
bool BoxHitTest(const VECTOR2I &aHitPoint, const BOX2I &aHittee, int aAccuracy)
Perform a point-to-box hit test.
wxString GetRefDesPrefix(const wxString &aRefDes)
Get the (non-numeric) prefix from a refdes - e.g.
bool contains(const _Container &__container, _Value __value)
Returns true if the container contains the given value.
void PackEmbeddedFiles(common::types::EmbeddedFiles &aOutput, const EMBEDDED_FILES &aFiles)
bool UnpackEmbeddedFiles(EMBEDDED_FILES &aOutput, const common::types::EmbeddedFiles &aProto)
KICOMMON_API int UnpackDistance(const types::Distance &aInput, const EDA_IU_SCALE &aScale)
KICOMMON_API KIID_PATH UnpackSheetPath(const types::SheetPath &aInput)
KICOMMON_API std::optional< KICAD_T > TypeNameFromAny(const google::protobuf::Any &aMessage)
KICOMMON_API VECTOR3D UnpackVector3D(const types::Vector3D &aInput)
KICOMMON_API void PackCustomProperties(google::protobuf::RepeatedPtrField< types::CustomProperty > *aOutput, const EDA_ITEM &aItem)
KICOMMON_API void PackDistance(types::Distance &aOutput, int aInput, const EDA_IU_SCALE &aScale)
KICOMMON_API void PackSheetPath(types::SheetPath &aOutput, const KIID_PATH &aInput)
KICOMMON_API void PackLibId(types::LibraryIdentifier *aOutput, const LIB_ID &aId)
KICOMMON_API LIB_ID UnpackLibId(const types::LibraryIdentifier &aId)
KICOMMON_API void UnpackCustomProperties(const google::protobuf::RepeatedPtrField< types::CustomProperty > &aInput, EDA_ITEM &aItem)
KICOMMON_API void PackVector3D(types::Vector3D &aOutput, const VECTOR3D &aInput)
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
@ NPTH
like PAD_PTH, but not plated mechanical use only, no connection allowed
@ NON_COMPONENT
Pad with no hole that does not connect to a physical component, but rather provides a connection poin...
@ SMD
Smd pad, appears on the solder paste layer (default)
@ PTH
Plated through hole pad.
@ CONN
Like smd, does not appear on the solder paste layer (default) Note: also has a special attribute in G...
@ FIDUCIAL_LOCAL
a fiducial (usually a smd) local to the parent footprint
@ FIDUCIAL_GLBL
a fiducial (usually a smd) for the full board
@ MECHANICAL
a pad used for mechanical support
@ PRESSFIT
a PTH with a hole diameter with tight tolerances for press fit pin
@ HEATSINK
a pad used as heat sink, usually in SMD footprints
@ NONE
no special fabrication property
@ TESTPOINT
a test point pad
@ CASTELLATED
a pad with a castellated through hole
@ BGA
Smd pad, used in BGA footprints.
BARCODE class definition.
Class to handle a set of BOARD_ITEMs.
#define TYPE_HASH(x)
Macro to generate unique identifier for a type.
#define NO_SETTER(owner, type)
Macro to define read-only fields (no setter method available)
#define ENUM_TO_WXANY(type)
@ PT_DEGREE
Angle expressed in degrees.
@ PT_SIZE
Size expressed in distance units (mm/inch)
#define REGISTER_TYPE(x)
Helper macro to map type hashes to names.
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Collection of utility functions for component reference designators (refdes)
std::vector< FAB_LAYER_COLOR > dummy
int StrNumCmp(const wxString &aString1, const wxString &aString2, CMP_T aCaseSensitivity)
Compare two strings with alphanumerical content.
wxString GetDefaultVariantName()
int GetTrailingInt(const wxString &aStr)
Gets the trailing int, if any, from a string.
wxString UnescapeString(const wxString &aSource)
A structure for storing weighted search terms.
wxString GetDefaultFieldName(FIELD_T aFieldId, TRANSLATION aTranslation)
Return a default symbol field name for a mandatory field type.
FIELD_T
The set of all field indices assuming an array like sequence that a SCH_COMPONENT or LIB_PART can hol...
@ USER
The field ID hasn't been set yet; field is invalid.
@ DESCRIPTION
Field Description of part, i.e. "1/4W 1% Metal Film Resistor".
@ DATASHEET
name of datasheet
@ REFERENCE
Field Reference of part, i.e. "IC21".
@ VALUE
Field Value of part, i.e. "3.3K".
static EDA_ORIENTATION orientation(double d)
void RotatePoint(int *pX, int *pY, const EDA_ANGLE &aAngle)
Calculate the new point of coord coord pX, pY, for a rotation center 0, 0.
constexpr KICAD_T BaseType(const KICAD_T aType)
Return the underlying type of the given type.
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
@ PCB_CONSTRAINT_T
a geometric constraint between board items
@ PCB_SHAPE_T
class PCB_SHAPE, a segment not on copper layers
@ PCB_DIM_ORTHOGONAL_T
class PCB_DIM_ORTHOGONAL, a linear dimension constrained to x/y
@ PCB_DIM_LEADER_T
class PCB_DIM_LEADER, a leader dimension (graphic item)
@ PCB_VIA_T
class PCB_VIA, a via (like a track segment on a copper layer)
@ PCB_DIM_CENTER_T
class PCB_DIM_CENTER, a center point marking (graphic item)
@ PCB_GROUP_T
class PCB_GROUP, a set of BOARD_ITEMs
@ PCB_TEXTBOX_T
class PCB_TEXTBOX, wrapped text on a layer
@ PCB_ZONE_T
class ZONE, a copper pour area
@ PCB_TEXT_T
class PCB_TEXT, text on a layer
@ PCB_3D_BODY_T
class PCB_3D_BODY, a 3D body (extruded or model) on a footprint
@ PCB_REFERENCE_IMAGE_T
class PCB_REFERENCE_IMAGE, bitmap on a layer
@ PCB_FIELD_T
class PCB_FIELD, text associated with a footprint property
@ PCB_MARKER_T
class PCB_MARKER, a marker used to show something
@ PCB_BARCODE_T
class PCB_BARCODE, a barcode (graphic item)
@ PCB_TABLECELL_T
class PCB_TABLECELL, PCB_TEXTBOX for use in tables
@ PCB_FOOTPRINT_T
class FOOTPRINT, a footprint
@ PCB_DIM_ALIGNED_T
class PCB_DIM_ALIGNED, a linear dimension (graphic item)
@ PCB_PAD_T
class PAD, a pad in a footprint
@ PCB_ARC_T
class PCB_ARC, an arc track segment on a copper layer
@ PCB_DIMENSION_T
class PCB_DIMENSION_BASE: abstract dimension meta-type
@ PCB_TABLE_T
class PCB_TABLE, table of PCB_TABLECELLs
@ PCB_POINT_T
class PCB_POINT, a 0-dimensional point
@ PCB_TRACE_T
class PCB_TRACK, a track segment (segment on a copper layer)
@ PCB_DIM_RADIAL_T
class PCB_DIM_RADIAL, a radius or diameter dimension
VECTOR2< int32_t > VECTOR2I
static PIECE rect(double aLeft, double aTop, double aRight, double aBottom, bool aMixed=false)
ZONE_CONNECTION
How pads are covered by copper in zone.
@ THERMAL
Use thermal relief for pads.
@ THT_THERMAL
Thermal relief only for THT pads.
@ NONE
Pads are not covered.
@ FULL
pads are covered by copper