You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

282 lines
7.2 KiB

* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
11 years ago
11 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2009 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
  5. * Copyright (C) 1992-2012 KiCad Developers, see AUTHORS.txt for contributors.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version 2
  10. * of the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, you may find one here:
  19. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  20. * or you may search the http://www.gnu.org website for the version 2 license,
  21. * or you may write to the Free Software Foundation, Inc.,
  22. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  23. */
  24. /**
  25. * @file class_footprints_listbox.cpp
  26. * class to display the list of available footprints
  27. */
  28. #include <fctsys.h>
  29. #include <wxstruct.h>
  30. #include <macros.h>
  31. #include <pgm_base.h>
  32. #include <wildcards_and_files_ext.h>
  33. #include <cvpcb.h>
  34. #include <cvpcb_mainframe.h>
  35. #include <cvstruct.h>
  36. #include <cvpcb_id.h>
  37. FOOTPRINTS_LISTBOX::FOOTPRINTS_LISTBOX( CVPCB_MAINFRAME* parent,
  38. wxWindowID id, const wxPoint& loc,
  39. const wxSize& size ) :
  40. ITEMS_LISTBOX_BASE( parent, id, loc, size, wxLC_SINGLE_SEL )
  41. {
  42. }
  43. FOOTPRINTS_LISTBOX::~FOOTPRINTS_LISTBOX()
  44. {
  45. }
  46. int FOOTPRINTS_LISTBOX::GetCount()
  47. {
  48. return m_footprintList.Count();
  49. }
  50. void FOOTPRINTS_LISTBOX::SetString( unsigned linecount, const wxString& text )
  51. {
  52. unsigned count = m_footprintList.Count();
  53. if( count > 0 )
  54. {
  55. if( linecount >= count )
  56. linecount = count - 1;
  57. m_footprintList[linecount] = text;
  58. }
  59. UpdateWidth( linecount );
  60. }
  61. wxString FOOTPRINTS_LISTBOX::GetSelectedFootprint()
  62. {
  63. wxString footprintName;
  64. int ii = GetFirstSelected();
  65. if( ii >= 0 )
  66. {
  67. wxString msg = m_footprintList[ii];
  68. msg.Trim( true );
  69. msg.Trim( false );
  70. footprintName = msg.AfterFirst( wxChar( ' ' ) );
  71. }
  72. return footprintName;
  73. }
  74. void FOOTPRINTS_LISTBOX::AppendLine( const wxString& text )
  75. {
  76. m_footprintList.Add( text );
  77. int lines = m_footprintList.Count();
  78. SetItemCount( lines );
  79. UpdateWidth( lines - 1 );
  80. }
  81. wxString FOOTPRINTS_LISTBOX::OnGetItemText( long item, long column ) const
  82. {
  83. if( item < 0 || item >= (long)m_footprintList.GetCount() )
  84. return wxEmptyString;
  85. return m_footprintList.Item( item );
  86. }
  87. void FOOTPRINTS_LISTBOX::SetSelection( int index, bool State )
  88. {
  89. if( index >= GetCount() )
  90. index = GetCount() - 1;
  91. if( (index >= 0) && (GetCount() > 0) )
  92. {
  93. #ifndef __WXMAC__
  94. Select( index, State );
  95. #endif
  96. EnsureVisible( index );
  97. #ifdef __WXMAC__
  98. Refresh();
  99. #endif
  100. }
  101. }
  102. void FOOTPRINTS_LISTBOX::SetFootprints( FOOTPRINT_LIST& aList, const wxString& aLibName,
  103. COMPONENT* aComponent, int aFilterType )
  104. {
  105. wxArrayString newList;
  106. wxString msg;
  107. wxString oldSelection;
  108. if( GetSelection() >= 0 && GetSelection() < (int)m_footprintList.GetCount() )
  109. oldSelection = m_footprintList[ GetSelection() ];
  110. for( unsigned ii = 0; ii < aList.GetCount(); ii++ )
  111. {
  112. if( aFilterType == UNFILTERED )
  113. {
  114. msg.Printf( wxT( "%3d %s:%s" ), int( newList.GetCount() + 1 ),
  115. GetChars( aList.GetItem( ii ).GetNickname() ),
  116. GetChars( aList.GetItem( ii ).GetFootprintName() ) );
  117. newList.Add( msg );
  118. continue;
  119. }
  120. if( (aFilterType & BY_LIBRARY) && !aLibName.IsEmpty()
  121. && !aList.GetItem( ii ).InLibrary( aLibName ) )
  122. continue;
  123. if( (aFilterType & BY_COMPONENT) && aComponent
  124. && !aComponent->MatchesFootprintFilters( aList.GetItem( ii ).GetFootprintName() ) )
  125. continue;
  126. if( (aFilterType & BY_PIN_COUNT) && aComponent
  127. && aComponent->GetNetCount() != aList.GetItem( ii ).GetUniquePadCount() )
  128. continue;
  129. msg.Printf( wxT( "%3d %s:%s" ), int( newList.GetCount() + 1 ),
  130. GetChars( aList.GetItem( ii ).GetNickname() ),
  131. GetChars( aList.GetItem( ii ).GetFootprintName() ) );
  132. newList.Add( msg );
  133. }
  134. if( newList == m_footprintList )
  135. return;
  136. m_footprintList = newList;
  137. int selection = m_footprintList.Index( oldSelection );
  138. if( selection == wxNOT_FOUND )
  139. selection = 0;
  140. DeleteAllItems();
  141. if( m_footprintList.GetCount() )
  142. {
  143. SetItemCount( m_footprintList.GetCount() );
  144. SetSelection( selection, true );
  145. RefreshItems( 0L, m_footprintList.GetCount()-1 );
  146. UpdateWidth();
  147. }
  148. }
  149. BEGIN_EVENT_TABLE( FOOTPRINTS_LISTBOX, ITEMS_LISTBOX_BASE )
  150. EVT_CHAR( FOOTPRINTS_LISTBOX::OnChar )
  151. EVT_LIST_ITEM_SELECTED( ID_CVPCB_FOOTPRINT_LIST, FOOTPRINTS_LISTBOX::OnLeftClick )
  152. EVT_LIST_ITEM_ACTIVATED( ID_CVPCB_FOOTPRINT_LIST, FOOTPRINTS_LISTBOX::OnLeftDClick )
  153. END_EVENT_TABLE()
  154. void FOOTPRINTS_LISTBOX::OnLeftClick( wxListEvent& event )
  155. {
  156. if( m_footprintList.IsEmpty() )
  157. return;
  158. // If the footprint view window is displayed, update the footprint.
  159. if( GetParent()->GetFpViewerFrame() )
  160. GetParent()->CreateScreenCmp();
  161. GetParent()->DisplayStatus();
  162. }
  163. void FOOTPRINTS_LISTBOX::OnLeftDClick( wxListEvent& event )
  164. {
  165. wxString footprintName = GetSelectedFootprint();
  166. GetParent()->SetNewPkg( footprintName );
  167. }
  168. void FOOTPRINTS_LISTBOX::OnChar( wxKeyEvent& event )
  169. {
  170. int key = event.GetKeyCode();
  171. switch( key )
  172. {
  173. case WXK_TAB:
  174. case WXK_RIGHT:
  175. case WXK_NUMPAD_RIGHT:
  176. GetParent()->ChangeFocus( true );
  177. return;
  178. case WXK_LEFT:
  179. case WXK_NUMPAD_LEFT:
  180. GetParent()->ChangeFocus( false );
  181. return;
  182. case WXK_HOME:
  183. case WXK_END:
  184. case WXK_UP:
  185. case WXK_DOWN:
  186. case WXK_PAGEUP:
  187. case WXK_PAGEDOWN:
  188. event.Skip();
  189. return;
  190. default:
  191. break;
  192. }
  193. // Search for an item name starting by the key code:
  194. key = toupper( key );
  195. for( unsigned ii = 0; ii < m_footprintList.GetCount(); ii++ )
  196. {
  197. wxString text = m_footprintList.Item( ii );
  198. // Search for the start char of the footprint name. Skip the line number.
  199. text.Trim( false ); // Remove leading spaces in line
  200. unsigned jj = 0;
  201. for( ; jj < text.Len(); jj++ )
  202. {
  203. // skip line number
  204. if( text[jj] == ' ' )
  205. break;
  206. }
  207. for( ; jj < text.Len(); jj++ )
  208. { // skip blanks
  209. if( text[jj] != ' ' )
  210. break;
  211. }
  212. int start_char = toupper( text[jj] );
  213. if( key == start_char )
  214. {
  215. SetSelection( ii, true ); // Ensure visible
  216. break;
  217. }
  218. }
  219. event.Skip();
  220. }