54#define MULTICHANNEL_EXTRA_DEBUG
78 std::set<FOOTPRINT*>& aComponents )
84 auto reportError = [&](
const wxString& aMessage,
int aOffset )
100 case RULE_AREA_PLACEMENT_SOURCE_TYPE::SHEETNAME:
106 case RULE_AREA_PLACEMENT_SOURCE_TYPE::COMPONENT_CLASS:
112 auto ok = compiler.
Compile( ruleText, &ucode, &preflightCtx );
122 auto val = ucode.
Run( &ctx );
123 if( val->AsDouble() != 0.0 )
126 fp->GetSheetname() );
128 aComponents.insert( fp );
138 std::vector<BOARD_ITEM*> result;
144 auto reportError = [&](
const wxString& aMessage,
int aOffset )
153 bool restoreBlankName =
false;
157 restoreBlankName =
true;
161 wxString ruleText = wxString::Format( wxT(
"A.enclosedByArea('%s')" ), aRuleArea->
GetZoneName() );
163 if( !compiler.
Compile( ruleText, &ucode, &preflightCtx ) )
165 if( restoreBlankName )
175 auto val = ucode.
Run( &ctx );
177 if( val->AsDouble() != 0.0 )
178 aItems.insert( aItem );
183 if( zone == aRuleArea )
190 testAndAdd( drawing );
195 bool addGroup =
true;
197 group->RunOnChildren(
200 if( aItem->
IsType( { PCB_ZONE_T, PCB_SHAPE_T, PCB_DIMENSION_T } ) )
202 ctx.SetItems( aItem, aItem );
203 auto val = ucode.Run( &ctx );
205 if( val->AsDouble() == 0.0 )
209 RECURSE_MODE::RECURSE );
212 aItems.insert(
group );
215 if( restoreBlankName )
224 std::set<FOOTPRINT*> rv;
225 if( aSheetName.EndsWith( wxT(
"/" ) ) )
226 aSheetName.RemoveLast();
228 for(
auto& fp :
board()->Footprints() )
230 auto sn = fp->GetSheetname();
231 if( sn.EndsWith( wxT(
"/" ) ) )
234 if( sn == aSheetName )
247 std::set<FOOTPRINT*> rv;
249 for(
auto& fp :
board()->Footprints() )
251 if( fp->GetComponentClass()->ContainsClassName( aComponentClassName ) )
262 std::vector<VECTOR2I> bbCorners;
263 bbCorners.reserve( aFootprints.size() * 4 );
265 for(
auto fp : aFootprints )
271 std::vector<VECTOR2I> hullVertices;
283 using PathAndName = std::pair<wxString, wxString>;
284 std::set<PathAndName> uniqueSheets;
285 std::set<wxString> uniqueComponentClasses;
291 uniqueSheets.insert( PathAndName( fp->GetSheetname(), fp->GetSheetfile() ) );
296 uniqueComponentClasses.insert( singleClass->GetName() );
299 for(
const PathAndName& sheet : uniqueSheets )
303 ent.
m_sourceType = RULE_AREA_PLACEMENT_SOURCE_TYPE::SHEETNAME;
314 for(
const wxString& compClass : uniqueComponentClasses )
318 ent.
m_sourceType = RULE_AREA_PLACEMENT_SOURCE_TYPE::COMPONENT_CLASS;
336 if( !zone->GetIsRuleArea() )
338 if( !zone->GetRuleAreaPlacementEnabled() )
349 area.
m_center = zone->Outline()->COutline( 0 ).Centre();
379 std::vector<ZONE*> refRAs;
381 auto isSelectedItemAnRA = [](
EDA_ITEM* aItem ) ->
ZONE*
386 ZONE* zone =
static_cast<ZONE*
>( aItem );
399 if(
auto zone = isSelectedItemAnRA( item ) )
401 refRAs.push_back(zone);
409 if(
auto grpZone = isSelectedItemAnRA( grpItem ) )
411 refRAs.push_back( grpZone );
417 if( refRAs.size() != 1 )
422 _(
"Select a reference Rule Area to copy from..." ),
425 return isSelectedItemAnRA( aItem ) !=
nullptr;
441 frame()->ShowInfoBarError(
_(
"No Rule Areas to repeat layout to have been found." ),
462 if( ra.
m_area == aRefZone )
496 if( !targetArea.second.m_doCopy )
499 targetArea.first->m_ruleName );
503 if( !targetArea.second.m_isOk )
509 targetArea.second.m_groupableItems ) )
511 auto errMsg = wxString::Format(
512 _(
"Copy Rule Area contents failed between rule areas '%s' and '%s'." ),
514 targetArea.first->m_area->GetZoneName() );
520 frame()->ShowInfoBarError( errMsg,
true );
529 commit.
Push(
_(
"Repeat layout" ) );
541 grpCommit.
Add( grp );
543 for(
BOARD_ITEM* item : targetArea.second.m_groupableItems )
549 grpCommit.
Push(
_(
"Group repeated items" ) );
555 frame()->ShowInfoBarMsg( wxString::Format(
_(
"Copied to %d Rule Areas." ), totalCopied ),
575 if( ( c >=
'a' && c <=
'z' ) || ( c >=
'A' && c <=
'Z' ) || ( c ==
'_' ) )
586 std::shared_ptr<CONNECTIVITY_DATA> aConnectivity,
592 std::set<BOARD_ITEM*> conns;
599 conns.insert( item );
611 std::shared_ptr<SHAPE> effShape = item->GetEffectiveShape( item->GetLayer() );
613 if( effShape->Collide( &aRAPoly, 0 ) )
615 aOutput.insert( item );
627 auto reportError = [&](
const wxString& aMessage,
int aOffset )
636 bool restoreBlankName =
false;
640 restoreBlankName =
true;
644 wxString ruleText = wxString::Format( wxT(
"A.enclosedByArea('%s')" ),
650 if( aOutput.contains( aItem ) )
654 auto val = ucode.
Run( &ctx );
656 if( val->AsDouble() != 0.0 )
658 aOutput.insert( aItem );
663 if( compiler.
Compile( ruleText, &ucode, &preflightCtx ) )
669 if( restoreBlankName )
680 std::unordered_set<BOARD_ITEM*>& aAffectedItems,
681 std::unordered_set<BOARD_ITEM*>& aGroupableItems )
696 newTargetOutline.
Move( disp );
704 aAffectedItems.insert( aTargetArea->
m_area );
705 aGroupableItems.insert( aTargetArea->
m_area );
709 std::set<BOARD_ITEM*> refRouting;
710 std::set<BOARD_ITEM*> targetRouting;
714 for(
auto& fpPair : aMatches )
717 fpPair.second, aOpts );
735 aAffectedItems.insert( item );
751 copied->SetParentGroup(
nullptr );
752 aGroupableItems.insert(
copied );
759 std::set<BOARD_ITEM*> sourceItems;
760 std::set<BOARD_ITEM*> targetItems;
767 if( item->Type() ==
PCB_TEXT_T && item->GetParent()
782 aAffectedItems.insert( item );
788 ZONE* zone =
static_cast<ZONE*
>( item );
791 bool layerMismatch =
false;
797 layerMismatch =
true;
802 aAffectedItems.insert( zone );
810 if( item->Type() ==
PCB_TEXT_T && item->GetParent()
834 ZONE* zone =
static_cast<ZONE*
>( item );
837 bool layerMismatch =
false;
845 layerMismatch =
true;
852 ZONE* targetZone =
static_cast<ZONE*
>( item->Clone() );
861 copied->SetParentGroup(
nullptr );
863 aGroupableItems.insert(
copied );
876 for(
auto& fpPair : aMatches )
901 aCommit->
Modify( targetFP );
910 if( !refField->IsVisible() )
914 wxCHECK2( targetField,
continue );
917 targetField->
SetPosition( refField->GetPosition() + disp );
921 aAffectedItems.insert( targetFP );
922 aGroupableItems.insert( targetFP );
938 const std::vector<BOARD_CONNECTED_ITEM*> refZoneConnectedPads =
939 connectivity->GetNetItems( aRefZone->
GetNetCode(), { PCB_PAD_T } );
946 const PAD* refPad =
static_cast<const PAD*
>( refConItem );
949 if( aComponentMatches.contains( sourceFootprint ) )
951 const FOOTPRINT* targetFootprint = aComponentMatches[sourceFootprint];
952 std::vector<const PAD*> targetFpPads = targetFootprint->
GetPads( refPad->
GetNumber() );
954 if( !targetFpPads.empty() )
956 int targetNetCode = targetFpPads[0]->GetNet()->GetNetCode();
971 std::unique_ptr<CONNECTION_GRAPH> cgRef ( CONNECTION_GRAPH::BuildFromFootprintSet( aRefArea->
m_raFootprints ) );
972 std::unique_ptr<CONNECTION_GRAPH> cgTarget ( CONNECTION_GRAPH::BuildFromFootprintSet( aTargetArea->
m_raFootprints ) );
978 case CONNECTION_GRAPH::ST_OK:
982 case CONNECTION_GRAPH::ST_EMPTY:
984 aMatches.
m_errorMsg =
_(
"One or both of the areas has no components assigned.");
986 case CONNECTION_GRAPH::ST_COMPONENT_COUNT_MISMATCH:
988 aMatches.
m_errorMsg =
_(
"Component count mismatch");
990 case CONNECTION_GRAPH::ST_ITERATION_COUNT_EXCEEDED:
992 aMatches.
m_errorMsg =
_(
"Iteration count exceeded (timeout)");
994 case CONNECTION_GRAPH::ST_TOPOLOGY_MISMATCH:
1007 const std::unordered_set<BOARD_ITEM*>& aItemsToRemove )
1009 std::deque<PCB_GROUP*> pending (
board()->Groups() );
1010 while( !pending.empty() )
1012 auto grp = pending.front();
1013 pending.pop_front();
1015 std::unordered_set<BOARD_ITEM*>& grpItems = grp->GetItems();
1016 size_t n_erased = 0;
1022 pending.push_back(
static_cast<PCB_GROUP*
>(refItem) );
1026 if( refItem->m_Uuid == testItem->m_Uuid )
1034 if( n_erased == grpItems.size() )
1053 frame()->ShowInfoBarError(
_(
"Cannot auto-generate any placement areas because the "
1054 "schematic has only one or no hierarchical sheet(s) or "
1055 "component classes." ),
1063 if( ret != wxID_OK )
1069 if( !zone->GetIsRuleArea() )
1071 if( !zone->GetRuleAreaPlacementEnabled() )
1074 std::set<FOOTPRINT*> components;
1077 if( components.empty() )
1084 if( zone->GetRuleAreaPlacementSourceType()
1085 == RULE_AREA_PLACEMENT_SOURCE_TYPE::SHEETNAME )
1089 wxT(
"Placement rule area for sheet '%s' already exists as '%s'\n" ),
1095 wxT(
"Placement rule area for component class '%s' already exists "
1107 wxT(
"%d placement areas found\n" ), (
int)
m_areas.
m_areas.size() );
1121 std::unique_ptr<ZONE> newZone(
new ZONE(
board() ) );
1123 if( ra.
m_sourceType == RULE_AREA_PLACEMENT_SOURCE_TYPE::SHEETNAME )
1125 newZone->SetZoneName(
1126 wxString::Format( wxT(
"auto-placement-area-%s" ), ra.
m_sheetPath ) );
1130 newZone->SetZoneName(
1131 wxString::Format( wxT(
"auto-placement-area-%s" ), ra.
m_componentClass ) );
1135 newZone->GetZoneName(), (
int) ra.
m_components.size() );
1137 newZone->SetIsRuleArea(
true );
1139 newZone->SetRuleAreaPlacementEnabled(
true );
1140 newZone->SetDoNotAllowZoneFills(
false );
1141 newZone->SetDoNotAllowVias(
false );
1142 newZone->SetDoNotAllowTracks(
false );
1143 newZone->SetDoNotAllowPads(
false );
1144 newZone->SetDoNotAllowFootprints(
false );
1146 if( ra.
m_sourceType == RULE_AREA_PLACEMENT_SOURCE_TYPE::SHEETNAME )
1148 newZone->SetRuleAreaPlacementSourceType( RULE_AREA_PLACEMENT_SOURCE_TYPE::SHEETNAME );
1149 newZone->SetRuleAreaPlacementSource( ra.
m_sheetPath );
1153 newZone->SetRuleAreaPlacementSourceType(
1154 RULE_AREA_PLACEMENT_SOURCE_TYPE::COMPONENT_CLASS );
1158 newZone->AddPolygon( raOutline );
1159 newZone->SetHatchStyle( ZONE_BORDER_DISPLAY_STYLE::NO_HATCH );
1166 ra.
m_area = newZone.get();
1167 commit.
Add( newZone.release() );
1171 commit.
Push(
_(
"Auto-generate placement rule areas" ) );
1189 std::unordered_set<BOARD_ITEM*> toPrune;
1192 std::inserter( toPrune, toPrune.begin() ) );
1195 toPrune.insert( ra.
m_area );
1201 grpCommit.
Add( grp );
1209 grpCommit.
Push(
_(
"Group components with their placement rule areas" ) );
virtual void Push(const wxString &aMessage=wxEmptyString, int aCommitFlags=0) override
Execute the changes.
COMMIT & Stage(EDA_ITEM *aItem, CHANGE_TYPE aChangeType, BASE_SCREEN *aScreen=nullptr) override
Add a change of the item aItem of type aChangeType to the change list.
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.
virtual COMMIT & Stage(EDA_ITEM *aItem, CHANGE_TYPE aChangeType, BASE_SCREEN *aScreen=nullptr)
Add a change of the item aItem of type aChangeType to the change list.
COMMIT & Modify(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
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)
LSET is a set of PCB_LAYER_IDs.
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
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 void SetPosition(const VECTOR2I &aPos) override
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
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:
wxString GetRuleAreaPlacementSource() const
void AddPolygon(std::vector< VECTOR2I > &aPolygon)
Add a polygon to the zone outline.
void HatchBorder()
Compute the hatch lines depending on the hatch parameters and stores it in the zone's attribute m_bor...
bool GetRuleAreaPlacementEnabled() const
SHAPE_POLY_SET * Outline()
const wxString & GetZoneName() const
virtual LSET GetLayerSet() const override
Return a std::bitset of all layers on which the item physically resides.
RULE_AREA_PLACEMENT_SOURCE_TYPE GetRuleAreaPlacementSourceType() const
void SetZoneName(const wxString &aName)
void UnHatchBorder()
Clear the zone's hatch.
void RemoveAllContours(void)
#define IGNORE_NETS
Function GetConnectedItems() Returns a list of items connected to a source item aItem.
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_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
RULE_AREA_PLACEMENT_SOURCE_TYPE 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