54#define MULTICHANNEL_EXTRA_DEBUG
78 std::set<FOOTPRINT*>& aComponents )
85 [&](
const wxString& aMessage,
int aOffset )
101 case PLACEMENT_SOURCE_T::SHEETNAME:
104 case PLACEMENT_SOURCE_T::COMPONENT_CLASS:
107 case PLACEMENT_SOURCE_T::GROUP_PLACEMENT:
112 auto ok = compiler.
Compile( ruleText, &ucode, &preflightCtx );
126 fp->GetSheetname() );
128 aComponents.insert( fp );
138 std::vector<BOARD_ITEM*> result;
145 [&](
const wxString& aMessage,
int aOffset )
154 bool restoreBlankName =
false;
158 restoreBlankName =
true;
162 wxString ruleText = wxString::Format( wxT(
"A.enclosedByArea('%s')" ), aRuleArea->
GetZoneName() );
164 if( !compiler.
Compile( ruleText, &ucode, &preflightCtx ) )
166 if( restoreBlankName )
176 auto val = ucode.
Run( &ctx );
178 if( val->AsDouble() != 0.0 )
179 aItems.insert( aItem );
184 if( zone == aRuleArea )
191 testAndAdd( drawing );
196 bool addGroup =
true;
198 group->RunOnChildren(
201 if( aItem->
IsType( { PCB_ZONE_T, PCB_SHAPE_T, PCB_DIMENSION_T } ) )
203 ctx.SetItems( aItem, aItem );
204 LIBEVAL::VALUE* val = ucode.Run( &ctx );
206 if( val->AsDouble() == 0.0 )
210 RECURSE_MODE::RECURSE );
213 aItems.insert(
group );
216 if( restoreBlankName )
225 std::set<FOOTPRINT*> rv;
227 if( aSheetName.EndsWith( wxT(
"/" ) ) )
228 aSheetName.RemoveLast();
232 auto sn = fp->GetSheetname();
233 if( sn.EndsWith( wxT(
"/" ) ) )
236 if( sn == aSheetName )
247 std::set<FOOTPRINT*> rv;
251 if( fp->GetComponentClass()->ContainsClassName( aComponentClassName ) )
261 std::set<FOOTPRINT*> rv;
265 if(
group->GetName() == aGroupName )
270 rv.insert(
static_cast<FOOTPRINT*
>( item ) );
282 std::vector<VECTOR2I> bbCorners;
283 bbCorners.reserve( aFootprints.size() * 4 );
291 std::vector<VECTOR2I> hullVertices;
303 using PathAndName = std::pair<wxString, wxString>;
304 std::set<PathAndName> uniqueSheets;
305 std::set<wxString> uniqueComponentClasses;
306 std::set<wxString> uniqueGroups;
312 uniqueSheets.insert( PathAndName( fp->GetSheetname(), fp->GetSheetfile() ) );
317 uniqueComponentClasses.insert( singleClass->GetName() );
319 if( fp->GetParentGroup() && !fp->GetParentGroup()->GetName().IsEmpty() )
320 uniqueGroups.insert( fp->GetParentGroup()->GetName() );
323 for(
const PathAndName& sheet : uniqueSheets )
340 for(
const wxString& compClass : uniqueComponentClasses )
355 for(
const wxString& groupName : uniqueGroups )
378 if( !zone->GetIsRuleArea() )
381 if( !zone->GetPlacementAreaEnabled() )
392 area.
m_center = zone->Outline()->COutline( 0 ).Centre();
424 std::vector<ZONE*> refRAs;
426 auto isSelectedItemAnRA =
432 ZONE* zone =
static_cast<ZONE*
>( aItem );
445 if(
auto zone = isSelectedItemAnRA( item ) )
447 refRAs.push_back(zone);
455 if(
auto grpZone = isSelectedItemAnRA( grpItem ) )
456 refRAs.push_back( grpZone );
461 if( refRAs.size() != 1 )
466 _(
"Select a reference Rule Area to copy from..." ),
469 return isSelectedItemAnRA( aItem ) !=
nullptr;
485 frame()->ShowInfoBarError(
_(
"No Rule Areas to repeat layout to have been found." ),
true );
505 if( ra.
m_area == aRefZone )
538 if( !targetArea.second.m_doCopy )
541 targetArea.first->m_ruleName );
545 if( !targetArea.second.m_isOk )
550 targetArea.second.m_groupableItems ) )
552 auto errMsg = wxString::Format(
553 _(
"Copy Rule Area contents failed between rule areas '%s' and '%s'." ),
555 targetArea.first->m_area->GetZoneName() );
561 frame()->ShowInfoBarError( errMsg,
true );
580 for(
BOARD_ITEM* item : compatData.m_groupableItems )
583 group->AddItem( item );
588 commit.
Push(
_(
"Repeat layout" ) );
591 frame()->ShowInfoBarMsg( wxString::Format(
_(
"Copied to %d Rule Areas." ), totalCopied ),
true );
611 if( ( c >=
'a' && c <=
'z' ) || ( c >=
'A' && c <=
'Z' ) || ( c ==
'_' ) )
622 std::shared_ptr<CONNECTIVITY_DATA> aConnectivity,
636 auto reportError = [&](
const wxString& aMessage,
int aOffset )
645 bool restoreBlankName =
false;
649 restoreBlankName =
true;
653 wxString ruleText = wxString::Format( wxT(
"A.enclosedByArea('%s')" ), aRA->
m_area->
GetZoneName() );
658 if( aOutput.contains( aItem ) )
666 aOutput.insert( aItem );
671 if( compiler.
Compile( ruleText, &ucode, &preflightCtx ) )
677 if( restoreBlankName )
686 std::unordered_set<BOARD_ITEM*>& aAffectedItems,
687 std::unordered_set<BOARD_ITEM*>& aGroupableItems )
699 for(
auto& fpPair : aMatches )
702 targetAnchorFp = fpPair.second;
712 disp = newpos - oldpos;
725 newTargetOutline.
Move( disp );
733 aAffectedItems.insert( aTargetArea->
m_area );
734 aGroupableItems.insert( aTargetArea->
m_area );
738 std::set<BOARD_CONNECTED_ITEM*> refRouting;
739 std::set<BOARD_CONNECTED_ITEM*> targetRouting;
746 for(
auto& fpPair : aMatches )
748 for(
PAD*
pad : fpPair.first->Pads() )
749 refc.insert(
pad->GetNetCode() );
751 for(
PAD*
pad : fpPair.second->Pads() )
752 targc.insert(
pad->GetNetCode() );
755 findRouting( targetRouting, connectivity, targetPoly, aTargetArea, aOpts );
756 findRouting( refRouting, connectivity, refPoly, aRefArea, aOpts );
770 aAffectedItems.insert( item );
793 copied->SetParentGroup(
nullptr );
795 aGroupableItems.insert(
copied );
802 std::set<BOARD_ITEM*> sourceItems;
803 std::set<BOARD_ITEM*> targetItems;
824 aAffectedItems.insert( item );
830 ZONE* zone =
static_cast<ZONE*
>( item );
833 bool layerMismatch =
false;
839 layerMismatch =
true;
844 aAffectedItems.insert( zone );
875 ZONE* zone =
static_cast<ZONE*
>( item );
878 bool layerMismatch =
false;
886 layerMismatch =
true;
893 ZONE* targetZone =
static_cast<ZONE*
>( item->Clone() );
894 fixupNet( zone, targetZone, aMatches );
902 copied->SetParentGroup(
nullptr );
906 aGroupableItems.insert(
copied );
914 for(
auto& fpPair : aMatches )
939 aCommit->
Modify( targetFP );
945 targetFP->
Move( disp );
948 if( !refField->IsVisible() )
952 wxCHECK2( targetField,
continue );
955 targetField->
SetPosition( refField->GetPosition() );
957 targetField->
Move( disp );
961 aAffectedItems.insert( targetFP );
962 aGroupableItems.insert( targetFP );
982 const std::vector<BOARD_CONNECTED_ITEM*> refConnectedPads = connectivity->GetNetItems( aRef->
GetNetCode(),
990 const PAD* refPad =
static_cast<const PAD*
>( refConItem );
993 if( aComponentMatches.contains( sourceFootprint ) )
995 const FOOTPRINT* targetFootprint = aComponentMatches[sourceFootprint];
996 std::vector<const PAD*> targetFpPads = targetFootprint->
GetPads( refPad->
GetNumber() );
998 if( !targetFpPads.empty() )
1000 int targetNetCode = targetFpPads[0]->GetNet()->GetNetCode();
1015 std::unique_ptr<CONNECTION_GRAPH> cgRef( CONNECTION_GRAPH::BuildFromFootprintSet( aRefArea->
m_raFootprints ) );
1016 std::unique_ptr<CONNECTION_GRAPH> cgTarget( CONNECTION_GRAPH::BuildFromFootprintSet( aTargetArea->
m_raFootprints ) );
1022 case CONNECTION_GRAPH::ST_OK:
1026 case CONNECTION_GRAPH::ST_EMPTY:
1028 aMatches.
m_errorMsg =
_(
"One or both of the areas has no components assigned.");
1030 case CONNECTION_GRAPH::ST_COMPONENT_COUNT_MISMATCH:
1032 aMatches.
m_errorMsg =
_(
"Component count mismatch");
1034 case CONNECTION_GRAPH::ST_ITERATION_COUNT_EXCEEDED:
1036 aMatches.
m_errorMsg =
_(
"Iteration count exceeded (timeout)");
1038 case CONNECTION_GRAPH::ST_TOPOLOGY_MISMATCH:
1051 const std::unordered_set<BOARD_ITEM*>& aItemsToRemove )
1057 std::vector<EDA_ITEM*> pruneList;
1063 if( refItem->m_Uuid == testItem->m_Uuid )
1064 pruneList.push_back( refItem );
1068 if( !pruneList.empty() )
1073 group->RemoveItem( item );
1075 if(
group->GetItems().empty() )
1092 frame()->ShowInfoBarError(
_(
"Cannot auto-generate any placement areas because the "
1093 "schematic has only one or no hierarchical sheet(s) or "
1094 "component classes." ),
1102 if( ret != wxID_OK )
1108 if( !zone->GetIsRuleArea() )
1111 if( !zone->GetPlacementAreaEnabled() )
1114 std::set<FOOTPRINT*> components;
1117 if( components.empty() )
1124 if( zone->GetPlacementAreaSourceType() == PLACEMENT_SOURCE_T::SHEETNAME )
1127 wxT(
"Placement rule area for sheet '%s' already exists as '%s'\n" ),
1130 else if( zone->GetPlacementAreaSourceType() == PLACEMENT_SOURCE_T::COMPONENT_CLASS )
1133 wxT(
"Placement rule area for component class '%s' already exists as '%s'\n" ),
1139 wxT(
"Placement rule area for group '%s' already exists as '%s'\n" ),
1166 std::unique_ptr<ZONE> newZone(
new ZONE(
board() ) );
1169 newZone->SetZoneName( wxString::Format( wxT(
"auto-placement-area-%s" ), ra.
m_sheetPath ) );
1170 else if( ra.
m_sourceType == PLACEMENT_SOURCE_T::COMPONENT_CLASS )
1171 newZone->SetZoneName( wxString::Format( wxT(
"auto-placement-area-%s" ), ra.
m_componentClass ) );
1173 newZone->SetZoneName( wxString::Format( wxT(
"auto-placement-area-%s" ), ra.
m_groupName ) );
1176 newZone->GetZoneName(),
1179 newZone->SetIsRuleArea(
true );
1181 newZone->SetPlacementAreaEnabled(
true );
1182 newZone->SetDoNotAllowZoneFills(
false );
1183 newZone->SetDoNotAllowVias(
false );
1184 newZone->SetDoNotAllowTracks(
false );
1185 newZone->SetDoNotAllowPads(
false );
1186 newZone->SetDoNotAllowFootprints(
false );
1190 newZone->SetPlacementAreaSourceType( PLACEMENT_SOURCE_T::SHEETNAME );
1191 newZone->SetPlacementAreaSource( ra.
m_sheetPath );
1193 else if( ra.
m_sourceType == PLACEMENT_SOURCE_T::COMPONENT_CLASS )
1195 newZone->SetPlacementAreaSourceType( PLACEMENT_SOURCE_T::COMPONENT_CLASS );
1200 newZone->SetPlacementAreaSourceType( PLACEMENT_SOURCE_T::GROUP_PLACEMENT );
1201 newZone->SetPlacementAreaSource( ra.
m_groupName );
1204 newZone->AddPolygon( raOutline );
1205 newZone->SetHatchStyle( ZONE_BORDER_DISPLAY_STYLE::NO_HATCH );
1210 ra.
m_area = newZone.release();
1227 std::unordered_set<BOARD_ITEM*> toPrune;
1232 toPrune.insert( ra.
m_area );
1246 group->AddItem( fp );
1251 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 void SetIsKnockout(bool aKnockout)
FOOTPRINT * GetParentFootprint() const
const ZONES & Zones() const
const TRACKS & Tracks() 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.
A base class for most all the KiCad significant classes used in schematics and boards.
virtual bool IsType(const std::vector< KICAD_T > &aScanTypes) const
Check whether the item is one of the listed types.
void SetAttributes(const EDA_TEXT &aSrc, bool aSetPosition=true)
Set the text attributes from another instance.
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()
return AllCuMask( MAX_CU_LAYERS );
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).
PCB_GROUP * DeepClone() const
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
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 SetZoneName(const wxString &aName)
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::unordered_map< RULE_AREA *, RULE_AREA_COMPAT_DATA > m_compatMap
REPEAT_LAYOUT_OPTIONS m_options
std::vector< RULE_AREA > m_areas
TMATCH::COMPONENT_MATCHES m_matchingComponents
PLACEMENT_SOURCE_T m_sourceType
wxString m_componentClass
std::set< FOOTPRINT * > m_raFootprints
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