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." ),
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++ )
{
if( *i == aItem )
{
if( aDc != NULL )
aItem->Draw( aPanel, aDc, wxPoint( 0, 0 ), -1, g_XorMode, NULL, DefaultTransform );
drawings.erase( i );
SetModified();
break;
}
}
......
......@@ -70,23 +70,11 @@ void LIB_EDIT_FRAME::OnLeftClick( wxDC* DC, const wxPoint& aPosition )
break;
case ID_LIBEDIT_DELETE_ITEM_BUTT:
DrawEntry = LocateItemUsingCursor( aPosition );
if( DrawEntry == NULL )
{
DisplayCmpDoc();
break;
}
SaveCopyInUndoList( m_component );
if( DrawEntry->Type() == LIB_PIN_T )
DeletePin( DC, m_component, (LIB_PIN*) DrawEntry );
if( LocateItemUsingCursor( aPosition ) )
deleteItem( DC );
else
m_component->RemoveDrawItem( DrawEntry, DrawPanel, DC );
DisplayCmpDoc();
DrawEntry = NULL;
OnModify( );
break;
case ID_LIBEDIT_ANCHOR_ITEM_BUTT:
......@@ -96,7 +84,7 @@ void LIB_EDIT_FRAME::OnLeftClick( wxDC* DC, const wxPoint& aPosition )
break;
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 );
break;
}
......@@ -132,7 +120,7 @@ void LIB_EDIT_FRAME::OnLeftDClick( wxDC* DC, const wxPoint& aPosition )
else
return;
DrawPanel->m_IgnoreMouseEvents = TRUE;
DrawPanel->m_IgnoreMouseEvents = true;
switch( m_drawItem->Type() )
{
......@@ -179,15 +167,11 @@ void LIB_EDIT_FRAME::OnLeftDClick( wxDC* DC, const wxPoint& aPosition )
}
break;
default:
wxString msg;
msg.Printf( wxT( "LIB_EDIT_FRAME::OnLeftDClick Error: unknown StructType %d" ),
m_drawItem->Type() );
DisplayError( this, msg );
wxFAIL_MSG( wxT( "Unhandled item <" ) + m_drawItem->GetClass() + wxT( ">" ) );
break;
}
DrawPanel->MoveCursorToCrossHair();
DrawPanel->m_IgnoreMouseEvents = FALSE;
DrawPanel->m_IgnoreMouseEvents = false;
}
......@@ -666,7 +666,7 @@ void LIB_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event )
break;
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;
case ID_POPUP_LIBEDIT_END_CREATE_ITEM:
......@@ -720,27 +720,9 @@ void LIB_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event )
}
case ID_POPUP_LIBEDIT_DELETE_ITEM:
if( m_drawItem == NULL )
break;
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 );
}
if( m_drawItem )
deleteItem( &dc );
m_drawItem = NULL;
OnModify( );
DrawPanel->CrossHairOn( &dc );
break;
case ID_POPUP_LIBEDIT_MOVE_ITEM_REQUEST:
......@@ -919,7 +901,9 @@ void LIB_EDIT_FRAME::TempCopyComponent()
{
if( m_tempCopyComponent )
delete m_tempCopyComponent;
m_tempCopyComponent = NULL;
if( m_component )
m_tempCopyComponent = new LIB_COMPONENT( *m_component );
}
......@@ -1037,7 +1021,7 @@ void LIB_EDIT_FRAME::OnSelectTool( wxCommandEvent& aEvent )
switch( id )
{
case ID_NO_TOOL_SELECTED:
SetToolID( id, wxCURSOR_ARROW, wxEmptyString );
SetToolID( id, DrawPanel->GetDefaultCursor(), wxEmptyString );
break;
case ID_LIBEDIT_PIN_BUTT:
......@@ -1051,7 +1035,7 @@ void LIB_EDIT_FRAME::OnSelectTool( wxCommandEvent& aEvent )
wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED );
cmd.SetId( ID_LIBEDIT_EDIT_PIN );
GetEventHandler()->ProcessEvent( cmd );
SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_ARROW, wxEmptyString );
SetToolID( ID_NO_TOOL_SELECTED, DrawPanel->GetDefaultCursor(), wxEmptyString );
}
break;
......@@ -1080,15 +1064,15 @@ void LIB_EDIT_FRAME::OnSelectTool( wxCommandEvent& aEvent )
break;
case ID_LIBEDIT_IMPORT_BODY_BUTT:
SetToolID( id, wxCURSOR_ARROW, _( "Import" ) );
SetToolID( id, DrawPanel->GetDefaultCursor(), _( "Import" ) );
LoadOneSymbol();
SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_ARROW, wxEmptyString );
SetToolID( ID_NO_TOOL_SELECTED, DrawPanel->GetDefaultCursor(), wxEmptyString );
break;
case ID_LIBEDIT_EXPORT_BODY_BUTT:
SetToolID( id, wxCURSOR_ARROW, _( "Export" ) );
SetToolID( id, DrawPanel->GetDefaultCursor(), _( "Export" ) );
SaveOneSymbol();
SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_ARROW, wxEmptyString );
SetToolID( ID_NO_TOOL_SELECTED, DrawPanel->GetDefaultCursor(), wxEmptyString );
break;
case ID_LIBEDIT_DELETE_ITEM_BUTT:
......@@ -1107,3 +1091,47 @@ void LIB_EDIT_FRAME::OnSelectTool( wxCommandEvent& aEvent )
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 );
}
......@@ -204,7 +204,7 @@ public:
*/
void ClearTempCopyComponent();
bool IsEditingDrawItem() { return m_drawItem && m_drawItem->InEditMode(); }
bool IsEditingDrawItem() { return m_drawItem && m_drawItem->InEditMode(); }
private:
......@@ -225,6 +225,13 @@ private:
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
public:
void SaveCopyInUndoList( EDA_ITEM* ItemToCopy, int flag_type_command = 0 );
......@@ -235,7 +242,6 @@ private:
// Editing pins
void CreatePin( wxDC* DC );
void DeletePin( wxDC* DC, LIB_COMPONENT* LibEntry, LIB_PIN* Pin );
void StartMovePin( wxDC* DC );
// Editing anchor
......
......@@ -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.
*/
......@@ -450,8 +413,7 @@ void LIB_EDIT_FRAME::CreatePin( wxDC* DC )
if( pin->m_Flags & IS_CANCELLED )
{
DeletePin( NULL, m_component, pin );
m_drawItem = NULL;
deleteItem( DC );
}
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