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 <gr_basic.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>
|
|
|
|
#include <pcbnew.h>
|
|
|
|
#include <pcbnew_id.h>
|
2014-10-13 13:23:30 +00:00
|
|
|
#include <dialog_find.h>
|
2012-05-28 20:01:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
// Initialize static member variables
|
|
|
|
wxString DIALOG_FIND::prevSearchString;
|
|
|
|
bool DIALOG_FIND::warpMouse = true;
|
|
|
|
|
|
|
|
|
|
|
|
DIALOG_FIND::DIALOG_FIND( PCB_BASE_FRAME* aParent ) : DIALOG_FIND_BASE( aParent )
|
|
|
|
{
|
|
|
|
parent = aParent;
|
2014-10-13 13:23:30 +00:00
|
|
|
foundItem = NULL;
|
2012-05-28 20:01:51 +00:00
|
|
|
GetSizer()->SetSizeHints( this );
|
|
|
|
|
|
|
|
m_SearchTextCtrl->AppendText( prevSearchString );
|
|
|
|
m_NoMouseWarpCheckBox->SetValue( !warpMouse );
|
|
|
|
|
|
|
|
itemCount = markerCount = 0;
|
|
|
|
|
2012-05-29 20:43:17 +00:00
|
|
|
Center();
|
2012-05-28 20:01:51 +00:00
|
|
|
}
|
|
|
|
|
2018-09-19 16:30:04 +00:00
|
|
|
|
2017-01-22 21:51:37 +00:00
|
|
|
void DIALOG_FIND::OnInitDialog( wxInitDialogEvent& event )
|
|
|
|
{
|
|
|
|
m_SearchTextCtrl->SetFocus();
|
|
|
|
m_SearchTextCtrl->SetSelection( -1, -1 );
|
|
|
|
}
|
|
|
|
|
2018-09-19 16:30:04 +00:00
|
|
|
|
2014-10-13 13:23:30 +00:00
|
|
|
void DIALOG_FIND::EnableWarp( bool aEnabled )
|
|
|
|
{
|
|
|
|
m_NoMouseWarpCheckBox->SetValue( !aEnabled );
|
|
|
|
warpMouse = aEnabled;
|
|
|
|
}
|
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 )
|
|
|
|
{
|
2015-09-03 07:44:30 +00:00
|
|
|
PCB_SCREEN* screen = parent->GetScreen();
|
2012-05-28 20:01:51 +00:00
|
|
|
wxPoint pos;
|
|
|
|
|
2019-05-29 19:04:45 +00:00
|
|
|
|
|
|
|
parent->GetToolManager()->RunAction( PCB_ACTIONS::selectionClear, true );
|
2012-05-28 20:01:51 +00:00
|
|
|
wxString searchString = m_SearchTextCtrl->GetValue();
|
|
|
|
|
|
|
|
if( !searchString.IsSameAs( prevSearchString, false ) )
|
|
|
|
{
|
|
|
|
itemCount = 0;
|
2018-09-19 16:30:04 +00:00
|
|
|
foundItem = NULL;
|
2012-05-28 20:01:51 +00:00
|
|
|
}
|
2018-09-19 16:30:04 +00:00
|
|
|
|
2012-05-28 20:01:51 +00:00
|
|
|
prevSearchString = searchString;
|
|
|
|
|
2019-06-13 17:28:55 +00:00
|
|
|
parent->GetCanvas()->GetViewStart( &screen->m_StartVisu.x, &screen->m_StartVisu.y );
|
2012-05-28 20:01:51 +00:00
|
|
|
|
|
|
|
int count = 0;
|
|
|
|
|
2019-05-31 00:15:57 +00:00
|
|
|
for( auto module : parent->GetBoard()->Modules() )
|
2012-05-28 20:01:51 +00:00
|
|
|
{
|
|
|
|
if( WildCompareString( searchString, module->GetReference().GetData(), false ) )
|
|
|
|
{
|
|
|
|
count++;
|
|
|
|
|
|
|
|
if( count > itemCount )
|
|
|
|
{
|
|
|
|
foundItem = module;
|
|
|
|
pos = module->GetPosition();
|
|
|
|
itemCount++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-13 18:53:58 +00:00
|
|
|
if( WildCompareString( searchString, module->GetValue().GetData(), false ) )
|
2012-05-28 20:01:51 +00:00
|
|
|
{
|
|
|
|
count++;
|
|
|
|
|
|
|
|
if( count > itemCount )
|
|
|
|
{
|
|
|
|
foundItem = module;
|
2013-03-13 18:53:58 +00:00
|
|
|
pos = module->GetPosition();
|
2012-05-28 20:01:51 +00:00
|
|
|
itemCount++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
wxString msg;
|
2013-03-13 18:53:58 +00:00
|
|
|
|
2012-05-28 20:01:51 +00:00
|
|
|
if( foundItem )
|
|
|
|
{
|
2019-05-29 19:04:45 +00:00
|
|
|
parent->GetToolManager()->RunAction( PCB_ACTIONS::selectItem, true, foundItem );
|
2019-06-13 17:28:55 +00:00
|
|
|
parent->FocusOnLocation( pos, true );
|
2017-12-15 11:37:46 +00:00
|
|
|
msg.Printf( _( "\"%s\" found" ), GetChars( searchString ) );
|
2012-05-28 20:01:51 +00:00
|
|
|
parent->SetStatusText( msg );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
parent->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 );
|
|
|
|
itemCount = 0;
|
|
|
|
}
|
2014-10-13 13:23:30 +00:00
|
|
|
|
|
|
|
if( callback )
|
|
|
|
callback( foundItem );
|
2012-05-28 20:01:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_FIND::onButtonFindMarkerClick( wxCommandEvent& aEvent )
|
|
|
|
{
|
2015-09-03 07:44:30 +00:00
|
|
|
PCB_SCREEN* screen = parent->GetScreen();
|
2012-05-28 20:01:51 +00:00
|
|
|
wxPoint pos;
|
2014-10-13 13:23:30 +00:00
|
|
|
foundItem = NULL;
|
2012-05-28 20:01:51 +00:00
|
|
|
|
2019-05-29 19:04:45 +00:00
|
|
|
parent->GetToolManager()->RunAction( PCB_ACTIONS::selectionClear, true );
|
2019-06-13 17:28:55 +00:00
|
|
|
parent->GetCanvas()->GetViewStart( &screen->m_StartVisu.x, &screen->m_StartVisu.y );
|
2012-05-28 20:01:51 +00:00
|
|
|
|
|
|
|
MARKER_PCB* marker = parent->GetBoard()->GetMARKER( markerCount++ );
|
|
|
|
|
|
|
|
if( marker )
|
|
|
|
{
|
|
|
|
foundItem = marker;
|
|
|
|
pos = marker->GetPosition();
|
|
|
|
}
|
|
|
|
|
|
|
|
wxString msg;
|
|
|
|
if( foundItem )
|
|
|
|
{
|
2019-05-29 19:04:45 +00:00
|
|
|
parent->GetToolManager()->RunAction( PCB_ACTIONS::selectItem, true, foundItem );
|
2019-06-13 17:28:55 +00:00
|
|
|
parent->FocusOnLocation( pos );
|
2012-05-28 20:01:51 +00:00
|
|
|
msg = _( "Marker found" );
|
|
|
|
parent->SetStatusText( msg );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
parent->SetStatusText( wxEmptyString );
|
|
|
|
msg = _( "No marker found" );
|
|
|
|
DisplayError( this, msg, 10 );
|
|
|
|
markerCount = 0;
|
|
|
|
}
|
2014-10-13 13:23:30 +00:00
|
|
|
|
|
|
|
if( callback )
|
|
|
|
callback( foundItem );
|
2012-05-28 20:01:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_FIND::onClose( wxCloseEvent& aEvent )
|
|
|
|
{
|
|
|
|
warpMouse = !m_NoMouseWarpCheckBox->IsChecked();
|
|
|
|
|
|
|
|
EndModal( 1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|