diff --git a/eeschema/dialogs/dialog_sch_find.fbp b/eeschema/dialogs/dialog_sch_find.fbp
index 36fd85f943..ed18566f2a 100644
--- a/eeschema/dialogs/dialog_sch_find.fbp
+++ b/eeschema/dialogs/dialog_sch_find.fbp
@@ -528,7 +528,7 @@
0
+
6
wxBOTTOM|wxLEFT|wxRIGHT
@@ -935,7 +992,7 @@
0
wxID_ANY
- Do not warp cursor to found item
+ D&o not warp cursor to found item
m_checkNoWarpCursor
diff --git a/eeschema/dialogs/dialog_schematic_find.cpp b/eeschema/dialogs/dialog_schematic_find.cpp
index 89aac3c7b3..135276dc39 100644
--- a/eeschema/dialogs/dialog_schematic_find.cpp
+++ b/eeschema/dialogs/dialog_schematic_find.cpp
@@ -1,3 +1,32 @@
+/*
+ * This program source code file is part of KiCad, a free EDA CAD application.
+ *
+ * Copyright (C) 2010 Wayne Stambaugh
+ * 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
+ */
+
+/**
+ * @file dialog_schematic_find.cpp
+ * @brief Schematic find and replace dialog implementation.
+ */
+
#include "dialog_schematic_find.h"
@@ -21,6 +50,7 @@ DIALOG_SCH_FIND::DIALOG_SCH_FIND( wxWindow* aParent, wxFindReplaceData* aData,
m_buttonReplaceAll->Show( true );
m_staticReplace->Show( true );
m_comboReplace->Show( true );
+ m_checkReplaceReferences->Show( true );
m_checkWildcardMatch->Show( false ); // Wildcard replace is not implemented.
}
@@ -36,6 +66,7 @@ DIALOG_SCH_FIND::DIALOG_SCH_FIND( wxWindow* aParent, wxFindReplaceData* aData,
m_checkWildcardMatch->SetValue( flags & FR_MATCH_WILDCARD );
m_checkAllFields->SetValue( flags & FR_SEARCH_ALL_FIELDS );
+ m_checkReplaceReferences->SetValue( flags & FR_REPLACE_REFERENCES );
m_checkAllPins->SetValue( flags & FR_SEARCH_ALL_PINS );
m_checkWrap->SetValue( flags & FR_SEARCH_WRAP );
m_checkCurrentSheetOnly->SetValue( flags & FR_CURRENT_SHEET_ONLY );
@@ -43,7 +74,21 @@ DIALOG_SCH_FIND::DIALOG_SCH_FIND( wxWindow* aParent, wxFindReplaceData* aData,
m_buttonFind->SetDefault();
m_comboFind->SetFocus();
SetPosition( aPosition );
- SetSize( aSize );
+
+ // Adjust the height of the dialog to prevent controls from being hidden when
+ // switching between the find and find/replace modes of the dialog. This ignores
+ // the users preferred height if any of the controls would be hidden.
+ wxSize size = aSize;
+
+ if( aSize != wxDefaultSize )
+ {
+ wxSize bestSize = GetBestSize();
+
+ if( size.GetHeight() != bestSize.GetHeight() )
+ size.SetHeight( bestSize.GetHeight() );
+ }
+
+ SetSize( size );
}
@@ -142,6 +187,9 @@ void DIALOG_SCH_FIND::SendEvent( const wxEventType& aEventType )
{
event.SetReplaceString( m_comboReplace->GetValue() );
flags |= FR_SEARCH_REPLACE;
+
+ if( m_checkReplaceReferences->GetValue() )
+ flags |= FR_REPLACE_REFERENCES;
}
if( m_radioForward->GetValue() )
diff --git a/eeschema/dialogs/dialog_schematic_find.h b/eeschema/dialogs/dialog_schematic_find.h
index 90a56966d4..738e36f69c 100644
--- a/eeschema/dialogs/dialog_schematic_find.h
+++ b/eeschema/dialogs/dialog_schematic_find.h
@@ -1,5 +1,26 @@
-#ifndef __dialog_schematic_find__
-#define __dialog_schematic_find__
+/*
+ * This program source code file is part of KiCad, a free EDA CAD application.
+ *
+ * Copyright (C) 2010 Wayne Stambaugh
+ * 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
+ */
/**
* @file
@@ -12,6 +33,9 @@
* find out how matching is performed against that item.
*/
+#ifndef __dialog_schematic_find__
+#define __dialog_schematic_find__
+
#include "dialog_schematic_find_base.h"
#include // Use the wxFindReplaceDialog events, data, and enums.
@@ -49,7 +73,10 @@ enum SchematicFindReplaceFlags
/// Used by the search event handler to let the dialog know that a replaceable
/// item has been found.
- FR_REPLACE_ITEM_FOUND = wxFR_MATCHCASE << 8
+ FR_REPLACE_ITEM_FOUND = wxFR_MATCHCASE << 8,
+
+ /// Used by replace to ignore the component reference designator field.
+ FR_REPLACE_REFERENCES = wxFR_MATCHCASE << 9
};
diff --git a/eeschema/dialogs/dialog_schematic_find_base.cpp b/eeschema/dialogs/dialog_schematic_find_base.cpp
index 312e74e6d8..c77391edff 100644
--- a/eeschema/dialogs/dialog_schematic_find_base.cpp
+++ b/eeschema/dialogs/dialog_schematic_find_base.cpp
@@ -67,7 +67,8 @@ DIALOG_SCH_FIND_BASE::DIALOG_SCH_FIND_BASE( wxWindow* parent, wxWindowID id, con
leftSizer->Add( leftGridSizer, 0, wxALL|wxEXPAND, 6 );
- m_checkWholeWord = new wxCheckBox( this, wxID_ANY, _("Match &whole word"), wxDefaultPosition, wxDefaultSize, 0 );
+ m_checkWholeWord = new wxCheckBox( this, wxID_ANY, _("Match whole wor&d"), wxDefaultPosition, wxDefaultSize, 0 );
+ m_checkWholeWord->SetValue(true);
leftSizer->Add( m_checkWholeWord, 0, wxALL, 6 );
m_checkMatchCase = new wxCheckBox( this, wxID_ANY, _("&Match case"), wxDefaultPosition, wxDefaultSize, 0 );
@@ -80,16 +81,21 @@ DIALOG_SCH_FIND_BASE::DIALOG_SCH_FIND_BASE( wxWindow* parent, wxWindowID id, con
m_checkWrap->SetValue(true);
leftSizer->Add( m_checkWrap, 0, wxBOTTOM|wxLEFT|wxRIGHT, 6 );
- m_checkAllFields = new wxCheckBox( this, wxID_ANY, _("Search all component &fields"), wxDefaultPosition, wxDefaultSize, 0 );
+ m_checkAllFields = new wxCheckBox( this, wxID_ANY, _("Search all com&ponent fields"), wxDefaultPosition, wxDefaultSize, 0 );
leftSizer->Add( m_checkAllFields, 0, wxBOTTOM|wxLEFT|wxRIGHT, 6 );
- m_checkAllPins = new wxCheckBox( this, wxID_ANY, _("Search all pin names and numbers"), wxDefaultPosition, wxDefaultSize, 0 );
+ m_checkAllPins = new wxCheckBox( this, wxID_ANY, _("Search all pin &names and numbers"), wxDefaultPosition, wxDefaultSize, 0 );
leftSizer->Add( m_checkAllPins, 0, wxBOTTOM|wxRIGHT|wxLEFT, 6 );
- m_checkCurrentSheetOnly = new wxCheckBox( this, wxID_ANY, _("Search the current sheet on&ly"), wxDefaultPosition, wxDefaultSize, 0 );
+ m_checkCurrentSheetOnly = new wxCheckBox( this, wxID_ANY, _("Search the current &sheet onl&y"), wxDefaultPosition, wxDefaultSize, 0 );
leftSizer->Add( m_checkCurrentSheetOnly, 0, wxBOTTOM|wxLEFT|wxRIGHT, 6 );
- m_checkNoWarpCursor = new wxCheckBox( this, wxID_ANY, _("Do not warp cursor to found item"), wxDefaultPosition, wxDefaultSize, 0 );
+ m_checkReplaceReferences = new wxCheckBox( this, wxID_ANY, _("Replace componen&t reference designators"), wxDefaultPosition, wxDefaultSize, 0 );
+ m_checkReplaceReferences->Hide();
+
+ leftSizer->Add( m_checkReplaceReferences, 0, wxBOTTOM|wxLEFT|wxRIGHT, 6 );
+
+ m_checkNoWarpCursor = new wxCheckBox( this, wxID_ANY, _("D&o not warp cursor to found item"), wxDefaultPosition, wxDefaultSize, 0 );
leftSizer->Add( m_checkNoWarpCursor, 0, wxBOTTOM|wxLEFT|wxRIGHT, 6 );
mainSizer->Add( leftSizer, 1, wxALL|wxEXPAND, 6 );
diff --git a/eeschema/dialogs/dialog_schematic_find_base.h b/eeschema/dialogs/dialog_schematic_find_base.h
index f095ae5f12..b8b0c411a3 100644
--- a/eeschema/dialogs/dialog_schematic_find_base.h
+++ b/eeschema/dialogs/dialog_schematic_find_base.h
@@ -48,6 +48,7 @@ class DIALOG_SCH_FIND_BASE : public wxDialog
wxCheckBox* m_checkAllFields;
wxCheckBox* m_checkAllPins;
wxCheckBox* m_checkCurrentSheetOnly;
+ wxCheckBox* m_checkReplaceReferences;
wxCheckBox* m_checkNoWarpCursor;
wxButton* m_buttonFind;
wxButton* m_buttonReplace;
diff --git a/eeschema/find.cpp b/eeschema/find.cpp
index 53ac012b6e..4d42344aad 100644
--- a/eeschema/find.cpp
+++ b/eeschema/find.cpp
@@ -309,13 +309,14 @@ void SCH_EDIT_FRAME::OnFindSchematicItem( wxFindDialogEvent& aEvent )
searchCriteria.SetFindString( aEvent.GetFindString() );
searchCriteria.SetReplaceString( aEvent.GetReplaceString() );
- if( m_foundItems.GetFindReplaceData().ChangesSearch( searchCriteria ) )
+ if( aEvent.GetEventType() == wxEVT_COMMAND_FIND_CLOSE )
{
- if( aEvent.GetEventType() == wxEVT_COMMAND_FIND_CLOSE )
- {
- warpCursor = true;
- }
- else if( aEvent.GetFlags() & FR_CURRENT_SHEET_ONLY && g_RootSheet->CountSheets() > 1 )
+ if( m_foundItems.GetCount() == 0 )
+ return;
+ }
+ else if( m_foundItems.IsSearchRequired( searchCriteria ) )
+ {
+ if( aEvent.GetFlags() & FR_CURRENT_SHEET_ONLY && g_RootSheet->CountSheets() > 1 )
{
m_foundItems.Collect( searchCriteria, m_CurrentSheet );
}
diff --git a/eeschema/sch_collectors.cpp b/eeschema/sch_collectors.cpp
index 5dd9cb6ac3..15c6e57e31 100644
--- a/eeschema/sch_collectors.cpp
+++ b/eeschema/sch_collectors.cpp
@@ -494,13 +494,14 @@ SEARCH_RESULT SCH_FIND_COLLECTOR::Inspect( EDA_ITEM* aItem, const void* aTestDat
void SCH_FIND_COLLECTOR::Collect( SCH_FIND_REPLACE_DATA& aFindReplaceData,
SCH_SHEET_PATH* aSheetPath )
{
- if( !m_findReplaceData.ChangesSearch( aFindReplaceData ) )
+ if( !m_findReplaceData.ChangesSearch( aFindReplaceData ) && !m_List.empty() && !m_forceSearch )
return;
m_findReplaceData = aFindReplaceData;
Empty(); // empty the collection just in case
m_data.clear();
m_foundIndex = 0;
+ m_forceSearch = false;
if( aSheetPath )
{
diff --git a/eeschema/sch_collectors.h b/eeschema/sch_collectors.h
index 1db5b0dfda..64f6f7c660 100644
--- a/eeschema/sch_collectors.h
+++ b/eeschema/sch_collectors.h
@@ -221,6 +221,10 @@ class SCH_FIND_COLLECTOR : public COLLECTOR
/// The current found item list index.
int m_foundIndex;
+ /// A flag to indicate that the schemtic has been modified and a new search must be
+ /// performed even if the search criteria hasn't changed.
+ bool m_forceSearch;
+
/**
* Function atEnd
* tests if #m_foundIndex is at the end of the list give the current find/replace
@@ -247,8 +251,11 @@ public:
{
SetScanTypes( aScanTypes );
m_foundIndex = 0;
+ m_forceSearch = false;
}
+ void SetForceSearch() { m_forceSearch = true; }
+
/**
* Function UpdateIndex
* updates the list index according to the current find and replace criteria.
@@ -266,12 +273,19 @@ public:
SCH_FIND_COLLECTOR_DATA GetFindData( int aIndex );
/**
- * Function GetFindReplaceData
+ * Function IsSearchRequired
+ * checks the current collector state agaianst \a aFindReplaceData to see if a new search
+ * needs to be performed to update the collector.
*
- * @return A reference to a #SCH_FIND_REPLACE_DATA object containing the current
- * search criteria.
+ * @param aFindReplaceData A #SCH_FIND_REPLACE_DATA object containing the search criteria
+ * to test for changes against the current search criteria.
+ * @return True if \a aFindReplaceData would require a new search to be performaed or
+ * the force search flag is true. Otherwise, false is returned.
*/
- SCH_FIND_REPLACE_DATA& GetFindReplaceData() { return m_findReplaceData; }
+ bool IsSearchRequired( SCH_FIND_REPLACE_DATA& aFindReplaceData )
+ {
+ return m_findReplaceData.ChangesSearch( aFindReplaceData ) || m_forceSearch;
+ }
/**
* Function GetText()
diff --git a/eeschema/sch_field.cpp b/eeschema/sch_field.cpp
index 173573205c..8273861359 100644
--- a/eeschema/sch_field.cpp
+++ b/eeschema/sch_field.cpp
@@ -364,7 +364,8 @@ bool SCH_FIELD::Matches( wxFindReplaceData& aSearchData, void* aAuxData, wxPoint
bool match;
wxString text = GetText();
- if( (m_id > VALUE) && !(aSearchData.GetFlags() & FR_SEARCH_ALL_FIELDS) )
+ if( ((m_id > VALUE) && !(aSearchData.GetFlags() & FR_SEARCH_ALL_FIELDS))
+ || ((m_id == REFERENCE) && !(aSearchData.GetFlags() & FR_REPLACE_REFERENCES)) )
return false;
wxLogTrace( traceFindItem, wxT( " child item " ) + GetSelectMenuText() );
@@ -398,6 +399,40 @@ bool SCH_FIELD::Matches( wxFindReplaceData& aSearchData, void* aAuxData, wxPoint
}
+bool SCH_FIELD::Replace( wxFindReplaceData& aSearchData, void* aAuxData )
+{
+ bool isReplaced;
+ wxString text = GetText();
+
+ if( m_id == REFERENCE && aAuxData != NULL )
+ {
+ wxCHECK_MSG( aSearchData.GetFlags() & FR_REPLACE_REFERENCES, false,
+ wxT( "Invalid replace component reference field call." ) ) ;
+
+ SCH_COMPONENT* component = (SCH_COMPONENT*) m_Parent;
+
+ wxCHECK_MSG( component != NULL, false,
+ wxT( "No component associated with field" ) + text );
+
+ text = component->GetRef( (SCH_SHEET_PATH*) aAuxData );
+
+ if( component->GetPartCount() > 1 )
+ text << LIB_COMPONENT::ReturnSubReference( component->GetUnit() );
+
+ isReplaced = EDA_ITEM::Replace( aSearchData, text );
+
+ if( isReplaced )
+ component->SetRef( (SCH_SHEET_PATH*) aAuxData, text );
+ }
+ else
+ {
+ isReplaced = EDA_ITEM::Replace( aSearchData, m_Text );
+ }
+
+ return isReplaced;
+}
+
+
void SCH_FIELD::Rotate( wxPoint rotationPoint )
{
RotatePoint( &m_Pos, rotationPoint, 900 );
diff --git a/eeschema/sch_field.h b/eeschema/sch_field.h
index 992900b677..098dcfbbe8 100644
--- a/eeschema/sch_field.h
+++ b/eeschema/sch_field.h
@@ -203,12 +203,9 @@ public:
void* aAuxData, wxPoint* aFindLocation );
/**
- * @copydoc EDA_ITEM::Replace(wxFindReplaceData&)
+ * @copydoc EDA_ITEM::Replace(wxFindReplaceData&,void*)
*/
- virtual bool Replace( wxFindReplaceData& aSearchData )
- {
- return EDA_ITEM::Replace( aSearchData, m_Text );
- }
+ virtual bool Replace( wxFindReplaceData& aSearchData, void* aAuxData = NULL );
virtual wxString GetSelectMenuText() const;
diff --git a/eeschema/sch_sheet.cpp b/eeschema/sch_sheet.cpp
index c34e9d67c8..1d58402398 100644
--- a/eeschema/sch_sheet.cpp
+++ b/eeschema/sch_sheet.cpp
@@ -955,7 +955,7 @@ bool SCH_SHEET::Matches( wxFindReplaceData& aSearchData, void* aAuxData, wxPoint
}
-bool SCH_SHEET::Replace( wxFindReplaceData& aSearchData )
+bool SCH_SHEET::Replace( wxFindReplaceData& aSearchData, void* aAuxData )
{
return EDA_ITEM::Replace( aSearchData, m_name );
}
diff --git a/eeschema/sch_sheet.h b/eeschema/sch_sheet.h
index b9955d6caa..b427da8eb8 100644
--- a/eeschema/sch_sheet.h
+++ b/eeschema/sch_sheet.h
@@ -206,9 +206,9 @@ public:
virtual bool Matches( wxFindReplaceData& aSearchData, void* aAuxData, wxPoint* aFindLocation );
/**
- * @copydoc EDA_ITEM::Replace(wxFindReplaceData&)
+ * @copydoc EDA_ITEM::Replace(wxFindReplaceData&,void*)
*/
- virtual bool Replace( wxFindReplaceData& aSearchData )
+ virtual bool Replace( wxFindReplaceData& aSearchData, void* aAuxData = NULL )
{
return EDA_ITEM::Replace( aSearchData, m_Text );
}
@@ -579,9 +579,9 @@ public:
virtual bool Matches( wxFindReplaceData& aSearchData, void* aAuxData, wxPoint* aFindLocation );
/**
- * @copydoc EDA_ITEM::Replace(wxFindReplaceData&)
+ * @copydoc EDA_ITEM::Replace(wxFindReplaceData&,void*)
*/
- virtual bool Replace( wxFindReplaceData& aSearchData );
+ virtual bool Replace( wxFindReplaceData& aSearchData, void* aAuxData = NULL );
/**
* @copydoc EDA_ITEM::IsReplaceable()
diff --git a/eeschema/sch_text.h b/eeschema/sch_text.h
index f1cbe31d80..6c2a19eedf 100644
--- a/eeschema/sch_text.h
+++ b/eeschema/sch_text.h
@@ -207,9 +207,9 @@ public:
virtual bool Matches( wxFindReplaceData& aSearchData, void* aAuxData, wxPoint* aFindLocation );
/**
- * @copydoc EDA_ITEM::Replace(wxFindReplaceData&)
+ * @copydoc EDA_ITEM::Replace(wxFindReplaceData&,void*)
*/
- virtual bool Replace( wxFindReplaceData& aSearchData )
+ virtual bool Replace( wxFindReplaceData& aSearchData, void* aAuxData = NULL )
{
return EDA_ITEM::Replace( aSearchData, m_Text );
}
diff --git a/eeschema/schframe.cpp b/eeschema/schframe.cpp
index 462e11ec4b..69f5b1c8f8 100644
--- a/eeschema/schframe.cpp
+++ b/eeschema/schframe.cpp
@@ -545,6 +545,9 @@ void SCH_EDIT_FRAME::OnModify()
GetScreen()->SetModify();
GetScreen()->SetSave();
+ if( m_dlgFindReplace == NULL )
+ m_foundItems.SetForceSearch();
+
wxString date = GenDate();
SCH_SCREENS s_list;
@@ -559,6 +562,7 @@ void SCH_EDIT_FRAME::OnModify()
screen->m_Date = date;
}
+
/*****************************************************************************
* Enable or disable menu entry and toolbar buttons according to current
* conditions.
@@ -680,7 +684,6 @@ void SCH_EDIT_FRAME::OnFindItems( wxCommandEvent& aEvent )
m_dlgFindReplace->SetFindEntries( m_findStringHistoryList );
m_dlgFindReplace->SetReplaceEntries( m_replaceStringHistoryList );
- m_dlgFindReplace->SetMinSize( m_dlgFindReplace->GetBestSize() );
m_dlgFindReplace->Show( true );
}
diff --git a/include/base_struct.h b/include/base_struct.h
index e96a686f99..f286735f31 100644
--- a/include/base_struct.h
+++ b/include/base_struct.h
@@ -661,9 +661,11 @@ public:
*
* @param aSearchData A reference to a wxFindReplaceData object containing the
* search and replace criteria.
+ * @param aAuxData A pointer to optional data required for the search or NULL
+ * if not used.
* @return True if the item text was modified, otherwise false.
*/
- virtual bool Replace( wxFindReplaceData& aSearchData ) { return false; }
+ virtual bool Replace( wxFindReplaceData& aSearchData, void* aAuxData = NULL ) { return false; }
/**
* Function IsReplaceable