From 6073bf3ea781fe4ca8b47d241cf1ee1f81cc688f Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Sun, 17 Dec 2017 21:21:00 -0800 Subject: [PATCH] Library Editor: Moving current item to the base screen Store the currently-edited item in the base screen class instead of the libedit_frame. This allows us to access it for double-click disambiguation and harmonizes the library editor with the schematic editor code that already does this. Fixes: lp:1738694 * https://bugs.launchpad.net/kicad/+bug/1738694 --- eeschema/class_sch_screen.h | 3 + eeschema/hotkeys.cpp | 35 ++++++----- eeschema/lib_collectors.cpp | 1 + eeschema/lib_export.cpp | 3 +- eeschema/libedit.cpp | 5 +- eeschema/libedit_onleftclick.cpp | 55 +++++++++-------- eeschema/libedit_onrightclick.cpp | 4 +- eeschema/libedit_undo_redo.cpp | 4 +- eeschema/libeditframe.cpp | 98 ++++++++++++++++--------------- eeschema/libeditframe.h | 8 +-- eeschema/pinedit.cpp | 20 +++---- eeschema/symbdraw.cpp | 68 +++++++++++---------- eeschema/symbedit.cpp | 2 +- 13 files changed, 167 insertions(+), 139 deletions(-) diff --git a/eeschema/class_sch_screen.h b/eeschema/class_sch_screen.h index d3aa93d9b5..8e7cc8fe2b 100644 --- a/eeschema/class_sch_screen.h +++ b/eeschema/class_sch_screen.h @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -171,6 +172,7 @@ public: * @return SCH_ITEM* - the one selected, or NULL. */ SCH_ITEM* GetCurItem() const { return (SCH_ITEM*) BASE_SCREEN::GetCurItem(); } + LIB_ITEM* GetCurLibItem() const { return (LIB_ITEM*) BASE_SCREEN::GetCurItem(); } /** * Sets the currently selected object, m_CurrentItem. @@ -178,6 +180,7 @@ public: * @param aItem Any object derived from SCH_ITEM */ void SetCurItem( SCH_ITEM* aItem ) { BASE_SCREEN::SetCurItem( (EDA_ITEM*) aItem ); } + void SetCurLibItem( LIB_ITEM* aItem ) { BASE_SCREEN::SetCurItem( (EDA_ITEM*) aItem ); } /** * Delete all draw items and clears the project settings. diff --git a/eeschema/hotkeys.cpp b/eeschema/hotkeys.cpp index 4e8f954a82..01af160b5f 100644 --- a/eeschema/hotkeys.cpp +++ b/eeschema/hotkeys.cpp @@ -674,7 +674,10 @@ bool LIB_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition, if( hotKey == NULL ) return false; - bool itemInEdit = m_drawItem && m_drawItem->InEditMode(); + SCH_SCREEN* screen = GetScreen(); + + // itemInEdit == false means no item currently edited. We can ask for editing a new item + bool itemInEdit = IsEditingDrawItem(); bool blocInProgress = GetScreen()->m_BlockLocate.GetState() != STATE_NO_BLOCK; @@ -732,12 +735,12 @@ bool LIB_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition, break; case HK_EDIT: - if( !itemInEdit ) - m_drawItem = LocateItemUsingCursor( aPosition ); + if ( !itemInEdit ) + SetDrawItem( LocateItemUsingCursor( aPosition ) ); - if( m_drawItem ) + if( GetDrawItem() ) { - switch( m_drawItem->Type() ) + switch( GetDrawItem()->Type() ) { case LIB_PIN_T: cmd.SetId( ID_LIBEDIT_EDIT_PIN ); @@ -773,9 +776,9 @@ bool LIB_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition, else { if ( !itemInEdit ) - m_drawItem = LocateItemUsingCursor( aPosition ); + SetDrawItem( LocateItemUsingCursor( aPosition ) ); - if( m_drawItem ) + if( GetDrawItem() ) { cmd.SetId( ID_LIBEDIT_ROTATE_ITEM ); GetEventHandler()->ProcessEvent( cmd ); @@ -792,10 +795,10 @@ bool LIB_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition, break; case HK_DELETE: - if( !itemInEdit ) - m_drawItem = LocateItemUsingCursor( aPosition ); + if ( !itemInEdit ) + SetDrawItem( LocateItemUsingCursor( aPosition ) ); - if( m_drawItem && !m_drawItem->InEditMode() ) + if( IsEditingDrawItem() ) { cmd.SetId( ID_POPUP_LIBEDIT_DELETE_ITEM ); Process_Special_Functions( cmd ); @@ -805,9 +808,9 @@ bool LIB_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition, case HK_LIBEDIT_MOVE_GRAPHIC_ITEM: if( !itemInEdit ) { - m_drawItem = LocateItemUsingCursor( aPosition ); + SetDrawItem( LocateItemUsingCursor( aPosition ) ); - if( m_drawItem ) + if( GetDrawItem() ) { cmd.SetId( ID_POPUP_LIBEDIT_MOVE_ITEM_REQUEST ); Process_Special_Functions( cmd ); @@ -818,9 +821,9 @@ bool LIB_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition, case HK_DRAG: if( !itemInEdit ) { - m_drawItem = LocateItemUsingCursor( aPosition ); + SetDrawItem( LocateItemUsingCursor( aPosition ) ); - if( m_drawItem && !m_drawItem->InEditMode() ) + if( IsEditingDrawItem() ) { cmd.SetId( ID_POPUP_LIBEDIT_MODIFY_ITEM ); Process_Special_Functions( cmd ); @@ -830,7 +833,7 @@ bool LIB_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition, case HK_MIRROR_Y: // Mirror Y if( !itemInEdit ) - m_drawItem = LocateItemUsingCursor( aPosition ); + SetDrawItem( LocateItemUsingCursor( aPosition ) ); cmd.SetId( ID_LIBEDIT_MIRROR_Y ); GetEventHandler()->ProcessEvent( cmd ); @@ -838,7 +841,7 @@ bool LIB_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition, case HK_MIRROR_X: // Mirror X if( !itemInEdit ) - m_drawItem = LocateItemUsingCursor( aPosition ); + SetDrawItem( LocateItemUsingCursor( aPosition ) ); cmd.SetId( ID_LIBEDIT_MIRROR_X ); GetEventHandler()->ProcessEvent( cmd ); diff --git a/eeschema/lib_collectors.cpp b/eeschema/lib_collectors.cpp index 2a7f1750ad..190eb4cf58 100644 --- a/eeschema/lib_collectors.cpp +++ b/eeschema/lib_collectors.cpp @@ -100,6 +100,7 @@ const KICAD_T LIB_COLLECTOR::DoubleClickItems[] = { LIB_POLYLINE_T, LIB_TEXT_T, LIB_FIELD_T, + LIB_BEZIER_T, EOT }; diff --git a/eeschema/lib_export.cpp b/eeschema/lib_export.cpp index 04f1eb8270..c42b95c2d7 100644 --- a/eeschema/lib_export.cpp +++ b/eeschema/lib_export.cpp @@ -183,7 +183,8 @@ void LIB_EDIT_FRAME::OnExportPart( wxCommandEvent& event ) } m_mruPath = fn.GetPath(); - m_drawItem = m_lastDrawItem = NULL; + m_lastDrawItem = NULL; + SetDrawItem( NULL ); msg.Printf( _( "Symbol \"%s\" saved in library \"%s\"" ), part->GetName(), fn.GetFullPath() ); SetStatusText( msg ); diff --git a/eeschema/libedit.cpp b/eeschema/libedit.cpp index 0f3786c21f..32f7763ba6 100644 --- a/eeschema/libedit.cpp +++ b/eeschema/libedit.cpp @@ -270,7 +270,7 @@ void LIB_EDIT_FRAME::OnRevertLibrary( wxCommandEvent& aEvent ) void LIB_EDIT_FRAME::OnCreateNewPart( wxCommandEvent& event ) { m_canvas->EndMouseCapture( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor() ); - m_drawItem = NULL; + SetDrawItem( NULL ); wxString lib = getTargetLib(); if( !m_libMgr->LibraryExists( lib ) ) @@ -491,7 +491,8 @@ void LIB_EDIT_FRAME::loadPart( const wxString& aAlias, const wxString& aLibrary, return; } - m_lastDrawItem = m_drawItem = nullptr; + m_lastDrawItem = nullptr; + SetDrawItem( NULL ); m_aliasName = aAlias; m_unit = ( aUnit <= part->GetUnitCount() ? aUnit : 1 ); diff --git a/eeschema/libedit_onleftclick.cpp b/eeschema/libedit_onleftclick.cpp index 5c8d5225f5..8915acb223 100644 --- a/eeschema/libedit_onleftclick.cpp +++ b/eeschema/libedit_onleftclick.cpp @@ -40,7 +40,7 @@ void LIB_EDIT_FRAME::OnLeftClick( wxDC* DC, const wxPoint& aPosition ) { - LIB_ITEM* item = m_drawItem; + LIB_ITEM* item = GetDrawItem(); bool item_in_edit = item && item->InEditMode(); bool no_item_edited = !item_in_edit; @@ -104,10 +104,10 @@ void LIB_EDIT_FRAME::OnLeftClick( wxDC* DC, const wxPoint& aPosition ) case ID_LIBEDIT_BODY_RECT_BUTT: case ID_LIBEDIT_BODY_TEXT_BUTT: if( no_item_edited ) - m_drawItem = CreateGraphicItem( part, DC ); - else if( m_drawItem ) + SetDrawItem( CreateGraphicItem( part, DC ) ); + else if( item ) { - if( m_drawItem->IsNew() ) + if( item->IsNew() ) GraphicItemBeginDraw( DC ); else EndDrawGraphicItem( DC ); @@ -115,10 +115,13 @@ void LIB_EDIT_FRAME::OnLeftClick( wxDC* DC, const wxPoint& aPosition ) break; case ID_LIBEDIT_DELETE_ITEM_BUTT: - m_drawItem = LocateItemUsingCursor( aPosition ); + item = LocateItemUsingCursor( aPosition ); - if( m_drawItem ) + if( item ) + { + SetDrawItem( item ); deleteItem( DC ); + } else { DisplayCmpDoc(); @@ -150,39 +153,45 @@ void LIB_EDIT_FRAME::OnLeftClick( wxDC* DC, const wxPoint& aPosition ) void LIB_EDIT_FRAME::OnLeftDClick( wxDC* DC, const wxPoint& aPosition ) { LIB_PART* part = GetCurPart(); + LIB_ITEM* item = GetDrawItem(); if( !part ) return; - if( !m_drawItem || !m_drawItem->InEditMode() ) + if( !item || !item->InEditMode() ) { // We can locate an item - m_drawItem = LocateItemUsingCursor( aPosition, LIB_COLLECTOR::DoubleClickItems ); + item = LocateItemUsingCursor( aPosition, LIB_COLLECTOR::DoubleClickItems ); - if( m_drawItem == NULL ) + if( item == NULL ) { + // The user canceled the disambiguation menu if( m_canvas->GetAbortRequest() ) m_canvas->SetAbortRequest( false ); + else + { + // If there is only a random double-click, we allow the use to edit the part + wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED ); - wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED ); - - cmd.SetId( ID_LIBEDIT_GET_FRAME_EDIT_PART ); - GetEventHandler()->ProcessEvent( cmd ); + cmd.SetId( ID_LIBEDIT_GET_FRAME_EDIT_PART ); + GetEventHandler()->ProcessEvent( cmd ); + } } } - if( m_drawItem ) - SetMsgPanel( m_drawItem ); + if( item ) + SetMsgPanel( item ); else return; m_canvas->SetIgnoreMouseEvents( true ); - bool not_edited = !m_drawItem->InEditMode(); + bool not_edited = !item->InEditMode(); - switch( m_drawItem->Type() ) + switch( item->Type() ) { case LIB_PIN_T: if( not_edited ) { + SetDrawItem( item ); wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED ); cmd.SetId( ID_LIBEDIT_EDIT_PIN ); @@ -194,28 +203,28 @@ void LIB_EDIT_FRAME::OnLeftDClick( wxDC* DC, const wxPoint& aPosition ) case LIB_CIRCLE_T: case LIB_RECTANGLE_T: if( not_edited ) - EditGraphicSymbol( DC, m_drawItem ); + EditGraphicSymbol( DC, item ); break; case LIB_POLYLINE_T: if( not_edited ) - EditGraphicSymbol( DC, m_drawItem ); - else if( m_drawItem->IsNew() ) + EditGraphicSymbol( DC, item ); + else if( item->IsNew() ) EndDrawGraphicItem( DC ); break; case LIB_TEXT_T: if( not_edited ) - EditSymbolText( DC, m_drawItem ); + EditSymbolText( DC, item ); break; case LIB_FIELD_T: if( not_edited ) - EditField( (LIB_FIELD*) m_drawItem ); + EditField( (LIB_FIELD*) item ); break; default: - wxFAIL_MSG( wxT( "Unhandled item <" ) + m_drawItem->GetClass() + wxT( ">" ) ); + wxFAIL_MSG( wxT( "Unhandled item <" ) + item->GetClass() + wxT( ">" ) ); break; } diff --git a/eeschema/libedit_onrightclick.cpp b/eeschema/libedit_onrightclick.cpp index 68388c4727..289e1f6e8f 100644 --- a/eeschema/libedit_onrightclick.cpp +++ b/eeschema/libedit_onrightclick.cpp @@ -102,7 +102,7 @@ bool LIB_EDIT_FRAME::OnRightClick( const wxPoint& aPosition, wxMenu* PopMenu ) return true; } - m_drawItem = item; + SetDrawItem( item ); bool not_edited = !item->InEditMode(); wxString msg; @@ -263,7 +263,7 @@ bool LIB_EDIT_FRAME::OnRightClick( const wxPoint& aPosition, wxMenu* PopMenu ) default: wxFAIL_MSG( wxString::Format( wxT( "Unknown library item type %d" ), item->Type() ) ); - m_drawItem = NULL; + SetDrawItem( NULL ); break; } diff --git a/eeschema/libedit_undo_redo.cpp b/eeschema/libedit_undo_redo.cpp index 1f340259ef..bfc4120ac0 100644 --- a/eeschema/libedit_undo_redo.cpp +++ b/eeschema/libedit_undo_redo.cpp @@ -78,7 +78,7 @@ void LIB_EDIT_FRAME::GetComponentFromRedoList( wxCommandEvent& event ) if( !m_aliasName.IsEmpty() && !part->HasAlias( m_aliasName ) ) m_aliasName = part->GetName(); - m_drawItem = NULL; + SetDrawItem( NULL ); UpdateAliasSelectList(); UpdatePartSelectList(); SetShowDeMorgan( part->HasConversion() ); @@ -121,7 +121,7 @@ void LIB_EDIT_FRAME::GetComponentFromUndoList( wxCommandEvent& event ) if( !m_aliasName.IsEmpty() && !part->HasAlias( m_aliasName ) ) m_aliasName = part->GetName(); - m_drawItem = NULL; + SetDrawItem( NULL ); UpdateAliasSelectList(); UpdatePartSelectList(); SetShowDeMorgan( part->HasConversion() ); diff --git a/eeschema/libeditframe.cpp b/eeschema/libeditframe.cpp index dc2d7ea9c4..508245b5d4 100644 --- a/eeschema/libeditframe.cpp +++ b/eeschema/libeditframe.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -68,7 +69,7 @@ wxString LIB_EDIT_FRAME:: m_aliasName; int LIB_EDIT_FRAME:: m_unit = 1; int LIB_EDIT_FRAME:: m_convert = 1; LIB_ITEM* LIB_EDIT_FRAME::m_lastDrawItem = NULL; -LIB_ITEM* LIB_EDIT_FRAME::m_drawItem = NULL; + bool LIB_EDIT_FRAME:: m_showDeMorgan = false; wxSize LIB_EDIT_FRAME:: m_clientSize = wxSize( -1, -1 ); int LIB_EDIT_FRAME:: m_textSize = -1; @@ -335,7 +336,8 @@ LIB_EDIT_FRAME::~LIB_EDIT_FRAME() // current screen is destroyed in EDA_DRAW_FRAME SetScreen( m_dummyScreen ); - m_drawItem = m_lastDrawItem = NULL; + m_lastDrawItem = NULL; + SetDrawItem( m_lastDrawItem ); delete m_tempCopyComponent; delete m_libMgr; @@ -343,12 +345,6 @@ LIB_EDIT_FRAME::~LIB_EDIT_FRAME() } -void LIB_EDIT_FRAME::SetDrawItem( LIB_ITEM* drawItem ) -{ - m_drawItem = drawItem; -} - - void LIB_EDIT_FRAME::OnCloseWindow( wxCloseEvent& Event ) { if( saveAllLibraries() ) @@ -755,6 +751,7 @@ void LIB_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event ) wxPoint pos; SCH_SCREEN* screen = GetScreen(); BLOCK_SELECTOR& block = screen->m_BlockLocate; + LIB_ITEM* item = screen->GetCurLibItem(); m_canvas->SetIgnoreMouseEvents( true ); @@ -813,28 +810,28 @@ void LIB_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event ) case ID_POPUP_LIBEDIT_END_CREATE_ITEM: m_canvas->MoveCursorToCrossHair(); - if( m_drawItem ) + if( item ) { EndDrawGraphicItem( &dc ); } break; case ID_POPUP_LIBEDIT_BODY_EDIT_ITEM: - if( m_drawItem ) + if( item ) { m_canvas->CrossHairOff( &dc ); - switch( m_drawItem->Type() ) + switch( item->Type() ) { case LIB_ARC_T: case LIB_CIRCLE_T: case LIB_RECTANGLE_T: case LIB_POLYLINE_T: - EditGraphicSymbol( &dc, m_drawItem ); + EditGraphicSymbol( &dc, item ); break; case LIB_TEXT_T: - EditSymbolText( &dc, m_drawItem ); + EditSymbolText( &dc, item ); break; default: @@ -848,33 +845,33 @@ void LIB_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event ) case ID_POPUP_LIBEDIT_DELETE_CURRENT_POLY_SEGMENT: { // Delete the last created segment, while creating a polyline draw item - if( m_drawItem == NULL ) + if( item == NULL ) break; m_canvas->MoveCursorToCrossHair(); - STATUS_FLAGS oldFlags = m_drawItem->GetFlags(); - m_drawItem->ClearFlags(); - m_drawItem->Draw( m_canvas, &dc, wxPoint( 0, 0 ), COLOR4D::UNSPECIFIED, g_XorMode, NULL, + STATUS_FLAGS oldFlags = item->GetFlags(); + item->ClearFlags(); + item->Draw( m_canvas, &dc, wxPoint( 0, 0 ), COLOR4D::UNSPECIFIED, g_XorMode, NULL, DefaultTransform ); - ( (LIB_POLYLINE*) m_drawItem )->DeleteSegment( GetCrossHairPosition( true ) ); - m_drawItem->Draw( m_canvas, &dc, wxPoint( 0, 0 ), COLOR4D::UNSPECIFIED, g_XorMode, NULL, + ( (LIB_POLYLINE*) item )->DeleteSegment( GetCrossHairPosition( true ) ); + item->Draw( m_canvas, &dc, wxPoint( 0, 0 ), COLOR4D::UNSPECIFIED, g_XorMode, NULL, DefaultTransform ); - m_drawItem->SetFlags( oldFlags ); + item->SetFlags( oldFlags ); m_lastDrawItem = NULL; } break; case ID_POPUP_LIBEDIT_DELETE_ITEM: - if( m_drawItem ) + if( item ) deleteItem( &dc ); break; case ID_POPUP_LIBEDIT_MOVE_ITEM_REQUEST: - if( m_drawItem == NULL ) + if( item == NULL ) break; - if( m_drawItem->Type() == LIB_PIN_T ) + if( item->Type() == LIB_PIN_T ) StartMovePin( &dc ); else StartMoveDrawSymbol( &dc ); @@ -882,14 +879,14 @@ void LIB_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event ) case ID_POPUP_LIBEDIT_MODIFY_ITEM: - if( m_drawItem == NULL ) + if( item == NULL ) break; m_canvas->MoveCursorToCrossHair(); - if( m_drawItem->Type() == LIB_RECTANGLE_T - || m_drawItem->Type() == LIB_CIRCLE_T - || m_drawItem->Type() == LIB_POLYLINE_T - || m_drawItem->Type() == LIB_ARC_T + if( item->Type() == LIB_RECTANGLE_T + || item->Type() == LIB_CIRCLE_T + || item->Type() == LIB_POLYLINE_T + || item->Type() == LIB_ARC_T ) { StartModifyDrawSymbol( &dc ); @@ -898,14 +895,14 @@ void LIB_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event ) break; case ID_POPUP_LIBEDIT_FIELD_EDIT_ITEM: - if( m_drawItem == NULL ) + if( item == NULL ) break; m_canvas->CrossHairOff( &dc ); - if( m_drawItem->Type() == LIB_FIELD_T ) + if( item->Type() == LIB_FIELD_T ) { - EditField( (LIB_FIELD*) m_drawItem ); + EditField( (LIB_FIELD*) item ); } m_canvas->MoveCursorToCrossHair(); @@ -916,14 +913,14 @@ void LIB_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event ) case ID_POPUP_LIBEDIT_PIN_GLOBAL_CHANGE_PINNAMESIZE_ITEM: case ID_POPUP_LIBEDIT_PIN_GLOBAL_CHANGE_PINNUMSIZE_ITEM: { - if( !m_drawItem || m_drawItem->Type() != LIB_PIN_T ) + if( !item || item->Type() != LIB_PIN_T ) break; LIB_PART* part = GetCurPart(); SaveCopyInUndoList( part ); - GlobalSetPins( (LIB_PIN*) m_drawItem, id ); + GlobalSetPins( (LIB_PIN*) item, id ); m_canvas->MoveCursorToCrossHair(); m_canvas->Refresh(); } @@ -1255,22 +1252,24 @@ void LIB_EDIT_FRAME::OnSelectTool( wxCommandEvent& aEvent ) void LIB_EDIT_FRAME::OnRotateItem( wxCommandEvent& aEvent ) { - if( m_drawItem == NULL ) + LIB_ITEM* item = GetDrawItem(); + + if( item == NULL ) return; - if( !m_drawItem->InEditMode() ) + if( !item->InEditMode() ) { LIB_PART* part = GetCurPart(); SaveCopyInUndoList( part ); - m_drawItem->SetUnit( m_unit ); + item->SetUnit( m_unit ); } - m_drawItem->Rotate(); + item->Rotate(); OnModify(); - if( !m_drawItem->InEditMode() ) - m_drawItem->ClearFlags(); + if( !item->InEditMode() ) + item->ClearFlags(); m_canvas->Refresh(); @@ -1371,11 +1370,11 @@ LIB_ITEM* LIB_EDIT_FRAME::locateItem( const wxPoint& aPosition, const KICAD_T aF } // Set to NULL in case user aborts the clarification context menu. - m_drawItem = NULL; + SetDrawItem( NULL ); m_canvas->SetAbortRequest( true ); // Changed to false if an item is selected PopupMenu( &selectMenu ); m_canvas->MoveCursorToCrossHair(); - item = m_drawItem; + item = GetDrawItem(); } } @@ -1396,7 +1395,9 @@ LIB_ITEM* LIB_EDIT_FRAME::locateItem( const wxPoint& aPosition, const KICAD_T aF void LIB_EDIT_FRAME::deleteItem( wxDC* aDC ) { - wxCHECK_RET( m_drawItem != NULL, "No drawing item selected to delete." ); + LIB_ITEM* item = GetDrawItem(); + + wxCHECK_RET( item != NULL, "No drawing item selected to delete." ); m_canvas->CrossHairOff( aDC ); @@ -1404,9 +1405,9 @@ void LIB_EDIT_FRAME::deleteItem( wxDC* aDC ) SaveCopyInUndoList( part ); - if( m_drawItem->Type() == LIB_PIN_T ) + if( item->Type() == LIB_PIN_T ) { - LIB_PIN* pin = (LIB_PIN*) m_drawItem; + LIB_PIN* pin = (LIB_PIN*) item; wxPoint pos = pin->GetPosition(); part->RemoveDrawItem( (LIB_ITEM*) pin, m_canvas, aDC ); @@ -1437,12 +1438,12 @@ void LIB_EDIT_FRAME::deleteItem( wxDC* aDC ) } else { - part->RemoveDrawItem( m_drawItem, m_canvas, aDC ); + part->RemoveDrawItem( item, m_canvas, aDC ); m_canvas->Refresh(); } } - m_drawItem = NULL; + SetDrawItem( NULL ); m_lastDrawItem = NULL; OnModify(); m_canvas->CrossHairOn( aDC ); @@ -1467,7 +1468,7 @@ void LIB_EDIT_FRAME::OnSelectItem( wxCommandEvent& aEvent ) { LIB_ITEM* item = m_collectedItems[index]; m_canvas->SetAbortRequest( false ); - m_drawItem = item; + SetDrawItem( item ); } } @@ -1697,7 +1698,8 @@ void LIB_EDIT_FRAME::emptyScreen() SetCurLib( wxEmptyString ); SetCurPart( nullptr ); m_aliasName.Empty(); - m_drawItem = m_lastDrawItem = nullptr; + m_lastDrawItem = nullptr; + SetDrawItem( NULL ); SetScreen( m_dummyScreen ); m_dummyScreen->ClearUndoRedoList(); Zoom_Automatique( false ); diff --git a/eeschema/libeditframe.h b/eeschema/libeditframe.h index 5587f91582..f59e1c9a03 100644 --- a/eeschema/libeditframe.h +++ b/eeschema/libeditframe.h @@ -34,6 +34,7 @@ #define LIBEDITFRM_H_ #include +#include #include #include @@ -97,7 +98,6 @@ class LIB_EDIT_FRAME : public SCH_BASE_FRAME static int m_drawLineWidth; static LIB_ITEM* m_lastDrawItem; - static LIB_ITEM* m_drawItem; static wxString m_aliasName; // The unit number to edit and show @@ -426,9 +426,9 @@ public: m_lastDrawItem = drawItem; } - LIB_ITEM* GetDrawItem() { return m_drawItem; } + LIB_ITEM* GetDrawItem() const { return GetScreen()->GetCurLibItem(); } - void SetDrawItem( LIB_ITEM* drawItem ); + void SetDrawItem( LIB_ITEM* drawItem ) { GetScreen()->SetCurLibItem( drawItem ); } bool GetShowDeMorgan() { return m_showDeMorgan; } @@ -463,7 +463,7 @@ public: */ void ClearTempCopyComponent(); - bool IsEditingDrawItem() { return m_drawItem && m_drawItem->InEditMode(); } + bool IsEditingDrawItem() { return GetDrawItem() && GetDrawItem()->InEditMode(); } private: void loadPart( const wxString& aLibrary, const wxString& aPart, int Unit ); diff --git a/eeschema/pinedit.cpp b/eeschema/pinedit.cpp index 5aba72b18e..7513ae1822 100644 --- a/eeschema/pinedit.cpp +++ b/eeschema/pinedit.cpp @@ -94,11 +94,11 @@ static int GetLastPinNumSize() void LIB_EDIT_FRAME::OnEditPin( wxCommandEvent& event ) { - if( m_drawItem == NULL || m_drawItem->Type() != LIB_PIN_T ) + if( GetDrawItem() == NULL || GetDrawItem()->Type() != LIB_PIN_T ) return; - STATUS_FLAGS item_flags = m_drawItem->GetFlags(); // save flags to restore them after editing - LIB_PIN* pin = (LIB_PIN*) m_drawItem; + STATUS_FLAGS item_flags = GetDrawItem()->GetFlags(); // save flags to restore them after editing + LIB_PIN* pin = (LIB_PIN*) GetDrawItem(); DIALOG_LIB_EDIT_PIN dlg( this, pin ); @@ -240,7 +240,7 @@ static void AbortPinMove( EDA_DRAW_PANEL* Panel, wxDC* DC ) */ void LIB_EDIT_FRAME::PlacePin() { - LIB_PIN* cur_pin = (LIB_PIN*) m_drawItem; + LIB_PIN* cur_pin = (LIB_PIN*) GetDrawItem(); bool ask_for_pin = true; wxPoint newpos; bool status; @@ -298,7 +298,7 @@ void LIB_EDIT_FRAME::PlacePin() CreateImagePins( cur_pin, m_unit, m_convert, m_showDeMorgan ); m_lastDrawItem = cur_pin; - part->AddDrawItem( m_drawItem ); + part->AddDrawItem( GetDrawItem() ); } // Put linked pins in new position, and clear flags @@ -311,7 +311,7 @@ void LIB_EDIT_FRAME::PlacePin() pin->ClearFlags(); } - m_drawItem = NULL; + SetDrawItem( NULL ); OnModify(); m_canvas->Refresh(); @@ -326,7 +326,7 @@ void LIB_EDIT_FRAME::PlacePin() */ void LIB_EDIT_FRAME::StartMovePin( wxDC* DC ) { - LIB_PIN* cur_pin = (LIB_PIN*) m_drawItem; + LIB_PIN* cur_pin = (LIB_PIN*) GetDrawItem(); wxPoint startPos; TempCopyComponent(); @@ -432,7 +432,7 @@ void LIB_EDIT_FRAME::CreatePin( wxDC* DC ) LIB_PIN* pin = new LIB_PIN( part ); - m_drawItem = pin; + SetDrawItem( pin ); pin->SetFlags( IS_NEW ); pin->SetUnit( m_unit ); @@ -649,7 +649,7 @@ void LIB_EDIT_FRAME::RepeatPinItem( wxDC* DC, LIB_PIN* SourcePin ) IncrementLabelMember( msg, GetRepeatDeltaLabel() ); pin->SetNumber( msg ); - m_drawItem = pin; + SetDrawItem( pin ); if( SynchronizePins() ) pin->SetFlags( IS_LINKED ); @@ -660,7 +660,7 @@ void LIB_EDIT_FRAME::RepeatPinItem( wxDC* DC, LIB_PIN* SourcePin ) SetCrossHairPosition( wxPoint( pin->GetPosition().x, -pin->GetPosition().y ) ); // Add this new pin in list, and creates pins for others parts if needed - m_drawItem = pin; + SetDrawItem( pin ); ClearTempCopyComponent(); PlacePin(); m_lastDrawItem = pin; diff --git a/eeschema/symbdraw.cpp b/eeschema/symbdraw.cpp index ca1f2bb2ca..76da79b4eb 100644 --- a/eeschema/symbdraw.cpp +++ b/eeschema/symbdraw.cpp @@ -147,6 +147,7 @@ static void AbortSymbolTraceOn( EDA_DRAW_PANEL* Panel, wxDC* DC ) LIB_ITEM* LIB_EDIT_FRAME::CreateGraphicItem( LIB_PART* LibEntry, wxDC* DC ) { + LIB_ITEM* item = GetDrawItem(); m_canvas->SetMouseCapture( SymbolDisplayDraw, AbortSymbolTraceOn ); wxPoint drawPos = GetCrossHairPosition( true ); @@ -157,19 +158,19 @@ LIB_ITEM* LIB_EDIT_FRAME::CreateGraphicItem( LIB_PART* LibEntry, wxDC* DC ) switch( GetToolId() ) { case ID_LIBEDIT_BODY_ARC_BUTT: - m_drawItem = new LIB_ARC( LibEntry ); + item = new LIB_ARC( LibEntry ); break; case ID_LIBEDIT_BODY_CIRCLE_BUTT: - m_drawItem = new LIB_CIRCLE( LibEntry ); + item = new LIB_CIRCLE( LibEntry ); break; case ID_LIBEDIT_BODY_RECT_BUTT: - m_drawItem = new LIB_RECTANGLE( LibEntry ); + item = new LIB_RECTANGLE( LibEntry ); break; case ID_LIBEDIT_BODY_LINE_BUTT: - m_drawItem = new LIB_POLYLINE( LibEntry ); + item = new LIB_POLYLINE( LibEntry ); break; case ID_LIBEDIT_BODY_TEXT_BUTT: @@ -188,11 +189,11 @@ LIB_ITEM* LIB_EDIT_FRAME::CreateGraphicItem( LIB_PART* LibEntry, wxDC* DC ) if( text->GetText().IsEmpty() ) { delete text; - m_drawItem = NULL; + item = NULL; } else { - m_drawItem = text; + item = text; } } break; @@ -202,22 +203,22 @@ LIB_ITEM* LIB_EDIT_FRAME::CreateGraphicItem( LIB_PART* LibEntry, wxDC* DC ) return NULL; } - if( m_drawItem ) + if( item ) { - m_drawItem->BeginEdit( IS_NEW, drawPos ); + item->BeginEdit( IS_NEW, drawPos ); // Don't set line parameters for text objects. - if( m_drawItem->Type() != LIB_TEXT_T ) + if( item->Type() != LIB_TEXT_T ) { - m_drawItem->SetWidth( m_drawLineWidth ); - m_drawItem->SetFillMode( m_drawFillStyle ); + item->SetWidth( m_drawLineWidth ); + item->SetFillMode( m_drawFillStyle ); } if( m_drawSpecificUnit ) - m_drawItem->SetUnit( m_unit ); + item->SetUnit( m_unit ); if( m_drawSpecificConvert ) - m_drawItem->SetConvert( m_convert ); + item->SetConvert( m_convert ); // Draw initial symbol: m_canvas->CallMouseCapture( DC, wxDefaultPosition, false ); @@ -230,21 +231,22 @@ LIB_ITEM* LIB_EDIT_FRAME::CreateGraphicItem( LIB_PART* LibEntry, wxDC* DC ) m_canvas->MoveCursorToCrossHair(); m_canvas->SetIgnoreMouseEvents( false ); + SetDrawItem( item ); - return m_drawItem; + return item; } void LIB_EDIT_FRAME::GraphicItemBeginDraw( wxDC* DC ) { - if( m_drawItem == NULL ) + if( GetDrawItem() == NULL ) return; wxPoint pos = GetCrossHairPosition( true ); - if( m_drawItem->ContinueEdit( pos ) ) + if( GetDrawItem()->ContinueEdit( pos ) ) { - m_drawItem->Draw( m_canvas, DC, pos, COLOR4D::UNSPECIFIED, g_XorMode, NULL, + GetDrawItem()->Draw( m_canvas, DC, pos, COLOR4D::UNSPECIFIED, g_XorMode, NULL, DefaultTransform ); return; } @@ -287,7 +289,9 @@ static void RedrawWhileMovingCursor( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wx void LIB_EDIT_FRAME::StartMoveDrawSymbol( wxDC* DC ) { - if( m_drawItem == NULL ) + LIB_ITEM* item = GetDrawItem(); + + if( item == NULL ) return; SetCursor( wxCURSOR_HAND ); @@ -296,10 +300,10 @@ void LIB_EDIT_FRAME::StartMoveDrawSymbol( wxDC* DC ) // For fields only, move the anchor point of the field // to the cursor position to allow user to see the text justification - if( m_drawItem->Type() == LIB_FIELD_T ) - m_drawItem->BeginEdit( IS_MOVED, m_drawItem->GetPosition() ); + if( item->Type() == LIB_FIELD_T ) + item->BeginEdit( IS_MOVED, item->GetPosition() ); else - m_drawItem->BeginEdit( IS_MOVED, GetCrossHairPosition( true ) ); + item->BeginEdit( IS_MOVED, GetCrossHairPosition( true ) ); m_canvas->SetMouseCapture( RedrawWhileMovingCursor, AbortSymbolTraceOn ); m_canvas->CallMouseCapture( DC, wxDefaultPosition, true ); @@ -308,11 +312,13 @@ void LIB_EDIT_FRAME::StartMoveDrawSymbol( wxDC* DC ) void LIB_EDIT_FRAME::StartModifyDrawSymbol( wxDC* DC ) { - if( m_drawItem == NULL ) + LIB_ITEM* item = GetDrawItem(); + + if( item == NULL ) return; TempCopyComponent(); - m_drawItem->BeginEdit( IS_RESIZED, GetCrossHairPosition( true ) ); + item->BeginEdit( IS_RESIZED, GetCrossHairPosition( true ) ); m_canvas->SetMouseCapture( SymbolDisplayDraw, AbortSymbolTraceOn ); m_canvas->CallMouseCapture( DC, wxDefaultPosition, true ); } @@ -335,11 +341,13 @@ static void SymbolDisplayDraw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& void LIB_EDIT_FRAME::EndDrawGraphicItem( wxDC* DC ) { + LIB_ITEM* item = GetDrawItem(); + + if( item == NULL ) + return; + if( LIB_PART* part = GetCurPart() ) { - if( !m_drawItem ) - return; - if( GetToolId() != ID_NO_TOOL_SELECTED ) SetCursor( wxCURSOR_PENCIL ); else @@ -354,12 +362,12 @@ void LIB_EDIT_FRAME::EndDrawGraphicItem( wxDC* DC ) SaveCopyInUndoList( part ); } - if( m_drawItem->IsNew() ) - part->AddDrawItem( m_drawItem ); + if( item->IsNew() ) + part->AddDrawItem( item ); - m_drawItem->EndEdit( GetCrossHairPosition( true ) ); + item->EndEdit( GetCrossHairPosition( true ) ); - m_drawItem = NULL; + SetDrawItem( NULL ); OnModify(); diff --git a/eeschema/symbedit.cpp b/eeschema/symbedit.cpp index 7e7dd8a71a..9b2a397b0c 100644 --- a/eeschema/symbedit.cpp +++ b/eeschema/symbedit.cpp @@ -50,7 +50,7 @@ void LIB_EDIT_FRAME::LoadOneSymbol() LIB_PART* part = GetCurPart(); // Exit if no library entry is selected or a command is in progress. - if( !part || ( m_drawItem && m_drawItem->GetFlags() ) ) + if( !part || ( GetDrawItem() && GetDrawItem()->GetFlags() ) ) return; PROJECT& prj = Prj();