53#include <wx/richmsgdlg.h>
57#define MULTICHANNEL_EXTRA_DEBUG
63 const std::vector<wxString>& aReasons )
65 if( !aParent || aReasons.empty() )
70 for(
size_t idx = 0; idx < aReasons.size(); ++idx )
73 reasonText += wxT(
"\n" );
75 reasonText += aReasons[idx];
78 wxRichMessageDialog dlg( aParent, aSummary,
_(
"Topology mismatch" ), wxICON_ERROR | wxOK );
79 dlg.ShowDetailedText( reasonText );
95 const std::vector<wxString>& aReasons )
const
97 wxWindow* parent = aParent ? aParent :
frame();
110 std::set<FOOTPRINT*>& aComponents )
112 if( !aRuleArea || !aRuleArea->
m_zone )
123 aComponents.insert(
static_cast<FOOTPRINT*
>( item ) );
126 return (
int) aComponents.size();
135 [&](
const wxString& aMessage,
int aOffset )
165 auto ok = compiler.
Compile( ruleText, &ucode, &preflightCtx );
179 fp->GetSheetname() );
181 aComponents.insert( fp );
191 if( !aRuleArea || !aRuleArea->
m_zone )
207 if( !boardItem->IsConnected() )
208 aItems.insert( boardItem );
212 return aItems.size() > 0;
220 [&](
const wxString& aMessage,
int aOffset )
231 wxString ruleText = wxString::Format( wxT(
"A.enclosedByArea('%s')" ),
234 if( !compiler.
Compile( ruleText, &ucode, &preflightCtx ) )
241 auto val = ucode.
Run( &ctx );
243 if( val->AsDouble() != 0.0 )
244 aItems.insert( aItem );
249 if( zone == aRuleArea->
m_zone )
257 if( !drawing->IsConnected() )
258 testAndAdd( drawing );
267 std::set<FOOTPRINT*> rv;
269 if( aSheetName.EndsWith( wxT(
"/" ) ) )
270 aSheetName.RemoveLast();
274 auto sn = fp->GetSheetname();
275 if( sn.EndsWith( wxT(
"/" ) ) )
278 if( sn == aSheetName )
289 std::set<FOOTPRINT*> rv;
293 if( fp->GetComponentClass()->ContainsClassName( aComponentClassName ) )
303 std::set<FOOTPRINT*> rv;
307 if(
group->GetName() == aGroupName )
312 rv.insert(
static_cast<FOOTPRINT*
>( item ) );
323 std::vector<VECTOR2I> bbCorners;
324 bbCorners.reserve( aFootprints.size() * 4 );
328 const BOX2I bb = fp->GetBoundingBox(
false ).GetInflated( aMargin );
332 std::vector<VECTOR2I> hullVertices;
344 using PathAndName = std::pair<wxString, wxString>;
345 std::set<PathAndName> uniqueSheets;
346 std::set<wxString> uniqueComponentClasses;
347 std::set<wxString> uniqueGroups;
353 uniqueSheets.insert( PathAndName( fp->GetSheetname(), fp->GetSheetfile() ) );
358 uniqueComponentClasses.insert( singleClass->GetName() );
360 if( fp->GetParentGroup() && !fp->GetParentGroup()->GetName().IsEmpty() )
361 uniqueGroups.insert( fp->GetParentGroup()->GetName() );
364 for(
const PathAndName& sheet : uniqueSheets )
373 m_areas.m_areas.push_back( ent );
378 (
int)
m_areas.m_areas.size() );
381 for(
const wxString& compClass : uniqueComponentClasses )
389 m_areas.m_areas.push_back( ent );
393 static_cast<int>(
m_areas.m_areas.size() ) );
396 for(
const wxString& groupName : uniqueGroups )
404 m_areas.m_areas.push_back( ent );
408 static_cast<int>(
m_areas.m_areas.size() ) );
419 if( !zone->GetIsRuleArea() )
422 if( !zone->GetPlacementAreaEnabled() )
430 area.
m_center = zone->Outline()->COutline( 0 ).Centre();
434 m_areas.m_areas.push_back( area );
464 std::vector<ZONE*> refRAs;
466 auto isSelectedItemAnRA =
472 ZONE* zone =
static_cast<ZONE*
>( aItem );
485 if(
ZONE* zone = isSelectedItemAnRA( item ) )
487 refRAs.push_back( zone );
495 if(
ZONE* grpZone = isSelectedItemAnRA( grpItem ) )
496 refRAs.push_back( grpZone );
501 if( refRAs.size() != 1 )
506 _(
"Select a reference Rule Area to copy from..." ),
509 return isSelectedItemAnRA( aItem ) !=
nullptr;
523 if(
m_areas.m_areas.size() <= 1 )
525 frame()->ShowInfoBarError(
_(
"No Rule Areas to repeat layout to have been found." ),
true );
545 if( ra.
m_zone == aRefZone )
579 wxString summary = wxString::Format(
_(
"Rule Area topologies do not match: %s" ), compat.
m_errorMsg );
590 auto errMsg = wxString::Format(
_(
"Copy Rule Area contents failed between rule areas '%s' and '%s'." ),
591 m_areas.m_refRA->m_zone->GetZoneName(),
597 frame()->ShowInfoBarError( errMsg,
true );
609 frame()->ShowInfoBarError(
_(
"Target group does not have a group." ),
true );
621 group->AddItem( item );
625 commit.
Push(
_(
"Repeat layout" ) );
637 for(
auto& [targetArea, compatData] :
m_areas.m_compatMap )
639 if( !compatData.m_doCopy )
642 targetArea->m_ruleName );
646 if( !compatData.m_isOk )
651 auto errMsg = wxString::Format(
_(
"Copy Rule Area contents failed between rule areas '%s' and '%s'." ),
652 m_areas.m_refRA->m_zone->GetZoneName(),
653 targetArea->m_zone->GetZoneName() );
658 frame()->ShowInfoBarError( errMsg,
true );
667 if(
m_areas.m_options.m_groupItems )
669 for(
const auto& [targetArea, compatData] :
m_areas.m_compatMap )
677 for(
BOARD_ITEM* item : compatData.m_groupableItems )
680 group->AddItem( item );
685 commit.
Push(
_(
"Repeat layout" ) );
688 frame()->ShowInfoBarMsg( wxString::Format(
_(
"Copied to %d Rule Areas." ), totalCopied ),
true );
708 if( ( c >=
'a' && c <=
'z' ) || ( c >=
'A' && c <=
'Z' ) || ( c ==
'_' ) )
719 std::shared_ptr<CONNECTIVITY_DATA> aConnectivity,
722 if( !aRuleArea || !aRuleArea->
m_zone )
744 if( bci->IsConnected() )
745 aOutput.insert( bci );
749 return (
int) aOutput.size();
757 [&](
const wxString& aMessage,
int aOffset )
768 wxString ruleText = wxString::Format( wxT(
"A.enclosedByArea('%s')" ),
774 if( aOutput.contains( aItem ) )
782 aOutput.insert( aItem );
787 if( compiler.
Compile( ruleText, &ucode, &preflightCtx ) )
794 if( drawing->IsConnected() )
820 targetAnchorFp = targetFP;
830 disp = newpos - oldpos;
843 newTargetOutline.
Move( disp );
848 std::map<EDA_GROUP*, EDA_GROUP*> groupMap;
850 auto fixupParentGroup =
855 if( !groupMap.contains( parentGroup ) )
858 groupMap[parentGroup] =
static_cast<PCB_GROUP*
>( newGroup );
859 aCommit->
Add( newGroup );
862 destItem->SetParentGroup( groupMap[parentGroup] );
869 bool targetZoneOnBoard =
false;
875 if( z == aTargetArea->
m_zone )
877 targetZoneOnBoard =
true;
883 if( targetZoneOnBoard )
892 std::set<BOARD_CONNECTED_ITEM*> refRouting;
893 std::set<BOARD_CONNECTED_ITEM*> targetRouting;
903 for(
PAD*
pad : refFP->Pads() )
904 refc.insert(
pad->GetNetCode() );
906 for(
PAD*
pad : targetFP->Pads() )
907 targc.insert(
pad->GetNetCode() );
957 fixupParentGroup( item,
copied );
968 std::set<BOARD_ITEM*> sourceItems;
969 std::set<BOARD_ITEM*> targetItems;
988 ZONE* zone =
static_cast<ZONE*
>( item );
991 bool layerMismatch =
false;
997 layerMismatch =
true;
1000 if( !layerMismatch )
1028 ZONE* zone =
static_cast<ZONE*
>( item );
1031 bool layerMismatch =
false;
1039 layerMismatch =
true;
1046 ZONE* targetZone =
static_cast<ZONE*
>( item->Duplicate(
false ) );
1064 fixupParentGroup( item,
copied );
1082 refFP->GetReference() );
1088 refFP->GetReference() );
1093 if( !refFP->GetEffectiveShape( refFP->GetLayer() )->Collide( &refPoly, 0 ) )
1099 aCommit->
Modify( targetFP );
1101 targetFP->SetLayerAndFlip( refFP->GetLayer() );
1102 targetFP->SetOrientation( refFP->GetOrientation() );
1103 targetFP->SetPosition( refFP->GetPosition() );
1104 targetFP->Rotate(
VECTOR2( 0, 0 ), rot );
1105 targetFP->Move( disp );
1107 for(
PCB_FIELD* refField : refFP->GetFields() )
1109 PCB_FIELD* targetField = targetFP->GetField( refField->GetName() );
1110 wxCHECK2( targetField,
continue );
1112 targetField->
SetLayerSet( refField->GetLayerSet() );
1113 targetField->
SetVisible( refField->IsVisible() );
1115 targetField->
SetPosition( refField->GetPosition() );
1117 targetField->
Move( disp );
1122 for(
BOARD_ITEM* refItem : refFP->GraphicalItems() )
1129 for(
BOARD_ITEM* targetItem : targetFP->GraphicalItems() )
1144 targetText->
Move( disp );
1152 targetFP->Models() = refFP->Models();
1175 const std::vector<BOARD_CONNECTED_ITEM*> refConnectedPads = connectivity->
GetNetItems( aRef->
GetNetCode(),
1183 const PAD* refPad =
static_cast<const PAD*
>( refConItem );
1186 if( aComponentMatches.contains( sourceFootprint ) )
1188 const FOOTPRINT* targetFootprint = aComponentMatches[sourceFootprint];
1189 std::vector<const PAD*> targetFpPads = targetFootprint->
GetPads( refPad->
GetNumber() );
1191 if( !targetFpPads.empty() )
1193 int targetNetCode = targetFpPads[0]->GetNet()->GetNetCode();
1211 std::vector<TMATCH::TOPOLOGY_MISMATCH_REASON> mismatchReasons;
1212 bool status = cgRef->FindIsomorphism( cgTarget.get(), aMatches.
m_matchingComponents, mismatchReasons );
1214 aMatches.
m_isOk = status;
1225 for(
const auto& reason : mismatchReasons )
1227 if( reason.m_reason.IsEmpty() )
1230 if( !reason.m_reference.IsEmpty() && !reason.m_candidate.IsEmpty() )
1235 reason.m_reason ) );
1237 else if( !reason.m_reference.IsEmpty() )
1241 reason.m_reason ) );
1257 const std::unordered_set<BOARD_ITEM*>& aItemsToRemove )
1263 std::vector<EDA_ITEM*> pruneList;
1269 if( refItem->m_Uuid == testItem->m_Uuid )
1270 pruneList.push_back( refItem );
1274 if( !pruneList.empty() )
1279 group->RemoveItem( item );
1281 if(
group->GetItems().empty() )
1296 if(
m_areas.m_areas.size() <= 1 )
1298 frame()->ShowInfoBarError(
_(
"Cannot auto-generate any placement areas because the "
1299 "schematic has only one or no hierarchical sheets, "
1300 "groups, or component classes." ),
1308 if( ret != wxID_OK )
1314 if( !zone->GetIsRuleArea() )
1317 if( !zone->GetPlacementAreaEnabled() )
1320 std::set<FOOTPRINT*> components;
1323 zoneRA.
m_sourceType = zone->GetPlacementAreaSourceType();
1326 if( components.empty() )
1336 wxT(
"Placement rule area for sheet '%s' already exists as '%s'\n" ),
1342 wxT(
"Placement rule area for component class '%s' already exists as '%s'\n" ),
1348 wxT(
"Placement rule area for group '%s' already exists as '%s'\n" ),
1375 std::unique_ptr<ZONE> newZone(
new ZONE(
board() ) );
1378 newZone->SetZoneName( wxString::Format( wxT(
"auto-placement-area-%s" ), ra.
m_sheetPath ) );
1380 newZone->SetZoneName( wxString::Format( wxT(
"auto-placement-area-%s" ), ra.
m_componentClass ) );
1382 newZone->SetZoneName( wxString::Format( wxT(
"auto-placement-area-%s" ), ra.
m_groupName ) );
1385 newZone->GetZoneName(),
1388 newZone->SetIsRuleArea(
true );
1390 newZone->SetPlacementAreaEnabled(
true );
1391 newZone->SetDoNotAllowZoneFills(
false );
1392 newZone->SetDoNotAllowVias(
false );
1393 newZone->SetDoNotAllowTracks(
false );
1394 newZone->SetDoNotAllowPads(
false );
1395 newZone->SetDoNotAllowFootprints(
false );
1400 newZone->SetPlacementAreaSource( ra.
m_sheetPath );
1410 newZone->SetPlacementAreaSource( ra.
m_groupName );
1413 newZone->AddPolygon( raOutline );
1421 ra.
m_zone = newZone.release();
1428 if(
m_areas.m_options.m_groupItems )
1438 std::unordered_set<BOARD_ITEM*> toPrune;
1443 toPrune.insert( ra.
m_zone );
1457 group->AddItem( fp );
1462 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,...
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 PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
virtual BOARD_ITEM * Duplicate(bool addToParentGroup, BOARD_COMMIT *aCommit=nullptr) const
Create a copy of this BOARD_ITEM.
virtual void SetLayerSet(const LSET &aLayers)
virtual bool IsKnockout() const
virtual void SetIsKnockout(bool aKnockout)
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
FOOTPRINT * GetParentFootprint() const
std::shared_ptr< CONNECTIVITY_DATA > GetConnectivity() const
Return a list of missing connections between components/tracks.
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).
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.
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.
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.
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.
A set of BOARD_ITEMs (i.e., without duplicates).
virtual VECTOR2I GetPosition() const override
virtual void SetPosition(const VECTOR2I &aPos) override
void Move(const VECTOR2I &aMoveVector) override
Move this object.
void Rotate(const VECTOR2I &aRotCentre, const EDA_ANGLE &aAngle) override
Rotate this object.
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.
virtual void CacheTriangulation(bool aPartition=true, bool aSimplify=false)
Build a polygon triangulation, needed to draw a polygon on OpenGL and in some other calculations.
const SHAPE_LINE_CHAIN & COutline(int aIndex) const
static std::unique_ptr< CONNECTION_GRAPH > BuildFromFootprintSet(const std::set< FOOTPRINT * > &aFps)
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.
PCB_LAYER_ID
A quick note on layer IDs:
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.
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
@ 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_FOOTPRINT_T
class FOOTPRINT, a footprint
@ PCB_PAD_T
class PAD, a pad in a footprint
VECTOR2< int32_t > VECTOR2I