2018-08-06 18:26:37 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2019-06-02 14:34:19 +00:00
|
|
|
* Copyright (C) 2018-2019 KiCad Developers, see AUTHORS.txt for contributors.
|
2018-08-06 18:26:37 +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 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 20:32:12 +00:00
|
|
|
|
2019-06-02 14:34:19 +00:00
|
|
|
#include <bitmaps.h>
|
2019-07-18 20:32:12 +00:00
|
|
|
#include <preview_items/ruler_item.h>
|
2018-08-06 18:26:37 +00:00
|
|
|
#include <tool/tool_event.h>
|
2019-06-02 14:34:19 +00:00
|
|
|
#include <tools/cvpcb_actions.h>
|
2019-07-18 20:32:12 +00:00
|
|
|
#include <tools/cvpcb_fpviewer_selection_tool.h>
|
|
|
|
#include <view/view.h>
|
2019-08-09 21:05:16 +00:00
|
|
|
#include <view/view_controls.h>
|
2018-08-06 18:26:37 +00:00
|
|
|
|
2019-07-18 20:32:12 +00:00
|
|
|
CVPCB_FOOTPRINT_VIEWER_SELECTION_TOOL::CVPCB_FOOTPRINT_VIEWER_SELECTION_TOOL() :
|
|
|
|
TOOL_INTERACTIVE( "cvpcb.FootprintViewerInteractiveSelection" ),
|
2019-06-05 19:15:57 +00:00
|
|
|
m_frame( nullptr )
|
2018-08-06 18:26:37 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-07-18 20:32:12 +00:00
|
|
|
bool CVPCB_FOOTPRINT_VIEWER_SELECTION_TOOL::Init()
|
2018-08-06 18:26:37 +00:00
|
|
|
{
|
2019-06-11 14:38:21 +00:00
|
|
|
getEditFrame<DISPLAY_FOOTPRINTS_FRAME>()->AddStandardSubMenus( m_menu );
|
2018-08-06 18:26:37 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-07-18 20:32:12 +00:00
|
|
|
void CVPCB_FOOTPRINT_VIEWER_SELECTION_TOOL::Reset( RESET_REASON aReason )
|
2018-08-06 18:26:37 +00:00
|
|
|
{
|
|
|
|
m_frame = getEditFrame<DISPLAY_FOOTPRINTS_FRAME>();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-07-18 20:32:12 +00:00
|
|
|
int CVPCB_FOOTPRINT_VIEWER_SELECTION_TOOL::Main( const TOOL_EVENT& aEvent )
|
2018-08-06 18:26:37 +00:00
|
|
|
{
|
|
|
|
// Main loop: keep receiving events
|
2019-06-17 13:43:22 +00:00
|
|
|
while( TOOL_EVENT* evt = Wait() )
|
2018-08-06 18:26:37 +00:00
|
|
|
{
|
2019-06-27 21:33:48 +00:00
|
|
|
if( m_frame->ToolStackIsEmpty() )
|
|
|
|
m_frame->GetCanvas()->SetCurrentCursor( wxCURSOR_ARROW );
|
|
|
|
|
2018-08-06 18:26:37 +00:00
|
|
|
// This is kind of hacky: activate RMB drag on any event.
|
|
|
|
// There doesn't seem to be any other good way to tell when another tool
|
|
|
|
// is canceled and control returns to the selection tool, except by the
|
|
|
|
// fact that the selection tool starts to get events again.
|
2019-06-24 15:27:05 +00:00
|
|
|
if( m_frame->IsCurrentTool( ACTIONS::selectionTool ) )
|
2018-08-06 18:26:37 +00:00
|
|
|
{
|
|
|
|
getViewControls()->SetAdditionalPanButtons( false, true );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Disable RMB pan for other tools; they can re-enable if desired
|
|
|
|
if( evt->IsActivate() )
|
|
|
|
{
|
|
|
|
getViewControls()->SetAdditionalPanButtons( false, false );
|
|
|
|
}
|
|
|
|
|
|
|
|
// single click? Select single object
|
|
|
|
if( evt->IsClick( BUT_LEFT ) )
|
|
|
|
{
|
|
|
|
clearSelection();
|
|
|
|
}
|
|
|
|
|
|
|
|
// right click? if there is any object - show the context menu
|
|
|
|
else if( evt->IsClick( BUT_RIGHT ) )
|
|
|
|
{
|
|
|
|
m_menu.ShowContextMenu( m_selection );
|
|
|
|
}
|
|
|
|
|
|
|
|
else if( evt->IsCancel() || evt->Action() == TA_UNDO_REDO_PRE )
|
|
|
|
{
|
|
|
|
clearSelection();
|
|
|
|
}
|
|
|
|
|
2019-05-28 14:39:14 +00:00
|
|
|
else
|
2019-06-16 11:06:49 +00:00
|
|
|
evt->SetPassEvent();
|
2018-08-06 18:26:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// This tool is supposed to be active forever
|
|
|
|
wxASSERT( false );
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-07-18 20:32:12 +00:00
|
|
|
int CVPCB_FOOTPRINT_VIEWER_SELECTION_TOOL::MeasureTool( const TOOL_EVENT& aEvent )
|
2018-08-06 18:26:37 +00:00
|
|
|
{
|
|
|
|
auto& view = *getView();
|
|
|
|
auto& controls = *getViewControls();
|
2019-07-18 20:32:12 +00:00
|
|
|
auto previous_settings = controls.GetSettings();
|
2018-08-06 18:26:37 +00:00
|
|
|
|
2019-07-15 12:15:58 +00:00
|
|
|
std::string tool = aEvent.GetCommandStr().get();
|
|
|
|
m_frame->PushTool( tool );
|
2018-08-06 18:26:37 +00:00
|
|
|
Activate();
|
|
|
|
|
|
|
|
KIGFX::PREVIEW::TWO_POINT_GEOMETRY_MANAGER twoPtMgr;
|
2019-07-18 20:32:12 +00:00
|
|
|
KIGFX::PREVIEW::RULER_ITEM ruler( twoPtMgr, m_frame->GetUserUnits() );
|
2018-08-06 18:26:37 +00:00
|
|
|
|
|
|
|
view.Add( &ruler );
|
|
|
|
view.SetVisible( &ruler, false );
|
|
|
|
|
|
|
|
bool originSet = false;
|
|
|
|
|
|
|
|
controls.ShowCursor( true );
|
|
|
|
controls.SetSnapping( true );
|
|
|
|
controls.SetAdditionalPanButtons( false, true );
|
|
|
|
|
2019-06-27 21:33:48 +00:00
|
|
|
while( TOOL_EVENT* evt = Wait() )
|
2018-08-06 18:26:37 +00:00
|
|
|
{
|
2019-06-27 21:33:48 +00:00
|
|
|
m_frame->GetCanvas()->SetCurrentCursor( wxCURSOR_ARROW );
|
2018-08-06 18:26:37 +00:00
|
|
|
const VECTOR2I cursorPos = controls.GetCursorPosition();
|
|
|
|
|
2019-07-18 20:32:12 +00:00
|
|
|
auto clearRuler = [&]() {
|
2019-07-01 21:01:33 +00:00
|
|
|
view.SetVisible( &ruler, false );
|
|
|
|
controls.SetAutoPan( false );
|
|
|
|
controls.CaptureCursor( false );
|
|
|
|
originSet = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
if( evt->IsCancelInteractive() )
|
2018-08-06 18:26:37 +00:00
|
|
|
{
|
2019-06-24 15:27:05 +00:00
|
|
|
if( originSet )
|
2019-07-01 21:01:33 +00:00
|
|
|
clearRuler();
|
|
|
|
else
|
2019-06-24 15:27:05 +00:00
|
|
|
{
|
2019-07-15 12:15:58 +00:00
|
|
|
m_frame->PopTool( tool );
|
2019-07-01 21:01:33 +00:00
|
|
|
break;
|
2019-06-24 15:27:05 +00:00
|
|
|
}
|
2019-07-01 21:01:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
else if( evt->IsActivate() )
|
|
|
|
{
|
|
|
|
if( originSet )
|
|
|
|
clearRuler();
|
|
|
|
|
|
|
|
if( evt->IsMoveTool() )
|
2019-06-24 15:27:05 +00:00
|
|
|
{
|
2019-07-01 21:01:33 +00:00
|
|
|
// leave ourselves on the stack so we come back after the move
|
2019-06-24 15:27:05 +00:00
|
|
|
break;
|
|
|
|
}
|
2019-07-01 21:01:33 +00:00
|
|
|
else
|
|
|
|
{
|
2019-07-15 12:15:58 +00:00
|
|
|
m_frame->PopTool( tool );
|
2019-06-24 15:27:05 +00:00
|
|
|
break;
|
2019-07-01 21:01:33 +00:00
|
|
|
}
|
2018-08-06 18:26:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// click or drag starts
|
2019-06-24 15:27:05 +00:00
|
|
|
else if( !originSet && ( evt->IsDrag( BUT_LEFT ) || evt->IsClick( BUT_LEFT ) ) )
|
2018-08-06 18:26:37 +00:00
|
|
|
{
|
|
|
|
if( !evt->IsDrag( BUT_LEFT ) )
|
|
|
|
{
|
|
|
|
twoPtMgr.SetOrigin( cursorPos );
|
|
|
|
twoPtMgr.SetEnd( cursorPos );
|
|
|
|
}
|
|
|
|
|
|
|
|
controls.CaptureCursor( true );
|
|
|
|
controls.SetAutoPan( true );
|
|
|
|
|
|
|
|
originSet = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
else if( !originSet && evt->IsMotion() )
|
|
|
|
{
|
|
|
|
// make sure the origin is set before a drag starts
|
|
|
|
// otherwise you can miss a step
|
|
|
|
twoPtMgr.SetOrigin( cursorPos );
|
|
|
|
twoPtMgr.SetEnd( cursorPos );
|
|
|
|
}
|
|
|
|
|
|
|
|
// second click or mouse up after drag ends
|
2019-06-24 15:27:05 +00:00
|
|
|
else if( originSet && ( evt->IsClick( BUT_LEFT ) || evt->IsMouseUp( BUT_LEFT ) ) )
|
2018-08-06 18:26:37 +00:00
|
|
|
{
|
|
|
|
originSet = false;
|
|
|
|
|
|
|
|
controls.SetAutoPan( false );
|
|
|
|
controls.CaptureCursor( false );
|
|
|
|
|
|
|
|
view.SetVisible( &ruler, false );
|
|
|
|
}
|
|
|
|
|
|
|
|
// move or drag when origin set updates rules
|
2019-06-24 15:27:05 +00:00
|
|
|
else if( originSet && ( evt->IsMotion() || evt->IsDrag( BUT_LEFT ) ) )
|
2018-08-06 18:26:37 +00:00
|
|
|
{
|
|
|
|
twoPtMgr.SetAngleSnap( evt->Modifier( MD_CTRL ) );
|
|
|
|
twoPtMgr.SetEnd( cursorPos );
|
|
|
|
|
|
|
|
view.SetVisible( &ruler, true );
|
|
|
|
view.Update( &ruler, KIGFX::GEOMETRY );
|
|
|
|
}
|
|
|
|
|
|
|
|
else if( evt->IsClick( BUT_RIGHT ) )
|
|
|
|
{
|
|
|
|
m_menu.ShowContextMenu( m_selection );
|
|
|
|
}
|
2019-07-26 18:16:44 +00:00
|
|
|
|
|
|
|
else
|
|
|
|
evt->SetPassEvent();
|
2018-08-06 18:26:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
view.SetVisible( &ruler, false );
|
|
|
|
view.Remove( &ruler );
|
|
|
|
controls.ApplySettings( previous_settings );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-07-18 20:32:12 +00:00
|
|
|
void CVPCB_FOOTPRINT_VIEWER_SELECTION_TOOL::setTransitions()
|
2019-06-02 14:34:19 +00:00
|
|
|
{
|
2019-07-18 20:32:12 +00:00
|
|
|
Go( &CVPCB_FOOTPRINT_VIEWER_SELECTION_TOOL::Main,
|
|
|
|
CVPCB_ACTIONS::selectionActivate.MakeEvent() );
|
|
|
|
Go( &CVPCB_FOOTPRINT_VIEWER_SELECTION_TOOL::MeasureTool, ACTIONS::measureTool.MakeEvent() );
|
2018-08-06 18:26:37 +00:00
|
|
|
}
|