2011-12-29 20:11:42 +00:00
|
|
|
/*
|
|
|
|
* 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.
|
2011-12-29 20:11:42 +00:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2011-09-30 18:15:37 +00:00
|
|
|
/**
|
|
|
|
* @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
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
2018-08-03 12:18:26 +00:00
|
|
|
#include <sch_draw_panel.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <eeschema_id.h>
|
2013-01-12 17:32:24 +00:00
|
|
|
#include <msgpanel.h>
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <general.h>
|
2018-01-30 10:49:51 +00:00
|
|
|
#include <lib_edit_frame.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <class_libentry.h>
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
|
|
|
2011-02-21 13:54:29 +00:00
|
|
|
void LIB_EDIT_FRAME::OnLeftClick( wxDC* DC, const wxPoint& aPosition )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2017-12-18 05:21:00 +00:00
|
|
|
LIB_ITEM* item = GetDrawItem();
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
bool item_in_edit = item && item->InEditMode();
|
|
|
|
bool no_item_edited = !item_in_edit;
|
2007-09-15 04:25:54 +00:00
|
|
|
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
LIB_PART* part = GetCurPart();
|
|
|
|
|
|
|
|
if( !part ) // No component loaded !
|
2007-09-15 04:25:54 +00:00
|
|
|
return;
|
|
|
|
|
2012-07-17 15:29:29 +00:00
|
|
|
if( ( GetToolId() == ID_NO_TOOL_SELECTED ) && no_item_edited )
|
2011-02-23 13:48:19 +00:00
|
|
|
{
|
2011-04-27 19:44:32 +00:00
|
|
|
item = LocateItemUsingCursor( aPosition );
|
2007-09-15 04:25:54 +00:00
|
|
|
|
2011-04-27 19:44:32 +00:00
|
|
|
if( item )
|
2013-01-12 17:32:24 +00:00
|
|
|
{
|
|
|
|
MSG_PANEL_ITEMS items;
|
2018-04-10 10:52:12 +00:00
|
|
|
item->GetMsgPanelInfo( m_UserUnits, items );
|
2016-10-18 16:59:26 +00:00
|
|
|
|
2013-01-12 17:32:24 +00:00
|
|
|
SetMsgPanel( items );
|
|
|
|
}
|
2011-02-23 13:48:19 +00:00
|
|
|
else
|
2011-04-27 19:44:32 +00:00
|
|
|
{
|
2011-02-23 13:48:19 +00:00
|
|
|
DisplayCmpDoc();
|
2011-04-27 19:44:32 +00:00
|
|
|
|
2011-12-29 20:11:42 +00:00
|
|
|
if( m_canvas->GetAbortRequest() )
|
|
|
|
m_canvas->SetAbortRequest( false );
|
2011-04-27 19:44:32 +00:00
|
|
|
}
|
2007-09-15 04:25:54 +00:00
|
|
|
}
|
|
|
|
|
2011-02-24 20:22:12 +00:00
|
|
|
switch( GetToolId() )
|
2007-09-15 04:25:54 +00:00
|
|
|
{
|
2017-06-10 07:06:25 +00:00
|
|
|
case ID_ZOOM_SELECTION:
|
|
|
|
break;
|
|
|
|
|
2011-02-24 20:22:12 +00:00
|
|
|
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 )
|
2011-02-25 15:17:07 +00:00
|
|
|
{
|
2011-04-27 19:44:32 +00:00
|
|
|
switch( item->Type() )
|
2011-02-25 15:17:07 +00:00
|
|
|
{
|
|
|
|
case LIB_PIN_T:
|
2013-02-06 11:54:51 +00:00
|
|
|
PlacePin();
|
2011-02-25 15:17:07 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
EndDrawGraphicItem( DC );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2011-02-24 12:35:14 +00:00
|
|
|
break;
|
2010-10-20 20:24:26 +00:00
|
|
|
|
2011-02-24 12:35:14 +00:00
|
|
|
case ID_LIBEDIT_PIN_BUTT:
|
2012-07-17 15:29:29 +00:00
|
|
|
if( no_item_edited )
|
2011-02-24 12:35:14 +00:00
|
|
|
CreatePin( DC );
|
|
|
|
else
|
2013-02-06 11:54:51 +00:00
|
|
|
PlacePin();
|
2011-02-24 12:35:14 +00:00
|
|
|
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:
|
2012-07-17 15:29:29 +00:00
|
|
|
if( no_item_edited )
|
2017-12-18 05:21:00 +00:00
|
|
|
SetDrawItem( CreateGraphicItem( part, DC ) );
|
|
|
|
else if( item )
|
2011-02-24 12:35:14 +00:00
|
|
|
{
|
2017-12-18 05:21:00 +00:00
|
|
|
if( item->IsNew() )
|
2011-02-24 12:35:14 +00:00
|
|
|
GraphicItemBeginDraw( DC );
|
2007-09-15 04:25:54 +00:00
|
|
|
else
|
2011-02-24 12:35:14 +00:00
|
|
|
EndDrawGraphicItem( DC );
|
|
|
|
}
|
|
|
|
break;
|
2010-10-20 20:24:26 +00:00
|
|
|
|
2011-02-24 12:35:14 +00:00
|
|
|
case ID_LIBEDIT_DELETE_ITEM_BUTT:
|
2017-12-18 05:21:00 +00:00
|
|
|
item = LocateItemUsingCursor( aPosition );
|
2011-02-28 13:53:49 +00:00
|
|
|
|
2017-12-18 05:21:00 +00:00
|
|
|
if( item )
|
|
|
|
{
|
2018-04-04 17:19:17 +00:00
|
|
|
deleteItem( DC, item );
|
2017-12-18 05:21:00 +00:00
|
|
|
}
|
2011-02-24 12:35:14 +00:00
|
|
|
else
|
2017-09-01 22:50:25 +00:00
|
|
|
{
|
2011-02-24 22:29:43 +00:00
|
|
|
DisplayCmpDoc();
|
2011-02-24 12:35:14 +00:00
|
|
|
|
2017-09-01 22:50:25 +00:00
|
|
|
if( m_canvas->GetAbortRequest() )
|
|
|
|
m_canvas->SetAbortRequest( false );
|
|
|
|
}
|
2011-02-24 12:35:14 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_LIBEDIT_ANCHOR_ITEM_BUTT:
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
SaveCopyInUndoList( part );
|
2011-10-07 14:41:30 +00:00
|
|
|
PlaceAnchor();
|
2017-06-12 14:17:48 +00:00
|
|
|
SetNoToolSelected();
|
2011-02-24 12:35:14 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2011-02-24 22:29:43 +00:00
|
|
|
wxFAIL_MSG( wxString::Format( wxT( "Unhandled command ID %d" ), GetToolId() ) );
|
2017-06-12 14:17:48 +00:00
|
|
|
SetNoToolSelected();
|
2011-02-24 12:35:14 +00:00
|
|
|
break;
|
2007-09-15 04:25:54 +00:00
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-09-04 18:57:37 +00:00
|
|
|
/*
|
|
|
|
* Called on a double click:
|
2008-08-11 18:21:21 +00:00
|
|
|
* If an editable item (field, pin, graphic):
|
|
|
|
* Call the suitable dialog editor.
|
2007-09-15 04:25:54 +00:00
|
|
|
*/
|
2011-02-21 13:54:29 +00:00
|
|
|
void LIB_EDIT_FRAME::OnLeftDClick( wxDC* DC, const wxPoint& aPosition )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
LIB_PART* part = GetCurPart();
|
2017-12-18 05:21:00 +00:00
|
|
|
LIB_ITEM* item = GetDrawItem();
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
|
|
|
|
if( !part )
|
2007-09-15 04:25:54 +00:00
|
|
|
return;
|
|
|
|
|
2017-12-18 05:21:00 +00:00
|
|
|
if( !item || !item->InEditMode() )
|
2008-08-11 18:21:21 +00:00
|
|
|
{ // We can locate an item
|
2017-12-18 05:21:00 +00:00
|
|
|
item = LocateItemUsingCursor( aPosition, LIB_COLLECTOR::DoubleClickItems );
|
2011-02-24 20:22:12 +00:00
|
|
|
|
2017-12-18 05:21:00 +00:00
|
|
|
if( item == NULL )
|
2007-09-15 04:25:54 +00:00
|
|
|
{
|
2017-12-18 05:21:00 +00:00
|
|
|
// The user canceled the disambiguation menu
|
2017-09-01 22:50:25 +00:00
|
|
|
if( m_canvas->GetAbortRequest() )
|
|
|
|
m_canvas->SetAbortRequest( false );
|
2017-12-18 05:21:00 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
// If there is only a random double-click, we allow the use to edit the part
|
|
|
|
wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED );
|
2017-09-01 22:50:25 +00:00
|
|
|
|
2017-12-18 05:21:00 +00:00
|
|
|
cmd.SetId( ID_LIBEDIT_GET_FRAME_EDIT_PART );
|
|
|
|
GetEventHandler()->ProcessEvent( cmd );
|
|
|
|
}
|
2007-09-15 04:25:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-18 05:21:00 +00:00
|
|
|
if( item )
|
|
|
|
SetMsgPanel( item );
|
2007-09-15 04:25:54 +00:00
|
|
|
else
|
|
|
|
return;
|
|
|
|
|
2011-12-29 20:11:42 +00:00
|
|
|
m_canvas->SetIgnoreMouseEvents( true );
|
2017-12-18 05:21:00 +00:00
|
|
|
bool not_edited = !item->InEditMode();
|
2007-09-15 04:25:54 +00:00
|
|
|
|
2017-12-18 05:21:00 +00:00
|
|
|
switch( item->Type() )
|
2007-09-15 04:25:54 +00:00
|
|
|
{
|
2010-12-10 19:47:44 +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
|
|
|
{
|
2017-12-18 05:21:00 +00:00
|
|
|
SetDrawItem( item );
|
2009-10-30 19:26:25 +00:00
|
|
|
wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED );
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
|
2009-10-30 19:26:25 +00:00
|
|
|
cmd.SetId( ID_LIBEDIT_EDIT_PIN );
|
|
|
|
GetEventHandler()->ProcessEvent( cmd );
|
2007-09-15 04:25:54 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2010-12-10 19:47:44 +00:00
|
|
|
case LIB_ARC_T:
|
|
|
|
case LIB_CIRCLE_T:
|
|
|
|
case LIB_RECTANGLE_T:
|
2013-01-02 07:55:48 +00:00
|
|
|
if( not_edited )
|
2017-12-18 05:21:00 +00:00
|
|
|
EditGraphicSymbol( DC, item );
|
2007-09-15 04:25:54 +00:00
|
|
|
break;
|
|
|
|
|
2010-12-10 19:47:44 +00:00
|
|
|
case LIB_POLYLINE_T:
|
2013-01-02 07:55:48 +00:00
|
|
|
if( not_edited )
|
2017-12-18 05:21:00 +00:00
|
|
|
EditGraphicSymbol( DC, item );
|
|
|
|
else if( item->IsNew() )
|
2007-09-15 04:25:54 +00:00
|
|
|
EndDrawGraphicItem( DC );
|
|
|
|
break;
|
|
|
|
|
2010-12-10 19:47:44 +00:00
|
|
|
case LIB_TEXT_T:
|
2013-01-02 07:55:48 +00:00
|
|
|
if( not_edited )
|
2017-12-18 05:21:00 +00:00
|
|
|
EditSymbolText( DC, item );
|
2007-09-15 04:25:54 +00:00
|
|
|
break;
|
|
|
|
|
2010-12-10 19:47:44 +00:00
|
|
|
case LIB_FIELD_T:
|
2013-01-02 07:55:48 +00:00
|
|
|
if( not_edited )
|
2017-12-18 05:21:00 +00:00
|
|
|
EditField( (LIB_FIELD*) item );
|
2007-09-15 04:25:54 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2017-12-18 05:21:00 +00:00
|
|
|
wxFAIL_MSG( wxT( "Unhandled item <" ) + item->GetClass() + wxT( ">" ) );
|
2007-09-15 04:25:54 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->MoveCursorToCrossHair();
|
2011-12-29 20:11:42 +00:00
|
|
|
m_canvas->SetIgnoreMouseEvents( false );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|