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.

202 lines
5.0 KiB

  1. /*
  2. * This program source code file is part of KICAD, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2012 Marco Mattila <marcom99@gmail.com>
  5. * Copyright (C) 2018 Jean-Pierre Charras jp.charras at wanadoo.fr
  6. * Copyright (C) 1992-2018 Kicad Developers, see AUTHORS.txt for contributors.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version 2
  11. * of the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, you may find one here:
  20. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  21. * or you may search the http://www.gnu.org website for the version 2 license,
  22. * or you may write to the Free Software Foundation, Inc.,
  23. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  24. */
  25. #include <fctsys.h>
  26. #include <gr_basic.h>
  27. #include <class_drawpanel.h>
  28. #include <confirm.h>
  29. #include <kicad_string.h>
  30. #include <pcb_edit_frame.h>
  31. #include <class_board.h>
  32. #include <class_module.h>
  33. #include <class_marker_pcb.h>
  34. #include <pcbnew.h>
  35. #include <pcbnew_id.h>
  36. #include <dialog_find.h>
  37. // Initialize static member variables
  38. wxString DIALOG_FIND::prevSearchString;
  39. bool DIALOG_FIND::warpMouse = true;
  40. DIALOG_FIND::DIALOG_FIND( PCB_BASE_FRAME* aParent ) : DIALOG_FIND_BASE( aParent )
  41. {
  42. parent = aParent;
  43. foundItem = NULL;
  44. GetSizer()->SetSizeHints( this );
  45. m_SearchTextCtrl->AppendText( prevSearchString );
  46. m_NoMouseWarpCheckBox->SetValue( !warpMouse );
  47. itemCount = markerCount = 0;
  48. Center();
  49. }
  50. void DIALOG_FIND::OnInitDialog( wxInitDialogEvent& event )
  51. {
  52. m_SearchTextCtrl->SetFocus();
  53. m_SearchTextCtrl->SetSelection( -1, -1 );
  54. }
  55. void DIALOG_FIND::EnableWarp( bool aEnabled )
  56. {
  57. m_NoMouseWarpCheckBox->SetValue( !aEnabled );
  58. warpMouse = aEnabled;
  59. }
  60. void DIALOG_FIND::onButtonCloseClick( wxCommandEvent& aEvent )
  61. {
  62. Close( true );
  63. }
  64. void DIALOG_FIND::onButtonFindItemClick( wxCommandEvent& aEvent )
  65. {
  66. PCB_SCREEN* screen = parent->GetScreen();
  67. wxPoint pos;
  68. wxString searchString = m_SearchTextCtrl->GetValue();
  69. if( !searchString.IsSameAs( prevSearchString, false ) )
  70. {
  71. itemCount = 0;
  72. foundItem = NULL;
  73. }
  74. prevSearchString = searchString;
  75. parent->GetCanvas()->GetViewStart( &screen->m_StartVisu.x, &screen->m_StartVisu.y );
  76. int count = 0;
  77. for( MODULE* module = parent->GetBoard()->m_Modules; module; module = module->Next() )
  78. {
  79. if( WildCompareString( searchString, module->GetReference().GetData(), false ) )
  80. {
  81. count++;
  82. if( count > itemCount )
  83. {
  84. foundItem = module;
  85. pos = module->GetPosition();
  86. itemCount++;
  87. break;
  88. }
  89. }
  90. if( WildCompareString( searchString, module->GetValue().GetData(), false ) )
  91. {
  92. count++;
  93. if( count > itemCount )
  94. {
  95. foundItem = module;
  96. pos = module->GetPosition();
  97. itemCount++;
  98. break;
  99. }
  100. }
  101. }
  102. wxString msg;
  103. if( foundItem )
  104. {
  105. parent->SetCurItem( foundItem );
  106. parent->FocusOnLocation( pos, !m_NoMouseWarpCheckBox->IsChecked(), true );
  107. msg.Printf( _( "\"%s\" found" ), GetChars( searchString ) );
  108. parent->SetStatusText( msg );
  109. }
  110. else
  111. {
  112. parent->SetStatusText( wxEmptyString );
  113. msg.Printf( _( "\"%s\" not found" ), GetChars( searchString ) );
  114. DisplayError( this, msg, 10 );
  115. itemCount = 0;
  116. }
  117. if( callback )
  118. callback( foundItem );
  119. }
  120. void DIALOG_FIND::onButtonFindMarkerClick( wxCommandEvent& aEvent )
  121. {
  122. PCB_SCREEN* screen = parent->GetScreen();
  123. wxPoint pos;
  124. foundItem = NULL;
  125. parent->GetCanvas()->GetViewStart( &screen->m_StartVisu.x, &screen->m_StartVisu.y );
  126. MARKER_PCB* marker = parent->GetBoard()->GetMARKER( markerCount++ );
  127. if( marker )
  128. {
  129. foundItem = marker;
  130. pos = marker->GetPosition();
  131. }
  132. wxString msg;
  133. if( foundItem )
  134. {
  135. parent->SetCurItem( foundItem );
  136. parent->FocusOnLocation( pos, !m_NoMouseWarpCheckBox->IsChecked() );
  137. msg = _( "Marker found" );
  138. parent->SetStatusText( msg );
  139. }
  140. else
  141. {
  142. parent->SetStatusText( wxEmptyString );
  143. msg = _( "No marker found" );
  144. DisplayError( this, msg, 10 );
  145. markerCount = 0;
  146. }
  147. if( callback )
  148. callback( foundItem );
  149. }
  150. void DIALOG_FIND::onClose( wxCloseEvent& aEvent )
  151. {
  152. warpMouse = !m_NoMouseWarpCheckBox->IsChecked();
  153. EndModal( 1 );
  154. }
  155. void PCB_EDIT_FRAME::InstallFindFrame()
  156. {
  157. DIALOG_FIND dlg( this );
  158. dlg.ShowModal();
  159. }