From a9a96c0e5179196f6e0b29bace82ddd725309449 Mon Sep 17 00:00:00 2001 From: Wayne Stambaugh Date: Mon, 10 Jan 2011 15:35:24 -0500 Subject: [PATCH] EESchema schematic item hit test improvements. * Merge LocateAnyPin() and LocatePinEnd() into single method and move to SCH_SCREEN object. --- eeschema/bus-wire-junction.cpp | 2 +- eeschema/controle.cpp | 4 ++-- eeschema/dangling_ends.cpp | 35 +--------------------------------- eeschema/delete.cpp | 4 ++-- eeschema/hotkeys.cpp | 8 ++++---- eeschema/locate.cpp | 35 ++-------------------------------- eeschema/onrightclick.cpp | 5 +++-- eeschema/protos.h | 7 +------ eeschema/sch_screen.cpp | 6 +++++- include/class_sch_screen.h | 12 +++++++++++- include/wxEeschemaStruct.h | 1 - 11 files changed, 32 insertions(+), 87 deletions(-) diff --git a/eeschema/bus-wire-junction.cpp b/eeschema/bus-wire-junction.cpp index ab0b6c5f08..bf6f5c96d5 100644 --- a/eeschema/bus-wire-junction.cpp +++ b/eeschema/bus-wire-junction.cpp @@ -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; } diff --git a/eeschema/controle.cpp b/eeschema/controle.cpp index b6e5c795ca..a8f369f217 100644 --- a/eeschema/controle.cpp +++ b/eeschema/controle.cpp @@ -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 ) { diff --git a/eeschema/dangling_ends.cpp b/eeschema/dangling_ends.cpp index 8f375bae07..a9db0ddd58 100644 --- a/eeschema/dangling_ends.cpp +++ b/eeschema/dangling_ends.cpp @@ -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; -} diff --git a/eeschema/delete.cpp b/eeschema/delete.cpp index cddf04830c..afba05b661 100644 --- a/eeschema/delete.cpp +++ b/eeschema/delete.cpp @@ -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 ); diff --git a/eeschema/hotkeys.cpp b/eeschema/hotkeys.cpp index f9da0d5a00..afa2433f08 100644 --- a/eeschema/hotkeys.cpp +++ b/eeschema/hotkeys.cpp @@ -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; } diff --git a/eeschema/locate.cpp b/eeschema/locate.cpp index 3a3e29582c..56289dd407 100644 --- a/eeschema/locate.cpp +++ b/eeschema/locate.cpp @@ -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; diff --git a/eeschema/onrightclick.cpp b/eeschema/onrightclick.cpp index f7a7640a7d..09d191e86b 100644 --- a/eeschema/onrightclick.cpp +++ b/eeschema/onrightclick.cpp @@ -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; } diff --git a/eeschema/protos.h b/eeschema/protos.h index 8967dd85ab..6006b36d6a 100644 --- a/eeschema/protos.h +++ b/eeschema/protos.h @@ -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 ); diff --git a/eeschema/sch_screen.cpp b/eeschema/sch_screen.cpp index 6315bd822b..ff144e9edd 100644 --- a/eeschema/sch_screen.cpp +++ b/eeschema/sch_screen.cpp @@ -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; diff --git a/include/class_sch_screen.h b/include/class_sch_screen.h index 5c36820dbc..8742eecf1b 100644 --- a/include/class_sch_screen.h +++ b/include/class_sch_screen.h @@ -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 diff --git a/include/wxEeschemaStruct.h b/include/wxEeschemaStruct.h index 1f8dbd7560..1d03c6213a 100644 --- a/include/wxEeschemaStruct.h +++ b/include/wxEeschemaStruct.h @@ -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: