SCH_ITEM* SCH_EDIT_FRAME::LocateItem( const wxPoint& aPosition, const KICAD_T aFilterList[], int aHotKeyCommandId ) { SCH_ITEM* item = NULL; m_collectedItems.Collect( GetScreen()->GetDrawItems(), aFilterList, aPosition ); if( m_collectedItems.GetCount() == 0 ) { ClearMsgPanel(); } else if( m_collectedItems.GetCount() == 1 ) { item = m_collectedItems[0]; } else { // There are certain parent/child and enclosure combinations that can be handled // automatically. Since schematics are meant to be human-readable we don't have // all the various overlap and coverage issues that we do in Pcbnew. if( m_collectedItems.GetCount() == 2 ) { SCH_ITEM* a = m_collectedItems[ 0 ]; SCH_ITEM* b = m_collectedItems[ 1 ]; if( a->GetParent() == b ) item = a; else if( a == b->GetParent() ) item = b; else if( a->Type() == SCH_SHEET_T && b->Type() != SCH_SHEET_T ) item = b; else if( b->Type() == SCH_SHEET_T && a->Type() != SCH_SHEET_T ) item = a; } // There are certain combinations of items that do not need clarification such as // a corner were two lines meet or all the items form a junction. if( aHotKeyCommandId ) { switch( aHotKeyCommandId ) { case HK_DRAG: if( m_collectedItems.IsCorner() || m_collectedItems.IsNode( false ) || m_collectedItems.IsDraggableJunction() ) { item = m_collectedItems[0]; } break; case HK_MOVE_COMPONENT_OR_ITEM: if( m_collectedItems.GetCount() == 2 && dynamic_cast< SCH_SHEET_PIN * >( m_collectedItems[0] ) && dynamic_cast< SCH_SHEET * >( m_collectedItems[1] ) ) { item = m_collectedItems[0]; } break; default: ; } } if( item == NULL ) { wxASSERT_MSG( m_collectedItems.GetCount() <= MAX_SELECT_ITEM_IDS, wxT( "Select item clarification context menu size limit exceeded." ) ); wxMenu selectMenu; AddMenuItem( &selectMenu, wxID_NONE, _( "Clarify Selection" ), KiBitmap( info_xpm ) ); selectMenu.AppendSeparator(); for( int i = 0; i < m_collectedItems.GetCount() && i < MAX_SELECT_ITEM_IDS; i++ ) { wxString text = m_collectedItems[i]->GetSelectMenuText( m_UserUnits ); BITMAP_DEF xpm = m_collectedItems[i]->GetMenuImage(); AddMenuItem( &selectMenu, ID_SELECT_ITEM_START + i, text, KiBitmap( xpm ) ); } // Set to NULL in case the user aborts the clarification context menu. GetScreen()->SetCurItem( NULL ); m_canvas->SetAbortRequest( true ); // Changed to false if an item is selected PopupMenu( &selectMenu ); if( !m_canvas->GetAbortRequest() ) { m_canvas->MoveCursorToCrossHair(); item = GetScreen()->GetCurItem(); } } } GetScreen()->SetCurItem( item ); if( item ) { if( item->Type() == SCH_COMPONENT_T ) ( (SCH_COMPONENT*) item )->SetCurrentSheetPath( &GetCurrentSheet() ); MSG_PANEL_ITEMS items; item->GetMsgPanelInfo( m_UserUnits, items ); SetMsgPanel( items ); } else { ClearMsgPanel(); } return item; }
SCH_ITEM* SCH_EDIT_FRAME::LocateItem( const wxPoint& aPosition, const KICAD_T aFilterList[], int aHotKeyCommandId ) { SCH_ITEM* item = NULL; m_collectedItems.Collect( GetScreen()->GetDrawItems(), aFilterList, aPosition ); if( m_collectedItems.GetCount() == 0 ) { ClearMsgPanel(); } else if( m_collectedItems.GetCount() == 1 ) { item = m_collectedItems[0]; } else { // There are certain combinations of items that do not need clarification such as // a corner were two lines meet or all the items form a junction. if( aHotKeyCommandId ) { switch( aHotKeyCommandId ) { case HK_DRAG: if( m_collectedItems.IsCorner() || m_collectedItems.IsNode( false ) || m_collectedItems.IsDraggableJunction() ) { item = m_collectedItems[0]; } default: ; } } if( item == NULL ) { wxASSERT_MSG( m_collectedItems.GetCount() <= MAX_SELECT_ITEM_IDS, wxT( "Select item clarification context menu size limit exceeded." ) ); wxMenu selectMenu; wxMenuItem* title = new wxMenuItem( &selectMenu, wxID_NONE, _( "Clarify Selection" ) ); selectMenu.Append( title ); selectMenu.AppendSeparator(); for( int i = 0; i < m_collectedItems.GetCount() && i < MAX_SELECT_ITEM_IDS; i++ ) { wxString text = m_collectedItems[i]->GetSelectMenuText(); BITMAP_DEF xpm = m_collectedItems[i]->GetMenuImage(); AddMenuItem( &selectMenu, ID_SELECT_ITEM_START + i, text, KiBitmap( xpm ) ); } // Set to NULL in case user aborts the clarification context menu. GetScreen()->SetCurItem( NULL ); m_canvas->SetAbortRequest( true ); // Changed to false if an item is selected PopupMenu( &selectMenu ); m_canvas->MoveCursorToCrossHair(); item = GetScreen()->GetCurItem(); } } GetScreen()->SetCurItem( item ); if( item ) { if( item->Type() == SCH_COMPONENT_T ) ( (SCH_COMPONENT*) item )->SetCurrentSheetPath( &GetCurrentSheet() ); MSG_PANEL_ITEMS items; item->GetMsgPanelInfo( items ); SetMsgPanel( items ); } else { ClearMsgPanel(); } return item; }