KiCad PCB EDA Suite
Loading...
Searching...
No Matches
fp_conflict_assignment_selector.cpp
Go to the documentation of this file.
1
4
5/*
6 * This program source code file is part of KICAD, a free EDA CAD application.
7 *
8 * Copyright (C) 2010-2014 Jean-Pierre Charras <jp.charras at wanadoo.fr>
9 * Copyright The KiCad Developers, see AUTHORS.TXT for contributors.
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <https://www.gnu.org/licenses/>.
23 */
24
25#include <common.h>
26
28#include <widgets/ui_common.h>
29
30
33{
34 m_listFp->AppendColumn( _( "Ref" ) );
35 m_listFp->AppendColumn( _( "Schematic assignment" ) );
36 m_listFp->AppendColumn( wxT( "<=" ) );
37 m_listFp->AppendColumn( wxT( "=>" ) );
38 m_listFp->AppendColumn( _( "Cmp file assignment" ) );
39
40 m_lineCount = 0;
41}
42
43
44void DIALOG_FP_CONFLICT_ASSIGNMENT_SELECTOR::Add( const wxString& aRef, const wxString& aFpSchName,
45 const wxString& aFpCmpName )
46{
47 long idx = m_listFp->InsertItem(m_lineCount, aRef );
48
49 m_listFp->SetItem( idx, COL_FPSCH, aFpSchName );
50 m_listFp->SetItem( idx, COL_SELSCH, wxT( "" ) );
51 m_listFp->SetItem( idx, COL_SELCMP, wxT( "X" ) );
52 m_listFp->SetItem( idx, COL_FPCMP, aFpCmpName );
53
54 m_lineCount ++;
55}
56
57
59{
60 // Find Reference
61 for( int ii = 0; ii < m_listFp->GetItemCount(); ii++ )
62 {
63 if( m_listFp->GetItemText( ii, COL_REF ) == aReference )
64 {
65 if( m_listFp->GetItemText( ii, COL_SELSCH ) != wxT( "X" ) )
66 return 1;
67
68 return 0;
69 }
70 }
71
72 return -1;
73}
74
75
77{
78 // When clicking on the column title:
79 // when it is the COL_SELCMP column, set all item choices to cmp file assignment.
80 // when it is the COL_SELSCH column, set all item choices to schematic assignment.
81
82 int column = event.GetColumn();
83 int colclr, colset;
84
85 switch( column )
86 {
87 case COL_SELSCH:
88 colclr = COL_SELCMP;
89 colset = COL_SELSCH;
90 break;
91
92 case COL_SELCMP:
93 colclr = COL_SELSCH;
94 colset = COL_SELCMP;
95 break;
96
97 default:
98 return;
99 }
100
101 for( int i = 0; i < m_listFp->GetItemCount(); i++ )
102 {
103 m_listFp->SetItem( i, colclr, wxT( "" ) );
104 m_listFp->SetItem( i, colset, wxT( "X" ) );
105 }
106}
107
108
110{
111 wxPoint pos = event.GetPosition();
112 int flgs = wxLIST_HITTEST_ONITEMLABEL;
113 long idx = m_listFp->HitTest( pos, flgs );
114
115 // Try to find the column clicked (must be COL_SELCMP or COL_SELSCH)
116 int colclr = -1, colset = -1;
117 int minpx = m_listFp->GetColumnWidth( 0 ) + m_listFp->GetColumnWidth( 1 );
118 int maxpx = minpx + m_listFp->GetColumnWidth( 2 );
119
120 if( pos.x > minpx && pos.x < maxpx )
121 {
122 colclr = COL_SELCMP;
123 colset = COL_SELSCH;
124 }
125
126 else
127 {
128 minpx = maxpx;
129 maxpx = minpx + m_listFp->GetColumnWidth( 3 );
130
131 if( pos.x > minpx && pos.x < maxpx )
132 {
133 colclr = COL_SELSCH;
134 colset = COL_SELCMP;
135 }
136 }
137
138 if( colclr < 0 )
139 return;
140
141 // Move selection to schematic or cmp file choice
142 // according to the column position (COL_SELCMP or COL_SELSCH)
143 m_listFp->SetItem( idx, colclr, wxT( "" ) );
144 m_listFp->SetItem( idx, colset, wxT( "X" ) );
145
146 event.Skip();
147}
148
149
151{
153 aEvent.Skip();
154}
155
156
158{
159 const int margin = 16;
160 int totalLength = 0;
161 int sel_length = KIUI::GetTextSize( wxT( "XX" ), m_listFp ).x;
162 int maxRefLength = KIUI::GetTextSize( wxT( "XXX" ), m_listFp ).x;
163
164 sel_length += margin;
165 m_listFp->SetColumnWidth( COL_SELSCH, sel_length );
166 m_listFp->SetColumnWidth( COL_SELCMP, sel_length );
167
168 // Find max character width of column Reference
169 for( int i = 0; i < m_listFp->GetItemCount(); i++ )
170 {
171 int length = KIUI::GetTextSize( m_listFp->GetItemText( i, COL_REF ), m_listFp ).x;
172
173 if( length > maxRefLength )
174 maxRefLength = length;
175 }
176
177
178 // Use the lengths of column texts to create a scale of the max list width
179 // to set the column widths
180 maxRefLength += margin;
181 totalLength = maxRefLength + sel_length + sel_length;
182
183 int cwidth = ( GetClientSize().x - totalLength ) / 2;
184
185 m_listFp->SetColumnWidth( COL_REF, maxRefLength );
186 m_listFp->SetColumnWidth( COL_FPSCH, cwidth - 2 );
187 m_listFp->SetColumnWidth( COL_FPCMP, cwidth );
188}
189
DIALOG_FP_CONFLICT_ASSIGNMENT_SELECTOR_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxString &title=_("Footprint Assignment Conflicts"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(-1,-1), long style=wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER)
void Add(const wxString &aRef, const wxString &aFpSchName, const wxString &aFpCmpName)
Add a line to the selection list.
The common library.
#define _(s)
KICOMMON_API wxSize GetTextSize(const wxString &aSingleLine, wxWindow *aWindow)
Return the size of aSingleLine of text when it is rendered in aWindow using whatever font is currentl...
Definition ui_common.cpp:78
Functions to provide common constants and other functions to assist in making a consistent UI.