KiCad PCB EDA Suite
Loading...
Searching...
No Matches
fp_conflict_assignment_selector.cpp
Go to the documentation of this file.
1
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, you may find one here:
23 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
24 * or you may search the http://www.gnu.org website for the version 2 license,
25 * or you may write to the Free Software Foundation, Inc.,
26 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
27 */
28
29#include <common.h>
30
32#include <widgets/ui_common.h>
33
34
37{
38 m_listFp->AppendColumn( _( "Ref" ) );
39 m_listFp->AppendColumn( _( "Schematic assignment" ) );
40 m_listFp->AppendColumn( wxT( "<=" ) );
41 m_listFp->AppendColumn( wxT( "=>" ) );
42 m_listFp->AppendColumn( _( "Cmp file assignment" ) );
43
44 m_lineCount = 0;
45}
46
47
48void DIALOG_FP_CONFLICT_ASSIGNMENT_SELECTOR::Add( const wxString& aRef, const wxString& aFpSchName,
49 const wxString& aFpCmpName )
50{
51 long idx = m_listFp->InsertItem(m_lineCount, aRef );
52
53 m_listFp->SetItem( idx, COL_FPSCH, aFpSchName );
54 m_listFp->SetItem( idx, COL_SELSCH, wxT( "" ) );
55 m_listFp->SetItem( idx, COL_SELCMP, wxT( "X" ) );
56 m_listFp->SetItem( idx, COL_FPCMP, aFpCmpName );
57
58 m_lineCount ++;
59}
60
61
63{
64 // Find Reference
65 for( int ii = 0; ii < m_listFp->GetItemCount(); ii++ )
66 {
67 if( m_listFp->GetItemText( ii, COL_REF ) == aReference )
68 {
69 if( m_listFp->GetItemText( ii, COL_SELSCH ) != wxT( "X" ) )
70 return 1;
71
72 return 0;
73 }
74 }
75
76 return -1;
77}
78
79
81{
82 // When clicking on the column title:
83 // when it is the COL_SELCMP column, set all item choices to cmp file assignment.
84 // when it is the COL_SELSCH column, set all item choices to schematic assignment.
85
86 int column = event.GetColumn();
87 int colclr, colset;
88
89 switch( column )
90 {
91 case COL_SELSCH:
92 colclr = COL_SELCMP;
93 colset = COL_SELSCH;
94 break;
95
96 case COL_SELCMP:
97 colclr = COL_SELSCH;
98 colset = COL_SELCMP;
99 break;
100
101 default:
102 return;
103 }
104
105 for( int i = 0; i < m_listFp->GetItemCount(); i++ )
106 {
107 m_listFp->SetItem( i, colclr, wxT( "" ) );
108 m_listFp->SetItem( i, colset, wxT( "X" ) );
109 }
110}
111
112
114{
115 wxPoint pos = event.GetPosition();
116 int flgs = wxLIST_HITTEST_ONITEMLABEL;
117 long idx = m_listFp->HitTest( pos, flgs );
118
119 // Try to find the column clicked (must be COL_SELCMP or COL_SELSCH)
120 int colclr = -1, colset = -1;
121 int minpx = m_listFp->GetColumnWidth( 0 ) + m_listFp->GetColumnWidth( 1 );
122 int maxpx = minpx + m_listFp->GetColumnWidth( 2 );
123
124 if( pos.x > minpx && pos.x < maxpx )
125 {
126 colclr = COL_SELCMP;
127 colset = COL_SELSCH;
128 }
129
130 else
131 {
132 minpx = maxpx;
133 maxpx = minpx + m_listFp->GetColumnWidth( 3 );
134
135 if( pos.x > minpx && pos.x < maxpx )
136 {
137 colclr = COL_SELSCH;
138 colset = COL_SELCMP;
139 }
140 }
141
142 if( colclr < 0 )
143 return;
144
145 // Move selection to schematic or cmp file choice
146 // according to the column position (COL_SELCMP or COL_SELSCH)
147 m_listFp->SetItem( idx, colclr, wxT( "" ) );
148 m_listFp->SetItem( idx, colset, wxT( "X" ) );
149
150 event.Skip();
151}
152
153
155{
157 aEvent.Skip();
158}
159
160
162{
163 const int margin = 16;
164 int totalLength = 0;
165 int sel_length = KIUI::GetTextSize( wxT( "XX" ), m_listFp ).x;
166 int maxRefLength = KIUI::GetTextSize( wxT( "XXX" ), m_listFp ).x;
167
168 sel_length += margin;
169 m_listFp->SetColumnWidth( COL_SELSCH, sel_length );
170 m_listFp->SetColumnWidth( COL_SELCMP, sel_length );
171
172 // Find max character width of column Reference
173 for( int i = 0; i < m_listFp->GetItemCount(); i++ )
174 {
175 int length = KIUI::GetTextSize( m_listFp->GetItemText( i, COL_REF ), m_listFp ).x;
176
177 if( length > maxRefLength )
178 maxRefLength = length;
179 }
180
181
182 // Use the lengths of column texts to create a scale of the max list width
183 // to set the column widths
184 maxRefLength += margin;
185 totalLength = maxRefLength + sel_length + sel_length;
186
187 int cwidth = ( GetClientSize().x - totalLength ) / 2;
188
189 m_listFp->SetColumnWidth( COL_REF, maxRefLength );
190 m_listFp->SetColumnWidth( COL_FPSCH, cwidth - 2 );
191 m_listFp->SetColumnWidth( COL_FPCMP, cwidth );
192}
193
Class DIALOG_FP_CONFLICT_ASSIGNMENT_SELECTOR_BASE.
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:77
Functions to provide common constants and other functions to assist in making a consistent UI.