56#include <wx/richmsgdlg.h>
60#define MULTICHANNEL_EXTRA_DEBUG
67 std::vector<wxString> refs;
74 refs.push_back( fp->GetReferenceAsString() );
77 std::sort( refs.begin(), refs.end(),
78 [](
const wxString& aLhs,
const wxString& aRhs )
80 return aLhs.CmpNoCase( aRhs ) < 0;
88 size_t componentsOnLine = 0;
90 for(
const wxString& ref : refs )
92 if( componentsOnLine == 10 )
106 if( !line.IsEmpty() )
122 for(
const wxString& reason : aReasons )
124 if( !
text.IsEmpty() )
135 const std::vector<wxString>& aReasons )
137 if( !aParent || aReasons.empty() )
140 wxRichMessageDialog dlg( aParent, aSummary,
_(
"Topology mismatch" ), wxICON_ERROR | wxOK );
157 const std::vector<wxString>& aReasons )
const
159 wxWindow* parent = aParent ? aParent :
frame();
172 std::set<FOOTPRINT*>& aComponents )
174 if( !aRuleArea || !aRuleArea->
m_zone )
185 aComponents.insert(
static_cast<FOOTPRINT*
>( item ) );
188 return (
int) aComponents.size();
197 [&](
const wxString& aMessage,
int aOffset )
227 auto ok = compiler.
Compile( ruleText, &ucode, &preflightCtx );
241 fp->GetSheetname() );
243 aComponents.insert( fp );
253 if( !aRuleArea || !aRuleArea->
m_zone )
278 if( !boardItem->IsConnected() || boardItem->Type() ==
PCB_ZONE_T )
279 aItems.insert( boardItem );
283 return aItems.size() > 0;
291 bool zoneOnBoard =
false;
295 if( zone == aRuleArea->
m_zone )
319 if( !boardItem->IsConnected() || boardItem->Type() ==
PCB_ZONE_T )
320 aItems.insert( boardItem );
325 return aItems.size() > 0;
334 [&](
const wxString& aMessage,
int aOffset )
345 wxString ruleText = wxString::Format( wxT(
"A.enclosedByArea('%s')" ),
348 if( !compiler.
Compile( ruleText, &ucode, &preflightCtx ) )
355 auto val = ucode.
Run( &ctx );
357 if( val->AsDouble() != 0.0 )
358 aItems.insert( aItem );
363 if( zone == aRuleArea->
m_zone )
371 if( !drawing->IsConnected() )
372 testAndAdd( drawing );
381 std::set<FOOTPRINT*> rv;
383 if( aSheetName.EndsWith( wxT(
"/" ) ) )
384 aSheetName.RemoveLast();
386 wxString childPrefix = aSheetName + wxT(
"/" );
390 auto sn = fp->GetSheetname();
392 if( sn.EndsWith( wxT(
"/" ) ) )
395 if( sn == aSheetName || sn.StartsWith( childPrefix ) )
406 std::set<FOOTPRINT*> rv;
410 if( fp->GetComponentClass()->ContainsClassName( aComponentClassName ) )
423 aOut.insert(
static_cast<FOOTPRINT*
>( item ) );
437 else if( item->IsBOARD_ITEM() )
438 aOut.insert(
static_cast<BOARD_ITEM*
>( item ) );
445 std::set<FOOTPRINT*> rv;
449 if(
group->GetName() == aGroupName )
459 std::set<BOARD_ITEM*> rv;
463 if(
group->GetName() != aGroupName )
468 if( item->IsBOARD_ITEM() )
469 rv.insert(
static_cast<BOARD_ITEM*
>( item ) );
479 std::vector<VECTOR2I> bbCorners;
480 bbCorners.reserve( aFootprints.size() * 4 );
484 const BOX2I bb = fp->GetBoundingBox(
false ).GetInflated( aMargin );
488 std::vector<VECTOR2I> hullVertices;
499 std::vector<VECTOR2I> bbCorners;
500 bbCorners.reserve( aItems.size() * 4 );
504 BOX2I bb = item->GetBoundingBox();
507 bb =
static_cast<FOOTPRINT*
>( item )->GetBoundingBox(
false );
512 std::vector<VECTOR2I> hullVertices;
526 std::vector<wxString> segments;
529 for( wxUniChar ch : aSheetName )
534 segments.push_back( cur );
545 segments.push_back( cur );
547 std::vector<wxString> rv;
548 wxString prefix = wxT(
"/" );
550 for(
size_t i = 0; i + 1 < segments.size(); ++i )
552 prefix += segments[i] + wxT(
"/" );
553 rv.push_back( prefix );
564 std::map<wxString, wxString> uniqueSheets;
565 std::set<wxString> uniqueComponentClasses;
566 std::set<wxString> uniqueGroups;
572 uniqueSheets[fp->GetSheetname()] = fp->GetSheetfile();
576 uniqueSheets.emplace( parent, wxString() );
581 uniqueComponentClasses.insert( singleClass->GetName() );
587 if( !grp->GetName().IsEmpty() )
588 uniqueGroups.insert( grp->GetName() );
592 for(
const auto& [sheetPath, sheetFile] : uniqueSheets )
601 m_areas.m_areas.push_back( ent );
606 (
int)
m_areas.m_areas.size() );
609 for(
const wxString& compClass : uniqueComponentClasses )
617 m_areas.m_areas.push_back( ent );
621 static_cast<int>(
m_areas.m_areas.size() ) );
624 for(
const wxString& groupName : uniqueGroups )
632 m_areas.m_areas.push_back( ent );
636 static_cast<int>(
m_areas.m_areas.size() ) );
647 if( !zone->GetIsRuleArea() )
650 if( !zone->GetPlacementAreaEnabled() )
658 area.
m_center = zone->Outline()->COutline( 0 ).Centre();
662 m_areas.m_areas.push_back( area );
692 std::vector<ZONE*> refRAs;
694 auto isSelectedItemAnRA =
700 ZONE* zone =
static_cast<ZONE*
>( aItem );
713 if(
ZONE* zone = isSelectedItemAnRA( item ) )
715 refRAs.push_back( zone );
723 if(
ZONE* grpZone = isSelectedItemAnRA( grpItem ) )
724 refRAs.push_back( grpZone );
729 if( refRAs.size() != 1 )
734 _(
"Select a reference Rule Area to copy from..." ),
737 return isSelectedItemAnRA( aItem ) !=
nullptr;
751 if(
m_areas.m_areas.size() <= 1 )
753 frame()->ShowInfoBarError(
_(
"No Rule Areas to repeat layout to have been found." ),
true );
773 if( ra.
m_zone == aRefZone )
785 std::vector<RULE_AREA*> targets;
792 targets.push_back( &ra );
796 if( targets.empty() )
799 int total =
static_cast<int>( targets.size() );
800 std::atomic<int> completed( 0 );
801 std::atomic<bool> cancelled(
false );
802 std::atomic<int> matchedComponents( 0 );
803 std::atomic<int> totalComponents( 0 );
818 auto future =
tp.submit_task(
819 [
this, refRA, &targets, &completed, &cancelled, &matchedComponents, &isoParams]()
823 if( cancelled.load( std::memory_order_relaxed ) )
826 matchedComponents.store( 0, std::memory_order_relaxed );
830 completed.fetch_add( 1, std::memory_order_relaxed );
836 std::unique_ptr<WX_PROGRESS_REPORTER>
reporter;
837 auto startTime = std::chrono::steady_clock::now();
838 double highWaterMark = 0.0;
840 while( future.wait_for( std::chrono::milliseconds( 100 ) ) != std::future_status::ready )
844 auto elapsed = std::chrono::steady_clock::now() - startTime;
846 if( elapsed > std::chrono::seconds( 1 ) )
848 reporter = std::make_unique<WX_PROGRESS_REPORTER>(
854 wxLog::FlushActive();
860 int done = completed.load( std::memory_order_relaxed );
861 int matched = matchedComponents.load( std::memory_order_relaxed );
862 int compTotal = totalComponents.load( std::memory_order_relaxed );
864 double fraction = ( compTotal > 0 )
865 ?
static_cast<double>( matched ) / compTotal
867 double progress =
static_cast<double>( done + fraction ) / total;
869 if( progress > highWaterMark )
870 highWaterMark = progress;
872 reporter->SetCurrentProgress( highWaterMark );
874 _(
"Resolving topology %d of %d (%d/%d components)" ),
875 done + 1, total, matched, compTotal ) );
878 cancelled.store(
true, std::memory_order_relaxed );
887 if( cancelled.load( std::memory_order_relaxed ) )
899 wxString* aErrorOut )
901 wxCHECK_MSG( aRefArea.
m_zone, -1, wxT(
"Reference Rule Area has no zone." ) );
902 wxCHECK_MSG( aTargetArea.
m_zone, -1, wxT(
"Target Rule Area has no zone." ) );
904 const bool silent = aErrorOut !=
nullptr;
906 auto reportError = [&](
const wxString& aMsg )
910 else if(
Pgm().IsGUI() )
911 frame()->ShowInfoBarError( aMsg,
true );
923 else if(
Pgm().IsGUI() )
925 wxString summary = wxString::Format(
_(
"Rule Area topologies do not match: %s" ), compat.
m_errorMsg );
932 std::optional<BOARD_COMMIT> localCommit;
934 if( !aExternalCommit )
935 localCommit.emplace(
GetManager(),
true,
false );
937 BOARD_COMMIT& commit = aExternalCommit ? *aExternalCommit : *localCommit;
950 auto errMsg = wxString::Format(
_(
"Could not copy the layout from '%s' to '%s'." ),
953 if( !aExternalCommit )
956 reportError( errMsg );
970 if( !aExternalCommit )
973 reportError(
_(
"Target group does not have a group." ) );
983 group->AddItem( item );
987 if( !aExternalCommit )
988 commit.
Push(
_(
"Repeat layout" ) );
1000 for(
auto& [targetArea, compatData] :
m_areas.m_compatMap )
1002 if( !compatData.m_doCopy )
1005 targetArea->m_ruleName );
1009 if( !compatData.m_isOk )
1014 auto errMsg = wxString::Format(
_(
"Could not copy the layout from '%s' to '%s'." ),
1015 m_areas.m_refRA->m_zone->GetZoneName(), targetArea->m_zone->GetZoneName() );
1020 frame()->ShowInfoBarError( errMsg,
true );
1029 if(
m_areas.m_options.m_groupItems )
1031 for(
const auto& [targetArea, compatData] :
m_areas.m_compatMap )
1033 if( compatData.m_groupableItems.size() < 2 )
1042 for(
BOARD_ITEM* item : compatData.m_groupableItems )
1045 group->AddItem( item );
1050 commit.
Push(
_(
"Repeat layout" ) );
1053 frame()->ShowInfoBarMsg( wxString::Format(
_(
"Copied to %d Rule Areas." ), totalCopied ),
true );
1065 for(
auto k : aRef )
1073 if( ( c >=
'a' && c <=
'z' ) || ( c >=
'A' && c <=
'Z' ) || ( c ==
'_' ) )
1084 std::shared_ptr<CONNECTIVITY_DATA> aConnectivity,
1087 if( !aRuleArea || !aRuleArea->
m_zone )
1116 if(
EDA_GROUP* parent = bci->GetParentGroup() )
1122 if( bci->IsConnected() )
1123 aOutput.insert( bci );
1127 return (
int) aOutput.size();
1134 bool zoneOnBoard =
false;
1138 if( zone == aRuleArea->
m_zone )
1152 if( aOutput.contains( aItem ) )
1156 if(
EDA_GROUP* parent = aItem->GetParentGroup() )
1166 aItem->TransformShapeToPolygon( itemShape, aItem->GetLayer(), 0, maxError,
ERROR_OUTSIDE );
1175 aOutput.insert( aItem );
1181 enclosedByZone( track );
1185 if( drawing->IsConnected() )
1198 [&](
const wxString& aMessage,
int aOffset )
1209 wxString ruleText = wxString::Format( wxT(
"A.enclosedByArea('%s')" ),
1215 if( aOutput.contains( aItem ) )
1219 if(
EDA_GROUP* parent = aItem->GetParentGroup() )
1230 aOutput.insert( aItem );
1235 if( compiler.
Compile( ruleText, &ucode, &preflightCtx ) )
1238 testAndAdd( track );
1242 if( drawing->IsConnected() )
1268 targetAnchorFp = targetFP;
1276 if( targetAnchorFp )
1283 disp = newpos - oldpos;
1296 newTargetOutline.
Move( disp );
1311 std::vector<std::pair<BOARD_ITEM*, BOARD_ITEM*>> groupFixupPairs;
1312 std::set<BOARD_ITEM*> reproducedSourceItems;
1314 auto fixupParentGroup =
1319 destItem->SetParentGroup(
nullptr );
1321 if( !preserveGroups )
1325 groupFixupPairs.emplace_back( sourceItem, destItem );
1327 reproducedSourceItems.insert( sourceItem );
1333 bool targetZoneOnBoard =
false;
1335 if( aTargetArea->
m_zone )
1339 if( z == aTargetArea->
m_zone )
1341 targetZoneOnBoard =
true;
1347 if( targetZoneOnBoard )
1355 if( preserveGroups )
1358 groupFixupPairs.emplace_back( aRefArea->
m_zone, aTargetArea->
m_zone );
1360 reproducedSourceItems.insert( aRefArea->
m_zone );
1366 std::set<BOARD_CONNECTED_ITEM*> refRouting;
1367 std::set<BOARD_CONNECTED_ITEM*> targetRouting;
1373 std::set<int> targc;
1377 for(
PAD*
pad : refFP->Pads() )
1378 refc.insert(
pad->GetNetCode() );
1380 for(
PAD*
pad : targetFP->Pads() )
1381 targc.insert(
pad->GetNetCode() );
1388 std::set<int> targetGroupNets;
1397 targetGroupNets.insert(
pad->GetNetCode() );
1401 targetGroupNets.insert( bci->GetNetCode() );
1420 if( item->GetParentGroup() )
1423 if( item->IsLocked() )
1426 if( item->GetNetCode() <= 0 || !targetGroupNets.contains( item->GetNetCode() ) )
1470 fixupParentGroup( item,
copied );
1480 std::vector<PCB_GENERATOR*> refGenerators;
1481 std::vector<PCB_GENERATOR*> targetGenerators;
1488 refGenerators.push_back(
static_cast<PCB_GENERATOR*
>( item ) );
1493 if( !targetGroup && !aTargetArea->
m_components.empty() )
1494 targetGroup = ( *aTargetArea->
m_components.begin() )->GetParentGroup();
1501 targetGenerators.push_back(
static_cast<PCB_GENERATOR*
>( member ) );
1512 if( gen->GetGeneratorType() != wxT(
"tuning_pattern" ) )
1515 if( gen->HitTest( refOut,
false ) )
1516 refGenerators.push_back( gen );
1517 else if( gen->HitTest( targetOut,
false ) )
1518 targetGenerators.push_back( gen );
1528 aCommit->
Remove( child );
1551 clone->
Move( disp );
1552 aCommit->
Add( clone );
1562 aCommit->
Add( child );
1572 std::set<BOARD_ITEM*> sourceItems;
1573 std::set<BOARD_ITEM*> targetItems;
1591 if( item->GetParent() && item->GetParent()->Type() ==
PCB_FOOTPRINT_T )
1608 ZONE* zone =
static_cast<ZONE*
>( item );
1631 if( item->GetParent() && item->GetParent()->Type() ==
PCB_FOOTPRINT_T )
1641 ZONE* zone =
static_cast<ZONE*
>( item );
1643 if( !skipLayerFilter )
1645 LSET allowedLayers =
1653 ZONE* targetZone =
static_cast<ZONE*
>( item->Duplicate(
false ) );
1660 if( !skipLayerFilter )
1674 fixupParentGroup( item,
copied );
1692 refFP->GetReference() );
1698 refFP->GetReference() );
1705 && !refFP->GetEffectiveShape( refFP->GetLayer() )->Collide( &refPoly, 0 ) )
1713 aCommit->
Modify( targetFP );
1715 targetFP->SetLayerAndFlip( refFP->GetLayer() );
1716 targetFP->SetOrientation( refFP->GetOrientation() );
1717 targetFP->SetPosition( refFP->GetPosition() );
1718 targetFP->Rotate(
VECTOR2( 0, 0 ), rot );
1719 targetFP->Move( disp );
1721 for(
PCB_FIELD* refField : refFP->GetFields() )
1723 wxCHECK2( refField,
continue );
1725 PCB_FIELD* targetField = targetFP->GetField( refField->GetName() );
1730 targetField->
SetLayerSet( refField->GetLayerSet() );
1731 targetField->
SetVisible( refField->IsVisible() );
1733 targetField->
SetPosition( refField->GetPosition() );
1736 targetField->
Move( disp );
1743 std::set<PCB_TEXT*> consumedTargets;
1745 for(
BOARD_ITEM* refItem : refFP->GraphicalItems() )
1753 for(
BOARD_ITEM* targetItem : targetFP->GraphicalItems() )
1760 if( consumedTargets.contains( candidate ) || candidate->
GetText() != refText->
GetText() )
1765 targetText = candidate;
1774 consumedTargets.insert( targetText );
1782 targetText->
Move( disp );
1787 targetFP->Models() = refFP->Models();
1789 std::set<PAD*> consumedPads;
1791 for(
PAD* refPad : refFP->Pads() )
1793 for(
PAD* targetPad : targetFP->Pads() )
1795 if( consumedPads.contains( targetPad ) || targetPad->GetNumber() != refPad->GetNumber() )
1800 consumedPads.insert( targetPad );
1801 targetPad->ImportSettingsFrom( *refPad );
1811 if( preserveGroups && refFP->GetParentGroup() )
1812 groupFixupPairs.emplace_back( refFP, targetFP );
1814 if( preserveGroups )
1815 reproducedSourceItems.insert( refFP );
1822 if( preserveGroups && !groupFixupPairs.empty() )
1824 std::map<EDA_GROUP*, EDA_GROUP*> groupMap;
1825 std::map<EDA_GROUP*, bool> fullyReproducedCache;
1827 auto groupFullyReproduced =
1830 if(
auto it = fullyReproducedCache.find( aGroup ); it != fullyReproducedCache.end() )
1833 bool reproduced =
true;
1835 for(
EDA_ITEM* member : aGroup->GetItems() )
1839 if( !member->IsBOARD_ITEM()
1840 || !reproducedSourceItems.contains(
static_cast<BOARD_ITEM*
>( member ) ) )
1847 fullyReproducedCache[aGroup] = reproduced;
1851 for(
const auto& [sourceItem, destItem] : groupFixupPairs )
1855 if( !parentGroup || !groupFullyReproduced( parentGroup ) )
1858 if( !groupMap.contains( parentGroup ) )
1868 newGroup->
Move( disp );
1871 groupMap[parentGroup] = newGroup;
1872 aCommit->
Add( newGroup );
1877 if(
EDA_GROUP* oldGroup = destItem->GetParentGroup() )
1879 if( oldGroup != groupMap[parentGroup] )
1880 aCommit->
Modify( oldGroup->AsEdaItem() );
1883 groupMap[parentGroup]->AddItem( destItem );
1903 if( aComponentMatches.empty() )
1910 const std::vector<BOARD_CONNECTED_ITEM*> refConnectedPads = connectivity->
GetNetItems( aRef->
GetNetCode(),
1918 const PAD* refPad =
static_cast<const PAD*
>( refConItem );
1921 if( aComponentMatches.contains( sourceFootprint ) )
1923 const FOOTPRINT* targetFootprint = aComponentMatches[sourceFootprint];
1924 std::vector<const PAD*> targetFpPads = targetFootprint->
GetPads( refPad->
GetNumber() );
1926 if( !targetFpPads.empty() )
1928 int targetNetCode = targetFpPads[0]->GetNet()->GetNetCode();
1939 const std::set<FOOTPRINT*>& aFootprints,
1940 const std::unordered_set<EDA_ITEM*>& aItems )
1942 std::vector<NETINFO_ITEM*> created;
1943 std::map<int, NETINFO_ITEM*> remap;
1949 auto isAutoName = [](
const wxString& aName )
1951 return aName.StartsWith( wxT(
"Net-(" ) ) || aName.StartsWith( wxT(
"unconnected-" ) );
1956 int code = aItem->GetNetCode();
1963 if( !oldNet || !isAutoName( oldNet->
GetNetname() ) )
1966 auto it = remap.find( code );
1968 if( it == remap.end() )
1974 name = wxString::Format( wxT(
"__dbapply_%d_%d" ), code, counter++ );
1978 aBoard->
Add( newNet );
1979 created.push_back( newNet );
1980 it = remap.emplace( code, newNet ).first;
1983 aItem->SetNet( it->second );
1988 for(
PAD*
pad : fp->Pads() )
2009 if( aRef.empty() || aRef.size() != aTarget.size() )
2018 std::map<KIID, FOOTPRINT*> targetByUuid;
2022 KIID uuid = symbolUuid( fp );
2025 if( uuid ==
niluuid || !targetByUuid.emplace( uuid, fp ).second )
2030 std::set<FOOTPRINT*> used;
2034 KIID uuid = symbolUuid( refFp );
2039 auto it = targetByUuid.find( uuid );
2041 if( it == targetByUuid.end() )
2047 if( refFp->GetFPID() != targetFp->
GetFPID() || refFp->Pads().size() != targetFp->
Pads().size() )
2050 if( !used.insert( targetFp ).second )
2053 result[refFp] = targetFp;
2056 aResult = std::move(
result );
2083 std::set<FOOTPRINT*> shared;
2086 std::inserter( shared, shared.begin() ) );
2088 if( !shared.empty() )
2092 aMatches.
m_errorMsg =
_(
"Target Rule Area shares components with the reference area" );
2095 _(
"This target Rule Area selects the same components as the reference area. "
2096 "Repeat layout cannot copy a Rule Area onto itself. Give each placement Rule "
2097 "Area a distinct sheet, component class or group." ) );
2098 aMatches.
m_mismatchReasons.push_back( wxString::Format(
_(
"Shared components:\n%s" ),
2106 std::unordered_map<int, std::vector<const RULE_AREA*>> netInternalAreas;
2110 std::unordered_map<int, int> areaNetPadCounts;
2116 if(
pad->GetNetCode() > 0 )
2117 areaNetPadCounts[
pad->GetNetCode()]++;
2121 for(
const auto& [netCode, padCount] : areaNetPadCounts )
2124 netInternalAreas[netCode].push_back( &area );
2135 if( aB->m_components.count( fp ) )
2142 std::unordered_set<int> globalNets;
2144 for(
const auto& [netCode, areas] : netInternalAreas )
2146 for(
size_t i = 0; i < areas.size() && !globalNets.count( netCode ); i++ )
2148 for(
size_t j = i + 1; j < areas.size(); j++ )
2150 if( disjoint( areas[i], areas[j] ) )
2152 globalNets.insert( netCode );
2173 std::vector<TMATCH::TOPOLOGY_MISMATCH_REASON> mismatchReasons;
2177 mismatchReasons, aParams );
2189 if( !status && !cancelled
2196 aMatches.
m_isOk = status;
2207 for(
const auto& reason : mismatchReasons )
2209 if( reason.m_reason.IsEmpty() )
2212 if( !reason.m_reference.IsEmpty() && !reason.m_candidate.IsEmpty() )
2214 else if( !reason.m_reference.IsEmpty() )
2218 reason.m_reason ) );
2225 aMatches.
m_mismatchReasons.push_back(
_(
"The components in the two areas could not be paired up." ) );
2232 aMatches.
m_mismatchReasons.push_back( wxString::Format(
_(
"Reference area components:\n%s" ),
2234 aMatches.
m_mismatchReasons.push_back( wxString::Format(
_(
"Target area components:\n%s" ),
2245 const std::unordered_set<BOARD_ITEM*>& aItemsToRemove )
2251 std::vector<EDA_ITEM*> pruneList;
2257 if( refItem->m_Uuid == testItem->m_Uuid )
2258 pruneList.push_back( refItem );
2262 if( !pruneList.empty() )
2267 group->RemoveItem( item );
2269 if(
group->GetItems().size() < 2 )
2284 if(
m_areas.m_areas.size() <= 1 )
2286 frame()->ShowInfoBarError(
_(
"Cannot auto-generate any placement areas because the "
2287 "schematic has only one or no hierarchical sheets, "
2288 "groups, or component classes." ),
2296 if( ret != wxID_OK )
2302 if( !zone->GetIsRuleArea() )
2305 if( !zone->GetPlacementAreaEnabled() )
2308 std::set<FOOTPRINT*> components;
2311 zoneRA.
m_sourceType = zone->GetPlacementAreaSourceType();
2314 if( components.empty() )
2324 wxT(
"Placement rule area for sheet '%s' already exists as '%s'\n" ),
2330 wxT(
"Placement rule area for component class '%s' already exists as '%s'\n" ),
2336 wxT(
"Placement rule area for group '%s' already exists as '%s'\n" ),
2370 if( groupItems.empty() )
2373 wxT(
"Skipping placement rule area generation for source group '%s': group has no board items." ),
2385 std::set<BOARD_ITEM*> outlineItems;
2386 std::set<EDA_GROUP*> groups;
2387 std::set<int> channelNets;
2391 outlineItems.insert( fp );
2394 channelNets.insert(
pad->GetNetCode() );
2405 std::set<int> foreignNets;
2413 foreignNets.insert(
pad->GetNetCode() );
2418 int net = track->GetNetCode();
2420 if( net > 0 && channelNets.count( net ) && !foreignNets.count( net ) )
2421 outlineItems.insert( track );
2427 std::unique_ptr<ZONE> newZone(
new ZONE(
board() ) );
2430 newZone->SetZoneName( wxString::Format( wxT(
"auto-placement-area-%s" ), ra.
m_sheetPath ) );
2432 newZone->SetZoneName( wxString::Format( wxT(
"auto-placement-area-%s" ), ra.
m_componentClass ) );
2434 newZone->SetZoneName( wxString::Format( wxT(
"auto-placement-area-%s" ), ra.
m_groupName ) );
2437 newZone->GetZoneName(),
2440 newZone->SetIsRuleArea(
true );
2442 newZone->SetPlacementAreaEnabled(
true );
2443 newZone->SetDoNotAllowZoneFills(
false );
2444 newZone->SetDoNotAllowVias(
false );
2445 newZone->SetDoNotAllowTracks(
false );
2446 newZone->SetDoNotAllowPads(
false );
2447 newZone->SetDoNotAllowFootprints(
false );
2452 newZone->SetPlacementAreaSource( ra.
m_sheetPath );
2462 newZone->SetPlacementAreaSource( ra.
m_groupName );
2465 newZone->AddPolygon( raOutline );
2473 ra.
m_zone = newZone.release();
2480 if(
m_areas.m_options.m_groupItems )
2494 std::unordered_set<BOARD_ITEM*> toPrune;
2499 toPrune.insert( ra.
m_zone );
2513 group->AddItem( fp );
2518 commit.
Push(
_(
"Auto-generate placement rule areas" ) );
virtual void Push(const wxString &aMessage=wxEmptyString, int aCommitFlags=0) override
Execute the changes.
virtual 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.
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.
FOOTPRINT * GetParentFootprint() const
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.
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
std::shared_ptr< CONNECTIVITY_DATA > GetConnectivity() const
Return a list of missing connections between components/tracks.
constexpr BOX2< Vec > GetInflated(coord_type aDx, coord_type aDy) const
Get a new rectangle that is this one, inflated by aDx and aDy.
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.
const std::vector< BOARD_CONNECTED_ITEM * > GetNetItems(int aNetCode, const std::vector< KICAD_T > &aTypes) const
Function GetNetItems() Returns the list of items that belong to a certain net.
A set of EDA_ITEMs (i.e., without duplicates).
std::unordered_set< EDA_ITEM * > & GetItems()
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
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(std::function< void(const wxString &aMessage, int aOffset)> 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
const wxString & GetNumber() const
void SetItems(BOARD_ITEM *a, BOARD_ITEM *b=nullptr)
static TOOL_ACTION repeatLayout
static TOOL_ACTION generatePlacementRuleAreas
static TOOL_ACTION selectItemInteractively
Selection of reference points/items.
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_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.
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={})
Build a polygon triangulation, needed to draw a polygon on OpenGL and in some other calculations.
void BooleanSubtract(const SHAPE_POLY_SET &b)
Perform boolean polyset difference.
const SHAPE_LINE_CHAIN & COutline(int aIndex) const
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.
bool GetIsRuleArea() const
Accessors to parameters used in Rule Area zones:
void AddPolygon(std::vector< VECTOR2I > &aPolygon)
Add a polygon to the zone outline.
wxString GetPlacementAreaSource() const
void HatchBorder()
Compute the hatch lines depending on the hatch parameters and stores it in the zone's attribute m_bor...
PLACEMENT_SOURCE_T GetPlacementAreaSourceType() const
SHAPE_POLY_SET * Outline()
const wxString & GetZoneName() const
bool GetPlacementAreaEnabled() const
virtual LSET GetLayerSet() const override
Return a std::bitset of all layers on which the item physically resides.
void UnHatchBorder()
Clear the zone's hatch.
void RemoveAllContours(void)
void BuildConvexHull(std::vector< VECTOR2I > &aResult, const std::vector< VECTOR2I > &aPoly)
Calculate the convex hull of a list of points in counter-clockwise order.
SHAPE_LINE_CHAIN RectifyPolygon(const SHAPE_LINE_CHAIN &aPoly)
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
Class to handle a set of BOARD_ITEMs.
PGM_BASE & Pgm()
The global program "get" accessor.
Utility functions for working with shapes.
void AccumulateDescription(wxString &aDesc, const wxString &aItem)
Utility to build comma separated lists in messages.
bool m_connectedRoutingOnly
bool m_includeLockedItems
std::vector< wxString > m_mismatchReasons
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::unordered_set< BOARD_ITEM * > m_groupableItems
Filled in by copyRuleAreaContents with affected items that can be grouped together.
std::unordered_set< EDA_ITEM * > m_designBlockItems
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.
thread_pool & GetKiCadThreadPool()
Get a reference to the current thread pool.
BS::priority_thread_pool thread_pool
@ PCB_GENERATOR_T
class PCB_GENERATOR, generator on a 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
VECTOR2< int32_t > VECTOR2I