2012-05-28 20:01:51 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KICAD, a free EDA CAD application.
|
|
|
|
*
|
2012-05-29 20:43:17 +00:00
|
|
|
* Copyright (C) 2012 Marco Mattila <marcom99@gmail.com>
|
2018-01-17 14:36:04 +00:00
|
|
|
* Copyright (C) 2018 Jean-Pierre Charras jp.charras at wanadoo.fr
|
|
|
|
* Copyright (C) 1992-2018 Kicad Developers, see AUTHORS.txt for contributors.
|
2012-05-28 20:01:51 +00:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <fctsys.h>
|
|
|
|
#include <confirm.h>
|
|
|
|
#include <kicad_string.h>
|
2018-01-29 20:58:58 +00:00
|
|
|
#include <pcb_edit_frame.h>
|
2019-05-28 23:23:58 +00:00
|
|
|
#include <tool/tool_manager.h>
|
|
|
|
#include <tools/pcb_actions.h>
|
2012-05-28 20:01:51 +00:00
|
|
|
#include <class_board.h>
|
|
|
|
#include <class_module.h>
|
|
|
|
#include <class_marker_pcb.h>
|
2019-07-26 23:52:17 +00:00
|
|
|
#include <class_text_mod.h>
|
|
|
|
#include <class_pcb_text.h>
|
2012-05-28 20:01:51 +00:00
|
|
|
#include <pcbnew.h>
|
|
|
|
#include <pcbnew_id.h>
|
2014-10-13 13:23:30 +00:00
|
|
|
#include <dialog_find.h>
|
2019-07-26 23:52:17 +00:00
|
|
|
#include <wx/fdrepdlg.h>
|
2012-05-28 20:01:51 +00:00
|
|
|
|
|
|
|
|
2019-07-26 23:52:17 +00:00
|
|
|
DIALOG_FIND::DIALOG_FIND( PCB_BASE_FRAME* aFrame ) :
|
|
|
|
DIALOG_FIND_BASE( aFrame )
|
2012-05-28 20:01:51 +00:00
|
|
|
{
|
2019-07-26 23:52:17 +00:00
|
|
|
m_frame = aFrame;
|
|
|
|
m_foundItem = NULL;
|
2012-05-28 20:01:51 +00:00
|
|
|
GetSizer()->SetSizeHints( this );
|
|
|
|
|
2019-07-26 23:52:17 +00:00
|
|
|
m_SearchCombo->Append( m_frame->GetFindHistoryList() );
|
|
|
|
|
|
|
|
if( m_SearchCombo->GetCount() )
|
|
|
|
{
|
|
|
|
m_SearchCombo->SetSelection( 0 );
|
|
|
|
m_SearchCombo->SelectAll();
|
|
|
|
}
|
2012-05-28 20:01:51 +00:00
|
|
|
|
2019-07-26 23:52:17 +00:00
|
|
|
m_matchCase->SetValue( ( m_frame->GetFindReplaceData().GetFlags() & wxFR_MATCHCASE ) > 0 );
|
|
|
|
m_matchWords->SetValue( ( m_frame->GetFindReplaceData().GetFlags() & wxFR_WHOLEWORD ) > 0 );
|
|
|
|
m_wildcards->SetValue( ( m_frame->GetFindReplaceData().GetFlags() & FR_MATCH_WILDCARD ) > 0 );
|
2012-05-28 20:01:51 +00:00
|
|
|
|
2019-07-26 23:52:17 +00:00
|
|
|
m_itemCount = m_markerCount = 0;
|
2012-05-28 20:01:51 +00:00
|
|
|
|
2019-07-26 23:52:17 +00:00
|
|
|
SetInitialFocus( m_SearchCombo );
|
2018-09-19 16:30:04 +00:00
|
|
|
|
2019-07-26 23:52:17 +00:00
|
|
|
Center();
|
2017-01-22 21:51:37 +00:00
|
|
|
}
|
|
|
|
|
2018-09-19 16:30:04 +00:00
|
|
|
|
2019-07-26 23:52:17 +00:00
|
|
|
void DIALOG_FIND::OnTextEnter( wxCommandEvent& aEvent )
|
2014-10-13 13:23:30 +00:00
|
|
|
{
|
2019-07-26 23:52:17 +00:00
|
|
|
onButtonFindItemClick( aEvent );
|
2014-10-13 13:23:30 +00:00
|
|
|
}
|
2012-05-28 20:01:51 +00:00
|
|
|
|
2018-09-19 16:30:04 +00:00
|
|
|
|
2012-05-28 20:01:51 +00:00
|
|
|
void DIALOG_FIND::onButtonCloseClick( wxCommandEvent& aEvent )
|
|
|
|
{
|
|
|
|
Close( true );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_FIND::onButtonFindItemClick( wxCommandEvent& aEvent )
|
|
|
|
{
|
2019-07-26 23:52:17 +00:00
|
|
|
PCB_SCREEN* screen = m_frame->GetScreen();
|
|
|
|
int flags = 0;
|
|
|
|
wxString msg;
|
2019-07-27 05:50:51 +00:00
|
|
|
wxString searchString = m_SearchCombo->GetValue();
|
|
|
|
int index = m_SearchCombo->FindString( searchString, true );
|
2019-07-26 23:52:17 +00:00
|
|
|
|
|
|
|
if( m_matchCase->GetValue() )
|
|
|
|
flags |= wxFR_MATCHCASE;
|
|
|
|
|
|
|
|
if( m_matchWords->GetValue() )
|
|
|
|
flags |= wxFR_WHOLEWORD;
|
|
|
|
|
|
|
|
if( m_wildcards->GetValue() )
|
|
|
|
flags |= FR_MATCH_WILDCARD;
|
2012-05-28 20:01:51 +00:00
|
|
|
|
2019-07-27 05:50:51 +00:00
|
|
|
if( index == wxNOT_FOUND )
|
|
|
|
{
|
|
|
|
m_SearchCombo->Insert( searchString, 0 );
|
|
|
|
}
|
|
|
|
else if( index != 0 )
|
|
|
|
{
|
|
|
|
/* Move the search string to the top of the list if it isn't already there. */
|
|
|
|
m_SearchCombo->Delete( index );
|
|
|
|
m_SearchCombo->Insert( searchString, 0 );
|
|
|
|
m_SearchCombo->SetSelection( 0 );
|
|
|
|
}
|
|
|
|
|
2019-07-26 23:52:17 +00:00
|
|
|
wxString last;
|
2019-05-29 19:04:45 +00:00
|
|
|
|
2019-07-26 23:52:17 +00:00
|
|
|
if( !m_frame->GetFindHistoryList().empty() )
|
|
|
|
last = m_frame->GetFindHistoryList().back();
|
2012-05-28 20:01:51 +00:00
|
|
|
|
2019-07-26 23:52:17 +00:00
|
|
|
if( !searchString.IsSameAs( last, false ) )
|
2012-05-28 20:01:51 +00:00
|
|
|
{
|
2019-07-26 23:52:17 +00:00
|
|
|
m_itemCount = 0;
|
|
|
|
m_foundItem = NULL;
|
|
|
|
m_frame->GetFindHistoryList().push_back( searchString );
|
2012-05-28 20:01:51 +00:00
|
|
|
}
|
2018-09-19 16:30:04 +00:00
|
|
|
|
2019-07-26 23:52:17 +00:00
|
|
|
m_frame->GetFindReplaceData().SetFindString( searchString );
|
|
|
|
m_frame->GetFindReplaceData().SetFlags( flags );
|
2012-05-28 20:01:51 +00:00
|
|
|
|
2019-07-27 05:50:51 +00:00
|
|
|
m_frame->GetToolManager()->RunAction( PCB_ACTIONS::selectionClear, true );
|
2019-07-26 23:52:17 +00:00
|
|
|
m_frame->GetCanvas()->GetViewStart( &screen->m_StartVisu.x, &screen->m_StartVisu.y );
|
2012-05-28 20:01:51 +00:00
|
|
|
|
|
|
|
int count = 0;
|
|
|
|
|
2019-07-26 23:52:17 +00:00
|
|
|
for( MODULE* module : m_frame->GetBoard()->Modules() )
|
2012-05-28 20:01:51 +00:00
|
|
|
{
|
2019-07-26 23:52:17 +00:00
|
|
|
if( module->Reference().Matches( m_frame->GetFindReplaceData(), nullptr )
|
|
|
|
|| module->Value().Matches( m_frame->GetFindReplaceData(), nullptr ) )
|
2012-05-28 20:01:51 +00:00
|
|
|
{
|
|
|
|
count++;
|
|
|
|
|
2019-07-26 23:52:17 +00:00
|
|
|
if( count > m_itemCount )
|
2012-05-28 20:01:51 +00:00
|
|
|
{
|
2019-07-26 23:52:17 +00:00
|
|
|
m_foundItem = module;
|
|
|
|
m_itemCount++;
|
2012-05-28 20:01:51 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-26 23:52:17 +00:00
|
|
|
for( BOARD_ITEM* item : module->GraphicalItems() )
|
|
|
|
{
|
|
|
|
TEXTE_MODULE* textItem = dynamic_cast<TEXTE_MODULE*>( item );
|
|
|
|
|
|
|
|
if( textItem && textItem->Matches( m_frame->GetFindReplaceData(), nullptr ) )
|
|
|
|
{
|
|
|
|
count++;
|
|
|
|
|
|
|
|
if( count > m_itemCount )
|
|
|
|
{
|
|
|
|
m_foundItem = module;
|
|
|
|
m_itemCount++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for( BOARD_ITEM* item : m_frame->GetBoard()->Drawings() )
|
|
|
|
{
|
|
|
|
TEXTE_PCB* textItem = dynamic_cast<TEXTE_PCB*>( item );
|
|
|
|
|
|
|
|
if( textItem && textItem->Matches( m_frame->GetFindReplaceData(), nullptr ) )
|
2012-05-28 20:01:51 +00:00
|
|
|
{
|
|
|
|
count++;
|
|
|
|
|
2019-07-26 23:52:17 +00:00
|
|
|
if( count > m_itemCount )
|
2012-05-28 20:01:51 +00:00
|
|
|
{
|
2019-07-26 23:52:17 +00:00
|
|
|
m_foundItem = textItem;
|
|
|
|
m_itemCount++;
|
2012-05-28 20:01:51 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-26 23:52:17 +00:00
|
|
|
if( m_foundItem )
|
2012-05-28 20:01:51 +00:00
|
|
|
{
|
2019-07-26 23:52:17 +00:00
|
|
|
m_frame->GetToolManager()->RunAction( PCB_ACTIONS::selectItem, true, m_foundItem );
|
|
|
|
m_frame->FocusOnLocation( m_foundItem->GetPosition(), true );
|
2017-12-15 11:37:46 +00:00
|
|
|
msg.Printf( _( "\"%s\" found" ), GetChars( searchString ) );
|
2019-07-26 23:52:17 +00:00
|
|
|
m_frame->SetStatusText( msg );
|
2012-05-28 20:01:51 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-07-26 23:52:17 +00:00
|
|
|
m_frame->SetStatusText( wxEmptyString );
|
2017-12-15 11:37:46 +00:00
|
|
|
msg.Printf( _( "\"%s\" not found" ), GetChars( searchString ) );
|
2012-05-28 20:01:51 +00:00
|
|
|
DisplayError( this, msg, 10 );
|
2019-07-26 23:52:17 +00:00
|
|
|
m_itemCount = 0;
|
2012-05-28 20:01:51 +00:00
|
|
|
}
|
2014-10-13 13:23:30 +00:00
|
|
|
|
2019-07-26 23:52:17 +00:00
|
|
|
if( m_highlightCallback )
|
|
|
|
m_highlightCallback( m_foundItem );
|
2012-05-28 20:01:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_FIND::onButtonFindMarkerClick( wxCommandEvent& aEvent )
|
|
|
|
{
|
2019-07-26 23:52:17 +00:00
|
|
|
PCB_SCREEN* screen = m_frame->GetScreen();
|
|
|
|
wxString msg;
|
2012-05-28 20:01:51 +00:00
|
|
|
|
2019-07-26 23:52:17 +00:00
|
|
|
m_foundItem = nullptr;
|
2012-05-28 20:01:51 +00:00
|
|
|
|
2019-07-26 23:52:17 +00:00
|
|
|
m_frame->GetToolManager()->RunAction( PCB_ACTIONS::selectionClear, true );
|
|
|
|
m_frame->GetCanvas()->GetViewStart( &screen->m_StartVisu.x, &screen->m_StartVisu.y );
|
|
|
|
|
|
|
|
MARKER_PCB* marker = m_frame->GetBoard()->GetMARKER( m_markerCount++ );
|
2012-05-28 20:01:51 +00:00
|
|
|
|
|
|
|
if( marker )
|
2019-07-26 23:52:17 +00:00
|
|
|
m_foundItem = marker;
|
2012-05-28 20:01:51 +00:00
|
|
|
|
2019-07-26 23:52:17 +00:00
|
|
|
if( m_foundItem )
|
2012-05-28 20:01:51 +00:00
|
|
|
{
|
2019-07-26 23:52:17 +00:00
|
|
|
m_frame->GetToolManager()->RunAction( PCB_ACTIONS::selectItem, true, m_foundItem );
|
|
|
|
m_frame->FocusOnLocation( m_foundItem->GetPosition() );
|
2012-05-28 20:01:51 +00:00
|
|
|
msg = _( "Marker found" );
|
2019-07-26 23:52:17 +00:00
|
|
|
m_frame->SetStatusText( msg );
|
2012-05-28 20:01:51 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-07-26 23:52:17 +00:00
|
|
|
m_frame->SetStatusText( wxEmptyString );
|
2012-05-28 20:01:51 +00:00
|
|
|
msg = _( "No marker found" );
|
|
|
|
DisplayError( this, msg, 10 );
|
2019-07-26 23:52:17 +00:00
|
|
|
m_markerCount = 0;
|
2012-05-28 20:01:51 +00:00
|
|
|
}
|
2014-10-13 13:23:30 +00:00
|
|
|
|
2019-07-26 23:52:17 +00:00
|
|
|
if( m_highlightCallback )
|
|
|
|
m_highlightCallback( m_foundItem );
|
2012-05-28 20:01:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_FIND::onClose( wxCloseEvent& aEvent )
|
|
|
|
{
|
2019-07-26 23:52:17 +00:00
|
|
|
int flags = 0;
|
|
|
|
|
|
|
|
if( m_matchCase->GetValue() )
|
|
|
|
flags |= wxFR_MATCHCASE;
|
|
|
|
|
|
|
|
if( m_matchWords->GetValue() )
|
|
|
|
flags |= wxFR_WHOLEWORD;
|
|
|
|
|
|
|
|
if( m_wildcards->GetValue() )
|
|
|
|
flags |= FR_MATCH_WILDCARD;
|
|
|
|
|
|
|
|
m_frame->GetFindReplaceData().SetFlags( flags );
|
2012-05-28 20:01:51 +00:00
|
|
|
|
|
|
|
EndModal( 1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|