KiCad PCB EDA Suite
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 CHANGELOG.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 
33 
36 {
37  m_listFp->AppendColumn( _( "Ref" ) );
38  m_listFp->AppendColumn( _( "Schematic assignment" ) );
39  m_listFp->AppendColumn( wxT( "<=" ) );
40  m_listFp->AppendColumn( wxT( "=>" ) );
41  m_listFp->AppendColumn( _( "Cmp file assignment" ) );
42 
43  m_lineCount = 0;
44 }
45 
46 void DIALOG_FP_CONFLICT_ASSIGNMENT_SELECTOR::Add( const wxString& aRef, const wxString& aFpSchName,
47  const wxString& aFpCmpName )
48 {
49  long idx = m_listFp->InsertItem(m_lineCount, aRef );
50 
51  m_listFp->SetItem(idx, COL_FPSCH, aFpSchName );
52  m_listFp->SetItem(idx, COL_SELSCH, wxT("") );
53  m_listFp->SetItem(idx, COL_SELCMP, wxT("X") );
54  m_listFp->SetItem(idx, COL_FPCMP, aFpCmpName );
55 
56  m_lineCount ++;
57 }
58 
60 {
61  // Find Reference
62  for( int ii = 0; ii < m_listFp->GetItemCount(); ii++ )
63  {
64  if( m_listFp->GetItemText( ii, COL_REF ) == aReference )
65  {
66  if( m_listFp->GetItemText( ii, COL_SELSCH ) != wxT("X") )
67  return 1;
68 
69  return 0;
70  }
71  }
72 
73  return -1;
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 assigment.
80  // when it is the COL_SELSCH column, set all item choices to schematic assigment.
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 
109 {
110  wxPoint pos = event.GetPosition();
111  int flgs = wxLIST_HITTEST_ONITEMLABEL;
112  long idx = m_listFp->HitTest( pos, flgs );
113 
114  // Try to find the column clicked (must be COL_SELCMP or COL_SELSCH)
115  int colclr = -1, colset;
116  int minpx = m_listFp->GetColumnWidth( 0 ) + m_listFp->GetColumnWidth( 1 );
117  int maxpx = minpx + m_listFp->GetColumnWidth( 2 );
118 
119  if( pos.x > minpx && pos.x < maxpx )
120  {
121  colclr = COL_SELCMP;
122  colset = COL_SELSCH;
123  }
124 
125  else
126  {
127  minpx = maxpx;
128  maxpx = minpx + m_listFp->GetColumnWidth( 3 );
129 
130  if( pos.x > minpx && pos.x < maxpx )
131  {
132  colclr = COL_SELSCH;
133  colset = COL_SELCMP;
134  }
135  }
136 
137  if( colclr < 0 )
138  return;
139 
140  // Move selection to schematic or cmp file choice
141  // according to the column position (COL_SELCMP or COL_SELSCH)
142  m_listFp->SetItem( idx, colclr, wxT("") );
143  m_listFp->SetItem( idx, colset, wxT("X") );
144 
145  event.Skip();
146 }
147 
148 
150 {
152  aEvent.Skip();
153 }
154 
155 
157 {
158  const int margin = 16;
159  int totalLength = 0;
160  int sel_length = GetTextSize( wxT("XX"), m_listFp ).x;
161  int maxRefLength = GetTextSize( wxT("XXX"), m_listFp ).x;
162 
163  sel_length += margin;
164  m_listFp->SetColumnWidth( COL_SELSCH, sel_length );
165  m_listFp->SetColumnWidth( COL_SELCMP, sel_length );
166 
167  // Find max character width of column Reference
168  for( int i = 0; i < m_listFp->GetItemCount(); i++ )
169  {
170  int length = GetTextSize( m_listFp->GetItemText( i, COL_REF ), m_listFp ).x;
171 
172  if( length > maxRefLength )
173  maxRefLength = length;
174  }
175 
176 
177  // Use the lengths of column texts to create a scale of the max list width
178  // to set the column widths
179  maxRefLength += margin;
180  totalLength = maxRefLength + sel_length + sel_length;
181 
182  int cwidth = (GetClientSize().x - totalLength) / 2;
183 
184  m_listFp->SetColumnWidth( COL_REF, maxRefLength );
185  m_listFp->SetColumnWidth( COL_FPSCH, cwidth - 2 );
186  m_listFp->SetColumnWidth( COL_FPCMP, cwidth );
187 }
188 
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: common.cpp:87
void Add(const wxString &aRef, const wxString &aFpSchName, const wxString &aFpCmpName)
Add a line to the selection list.
size_t i
Definition: json11.cpp:597
Class DIALOG_FP_CONFLICT_ASSIGNMENT_SELECTOR_BASE.
The common library.