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
This commit is contained in:
Seth Hillbrand 2017-12-17 21:21:00 -08:00 committed by Wayne Stambaugh
parent 09cff5d8ed
commit 6073bf3ea7
13 changed files with 167 additions and 139 deletions

View File

@ -33,6 +33,7 @@
#include <macros.h> #include <macros.h>
#include <dlist.h> #include <dlist.h>
#include <sch_item_struct.h> #include <sch_item_struct.h>
#include <lib_draw_item.h>
#include <class_base_screen.h> #include <class_base_screen.h>
#include <class_title_block.h> #include <class_title_block.h>
#include <class_page_info.h> #include <class_page_info.h>
@ -171,6 +172,7 @@ public:
* @return SCH_ITEM* - the one selected, or NULL. * @return SCH_ITEM* - the one selected, or NULL.
*/ */
SCH_ITEM* GetCurItem() const { return (SCH_ITEM*) BASE_SCREEN::GetCurItem(); } 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. * Sets the currently selected object, m_CurrentItem.
@ -178,6 +180,7 @@ public:
* @param aItem Any object derived from SCH_ITEM * @param aItem Any object derived from SCH_ITEM
*/ */
void SetCurItem( SCH_ITEM* aItem ) { BASE_SCREEN::SetCurItem( (EDA_ITEM*) aItem ); } 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. * Delete all draw items and clears the project settings.

View File

@ -674,7 +674,10 @@ bool LIB_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition,
if( hotKey == NULL ) if( hotKey == NULL )
return false; 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; 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; break;
case HK_EDIT: case HK_EDIT:
if( !itemInEdit ) if ( !itemInEdit )
m_drawItem = LocateItemUsingCursor( aPosition ); SetDrawItem( LocateItemUsingCursor( aPosition ) );
if( m_drawItem ) if( GetDrawItem() )
{ {
switch( m_drawItem->Type() ) switch( GetDrawItem()->Type() )
{ {
case LIB_PIN_T: case LIB_PIN_T:
cmd.SetId( ID_LIBEDIT_EDIT_PIN ); cmd.SetId( ID_LIBEDIT_EDIT_PIN );
@ -773,9 +776,9 @@ bool LIB_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition,
else else
{ {
if ( !itemInEdit ) if ( !itemInEdit )
m_drawItem = LocateItemUsingCursor( aPosition ); SetDrawItem( LocateItemUsingCursor( aPosition ) );
if( m_drawItem ) if( GetDrawItem() )
{ {
cmd.SetId( ID_LIBEDIT_ROTATE_ITEM ); cmd.SetId( ID_LIBEDIT_ROTATE_ITEM );
GetEventHandler()->ProcessEvent( cmd ); GetEventHandler()->ProcessEvent( cmd );
@ -792,10 +795,10 @@ bool LIB_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition,
break; break;
case HK_DELETE: case HK_DELETE:
if( !itemInEdit ) if ( !itemInEdit )
m_drawItem = LocateItemUsingCursor( aPosition ); SetDrawItem( LocateItemUsingCursor( aPosition ) );
if( m_drawItem && !m_drawItem->InEditMode() ) if( IsEditingDrawItem() )
{ {
cmd.SetId( ID_POPUP_LIBEDIT_DELETE_ITEM ); cmd.SetId( ID_POPUP_LIBEDIT_DELETE_ITEM );
Process_Special_Functions( cmd ); 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: case HK_LIBEDIT_MOVE_GRAPHIC_ITEM:
if( !itemInEdit ) if( !itemInEdit )
{ {
m_drawItem = LocateItemUsingCursor( aPosition ); SetDrawItem( LocateItemUsingCursor( aPosition ) );
if( m_drawItem ) if( GetDrawItem() )
{ {
cmd.SetId( ID_POPUP_LIBEDIT_MOVE_ITEM_REQUEST ); cmd.SetId( ID_POPUP_LIBEDIT_MOVE_ITEM_REQUEST );
Process_Special_Functions( cmd ); Process_Special_Functions( cmd );
@ -818,9 +821,9 @@ bool LIB_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition,
case HK_DRAG: case HK_DRAG:
if( !itemInEdit ) if( !itemInEdit )
{ {
m_drawItem = LocateItemUsingCursor( aPosition ); SetDrawItem( LocateItemUsingCursor( aPosition ) );
if( m_drawItem && !m_drawItem->InEditMode() ) if( IsEditingDrawItem() )
{ {
cmd.SetId( ID_POPUP_LIBEDIT_MODIFY_ITEM ); cmd.SetId( ID_POPUP_LIBEDIT_MODIFY_ITEM );
Process_Special_Functions( cmd ); 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 case HK_MIRROR_Y: // Mirror Y
if( !itemInEdit ) if( !itemInEdit )
m_drawItem = LocateItemUsingCursor( aPosition ); SetDrawItem( LocateItemUsingCursor( aPosition ) );
cmd.SetId( ID_LIBEDIT_MIRROR_Y ); cmd.SetId( ID_LIBEDIT_MIRROR_Y );
GetEventHandler()->ProcessEvent( cmd ); 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 case HK_MIRROR_X: // Mirror X
if( !itemInEdit ) if( !itemInEdit )
m_drawItem = LocateItemUsingCursor( aPosition ); SetDrawItem( LocateItemUsingCursor( aPosition ) );
cmd.SetId( ID_LIBEDIT_MIRROR_X ); cmd.SetId( ID_LIBEDIT_MIRROR_X );
GetEventHandler()->ProcessEvent( cmd ); GetEventHandler()->ProcessEvent( cmd );

View File

@ -100,6 +100,7 @@ const KICAD_T LIB_COLLECTOR::DoubleClickItems[] = {
LIB_POLYLINE_T, LIB_POLYLINE_T,
LIB_TEXT_T, LIB_TEXT_T,
LIB_FIELD_T, LIB_FIELD_T,
LIB_BEZIER_T,
EOT EOT
}; };

View File

@ -183,7 +183,8 @@ void LIB_EDIT_FRAME::OnExportPart( wxCommandEvent& event )
} }
m_mruPath = fn.GetPath(); 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() ); msg.Printf( _( "Symbol \"%s\" saved in library \"%s\"" ), part->GetName(), fn.GetFullPath() );
SetStatusText( msg ); SetStatusText( msg );

View File

@ -270,7 +270,7 @@ void LIB_EDIT_FRAME::OnRevertLibrary( wxCommandEvent& aEvent )
void LIB_EDIT_FRAME::OnCreateNewPart( wxCommandEvent& event ) void LIB_EDIT_FRAME::OnCreateNewPart( wxCommandEvent& event )
{ {
m_canvas->EndMouseCapture( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor() ); m_canvas->EndMouseCapture( ID_NO_TOOL_SELECTED, m_canvas->GetDefaultCursor() );
m_drawItem = NULL; SetDrawItem( NULL );
wxString lib = getTargetLib(); wxString lib = getTargetLib();
if( !m_libMgr->LibraryExists( lib ) ) if( !m_libMgr->LibraryExists( lib ) )
@ -491,7 +491,8 @@ void LIB_EDIT_FRAME::loadPart( const wxString& aAlias, const wxString& aLibrary,
return; return;
} }
m_lastDrawItem = m_drawItem = nullptr; m_lastDrawItem = nullptr;
SetDrawItem( NULL );
m_aliasName = aAlias; m_aliasName = aAlias;
m_unit = ( aUnit <= part->GetUnitCount() ? aUnit : 1 ); m_unit = ( aUnit <= part->GetUnitCount() ? aUnit : 1 );

View File

@ -40,7 +40,7 @@
void LIB_EDIT_FRAME::OnLeftClick( wxDC* DC, const wxPoint& aPosition ) 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 item_in_edit = item && item->InEditMode();
bool no_item_edited = !item_in_edit; 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_RECT_BUTT:
case ID_LIBEDIT_BODY_TEXT_BUTT: case ID_LIBEDIT_BODY_TEXT_BUTT:
if( no_item_edited ) if( no_item_edited )
m_drawItem = CreateGraphicItem( part, DC ); SetDrawItem( CreateGraphicItem( part, DC ) );
else if( m_drawItem ) else if( item )
{ {
if( m_drawItem->IsNew() ) if( item->IsNew() )
GraphicItemBeginDraw( DC ); GraphicItemBeginDraw( DC );
else else
EndDrawGraphicItem( DC ); EndDrawGraphicItem( DC );
@ -115,10 +115,13 @@ void LIB_EDIT_FRAME::OnLeftClick( wxDC* DC, const wxPoint& aPosition )
break; break;
case ID_LIBEDIT_DELETE_ITEM_BUTT: case ID_LIBEDIT_DELETE_ITEM_BUTT:
m_drawItem = LocateItemUsingCursor( aPosition ); item = LocateItemUsingCursor( aPosition );
if( m_drawItem ) if( item )
{
SetDrawItem( item );
deleteItem( DC ); deleteItem( DC );
}
else else
{ {
DisplayCmpDoc(); 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 ) void LIB_EDIT_FRAME::OnLeftDClick( wxDC* DC, const wxPoint& aPosition )
{ {
LIB_PART* part = GetCurPart(); LIB_PART* part = GetCurPart();
LIB_ITEM* item = GetDrawItem();
if( !part ) if( !part )
return; return;
if( !m_drawItem || !m_drawItem->InEditMode() ) if( !item || !item->InEditMode() )
{ // We can locate an item { // 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() ) if( m_canvas->GetAbortRequest() )
m_canvas->SetAbortRequest( false ); 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 ) if( item )
SetMsgPanel( m_drawItem ); SetMsgPanel( item );
else else
return; return;
m_canvas->SetIgnoreMouseEvents( true ); 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: case LIB_PIN_T:
if( not_edited ) if( not_edited )
{ {
SetDrawItem( item );
wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED ); wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED );
cmd.SetId( ID_LIBEDIT_EDIT_PIN ); 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_CIRCLE_T:
case LIB_RECTANGLE_T: case LIB_RECTANGLE_T:
if( not_edited ) if( not_edited )
EditGraphicSymbol( DC, m_drawItem ); EditGraphicSymbol( DC, item );
break; break;
case LIB_POLYLINE_T: case LIB_POLYLINE_T:
if( not_edited ) if( not_edited )
EditGraphicSymbol( DC, m_drawItem ); EditGraphicSymbol( DC, item );
else if( m_drawItem->IsNew() ) else if( item->IsNew() )
EndDrawGraphicItem( DC ); EndDrawGraphicItem( DC );
break; break;
case LIB_TEXT_T: case LIB_TEXT_T:
if( not_edited ) if( not_edited )
EditSymbolText( DC, m_drawItem ); EditSymbolText( DC, item );
break; break;
case LIB_FIELD_T: case LIB_FIELD_T:
if( not_edited ) if( not_edited )
EditField( (LIB_FIELD*) m_drawItem ); EditField( (LIB_FIELD*) item );
break; break;
default: default:
wxFAIL_MSG( wxT( "Unhandled item <" ) + m_drawItem->GetClass() + wxT( ">" ) ); wxFAIL_MSG( wxT( "Unhandled item <" ) + item->GetClass() + wxT( ">" ) );
break; break;
} }

View File

@ -102,7 +102,7 @@ bool LIB_EDIT_FRAME::OnRightClick( const wxPoint& aPosition, wxMenu* PopMenu )
return true; return true;
} }
m_drawItem = item; SetDrawItem( item );
bool not_edited = !item->InEditMode(); bool not_edited = !item->InEditMode();
wxString msg; wxString msg;
@ -263,7 +263,7 @@ bool LIB_EDIT_FRAME::OnRightClick( const wxPoint& aPosition, wxMenu* PopMenu )
default: default:
wxFAIL_MSG( wxString::Format( wxT( "Unknown library item type %d" ), wxFAIL_MSG( wxString::Format( wxT( "Unknown library item type %d" ),
item->Type() ) ); item->Type() ) );
m_drawItem = NULL; SetDrawItem( NULL );
break; break;
} }

View File

@ -78,7 +78,7 @@ void LIB_EDIT_FRAME::GetComponentFromRedoList( wxCommandEvent& event )
if( !m_aliasName.IsEmpty() && !part->HasAlias( m_aliasName ) ) if( !m_aliasName.IsEmpty() && !part->HasAlias( m_aliasName ) )
m_aliasName = part->GetName(); m_aliasName = part->GetName();
m_drawItem = NULL; SetDrawItem( NULL );
UpdateAliasSelectList(); UpdateAliasSelectList();
UpdatePartSelectList(); UpdatePartSelectList();
SetShowDeMorgan( part->HasConversion() ); SetShowDeMorgan( part->HasConversion() );
@ -121,7 +121,7 @@ void LIB_EDIT_FRAME::GetComponentFromUndoList( wxCommandEvent& event )
if( !m_aliasName.IsEmpty() && !part->HasAlias( m_aliasName ) ) if( !m_aliasName.IsEmpty() && !part->HasAlias( m_aliasName ) )
m_aliasName = part->GetName(); m_aliasName = part->GetName();
m_drawItem = NULL; SetDrawItem( NULL );
UpdateAliasSelectList(); UpdateAliasSelectList();
UpdatePartSelectList(); UpdatePartSelectList();
SetShowDeMorgan( part->HasConversion() ); SetShowDeMorgan( part->HasConversion() );

View File

@ -32,6 +32,7 @@
#include <pgm_base.h> #include <pgm_base.h>
#include <kiface_i.h> #include <kiface_i.h>
#include <class_drawpanel.h> #include <class_drawpanel.h>
#include <class_base_screen.h>
#include <confirm.h> #include <confirm.h>
#include <eda_doc.h> #include <eda_doc.h>
#include <gr_basic.h> #include <gr_basic.h>
@ -68,7 +69,7 @@ wxString LIB_EDIT_FRAME:: m_aliasName;
int LIB_EDIT_FRAME:: m_unit = 1; int LIB_EDIT_FRAME:: m_unit = 1;
int LIB_EDIT_FRAME:: m_convert = 1; int LIB_EDIT_FRAME:: m_convert = 1;
LIB_ITEM* LIB_EDIT_FRAME::m_lastDrawItem = NULL; LIB_ITEM* LIB_EDIT_FRAME::m_lastDrawItem = NULL;
LIB_ITEM* LIB_EDIT_FRAME::m_drawItem = NULL;
bool LIB_EDIT_FRAME:: m_showDeMorgan = false; bool LIB_EDIT_FRAME:: m_showDeMorgan = false;
wxSize LIB_EDIT_FRAME:: m_clientSize = wxSize( -1, -1 ); wxSize LIB_EDIT_FRAME:: m_clientSize = wxSize( -1, -1 );
int LIB_EDIT_FRAME:: m_textSize = -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 // current screen is destroyed in EDA_DRAW_FRAME
SetScreen( m_dummyScreen ); SetScreen( m_dummyScreen );
m_drawItem = m_lastDrawItem = NULL; m_lastDrawItem = NULL;
SetDrawItem( m_lastDrawItem );
delete m_tempCopyComponent; delete m_tempCopyComponent;
delete m_libMgr; 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 ) void LIB_EDIT_FRAME::OnCloseWindow( wxCloseEvent& Event )
{ {
if( saveAllLibraries() ) if( saveAllLibraries() )
@ -755,6 +751,7 @@ void LIB_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event )
wxPoint pos; wxPoint pos;
SCH_SCREEN* screen = GetScreen(); SCH_SCREEN* screen = GetScreen();
BLOCK_SELECTOR& block = screen->m_BlockLocate; BLOCK_SELECTOR& block = screen->m_BlockLocate;
LIB_ITEM* item = screen->GetCurLibItem();
m_canvas->SetIgnoreMouseEvents( true ); m_canvas->SetIgnoreMouseEvents( true );
@ -813,28 +810,28 @@ void LIB_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event )
case ID_POPUP_LIBEDIT_END_CREATE_ITEM: case ID_POPUP_LIBEDIT_END_CREATE_ITEM:
m_canvas->MoveCursorToCrossHair(); m_canvas->MoveCursorToCrossHair();
if( m_drawItem ) if( item )
{ {
EndDrawGraphicItem( &dc ); EndDrawGraphicItem( &dc );
} }
break; break;
case ID_POPUP_LIBEDIT_BODY_EDIT_ITEM: case ID_POPUP_LIBEDIT_BODY_EDIT_ITEM:
if( m_drawItem ) if( item )
{ {
m_canvas->CrossHairOff( &dc ); m_canvas->CrossHairOff( &dc );
switch( m_drawItem->Type() ) switch( item->Type() )
{ {
case LIB_ARC_T: case LIB_ARC_T:
case LIB_CIRCLE_T: case LIB_CIRCLE_T:
case LIB_RECTANGLE_T: case LIB_RECTANGLE_T:
case LIB_POLYLINE_T: case LIB_POLYLINE_T:
EditGraphicSymbol( &dc, m_drawItem ); EditGraphicSymbol( &dc, item );
break; break;
case LIB_TEXT_T: case LIB_TEXT_T:
EditSymbolText( &dc, m_drawItem ); EditSymbolText( &dc, item );
break; break;
default: default:
@ -848,33 +845,33 @@ void LIB_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event )
case ID_POPUP_LIBEDIT_DELETE_CURRENT_POLY_SEGMENT: case ID_POPUP_LIBEDIT_DELETE_CURRENT_POLY_SEGMENT:
{ {
// Delete the last created segment, while creating a polyline draw item // Delete the last created segment, while creating a polyline draw item
if( m_drawItem == NULL ) if( item == NULL )
break; break;
m_canvas->MoveCursorToCrossHair(); m_canvas->MoveCursorToCrossHair();
STATUS_FLAGS oldFlags = m_drawItem->GetFlags(); STATUS_FLAGS oldFlags = item->GetFlags();
m_drawItem->ClearFlags(); item->ClearFlags();
m_drawItem->Draw( m_canvas, &dc, wxPoint( 0, 0 ), COLOR4D::UNSPECIFIED, g_XorMode, NULL, item->Draw( m_canvas, &dc, wxPoint( 0, 0 ), COLOR4D::UNSPECIFIED, g_XorMode, NULL,
DefaultTransform ); DefaultTransform );
( (LIB_POLYLINE*) m_drawItem )->DeleteSegment( GetCrossHairPosition( true ) ); ( (LIB_POLYLINE*) item )->DeleteSegment( GetCrossHairPosition( true ) );
m_drawItem->Draw( m_canvas, &dc, wxPoint( 0, 0 ), COLOR4D::UNSPECIFIED, g_XorMode, NULL, item->Draw( m_canvas, &dc, wxPoint( 0, 0 ), COLOR4D::UNSPECIFIED, g_XorMode, NULL,
DefaultTransform ); DefaultTransform );
m_drawItem->SetFlags( oldFlags ); item->SetFlags( oldFlags );
m_lastDrawItem = NULL; m_lastDrawItem = NULL;
} }
break; break;
case ID_POPUP_LIBEDIT_DELETE_ITEM: case ID_POPUP_LIBEDIT_DELETE_ITEM:
if( m_drawItem ) if( item )
deleteItem( &dc ); deleteItem( &dc );
break; break;
case ID_POPUP_LIBEDIT_MOVE_ITEM_REQUEST: case ID_POPUP_LIBEDIT_MOVE_ITEM_REQUEST:
if( m_drawItem == NULL ) if( item == NULL )
break; break;
if( m_drawItem->Type() == LIB_PIN_T ) if( item->Type() == LIB_PIN_T )
StartMovePin( &dc ); StartMovePin( &dc );
else else
StartMoveDrawSymbol( &dc ); StartMoveDrawSymbol( &dc );
@ -882,14 +879,14 @@ void LIB_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event )
case ID_POPUP_LIBEDIT_MODIFY_ITEM: case ID_POPUP_LIBEDIT_MODIFY_ITEM:
if( m_drawItem == NULL ) if( item == NULL )
break; break;
m_canvas->MoveCursorToCrossHair(); m_canvas->MoveCursorToCrossHair();
if( m_drawItem->Type() == LIB_RECTANGLE_T if( item->Type() == LIB_RECTANGLE_T
|| m_drawItem->Type() == LIB_CIRCLE_T || item->Type() == LIB_CIRCLE_T
|| m_drawItem->Type() == LIB_POLYLINE_T || item->Type() == LIB_POLYLINE_T
|| m_drawItem->Type() == LIB_ARC_T || item->Type() == LIB_ARC_T
) )
{ {
StartModifyDrawSymbol( &dc ); StartModifyDrawSymbol( &dc );
@ -898,14 +895,14 @@ void LIB_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event )
break; break;
case ID_POPUP_LIBEDIT_FIELD_EDIT_ITEM: case ID_POPUP_LIBEDIT_FIELD_EDIT_ITEM:
if( m_drawItem == NULL ) if( item == NULL )
break; break;
m_canvas->CrossHairOff( &dc ); 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(); 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_PINNAMESIZE_ITEM:
case ID_POPUP_LIBEDIT_PIN_GLOBAL_CHANGE_PINNUMSIZE_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; break;
LIB_PART* part = GetCurPart(); LIB_PART* part = GetCurPart();
SaveCopyInUndoList( part ); SaveCopyInUndoList( part );
GlobalSetPins( (LIB_PIN*) m_drawItem, id ); GlobalSetPins( (LIB_PIN*) item, id );
m_canvas->MoveCursorToCrossHair(); m_canvas->MoveCursorToCrossHair();
m_canvas->Refresh(); m_canvas->Refresh();
} }
@ -1255,22 +1252,24 @@ void LIB_EDIT_FRAME::OnSelectTool( wxCommandEvent& aEvent )
void LIB_EDIT_FRAME::OnRotateItem( wxCommandEvent& aEvent ) void LIB_EDIT_FRAME::OnRotateItem( wxCommandEvent& aEvent )
{ {
if( m_drawItem == NULL ) LIB_ITEM* item = GetDrawItem();
if( item == NULL )
return; return;
if( !m_drawItem->InEditMode() ) if( !item->InEditMode() )
{ {
LIB_PART* part = GetCurPart(); LIB_PART* part = GetCurPart();
SaveCopyInUndoList( part ); SaveCopyInUndoList( part );
m_drawItem->SetUnit( m_unit ); item->SetUnit( m_unit );
} }
m_drawItem->Rotate(); item->Rotate();
OnModify(); OnModify();
if( !m_drawItem->InEditMode() ) if( !item->InEditMode() )
m_drawItem->ClearFlags(); item->ClearFlags();
m_canvas->Refresh(); 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. // 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 m_canvas->SetAbortRequest( true ); // Changed to false if an item is selected
PopupMenu( &selectMenu ); PopupMenu( &selectMenu );
m_canvas->MoveCursorToCrossHair(); 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 ) 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 ); m_canvas->CrossHairOff( aDC );
@ -1404,9 +1405,9 @@ void LIB_EDIT_FRAME::deleteItem( wxDC* aDC )
SaveCopyInUndoList( part ); 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(); wxPoint pos = pin->GetPosition();
part->RemoveDrawItem( (LIB_ITEM*) pin, m_canvas, aDC ); part->RemoveDrawItem( (LIB_ITEM*) pin, m_canvas, aDC );
@ -1437,12 +1438,12 @@ void LIB_EDIT_FRAME::deleteItem( wxDC* aDC )
} }
else else
{ {
part->RemoveDrawItem( m_drawItem, m_canvas, aDC ); part->RemoveDrawItem( item, m_canvas, aDC );
m_canvas->Refresh(); m_canvas->Refresh();
} }
} }
m_drawItem = NULL; SetDrawItem( NULL );
m_lastDrawItem = NULL; m_lastDrawItem = NULL;
OnModify(); OnModify();
m_canvas->CrossHairOn( aDC ); m_canvas->CrossHairOn( aDC );
@ -1467,7 +1468,7 @@ void LIB_EDIT_FRAME::OnSelectItem( wxCommandEvent& aEvent )
{ {
LIB_ITEM* item = m_collectedItems[index]; LIB_ITEM* item = m_collectedItems[index];
m_canvas->SetAbortRequest( false ); m_canvas->SetAbortRequest( false );
m_drawItem = item; SetDrawItem( item );
} }
} }
@ -1697,7 +1698,8 @@ void LIB_EDIT_FRAME::emptyScreen()
SetCurLib( wxEmptyString ); SetCurLib( wxEmptyString );
SetCurPart( nullptr ); SetCurPart( nullptr );
m_aliasName.Empty(); m_aliasName.Empty();
m_drawItem = m_lastDrawItem = nullptr; m_lastDrawItem = nullptr;
SetDrawItem( NULL );
SetScreen( m_dummyScreen ); SetScreen( m_dummyScreen );
m_dummyScreen->ClearUndoRedoList(); m_dummyScreen->ClearUndoRedoList();
Zoom_Automatique( false ); Zoom_Automatique( false );

View File

@ -34,6 +34,7 @@
#define LIBEDITFRM_H_ #define LIBEDITFRM_H_
#include <sch_base_frame.h> #include <sch_base_frame.h>
#include <class_base_screen.h>
#include <class_sch_screen.h> #include <class_sch_screen.h>
#include <lib_draw_item.h> #include <lib_draw_item.h>
@ -97,7 +98,6 @@ class LIB_EDIT_FRAME : public SCH_BASE_FRAME
static int m_drawLineWidth; static int m_drawLineWidth;
static LIB_ITEM* m_lastDrawItem; static LIB_ITEM* m_lastDrawItem;
static LIB_ITEM* m_drawItem;
static wxString m_aliasName; static wxString m_aliasName;
// The unit number to edit and show // The unit number to edit and show
@ -426,9 +426,9 @@ public:
m_lastDrawItem = drawItem; 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; } bool GetShowDeMorgan() { return m_showDeMorgan; }
@ -463,7 +463,7 @@ public:
*/ */
void ClearTempCopyComponent(); void ClearTempCopyComponent();
bool IsEditingDrawItem() { return m_drawItem && m_drawItem->InEditMode(); } bool IsEditingDrawItem() { return GetDrawItem() && GetDrawItem()->InEditMode(); }
private: private:
void loadPart( const wxString& aLibrary, const wxString& aPart, int Unit ); void loadPart( const wxString& aLibrary, const wxString& aPart, int Unit );

View File

@ -94,11 +94,11 @@ static int GetLastPinNumSize()
void LIB_EDIT_FRAME::OnEditPin( wxCommandEvent& event ) 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; return;
STATUS_FLAGS item_flags = m_drawItem->GetFlags(); // save flags to restore them after editing STATUS_FLAGS item_flags = GetDrawItem()->GetFlags(); // save flags to restore them after editing
LIB_PIN* pin = (LIB_PIN*) m_drawItem; LIB_PIN* pin = (LIB_PIN*) GetDrawItem();
DIALOG_LIB_EDIT_PIN dlg( this, pin ); 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() 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; bool ask_for_pin = true;
wxPoint newpos; wxPoint newpos;
bool status; bool status;
@ -298,7 +298,7 @@ void LIB_EDIT_FRAME::PlacePin()
CreateImagePins( cur_pin, m_unit, m_convert, m_showDeMorgan ); CreateImagePins( cur_pin, m_unit, m_convert, m_showDeMorgan );
m_lastDrawItem = cur_pin; m_lastDrawItem = cur_pin;
part->AddDrawItem( m_drawItem ); part->AddDrawItem( GetDrawItem() );
} }
// Put linked pins in new position, and clear flags // Put linked pins in new position, and clear flags
@ -311,7 +311,7 @@ void LIB_EDIT_FRAME::PlacePin()
pin->ClearFlags(); pin->ClearFlags();
} }
m_drawItem = NULL; SetDrawItem( NULL );
OnModify(); OnModify();
m_canvas->Refresh(); m_canvas->Refresh();
@ -326,7 +326,7 @@ void LIB_EDIT_FRAME::PlacePin()
*/ */
void LIB_EDIT_FRAME::StartMovePin( wxDC* DC ) void LIB_EDIT_FRAME::StartMovePin( wxDC* DC )
{ {
LIB_PIN* cur_pin = (LIB_PIN*) m_drawItem; LIB_PIN* cur_pin = (LIB_PIN*) GetDrawItem();
wxPoint startPos; wxPoint startPos;
TempCopyComponent(); TempCopyComponent();
@ -432,7 +432,7 @@ void LIB_EDIT_FRAME::CreatePin( wxDC* DC )
LIB_PIN* pin = new LIB_PIN( part ); LIB_PIN* pin = new LIB_PIN( part );
m_drawItem = pin; SetDrawItem( pin );
pin->SetFlags( IS_NEW ); pin->SetFlags( IS_NEW );
pin->SetUnit( m_unit ); pin->SetUnit( m_unit );
@ -649,7 +649,7 @@ void LIB_EDIT_FRAME::RepeatPinItem( wxDC* DC, LIB_PIN* SourcePin )
IncrementLabelMember( msg, GetRepeatDeltaLabel() ); IncrementLabelMember( msg, GetRepeatDeltaLabel() );
pin->SetNumber( msg ); pin->SetNumber( msg );
m_drawItem = pin; SetDrawItem( pin );
if( SynchronizePins() ) if( SynchronizePins() )
pin->SetFlags( IS_LINKED ); 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 ) ); SetCrossHairPosition( wxPoint( pin->GetPosition().x, -pin->GetPosition().y ) );
// Add this new pin in list, and creates pins for others parts if needed // Add this new pin in list, and creates pins for others parts if needed
m_drawItem = pin; SetDrawItem( pin );
ClearTempCopyComponent(); ClearTempCopyComponent();
PlacePin(); PlacePin();
m_lastDrawItem = pin; m_lastDrawItem = pin;

View File

@ -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* LIB_EDIT_FRAME::CreateGraphicItem( LIB_PART* LibEntry, wxDC* DC )
{ {
LIB_ITEM* item = GetDrawItem();
m_canvas->SetMouseCapture( SymbolDisplayDraw, AbortSymbolTraceOn ); m_canvas->SetMouseCapture( SymbolDisplayDraw, AbortSymbolTraceOn );
wxPoint drawPos = GetCrossHairPosition( true ); wxPoint drawPos = GetCrossHairPosition( true );
@ -157,19 +158,19 @@ LIB_ITEM* LIB_EDIT_FRAME::CreateGraphicItem( LIB_PART* LibEntry, wxDC* DC )
switch( GetToolId() ) switch( GetToolId() )
{ {
case ID_LIBEDIT_BODY_ARC_BUTT: case ID_LIBEDIT_BODY_ARC_BUTT:
m_drawItem = new LIB_ARC( LibEntry ); item = new LIB_ARC( LibEntry );
break; break;
case ID_LIBEDIT_BODY_CIRCLE_BUTT: case ID_LIBEDIT_BODY_CIRCLE_BUTT:
m_drawItem = new LIB_CIRCLE( LibEntry ); item = new LIB_CIRCLE( LibEntry );
break; break;
case ID_LIBEDIT_BODY_RECT_BUTT: case ID_LIBEDIT_BODY_RECT_BUTT:
m_drawItem = new LIB_RECTANGLE( LibEntry ); item = new LIB_RECTANGLE( LibEntry );
break; break;
case ID_LIBEDIT_BODY_LINE_BUTT: case ID_LIBEDIT_BODY_LINE_BUTT:
m_drawItem = new LIB_POLYLINE( LibEntry ); item = new LIB_POLYLINE( LibEntry );
break; break;
case ID_LIBEDIT_BODY_TEXT_BUTT: 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() ) if( text->GetText().IsEmpty() )
{ {
delete text; delete text;
m_drawItem = NULL; item = NULL;
} }
else else
{ {
m_drawItem = text; item = text;
} }
} }
break; break;
@ -202,22 +203,22 @@ LIB_ITEM* LIB_EDIT_FRAME::CreateGraphicItem( LIB_PART* LibEntry, wxDC* DC )
return NULL; 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. // 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 ); item->SetWidth( m_drawLineWidth );
m_drawItem->SetFillMode( m_drawFillStyle ); item->SetFillMode( m_drawFillStyle );
} }
if( m_drawSpecificUnit ) if( m_drawSpecificUnit )
m_drawItem->SetUnit( m_unit ); item->SetUnit( m_unit );
if( m_drawSpecificConvert ) if( m_drawSpecificConvert )
m_drawItem->SetConvert( m_convert ); item->SetConvert( m_convert );
// Draw initial symbol: // Draw initial symbol:
m_canvas->CallMouseCapture( DC, wxDefaultPosition, false ); 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->MoveCursorToCrossHair();
m_canvas->SetIgnoreMouseEvents( false ); m_canvas->SetIgnoreMouseEvents( false );
SetDrawItem( item );
return m_drawItem; return item;
} }
void LIB_EDIT_FRAME::GraphicItemBeginDraw( wxDC* DC ) void LIB_EDIT_FRAME::GraphicItemBeginDraw( wxDC* DC )
{ {
if( m_drawItem == NULL ) if( GetDrawItem() == NULL )
return; return;
wxPoint pos = GetCrossHairPosition( true ); 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 ); DefaultTransform );
return; return;
} }
@ -287,7 +289,9 @@ static void RedrawWhileMovingCursor( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wx
void LIB_EDIT_FRAME::StartMoveDrawSymbol( wxDC* DC ) void LIB_EDIT_FRAME::StartMoveDrawSymbol( wxDC* DC )
{ {
if( m_drawItem == NULL ) LIB_ITEM* item = GetDrawItem();
if( item == NULL )
return; return;
SetCursor( wxCURSOR_HAND ); SetCursor( wxCURSOR_HAND );
@ -296,10 +300,10 @@ void LIB_EDIT_FRAME::StartMoveDrawSymbol( wxDC* DC )
// For fields only, move the anchor point of the field // For fields only, move the anchor point of the field
// to the cursor position to allow user to see the text justification // to the cursor position to allow user to see the text justification
if( m_drawItem->Type() == LIB_FIELD_T ) if( item->Type() == LIB_FIELD_T )
m_drawItem->BeginEdit( IS_MOVED, m_drawItem->GetPosition() ); item->BeginEdit( IS_MOVED, item->GetPosition() );
else else
m_drawItem->BeginEdit( IS_MOVED, GetCrossHairPosition( true ) ); item->BeginEdit( IS_MOVED, GetCrossHairPosition( true ) );
m_canvas->SetMouseCapture( RedrawWhileMovingCursor, AbortSymbolTraceOn ); m_canvas->SetMouseCapture( RedrawWhileMovingCursor, AbortSymbolTraceOn );
m_canvas->CallMouseCapture( DC, wxDefaultPosition, true ); m_canvas->CallMouseCapture( DC, wxDefaultPosition, true );
@ -308,11 +312,13 @@ void LIB_EDIT_FRAME::StartMoveDrawSymbol( wxDC* DC )
void LIB_EDIT_FRAME::StartModifyDrawSymbol( wxDC* DC ) void LIB_EDIT_FRAME::StartModifyDrawSymbol( wxDC* DC )
{ {
if( m_drawItem == NULL ) LIB_ITEM* item = GetDrawItem();
if( item == NULL )
return; return;
TempCopyComponent(); TempCopyComponent();
m_drawItem->BeginEdit( IS_RESIZED, GetCrossHairPosition( true ) ); item->BeginEdit( IS_RESIZED, GetCrossHairPosition( true ) );
m_canvas->SetMouseCapture( SymbolDisplayDraw, AbortSymbolTraceOn ); m_canvas->SetMouseCapture( SymbolDisplayDraw, AbortSymbolTraceOn );
m_canvas->CallMouseCapture( DC, wxDefaultPosition, true ); 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 ) void LIB_EDIT_FRAME::EndDrawGraphicItem( wxDC* DC )
{ {
LIB_ITEM* item = GetDrawItem();
if( item == NULL )
return;
if( LIB_PART* part = GetCurPart() ) if( LIB_PART* part = GetCurPart() )
{ {
if( !m_drawItem )
return;
if( GetToolId() != ID_NO_TOOL_SELECTED ) if( GetToolId() != ID_NO_TOOL_SELECTED )
SetCursor( wxCURSOR_PENCIL ); SetCursor( wxCURSOR_PENCIL );
else else
@ -354,12 +362,12 @@ void LIB_EDIT_FRAME::EndDrawGraphicItem( wxDC* DC )
SaveCopyInUndoList( part ); SaveCopyInUndoList( part );
} }
if( m_drawItem->IsNew() ) if( item->IsNew() )
part->AddDrawItem( m_drawItem ); part->AddDrawItem( item );
m_drawItem->EndEdit( GetCrossHairPosition( true ) ); item->EndEdit( GetCrossHairPosition( true ) );
m_drawItem = NULL; SetDrawItem( NULL );
OnModify(); OnModify();

View File

@ -50,7 +50,7 @@ void LIB_EDIT_FRAME::LoadOneSymbol()
LIB_PART* part = GetCurPart(); LIB_PART* part = GetCurPart();
// Exit if no library entry is selected or a command is in progress. // 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; return;
PROJECT& prj = Prj(); PROJECT& prj = Prj();