kicad/eeschema/libedit/libedit_onleftclick.cpp

233 lines
6.1 KiB
C++
Raw Normal View History

/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
2013-01-01 20:52:37 +00:00
* Copyright (C) 2013 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2013 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 1992-2013 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* @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 <class_drawpanel.h>
#include <eeschema_id.h>
#include <msgpanel.h>
#include <general.h>
2018-01-30 10:49:51 +00:00
#include <lib_edit_frame.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 = GetDrawItem();
bool item_in_edit = item && item->InEditMode();
bool no_item_edited = !item_in_edit;
2007-09-15 04:25:54 +00:00
LIB_PART* part = GetCurPart();
if( !part ) // No component loaded !
2007-09-15 04:25:54 +00:00
return;
if( ( GetToolId() == ID_NO_TOOL_SELECTED ) && no_item_edited )
{
item = LocateItemUsingCursor( aPosition );
2007-09-15 04:25:54 +00:00
if( item )
{
MSG_PANEL_ITEMS items;
item->GetMsgPanelInfo( m_UserUnits, items );
SetMsgPanel( items );
}
else
{
DisplayCmpDoc();
if( m_canvas->GetAbortRequest() )
m_canvas->SetAbortRequest( false );
}
2007-09-15 04:25:54 +00:00
}
switch( GetToolId() )
2007-09-15 04:25:54 +00:00
{
case ID_ZOOM_SELECTION:
break;
case ID_NO_TOOL_SELECTED:
2013-01-01 20:52:37 +00:00
// If an item is currently in edit, finish edit
if( item_in_edit )
{
switch( item->Type() )
{
case LIB_PIN_T:
PlacePin();
break;
default:
EndDrawGraphicItem( DC );
break;
}
}
break;
case ID_LIBEDIT_PIN_BUTT:
if( no_item_edited )
CreatePin( DC );
else
PlacePin();
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( no_item_edited )
SetDrawItem( CreateGraphicItem( part, DC ) );
else if( item )
{
if( item->IsNew() )
GraphicItemBeginDraw( DC );
2007-09-15 04:25:54 +00:00
else
EndDrawGraphicItem( DC );
}
break;
case ID_LIBEDIT_DELETE_ITEM_BUTT:
item = LocateItemUsingCursor( aPosition );
if( item )
{
deleteItem( DC, item );
}
else
{
DisplayCmpDoc();
if( m_canvas->GetAbortRequest() )
m_canvas->SetAbortRequest( false );
}
break;
case ID_LIBEDIT_ANCHOR_ITEM_BUTT:
SaveCopyInUndoList( part );
PlaceAnchor();
SetNoToolSelected();
break;
default:
wxFAIL_MSG( wxString::Format( wxT( "Unhandled command ID %d" ), GetToolId() ) );
SetNoToolSelected();
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
{
LIB_PART* part = GetCurPart();
LIB_ITEM* item = GetDrawItem();
if( !part )
2007-09-15 04:25:54 +00:00
return;
if( !item || !item->InEditMode() )
{ // We can locate an item
item = LocateItemUsingCursor( aPosition, LIB_COLLECTOR::DoubleClickItems );
if( item == NULL )
2007-09-15 04:25:54 +00:00
{
// 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 );
cmd.SetId( ID_LIBEDIT_GET_FRAME_EDIT_PART );
GetEventHandler()->ProcessEvent( cmd );
}
2007-09-15 04:25:54 +00:00
}
}
if( item )
SetMsgPanel( item );
2007-09-15 04:25:54 +00:00
else
return;
m_canvas->SetIgnoreMouseEvents( true );
bool not_edited = !item->InEditMode();
2007-09-15 04:25:54 +00:00
switch( item->Type() )
2007-09-15 04:25:54 +00:00
{
case LIB_PIN_T:
2013-01-02 07:55:48 +00:00
if( not_edited )
2007-09-15 04:25:54 +00:00
{
SetDrawItem( item );
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:
2013-01-02 07:55:48 +00:00
if( not_edited )
EditGraphicSymbol( DC, item );
2007-09-15 04:25:54 +00:00
break;
case LIB_POLYLINE_T:
2013-01-02 07:55:48 +00:00
if( not_edited )
EditGraphicSymbol( DC, item );
else if( item->IsNew() )
2007-09-15 04:25:54 +00:00
EndDrawGraphicItem( DC );
break;
case LIB_TEXT_T:
2013-01-02 07:55:48 +00:00
if( not_edited )
EditSymbolText( DC, item );
2007-09-15 04:25:54 +00:00
break;
case LIB_FIELD_T:
2013-01-02 07:55:48 +00:00
if( not_edited )
EditField( (LIB_FIELD*) item );
2007-09-15 04:25:54 +00:00
break;
default:
wxFAIL_MSG( wxT( "Unhandled item <" ) + item->GetClass() + wxT( ">" ) );
2007-09-15 04:25:54 +00:00
break;
}
m_canvas->MoveCursorToCrossHair();
m_canvas->SetIgnoreMouseEvents( false );
2007-05-06 16:03:28 +00:00
}