KiCad PCB EDA Suite
dialog_find.cpp
Go to the documentation of this file.
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) 2006 Jean-Pierre Charras <jean-pierre.charras@gipsa-lab.inpg.fr>
6  * Copyright (C) 1992-2012 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 
26 #include <fctsys.h>
27 #include <gr_basic.h>
28 #include <class_drawpanel.h>
29 #include <confirm.h>
30 #include <kicad_string.h>
31 #include <wxPcbStruct.h>
32 
33 #include <class_board.h>
34 #include <class_module.h>
35 #include <class_marker_pcb.h>
36 
37 #include <pcbnew.h>
38 #include <pcbnew_id.h>
39 #include <dialog_find.h>
40 
41 
42 // Initialize static member variables
44 bool DIALOG_FIND::warpMouse = true;
45 
46 
48 {
49  parent = aParent;
50  foundItem = NULL;
51  GetSizer()->SetSizeHints( this );
52 
53  m_SearchTextCtrl->AppendText( prevSearchString );
54  m_NoMouseWarpCheckBox->SetValue( !warpMouse );
55 
56  itemCount = markerCount = 0;
57 
58  Center();
59 }
60 
61 void DIALOG_FIND::OnInitDialog( wxInitDialogEvent& event )
62 {
63  m_SearchTextCtrl->SetFocus();
64  m_SearchTextCtrl->SetSelection( -1, -1 );
65 }
66 
67 void DIALOG_FIND::EnableWarp( bool aEnabled )
68 {
69  m_NoMouseWarpCheckBox->SetValue( !aEnabled );
70  warpMouse = aEnabled;
71 }
72 
73 void DIALOG_FIND::onButtonCloseClick( wxCommandEvent& aEvent )
74 {
75  Close( true );
76 }
77 
78 
79 void DIALOG_FIND::onButtonFindItemClick( wxCommandEvent& aEvent )
80 {
81  PCB_SCREEN* screen = parent->GetScreen();
82  wxPoint pos;
83 
84  foundItem = NULL;
85  wxString searchString = m_SearchTextCtrl->GetValue();
86 
87  if( !searchString.IsSameAs( prevSearchString, false ) )
88  {
89  itemCount = 0;
90  }
91  prevSearchString = searchString;
92 
93  parent->GetCanvas()->GetViewStart( &screen->m_StartVisu.x, &screen->m_StartVisu.y );
94 
95  int count = 0;
96 
97  for( MODULE* module = parent->GetBoard()->m_Modules; module; module = module->Next() )
98  {
99  if( WildCompareString( searchString, module->GetReference().GetData(), false ) )
100  {
101  count++;
102 
103  if( count > itemCount )
104  {
105  foundItem = module;
106  pos = module->GetPosition();
107  itemCount++;
108  break;
109  }
110  }
111 
112  if( WildCompareString( searchString, module->GetValue().GetData(), false ) )
113  {
114  count++;
115 
116  if( count > itemCount )
117  {
118  foundItem = module;
119  pos = module->GetPosition();
120  itemCount++;
121  break;
122  }
123  }
124  }
125 
126  wxString msg;
127 
128  if( foundItem )
129  {
131  msg.Printf( _( "<%s> found" ), GetChars( searchString ) );
132  parent->SetStatusText( msg );
133 
134  parent->CursorGoto( pos, !m_NoMouseWarpCheckBox->IsChecked() );
135  }
136  else
137  {
138  parent->SetStatusText( wxEmptyString );
139  msg.Printf( _( "<%s> not found" ), GetChars( searchString ) );
140  DisplayError( this, msg, 10 );
141  itemCount = 0;
142  }
143 
144  if( callback )
145  callback( foundItem );
146 }
147 
148 
149 void DIALOG_FIND::onButtonFindMarkerClick( wxCommandEvent& aEvent )
150 {
151  PCB_SCREEN* screen = parent->GetScreen();
152  wxPoint pos;
153  foundItem = NULL;
154 
155  parent->GetCanvas()->GetViewStart( &screen->m_StartVisu.x, &screen->m_StartVisu.y );
156 
157  MARKER_PCB* marker = parent->GetBoard()->GetMARKER( markerCount++ );
158 
159  if( marker )
160  {
161  foundItem = marker;
162  pos = marker->GetPosition();
163  }
164 
165  wxString msg;
166  if( foundItem )
167  {
169  msg = _( "Marker found" );
170  parent->SetStatusText( msg );
171 
172  parent->CursorGoto( pos, !m_NoMouseWarpCheckBox->IsChecked() );
173  }
174  else
175  {
176  parent->SetStatusText( wxEmptyString );
177  msg = _( "No marker found" );
178  DisplayError( this, msg, 10 );
179  markerCount = 0;
180  }
181 
182  if( callback )
183  callback( foundItem );
184 }
185 
186 
187 void DIALOG_FIND::onClose( wxCloseEvent& aEvent )
188 {
189  warpMouse = !m_NoMouseWarpCheckBox->IsChecked();
190 
191  EndModal( 1 );
192 }
193 
194 
196 {
197  DIALOG_FIND dlg( this );
198  dlg.ShowModal();
199 }
200 
void OnInitDialog(wxInitDialogEvent &event) override
Definition: dialog_find.cpp:61
MARKER_PCB * GetMARKER(int index) const
Function GetMARKER returns the MARKER at a given index.
Definition: class_board.h:310
This file is part of the common library.
EDA_DRAW_PANEL * GetCanvas()
Definition: draw_frame.h:299
int markerCount
Definition: dialog_find.h:44
Class BOARD to handle a board.
void EnableWarp(bool aEnabled)
Definition: dialog_find.cpp:67
void InstallFindFrame()
MODULE * Next() const
Definition: class_module.h:99
void SetCurItem(BOARD_ITEM *aItem, bool aDisplayInfo=true)
Function SetCurItem sets the currently selected item and displays it in the MsgPanel.
BOARD * GetBoard() const
void onButtonFindMarkerClick(wxCommandEvent &event) override
const wxPoint & GetPosition() const override
void CursorGoto(const wxPoint &aPos, bool aWarp=true)
Function CursorGoto positions the cursor at a given coordinate and reframes the drawing if the reques...
wxCheckBox * m_NoMouseWarpCheckBox
wxPoint m_StartVisu
Coordinates in drawing units of the current view position (upper left corner of device) ...
static bool warpMouse
Definition: dialog_find.h:46
Markers used to show a drc problem on boards.
bool WildCompareString(const wxString &pattern, const wxString &string_to_tst, bool case_sensitive)
Function WildCompareString compares a string against wild card (* and ?) pattern using the usual rule...
Definition: string.cpp:305
DIALOG_FIND(PCB_BASE_FRAME *aParent)
Definition: dialog_find.cpp:47
boost::function< void(BOARD_ITEM *)> callback
Definition: dialog_find.h:50
PCB_BASE_FRAME * parent
Definition: dialog_find.h:42
static wxString prevSearchString
Definition: dialog_find.h:45
BOARD_ITEM * foundItem
Definition: dialog_find.h:47
wxTextCtrl * m_SearchTextCtrl
void onClose(wxCloseEvent &event) override
void onButtonFindItemClick(wxCommandEvent &event) override
Definition: dialog_find.cpp:79
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:92
DLIST< MODULE > m_Modules
Definition: class_board.h:243
PCB_SCREEN * GetScreen() const override
Function GetScreen returns a pointer to a BASE_SCREEN or one of its derivatives.
Module description (excepted pads)
void onButtonCloseClick(wxCommandEvent &event) override
Definition: dialog_find.cpp:73
void DisplayError(wxWindow *parent, const wxString &text, int displaytime)
Function DisplayError displays an error or warning message box with aMessage.
Definition: confirm.cpp:69
class PCB_BASE_FRAME basic PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer...
Class DIALOG_FIND_BASE.