50#define MULTICHANNEL_EXTRA_DEBUG
74 std::set<FOOTPRINT*>& aComponents )
80 auto reportError = [&](
const wxString& aMessage,
int aOffset )
96 case RULE_AREA_PLACEMENT_SOURCE_TYPE::SHEETNAME:
102 case RULE_AREA_PLACEMENT_SOURCE_TYPE::COMPONENT_CLASS:
108 auto ok = compiler.
Compile( ruleText, &ucode, &preflightCtx );
118 auto val = ucode.
Run( &ctx );
119 if( val->AsDouble() != 0.0 )
122 fp->GetSheetname() );
124 aComponents.insert( fp );
134 std::set<FOOTPRINT*> rv;
135 if( aSheetName.EndsWith( wxT(
"/" ) ) )
136 aSheetName.RemoveLast();
138 for(
auto& fp :
board()->Footprints() )
140 auto sn = fp->GetSheetname();
141 if( sn.EndsWith( wxT(
"/" ) ) )
144 if( sn == aSheetName )
157 std::set<FOOTPRINT*> rv;
159 for(
auto& fp :
board()->Footprints() )
161 if( fp->GetComponentClass()->ContainsClassName( aComponentClassName ) )
172 std::vector<VECTOR2I> bbCorners;
173 bbCorners.reserve( aFootprints.size() * 4 );
175 for(
auto fp : aFootprints )
181 std::vector<VECTOR2I> hullVertices;
193 using PathAndName = std::pair<wxString, wxString>;
194 std::set<PathAndName> uniqueSheets;
195 std::set<wxString> uniqueComponentClasses;
201 uniqueSheets.insert( PathAndName( fp->GetSheetname(), fp->GetSheetfile() ) );
206 uniqueComponentClasses.insert( singleClass->GetName() );
209 for(
const PathAndName& sheet : uniqueSheets )
213 ent.
m_sourceType = RULE_AREA_PLACEMENT_SOURCE_TYPE::SHEETNAME;
224 for(
const wxString& compClass : uniqueComponentClasses )
228 ent.
m_sourceType = RULE_AREA_PLACEMENT_SOURCE_TYPE::COMPONENT_CLASS;
246 if( !zone->GetIsRuleArea() )
248 if( !zone->GetRuleAreaPlacementEnabled() )
259 area.
m_center = zone->Outline()->COutline( 0 ).Centre();
283 std::vector<ZONE*> refRAs;
285 auto isSelectedItemAnRA = [] (
EDA_ITEM* aItem ) ->
ZONE*
289 ZONE* zone =
static_cast<ZONE*
>( aItem );
299 if(
auto zone = isSelectedItemAnRA( item ) )
301 refRAs.push_back(zone);
308 if(
auto grpZone = isSelectedItemAnRA( grpItem ) )
310 refRAs.push_back( grpZone );
316 if( refRAs.size() != 1 )
318 frame()->ShowInfoBarError(
_(
"Please select a single reference Rule Area to copy from." ),
332 frame()->ShowInfoBarError(
_(
"No Rule Areas to repeat layout to have been found." ),
354 if( ra.
m_area == aRefZone )
385 if( !targetArea.second.m_doCopy )
388 targetArea.first->m_ruleName );
392 if( !targetArea.second.m_isOk )
397 std::unordered_set<BOARD_ITEM*> affectedItems;
398 std::unordered_set<BOARD_ITEM*> groupableItems;
403 auto errMsg = wxString::Format(
404 _(
"Copy Rule Area contents failed between rule areas '%s' and '%s'." ),
406 targetArea.first->m_area->GetZoneName() );
411 frame()->ShowInfoBarError( errMsg,
true );
417 commit.
Push(
_(
"Repeat layout" ) );
428 grpCommit.
Add( grp );
430 for(
auto item : groupableItems )
435 grpCommit.
Push(
_(
"Group components with their placement rule areas" ) );
443 frame()->ShowInfoBarMsg( wxString::Format(
_(
"Copied to %d Rule Areas." ), totalCopied ),
463 if( ( c >=
'a' && c <=
'z' ) || ( c >=
'A' && c <=
'Z' ) || ( c ==
'_' ) )
474 std::shared_ptr<CONNECTIVITY_DATA> aConnectivity,
479 std::set<BOARD_ITEM*> conns;
483 const std::vector<BOARD_CONNECTED_ITEM*> connItems = aConnectivity->GetConnectedItems(
487 conns.insert( item );
499 std::shared_ptr<SHAPE> effShape = item->GetEffectiveShape( item->GetLayer() );
501 if( effShape->Collide( &aRAPoly, 0 ) )
503 aOutput.insert( item );
515 std::unordered_set<BOARD_ITEM*>& aAffectedItems,
516 std::unordered_set<BOARD_ITEM*>& aGroupableItems )
531 newTargetOutline.
Move( disp );
539 aAffectedItems.insert( aTargetArea->
m_area );
540 aGroupableItems.insert( aTargetArea->
m_area );
544 std::set<BOARD_ITEM*> refRouting;
545 std::set<BOARD_ITEM*> targetRouting;
549 for(
auto& fpPair : aMatches )
552 fpPair.second, aOpts );
570 aAffectedItems.insert( item );
584 copied->
Move( disp );
585 aGroupableItems.insert( copied );
586 aCommit->
Add( copied );
598 for(
auto& fpPair : aMatches )
619 aCommit->
Modify( targetFP );
630 aAffectedItems.insert( targetFP );
631 aGroupableItems.insert( targetFP );
643 std::unique_ptr<CONNECTION_GRAPH> cgRef ( CONNECTION_GRAPH::BuildFromFootprintSet( aRefArea->
m_raFootprints ) );
644 std::unique_ptr<CONNECTION_GRAPH> cgTarget ( CONNECTION_GRAPH::BuildFromFootprintSet( aTargetArea->
m_raFootprints ) );
650 case CONNECTION_GRAPH::ST_OK:
654 case CONNECTION_GRAPH::ST_EMPTY:
656 aMatches.
m_errorMsg =
_(
"One or both of the areas has no components assigned.");
658 case CONNECTION_GRAPH::ST_COMPONENT_COUNT_MISMATCH:
660 aMatches.
m_errorMsg =
_(
"Component count mismatch");
662 case CONNECTION_GRAPH::ST_ITERATION_COUNT_EXCEEDED:
664 aMatches.
m_errorMsg =
_(
"Iteration count exceeded (timeout)");
666 case CONNECTION_GRAPH::ST_TOPOLOGY_MISMATCH:
682 std::unordered_set<BOARD_ITEM*>& grpItems = grp->GetItems();
685 for(
auto refItem : grpItems )
688 for (
auto& testItem : aItemsToRemove )
691 if( refItem->m_Uuid == testItem->m_Uuid )
699 if( n_erased == grpItems.size() )
718 frame()->ShowInfoBarError(
_(
"Cannot auto-generate any placement areas because the "
719 "schematic has only one or no hierarchical sheet(s) or "
720 "component classes." ),
735 if( !zone->GetIsRuleArea() )
737 if( !zone->GetRuleAreaPlacementEnabled() )
740 std::set<FOOTPRINT*> components;
743 if( components.empty() )
748 if( components == ra.m_components )
750 if( zone->GetRuleAreaPlacementSourceType()
751 == RULE_AREA_PLACEMENT_SOURCE_TYPE::SHEETNAME )
755 wxT(
"Placement rule area for sheet '%s' already exists as '%s'\n" ),
756 ra.m_sheetPath, zone->GetZoneName() );
761 wxT(
"Placement rule area for component class '%s' already exists "
763 ra.m_componentClass, zone->GetZoneName() );
767 ra.m_existsAlready =
true;
773 wxT(
"%d placement areas found\n" ), (
int)
m_areas.
m_areas.size() );
786 std::unique_ptr<ZONE> newZone(
new ZONE(
board() ) );
788 if( ra.
m_sourceType == RULE_AREA_PLACEMENT_SOURCE_TYPE::SHEETNAME )
790 newZone->SetZoneName(
791 wxString::Format( wxT(
"auto-placement-area-%s" ), ra.
m_sheetPath ) );
795 newZone->SetZoneName(
802 newZone->SetIsRuleArea(
true );
804 newZone->SetRuleAreaPlacementEnabled(
true );
805 newZone->SetDoNotAllowCopperPour(
false );
806 newZone->SetDoNotAllowVias(
false );
807 newZone->SetDoNotAllowTracks(
false );
808 newZone->SetDoNotAllowPads(
false );
809 newZone->SetDoNotAllowFootprints(
false );
811 if( ra.
m_sourceType == RULE_AREA_PLACEMENT_SOURCE_TYPE::SHEETNAME )
813 newZone->SetRuleAreaPlacementSourceType( RULE_AREA_PLACEMENT_SOURCE_TYPE::SHEETNAME );
814 newZone->SetRuleAreaPlacementSource( ra.
m_sheetPath );
818 newZone->SetRuleAreaPlacementSourceType(
819 RULE_AREA_PLACEMENT_SOURCE_TYPE::COMPONENT_CLASS );
823 newZone->AddPolygon( raOutline );
824 newZone->SetHatchStyle( ZONE_BORDER_DISPLAY_STYLE::NO_HATCH );
831 ra.
m_area = newZone.get();
832 commit.
Add( newZone.release() );
836 commit.
Push(
_(
"Auto-generate placement rule areas" ) );
853 std::unordered_set<BOARD_ITEM*> toPrune;
856 std::inserter( toPrune, toPrune.begin() ) );
859 toPrune.insert( ra.
m_area );
865 grpCommit.
Add( grp );
873 grpCommit.
Push(
_(
"Group components with their placement rule areas" ) );
virtual void Push(const wxString &aMessage=wxEmptyString, int aCommitFlags=0) override
Revert the commit by restoring the modified items state.
COMMIT & Stage(EDA_ITEM *aItem, CHANGE_TYPE aChangeType, BASE_SCREEN *aScreen=nullptr) override
virtual void Revert() override
A base class derived from BOARD_ITEM for items that can be connected and have a net,...
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
virtual void Move(const VECTOR2I &aMoveVector)
Move this object.
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)
Notify observers that aItem has been removed.
virtual COMMIT & Stage(EDA_ITEM *aItem, CHANGE_TYPE aChangeType, BASE_SCREEN *aScreen=nullptr)
COMMIT & Modify(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Create an undo entry for an item that has been already modified.
COMMIT & Add(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Notify observers that aItem has been added.
int GetStatus(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
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.
const EDA_ANGLE & GetTextAngle() const
virtual void SetTextAngle(const EDA_ANGLE &aAngle)
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)
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.
void SetItems(BOARD_ITEM *a, BOARD_ITEM *b=nullptr)
static TOOL_ACTION repeatLayout
static TOOL_ACTION generatePlacementRuleAreas
A set of BOARD_ITEMs (i.e., without duplicates).
virtual VECTOR2I GetPosition() const override
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 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.
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_SHAPE_T
class PCB_SHAPE, a segment not on copper layers
@ 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_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)