Finish removing GetCurItem() from eeschema.

This commit is contained in:
Jeff Young 2019-05-02 21:44:23 +01:00
parent 6e695aac25
commit 21b315f2af
8 changed files with 34 additions and 88 deletions

View File

@ -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;

View File

@ -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();
}
}

View File

@ -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<SCH_SELECTION_TOOL>();
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 );

View File

@ -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 )

View File

@ -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:

View File

@ -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 );
}
}

View File

@ -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<SCH_COMPONENT*>( 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 );
}
}

View File

@ -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<SCH_COMPONENT*>( 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 );
}