From 21b315f2af42eafbb7df187f8f279ee8665abf67 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Thu, 2 May 2019 21:44:23 +0100 Subject: [PATCH] Finish removing GetCurItem() from eeschema. --- eeschema/edit_label.cpp | 4 --- eeschema/getpart.cpp | 43 +++++++++++----------- eeschema/hotkeys.cpp | 52 ++++----------------------- eeschema/sch_edit_frame.cpp | 3 -- eeschema/sch_edit_frame.h | 3 +- eeschema/tools/sch_drawing_tool.cpp | 4 ++- eeschema/tools/sch_edit_tool.cpp | 3 +- eeschema/tools/sch_selection_tool.cpp | 10 ++---- 8 files changed, 34 insertions(+), 88 deletions(-) diff --git a/eeschema/edit_label.cpp b/eeschema/edit_label.cpp index e657e5ee76..44fa63e032 100644 --- a/eeschema/edit_label.cpp +++ b/eeschema/edit_label.cpp @@ -158,10 +158,6 @@ void SCH_EDIT_FRAME::ConvertTextType( SCH_TEXT* aText, KICAD_T aType ) if( selected ) m_toolManager->RunAction( SCH_ACTIONS::addItemToSel, true, newtext ); - // if the old item is the current schematic item, replace it by the new text: - if( screen->GetCurItem() == aText ) - screen->SetCurItem( newtext ); - SetRepeatItem( nullptr ); delete aText; diff --git a/eeschema/getpart.cpp b/eeschema/getpart.cpp index 6939a8dbb9..eaef12a7df 100644 --- a/eeschema/getpart.cpp +++ b/eeschema/getpart.cpp @@ -204,47 +204,44 @@ SCH_BASE_FRAME::COMPONENT_SELECTION SCH_BASE_FRAME::SelectCompFromLibTree( } -void SCH_EDIT_FRAME::OnSelectUnit( wxCommandEvent& aEvent ) +void SCH_EDIT_FRAME::SelectUnit( SCH_COMPONENT* aComponent, int aUnit ) { - SCH_SCREEN* screen = GetScreen(); - SCH_ITEM* item = screen->GetCurItem(); - SCH_COMPONENT* component = (SCH_COMPONENT*) item; - GetCanvas()->MoveCursorToCrossHair(); - int unit = aEvent.GetId() + 1 - ID_POPUP_SCH_SELECT_UNIT1; - - LIB_PART* part = GetLibPart( component->GetLibId() ); + LIB_PART* part = GetLibPart( aComponent->GetLibId() ); if( !part ) return; int unitCount = part->GetUnitCount(); - if( unitCount <= 1 || component->GetUnit() == unit ) + if( unitCount <= 1 || aComponent->GetUnit() == aUnit ) return; - if( unit > unitCount ) - unit = unitCount; + if( aUnit > unitCount ) + aUnit = unitCount; - STATUS_FLAGS flags = component->GetFlags(); + STATUS_FLAGS savedFlags = aComponent->GetFlags(); - if( !component->GetEditFlags() ) // No command in progress: save in undo list - SaveCopyInUndoList( component, UR_CHANGED ); + if( !aComponent->GetEditFlags() ) // No command in progress: save in undo list + SaveCopyInUndoList( aComponent, UR_CHANGED ); /* Update the unit number. */ - component->SetUnitSelection( g_CurrentSheet, unit ); - component->SetUnit( unit ); - component->ClearFlags(); - component->SetFlags( flags ); // Restore m_Flag modified by SetUnit() + aComponent->SetUnitSelection( g_CurrentSheet, aUnit ); + aComponent->SetUnit( aUnit ); + aComponent->ClearFlags(); + aComponent->SetFlags( savedFlags ); // Restore m_Flag modified by SetUnit() - if( m_autoplaceFields ) - component->AutoAutoplaceFields( GetScreen() ); + if( !aComponent->GetEditFlags() ) // No command in progress: update schematic + { + if( m_autoplaceFields ) + aComponent->AutoAutoplaceFields( GetScreen() ); - TestDanglingEnds(); + TestDanglingEnds(); - RefreshItem( component ); - OnModify(); + RefreshItem( aComponent ); + OnModify(); + } } diff --git a/eeschema/hotkeys.cpp b/eeschema/hotkeys.cpp index 71fb25533c..41667e0c07 100644 --- a/eeschema/hotkeys.cpp +++ b/eeschema/hotkeys.cpp @@ -414,24 +414,16 @@ EDA_HOTKEY* SCH_EDIT_FRAME::GetHotKeyDescription( int aCommand ) const /* - * Hot keys. Some commands are relative to the item under the mouse cursor - * Commands are case insensitive + * Hot keys. Commands are case insensitive. */ bool SCH_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition, EDA_ITEM* aItem ) { if( aHotKey == 0 ) return false; - wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED ); - - SCH_SCREEN* screen = GetScreen(); - - // itemInEdit == false means no item currently edited. We can ask for editing a new item - bool itemInEdit = screen->GetCurItem() && screen->GetCurItem()->GetEditFlags(); - - // notBusy == true means no item currently edited and no other command in progress - // We can change active tool and ask for editing a new item - bool notBusy = !itemInEdit; + wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED ); + SCH_SELECTION_TOOL* selTool = GetToolManager()->GetTool(); + SELECTION& selection = selTool->GetSelection(); /* Convert lower to upper case (the usual toupper function has problem * with non ascii codes like function keys */ @@ -466,23 +458,11 @@ bool SCH_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition, GetScreen()->m_O_Curseur = GetCrossHairPosition(); break; - case HK_END_CURR_LINEWIREBUS: - // this key terminates a new line/bus/wire in progress - if( aItem && aItem->IsNew() && - aItem->Type() == SCH_LINE_T ) - { - cmd.SetId( hotKey->m_IdMenuEvent ); - GetEventHandler()->ProcessEvent( cmd ); - } - break; - case HK_UNDO: // Hot keys that map to command IDs that cannot be called case HK_REDO: // while busy performing another command. case HK_FIND_ITEM: case HK_FIND_REPLACE: - case HK_DELETE_NODE: - case HK_LEAVE_SHEET: - if( notBusy ) + if( SCH_CONDITIONS::Idle( selection ) ) { cmd.SetId( hotKey->m_IdMenuEvent ); GetEventHandler()->ProcessEvent( cmd ); @@ -491,7 +471,7 @@ bool SCH_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition, case HK_FIND_NEXT_ITEM: case HK_FIND_NEXT_DRC_MARKER: - if( notBusy ) + if( SCH_CONDITIONS::Idle( selection ) ) { wxFindDialogEvent event( hotKey->m_IdMenuEvent, GetId() ); event.SetEventObject( this ); @@ -501,29 +481,9 @@ bool SCH_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition, } break; - case HK_EDIT: - // Edit schematic item. Do not allow sheet editing when mowing because sheet editing - // can be complex. - if( itemInEdit && screen->GetCurItem()->Type() == SCH_SHEET_T ) - break; - - // Fall through - case HK_EDIT_COMPONENT_VALUE: // Edit component value field. - case HK_EDIT_COMPONENT_REFERENCE: // Edit component value reference. - case HK_EDIT_COMPONENT_FOOTPRINT: // Edit component footprint field. - case HK_SHOW_COMPONENT_DATASHEET: // Show component datasheet in browser. - case HK_EDIT_COMPONENT_WITH_LIBEDIT: // Call Libedit and load the current component - case HK_AUTOPLACE_FIELDS: // Autoplace all fields around component - case HK_UNFOLD_BUS: // Unfold a bus wire case HK_CANVAS_CAIRO: case HK_CANVAS_OPENGL: { - // force a new item search on hot keys at current position, - // if there is no currently edited item, - // to avoid using a previously selected item - if( ! itemInEdit ) - screen->SetCurItem( NULL ); - EDA_HOTKEY_CLIENT_DATA data( aPosition ); cmd.SetInt( hotKey->m_Idcommand ); cmd.SetClientObject( &data ); diff --git a/eeschema/sch_edit_frame.cpp b/eeschema/sch_edit_frame.cpp index 95adb6beec..1dc5553792 100644 --- a/eeschema/sch_edit_frame.cpp +++ b/eeschema/sch_edit_frame.cpp @@ -277,9 +277,6 @@ BEGIN_EVENT_TABLE( SCH_EDIT_FRAME, EDA_DRAW_FRAME ) EVT_TOOL( ID_TB_OPTIONS_HIDDEN_PINS, SCH_EDIT_FRAME::OnSelectOptionToolbar ) EVT_TOOL( ID_TB_OPTIONS_BUS_WIRES_ORIENT, SCH_EDIT_FRAME::OnSelectOptionToolbar ) - EVT_MENU_RANGE( ID_POPUP_SCH_SELECT_UNIT1, ID_POPUP_SCH_SELECT_UNIT_CMP_MAX, - SCH_EDIT_FRAME::OnSelectUnit ) - /* Handle user interface update events. */ EVT_UPDATE_UI( wxID_PASTE, SCH_EDIT_FRAME::OnUpdatePaste ) EVT_UPDATE_UI( ID_TB_OPTIONS_HIDDEN_PINS, SCH_EDIT_FRAME::OnUpdateHiddenPins ) diff --git a/eeschema/sch_edit_frame.h b/eeschema/sch_edit_frame.h index 5c7236b211..ef933b7a72 100644 --- a/eeschema/sch_edit_frame.h +++ b/eeschema/sch_edit_frame.h @@ -1016,8 +1016,7 @@ public: void ConvertPart( SCH_COMPONENT* aComponent ); -private: - void OnSelectUnit( wxCommandEvent& aEvent ); + void SelectUnit( SCH_COMPONENT* aComponent, int aUnit ); /* Undo - redo */ public: diff --git a/eeschema/tools/sch_drawing_tool.cpp b/eeschema/tools/sch_drawing_tool.cpp index df345beb93..41ed0fceec 100644 --- a/eeschema/tools/sch_drawing_tool.cpp +++ b/eeschema/tools/sch_drawing_tool.cpp @@ -354,9 +354,11 @@ int SCH_DRAWING_TOOL::doPlaceComponent( SCH_COMPONENT* aComponent, SCHLIB_FILTER if( evt->GetCommandId().get() >= ID_POPUP_SCH_SELECT_UNIT_CMP && evt->GetCommandId().get() <= ID_POPUP_SCH_SELECT_UNIT_CMP_MAX ) { + int unit = evt->GetCommandId().get() - ID_POPUP_SCH_SELECT_UNIT_CMP; + if( aComponent ) { - aComponent->SetUnit( evt->GetCommandId().get() - ID_POPUP_SCH_SELECT_UNIT_CMP ); + m_frame->SelectUnit( aComponent, unit ); m_toolMgr->RunAction( SCH_ACTIONS::refreshPreview ); } } diff --git a/eeschema/tools/sch_edit_tool.cpp b/eeschema/tools/sch_edit_tool.cpp index ce53167dbb..c081777a80 100644 --- a/eeschema/tools/sch_edit_tool.cpp +++ b/eeschema/tools/sch_edit_tool.cpp @@ -716,10 +716,11 @@ int SCH_EDIT_TOOL::Main( const TOOL_EVENT& aEvent ) && evt->GetCommandId().get() <= ID_POPUP_SCH_SELECT_UNIT_CMP_MAX ) { SCH_COMPONENT* component = dynamic_cast( selection.Front() ); + int unit = evt->GetCommandId().get() - ID_POPUP_SCH_SELECT_UNIT_CMP; if( component ) { - component->SetUnit( evt->GetCommandId().get() - ID_POPUP_SCH_SELECT_UNIT_CMP ); + m_frame->SelectUnit( component, unit ); m_toolMgr->RunAction( SCH_ACTIONS::refreshPreview ); } } diff --git a/eeschema/tools/sch_selection_tool.cpp b/eeschema/tools/sch_selection_tool.cpp index 77f4b35b37..bee0f862b0 100644 --- a/eeschema/tools/sch_selection_tool.cpp +++ b/eeschema/tools/sch_selection_tool.cpp @@ -323,13 +323,10 @@ int SCH_SELECTION_TOOL::Main( const TOOL_EVENT& aEvent ) && evt->GetCommandId().get() <= ID_POPUP_SCH_SELECT_UNIT_CMP_MAX ) { SCH_COMPONENT* component = dynamic_cast( m_selection.Front() ); + int unit = evt->GetCommandId().get() - ID_POPUP_SCH_SELECT_UNIT_CMP; if( component ) - { - m_frame->SaveCopyInUndoList( component, UR_CHANGED ); - component->SetUnit( evt->GetCommandId().get() - ID_POPUP_SCH_SELECT_UNIT_CMP ); - m_frame->RefreshItem( component ); - } + m_frame->SelectUnit( component, unit ); } } @@ -934,9 +931,6 @@ void SCH_SELECTION_TOOL::select( SCH_ITEM* aItem ) void SCH_SELECTION_TOOL::unselect( SCH_ITEM* aItem ) { unhighlight( aItem, SELECTED, &m_selection ); - - if( m_frame && m_frame->GetScreen()->GetCurItem() == aItem ) - m_frame->GetScreen()->SetCurItem( nullptr ); }