25#include <magic_enum.hpp>
29#include <unordered_set>
33#include <wx/tokenzr.h>
72#include <google/protobuf/any.pb.h>
73#include <api/board/board_types.pb.h>
173 std::map<EDA_ITEM*, EDA_ITEM*> ptrMap;
178 if( field->IsMandatory() )
180 PCB_FIELD* existingField = GetField( field->GetId() );
181 ptrMap[field] = existingField;
182 *existingField = *field;
183 existingField->SetParent( this );
187 PCB_FIELD* newField = static_cast<PCB_FIELD*>( field->Clone() );
188 ptrMap[field] = newField;
194 for(
PAD*
pad : aFootprint.Pads() )
196 PAD* newPad = static_cast<PAD*>( pad->Clone() );
197 ptrMap[ pad ] = newPad;
198 Add( newPad, ADD_MODE::APPEND );
202 for(
ZONE* zone : aFootprint.Zones() )
204 ZONE* newZone = static_cast<ZONE*>( zone->Clone() );
205 ptrMap[ zone ] = newZone;
206 Add( newZone, ADD_MODE::APPEND );
212 newZone->SetNetCode( -1 );
216 for(
BOARD_ITEM* item : aFootprint.GraphicalItems() )
218 BOARD_ITEM* newItem = static_cast<BOARD_ITEM*>( item->Clone() );
219 ptrMap[ item ] = newItem;
220 Add( newItem, ADD_MODE::APPEND );
226 PCB_GROUP* newGroup = static_cast<PCB_GROUP*>( group->Clone() );
227 ptrMap[ group ] = newGroup;
228 Add( newGroup, ADD_MODE::APPEND );
231 for(
PCB_POINT* point : aFootprint.Points() )
233 PCB_POINT* newPoint = static_cast<PCB_POINT*>( point->Clone() );
234 ptrMap[ point ] = newPoint;
235 Add( newPoint, ADD_MODE::APPEND );
241 PCB_GROUP* newGroup = static_cast<PCB_GROUP*>( ptrMap[ group ] );
243 newGroup->GetItems().clear();
245 for( EDA_ITEM* member : group->GetItems() )
247 if( ptrMap.count( member ) )
248 newGroup->AddItem( ptrMap[ member ] );
252 for(
auto& [
name, file ] : aFootprint.EmbeddedFileMap() )
261 *
this = std::move( aFootprint );
301 board->IncrementTimeStamp();
308 types::FootprintInstance footprint;
310 footprint.mutable_id()->set_value(
m_Uuid.AsStdString() );
311 footprint.mutable_position()->set_x_nm(
GetPosition().x );
312 footprint.mutable_position()->set_y_nm(
GetPosition().y );
315 footprint.set_locked(
IsLocked() ? kiapi::common::types::LockedState::LS_LOCKED
316 : kiapi::common::types::LockedState::LS_UNLOCKED );
318 google::protobuf::Any buf;
320 buf.UnpackTo( footprint.mutable_reference_field() );
322 buf.UnpackTo( footprint.mutable_value_field() );
324 buf.UnpackTo( footprint.mutable_datasheet_field() );
326 buf.UnpackTo( footprint.mutable_description_field() );
328 types::FootprintAttributes* attrs = footprint.mutable_attributes();
334 attrs->set_do_not_populate(
IsDNP() );
338 attrs->set_mounting_style( types::FootprintMountingStyle::FMS_THROUGH_HOLE );
340 attrs->set_mounting_style( types::FootprintMountingStyle::FMS_SMD );
342 attrs->set_mounting_style( types::FootprintMountingStyle::FMS_UNSPECIFIED );
344 types::Footprint* def = footprint.mutable_definition();
349 def->mutable_attributes()->set_keywords(
GetKeywords().ToUTF8() );
353 types::FootprintDesignRuleOverrides* overrides = footprint.mutable_overrides();
367 overrides->set_zone_connection(
372 types::NetTieDefinition* netTie = def->add_net_ties();
373 wxStringTokenizer tokenizer(
group,
", \t\r\n", wxTOKEN_STRTOK );
375 while( tokenizer.HasMoreTokens() )
376 netTie->add_pad_number( tokenizer.GetNextToken().ToUTF8() );
382 types::JumperSettings* jumpers = def->mutable_jumpers();
387 types::JumperGroup* jumperGroup = jumpers->add_groups();
389 for(
const wxString& padName :
group )
390 jumperGroup->add_pad_names( padName.ToUTF8() );
395 if( item->IsMandatory() )
398 google::protobuf::Any* itemMsg = def->add_items();
399 item->Serialize( *itemMsg );
402 for(
const PAD* item :
Pads() )
404 google::protobuf::Any* itemMsg = def->add_items();
405 item->Serialize( *itemMsg );
410 google::protobuf::Any* itemMsg = def->add_items();
411 item->Serialize( *itemMsg );
416 google::protobuf::Any* itemMsg = def->add_items();
417 item->Serialize( *itemMsg );
422 google::protobuf::Any* itemMsg = def->add_items();
423 types::Footprint3DModel modelMsg;
424 modelMsg.set_filename(
model.m_Filename.ToUTF8() );
428 modelMsg.set_visible(
model.m_Show );
429 modelMsg.set_opacity(
model.m_Opacity );
430 itemMsg->PackFrom( modelMsg );
435 footprint.set_symbol_sheet_name(
m_sheetname.ToUTF8() );
436 footprint.set_symbol_sheet_filename(
m_sheetfile.ToUTF8() );
437 footprint.set_symbol_footprint_filters(
m_filters.ToUTF8() );
439 aContainer.PackFrom( footprint );
446 types::FootprintInstance footprint;
448 if( !aContainer.UnpackTo( &footprint ) )
455 SetLocked( footprint.locked() == kiapi::common::types::LockedState::LS_LOCKED );
457 google::protobuf::Any buf;
458 types::Field mandatoryField;
460 if( footprint.has_reference_field() )
462 mandatoryField = footprint.reference_field();
464 buf.PackFrom( mandatoryField );
468 if( footprint.has_value_field() )
470 mandatoryField = footprint.value_field();
472 buf.PackFrom( mandatoryField );
476 if( footprint.has_datasheet_field() )
478 mandatoryField = footprint.datasheet_field();
480 buf.PackFrom( mandatoryField );
484 if( footprint.has_description_field() )
486 mandatoryField = footprint.description_field();
488 buf.PackFrom( mandatoryField );
494 switch( footprint.attributes().mounting_style() )
496 case types::FootprintMountingStyle::FMS_THROUGH_HOLE:
500 case types::FootprintMountingStyle::FMS_SMD:
508 SetBoardOnly( footprint.attributes().not_in_schematic() );
512 SetDNP( footprint.attributes().do_not_populate() );
519 SetKeywords( footprint.definition().attributes().keywords() );
521 const types::FootprintDesignRuleOverrides& overrides = footprint.overrides();
523 if( overrides.has_copper_clearance() )
528 if( overrides.has_solder_mask() && overrides.solder_mask().has_solder_mask_margin() )
533 if( overrides.has_solder_paste() )
535 const types::SolderPasteOverrides& pasteSettings = overrides.solder_paste();
537 if( pasteSettings.has_solder_paste_margin() )
542 if( pasteSettings.has_solder_paste_margin_ratio() )
552 for(
const types::NetTieDefinition& netTieMsg : footprint.definition().net_ties() )
556 for(
const std::string&
pad : netTieMsg.pad_number() )
557 group.Append( wxString::Format( wxT(
"%s, " ),
pad ) );
566 for(
const types::JumperGroup& groupMsg : footprint.definition().jumpers().groups() )
568 std::set<wxString>
group;
570 for(
const std::string& padName : groupMsg.pad_names() )
571 group.insert( wxString::FromUTF8( padName ) );
579 for(
int layerMsg : footprint.definition().private_layers() )
584 privateLayers.
set( layer );
590 m_sheetname = wxString::FromUTF8( footprint.symbol_sheet_name() );
591 m_sheetfile = wxString::FromUTF8( footprint.symbol_sheet_filename() );
592 m_filters = wxString::FromUTF8( footprint.symbol_footprint_filters() );
597 if( !field->IsMandatory() )
603 board->UncacheChildrenById(
this );
612 for(
const google::protobuf::Any& itemMsg : footprint.definition().items() )
620 if( itemMsg.type_url() ==
"type.googleapis.com/kiapi.board.types.Footprint3DModel" )
622 types::Footprint3DModel modelMsg;
624 if( !itemMsg.UnpackTo( &modelMsg ) )
629 model.m_Filename = wxString::FromUTF8( modelMsg.filename() );
630 model.m_Show = modelMsg.visible();
631 model.m_Opacity = modelMsg.opacity();
640 wxLogTrace(
traceApi, wxString::Format( wxS(
"Attempting to unpack unknown type %s "
641 "from footprint message, skipping" ),
642 itemMsg.type_url() ) );
650 if( item && item->Deserialize( itemMsg ) )
662 if( field->GetId() == aFieldType )
677 if( field->GetId() == aFieldType )
687 return GetField( aFieldName ) !=
nullptr;
695 if( field->GetName() == aFieldName )
711 if( !field->IsVisible() || field->GetText().IsEmpty() )
715 aVector.push_back( field );
718 std::sort( aVector.begin(), aVector.end(),
721 return lhs->GetOrdinal() < rhs->GetOrdinal();
731 ordinal = std::max( ordinal, field->GetOrdinal() + 1 );
738 bool aStyleShapes,
bool aStyleDimensions,
bool aStyleBarcodes )
743 field->StyleFromSettings(
board.GetDesignSettings(),
true );
748 switch( item->Type() )
753 item->StyleFromSettings(
board.GetDesignSettings(),
true );
758 if( aStyleShapes && !item->IsOnCopperLayer() )
759 item->StyleFromSettings(
board.GetDesignSettings(),
true );
768 if( aStyleDimensions )
769 item->StyleFromSettings(
board.GetDesignSettings(),
true );
775 item->StyleFromSettings(
board.GetDesignSettings(),
true );
788 std::vector< BOARD_ITEM* > item_list;
791 item_list.push_back( field );
794 item_list.push_back(
pad );
797 item_list.push_back( gr_item );
802 item_list.push_back(
group );
806 item_list.push_back( zone );
810 item_list.push_back( point );
812 bool changed =
false;
818 item->ResetUuidDirect();
855 board->UncacheChildrenById(
this );
863 for(
PCB_FIELD* field : aOther.m_fields )
866 aOther.m_fields.clear();
874 for(
PAD*
pad : aOther.Pads() )
877 aOther.Pads().clear();
885 for(
ZONE* item : aOther.Zones() )
893 item->SetNetCode( -1 );
896 aOther.Zones().clear();
904 for(
BOARD_ITEM* item : aOther.GraphicalItems() )
907 aOther.GraphicalItems().clear();
918 aOther.Groups().clear();
926 for(
PCB_POINT* point : aOther.Points() )
929 aOther.Points().clear();
943 aOther.m_componentClassCacheProxy->GetStaticComponentClass() );
946 aOther.m_fields.clear();
947 aOther.Pads().clear();
948 aOther.Zones().clear();
949 aOther.GraphicalItems().clear();
950 aOther.m_initial_comments =
nullptr;
984 board->UncacheChildrenById(
this );
986 std::map<EDA_ITEM*, EDA_ITEM*> ptrMap;
997 ptrMap[field] = newField;
1010 ptrMap[
pad ] = newPad;
1022 ZONE* newZone =
static_cast<ZONE*
>( zone->Clone() );
1023 ptrMap[ zone ] = newZone;
1042 ptrMap[ item ] = newItem;
1058 newGroup->
AddItem( ptrMap[ member ] );
1072 ptrMap[ point ] = newItem;
1103 *
this = *
static_cast<const FOOTPRINT*
>( aOther );
1130 aVars->push_back( wxT(
"REFERENCE" ) );
1131 aVars->push_back( wxT(
"VALUE" ) );
1132 aVars->push_back( wxT(
"LAYER" ) );
1133 aVars->push_back( wxT(
"FOOTPRINT_LIBRARY" ) );
1134 aVars->push_back( wxT(
"FOOTPRINT_NAME" ) );
1135 aVars->push_back( wxT(
"SHORT_NET_NAME(<pad_number>)" ) );
1136 aVars->push_back( wxT(
"NET_NAME(<pad_number>)" ) );
1137 aVars->push_back( wxT(
"NET_CLASS(<pad_number>)" ) );
1138 aVars->push_back( wxT(
"PIN_NAME(<pad_number>)" ) );
1147 if( token->IsSameAs( wxT(
"REFERENCE" ) ) )
1152 else if( token->IsSameAs( wxT(
"VALUE" ) ) )
1157 else if( token->IsSameAs( wxT(
"LAYER" ) ) )
1162 else if( token->IsSameAs( wxT(
"FOOTPRINT_LIBRARY" ) ) )
1164 *token =
m_fpid.GetUniStringLibNickname();
1167 else if( token->IsSameAs( wxT(
"FOOTPRINT_NAME" ) ) )
1169 *token =
m_fpid.GetUniStringLibItemName();
1172 else if( token->StartsWith( wxT(
"SHORT_NET_NAME(" ) )
1173 || token->StartsWith( wxT(
"NET_NAME(" ) )
1174 || token->StartsWith( wxT(
"NET_CLASS(" ) )
1175 || token->StartsWith( wxT(
"PIN_NAME(" ) ) )
1177 wxString padNumber = token->AfterFirst(
'(' );
1178 padNumber = padNumber.BeforeLast(
')' );
1182 if(
pad->GetNumber() == padNumber )
1184 if( token->StartsWith( wxT(
"SHORT_NET_NAME" ) ) )
1185 *token =
pad->GetShortNetname();
1186 else if( token->StartsWith( wxT(
"NET_NAME" ) ) )
1187 *token =
pad->GetNetname();
1188 else if( token->StartsWith( wxT(
"NET_CLASS" ) ) )
1189 *token =
pad->GetNetClassName();
1191 *token =
pad->GetPinFunction();
1199 *token = field->GetShownText(
false, aDepth + 1 );
1218 return it !=
m_variants.end() ? &it->second :
nullptr;
1226 return it !=
m_variants.end() ? &it->second :
nullptr;
1232 if( aVariant.
GetName().IsEmpty()
1244 it->second = std::move( updated );
1254 if( aVariantName.IsEmpty()
1257 wxASSERT_MSG(
false, wxT(
"Variant name cannot be empty or default." ) );
1271 auto inserted =
m_variants.emplace( aVariantName, std::move( variant ) );
1272 return &inserted.first->second;
1284 if( aNewName.IsEmpty()
1295 auto existingIt =
m_variants.find( aNewName );
1297 if( existingIt !=
m_variants.end() && existingIt != it )
1300 if( it->first == aNewName )
1306 m_variants.emplace( aNewName, std::move( variant ) );
1325 return variant->
GetDNP();
1377 return field->GetText();
1401 switch( aBoardItem->
Type() )
1427 m_pads.push_back(
static_cast<PAD*
>( aBoardItem ) );
1429 m_pads.push_front(
static_cast<PAD*
>( aBoardItem ) );
1435 m_zones.push_back(
static_cast<ZONE*
>( aBoardItem ) );
1450 wxFAIL_MSG( wxT(
"FOOTPRINT::Add(): Markers go at the board level, even in the footprint editor" ) );
1454 wxFAIL_MSG( wxT(
"FOOTPRINT::Add(): Nested footprints not supported" ) );
1466 wxFAIL_MSG( wxString::Format( wxT(
"FOOTPRINT::Add(): BOARD_ITEM type (%d) not handled" ),
1467 aBoardItem->
Type() ) );
1478 board->CacheItemSubtreeById( aBoardItem );
1486 switch( aBoardItem->
Type() )
1491 if( *it == aBoardItem )
1513 if( *it == aBoardItem )
1523 for(
auto it =
m_pads.begin(); it !=
m_pads.end(); ++it )
1525 if( *it ==
static_cast<PAD*
>( aBoardItem ) )
1537 if( *it ==
static_cast<ZONE*
>( aBoardItem ) )
1549 if( *it ==
static_cast<PCB_GROUP*
>( aBoardItem ) )
1559 wxFAIL_MSG( wxT(
"FOOTPRINT::Remove(): Markers go at the board level, even in the footprint editor" ) );
1563 wxFAIL_MSG( wxT(
"FOOTPRINT::Remove(): Nested footprints not supported" ) );
1569 if( *it ==
static_cast<PCB_POINT*
>( aBoardItem ) )
1579 wxFAIL_MSG( wxString::Format( wxT(
"FOOTPRINT::Remove() needs work: BOARD_ITEM type (%d) not handled" ),
1580 aBoardItem->
Type() ) );
1585 board->UncacheItemSubtreeById( aBoardItem );
1610 switch(
pad->GetProperty() )
1628 switch(
pad->GetAttribute() )
1635 if(
pad->IsOnCopperLayer() )
1663 return _(
"Through hole" );
1665 return _(
"Other" );
1678 wxStringTokenizer keywordTokenizer(
GetKeywords(), wxS(
" \t\r\n" ), wxTOKEN_STRTOK );
1680 while( keywordTokenizer.HasMoreTokens() )
1701 if(
dummy.IsFlipped() )
1705 bbox.
Merge(
pad->GetBoundingBox() );
1757 std::vector<PCB_TEXT*> texts;
1758 bool isFPEdit =
board &&
board->IsFootprintHolder();
1779 texts.push_back(
static_cast<PCB_TEXT*
>( item ) );
1797 bbox.
Merge( item->GetBoundingBox() );
1803 if( field->IsReference() || field->IsValue() )
1806 texts.push_back( field );
1810 bbox.
Merge(
pad->GetBoundingBox() );
1813 bbox.
Merge( zone->GetBoundingBox() );
1816 bbox.
Merge( point->GetBoundingBox() );
1821 if( aIncludeText || noDrawItems )
1838 bool valueLayerIsVisible =
true;
1839 bool refLayerIsVisible =
true;
1857 if( (
Value().IsVisible() && valueLayerIsVisible ) || noDrawItems )
1862 if( (
Reference().IsVisible() && refLayerIsVisible ) || noDrawItems )
1875 if( aIncludeText || noDrawItems )
1893 std::vector<PCB_TEXT*> texts;
1895 bool isFPEdit =
board &&
board->IsFootprintHolder();
1905 if( ( aLayers & item->GetLayerSet() ).none() )
1913 bbox.
Merge( item->GetBoundingBox() );
1918 if( ( aLayers &
pad->GetLayerSet() ).none() )
1921 bbox.
Merge(
pad->GetBoundingBox() );
1926 if( ( aLayers & zone->GetLayerSet() ).none() )
1929 bbox.
Merge( zone->GetBoundingBox() );
1937 if( ( aLayers & point->GetLayerSet() ).none() )
1940 bbox.
Merge( point->GetBoundingBox() );
1950 bool isFPEdit =
board &&
board->IsFootprintHolder();
1976 pad->Padstack().ForEachUniqueLayer(
1990 const SHAPE_POLY_SET& layerPoly = *zone->GetFilledPolysList( layer );
2006 const int halfsize =
pcbIUScale.mmToIU( 1.0 );
2017 std::vector<VECTOR2I> convex_hull;
2026 for(
const VECTOR2I& pt : convex_hull )
2039 bool isFPEdit =
board &&
board->IsFootprintHolder();
2049 if( item->IsOnLayer( aLayer ) )
2063 if(
pad->IsOnLayer( aLayer ) )
2069 if( zone->GetIsRuleArea() )
2072 if( zone->IsOnLayer( aLayer ) )
2074 const std::shared_ptr<SHAPE_POLY_SET>& layerPoly = zone->GetFilledPolysList( aLayer );
2076 for(
int ii = 0; ii < layerPoly->OutlineCount(); ii++ )
2077 rawPolys.
AddOutline( layerPoly->COutline( ii ) );
2081 std::vector<VECTOR2I> convex_hull;
2086 for(
const VECTOR2I& pt : convex_hull )
2099 variant =
board->GetCurrentVariant();
2113 aList.emplace_back(
_(
"Footprint Name" ),
GetFPID().GetLibItemName().wx_str() );
2115 aList.emplace_back(
_(
"Pads" ), wxString::Format( wxT(
"%zu" ), padCount ) );
2118 wxString::Format(
_(
"Keywords: %s" ),
GetKeywords() ) );
2127 case F_Cu: aList.emplace_back(
_(
"Board Side" ),
_(
"Front" ) );
break;
2128 case B_Cu: aList.emplace_back(
_(
"Board Side" ),
_(
"Back (Flipped)" ) );
break;
2132 aList.emplace_back(
_(
"Rotation" ), wxString::Format( wxT(
"%.4g" ),
GetOrientation().AsDegrees() ) );
2134 auto addToken = []( wxString* aStr,
const wxString& aAttr )
2136 if( !aStr->IsEmpty() )
2137 *aStr += wxT(
", " );
2146 addToken( &status,
_(
"Locked" ) );
2149 addToken( &status,
_(
"autoplaced" ) );
2152 addToken( &attrs,
_(
"not in schematic" ) );
2155 addToken( &attrs,
_(
"exclude from pos files" ) );
2158 addToken( &attrs,
_(
"exclude from BOM" ) );
2161 addToken( &attrs,
_(
"DNP" ) );
2163 aList.emplace_back(
_(
"Status: " ) + status,
_(
"Attributes:" ) + wxS(
" " ) + attrs );
2167 aList.emplace_back(
_(
"Component Class" ),
2171 msg.Printf(
_(
"Footprint: %s" ),
m_fpid.GetUniStringLibId() );
2173 aList.emplace_back( msg, msg2 );
2177 aList.emplace_back( msg, msg2 );
2185 if(
board->IsFootprintHolder() )
2217 if(
pad->IsOnLayer( aLayer ) )
2223 if( zone->IsOnLayer( aLayer ) )
2229 if( field->IsOnLayer( aLayer ) )
2235 if( item->IsOnLayer( aLayer ) )
2247 if(
pad->IsOnLayer( aLayer ) &&
pad->HitTest( aPosition, aAccuracy ) )
2253 if( zone->IsOnLayer( aLayer ) && zone->HitTest( aPosition, aAccuracy ) )
2259 if( item->Type() !=
PCB_TEXT_T && item->IsOnLayer( aLayer )
2260 && item->HitTest( aPosition, aAccuracy ) )
2272 std::vector<BOARD_ITEM*> items;
2276 if(
pad->IsOnLayer( aLayer ) )
2277 items.push_back(
pad );
2282 if( zone->IsOnLayer( aLayer ) )
2283 items.push_back( zone );
2288 if( item->Type() !=
PCB_TEXT_T && item->IsOnLayer( aLayer ) )
2289 items.push_back( item );
2298 if( !aContained && item->HitTest( aRect, aContained, aAccuracy ) )
2300 else if( aContained && !item->HitTest( aRect, aContained, aAccuracy ) )
2307 return !items.empty() && aContained;
2326 BOX2I arect = aRect;
2346 if(
pad->HitTest( arect,
false, 0 ) )
2352 if( zone->HitTest( arect,
false, 0 ) )
2358 if( point->HitTest( arect,
false, 0 ) )
2369 if( item->Type() !=
PCB_TEXT_T && item->HitTest( arect,
false, 0 ) )
2383 using std::ranges::all_of;
2384 using std::ranges::any_of;
2391 [&](
const auto* aItem )
2393 return aItem && aItem->HitTest( aPoly, aContained );
2399 auto drawings =
m_drawings | std::views::filter( [](
const auto* aItem )
2410 return all_of( drawings, hitTest )
2411 && all_of(
m_pads, hitTest )
2412 && all_of(
m_zones, hitTest );
2417 return any_of( drawings, hitTest )
2418 || any_of(
m_pads, hitTest )
2419 || any_of(
m_zones, hitTest );
2426 bool can_select = aSearchAfterMe ? false :
true;
2430 if( !can_select &&
pad == aSearchAfterMe )
2436 if( can_select &&
pad->GetNumber() == aPadNumber )
2448 if(
pad->m_Uuid == aUuid )
2461 if( !(
pad->GetLayerSet() & aLayerMask ).any() )
2464 if(
pad->HitTest( aPosition ) )
2474 std::vector<const PAD*> retv;
2478 if( ( aIgnore && aIgnore ==
pad ) || (
pad->GetNumber() != aPadNumber ) )
2481 retv.push_back(
pad );
2509 std::set<wxString> usedNumbers;
2521 if(
pad->GetNumber().IsEmpty() )
2531 usedNumbers.insert(
pad->GetNumber() );
2552 auto isElectricalPadNumber = [](
const wxString& num ) ->
bool
2559 while( i < num.size() && wxIsalpha( num[i] ) )
2567 if( i == num.size() )
2570 for(
size_t j = i; j < num.size(); ++j )
2572 if( !wxIsdigit( num[j] ) )
2579 std::set<wxString> counted;
2591 const wxString& num =
pad->GetNumber();
2593 if( isElectricalPadNumber( num ) )
2594 counted.insert( num );
2597 return static_cast<unsigned>( counted.size() );
2603 if(
nullptr == a3DModel )
2646 const std::vector<KICAD_T>& aScanTypes )
2648#if 0 && defined(DEBUG)
2649 std::cout <<
GetClass().mb_str() <<
' ';
2652 bool drawingsScanned =
false;
2654 for(
KICAD_T scanType : aScanTypes )
2702 if( !drawingsScanned )
2710 drawingsScanned =
true;
2746 if( reference.IsEmpty() )
2747 reference =
_(
"<no reference designator>" );
2749 return wxString::Format(
_(
"Footprint %s" ), reference );
2755 return wxString::Format( wxT(
"%s (%s)" ),
2794 aFunction( drawing );
2800 catch( std::bad_function_call& )
2802 wxFAIL_MSG( wxT(
"Error running FOOTPRINT::RunOnChildren" ) );
2809 std::vector<int> layers;
2811 layers.reserve( 6 );
2817 wxASSERT_MSG(
false, wxT(
"Illegal layer" ) );
2834 bool f_silk =
false, b_silk =
false, non_silk =
false;
2838 if( item->GetLayer() ==
F_SilkS )
2840 else if( item->GetLayer() ==
B_SilkS )
2846 if( ( f_silk || b_silk ) && !non_silk &&
m_pads.empty() )
2883 constexpr double MINIMAL_ZOOM_LEVEL_FOR_VISIBILITY = 1.5;
2886 return MINIMAL_ZOOM_LEVEL_FOR_VISIBILITY;
2899 int biggest_clearance =
board->GetMaxClearanceValue();
2900 area.
Inflate( biggest_clearance );
2911 if( aName.find_first_of( invalids ) != std::string::npos )
2925 static const wxChar invalidChars[] = wxT(
"%$<>\t\n\r\"\\/:");
2926 static const wxChar invalidCharsReadable[] = wxT(
"% $ < > 'tab' 'return' 'line feed' \\ \" / :");
2929 return invalidCharsReadable;
2931 return invalidChars;
2937 if( aMoveVector.
x == 0 && aMoveVector.
y == 0 )
2951 EDA_ANGLE newOrientation = orientation + aAngle;
2958 field->KeepUpright();
2963 static_cast<PCB_TEXT*
>( item )->KeepUpright();
2970 wxASSERT( aLayer ==
F_Cu || aLayer ==
B_Cu );
3025 field->OnFootprintTransformed();
3028 pad->OnFootprintTransformed();
3031 zone->OnFootprintTransformed();
3039 item->OnFootprintTransformed();
3044 point->OnFootprintTransformed();
3085 if( !std::isfinite( aScaleX ) || !std::isfinite( aScaleY ) || aScaleX <= 0.0 || aScaleY <= 0.0 )
3090 const double ratioX = aScaleX / oldSx;
3091 const double ratioY = aScaleY / oldSy;
3092 const double linearFactor = ( aScaleX + aScaleY ) / ( oldSx + oldSy );
3100 pad->OnFootprintRescaled( ratioX, ratioY, linearFactor,
anchor, parentRotate );
3103 field->OnFootprintRescaled( ratioX, ratioY, linearFactor,
anchor, parentRotate );
3106 item->OnFootprintRescaled( ratioX, ratioY, linearFactor,
anchor, parentRotate );
3109 zone->OnFootprintRescaled( ratioX, ratioY, linearFactor,
anchor, parentRotate );
3112 point->OnFootprintTransformed();
3140 field->OnFootprintTransformed();
3143 pad->OnFootprintTransformed();
3146 zone->OnFootprintTransformed();
3149 point->OnFootprintTransformed();
3157 item->OnFootprintTransformed();
3161 item->Move(
delta );
3201 field->Move( moveVector );
3205 pad->Move( moveVector );
3209 item->Move( moveVector );
3213 zone->Move( moveVector );
3217 point->Move( moveVector );
3256 field->OnFootprintTransformed();
3259 pad->OnFootprintTransformed();
3262 zone->OnFootprintTransformed();
3265 point->OnFootprintTransformed();
3273 item->OnFootprintTransformed();
3277 item->Rotate( rotationCenter, angleChange );
3313 const BOARD_ITEM* aItem,
bool addToFootprint )
3317 switch( aItem->
Type() )
3321 PAD* new_pad =
new PAD( *
static_cast<const PAD*
>( aItem ) );
3324 if( addToFootprint )
3325 m_pads.push_back( new_pad );
3333 ZONE* new_zone =
new ZONE( *
static_cast<const ZONE*
>( aItem ) );
3336 if( addToFootprint )
3337 m_zones.push_back( new_zone );
3339 new_item = new_zone;
3348 if( addToFootprint )
3351 new_item = new_point;
3363 switch(
static_cast<const PCB_FIELD*
>( aItem )->GetId() )
3372 if( addToFootprint )
3375 new_item = new_text;
3384 if( addToFootprint )
3387 new_item = new_shape;
3396 if( addToFootprint )
3399 new_item = new_barcode;
3408 if( addToFootprint )
3411 new_item = new_image;
3420 if( addToFootprint )
3423 new_item = new_textbox;
3436 if( addToFootprint )
3439 new_item = dimension;
3447 if( addToFootprint )
3449 group->RunOnChildren(
3469 wxFAIL_MSG( wxT(
"Duplication not supported for items of class " ) + aItem->
GetClass() );
3479 std::set<wxString> usedNumbers;
3483 usedNumbers.insert(
pad->GetNumber() );
3490 while( usedNumbers.count( wxString::Format( wxT(
"%s%d" ), prefix, num ) ) )
3493 return wxString::Format( wxT(
"%s%d" ), prefix, num );
3501 if(
group.contains( aPadNumber ) )
3505 return std::nullopt;
3556 for(
int jj = 0; jj < aPolySet.
HoleCount( ii ); jj++ )
3560 return aPolySet.
Area();
3575 return markerShape.
Area();
3579 double combinedArea = 0.0;
3584 return combinedArea;
3635 double width =
static_cast<const PCB_TRACK*
>( aItem )->GetWidth();
3636 return width * width;
3640 static_cast<const PAD*
>( aItem )->Padstack().ForEachUniqueLayer(
3650 const ZONE* zone =
static_cast<const ZONE*
>( aItem );
3700 for(
int i = 0; i < aCollector.
GetCount(); ++i )
3704 switch( item->
Type() )
3736 double footprintRegionArea =
polygonArea( footprintRegion );
3737 double uncoveredRegionArea = footprintRegionArea -
polygonArea( coveredRegion );
3738 double coveredArea = footprintRegionArea - uncoveredRegionArea;
3741 if( footprintRegionArea == 0 )
3744 double ratio = coveredArea / footprintRegionArea;
3751 return std::min( ratio, 1.0 );
3757 std::shared_ptr<SHAPE_COMPOUND> shape = std::make_shared<SHAPE_COMPOUND>();
3778 shape->AddShape(
pad->GetEffectiveShape( aLayer, aFlash )->Clone() );
3783 shape->AddShape( item->GetEffectiveShape( aLayer, aFlash )->Clone() );
3785 shape->AddShape( item->GetEffectiveShape( aLayer, aFlash )->Clone() );
3832 std::vector<PCB_SHAPE*> list_front;
3833 std::vector<PCB_SHAPE*> list_back;
3834 std::map<int, int> front_width_histogram;
3835 std::map<int, int> back_width_histogram;
3842 list_back.push_back( shape );
3849 list_front.push_back( shape );
3854 if( !list_front.size() && !list_back.size() )
3858 int chainingEpsilon =
pcbIUScale.mmToIU( 0.02 );
3861 true, aErrorHandler ) )
3871 auto max = std::max_element( front_width_histogram.begin(), front_width_histogram.end(),
3872 [](
const std::pair<int, int>& a,
const std::pair<int, int>& b )
3874 return a.second < b.second;
3877 if( max != front_width_histogram.end() )
3900 auto max = std::max_element( back_width_histogram.begin(), back_width_histogram.end(),
3901 [](
const std::pair<int, int>& a,
const std::pair<int, int>& b )
3903 return a.second < b.second;
3906 if( max != back_width_histogram.end() )
3929 std::map<PCB_LAYER_ID, std::vector<PCB_SHAPE*>> layer_shapes;
3935 if( item->Type() != PCB_SHAPE_T )
3938 for( PCB_LAYER_ID layer : item->GetLayerSet() )
3940 if( !IsCopperLayer( layer ) )
3943 if( board && !board->GetEnabledLayers().Contains( layer ) )
3946 layer_shapes[layer].push_back( static_cast<PCB_SHAPE*>( item ) );
3950 for(
size_t ii = 0; ii < m_pads.size(); ++ii )
3953 bool has_nettie =
false;
3955 auto it = map.find(
pad->GetNumber() );
3957 if( it == map.end() || it->second < 0 )
3960 for(
size_t jj = ii + 1; jj < m_pads.size(); ++jj )
3962 PAD* other = m_pads[ jj ];
3964 auto it2 = map.find( other->
GetNumber() );
3966 if( it2 == map.end() || it2->second < 0 )
3969 if( it2->second == it->second )
3971 m_netTieCache[
pad].insert(
pad->GetNetCode() );
3973 m_netTieCache[other].insert( other->
GetNetCode() );
3974 m_netTieCache[other].insert(
pad->GetNetCode() );
3982 for(
auto& [ layer, shapes ] : layer_shapes )
3984 auto pad_shape =
pad->GetEffectiveShape( layer );
3986 for(
auto other_shape : shapes )
3988 auto shape = other_shape->GetEffectiveShape( layer );
3990 if( pad_shape->Collide( shape.get() ) )
3992 std::set<int>& nettie = m_netTieCache[
pad];
3993 m_netTieCache[other_shape].insert( nettie.begin(), nettie.end() );
4003 std::map<wxString, int> padNumberToGroupIdxMap;
4006 padNumberToGroupIdxMap[
pad->GetNumber() ] = -1;
4009 [&]( wxString aPad,
int aGroup )
4011 aPad.Trim(
true ).Trim(
false );
4013 if( !aPad.IsEmpty() )
4014 padNumberToGroupIdxMap[ aPad ] = aGroup;
4023 for( wxUniCharRef ch :
group )
4032 switch(
static_cast<unsigned char>( ch ) )
4039 processPad(
pad, ii );
4049 processPad(
pad, ii );
4052 return padNumberToGroupIdxMap;
4062 int groupIdx = padToNetTieGroupMap[ aPad->
GetNumber() ];
4063 std::vector<PAD*> otherPads;
4069 if( padToNetTieGroupMap[
pad->GetNumber() ] == groupIdx )
4070 otherPads.push_back(
pad );
4083 if( setAttr && likelyAttr && setAttr != likelyAttr )
4087 switch( likelyAttr )
4090 msg.Printf(
_(
"(expected 'Through hole'; actual '%s')" ),
GetTypeName() );
4093 msg.Printf(
_(
"(expected 'SMD'; actual '%s')" ),
GetTypeName() );
4098 (aErrorHandler)( msg );
4104 const std::function<
void(
const PAD*,
int,
4105 const wxString& )>& aErrorHandler )
4107 if( aErrorHandler ==
nullptr )
4112 pad->CheckPad( aUnitsProvider,
false,
4113 [&](
int errorCode,
const wxString& msg )
4115 aErrorHandler(
pad, errorCode, msg );
4123 const VECTOR2I& )>& aErrorHandler )
4125 std::unordered_map<PTR_PTR_CACHE_KEY, int> checkedPairs;
4140 if(
static_cast<void*
>( a ) >
static_cast<void*
>( b ) )
4143 if( checkedPairs.find( { a, b } ) == checkedPairs.end() )
4145 checkedPairs[ { a, b } ] = 1;
4157 std::shared_ptr<SHAPE_SEGMENT> holeA =
pad->GetEffectiveHoleShape();
4160 if( holeA->Collide( holeB->GetSeg(), 0 ) )
4177 SHAPE* padShape =
pad->GetEffectiveShape( l ).get();
4180 if( padShape->
Collide( otherShape, 0,
nullptr, &pos ) )
4193 const VECTOR2I& )>& aErrorHandler )
4202 std::vector<BOARD_ITEM*> copperItems;
4206 if( item->IsOnCopperLayer() )
4207 copperItems.push_back( item );
4209 item->RunOnChildren(
4213 copperItems.push_back( descendent );
4220 if( !zone->GetIsRuleArea() && zone->IsOnCopperLayer() )
4221 copperItems.push_back( zone );
4226 if( field->IsOnCopperLayer() )
4227 copperItems.push_back( field );
4237 std::map<int, std::vector<const PAD*>> outlineIdxToPadsMap;
4241 if( item->IsOnLayer( layer ) )
4251 for(
int ii = 0; ii < copperOutlines.
OutlineCount(); ++ii )
4253 if(
pad->GetEffectiveShape( layer )->Collide( &copperOutlines.
Outline( ii ), 0 ) )
4254 outlineIdxToPadsMap[ ii ].emplace_back(
pad );
4261 for(
const auto& [ outlineIdx, pads ] : outlineIdxToPadsMap )
4263 if( pads.size() > 1 )
4265 const PAD* firstPad = pads[0];
4266 int firstGroupIdx = padNumberToGroupIdxMap[ firstPad->
GetNumber() ];
4268 for(
size_t ii = 1; ii < pads.size(); ++ii )
4270 const PAD* thisPad = pads[ii];
4271 int thisGroupIdx = padNumberToGroupIdxMap[ thisPad->
GetNumber() ];
4273 if( thisGroupIdx < 0 || thisGroupIdx != firstGroupIdx )
4282 if( item->HitTest( pos, 1 ) )
4284 shortingItem = item;
4290 aErrorHandler( shortingItem, firstPad, thisPad, pos );
4292 aErrorHandler( firstPad, thisPad,
nullptr, pos );
4303 std::set<wxString> padNumbers;
4312 msg.Printf(
_(
"(net-tie pad group contains unknown pad number %s)" ), padNumber );
4313 aErrorHandler( msg );
4315 else if( !padNumbers.insert(
pad->GetNumber() ).second )
4317 msg.Printf(
_(
"(pad %s appears in more than one net-tie pad group)" ), padNumber );
4318 aErrorHandler( msg );
4326 const VECTOR2I& aPt )>& aErrorHandler )
4328 auto checkColliding =
4343 if( itemShape->Collide( otherShape.get(), 0, &
actual, &pos ) )
4344 aErrorHandler( item, other, pos );
4353 checkColliding( item, other );
4357 checkColliding( item,
pad );
4368 std::swap( *
this, *
image );
4377 image->RunOnChildren(
4405 return *
this == other;
4414 for(
size_t ii = 0; ii <
m_pads.size(); ++ii )
4423 for(
size_t ii = 0; ii <
m_drawings.size(); ++ii )
4432 for(
size_t ii = 0; ii <
m_zones.size(); ++ii )
4442 std::vector<PCB_FIELD*> fields, otherFields;
4447 if( fields.size() != otherFields.size() )
4450 for(
size_t ii = 0; ii < fields.size(); ++ii )
4454 if( !( *fields[ii] == *otherFields[ii] ) )
4470 double similarity = 1.0;
4479 similarity *=
pad->Similarity( *otherPad );
4491 if( aPtA.
x != aPtB.
x )
4492 return aPtA.
x < aPtB.
x;
4494 if( aPtA.
y != aPtB.
y )
4495 return aPtA.
y < aPtB.
y;
4497 return std::nullopt;
4503 if( itemA->
Type() != itemB->
Type() )
4504 return itemA->
Type() < itemB->
Type();
4509 switch( itemA->
Type() )
4631 return itemA < itemB;
4643 std::optional<bool> padCopperMatches;
4646 const PAD* checkPad = aFirst;
4659 padCopperMatches = aFirst->
GetSize( aLayer ).
x < aSecond->
GetSize( aLayer ).
x;
4661 padCopperMatches = aFirst->
GetSize( aLayer ).
y < aSecond->
GetSize( aLayer ).
y;
4663 padCopperMatches = aFirst->
GetShape( aLayer ) < aSecond->
GetShape( aLayer );
4666 if( padCopperMatches.has_value() )
4667 return *padCopperMatches;
4675 return aFirst < aSecond;
4680bool FOOTPRINT::cmp_padstack::operator()(
const PAD* aFirst,
const PAD* aSecond )
const
4720 if( firstShape->VertexCount() != secondShape->VertexCount() )
4721 return firstShape->VertexCount() < secondShape->VertexCount();
4723 for(
int ii = 0; ii < firstShape->VertexCount(); ++ii )
4725 if( std::optional<bool> cmp =
cmp_points_opt( firstShape->CVertex( ii ), secondShape->CVertex( ii ) ) )
4759 return aFirst < aSecond;
4764 int aMaxError,
ERROR_LOC aErrorLoc )
const
4775 clearance.x +=
pad->GetSolderMaskExpansion( padLayer );
4776 clearance.y +=
pad->GetSolderMaskExpansion( padLayer );
4799 if( dummySize.
x <= 0 || dummySize.
y <= 0 )
4803 dummy.SetSize( padLayer, dummySize );
4804 dummy.TransformShapeToPolygon( aBuffer, padLayer, 0, aMaxError, aErrorLoc );
4808 pad->TransformShapeToPolygon( aBuffer, padLayer,
clearance.x, aMaxError, aErrorLoc );
4814 if( !
pad->FlashLayer( aLayer ) )
4819 pad->Padstack().ForEachUniqueLayer(
4822 processPad(
pad, l );
4827 processPad(
pad, aLayer );
4834 int aError,
ERROR_LOC aErrorLoc,
bool aIncludeText,
4835 bool aIncludeShapes,
bool aIncludePrivateItems )
const
4842 if( item->Type() ==
PCB_TEXT_T && aIncludeText )
4847 text->TransformTextToPolySet( aBuffer, aClearance, aError, aErrorLoc );
4858 textbox->PCB_SHAPE::TransformShapeToPolygon( aBuffer, aLayer, 0, aError, aErrorLoc );
4865 if( item->Type() ==
PCB_SHAPE_T && aIncludeShapes )
4886 if( ( aLayer ==
UNDEFINED_LAYER || field->GetLayer() == aLayer ) && field->IsVisible() )
4887 field->TransformTextToPolySet( aBuffer, aClearance, aError, aErrorLoc );
4897 std::set<KIFONT::OUTLINE_FONT*>
fonts;
4911 if( permission == PERMISSION::EDITABLE || permission == PERMISSION::INSTALLABLE )
4912 fonts.insert( outlineFont );
4918 processItem( item );
4921 processItem( field );
4966 return wxEmptyString;
4971 const std::unordered_set<wxString>& aComponentClassNames )
5020 LSET padLayers =
pad->GetLayerSet();
5021 padLayers |= boardCopper;
5022 pad->SetLayerSet( padLayers );
5034 if( zcMap.
Choices().GetCount() == 0 )
5046 if( layerEnum.
Choices().GetCount() == 0 )
5054 wxPGChoices fpLayers;
5065 auto isNotFootprintHolder =
5071 return !
board->IsFootprintHolder();
5078 layer->SetChoices( fpLayers );
5079 layer->SetAvailableFunc( isNotFootprintHolder );
5095 const wxString groupFields =
_HKI(
"Fields" );
5101 const wxString propertyFields =
_HKI(
"Footprint Properties" );
5119 const wxString groupAttributes =
_HKI(
"Attributes" );
5133 const wxString groupOverrides =
_HKI(
"Overrides" );
types::KiCadObjectType ToProtoEnum(KICAD_T aValue)
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)
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
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.
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 bool IsOnLayer(PCB_LAYER_ID aLayer) const
Test to see if this object is on the given layer.
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
virtual std::shared_ptr< SHAPE > GetEffectiveShape(PCB_LAYER_ID aLayer=UNDEFINED_LAYER, FLASHING aFlash=FLASHING::DEFAULT) const
Some pad shapes can be complex (rounded/chamfered rectangle), even without considering custom shapes.
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
virtual bool IsOnCopperLayer() const
wxString GetLayerName() const
Return the name of the PCB layer on which the item resides.
Information pertinent to a Pcbnew printed circuit board.
PCB_LAYER_ID FlipLayer(PCB_LAYER_ID aLayer) const
int GetCopperLayerCount() 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)
Gets an effective component class for the given constituent class names.
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)
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.
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.
FONT is an abstract base class for both outline and stroke fonts.
virtual bool IsOutline() const
Class OUTLINE_FONT implements 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.
void ShapeToPolygon(SHAPE_LINE_CHAIN &aPolygon, int aScale=-1) const
Return the shape polygon in internal units in a SHAPE_LINE_CHAIN the coordinates are relatives to the...
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.
virtual std::shared_ptr< SHAPE > GetEffectiveShape(PCB_LAYER_ID aLayer, FLASHING flashPTHPads=FLASHING::DEFAULT) const override
Some pad shapes can be complex (rounded/chamfered rectangle), even without considering custom shapes.
const BOX2I GetBoundingBox() const override
The bounding box is cached, so this will be efficient most of the time.
bool IsOnLayer(PCB_LAYER_ID aLayer) const override
Test to see if this object is on the given layer.
int GetDrillSizeY() const
PAD_ATTRIB GetAttribute() const
const wxString & GetNumber() const
VECTOR2I GetPosition() const override
int GetDrillSizeX() 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,...
bool HasDrilledHole() const override
std::shared_ptr< SHAPE_SEGMENT > GetEffectiveHoleShape() const override
Return a SHAPE_SEGMENT object representing the pad's hole.
wxString GetShownText(bool aAllowExtraText, int aDepth=0) const override
Return the string actually shown after processing of the base text.
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.
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
void TransformShapeToPolygon(SHAPE_POLY_SET &aBuffer, PCB_LAYER_ID aLayer, int aClearance, int aError, ERROR_LOC aErrorLoc, bool ignoreLineWidth=false) const override
Convert the shape to a closed polygon.
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
Disables the border, this is done by changing the stroke internally.
void TransformTextToPolySet(SHAPE_POLY_SET &aBuffer, int aClearance, int aMaxError, ERROR_LOC aErrorLoc) const
Function TransformTextToPolySet Convert the text to a polygonSet describing the actual character stro...
EDA_ANGLE GetTextAngle() const override
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 & SetIsHiddenFromLibraryEditors(bool aIsHidden=true)
Provide class metadata.Helper macro to map type hashes to names.
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 & 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...
void SetClosed(bool aClosed)
Mark the line chain as closed (i.e.
double Area(bool aAbsolute=true) const
Return the area of this chain.
const VECTOR2I NearestPoint(const VECTOR2I &aP, bool aAllowInternalShapePoints=true) const
Find a point on the line chain that is closest to point aP.
Represent a set of closed polygons.
void BooleanAdd(const SHAPE_POLY_SET &b)
Perform boolean polyset union.
int AddOutline(const SHAPE_LINE_CHAIN &aOutline)
Adds a new outline to the set and returns its index.
double Area()
Return the area of this poly set.
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 HoleCount(int aOutline) const
Returns the number of holes in a given outline.
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)
void Simplify()
Simplify the polyset (merges overlapping polys, eliminates degeneracy/self-intersections)
SHAPE_LINE_CHAIN & Outline(int aIndex)
Return the reference to aIndex-th outline in the set.
SHAPE_LINE_CHAIN & Hole(int aOutline, int aHole)
Return the reference to aHole-th hole in the aIndex-th outline.
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.
An abstract shape on 2D plane.
virtual bool Collide(const VECTOR2I &aP, int aClearance=0, int *aActual=nullptr, VECTOR2I *aLocation=nullptr) const
Check if the boundary of shape (this) lies closer to the point aP than aClearance,...
Handle a list of polygons defining a copper zone.
bool GetIsRuleArea() const
Accessors to parameters used in Rule Area zones:
SHAPE_POLY_SET * Outline()
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
void TransformShapeToPolygon(SHAPE_POLY_SET &aBuffer, PCB_LAYER_ID aLayer, int aClearance, int aError, ERROR_LOC aErrorLoc, bool ignoreLineWidth=false) const override
Convert the zone shape to a closed polygon Used in filling zones calculations Circles and arcs are ap...
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.
@ DRCE_DRILLED_HOLES_TOO_CLOSE
@ DRCE_DRILLED_HOLES_COLOCATED
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
@ RECTANGLE
Use RECTANGLE instead of RECT to avoid collision in a Windows header.
@ 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.
PCB_LAYER_ID FlipLayer(PCB_LAYER_ID aLayerId, int aCopperLayersCount)
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.
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)
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.
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 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 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
@ SMD
Smd pad, appears on the solder paste layer (default)
@ PTH
Plated through hole pad.
@ 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 NO_SETTER(owner, type)
@ PT_DEGREE
Angle expressed in degrees.
@ PT_SIZE
Size expressed in distance units (mm/inch)
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, bool aIgnoreCase)
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.
FIELD_T
The set of all field indices assuming an array like sequence that a SCH_COMPONENT or LIB_PART can hol...
@ 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".
wxString GetCanonicalFieldName(FIELD_T aFieldType)
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_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_GENERATOR_T
class PCB_GENERATOR, generator on a layer
@ 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_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
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