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) 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 
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 <pcb_edit_frame.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  parent->FocusOnLocation( pos, !m_NoMouseWarpCheckBox->IsChecked(), true );
132  msg.Printf( _( "\"%s\" found" ), GetChars( searchString ) );
133  parent->SetStatusText( msg );
134  }
135  else
136  {
137  parent->SetStatusText( wxEmptyString );
138  msg.Printf( _( "\"%s\" not found" ), GetChars( searchString ) );
139  DisplayError( this, msg, 10 );
140  itemCount = 0;
141  }
142 
143  if( callback )
144  callback( foundItem );
145 }
146 
147 
148 void DIALOG_FIND::onButtonFindMarkerClick( wxCommandEvent& aEvent )
149 {
150  PCB_SCREEN* screen = parent->GetScreen();
151  wxPoint pos;
152  foundItem = NULL;
153 
154  parent->GetCanvas()->GetViewStart( &screen->m_StartVisu.x, &screen->m_StartVisu.y );
155 
156  MARKER_PCB* marker = parent->GetBoard()->GetMARKER( markerCount++ );
157 
158  if( marker )
159  {
160  foundItem = marker;
161  pos = marker->GetPosition();
162  }
163 
164  wxString msg;
165  if( foundItem )
166  {
168  parent->FocusOnLocation( pos, !m_NoMouseWarpCheckBox->IsChecked() );
169  msg = _( "Marker found" );
170  parent->SetStatusText( msg );
171  }
172  else
173  {
174  parent->SetStatusText( wxEmptyString );
175  msg = _( "No marker found" );
176  DisplayError( this, msg, 10 );
177  markerCount = 0;
178  }
179 
180  if( callback )
181  callback( foundItem );
182 }
183 
184 
185 void DIALOG_FIND::onClose( wxCloseEvent& aEvent )
186 {
187  warpMouse = !m_NoMouseWarpCheckBox->IsChecked();
188 
189  EndModal( 1 );
190 }
191 
192 
194 {
195  DIALOG_FIND dlg( this );
196  dlg.ShowModal();
197 }
198 
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:321
const wxPoint GetPosition() const override
This file is part of the common library.
EDA_DRAW_PANEL * GetCanvas()
Definition: draw_frame.h:342
int markerCount
Definition: dialog_find.h:44
void FocusOnLocation(const wxPoint &aPos, bool aWarpMouseCursor=true, bool aCenterView=false)
Useful to focus on a particular location, in find functions Move the graphic cursor (crosshair cursor...
Class BOARD to handle a board.
void EnableWarp(bool aEnabled)
Definition: dialog_find.cpp:67
void InstallFindFrame()
MODULE * Next() const
Definition: class_module.h:121
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
wxCheckBox * m_NoMouseWarpCheckBox
wxPoint m_StartVisu
Coordinates in drawing units of the current view position (upper left corner of device) ...
Definition: base_screen.h:198
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:245
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:241
class PCB_BASE_FRAME basic PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer...
Class DIALOG_FIND_BASE.