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.

203 lines
7.3 KiB

  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. /**
  25. * @file
  26. *
  27. * Subclass of DIALOG_SCH_FIND_BASE, which is generated by wxFormBuilder.
  28. *
  29. * This dialog is used to define the search criteria used to search for items
  30. * in the current schematic. What is searched depends on the schematic item
  31. * type. Check the Matches() method for each item derived from SCH_ITEM() to
  32. * find out how matching is performed against that item.
  33. */
  34. #ifndef __dialog_schematic_find__
  35. #define __dialog_schematic_find__
  36. #include "dialog_schematic_find_base.h"
  37. #include <wx/fdrepdlg.h> // Use the wxFindReplaceDialog events, data, and enums.
  38. /**
  39. * Define schematic specific find and replace dialog flags based on the enum entries
  40. * in wxFindReplaceFlags. These flags are intended to be used as bit masks in the
  41. * wxFindReplaceData::m_Flags member variable. The variable is defined as a wxUint32.
  42. */
  43. enum SchematicFindReplaceFlags
  44. {
  45. // The last wxFindReplaceFlag enum is wxFR_MATCHCASE = 0x4.
  46. /// Search the current sheet only.
  47. FR_CURRENT_SHEET_ONLY = wxFR_MATCHCASE << 1,
  48. /// Search all fields in component, not just the value and reference fields.
  49. FR_SEARCH_ALL_FIELDS = wxFR_MATCHCASE << 2,
  50. /// Search texts (name and number (a 4 letters text) )in pins.
  51. FR_SEARCH_ALL_PINS = wxFR_MATCHCASE << 3,
  52. /// Perform search using simple wild card matching (* & ?).
  53. FR_MATCH_WILDCARD = wxFR_MATCHCASE << 4,
  54. /// Wrap around the beginning or end of search list.
  55. FR_SEARCH_WRAP = wxFR_MATCHCASE << 5,
  56. /// Don't warp cursor to found item until the dialog is closed.
  57. FR_NO_WARP_CURSOR = wxFR_MATCHCASE << 6,
  58. /// Perform a search for a item that has replaceable text.
  59. FR_SEARCH_REPLACE = wxFR_MATCHCASE << 7,
  60. /// Used by the search event handler to let the dialog know that a replaceable
  61. /// item has been found.
  62. FR_REPLACE_ITEM_FOUND = wxFR_MATCHCASE << 8,
  63. /// Used by replace to ignore the component reference designator field.
  64. FR_REPLACE_REFERENCES = wxFR_MATCHCASE << 9
  65. };
  66. /**
  67. * Definition FR_MASK_NON_COMPARE_FLAGS
  68. * is used to mask find/replace flag bits that do not effect the search results.
  69. */
  70. #define FR_MASK_NON_COMPARE_FLAGS ~( wxFR_DOWN | FR_SEARCH_WRAP | FR_NO_WARP_CURSOR | \
  71. FR_REPLACE_ITEM_FOUND )
  72. /**
  73. * Class SCH_FIND_REPLACE_DATA
  74. * adds missing useful comparison and assignment operators to the wxFindReplaceData object.
  75. */
  76. class SCH_FIND_REPLACE_DATA : public wxFindReplaceData
  77. {
  78. public:
  79. SCH_FIND_REPLACE_DATA& operator =( SCH_FIND_REPLACE_DATA& aFindReplaceData )
  80. {
  81. if( this == &aFindReplaceData )
  82. return *this;
  83. SetFlags( aFindReplaceData.GetFlags() );
  84. SetFindString( aFindReplaceData.GetFindString() );
  85. SetReplaceString( aFindReplaceData.GetReplaceString() );
  86. return *this;
  87. }
  88. bool operator ==( SCH_FIND_REPLACE_DATA& aFindReplaceData )
  89. {
  90. return ( (GetFlags() == aFindReplaceData.GetFlags())
  91. && (GetFindString() == aFindReplaceData.GetFindString())
  92. && (GetReplaceString() == aFindReplaceData.GetReplaceString()) );
  93. }
  94. bool operator !=( SCH_FIND_REPLACE_DATA& aFindReplaceData )
  95. {
  96. return !( *this == aFindReplaceData );
  97. }
  98. /**
  99. * Function ChangesCompare
  100. * tests \a aFindReplaceData to see if it would result in a change in the search string
  101. * comparison results.
  102. *
  103. * @param aFindReplaceData A reference to a #SCH_FIND_REPLACE_DATA object to compare
  104. * against.
  105. * @return True if \a aFindReplaceData would result in a search and/or replace change,
  106. * otherwise false.
  107. */
  108. bool ChangesCompare( const SCH_FIND_REPLACE_DATA& aFindReplaceData )
  109. {
  110. return ( (GetFindString() != aFindReplaceData.GetFindString())
  111. || (GetCompareFlags() != aFindReplaceData.GetCompareFlags()) );
  112. }
  113. bool IsReplacing() const { return (GetFlags() & FR_SEARCH_REPLACE) != 0; }
  114. bool IsWrapping() const { return (GetFlags() & FR_SEARCH_WRAP) != 0; }
  115. private:
  116. /**
  117. * Function GetSearchFlags
  118. * @return The flags that only effect the search result.
  119. */
  120. wxUint32 GetCompareFlags() const { return GetFlags() & FR_MASK_NON_COMPARE_FLAGS; }
  121. };
  122. /** Implementing DIALOG_SCH_FIND_BASE */
  123. class DIALOG_SCH_FIND : public DIALOG_SCH_FIND_BASE
  124. {
  125. protected:
  126. // Handlers for DIALOG_SCH_FIND_BASE events.
  127. void OnClose( wxCloseEvent& aEvent ) override;
  128. void OnTextEnter( wxCommandEvent& event ) override;
  129. void OnUpdateFindUI( wxUpdateUIEvent& aEvent ) override;
  130. void OnUpdateReplaceUI( wxUpdateUIEvent& aEvent ) override;
  131. void OnUpdateReplaceAllUI( wxUpdateUIEvent& aEvent ) override;
  132. void OnUpdateWholeWordUI( wxUpdateUIEvent& aEvent ) override;
  133. void OnUpdateWildcardUI( wxUpdateUIEvent& aEvent ) override;
  134. void OnFind( wxCommandEvent& aEvent ) override;
  135. void OnReplace( wxCommandEvent& aEvent ) override;
  136. void OnCancel( wxCommandEvent& aEvent ) override;
  137. void SendEvent( const wxEventType& aEventType );
  138. wxFindReplaceData *m_findReplaceData;
  139. DECLARE_NO_COPY_CLASS( DIALOG_SCH_FIND )
  140. public:
  141. DIALOG_SCH_FIND( wxWindow* aParent, wxFindReplaceData* aData,
  142. const wxPoint& aPosition = wxDefaultPosition,
  143. const wxSize& aSize = wxDefaultSize, int aStyle = 0 );
  144. const wxFindReplaceData *GetData() const { return m_findReplaceData; }
  145. void SetData(wxFindReplaceData *aData) { m_findReplaceData = aData; }
  146. void SetFindEntries( const wxArrayString& aEntries );
  147. wxArrayString GetFindEntries() const;
  148. void SetReplaceEntries( const wxArrayString& aEntries );
  149. wxArrayString GetReplaceEntries() const { return m_comboReplace->GetStrings(); }
  150. };
  151. BEGIN_DECLARE_EVENT_TYPES()
  152. DECLARE_LOCAL_EVENT_TYPE( EVT_COMMAND_FIND_DRC_MARKER, wxID_ANY )
  153. DECLARE_LOCAL_EVENT_TYPE( EVT_COMMAND_FIND_COMPONENT_IN_LIB, wxID_ANY )
  154. END_DECLARE_EVENT_TYPES()
  155. #define EVT_FIND_DRC_MARKER( id, fn ) \
  156. wx__DECLARE_EVT1( EVT_COMMAND_FIND_DRC_MARKER, id, wxFindDialogEventHandler( fn ) )
  157. #define EVT_FIND_COMPONENT_IN_LIB( id, fn ) \
  158. wx__DECLARE_EVT1( EVT_COMMAND_FIND_COMPONENT_IN_LIB, id, wxFindDialogEventHandler( fn ) )
  159. #endif // __dialog_schematic_find__