kicad/eeschema/libedit_onleftclick.cpp

193 lines
4.5 KiB
C++
Raw Normal View History

/**
* @file libedit_onleftclick.cpp
* @brief Eeschema library editor event handler for a mouse left button single or double click.
2007-09-15 04:25:54 +00:00
*/
2007-05-06 16:03:28 +00:00
#include "fctsys.h"
#include "gr_basic.h"
#include "class_drawpanel.h"
#include "confirm.h"
#include "eeschema_id.h"
2007-05-06 16:03:28 +00:00
#include "general.h"
#include "protos.h"
2010-02-16 16:21:52 +00:00
#include "libeditframe.h"
#include "class_libentry.h"
2007-05-06 16:03:28 +00:00
void LIB_EDIT_FRAME::OnLeftClick( wxDC* DC, const wxPoint& aPosition )
2007-05-06 16:03:28 +00:00
{
LIB_ITEM* item = m_drawItem;
2007-09-15 04:25:54 +00:00
if( m_component == NULL ) // No component loaded !
2007-09-15 04:25:54 +00:00
return;
if( item == NULL || item->m_Flags == 0 )
{
item = LocateItemUsingCursor( aPosition );
2007-09-15 04:25:54 +00:00
if( item )
item->DisplayInfo( this );
else
{
DisplayCmpDoc();
if( DrawPanel->m_AbortRequest )
DrawPanel->m_AbortRequest = false;
}
2007-09-15 04:25:54 +00:00
}
switch( GetToolId() )
2007-09-15 04:25:54 +00:00
{
case ID_NO_TOOL_SELECTED:
if( item && item->m_Flags ) // moved object
{
switch( item->Type() )
{
case LIB_PIN_T:
PlacePin( DC );
break;
default:
EndDrawGraphicItem( DC );
break;
}
}
break;
case ID_LIBEDIT_PIN_BUTT:
if( m_drawItem == NULL || m_drawItem->m_Flags == 0 )
{
CreatePin( DC );
}
else
{
PlacePin( DC );
}
break;
case ID_LIBEDIT_BODY_LINE_BUTT:
case ID_LIBEDIT_BODY_ARC_BUTT:
case ID_LIBEDIT_BODY_CIRCLE_BUTT:
case ID_LIBEDIT_BODY_RECT_BUTT:
case ID_LIBEDIT_BODY_TEXT_BUTT:
if( m_drawItem == NULL || m_drawItem->m_Flags == 0 )
{
m_drawItem = CreateGraphicItem( m_component, DC );
}
else if( m_drawItem )
{
if( m_drawItem->IsNew() )
GraphicItemBeginDraw( DC );
2007-09-15 04:25:54 +00:00
else
EndDrawGraphicItem( DC );
}
break;
case ID_LIBEDIT_DELETE_ITEM_BUTT:
m_drawItem = LocateItemUsingCursor( aPosition );
if( m_drawItem )
deleteItem( DC );
else
DisplayCmpDoc();
break;
case ID_LIBEDIT_ANCHOR_ITEM_BUTT:
SaveCopyInUndoList( m_component );
PlaceAnchor();
SetToolID( ID_NO_TOOL_SELECTED, DrawPanel->GetDefaultCursor(), wxEmptyString );
break;
default:
wxFAIL_MSG( wxString::Format( wxT( "Unhandled command ID %d" ), GetToolId() ) );
SetToolID( ID_NO_TOOL_SELECTED, DrawPanel->GetDefaultCursor(), wxEmptyString );
break;
2007-09-15 04:25:54 +00:00
}
2007-05-06 16:03:28 +00:00
}
/*
* Called on a double click:
* If an editable item (field, pin, graphic):
* Call the suitable dialog editor.
2007-09-15 04:25:54 +00:00
*/
void LIB_EDIT_FRAME::OnLeftDClick( wxDC* DC, const wxPoint& aPosition )
2007-05-06 16:03:28 +00:00
{
if( m_component == NULL )
2007-09-15 04:25:54 +00:00
return;
if( ( m_drawItem == NULL ) || ( m_drawItem->m_Flags == 0 ) )
{ // We can locate an item
m_drawItem = LocateItemUsingCursor( aPosition );
if( m_drawItem == NULL )
2007-09-15 04:25:54 +00:00
{
wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED );
cmd.SetId( ID_LIBEDIT_GET_FRAME_EDIT_PART );
GetEventHandler()->ProcessEvent( cmd );
2007-09-15 04:25:54 +00:00
}
}
if( m_drawItem )
m_drawItem->DisplayInfo( this );
2007-09-15 04:25:54 +00:00
else
return;
DrawPanel->m_IgnoreMouseEvents = true;
2007-09-15 04:25:54 +00:00
switch( m_drawItem->Type() )
2007-09-15 04:25:54 +00:00
{
case LIB_PIN_T:
if( m_drawItem->m_Flags == 0 )
2007-09-15 04:25:54 +00:00
{
wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED );
cmd.SetId( ID_LIBEDIT_EDIT_PIN );
GetEventHandler()->ProcessEvent( cmd );
2007-09-15 04:25:54 +00:00
}
break;
case LIB_ARC_T:
case LIB_CIRCLE_T:
case LIB_RECTANGLE_T:
if( m_drawItem->m_Flags == 0 )
2007-09-15 04:25:54 +00:00
{
EditGraphicSymbol( DC, m_drawItem );
2007-09-15 04:25:54 +00:00
}
break;
case LIB_POLYLINE_T:
if( m_drawItem->m_Flags == 0 )
2007-09-15 04:25:54 +00:00
{
EditGraphicSymbol( DC, m_drawItem );
2007-09-15 04:25:54 +00:00
}
else if( m_drawItem->IsNew() )
2007-09-15 04:25:54 +00:00
{
EndDrawGraphicItem( DC );
}
break;
case LIB_TEXT_T:
if( m_drawItem->m_Flags == 0 )
2007-09-15 04:25:54 +00:00
{
EditSymbolText( DC, m_drawItem );
2007-09-15 04:25:54 +00:00
}
break;
case LIB_FIELD_T:
if( m_drawItem->m_Flags == 0 )
2007-09-15 04:25:54 +00:00
{
EditField( DC, (LIB_FIELD*) m_drawItem );
2007-09-15 04:25:54 +00:00
}
break;
default:
wxFAIL_MSG( wxT( "Unhandled item <" ) + m_drawItem->GetClass() + wxT( ">" ) );
2007-09-15 04:25:54 +00:00
break;
}
DrawPanel->MoveCursorToCrossHair();
DrawPanel->m_IgnoreMouseEvents = false;
2007-05-06 16:03:28 +00:00
}