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 (C) 1992-2014 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
47void DIALOG_FP_CONFLICT_ASSIGNMENT_SELECTOR::Add( const wxString& aRef, const wxString& aFpSchName,
48 const wxString& aFpCmpName )
49{
50 long idx = m_listFp->InsertItem(m_lineCount, aRef );
51
52 m_listFp->SetItem(idx, COL_FPSCH, aFpSchName );
53 m_listFp->SetItem(idx, COL_SELSCH, wxT("") );
54 m_listFp->SetItem(idx, COL_SELCMP, wxT("X") );
55 m_listFp->SetItem(idx, COL_FPCMP, aFpCmpName );
56
57 m_lineCount ++;
58}
59
61{
62 // Find Reference
63 for( int ii = 0; ii < m_listFp->GetItemCount(); ii++ )
64 {
65 if( m_listFp->GetItemText( ii, COL_REF ) == aReference )
66 {
67 if( m_listFp->GetItemText( ii, COL_SELSCH ) != wxT("X") )
68 return 1;
69
70 return 0;
71 }
72 }
73
74 return -1;
75}
76
78{
79 // When clicking on the column title:
80 // when it is the COL_SELCMP column, set all item choices to cmp file assignment.
81 // when it is the COL_SELSCH column, set all item choices to schematic assignment.
82
83 int column = event.GetColumn();
84 int colclr, colset;
85
86 switch( column )
87 {
88 case COL_SELSCH:
89 colclr = COL_SELCMP;
90 colset = COL_SELSCH;
91 break;
92
93 case COL_SELCMP:
94 colclr = COL_SELSCH;
95 colset = COL_SELCMP;
96 break;
97
98 default:
99 return;
100 }
101
102 for( int i = 0; i < m_listFp->GetItemCount(); i++ )
103 {
104 m_listFp->SetItem( i, colclr, wxT("") );
105 m_listFp->SetItem( i, colset, wxT("X") );
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
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.