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.

377 lines
9.9 KiB

17 years ago
18 years ago
18 years ago
  1. /********************************************/
  2. /* PCBNEW - Find dialog box implementation. */
  3. /********************************************/
  4. #include "fctsys.h"
  5. #include "gr_basic.h"
  6. #include "common.h"
  7. #include "class_drawpanel.h"
  8. #include "confirm.h"
  9. #include "kicad_string.h"
  10. #include "pcbnew.h"
  11. #include "wxPcbStruct.h"
  12. #include "pcbnew_id.h"
  13. #include "protos.h"
  14. #include "find.h"
  15. static wxString s_OldStringFound;
  16. static int s_ItemCount, s_MarkerCount;
  17. void WinEDA_PcbFrame::InstallFindFrame( const wxPoint& pos, wxDC* DC )
  18. {
  19. WinEDA_PcbFindFrame* frame = new WinEDA_PcbFindFrame( this, DC, pos );
  20. frame->ShowModal();
  21. frame->Destroy();
  22. }
  23. void WinEDA_PcbFindFrame::FindItem( wxCommandEvent& event )
  24. {
  25. PCB_SCREEN* screen = (PCB_SCREEN*) ( m_Parent->GetScreen() );
  26. wxPoint locate_pos;
  27. wxString msg;
  28. bool FindMarker = FALSE;
  29. BOARD_ITEM* foundItem = 0;
  30. switch( event.GetId() )
  31. {
  32. case ID_FIND_ITEM:
  33. s_ItemCount = 0;
  34. break;
  35. case ID_FIND_MARKER:
  36. s_MarkerCount = 0;
  37. // fall thru
  38. case ID_FIND_NEXT_MARKER:
  39. FindMarker = TRUE;
  40. break;
  41. }
  42. s_OldStringFound = m_NewText->GetValue();
  43. m_Parent->DrawPanel->GetViewStart( &screen->m_StartVisu.x,
  44. &screen->m_StartVisu.y );
  45. if( FindMarker )
  46. {
  47. MARKER_PCB* marker = m_Parent->GetBoard()->GetMARKER( s_MarkerCount++ );
  48. if( marker )
  49. {
  50. foundItem = marker;
  51. locate_pos = marker->GetPosition();
  52. }
  53. }
  54. else
  55. {
  56. int StartCount = 0;
  57. for( MODULE* module = m_Parent->GetBoard()->m_Modules;
  58. module;
  59. module = module->Next() )
  60. {
  61. if( WildCompareString( s_OldStringFound,
  62. module->GetReference().GetData(), FALSE ) )
  63. {
  64. StartCount++;
  65. if( StartCount > s_ItemCount )
  66. {
  67. foundItem = module;
  68. locate_pos = module->GetPosition();
  69. s_ItemCount++;
  70. break;
  71. }
  72. }
  73. if( WildCompareString( s_OldStringFound,
  74. module->m_Value->m_Text.GetData(), FALSE ) )
  75. {
  76. StartCount++;
  77. if( StartCount > s_ItemCount )
  78. {
  79. foundItem = module;
  80. locate_pos = module->m_Pos;
  81. s_ItemCount++;
  82. break;
  83. }
  84. }
  85. }
  86. }
  87. if( foundItem )
  88. {
  89. m_Parent->SetCurItem( foundItem );
  90. if( FindMarker )
  91. msg = _( "Marker found" );
  92. else
  93. msg.Printf( _( "<%s> Found" ), GetChars( s_OldStringFound ) );
  94. m_Parent->Affiche_Message( msg );
  95. m_Parent->CursorGoto( locate_pos );
  96. EndModal( 1 );
  97. }
  98. else
  99. {
  100. m_Parent->Affiche_Message( wxEmptyString );
  101. if( FindMarker )
  102. msg = _( "Marker not found" );
  103. else
  104. msg.Printf( _( "<%s> Not Found" ), GetChars( s_OldStringFound ) );
  105. DisplayError( this, msg, 10 );
  106. EndModal( 0 );
  107. }
  108. }
  109. /*!
  110. * WinEDA_PcbFindFrame type definition
  111. */
  112. IMPLEMENT_DYNAMIC_CLASS( WinEDA_PcbFindFrame, wxDialog )
  113. /*!
  114. * WinEDA_PcbFindFrame event table definition
  115. */
  116. BEGIN_EVENT_TABLE( WinEDA_PcbFindFrame, wxDialog )
  117. ////@begin WinEDA_PcbFindFrame event table entries
  118. EVT_BUTTON( ID_FIND_ITEM, WinEDA_PcbFindFrame::OnFindItemClick )
  119. EVT_BUTTON( ID_FIND_NEXT_ITEM, WinEDA_PcbFindFrame::OnFindNextItemClick )
  120. EVT_BUTTON( ID_FIND_MARKER, WinEDA_PcbFindFrame::OnFindMarkerClick )
  121. EVT_BUTTON( ID_FIND_NEXT_MARKER, WinEDA_PcbFindFrame::OnFindNextMarkerClick )
  122. ////@end WinEDA_PcbFindFrame event table entries
  123. END_EVENT_TABLE()
  124. /*!
  125. * WinEDA_PcbFindFrame constructors
  126. */
  127. WinEDA_PcbFindFrame::WinEDA_PcbFindFrame()
  128. {
  129. }
  130. WinEDA_PcbFindFrame::WinEDA_PcbFindFrame( WinEDA_BasePcbFrame* parent,
  131. wxDC* DC,
  132. const wxPoint& pos,
  133. wxWindowID id,
  134. const wxString& caption,
  135. const wxSize& size,
  136. long style )
  137. {
  138. m_Parent = parent;
  139. m_DC = DC;
  140. Create( parent, id, caption, pos, size, style );
  141. m_NewText->SetFocus();
  142. }
  143. /*!
  144. * WinEDA_PcbFindFrame creator
  145. */
  146. bool WinEDA_PcbFindFrame::Create( wxWindow* parent,
  147. wxWindowID id,
  148. const wxString& caption,
  149. const wxPoint& pos,
  150. const wxSize& size,
  151. long style )
  152. {
  153. ////@begin WinEDA_PcbFindFrame member initialisation
  154. m_NewText = NULL;
  155. ////@end WinEDA_PcbFindFrame member initialisation
  156. ////@begin WinEDA_PcbFindFrame creation
  157. SetExtraStyle( wxWS_EX_BLOCK_EVENTS );
  158. wxDialog::Create( parent, id, caption, pos, size, style );
  159. CreateControls();
  160. if( GetSizer() )
  161. {
  162. GetSizer()->SetSizeHints( this );
  163. }
  164. Centre();
  165. ////@end WinEDA_PcbFindFrame creation
  166. return true;
  167. }
  168. /*!
  169. * Control creation for WinEDA_PcbFindFrame
  170. */
  171. void WinEDA_PcbFindFrame::CreateControls()
  172. {
  173. ////@begin WinEDA_PcbFindFrame content construction
  174. // Generated by DialogBlocks, 29/04/2009 15:15:49 (unregistered)
  175. WinEDA_PcbFindFrame* itemDialog1 = this;
  176. wxBoxSizer* itemBoxSizer2 = new wxBoxSizer( wxVERTICAL );
  177. itemDialog1->SetSizer( itemBoxSizer2 );
  178. wxStaticText* itemStaticText3 = new wxStaticText( itemDialog1,
  179. wxID_STATIC,
  180. _( "Item to find:" ),
  181. wxDefaultPosition,
  182. wxDefaultSize,
  183. 0 );
  184. itemBoxSizer2->Add( itemStaticText3,
  185. 0,
  186. wxGROW | wxLEFT | wxRIGHT | wxTOP | wxADJUST_MINSIZE,
  187. 5 );
  188. m_NewText = new wxTextCtrl( itemDialog1, ID_TEXTCTRL, _T( "" ),
  189. wxDefaultPosition, wxDefaultSize, 0 );
  190. itemBoxSizer2->Add( m_NewText, 0, wxGROW | wxLEFT | wxRIGHT | wxBOTTOM, 5 );
  191. wxBoxSizer* itemBoxSizer5 = new wxBoxSizer( wxHORIZONTAL );
  192. itemBoxSizer2->Add( itemBoxSizer5,
  193. 0,
  194. wxALIGN_CENTER_HORIZONTAL | wxLEFT | wxRIGHT |
  195. wxBOTTOM,
  196. 5 );
  197. wxBoxSizer* itemBoxSizer6 = new wxBoxSizer( wxVERTICAL );
  198. itemBoxSizer5->Add( itemBoxSizer6,
  199. 0,
  200. wxALIGN_CENTER_VERTICAL | wxLEFT | wxRIGHT,
  201. 5 );
  202. wxButton* itemButton7 =
  203. new wxButton( itemDialog1, ID_FIND_ITEM, _( "Find Item" ),
  204. wxDefaultPosition, wxDefaultSize, 0 );
  205. itemButton7->SetDefault();
  206. itemBoxSizer6->Add( itemButton7, 0, wxGROW | wxLEFT | wxRIGHT | wxTOP, 5 );
  207. wxButton* itemButton8 =
  208. new wxButton( itemDialog1, ID_FIND_NEXT_ITEM, _( "Find Next Item" ),
  209. wxDefaultPosition, wxDefaultSize,
  210. 0 );
  211. itemBoxSizer6->Add( itemButton8,
  212. 0,
  213. wxGROW | wxLEFT | wxRIGHT | wxBOTTOM,
  214. 5 );
  215. wxBoxSizer* itemBoxSizer9 = new wxBoxSizer( wxVERTICAL );
  216. itemBoxSizer5->Add( itemBoxSizer9,
  217. 0,
  218. wxALIGN_CENTER_VERTICAL | wxLEFT | wxRIGHT,
  219. 5 );
  220. wxButton* itemButton10 =
  221. new wxButton( itemDialog1, ID_FIND_MARKER, _( "Find Marker" ),
  222. wxDefaultPosition, wxDefaultSize, 0 );
  223. itemBoxSizer9->Add( itemButton10, 0, wxGROW | wxLEFT | wxRIGHT | wxTOP, 5 );
  224. wxButton* itemButton11 = new wxButton( itemDialog1,
  225. ID_FIND_NEXT_MARKER,
  226. _( "Find Next Marker" ),
  227. wxDefaultPosition,
  228. wxDefaultSize,
  229. 0 );
  230. itemBoxSizer9->Add( itemButton11,
  231. 0,
  232. wxGROW | wxLEFT | wxRIGHT | wxBOTTOM,
  233. 5 );
  234. ////@end WinEDA_PcbFindFrame content construction
  235. }
  236. /*!
  237. * Should we show tooltips?
  238. */
  239. bool WinEDA_PcbFindFrame::ShowToolTips()
  240. {
  241. return true;
  242. }
  243. /*!
  244. * Get bitmap resources
  245. */
  246. wxBitmap WinEDA_PcbFindFrame::GetBitmapResource( const wxString& name )
  247. {
  248. // Bitmap retrieval
  249. ////@begin WinEDA_PcbFindFrame bitmap retrieval
  250. wxUnusedVar( name );
  251. return wxNullBitmap;
  252. ////@end WinEDA_PcbFindFrame bitmap retrieval
  253. }
  254. /*!
  255. * Get icon resources
  256. */
  257. wxIcon WinEDA_PcbFindFrame::GetIconResource( const wxString& name )
  258. {
  259. // Icon retrieval
  260. ////@begin WinEDA_PcbFindFrame icon retrieval
  261. wxUnusedVar( name );
  262. return wxNullIcon;
  263. ////@end WinEDA_PcbFindFrame icon retrieval
  264. }
  265. /*!
  266. * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_FIND_ITEM
  267. */
  268. void WinEDA_PcbFindFrame::OnFindItemClick( wxCommandEvent& event )
  269. {
  270. FindItem( event );
  271. }
  272. /*!
  273. * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_FIND_NEXT_ITEM
  274. */
  275. void WinEDA_PcbFindFrame::OnFindNextItemClick( wxCommandEvent& event )
  276. {
  277. FindItem( event );
  278. }
  279. /*!
  280. * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_FIND_MARKER
  281. */
  282. void WinEDA_PcbFindFrame::OnFindMarkerClick( wxCommandEvent& event )
  283. {
  284. FindItem( event );
  285. }
  286. /*!
  287. * wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_FIND_NEXT_MARKER
  288. */
  289. void WinEDA_PcbFindFrame::OnFindNextMarkerClick( wxCommandEvent& event )
  290. {
  291. FindItem( event );
  292. }