Commit a9a96c0e authored by Wayne Stambaugh's avatar Wayne Stambaugh

EESchema schematic item hit test improvements.

* Merge LocateAnyPin() and LocatePinEnd() into single method and move to
  SCH_SCREEN object.
parent f34926be
......@@ -753,7 +753,7 @@ bool IsJunctionNeeded( SCH_EDIT_FRAME* frame, wxPoint& pos )
if( PickStruct( pos, frame->GetScreen(), WIREITEM | WIRE_BUS_ENDPOINTS_ONLY ) )
return TRUE;
if( frame->LocatePinEnd( frame->GetScreen()->GetDrawItems(), pos ) )
if( frame->GetScreen()->GetPin( pos, NULL, true ) )
return TRUE;
}
......
......@@ -156,7 +156,7 @@ SCH_ITEM* SCH_EDIT_FRAME::SchematicGeneralLocateAndDisplay( const wxPoint& refpo
if( DrawStruct ) // We have found a wire: Search for a connected pin at the same location
{
Pin = LocateAnyPin( (SCH_ITEM*) m_CurrentSheet->LastDrawList(), refpoint, &LibItem );
Pin = GetScreen()->GetPin( refpoint, &LibItem );
if( Pin )
{
......@@ -192,7 +192,7 @@ SCH_ITEM* SCH_EDIT_FRAME::SchematicGeneralLocateAndDisplay( const wxPoint& refpo
}
/* search for a pin */
Pin = LocateAnyPin( (SCH_ITEM*) m_CurrentSheet->LastDrawList(), refpoint, &LibItem );
Pin = GetScreen()->GetPin( refpoint, &LibItem );
if( Pin )
{
......
......@@ -6,6 +6,7 @@
#include "gr_basic.h"
#include "sch_item_struct.h"
#include "wxEeschemaStruct.h"
#include "class_sch_screen.h"
#include "general.h"
#include "protos.h"
......@@ -49,37 +50,3 @@ void SCH_EDIT_FRAME::TestDanglingEnds( SCH_ITEM* aDrawList, wxDC* aDC )
}
}
}
/**
* Test if point pos is on a pin end.
*
* @param DrawList = List of SCH_ITEMs to check.
* @param pos - Position of pin end to locate.
* @return a LIB_PIN pointer to the located pin or NULL if no pin was found.
*/
LIB_PIN* SCH_EDIT_FRAME::LocatePinEnd( SCH_ITEM* DrawList, const wxPoint& pos )
{
SCH_COMPONENT* DrawLibItem;
LIB_PIN* Pin;
wxPoint pinpos;
Pin = LocateAnyPin( DrawList, pos, &DrawLibItem );
if( !Pin )
return NULL;
pinpos = Pin->GetPosition();
if( DrawLibItem == NULL )
NEGATE( pinpos.y ); // In libraries Y axis is bottom to top
// and in schematic Y axis is top to bottom
else // calculate the pin position in schematic
pinpos = DrawLibItem->GetTransform().TransformCoordinate( pinpos ) + DrawLibItem->m_Pos;
if( pos == pinpos )
return Pin;
return NULL;
}
......@@ -51,7 +51,7 @@ static bool MarkConnected( SCH_EDIT_FRAME* frame, SCH_ITEM* ListStruct, SCH_LINE
#define SEGM ( (SCH_LINE*) Struct )
if( segment->IsEndPoint( SEGM->m_Start ) )
{
if( !frame->LocatePinEnd( ListStruct, SEGM->m_Start ) )
if( !frame->GetScreen()->GetPin( SEGM->m_Start, NULL, true ) )
{
Struct->m_Flags |= CANDIDATE;
MarkConnected( frame, ListStruct, SEGM );
......@@ -59,7 +59,7 @@ static bool MarkConnected( SCH_EDIT_FRAME* frame, SCH_ITEM* ListStruct, SCH_LINE
}
if( segment->IsEndPoint( SEGM->m_End ) )
{
if( !frame->LocatePinEnd( ListStruct, SEGM->m_End ) )
if( !frame->GetScreen()->GetPin( SEGM->m_End, NULL, true ) )
{
Struct->m_Flags |= CANDIDATE;
MarkConnected( frame, ListStruct, SEGM );
......
......@@ -689,9 +689,10 @@ void SCH_EDIT_FRAME::OnHotKey( wxDC* DC, int hotkey, EDA_ITEM* DrawStruct )
break;
if( DrawStruct->Type() == SCH_SHEET_T )
{
SCH_SHEET* sheet = (SCH_SHEET*) DrawStruct;
// If it's a sheet, then check if a pinsheet is under the cursor
SCH_SHEET_PIN* slabel = LocateSheetLabel( (SCH_SHEET*) DrawStruct,
GetScreen()->m_Curseur );
SCH_SHEET_PIN* slabel = sheet->GetLabel( GetScreen()->m_Curseur );
if( slabel )
DrawStruct = slabel;
}
......@@ -707,8 +708,7 @@ void SCH_EDIT_FRAME::OnHotKey( wxDC* DC, int hotkey, EDA_ITEM* DrawStruct )
if( HK_Descr->m_Idcommand == HK_COPY_COMPONENT_OR_LABEL )
{
GetScreen()->SetCurItem( (SCH_ITEM*) DrawStruct );
wxCommandEvent event( wxEVT_COMMAND_TOOL_CLICKED,
HK_Descr->m_IdMenuEvent );
wxCommandEvent event( wxEVT_COMMAND_TOOL_CLICKED, HK_Descr->m_IdMenuEvent );
wxPostEvent( this, event );
break;
}
......
......@@ -324,38 +324,6 @@ bool SnapPoint2( const wxPoint& aPosRef, int SearchMask, SCH_ITEM* DrawList )
}
SCH_SHEET_PIN* LocateSheetLabel( SCH_SHEET* Sheet, const wxPoint& pos )
{
return Sheet->GetLabel( pos );
}
LIB_PIN* LocateAnyPin( SCH_ITEM* DrawList, const wxPoint& RefPos, SCH_COMPONENT** libpart )
{
SCH_ITEM* item;
SCH_COMPONENT* component = NULL;
LIB_PIN* pin = NULL;
for( item = DrawList; item != NULL; item = item->Next() )
{
if( item->Type() != SCH_COMPONENT_T )
continue;
component = (SCH_COMPONENT*) item;
pin = (LIB_PIN*) component->GetDrawItem( RefPos, LIB_PIN_T );
if( pin )
break;
}
if( libpart )
*libpart = component;
return pin;
}
SCH_SHEET_PIN* LocateAnyPinSheet( const wxPoint& RefPos, SCH_ITEM* DrawList )
{
SCH_ITEM* DrawStruct;
......@@ -366,7 +334,8 @@ SCH_SHEET_PIN* LocateAnyPinSheet( const wxPoint& RefPos, SCH_ITEM* DrawList )
if( DrawStruct->Type() != SCH_SHEET_T )
continue;
PinSheet = LocateSheetLabel( (SCH_SHEET*) DrawStruct, RefPos );
SCH_SHEET* sheet = (SCH_SHEET*) DrawStruct;
PinSheet = sheet->GetLabel( RefPos );
if( PinSheet )
break;
......
......@@ -70,8 +70,9 @@ bool SCH_EDIT_FRAME::OnRightClick( const wxPoint& MousePos, wxMenu* PopMenu )
if( DrawStruct && (DrawStruct->Type() == SCH_SHEET_T) )
{
SCH_SHEET_PIN* slabel;
slabel = LocateSheetLabel( (SCH_SHEET*) DrawStruct, GetScreen()->m_Curseur );
SCH_SHEET* sheet = (SCH_SHEET*) DrawStruct;
SCH_SHEET_PIN* slabel = sheet->GetLabel( GetScreen()->m_Curseur );
if( slabel )
DrawStruct = slabel;
}
......
......@@ -114,12 +114,7 @@ SCH_COMPONENT* LocateSmallestComponent( SCH_SCREEN* Screen );
* Pointer to the structure if only 1 item is selected.
* NULL if no items are selects.
*/
SCH_ITEM* PickStruct( const wxPoint& refpos, SCH_SCREEN* screen, int SearchMask );
SCH_SHEET_PIN* LocateSheetLabel( SCH_SHEET* Sheet, const wxPoint& pos );
LIB_PIN* LocateAnyPin( SCH_ITEM* DrawList,
const wxPoint& RefPos,
SCH_COMPONENT** libpart = NULL );
SCH_ITEM* PickStruct( const wxPoint& refpos, SCH_SCREEN* screen, int SearchMask );
SCH_SHEET_PIN* LocateAnyPinSheet( const wxPoint& RefPos, SCH_ITEM* DrawList );
......
......@@ -378,7 +378,8 @@ void SCH_SCREEN::ClearDrawingState()
}
LIB_PIN* SCH_SCREEN::GetPin( const wxPoint& aPosition, SCH_COMPONENT** aComponent )
LIB_PIN* SCH_SCREEN::GetPin( const wxPoint& aPosition, SCH_COMPONENT** aComponent,
bool aEndPointOnly )
{
SCH_ITEM* item;
SCH_COMPONENT* component = NULL;
......@@ -397,6 +398,9 @@ LIB_PIN* SCH_SCREEN::GetPin( const wxPoint& aPosition, SCH_COMPONENT** aComponen
break;
}
if( pin && aEndPointOnly && ( component->GetPinPhysicalPosition( pin ) != aPosition ) )
pin = NULL;
if( aComponent )
*aComponent = component;
......
......@@ -128,7 +128,17 @@ public:
int CountConnectedItems( const wxPoint& aPos, bool aTestJunctions ) const;
LIB_PIN* GetPin( const wxPoint& aPosition, SCH_COMPONENT** aComponent = NULL );
/**
* Function GetPin
* test the screen for a component pin item at \a aPosition.
* @param aPosition Position to test.
* @param aComponent The component if a pin was found, otherwise NULL.
* @param aEndPointOnly Set to true to test if \a aPosition is the connection
* point of the pin.
* @return The pin item if found, otherwise NULL.
*/
LIB_PIN* GetPin( const wxPoint& aPosition, SCH_COMPONENT** aComponent = NULL,
bool aEndPointOnly = false );
/**
* Function ClearAnnotation
......
......@@ -668,7 +668,6 @@ public:
void RepeatDrawItem( wxDC* DC );
void TestDanglingEnds( SCH_ITEM* DrawList, wxDC* DC );
LIB_PIN* LocatePinEnd( SCH_ITEM* DrawList, const wxPoint& pos );
// ERC:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment