2013-08-07 09:20:12 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2013 CERN
|
|
|
|
* @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2013-08-02 14:46:53 +00:00
|
|
|
#include <cstring>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#include <tool/tool_event.h>
|
2013-09-27 16:51:21 +00:00
|
|
|
#include <tool/tool_action.h>
|
2013-08-02 14:46:53 +00:00
|
|
|
#include <tool/tool_manager.h>
|
2019-04-29 17:50:46 +00:00
|
|
|
#include <tool/actions.h>
|
2013-08-02 14:46:53 +00:00
|
|
|
|
2013-08-07 09:20:12 +00:00
|
|
|
struct FlagString
|
|
|
|
{
|
2013-10-14 11:43:57 +00:00
|
|
|
int flag;
|
|
|
|
std::string str;
|
2013-08-02 14:46:53 +00:00
|
|
|
};
|
|
|
|
|
2013-08-07 09:20:12 +00:00
|
|
|
|
2013-10-14 18:40:36 +00:00
|
|
|
static const std::string flag2string( int aFlag, const FlagString* aExps )
|
2013-08-02 14:46:53 +00:00
|
|
|
{
|
2013-10-14 11:43:57 +00:00
|
|
|
std::string rv;
|
2013-08-21 15:37:27 +00:00
|
|
|
|
2013-10-14 18:40:36 +00:00
|
|
|
for( int i = 0; aExps[i].str.length(); i++ )
|
2013-10-14 11:43:57 +00:00
|
|
|
{
|
2013-10-14 18:40:36 +00:00
|
|
|
if( aExps[i].flag & aFlag )
|
|
|
|
rv += aExps[i].str + " ";
|
2013-10-14 11:43:57 +00:00
|
|
|
}
|
2013-08-21 15:37:27 +00:00
|
|
|
|
2013-10-14 11:43:57 +00:00
|
|
|
return rv;
|
2013-08-02 14:46:53 +00:00
|
|
|
}
|
|
|
|
|
2013-08-07 09:20:12 +00:00
|
|
|
|
2019-06-27 11:47:24 +00:00
|
|
|
void TOOL_EVENT::init()
|
|
|
|
{
|
|
|
|
// By default only MESSAGEs and Cancels are passed to multiple recipients
|
2019-07-12 21:42:30 +00:00
|
|
|
m_passEvent = m_category == TC_MESSAGE || IsCancelInteractive() || IsActivate();
|
2019-06-27 11:47:24 +00:00
|
|
|
|
|
|
|
m_hasPosition = ( m_category == TC_MOUSE || m_category == TC_COMMAND );
|
2019-10-03 15:55:05 +00:00
|
|
|
|
|
|
|
// Cancel tool doesn't contain a position
|
|
|
|
if( IsCancel() )
|
|
|
|
m_hasPosition = false;
|
2021-02-21 12:45:50 +00:00
|
|
|
|
|
|
|
m_forceImmediate = false;
|
2019-06-27 11:47:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-27 16:51:21 +00:00
|
|
|
bool TOOL_EVENT::IsAction( const TOOL_ACTION* aAction ) const
|
|
|
|
{
|
|
|
|
return Matches( aAction->MakeEvent() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-08-02 14:46:53 +00:00
|
|
|
const std::string TOOL_EVENT::Format() const
|
|
|
|
{
|
2013-10-14 11:43:57 +00:00
|
|
|
std::string ev;
|
|
|
|
|
2013-10-14 14:13:35 +00:00
|
|
|
const FlagString categories[] =
|
|
|
|
{
|
2013-10-14 18:40:36 +00:00
|
|
|
{ TC_MOUSE, "mouse" },
|
|
|
|
{ TC_KEYBOARD, "keyboard" },
|
|
|
|
{ TC_COMMAND, "command" },
|
|
|
|
{ TC_MESSAGE, "message" },
|
|
|
|
{ TC_VIEW, "view" },
|
2013-10-14 14:13:35 +00:00
|
|
|
{ 0, "" }
|
2013-10-14 11:43:57 +00:00
|
|
|
};
|
|
|
|
|
2013-10-14 14:13:35 +00:00
|
|
|
const FlagString actions[] =
|
|
|
|
{
|
2019-06-15 00:29:42 +00:00
|
|
|
{ TA_MOUSE_CLICK, "click" },
|
|
|
|
{ TA_MOUSE_DBLCLICK, "double click" },
|
|
|
|
{ TA_MOUSE_UP, "button-up" },
|
|
|
|
{ TA_MOUSE_DOWN, "button-down" },
|
|
|
|
{ TA_MOUSE_DRAG, "drag" },
|
|
|
|
{ TA_MOUSE_MOTION, "motion" },
|
|
|
|
{ TA_MOUSE_WHEEL, "wheel" },
|
|
|
|
{ TA_KEY_PRESSED, "key-pressed" },
|
|
|
|
{ TA_VIEW_REFRESH, "view-refresh" },
|
|
|
|
{ TA_VIEW_ZOOM, "view-zoom" },
|
|
|
|
{ TA_VIEW_PAN, "view-pan" },
|
|
|
|
{ TA_VIEW_DIRTY, "view-dirty" },
|
|
|
|
{ TA_CHANGE_LAYER, "change-layer" },
|
|
|
|
{ TA_CANCEL_TOOL, "cancel-tool" },
|
|
|
|
{ TA_CHOICE_MENU_UPDATE, "choice-menu-update" },
|
|
|
|
{ TA_CHOICE_MENU_CHOICE, "choice-menu-choice" },
|
|
|
|
{ TA_UNDO_REDO_PRE, "undo-redo-pre" },
|
|
|
|
{ TA_UNDO_REDO_POST, "undo-redo-post" },
|
|
|
|
{ TA_ACTION, "action" },
|
|
|
|
{ TA_ACTIVATE, "activate" },
|
|
|
|
{ 0, "" }
|
2013-10-14 11:43:57 +00:00
|
|
|
};
|
|
|
|
|
2013-10-14 14:13:35 +00:00
|
|
|
const FlagString buttons[] =
|
|
|
|
{
|
2013-10-15 08:41:00 +00:00
|
|
|
{ BUT_NONE, "none" },
|
|
|
|
{ BUT_LEFT, "left" },
|
|
|
|
{ BUT_RIGHT, "right" },
|
|
|
|
{ BUT_MIDDLE, "middle" },
|
2013-11-28 14:19:50 +00:00
|
|
|
{ 0, "" }
|
2013-10-14 11:43:57 +00:00
|
|
|
};
|
|
|
|
|
2013-10-14 14:13:35 +00:00
|
|
|
const FlagString modifiers[] =
|
|
|
|
{
|
2013-10-14 18:40:36 +00:00
|
|
|
{ MD_SHIFT, "shift" },
|
|
|
|
{ MD_CTRL, "ctrl" },
|
|
|
|
{ MD_ALT, "alt" },
|
|
|
|
{ 0, "" }
|
2013-10-14 11:43:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
ev = "category: ";
|
|
|
|
ev += flag2string( m_category, categories );
|
|
|
|
ev += " action: ";
|
|
|
|
ev += flag2string( m_actions, actions );
|
|
|
|
|
2013-10-14 18:40:36 +00:00
|
|
|
if( m_actions & TA_MOUSE )
|
2013-10-14 11:43:57 +00:00
|
|
|
{
|
|
|
|
ev += " btns: ";
|
|
|
|
ev += flag2string( m_mouseButtons, buttons );
|
|
|
|
}
|
|
|
|
|
2013-10-14 18:40:36 +00:00
|
|
|
if( m_actions & TA_KEYBOARD )
|
2013-10-14 11:43:57 +00:00
|
|
|
{
|
2013-08-21 15:37:27 +00:00
|
|
|
char tmp[128];
|
|
|
|
sprintf( tmp, "key: %d", m_keyCode );
|
|
|
|
ev += tmp;
|
2013-10-14 11:43:57 +00:00
|
|
|
}
|
|
|
|
|
2013-10-14 18:40:36 +00:00
|
|
|
if( m_actions & ( TA_MOUSE | TA_KEYBOARD ) )
|
2013-10-14 11:43:57 +00:00
|
|
|
{
|
|
|
|
ev += " mods: ";
|
|
|
|
ev += flag2string( m_modifiers, modifiers );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( m_commandId )
|
|
|
|
{
|
|
|
|
char tmp[128];
|
|
|
|
sprintf( tmp, "cmd-id: %d", *m_commandId );
|
|
|
|
ev += tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( m_commandStr )
|
|
|
|
ev += "cmd-str: " + ( *m_commandStr );
|
|
|
|
|
|
|
|
return ev;
|
2013-08-02 14:46:53 +00:00
|
|
|
}
|
|
|
|
|
2013-08-07 09:20:12 +00:00
|
|
|
|
2013-08-02 14:46:53 +00:00
|
|
|
const std::string TOOL_EVENT_LIST::Format() const
|
|
|
|
{
|
2013-12-13 16:27:30 +00:00
|
|
|
std::string s;
|
2013-10-14 11:43:57 +00:00
|
|
|
|
2017-09-24 18:11:58 +00:00
|
|
|
for( const TOOL_EVENT& e : m_events )
|
2013-10-14 11:43:57 +00:00
|
|
|
s += e.Format() + " ";
|
2013-08-02 14:46:53 +00:00
|
|
|
|
2013-10-14 11:43:57 +00:00
|
|
|
return s;
|
2013-08-02 14:46:53 +00:00
|
|
|
}
|
2019-04-29 17:50:46 +00:00
|
|
|
|
|
|
|
|
2019-05-06 20:37:54 +00:00
|
|
|
bool TOOL_EVENT::IsClick( int aButtonMask ) const
|
|
|
|
{
|
2019-10-03 15:55:05 +00:00
|
|
|
return ( m_actions & TA_MOUSE_CLICK ) && ( m_mouseButtons & aButtonMask ) == m_mouseButtons;
|
2019-05-06 20:37:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool TOOL_EVENT::IsDblClick( int aButtonMask ) const
|
|
|
|
{
|
2019-07-06 16:50:02 +00:00
|
|
|
return m_actions == TA_MOUSE_DBLCLICK && ( m_mouseButtons & aButtonMask ) == m_mouseButtons;
|
2019-05-06 20:37:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-20 18:44:13 +00:00
|
|
|
bool TOOL_EVENT::IsCancelInteractive() const
|
2019-04-29 17:50:46 +00:00
|
|
|
{
|
2019-07-04 13:19:08 +00:00
|
|
|
return( ( m_commandStr.is_initialized()
|
|
|
|
&& m_commandStr.get() == ACTIONS::cancelInteractive.GetName() )
|
|
|
|
|| ( m_commandId.is_initialized()
|
|
|
|
&& m_commandId.get() == ACTIONS::cancelInteractive.GetId() )
|
|
|
|
|| ( m_actions == TA_CANCEL_TOOL ) );
|
2019-04-29 17:50:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-20 18:44:13 +00:00
|
|
|
bool TOOL_EVENT::IsSelectionEvent() const
|
2019-04-29 17:50:46 +00:00
|
|
|
{
|
2019-07-01 21:01:33 +00:00
|
|
|
return Matches( EVENTS::ClearedEvent )
|
2019-07-04 13:19:08 +00:00
|
|
|
|| Matches( EVENTS::UnselectedEvent )
|
|
|
|
|| Matches( EVENTS::SelectedEvent );
|
2019-04-29 17:50:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-20 18:44:13 +00:00
|
|
|
bool TOOL_EVENT::IsPointEditor() const
|
2019-06-27 11:47:24 +00:00
|
|
|
{
|
2019-07-04 13:19:08 +00:00
|
|
|
return( ( m_commandStr.is_initialized()
|
|
|
|
&& m_commandStr.get().find( "PointEditor" ) != GetCommandStr()->npos )
|
|
|
|
|| ( m_commandId.is_initialized()
|
|
|
|
&& m_commandId.get() == ACTIONS::activatePointEditor.GetId() ) );
|
2019-06-27 11:47:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-20 18:44:13 +00:00
|
|
|
bool TOOL_EVENT::IsMoveTool() const
|
2019-07-01 21:01:33 +00:00
|
|
|
{
|
2019-07-04 13:19:08 +00:00
|
|
|
return( m_commandStr.is_initialized()
|
|
|
|
&& m_commandStr.get().find( "InteractiveMove" ) != GetCommandStr()->npos );
|
2019-07-01 21:01:33 +00:00
|
|
|
}
|
2021-02-02 01:05:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
bool TOOL_EVENT::IsSimulator() const
|
|
|
|
{
|
|
|
|
return( m_commandStr.is_initialized()
|
|
|
|
&& m_commandStr.get().find( "Simulation" ) != GetCommandStr()->npos );
|
2021-02-21 12:45:50 +00:00
|
|
|
}
|