2018-08-06 20:26:37 +02:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2021-07-23 20:15:55 +01:00
|
|
|
* Copyright (C) 2018-2021 KiCad Developers, see AUTHORS.txt for contributors.
|
2018-08-06 20:26:37 +02: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 3 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, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <functional>
|
|
|
|
using namespace std::placeholders;
|
2019-07-18 22:32:12 +02:00
|
|
|
|
2018-08-06 20:26:37 +02:00
|
|
|
#include <tool/tool_event.h>
|
2020-09-22 16:19:24 -07:00
|
|
|
#include <tool/tool_manager.h>
|
2019-06-02 15:34:19 +01:00
|
|
|
#include <tools/cvpcb_actions.h>
|
2019-07-18 22:32:12 +02:00
|
|
|
#include <tools/cvpcb_fpviewer_selection_tool.h>
|
2021-03-07 15:31:19 -05:00
|
|
|
|
2018-08-06 20:26:37 +02:00
|
|
|
|
2019-07-18 22:32:12 +02:00
|
|
|
CVPCB_FOOTPRINT_VIEWER_SELECTION_TOOL::CVPCB_FOOTPRINT_VIEWER_SELECTION_TOOL() :
|
|
|
|
TOOL_INTERACTIVE( "cvpcb.FootprintViewerInteractiveSelection" ),
|
2019-06-05 20:15:57 +01:00
|
|
|
m_frame( nullptr )
|
2018-08-06 20:26:37 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-07-18 22:32:12 +02:00
|
|
|
bool CVPCB_FOOTPRINT_VIEWER_SELECTION_TOOL::Init()
|
2018-08-06 20:26:37 +02:00
|
|
|
{
|
2019-06-11 15:38:21 +01:00
|
|
|
getEditFrame<DISPLAY_FOOTPRINTS_FRAME>()->AddStandardSubMenus( m_menu );
|
2018-08-06 20:26:37 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-07-18 22:32:12 +02:00
|
|
|
void CVPCB_FOOTPRINT_VIEWER_SELECTION_TOOL::Reset( RESET_REASON aReason )
|
2018-08-06 20:26:37 +02:00
|
|
|
{
|
|
|
|
m_frame = getEditFrame<DISPLAY_FOOTPRINTS_FRAME>();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-07-18 22:32:12 +02:00
|
|
|
int CVPCB_FOOTPRINT_VIEWER_SELECTION_TOOL::Main( const TOOL_EVENT& aEvent )
|
2018-08-06 20:26:37 +02:00
|
|
|
{
|
|
|
|
// Main loop: keep receiving events
|
2019-06-17 14:43:22 +01:00
|
|
|
while( TOOL_EVENT* evt = Wait() )
|
2018-08-06 20:26:37 +02:00
|
|
|
{
|
2019-06-27 22:33:48 +01:00
|
|
|
if( m_frame->ToolStackIsEmpty() )
|
2020-10-08 00:50:28 +00:00
|
|
|
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::ARROW );
|
2019-06-27 22:33:48 +01:00
|
|
|
|
2018-08-06 20:26:37 +02:00
|
|
|
if( evt->IsClick( BUT_LEFT ) )
|
|
|
|
{
|
|
|
|
clearSelection();
|
|
|
|
}
|
|
|
|
else if( evt->IsClick( BUT_RIGHT ) )
|
|
|
|
{
|
|
|
|
m_menu.ShowContextMenu( m_selection );
|
|
|
|
}
|
2020-09-22 16:19:24 -07:00
|
|
|
else if( evt->IsDblClick( BUT_MIDDLE ) )
|
|
|
|
{
|
|
|
|
m_toolMgr->RunAction( ACTIONS::zoomFitScreen, true );
|
|
|
|
}
|
2018-08-06 20:26:37 +02:00
|
|
|
else if( evt->IsCancel() || evt->Action() == TA_UNDO_REDO_PRE )
|
|
|
|
{
|
|
|
|
clearSelection();
|
|
|
|
}
|
2019-05-28 15:39:14 +01:00
|
|
|
else
|
2021-07-23 20:15:55 +01:00
|
|
|
{
|
2019-06-16 12:06:49 +01:00
|
|
|
evt->SetPassEvent();
|
2021-07-23 20:15:55 +01:00
|
|
|
}
|
2018-08-06 20:26:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-05-22 19:27:05 +01:00
|
|
|
int CVPCB_FOOTPRINT_VIEWER_SELECTION_TOOL::UpdateMenu( const TOOL_EVENT& aEvent )
|
2018-08-06 20:26:37 +02:00
|
|
|
{
|
2020-05-22 19:27:05 +01:00
|
|
|
ACTION_MENU* actionMenu = aEvent.Parameter<ACTION_MENU*>();
|
|
|
|
CONDITIONAL_MENU* conditionalMenu = dynamic_cast<CONDITIONAL_MENU*>( actionMenu );
|
2018-08-06 20:26:37 +02:00
|
|
|
|
2020-05-22 19:27:05 +01:00
|
|
|
if( conditionalMenu )
|
|
|
|
conditionalMenu->Evaluate( m_selection );
|
2018-08-06 20:26:37 +02:00
|
|
|
|
2020-05-22 19:27:05 +01:00
|
|
|
if( actionMenu )
|
|
|
|
actionMenu->UpdateAll();
|
2018-08-06 20:26:37 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-05-22 19:27:05 +01:00
|
|
|
|
2019-07-18 22:32:12 +02:00
|
|
|
void CVPCB_FOOTPRINT_VIEWER_SELECTION_TOOL::setTransitions()
|
2019-06-02 15:34:19 +01:00
|
|
|
{
|
2020-05-22 19:27:05 +01:00
|
|
|
Go( &CVPCB_FOOTPRINT_VIEWER_SELECTION_TOOL::UpdateMenu, ACTIONS::updateMenu.MakeEvent() );
|
2019-07-18 22:32:12 +02:00
|
|
|
Go( &CVPCB_FOOTPRINT_VIEWER_SELECTION_TOOL::Main,
|
|
|
|
CVPCB_ACTIONS::selectionActivate.MakeEvent() );
|
2018-08-06 20:26:37 +02:00
|
|
|
}
|