2007-09-02 15:49:11 +00:00
|
|
|
/******************************************************/
|
2009-10-30 19:26:25 +00:00
|
|
|
/* Routines for locating an element of a schematic. */
|
2007-09-02 15:49:11 +00:00
|
|
|
/******************************************************/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
#include "fctsys.h"
|
|
|
|
#include "common.h"
|
|
|
|
#include "trigo.h"
|
|
|
|
#include "macros.h"
|
2010-11-10 15:30:12 +00:00
|
|
|
#include "class_sch_screen.h"
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-09-25 18:49:04 +00:00
|
|
|
#include "general.h"
|
2007-06-05 12:10:51 +00:00
|
|
|
#include "protos.h"
|
2009-09-25 18:49:04 +00:00
|
|
|
#include "class_library.h"
|
2010-11-11 21:10:27 +00:00
|
|
|
#include "sch_marker.h"
|
|
|
|
#include "sch_items.h"
|
|
|
|
#include "sch_component.h"
|
|
|
|
#include "sch_sheet.h"
|
2010-11-10 15:30:12 +00:00
|
|
|
#include "lib_pin.h"
|
|
|
|
#include "template_fieldnames.h"
|
2009-09-25 18:49:04 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2008-04-14 19:22:48 +00:00
|
|
|
static SCH_ITEM* LastSnappedStruct = NULL;
|
2009-01-02 13:19:34 +00:00
|
|
|
static bool SnapPoint2( const wxPoint& aPosRef, int SearchMask,
|
2009-07-25 04:53:39 +00:00
|
|
|
SCH_ITEM* DrawList, double aScaleFactor );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
|
2009-09-29 18:38:21 +00:00
|
|
|
/**
|
|
|
|
* Search the smaller (considering its area) component under the mouse
|
|
|
|
* cursor or the pcb cursor
|
|
|
|
*
|
|
|
|
* If more than 1 component is found, a pointer to the smaller component is
|
|
|
|
* returned
|
2007-09-02 15:49:11 +00:00
|
|
|
*/
|
2009-09-29 18:38:21 +00:00
|
|
|
SCH_COMPONENT* LocateSmallestComponent( SCH_SCREEN* Screen )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-01-31 18:08:47 +00:00
|
|
|
SCH_COMPONENT* component = NULL, * lastcomponent = NULL;
|
2008-04-14 19:22:48 +00:00
|
|
|
SCH_ITEM* DrawList;
|
|
|
|
EDA_Rect BoundaryBox;
|
|
|
|
float sizeref = 0, sizecurr;
|
2007-09-02 15:49:11 +00:00
|
|
|
|
2010-12-08 20:12:46 +00:00
|
|
|
DrawList = Screen->GetDrawItems();
|
2007-09-02 15:49:11 +00:00
|
|
|
|
|
|
|
while( DrawList )
|
|
|
|
{
|
2010-12-08 20:12:46 +00:00
|
|
|
if( !SnapPoint2( Screen->m_MousePosition, LIBITEM, DrawList, Screen->GetZoom() ) )
|
2007-09-02 15:49:11 +00:00
|
|
|
{
|
2010-12-08 20:12:46 +00:00
|
|
|
if( !SnapPoint2( Screen->m_Curseur, LIBITEM, DrawList, Screen->GetScalingFactor() ) )
|
2007-09-02 15:49:11 +00:00
|
|
|
break;
|
|
|
|
}
|
2010-12-08 20:12:46 +00:00
|
|
|
|
2009-01-31 18:08:47 +00:00
|
|
|
component = (SCH_COMPONENT*) LastSnappedStruct;
|
2009-06-11 14:26:17 +00:00
|
|
|
DrawList = component->Next();
|
2010-12-08 20:12:46 +00:00
|
|
|
|
2009-01-31 18:08:47 +00:00
|
|
|
if( lastcomponent == NULL ) // First time a component is located
|
2007-09-02 15:49:11 +00:00
|
|
|
{
|
2009-01-31 18:08:47 +00:00
|
|
|
lastcomponent = component;
|
2010-12-10 19:47:44 +00:00
|
|
|
BoundaryBox = lastcomponent->GetBoundingBox();
|
2010-12-08 20:12:46 +00:00
|
|
|
sizeref = ABS( (float) BoundaryBox.GetWidth() * BoundaryBox.GetHeight() );
|
2007-09-02 15:49:11 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-12-10 19:47:44 +00:00
|
|
|
BoundaryBox = component->GetBoundingBox();
|
2010-12-08 20:12:46 +00:00
|
|
|
sizecurr = ABS( (float) BoundaryBox.GetWidth() * BoundaryBox.GetHeight() );
|
|
|
|
|
2007-09-02 15:49:11 +00:00
|
|
|
if( sizeref > sizecurr ) // a smallest component is found
|
|
|
|
{
|
|
|
|
sizeref = sizecurr;
|
2009-01-31 18:08:47 +00:00
|
|
|
lastcomponent = component;
|
2007-09-02 15:49:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-31 18:08:47 +00:00
|
|
|
return lastcomponent;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-31 18:08:47 +00:00
|
|
|
/* Search an item at pos refpos
|
2009-06-11 14:26:17 +00:00
|
|
|
* SearchMask = (bitwise OR):
|
2007-09-02 15:49:11 +00:00
|
|
|
* LIBITEM
|
|
|
|
* WIREITEM
|
|
|
|
* BUSITEM
|
|
|
|
* RACCORDITEM
|
|
|
|
* JUNCTIONITEM
|
|
|
|
* DRAWITEM
|
|
|
|
* TEXTITEM
|
|
|
|
* LABELITEM
|
|
|
|
* SHEETITEM
|
|
|
|
* MARKERITEM
|
|
|
|
* NOCONNECTITEM
|
|
|
|
* SEARCH_PINITEM
|
|
|
|
* SHEETLABELITEM
|
|
|
|
* FIELDCMPITEM
|
2008-03-20 01:50:21 +00:00
|
|
|
*
|
2009-11-04 20:46:53 +00:00
|
|
|
* if EXCLUDE_WIRE_BUS_ENDPOINTS is set, in wire or bus search and locate,
|
2007-09-02 15:49:11 +00:00
|
|
|
* start and end points are not included in search
|
2009-11-04 20:46:53 +00:00
|
|
|
* if WIRE_BUS_ENDPOINTS_ONLY is set, in wire or bus search and locate,
|
2007-09-02 15:49:11 +00:00
|
|
|
* only start and end points are included in search
|
2008-03-20 01:50:21 +00:00
|
|
|
*
|
|
|
|
*
|
2007-09-02 15:49:11 +00:00
|
|
|
* Return:
|
2009-01-31 18:08:47 +00:00
|
|
|
* pointer on item found or NULL
|
2008-03-20 01:50:21 +00:00
|
|
|
*
|
2007-09-02 15:49:11 +00:00
|
|
|
*/
|
2010-12-08 20:12:46 +00:00
|
|
|
SCH_ITEM* PickStruct( const wxPoint& refpos, SCH_SCREEN* screen, int SearchMask )
|
2009-12-02 21:44:03 +00:00
|
|
|
{
|
2010-12-08 20:12:46 +00:00
|
|
|
if( screen == NULL || screen->GetDrawItems() == NULL )
|
2008-03-20 01:50:21 +00:00
|
|
|
return NULL;
|
2007-09-02 15:49:11 +00:00
|
|
|
|
2010-12-08 20:12:46 +00:00
|
|
|
if( SnapPoint2( refpos, SearchMask, screen->GetDrawItems(), screen->GetScalingFactor() ) )
|
2007-09-02 15:49:11 +00:00
|
|
|
{
|
|
|
|
return LastSnappedStruct;
|
|
|
|
}
|
2010-12-08 20:12:46 +00:00
|
|
|
|
2007-09-02 15:49:11 +00:00
|
|
|
return NULL;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-09-02 15:49:11 +00:00
|
|
|
|
2010-11-12 16:36:43 +00:00
|
|
|
/**
|
|
|
|
* Function PickStruct
|
2009-07-25 04:53:39 +00:00
|
|
|
* Search items in a block
|
|
|
|
* @return items count
|
|
|
|
* @param aBlock a BLOCK_SELECTOR that gives the search area boundary
|
|
|
|
* list of items is stored in aBlock
|
2007-09-02 15:49:11 +00:00
|
|
|
*/
|
2010-12-08 20:12:46 +00:00
|
|
|
int PickItemsInBlock( BLOCK_SELECTOR& aBlock, SCH_SCREEN* aScreen )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-07-25 04:53:39 +00:00
|
|
|
int itemcount = 0;
|
|
|
|
|
|
|
|
if( aScreen == NULL )
|
|
|
|
return itemcount;
|
2007-09-02 15:49:11 +00:00
|
|
|
|
2009-11-28 09:24:37 +00:00
|
|
|
EDA_Rect area;
|
|
|
|
area.SetOrigin( aBlock.GetOrigin());
|
|
|
|
area.SetSize( aBlock.GetSize() );
|
|
|
|
area.Normalize();
|
2008-03-20 01:50:21 +00:00
|
|
|
|
2009-07-25 04:53:39 +00:00
|
|
|
ITEM_PICKER picker;
|
2010-12-10 19:47:44 +00:00
|
|
|
SCH_ITEM* item = aScreen->GetDrawItems();
|
2010-12-08 20:12:46 +00:00
|
|
|
|
2010-12-10 19:47:44 +00:00
|
|
|
for( ; item != NULL; item = item->Next() )
|
2007-09-02 15:49:11 +00:00
|
|
|
{
|
2010-12-10 19:47:44 +00:00
|
|
|
if( item->HitTest( area ) )
|
2007-09-02 15:49:11 +00:00
|
|
|
{
|
|
|
|
/* Put this structure in the picked list: */
|
2010-12-10 19:47:44 +00:00
|
|
|
picker.m_PickedItem = item;
|
|
|
|
picker.m_PickedItemType = item->Type();
|
2009-11-04 20:46:53 +00:00
|
|
|
aBlock.PushItem( picker );
|
2009-07-25 04:53:39 +00:00
|
|
|
itemcount++;
|
2007-09-02 15:49:11 +00:00
|
|
|
}
|
|
|
|
}
|
2009-11-04 20:46:53 +00:00
|
|
|
|
2009-07-25 04:53:39 +00:00
|
|
|
return itemcount;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-09-02 15:49:11 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
/*****************************************************************************
|
2009-09-29 18:38:21 +00:00
|
|
|
* Routine to search all objects for the closest point to a given point, in *
|
|
|
|
* drawing space, and snap it to that points if closer than SnapDistance. *
|
|
|
|
* Note we use L1 norm as distance measure, as it is the fastest. *
|
2007-06-05 12:10:51 +00:00
|
|
|
* This routine updates LastSnappedStruct to the last object used in to snap *
|
2009-09-29 18:38:21 +00:00
|
|
|
* a point. This variable is global to this module only (see above). *
|
2009-11-28 09:24:37 +00:00
|
|
|
* The routine returns true if point was snapped. *
|
2007-06-05 12:10:51 +00:00
|
|
|
*****************************************************************************/
|
2010-12-08 20:12:46 +00:00
|
|
|
bool SnapPoint2( const wxPoint& aPosRef, int SearchMask, SCH_ITEM* DrawList, double aScaleFactor )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2008-04-14 19:22:48 +00:00
|
|
|
for( ; DrawList != NULL; DrawList = DrawList->Next() )
|
2007-09-02 15:49:11 +00:00
|
|
|
{
|
2009-11-04 20:46:53 +00:00
|
|
|
int hitminDist = MAX( g_DrawDefaultLineThickness, 3 );
|
2010-12-08 20:12:46 +00:00
|
|
|
|
2007-09-02 15:49:11 +00:00
|
|
|
switch( DrawList->Type() )
|
|
|
|
{
|
2010-12-10 19:47:44 +00:00
|
|
|
case SCH_POLYLINE_T:
|
2007-09-02 15:49:11 +00:00
|
|
|
#undef STRUCT
|
2009-12-02 21:44:03 +00:00
|
|
|
#define STRUCT ( (SCH_POLYLINE*) DrawList )
|
2007-09-02 15:49:11 +00:00
|
|
|
if( !( SearchMask & (DRAWITEM | WIREITEM | BUSITEM) ) )
|
|
|
|
break;
|
2008-03-20 01:50:21 +00:00
|
|
|
|
2009-06-11 14:26:17 +00:00
|
|
|
for( unsigned i = 0; i < STRUCT->GetCornerCount() - 1; i++ )
|
2007-09-02 15:49:11 +00:00
|
|
|
{
|
2009-06-13 17:06:07 +00:00
|
|
|
if( TestSegmentHit( aPosRef, STRUCT->m_PolyPoints[i],
|
2009-11-04 20:46:53 +00:00
|
|
|
STRUCT->m_PolyPoints[i + 1], hitminDist ) )
|
2007-09-02 15:49:11 +00:00
|
|
|
{
|
|
|
|
LastSnappedStruct = DrawList;
|
2009-11-28 09:24:37 +00:00
|
|
|
return true;
|
2007-09-02 15:49:11 +00:00
|
|
|
}
|
|
|
|
}
|
2008-04-14 19:22:48 +00:00
|
|
|
|
2007-09-02 15:49:11 +00:00
|
|
|
break;
|
|
|
|
|
2010-12-10 19:47:44 +00:00
|
|
|
case SCH_LINE_T:
|
2007-09-02 15:49:11 +00:00
|
|
|
#undef STRUCT
|
2009-12-02 21:44:03 +00:00
|
|
|
#define STRUCT ( (SCH_LINE*) DrawList )
|
2007-09-02 15:49:11 +00:00
|
|
|
if( !( SearchMask & (DRAWITEM | WIREITEM | BUSITEM) ) )
|
|
|
|
break;
|
|
|
|
|
2009-06-13 17:06:07 +00:00
|
|
|
if( TestSegmentHit( aPosRef, STRUCT->m_Start, STRUCT->m_End, 0 ) )
|
2007-09-02 15:49:11 +00:00
|
|
|
{
|
2010-12-10 19:47:44 +00:00
|
|
|
if( ( ( SearchMask & DRAWITEM ) && ( STRUCT->GetLayer() == LAYER_NOTES ) )
|
|
|
|
|| ( ( SearchMask & WIREITEM ) && ( STRUCT->GetLayer() == LAYER_WIRE ) )
|
|
|
|
|| ( ( SearchMask & BUSITEM ) && ( STRUCT->GetLayer() == LAYER_BUS ) ) )
|
2007-09-02 15:49:11 +00:00
|
|
|
{
|
2010-12-10 19:47:44 +00:00
|
|
|
if( SearchMask & EXCLUDE_WIRE_BUS_ENDPOINTS && STRUCT->IsEndPoint( aPosRef ) )
|
|
|
|
break;
|
2007-09-02 15:49:11 +00:00
|
|
|
|
2010-12-10 19:47:44 +00:00
|
|
|
if( SearchMask & WIRE_BUS_ENDPOINTS_ONLY && !STRUCT->IsEndPoint( aPosRef ) )
|
|
|
|
break;
|
2007-09-02 15:49:11 +00:00
|
|
|
|
|
|
|
LastSnappedStruct = DrawList;
|
2009-11-28 09:24:37 +00:00
|
|
|
return true;
|
2007-09-02 15:49:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
2010-12-10 19:47:44 +00:00
|
|
|
case SCH_BUS_ENTRY_T:
|
2007-09-02 15:49:11 +00:00
|
|
|
#undef STRUCT
|
2009-12-02 21:44:03 +00:00
|
|
|
#define STRUCT ( (SCH_BUS_ENTRY*) DrawList )
|
2007-09-02 15:49:11 +00:00
|
|
|
if( !( SearchMask & (RACCORDITEM) ) )
|
|
|
|
break;
|
|
|
|
|
2010-12-10 19:47:44 +00:00
|
|
|
if( TestSegmentHit( aPosRef, STRUCT->m_Pos, STRUCT->m_End(), hitminDist ) )
|
2007-09-02 15:49:11 +00:00
|
|
|
{
|
|
|
|
LastSnappedStruct = DrawList;
|
2009-11-28 09:24:37 +00:00
|
|
|
return true;
|
2007-09-02 15:49:11 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2010-12-10 19:47:44 +00:00
|
|
|
case SCH_JUNCTION_T:
|
2007-09-02 15:49:11 +00:00
|
|
|
#undef STRUCT
|
2009-12-02 21:44:03 +00:00
|
|
|
#define STRUCT ( (SCH_JUNCTION*) DrawList )
|
2007-09-02 15:49:11 +00:00
|
|
|
if( !(SearchMask & JUNCTIONITEM) )
|
|
|
|
break;
|
2009-06-11 14:26:17 +00:00
|
|
|
if( STRUCT->HitTest( aPosRef ) )
|
2007-09-02 15:49:11 +00:00
|
|
|
{
|
|
|
|
LastSnappedStruct = DrawList;
|
2009-11-28 09:24:37 +00:00
|
|
|
return true;
|
2007-09-02 15:49:11 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2010-12-10 19:47:44 +00:00
|
|
|
case SCH_NO_CONNECT_T:
|
2007-09-02 15:49:11 +00:00
|
|
|
#undef STRUCT
|
2009-12-02 21:44:03 +00:00
|
|
|
#define STRUCT ( (SCH_NO_CONNECT*) DrawList )
|
2007-09-02 15:49:11 +00:00
|
|
|
if( !(SearchMask & NOCONNECTITEM) )
|
|
|
|
break;
|
2009-06-11 14:26:17 +00:00
|
|
|
if( STRUCT->HitTest( aPosRef ) )
|
2007-09-02 15:49:11 +00:00
|
|
|
{
|
|
|
|
LastSnappedStruct = DrawList;
|
2009-11-28 09:24:37 +00:00
|
|
|
return true;
|
2007-09-02 15:49:11 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2010-12-10 19:47:44 +00:00
|
|
|
case SCH_MARKER_T:
|
2009-01-31 18:08:47 +00:00
|
|
|
{
|
2007-09-02 15:49:11 +00:00
|
|
|
#undef STRUCT
|
2009-12-02 21:44:03 +00:00
|
|
|
#define STRUCT ( (SCH_MARKER*) DrawList )
|
2007-09-02 15:49:11 +00:00
|
|
|
if( !(SearchMask & MARKERITEM) )
|
|
|
|
break;
|
2009-11-04 20:46:53 +00:00
|
|
|
if( STRUCT->HitTest( aPosRef ) )
|
2007-09-02 15:49:11 +00:00
|
|
|
{
|
|
|
|
LastSnappedStruct = DrawList;
|
2009-11-28 09:24:37 +00:00
|
|
|
return true;
|
2007-09-02 15:49:11 +00:00
|
|
|
}
|
|
|
|
break;
|
2009-01-31 18:08:47 +00:00
|
|
|
}
|
2007-09-02 15:49:11 +00:00
|
|
|
|
2010-12-10 19:47:44 +00:00
|
|
|
case SCH_TEXT_T:
|
2007-09-02 15:49:11 +00:00
|
|
|
#undef STRUCT
|
2008-03-20 01:50:21 +00:00
|
|
|
#define STRUCT ( (SCH_TEXT*) DrawList )
|
2009-05-12 12:12:34 +00:00
|
|
|
if( !( SearchMask & TEXTITEM) )
|
2007-09-02 15:49:11 +00:00
|
|
|
break;
|
2009-01-31 18:08:47 +00:00
|
|
|
if( STRUCT->HitTest( aPosRef ) )
|
2007-09-02 15:49:11 +00:00
|
|
|
{
|
|
|
|
LastSnappedStruct = DrawList;
|
2009-11-28 09:24:37 +00:00
|
|
|
return true;
|
2007-09-02 15:49:11 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
2010-12-10 19:47:44 +00:00
|
|
|
case SCH_LABEL_T:
|
|
|
|
case SCH_GLOBAL_LABEL_T:
|
|
|
|
case SCH_HIERARCHICAL_LABEL_T:
|
2009-01-31 18:08:47 +00:00
|
|
|
#undef STRUCT
|
2009-11-04 20:46:53 +00:00
|
|
|
#define STRUCT ( (SCH_TEXT*) DrawList ) // SCH_TEXT is the base
|
|
|
|
// class of these labels
|
2009-01-31 18:08:47 +00:00
|
|
|
if( !(SearchMask & LABELITEM) )
|
|
|
|
break;
|
|
|
|
if( STRUCT->HitTest( aPosRef ) )
|
2007-09-02 15:49:11 +00:00
|
|
|
{
|
|
|
|
LastSnappedStruct = DrawList;
|
2009-11-28 09:24:37 +00:00
|
|
|
return true;
|
2007-09-02 15:49:11 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2010-12-10 19:47:44 +00:00
|
|
|
case SCH_COMPONENT_T:
|
2007-09-02 15:49:11 +00:00
|
|
|
if( !( SearchMask & (LIBITEM | FIELDCMPITEM) ) )
|
|
|
|
break;
|
|
|
|
|
|
|
|
if( SearchMask & FIELDCMPITEM )
|
|
|
|
{
|
2009-06-11 14:26:17 +00:00
|
|
|
SCH_COMPONENT* DrawLibItem = (SCH_COMPONENT*) DrawList;
|
2009-01-02 17:07:50 +00:00
|
|
|
for( int i = REFERENCE; i < DrawLibItem->GetFieldCount(); i++ )
|
2007-09-02 15:49:11 +00:00
|
|
|
{
|
2009-12-02 21:44:03 +00:00
|
|
|
SCH_FIELD* field = DrawLibItem->GetField( i );
|
2008-10-06 05:44:29 +00:00
|
|
|
|
|
|
|
if( field->m_Attributs & TEXT_NO_VISIBLE )
|
2007-09-02 15:49:11 +00:00
|
|
|
continue;
|
2008-10-06 05:44:29 +00:00
|
|
|
|
|
|
|
if( field->IsVoid() )
|
2007-09-02 15:49:11 +00:00
|
|
|
continue;
|
2008-10-06 05:44:29 +00:00
|
|
|
|
2010-12-10 19:47:44 +00:00
|
|
|
EDA_Rect BoundaryBox = field->GetBoundingBox();
|
|
|
|
|
2009-01-02 13:19:34 +00:00
|
|
|
if( BoundaryBox.Inside( aPosRef ) )
|
2007-09-02 15:49:11 +00:00
|
|
|
{
|
2008-10-06 05:44:29 +00:00
|
|
|
LastSnappedStruct = field;
|
2009-11-28 09:24:37 +00:00
|
|
|
return true;
|
2007-09-02 15:49:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
#undef STRUCT
|
2008-03-20 01:50:21 +00:00
|
|
|
#define STRUCT ( (SCH_COMPONENT*) DrawList )
|
2010-12-10 19:47:44 +00:00
|
|
|
EDA_Rect BoundaryBox = STRUCT->GetBoundingBox();
|
|
|
|
|
2009-01-02 13:19:34 +00:00
|
|
|
if( BoundaryBox.Inside( aPosRef ) )
|
2007-09-02 15:49:11 +00:00
|
|
|
{
|
|
|
|
LastSnappedStruct = DrawList;
|
2009-11-28 09:24:37 +00:00
|
|
|
return true;
|
2007-09-02 15:49:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2010-12-10 19:47:44 +00:00
|
|
|
case SCH_SHEET_T:
|
2007-09-02 15:49:11 +00:00
|
|
|
#undef STRUCT
|
2009-11-04 20:46:53 +00:00
|
|
|
#define STRUCT ( (SCH_SHEET*) DrawList )
|
2007-09-02 15:49:11 +00:00
|
|
|
if( !(SearchMask & SHEETITEM) )
|
|
|
|
break;
|
2009-01-31 18:08:47 +00:00
|
|
|
if( STRUCT->HitTest( aPosRef ) )
|
2007-09-02 15:49:11 +00:00
|
|
|
{
|
|
|
|
LastSnappedStruct = DrawList;
|
2009-11-28 09:24:37 +00:00
|
|
|
return true;
|
2007-09-02 15:49:11 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
wxString msg;
|
2009-11-04 20:46:53 +00:00
|
|
|
msg.Printf( wxT( "SnapPoint2() error: unexpected struct type %d (" ),
|
|
|
|
DrawList->Type() );
|
2007-09-13 11:28:58 +00:00
|
|
|
msg << DrawList->GetClass() << wxT( ")" );
|
2009-08-01 19:26:05 +00:00
|
|
|
wxMessageBox( msg );
|
2007-09-02 15:49:11 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-04 20:46:53 +00:00
|
|
|
SCH_SHEET_PIN* LocateSheetLabel( SCH_SHEET* Sheet, const wxPoint& pos )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2010-06-24 18:31:43 +00:00
|
|
|
return Sheet->GetLabel( pos );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-09-02 15:49:11 +00:00
|
|
|
|
2010-06-24 18:31:43 +00:00
|
|
|
LIB_PIN* LocateAnyPin( SCH_ITEM* DrawList, const wxPoint& RefPos, SCH_COMPONENT** libpart )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2008-04-14 19:22:48 +00:00
|
|
|
SCH_ITEM* DrawStruct;
|
2009-09-18 14:56:05 +00:00
|
|
|
LIB_COMPONENT* Entry;
|
2009-10-06 13:19:40 +00:00
|
|
|
SCH_COMPONENT* schItem = NULL;
|
2009-10-08 13:19:28 +00:00
|
|
|
LIB_PIN* Pin = NULL;
|
2007-09-02 15:49:11 +00:00
|
|
|
|
2010-12-08 20:12:46 +00:00
|
|
|
for( DrawStruct = DrawList; DrawStruct != NULL; DrawStruct = DrawStruct->Next() )
|
2007-09-02 15:49:11 +00:00
|
|
|
{
|
2010-12-10 19:47:44 +00:00
|
|
|
if( DrawStruct->Type() != SCH_COMPONENT_T )
|
2007-09-02 15:49:11 +00:00
|
|
|
continue;
|
2010-12-08 20:12:46 +00:00
|
|
|
|
2009-10-06 13:19:40 +00:00
|
|
|
schItem = (SCH_COMPONENT*) DrawStruct;
|
|
|
|
Entry = CMP_LIBRARY::FindLibraryComponent( schItem->m_ChipName );
|
2009-08-27 11:41:56 +00:00
|
|
|
|
2007-09-02 15:49:11 +00:00
|
|
|
if( Entry == NULL )
|
|
|
|
continue;
|
2009-11-04 20:46:53 +00:00
|
|
|
|
|
|
|
/* we use LocateDrawItem to locate pins. but this function suppose a
|
2009-10-08 13:19:28 +00:00
|
|
|
* component.
|
2009-10-06 13:52:43 +00:00
|
|
|
* at 0,0 location
|
|
|
|
* So we must calculate the ref position relative to the component
|
2009-10-08 13:19:28 +00:00
|
|
|
*/
|
2009-10-06 13:19:40 +00:00
|
|
|
wxPoint libPos = RefPos - schItem->m_Pos;
|
2009-10-08 13:19:28 +00:00
|
|
|
Pin = (LIB_PIN*) Entry->LocateDrawItem( schItem->m_Multi,
|
|
|
|
schItem->m_Convert,
|
2010-12-10 19:47:44 +00:00
|
|
|
LIB_PIN_T,
|
2009-10-08 13:19:28 +00:00
|
|
|
libPos, schItem->m_Transform );
|
2007-09-02 15:49:11 +00:00
|
|
|
if( Pin )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( libpart )
|
2009-10-06 13:19:40 +00:00
|
|
|
*libpart = schItem;
|
2010-12-08 20:12:46 +00:00
|
|
|
|
2007-09-02 15:49:11 +00:00
|
|
|
return Pin;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-09-02 15:49:11 +00:00
|
|
|
|
2009-11-04 20:46:53 +00:00
|
|
|
SCH_SHEET_PIN* LocateAnyPinSheet( const wxPoint& RefPos, SCH_ITEM* DrawList )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2008-04-14 19:22:48 +00:00
|
|
|
SCH_ITEM* DrawStruct;
|
2009-11-04 20:46:53 +00:00
|
|
|
SCH_SHEET_PIN* PinSheet = NULL;
|
2007-09-02 15:49:11 +00:00
|
|
|
|
2010-12-08 20:12:46 +00:00
|
|
|
for( DrawStruct = DrawList; DrawStruct != NULL; DrawStruct = DrawStruct->Next() )
|
2007-09-02 15:49:11 +00:00
|
|
|
{
|
2010-12-10 19:47:44 +00:00
|
|
|
if( DrawStruct->Type() != SCH_SHEET_T )
|
2007-09-02 15:49:11 +00:00
|
|
|
continue;
|
2009-09-29 18:38:21 +00:00
|
|
|
|
2009-11-04 20:46:53 +00:00
|
|
|
PinSheet = LocateSheetLabel( (SCH_SHEET*) DrawStruct, RefPos );
|
2010-12-08 20:12:46 +00:00
|
|
|
|
2007-09-02 15:49:11 +00:00
|
|
|
if( PinSheet )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return PinSheet;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|