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
24#include <wx/listctrl.h>
25
26#include <board.h>
27#include <footprint.h>
28
31
32
33void AddConstraintListColumns( wxListCtrl* aList )
34{
35 aList->InsertColumn( CONSTRAINT_COL_ITEM_1, _( "Item 1" ), wxLIST_FORMAT_LEFT, 150 );
36 aList->InsertColumn( CONSTRAINT_COL_ITEM_2, _( "Item 2" ), wxLIST_FORMAT_LEFT, 150 );
37 aList->InsertColumn( CONSTRAINT_COL_TYPE, _( "Constraint" ), wxLIST_FORMAT_LEFT, 150 );
38 aList->InsertColumn( CONSTRAINT_COL_STATE, _( "State" ), wxLIST_FORMAT_LEFT, 130 );
39}
40
41
42void PopulateConstraintList( wxListCtrl* aList, BOARD* aBoard, UNITS_PROVIDER* aUnits,
44 const std::function<void( long, PCB_CONSTRAINT* )>& aOnRow )
45{
46 aList->DeleteAllItems();
47
48 if( !aBoard )
49 return;
50
51 std::set<KIID> errored( aDiag.errored.begin(), aDiag.errored.end() );
52 std::set<KIID> conflicting( aDiag.conflicting.begin(), aDiag.conflicting.end() );
53 std::set<KIID> redundant( aDiag.redundant.begin(), aDiag.redundant.end() );
54
55 auto memberLabel =
56 [&]( const CONSTRAINT_MEMBER& aMember ) -> wxString
57 {
58 return ConstraintMemberLabel( aBoard->ResolveItem( aMember.m_item, true ),
59 aMember, aUnits );
60 };
61
62 auto addRows =
63 [&]( const CONSTRAINTS& aConstraints )
64 {
65 for( PCB_CONSTRAINT* constraint : aConstraints )
66 {
67 const std::vector<CONSTRAINT_MEMBER>& members = constraint->GetMembers();
68
69 wxString item1 = !members.empty() ? memberLabel( members[0] ) : wxString();
70 wxString item2 = members.size() > 1 ? memberLabel( members[1] ) : wxString();
71
72 // Constraints with more than two members (e.g. symmetric) still get two
73 // columns; flag the extras so the count is not silently lost.
74 if( members.size() > 2 )
75 item2 += wxString::Format( _( " (+%zu)" ), members.size() - 2 );
76
77 long row = aList->InsertItem( aList->GetItemCount(), item1 );
78 aList->SetItem( row, CONSTRAINT_COL_ITEM_2, item2 );
79 aList->SetItem( row, CONSTRAINT_COL_TYPE,
80 ConstraintDisplayLabel( *constraint, aUnits->GetUserUnits() ) );
81
82 wxString state;
83
84 if( errored.contains( constraint->m_Uuid ) )
85 state = _( "Error (missing item)" );
86 else if( conflicting.contains( constraint->m_Uuid ) )
87 state = _( "Over-constrained" );
88 else if( redundant.contains( constraint->m_Uuid ) )
89 state = _( "Redundant" );
90 else
91 state = _( "OK" );
92
93 aList->SetItem( row, CONSTRAINT_COL_STATE, state );
94 aOnRow( row, constraint );
95 }
96 };
97
98 addRows( aBoard->Constraints() );
99
100 for( FOOTPRINT* footprint : aBoard->Footprints() )
101 addRows( footprint->Constraints() );
102}
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:373
const FOOTPRINTS & Footprints() const
Definition board.h:421
const CONSTRAINTS & Constraints() const
Geometric constraints (#2329) owned by this board.
Definition board.h:465
BOARD_ITEM * ResolveItem(const KIID &aID, bool aAllowNullptrReturn=false) const
Definition board.cpp:1913
A geometric constraint between board items (issue #2329).
EDA_UNITS GetUserUnits() const
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...