kicad/pcbnew/find.cpp

387 lines
11 KiB
C++
Raw Normal View History

/***************************************************/
/* PCBNEW - Gestion des Recherches (fonction Find) */
/***************************************************/
2007-05-06 16:03:28 +00:00
/* Fichier find.cpp */
2007-05-06 16:03:28 +00:00
/*
* Affichage et modifications des parametres de travail de PcbNew
* Parametres = dimensions des via, pistes, isolements, options...
*/
2007-05-06 16:03:28 +00:00
#include "fctsys.h"
#include "gr_basic.h"
#include "common.h"
#include "pcbnew.h"
#include "id.h"
#include "protos.h"
#include "find.h"
/* Fonctions locales */
/* variables locales */
static wxString s_OldStringFound;
static int s_ItemCount, s_MarkerCount;
2007-05-06 16:03:28 +00:00
/*********************************************************************/
void WinEDA_PcbFrame::InstallFindFrame( const wxPoint& pos, wxDC* DC )
2007-05-06 16:03:28 +00:00
/*********************************************************************/
{
WinEDA_PcbFindFrame* frame = new WinEDA_PcbFindFrame( this, DC, pos );
2007-08-10 19:14:51 +00:00
frame->ShowModal();
frame->Destroy();
2007-05-06 16:03:28 +00:00
}
/*******************************************************/
void WinEDA_PcbFindFrame::FindItem( wxCommandEvent& event )
2007-05-06 16:03:28 +00:00
/********************************************************/
{
PCB_SCREEN* screen = m_Parent->GetScreen();
wxPoint locate_pos;
wxString msg;
bool succes = FALSE;
bool FindMarker = FALSE;
MODULE* Module;
int StartCount;
switch( event.GetId() )
2007-06-20 00:33:23 +00:00
{
case ID_FIND_ITEM:
s_ItemCount = 0;
break;
case ID_FIND_MARKER:
s_MarkerCount = 0;
case ID_FIND_NEXT_MARKER:
FindMarker = TRUE;
break;
2007-06-20 00:33:23 +00:00
}
s_OldStringFound = m_NewText->GetValue();
m_Parent->DrawPanel->GetViewStart( &screen->m_StartVisu.x, &screen->m_StartVisu.y );
2007-06-20 00:33:23 +00:00
StartCount = 0;
2007-06-20 00:33:23 +00:00
if( FindMarker )
{
MARQUEUR* Marker = (MARQUEUR*) m_Parent->m_Pcb->m_Drawings;
for( ; Marker != NULL; Marker = (MARQUEUR*) Marker->Pnext )
2007-06-20 00:33:23 +00:00
{
2007-09-01 12:00:30 +00:00
if( Marker->Type() != TYPEMARQUEUR )
continue;
2007-06-20 00:33:23 +00:00
StartCount++;
if( StartCount > s_MarkerCount )
2007-06-20 00:33:23 +00:00
{
succes = TRUE;
2007-06-20 00:33:23 +00:00
locate_pos = Marker->m_Pos;
s_MarkerCount++;
break;
}
}
}
else
2007-06-20 00:33:23 +00:00
{
for( Module = m_Parent->m_Pcb->m_Modules; Module != NULL; Module = (MODULE*) Module->Pnext )
2007-06-20 00:33:23 +00:00
{
if( WildCompareString( s_OldStringFound, Module->m_Reference->m_Text.GetData(),
FALSE ) )
2007-06-20 00:33:23 +00:00
{
StartCount++;
if( StartCount > s_ItemCount )
{
succes = TRUE;
locate_pos = Module->m_Pos;
s_ItemCount++;
break;
}
2007-06-20 00:33:23 +00:00
}
if( WildCompareString( s_OldStringFound, Module->m_Value->m_Text.GetData(), FALSE ) )
2007-06-20 00:33:23 +00:00
{
StartCount++;
if( StartCount > s_ItemCount )
{
succes = TRUE;
locate_pos = Module->m_Pos;
s_ItemCount++;
break;
}
2007-06-20 00:33:23 +00:00
}
}
}
if( succes )
{
/* Il y a peut-etre necessite de recadrer le dessin: */
if( !m_Parent->DrawPanel->IsPointOnDisplay( locate_pos ) )
2007-06-20 00:33:23 +00:00
{
screen->m_Curseur = locate_pos;
m_Parent->Recadre_Trace( TRUE );
2007-06-20 00:33:23 +00:00
}
else
{
// Positionnement du curseur sur l'item
m_Parent->DrawPanel->CursorOff( m_DC );
2007-06-20 00:33:23 +00:00
screen->m_Curseur = locate_pos;
GRMouseWarp( m_Parent->DrawPanel, screen->m_Curseur );
2007-06-20 00:33:23 +00:00
m_Parent->DrawPanel->MouseToCursorSchema();
m_Parent->DrawPanel->CursorOn( m_DC );
2007-06-20 00:33:23 +00:00
}
if( FindMarker )
msg = _( "Marker found" );
else
msg.Printf( _( "<%s> Found" ), s_OldStringFound.GetData() );
m_Parent->Affiche_Message( msg );
EndModal( 1 );
2007-06-20 00:33:23 +00:00
}
else
{
m_Parent->Affiche_Message( wxEmptyString );
if( FindMarker )
msg = _( "Marker not found" );
else
msg.Printf( _( "<%s> Not Found" ), s_OldStringFound.GetData() );
DisplayError( this, msg, 10 );
EndModal( 0 );
2007-06-20 00:33:23 +00:00
}
2007-05-06 16:03:28 +00:00
}
/*!
* WinEDA_PcbFindFrame type definition
*/
IMPLEMENT_DYNAMIC_CLASS( WinEDA_PcbFindFrame, wxDialog )
/*!
* WinEDA_PcbFindFrame event table definition
*/
BEGIN_EVENT_TABLE( WinEDA_PcbFindFrame, wxDialog )
////@begin WinEDA_PcbFindFrame event table entries
EVT_BUTTON( ID_FIND_ITEM, WinEDA_PcbFindFrame::OnFindItemClick )
2007-05-06 16:03:28 +00:00
EVT_BUTTON( ID_FIND_NEXT_ITEM, WinEDA_PcbFindFrame::OnFindNextItemClick )
2007-05-06 16:03:28 +00:00
EVT_BUTTON( ID_FIND_MARKER, WinEDA_PcbFindFrame::OnFindMarkerClick )
2007-05-06 16:03:28 +00:00
EVT_BUTTON( ID_FIND_NEXT_MARKER, WinEDA_PcbFindFrame::OnFindNextMarkerClick )
2007-05-06 16:03:28 +00:00
////@end WinEDA_PcbFindFrame event table entries
END_EVENT_TABLE()
/*!
* WinEDA_PcbFindFrame constructors
*/
WinEDA_PcbFindFrame::WinEDA_PcbFindFrame()
2007-05-06 16:03:28 +00:00
{
}
WinEDA_PcbFindFrame::WinEDA_PcbFindFrame( WinEDA_BasePcbFrame* parent,
wxDC* DC,
const wxPoint& pos,
wxWindowID id,
const wxString& caption,
const wxSize& size,
long style )
2007-05-06 16:03:28 +00:00
{
2007-06-20 00:33:23 +00:00
m_Parent = parent;
m_DC = DC;
2007-05-06 16:03:28 +00:00
Create( parent, id, caption, pos, size, style );
2007-05-06 16:03:28 +00:00
2007-06-20 00:33:23 +00:00
m_NewText->SetFocus();
2007-05-06 16:03:28 +00:00
}
2007-05-06 16:03:28 +00:00
/*!
* WinEDA_PcbFindFrame creator
*/
bool WinEDA_PcbFindFrame::Create( wxWindow* parent,
wxWindowID id,
const wxString& caption,
const wxPoint& pos,
const wxSize& size,
long style )
2007-05-06 16:03:28 +00:00
{
////@begin WinEDA_PcbFindFrame member initialisation
m_NewText = NULL;
2007-05-06 16:03:28 +00:00
////@end WinEDA_PcbFindFrame member initialisation
////@begin WinEDA_PcbFindFrame creation
SetExtraStyle( GetExtraStyle() | wxWS_EX_BLOCK_EVENTS );
2007-05-06 16:03:28 +00:00
wxDialog::Create( parent, id, caption, pos, size, style );
CreateControls();
GetSizer()->Fit( this );
GetSizer()->SetSizeHints( this );
2007-05-06 16:03:28 +00:00
Centre();
2007-05-06 16:03:28 +00:00
////@end WinEDA_PcbFindFrame creation
return true;
}
2007-05-06 16:03:28 +00:00
/*!
* Control creation for WinEDA_PcbFindFrame
*/
void WinEDA_PcbFindFrame::CreateControls()
{
SetFont( *g_DialogFont );
2007-05-06 16:03:28 +00:00
////@begin WinEDA_PcbFindFrame content construction
// Generated by DialogBlocks, 04/03/2006 14:04:20 (unregistered)
WinEDA_PcbFindFrame* itemDialog1 = this;
wxBoxSizer* itemBoxSizer2 = new wxBoxSizer( wxVERTICAL );
itemDialog1->SetSizer( itemBoxSizer2 );
wxStaticText* itemStaticText3 = new wxStaticText( itemDialog1, wxID_STATIC,
_(
"Item to find:" ),
wxDefaultPosition, wxDefaultSize, 0 );
itemBoxSizer2->Add( itemStaticText3,
0,
wxGROW | wxLEFT | wxRIGHT | wxTOP | wxADJUST_MINSIZE,
5 );
m_NewText = new wxTextCtrl( itemDialog1, ID_TEXTCTRL, _T(
"" ), wxDefaultPosition, wxDefaultSize, 0 );
itemBoxSizer2->Add( m_NewText, 0, wxGROW | wxLEFT | wxRIGHT | wxBOTTOM, 5 );
wxBoxSizer* itemBoxSizer5 = new wxBoxSizer( wxHORIZONTAL );
itemBoxSizer2->Add( itemBoxSizer5,
0,
wxALIGN_CENTER_HORIZONTAL | wxLEFT | wxRIGHT | wxBOTTOM,
5 );
wxBoxSizer* itemBoxSizer6 = new wxBoxSizer( wxVERTICAL );
itemBoxSizer5->Add( itemBoxSizer6, 0, wxALIGN_CENTER_VERTICAL | wxLEFT | wxRIGHT, 5 );
wxButton* itemButton7 = new wxButton( itemDialog1, ID_FIND_ITEM, _(
"Find Item" ), wxDefaultPosition, wxDefaultSize, 0 );
2007-05-06 16:03:28 +00:00
itemButton7->SetDefault();
itemButton7->SetForegroundColour( wxColour( 102, 0, 0 ) );
itemBoxSizer6->Add( itemButton7, 0, wxGROW | wxLEFT | wxRIGHT | wxTOP, 5 );
wxButton* itemButton8 = new wxButton( itemDialog1, ID_FIND_NEXT_ITEM, _(
"Find Next Item" ), wxDefaultPosition, wxDefaultSize,
0 );
itemButton8->SetForegroundColour( wxColour( 111, 0, 0 ) );
itemBoxSizer6->Add( itemButton8, 0, wxGROW | wxLEFT | wxRIGHT | wxBOTTOM, 5 );
wxBoxSizer* itemBoxSizer9 = new wxBoxSizer( wxVERTICAL );
itemBoxSizer5->Add( itemBoxSizer9, 0, wxALIGN_CENTER_VERTICAL | wxLEFT | wxRIGHT, 5 );
wxButton* itemButton10 = new wxButton( itemDialog1, ID_FIND_MARKER, _(
"Find Marker" ), wxDefaultPosition, wxDefaultSize,
0 );
itemButton10->SetForegroundColour( wxColour( 0, 0, 255 ) );
itemBoxSizer9->Add( itemButton10, 0, wxGROW | wxLEFT | wxRIGHT | wxTOP, 5 );
wxButton* itemButton11 = new wxButton( itemDialog1, ID_FIND_NEXT_MARKER, _(
"Find Next Marker" ), wxDefaultPosition,
wxDefaultSize, 0 );
itemButton11->SetForegroundColour( wxColour( 0, 0, 255 ) );
itemBoxSizer9->Add( itemButton11, 0, wxGROW | wxLEFT | wxRIGHT | wxBOTTOM, 5 );
2007-05-06 16:03:28 +00:00
////@end WinEDA_PcbFindFrame content construction
}
2007-05-06 16:03:28 +00:00
/*!
* Should we show tooltips?
*/
bool WinEDA_PcbFindFrame::ShowToolTips()
{
return true;
}
2007-05-06 16:03:28 +00:00
/*!
* Get bitmap resources
*/
wxBitmap WinEDA_PcbFindFrame::GetBitmapResource( const wxString& name )
{
// Bitmap retrieval
////@begin WinEDA_PcbFindFrame bitmap retrieval
wxUnusedVar( name );
2007-05-06 16:03:28 +00:00
return wxNullBitmap;
2007-05-06 16:03:28 +00:00
////@end WinEDA_PcbFindFrame bitmap retrieval
}
2007-05-06 16:03:28 +00:00
/*!
* Get icon resources
*/
wxIcon WinEDA_PcbFindFrame::GetIconResource( const wxString& name )
{
// Icon retrieval
////@begin WinEDA_PcbFindFrame icon retrieval
wxUnusedVar( name );
2007-05-06 16:03:28 +00:00
return wxNullIcon;
2007-05-06 16:03:28 +00:00
////@end WinEDA_PcbFindFrame icon retrieval
}
2007-05-06 16:03:28 +00:00
/*!
* wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_FIND_ITEM
*/
void WinEDA_PcbFindFrame::OnFindItemClick( wxCommandEvent& event )
{
FindItem( event );
2007-05-06 16:03:28 +00:00
}
2007-05-06 16:03:28 +00:00
/*!
* wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_FIND_NEXT_ITEM
*/
void WinEDA_PcbFindFrame::OnFindNextItemClick( wxCommandEvent& event )
{
FindItem( event );
2007-05-06 16:03:28 +00:00
}
2007-05-06 16:03:28 +00:00
/*!
* wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_FIND_MARKER
*/
void WinEDA_PcbFindFrame::OnFindMarkerClick( wxCommandEvent& event )
{
FindItem( event );
2007-05-06 16:03:28 +00:00
}
2007-05-06 16:03:28 +00:00
/*!
* wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_FIND_NEXT_MARKER
*/
void WinEDA_PcbFindFrame::OnFindNextMarkerClick( wxCommandEvent& event )
{
FindItem( event );
2007-05-06 16:03:28 +00:00
}