dialog_schematic_find.h 7.11 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
/*
 * This program source code file is part of KiCad, a free EDA CAD application.
 *
 * Copyright (C) 2010 Wayne Stambaugh <stambaughw@verizon.net>
 * Copyright (C) 2010-2011 KiCad Developers, see AUTHORS.txt for contributors.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, you may find one here:
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 * or you may search the http://www.gnu.org website for the version 2 license,
 * or you may write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 */
24 25 26 27 28 29 30 31 32 33 34 35

/**
 * @file
 *
 * Subclass of DIALOG_SCH_FIND_BASE, which is generated by wxFormBuilder.
 *
 * This dialog is used to define the search criteria used to search for items
 * in the current schematic.  What is searched depends on the schematic item
 * type.  Check the Matches() method for each item derived from SCH_ITEM() to
 * find out how matching is performed against that item.
 */

36 37 38
#ifndef __dialog_schematic_find__
#define __dialog_schematic_find__

39 40 41 42 43
#include "dialog_schematic_find_base.h"

#include <wx/fdrepdlg.h>          // Use the wxFindReplaceDialog events, data, and enums.


44 45
/**
 * Define schematic specific find and replace dialog flags based on the enum entries
46
 * in wxFindReplaceFlags.   These flags are intended to be used as bit masks in the
47
 * wxFindReplaceData::m_Flags member variable.  The variable is defined as a wxUint32.
48 49 50
 */
enum SchematicFindReplaceFlags
{
51
    // The last wxFindReplaceFlag enum is wxFR_MATCHCASE = 0x4.
52

53
    /// Search the current sheet only.
54 55
    FR_CURRENT_SHEET_ONLY    = wxFR_MATCHCASE << 1,

56
    /// Search all fields in component, not just the value and reference fields.
57 58
    FR_SEARCH_ALL_FIELDS     = wxFR_MATCHCASE << 2,

59 60
    /// Search texts (name and number (a 4 letters text) )in pins.
    FR_SEARCH_ALL_PINS       = wxFR_MATCHCASE << 3,
61

62
    /// Perform search using simple wild card matching (* & ?).
63
    FR_MATCH_WILDCARD        = wxFR_MATCHCASE << 4,
64

65
    /// Wrap around the beginning or end of search list.
66 67
    FR_SEARCH_WRAP           = wxFR_MATCHCASE << 5,

68 69 70
    /// Don't warp cursor to found item until the dialog is closed.
    FR_NO_WARP_CURSOR        = wxFR_MATCHCASE << 6,

71
    /// Perform a search for a item that has replaceable text.
72 73 74 75
    FR_SEARCH_REPLACE        = wxFR_MATCHCASE << 7,

    /// Used by the search event handler to let the dialog know that a replaceable
    /// item has been found.
76 77 78 79
    FR_REPLACE_ITEM_FOUND    = wxFR_MATCHCASE << 8,

    /// Used by replace to ignore the component reference designator field.
    FR_REPLACE_REFERENCES    = wxFR_MATCHCASE << 9
80 81 82
};


83
/**
84
 * Definition FR_MASK_NON_COMPARE_FLAGS
85 86
 * is used to mask find/replace flag bits that do not effect the search results.
 */
87 88
#define FR_MASK_NON_COMPARE_FLAGS  ~( wxFR_DOWN | FR_SEARCH_WRAP | FR_NO_WARP_CURSOR | \
                                      FR_REPLACE_ITEM_FOUND )
89 90


91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
/**
 * Class SCH_FIND_REPLACE_DATA
 * adds missing useful comparison and assignment operators to the wxFindReplaceData object.
 */
class SCH_FIND_REPLACE_DATA : public wxFindReplaceData
{
public:

    SCH_FIND_REPLACE_DATA& operator =( SCH_FIND_REPLACE_DATA& aFindReplaceData )
    {
        if( this == &aFindReplaceData )
            return *this;

        SetFlags( aFindReplaceData.GetFlags() );
        SetFindString( aFindReplaceData.GetFindString() );
        SetReplaceString( aFindReplaceData.GetReplaceString() );

        return *this;
    }

    bool operator ==( SCH_FIND_REPLACE_DATA& aFindReplaceData )
    {
        return ( (GetFlags() == aFindReplaceData.GetFlags())
                 && (GetFindString() == aFindReplaceData.GetFindString())
                 && (GetReplaceString() == aFindReplaceData.GetReplaceString()) );
    }

    bool operator !=( SCH_FIND_REPLACE_DATA& aFindReplaceData )
    {
        return !( *this == aFindReplaceData );
    }
122 123 124


    /**
125 126 127
     * Function ChangesCompare
     * tests \a aFindReplaceData to see if it would result in a change in the search string
     * comparison results.
128 129 130 131 132 133
     *
     * @param aFindReplaceData A reference to a #SCH_FIND_REPLACE_DATA object to compare
     *                         against.
     * @return True if \a aFindReplaceData would result in a search and/or replace change,
     *         otherwise false.
     */
134
    bool ChangesCompare( 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 144 145 146 147

private:
    /**
     * Function GetSearchFlags
     * @return The flags that only effect the search result.
     */
148
    wxUint32 GetCompareFlags() const { return GetFlags() & FR_MASK_NON_COMPARE_FLAGS; }
149 150 151
};


152 153 154 155 156 157 158
/** Implementing DIALOG_SCH_FIND_BASE */
class DIALOG_SCH_FIND : public DIALOG_SCH_FIND_BASE
{
protected:
    // Handlers for DIALOG_SCH_FIND_BASE events.
    void OnClose( wxCloseEvent& aEvent );
    void OnUpdateFindUI( wxUpdateUIEvent& aEvent );
159
    void OnUpdateReplaceUI( wxUpdateUIEvent& aEvent );
160 161
    void OnUpdateWholeWordUI( wxUpdateUIEvent& aEvent );
    void OnUpdateWildcardUI( wxUpdateUIEvent& aEvent );
162

163
    void OnFind( wxCommandEvent& aEvent );
164
    void OnReplace( wxCommandEvent& aEvent );
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
    void OnCancel( wxCommandEvent& aEvent );

    void SendEvent( const wxEventType& aEventType );

    wxFindReplaceData *m_findReplaceData;

    DECLARE_NO_COPY_CLASS( DIALOG_SCH_FIND )

public:
    DIALOG_SCH_FIND( wxWindow* aParent, wxFindReplaceData* aData,
                     const wxPoint& aPosition = wxDefaultPosition,
                     const wxSize& aSize = wxDefaultSize, int aStyle = 0 );

    const wxFindReplaceData *GetData() const { return m_findReplaceData; }
    void SetData(wxFindReplaceData *aData) { m_findReplaceData = aData; }

    void SetFindEntries( const wxArrayString& aEntries );
    wxArrayString GetFindEntries() const;

    void SetReplaceEntries( const wxArrayString& aEntries );
    wxArrayString GetReplaceEntries() const { return m_comboReplace->GetStrings(); }
};


BEGIN_DECLARE_EVENT_TYPES()
190 191
    DECLARE_LOCAL_EVENT_TYPE( EVT_COMMAND_FIND_DRC_MARKER, wxID_ANY )
    DECLARE_LOCAL_EVENT_TYPE( EVT_COMMAND_FIND_COMPONENT_IN_LIB, wxID_ANY )
192 193 194 195 196 197 198 199 200 201
END_DECLARE_EVENT_TYPES()


#define EVT_FIND_DRC_MARKER( id, fn ) \
    wx__DECLARE_EVT1( EVT_COMMAND_FIND_DRC_MARKER, id, wxFindDialogEventHandler( fn ) )

#define EVT_FIND_COMPONENT_IN_LIB( id, fn ) \
    wx__DECLARE_EVT1( EVT_COMMAND_FIND_COMPONENT_IN_LIB, id, wxFindDialogEventHandler( fn ) )

#endif // __dialog_schematic_find__