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 
62 void DIALOG_FIND::OnInitDialog( wxInitDialogEvent& event )
63 {
64  m_SearchTextCtrl->SetFocus();
65  m_SearchTextCtrl->SetSelection( -1, -1 );
66 }
67 
68 
69 void DIALOG_FIND::EnableWarp( bool aEnabled )
70 {
71  m_NoMouseWarpCheckBox->SetValue( !aEnabled );
72  warpMouse = aEnabled;
73 }
74 
75 
76 void DIALOG_FIND::onButtonCloseClick( wxCommandEvent& aEvent )
77 {
78  Close( true );
79 }
80 
81 
82 void DIALOG_FIND::onButtonFindItemClick( wxCommandEvent& aEvent )
83 {
84  PCB_SCREEN* screen = parent->GetScreen();
85  wxPoint pos;
86 
87  wxString searchString = m_SearchTextCtrl->GetValue();
88 
89  if( !searchString.IsSameAs( prevSearchString, false ) )
90  {
91  itemCount = 0;
92  foundItem = NULL;
93  }
94 
95  prevSearchString = searchString;
96 
97  parent->GetCanvas()->GetViewStart( &screen->m_StartVisu.x, &screen->m_StartVisu.y );
98 
99  int count = 0;
100 
101  for( MODULE* module = parent->GetBoard()->m_Modules; module; module = module->Next() )
102  {
103  if( WildCompareString( searchString, module->GetReference().GetData(), false ) )
104  {
105  count++;
106 
107  if( count > itemCount )
108  {
109  foundItem = module;
110  pos = module->GetPosition();
111  itemCount++;
112  break;
113  }
114  }
115 
116  if( WildCompareString( searchString, module->GetValue().GetData(), false ) )
117  {
118  count++;
119 
120  if( count > itemCount )
121  {
122  foundItem = module;
123  pos = module->GetPosition();
124  itemCount++;
125  break;
126  }
127  }
128  }
129 
130  wxString msg;
131 
132  if( foundItem )
133  {
135  parent->FocusOnLocation( pos, !m_NoMouseWarpCheckBox->IsChecked(), true );
136  msg.Printf( _( "\"%s\" found" ), GetChars( searchString ) );
137  parent->SetStatusText( msg );
138  }
139  else
140  {
141  parent->SetStatusText( wxEmptyString );
142  msg.Printf( _( "\"%s\" not found" ), GetChars( searchString ) );
143  DisplayError( this, msg, 10 );
144  itemCount = 0;
145  }
146 
147  if( callback )
148  callback( foundItem );
149 }
150 
151 
152 void DIALOG_FIND::onButtonFindMarkerClick( wxCommandEvent& aEvent )
153 {
154  PCB_SCREEN* screen = parent->GetScreen();
155  wxPoint pos;
156  foundItem = NULL;
157 
158  parent->GetCanvas()->GetViewStart( &screen->m_StartVisu.x, &screen->m_StartVisu.y );
159 
160  MARKER_PCB* marker = parent->GetBoard()->GetMARKER( markerCount++ );
161 
162  if( marker )
163  {
164  foundItem = marker;
165  pos = marker->GetPosition();
166  }
167 
168  wxString msg;
169  if( foundItem )
170  {
172  parent->FocusOnLocation( pos, !m_NoMouseWarpCheckBox->IsChecked() );
173  msg = _( "Marker found" );
174  parent->SetStatusText( msg );
175  }
176  else
177  {
178  parent->SetStatusText( wxEmptyString );
179  msg = _( "No marker found" );
180  DisplayError( this, msg, 10 );
181  markerCount = 0;
182  }
183 
184  if( callback )
185  callback( foundItem );
186 }
187 
188 
189 void DIALOG_FIND::onClose( wxCloseEvent& aEvent )
190 {
191  warpMouse = !m_NoMouseWarpCheckBox->IsChecked();
192 
193  EndModal( 1 );
194 }
195 
196 
198 {
199  DIALOG_FIND dlg( this );
200  dlg.ShowModal();
201 }
202 
void OnInitDialog(wxInitDialogEvent &event) override
Definition: dialog_find.cpp:62
MARKER_PCB * GetMARKER(int index) const
Function GetMARKER returns the MARKER at a given index.
Definition: class_board.h:327
const wxPoint GetPosition() const override
virtual EDA_DRAW_PANEL * GetCanvas() const
Definition: draw_frame.h:388
This file is part of the common library.
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:69
void InstallFindFrame()
MODULE * Next() const
Definition: class_module.h:123
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:377
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:82
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:248
PCB_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
Module description (excepted pads)
void onButtonCloseClick(wxCommandEvent &event) override
Definition: dialog_find.cpp:76
void DisplayError(wxWindow *parent, const wxString &text, int displaytime)
Function DisplayError displays an error or warning message box with aMessage.
Definition: confirm.cpp:245
class PCB_BASE_FRAME basic PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer...
Class DIALOG_FIND_BASE.