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  wxListItem item = event.GetItem();
83 
84  int column = event.GetColumn();
85  int colclr, colset;
86 
87  switch( column )
88  {
89  case COL_SELSCH:
90  colclr = COL_SELCMP;
91  colset = COL_SELSCH;
92  break;
93 
94  case COL_SELCMP:
95  colclr = COL_SELSCH;
96  colset = COL_SELCMP;
97  break;
98 
99  default:
100  return;
101  }
102 
103  for( int i = 0; i < m_listFp->GetItemCount(); i++ )
104  {
105  m_listFp->SetItem( i, colclr, wxT("") );
106  m_listFp->SetItem( i, colset, wxT("X") );
107  }
108 }
109 
111 {
112  wxPoint pos = event.GetPosition();
113  int flgs = wxLIST_HITTEST_ONITEMLABEL;
114  long idx = m_listFp->HitTest( pos, flgs );
115 
116  // Try to find the column clicked (must be COL_SELCMP or COL_SELSCH)
117  int colclr = -1, colset;
118  int minpx = m_listFp->GetColumnWidth( 0 ) + m_listFp->GetColumnWidth( 1 );
119  int maxpx = minpx + m_listFp->GetColumnWidth( 2 );
120 
121  if( pos.x > minpx && pos.x < maxpx )
122  {
123  colclr = COL_SELCMP;
124  colset = COL_SELSCH;
125  }
126 
127  else
128  {
129  minpx = maxpx;
130  maxpx = minpx + m_listFp->GetColumnWidth( 3 );
131 
132  if( pos.x > minpx && pos.x < maxpx )
133  {
134  colclr = COL_SELSCH;
135  colset = COL_SELCMP;
136  }
137  }
138 
139  if( colclr < 0 )
140  return;
141 
142  // Move selection to schematic or cmp file choice
143  // according to the column position (COL_SELCMP or COL_SELSCH)
144  m_listFp->SetItem( idx, colclr, wxT("") );
145  m_listFp->SetItem( idx, colset, wxT("X") );
146 
147  event.Skip();
148 }
149 
150 
152 {
154  aEvent.Skip();
155 }
156 
157 
159 {
160  const int margin = 16;
161  int totalLength = 0;
162  int sel_length = GetTextSize( wxT("XX"), m_listFp ).x;
163  int maxRefLength = GetTextSize( wxT("XXX"), m_listFp ).x;
164 
165  sel_length += margin;
166  m_listFp->SetColumnWidth( COL_SELSCH, sel_length );
167  m_listFp->SetColumnWidth( COL_SELCMP, sel_length );
168 
169  // Find max character width of column Reference
170  for( int i = 0; i < m_listFp->GetItemCount(); i++ )
171  {
172  int length = GetTextSize( m_listFp->GetItemText( i, COL_REF ), m_listFp ).x;
173 
174  if( length > maxRefLength )
175  maxRefLength = length;
176  }
177 
178 
179  // Use the lengths of column texts to create a scale of the max list width
180  // to set the column widths
181  maxRefLength += margin;
182  totalLength = maxRefLength + sel_length + sel_length;
183 
184  int cwidth = (GetClientSize().x - totalLength) / 2;
185 
186  m_listFp->SetColumnWidth( COL_REF, maxRefLength );
187  m_listFp->SetColumnWidth( COL_FPSCH, cwidth - 2 );
188  m_listFp->SetColumnWidth( COL_FPCMP, cwidth );
189 }
190 
wxSize GetTextSize(const wxString &aSingleLine, wxWindow *aWindow)
Function GetTextSize returns the size of aSingleLine of text when it is rendered in aWindow using wha...
Definition: common.cpp:93
void Add(const wxString &aRef, const wxString &aFpSchName, const wxString &aFpCmpName)
Add a line to the selection list.
Class DIALOG_FP_CONFLICT_ASSIGNMENT_SELECTOR_BASE.
The common library.