KiCad PCB EDA Suite
dialog_schematic_find.h
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) 2010 Wayne Stambaugh <stambaughw@verizon.net>
5  * Copyright (C) 2010-2011 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
36 #ifndef __dialog_schematic_find__
37 #define __dialog_schematic_find__
38 
40 
41 #include <wx/fdrepdlg.h> // Use the wxFindReplaceDialog events, data, and enums.
42 
43 
50 {
51  // The last wxFindReplaceFlag enum is wxFR_MATCHCASE = 0x4.
52 
54  FR_CURRENT_SHEET_ONLY = wxFR_MATCHCASE << 1,
55 
57  FR_SEARCH_ALL_FIELDS = wxFR_MATCHCASE << 2,
58 
60  FR_SEARCH_ALL_PINS = wxFR_MATCHCASE << 3,
61 
63  FR_MATCH_WILDCARD = wxFR_MATCHCASE << 4,
64 
66  FR_SEARCH_WRAP = wxFR_MATCHCASE << 5,
67 
69  FR_NO_WARP_CURSOR = wxFR_MATCHCASE << 6,
70 
72  FR_SEARCH_REPLACE = wxFR_MATCHCASE << 7,
73 
76  FR_REPLACE_ITEM_FOUND = wxFR_MATCHCASE << 8,
77 
79  FR_REPLACE_REFERENCES = wxFR_MATCHCASE << 9
80 };
81 
82 
87 #define FR_MASK_NON_COMPARE_FLAGS ~( wxFR_DOWN | FR_SEARCH_WRAP | FR_NO_WARP_CURSOR | \
88  FR_REPLACE_ITEM_FOUND )
89 
90 
95 class SCH_FIND_REPLACE_DATA : public wxFindReplaceData
96 {
97 public:
98 
100  {
101  if( this == &aFindReplaceData )
102  return *this;
103 
104  SetFlags( aFindReplaceData.GetFlags() );
105  SetFindString( aFindReplaceData.GetFindString() );
106  SetReplaceString( aFindReplaceData.GetReplaceString() );
107 
108  return *this;
109  }
110 
111  bool operator ==( SCH_FIND_REPLACE_DATA& aFindReplaceData )
112  {
113  return ( (GetFlags() == aFindReplaceData.GetFlags())
114  && (GetFindString() == aFindReplaceData.GetFindString())
115  && (GetReplaceString() == aFindReplaceData.GetReplaceString()) );
116  }
117 
118  bool operator !=( SCH_FIND_REPLACE_DATA& aFindReplaceData )
119  {
120  return !( *this == aFindReplaceData );
121  }
122 
123 
134  bool ChangesCompare( const SCH_FIND_REPLACE_DATA& aFindReplaceData )
135  {
136  return ( (GetFindString() != aFindReplaceData.GetFindString())
137  || (GetCompareFlags() != aFindReplaceData.GetCompareFlags()) );
138  }
139 
140  bool IsReplacing() const { return (GetFlags() & FR_SEARCH_REPLACE) != 0; }
141  bool IsWrapping() const { return (GetFlags() & FR_SEARCH_WRAP) != 0; }
142 
143 private:
148  wxUint32 GetCompareFlags() const { return GetFlags() & FR_MASK_NON_COMPARE_FLAGS; }
149 };
150 
151 
154 {
155 protected:
156  // Handlers for DIALOG_SCH_FIND_BASE events.
157  void OnClose( wxCloseEvent& aEvent ) override;
158  void OnUpdateFindUI( wxUpdateUIEvent& aEvent ) override;
159  void OnUpdateReplaceUI( wxUpdateUIEvent& aEvent ) override;
160  void OnUpdateReplaceAllUI( wxUpdateUIEvent& aEvent ) override;
161  void OnUpdateWholeWordUI( wxUpdateUIEvent& aEvent ) override;
162  void OnUpdateWildcardUI( wxUpdateUIEvent& aEvent ) override;
163 
164  void OnFind( wxCommandEvent& aEvent ) override;
165  void OnReplace( wxCommandEvent& aEvent ) override;
166  void OnCancel( wxCommandEvent& aEvent ) override;
167 
168  void SendEvent( const wxEventType& aEventType );
169 
170  wxFindReplaceData *m_findReplaceData;
171 
172  DECLARE_NO_COPY_CLASS( DIALOG_SCH_FIND )
173 
174 public:
175  DIALOG_SCH_FIND( wxWindow* aParent, wxFindReplaceData* aData,
176  const wxPoint& aPosition = wxDefaultPosition,
177  const wxSize& aSize = wxDefaultSize, int aStyle = 0 );
178 
179  const wxFindReplaceData *GetData() const { return m_findReplaceData; }
180  void SetData(wxFindReplaceData *aData) { m_findReplaceData = aData; }
181 
182  void SetFindEntries( const wxArrayString& aEntries );
183  wxArrayString GetFindEntries() const;
184 
185  void SetReplaceEntries( const wxArrayString& aEntries );
186  wxArrayString GetReplaceEntries() const { return m_comboReplace->GetStrings(); }
187 };
188 
189 
190 BEGIN_DECLARE_EVENT_TYPES()
191  DECLARE_LOCAL_EVENT_TYPE( EVT_COMMAND_FIND_DRC_MARKER, wxID_ANY )
192  DECLARE_LOCAL_EVENT_TYPE( EVT_COMMAND_FIND_COMPONENT_IN_LIB, wxID_ANY )
193 END_DECLARE_EVENT_TYPES()
194 
195 
196 #define EVT_FIND_DRC_MARKER( id, fn ) \
197  wx__DECLARE_EVT1( EVT_COMMAND_FIND_DRC_MARKER, id, wxFindDialogEventHandler( fn ) )
198 
199 #define EVT_FIND_COMPONENT_IN_LIB( id, fn ) \
200  wx__DECLARE_EVT1( EVT_COMMAND_FIND_COMPONENT_IN_LIB, id, wxFindDialogEventHandler( fn ) )
201 
202 #endif // __dialog_schematic_find__
void OnUpdateReplaceAllUI(wxUpdateUIEvent &aEvent) override
void OnUpdateWholeWordUI(wxUpdateUIEvent &aEvent) override
wxUint32 GetCompareFlags() const
Function GetSearchFlags.
SchematicFindReplaceFlags
Define schematic specific find and replace dialog flags based on the enum entries in wxFindReplaceFla...
wxArrayString GetReplaceEntries() const
Class DIALOG_SCH_FIND_BASE.
bool ChangesCompare(const SCH_FIND_REPLACE_DATA &aFindReplaceData)
Function ChangesCompare tests aFindReplaceData to see if it would result in a change in the search st...
Search texts (name and number (a 4 letters text) )in pins.
Used by the search event handler to let the dialog know that a replaceable item has been found...
Wrap around the beginning or end of search list.
Search all fields in component, not just the value and reference fields.
void OnReplace(wxCommandEvent &aEvent) override
void SendEvent(const wxEventType &aEventType)
Implementing DIALOG_SCH_FIND_BASE.
SCH_FIND_REPLACE_DATA & operator=(SCH_FIND_REPLACE_DATA &aFindReplaceData)
#define FR_MASK_NON_COMPARE_FLAGS
Definition FR_MASK_NON_COMPARE_FLAGS is used to mask find/replace flag bits that do not effect the se...
wxFindReplaceData * m_findReplaceData
bool operator==(SCH_FIND_REPLACE_DATA &aFindReplaceData)
void OnClose(wxCloseEvent &aEvent) override
void OnUpdateReplaceUI(wxUpdateUIEvent &aEvent) override
Perform search using simple wild card matching (* & ?).
Search the current sheet only.
void SetReplaceEntries(const wxArrayString &aEntries)
void SetFindEntries(const wxArrayString &aEntries)
void OnUpdateFindUI(wxUpdateUIEvent &aEvent) override
void SetData(wxFindReplaceData *aData)
void OnUpdateWildcardUI(wxUpdateUIEvent &aEvent) override
void OnFind(wxCommandEvent &aEvent) override
Don't warp cursor to found item until the dialog is closed.
bool operator!=(SCH_FIND_REPLACE_DATA &aFindReplaceData)
Used by replace to ignore the component reference designator field.
Class SCH_FIND_REPLACE_DATA adds missing useful comparison and assignment operators to the wxFindRepl...
Perform a search for a item that has replaceable text.
const wxFindReplaceData * GetData() const
wxArrayString GetFindEntries() const
void OnCancel(wxCommandEvent &aEvent) override