KiCad PCB EDA Suite
Loading...
Searching...
No Matches
constraint_list_view.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
21
22#include <set>
23#include <unordered_set>
24
25#include <wx/listctrl.h>
26
27#include <board.h>
28#include <footprint.h>
29
33
34
35void AddConstraintListColumns( wxListCtrl* aList )
36{
37 aList->InsertColumn( CONSTRAINT_COL_ITEM_1, _( "Item 1" ), wxLIST_FORMAT_LEFT, 150 );
38 aList->InsertColumn( CONSTRAINT_COL_ITEM_2, _( "Item 2" ), wxLIST_FORMAT_LEFT, 150 );
39 aList->InsertColumn( CONSTRAINT_COL_TYPE, _( "Constraint" ), wxLIST_FORMAT_LEFT, 150 );
40 aList->InsertColumn( CONSTRAINT_COL_STATE, _( "State" ), wxLIST_FORMAT_LEFT, 130 );
41}
42
43
44void PopulateConstraintList( wxListCtrl* aList, BOARD* aBoard, UNITS_PROVIDER* aUnits,
46 const std::function<void( long, PCB_CONSTRAINT* )>& aOnRow )
47{
48 aList->DeleteAllItems();
49
50 if( !aBoard )
51 return;
52
53 std::set<KIID> errored( aDiag.errored.begin(), aDiag.errored.end() );
54 std::set<KIID> conflicting( aDiag.conflicting.begin(), aDiag.conflicting.end() );
55 std::set<KIID> redundant( aDiag.redundant.begin(), aDiag.redundant.end() );
56
57 // Resolving a member that is not on the board scans the whole board
58 std::unordered_set<KIID> onBoard = CollectMemberCandidateIds( aBoard );
59
60 auto memberLabel =
61 [&]( const CONSTRAINT_MEMBER& aMember ) -> wxString
62 {
63 BOARD_ITEM* item = onBoard.contains( aMember.m_item ) ? aBoard->ResolveItem( aMember.m_item, true )
64 : nullptr;
65
66 return ConstraintMemberLabel( item, aMember, aUnits );
67 };
68
69 auto addRows =
70 [&]( const CONSTRAINTS& aConstraints )
71 {
72 for( PCB_CONSTRAINT* constraint : aConstraints )
73 {
74 const std::vector<CONSTRAINT_MEMBER>& members = constraint->GetMembers();
75
76 wxString item1 = !members.empty() ? memberLabel( members[0] ) : wxString();
77 wxString item2 = members.size() > 1 ? memberLabel( members[1] ) : wxString();
78
79 // Constraints with more than two members (e.g. symmetric) still get two
80 // columns; flag the extras so the count is not silently lost.
81 if( members.size() > 2 )
82 item2 += wxString::Format( _( " (+%zu)" ), members.size() - 2 );
83
84 long row = aList->InsertItem( aList->GetItemCount(), item1 );
85 aList->SetItem( row, CONSTRAINT_COL_ITEM_2, item2 );
86 aList->SetItem( row, CONSTRAINT_COL_TYPE,
87 ConstraintDisplayLabel( *constraint, aUnits->GetUserUnits() ) );
88
89 wxString state;
90
91 if( errored.contains( constraint->m_Uuid ) )
92 state = _( "Error (missing item)" );
93 else if( conflicting.contains( constraint->m_Uuid ) )
94 state = _( "Over-constrained" );
95 else if( redundant.contains( constraint->m_Uuid ) )
96 state = _( "Redundant" );
97 else
98 state = _( "OK" );
99
100 aList->SetItem( row, CONSTRAINT_COL_STATE, state );
101 aOnRow( row, constraint );
102 }
103 };
104
105 addRows( aBoard->Constraints() );
106
107 for( FOOTPRINT* footprint : aBoard->Footprints() )
108 addRows( footprint->Constraints() );
109}
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:85
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:411
const FOOTPRINTS & Footprints() const
Definition board.h:465
const CONSTRAINTS & Constraints() const
Geometric constraints (#2329) owned by this board.
Definition board.h:522
BOARD_ITEM * ResolveItem(const KIID &aID, bool aAllowNullptrReturn=false) const
Definition board.cpp:2142
A geometric constraint between board items (issue #2329).
EDA_UNITS GetUserUnits() const
std::unordered_set< KIID > CollectMemberCandidateIds(const BOARD *aBoard)
The ids of every item on aBoard a constraint member can resolve to (shapes, dimensions and table cell...
void PopulateConstraintList(wxListCtrl *aList, BOARD *aBoard, UNITS_PROVIDER *aUnits, const BOARD_CONSTRAINT_DIAGNOSTICS &aDiag, const std::function< void(long, PCB_CONSTRAINT *)> &aOnRow)
Fill aList with one row per constraint on aBoard (board-owned then footprint-owned),...
void AddConstraintListColumns(wxListCtrl *aList)
Add the four constraint columns (Item 1 / Item 2 / Constraint / State) to a report-mode list.
@ CONSTRAINT_COL_TYPE
@ CONSTRAINT_COL_ITEM_1
@ CONSTRAINT_COL_ITEM_2
@ CONSTRAINT_COL_STATE
#define _(s)
wxString ConstraintMemberLabel(BOARD_ITEM *aItem, const CONSTRAINT_MEMBER &aMember, UNITS_PROVIDER *aUnitsProvider)
Label for one constrained item in a list combining the item description with its anchored feature suc...
wxString ConstraintDisplayLabel(const PCB_CONSTRAINT &aConstraint, EDA_UNITS aUnits)
Display label for a constraint in lists and menus.
std::deque< PCB_CONSTRAINT * > CONSTRAINTS
Board-wide diagnostics for the constraint overlay and info bar.
std::vector< KIID > errored
Invalid constraints (member missing, deleted, or of a kind incompatible with the type).
One participant in a constraint: a referenced board item plus the feature of that item that participa...