71#include <wx/richmsgdlg.h>
75#define MULTICHANNEL_EXTRA_DEBUG
82 std::vector<wxString> refs;
89 refs.push_back( fp->GetReferenceAsString() );
92 std::sort( refs.begin(), refs.end(),
93 [](
const wxString& aLhs,
const wxString& aRhs )
95 return aLhs.CmpNoCase( aRhs ) < 0;
103 size_t componentsOnLine = 0;
105 for(
const wxString& ref : refs )
107 if( componentsOnLine == 10 )
114 componentsOnLine = 0;
121 if( !line.IsEmpty() )
137 for(
const wxString& reason : aReasons )
139 if( !
text.IsEmpty() )
150 const std::vector<wxString>& aReasons )
152 if( !aParent || aReasons.empty() )
155 wxRichMessageDialog dlg( aParent, aSummary,
_(
"Topology mismatch" ), wxICON_ERROR | wxOK );
166 aOut.insert(
static_cast<FOOTPRINT*
>( item ) );
180 else if( item->IsBOARD_ITEM() )
181 aOut.insert(
static_cast<BOARD_ITEM*
>( item ) );
254 return *std::ranges::min_element( aMatches,
255 [](
const auto& aA,
const auto& aB )
272 const KIID& aAnchor )
274 auto it = std::ranges::find_if( aMatches, [&](
const auto& aPair ) {
return aPair.first->m_Uuid == aAnchor; } );
275 return it != aMatches.end() ? *it :
firstPair( aMatches );
286 if( aAnchor !=
niluuid && !aMatches.empty() )
288 const auto& [refAnchorFp, targetAnchorFp] =
anchorPair( aMatches, aAnchor );
289 VECTOR2I oldpos = refAnchorFp->GetPosition();
291 aRot = targetAnchorFp->GetOrientation() - refAnchorFp->GetOrientation();
293 aDisp = targetAnchorFp->GetPosition() - oldpos;
298 outline.
Move( aDisp );
306 std::set<ZONE*> zones;
313 ZONE* zone =
static_cast<ZONE*
>( aItem );
322 for(
EDA_ITEM* child : aGroup->GetItems() )
324 if(
ZONE* zone = asLinked( child ) )
326 zones.insert( zone );
337 if(
ZONE* zone = asLinked( item ) )
339 zones.insert( zone );
359 ZONE* zone =
static_cast<ZONE*
>( child );
409 const std::vector<wxString>& aReasons )
const
411 wxWindow* parent = aParent ? aParent :
frame();
419 wxCHECK( selTool,
false );
423 std::shared_ptr<MULTICHANNEL_CONTEXT_MENU> menu = std::make_shared<MULTICHANNEL_CONTEXT_MENU>(
this );
446 std::set<FOOTPRINT*>& aComponents )
448 if( !aRuleArea || !aRuleArea->
m_zone )
459 aComponents.insert(
static_cast<FOOTPRINT*
>( item ) );
462 return (
int) aComponents.size();
471 [&](
const wxString& aMessage,
int aOffset )
484 sourceName.Replace( wxT(
"'" ), wxT(
"\\'" ) );
491 ruleText = wxT(
"A.memberOfSheetOrChildren('" ) + sourceName + wxT(
"')" );
494 ruleText = wxT(
"A.hasComponentClass('" ) + sourceName + wxT(
"')" );
497 ruleText = wxT(
"A.memberOfGroup('" ) + sourceName + wxT(
"')" );
504 auto ok = compiler.
Compile( ruleText, &ucode, &preflightCtx );
518 fp->GetSheetname() );
520 aComponents.insert( fp );
530 if( !aRuleArea || !aRuleArea->
m_zone )
555 if( !boardItem->IsConnected() || boardItem->Type() ==
PCB_ZONE_T )
556 aItems.insert( boardItem );
568 && areaBox.
Contains( aItem->GetBoundingBox() );
573 if( !zone->GetIsRuleArea() && inside( zone ) )
574 aItems.insert( zone );
579 if( !drawing->IsConnected() && !drawing->GetParentGroup() && inside( drawing ) )
580 aItems.insert( drawing );
584 return aItems.size() > 0;
589 std::set<BOARD_ITEM*> members;
600 if( !boardItem->IsConnected() || boardItem->Type() ==
PCB_ZONE_T )
601 aItems.insert( boardItem );
612 bool zoneOnBoard =
false;
616 if( zone == aRuleArea->
m_zone )
632 std::set<BOARD_ITEM*> members;
641 if( !boardItem->IsConnected() || boardItem->Type() ==
PCB_ZONE_T )
642 aItems.insert( boardItem );
646 return aItems.size() > 0;
655 [&](
const wxString& aMessage,
int aOffset )
666 wxString ruleText = wxString::Format( wxT(
"A.enclosedByArea('%s')" ),
669 if( !compiler.
Compile( ruleText, &ucode, &preflightCtx ) )
676 auto val = ucode.
Run( &ctx );
678 if( val->AsDouble() != 0.0 )
679 aItems.insert( aItem );
684 if( zone == aRuleArea->
m_zone )
692 if( !drawing->IsConnected() )
693 testAndAdd( drawing );
702 std::set<FOOTPRINT*> rv;
704 if( aSheetName.EndsWith( wxT(
"/" ) ) )
705 aSheetName.RemoveLast();
707 wxString childPrefix = aSheetName + wxT(
"/" );
711 auto sn = fp->GetSheetname();
713 if( sn.EndsWith( wxT(
"/" ) ) )
716 if( sn == aSheetName || sn.StartsWith( childPrefix ) )
727 std::set<FOOTPRINT*> rv;
731 if( fp->GetComponentClass()->ContainsClassName( aComponentClassName ) )
741 std::set<FOOTPRINT*> rv;
745 if(
group->GetName().Matches( aGroupName ) )
759 if( !
group->GetName().Matches( aGroupName ) )
774 std::set<BOARD_ITEM*> rv;
778 if( !
group->GetName().Matches( aGroupName ) )
783 if( item->IsBOARD_ITEM() )
784 rv.insert(
static_cast<BOARD_ITEM*
>( item ) );
794 std::vector<VECTOR2I> bbCorners;
795 bbCorners.reserve( aFootprints.size() * 4 );
799 const BOX2I bb = fp->GetBoundingBox(
false ).GetInflated( aMargin );
803 std::vector<VECTOR2I> hullVertices;
814 std::vector<VECTOR2I> bbCorners;
815 bbCorners.reserve( aItems.size() * 4 );
819 BOX2I bb = item->GetBoundingBox();
822 bb =
static_cast<FOOTPRINT*
>( item )->GetBoundingBox(
false );
827 std::vector<VECTOR2I> hullVertices;
841 std::vector<wxString> segments;
844 for( wxUniChar ch : aSheetName )
849 segments.push_back( cur );
860 segments.push_back( cur );
862 std::vector<wxString> rv;
863 wxString prefix = wxT(
"/" );
865 for(
size_t i = 0; i + 1 < segments.size(); ++i )
867 prefix += segments[i] + wxT(
"/" );
868 rv.push_back( prefix );
879 std::map<wxString, wxString> uniqueSheets;
880 std::set<wxString> uniqueComponentClasses;
881 std::set<wxString> uniqueGroups;
887 uniqueSheets[fp->GetSheetname()] = fp->GetSheetfile();
891 uniqueSheets.emplace( parent, wxString() );
896 uniqueComponentClasses.insert( singleClass->GetName() );
902 if( !grp->GetName().IsEmpty() )
903 uniqueGroups.insert( grp->GetName() );
907 for(
const auto& [sheetPath, sheetFile] : uniqueSheets )
916 m_areas.m_areas.push_back( ent );
921 (
int)
m_areas.m_areas.size() );
924 for(
const wxString& compClass : uniqueComponentClasses )
932 m_areas.m_areas.push_back( ent );
936 static_cast<int>(
m_areas.m_areas.size() ) );
939 for(
const wxString& groupName : uniqueGroups )
947 m_areas.m_areas.push_back( ent );
951 static_cast<int>(
m_areas.m_areas.size() ) );
962 if( !zone->GetIsRuleArea() )
965 if( !zone->GetPlacementAreaEnabled() )
973 area.
m_center = zone->Outline()->COutline( 0 ).Centre();
991 m_areas.m_areas.push_back( area );
1010 std::vector<ZONE*> refRAs;
1012 auto isSelectedItemAnRA =
1018 ZONE* zone =
static_cast<ZONE*
>( aItem );
1031 if(
ZONE* zone = isSelectedItemAnRA( item ) )
1033 refRAs.push_back( zone );
1041 if(
ZONE* grpZone = isSelectedItemAnRA( grpItem ) )
1042 refRAs.push_back( grpZone );
1056 frame()->ShowInfoBarMsg(
_(
"Select the footprints of the circuit to repeat." ),
true );
1060 else if( refRAs.size() != 1 )
1065 _(
"Select a reference Rule Area to copy from..." ),
1068 return isSelectedItemAnRA( aItem ) !=
nullptr;
1083 if(
m_areas.m_areas.size() <= 1 )
1085 frame()->ShowInfoBarError(
_(
"No Rule Areas to repeat layout to have been found." ),
true );
1089 const KIID& linkSet = refRAs.front()->GetLinkSet();
1090 m_areas.m_options = refRAs.front()->GetRepeatOptions();
1094 for(
auto& [area, compat] :
m_areas.m_compatMap )
1095 compat.m_doCopy = compat.m_isOk && ( linkSet ==
niluuid || area->m_zone->GetLinkSet() == linkSet );
1112static bool isChannelNet(
const std::vector<FOOTPRINT*>& aOwners,
const std::set<FOOTPRINT*>& aChannel )
1114 return std::ranges::count_if( aOwners, [&](
FOOTPRINT* aFp ) {
return !aChannel.contains( aFp ); } ) <= 1;
1118static std::set<int>
channelNets(
const std::map<
int, std::vector<FOOTPRINT*>>& aNetOwners,
1119 const std::set<FOOTPRINT*>& aChannel )
1123 for(
const auto& [net, owners] : aNetOwners )
1125 if( owners.size() > 1 &&
isChannelNet( owners, aChannel )
1126 && std::ranges::any_of( owners, [&](
FOOTPRINT* aFp ) {
return aChannel.contains( aFp ); } ) )
1158 if( aAmong.contains(
pad->GetNetCode() ) )
1159 nets.insert(
pad->GetNetCode() );
1169 using PATH = std::vector<KIID>;
1171 std::optional<PATH> refPrefix;
1177 if(
path.size() < 2 )
1181 refPrefix = PATH(
path.begin(),
path.end() - 1 );
1183 size_t depth = std::min( refPrefix->size(),
path.size() - 1 );
1184 auto diff = std::mismatch( refPrefix->begin(), refPrefix->begin() + depth,
path.begin() );
1186 refPrefix->resize( diff.first - refPrefix->begin() );
1189 if( !refPrefix || refPrefix->empty() )
1192 const size_t depth = refPrefix->size();
1197 return PATH( aPath.begin() + depth, aPath.end() );
1200 std::map<PATH, FOOTPRINT*> refByRest;
1203 refByRest[rest( fp->GetPath() )] = fp;
1205 std::map<PATH, TMATCH::COMPONENT_MATCHES> instances;
1211 if( aRef.contains( fp ) ||
path.size() <= depth )
1214 PATH prefix(
path.begin(),
path.begin() + depth );
1216 if( prefix == *refPrefix )
1219 if(
auto it = refByRest.find( rest(
path ) ); it != refByRest.end() && it->second->GetFPID() == fp->GetFPID() )
1220 instances[prefix][it->second] = fp;
1223 std::vector<TMATCH::COMPONENT_MATCHES>
result;
1225 for(
auto& [prefix, matches] : instances )
1226 result.push_back( std::move( matches ) );
1253 int net =
pad->GetNetCode();
1267 if( it->second != peerNet )
1272 if( peerNet <= 0 ||
m_netsTaken.contains( peerNet ) )
1277 aAdded.push_back( net );
1288 std::vector<int> added;
1290 if(
bind( ref, aChoice, added ) )
1292 m_map[ref] = aChoice;
1293 m_used.insert( aChoice );
1295 if(
extend( aIndex + 1 ) )
1302 for(
int net : added )
1313 if( aIndex ==
m_order.size() )
1322 auto mapped = std::ranges::find_if( ref->
Pads(),
1323 [&](
PAD* aPad ) { return m_netMap.contains( aPad->GetNetCode() ); } );
1325 if( mapped != ref->
Pads().end() )
1330 &&
pair( aIndex, fp ) )
1351 m_areas.m_options.m_groupItems =
true;
1378 std::map<int, std::vector<FOOTPRINT*>> netOwners;
1382 for(
PAD*
pad : fp->Pads() )
1384 std::vector<FOOTPRINT*>& owners = netOwners[
pad->GetNetCode()];
1386 if(
pad->GetNetCode() > 0 && ( owners.empty() || owners.back() != fp ) )
1387 owners.push_back( fp );
1400 std::set<int> internal =
channelNets( netOwners, selected );
1401 std::set<FOOTPRINT*> leaves;
1405 if(
padNets( fp, internal ).size() <= 1 )
1406 leaves.insert( fp );
1409 std::vector<RULE_AREA_COMPAT_DATA> found;
1417 if( !aCandidate.m_discovered.contains( fp ) )
1418 aCandidate.m_unmatched.insert( fp );
1421 aCandidate.m_doCopy =
true;
1423 return aCandidate.m_unmatched.empty()
1424 || ( aLoose && std::ranges::all_of( aCandidate.m_unmatched,
1425 [&](
FOOTPRINT* aFp ) { return leaves.contains( aFp ); } ) );
1433 if( classify( candidate ) )
1434 found.push_back( std::move( candidate ) );
1439 std::map<LIB_ID, int> fpidCount;
1442 fpidCount[fp->GetFPID()]++;
1445 FOOTPRINT* seed = *std::ranges::min_element( selected,
1448 return std::make_pair( leaves.contains( aA ), fpidCount[aA->
GetFPID()] )
1449 < std::make_pair( leaves.contains( aB ), fpidCount[aB->
GetFPID()] );
1452 std::vector<FOOTPRINT*> order = { seed };
1454 for(
size_t i = 0; i < order.size(); ++i )
1456 for(
int net :
padNets( order[i], internal ) )
1460 if( selected.contains( fp ) && std::ranges::find( order, fp ) == order.end() )
1461 order.push_back( fp );
1466 std::set<FOOTPRINT*> claimed = selected;
1470 if( claimed.contains( twin ) || twin->GetFPID() != seed->
GetFPID() )
1473 FLAT_MATCHER matcher{ netOwners, internal, leaves, claimed, order, aLoose };
1475 bool ok = matcher.pair( 0, twin );
1477 if( matcher.m_budget < 0 )
1481 found.push_back( std::move( candidate ) );
1487 if( !ok || !classify( candidate ) )
1493 std::set<FOOTPRINT*> both;
1494 std::unordered_set<int> rails;
1496 for(
const auto& [ref, target] : candidate.
m_discovered )
1500 both.insert( { ref, target } );
1505 for(
PAD*
pad : fp->Pads() )
1508 rails.insert(
pad->GetNetCode() );
1519 found.push_back( std::move( candidate ) );
1529 const std::set<FOOTPRINT*>& selected =
m_areas.m_selectedFootprints;
1536 m_areas.m_scratchItems.clear();
1538 if( selected.empty() )
1541 std::vector<RULE_AREA_COMPAT_DATA> found =
findMatches( selected, aLoose );
1544 m_areas.m_areas.reserve( found.size() + 1 );
1547 [&](
const SHAPE_LINE_CHAIN& aOutline,
const std::set<FOOTPRINT*>& aFootprints,
1553 m_areas.m_scratchItems.emplace_back( zone );
1572 std::set<FOOTPRINT*> targets;
1574 for(
const auto& [ref, target] : candidate.m_discovered )
1575 targets.insert( target );
1582 for(
size_t i = 0; i < found.size(); ++i )
1583 m_areas.m_compatMap[&
m_areas.m_areas[i + 1]] = std::move( found[i] );
1587 bool unticked =
false;
1589 for(
auto& [area, compat] :
m_areas.m_compatMap )
1591 unticked |= compat.m_doCopy && !compat.m_isOk;
1592 compat.m_doCopy &= compat.m_isOk;
1596 if( unticked && resolved )
1600 (
int)
m_areas.m_compatMap.size() );
1610 [&](
const std::set<FOOTPRINT*>& aSet )
1614 return std::ranges::any_of(
findMatches( aSet,
false ),
1621 std::set<FOOTPRINT*>
result = aSeed;
1629 if( aLargest &&
path.size() >= 2 )
1631 std::set<FOOTPRINT*> sheet;
1637 if( other.size() ==
path.size() && std::equal(
path.begin(),
path.end() - 1, other.begin() ) )
1641 bool holdsSeed = std::ranges::all_of( aSeed, [&](
FOOTPRINT* aFp ) {
return sheet.contains( aFp ); } );
1643 if( sheet.size() >
result.size() && holdsSeed && hasTwin( sheet ) )
1652 constexpr size_t maxOwners = 12;
1654 std::set<FOOTPRINT*> rejected;
1657 while( grew && budget > 0 )
1662 const std::set<FOOTPRINT*> frontier =
result;
1664 for(
const auto& [net, owners] : netOwners )
1666 if( owners.size() > maxOwners || !std::ranges::any_of( owners, [&](
FOOTPRINT* aFp )
1667 { return frontier.contains( aFp ); } ) )
1677 if(
result.contains( fp ) || rejected.contains( fp ) )
1680 std::set<FOOTPRINT*> trial =
result;
1683 if( hasTwin( trial ) )
1685 result = std::move( trial );
1690 rejected.insert( fp );
1721 std::set<FOOTPRINT*> seed;
1726 seed.insert(
static_cast<FOOTPRINT*
>( item ) );
1733 frame()->ShowInfoBarMsg(
_(
"Select a footprint to expand from." ),
true );
1739 if( expanded.size() == seed.size() )
1741 frame()->ShowInfoBarMsg(
_(
"No larger topology repeats elsewhere on the board." ),
true );
1745 EDA_ITEMS items( expanded.begin(), expanded.end() );
1750 frame()->ShowInfoBarMsg( wxString::Format(
_(
"Selected %d parts that repeat elsewhere." ), (
int) expanded.size() ),
1759 std::set<FOOTPRINT*> pruned;
1765 for(
const auto& [area, compat] :
m_areas.m_compatMap )
1767 if( compat.m_doCopy )
1768 pruned.insert( compat.m_unmatched.begin(), compat.m_unmatched.end() );
1787 for(
auto& [area, compat] :
m_areas.m_compatMap )
1789 compat.m_isOk =
false;
1790 compat.m_errorMsg =
_(
"The ticked channels share no selected part" );
1798 [&](
FOOTPRINT* aFp ) { return aFp->m_Uuid == m_areas.m_options.m_anchor; } ) )
1801 int64_t biggest = -1;
1813 std::vector<TOPOLOGY_JOB> jobs;
1815 for(
auto& [area, compat] :
m_areas.m_compatMap )
1817 area->m_components.clear();
1821 if(
auto it = compat.m_discovered.find( fp ); it != compat.m_discovered.end() )
1822 area->m_components.insert( it->second );
1825 if( compat.m_searchLimit )
1827 compat.m_isOk =
false;
1828 compat.m_errorMsg =
_(
"Search limit reached" );
1832 jobs.push_back( { ref, area, &compat } );
1864 std::vector<RULE_AREA*> channels = { ref };
1867 for(
auto& [area, compat] :
m_areas.m_compatMap )
1869 if( compat.m_doCopy && compat.m_isOk )
1870 channels.push_back( area );
1873 if( channels.size() < 2 )
1879 auto it = std::ranges::find_if(
m_areas.m_scratchItems,
1880 [&](
const auto& aScratch ) { return aScratch.get() == aItem; } );
1881 commit.
Add( it->release() );
1884 std::set<wxString> names;
1887 names.insert(
group->GetName() );
1892 RULE_AREA* matched = area == ref ? channels[1] : area;
1893 const auto& [refAnchor, targetAnchor] =
1898 [&](
const wxString& aName ) { return names.contains( aName ); } );
1899 names.insert(
name );
1901 area->m_group->SetName(
name );
1902 area->m_zone->SetZoneName(
name );
1905 wxString sheet =
anchor->GetSheetname();
1910 area->m_zone->SetPlacementAreaSource( wholeSheet ? sheet : area->m_group->GetName() );
1912 addToBoard( area->m_zone );
1913 addToBoard( area->m_group );
1916 for(
FOOTPRINT* fp : area->m_components )
1927 std::set<BOARD_ITEM*> found;
1929 if(
m_areas.m_options.m_copyRouting )
1936 nets.insert(
pad->GetNetCode() );
1940 found.insert( item );
1943 if(
m_areas.m_options.m_copyOtherItems )
1954 std::vector<RULE_AREA*> targets;
1959 targets.push_back( area );
1969 int created = (int) channels.size();
1971 commit.
Push(
_(
"Repeat Layout" ) );
1979 frame()->ShowInfoBarMsg( wxString::Format(
m_areas.m_linkAreas ?
_(
"Created %d linked channels." )
1980 :
_(
"Created %d channels." ),
1994 refs.push_back( fp->GetReference() );
1997 return wxJoin( refs,
',' );
2033 auto savedCompat =
m_areas.m_compatMap;
2038 m_areas.m_options.m_groupItems =
false;
2048 view->AddToPreview( clone,
true );
2062 if( isContainer( aItem ) )
2064 aItem->RunOnChildren( [&](
BOARD_ITEM* aChild )
2066 if( !isContainer( aChild ) )
2067 previewClone( aChild );
2079 for(
const auto& [area, compat] :
m_areas.m_compatMap )
2081 for(
BOARD_ITEM* item : compat.m_affectedItems )
2084 for(
BOARD_ITEM* item : compat.m_groupableItems )
2089 for(
const auto& [area, compat] :
m_areas.m_compatMap )
2091 for(
BOARD_ITEM* item : compat.m_affectedItems )
2105 std::vector<BOARD_ITEM*>
moved;
2108 moved.push_back( fp );
2111 connectivity->Update( fp );
2113 connectivity->RecalculateRatsnest();
2116 [&](
const std::shared_ptr<const CN_ANCHOR>& aNode )
2124 for(
const CN_EDGE& edge : connectivity->GetRatsnestForItems(
moved ) )
2126 const std::shared_ptr<const CN_ANCHOR>& a = edge.GetSourceNode();
2127 const std::shared_ptr<const CN_ANCHOR>& b = edge.GetTargetNode();
2129 if( a && b && !a->Dirty() && !b->Dirty() && ( movedPad( a ) || movedPad( b ) ) )
2138 m_areas.m_compatMap = std::move( savedCompat );
2139 m_areas.m_options = savedOptions;
2152 std::vector<BOARD_ITEM*>
moved;
2155 moved.push_back( fp );
2166 std::set<BOARD_CONNECTED_ITEM*> scanned;
2167 std::set<BOARD_CONNECTED_ITEM*> routing;
2173 if( aNets.contains( item->GetNetCode() ) )
2174 routing.insert( item );
2181 const std::set<BOARD_CONNECTED_ITEM*> inside = routing;
2188 for(
CN_ITEM* cnItem : connectivity->GetConnectivityAlgo()->ItemEntry( item ).GetItems() )
2203 if(
next->GetNetCode() == item->GetNetCode() && aNets.contains(
next->GetNetCode() ) )
2204 routing.insert(
next );
2232 m_highlight->SetStrokeColor( aColor.WithAlpha( 0.9 ) );
2233 m_highlight->SetFillColor( aColor.WithAlpha( 0.08 ) );
2270 view->ClearPreview();
2302 if( !item || !
view->HasItem( item ) )
2305 view->Hide( item, aHide );
2337 if( ra.
m_zone == aRefZone )
2349 std::vector<TOPOLOGY_JOB> jobs;
2356 jobs.push_back( {
m_areas.m_refRA, &ra, &
m_areas.m_compatMap[&ra] } );
2374 int total =
static_cast<int>( aJobs.size() );
2375 std::atomic<int> completed( 0 );
2376 std::atomic<bool> cancelled(
false );
2377 std::atomic<int> matchedComponents( 0 );
2378 std::atomic<int> totalComponents( 0 );
2391 auto future = std::async(
2393 [
this, &aJobs, &completed, &cancelled, &matchedComponents, &isoParams]()
2397 if( cancelled.load( std::memory_order_relaxed ) )
2400 matchedComponents.store( 0, std::memory_order_relaxed );
2403 if( cancelled.load( std::memory_order_relaxed ) )
2406 completed.fetch_add( 1, std::memory_order_relaxed );
2414 std::unique_ptr<WINDOW_DISABLER> dialogDisabler;
2415 std::unique_ptr<WINDOW_DISABLER> frameDisabler;
2416 std::unique_ptr<WX_PROGRESS_REPORTER>
reporter;
2417 auto startTime = std::chrono::steady_clock::now();
2418 double highWaterMark = 0.0;
2420 while( future.wait_for( std::chrono::milliseconds( 100 ) ) != std::future_status::ready )
2425 if( std::chrono::steady_clock::now() - startTime > std::chrono::milliseconds( 250 ) )
2429 dialogDisabler = std::make_unique<WINDOW_DISABLER>(
m_dialog );
2430 frameDisabler = std::make_unique<WINDOW_DISABLER>(
frame() );
2436 wxLog::FlushActive();
2442 int done = completed.load( std::memory_order_relaxed );
2443 int matched = matchedComponents.load( std::memory_order_relaxed );
2444 int compTotal = totalComponents.load( std::memory_order_relaxed );
2446 double fraction = ( compTotal > 0 )
2447 ?
static_cast<double>( matched ) / compTotal
2449 double progress =
static_cast<double>( done + fraction ) / total;
2451 if( progress > highWaterMark )
2452 highWaterMark = progress;
2454 reporter->SetCurrentProgress( highWaterMark );
2455 reporter->Report( wxString::Format(
2456 _(
"Resolving topology %d of %d (%d/%d components)" ),
2457 std::min( done + 1, total ), total, matched, compTotal ) );
2460 cancelled.store(
true, std::memory_order_relaxed );
2469 if( !cancelled.load( std::memory_order_relaxed ) )
2473 for(
size_t i =
static_cast<size_t>( completed.load() ); i < aJobs.size(); ++i )
2475 aJobs[i].m_compat->m_isOk =
false;
2476 aJobs[i].m_compat->m_errorMsg =
_(
"Cancelled" );
2477 aJobs[i].m_compat->m_mismatchReasons.clear();
2486 wxString* aErrorOut )
2488 wxCHECK_MSG( aRefArea.
m_zone, -1, wxT(
"Reference Rule Area has no zone." ) );
2489 wxCHECK_MSG( aTargetArea.
m_zone, -1, wxT(
"Target Rule Area has no zone." ) );
2491 const bool silent = aErrorOut !=
nullptr;
2493 auto reportError = [&](
const wxString& aMsg )
2497 else if(
Pgm().IsGUI() )
2498 frame()->ShowInfoBarError( aMsg,
true );
2510 else if(
Pgm().IsGUI() )
2512 wxString summary = wxString::Format(
_(
"Rule Area topologies do not match: %s" ), compat.
m_errorMsg );
2519 std::optional<BOARD_COMMIT> localCommit;
2521 if( !aExternalCommit )
2522 localCommit.emplace(
GetManager(),
true,
false );
2524 BOARD_COMMIT& commit = aExternalCommit ? *aExternalCommit : *localCommit;
2547 if( !aExternalCommit )
2550 reportError(
_(
"Target group does not have a group." ) );
2560 if(
group->ContainsItem( item ) )
2564 group->AddItem( item );
2568 if( !aExternalCommit )
2569 commit.
Push(
_(
"Repeat Layout" ) );
2577 int totalCopied = 0;
2579 for(
auto& [targetArea, compatData] :
m_areas.m_compatMap )
2581 if( !compatData.m_doCopy )
2584 targetArea->m_ruleName );
2588 if( !compatData.m_isOk )
2595 if(
m_areas.m_options.m_groupItems )
2597 for(
const auto& [targetArea, compatData] :
m_areas.m_compatMap )
2599 if( compatData.m_groupableItems.size() < 2 )
2618 for(
BOARD_ITEM* item : compatData.m_groupableItems )
2634 std::vector<RULE_AREA*> targets;
2636 for(
const auto& [targetArea, compatData] :
m_areas.m_compatMap )
2638 if( compatData.m_doCopy && compatData.m_isOk )
2639 targets.push_back( targetArea );
2645 commit.
Push(
_(
"Repeat Layout" ) );
2648 frame()->ShowInfoBarMsg( wxString::Format(
_(
"Copied to %d Rule Areas." ), totalCopied ),
true );
2668 std::set<KIID> oldSets;
2671 auto join = [&](
ZONE* aZone,
const KIID& aAnchor )
2697 join( target->m_zone,
anchor );
2707 std::map<KIID, std::vector<ZONE*>> members;
2711 if( aSets.contains( zone->GetLinkSet() ) )
2712 members[zone->GetLinkSet()].push_back( zone );
2715 for(
const auto& [linkSet, zones] : members )
2717 if( zones.size() < 2 )
2730 || ( generators && generators->Router() && generators->Router()->RoutingInProgress() );
2738 if( sources.size() != 1 )
2740 frame()->ShowInfoBarMsg( sources.empty() ?
_(
"Select a linked Rule Area, or a part of one, to update the "
2742 :
_(
"Select items from a single linked channel." ),
2749 frame()->ShowInfoBarWarning(
_(
"Finish routing before updating linked layouts." ),
true );
2762 if( members.empty() )
2763 frame()->ShowInfoBarMsg(
_(
"Select a linked Rule Area, or a part of one, to unlink." ),
true );
2774 std::set<KIID> oldSets;
2776 for(
ZONE* zone : aZones )
2778 if( zone->GetLinkSet() !=
niluuid )
2779 oldSets.insert( zone->GetLinkSet() );
2785 commit.
Push(
_(
"Unlink Layout" ) );
2797 std::vector<RULE_AREA*> linked;
2798 std::map<FOOTPRINT*, int> footprintUse;
2805 linked.push_back( &area );
2807 if( area.
m_zone == aSource )
2821 return std::ranges::any_of( aArea->m_components,
2822 [&](
FOOTPRINT* aFp ) { return footprintUse[aFp] > 1; } );
2826 auto overlapsOtherArea =
2829 return std::ranges::any_of( linked,
2832 return aOther != aArea
2840 if( sharesParts( ref ) || ( !refGrouped && overlapsOtherArea( ref, *ref->
m_zone->
Outline() ) ) )
2844 frame()->ShowInfoBarWarning(
2845 wxString::Format(
_(
"'%s' overlaps another linked Rule Area." ), ref->
m_ruleName ),
true );
2852 std::vector<wxString> problems;
2853 std::vector<SHAPE_POLY_SET> acceptedOutlines;
2859 std::vector<RULE_AREA*> targets;
2860 std::vector<TOPOLOGY_JOB> jobs;
2867 targets.push_back( target );
2868 jobs.push_back( { ref, target, &
m_areas.m_compatMap[target] } );
2883 problems.push_back( wxString::Format( wxT(
"'%s': %s" ), target->m_ruleName, compat.
m_errorMsg ) );
2894 bool overlapsAccepted = std::ranges::any_of( acceptedOutlines,
2902 if( sharesParts( target )
2903 || ( !scoped && ( overlapsAccepted || overlapsOtherArea( target, *target->m_zone->Outline() )
2904 || overlapsOtherArea( target, repeated ) ) ) )
2907 wxString::Format(
_(
"'%s' overlaps another linked Rule Area." ), target->m_ruleName ) );
2912 acceptedOutlines.push_back( std::move( repeated ) );
2917 if( !problems.empty() &&
Pgm().IsGUI() )
2919 frame()->ShowInfoBarWarning(
2920 wxString::Format(
_(
"Some linked Rule Areas were not updated. %s" ),
JoinMismatchReasons( problems ) ),
2934 if( !aRuleArea || !aRuleArea->
m_zone )
2963 if(
EDA_GROUP* parent = bci->GetParentGroup() )
2969 if( bci->IsConnected() )
2970 aOutput.insert( bci );
2975 return (
int) aOutput.size();
2977 count = (int) aOutput.size();
2982 std::set<BOARD_ITEM*> members;
2998 aOutput.insert( bci );
3009 bool zoneOnBoard =
false;
3013 if( zone == aRuleArea->
m_zone )
3023 const BOX2I areaBox = areaOutline.
BBox();
3028 if( aOutput.contains( aItem ) )
3032 if(
EDA_GROUP* parent = aItem->GetParentGroup() )
3039 || !areaBox.
Contains( aItem->GetBoundingBox() ) )
3045 aItem->TransformShapeToPolygon( itemShape, aItem->GetLayer(), 0, maxError,
ERROR_OUTSIDE );
3054 aOutput.insert( aItem );
3060 enclosedByZone( track );
3064 if( drawing->IsConnected() )
3077 [&](
const wxString& aMessage,
int aOffset )
3088 wxString ruleText = wxString::Format( wxT(
"A.enclosedByArea('%s')" ),
3096 if( aOutput.contains( aItem ) )
3100 if(
EDA_GROUP* parent = aItem->GetParentGroup() )
3108 || !zoneBox.
Intersects( aItem->GetBoundingBox() ) )
3118 aOutput.insert( aItem );
3123 if( compiler.
Compile( ruleText, &ucode, &preflightCtx ) )
3126 testAndAdd( track );
3130 if( drawing->IsConnected() )
3149 std::map<int, int> netMap;
3153 for(
const PAD* refPad : refFP->Pads() )
3155 if( refPad->GetNetCode() <= 0 )
3158 std::vector<const PAD*> targetPads = targetFP->GetPads( refPad->GetNumber() );
3160 if( !targetPads.empty() )
3161 netMap.emplace( refPad->GetNetCode(), targetPads[0]->GetNetCode() );
3180 std::vector<std::pair<BOARD_ITEM*, BOARD_ITEM*>> groupFixupPairs;
3181 std::set<BOARD_ITEM*> reproducedSourceItems;
3183 auto fixupParentGroup =
3188 destItem->SetParentGroup(
nullptr );
3190 if( !preserveGroups )
3194 groupFixupPairs.emplace_back( sourceItem, destItem );
3196 reproducedSourceItems.insert( sourceItem );
3202 bool targetZoneOnBoard =
false;
3204 if( aTargetArea->
m_zone )
3208 if( z == aTargetArea->
m_zone )
3210 targetZoneOnBoard =
true;
3216 if( targetZoneOnBoard )
3224 if( preserveGroups )
3227 groupFixupPairs.emplace_back( aRefArea->
m_zone, aTargetArea->
m_zone );
3229 reproducedSourceItems.insert( aRefArea->
m_zone );
3235 std::set<BOARD_CONNECTED_ITEM*> refRouting;
3236 std::set<BOARD_CONNECTED_ITEM*> targetRouting;
3242 std::set<int> targc;
3246 for(
PAD*
pad : refFP->Pads() )
3247 refc.insert(
pad->GetNetCode() );
3249 for(
PAD*
pad : targetFP->Pads() )
3250 targc.insert(
pad->GetNetCode() );
3267 std::set<int> targetGroupNets;
3272 targetGroupNets.insert(
pad->GetNetCode() );
3277 std::set<BOARD_ITEM*> members;
3283 targetGroupNets.insert( bci->GetNetCode() );
3290 std::set<int> targetChannelNets;
3292 for(
int net : targetGroupNets )
3296 targetChannelNets.insert( net );
3300 std::vector<FOOTPRINT*> owners;
3304 if( std::ranges::find( owners,
pad->GetParentFootprint() ) == owners.end() )
3305 owners.push_back(
pad->GetParentFootprint() );
3309 targetChannelNets.insert( net );
3326 if( item->GetParentGroup() )
3329 if( item->IsLocked() )
3332 if( item->GetNetCode() <= 0 || !targetChannelNets.contains( item->GetNetCode() ) )
3376 fixupParentGroup( item,
copied );
3386 std::vector<PCB_GENERATOR*> refGenerators;
3387 std::vector<PCB_GENERATOR*> targetGenerators;
3389 auto appendGenerators =
3390 [&](
EDA_GROUP* aGroup, std::vector<PCB_GENERATOR*>& aOut )
3392 std::set<BOARD_ITEM*> members;
3407 refGenerators.push_back(
static_cast<PCB_GENERATOR*
>( item ) );
3412 if( !targetGroup && !aTargetArea->
m_components.empty() )
3413 targetGroup = ( *aTargetArea->
m_components.begin() )->GetParentGroup();
3416 appendGenerators( targetGroup, targetGenerators );
3425 appendGenerators( refGroup, refGenerators );
3428 appendGenerators( targetGroup, targetGenerators );
3430 if( !refGroup || !targetGroup )
3437 if( gen->GetGeneratorType() != wxT(
"tuning_pattern" ) )
3440 if( !refGroup && gen->HitTest( refOut,
false ) )
3441 refGenerators.push_back( gen );
3442 else if( !targetGroup && !( refGroup && gen->HitTest( refOut,
false ) )
3443 && gen->HitTest( targetOut,
false ) )
3444 targetGenerators.push_back( gen );
3458 aCommit->
Remove( child );
3482 clone->
Move( disp );
3483 aCommit->
Add( clone );
3491 fixupNet( bci, bci, hasMatches, netMap );
3493 aCommit->
Add( child );
3503 std::set<BOARD_ITEM*> sourceItems;
3504 std::set<BOARD_ITEM*> targetItems;
3522 if( item->GetParent() && item->GetParent()->Type() ==
PCB_FOOTPRINT_T )
3539 ZONE* zone =
static_cast<ZONE*
>( item );
3562 if( item->GetParent() && item->GetParent()->Type() ==
PCB_FOOTPRINT_T )
3572 ZONE* zone =
static_cast<ZONE*
>( item );
3574 if( !skipLayerFilter )
3576 LSET allowedLayers =
3584 ZONE* targetZone =
static_cast<ZONE*
>( item->Duplicate(
false ) );
3585 fixupNet( zone, targetZone, hasMatches, netMap );
3591 if( !skipLayerFilter )
3605 fixupParentGroup( item,
copied );
3623 refFP->GetReference() );
3629 refFP->GetReference() );
3637 && !refFP->GetEffectiveShape( refFP->GetLayer() )->Collide( &refPoly, 0 ) )
3645 aCommit->
Modify( targetFP );
3647 targetFP->SetLayerAndFlip( refFP->GetLayer() );
3648 targetFP->SetOrientation( refFP->GetOrientation() );
3649 targetFP->SetPosition( refFP->GetPosition() );
3650 targetFP->Rotate(
VECTOR2( 0, 0 ), rot );
3651 targetFP->Move( disp );
3653 for(
PCB_FIELD* refField : refFP->GetFields() )
3655 wxCHECK2( refField,
continue );
3657 PCB_FIELD* targetField = targetFP->GetField( refField->GetName() );
3662 targetField->
SetLayerSet( refField->GetLayerSet() );
3663 targetField->
SetVisible( refField->IsVisible() );
3665 targetField->
SetPosition( refField->GetPosition() );
3668 targetField->
Move( disp );
3675 std::set<PCB_TEXT*> consumedTargets;
3677 for(
BOARD_ITEM* refItem : refFP->GraphicalItems() )
3685 for(
BOARD_ITEM* targetItem : targetFP->GraphicalItems() )
3692 if( consumedTargets.contains( candidate ) || candidate->
GetText() != refText->
GetText() )
3697 targetText = candidate;
3706 consumedTargets.insert( targetText );
3714 targetText->
Move( disp );
3719 targetFP->Models() = refFP->Models();
3721 std::set<PAD*> consumedPads;
3723 for(
PAD* refPad : refFP->Pads() )
3725 for(
PAD* targetPad : targetFP->Pads() )
3727 if( consumedPads.contains( targetPad ) || targetPad->GetNumber() != refPad->GetNumber() )
3732 consumedPads.insert( targetPad );
3733 targetPad->ImportSettingsFrom( *refPad );
3743 if( preserveGroups && refFP->GetParentGroup() )
3744 groupFixupPairs.emplace_back( refFP, targetFP );
3746 if( preserveGroups )
3747 reproducedSourceItems.insert( refFP );
3754 if( preserveGroups && !groupFixupPairs.empty() )
3756 std::map<EDA_GROUP*, EDA_GROUP*> groupMap;
3757 std::map<EDA_GROUP*, bool> fullyReproducedCache;
3759 auto groupFullyReproduced =
3762 if(
auto it = fullyReproducedCache.find( aGroup ); it != fullyReproducedCache.end() )
3765 bool reproduced =
true;
3767 for(
EDA_ITEM* member : aGroup->GetItems() )
3771 if( !member->IsBOARD_ITEM()
3772 || !reproducedSourceItems.contains(
static_cast<BOARD_ITEM*
>( member ) ) )
3779 fullyReproducedCache[aGroup] = reproduced;
3783 for(
const auto& [sourceItem, destItem] : groupFixupPairs )
3787 if( !parentGroup || !groupFullyReproduced( parentGroup ) )
3790 if( !groupMap.contains( parentGroup ) )
3800 newGroup->
Move( disp );
3803 groupMap[parentGroup] = newGroup;
3804 aCommit->
Add( newGroup );
3809 if(
EDA_GROUP* oldGroup = destItem->GetParentGroup() )
3811 if( oldGroup != groupMap[parentGroup] )
3812 aCommit->
Modify( oldGroup->AsEdaItem() );
3815 groupMap[parentGroup]->AddItem( destItem );
3831 const std::map<int, int>& aNetMap )
3840 auto it = aNetMap.find( aRef->
GetNetCode() );
3842 if( it != aNetMap.end() )
3848 const std::set<FOOTPRINT*>& aFootprints,
3849 const std::unordered_set<EDA_ITEM*>& aItems )
3851 std::vector<NETINFO_ITEM*> created;
3852 std::map<int, NETINFO_ITEM*> remap;
3858 auto isAutoName = [](
const wxString& aName )
3860 return aName.StartsWith( wxT(
"Net-(" ) ) || aName.StartsWith( wxT(
"unconnected-" ) );
3865 int code = aItem->GetNetCode();
3872 if( !oldNet || !isAutoName( oldNet->
GetNetname() ) )
3875 auto it = remap.find( code );
3877 if( it == remap.end() )
3883 name = wxString::Format( wxT(
"__dbapply_%d_%d" ), code, counter++ );
3887 aBoard->
Add( newNet );
3888 created.push_back( newNet );
3889 it = remap.emplace( code, newNet ).first;
3892 aItem->SetNet( it->second );
3897 for(
PAD*
pad : fp->Pads() )
3916 if( aRef.empty() || aRef.size() != aTarget.size() )
3920 std::set<FOOTPRINT*> used;
3925 size_t bestLength = 0;
3932 if( length > bestLength )
3934 targetFp = candidate;
3935 bestLength = length;
3938 else if( length == bestLength && length > 0 )
3945 if( !targetFp || tied )
3949 if( refFp->GetFPID() != targetFp->
GetFPID() || refFp->Pads().size() != targetFp->
Pads().size() )
3952 if( !used.insert( targetFp ).second )
3955 result[refFp] = targetFp;
3958 aResult = std::move(
result );
3966 const std::unordered_set<int>& aExtraGlobalNets )
3986 std::set<FOOTPRINT*> shared;
3989 std::inserter( shared, shared.begin() ) );
3991 if( !shared.empty() )
3995 aMatches.
m_errorMsg =
_(
"Target Rule Area shares components with the reference area" );
3998 _(
"This target Rule Area selects the same components as the reference area. "
3999 "Repeat layout cannot copy a Rule Area onto itself. Give each placement Rule "
4000 "Area a distinct sheet, component class or group." ) );
4001 aMatches.
m_mismatchReasons.push_back( wxString::Format(
_(
"Shared components:\n%s" ),
4009 std::unordered_map<int, std::vector<const RULE_AREA*>> netInternalAreas;
4013 std::unordered_map<int, int> areaNetPadCounts;
4019 if(
pad->GetNetCode() > 0 )
4020 areaNetPadCounts[
pad->GetNetCode()]++;
4024 for(
const auto& [netCode, padCount] : areaNetPadCounts )
4027 netInternalAreas[netCode].push_back( &area );
4038 if( aB->m_components.count( fp ) )
4045 std::unordered_set<int> globalNets = aExtraGlobalNets;
4047 for(
const auto& [netCode, areas] : netInternalAreas )
4049 for(
size_t i = 0; i < areas.size() && !globalNets.count( netCode ); i++ )
4051 for(
size_t j = i + 1; j < areas.size(); j++ )
4053 if( disjoint( areas[i], areas[j] ) )
4055 globalNets.insert( netCode );
4076 std::vector<TMATCH::TOPOLOGY_MISMATCH_REASON> mismatchReasons;
4080 mismatchReasons, aParams );
4092 if( !status && !cancelled
4099 aMatches.
m_isOk = status;
4110 for(
const auto& reason : mismatchReasons )
4112 if( reason.m_reason.IsEmpty() )
4115 if( !reason.m_reference.IsEmpty() && !reason.m_candidate.IsEmpty() )
4117 else if( !reason.m_reference.IsEmpty() )
4121 reason.m_reason ) );
4128 aMatches.
m_mismatchReasons.push_back(
_(
"The components in the two areas could not be paired up." ) );
4135 aMatches.
m_mismatchReasons.push_back( wxString::Format(
_(
"Reference area components:\n%s" ),
4137 aMatches.
m_mismatchReasons.push_back( wxString::Format(
_(
"Target area components:\n%s" ),
4148 const std::unordered_set<BOARD_ITEM*>& aItemsToRemove )
4154 std::vector<EDA_ITEM*> pruneList;
4160 if( refItem->m_Uuid == testItem->m_Uuid )
4161 pruneList.push_back( refItem );
4165 if( !pruneList.empty() )
4170 group->RemoveItem( item );
4172 if(
group->GetItems().size() < 2 )
4189 if(
m_areas.m_areas.size() <= 1 )
4191 frame()->ShowInfoBarError(
_(
"Cannot auto-generate any placement areas because the "
4192 "schematic has only one or no hierarchical sheets, "
4193 "groups, or component classes." ),
4201 if( ret != wxID_OK )
4221 wxString existingAreaTraceFormat;
4226 existingAreaTraceFormat = wxT(
"Placement rule area for sheet '%s' already exists as '%s'\n" );
4231 existingAreaTraceFormat = wxT(
"Placement rule area for component class '%s' already exists as '%s'\n" );
4236 existingAreaTraceFormat = wxT(
"Placement rule area for group '%s' already exists as '%s'\n" );
4239 std::unique_ptr<ZONE> newZone(
new ZONE(
board() ) );
4240 newZone->SetZoneName( wxString::Format( wxT(
"auto-placement-area-%s" ),
source ) );
4241 newZone->SetPlacementAreaSourceType( ra.
m_sourceType );
4242 newZone->SetPlacementAreaSource(
source );
4244 std::vector<ZONE*> oldZones;
4248 if( !zone->GetIsRuleArea() || !zone->GetPlacementAreaEnabled() )
4251 if( zone->GetPlacementAreaSourceType() != newZone->GetPlacementAreaSourceType()
4252 || zone->GetPlacementAreaSource() != newZone->GetPlacementAreaSource() )
4259 oldZones.push_back( zone );
4262 if( !oldZones.empty() && !
m_areas.m_replaceExisting )
4274 if( groupItems.empty() )
4277 wxT(
"Skipping placement rule area generation for source group '%s': group has no board items." ),
4289 std::set<BOARD_ITEM*> outlineItems;
4290 std::set<EDA_GROUP*> groups;
4295 outlineItems.insert( fp );
4309 std::set<int> foreignNets;
4317 foreignNets.insert(
pad->GetNetCode() );
4322 int net = track->GetNetCode();
4324 if( net > 0 &&
channelNets.count( net ) && !foreignNets.count( net ) )
4325 outlineItems.insert( track );
4332 newZone->GetZoneName(),
4337 for(
ZONE* oldZone : oldZones )
4338 commit.
Remove( oldZone );
4340 ra.
m_zone = newZone.release();
4347 if(
m_areas.m_options.m_groupItems )
4354 std::unordered_set<BOARD_ITEM*> toPrune;
4370 group->AddItem( fp );
4375 commit.
Push(
_(
"Auto-generate Placement Rule Areas" ) );
constexpr EDA_IU_SCALE pcbIUScale
#define SKIP_ENTERED_GROUP
static TOOL_ACTION selectItem
Select an item (specified as the event parameter).
static TOOL_ACTION selectionClear
Clear the current selection.
static TOOL_ACTION selectItems
Select a list of items (specified as the event parameter)
void Push(const wxString &aMessage=wxEmptyString, int aCommitFlags=0) override
Execute the changes.
void Revert() override
Revert the commit by restoring the modified items state.
A base class derived from BOARD_ITEM for items that can be connected and have a net,...
virtual bool SetNetCode(int aNetCode, bool aNoAssert)
Set net using a net code.
bool IsConnected() const override
Returns information if the object is derived from BOARD_CONNECTED_ITEM.
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
virtual void SetLayerSet(const LSET &aLayers)
virtual bool IsKnockout() const
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
virtual void SetIsKnockout(bool aKnockout)
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.
FOOTPRINT * GetParentFootprint() const
virtual void RunOnChildren(const std::function< void(BOARD_ITEM *)> &aFunction, RECURSE_MODE aMode) const
Invoke a function on all children.
Information pertinent to a Pcbnew printed circuit board.
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT, bool aSkipConnectivity=false) override
Removes an item from the container.
NETINFO_ITEM * FindNet(int aNetcode) const
Search for a net with the given netcode.
const FOOTPRINTS & Footprints() const
static wxString MakeUniqueZoneName(const wxString &aBaseName, const std::function< bool(const wxString &)> &aInUse)
Return a name based on aBaseName for which aInUse returns false, adding or incrementing a _<number> s...
BOARD_ITEM * ResolveItem(const KIID &aID, bool aAllowNullptrReturn=false) const
BOARD_DESIGN_SETTINGS & GetDesignSettings()
std::shared_ptr< CONNECTIVITY_DATA > GetConnectivity() const
Return a list of missing connections between components/tracks.
constexpr const Vec GetEnd() const
constexpr ecoord_type GetArea() const
Return the area of the rectangle.
constexpr bool Contains(const Vec &aPoint) const
constexpr BOX2< Vec > GetInflated(coord_type aDx, coord_type aDy) const
Get a new rectangle that is this one, inflated by aDx and aDy.
constexpr const Vec & GetOrigin() const
constexpr bool Intersects(const BOX2< Vec > &aRect) const
CN_EDGE represents a point-to-point connection, whether realized or unrealized (ie: tracks etc.
CN_ITEM represents a BOARD_CONNECTED_ITEM in the connectivity system (ie: a pad, track/arc/via,...
const std::vector< CN_ITEM * > & ConnectedItems() const
Represent a set of changes (additions, deletions or modifications) of a data model (e....
COMMIT & Remove(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Remove a new item from the model.
COMMIT & Modify(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr, RECURSE_MODE aRecurse=RECURSE_MODE::NO_RECURSE)
Modify a given item in the model.
COMMIT & Add(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Add a new item to the model.
int GetStatus(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Returns status of an item.
A lightweight representation of a component class.
const std::vector< COMPONENT_CLASS * > & GetConstituentClasses() const
Fetches a vector of the constituent classes for this (effective) class.
void ClearLocalRatsnest()
Erase the temporary, selection-based ratsnest (i.e.
void BlockRatsnestItems(const std::vector< BOARD_ITEM * > &aItems)
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=nullptr) override
A set of EDA_ITEMs (i.e., without duplicates).
std::unordered_set< EDA_ITEM * > & GetItems()
void AddItem(EDA_ITEM *aItem)
Add item to group.
bool ContainsItem(const EDA_ITEM *aItem) const
Test if an item is a direct or nested member of this group.
virtual EDA_ITEM * AsEdaItem()=0
A base class for most all the KiCad significant classes used in schematics and boards.
virtual EDA_GROUP * GetParentGroup() const
KICAD_T Type() const
Returns the type of object.
void ClearFlags(EDA_ITEM_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
virtual void SetParentGroup(EDA_GROUP *aGroup)
virtual const wxString & GetText() const
Return the string associated with the text object.
virtual bool IsVisible() const
void SetAttributes(const EDA_TEXT &aSrc, bool aSetPosition=true)
Set the text attributes from another instance.
virtual void SetVisible(bool aVisible)
const TEXT_ATTRIBUTES & GetAttributes() const
A color representation with 4 components: red, green, blue, alpha.
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
wxString AsString() const
void SetErrorCallback(std::function< void(const wxString &aMessage, int aOffset)> aCallback)
bool Compile(const wxString &aString, UCODE *aCode, CONTEXT *aPreflightContext)
void SetErrorCallback(ERROR_CALLBACK aCallback)
VALUE * Run(CONTEXT *ctx)
virtual double AsDouble() const
LSET is a set of PCB_LAYER_IDs.
bool ContainsAll(const LSET &aLayers) const
See if this layer set contains all layers in another set.
static LSET AllCuMask(int aCuLayerCount)
Return a mask holding the requested number of Cu PCB_LAYER_IDs.
bool Contains(PCB_LAYER_ID aLayer) const
See if the layer set contains a PCB layer.
Handle the data for a net.
const wxString & GetNetname() const
void SetItems(BOARD_ITEM *a, BOARD_ITEM *b=nullptr)
static TOOL_ACTION unlinkLayout
static TOOL_ACTION repeatLayout
static TOOL_ACTION generatePlacementRuleAreas
static TOOL_ACTION expandToLargestTopology
static TOOL_ACTION updateLinkedLayouts
static TOOL_ACTION expandToMatchingTopology
static TOOL_ACTION selectItemInteractively
Selection of reference points/items.
void RedrawRatsnest()
Force refresh of the ratsnest visual representation.
void Rotate(const VECTOR2I &aRotCentre, const EDA_ANGLE &aAngle) override
Rotate this object.
PCB_GENERATOR * DeepClone() const
void Move(const VECTOR2I &aMoveVector) override
Move this object.
A set of BOARD_ITEMs (i.e., without duplicates).
void RunOnChildren(const std::function< void(BOARD_ITEM *)> &aFunction, RECURSE_MODE aMode) const override
Invoke a function on all children.
void Rotate(const VECTOR2I &aRotCentre, const EDA_ANGLE &aAngle) override
Rotate this object.
void Move(const VECTOR2I &aMoveVector) override
Move this object.
EDA_ITEM * AsEdaItem() override
EDA_ANGLE GetTextAngle() const override
VECTOR2I GetPosition() const override
void SetPosition(const VECTOR2I &aPos) override
void Move(const VECTOR2I &aMoveVector) override
Move this object.
void SetTextAngle(const EDA_ANGLE &aAngle) override
void Rotate(const VECTOR2I &aRotCentre, const EDA_ANGLE &aAngle) override
Rotate this object.
A small class to help profiling.
void Stop()
Save the time when this function was called, and set the counter stane to stop.
static SELECTION_CONDITION HasTypes(std::vector< KICAD_T > aTypes)
Create a functor that tests if among the selected items there is at least one of a given types.
static SELECTION_CONDITION HasType(KICAD_T aType)
Create a functor that tests if among the selected items there is at least one of a given type.
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
void Move(const VECTOR2I &aVector) override
void Rotate(const EDA_ANGLE &aAngle, const VECTOR2I &aCenter={ 0, 0 }) override
Rotate all vertices by a given angle.
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 IsEmpty() const
Return true if the set is empty (no polygons at all)
virtual void CacheTriangulation(bool aSimplify=false, const TASK_SUBMITTER &aSubmitter={}, bool aBuildIndexes=false)
Build a polygon triangulation, needed to draw a polygon on OpenGL and in some other calculations.
void BooleanIntersection(const SHAPE_POLY_SET &b)
Perform boolean polyset intersection.
void BooleanSubtract(const SHAPE_POLY_SET &b)
Perform boolean polyset difference.
const SHAPE_LINE_CHAIN & COutline(int aIndex) const
const BOX2I BBox(int aClearance=0) const override
Compute a bounding box of the shape, with a margin of aClearance a collision.
virtual VECTOR2I Centre() const
Compute a center-of-mass of the shape.
static std::unique_ptr< CONNECTION_GRAPH > BuildFromFootprintSet(const std::set< FOOTPRINT * > &aFps, const std::set< FOOTPRINT * > &aOtherChannelFps={}, const std::unordered_set< int > &aGlobalNets={})
Define a general 2D-vector/point.
Handle a list of polygons defining a copper zone.
void SetDoNotAllowPads(bool aEnable)
bool GetIsRuleArea() const
Accessors to parameters used in Rule Area zones:
const REPEAT_LAYOUT_OPTIONS & GetRepeatOptions() const
void AddPolygon(std::vector< VECTOR2I > &aPolygon)
Add a polygon to the zone outline.
wxString GetPlacementAreaSource() const
void SetRepeatOptions(const REPEAT_LAYOUT_OPTIONS &aOpts)
void HatchBorder()
Compute the hatch lines depending on the hatch parameters and stores it in the zone's attribute m_bor...
void SetLinkSet(const KIID &aLinkSet)
PLACEMENT_SOURCE_T GetPlacementAreaSourceType() const
SHAPE_POLY_SET * Outline()
void SetHatchStyle(ZONE_BORDER_DISPLAY_STYLE aStyle)
void SetIsRuleArea(bool aEnable)
void SetDoNotAllowTracks(bool aEnable)
const wxString & GetZoneName() const
void SetLayerSet(const LSET &aLayerSet) override
bool GetPlacementAreaEnabled() const
void SetDoNotAllowVias(bool aEnable)
virtual LSET GetLayerSet() const override
Return a std::bitset of all layers on which the item physically resides.
void SetDoNotAllowFootprints(bool aEnable)
const KIID & GetLinkSet() const
The set of placement rule areas that share one layout, or niluuid when this one is not linked.
void SetDoNotAllowZoneFills(bool aEnable)
void UnHatchBorder()
Clear the zone's hatch.
void RemoveAllContours(void)
void SetPlacementAreaEnabled(bool aEnabled)
void BuildConvexHull(std::vector< VECTOR2I > &aResult, const std::vector< VECTOR2I > &aPoly)
Calculate the convex hull of a list of points in counter-clockwise order.
static constexpr EDA_ANGLE ANGLE_0
SHAPE_LINE_CHAIN RectifyPolygon(const SHAPE_LINE_CHAIN &aPoly)
Take a polygon and 'rectify' it, so that all sides are H/V.
void CollectBoxCorners(const BOX2I &aBox, std::vector< VECTOR2I > &aCorners)
Add the 4 corners of a BOX2I to a vector.
std::map< FOOTPRINT *, FOOTPRINT * > COMPONENT_MATCHES
size_t CommonPathTailLength(const KIID_PATH &aA, const KIID_PATH &aB)
Count the trailing elements two symbol instance paths share.
Class to handle a set of BOARD_ITEMs.
PGM_BASE & Pgm()
The global program "get" accessor.
std::vector< EDA_ITEM * > EDA_ITEMS
Utility functions for working with shapes.
int StrNumCmp(const wxString &aString1, const wxString &aString2, CMP_T aCaseSensitivity)
Compare two strings with alphanumerical content.
void AccumulateDescription(wxString &aDesc, const wxString &aItem)
Utility to build comma separated lists in messages.
TMATCH::COMPONENT_MATCHES m_map
bool bind(FOOTPRINT *aRef, FOOTPRINT *aTarget, std::vector< int > &aAdded)
const std::vector< FOOTPRINT * > & m_order
bool extend(size_t aIndex)
const std::set< int > & m_internal
std::set< int > m_netsTaken
const std::map< int, std::vector< FOOTPRINT * > > & m_netOwners
bool pair(size_t aIndex, FOOTPRINT *aChoice)
const std::set< FOOTPRINT * > & m_leaves
std::map< int, int > m_netMap
const std::set< FOOTPRINT * > & m_claimed
std::set< FOOTPRINT * > m_used
Options for copying a placement rule area onto the others linked to it.
bool m_connectedRoutingOnly
KIID m_anchor
This area's own anchor footprint, or niluuid for the area center.
bool m_includeLockedItems
std::vector< wxString > m_mismatchReasons
TMATCH::COMPONENT_MATCHES m_discovered
Pairing found by discovery.
std::unordered_set< BOARD_ITEM * > m_affectedItems
Filled in by copyRuleAreaContents with items that were affected by the copy operation.
TMATCH::COMPONENT_MATCHES m_matchingComponents
std::set< FOOTPRINT * > m_unmatched
Selected footprints the channel lacks.
std::unordered_set< BOARD_ITEM * > m_groupableItems
Filled in by copyRuleAreaContents with affected items that can be grouped together.
bool ScansContents() const
True when the contents are scanned from the area rather than taken from an exact item list.
std::unordered_set< EDA_ITEM * > m_designBlockItems
bool m_fromSelection
The reference of a plain selection, copied as given with its footprint area deciding what else comes ...
PLACEMENT_SOURCE_T m_sourceType
wxString m_componentClass
std::set< FOOTPRINT * > m_components
std::atomic< bool > * m_cancelled
std::atomic< int > * m_matchedComponents
std::atomic< int > * m_totalComponents
IbisParser parser & reporter
wxString result
Test unit parsing edge cases and error handling.
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.
@ 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_GROUP_T
class PCB_GROUP, a set of BOARD_ITEMs
@ PCB_ZONE_T
class ZONE, a copper pour area
@ PCB_TEXT_T
class PCB_TEXT, text on a layer
@ PCB_TABLECELL_T
class PCB_TABLECELL, PCB_TEXTBOX for use in tables
@ PCB_FOOTPRINT_T
class FOOTPRINT, a footprint
@ 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_TRACE_T
class PCB_TRACK, a track segment (segment on a copper layer)
VECTOR2< int32_t > VECTOR2I