2007-08-14 19:24:48 +00:00
|
|
|
/****************************************************************/
|
2009-12-02 21:44:03 +00:00
|
|
|
/* EESchema: find.cpp (functions for searching a schematic item */
|
2007-08-14 19:24:48 +00:00
|
|
|
/****************************************************************/
|
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
/*
|
2007-08-20 10:55:09 +00:00
|
|
|
* Search a text (text, value, reference) within a component or
|
|
|
|
* search a component in libraries, a marker ...,
|
2007-08-14 19:24:48 +00:00
|
|
|
* in current sheet or whole the project
|
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
#include "fctsys.h"
|
2009-04-14 16:45:22 +00:00
|
|
|
#include "appl_wxstruct.h"
|
2007-06-05 12:10:51 +00:00
|
|
|
#include "common.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
#include "class_drawpanel.h"
|
|
|
|
#include "confirm.h"
|
|
|
|
#include "kicad_string.h"
|
|
|
|
#include "gestfich.h"
|
2009-09-18 14:56:05 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
#include "program.h"
|
|
|
|
#include "general.h"
|
2009-07-07 17:50:02 +00:00
|
|
|
#include "class_marker_sch.h"
|
2009-09-18 14:56:05 +00:00
|
|
|
#include "protos.h"
|
2009-09-25 18:49:04 +00:00
|
|
|
#include "class_library.h"
|
2010-03-04 09:32:51 +00:00
|
|
|
#include "class_pin.h"
|
2009-09-18 14:56:05 +00:00
|
|
|
|
2009-12-20 19:48:58 +00:00
|
|
|
#include "kicad_device_context.h"
|
|
|
|
|
2009-09-18 14:56:05 +00:00
|
|
|
#include <boost/foreach.hpp>
|
|
|
|
|
2010-03-16 18:22:59 +00:00
|
|
|
#include "dialog_schematic_find.h"
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2010-02-10 16:25:13 +00:00
|
|
|
|
2010-03-16 18:22:59 +00:00
|
|
|
void WinEDA_SchematicFrame::OnFindDrcMarker( wxFindDialogEvent& event )
|
|
|
|
{
|
|
|
|
static SCH_MARKER* lastMarker = NULL;
|
2010-02-10 16:25:13 +00:00
|
|
|
|
2010-03-16 18:22:59 +00:00
|
|
|
wxString msg;
|
|
|
|
SCH_SHEET_LIST schematic;
|
|
|
|
SCH_SHEET_PATH* sheetFoundIn = NULL;
|
|
|
|
bool wrap = ( event.GetFlags() & FR_SEARCH_WRAP ) != 0;
|
|
|
|
wxRect clientRect( wxPoint( 0, 0 ), GetClientSize() );
|
2010-02-10 16:25:13 +00:00
|
|
|
|
2010-03-16 18:22:59 +00:00
|
|
|
if( event.GetFlags() & FR_CURRENT_SHEET_ONLY )
|
|
|
|
{
|
|
|
|
sheetFoundIn = m_CurrentSheet;
|
|
|
|
lastMarker = (SCH_MARKER*) m_CurrentSheet->FindNextItem( TYPE_SCH_MARKER,
|
|
|
|
lastMarker, wrap );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
lastMarker = (SCH_MARKER*) schematic.FindNextItem( TYPE_SCH_MARKER, &sheetFoundIn,
|
|
|
|
lastMarker, wrap );
|
|
|
|
}
|
2010-02-10 16:25:13 +00:00
|
|
|
|
2010-03-16 18:22:59 +00:00
|
|
|
if( lastMarker != NULL )
|
|
|
|
{
|
|
|
|
if( sheetFoundIn != GetSheet() )
|
|
|
|
{
|
|
|
|
sheetFoundIn->LastScreen()->SetZoom( GetScreen()->GetZoom() );
|
|
|
|
*m_CurrentSheet = *sheetFoundIn;
|
|
|
|
ActiveScreen = m_CurrentSheet->LastScreen();
|
|
|
|
m_CurrentSheet->UpdateAllScreenReferences();
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2010-03-16 18:22:59 +00:00
|
|
|
sheetFoundIn->LastScreen()->m_Curseur = lastMarker->m_Pos;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2010-03-16 18:22:59 +00:00
|
|
|
Recadre_Trace( TRUE );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2010-03-16 18:22:59 +00:00
|
|
|
wxString path = sheetFoundIn->Path();
|
|
|
|
wxString units = GetAbbreviatedUnitsLabel();
|
2010-07-12 14:07:09 +00:00
|
|
|
double x = To_User_Unit( g_UserUnit, (double) lastMarker->m_Pos.x, m_InternalUnits );
|
|
|
|
double y = To_User_Unit( g_UserUnit, (double) lastMarker->m_Pos.y, m_InternalUnits );
|
2010-03-16 18:22:59 +00:00
|
|
|
msg.Printf( _( "Design rule check marker found in sheet %s at %0.3f%s, %0.3f%s" ),
|
|
|
|
GetChars( path ), x, GetChars( units ), y, GetChars( units) );
|
|
|
|
SetStatusText( msg );
|
|
|
|
}
|
2007-08-14 19:24:48 +00:00
|
|
|
else
|
2010-03-16 18:22:59 +00:00
|
|
|
{
|
|
|
|
SetStatusText( _( "No more markers were found." ) );
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
2007-08-14 19:24:48 +00:00
|
|
|
|
|
|
|
|
2007-10-01 15:37:42 +00:00
|
|
|
/**
|
|
|
|
* Function FindComponentAndItem
|
|
|
|
* finds a Component in the schematic, and an item in this component.
|
2007-10-31 17:47:44 +00:00
|
|
|
* @param component_reference The component reference to find.
|
2009-12-02 21:44:03 +00:00
|
|
|
* @param text_to_find - The text to search for, either in value, reference
|
|
|
|
* or elsewhere.
|
2007-10-01 15:37:42 +00:00
|
|
|
* @param Find_in_hierarchy: false => Search is made in current sheet
|
|
|
|
* true => the whole hierarchy
|
|
|
|
* @param SearchType: 0 => find component
|
|
|
|
* 1 => find pin
|
|
|
|
* 2 => find ref
|
|
|
|
* 3 => find value
|
|
|
|
* >= 4 => unused (same as 0)
|
|
|
|
* @param mouseWarp If true, then move the mouse cursor to the item.
|
|
|
|
*/
|
2010-03-16 18:22:59 +00:00
|
|
|
SCH_ITEM* WinEDA_SchematicFrame::FindComponentAndItem( const wxString& component_reference,
|
|
|
|
bool Find_in_hierarchy,
|
|
|
|
int SearchType,
|
|
|
|
const wxString& text_to_find,
|
|
|
|
bool mouseWarp )
|
2007-10-01 15:37:42 +00:00
|
|
|
{
|
2009-12-02 21:44:03 +00:00
|
|
|
SCH_SHEET_PATH* sheet, * SheetWithComponentFound = NULL;
|
|
|
|
SCH_ITEM* DrawList = NULL;
|
|
|
|
SCH_COMPONENT* Component = NULL;
|
|
|
|
wxSize DrawAreaSize = DrawPanel->GetClientSize();
|
|
|
|
wxPoint pos, curpos;
|
|
|
|
bool DoCenterAndRedraw = FALSE;
|
|
|
|
bool NotFound = true;
|
|
|
|
wxString msg;
|
|
|
|
LIB_PIN* pin;
|
|
|
|
SCH_SHEET_LIST SheetList;
|
2007-10-01 15:37:42 +00:00
|
|
|
|
2008-02-12 21:12:46 +00:00
|
|
|
sheet = SheetList.GetFirst();
|
2007-10-01 15:37:42 +00:00
|
|
|
if( !Find_in_hierarchy )
|
2008-02-19 07:06:58 +00:00
|
|
|
sheet = m_CurrentSheet;
|
2007-10-01 15:37:42 +00:00
|
|
|
|
2008-02-12 21:12:46 +00:00
|
|
|
for( ; sheet != NULL; sheet = SheetList.GetNext() )
|
2007-10-01 15:37:42 +00:00
|
|
|
{
|
2008-04-14 19:22:48 +00:00
|
|
|
DrawList = (SCH_ITEM*) sheet->LastDrawList();
|
2009-12-02 21:44:03 +00:00
|
|
|
for( ; ( DrawList != NULL ) && ( NotFound == true );
|
|
|
|
DrawList = DrawList->Next() )
|
2007-10-01 15:37:42 +00:00
|
|
|
{
|
2008-03-20 01:50:21 +00:00
|
|
|
if( DrawList->Type() == TYPE_SCH_COMPONENT )
|
2007-10-01 15:37:42 +00:00
|
|
|
{
|
2008-03-20 01:50:21 +00:00
|
|
|
SCH_COMPONENT* pSch;
|
|
|
|
pSch = (SCH_COMPONENT*) DrawList;
|
2009-04-14 16:45:22 +00:00
|
|
|
if( component_reference.CmpNoCase( pSch->GetRef( sheet ) ) == 0 )
|
2007-10-01 15:37:42 +00:00
|
|
|
{
|
|
|
|
Component = pSch;
|
2008-02-12 21:12:46 +00:00
|
|
|
SheetWithComponentFound = sheet;
|
2007-10-01 15:37:42 +00:00
|
|
|
|
|
|
|
switch( SearchType )
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
case 0: // Find component only
|
|
|
|
NotFound = FALSE;
|
|
|
|
pos = pSch->m_Pos;
|
2008-02-19 07:06:58 +00:00
|
|
|
break;
|
2007-10-01 15:37:42 +00:00
|
|
|
|
|
|
|
case 1: // find a pin
|
2009-12-02 21:44:03 +00:00
|
|
|
pos = pSch->m_Pos; /* temporary: will be changed if
|
|
|
|
* the pin is found */
|
2009-10-30 19:26:25 +00:00
|
|
|
pin = pSch->GetPin( text_to_find );
|
2007-10-01 15:37:42 +00:00
|
|
|
if( pin == NULL )
|
|
|
|
break;
|
|
|
|
NotFound = FALSE;
|
|
|
|
pos += pin->m_Pos;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2: // find reference
|
|
|
|
NotFound = FALSE;
|
2008-10-06 05:44:29 +00:00
|
|
|
pos = pSch->GetField( REFERENCE )->m_Pos;
|
2007-10-01 15:37:42 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 3: // find value
|
|
|
|
pos = pSch->m_Pos;
|
2008-10-06 05:44:29 +00:00
|
|
|
if( text_to_find.CmpNoCase( pSch->GetField( VALUE )->m_Text ) != 0 )
|
2007-10-01 15:37:42 +00:00
|
|
|
break;
|
|
|
|
NotFound = FALSE;
|
2008-10-06 05:44:29 +00:00
|
|
|
pos = pSch->GetField( VALUE )->m_Pos;
|
2007-10-01 15:37:42 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( (Find_in_hierarchy == FALSE) || (NotFound == FALSE) )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( Component )
|
|
|
|
{
|
2008-02-12 21:12:46 +00:00
|
|
|
sheet = SheetWithComponentFound;
|
|
|
|
if( sheet != GetSheet() )
|
2007-10-01 15:37:42 +00:00
|
|
|
{
|
2008-02-12 21:12:46 +00:00
|
|
|
sheet->LastScreen()->SetZoom( GetScreen()->GetZoom() );
|
|
|
|
*m_CurrentSheet = *sheet;
|
2009-04-14 16:45:22 +00:00
|
|
|
ActiveScreen = m_CurrentSheet->LastScreen();
|
2008-02-19 07:06:58 +00:00
|
|
|
m_CurrentSheet->UpdateAllScreenReferences();
|
2009-04-14 16:45:22 +00:00
|
|
|
DoCenterAndRedraw = TRUE;
|
2007-10-01 15:37:42 +00:00
|
|
|
}
|
|
|
|
wxPoint delta;
|
2009-04-14 16:45:22 +00:00
|
|
|
pos -= Component->m_Pos;
|
|
|
|
delta = TransformCoordinate( Component->m_Transform, pos );
|
|
|
|
pos = delta + Component->m_Pos;
|
2007-10-01 15:37:42 +00:00
|
|
|
|
2009-04-14 16:45:22 +00:00
|
|
|
wxPoint old_cursor_position = sheet->LastScreen()->m_Curseur;
|
2008-02-12 21:12:46 +00:00
|
|
|
sheet->LastScreen()->m_Curseur = pos;
|
2007-10-01 15:37:42 +00:00
|
|
|
|
|
|
|
curpos = DrawPanel->CursorScreenPosition();
|
|
|
|
|
|
|
|
DrawPanel->GetViewStart(
|
2008-02-12 21:12:46 +00:00
|
|
|
&( GetScreen()->m_StartVisu.x ),
|
2009-04-14 16:45:22 +00:00
|
|
|
&( GetScreen()->m_StartVisu.y ) );
|
2007-10-01 15:37:42 +00:00
|
|
|
|
2009-10-30 19:26:25 +00:00
|
|
|
// Calculating cursor position with original screen.
|
2009-01-02 13:19:34 +00:00
|
|
|
curpos -= GetScreen()->m_StartVisu;
|
2007-10-01 15:37:42 +00:00
|
|
|
|
2009-10-30 19:26:25 +00:00
|
|
|
/* There may be need to reframe the drawing */
|
2008-02-19 07:06:58 +00:00
|
|
|
#define MARGIN 30
|
2009-12-02 21:44:03 +00:00
|
|
|
if( ( curpos.x <= MARGIN ) || ( curpos.x >= DrawAreaSize.x - MARGIN )
|
|
|
|
|| ( curpos.y <= MARGIN ) || ( curpos.y >= DrawAreaSize.y - MARGIN ) )
|
2007-10-01 15:37:42 +00:00
|
|
|
{
|
|
|
|
DoCenterAndRedraw = true;;
|
|
|
|
}
|
2008-02-19 07:06:58 +00:00
|
|
|
#undef MARGIN
|
2007-10-01 15:37:42 +00:00
|
|
|
|
2009-04-14 16:45:22 +00:00
|
|
|
if( DoCenterAndRedraw )
|
2007-10-01 15:37:42 +00:00
|
|
|
Recadre_Trace( mouseWarp );
|
|
|
|
else
|
|
|
|
{
|
2009-12-20 19:48:58 +00:00
|
|
|
INSTALL_DC( dc, DrawPanel );
|
2007-10-01 15:37:42 +00:00
|
|
|
|
2008-02-12 21:12:46 +00:00
|
|
|
EXCHG( old_cursor_position, sheet->LastScreen()->m_Curseur );
|
2007-10-01 15:37:42 +00:00
|
|
|
DrawPanel->CursorOff( &dc );
|
|
|
|
|
|
|
|
if( mouseWarp )
|
2009-01-17 20:31:19 +00:00
|
|
|
DrawPanel->MouseTo( curpos );
|
2007-10-01 15:37:42 +00:00
|
|
|
|
2008-02-12 21:12:46 +00:00
|
|
|
EXCHG( old_cursor_position, sheet->LastScreen()->m_Curseur );
|
2007-10-01 15:37:42 +00:00
|
|
|
|
|
|
|
DrawPanel->CursorOn( &dc );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Print diaq */
|
|
|
|
wxString msg_item;
|
|
|
|
msg = component_reference;
|
|
|
|
|
|
|
|
switch( SearchType )
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
case 0:
|
|
|
|
break; // Find component only
|
|
|
|
|
|
|
|
case 1: // find a pin
|
|
|
|
msg_item = _( "Pin " ) + text_to_find;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2: // find reference
|
|
|
|
msg_item = _( "Ref " ) + text_to_find;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 3: // find value
|
|
|
|
msg_item = _( "Value " ) + text_to_find;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 4: // find field. todo
|
|
|
|
msg_item = _( "Field " ) + text_to_find;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( Component )
|
|
|
|
{
|
|
|
|
if( !NotFound )
|
|
|
|
{
|
|
|
|
if( !msg_item.IsEmpty() )
|
|
|
|
msg += wxT( " " ) + msg_item;
|
2008-02-19 07:06:58 +00:00
|
|
|
msg += _( " found" );
|
2007-10-01 15:37:42 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-02-19 07:06:58 +00:00
|
|
|
msg += _( " found" );
|
2007-10-01 15:37:42 +00:00
|
|
|
if( !msg_item.IsEmpty() )
|
|
|
|
{
|
|
|
|
msg += wxT( " but " ) + msg_item + _( " not found" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( !msg_item.IsEmpty() )
|
|
|
|
msg += wxT( " " ) + msg_item;
|
|
|
|
msg += _( " not found" );
|
|
|
|
}
|
|
|
|
|
2010-03-16 18:22:59 +00:00
|
|
|
SetStatusText( msg );
|
2007-10-01 15:37:42 +00:00
|
|
|
|
|
|
|
return DrawList;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-14 19:24:48 +00:00
|
|
|
/**
|
2010-03-16 18:22:59 +00:00
|
|
|
* Finds an item in the schematic matching the search string.
|
|
|
|
*
|
|
|
|
* @param event - Find dialog event containing the find parameters.
|
2007-08-14 19:24:48 +00:00
|
|
|
*/
|
2010-03-16 18:22:59 +00:00
|
|
|
void WinEDA_SchematicFrame::OnFindSchematicItem( wxFindDialogEvent& event )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2010-06-11 18:34:20 +00:00
|
|
|
static SCH_ITEM* lastItem = NULL;
|
2007-08-14 19:24:48 +00:00
|
|
|
|
2010-03-16 18:22:59 +00:00
|
|
|
SCH_SHEET_LIST schematic;
|
|
|
|
wxString msg;
|
|
|
|
SCH_SHEET_PATH* sheetFoundIn = NULL;
|
|
|
|
wxFindReplaceData searchCriteria;
|
2007-08-14 19:24:48 +00:00
|
|
|
|
2010-03-16 18:22:59 +00:00
|
|
|
searchCriteria.SetFlags( event.GetFlags() );
|
|
|
|
searchCriteria.SetFindString( event.GetFindString() );
|
|
|
|
searchCriteria.SetReplaceString( event.GetReplaceString() );
|
2007-08-14 19:24:48 +00:00
|
|
|
|
2010-06-11 18:34:20 +00:00
|
|
|
if( event.GetFlags() & FR_CURRENT_SHEET_ONLY && g_RootSheet->CountSheets() > 1 )
|
2007-08-14 19:24:48 +00:00
|
|
|
{
|
2010-03-16 18:22:59 +00:00
|
|
|
sheetFoundIn = m_CurrentSheet;
|
|
|
|
lastItem = m_CurrentSheet->MatchNextItem( searchCriteria, lastItem );
|
2007-08-14 19:24:48 +00:00
|
|
|
}
|
2010-03-16 18:22:59 +00:00
|
|
|
else
|
2007-08-14 19:24:48 +00:00
|
|
|
{
|
2010-03-16 18:22:59 +00:00
|
|
|
lastItem = schematic.MatchNextItem( searchCriteria, &sheetFoundIn, lastItem );
|
2007-08-14 19:24:48 +00:00
|
|
|
}
|
|
|
|
|
2010-03-16 18:22:59 +00:00
|
|
|
if( lastItem != NULL )
|
2007-08-14 19:24:48 +00:00
|
|
|
{
|
2010-03-16 18:22:59 +00:00
|
|
|
if( sheetFoundIn != GetSheet() )
|
2007-08-14 19:24:48 +00:00
|
|
|
{
|
2010-03-16 18:22:59 +00:00
|
|
|
sheetFoundIn->LastScreen()->SetZoom( GetScreen()->GetZoom() );
|
|
|
|
*m_CurrentSheet = *sheetFoundIn;
|
2009-04-14 16:45:22 +00:00
|
|
|
ActiveScreen = m_CurrentSheet->LastScreen();
|
2008-02-19 07:06:58 +00:00
|
|
|
m_CurrentSheet->UpdateAllScreenReferences();
|
2007-08-14 19:24:48 +00:00
|
|
|
}
|
2007-10-01 15:37:42 +00:00
|
|
|
|
2010-03-16 18:22:59 +00:00
|
|
|
sheetFoundIn->LastScreen()->m_Curseur = lastItem->GetBoundingBox().Centre();
|
|
|
|
Recadre_Trace( true );
|
2007-10-01 15:37:42 +00:00
|
|
|
|
2010-03-16 18:22:59 +00:00
|
|
|
msg = event.GetFindString() + _( " found in " ) + sheetFoundIn->PathHumanReadable();
|
|
|
|
SetStatusText( msg );
|
2007-08-14 19:24:48 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-03-16 18:22:59 +00:00
|
|
|
msg.Printf( _( "No item found matching %s." ), GetChars( event.GetFindString() ) );
|
|
|
|
SetStatusText( msg );
|
2007-08-14 19:24:48 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|