48#define MULTICHANNEL_EXTRA_DEBUG
72 std::set<FOOTPRINT*>& aComponents )
78 auto reportError = [&](
const wxString& aMessage,
int aOffset )
100 auto val = ucode.
Run( &ctx );
101 if( val->AsDouble() != 0.0 )
104 fp->GetSheetname() );
106 aComponents.insert( fp );
116 std::set<FOOTPRINT*> rv;
117 if( aSheetName.EndsWith( wxT(
"/" ) ) )
118 aSheetName.RemoveLast();
120 for(
auto& fp :
board()->Footprints() )
122 auto sn = fp->GetSheetname();
123 if( sn.EndsWith( wxT(
"/" ) ) )
126 if( sn == aSheetName )
139 std::vector<VECTOR2I> bbCorners, hullVertices;
141 for(
auto fp : aFootprints )
143 auto bb = fp->GetBoundingBox(
false,
false );
144 bb.Inflate( aMargin );
146 bbCorners.push_back(
VECTOR2I( bb.GetX(), bb.GetY() ) );
147 bbCorners.push_back(
VECTOR2I( bb.GetX() + bb.GetWidth(), bb.GetY() ) );
148 bbCorners.push_back(
VECTOR2I( bb.GetX() + bb.GetWidth(), bb.GetY() + bb.GetHeight() ) );
149 bbCorners.push_back(
VECTOR2I( bb.GetX(), bb.GetY() + bb.GetHeight() ) );
161 const auto& seg = hull.
CSegment( i );
162 const VECTOR2I p0( seg.A.x, seg.B.y );
163 const VECTOR2I p1( seg.B.x, seg.A.y );
165 raOutline.
Append( seg.A );
181 using PathAndName = std::pair<wxString, wxString>;
182 std::set<PathAndName> uniqueSheets;
188 uniqueSheets.insert( PathAndName( fp->GetSheetname(), fp->GetSheetfile() ) );
191 for(
const PathAndName& sheet : uniqueSheets )
213 if( !zone->GetIsRuleArea() )
215 if( zone->GetRuleAreaType() != RULE_AREA_TYPE::PLACEMENT )
226 area.
m_center = zone->Outline()->COutline( 0 ).Centre();
250 std::vector<ZONE*> refRAs;
252 auto isSelectedItemAnRA = [] (
EDA_ITEM* aItem ) ->
ZONE*
256 ZONE* zone =
static_cast<ZONE*
>( aItem );
266 if(
auto zone = isSelectedItemAnRA( item ) )
268 refRAs.push_back(zone);
275 if(
auto grpZone = isSelectedItemAnRA( grpItem ) )
277 refRAs.push_back( grpZone );
283 if( refRAs.size() != 1 )
285 frame()->ShowInfoBarError(
_(
"Please select a single reference Rule Area to copy from." ),
299 frame()->ShowInfoBarError(
_(
"No Rule Areas to repeat layout to have been found." ),
306 int ret = dialog.ShowModal();
321 if( ra.
m_area == aRefZone )
352 if( !targetArea.second.m_doCopy )
355 targetArea.first->m_ruleName );
359 if( !targetArea.second.m_isOk )
364 std::unordered_set<BOARD_ITEM*> affectedItems;
365 std::unordered_set<BOARD_ITEM*> groupableItems;
370 auto errMsg = wxString::Format(
371 _(
"Copy Rule Area contents failed between rule areas '%s' and '%s'." ),
373 targetArea.first->m_area->GetZoneName() );
378 frame()->ShowInfoBarError( errMsg,
true );
384 commit.
Push(
_(
"Repeat layout" ) );
395 grpCommit.
Add( grp );
397 for(
auto item : groupableItems )
402 grpCommit.
Push(
_(
"Group components with their placement rule areas" ) );
410 frame()->ShowInfoBarMsg( wxString::Format(
_(
"Copied to %d Rule Areas." ), totalCopied ),
430 if( ( c >=
'a' && c <=
'z' ) || ( c >=
'A' && c <=
'Z' ) || ( c ==
'_' ) )
441 std::shared_ptr<CONNECTIVITY_DATA> aConnectivity,
446 std::set<BOARD_ITEM*> conns;
450 const std::vector<BOARD_CONNECTED_ITEM*> connItems = aConnectivity->GetConnectedItems(
454 conns.insert( item );
466 std::shared_ptr<SHAPE> effShape = item->GetEffectiveShape( item->GetLayer() );
468 if( effShape->Collide( &aRAPoly, 0 ) )
470 aOutput.insert( item );
482 std::unordered_set<BOARD_ITEM*>& aAffectedItems,
483 std::unordered_set<BOARD_ITEM*>& aGroupableItems )
498 newTargetOutline.
Move( disp );
506 aAffectedItems.insert( aTargetArea->
m_area );
507 aGroupableItems.insert( aTargetArea->
m_area );
511 std::set<BOARD_ITEM*> refRouting;
512 std::set<BOARD_ITEM*> targetRouting;
516 for(
auto& fpPair : aMatches )
519 fpPair.second, aOpts );
537 aAffectedItems.insert( item );
551 copied->
Move( disp );
552 aGroupableItems.insert( copied );
553 aCommit->
Add( copied );
565 for(
auto& fpPair : aMatches )
586 aCommit->
Modify( targetFP );
597 aAffectedItems.insert( targetFP );
598 aGroupableItems.insert( targetFP );
610 std::unique_ptr<CONNECTION_GRAPH> cgRef ( CONNECTION_GRAPH::BuildFromFootprintSet( aRefArea->
m_raFootprints ) );
611 std::unique_ptr<CONNECTION_GRAPH> cgTarget ( CONNECTION_GRAPH::BuildFromFootprintSet( aTargetArea->
m_raFootprints ) );
617 case CONNECTION_GRAPH::ST_OK:
621 case CONNECTION_GRAPH::ST_EMPTY:
623 aMatches.
m_errorMsg =
_(
"One or both of the areas has no components assigned.");
625 case CONNECTION_GRAPH::ST_COMPONENT_COUNT_MISMATCH:
627 aMatches.
m_errorMsg =
_(
"Component count mismatch");
629 case CONNECTION_GRAPH::ST_ITERATION_COUNT_EXCEEDED:
631 aMatches.
m_errorMsg =
_(
"Iteration count exceeded (timeout)");
633 case CONNECTION_GRAPH::ST_TOPOLOGY_MISMATCH:
649 std::unordered_set<BOARD_ITEM*>& grpItems = grp->GetItems();
652 for(
auto refItem : grpItems )
655 for (
auto& testItem : aItemsToRemove )
658 if( refItem->m_Uuid == testItem->m_Uuid )
666 if( n_erased == grpItems.size() )
685 frame()->ShowInfoBarError(
_(
"Cannot auto-generate any placement areas because the "
686 "schematic has only one or no hierarchical sheet(s)." ),
693 int ret = dialog.ShowModal();
701 if( !zone->GetIsRuleArea() )
703 if( zone->GetRuleAreaType() != RULE_AREA_TYPE::PLACEMENT )
706 std::set<FOOTPRINT*> components;
709 if( components.empty() )
714 if( components == ra.m_sheetComponents )
717 wxT(
"Placement rule area for sheet '%s' already exists as '%s'\n" ),
718 ra.m_sheetPath, zone->GetZoneName() );
721 ra.m_existsAlready =
true;
727 wxT(
"%d placement areas found\n" ), (
int)
m_areas.
m_areas.size() );
740 std::unique_ptr<ZONE> newZone(
new ZONE(
board() ) );
742 newZone->SetZoneName( wxString::Format( wxT(
"auto-placement-area-%s" ), ra.
m_sheetPath ) );
745 wxT(
"Generated rule area '%s' (%d components)\n" ),
746 newZone->GetZoneName(),
749 newZone->SetIsRuleArea(
true );
751 newZone->SetRuleAreaType( RULE_AREA_TYPE::PLACEMENT );
752 newZone->SetRuleAreaExpression(
753 wxString::Format( wxT(
"A.memberOfSheet('%s')" ), ra.
m_sheetPath ) );
754 newZone->AddPolygon( raOutline );
755 newZone->SetHatchStyle( ZONE_BORDER_DISPLAY_STYLE::NO_HATCH );
762 ra.
m_area = newZone.get();
763 commit.
Add( newZone.release() );
767 commit.
Push(
_(
"Auto-generate placement rule areas" ) );
784 std::unordered_set<BOARD_ITEM*> toPrune;
787 std::inserter( toPrune, toPrune.begin() ) );
790 toPrune.insert( ra.
m_area );
796 grpCommit.
Add( grp );
804 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.
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)
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)
bool Contains(PCB_LAYER_ID aLayer)
See if the layer set contains a PCB layer.
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Return a mask holding the requested number of Cu PCB_LAYER_IDs.
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
bool PointInside(const VECTOR2I &aPt, int aAccuracy=0, bool aUseBBoxCache=false) const override
Check if point aP lies inside a closed shape.
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 SetClosed(bool aClosed)
Mark the line chain as closed (i.e.
void Simplify(int aMaxError=0)
Simplify the line chain by removing colinear adjacent segments and duplicate vertices.
void Append(int aX, int aY, bool aAllowDuplication=false)
Append a new point at the end of the line chain.
int SegmentCount() const
Return the number of segments in this line chain.
const SEG CSegment(int aIndex) const
Return a constant copy of the aIndex segment in the line chain.
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.
RULE_AREA_TYPE GetRuleAreaType() const
void HatchBorder()
Compute the hatch lines depending on the hatch parameters and stores it in the zone's attribute m_bor...
const wxString & GetRuleAreaExpression() 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.
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.
std::map< FOOTPRINT *, FOOTPRINT * > COMPONENT_MATCHES
Class to handle a set of BOARD_ITEMs.
PGM_BASE & Pgm()
The global Program "get" accessor.
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
std::set< FOOTPRINT * > m_sheetComponents
std::set< FOOTPRINT * > m_raFootprints
@ 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)
VECTOR2< int32_t > VECTOR2I