Commit 4d1cdfd4 authored by Wayne Stambaugh's avatar Wayne Stambaugh

Schematic component library editor delete item improvements.

* Merge two duplicate case statement and delete pin code paths into a
  single delete function.
* Make all delete commands use new delete function.
* Fix a few set tool ID calls to use default cursor instead of arrow
  cursor.
parent cb647737
...@@ -426,14 +426,15 @@ from component %s in library %s." ), ...@@ -426,14 +426,15 @@ from component %s in library %s." ),
LIB_DRAW_ITEM_LIST::iterator i; LIB_DRAW_ITEM_LIST::iterator i;
if( aDc != NULL )
aItem->Draw( aPanel, aDc, wxPoint( 0, 0 ), -1, g_XorMode, NULL, DefaultTransform );
for( i = drawings.begin(); i < drawings.end(); i++ ) for( i = drawings.begin(); i < drawings.end(); i++ )
{ {
if( *i == aItem ) if( *i == aItem )
{ {
if( aDc != NULL )
aItem->Draw( aPanel, aDc, wxPoint( 0, 0 ), -1, g_XorMode, NULL, DefaultTransform );
drawings.erase( i ); drawings.erase( i );
SetModified();
break; break;
} }
} }
......
...@@ -70,23 +70,11 @@ void LIB_EDIT_FRAME::OnLeftClick( wxDC* DC, const wxPoint& aPosition ) ...@@ -70,23 +70,11 @@ void LIB_EDIT_FRAME::OnLeftClick( wxDC* DC, const wxPoint& aPosition )
break; break;
case ID_LIBEDIT_DELETE_ITEM_BUTT: case ID_LIBEDIT_DELETE_ITEM_BUTT:
DrawEntry = LocateItemUsingCursor( aPosition ); if( LocateItemUsingCursor( aPosition ) )
deleteItem( DC );
if( DrawEntry == NULL )
{
DisplayCmpDoc();
break;
}
SaveCopyInUndoList( m_component );
if( DrawEntry->Type() == LIB_PIN_T )
DeletePin( DC, m_component, (LIB_PIN*) DrawEntry );
else else
m_component->RemoveDrawItem( DrawEntry, DrawPanel, DC ); DisplayCmpDoc();
DrawEntry = NULL;
OnModify( );
break; break;
case ID_LIBEDIT_ANCHOR_ITEM_BUTT: case ID_LIBEDIT_ANCHOR_ITEM_BUTT:
...@@ -96,7 +84,7 @@ void LIB_EDIT_FRAME::OnLeftClick( wxDC* DC, const wxPoint& aPosition ) ...@@ -96,7 +84,7 @@ void LIB_EDIT_FRAME::OnLeftClick( wxDC* DC, const wxPoint& aPosition )
break; break;
default: default:
DisplayError( this, wxT( "LIB_EDIT_FRAME::OnLeftClick error" ) ); wxFAIL_MSG( wxString::Format( wxT( "Unhandled command ID %d" ), GetToolId() ) );
SetToolID( ID_NO_TOOL_SELECTED, DrawPanel->GetDefaultCursor(), wxEmptyString ); SetToolID( ID_NO_TOOL_SELECTED, DrawPanel->GetDefaultCursor(), wxEmptyString );
break; break;
} }
...@@ -132,7 +120,7 @@ void LIB_EDIT_FRAME::OnLeftDClick( wxDC* DC, const wxPoint& aPosition ) ...@@ -132,7 +120,7 @@ void LIB_EDIT_FRAME::OnLeftDClick( wxDC* DC, const wxPoint& aPosition )
else else
return; return;
DrawPanel->m_IgnoreMouseEvents = TRUE; DrawPanel->m_IgnoreMouseEvents = true;
switch( m_drawItem->Type() ) switch( m_drawItem->Type() )
{ {
...@@ -179,15 +167,11 @@ void LIB_EDIT_FRAME::OnLeftDClick( wxDC* DC, const wxPoint& aPosition ) ...@@ -179,15 +167,11 @@ void LIB_EDIT_FRAME::OnLeftDClick( wxDC* DC, const wxPoint& aPosition )
} }
break; break;
default: default:
wxString msg; wxFAIL_MSG( wxT( "Unhandled item <" ) + m_drawItem->GetClass() + wxT( ">" ) );
msg.Printf( wxT( "LIB_EDIT_FRAME::OnLeftDClick Error: unknown StructType %d" ),
m_drawItem->Type() );
DisplayError( this, msg );
break; break;
} }
DrawPanel->MoveCursorToCrossHair(); DrawPanel->MoveCursorToCrossHair();
DrawPanel->m_IgnoreMouseEvents = FALSE; DrawPanel->m_IgnoreMouseEvents = false;
} }
...@@ -666,7 +666,7 @@ void LIB_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event ) ...@@ -666,7 +666,7 @@ void LIB_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event )
break; break;
case ID_LIBEDIT_EDIT_PIN_BY_PIN: case ID_LIBEDIT_EDIT_PIN_BY_PIN:
g_EditPinByPinIsOn = m_HToolBar->GetToolState(ID_LIBEDIT_EDIT_PIN_BY_PIN); g_EditPinByPinIsOn = m_HToolBar->GetToolState( ID_LIBEDIT_EDIT_PIN_BY_PIN );
break; break;
case ID_POPUP_LIBEDIT_END_CREATE_ITEM: case ID_POPUP_LIBEDIT_END_CREATE_ITEM:
...@@ -720,27 +720,9 @@ void LIB_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event ) ...@@ -720,27 +720,9 @@ void LIB_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event )
} }
case ID_POPUP_LIBEDIT_DELETE_ITEM: case ID_POPUP_LIBEDIT_DELETE_ITEM:
if( m_drawItem == NULL ) if( m_drawItem )
break; deleteItem( &dc );
DrawPanel->MoveCursorToCrossHair();
DrawPanel->CrossHairOff( &dc );
SaveCopyInUndoList( m_component );
if( m_drawItem->Type() == LIB_PIN_T )
{
DeletePin( &dc, m_component, (LIB_PIN*) m_drawItem );
}
else
{
if( DrawPanel->IsMouseCaptured() )
DrawPanel->m_endMouseCaptureCallback( DrawPanel, &dc );
else
m_component->RemoveDrawItem( m_drawItem, DrawPanel, &dc );
}
m_drawItem = NULL;
OnModify( );
DrawPanel->CrossHairOn( &dc );
break; break;
case ID_POPUP_LIBEDIT_MOVE_ITEM_REQUEST: case ID_POPUP_LIBEDIT_MOVE_ITEM_REQUEST:
...@@ -919,7 +901,9 @@ void LIB_EDIT_FRAME::TempCopyComponent() ...@@ -919,7 +901,9 @@ void LIB_EDIT_FRAME::TempCopyComponent()
{ {
if( m_tempCopyComponent ) if( m_tempCopyComponent )
delete m_tempCopyComponent; delete m_tempCopyComponent;
m_tempCopyComponent = NULL; m_tempCopyComponent = NULL;
if( m_component ) if( m_component )
m_tempCopyComponent = new LIB_COMPONENT( *m_component ); m_tempCopyComponent = new LIB_COMPONENT( *m_component );
} }
...@@ -1037,7 +1021,7 @@ void LIB_EDIT_FRAME::OnSelectTool( wxCommandEvent& aEvent ) ...@@ -1037,7 +1021,7 @@ void LIB_EDIT_FRAME::OnSelectTool( wxCommandEvent& aEvent )
switch( id ) switch( id )
{ {
case ID_NO_TOOL_SELECTED: case ID_NO_TOOL_SELECTED:
SetToolID( id, wxCURSOR_ARROW, wxEmptyString ); SetToolID( id, DrawPanel->GetDefaultCursor(), wxEmptyString );
break; break;
case ID_LIBEDIT_PIN_BUTT: case ID_LIBEDIT_PIN_BUTT:
...@@ -1051,7 +1035,7 @@ void LIB_EDIT_FRAME::OnSelectTool( wxCommandEvent& aEvent ) ...@@ -1051,7 +1035,7 @@ void LIB_EDIT_FRAME::OnSelectTool( wxCommandEvent& aEvent )
wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED ); wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED );
cmd.SetId( ID_LIBEDIT_EDIT_PIN ); cmd.SetId( ID_LIBEDIT_EDIT_PIN );
GetEventHandler()->ProcessEvent( cmd ); GetEventHandler()->ProcessEvent( cmd );
SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_ARROW, wxEmptyString ); SetToolID( ID_NO_TOOL_SELECTED, DrawPanel->GetDefaultCursor(), wxEmptyString );
} }
break; break;
...@@ -1080,15 +1064,15 @@ void LIB_EDIT_FRAME::OnSelectTool( wxCommandEvent& aEvent ) ...@@ -1080,15 +1064,15 @@ void LIB_EDIT_FRAME::OnSelectTool( wxCommandEvent& aEvent )
break; break;
case ID_LIBEDIT_IMPORT_BODY_BUTT: case ID_LIBEDIT_IMPORT_BODY_BUTT:
SetToolID( id, wxCURSOR_ARROW, _( "Import" ) ); SetToolID( id, DrawPanel->GetDefaultCursor(), _( "Import" ) );
LoadOneSymbol(); LoadOneSymbol();
SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_ARROW, wxEmptyString ); SetToolID( ID_NO_TOOL_SELECTED, DrawPanel->GetDefaultCursor(), wxEmptyString );
break; break;
case ID_LIBEDIT_EXPORT_BODY_BUTT: case ID_LIBEDIT_EXPORT_BODY_BUTT:
SetToolID( id, wxCURSOR_ARROW, _( "Export" ) ); SetToolID( id, DrawPanel->GetDefaultCursor(), _( "Export" ) );
SaveOneSymbol(); SaveOneSymbol();
SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_ARROW, wxEmptyString ); SetToolID( ID_NO_TOOL_SELECTED, DrawPanel->GetDefaultCursor(), wxEmptyString );
break; break;
case ID_LIBEDIT_DELETE_ITEM_BUTT: case ID_LIBEDIT_DELETE_ITEM_BUTT:
...@@ -1107,3 +1091,47 @@ void LIB_EDIT_FRAME::OnSelectTool( wxCommandEvent& aEvent ) ...@@ -1107,3 +1091,47 @@ void LIB_EDIT_FRAME::OnSelectTool( wxCommandEvent& aEvent )
DrawPanel->m_IgnoreMouseEvents = false; DrawPanel->m_IgnoreMouseEvents = false;
} }
void LIB_EDIT_FRAME::deleteItem( wxDC* aDC )
{
wxCHECK_RET( m_drawItem != NULL, wxT( "No drawing item selected to delete." ) );
DrawPanel->CrossHairOff( aDC );
SaveCopyInUndoList( m_component );
if( m_drawItem->Type() == LIB_PIN_T )
{
LIB_PIN* pin = (LIB_PIN*) m_drawItem;
wxPoint pos = pin->GetPosition();
m_component->RemoveDrawItem( (LIB_DRAW_ITEM*) pin, DrawPanel, aDC );
if( g_EditPinByPinIsOn == false )
{
LIB_PIN* tmp = m_component->GetNextPin();
while( tmp != NULL )
{
pin = tmp;
tmp = m_component->GetNextPin( pin );
if( pin->GetPosition() != pos )
continue;
m_component->RemoveDrawItem( (LIB_DRAW_ITEM*) pin );
}
}
}
else
{
if( DrawPanel->IsMouseCaptured() )
DrawPanel->m_endMouseCaptureCallback( DrawPanel, aDC );
else
m_component->RemoveDrawItem( m_drawItem, DrawPanel, aDC );
}
m_drawItem = NULL;
OnModify();
DrawPanel->CrossHairOn( aDC );
}
...@@ -225,6 +225,13 @@ private: ...@@ -225,6 +225,13 @@ private:
void DisplayCmpDoc(); void DisplayCmpDoc();
/**
* Function deleteItem
* deletes the currently selected draw item.
* @param aDC The device context to draw upon when removing item.
*/
void deleteItem( wxDC* aDC );
// General editing // General editing
public: public:
void SaveCopyInUndoList( EDA_ITEM* ItemToCopy, int flag_type_command = 0 ); void SaveCopyInUndoList( EDA_ITEM* ItemToCopy, int flag_type_command = 0 );
...@@ -235,7 +242,6 @@ private: ...@@ -235,7 +242,6 @@ private:
// Editing pins // Editing pins
void CreatePin( wxDC* DC ); void CreatePin( wxDC* DC );
void DeletePin( wxDC* DC, LIB_COMPONENT* LibEntry, LIB_PIN* Pin );
void StartMovePin( wxDC* DC ); void StartMovePin( wxDC* DC );
// Editing anchor // Editing anchor
......
...@@ -367,43 +367,6 @@ static void DrawMovePin( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosi ...@@ -367,43 +367,6 @@ static void DrawMovePin( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosi
} }
/*
* Delete pin at the current mouse position.
* If g_EditPinByPinIsOn == false:
* All pins at the same position will be erased.
* Otherwise only the pin of the current unit and convert will be erased.
*/
void LIB_EDIT_FRAME::DeletePin( wxDC* DC, LIB_COMPONENT* LibEntry, LIB_PIN* Pin )
{
LIB_PIN* tmp;
wxPoint PinPos;
if( LibEntry == NULL || Pin == NULL )
return;
PinPos = Pin->GetPosition();
LibEntry->RemoveDrawItem( (LIB_DRAW_ITEM*) Pin, DrawPanel, DC );
if( g_EditPinByPinIsOn == false )
{
tmp = LibEntry->GetNextPin();
while( tmp != NULL )
{
Pin = tmp;
tmp = LibEntry->GetNextPin( Pin );
if( Pin->GetPosition() != PinPos )
continue;
LibEntry->RemoveDrawItem( (LIB_DRAW_ITEM*) Pin );
}
}
OnModify( );
}
/* /*
* Create a new pin. * Create a new pin.
*/ */
...@@ -450,8 +413,7 @@ void LIB_EDIT_FRAME::CreatePin( wxDC* DC ) ...@@ -450,8 +413,7 @@ void LIB_EDIT_FRAME::CreatePin( wxDC* DC )
if( pin->m_Flags & IS_CANCELLED ) if( pin->m_Flags & IS_CANCELLED )
{ {
DeletePin( NULL, m_component, pin ); deleteItem( DC );
m_drawItem = NULL;
} }
else else
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment