Header clean up round 6.

This commit is contained in:
Wayne Stambaugh 2020-12-26 19:41:04 -05:00
parent 8300e17b69
commit 2a3e921d58
28 changed files with 1272 additions and 1345 deletions

View File

@ -2,6 +2,8 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2013 CERN * Copyright (C) 2013 CERN
* Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors.
*
* @author Maciej Suminski <maciej.suminski@cern.ch> * @author Maciej Suminski <maciej.suminski@cern.ch>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
@ -40,15 +42,11 @@ class TOOL_ACTION;
* Functors that can be used to figure out how the action controls should be displayed in the UI * Functors that can be used to figure out how the action controls should be displayed in the UI
* and if an action should be enabled given the current selection. * and if an action should be enabled given the current selection.
* *
* @note @c checkCondition is also used for determing the state of a toggled toolbar item * @note @c checkCondition is also used for determining the state of a toggled toolbar item
* (the item is toggled when the condition is true). * (the item is toggled when the condition is true).
*/ */
struct ACTION_CONDITIONS struct ACTION_CONDITIONS
{ {
SELECTION_CONDITION checkCondition; ///< Returns true if the UI control should be checked
SELECTION_CONDITION enableCondition; ///< Returns true if the UI control should be enabled
SELECTION_CONDITION showCondition; ///< Returns true if the UI control should be shown
ACTION_CONDITIONS() ACTION_CONDITIONS()
{ {
checkCondition = SELECTION_CONDITIONS::ShowNever; // Never check by default checkCondition = SELECTION_CONDITIONS::ShowNever; // Never check by default
@ -73,13 +71,16 @@ struct ACTION_CONDITIONS
showCondition = aCondition; showCondition = aCondition;
return *this; return *this;
} }
SELECTION_CONDITION checkCondition; ///< Returns true if the UI control should be checked
SELECTION_CONDITION enableCondition; ///< Returns true if the UI control should be enabled
SELECTION_CONDITION showCondition; ///< Returns true if the UI control should be shown
}; };
/** /**
* ACTION_MANAGER * Manage #TOOL_ACTION objects.
* *
* Takes care of TOOL_ACTION objects. Registers them and allows one to run them * Registering them and allows one to run them using associated hot keys, names or ids.
* using associated hot keys, names or ids.
*/ */
class ACTION_MANAGER class ACTION_MANAGER
{ {
@ -90,12 +91,12 @@ public:
ACTION_MANAGER( TOOL_MANAGER* aToolManager ); ACTION_MANAGER( TOOL_MANAGER* aToolManager );
/** /**
* Unregisters every registered action. * Unregister every registered action.
*/ */
~ACTION_MANAGER(); ~ACTION_MANAGER();
/** /**
* Adds a tool action to the manager and sets it up. After that is is possible to invoke * Add a tool action to the manager and sets it up. After that is is possible to invoke
* the action using hotkeys or sending a command event with its name. * the action using hotkeys or sending a command event with its name.
* *
* @param aAction: action to be added. Ownership is not transferred. * @param aAction: action to be added. Ownership is not transferred.
@ -103,7 +104,7 @@ public:
void RegisterAction( TOOL_ACTION* aAction ); void RegisterAction( TOOL_ACTION* aAction );
/** /**
* Generates an unique ID from for an action with given name. * Generate an unique ID from for an action with given name.
*/ */
static int MakeActionId( const std::string& aActionName ); static int MakeActionId( const std::string& aActionName );
@ -113,7 +114,7 @@ public:
const std::map<std::string, TOOL_ACTION*>& GetActions() const; const std::map<std::string, TOOL_ACTION*>& GetActions() const;
/** /**
* Finds an action with a given name (if there is one available). * Find an action with a given name (if there is one available).
* *
* @param aActionName is the searched action. * @param aActionName is the searched action.
* @return Pointer to a TOOL_ACTION object or NULL if there is no such action. * @return Pointer to a TOOL_ACTION object or NULL if there is no such action.
@ -121,7 +122,7 @@ public:
TOOL_ACTION* FindAction( const std::string& aActionName ) const; TOOL_ACTION* FindAction( const std::string& aActionName ) const;
/** /**
* Runs an action associated with a hotkey (if there is one available). * Run an action associated with a hotkey (if there is one available).
* *
* @param aHotKey is the hotkey to be handled. * @param aHotKey is the hotkey to be handled.
* @return True if there was an action associated with the hotkey, false otherwise. * @return True if there was an action associated with the hotkey, false otherwise.
@ -129,20 +130,22 @@ public:
bool RunHotKey( int aHotKey ) const; bool RunHotKey( int aHotKey ) const;
/** /**
* Returns the hot key associated with a given action or 0 if there is none. * Return the hot key associated with a given action or 0 if there is none.
* *
* @param aAction is the queried action. * @param aAction is the queried action.
*/ */
int GetHotKey( const TOOL_ACTION& aAction ) const; int GetHotKey( const TOOL_ACTION& aAction ) const;
/** /**
* Optionally reads the hotkey config files and then rebuilds the internal hotkey maps. * Optionally read the hotkey config files and then rebuilds the internal hotkey maps.
*/ */
void UpdateHotKeys( bool aFullUpdate ); void UpdateHotKeys( bool aFullUpdate );
/** /**
* Returns list of TOOL_ACTIONs. TOOL_ACTIONs add themselves to the list upon their * Return list of TOOL_ACTIONs.
* creation. *
* #TOOL_ACTIONs add themselves to the list upon their creation.
*
* @return List of TOOL_ACTIONs. * @return List of TOOL_ACTIONs.
*/ */
static std::list<TOOL_ACTION*>& GetActionList() static std::list<TOOL_ACTION*>& GetActionList()
@ -156,36 +159,36 @@ public:
* Set the conditions the UI elements for activating a specific tool action should use * Set the conditions the UI elements for activating a specific tool action should use
* for determining the current UI state (e.g. checked, enabled, shown) * for determining the current UI state (e.g. checked, enabled, shown)
* *
* @param aAction is the tool action using these conditions * @param aAction is the tool action using these conditions.
* @param aConditions are the conditions to use for the action * @param aConditions are the conditions to use for the action.
*/ */
void SetConditions( const TOOL_ACTION& aAction, const ACTION_CONDITIONS& aConditions ); void SetConditions( const TOOL_ACTION& aAction, const ACTION_CONDITIONS& aConditions );
/** /**
* Get the conditions to use for a specific tool action. * Get the conditions to use for a specific tool action.
* *
* @param aAction is the tool action * @param aAction is the tool action.
* @return the action conditions, returns nullptr if no conditions are registered * @return the action conditions, returns nullptr if no conditions are registered.
*/ */
const ACTION_CONDITIONS* GetCondition( const TOOL_ACTION& aAction ) const; const ACTION_CONDITIONS* GetCondition( const TOOL_ACTION& aAction ) const;
private: private:
// Resolves a hotkey by applying legacy and current settings over the action's // Resolve a hotkey by applying legacy and current settings over the action's
// default hotkey. // default hotkey.
int processHotKey( TOOL_ACTION* aAction, std::map<std::string, int> aLegacyMap, int processHotKey( TOOL_ACTION* aAction, std::map<std::string, int> aLegacyMap,
std::map<std::string, int> aHotKeyMap ); std::map<std::string, int> aHotKeyMap );
///> Tool manager needed to run actions ///< Tool manager needed to run actions
TOOL_MANAGER* m_toolMgr; TOOL_MANAGER* m_toolMgr;
///> Map for indexing actions by their names ///< Map for indexing actions by their names
std::map<std::string, TOOL_ACTION*> m_actionNameIndex; std::map<std::string, TOOL_ACTION*> m_actionNameIndex;
///> Map for indexing actions by their hotkeys ///< Map for indexing actions by their hotkeys
typedef std::map<int, std::list<TOOL_ACTION*> > HOTKEY_LIST; typedef std::map<int, std::list<TOOL_ACTION*> > HOTKEY_LIST;
HOTKEY_LIST m_actionHotKeys; HOTKEY_LIST m_actionHotKeys;
///> Quick action<->hot key lookup ///< Quick action<->hot key lookup
std::map<int, int> m_hotkeys; std::map<int, int> m_hotkeys;
/// Map the command ID that wx uses for the action to the UI conditions for the /// Map the command ID that wx uses for the action to the UI conditions for the

View File

@ -2,6 +2,8 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2013-2017 CERN * Copyright (C) 2013-2017 CERN
* Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors.
*
* @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch> * @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
* @author Maciej Suminski <maciej.suminski@cern.ch> * @author Maciej Suminski <maciej.suminski@cern.ch>
* *
@ -43,7 +45,7 @@ class TOOL_INTERACTIVE;
class ACTION_MENU : public wxMenu class ACTION_MENU : public wxMenu
{ {
public: public:
///> Default constructor ///< Default constructor
ACTION_MENU( bool isContextMenu, TOOL_INTERACTIVE* aTool = nullptr ); ACTION_MENU( bool isContextMenu, TOOL_INTERACTIVE* aTool = nullptr );
~ACTION_MENU() override; ~ACTION_MENU() override;
@ -52,7 +54,7 @@ public:
ACTION_MENU& operator=( const ACTION_MENU& aMenu ) = delete; ACTION_MENU& operator=( const ACTION_MENU& aMenu ) = delete;
/** /**
* Sets title for the menu. The title is shown as a text label shown on the top of * Set title for the menu. The title is shown as a text label shown on the top of
* the menu. * the menu.
* *
* @param aTitle is the new title. * @param aTitle is the new title.
@ -60,36 +62,40 @@ public:
void SetTitle( const wxString& aTitle ) override; void SetTitle( const wxString& aTitle ) override;
/** /**
* Decides whether a title for a pop up menu should be displayed. * Decide whether a title for a pop up menu should be displayed.
*/ */
void DisplayTitle( bool aDisplay = true ); void DisplayTitle( bool aDisplay = true );
/** /**
* Assigns an icon for the entry. * Assign an icon for the entry.
* *
* @param aIcon is the icon to be assigned. NULL is used to remove icon. * @param aIcon is the icon to be assigned. NULL is used to remove icon.
*/ */
void SetIcon( const BITMAP_OPAQUE* aIcon ); void SetIcon( const BITMAP_OPAQUE* aIcon );
/** /**
* Adds a wxWidgets-style entry to the menu. After highlighting/selecting the entry, * Add a wxWidgets-style entry to the menu.
* a wxWidgets event is generated. *
* After highlighting/selecting the entry, a wxWidgets event is generated.
*/ */
wxMenuItem* Add( const wxString& aLabel, int aId, const BITMAP_OPAQUE* aIcon ); wxMenuItem* Add( const wxString& aLabel, int aId, const BITMAP_OPAQUE* aIcon );
wxMenuItem* Add( const wxString& aLabel, const wxString& aToolTip, int aId, wxMenuItem* Add( const wxString& aLabel, const wxString& aToolTip, int aId,
const BITMAP_OPAQUE* aIcon, bool aIsCheckmarkEntry = false ); const BITMAP_OPAQUE* aIcon, bool aIsCheckmarkEntry = false );
/** /**
* Adds an entry to the menu, basing on the TOOL_ACTION object. After selecting the entry, * Add an entry to the menu based on the #TOOL_ACTION object.
* a TOOL_EVENT command containing name of the action is sent. *
* After selecting the entry, a #TOOL_EVENT command containing name of the action is sent.
* *
* @param aAction is the action to be added to menu entry. * @param aAction is the action to be added to menu entry.
*/ */
wxMenuItem* Add( const TOOL_ACTION& aAction, bool aIsCheckmarkEntry = false ); wxMenuItem* Add( const TOOL_ACTION& aAction, bool aIsCheckmarkEntry = false );
/** /**
* Adds an action menu as a submenu. The difference between this function and * Add an action menu as a submenu.
* wxMenu::AppendSubMenu() is the capability to handle icons. *
* The difference between this function and wxMenu::AppendSubMenu() is the capability to
* handle icons.
* *
* @param aMenu is the submenu to be added. * @param aMenu is the submenu to be added.
*/ */
@ -97,23 +103,27 @@ public:
/** /**
* Add a standard close item to the menu with the accelerator key CTRL-W. * Add a standard close item to the menu with the accelerator key CTRL-W.
*
* Emits the wxID_CLOSE event. * Emits the wxID_CLOSE event.
* *
* @param aAppname is the application name to append to the tooltip * @param aAppname is the application name to append to the tooltip.
*/ */
void AddClose( wxString aAppname = "" ); void AddClose( wxString aAppname = "" );
/** /**
* Adds either a standard Quit or Close item to the menu. If aKiface is NULL or in * Add either a standard Quit or Close item to the menu.
* single-instance then Quite (wxID_QUIT) is used, otherwise Close (wxID_CLOSE) is used.
* *
* @param aAppname is the application name to append to the tooltip * If \a aKiface is NULL or in single-instance then quit (wxID_QUIT) is used, otherwise
* close (wxID_CLOSE) is used.
*
* @param aAppname is the application name to append to the tooltip.
*/ */
void AddQuitOrClose( KIFACE_I* aKiface, wxString aAppname = "" ); void AddQuitOrClose( KIFACE_I* aKiface, wxString aAppname = "" );
/** /**
* Removes all the entries from the menu (as well as its title). It leaves the menu in the * Remove all the entries from the menu (as well as its title).
* initial state. *
* It leaves the menu in the initial state.
*/ */
void Clear(); void Clear();
@ -123,8 +133,9 @@ public:
bool HasEnabledItems() const; bool HasEnabledItems() const;
/** /**
* Returns the position of selected item. If the returned value is negative, that means that * Return the position of selected item.
* menu was dismissed. *
* If the returned value is negative, that means that menu was dismissed.
* *
* @return The position of selected item in the action menu. * @return The position of selected item in the action menu.
*/ */
@ -134,25 +145,25 @@ public:
} }
/** /**
* Runs update handlers for the menu and its submenus. * Run update handlers for the menu and its submenus.
*/ */
void UpdateAll(); void UpdateAll();
/** /**
* Clears the dirty flag on the menu and all descendants. * Clear the dirty flag on the menu and all descendants.
*/ */
void ClearDirty(); void ClearDirty();
void SetDirty(); void SetDirty();
/** /**
* Sets a tool that is the creator of the menu. * Set a tool that is the creator of the menu.
* *
* @param aTool is the tool that created the menu. * @param aTool is the tool that created the menu.
*/ */
void SetTool( TOOL_INTERACTIVE* aTool ); void SetTool( TOOL_INTERACTIVE* aTool );
/** /**
* Creates a deep, recursive copy of this ACTION_MENU. * Create a deep, recursive copy of this ACTION_MENU.
*/ */
ACTION_MENU* Clone() const; ACTION_MENU* Clone() const;
@ -162,23 +173,27 @@ public:
static constexpr bool CHECK = true; static constexpr bool CHECK = true;
protected: protected:
///> Returns an instance of this class. It has to be overridden in inheriting classes. ///< Return an instance of this class. It has to be overridden in inheriting classes.
virtual ACTION_MENU* create() const; virtual ACTION_MENU* create() const;
///> Returns an instance of TOOL_MANAGER class. ///< Returns an instance of TOOL_MANAGER class.
TOOL_MANAGER* getToolManager() const; TOOL_MANAGER* getToolManager() const;
/** /**
* Update menu state stub. It is called before a menu is shown, in order to update its state. * Update menu state stub.
* Here you can tick current settings, enable/disable entries, etc. *
* It is called before a menu is shown, in order to update its state. Here you can tick
* current settings, enable/disable entries, etc.
*/ */
virtual void update() virtual void update()
{ {
} }
/** /**
* Event handler stub. It should be used if you want to generate a TOOL_EVENT from a wxMenuEvent. * Event handler stub.
* It will be called when a menu entry is clicked. *
* It should be used if you want to generate a #TOOL_EVENT from a wxMenuEvent. It will be
* called when a menu entry is clicked.
*/ */
virtual OPT_TOOL_EVENT eventHandler( const wxMenuEvent& ) virtual OPT_TOOL_EVENT eventHandler( const wxMenuEvent& )
{ {
@ -186,32 +201,32 @@ protected:
} }
/** /**
* Copies another menus data to this instance. Old entries are preserved, and ones form aMenu * Copy another menus data to this instance.
* are copied. *
* Old entries are preserved and ones form aMenu are copied.
*/ */
void copyFrom( const ACTION_MENU& aMenu ); void copyFrom( const ACTION_MENU& aMenu );
protected: protected:
/** /**
* Function appendCopy * Append a copy of wxMenuItem.
* Appends a copy of wxMenuItem.
*/ */
wxMenuItem* appendCopy( const wxMenuItem* aSource ); wxMenuItem* appendCopy( const wxMenuItem* aSource );
///> Initializes handlers for events. ///< Initialize handlers for events.
void setupEvents(); void setupEvents();
///> Updates hot key settings for TOOL_ACTIONs in this menu. ///< Update hot key settings for TOOL_ACTIONs in this menu.
void updateHotKeys(); void updateHotKeys();
///> Traverses the submenus tree looking for a submenu capable of handling a particular menu ///< Traverse the submenus tree looking for a submenu capable of handling a particular menu
///> event. In case it is handled, it is returned the aToolEvent parameter. ///< event. In case it is handled, it is returned the aToolEvent parameter.
void runEventHandlers( const wxMenuEvent& aMenuEvent, OPT_TOOL_EVENT& aToolEvent ); void runEventHandlers( const wxMenuEvent& aMenuEvent, OPT_TOOL_EVENT& aToolEvent );
///> Runs a function on the menu and all its submenus. ///< Run a function on the menu and all its submenus.
void runOnSubmenus( std::function<void(ACTION_MENU*)> aFunction ); void runOnSubmenus( std::function<void(ACTION_MENU*)> aFunction );
///> Checks if any of submenus contains a TOOL_ACTION with a specific ID. ///< Check if any of submenus contains a TOOL_ACTION with a specific ID.
OPT_TOOL_EVENT findToolAction( int aId ); OPT_TOOL_EVENT findToolAction( int aId );
bool m_isForcedPosition; bool m_isForcedPosition;
@ -222,22 +237,22 @@ protected:
bool m_titleDisplayed; bool m_titleDisplayed;
bool m_isContextMenu; bool m_isContextMenu;
///> Menu title ///< Menu title
wxString m_title; wxString m_title;
///> Optional icon ///< Optional icon
const BITMAP_OPAQUE* m_icon; const BITMAP_OPAQUE* m_icon;
///> Stores the id number of selected item. ///< Stores the id number of selected item.
int m_selected; int m_selected;
///> Creator of the menu ///< Creator of the menu
TOOL_INTERACTIVE* m_tool; TOOL_INTERACTIVE* m_tool;
///> Associates tool actions with menu item IDs. Non-owning. ///< Associates tool actions with menu item IDs. Non-owning.
std::map<int, const TOOL_ACTION*> m_toolActions; std::map<int, const TOOL_ACTION*> m_toolActions;
///> List of submenus. ///< List of submenus.
std::list<ACTION_MENU*> m_submenus; std::list<ACTION_MENU*> m_submenus;
friend class TOOL_INTERACTIVE; friend class TOOL_INTERACTIVE;

View File

@ -1,7 +1,7 @@
/* /*
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2019 KiCad Developers, see CHANGELOG.txt for contributors. * Copyright (C) 2019-2020 KiCad Developers, see AUTHORS.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -54,6 +54,7 @@ public:
/** /**
* Set the default action to use when first creating the toolbar palette icon. * Set the default action to use when first creating the toolbar palette icon.
*
* If no default action is provided, the default will be the first action in the * If no default action is provided, the default will be the first action in the
* vector. * vector.
* *
@ -82,16 +83,16 @@ public:
const std::vector< const TOOL_ACTION*>& GetActions() const { return m_actions; } const std::vector< const TOOL_ACTION*>& GetActions() const { return m_actions; }
protected: protected:
///> The action ID for this action group ///< The action ID for this action group
int m_id; int m_id;
///> The name of this action group ///< The name of this action group
std::string m_name; std::string m_name;
///> The default action to display on the toolbar item ///< The default action to display on the toolbar item
const TOOL_ACTION* m_defaultAction; const TOOL_ACTION* m_defaultAction;
///> The actions that compose the group ///< The actions that compose the group
std::vector<const TOOL_ACTION*> m_actions; std::vector<const TOOL_ACTION*> m_actions;
}; };
@ -107,7 +108,7 @@ public:
* *
* @param aParent is the parent window * @param aParent is the parent window
* @param aVertical is true if the palette should make the buttons a vertical line, * @param aVertical is true if the palette should make the buttons a vertical line,
* false for a horizonatl line. * false for a horizontal line.
*/ */
ACTION_TOOLBAR_PALETTE( wxWindow* aParent, bool aVertical ); ACTION_TOOLBAR_PALETTE( wxWindow* aParent, bool aVertical );
@ -159,29 +160,26 @@ public:
protected: protected:
void onCharHook( wxKeyEvent& aEvent ); void onCharHook( wxKeyEvent& aEvent );
protected:
// The group that the buttons in the palette are part of // The group that the buttons in the palette are part of
ACTION_GROUP* m_group; ACTION_GROUP* m_group;
///> The size each button on the toolbar should be ///< The size each button on the toolbar should be
wxRect m_buttonSize; wxRect m_buttonSize;
///> True if the palette uses vertical buttons, false for horizontal buttons ///< True if the palette uses vertical buttons, false for horizontal buttons
bool m_isVertical; bool m_isVertical;
wxPanel* m_panel; wxPanel* m_panel;
wxBoxSizer* m_mainSizer; wxBoxSizer* m_mainSizer;
wxBoxSizer* m_buttonSizer; wxBoxSizer* m_buttonSizer;
///> The buttons that act as the toolbar on the palette ///< The buttons that act as the toolbar on the palette
std::map<int, BITMAP_BUTTON*> m_buttons; std::map<int, BITMAP_BUTTON*> m_buttons;
}; };
/** /**
* ACTION_TOOLBAR * Define the structure of a toolbar with buttons that invoke ACTIONs.
*
* Defines the structure of a toolbar with buttons that invoke ACTIONs.
*/ */
class ACTION_TOOLBAR : public wxAuiToolBar class ACTION_TOOLBAR : public wxAuiToolBar
{ {
@ -200,18 +198,19 @@ public:
void SetAuiManager( wxAuiManager* aManager ) { m_auiManager = aManager; } void SetAuiManager( wxAuiManager* aManager ) { m_auiManager = aManager; }
/** /**
* Adds a TOOL_ACTION-based button to the toolbar. After selecting the entry, * Add a TOOL_ACTION-based button to the toolbar.
* a TOOL_EVENT command containing name of the action is sent.
* *
* @param aAction is the action to add * After selecting the entry, a #TOOL_EVENT command containing name of the action is sent.
* @param aIsToggleEntry makes the toolbar item a toggle entry when true *
* @param aIsCancellable when true, cancels the tool if clicked when tool is active * @param aAction is the action to add.
* @param aIsToggleEntry makes the toolbar item a toggle entry when true.
* @param aIsCancellable when true, cancels the tool if clicked when tool is active.
*/ */
void Add( const TOOL_ACTION& aAction, bool aIsToggleEntry = false, void Add( const TOOL_ACTION& aAction, bool aIsToggleEntry = false,
bool aIsCancellable = false ); bool aIsCancellable = false );
/** /**
* Adds a large button such as used in the Kicad Manager Frame's launch bar. * Add a large button such as used in the KiCad Manager Frame's launch bar.
* *
* @param aAction * @param aAction
*/ */
@ -227,6 +226,7 @@ public:
/** /**
* Add a context menu to a specific tool item on the toolbar. * Add a context menu to a specific tool item on the toolbar.
*
* This toolbar gets ownership of the menu object, and will delete it when the * This toolbar gets ownership of the menu object, and will delete it when the
* ClearToolbar() function is called. * ClearToolbar() function is called.
* *
@ -239,7 +239,8 @@ public:
* Add a set of actions to a toolbar as a group. One action from the group will be displayed * Add a set of actions to a toolbar as a group. One action from the group will be displayed
* at a time. * at a time.
* *
* @param aGroup is the group to add. The first action in the group will be the first shown on the toolbar. * @param aGroup is the group to add. The first action in the group will be the first shown
* on the toolbar.
* @param aIsToggleEntry makes the toolbar item a toggle entry when true * @param aIsToggleEntry makes the toolbar item a toggle entry when true
*/ */
void AddGroup( ACTION_GROUP* aGroup, bool aIsToggleEntry = false ); void AddGroup( ACTION_GROUP* aGroup, bool aIsToggleEntry = false );
@ -258,14 +259,16 @@ public:
void ClearToolbar(); void ClearToolbar();
/** /**
* Updates the bitmap of a particular tool. Not icon-based because we use it * Updates the bitmap of a particular tool.
* for the custom-drawn layer pair bitmap. *
* Not icon-based because we use it for the custom-drawn layer pair bitmap.
*/ */
void SetToolBitmap( const TOOL_ACTION& aAction, const wxBitmap& aBitmap ); void SetToolBitmap( const TOOL_ACTION& aAction, const wxBitmap& aBitmap );
/** /**
* Applies the default toggle action. For checked items this is check/uncheck; for * Apply the default toggle action.
* non-checked items it's enable/disable. *
* For checked items this is check/uncheck; for non-checked items it's enable/disable.
*/ */
void Toggle( const TOOL_ACTION& aAction, bool aState ); void Toggle( const TOOL_ACTION& aAction, bool aState );
@ -276,7 +279,8 @@ public:
* *
* The standard Realize() draws both horizontal and vertical to determine sizing * The standard Realize() draws both horizontal and vertical to determine sizing
* However with many icons, potato PCs, etc, you can actually see that double draw * However with many icons, potato PCs, etc, you can actually see that double draw
* This custom function avoids the double draw if the HORIZONTAL or VERTICAL toolbar properties are set. * This custom function avoids the double draw if the HORIZONTAL or VERTICAL toolbar
* properties are set.
*/ */
bool KiRealize(); bool KiRealize();
@ -292,33 +296,32 @@ protected:
void doSelectAction( ACTION_GROUP* aGroup, const TOOL_ACTION& aAction ); void doSelectAction( ACTION_GROUP* aGroup, const TOOL_ACTION& aAction );
/** /**
* Popup the ACTION_TOOLBAR_PALETTE associated with the ACTION_GROUP of the * Popup the #ACTION_TOOLBAR_PALETTE associated with the ACTION_GROUP of the
* given toolbar item. * given toolbar item.
*/ */
void popupPalette( wxAuiToolBarItem* aItem ); void popupPalette( wxAuiToolBarItem* aItem );
///> Handler for a mouse up/down event ///< Handler for a mouse up/down event
void onMouseClick( wxMouseEvent& aEvent ); void onMouseClick( wxMouseEvent& aEvent );
///> Handler for when a drag event occurs on an item ///< Handler for when a drag event occurs on an item
void onItemDrag( wxAuiToolBarEvent& aEvent ); void onItemDrag( wxAuiToolBarEvent& aEvent );
///> The default tool event handler ///< The default tool event handler
void onToolEvent( wxAuiToolBarEvent& aEvent ); void onToolEvent( wxAuiToolBarEvent& aEvent );
///> Handle a right-click on a menu item ///< Handle a right-click on a menu item
void onToolRightClick( wxAuiToolBarEvent& aEvent ); void onToolRightClick( wxAuiToolBarEvent& aEvent );
///> Handle the button select inside the palette ///< Handle the button select inside the palette
void onPaletteEvent( wxCommandEvent& aEvent ); void onPaletteEvent( wxCommandEvent& aEvent );
///> Handle the palette timer triggering ///< Handle the palette timer triggering
void onTimerDone( wxTimerEvent& aEvent ); void onTimerDone( wxTimerEvent& aEvent );
///> Render the triangle in the lower-right corner that represents that an action pallette ///< Render the triangle in the lower-right corner that represents that an action palette
///> is available for an item ///< is available for an item
void OnCustomRender( wxDC& aDc, const wxAuiToolBarItem& aItem, void OnCustomRender( wxDC& aDc, const wxAuiToolBarItem& aItem, const wxRect& aRect ) override;
const wxRect& aRect ) override;
protected: protected:
// Timer used to determine when the palette should be opened after a group item is pressed // Timer used to determine when the palette should be opened after a group item is pressed

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2013-2016 CERN * Copyright (C) 2013-2016 CERN
* Copyright (C) 2016-2019 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 2016-2020 KiCad Developers, see AUTHORS.txt for contributors.
* @author Maciej Suminski <maciej.suminski@cern.ch> * @author Maciej Suminski <maciej.suminski@cern.ch>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
@ -35,10 +35,10 @@ class TOOL_MANAGER;
#define LEGACY_HK_NAME( x ) x #define LEGACY_HK_NAME( x ) x
/** /**
* ACTIONS * Gather all the actions that are shared by tools.
* *
* Gathers all the actions that are shared by tools. The instance of a subclass of * The instance of a subclass of ACTIONS is created inside of #ACTION_MANAGER object that
* ACTIONS is created inside of ACTION_MANAGER object that registers the actions. * registers the actions.
*/ */
class ACTIONS class ACTIONS
{ {
@ -184,28 +184,26 @@ public:
static TOOL_ACTION reportBug; static TOOL_ACTION reportBug;
/** /**
* Function TranslateLegacyId() * Translate legacy tool ids to the corresponding TOOL_ACTION name.
* Translates legacy tool ids to the corresponding TOOL_ACTION name. *
* @param aId is legacy tool id to be translated. * @param aId is legacy tool id to be translated.
* @return std::string is name of the corresponding TOOL_ACTION. It may be empty, if there is * @return std::string is name of the corresponding TOOL_ACTION. It may be empty, if there is
* no corresponding TOOL_ACTION. * no corresponding TOOL_ACTION.
*/ */
virtual OPT<TOOL_EVENT> TranslateLegacyId( int aId ) = 0; virtual OPT<TOOL_EVENT> TranslateLegacyId( int aId ) = 0;
///> Cursor control event types ///< Cursor control event types
enum CURSOR_EVENT_TYPE { CURSOR_NONE, CURSOR_UP, CURSOR_DOWN, CURSOR_LEFT, CURSOR_RIGHT, enum CURSOR_EVENT_TYPE { CURSOR_NONE, CURSOR_UP, CURSOR_DOWN, CURSOR_LEFT, CURSOR_RIGHT,
CURSOR_CLICK, CURSOR_DBL_CLICK, CURSOR_RIGHT_CLICK, CURSOR_CLICK, CURSOR_DBL_CLICK, CURSOR_RIGHT_CLICK,
CURSOR_FAST_MOVE = 0x8000 }; CURSOR_FAST_MOVE = 0x8000 };
///> Remove event modifier flags ///< Remove event modifier flags
enum class REMOVE_FLAGS { NORMAL = 0x00, ALT = 0x01, CUT = 0x02 }; enum class REMOVE_FLAGS { NORMAL = 0x00, ALT = 0x01, CUT = 0x02 };
}; };
/** /**
* EVENTS * Gather all the events that are shared by tools.
*
* Gathers all the events that are shared by tools.
*/ */
class EVENTS class EVENTS
{ {
@ -214,13 +212,13 @@ public:
const static TOOL_EVENT UnselectedEvent; const static TOOL_EVENT UnselectedEvent;
const static TOOL_EVENT ClearedEvent; const static TOOL_EVENT ClearedEvent;
//< Selected item had a property changed (except movement) ///< Selected item had a property changed (except movement)
const static TOOL_EVENT SelectedItemsModified; const static TOOL_EVENT SelectedItemsModified;
//< Selected items were moved, this can be very high frequency on the canvas, use with care ///< Selected items were moved, this can be very high frequency on the canvas, use with care
const static TOOL_EVENT SelectedItemsMoved; const static TOOL_EVENT SelectedItemsMoved;
///> Used to inform tools that the selection should temporarily be non-editable ///< Used to inform tools that the selection should temporarily be non-editable
const static TOOL_EVENT InhibitSelectionEditing; const static TOOL_EVENT InhibitSelectionEditing;
const static TOOL_EVENT UninhibitSelectionEditing; const static TOOL_EVENT UninhibitSelectionEditing;
}; };

View File

@ -1,7 +1,7 @@
/* /*
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2019 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 2019-2020 KiCad Developers, see AUTHORS.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -29,9 +29,7 @@
class EDA_BASE_FRAME; class EDA_BASE_FRAME;
/** /**
* COMMON_CONTROL * Handle actions that are shared between different applications
*
* Handles actions that are shared between different applications
*/ */
class COMMON_CONTROL : public TOOL_INTERACTIVE class COMMON_CONTROL : public TOOL_INTERACTIVE
@ -57,11 +55,11 @@ public:
int GetInvolved( const TOOL_EVENT& aEvent ); int GetInvolved( const TOOL_EVENT& aEvent );
int ReportBug( const TOOL_EVENT& aEvent ); int ReportBug( const TOOL_EVENT& aEvent );
///> Sets up handlers for various events. ///< Sets up handlers for various events.
void setTransitions() override; void setTransitions() override;
private: private:
///> Pointer to the currently used edit frame. ///< Pointer to the currently used edit frame.
EDA_BASE_FRAME* m_frame; EDA_BASE_FRAME* m_frame;
static wxString m_bugReportUrl; static wxString m_bugReportUrl;

View File

@ -2,6 +2,8 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2014-2016 CERN * Copyright (C) 2014-2016 CERN
* Copyright (C) 2019-2020 KiCad Developers, see AUTHORS.txt for contributors.
*
* @author Maciej Suminski <maciej.suminski@cern.ch> * @author Maciej Suminski <maciej.suminski@cern.ch>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
@ -30,11 +32,8 @@
class EDA_DRAW_FRAME; class EDA_DRAW_FRAME;
/** /**
* COMMON_TOOLS * Handles action that are shared between different applications.
*
* Handles actions that are shared between different applications
*/ */
class COMMON_TOOLS : public TOOL_INTERACTIVE class COMMON_TOOLS : public TOOL_INTERACTIVE
{ {
public: public:
@ -90,30 +89,29 @@ public:
private: private:
/** /**
* Enum ZOOM_FIT_TYPE_T * The set of "Zoom to Fit" types that can be performed.
* is the set of "Zoom to Fit" types that can be performed
*/ */
enum ZOOM_FIT_TYPE_T enum ZOOM_FIT_TYPE_T
{ {
ZOOM_FIT_ALL, // Zoom to fall all items in view INCLUDING page and border ZOOM_FIT_ALL, ///< Zoom to fall all items in view INCLUDING page and border
ZOOM_FIT_OBJECTS, // Zoom to fit all items in view EXCLUDING page and border ZOOM_FIT_OBJECTS, ///< Zoom to fit all items in view EXCLUDING page and border
}; };
///> Sets up handlers for various events. ///< Sets up handlers for various events.
void setTransitions() override; void setTransitions() override;
///> Pointer to the currently used edit frame. ///< Pointer to the currently used edit frame.
EDA_DRAW_FRAME* m_frame; EDA_DRAW_FRAME* m_frame;
int doZoomInOut( bool aDirection, bool aCenterOnCursor ); int doZoomInOut( bool aDirection, bool aCenterOnCursor );
///> Note: idx == 0 is Auto; idx == 1 is first entry in zoomList ///< Note: idx == 0 is Auto; idx == 1 is first entry in zoomList
int doZoomToPreset( int idx, bool aCenterOnCursor ); int doZoomToPreset( int idx, bool aCenterOnCursor );
int doZoomFit( ZOOM_FIT_TYPE_T aFitType ); int doZoomFit( ZOOM_FIT_TYPE_T aFitType );
std::vector<VECTOR2I> m_grids; // grids from APP_SETTINGS converted to internal units std::vector<VECTOR2I> m_grids; ///< Grids from #APP_SETTINGS converted to internal units
// and with the user grid appended ///< and with the user grid appended.
// The last used units in each system (used for toggling between metric and imperial) // The last used units in each system (used for toggling between metric and imperial)
EDA_UNITS m_imperialUnit; EDA_UNITS m_imperialUnit;

View File

@ -2,6 +2,8 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2015 CERN * Copyright (C) 2015 CERN
* Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors.
*
* @author Maciej Suminski <maciej.suminski@cern.ch> * @author Maciej Suminski <maciej.suminski@cern.ch>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
@ -38,7 +40,7 @@ class TOOL_INTERACTIVE;
class CONDITIONAL_MENU : public ACTION_MENU class CONDITIONAL_MENU : public ACTION_MENU
{ {
public: public:
///> Constant to indicate that we do not care about an ENTRY location in the menu. ///< Constant to indicate that we do not care about an #ENTRY location in the menu.
static const int ANY_ORDER = -1; static const int ANY_ORDER = -1;
CONDITIONAL_MENU( TOOL_INTERACTIVE* aTool ); CONDITIONAL_MENU( TOOL_INTERACTIVE* aTool );
@ -46,12 +48,12 @@ public:
ACTION_MENU* create() const override; ACTION_MENU* create() const override;
/** /**
* Adds a menu entry to run a TOOL_ACTION on selected items. * Add a menu entry to run a #TOOL_ACTION on selected items.
* *
* @param aAction is a menu entry to be added. * @param aAction is a menu entry to be added.
* @param aCondition is a condition that has to be fulfilled to show the menu entry in the menu. * @param aCondition is a condition that has to be fulfilled to show the menu entry in the menu.
* @param aOrder determines location of the added item, higher numbers are put on the bottom. * @param aOrder determines location of the added item, higher numbers are put on the bottom.
* You may use ANY_ORDER here if you think it does not matter. * You may use ANY_ORDER here if you think it does not matter.
*/ */
void AddItem( const TOOL_ACTION& aAction, const SELECTION_CONDITION& aCondition, void AddItem( const TOOL_ACTION& aAction, const SELECTION_CONDITION& aCondition,
int aOrder = ANY_ORDER ); int aOrder = ANY_ORDER );
@ -60,15 +62,15 @@ public:
const SELECTION_CONDITION& aCondition, int aOrder = ANY_ORDER ); const SELECTION_CONDITION& aCondition, int aOrder = ANY_ORDER );
/** /**
* Adds a checked menu entry to run a TOOL_ACTION on selected items. * Add a checked menu entry to run a TOOL_ACTION on selected items.
* *
* The condition for checking the menu entry should be supplied through a ACTION_CONDITION * The condition for checking the menu entry should be supplied through a #ACTION_CONDITION
* registered with the ACTION_MANAGER. * registered with the #ACTION_MANAGER.
* *
* @param aAction is a menu entry to be added. * @param aAction is a menu entry to be added.
* @param aCondition is a condition that has to be fulfilled to show the menu entry in the menu. * @param aCondition is a condition that has to be fulfilled to show the menu entry in the menu.
* @param aOrder determines location of the added item, higher numbers are put on the bottom. * @param aOrder determines location of the added item, higher numbers are put on the bottom.
* You may use ANY_ORDER here if you think it does not matter. * You may use #ANY_ORDER here if you think it does not matter.
*/ */
void AddCheckItem( const TOOL_ACTION& aAction, const SELECTION_CONDITION& aCondition, void AddCheckItem( const TOOL_ACTION& aAction, const SELECTION_CONDITION& aCondition,
int aOrder = ANY_ORDER ); int aOrder = ANY_ORDER );
@ -77,41 +79,43 @@ public:
const SELECTION_CONDITION& aCondition, int aOrder = ANY_ORDER ); const SELECTION_CONDITION& aCondition, int aOrder = ANY_ORDER );
/** /**
* Adds a submenu to the menu. CONDITIONAL_MENU takes ownership of the added menu, so it will * Add a submenu to the menu.
* be freed when the CONDITIONAL_MENU object is destroyed. * CONDITIONAL_MENU takes ownership of the added menu, so it will be freed when the
* CONDITIONAL_MENU object is destroyed.
* *
* @param aMenu is the submenu to be added. * @param aMenu is the submenu to be added.
* @param aExpand determines if the added submenu items should be added as individual items * @param aExpand determines if the added submenu items should be added as individual items
* or as a submenu. * or as a submenu.
* @param aCondition is a condition that has to be fulfilled to show the submenu entry in the menu. * @param aCondition is a condition that has to be fulfilled to show the submenu entry in
* the menu.
* @param aOrder determines location of the added menu, higher numbers are put on the bottom. * @param aOrder determines location of the added menu, higher numbers are put on the bottom.
* You may use ANY_ORDER here if you think it does not matter. * You may use ANY_ORDER here if you think it does not matter.
*/ */
void AddMenu( ACTION_MENU* aMenu, void AddMenu( ACTION_MENU* aMenu,
const SELECTION_CONDITION& aCondition = SELECTION_CONDITIONS::ShowAlways, const SELECTION_CONDITION& aCondition = SELECTION_CONDITIONS::ShowAlways,
int aOrder = ANY_ORDER ); int aOrder = ANY_ORDER );
/** /**
* Adds a separator to the menu. * Add a separator to the menu.
* *
* @param aOrder determines location of the separator, higher numbers are put on the bottom. * @param aOrder determines location of the separator, higher numbers are put on the bottom.
*/ */
void AddSeparator( int aOrder = ANY_ORDER ); void AddSeparator( int aOrder = ANY_ORDER );
/** /**
* Updates the contents of the menu based on the supplied conditions. * Update the contents of the menu based on the supplied conditions.
*/ */
void Evaluate( SELECTION& aSelection ); void Evaluate( SELECTION& aSelection );
/** /**
* Updates the initial contents so that wxWidgets doesn't get its knickers tied in a knot * Update the initial contents so that wxWidgets doesn't get its knickers tied in a knot
* over the menu being empty (mainly an issue on GTK, but also on OSX with the preferences * over the menu being empty (mainly an issue on GTK, but also on OSX with the preferences
* and quit menu items). * and quit menu items).
*/ */
void Resolve(); void Resolve();
private: private:
///> Helper class to organize menu entries. ///< Helper class to organize menu entries.
class ENTRY class ENTRY
{ {
public: public:
@ -158,7 +162,7 @@ private:
~ENTRY(); ~ENTRY();
///> Possible entry types. ///< Possible entry types.
enum ENTRY_TYPE { enum ENTRY_TYPE {
ACTION, ACTION,
MENU, MENU,
@ -226,19 +230,19 @@ private:
wxMenuItem* wxItem; wxMenuItem* wxItem;
} m_data; } m_data;
///> Condition to be fulfilled to show the entry in menu. ///< Condition to be fulfilled to show the entry in menu.
SELECTION_CONDITION m_condition; SELECTION_CONDITION m_condition;
///> Order number, the higher the number the lower position it takes it is in the menu. ///< Order number, the higher the number the lower position it takes it is in the menu.
int m_order; int m_order;
bool m_isCheckmarkEntry; bool m_isCheckmarkEntry;
}; };
///> Inserts the entry, preserving the requested order. ///< Inserts the entry, preserving the requested order.
void addEntry( ENTRY aEntry ); void addEntry( ENTRY aEntry );
///> List of all menu entries. ///< List of all menu entries.
std::list<ENTRY> m_entries; std::list<ENTRY> m_entries;
}; };

View File

@ -2,8 +2,9 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2013 CERN * Copyright (C) 2013 CERN
* Copyright (C) 2016-2020 KiCad Developers, see AUTHORS.txt for contributors.
*
* @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch> * @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
* Copyright (C) 2016-2019 KiCad Developers, see AUTHORS.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -39,8 +40,9 @@
#include <advanced_config.h> #include <advanced_config.h>
/** /**
* Class COROUNTINE. * Implement a coroutine.
* Implements a coroutine. Wikipedia has a good explanation: *
* Wikipedia has a good explanation:
* *
* "Coroutines are computer program components that generalize subroutines to * "Coroutines are computer program components that generalize subroutines to
* allow multiple entry points for suspending and resuming execution at certain locations. * allow multiple entry points for suspending and resuming execution at certain locations.
@ -135,8 +137,7 @@ public:
} }
/** /**
* Constructor * Create a coroutine from a member method of an object.
* Creates a coroutine from a member method of an object
*/ */
template <class T> template <class T>
COROUTINE( T* object, ReturnType(T::*ptr)( ArgType ) ) : COROUTINE( T* object, ReturnType(T::*ptr)( ArgType ) ) :
@ -145,8 +146,7 @@ public:
} }
/** /**
* Constructor * Create a coroutine from a delegate object.
* Creates a coroutine from a delegate object
*/ */
COROUTINE( std::function<ReturnType(ArgType)> aEntry ) : COROUTINE( std::function<ReturnType(ArgType)> aEntry ) :
m_func( std::move( aEntry ) ), m_func( std::move( aEntry ) ),
@ -176,9 +176,8 @@ public:
public: public:
/** /**
* Function KiYield() * Stop execution of the coroutine and returns control to the caller.
* *
* Stops execution of the coroutine and returns control to the caller.
* After a yield, Call() or Resume() methods invoked by the caller will * After a yield, Call() or Resume() methods invoked by the caller will
* immediately return true, indicating that we are not done yet, just asleep. * immediately return true, indicating that we are not done yet, just asleep.
*/ */
@ -188,10 +187,9 @@ public:
} }
/** /**
* Function KiYield() * KiYield with a value.
* *
* KiYield with a value - passes a value of given type to the caller. * Passe a value of given type to the caller. Useful for implementing generator objects.
* Useful for implementing generator objects.
*/ */
void KiYield( ReturnType& aRetVal ) void KiYield( ReturnType& aRetVal )
{ {
@ -200,9 +198,8 @@ public:
} }
/** /**
* Function RunMainStack() * Run a functor inside the application main stack context.
* *
* Run a functor inside the application main stack context
* Call this function for example if the operation will spawn a webkit browser instance which * Call this function for example if the operation will spawn a webkit browser instance which
* will walk the stack to the upper border of the address space on mac osx systems because * will walk the stack to the upper border of the address space on mac osx systems because
* its javascript needs garbage collection (for example if you paste text into an edit box). * its javascript needs garbage collection (for example if you paste text into an edit box).
@ -214,12 +211,12 @@ public:
} }
/** /**
* Function Call() * Start execution of a coroutine, passing args as its arguments.
* *
* Starts execution of a coroutine, passing args as its arguments. Call this method * Call this method from the application main stack only.
* from the application main stack only. *
* @return true, if the coroutine has yielded and false if it has finished its * @return true if the coroutine has yielded and false if it has finished its
* execution (returned). * execution (returned).
*/ */
bool Call( ArgType aArg ) bool Call( ArgType aArg )
{ {
@ -231,12 +228,12 @@ public:
} }
/** /**
* Function Call() * Start execution of a coroutine, passing args as its arguments.
* *
* Starts execution of a coroutine, passing args as its arguments. Call this method * Call this method for a nested coroutine invocation.
* for a nested coroutine invocation. *
* @return true, if the coroutine has yielded and false if it has finished its * @return true if the coroutine has yielded and false if it has finished its
* execution (returned). * execution (returned).
*/ */
bool Call( const COROUTINE& aCor, ArgType aArg ) bool Call( const COROUTINE& aCor, ArgType aArg )
{ {
@ -248,13 +245,13 @@ public:
} }
/** /**
* Function Resume() * Resume execution of a previously yielded coroutine.
* *
* Resumes execution of a previously yielded coroutine. Call this method only * Call this method only from the main application stack.
* from the main application stack. *
* @return true, if the coroutine has yielded again and false if it has finished its * @return true if the coroutine has yielded again and false if it has finished its
* execution (returned). * execution (returned).
*/ */
bool Resume() bool Resume()
{ {
CALL_CONTEXT ctx; CALL_CONTEXT ctx;
@ -265,13 +262,13 @@ public:
} }
/** /**
* Function Resume() * Resume execution of a previously yielded coroutine.
* *
* Resumes execution of a previously yielded coroutine. Call this method * Call this method for a nested coroutine invocation.
* for a nested coroutine invocation. *
* @return true, if the coroutine has yielded again and false if it has finished its * @return true if the coroutine has yielded again and false if it has finished its
* execution (returned). * execution (returned).
*/ */
bool Resume( const COROUTINE& aCor ) bool Resume( const COROUTINE& aCor )
{ {
INVOCATION_ARGS args{ INVOCATION_ARGS::FROM_ROUTINE, this, aCor.m_callContext }; INVOCATION_ARGS args{ INVOCATION_ARGS::FROM_ROUTINE, this, aCor.m_callContext };
@ -282,9 +279,7 @@ public:
} }
/** /**
* Function ReturnValue() * Return the yielded value (the argument KiYield() was called with).
*
* Returns the yielded value (the argument KiYield() was called with)
*/ */
const ReturnType& ReturnValue() const const ReturnType& ReturnValue() const
{ {
@ -292,9 +287,7 @@ public:
} }
/** /**
* Function Running() * @return true if the coroutine is active.
*
* @return true, if the coroutine is active
*/ */
bool Running() const bool Running() const
{ {
@ -314,7 +307,8 @@ private:
size_t stackSize = m_stacksize; size_t stackSize = m_stacksize;
void* sp = nullptr; void* sp = nullptr;
#ifndef LIBCONTEXT_HAS_OWN_STACK #ifndef LIBCONTEXT_HAS_OWN_STACK
// fixme: Clean up stack stuff. Add a guard // fixme: Clean up stack stuff. Add a guard
m_stack.reset( new char[stackSize] ); m_stack.reset( new char[stackSize] );
@ -327,7 +321,7 @@ private:
#ifdef KICAD_USE_VALGRIND #ifdef KICAD_USE_VALGRIND
valgrind_stack = VALGRIND_STACK_REGISTER( sp, m_stack.get() ); valgrind_stack = VALGRIND_STACK_REGISTER( sp, m_stack.get() );
#endif #endif
#endif #endif
m_callee = libcontext::make_fcontext( sp, stackSize, callerStub ); m_callee = libcontext::make_fcontext( sp, stackSize, callerStub );
m_running = true; m_running = true;
@ -345,6 +339,7 @@ private:
static void callerStub( intptr_t aData ) static void callerStub( intptr_t aData )
{ {
INVOCATION_ARGS& args = *reinterpret_cast<INVOCATION_ARGS*>( aData ); INVOCATION_ARGS& args = *reinterpret_cast<INVOCATION_ARGS*>( aData );
// get pointer to self // get pointer to self
COROUTINE* cor = args.destination; COROUTINE* cor = args.destination;
cor->m_callContext = args.context; cor->m_callContext = args.context;
@ -364,7 +359,7 @@ private:
{ {
args = reinterpret_cast<INVOCATION_ARGS*>( args = reinterpret_cast<INVOCATION_ARGS*>(
libcontext::jump_fcontext( &m_caller, m_callee, libcontext::jump_fcontext( &m_caller, m_callee,
reinterpret_cast<intptr_t>( args ) ) reinterpret_cast<intptr_t>( args ) )
); );
return args; return args;
@ -374,9 +369,10 @@ private:
{ {
INVOCATION_ARGS args{ INVOCATION_ARGS::FROM_ROUTINE, nullptr, nullptr }; INVOCATION_ARGS args{ INVOCATION_ARGS::FROM_ROUTINE, nullptr, nullptr };
INVOCATION_ARGS* ret; INVOCATION_ARGS* ret;
ret = reinterpret_cast<INVOCATION_ARGS*>( ret = reinterpret_cast<INVOCATION_ARGS*>(
libcontext::jump_fcontext( &m_callee, m_caller, libcontext::jump_fcontext( &m_callee, m_caller,
reinterpret_cast<intptr_t>( &args ) ) reinterpret_cast<intptr_t>( &args ) )
); );
m_callContext = ret->context; m_callContext = ret->context;

View File

@ -2,6 +2,8 @@
* This program source code file is part of KICAD, a free EDA CAD application. * This program source code file is part of KICAD, a free EDA CAD application.
* *
* Copyright (C) 2014 CERN * Copyright (C) 2014 CERN
* Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors.
*
* @author Maciej Suminski <maciej.suminski@cern.ch> * @author Maciej Suminski <maciej.suminski@cern.ch>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
@ -42,18 +44,16 @@ enum GRID_CONSTRAINT_TYPE
/** /**
* EDIT_CONSTRAINT * Describe constraints between two edit handles.
* *
* Allows one to describe constraints between two edit handles. After the constrained handle is changed, * After the constrained handle is changed, Apply() has to be called to fix its coordinates
* Apply() has to be called to fix its coordinates according to the implemented constraint. * according to the implemented constraint.
*/ */
template<class EDIT_TYPE> template<class EDIT_TYPE>
class EDIT_CONSTRAINT class EDIT_CONSTRAINT
{ {
public: public:
/** /**
* Constructor
*
* @param aConstrained is EDIT_POINT to which the constraint is applied. * @param aConstrained is EDIT_POINT to which the constraint is applied.
*/ */
EDIT_CONSTRAINT( EDIT_TYPE& aConstrained ) : m_constrained( aConstrained ) {}; EDIT_CONSTRAINT( EDIT_TYPE& aConstrained ) : m_constrained( aConstrained ) {};
@ -61,16 +61,12 @@ public:
virtual ~EDIT_CONSTRAINT() {}; virtual ~EDIT_CONSTRAINT() {};
/** /**
* Function Apply() * Correct coordinates of the constrained edit handle.
*
* Corrects coordinates of the constrained edit handle.
*/ */
virtual void Apply( EDIT_TYPE& aHandle ) = 0; virtual void Apply( EDIT_TYPE& aHandle ) = 0;
/** /**
* Function Apply() * Correct coordinates of the constrained edit handle.
*
* Corrects coordinates of the constrained edit handle.
*/ */
void Apply() void Apply()
{ {
@ -78,21 +74,17 @@ public:
} }
protected: protected:
EDIT_TYPE& m_constrained; ///< Point that is constrained by rules implemented by Apply() EDIT_TYPE& m_constrained; ///< Point that is constrained by rules implemented by Apply().
}; };
/** /**
* EC_VERTICAL. * #EDIT_CONSTRAINT that imposes a constraint that two points have to have the same X coordinate.
*
* EDIT_CONSTRAINT that imposes a constraint that two points have to have the same X coordinate.
*/ */
class EC_VERTICAL : public EDIT_CONSTRAINT<EDIT_POINT> class EC_VERTICAL : public EDIT_CONSTRAINT<EDIT_POINT>
{ {
public: public:
/** /**
* Constructor.
*
* @param aConstrained is the point that is put under constrain. * @param aConstrained is the point that is put under constrain.
* @param aConstrainer is the point that is the source of the constrain. * @param aConstrainer is the point that is the source of the constrain.
*/ */
@ -100,7 +92,7 @@ public:
EDIT_CONSTRAINT<EDIT_POINT>( aConstrained ), m_constrainer( aConstrainer ) EDIT_CONSTRAINT<EDIT_POINT>( aConstrained ), m_constrainer( aConstrainer )
{} {}
///> @copydoc EDIT_CONSTRAINT::Apply() ///< @copydoc EDIT_CONSTRAINT::Apply()
virtual void Apply( EDIT_POINT& aHandle ) override; virtual void Apply( EDIT_POINT& aHandle ) override;
private: private:
@ -109,16 +101,12 @@ private:
/** /**
* EC_HORIZONTAL. * #EDIT_CONSTRAINT that imposes a constraint that two points have to have the same Y coordinate.
*
* EDIT_CONSTRAINT that imposes a constraint that two points have to have the same Y coordinate.
*/ */
class EC_HORIZONTAL : public EDIT_CONSTRAINT<EDIT_POINT> class EC_HORIZONTAL : public EDIT_CONSTRAINT<EDIT_POINT>
{ {
public: public:
/** /**
* Constructor.
*
* @param aConstrained is the point that is put under constrain. * @param aConstrained is the point that is put under constrain.
* @param aConstrainer is the point that is the source of the constrain. * @param aConstrainer is the point that is the source of the constrain.
*/ */
@ -126,7 +114,7 @@ public:
EDIT_CONSTRAINT<EDIT_POINT>( aConstrained ), m_constrainer( aConstrainer ) EDIT_CONSTRAINT<EDIT_POINT>( aConstrained ), m_constrainer( aConstrainer )
{} {}
///> @copydoc EDIT_CONSTRAINT::Apply() ///< @copydoc EDIT_CONSTRAINT::Apply()
virtual void Apply( EDIT_POINT& aHandle ) override; virtual void Apply( EDIT_POINT& aHandle ) override;
private: private:
@ -135,17 +123,13 @@ private:
/** /**
* EC_45DEGREE * #EDIT_CONSTRAINT that imposes a constraint that two points have to be located at angle of 45
*
* EDIT_CONSTRAINT that imposes a constraint that two points have to be located at angle of 45
* degree multiplicity. * degree multiplicity.
*/ */
class EC_45DEGREE : public EDIT_CONSTRAINT<EDIT_POINT> class EC_45DEGREE : public EDIT_CONSTRAINT<EDIT_POINT>
{ {
public: public:
/** /**
* Constructor.
*
* @param aConstrained is the point that is put under constrain. * @param aConstrained is the point that is put under constrain.
* @param aConstrainer is the point that is the source of the constrain. * @param aConstrainer is the point that is the source of the constrain.
*/ */
@ -153,7 +137,7 @@ public:
EDIT_CONSTRAINT<EDIT_POINT>( aConstrained ), m_constrainer( aConstrainer ) EDIT_CONSTRAINT<EDIT_POINT>( aConstrained ), m_constrainer( aConstrainer )
{} {}
///> @copydoc EDIT_CONSTRAINT::Apply() ///< @copydoc EDIT_CONSTRAINT::Apply()
virtual void Apply( EDIT_POINT& aHandle ) override; virtual void Apply( EDIT_POINT& aHandle ) override;
private: private:
@ -162,9 +146,7 @@ private:
/** /**
* EC_LINE * #EDIT_CONSTRAINT that imposes a constraint that a point has to lie on a line (determined
*
* EDIT_CONSTRAINT that imposes a constraint that a point has to lie on a line (determined
* by 2 points). * by 2 points).
*/ */
class EC_LINE : public EDIT_CONSTRAINT<EDIT_POINT> class EC_LINE : public EDIT_CONSTRAINT<EDIT_POINT>
@ -172,7 +154,7 @@ class EC_LINE : public EDIT_CONSTRAINT<EDIT_POINT>
public: public:
EC_LINE( EDIT_POINT& aConstrained, const EDIT_POINT& aConstrainer ); EC_LINE( EDIT_POINT& aConstrained, const EDIT_POINT& aConstrainer );
///> @copydoc EDIT_CONSTRAINT::Apply() ///< @copydoc EDIT_CONSTRAINT::Apply()
virtual void Apply( EDIT_POINT& aHandle ) override; virtual void Apply( EDIT_POINT& aHandle ) override;
private: private:
@ -182,16 +164,12 @@ private:
/** /**
* EC_CIRCLE. * #EDIT_CONSTRAINT that imposes a constraint that a point has to lie on a circle.
*
* EDIT_CONSTRAINT that imposes a constraint that a point has to lie on a circle.
*/ */
class EC_CIRCLE : public EDIT_CONSTRAINT<EDIT_POINT> class EC_CIRCLE : public EDIT_CONSTRAINT<EDIT_POINT>
{ {
public: public:
/** /**
* Constructor.
*
* @param aConstrained is the point that is put under constrain. * @param aConstrained is the point that is put under constrain.
* @param aCenter is the point that is the center of the circle. * @param aCenter is the point that is the center of the circle.
* @param aEnd is the point that decides on the radius of the circle. * @param aEnd is the point that decides on the radius of the circle.
@ -200,22 +178,20 @@ public:
EDIT_CONSTRAINT<EDIT_POINT>( aConstrained ), m_center( aCenter ), m_end( aEnd ) EDIT_CONSTRAINT<EDIT_POINT>( aConstrained ), m_center( aCenter ), m_end( aEnd )
{} {}
///> @copydoc EDIT_CONSTRAINT::Apply() ///< @copydoc EDIT_CONSTRAINT::Apply()
virtual void Apply( EDIT_POINT& aHandle ) override; virtual void Apply( EDIT_POINT& aHandle ) override;
private: private:
///> Point that imposes the constraint (center of the circle). ///< Point that imposes the constraint (center of the circle).
const EDIT_POINT& m_center; const EDIT_POINT& m_center;
///> Point that imposes the constraint (decides on the radius of the circle). ///< Point that imposes the constraint (decides on the radius of the circle).
const EDIT_POINT& m_end; const EDIT_POINT& m_end;
}; };
/** /**
* EC_CONVERGING * #EDIT_CONSTRAINT for 3 segments: dragged and two adjacent ones, enforcing to keep their slopes
*
* EDIT_CONSTRAINT for 3 segments: dragged and two adjacent ones, enforcing to keep their slopes
* and allows only to change ending points. Applied to zones. * and allows only to change ending points. Applied to zones.
*/ */
class EC_CONVERGING : public EDIT_CONSTRAINT<EDIT_LINE> class EC_CONVERGING : public EDIT_CONSTRAINT<EDIT_LINE>
@ -225,39 +201,37 @@ public:
virtual ~EC_CONVERGING(); virtual ~EC_CONVERGING();
///> @copydoc EDIT_CONSTRAINT::Apply() ///< @copydoc EDIT_CONSTRAINT::Apply()
virtual void Apply( EDIT_LINE& aHandle ) override; virtual void Apply( EDIT_LINE& aHandle ) override;
private: private:
///> Constraint for origin side segment. ///< Constraint for origin side segment.
EDIT_CONSTRAINT<EDIT_POINT>* m_originSideConstraint; EDIT_CONSTRAINT<EDIT_POINT>* m_originSideConstraint;
///> Constraint for end side segment. ///< Constraint for end side segment.
EDIT_CONSTRAINT<EDIT_POINT>* m_endSideConstraint; EDIT_CONSTRAINT<EDIT_POINT>* m_endSideConstraint;
///> Additional constriant, applied when at least two points are collinear. It is a pointer to ///< Additional constraint, applied when at least two points are collinear. It is a pointer to
///> m_[origin/end]SideConstraint, so it should not be freed. ///< m_[origin/end]SideConstraint, so it should not be freed.
EDIT_CONSTRAINT<EDIT_POINT>* m_colinearConstraint; EDIT_CONSTRAINT<EDIT_POINT>* m_colinearConstraint;
///> EDIT_POINTS instance that stores currently modified lines. ///< EDIT_POINTS instance that stores currently modified lines.
EDIT_POINTS& m_editPoints; EDIT_POINTS& m_editPoints;
///> Vector that represents the initial direction of the dragged segment. ///< Vector that represents the initial direction of the dragged segment.
VECTOR2I m_draggedVector; VECTOR2I m_draggedVector;
}; };
/** /**
* EC_SNAPLINE * #EDIT_CONSTRAINT for a EDIT_LINE, one of the ends is snapped to a spot determined by a
*
* EDIT_CONSTRAINT for a EDIT_LINE, one of the ends is snapped to a spot determined by a
* transform function passed as parameter (e.g. it can be snapped to a grid), instead of having * transform function passed as parameter (e.g. it can be snapped to a grid), instead of having
* the line center snapped to a point. * the line center snapped to a point.
*/ */
class EC_SNAPLINE : public EDIT_CONSTRAINT<EDIT_LINE> class EC_SNAPLINE : public EDIT_CONSTRAINT<EDIT_LINE>
{ {
public: public:
///> Typedef for a function that determines snapping point. ///< Typedef for a function that determines snapping point.
typedef boost::function<VECTOR2D (const VECTOR2D&)> V2D_TRANSFORM_FUN; typedef boost::function<VECTOR2D (const VECTOR2D&)> V2D_TRANSFORM_FUN;
EC_SNAPLINE( EDIT_LINE& aLine, V2D_TRANSFORM_FUN aSnapFun ); EC_SNAPLINE( EDIT_LINE& aLine, V2D_TRANSFORM_FUN aSnapFun );
@ -265,19 +239,17 @@ public:
virtual ~EC_SNAPLINE() virtual ~EC_SNAPLINE()
{} {}
///> @copydoc EDIT_CONSTRAINT::Apply() ///< @copydoc EDIT_CONSTRAINT::Apply()
virtual void Apply( EDIT_LINE& aHandle ) override; virtual void Apply( EDIT_LINE& aHandle ) override;
private: private:
///> Function that determines snapping point. ///< Function that determines snapping point.
V2D_TRANSFORM_FUN m_snapFun; V2D_TRANSFORM_FUN m_snapFun;
}; };
/** /**
* EC_PERPLINE * #EDIT_CONSTRAINT for a EDIT_LINE, that constrains the line to move perpendicular
*
* EDIT_CONSTRAINT for a EDIT_LINE, that constrains the line to move perpendicular
* to the line itself. * to the line itself.
*/ */
class EC_PERPLINE : public EDIT_CONSTRAINT<EDIT_LINE> class EC_PERPLINE : public EDIT_CONSTRAINT<EDIT_LINE>
@ -289,7 +261,7 @@ public:
virtual ~EC_PERPLINE() virtual ~EC_PERPLINE()
{} {}
///> @copydoc EDIT_CONSTRAINT::Apply() ///< @copydoc EDIT_CONSTRAINT::Apply()
virtual void Apply( EDIT_LINE& aHandle ) override; virtual void Apply( EDIT_LINE& aHandle ) override;
private: private:

View File

@ -2,6 +2,8 @@
* This program source code file is part of KICAD, a free EDA CAD application. * This program source code file is part of KICAD, a free EDA CAD application.
* *
* Copyright (C) 2014-2017 CERN * Copyright (C) 2014-2017 CERN
* Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors.
*
* @author Maciej Suminski <maciej.suminski@cern.ch> * @author Maciej Suminski <maciej.suminski@cern.ch>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
@ -37,17 +39,15 @@
/** /**
* EDIT_POINT * Represent a single point that can be used for modifying items.
* *
* Represents a single point that can be used for modifying items. It is directly related to one * It is directly related to one of points in a graphical item (e.g. vertex of a zone or
* of points in a graphical item (e.g. vertex of a zone or center of a circle). * center of a circle).
*/ */
class EDIT_POINT class EDIT_POINT
{ {
public: public:
/** /**
* Constructor
*
* @param aPoint stores coordinates for EDIT_POINT. * @param aPoint stores coordinates for EDIT_POINT.
*/ */
EDIT_POINT( const VECTOR2I& aPoint, std::pair<EDA_ITEM*, int> aConnected = { nullptr, 0 } ) : EDIT_POINT( const VECTOR2I& aPoint, std::pair<EDA_ITEM*, int> aConnected = { nullptr, 0 } ) :
@ -62,10 +62,10 @@ public:
virtual ~EDIT_POINT() {} virtual ~EDIT_POINT() {}
/** /**
* Function GetPosition() * Return coordinates of an EDIT_POINT.
* *
* Returns coordinates of an EDIT_POINT. Note that it may be different than coordinates of * @note It may be different than coordinates of a graphical item that is bound to the
* a graphical item that is bound to the EDIT_POINT. * EDIT_POINT.
*/ */
virtual VECTOR2I GetPosition() const virtual VECTOR2I GetPosition() const
{ {
@ -81,9 +81,7 @@ public:
} }
/** /**
* Function GetX() * Return X coordinate of an EDIT_POINT.
*
* Returns X coordinate of an EDIT_POINT.
*/ */
inline int GetX() const inline int GetX() const
{ {
@ -91,9 +89,7 @@ public:
} }
/** /**
* Function GetY() * Return Y coordinate of an EDIT_POINT.
*
* Returns Y coordinate of an EDIT_POINT.
*/ */
inline int GetY() const inline int GetY() const
{ {
@ -101,10 +97,10 @@ public:
} }
/** /**
* Function SetPosition() * Set new coordinates for an EDIT_POINT.
*
* It does not change the coordinates of a graphical item.
* *
* Sets new coordinates for an EDIT_POINT. It does not change the coordinates of a graphical
* item.
* @param aPosition are new coordinates. * @param aPosition are new coordinates.
*/ */
virtual void SetPosition( const VECTOR2I& aPosition ) virtual void SetPosition( const VECTOR2I& aPosition )
@ -119,18 +115,16 @@ public:
} }
/** /**
* Function WithinPoint() * Check if given point is within a square centered in the EDIT_POINT position.
* *
* Checks if given point is within a square centered in the EDIT_POINT position.
* @param aPoint is point to be checked. * @param aPoint is point to be checked.
* @param aSize is length of the square side. * @param aSize is length of the square side.
*/ */
bool WithinPoint( const VECTOR2I& aPoint, unsigned int aSize ) const; bool WithinPoint( const VECTOR2I& aPoint, unsigned int aSize ) const;
/** /**
* Function SetConstraint() * Set a constraint for and EDIT_POINT.
* *
* Sets a constraint for and EDIT_POINT.
* @param aConstraint is the constraint to be set. * @param aConstraint is the constraint to be set.
*/ */
void SetConstraint( EDIT_CONSTRAINT<EDIT_POINT>* aConstraint ) void SetConstraint( EDIT_CONSTRAINT<EDIT_POINT>* aConstraint )
@ -139,9 +133,7 @@ public:
} }
/** /**
* Function GetConstraint() * Return the constraint imposed on an EDIT_POINT. If there are no constraints, NULL is
*
* Returns the constraint imposed on an EDIT_POINT. If there are no constraints, NULL is
* returned. * returned.
*/ */
EDIT_CONSTRAINT<EDIT_POINT>* GetConstraint() const EDIT_CONSTRAINT<EDIT_POINT>* GetConstraint() const
@ -150,9 +142,7 @@ public:
} }
/** /**
* Function ClearConstraint() * Remove previously set constraint.
*
* Removes previously set constraint.
*/ */
inline void ClearConstraint() inline void ClearConstraint()
{ {
@ -160,9 +150,8 @@ public:
} }
/** /**
* Function IsConstrained() * Check if point is constrained.
* *
* Checks if point is constrained.
* @return True is point is constrained, false otherwise. * @return True is point is constrained, false otherwise.
*/ */
inline bool IsConstrained() const inline bool IsConstrained() const
@ -171,9 +160,7 @@ public:
} }
/** /**
* Function ApplyConstraint() * Correct coordinates of an EDIT_POINT by applying previously set constraint.
*
* Corrects coordinates of an EDIT_POINT by applying previously set constraint.
*/ */
virtual void ApplyConstraint() virtual void ApplyConstraint()
{ {
@ -195,43 +182,40 @@ public:
return m_position == aOther.m_position; return m_position == aOther.m_position;
} }
///> Single point size in pixels ///< Single point size in pixels
static const int POINT_SIZE = 10; static const int POINT_SIZE = 10;
///> Border size when not hovering ///< Border size when not hovering
static const int BORDER_SIZE = 2; static const int BORDER_SIZE = 2;
///> Border size when hovering ///< Border size when hovering
static const int HOVER_SIZE = 5; static const int HOVER_SIZE = 5;
private: private:
VECTOR2I m_position; // Position of EDIT_POINT VECTOR2I m_position; ///< Position of EDIT_POINT.
bool m_isActive; // True if this point is being manipulated bool m_isActive; ///< True if this point is being manipulated.
bool m_isHover; // True if this point is being hovered over bool m_isHover; ///< True if this point is being hovered over.
GRID_CONSTRAINT_TYPE m_gridConstraint; // Describes the grid snapping behavior. GRID_CONSTRAINT_TYPE m_gridConstraint; ///< Describe the grid snapping behavior.
///> An optional connected item record used to mimic polyLine behaviour with individual ///< An optional connected item record used to mimic polyLine behavior with individual
/// line segments. ///< line segments.
std::pair<EDA_ITEM*, int> m_connected; std::pair<EDA_ITEM*, int> m_connected;
///> Constraint for the point, NULL if none ///< Constraint for the point, NULL if none
std::shared_ptr<EDIT_CONSTRAINT<EDIT_POINT> > m_constraint; std::shared_ptr<EDIT_CONSTRAINT<EDIT_POINT> > m_constraint;
}; };
/** /**
* EDIT_LINE * Represent a line connecting two EDIT_POINTs.
* *
* Represents a line connecting two EDIT_POINTs. That allows one to move them * This allows one to move them both by dragging the EDIT_POINT in the middle. It uses
* both by dragging the EDIT_POINT in the middle. As it uses references to * references to EDIT_POINTs, all coordinates are automatically synchronized.
* EDIT_POINTs, all coordinates are automatically synchronized.
*/ */
class EDIT_LINE : public EDIT_POINT class EDIT_LINE : public EDIT_POINT
{ {
public: public:
/** /**
* Constructor
*
* @param aOrigin is the origin of EDIT_LINE. * @param aOrigin is the origin of EDIT_LINE.
* @param aEnd is the end of EDIT_LINE. * @param aEnd is the end of EDIT_LINE.
*/ */
@ -243,13 +227,13 @@ public:
SetGridConstraint( SNAP_BY_GRID ); SetGridConstraint( SNAP_BY_GRID );
} }
///> @copydoc EDIT_POINT::GetPosition() ///< @copydoc EDIT_POINT::GetPosition()
virtual VECTOR2I GetPosition() const override virtual VECTOR2I GetPosition() const override
{ {
return ( m_origin.GetPosition() + m_end.GetPosition() ) / 2; return ( m_origin.GetPosition() + m_end.GetPosition() ) / 2;
} }
///> @copydoc EDIT_POINT::GetPosition() ///< @copydoc EDIT_POINT::GetPosition()
virtual void SetPosition( const VECTOR2I& aPosition ) override virtual void SetPosition( const VECTOR2I& aPosition ) override
{ {
VECTOR2I difference = aPosition - GetPosition(); VECTOR2I difference = aPosition - GetPosition();
@ -258,7 +242,7 @@ public:
m_end.SetPosition( m_end.GetPosition() + difference ); m_end.SetPosition( m_end.GetPosition() + difference );
} }
///> @copydoc EDIT_POINT::ApplyConstraint() ///< @copydoc EDIT_POINT::ApplyConstraint()
virtual void ApplyConstraint() override virtual void ApplyConstraint() override
{ {
if( m_constraint ) if( m_constraint )
@ -269,9 +253,8 @@ public:
} }
/** /**
* Function SetConstraint() * Set a constraint for and EDIT_POINT.
* *
* Sets a constraint for and EDIT_POINT.
* @param aConstraint is the constraint to be set. * @param aConstraint is the constraint to be set.
*/ */
void SetConstraint( EDIT_CONSTRAINT<EDIT_LINE>* aConstraint ) void SetConstraint( EDIT_CONSTRAINT<EDIT_LINE>* aConstraint )
@ -280,9 +263,7 @@ public:
} }
/** /**
* Function GetConstraint() * Return the constraint imposed on an EDIT_POINT. If there are no constraints, NULL is
*
* Returns the constraint imposed on an EDIT_POINT. If there are no constraints, NULL is
* returned. * returned.
*/ */
EDIT_CONSTRAINT<EDIT_LINE>* GetConstraint() const EDIT_CONSTRAINT<EDIT_LINE>* GetConstraint() const
@ -291,9 +272,7 @@ public:
} }
/** /**
* Function GetOrigin() * Return the origin EDIT_POINT.
*
* Returns the origin EDIT_POINT.
*/ */
EDIT_POINT& GetOrigin() EDIT_POINT& GetOrigin()
{ {
@ -306,9 +285,7 @@ public:
} }
/** /**
* Function GetEnd() * Return the end EDIT_POINT.
*
* Returns the end EDIT_POINT.
*/ */
EDIT_POINT& GetEnd() EDIT_POINT& GetEnd()
{ {
@ -334,38 +311,31 @@ private:
EDIT_POINT& m_origin; ///< Origin point for a line EDIT_POINT& m_origin; ///< Origin point for a line
EDIT_POINT& m_end; ///< End point for a line EDIT_POINT& m_end; ///< End point for a line
///> Constraint for the point, NULL if none ///< Constraint for the point, NULL if none
std::shared_ptr<EDIT_CONSTRAINT<EDIT_LINE> > m_constraint; std::shared_ptr<EDIT_CONSTRAINT<EDIT_LINE> > m_constraint;
}; };
/** /**
* EDIT_POINTS * EDIT_POINTS is a #VIEW_ITEM that manages EDIT_POINTs and EDIT_LINEs and draws them.
*
* EDIT_POINTS is a VIEW_ITEM that manages EDIT_POINTs and EDIT_LINEs and draws them.
*/ */
class EDIT_POINTS : public EDA_ITEM class EDIT_POINTS : public EDA_ITEM
{ {
public: public:
/** /**
* Constructor.
*
* @param aParent is the item to which EDIT_POINTs are related. * @param aParent is the item to which EDIT_POINTs are related.
*/ */
EDIT_POINTS( EDA_ITEM* aParent ); EDIT_POINTS( EDA_ITEM* aParent );
/** /**
* Function FindPoint() * Return a point that is at given coordinates or NULL if there is no such point.
* *
* Returns a point that is at given coordinates or NULL if there is no such point.
* @param aLocation is the location for searched point. * @param aLocation is the location for searched point.
*/ */
EDIT_POINT* FindPoint( const VECTOR2I& aLocation, KIGFX::VIEW *aView ); EDIT_POINT* FindPoint( const VECTOR2I& aLocation, KIGFX::VIEW *aView );
/** /**
* Function GetParent() * Return parent of the EDIT_POINTS.
*
* Returns parent of the EDIT_POINTS.
*/ */
EDA_ITEM* GetParent() const EDA_ITEM* GetParent() const
{ {
@ -373,9 +343,8 @@ public:
} }
/** /**
* Function AddPoint() * Add an EDIT_POINT.
* *
* Adds an EDIT_POINT.
* @param aPoint is the new point. * @param aPoint is the new point.
*/ */
void AddPoint( const EDIT_POINT& aPoint ) void AddPoint( const EDIT_POINT& aPoint )
@ -384,9 +353,8 @@ public:
} }
/** /**
* Function AddPoint() * Add an EDIT_POINT.
* *
* Adds an EDIT_POINT.
* @param aPoint are coordinates of the new point. * @param aPoint are coordinates of the new point.
*/ */
void AddPoint( const VECTOR2I& aPoint, std::pair<EDA_ITEM*, int> aConnected = { nullptr, 0 } ) void AddPoint( const VECTOR2I& aPoint, std::pair<EDA_ITEM*, int> aConnected = { nullptr, 0 } )
@ -395,9 +363,8 @@ public:
} }
/** /**
* Function AddLine()
*
* Adds an EDIT_LINE. * Adds an EDIT_LINE.
*
* @param aLine is the new line. * @param aLine is the new line.
*/ */
void AddLine( const EDIT_LINE& aLine ) void AddLine( const EDIT_LINE& aLine )
@ -406,9 +373,8 @@ public:
} }
/** /**
* Function AddLine()
*
* Adds an EDIT_LINE. * Adds an EDIT_LINE.
*
* @param aOrigin is the origin for a new line. * @param aOrigin is the origin for a new line.
* @param aEnd is the end for a new line. * @param aEnd is the end for a new line.
*/ */
@ -418,8 +384,6 @@ public:
} }
/** /**
* Function AddBreak()
*
* Adds a break, indicating the end of a contour. * Adds a break, indicating the end of a contour.
*/ */
void AddBreak() void AddBreak()
@ -429,66 +393,60 @@ public:
} }
/** /**
* Function GetContourStartIdx() * Return index of the contour origin for a point with given index.
* *
* Returns index of the contour origin for a point with given index.
* @param aPointIdx is the index of point for which the contour origin is searched. * @param aPointIdx is the index of point for which the contour origin is searched.
* @return Index of the contour origin point. * @return Index of the contour origin point.
*/ */
int GetContourStartIdx( int aPointIdx ) const; int GetContourStartIdx( int aPointIdx ) const;
/** /**
* Function GetContourEndIdx() * Return index of the contour finish for a point with given index.
* *
* Returns index of the contour finish for a point with given index.
* @param aPointIdx is the index of point for which the contour finish is searched. * @param aPointIdx is the index of point for which the contour finish is searched.
* @return Index of the contour finish point. * @return Index of the contour finish point.
*/ */
int GetContourEndIdx( int aPointIdx ) const; int GetContourEndIdx( int aPointIdx ) const;
/** /**
* Function IsContourStart() * Check if a point with given index is a contour origin.
* *
* Checks is a point with given index is a contour origin.
* @param aPointIdx is the index of the point to be checked. * @param aPointIdx is the index of the point to be checked.
* @return True if the point is an origin of a contour. * @return True if the point is an origin of a contour.
*/ */
bool IsContourStart( int aPointIdx ) const; bool IsContourStart( int aPointIdx ) const;
/** /**
* Function IsContourEnd() * Check is a point with given index is a contour finish.
* *
* Checks is a point with given index is a contour finish.
* @param aPointIdx is the index of the point to be checked. * @param aPointIdx is the index of the point to be checked.
* @return True if the point is a finish of a contour. * @return True if the point is a finish of a contour.
*/ */
bool IsContourEnd( int aPointIdx ) const; bool IsContourEnd( int aPointIdx ) const;
/** /**
* Function Previous() * Return the point that is after the given point in the list.
* *
* Returns the point that is after the given point in the list.
* @param aPoint is the point that is supposed to be preceding the searched point. * @param aPoint is the point that is supposed to be preceding the searched point.
* @param aTraverseContours decides if in case of breaks should we return to the origin * @param aTraverseContours decides if in case of breaks should we return to the origin
* of contour or continue with the next contour. * of contour or continue with the next contour.
* @return The point following aPoint in the list. If aPoint is the first in * @return The point following aPoint in the list. If aPoint is the first in
* the list, the last from the list will be returned. If there are no points at all, NULL * the list, the last from the list will be returned. If there are no points at
* is returned. * all, NULL is returned.
*/ */
EDIT_POINT* Previous( const EDIT_POINT& aPoint, bool aTraverseContours = true ); EDIT_POINT* Previous( const EDIT_POINT& aPoint, bool aTraverseContours = true );
EDIT_LINE* Previous( const EDIT_LINE& aLine ); EDIT_LINE* Previous( const EDIT_LINE& aLine );
/** /**
* Function Next() * Return the point that is before the given point in the list.
* *
* Returns the point that is before the given point in the list.
* @param aPoint is the point that is supposed to be following the searched point. * @param aPoint is the point that is supposed to be following the searched point.
* @param aTraverseContours decides if in case of breaks should we return to the origin * @param aTraverseContours decides if in case of breaks should we return to the origin
* of contour or continue with the next contour. * of contour or continue with the next contour.
* @return The point preceding aPoint in the list. If aPoint is the last in * @return The point preceding aPoint in the list. If aPoint is the last in the list, the
* the list, the first point from the list will be returned. If there are no points at all, * first point from the list will be returned. If there are no points at all,
* NULL is returned. * NULL is returned.
*/ */
EDIT_POINT* Next( const EDIT_POINT& aPoint, bool aTraverseContours = true ); EDIT_POINT* Next( const EDIT_POINT& aPoint, bool aTraverseContours = true );
@ -515,9 +473,7 @@ public:
} }
/** /**
* Function PointsSize() * Return number of stored EDIT_POINTs.
*
* Returns number of stored EDIT_POINTs.
*/ */
unsigned int PointsSize() const unsigned int PointsSize() const
{ {
@ -525,22 +481,20 @@ public:
} }
/** /**
* Function LinesSize() * Return number of stored EDIT_LINEs.
*
* Returns number of stored EDIT_LINEs.
*/ */
unsigned int LinesSize() const unsigned int LinesSize() const
{ {
return m_lines.size(); return m_lines.size();
} }
///> @copydoc VIEW_ITEM::ViewBBox() ///< @copydoc VIEW_ITEM::ViewBBox()
virtual const BOX2I ViewBBox() const override; virtual const BOX2I ViewBBox() const override;
///> @copydoc VIEW_ITEM::ViewDraw() ///< @copydoc VIEW_ITEM::ViewDraw()
virtual void ViewDraw( int aLayer, KIGFX::VIEW* aView ) const override; virtual void ViewDraw( int aLayer, KIGFX::VIEW* aView ) const override;
///> @copydoc VIEW_ITEM::ViewGetLayers() ///< @copydoc VIEW_ITEM::ViewGetLayers()
virtual void ViewGetLayers( int aLayers[], int& aCount ) const override virtual void ViewGetLayers( int aLayers[], int& aCount ) const override
{ {
aCount = 1; aCount = 1;
@ -553,8 +507,10 @@ public:
} }
#endif #endif
/** Get class name /**
* @return string "EDIT_POINTS" * Get the class name.
*
* @return string "EDIT_POINTS".
*/ */
virtual wxString GetClass() const override virtual wxString GetClass() const override
{ {
@ -562,11 +518,11 @@ public:
} }
private: private:
EDA_ITEM* m_parent; ///< Parent of the EDIT_POINTs EDA_ITEM* m_parent; ///< Parent of the EDIT_POINTs.
std::deque<EDIT_POINT> m_points; ///< EDIT_POINTs for modifying m_parent std::deque<EDIT_POINT> m_points; ///< EDIT_POINTs for modifying m_parent.
std::deque<EDIT_LINE> m_lines; ///< EDIT_LINEs for modifying m_parent std::deque<EDIT_LINE> m_lines; ///< EDIT_LINEs for modifying m_parent.
std::list<int> m_contours; ///< Indices of end contour points std::list<int> m_contours; ///< Indices of end contour points.
bool m_allowPoints; ///< If false, only allow editing of EDIT_LINES bool m_allowPoints; ///< If false, only allow editing of EDIT_LINES.
}; };
#endif /* EDIT_POINTS_H_ */ #endif /* EDIT_POINTS_H_ */

View File

@ -33,6 +33,7 @@
class EDA_BASE_FRAME; class EDA_BASE_FRAME;
class EDA_DRAW_FRAME; class EDA_DRAW_FRAME;
/** /**
* Class that groups generic conditions for editor states. * Class that groups generic conditions for editor states.
*/ */
@ -49,116 +50,117 @@ public:
{} {}
/** /**
* Creates a functor that tests if the content of the frame is modified. * Create a functor that tests if the content of the frame is modified.
* *
* @return Functor testing for modified content * @return Functor testing for modified content.
*/ */
SELECTION_CONDITION ContentModified(); SELECTION_CONDITION ContentModified();
/** /**
* Creates a functor that tests if there are any items in the undo queue * Create a functor that tests if there are any items in the undo queue.
* *
* @return Functor testing if the undo queue has items. * @return Functor testing if the undo queue has items.
*/ */
SELECTION_CONDITION UndoAvailable(); SELECTION_CONDITION UndoAvailable();
/** /**
* Creates a functor that tests if there are any items in the redo queue * Create a functor that tests if there are any items in the redo queue.
* *
* @return Functor testing if the redo queue has items. * @return Functor testing if the redo queue has items.
*/ */
SELECTION_CONDITION RedoAvailable(); SELECTION_CONDITION RedoAvailable();
/** /**
* Creates a functor that tests if the frame has the specified units * Create a functor that tests if the frame has the specified units.
* *
* @return Functor testing the units of a frame. * @return Functor testing the units of a frame.
*/ */
SELECTION_CONDITION Units( EDA_UNITS aUnit ); SELECTION_CONDITION Units( EDA_UNITS aUnit );
/** /**
* Creates a functor testing if the specified tool is the current active tool in the frame. * Create a functor testing if the specified tool is the current active tool in the frame.
* *
* @return Functor testing the current tool of a frame * @return Functor testing the current tool of a frame.
*/ */
SELECTION_CONDITION CurrentTool( const TOOL_ACTION& aTool ); SELECTION_CONDITION CurrentTool( const TOOL_ACTION& aTool );
/** /**
* Creates a functor testing if there are no tools active in the frame. * Create a functor testing if there are no tools active in the frame.
* *
* @return Functor testing the frame has no tools running * @return Functor testing the frame has no tools running.
*/ */
SELECTION_CONDITION NoActiveTool(); SELECTION_CONDITION NoActiveTool();
/** /**
* Creates a functor testing if the grid is visible in a frame. * Create a functor testing if the grid is visible in a frame.
* *
* @note this requires the frame passed into the constructor be be derived from EDA_DRAW_FRAME. * @note This requires the frame passed into the constructor be be derived from EDA_DRAW_FRAME.
* *
* @return Functor testing if the grid is visible * @return Functor testing if the grid is visible
*/ */
SELECTION_CONDITION GridVisible(); SELECTION_CONDITION GridVisible();
/** /**
* Creates a functor testing if polar coordinates are current being used. * Create a functor testing if polar coordinates are current being used.
* *
* @note this requires the frame passed into the constructor be be derived from EDA_DRAW_FRAME. * @note This requires the frame passed into the constructor be be derived from EDA_DRAW_FRAME.
* *
* @return Functor testing if the grid is visible * @return Functor testing if the grid is visible
*/ */
SELECTION_CONDITION PolarCoordinates(); SELECTION_CONDITION PolarCoordinates();
/** /**
* Creates a functor testing if the cursor is full screen in a frame. * Create a functor testing if the cursor is full screen in a frame.
* *
* @note this requires the frame passed into the constructor be be derived from EDA_DRAW_FRAME. * @note This requires the frame passed into the constructor be be derived from EDA_DRAW_FRAME.
* *
* @return Functor testing if the cursor is full screen * @return Functor testing if the cursor is full screen
*/ */
SELECTION_CONDITION FullscreenCursor(); SELECTION_CONDITION FullscreenCursor();
/** /**
* Creates a functor testing if the specified canvas is active in the frame. * Create a functor testing if the specified canvas is active in the frame.
* *
* @note this requires the frame passed into the constructor be be derived from EDA_DRAW_FRAME. * @note This requires the frame passed into the constructor be be derived from EDA_DRAW_FRAME.
* *
* @return Functor testing the canvas type of the frame * @return Functor testing the canvas type of the frame
*/ */
SELECTION_CONDITION CanvasType( EDA_DRAW_PANEL_GAL::GAL_TYPE aType ); SELECTION_CONDITION CanvasType( EDA_DRAW_PANEL_GAL::GAL_TYPE aType );
protected: protected:
///> Helper function used by ContentModified() ///< Helper function used by ContentModified().
static bool contentModifiedFunc( const SELECTION& aSelection, EDA_BASE_FRAME* aFrame ); static bool contentModifiedFunc( const SELECTION& aSelection, EDA_BASE_FRAME* aFrame );
///> Helper function used by UndoAvailable() ///< Helper function used by UndoAvailable().
static bool undoFunc( const SELECTION& aSelection, EDA_BASE_FRAME* aFrame ); static bool undoFunc( const SELECTION& aSelection, EDA_BASE_FRAME* aFrame );
///> Helper function used by RedoAvailable() ///< Helper function used by RedoAvailable().
static bool redoFunc( const SELECTION& aSelection, EDA_BASE_FRAME* aFrame ); static bool redoFunc( const SELECTION& aSelection, EDA_BASE_FRAME* aFrame );
///> Helper function used by Units() ///< Helper function used by Units().
static bool unitsFunc( const SELECTION& aSelection, EDA_BASE_FRAME* aFrame, EDA_UNITS aUnits ); static bool unitsFunc( const SELECTION& aSelection, EDA_BASE_FRAME* aFrame, EDA_UNITS aUnits );
///> Helper function used by CurrentTool() ///< Helper function used by CurrentTool().
static bool toolFunc( const SELECTION& aSelection, EDA_BASE_FRAME* aFrame, const TOOL_ACTION& aTool ); static bool toolFunc( const SELECTION& aSelection, EDA_BASE_FRAME* aFrame,
const TOOL_ACTION& aTool );
///> Helper function used by NoActiveTool() ///< Helper function used by NoActiveTool().
static bool noToolFunc( const SELECTION& aSelection, EDA_BASE_FRAME* aFrame ); static bool noToolFunc( const SELECTION& aSelection, EDA_BASE_FRAME* aFrame );
///> Helper function used by GridVisible() ///< Helper function used by GridVisible().
static bool gridFunc( const SELECTION& aSelection, EDA_DRAW_FRAME* aFrame ); static bool gridFunc( const SELECTION& aSelection, EDA_DRAW_FRAME* aFrame );
///> Helper function used by PolarCoordinates() ///< Helper function used by PolarCoordinates().
static bool polarCoordFunc( const SELECTION& aSelection, EDA_DRAW_FRAME* aFrame ); static bool polarCoordFunc( const SELECTION& aSelection, EDA_DRAW_FRAME* aFrame );
///> Helper function used by FullscreenCursor() ///< Helper function used by FullscreenCursor().
static bool cursorFunc( const SELECTION& aSelection, EDA_DRAW_FRAME* aFrame ); static bool cursorFunc( const SELECTION& aSelection, EDA_DRAW_FRAME* aFrame );
///> Helper function used by CanvasType() ///< Helper function used by CanvasType().
static bool canvasTypeFunc( const SELECTION& aSelection, EDA_DRAW_FRAME* aFrame, static bool canvasTypeFunc( const SELECTION& aSelection, EDA_DRAW_FRAME* aFrame,
EDA_DRAW_PANEL_GAL::GAL_TYPE aType ); EDA_DRAW_PANEL_GAL::GAL_TYPE aType );
///> The frame to apply the conditions to ///< The frame to apply the conditions to.
EDA_BASE_FRAME* m_frame; EDA_BASE_FRAME* m_frame;
}; };

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2019 CERN * Copyright (C) 2019 CERN
* Copyright (C) 2019 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 2019-2020 KiCad Developers, see AUTHORS.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -45,7 +45,7 @@ public:
/// @copydoc TOOL_INTERACTIVE::Reset() /// @copydoc TOOL_INTERACTIVE::Reset()
void Reset( RESET_REASON aReason ) override { } void Reset( RESET_REASON aReason ) override { }
///> Event handler types. ///< Event handler types.
typedef std::function<bool(const VECTOR2D&)> CLICK_HANDLER; typedef std::function<bool(const VECTOR2D&)> CLICK_HANDLER;
typedef std::function<void(const VECTOR2D&)> MOTION_HANDLER; typedef std::function<void(const VECTOR2D&)> MOTION_HANDLER;
typedef std::function<void(void)> CANCEL_HANDLER; typedef std::function<void(void)> CANCEL_HANDLER;
@ -60,15 +60,15 @@ public:
EXCEPTION_CANCEL EXCEPTION_CANCEL
}; };
///> Main event loop. ///< Main event loop.
int Main( const TOOL_EVENT& aEvent ); int Main( const TOOL_EVENT& aEvent );
inline void SetCursor( KICURSOR aCursor ) { m_cursor = aCursor; } inline void SetCursor( KICURSOR aCursor ) { m_cursor = aCursor; }
/** /**
* Function SetClickHandler() * Set a handler for mouse click event.
* Sets a handler for mouse click event. Handler may decide to receive further click by *
* returning true. * The handler may decide to receive further click by returning true.
*/ */
inline void SetClickHandler( CLICK_HANDLER aHandler ) inline void SetClickHandler( CLICK_HANDLER aHandler )
{ {
@ -77,8 +77,9 @@ public:
} }
/** /**
* Function SetMotionHandler() * Set a handler for mouse motion.
* Sets a handler for mouse motion. Used for roll-over highlighting. *
* This is used for roll-over highlighting.
*/ */
inline void SetMotionHandler( MOTION_HANDLER aHandler ) inline void SetMotionHandler( MOTION_HANDLER aHandler )
{ {
@ -87,8 +88,7 @@ public:
} }
/** /**
* Function SetCancelHandler() * Set a handler for cancel events (ESC or context-menu Cancel).
* Sets a handler for cancel events (ESC or context-menu Cancel).
*/ */
inline void SetCancelHandler( CANCEL_HANDLER aHandler ) inline void SetCancelHandler( CANCEL_HANDLER aHandler )
{ {
@ -97,8 +97,9 @@ public:
} }
/** /**
* Function SetFinalizeHandler() * Set a handler for the finalize event.
* Sets a handler for the finalize event. Takes the state of the exit from the Main loop *
* Takes the state of the exit from the main loop.
*/ */
inline void SetFinalizeHandler( FINALIZE_HANDLER aHandler ) inline void SetFinalizeHandler( FINALIZE_HANDLER aHandler )
{ {
@ -107,13 +108,13 @@ public:
} }
private: private:
///> Reinitializes tool to its initial state. ///< Reinitializes tool to its initial state.
void resetPicker(); void resetPicker();
///> Applies the requested VIEW_CONTROLS settings. ///< Applies the requested VIEW_CONTROLS settings.
void setControls(); void setControls();
///> @copydoc TOOL_INTERACTIVE::setTransitions(); ///< @copydoc TOOL_INTERACTIVE::setTransitions();
void setTransitions() override; void setTransitions() override;
private: private:

View File

@ -2,6 +2,8 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2014 CERN * Copyright (C) 2014 CERN
* Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors.
*
* @author Maciej Suminski <maciej.suminski@cern.ch> * @author Maciej Suminski <maciej.suminski@cern.ch>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
@ -30,7 +32,7 @@
#include <vector> #include <vector>
#include <tool/selection.h> #include <tool/selection.h>
///> Functor type that checks a specific condition for selected items. ///< Functor type that checks a specific condition for selected items.
typedef std::function<bool (const SELECTION&)> SELECTION_CONDITION; typedef std::function<bool (const SELECTION&)> SELECTION_CONDITION;
SELECTION_CONDITION operator||( const SELECTION_CONDITION& aConditionA, SELECTION_CONDITION operator||( const SELECTION_CONDITION& aConditionA,
@ -89,7 +91,7 @@ public:
} }
/** /**
* Tests if there are any items selected. * Test if there are any items selected.
* *
* @param aSelection is the selection to be tested. * @param aSelection is the selection to be tested.
* @return True if there is at least one item selected. * @return True if there is at least one item selected.
@ -97,7 +99,7 @@ public:
static bool NotEmpty( const SELECTION& aSelection ); static bool NotEmpty( const SELECTION& aSelection );
/** /**
* Tests if there are no items selected. * Test if there are no items selected.
* *
* @param aSelection is the selection to be tested. * @param aSelection is the selection to be tested.
* @return True if there are no items selected. * @return True if there are no items selected.
@ -105,7 +107,7 @@ public:
static bool Empty( const SELECTION& aSelection ); static bool Empty( const SELECTION& aSelection );
/** /**
* Tests if there no items selected or being edited. * Test if there no items selected or being edited.
* *
* @param aSelection is the selection to be tested. * @param aSelection is the selection to be tested.
* @return True if there are no items being edited or no items selected. * @return True if there are no items being edited or no items selected.
@ -113,7 +115,7 @@ public:
static bool Idle( const SELECTION& aSelection ); static bool Idle( const SELECTION& aSelection );
/** /**
* Tests if all selected items are not being edited. * Test if all selected items are not being edited.
* *
* @param aSelection is the selection to be tested. * @param aSelection is the selection to be tested.
* @return True if no selected items are being edited. * @return True if no selected items are being edited.
@ -121,7 +123,8 @@ public:
static bool IdleSelection( const SELECTION& aSelection ); static bool IdleSelection( const SELECTION& aSelection );
/** /**
* Creates a functor that tests if among the selected items there is at least one of a given type. * Create a functor that tests if among the selected items there is at least one of a
* given type.
* *
* @param aType is the type that is searched. * @param aType is the type that is searched.
* @return Functor testing for presence of items of a given type. * @return Functor testing for presence of items of a given type.
@ -129,7 +132,7 @@ public:
static SELECTION_CONDITION HasType( KICAD_T aType ); static SELECTION_CONDITION HasType( KICAD_T aType );
/** /**
* Creates a functor that tests if the selected items are *only* of given type. * Create a functor that tests if the selected items are *only* of given type.
* *
* @param aType is the type that is searched. * @param aType is the type that is searched.
* @return Functor testing if selected items are exclusively of one type. * @return Functor testing if selected items are exclusively of one type.
@ -137,16 +140,16 @@ public:
static SELECTION_CONDITION OnlyType( KICAD_T aType ); static SELECTION_CONDITION OnlyType( KICAD_T aType );
/** /**
* Creates a functor that tests if the selected items are *only* of given types. * Create a functor that tests if the selected items are *only* of given types.
* *
* @param aTypes is an array containing types that are searched. It has to be ended with * @param aTypes is an array containing types that are searched. It has to be ended with
* KICAD_T::EOT as end marker. * #KICAD_T::EOT as end marker.
* @return Functor testing if selected items are exclusively of the requested types. * @return Functor testing if selected items are exclusively of the requested types.
*/ */
static SELECTION_CONDITION OnlyTypes( const KICAD_T aTypes[] ); static SELECTION_CONDITION OnlyTypes( const KICAD_T aTypes[] );
/** /**
* Creates a functor that tests if the number of selected items is equal to the value given as * Create a functor that tests if the number of selected items is equal to the value given as
* parameter. * parameter.
* *
* @param aNumber is the number of expected items. * @param aNumber is the number of expected items.
@ -155,7 +158,7 @@ public:
static SELECTION_CONDITION Count( int aNumber ); static SELECTION_CONDITION Count( int aNumber );
/** /**
* Creates a functor that tests if the number of selected items is greater than the value given * Create a functor that tests if the number of selected items is greater than the value given
* as parameter. * as parameter.
* *
* @param aNumber is the number used for comparison. * @param aNumber is the number used for comparison.
@ -164,7 +167,7 @@ public:
static SELECTION_CONDITION MoreThan( int aNumber ); static SELECTION_CONDITION MoreThan( int aNumber );
/** /**
* Creates a functor that tests if the number of selected items is smaller than the value given * Create a functor that tests if the number of selected items is smaller than the value given
* as parameter. * as parameter.
* *
* @param aNumber is the number used for comparison. * @param aNumber is the number used for comparison.
@ -173,52 +176,52 @@ public:
static SELECTION_CONDITION LessThan( int aNumber ); static SELECTION_CONDITION LessThan( int aNumber );
private: private:
///> Helper function used by HasType() ///< Helper function used by HasType()
static bool hasTypeFunc( const SELECTION& aSelection, KICAD_T aType ); static bool hasTypeFunc( const SELECTION& aSelection, KICAD_T aType );
///> Helper function used by OnlyType() ///< Helper function used by OnlyType()
static bool onlyTypeFunc( const SELECTION& aSelection, KICAD_T aType ); static bool onlyTypeFunc( const SELECTION& aSelection, KICAD_T aType );
///> Helper function used by OnlyTypes() ///< Helper function used by OnlyTypes()
static bool onlyTypesFunc( const SELECTION& aSelection, const KICAD_T aTypes[] ); static bool onlyTypesFunc( const SELECTION& aSelection, const KICAD_T aTypes[] );
///> Helper function used by Count() ///< Helper function used by Count()
static bool countFunc( const SELECTION& aSelection, int aNumber ); static bool countFunc( const SELECTION& aSelection, int aNumber );
///> Helper function used by MoreThan() ///< Helper function used by MoreThan()
static bool moreThanFunc( const SELECTION& aSelection, int aNumber ); static bool moreThanFunc( const SELECTION& aSelection, int aNumber );
///> Helper function used by LessThan() ///< Helper function used by LessThan()
static bool lessThanFunc( const SELECTION& aSelection, int aNumber ); static bool lessThanFunc( const SELECTION& aSelection, int aNumber );
///> Helper function used by operator|| ///< Helper function used by operator||
static bool orFunc( const SELECTION_CONDITION& aConditionA, static bool orFunc( const SELECTION_CONDITION& aConditionA,
const SELECTION_CONDITION& aConditionB, const SELECTION& aSelection ) const SELECTION_CONDITION& aConditionB, const SELECTION& aSelection )
{ {
return aConditionA( aSelection ) || aConditionB( aSelection ); return aConditionA( aSelection ) || aConditionB( aSelection );
} }
///> Helper function used by operator&& ///< Helper function used by operator&&
static bool andFunc( const SELECTION_CONDITION& aConditionA, static bool andFunc( const SELECTION_CONDITION& aConditionA,
const SELECTION_CONDITION& aConditionB, const SELECTION& aSelection ) const SELECTION_CONDITION& aConditionB, const SELECTION& aSelection )
{ {
return aConditionA( aSelection ) && aConditionB( aSelection ); return aConditionA( aSelection ) && aConditionB( aSelection );
} }
///> Helper function used by operator! ///< Helper function used by operator!
static bool notFunc( const SELECTION_CONDITION& aCondition, const SELECTION& aSelection ) static bool notFunc( const SELECTION_CONDITION& aCondition, const SELECTION& aSelection )
{ {
return !aCondition( aSelection ); return !aCondition( aSelection );
} }
///> Helper function used by operator|| ///< Helper function used by operator||
static bool orBoolFunc( const SELECTION_CONDITION& aConditionA, static bool orBoolFunc( const SELECTION_CONDITION& aConditionA,
SELECTION_BOOL& aConditionB, const SELECTION& aSelection ) SELECTION_BOOL& aConditionB, const SELECTION& aSelection )
{ {
return aConditionA( aSelection ) || aConditionB( aSelection ); return aConditionA( aSelection ) || aConditionB( aSelection );
} }
///> Helper function used by operator&& ///< Helper function used by operator&&
static bool andBoolFunc( const SELECTION_CONDITION& aConditionA, static bool andBoolFunc( const SELECTION_CONDITION& aConditionA,
SELECTION_BOOL& aConditionB, const SELECTION& aSelection ) SELECTION_BOOL& aConditionB, const SELECTION& aSelection )
{ {

View File

@ -2,6 +2,8 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2013-2015 CERN * Copyright (C) 2013-2015 CERN
* Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors.
*
* @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch> * @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
* @author Maciej Suminski <maciej.suminski@cern.ch> * @author Maciej Suminski <maciej.suminski@cern.ch>
* *
@ -34,10 +36,13 @@
struct BITMAP_OPAQUE; struct BITMAP_OPAQUE;
/** /**
* Represents a single user action. For instance: * Represent a single user action.
*
* For instance:
* - changing layer to top by pressing PgUp * - changing layer to top by pressing PgUp
* - running the DRC from the menu * - running the DRC from the menu
* and so on, and so forth.... * and so on, and so forth....
*
* Action class groups all necessary properties of an action, including explanation, * Action class groups all necessary properties of an action, including explanation,
* icons, hotkeys, menu items, etc. * icons, hotkeys, menu items, etc.
*/ */
@ -46,7 +51,8 @@ class TOOL_ACTION
public: public:
TOOL_ACTION( const std::string& aName, TOOL_ACTION_SCOPE aScope = AS_CONTEXT, TOOL_ACTION( const std::string& aName, TOOL_ACTION_SCOPE aScope = AS_CONTEXT,
int aDefaultHotKey = 0, const std::string& aLegacyHotKeyName = "", int aDefaultHotKey = 0, const std::string& aLegacyHotKeyName = "",
const wxString& aMenuText = wxEmptyString, const wxString& aTooltip = wxEmptyString, const wxString& aMenuText = wxEmptyString,
const wxString& aTooltip = wxEmptyString,
const BITMAP_OPAQUE* aIcon = nullptr, TOOL_ACTION_FLAGS aFlags = AF_NONE, const BITMAP_OPAQUE* aIcon = nullptr, TOOL_ACTION_FLAGS aFlags = AF_NONE,
void* aParam = nullptr ); void* aParam = nullptr );
@ -67,35 +73,39 @@ public:
} }
/** /**
* Returns name of the action. It is the same one that is contained in TOOL_EVENT that is * Return name of the action.
* sent by activating the TOOL_ACTION. Convention is "app.tool.actionName". *
* It is the same one that is contained in #TOOL_EVENT that is sent by activating the
* TOOL_ACTION. Convention is "app.tool.actionName".
* *
* @return Name of the action. * @return Name of the action.
*/ */
const std::string& GetName() const { return m_name; } const std::string& GetName() const { return m_name; }
/** /**
* Returns the default hotkey (if any) for the action. * Return the default hotkey (if any) for the action.
*/ */
int GetDefaultHotKey() const { return m_defaultHotKey; } int GetDefaultHotKey() const { return m_defaultHotKey; }
/** /**
* Returns the hotkey keycode which initiates the action. * Return the hotkey keycode which initiates the action.
*/ */
int GetHotKey() const { return m_hotKey; } int GetHotKey() const { return m_hotKey; }
void SetHotKey( int aKeycode ); void SetHotKey( int aKeycode );
/** /**
* Returns the unique id of the TOOL_ACTION object. It is valid only after registering the * Return the unique id of the TOOL_ACTION object.
* TOOL_ACTION by ACTION_MANAGER. *
* It is valid only after registering the TOOL_ACTION by #ACTION_MANAGER.
* *
* @return The unique identification number. If the number is negative, then it is not valid. * @return The unique identification number. If the number is negative, then it is not valid.
*/ */
int GetId() const { return m_id; } int GetId() const { return m_id; }
/* /*
* Get the unique ID for this action in the user interface system. This is simply * Get the unique ID for this action in the user interface system.
* the action ID offset by @c ACTION_BASE_UI_ID. *
* This is simply the action ID offset by @c ACTION_BASE_UI_ID.
* *
* @return The unique ID number for use in the user interface system. * @return The unique ID number for use in the user interface system.
*/ */
@ -107,7 +117,7 @@ public:
static int GetBaseUIId() { return ACTION_BASE_UI_ID; } static int GetBaseUIId() { return ACTION_BASE_UI_ID; }
/** /**
* Returns the event associated with the action (i.e. the event that will be sent after * Return the event associated with the action (i.e. the event that will be sent after
* activating the action). * activating the action).
*/ */
TOOL_EVENT MakeEvent() const TOOL_EVENT MakeEvent() const
@ -127,14 +137,14 @@ public:
TOOL_ACTION_SCOPE GetScope() const { return m_scope; } TOOL_ACTION_SCOPE GetScope() const { return m_scope; }
/** /**
* Returns name of the tool associated with the action. It is basically the action name * Return name of the tool associated with the action. It is basically the action name
* stripped of the last part (e.g. for "pcbnew.InteractiveDrawing.drawCircle" it is * stripped of the last part (e.g. for "pcbnew.InteractiveDrawing.drawCircle" it is
* "pcbnew.InteractiveDrawing"). * "pcbnew.InteractiveDrawing").
*/ */
std::string GetToolName() const; std::string GetToolName() const;
/** /**
* Returns true if the action is intended to activate a tool. * Return true if the action is intended to activate a tool.
*/ */
bool IsActivation() const bool IsActivation() const
{ {
@ -142,7 +152,7 @@ public:
} }
/** /**
* Returns true if the action is a notification. * Return true if the action is a notification.
*/ */
bool IsNotification() const bool IsNotification() const
{ {
@ -150,7 +160,9 @@ public:
} }
/** /**
* Returns an icon associated with the action. It is used in context menu. * Return an icon associated with the action.
*
* It is used in context menu.
*/ */
const BITMAP_OPAQUE* GetIcon() const const BITMAP_OPAQUE* GetIcon() const
{ {
@ -162,15 +174,15 @@ protected:
friend class ACTION_MANAGER; friend class ACTION_MANAGER;
///> Base ID to use inside the user interface system to offset the action IDs. ///< Base ID to use inside the user interface system to offset the action IDs.
static constexpr int ACTION_BASE_UI_ID = 20000; static constexpr int ACTION_BASE_UI_ID = 20000;
/// Name of the action (convention is "app.tool.actionName") ///< Name of the action (convention is "app.tool.actionName")
std::string m_name; std::string m_name;
TOOL_ACTION_SCOPE m_scope; TOOL_ACTION_SCOPE m_scope;
const int m_defaultHotKey; // Default hot key const int m_defaultHotKey; // Default hot key
int m_hotKey; // The curret hotkey (post-user-settings-application) int m_hotKey; // The current hotkey (post-user-settings-application)
const std::string m_legacyName; // Name for reading legacy hotkey settings const std::string m_legacyName; // Name for reading legacy hotkey settings
wxString m_label; wxString m_label;

View File

@ -2,8 +2,9 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2013 CERN * Copyright (C) 2013 CERN
* Copyright (C) 2016-2020 KiCad Developers, see AUTHORS.txt for contributors.
*
* @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch> * @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
* Copyright (C) 2016 KiCad Developers, see AUTHORS.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -45,10 +46,10 @@ class VIEW_CONTROLS;
enum TOOL_TYPE enum TOOL_TYPE
{ {
///> Tool that interacts with the user ///< Tool that interacts with the user
INTERACTIVE = 0x01, INTERACTIVE = 0x01,
///> Tool that runs in the background without any user intervention ///< Tool that runs in the background without any user intervention
BATCH = 0x02 BATCH = 0x02
}; };
@ -59,8 +60,6 @@ using TOOL_STATE_FUNC = std::function<int(const TOOL_EVENT&)>;
/** /**
* TOOL_BASE
*
* Base abstract interface for all kinds of tools. * Base abstract interface for all kinds of tools.
*/ */
@ -75,7 +74,7 @@ public:
virtual ~TOOL_BASE() {}; virtual ~TOOL_BASE() {};
///> Determines the reason of reset for a tool ///< Determine the reason of reset for a tool.
enum RESET_REASON enum RESET_REASON
{ {
RUN, ///< Tool is invoked after being inactive RUN, ///< Tool is invoked after being inactive
@ -84,7 +83,6 @@ public:
}; };
/** /**
* Function Init()
* Init() is called once upon a registration of the tool. * Init() is called once upon a registration of the tool.
* *
* @return True if the initialization went fine, false - otherwise. * @return True if the initialization went fine, false - otherwise.
@ -95,16 +93,17 @@ public:
} }
/** /**
* Function Reset() * Bring the tool to a known, initial state.
* Brings the tool to a known, initial state. If the tool claimed anything from *
* the model or the view, it must release it when its reset. * If the tool claimed anything from the model or the view, it must release it when its
* reset.
* @param aReason contains information about the reason of tool reset. * @param aReason contains information about the reason of tool reset.
*/ */
virtual void Reset( RESET_REASON aReason ) = 0; virtual void Reset( RESET_REASON aReason ) = 0;
/** /**
* Function GetType() * Return the type of the tool.
* Returns the type of the tool. *
* @return The type of the tool. * @return The type of the tool.
*/ */
TOOL_TYPE GetType() const TOOL_TYPE GetType() const
@ -113,9 +112,10 @@ public:
} }
/** /**
* Function GetId() * Return the unique identifier of the tool.
* Returns the unique identifier of the tool. The identifier is set by an instance of *
* TOOL_MANAGER. * The identifier is set by an instance of #TOOL_MANAGER.
*
* @return Identifier of the tool. * @return Identifier of the tool.
*/ */
TOOL_ID GetId() const TOOL_ID GetId() const
@ -124,9 +124,11 @@ public:
} }
/** /**
* Function GetName() * Return the name of the tool.
* Returns the name of the tool. Tool names are expected to obey the format: *
* application.ToolName (eg. pcbnew.InteractiveSelection). * Tool names are expected to obey the format: application.ToolName (eg.
* pcbnew.InteractiveSelection).
*
* @return The name of the tool. * @return The name of the tool.
*/ */
const std::string& GetName() const const std::string& GetName() const
@ -135,10 +137,9 @@ public:
} }
/** /**
* Function GetManager() * Return the instance of #TOOL_MANAGER that takes care of the tool.
* Returns the instance of TOOL_MANAGER that takes care of the tool. *
* @return Instance of the TOOL_MANAGER. If there is no TOOL_MANAGER associated, it returns * @return Instance of the #TOOL_MANAGER or NULL if there is no associated tool manager.
* NULL.
*/ */
TOOL_MANAGER* GetManager() const TOOL_MANAGER* GetManager() const
{ {
@ -154,34 +155,31 @@ protected:
friend class TOOL_SETTINGS; friend class TOOL_SETTINGS;
/** /**
* Function attachManager() * Set the #TOOL_MANAGER the tool will belong to.
* *
* Sets the TOOL_MANAGER the tool will belong to. * Called by #TOOL_MANAGER::RegisterTool()
* Called by TOOL_MANAGER::RegisterTool()
*/ */
void attachManager( TOOL_MANAGER* aManager ); void attachManager( TOOL_MANAGER* aManager );
/** /**
* Function getView() * Returns the instance of #VIEW object used in the application. It allows tools to draw.
* *
* Returns the instance of VIEW object used in the application. It allows tools to draw.
* @return The instance of VIEW. * @return The instance of VIEW.
*/ */
KIGFX::VIEW* getView() const; KIGFX::VIEW* getView() const;
/** /**
* Function getViewControls() * Return the instance of VIEW_CONTROLS object used in the application.
*
* It allows tools to read & modify user input and its settings (eg. show cursor, enable
* snapping to grid, etc.).
* *
* Returns the instance of VIEW_CONTROLS object used in the application. It allows tools to
* read & modify user input and its settings (eg. show cursor, enable snapping to grid, etc.)
* @return The instance of VIEW_CONTROLS. * @return The instance of VIEW_CONTROLS.
*/ */
KIGFX::VIEW_CONTROLS* getViewControls() const; KIGFX::VIEW_CONTROLS* getViewControls() const;
/** /**
* Function getEditFrame() * Return the application window object, casted to requested user type.
*
* Returns the application window object, casted to requested user type.
*/ */
template <typename T> template <typename T>
T* getEditFrame() const T* getEditFrame() const
@ -193,9 +191,7 @@ protected:
} }
/** /**
* Function getModel() * Return the model object if it matches the requested type.
*
* Returns the model object if it matches the requested type.
*/ */
template <typename T> template <typename T>
T* getModel() const T* getModel() const
@ -207,14 +203,14 @@ protected:
return static_cast<T*>( m ); return static_cast<T*>( m );
} }
///> Stores the type of the tool. ///< Store the type of the tool.
TOOL_TYPE m_type; TOOL_TYPE m_type;
///> Unique identifier for the tool, assigned by a TOOL_MANAGER instance. ///< Unique identifier for the tool, assigned by a TOOL_MANAGER instance.
TOOL_ID m_toolId; TOOL_ID m_toolId;
///> Name of the tool. Names are expected to obey the format application.ToolName ///< Name of the tool. Names are expected to obey the format application.ToolName
///> (eg. pcbnew.InteractiveSelection). ///< (eg. pcbnew.InteractiveSelection).
std::string m_toolName; std::string m_toolName;
TOOL_MANAGER* m_toolMgr; TOOL_MANAGER* m_toolMgr;
//TOOL_SETTINGS m_toolSettings; //TOOL_SETTINGS m_toolSettings;

View File

@ -2,6 +2,8 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2013 CERN * Copyright (C) 2013 CERN
* Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors.
*
* @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch> * @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
@ -42,28 +44,28 @@ class VIEW;
* - takes wx events, * - takes wx events,
* - fixes all wx quirks (mouse warping, panning, ordering problems, etc) * - fixes all wx quirks (mouse warping, panning, ordering problems, etc)
* - translates coordinates to world space * - translates coordinates to world space
* - low-level input conditioning (drag/click threshold), updating mouse position during view auto-scroll/pan. * - low-level input conditioning (drag/click threshold), updating mouse position during
* view auto-scroll/pan.
* - issues TOOL_EVENTS to the tool manager * - issues TOOL_EVENTS to the tool manager
*/ */
class TOOL_DISPATCHER : public wxEvtHandler class TOOL_DISPATCHER : public wxEvtHandler
{ {
public: public:
/** /**
* @param aToolMgr: tool manager instance the events will be sent to * @param aToolMgr: tool manager instance the events will be sent to.
* @param aActions: ACTIONS subclass instance for ACTIONS::TranslateLegacyId() * @param aActions: ACTIONS subclass instance for ACTIONS::TranslateLegacyId().
*/ */
TOOL_DISPATCHER( TOOL_MANAGER* aToolMgr, ACTIONS *aActions ); TOOL_DISPATCHER( TOOL_MANAGER* aToolMgr, ACTIONS *aActions );
virtual ~TOOL_DISPATCHER(); virtual ~TOOL_DISPATCHER();
/** /**
* Brings the dispatcher to its initial state. * Bring the dispatcher to its initial state.
*/ */
virtual void ResetState(); virtual void ResetState();
/** /**
* Processes wxEvents (mostly UI events), translates them to TOOL_EVENTs, and makes tools * Process wxEvents (mostly UI events), translate them to TOOL_EVENTs, and make tools
* handle those. * handle those.
* *
* @param aEvent is the wxWidgets event to be processed. * @param aEvent is the wxWidgets event to be processed.
@ -71,12 +73,12 @@ public:
virtual void DispatchWxEvent( wxEvent& aEvent ); virtual void DispatchWxEvent( wxEvent& aEvent );
/** /**
* Maps a wxWidgets key event to a TOOL_EVENT. * Map a wxWidgets key event to a TOOL_EVENT.
*/ */
OPT<TOOL_EVENT> GetToolEvent( wxKeyEvent* aKeyEvent, bool* aSpecialKeyFlag ); OPT<TOOL_EVENT> GetToolEvent( wxKeyEvent* aKeyEvent, bool* aSpecialKeyFlag );
/** /**
* Processes wxCommands (mostly menu related events) and runs appropriate actions (eg. run the * Process wxCommands (mostly menu related events) and runs appropriate actions (eg. run the
* specified tool). * specified tool).
* *
* @param aEvent is the wxCommandEvent to be processed. * @param aEvent is the wxCommandEvent to be processed.
@ -84,21 +86,21 @@ public:
virtual void DispatchWxCommand( wxCommandEvent& aEvent ); virtual void DispatchWxCommand( wxCommandEvent& aEvent );
private: private:
///> Number of mouse buttons that is handled in events. ///< Number of mouse buttons that is handled in events.
static const int MouseButtonCount = 3; static const int MouseButtonCount = 3;
///> The time threshold for a mouse button press that distinguishes between a single mouse ///< The time threshold for a mouse button press that distinguishes between a single mouse
///> click and a beginning of drag event (expressed in milliseconds). ///< click and a beginning of drag event (expressed in milliseconds).
static const int DragTimeThreshold = 300; static const int DragTimeThreshold = 300;
///> The distance threshold for mouse cursor that disinguishes between a single mouse click ///< The distance threshold for mouse cursor that distinguishes between a single mouse click
///> and a beginning of drag event (expressed in screen pixels). ///< and a beginning of drag event (expressed in screen pixels).
static const int DragDistanceThreshold = 8; static const int DragDistanceThreshold = 8;
///> Handles mouse related events (click, motion, dragging). ///< Handles mouse related events (click, motion, dragging).
bool handleMouseButton( wxEvent& aEvent, int aIndex, bool aMotion ); bool handleMouseButton( wxEvent& aEvent, int aIndex, bool aMotion );
///> Saves the state of key modifiers (Alt, Ctrl and so on). ///< Saves the state of key modifiers (Alt, Ctrl and so on).
static int decodeModifiers( const wxKeyboardState* aState ) static int decodeModifiers( const wxKeyboardState* aState )
{ {
int mods = 0; int mods = 0;
@ -115,22 +117,22 @@ private:
return mods; return mods;
} }
///> Stores all the informations regarding a mouse button state. ///< Stores all the information regarding a mouse button state.
struct BUTTON_STATE; struct BUTTON_STATE;
///> The last mouse cursor position (in world coordinates). ///< The last mouse cursor position (in world coordinates).
VECTOR2D m_lastMousePos; VECTOR2D m_lastMousePos;
///> State of mouse buttons. ///< State of mouse buttons.
std::vector<BUTTON_STATE*> m_buttons; std::vector<BUTTON_STATE*> m_buttons;
///> Returns the instance of VIEW, used by the application. ///< Returns the instance of VIEW, used by the application.
KIGFX::VIEW* getView(); KIGFX::VIEW* getView();
///> Instance of tool manager that cooperates with the dispatcher. ///< Instance of tool manager that cooperates with the dispatcher.
TOOL_MANAGER* m_toolMgr; TOOL_MANAGER* m_toolMgr;
///> Instance of an actions list that handles legacy action translation ///< Instance of an actions list that handles legacy action translation
ACTIONS* m_actions; ACTIONS* m_actions;
}; };

View File

@ -2,6 +2,8 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2013 CERN * Copyright (C) 2013 CERN
* Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors.
*
* @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch> * @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
@ -45,7 +47,6 @@ class TOOL_BASE;
/** /**
* Internal (GUI-independent) event definitions. * Internal (GUI-independent) event definitions.
* Enums are mostly self-explanatory.
*/ */
enum TOOL_EVENT_CATEGORY enum TOOL_EVENT_CATEGORY
{ {
@ -88,7 +89,7 @@ enum TOOL_ACTIONS
TA_CANCEL_TOOL = 0x2000, TA_CANCEL_TOOL = 0x2000,
// Context menu update. Issued whenever context menu is open and the user hovers the mouse // Context menu update. Issued whenever context menu is open and the user hovers the mouse
// over one of choices. Used in dynamic highligting in disambiguation menu // over one of choices. Used in dynamic highlighting in disambiguation menu
TA_CHOICE_MENU_UPDATE = 0x4000, TA_CHOICE_MENU_UPDATE = 0x4000,
// Context menu choice. Sent if the user picked something from the context menu or // Context menu choice. Sent if the user picked something from the context menu or
@ -142,17 +143,17 @@ enum TOOL_MODIFIERS
/// Scope of tool actions /// Scope of tool actions
enum TOOL_ACTION_SCOPE enum TOOL_ACTION_SCOPE
{ {
AS_CONTEXT = 1, ///> Action belongs to a particular tool (i.e. a part of a pop-up menu) AS_CONTEXT = 1, ///< Action belongs to a particular tool (i.e. a part of a pop-up menu)
AS_ACTIVE, ///> All active tools AS_ACTIVE, ///< All active tools
AS_GLOBAL ///> Global action (toolbar/main menu event, global shortcut) AS_GLOBAL ///< Global action (toolbar/main menu event, global shortcut)
}; };
/// Flags for tool actions /// Flags for tool actions
enum TOOL_ACTION_FLAGS enum TOOL_ACTION_FLAGS
{ {
AF_NONE = 0, AF_NONE = 0,
AF_ACTIVATE = 1, ///> Action activates a tool AF_ACTIVATE = 1, ///< Action activates a tool
AF_NOTIFY = 2 ///> Action is a notification (it is by default passed to all tools) AF_NOTIFY = 2 ///< Action is a notification (it is by default passed to all tools)
}; };
/// Defines when a context menu is opened. /// Defines when a context menu is opened.
@ -164,16 +165,13 @@ enum CONTEXT_MENU_TRIGGER
}; };
/** /**
* TOOL_EVENT
*
* Generic, UI-independent tool event. * Generic, UI-independent tool event.
*/ */
class TOOL_EVENT class TOOL_EVENT
{ {
public: public:
/** /**
* Function Format() * Return information about event in form of a human-readable string.
* Returns information about event in form of a human-readable string.
* *
* @return Event information. * @return Event information.
*/ */
@ -243,46 +241,46 @@ public:
init(); init();
} }
///> Returns the category (eg. mouse/keyboard/action) of an event.. ///< Returns the category (eg. mouse/keyboard/action) of an event..
TOOL_EVENT_CATEGORY Category() const { return m_category; } TOOL_EVENT_CATEGORY Category() const { return m_category; }
///> Returns more specific information about the type of an event. ///< Returns more specific information about the type of an event.
TOOL_ACTIONS Action() const { return m_actions; } TOOL_ACTIONS Action() const { return m_actions; }
///> These give a tool a method of informing the TOOL_MANAGER that a particular event should ///< These give a tool a method of informing the TOOL_MANAGER that a particular event should
///> be passed on to subsequent tools on the stack. Defaults to true for TC_MESSAGES; false ///< be passed on to subsequent tools on the stack. Defaults to true for TC_MESSAGES; false
///> for everything else. ///< for everything else.
bool PassEvent() const { return m_passEvent; } bool PassEvent() const { return m_passEvent; }
void SetPassEvent( bool aPass = true ) { m_passEvent = aPass; } void SetPassEvent( bool aPass = true ) { m_passEvent = aPass; }
///> Returns if it this event has a valid position (true for mouse events and context-menu ///< Returns if it this event has a valid position (true for mouse events and context-menu
///> or hotkey-based command events) ///< or hotkey-based command events)
bool HasPosition() const { return m_hasPosition; } bool HasPosition() const { return m_hasPosition; }
void SetHasPosition( bool aHasPosition ) { m_hasPosition = aHasPosition; } void SetHasPosition( bool aHasPosition ) { m_hasPosition = aHasPosition; }
TOOL_BASE* FirstResponder() const { return m_firstResponder; } TOOL_BASE* FirstResponder() const { return m_firstResponder; }
void SetFirstResponder( TOOL_BASE* aTool ) { m_firstResponder = aTool; } void SetFirstResponder( TOOL_BASE* aTool ) { m_firstResponder = aTool; }
///> Returns information about difference between current mouse cursor position and the place ///< Returns information about difference between current mouse cursor position and the place
///> where dragging has started. ///< where dragging has started.
const VECTOR2D Delta() const const VECTOR2D Delta() const
{ {
return returnCheckedPosition( m_mouseDelta ); return returnCheckedPosition( m_mouseDelta );
} }
///> Returns mouse cursor position in world coordinates. ///< Returns mouse cursor position in world coordinates.
const VECTOR2D Position() const const VECTOR2D Position() const
{ {
return returnCheckedPosition( m_mousePos ); return returnCheckedPosition( m_mousePos );
} }
///> Returns the point where dragging has started. ///< Returns the point where dragging has started.
const VECTOR2D DragOrigin() const const VECTOR2D DragOrigin() const
{ {
return returnCheckedPosition( m_mouseDragOrigin ); return returnCheckedPosition( m_mouseDragOrigin );
} }
///> Returns information about mouse buttons state. ///< Returns information about mouse buttons state.
int Buttons() const int Buttons() const
{ {
assert( m_category == TC_MOUSE ); // this should be used only with mouse events assert( m_category == TC_MOUSE ); // this should be used only with mouse events
@ -338,7 +336,7 @@ public:
return m_actions == TA_PRIME; return m_actions == TA_PRIME;
} }
///> Returns information about key modifiers state (Ctrl, Alt, etc.) ///< Returns information about key modifiers state (Ctrl, Alt, etc.)
int Modifier( int aMask = MD_MODIFIER_MASK ) const int Modifier( int aMask = MD_MODIFIER_MASK ) const
{ {
return m_modifiers & aMask; return m_modifiers & aMask;
@ -355,8 +353,7 @@ public:
} }
/** /**
* Function Matches() * Test whether two events match in terms of category & action or command.
* Tests whether two events match in terms of category & action or command.
* *
* @param aEvent is the event to test against. * @param aEvent is the event to test against.
* @return True if two events match, false otherwise. * @return True if two events match, false otherwise.
@ -388,47 +385,41 @@ public:
} }
/** /**
* Function IsAction() * Test if the event contains an action issued upon activation of the given #TOOL_ACTION.
* Tests if the event contains an action issued upon activation of the given TOOL_ACTION. *
* @param aAction is the TOOL_ACTION to be checked against. * @param aAction is the TOOL_ACTION to be checked against.
* @return True if it matches the given TOOL_ACTION. * @return True if it matches the given TOOL_ACTION.
*/ */
bool IsAction( const TOOL_ACTION* aAction ) const; bool IsAction( const TOOL_ACTION* aAction ) const;
/** /**
* Function IsCancelInteractive() * Indicate the event should restart/end an ongoing interactive tool's event loop (eg esc
*
* Indicates the event should restart/end an ongoing interactive tool's event loop (eg esc
* key, click cancel, start different tool). * key, click cancel, start different tool).
*/ */
bool IsCancelInteractive(); bool IsCancelInteractive();
/** /**
* Function IsSelectionEvent() * Indicate an selection-changed notification event.
*
* Indicates an selection-changed notification event.
*/ */
bool IsSelectionEvent(); bool IsSelectionEvent();
/** /**
* Function IsPointEditor * Indicate if the event is from one of the point editors.
* *
* Indicates if the event is from one of the point editors. Usually used to allow the * Usually used to allow the point editor to activate itself without de-activating the
* point editor to activate itself without de-activating the current drawing tool. * current drawing tool.
*/ */
bool IsPointEditor(); bool IsPointEditor();
/** /**
* Function IsMoveTool * Indicate if the event is from one of the move tools.
* *
* Indicates if the event is from one of the move tools. Usually used to allow move to * Usually used to allow move to be done without de-activating the current drawing tool.
* be done without de-activating the current drawing tool.
*/ */
bool IsMoveTool(); bool IsMoveTool();
/** /**
* Function Parameter() * Return a non-standard parameter assigned to the event. Its meaning depends on the
* Returns a non-standard parameter assigned to the event. Its meaning depends on the
* target tool. * target tool.
*/ */
template<typename T> template<typename T>
@ -444,9 +435,9 @@ public:
} }
/** /**
* Function SetParameter() * Set a non-standard parameter assigned to the event. Its meaning depends on the
* Sets a non-standard parameter assigned to the event. Its meaning depends on the
* target tool. * target tool.
*
* @param aParam is the new parameter. * @param aParam is the new parameter.
*/ */
template<typename T> template<typename T>
@ -500,6 +491,7 @@ private:
/** /**
* Ensure that the event is a type that has a position before returning a * Ensure that the event is a type that has a position before returning a
* position, otherwise return a null-constructed position. * position, otherwise return a null-constructed position.
*
* Used to defend the position accessors from runtime access when the event * Used to defend the position accessors from runtime access when the event
* does not have a valid position. * does not have a valid position.
* *
@ -524,29 +516,29 @@ private:
bool m_passEvent; bool m_passEvent;
bool m_hasPosition; bool m_hasPosition;
///> Difference between mouse cursor position and ///< Difference between mouse cursor position and
///> the point where dragging event has started ///< the point where dragging event has started
VECTOR2D m_mouseDelta; VECTOR2D m_mouseDelta;
///> Current mouse cursor position ///< Current mouse cursor position
VECTOR2D m_mousePos; VECTOR2D m_mousePos;
///> Point where dragging has started ///< Point where dragging has started
VECTOR2D m_mouseDragOrigin; VECTOR2D m_mouseDragOrigin;
///> State of mouse buttons ///< State of mouse buttons
int m_mouseButtons; int m_mouseButtons;
///> Stores code of pressed/released key ///< Stores code of pressed/released key
int m_keyCode; int m_keyCode;
///> State of key modifierts (Ctrl/Alt/etc.) ///< State of key modifiers (Ctrl/Alt/etc.)
int m_modifiers; int m_modifiers;
///> Generic parameter used for passing non-standard data. ///< Generic parameter used for passing non-standard data.
void* m_param; void* m_param;
///> The first tool to receive the event ///< The first tool to receive the event
TOOL_BASE* m_firstResponder; TOOL_BASE* m_firstResponder;
OPT<int> m_commandId; OPT<int> m_commandId;
@ -556,10 +548,8 @@ private:
typedef OPT<TOOL_EVENT> OPT_TOOL_EVENT; typedef OPT<TOOL_EVENT> OPT_TOOL_EVENT;
/** /**
* TOOL_EVENT_LIST * A list of TOOL_EVENTs, with overloaded || operators allowing for concatenating TOOL_EVENTs
* * with little code.
* A list of TOOL_EVENTs, with overloaded || operators allowing for
* concatenating TOOL_EVENTs with little code.
*/ */
class TOOL_EVENT_LIST class TOOL_EVENT_LIST
{ {
@ -568,17 +558,17 @@ public:
typedef std::deque<TOOL_EVENT>::iterator iterator; typedef std::deque<TOOL_EVENT>::iterator iterator;
typedef std::deque<TOOL_EVENT>::const_iterator const_iterator; typedef std::deque<TOOL_EVENT>::const_iterator const_iterator;
///> Default constructor. Creates an empty list. ///< Default constructor. Creates an empty list.
TOOL_EVENT_LIST() TOOL_EVENT_LIST()
{} {}
///> Constructor for a list containing only one TOOL_EVENT. ///< Constructor for a list containing only one TOOL_EVENT.
TOOL_EVENT_LIST( const TOOL_EVENT& aSingleEvent ) TOOL_EVENT_LIST( const TOOL_EVENT& aSingleEvent )
{ {
m_events.push_back( aSingleEvent ); m_events.push_back( aSingleEvent );
} }
///> Copy an existing TOOL_EVENT_LIST ///<y Copy an existing TOOL_EVENT_LIST
TOOL_EVENT_LIST( const TOOL_EVENT_LIST& aEventList ) = default; TOOL_EVENT_LIST( const TOOL_EVENT_LIST& aEventList ) = default;
/** /**
@ -601,9 +591,9 @@ public:
} }
/** /**
* Function Add() * Add a tool event to the list.
* Adds a tool event to the list. *
* @param aEvent is the tool event to be addded. * @param aEvent is the tool event to be added.
*/ */
void Add( const TOOL_EVENT& aEvent ) void Add( const TOOL_EVENT& aEvent )
{ {

View File

@ -2,8 +2,9 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2013 CERN * Copyright (C) 2013 CERN
* Copyright (C) 2016-2020 KiCad Developers, see AUTHORS.txt for contributors.
*
* @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch> * @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
* Copyright (C) 2016 KiCad Developers, see AUTHORS.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -37,62 +38,59 @@ class TOOL_INTERACTIVE : public TOOL_BASE
{ {
public: public:
/** /**
* Constructor * Create a tool with given id & name. The name must be unique.
* */
* Creates a tool with given id & name. The name must be unique. */
TOOL_INTERACTIVE( TOOL_ID aId, const std::string& aName ); TOOL_INTERACTIVE( TOOL_ID aId, const std::string& aName );
/** /**
* Constructor * Creates a tool with given name. The name must be unique.
* */
* Creates a tool with given name. The name must be unique. */
TOOL_INTERACTIVE( const std::string& aName ); TOOL_INTERACTIVE( const std::string& aName );
virtual ~TOOL_INTERACTIVE(); virtual ~TOOL_INTERACTIVE();
/** /**
* Function Activate() * Run the tool.
* Runs the tool. After activation, the tool starts receiving events until it is finished. *
* After activation, the tool starts receiving events until it is finished.
*/ */
void Activate(); void Activate();
TOOL_MENU& GetToolMenu() { return m_menu; } TOOL_MENU& GetToolMenu() { return m_menu; }
/** /**
* Function SetContextMenu() * Assign a context menu and tells when it should be activated.
* *
* Assigns a context menu and tells when it should be activated.
* @param aMenu is the menu to be assigned. * @param aMenu is the menu to be assigned.
* @param aTrigger determines conditions upon which the context menu is activated. * @param aTrigger determines conditions upon which the context menu is activated.
*/ */
void SetContextMenu( ACTION_MENU* aMenu, CONTEXT_MENU_TRIGGER aTrigger = CMENU_BUTTON ); void SetContextMenu( ACTION_MENU* aMenu, CONTEXT_MENU_TRIGGER aTrigger = CMENU_BUTTON );
/** /**
* Function RunMainStack() * Call a function using the main stack.
* *
* Calls a function using the main stack.
* @param aFunc is the function to be calls. * @param aFunc is the function to be calls.
*/ */
void RunMainStack( std::function<void()> aFunc ); void RunMainStack( std::function<void()> aFunc );
/** /**
* Function Go() * Define which state (aStateFunc) to go when a certain event arrives (aConditions).
* *
* Defines which state (aStateFunc) to go when a certain event arrives (aConditions).
* No conditions means any event. * No conditions means any event.
*/ */
template <class T> template <class T>
void Go( int (T::* aStateFunc)( const TOOL_EVENT& ), void Go( int (T::* aStateFunc)( const TOOL_EVENT& ),
const TOOL_EVENT_LIST& aConditions = TOOL_EVENT( TC_ANY, TA_ANY ) ); const TOOL_EVENT_LIST& aConditions = TOOL_EVENT( TC_ANY, TA_ANY ) );
/** /**
* Function Wait() * Suspend execution of the tool until an event specified in aEventList arrives.
* *
* Suspends execution of the tool until an event specified in aEventList arrives.
* No parameters means waiting for any event. * No parameters means waiting for any event.
*/ */
TOOL_EVENT* Wait( const TOOL_EVENT_LIST& aEventList = TOOL_EVENT( TC_ANY, TA_ANY ) ); TOOL_EVENT* Wait( const TOOL_EVENT_LIST& aEventList = TOOL_EVENT( TC_ANY, TA_ANY ) );
/** functions below are not yet implemented - their interface may change */ /**
* The functions below are not yet implemented - their interface may change
*/
/*template <class Parameters, class ReturnValue> /*template <class Parameters, class ReturnValue>
bool InvokeTool( const std::string& aToolName, const Parameters& parameters, bool InvokeTool( const std::string& aToolName, const Parameters& parameters,
ReturnValue& returnValue ); ReturnValue& returnValue );
@ -109,13 +107,14 @@ protected:
private: private:
/** /**
* This method is meant to be overridden in order to specify handlers for events. It is called * This method is meant to be overridden in order to specify handlers for events.
* every time tool is reset or finished. *
* It is called every time tool is reset or finished.
*/ */
virtual void setTransitions() = 0; virtual void setTransitions() = 0;
/** /**
* Clears the current transition map and restores the default one created by setTransitions(). * Clear the current transition map and restores the default one created by setTransitions().
*/ */
void resetTransitions(); void resetTransitions();

View File

@ -2,6 +2,8 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2013 CERN * Copyright (C) 2013 CERN
* Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors.
*
* @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch> * @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
* @author Maciej Suminski <maciej.suminski@cern.ch> * @author Maciej Suminski <maciej.suminski@cern.ch>
* *
@ -42,7 +44,6 @@ class APP_SETTINGS_BASE;
/** /**
* TOOL_MANAGER.
* Master controller class: * Master controller class:
* - registers editing tools * - registers editing tools
* - pumps UI events to tools requesting them * - pumps UI events to tools requesting them
@ -71,16 +72,15 @@ public:
static TOOL_ID MakeToolId( const std::string& aToolName ); static TOOL_ID MakeToolId( const std::string& aToolName );
/** /**
* Function RegisterTool() * Add a tool to the manager set and sets it up. Called once for each tool during
* Adds a tool to the manager set and sets it up. Called once for * application initialization.
* each tool during application initialization. *
* @param aTool: tool to be added. Ownership is transferred. * @param aTool: tool to be added. Ownership is transferred.
*/ */
void RegisterTool( TOOL_BASE* aTool ); void RegisterTool( TOOL_BASE* aTool );
/** /**
* Function InvokeTool() * Call a tool by sending a tool activation event to tool of given ID.
* Calls a tool by sending a tool activation event to tool of given ID.
* *
* @param aToolId is the ID number of the requested tool. * @param aToolId is the ID number of the requested tool.
* @return True if the requested tool was invoked successfully. * @return True if the requested tool was invoked successfully.
@ -88,8 +88,7 @@ public:
bool InvokeTool( TOOL_ID aToolId ); bool InvokeTool( TOOL_ID aToolId );
/** /**
* Function InvokeTool() * Call a tool by sending a tool activation event to tool of given name.
* Calls a tool by sending a tool activation event to tool of given name.
* *
* @param aToolName is the name of the requested tool. * @param aToolName is the name of the requested tool.
* @return True if the requested tool was invoked successfully. * @return True if the requested tool was invoked successfully.
@ -127,14 +126,15 @@ public:
void ShutdownTool( const std::string& aToolName ); void ShutdownTool( const std::string& aToolName );
/** /**
* Function RunAction() * Run the specified action.
* Runs the specified action. The common format for action names is "application.ToolName.Action". *
* The common format for action names is "application.ToolName.Action".
* *
* @param aActionName is the name of action to be invoked. * @param aActionName is the name of action to be invoked.
* @param aNow decides if the action has to be run immediately or after the current coroutine * @param aNow decides if the action has to be run immediately or after the current coroutine
* is preemptied. * is preemptied.
* @param aParam is an optional parameter that might be used by the invoked action. Its meaning * @param aParam is an optional parameter that might be used by the invoked action. Its meaning
* depends on the action. * depends on the action.
* @return False if the action was not found. * @return False if the action was not found.
*/ */
template<typename T> template<typename T>
@ -151,18 +151,16 @@ public:
} }
/** /**
* Function RunAction() * Run the specified action.
* Runs the specified action.
* *
* This function will only return if the action has been handled when the action is run * This function will only return if the action has been handled when the action is run
* immediately (aNow = true), otherwise it will always return false. * immediately (aNow = true), otherwise it will always return false.
* *
* @param aAction is the action to be invoked. * @param aAction is the action to be invoked.
* @param aNow decides if the action has to be run immediately or after the current coroutine * @param aNow decides if the action has to be run immediately or after the current coroutine
* is preemptied. * is preemptied.
* @param aParam is an optional parameter that might be used by the invoked action. Its meaning * @param aParam is an optional parameter that might be used by the invoked action. Its meaning
* depends on the action. * depends on the action.
*
* @return True if the action was handled immediately * @return True if the action was handled immediately
*/ */
template <typename T> template <typename T>
@ -186,22 +184,20 @@ public:
void CancelTool(); void CancelTool();
/** /**
* Function PrimeTool() * "Prime" a tool by sending a cursor left-click event with the mouse position set
* "Primes" a tool by sending a cursor left-click event with the mouse position set
* to the passed in position. * to the passed in position.
* *
* @param aPosition is the mouse position to use in the event * @param aPosition is the mouse position to use in the event
*/ */
void PrimeTool( const VECTOR2D& aPosition ); void PrimeTool( const VECTOR2D& aPosition );
///> @copydoc ACTION_MANAGER::GetHotKey() ///< @copydoc ACTION_MANAGER::GetHotKey()
int GetHotKey( const TOOL_ACTION& aAction ); int GetHotKey( const TOOL_ACTION& aAction );
ACTION_MANAGER* GetActionManager() { return m_actionMgr; } ACTION_MANAGER* GetActionManager() { return m_actionMgr; }
/** /**
* Function FindTool() * Search for a tool with given ID.
* Searches for a tool with given ID.
* *
* @param aId is the ID number of the requested tool. * @param aId is the ID number of the requested tool.
* @return Pointer to the requested tool or NULL in case of failure. * @return Pointer to the requested tool or NULL in case of failure.
@ -209,8 +205,7 @@ public:
TOOL_BASE* FindTool( int aId ) const; TOOL_BASE* FindTool( int aId ) const;
/** /**
* Function FindTool() * Search for a tool with given name.
* Searches for a tool with given name.
* *
* @param aName is the name of the requested tool. * @param aName is the name of the requested tool.
* @return Pointer to the requested tool or NULL in case of failure. * @return Pointer to the requested tool or NULL in case of failure.
@ -218,8 +213,7 @@ public:
TOOL_BASE* FindTool( const std::string& aName ) const; TOOL_BASE* FindTool( const std::string& aName ) const;
/* /*
* Function GetTool() * Return the tool of given type or NULL if there is no such tool registered.
* Returns the tool of given type or NULL if there is no such tool registered.
*/ */
template<typename T> template<typename T>
T* GetTool() T* GetTool()
@ -233,42 +227,41 @@ public:
} }
/** /**
* Function DeactivateTool() * Deactivate the currently active tool.
* Deactivates the currently active tool.
*/ */
void DeactivateTool(); void DeactivateTool();
/** /**
* Function IsToolActive() * Return true if a tool with given id is active (executing)
* Returns true if a tool with given id is active (executing)
*/ */
bool IsToolActive( TOOL_ID aId ) const; bool IsToolActive( TOOL_ID aId ) const;
/** /**
* Function ResetTools() * Reset all tools (i.e. calls their Reset() method).
* Resets all tools (i.e. calls their Reset() method).
*/ */
void ResetTools( TOOL_BASE::RESET_REASON aReason ); void ResetTools( TOOL_BASE::RESET_REASON aReason );
/** /**
* Function InitTools() * Initializes all registered tools.
* Initializes all registered tools. If a tool fails during the initialization, it is *
* deactivated and becomes unavailable for further use. Initialization should be done * If a tool fails during the initialization, it is deactivated and becomes unavailable
* only once. * for further use. Initialization should be done only once.
*/ */
void InitTools(); void InitTools();
/** /**
* Propagates an event to tools that requested events of matching type(s). * Propagate an event to tools that requested events of matching type(s).
*
* @param aEvent is the event to be processed. * @param aEvent is the event to be processed.
* @return true if the event is a managed hotkey * @return true if the event is a managed hotkey
*/ */
bool ProcessEvent( const TOOL_EVENT& aEvent ); bool ProcessEvent( const TOOL_EVENT& aEvent );
/** /**
* Puts an event to the event queue to be processed at the end of event processing cycle. * Put an event to the event queue to be processed at the end of event processing cycle.
*
* @param aEvent is the event to be put into the queue. * @param aEvent is the event to be put into the queue.
*/ */
inline void PostEvent( const TOOL_EVENT& aEvent ) inline void PostEvent( const TOOL_EVENT& aEvent )
@ -277,7 +270,8 @@ public:
} }
/** /**
* Sets the work environment (model, view, view controls and the parent window). * Set the work environment (model, view, view controls and the parent window).
*
* These are made available to the tool. Called by the parent frame when it is set up. * These are made available to the tool. Called by the parent frame when it is set up.
*/ */
void SetEnvironment( EDA_ITEM* aModel, KIGFX::VIEW* aView, void SetEnvironment( EDA_ITEM* aModel, KIGFX::VIEW* aView,
@ -286,7 +280,7 @@ public:
/* /*
* Accessors for the environment objects (view, model, etc.) * Accessors for the environment objects (view, model, etc.)
* */ */
KIGFX::VIEW* GetView() const { return m_view; } KIGFX::VIEW* GetView() const { return m_view; }
KIGFX::VIEW_CONTROLS* GetViewControls() const { return m_viewControls; } KIGFX::VIEW_CONTROLS* GetViewControls() const { return m_viewControls; }
@ -301,8 +295,9 @@ public:
TOOLS_HOLDER* GetToolHolder() const { return m_frame; } TOOLS_HOLDER* GetToolHolder() const { return m_frame; }
/** /**
* Returns id of the tool that is on the top of the active tools stack * Return id of the tool that is on the top of the active tools stack (was invoked the
* (was invoked the most recently). * most recently).
*
* @return Id of the currently used tool. * @return Id of the currently used tool.
*/ */
inline int GetCurrentToolId() const inline int GetCurrentToolId() const
@ -311,8 +306,9 @@ public:
} }
/** /**
* Returns the tool that is on the top of the active tools stack * Return the tool that is on the top of the active tools stack (was invoked the most
* (was invoked the most recently). * recently).
*
* @return Pointer to the currently used tool. * @return Pointer to the currently used tool.
*/ */
inline TOOL_BASE* GetCurrentTool() const inline TOOL_BASE* GetCurrentTool() const
@ -321,7 +317,7 @@ public:
} }
/** /**
* Returns the TOOL_STATE object representing the state of the active tool. If there are no * Return the #TOOL_STATE object representing the state of the active tool. If there are no
* tools active, it returns nullptr. * tools active, it returns nullptr.
*/ */
TOOL_STATE* GetCurrentToolState() const TOOL_STATE* GetCurrentToolState() const
@ -331,24 +327,29 @@ public:
} }
/** /**
* Returns priority of a given tool. Higher number means that the tool is closer to the * Return priority of a given tool.
* beginning of the active tools queue (i.e. receives events earlier, tools with lower *
* priority receive events later). * Higher number means that the tool is closer to the beginning of the active tools
* queue (i.e. receives events earlier, tools with lower priority receive events later).
*
* @param aToolId is the id of queried tool. * @param aToolId is the id of queried tool.
* @return The priority of a given tool. If returned number is negative, then it means that * @return The priority of a given tool. If returned number is negative, then it means that
* the tool id is invalid or the tool is not active. * the tool id is invalid or the tool is not active.
*/ */
int GetPriority( int aToolId ) const; int GetPriority( int aToolId ) const;
/** /**
* Defines a state transition - the events that cause a given handler method in the tool * Define a state transition.
* to be called. Called by TOOL_INTERACTIVE::Go(). May be called from a coroutine context. *
* The events that cause a given handler method in the tool to be called. Called by
* TOOL_INTERACTIVE::Go(). May be called from a coroutine context.
*/ */
void ScheduleNextState( TOOL_BASE* aTool, TOOL_STATE_FUNC& aHandler, void ScheduleNextState( TOOL_BASE* aTool, TOOL_STATE_FUNC& aHandler,
const TOOL_EVENT_LIST& aConditions ); const TOOL_EVENT_LIST& aConditions );
/** /**
* Clears the state transition map for a tool * Clear the state transition map for a tool.
*
* @param aTool is the tool that should have the transition map cleared. * @param aTool is the tool that should have the transition map cleared.
*/ */
void ClearTransitions( TOOL_BASE* aTool ); void ClearTransitions( TOOL_BASE* aTool );
@ -356,22 +357,23 @@ public:
void RunMainStack( TOOL_BASE* aTool, std::function<void()> aFunc ); void RunMainStack( TOOL_BASE* aTool, std::function<void()> aFunc );
/** /**
* Updates the status bar and synchronizes toolbars. * Update the status bar and synchronizes toolbars.
*/ */
void UpdateUI( const TOOL_EVENT& aEvent ); void UpdateUI( const TOOL_EVENT& aEvent );
/** /**
* Pauses execution of a given tool until one or more events matching aConditions arrives. * Pause execution of a given tool until one or more events matching aConditions arrives.
* The pause/resume operation is done through COROUTINE object. *
* Called only from coroutines. * The pause/resume operation is done through #COROUTINE object. Called only from coroutines.
*/ */
TOOL_EVENT* ScheduleWait( TOOL_BASE* aTool, const TOOL_EVENT_LIST& aConditions ); TOOL_EVENT* ScheduleWait( TOOL_BASE* aTool, const TOOL_EVENT_LIST& aConditions );
/** /**
* Sets behaviour of the tool's context popup menu. * Set behavior of the tool's context popup menu.
* @param aTool - the parent tool *
* @param aMenu - the menu structure, defined by the tool * @param aTool is the parent tool.
* @param aTrigger - when the menu is activated: * @param aMenu is the menu structure, defined by the tool.
* @param aTrigger determines when the menu is activated:
* CMENU_NOW: opens the menu right now * CMENU_NOW: opens the menu right now
* CMENU_BUTTON: opens the menu when RMB is pressed * CMENU_BUTTON: opens the menu when RMB is pressed
* CMENU_OFF: menu is disabled. * CMENU_OFF: menu is disabled.
@ -380,23 +382,26 @@ public:
void ScheduleContextMenu( TOOL_BASE* aTool, ACTION_MENU* aMenu, CONTEXT_MENU_TRIGGER aTrigger ); void ScheduleContextMenu( TOOL_BASE* aTool, ACTION_MENU* aMenu, CONTEXT_MENU_TRIGGER aTrigger );
/** /**
* Stores an information to the system clipboard. * Store information to the system clipboard.
* @param aText is the information to be stored, expected UTF8 encoding. *
* the text will be stored as Unicode string (not stored as UTF8 string) * @param aText is the information to be stored, expected UTF8 encoding. The text will be
* stored as Unicode string (not stored as UTF8 string).
* @return False if error occurred. * @return False if error occurred.
*/ */
bool SaveClipboard( const std::string& aTextUTF8 ); bool SaveClipboard( const std::string& aTextUTF8 );
/** /**
* Returns the information currently stored in the system clipboard. If data stored in the * Return the information currently stored in the system clipboard.
* clipboard is in non-text format, empty string is returned. *
* Note also the clipboard is expected containing unicode chars, not only ASCII7 chars. * If data stored in the clipboard is in non-text format, empty string is returned.
* The returned string is UTF8 encoded *
* @note The clipboard is expected containing Unicode chars, not only ASCII7 chars.
* The returned string is UTF8 encoded
*/ */
std::string GetClipboardUTF8() const; std::string GetClipboardUTF8() const;
/** /**
* Returns the view controls settings for the current tool or the general settings if there is * Return the view controls settings for the current tool or the general settings if there is
* no active tool. * no active tool.
*/ */
const KIGFX::VC_SETTINGS& GetCurrentToolVC() const; const KIGFX::VC_SETTINGS& GetCurrentToolVC() const;
@ -410,9 +415,10 @@ public:
} }
/** /**
* Disables mouse warping after the current context menu is closed. * Disable mouse warping after the current context menu is closed.
* Must be called before invoking each context menu. *
* It's a good idea to call this from non-modal dialogs (e.g. DRC window). * This must be called before invoking each context menu. It's a good idea to call this
* from non-modal dialogs (e.g. DRC window).
*/ */
void VetoContextMenuMouseWarp() void VetoContextMenuMouseWarp()
{ {
@ -420,14 +426,13 @@ public:
} }
/** /**
* Function DispatchContextMenu() * Handle context menu related events.
* Handles context menu related events.
*/ */
void DispatchContextMenu( const TOOL_EVENT& aEvent ); void DispatchContextMenu( const TOOL_EVENT& aEvent );
/** /**
* Function dispatchHotKey() * Handle specific events, that are intended for TOOL_MANAGER rather than tools.
* Handles specific events, that are intended for TOOL_MANAGER rather than tools. *
* @param aEvent is the event to be processed. * @param aEvent is the event to be processed.
* @return true if the event was processed and should not go any further. * @return true if the event was processed and should not go any further.
*/ */
@ -442,49 +447,48 @@ private:
typedef std::pair<TOOL_EVENT_LIST, TOOL_STATE_FUNC> TRANSITION; typedef std::pair<TOOL_EVENT_LIST, TOOL_STATE_FUNC> TRANSITION;
/** /**
* Function dispatchInternal * Passe an event at first to the active tools, then to all others.
* Passes an event at first to the active tools, then to all others.
*/ */
bool dispatchInternal( const TOOL_EVENT& aEvent ); bool dispatchInternal( const TOOL_EVENT& aEvent );
/** /**
* Function dispatchActivation() * Check if it is a valid activation event and invokes a proper tool.
* Checks if it is a valid activation event and invokes a proper tool. *
* @param aEvent is an event to be tested. * @param aEvent is an event to be tested.
* @return True if a tool was invoked, false otherwise. * @return True if a tool was invoked, false otherwise.
*/ */
bool dispatchActivation( const TOOL_EVENT& aEvent ); bool dispatchActivation( const TOOL_EVENT& aEvent );
/** /**
* Function invokeTool() * Invoke a tool by sending a proper event (in contrary to runTool, which makes the tool run
* Invokes a tool by sending a proper event (in contrary to runTool, which makes the tool run
* for real). * for real).
*
* @param aTool is the tool to be invoked. * @param aTool is the tool to be invoked.
*/ */
bool invokeTool( TOOL_BASE* aTool ); bool invokeTool( TOOL_BASE* aTool );
/** /**
* Function runTool() * Make a tool active, so it can receive events and react to them.
* Makes a tool active, so it can receive events and react to them. Activated tool is pushed *
* on the active tools stack, so the last activated tool receives events first. * The activated tool is pushed on the active tools stack, so the last activated tool
* receives events first.
* *
* @param aTool is the tool to be run. * @param aTool is the tool to be run.
*/ */
bool runTool( TOOL_BASE* aTool ); bool runTool( TOOL_BASE* aTool );
/** /**
* Function finishTool() * Deactivate a tool and does the necessary clean up.
* Deactivates a tool and does the necessary clean up.
* *
* @param aState is the state variable of the tool to be stopped. * @param aState is the state variable of the tool to be stopped.
* @return m_activeTools iterator. If the tool has been completely deactivated, it points * @return m_activeTools iterator. If the tool has been completely deactivated, it points
* to the next active tool on the list. Otherwise it is an iterator pointing to aState. * to the next active tool on the list. Otherwise it is an iterator pointing to
* \a aState.
*/ */
ID_LIST::iterator finishTool( TOOL_STATE* aState ); ID_LIST::iterator finishTool( TOOL_STATE* aState );
/** /**
* Function isRegistered() * Return information about a tool registration status.
* Returns information about a tool registration status.
* *
* @param aTool is the tool to be checked. * @param aTool is the tool to be checked.
* @return true if the tool is in the registered tools list, false otherwise. * @return true if the tool is in the registered tools list, false otherwise.
@ -495,8 +499,7 @@ private:
} }
/** /**
* Function isActive() * Return information about a tool activation status.
* Returns information about a tool activation status.
* *
* @param aTool is the tool to be checked. * @param aTool is the tool to be checked.
* @return True if the tool is on the active tools stack, false otherwise. * @return True if the tool is on the active tools stack, false otherwise.
@ -504,53 +507,54 @@ private:
bool isActive( TOOL_BASE* aTool ); bool isActive( TOOL_BASE* aTool );
/** /**
* Function saveViewControls() * Save the #VIEW_CONTROLS settings to the tool state object.
* Saves the VIEW_CONTROLS settings to the tool state object. If VIEW_CONTROLS *
* settings are affected by TOOL_MANAGER, the original settings are saved. * If #VIEW_CONTROLS settings are affected by #TOOL_MANAGER, the original settings are saved.
*/ */
void saveViewControls( TOOL_STATE* aState ); void saveViewControls( TOOL_STATE* aState );
/** /**
* Function applyViewControls() * Apply #VIEW_CONTROLS settings stored in a #TOOL_STATE object.
* Applies VIEW_CONTROLS settings stored in a TOOL_STATE object.
*/ */
void applyViewControls( TOOL_STATE* aState ); void applyViewControls( TOOL_STATE* aState );
/** /**
* Main function for event processing. * Main function for event processing.
* @return true if a hotkey was handled *
* @return true if a hotkey was handled.
*/ */
bool processEvent( const TOOL_EVENT& aEvent ); bool processEvent( const TOOL_EVENT& aEvent );
/** /**
* Saves the previous active state and sets a new one. * Save the previous active state and sets a new one.
*
* @param aState is the new active state. Might be null to indicate there is no new * @param aState is the new active state. Might be null to indicate there is no new
* active state. * active state.
*/ */
void setActiveState( TOOL_STATE* aState ); void setActiveState( TOOL_STATE* aState );
/// List of tools in the order they were registered ///< List of tools in the order they were registered
TOOL_VEC m_toolOrder; TOOL_VEC m_toolOrder;
/// Index of registered tools current states, associated by tools' objects. ///< Index of registered tools current states, associated by tools' objects.
TOOL_STATE_MAP m_toolState; TOOL_STATE_MAP m_toolState;
/// Index of the registered tools current states, associated by tools' names. ///< Index of the registered tools current states, associated by tools' names.
NAME_STATE_MAP m_toolNameIndex; NAME_STATE_MAP m_toolNameIndex;
/// Index of the registered tools current states, associated by tools' ID numbers. ///< Index of the registered tools current states, associated by tools' ID numbers.
ID_STATE_MAP m_toolIdIndex; ID_STATE_MAP m_toolIdIndex;
/// Index of the registered tools to easily lookup by their type. ///< Index of the registered tools to easily lookup by their type.
std::map<const char*, TOOL_BASE*> m_toolTypes; std::map<const char*, TOOL_BASE*> m_toolTypes;
/// Stack of the active tools ///< Stack of the active tools
ID_LIST m_activeTools; ID_LIST m_activeTools;
/// Instance of ACTION_MANAGER that handles TOOL_ACTIONs ///< Instance of ACTION_MANAGER that handles TOOL_ACTIONs
ACTION_MANAGER* m_actionMgr; ACTION_MANAGER* m_actionMgr;
/// Original cursor position, if overridden by the context menu handler ///< Original cursor position, if overridden by the context menu handler
std::map<TOOL_ID, OPT<VECTOR2D>> m_cursorSettings; std::map<TOOL_ID, OPT<VECTOR2D>> m_cursorSettings;
EDA_ITEM* m_model; EDA_ITEM* m_model;
@ -559,21 +563,21 @@ private:
TOOLS_HOLDER* m_frame; TOOLS_HOLDER* m_frame;
APP_SETTINGS_BASE* m_settings; APP_SETTINGS_BASE* m_settings;
/// Queue that stores events to be processed at the end of the event processing cycle. ///< Queue that stores events to be processed at the end of the event processing cycle.
std::list<TOOL_EVENT> m_eventQueue; std::list<TOOL_EVENT> m_eventQueue;
/// Right click context menu position. ///< Right click context menu position.
VECTOR2D m_menuCursor; VECTOR2D m_menuCursor;
bool m_warpMouseAfterContextMenu; bool m_warpMouseAfterContextMenu;
/// Flag indicating whether a context menu is currently displayed. ///< Flag indicating whether a context menu is currently displayed.
bool m_menuActive; bool m_menuActive;
/// Tool currently displaying a popup menu. It is negative when there is no menu displayed. ///< Tool currently displaying a popup menu. It is negative when there is no menu displayed.
TOOL_ID m_menuOwner; TOOL_ID m_menuOwner;
/// Pointer to the state object corresponding to the currently executed tool. ///< Pointer to the state object corresponding to the currently executed tool.
TOOL_STATE* m_activeState; TOOL_STATE* m_activeState;
}; };

View File

@ -1,7 +1,7 @@
/* /*
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2017 KiCad Developers, see CHANGELOG.txt for contributors. * Copyright (C) 2017-2020 KiCad Developers, see AUTHORS.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -33,57 +33,42 @@
class ACTION_MENU; class ACTION_MENU;
/** /**
* TOOL_MENU * Manage a #CONDITIONAL_MENU and some number of CONTEXT_MENUs as sub-menus.
* *
* Manages a CONDITIONAL_MENU and some number of * Each "top-level" interactive tool can have one of these, and other tools can contribute
* CONTEXT_MENUs as sub-menus * #CONTEXT_MENUS to it. There are also helper functions for adding common sets of menu
* * items, for example zoom and grid controls.
* Each "top-level" interactive tool can have one of these,
* and other tools can contribute CONTEXT_MENUS to it.
*
* There are also helper functions for adding common sets of
* menu items, for example zoom and grid controls.
*/ */
class TOOL_MENU class TOOL_MENU
{ {
public: public:
/** /**
* Function TOOL_MENU * Construct a new TOOL_MENU for a specific tool.
* *
* Construct a new TOOL_MENU for a specific tool. This menu * This menu will be empty - it's up to the caller to add the relevant items. This can be
* will be empty - it's up to the caller to add the relevant * done directly, using the reference returned by TOOL_MENU::GetMenu(), or the helpers for
* items. This can be done directy, using the reference returned * common command sets can be used, or a combination of the two.
* by TOOL_MENU::GetMenu(), or the helpers for common command sets
* can be used, or a combination of the two.
*/ */
TOOL_MENU( TOOL_INTERACTIVE& aTool ); TOOL_MENU( TOOL_INTERACTIVE& aTool );
/** /**
* Destructor, also destructs any submenus created with * Destruct any submenus created with TOOL_MENU::CreateSubMenu().
* TOOL_MENU::CreateSubMenu().
*/ */
~TOOL_MENU(); ~TOOL_MENU();
/** /**
* Function GetMenu * @return reference to the CONDITIONAL_MENU model, which can be used by tools to add
* * their own commands to the menu.
* @return reference to the CONDITIONAL_MENU model, which can be
* used tby tools to add their own commands to the menu.
*/ */
CONDITIONAL_MENU& GetMenu(); CONDITIONAL_MENU& GetMenu();
/** /**
* Function CreateSubMenu * Store a submenu of this menu model. This can be shared with other menu models.
* *
* Store a submenu of this menu model. This can be shared with * It is the callers responsibility to add the submenu to m_menu (via GetMenu() ) in the
* other menu models. * right way, as well as to set the tool with SetTool(), since it's not a given that the
* * menu's tool is the tool that directly owns this #TOOL_MENU.
* It is the callers responsibility to add the submenu to
* m_menu (via GetMenu() ) in the right way, as well
* as to set the tool with SetTool(), since it's not a given
* that the menu's tool is the tool that directly owns this
* TOOL_MENU
* *
* @param aSubMenu: a sub menu to add * @param aSubMenu: a sub menu to add
*/ */
@ -98,39 +83,34 @@ public:
} }
/** /**
* Function ShowContextMenu * Helper function to set and immediately show a #CONDITIONAL_MENU in concert with the
* given #SELECTION
* *
* Helper function to set and immediately show a CONDITIONAL_MENU * You don't have to use this function, if the caller has a different way to show the
* in concert with the given SELECTION * menu, it can create one from the reference returned by TOOL_MENU::GetMenu(), but it
* * will have to be managed externally to this class.
* You don't have to use this function, if the caller has a
* different way to show the menu, it can create one from
* the reference returned by TOOL_MENU::GetMenu(), but it will
* have to be managed externally to this class.
*/ */
void ShowContextMenu( SELECTION& aSelection ); void ShowContextMenu( SELECTION& aSelection );
/** /**
* Function ShowContextMenu * Helper function to show a context menu without any selection for tools that can't
* * make selections.
* Helper function to show a context menu without any selection
* for tools that can't make selections.
*/ */
void ShowContextMenu(); void ShowContextMenu();
private: private:
/** /**
* The conditional menu displayed by the tool * The conditional menu displayed by the tool.
*/ */
CONDITIONAL_MENU m_menu; CONDITIONAL_MENU m_menu;
/** /**
* The tool that owns this menu * The tool that owns this menu.
*/ */
TOOL_INTERACTIVE& m_tool; TOOL_INTERACTIVE& m_tool;
/** /**
* Lifetime-managing container of submenus * Lifetime-managing container of submenus.
*/ */
std::vector<std::shared_ptr<ACTION_MENU> > m_subMenus; std::vector<std::shared_ptr<ACTION_MENU> > m_subMenus;
}; };

View File

@ -36,7 +36,6 @@ class ACTIONS;
/* /*
* Class TOOLS_HOLDER
* A mix-in class which allows its owner to hold a set of tools from the tool framework. * A mix-in class which allows its owner to hold a set of tools from the tool framework.
* *
* This is just the framework; the owner is responsible for registering individual tools, * This is just the framework; the owner is responsible for registering individual tools,
@ -44,27 +43,6 @@ class ACTIONS;
*/ */
class TOOLS_HOLDER class TOOLS_HOLDER
{ {
protected:
TOOL_MANAGER* m_toolManager;
ACTIONS* m_actions;
TOOL_DISPATCHER* m_toolDispatcher;
SELECTION m_dummySelection; // Empty dummy selection
std::vector<std::string> m_toolStack; // Stack of user-level "tools". This is NOT a
// stack of TOOL instances, because somewhat
// confusingly most TOOLs implement more than one
// user-level tool. A user-level tool actually
// equates to an ACTION handler, so this stack
// stores ACTION names.
bool m_immediateActions; // Preference for immediate actions. If false,
// the first invocation of a hotkey will just
// select the relevant tool rather than executing
// the tool's action.
bool m_dragSelects; // Prefer selection to dragging.
bool m_moveWarpsCursor; // cursor is warped to move/drag origin
public: public:
TOOLS_HOLDER(); TOOLS_HOLDER();
@ -79,8 +57,8 @@ public:
* Register an action's update conditions with the UI layer to allow the UI to appropriately * Register an action's update conditions with the UI layer to allow the UI to appropriately
* display the state of its controls. * display the state of its controls.
* *
* @param aAction is the action to register * @param aAction is the action to register.
* @param aConditions are the UI conditions to use for the control states * @param aConditions are the UI conditions to use for the control states.
*/ */
virtual void RegisterUIUpdateHandler( const TOOL_ACTION& aAction, virtual void RegisterUIUpdateHandler( const TOOL_ACTION& aAction,
const ACTION_CONDITIONS& aConditions ) const ACTION_CONDITIONS& aConditions )
@ -89,18 +67,18 @@ public:
} }
/** /**
* Register a UI update handler for the control with ID @c aID * Register a UI update handler for the control with ID @c aID.
* *
* @param aID is the control ID to register the handler for * @param aID is the control ID to register the handler for.
* @param aConditions are the UI conditions to use for the control states * @param aConditions are the UI conditions to use for the control states.
*/ */
virtual void RegisterUIUpdateHandler( int aID, const ACTION_CONDITIONS& aConditions ) virtual void RegisterUIUpdateHandler( int aID, const ACTION_CONDITIONS& aConditions )
{} {}
/** /**
* Unregister a UI handler for an action that was registered using @c RegisterUIUpdateHandler * Unregister a UI handler for an action that was registered using @c RegisterUIUpdateHandler.
* *
* @param aAction is the action to unregister the handler for * @param aAction is the action to unregister the handler for.
*/ */
virtual void UnregisterUIUpdateHandler( const TOOL_ACTION& aAction ) virtual void UnregisterUIUpdateHandler( const TOOL_ACTION& aAction )
{ {
@ -108,9 +86,9 @@ public:
} }
/** /**
* Unregister a UI handler for a given ID that was registered using @c RegisterUIUpdateHandler * Unregister a UI handler for a given ID that was registered using @c RegisterUIUpdateHandler.
* *
* @param aID is the control ID to unregister the handler for * @param aID is the control ID to unregister the handler for.
*/ */
virtual void UnregisterUIUpdateHandler( int aID ) virtual void UnregisterUIUpdateHandler( int aID )
{} {}
@ -118,7 +96,7 @@ public:
/** /**
* Get the current selection from the canvas area. * Get the current selection from the canvas area.
* *
* @return the current selection * @return the current selection.
*/ */
virtual SELECTION& GetCurrentSelection() virtual SELECTION& GetCurrentSelection()
{ {
@ -126,9 +104,11 @@ public:
} }
/** /**
* NB: the definition of "tool" is different at the user level. The implementation uses * NB: the definition of "tool" is different at the user level.
* a single TOOL_BASE derived class to implement several user "tools", such as rectangle *
* and circle, or wire and bus. So each user-level tool is actually a TOOL_ACTION. * The implementation uses a single TOOL_BASE derived class to implement several user
* "tools", such as rectangle and circle, or wire and bus. So each user-level tool is
* actually a #TOOL_ACTION.
*/ */
virtual void PushTool( const std::string& actionName ); virtual void PushTool( const std::string& actionName );
virtual void PopTool( const std::string& actionName ); virtual void PopTool( const std::string& actionName );
@ -141,20 +121,20 @@ public:
virtual void DisplayToolMsg( const wxString& msg ) {}; virtual void DisplayToolMsg( const wxString& msg ) {};
/** /**
* Indicates that hotkeys should perform an immediate action even if another tool is * Indicate that hotkeys should perform an immediate action even if another tool is
* currently active. If false, the first hotkey should select the relevant tool. * currently active. If false, the first hotkey should select the relevant tool.
*/ */
bool GetDoImmediateActions() const { return m_immediateActions; } bool GetDoImmediateActions() const { return m_immediateActions; }
/** /**
* Indicates that a drag should draw a selection rectangle, even when started over an * Indicate that a drag should draw a selection rectangle, even when started over an
* item. * item.
*/ */
bool GetDragSelects() const { return m_dragSelects; } bool GetDragSelects() const { return m_dragSelects; }
/** /**
* Indicates that a move operation should warp the mouse pointer to the origin of the * Indicate that a move operation should warp the mouse pointer to the origin of the
* move object. This improves snapping, but some users are alergic to mouse warping. * move object. This improves snapping, but some users are allergic to mouse warping.
*/ */
bool GetMoveWarpsCursor() const { return m_moveWarpsCursor; } bool GetMoveWarpsCursor() const { return m_moveWarpsCursor; }
@ -171,6 +151,27 @@ public:
virtual void RefreshCanvas() { } virtual void RefreshCanvas() { }
virtual wxString ConfigBaseName() { return wxEmptyString; } virtual wxString ConfigBaseName() { return wxEmptyString; }
protected:
TOOL_MANAGER* m_toolManager;
ACTIONS* m_actions;
TOOL_DISPATCHER* m_toolDispatcher;
SELECTION m_dummySelection; // Empty dummy selection
std::vector<std::string> m_toolStack; // Stack of user-level "tools". This is NOT a
// stack of TOOL instances, because somewhat
// confusingly most TOOLs implement more than one
// user-level tool. A user-level tool actually
// equates to an ACTION handler, so this stack
// stores ACTION names.
bool m_immediateActions; // Preference for immediate actions. If false,
// the first invocation of a hotkey will just
// select the relevant tool rather than executing
// the tool's action.
bool m_dragSelects; // Prefer selection to dragging.
bool m_moveWarpsCursor; // cursor is warped to move/drag origin
}; };
#endif // TOOL_HOLDER_H #endif // TOOL_HOLDER_H

View File

@ -2,6 +2,8 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2013-2016 CERN * Copyright (C) 2013-2016 CERN
* Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors.
*
* @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch> * @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
@ -46,19 +48,21 @@ class VIEW_GROUP;
class VIEW_RTREE; class VIEW_RTREE;
/** /**
* VIEW. * Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device
* Holds a (potentially large) number of VIEW_ITEMs and renders them on a graphics device * provided by the GAL.
* provided by the GAL. VIEWs can exist in two flavors: *
* VIEWs can exist in two flavors:
* - dynamic - where items can be added, removed or changed anytime, intended for the main * - dynamic - where items can be added, removed or changed anytime, intended for the main
* editing panel. Each VIEW_ITEM can be added to a single dynamic view. * editing panel. Each VIEW_ITEM can be added to a single dynamic view.
* - static - where items are added once at the startup and are not linked with the VIEW. * - static - where items are added once at the startup and are not linked with the VIEW.
* Foreseen for preview windows and printing. * Foreseen for preview windows and printing.
* Items in a view are grouped in layers (not to be confused with Kicad's PCB layers). Each layer is *
* identified by an integer number. Visibility and rendering order can be set individually for each * Items in a view are grouped in layers (not to be confused with Kicad's PCB layers). Each
* of the layers. Future versions of the VIEW will also allows one to assign different layers to different * layer is identified by an integer number. Visibility and rendering order can be set
* rendering targets, which will be composited at the final stage by the GAL. * individually for each of the layers. Future versions of the VIEW will also allows one to
* The VIEW class also provides fast methods for finding all visible objects that are within a given * assign different layers to different rendering targets, which will be composited at the
* rectangular area, useful for object selection/hit testing. * final stage by the GAL. The VIEW class also provides fast methods for finding all visible
* objects that are within a given rectangular area, useful for object selection/hit testing.
*/ */
class VIEW class VIEW
{ {
@ -68,49 +72,52 @@ public:
typedef std::pair<VIEW_ITEM*, int> LAYER_ITEM_PAIR; typedef std::pair<VIEW_ITEM*, int> LAYER_ITEM_PAIR;
/** /**
* Constructor.
* @param aIsDynamic decides whether we are creating a static or a dynamic VIEW. * @param aIsDynamic decides whether we are creating a static or a dynamic VIEW.
*/ */
VIEW( bool aIsDynamic = true ); VIEW( bool aIsDynamic = true );
virtual ~VIEW(); virtual ~VIEW();
// nasty hack, invoked by the destructor of VIEW_ITEM to auto-remove the item /**
// from the owning VIEW if there is any. Kicad relies too much on this mechanism. * Nasty hack, invoked by the destructor of VIEW_ITEM to auto-remove the item
// this is the only linking dependency now between EDA_ITEM and VIEW class. In near future * from the owning VIEW if there is any.
// I'll replace it with observers. *
* KiCad relies too much on this mechanism. This is the only linking dependency now
* between #EDA_ITEM and VIEW class. In near future I'll replace it with observers.
*/
static void OnDestroy( VIEW_ITEM* aItem ); static void OnDestroy( VIEW_ITEM* aItem );
/** /**
* Function Add() * Add a #VIEW_ITEM to the view.
* Adds a VIEW_ITEM to the view. *
* Set aDrawPriority to -1 to assign sequential priorities. * Set \a aDrawPriority to -1 to assign sequential priorities.
*
* @param aItem: item to be added. No ownership is given * @param aItem: item to be added. No ownership is given
* @param aDrawPriority: priority to draw this item on its layer, lowest first. * @param aDrawPriority: priority to draw this item on its layer, lowest first.
*/ */
virtual void Add( VIEW_ITEM* aItem, int aDrawPriority = -1 ); virtual void Add( VIEW_ITEM* aItem, int aDrawPriority = -1 );
/** /**
* Function Remove() * Remove a #VIEW_ITEM from the view.
* Removes a VIEW_ITEM from the view. *
* @param aItem: item to be removed. Caller must dispose the removed item if necessary * @param aItem: item to be removed. Caller must dispose the removed item if necessary
*/ */
virtual void Remove( VIEW_ITEM* aItem ); virtual void Remove( VIEW_ITEM* aItem );
/** /**
* Function Query() * Find all visible items that touch or are within the rectangle \a aRect.
* Finds all visible items that touch or are within the rectangle aRect. *
* @param aRect area to search for items * @param aRect area to search for items
* @param aResult result of the search, containing VIEW_ITEMs associated with their layers. * @param aResult result of the search, containing VIEW_ITEMs associated with their layers.
* Sorted according to the rendering order (items that are on top of the rendering stack as * Sorted according to the rendering order (items that are on top of the
* first). * rendering stack as first).
* @return Number of found items. * @return Number of found items.
*/ */
virtual int Query( const BOX2I& aRect, std::vector<LAYER_ITEM_PAIR>& aResult ) const; virtual int Query( const BOX2I& aRect, std::vector<LAYER_ITEM_PAIR>& aResult ) const;
/** /**
* Sets the item visibility. * Set the item visibility.
* *
* @param aItem: the item to modify. * @param aItem: the item to modify.
* @param aIsVisible: whether the item is visible (on all layers), or not. * @param aIsVisible: whether the item is visible (on all layers), or not.
@ -118,7 +125,7 @@ public:
void SetVisible( VIEW_ITEM* aItem, bool aIsVisible = true ); void SetVisible( VIEW_ITEM* aItem, bool aIsVisible = true );
/** /**
* Temporarily hides the item in the view (e.g. for overlaying) * Temporarily hide the item in the view (e.g. for overlaying).
* *
* @param aItem: the item to modify. * @param aItem: the item to modify.
* @param aHide: whether the item is hidden (on all layers), or not. * @param aHide: whether the item is hidden (on all layers), or not.
@ -126,7 +133,7 @@ public:
void Hide( VIEW_ITEM* aItem, bool aHide = true ); void Hide( VIEW_ITEM* aItem, bool aHide = true );
/** /**
* Returns information if the item is visible (or not). * Return information if the item is visible (or not).
* *
* @param aItem: the item to test. * @param aItem: the item to test.
* @return when true, the item is visible (i.e. to be displayed, not visible in the * @return when true, the item is visible (i.e. to be displayed, not visible in the
@ -135,7 +142,7 @@ public:
bool IsVisible( const VIEW_ITEM* aItem ) const; bool IsVisible( const VIEW_ITEM* aItem ) const;
/** /**
* For dynamic VIEWs, informs the associated VIEW that the graphical representation of * For dynamic VIEWs, inform the associated VIEW that the graphical representation of
* this item has changed. For static views calling has no effect. * this item has changed. For static views calling has no effect.
* *
* @param aItem: the item to update. * @param aItem: the item to update.
@ -145,9 +152,9 @@ public:
virtual void Update( const VIEW_ITEM* aItem ) const; virtual void Update( const VIEW_ITEM* aItem ) const;
/** /**
* Function SetRequired() * Mark the \a aRequiredId layer as required for the aLayerId layer. In order to display the
* Marks the aRequiredId layer as required for the aLayerId layer. In order to display the
* layer, all of its required layers have to be enabled. * layer, all of its required layers have to be enabled.
*
* @param aLayerId is the id of the layer for which we enable/disable the required layer. * @param aLayerId is the id of the layer for which we enable/disable the required layer.
* @param aRequiredId is the id of the required layer. * @param aRequiredId is the id of the required layer.
* @param aRequired tells if the required layer should be added or removed from the list. * @param aRequired tells if the required layer should be added or removed from the list.
@ -155,8 +162,8 @@ public:
void SetRequired( int aLayerId, int aRequiredId, bool aRequired = true ); void SetRequired( int aLayerId, int aRequiredId, bool aRequired = true );
/** /**
* Function CopySettings() * Copy layers and visibility settings from another view.
* Copies layers and visibility settings from another view. *
* @param aOtherView: view from which settings will be copied. * @param aOtherView: view from which settings will be copied.
*/ */
void CopySettings( const VIEW* aOtherView ); void CopySettings( const VIEW* aOtherView );
@ -168,15 +175,15 @@ public:
*/ */
/** /**
* Function SetGAL() * Assign a rendering device for the VIEW.
* Assigns a rendering device for the VIEW. *
* @param aGal: pointer to the GAL output device * @param aGal: pointer to the GAL output device.
*/ */
void SetGAL( GAL* aGal ); void SetGAL( GAL* aGal );
/** /**
* Function GetGAL() * Return the #GAL this view is using to draw graphical primitives.
* Returns the GAL this view is using to draw graphical primitives. *
* @return Pointer to the currently used GAL instance. * @return Pointer to the currently used GAL instance.
*/ */
inline GAL* GetGAL() const inline GAL* GetGAL() const
@ -185,8 +192,7 @@ public:
} }
/** /**
* Function SetPainter() * Set the painter object used by the view for drawing #VIEW_ITEMS.
* Sets the painter object used by the view for drawing VIEW_ITEMS.
*/ */
inline void SetPainter( PAINTER* aPainter ) inline void SetPainter( PAINTER* aPainter )
{ {
@ -194,8 +200,8 @@ public:
} }
/** /**
* Function GetPainter() * Return the painter object used by the view for drawing #VIEW_ITEMS.
* Returns the painter object used by the view for drawing VIEW_ITEMS. *
* @return Pointer to the currently used Painter instance. * @return Pointer to the currently used Painter instance.
*/ */
inline PAINTER* GetPainter() const inline PAINTER* GetPainter() const
@ -204,30 +210,29 @@ public:
} }
/** /**
* Function SetViewport() * Set the visible area of the VIEW.
* Sets the visible area of the VIEW. *
* @param aViewport: desired visible area, in world space coordinates. * @param aViewport: desired visible area, in world space coordinates.
*/ */
void SetViewport( const BOX2D& aViewport ); void SetViewport( const BOX2D& aViewport );
/** /**
* Function GetViewport() * Return the current viewport visible area rectangle.
* Returns the current viewport visible area rectangle. *
* @return Current viewport rectangle * @return Current viewport rectangle.
*/ */
BOX2D GetViewport() const; BOX2D GetViewport() const;
/** /**
* Function SetMirror() * Control the mirroring of the VIEW.
* Controls the mirroring of the VIEW. *
* @param aMirrorX: when true, the X axis is mirrored * @param aMirrorX: when true, the X axis is mirrored.
* @param aMirrorY: when true, the Y axis is mirrored. * @param aMirrorY: when true, the Y axis is mirrored.
*/ */
void SetMirror( bool aMirrorX, bool aMirrorY ); void SetMirror( bool aMirrorX, bool aMirrorY );
/** /**
* Function IsMirroredX() * Return true if view is flipped across the X axis.
* Returns true if view is flipped across the X axis.
*/ */
bool IsMirroredX() const bool IsMirroredX() const
{ {
@ -235,8 +240,7 @@ public:
} }
/** /**
* Function IsMirroredX() * Return true if view is flipped across the Y axis.
* Returns true if view is flipped across the Y axis.
*/ */
bool IsMirroredY() const bool IsMirroredY() const
{ {
@ -244,16 +248,16 @@ public:
} }
/** /**
* Function SetScale() * Set the scaling factor, zooming around a given anchor point.
* Sets the scaling factor, zooming around a given anchor point. *
* (depending on correct GAL unit length & DPI settings). * (depending on correct GAL unit length & DPI settings).
* @param aAnchor: the zooming anchor point *
* @param aScale: the scale factor * @param aAnchor is the zooming anchor point.
* @param aScale is the scale factor.
*/ */
virtual void SetScale( double aScale, VECTOR2D aAnchor = { 0, 0 } ); virtual void SetScale( double aScale, VECTOR2D aAnchor = { 0, 0 } );
/** /**
* Function GetScale()
* @return Current scale factor of this VIEW. * @return Current scale factor of this VIEW.
*/ */
inline double GetScale() const inline double GetScale() const
@ -262,8 +266,8 @@ public:
} }
/** /**
* Function SetBoundary() * Set limits for view area.
* Sets limits for view area. *
* @param aBoundary is the box that limits view area. * @param aBoundary is the box that limits view area.
*/ */
inline void SetBoundary( const BOX2D& aBoundary ) inline void SetBoundary( const BOX2D& aBoundary )
@ -272,8 +276,8 @@ public:
} }
/** /**
* Function SetBoundary() * Set limits for view area.
* Sets limits for view area. *
* @param aBoundary is the box that limits view area. * @param aBoundary is the box that limits view area.
*/ */
inline void SetBoundary( const BOX2I& aBoundary ) inline void SetBoundary( const BOX2I& aBoundary )
@ -283,7 +287,6 @@ public:
} }
/** /**
* Function GetBoundary()
* @return Current view area boundary. * @return Current view area boundary.
*/ */
inline const BOX2D& GetBoundary() const inline const BOX2D& GetBoundary() const
@ -292,8 +295,8 @@ public:
} }
/** /**
* Function SetScaleLimits() * Set minimum and maximum values for scale.
* Sets minimum and maximum values for scale. *
* @param aMaximum is the maximum value for scale. * @param aMaximum is the maximum value for scale.
* @param aMinimum is the minimum value for scale. * @param aMinimum is the minimum value for scale.
*/ */
@ -306,25 +309,25 @@ public:
} }
/** /**
* Function SetCenter() * Set the center point of the VIEW (i.e. the point in world space that will be drawn in
* Sets the center point of the VIEW (i.e. the point in world space that will be drawn in the middle * the middle of the screen).
* of the screen). *
* @param aCenter: the new center point, in world space coordinates. * @param aCenter: the new center point, in world space coordinates.
*/ */
void SetCenter( const VECTOR2D& aCenter ); void SetCenter( const VECTOR2D& aCenter );
/** /**
* Function SetCenter() * Set the center point of the VIEW, attempting to avoid \a occultingScreenRect (for
* Sets the center point of the VIEW, attempting to avoid \a occultingScreenRect (for
* instance, the screen rect of a modeless dialog in front of the VIEW). * instance, the screen rect of a modeless dialog in front of the VIEW).
*
* @param aCenter: the new center point, in world space coordinates. * @param aCenter: the new center point, in world space coordinates.
* @param occultingScreenRect: the occulting rect, in screen space coordinates. * @param occultingScreenRect: the occulting rect, in screen space coordinates.
*/ */
void SetCenter( VECTOR2D aCenter, const BOX2D& occultingScreenRect ); void SetCenter( VECTOR2D aCenter, const BOX2D& occultingScreenRect );
/** /**
* Function GetCenter() * Return the center point of this VIEW (in world space coordinates).
* Returns the center point of this VIEW (in world space coordinates) *
* @return center point of the view * @return center point of the view
*/ */
const VECTOR2D& GetCenter() const const VECTOR2D& GetCenter() const
@ -333,54 +336,53 @@ public:
} }
/** /**
* Function ToWorld()
* Converts a screen space point/vector to a point/vector in world space coordinates. * Converts a screen space point/vector to a point/vector in world space coordinates.
* @param aCoord: the point/vector to be converted *
* @param aAbsolute: when true, aCoord is treated as a point, otherwise - as a direction (vector) * @param aCoord is the point/vector to be converted.
* @param aAbsolute when true aCoord is treated as a point, otherwise as a direction (vector).
*/ */
VECTOR2D ToWorld( const VECTOR2D& aCoord, bool aAbsolute = true ) const; VECTOR2D ToWorld( const VECTOR2D& aCoord, bool aAbsolute = true ) const;
/** /**
* Function ToWorld()
* Converts a screen space one dimensional size to a one dimensional size in world * Converts a screen space one dimensional size to a one dimensional size in world
* space coordinates. * space coordinates.
* @param aSize : the size to be converted *
* @param aSize is the size to be converted.
*/ */
double ToWorld( double aSize ) const; double ToWorld( double aSize ) const;
/** /**
* Function ToScreen() * Convert a world space point/vector to a point/vector in screen space coordinates.
* Converts a world space point/vector to a point/vector in screen space coordinates. *
* @param aCoord: the point/vector to be converted * @param aCoord is the point/vector to be converted.
* @param aAbsolute: when true, aCoord is treated as a point, otherwise - as a direction (vector) * @param aAbsolute when true aCoord is treated as a point, otherwise as a direction (vector).
*/ */
VECTOR2D ToScreen( const VECTOR2D& aCoord, bool aAbsolute = true ) const; VECTOR2D ToScreen( const VECTOR2D& aCoord, bool aAbsolute = true ) const;
/** /**
* Function ToScreen() * Convert a world space one dimensional size to a one dimensional size in screen space.
* Converts a world space one dimensionsal size to a one dimensional size in screen space. *
* @param aSize: the size to be transformed. * @param aSize: the size to be transformed.
*/ */
double ToScreen( double aSize ) const; double ToScreen( double aSize ) const;
/** /**
* Function GetScreenPixelSize() * Return the size of the our rendering area in pixels.
* Returns the size of the our rendering area, in pixels. *
* @return viewport screen size * @return viewport screen size.
*/ */
const VECTOR2I& GetScreenPixelSize() const; const VECTOR2I& GetScreenPixelSize() const;
/** /**
* Function Clear() * Remove all items from the view.
* Removes all items from the view.
*/ */
void Clear(); void Clear();
/** /**
* Function SetLayerVisible() * Control the visibility of a particular layer.
* Controls the visibility of a particular layer. *
* @param aLayer: the layer to show/hide. * @param aLayer is the layer to show/hide.
* @param aVisible: the obvious. * @param aVisible is the layer visibility state.
*/ */
inline void SetLayerVisible( int aLayer, bool aVisible = true ) inline void SetLayerVisible( int aLayer, bool aVisible = true )
{ {
@ -395,9 +397,9 @@ public:
} }
/** /**
* Function IsLayerVisible() * Return information about visibility of a particular layer.
* Returns information about visibility of a particular layer. *
* @param aLayer: true if the layer is visible, false otherwise * @param aLayer true if the layer is visible, false otherwise.
*/ */
inline bool IsLayerVisible( int aLayer ) const inline bool IsLayerVisible( int aLayer ) const
{ {
@ -412,8 +414,8 @@ public:
} }
/** /**
* Function SetLayerTarget() * Change the rendering target for a particular layer.
* Changes the rendering target for a particular layer. *
* @param aLayer is the layer. * @param aLayer is the layer.
* @param aTarget is the rendering target. * @param aTarget is the rendering target.
*/ */
@ -424,69 +426,71 @@ public:
} }
/** /**
* Function SetLayerOrder() * Set rendering order of a particular layer. Lower values are rendered first.
* Sets rendering order of a particular layer. Lower values are rendered first. *
* @param aLayer: the layer * @param aLayer is the layer.
* @param aRenderingOrder: arbitrary number denoting the rendering order. * @param aRenderingOrder is an arbitrary number denoting the rendering order.
*/ */
void SetLayerOrder( int aLayer, int aRenderingOrder ); void SetLayerOrder( int aLayer, int aRenderingOrder );
/** /**
* Function GetLayerOrder() * Return rendering order of a particular layer. Lower values are rendered first.
* Returns rendering order of a particular layer. Lower values are rendered first. *
* @param aLayer: the layer * @param aLayer is the layer.
* @return Rendering order of a particular layer. * @return Rendering order of a particular layer.
*/ */
int GetLayerOrder( int aLayer ) const; int GetLayerOrder( int aLayer ) const;
/** /**
* Function SortLayers() * Change the order of given layer ids, so after sorting the order corresponds to layers
* Changes the order of given layer ids, so after sorting the order corresponds to layers
* rendering order (descending, ie. order in which layers should be drawn - from the bottom to * rendering order (descending, ie. order in which layers should be drawn - from the bottom to
* the top). * the top).
*
* @param aLayers stores id of layers to be sorted. * @param aLayers stores id of layers to be sorted.
* @param aCount stores the number of layers. * @param aCount stores the number of layers.
*/ */
void SortLayers( int aLayers[], int& aCount ) const; void SortLayers( int aLayers[], int& aCount ) const;
/** /**
* Remaps the data between layer ids without invalidating that data * Remap the data between layer ids without invalidating that data.
* *
* Used by GerbView for the "Sort by X2" functionality * Used by GerbView for the "Sort by X2" functionality.
* *
* @param aReorderMap is a mapping of old to new layer ids * @param aReorderMap is a mapping of old to new layer ids.
*/ */
void ReorderLayerData( std::unordered_map<int, int> aReorderMap ); void ReorderLayerData( std::unordered_map<int, int> aReorderMap );
/** /**
* Function UpdateLayerColor() * Apply the new coloring scheme held by RENDER_SETTINGS in case that it has changed.
* Applies the new coloring scheme held by RENDER_SETTINGS in case that it has changed. *
* @param aLayer is a number of the layer to be updated. * @param aLayer is a number of the layer to be updated.
* @see RENDER_SETTINGS * @see RENDER_SETTINGS
*/ */
void UpdateLayerColor( int aLayer ); void UpdateLayerColor( int aLayer );
/** /**
* Function UpdateAllLayersColor() * Apply the new coloring scheme to all layers. The used scheme is held by #RENDER_SETTINGS.
* Applies the new coloring scheme to all layers. The used scheme is held by RENDER_SETTINGS. *
* @see RENDER_SETTINGS * @see RENDER_SETTINGS
*/ */
void UpdateAllLayersColor(); void UpdateAllLayersColor();
/** /**
* Function SetTopLayer() * Set given layer to be displayed on the top or sets back the default order of layers.
* Sets given layer to be displayed on the top or sets back the default order of layers. *
* @param aEnabled = true to display aLayer on the top. * @param aEnabled = true to display aLayer on the top.
* @param aLayer: the layer or -1 in case when no particular layer should * @param aLayer is the layer or -1 in case when no particular layer should be displayed
* be displayed on the top. * on the top.
*/ */
virtual void SetTopLayer( int aLayer, bool aEnabled = true ); virtual void SetTopLayer( int aLayer, bool aEnabled = true );
/** /**
* Function EnableTopLayer() * Enable or disable display of the top layer.
* Enables or disables display of the top layer. When disabled - layers are rendered as usual *
* with no influence from SetTopLayer function. Otherwise on the top there is displayed the * When disabled, layers are rendered as usual with no influence from SetTopLayer
* layer set previously with SetTopLayer function. * function. Otherwise on the top there is displayed the layer set previously with
* SetTopLayer function.
*
* @param aEnable whether to enable or disable display of the top layer. * @param aEnable whether to enable or disable display of the top layer.
*/ */
virtual void EnableTopLayer( bool aEnable ); virtual void EnableTopLayer( bool aEnable );
@ -494,40 +498,35 @@ public:
virtual int GetTopLayer() const; virtual int GetTopLayer() const;
/** /**
* Function ClearTopLayers() * Remove all layers from the on-the-top set (they are no longer displayed over the rest of
* Removes all layers from the on-the-top set (they are no longer displayed over the rest of
* layers). * layers).
*/ */
void ClearTopLayers(); void ClearTopLayers();
/** /**
* Function UpdateLayerOrder() * Do everything that is needed to apply the rendering order of layers.
* Does everything that is needed to apply the rendering order of layers. It has to be called *
* after modification of renderingOrder field of LAYER. * It has to be called after modification of renderingOrder field of LAYER.
*/ */
void UpdateAllLayersOrder(); void UpdateAllLayersOrder();
/** /**
* Function ClearTargets() * Clear targets that are marked as dirty.
* Clears targets that are marked as dirty.
*/ */
void ClearTargets(); void ClearTargets();
/** /**
* Function Redraw()
* Immediately redraws the whole view. * Immediately redraws the whole view.
*/ */
virtual void Redraw(); virtual void Redraw();
/** /**
* Function RecacheAllItems() * Rebuild GAL display lists.
* Rebuilds GAL display lists.
*/ */
void RecacheAllItems(); void RecacheAllItems();
/** /**
* Function IsDynamic() * Tell if the VIEW is dynamic (ie. can be changed, for example displaying PCBs in a window)
* Tells if the VIEW is dynamic (ie. can be changed, for example displaying PCBs in a window)
* or static (that cannot be modified, eg. displaying image/PDF). * or static (that cannot be modified, eg. displaying image/PDF).
*/ */
bool IsDynamic() const bool IsDynamic() const
@ -536,8 +535,8 @@ public:
} }
/** /**
* Function IsDirty() * Return true if any of the VIEW layers needs to be refreshened.
* Returns true if any of the VIEW layers needs to be refreshened. *
* @return True in case if any of layers is marked as dirty. * @return True in case if any of layers is marked as dirty.
*/ */
bool IsDirty() const bool IsDirty() const
@ -552,9 +551,9 @@ public:
} }
/** /**
* Function IsTargetDirty() * Return true if any of layers belonging to the target or the target itself should be
* Returns true if any of layers belonging to the target or the target itself should be
* redrawn. * redrawn.
*
* @return True if the above condition is fulfilled. * @return True if the above condition is fulfilled.
*/ */
bool IsTargetDirty( int aTarget ) const bool IsTargetDirty( int aTarget ) const
@ -564,8 +563,8 @@ public:
} }
/** /**
* Function MarkTargetDirty() * Set or clear target 'dirty' flag.
* Sets or clears target 'dirty' flag. *
* @param aTarget is the target to set. * @param aTarget is the target to set.
*/ */
inline void MarkTargetDirty( int aTarget ) inline void MarkTargetDirty( int aTarget )
@ -574,7 +573,7 @@ public:
m_dirtyTargets[aTarget] = true; m_dirtyTargets[aTarget] = true;
} }
/// Returns true if the layer is cached /// Return true if the layer is cached.
inline bool IsCached( int aLayer ) const inline bool IsCached( int aLayer ) const
{ {
wxCHECK( aLayer < (int) m_layers.size(), false ); wxCHECK( aLayer < (int) m_layers.size(), false );
@ -590,8 +589,7 @@ public:
} }
/** /**
* Function MarkDirty() * Force redraw of view on the next rendering.
* Forces redraw of view on the next rendering.
*/ */
void MarkDirty() void MarkDirty()
{ {
@ -600,34 +598,34 @@ public:
} }
/** /**
* Function MarkForUpdate() * Add an item to a list of items that are going to be refreshed upon the next frame rendering.
* Adds an item to a list of items that are going to be refreshed upon the next frame rendering. *
* @param aItem is the item to be refreshed. * @param aItem is the item to be refreshed.
*/ */
void MarkForUpdate( VIEW_ITEM* aItem ); void MarkForUpdate( VIEW_ITEM* aItem );
/** /**
* Function UpdateItems() * Iterate through the list of items that asked for updating and updates them.
* Iterates through the list of items that asked for updating and updates them.
*/ */
void UpdateItems(); void UpdateItems();
/** /**
* Updates all items in the view according to the given flags * Update all items in the view according to the given flags.
*
* @param aUpdateFlags is is according to KIGFX::VIEW_UPDATE_FLAGS * @param aUpdateFlags is is according to KIGFX::VIEW_UPDATE_FLAGS
*/ */
void UpdateAllItems( int aUpdateFlags ); void UpdateAllItems( int aUpdateFlags );
/** /**
* Updates items in the view according to the given flags and condition * Update items in the view according to the given flags and condition.
* @param aUpdateFlags is is according to KIGFX::VIEW_UPDATE_FLAGS *
* @param aCondition is a function returning true if the item should be updated * @param aUpdateFlags is is according to KIGFX::VIEW_UPDATE_FLAGS.
* @param aCondition is a function returning true if the item should be updated.
*/ */
void UpdateAllItemsConditionally( int aUpdateFlags, void UpdateAllItemsConditionally( int aUpdateFlags,
std::function<bool( VIEW_ITEM* )> aCondition ); std::function<bool( VIEW_ITEM* )> aCondition );
/** /**
* Function IsUsingDrawPriority()
* @return true if draw priority is being respected while redrawing. * @return true if draw priority is being respected while redrawing.
*/ */
bool IsUsingDrawPriority() const bool IsUsingDrawPriority() const
@ -636,7 +634,6 @@ public:
} }
/** /**
* Function UseDrawPriority()
* @param aFlag is true if draw priority should be respected while redrawing. * @param aFlag is true if draw priority should be respected while redrawing.
*/ */
void UseDrawPriority( bool aFlag ) void UseDrawPriority( bool aFlag )
@ -645,7 +642,6 @@ public:
} }
/** /**
* Function IsDrawOrderReversed()
* @return true if draw order is reversed * @return true if draw order is reversed
*/ */
bool IsDrawOrderReversed() const bool IsDrawOrderReversed() const
@ -654,8 +650,8 @@ public:
} }
/** /**
* Function ReverseDrawOrder()
* Only takes effect if UseDrawPriority is true. * Only takes effect if UseDrawPriority is true.
*
* @param aFlag is true if draw order should be reversed * @param aFlag is true if draw order should be reversed
*/ */
void ReverseDrawOrder( bool aFlag ) void ReverseDrawOrder( bool aFlag )
@ -673,38 +669,125 @@ public:
void ShowPreview( bool aShow = true ); void ShowPreview( bool aShow = true );
/** /**
* Returns a new VIEW object that shares the same set of VIEW_ITEMs and LAYERs. * Return a new VIEW object that shares the same set of VIEW_ITEMs and LAYERs.
*
* GAL, PAINTER and other properties are left uninitialized. * GAL, PAINTER and other properties are left uninitialized.
*/ */
std::unique_ptr<VIEW> DataReference() const; std::unique_ptr<VIEW> DataReference() const;
/** /**
* Get the current print mode.
*
* Return values less than or equal to zero indicate the current mode is the draw mode.
* Return values greater than zero indicate print mode.
* @return the printing mode. * @return the printing mode.
* if return <= 0, the current mode is not a printing mode, just the draw mode
*/ */
int GetPrintMode() { return m_printMode; } int GetPrintMode() { return m_printMode; }
/** /**
* Set the printing mode. * Set the printing mode.
* @param aPrintMode is the printing mode. *
* If 0, the current mode is not a printing mode, just the draw mode * @param aPrintMode is the printing mode. If 0, the current mode is not a printing mode,
* just the draw mode
*/ */
void SetPrintMode( int aPrintMode ) { m_printMode = aPrintMode; } void SetPrintMode( int aPrintMode ) { m_printMode = aPrintMode; }
static constexpr int VIEW_MAX_LAYERS = 512; ///< maximum number of layers that may be shown static constexpr int VIEW_MAX_LAYERS = 512; ///< maximum number of layers that may be shown
protected: protected:
struct VIEW_LAYER struct VIEW_LAYER
{ {
bool visible; ///< is the layer to be rendered? bool visible; ///< Is the layer to be rendered?
bool displayOnly; ///< is the layer display only? bool displayOnly; ///< Is the layer display only?
std::shared_ptr<VIEW_RTREE> items; ///< R-tree indexing all items on this layer. std::shared_ptr<VIEW_RTREE> items; ///< R-tree indexing all items on this layer.
int renderingOrder; ///< rendering order of this layer int renderingOrder; ///< Rendering order of this layer.
int id; ///< layer ID int id; ///< Layer ID.
RENDER_TARGET target; ///< where the layer should be rendered RENDER_TARGET target; ///< Where the layer should be rendered.
std::set<int> requiredLayers; ///< layers that have to be enabled to show the layer std::set<int> requiredLayers; ///< Layers that have to be enabled to show
///< the layer.
}; };
VIEW( const VIEW& ) = delete;
///* Redraws contents within rect aRect
void redrawRect( const BOX2I& aRect );
inline void markTargetClean( int aTarget )
{
wxCHECK( aTarget < TARGETS_NUMBER, /* void */ );
m_dirtyTargets[aTarget] = false;
}
/**
* Draw an item, but on a specified layers.
*
* It has to be marked that some of drawing settings are based on the layer on which
* an item is drawn.
*
* @param aItem is the item to be drawn.
* @param aLayer is the layer which should be drawn.
* @param aImmediate dictates the way of drawing - it allows one to force immediate
* drawing mode for cached items.
*/
void draw( VIEW_ITEM* aItem, int aLayer, bool aImmediate = false );
/**
* Draw an item on all layers that the item uses.
*
* @param aItem is the item to be drawn.
* @param aImmediate dictates the way of drawing - it allows one to force immediate
* drawing mode for cached items.
*/
void draw( VIEW_ITEM* aItem, bool aImmediate = false );
/**
* Draw a group of items on all layers that those items use.
*
* @param aGroup is the group to be drawn.
* @param aImmediate dictates the way of drawing - it allows one to force immediate
* drawing mode for cached items.
*/
void draw( VIEW_GROUP* aGroup, bool aImmediate = false );
///< Sort m_orderedLayers when layer rendering order has changed
void sortLayers();
///< Clear cached GAL group numbers (*ONLY* numbers stored in VIEW_ITEMs, not group objects
///< used by GAL)
void clearGroupCache();
/**
* Manage dirty flags & redraw queuing when updating an item.
*
* @param aItem is the item to be updated.
* @param aUpdateFlags determines the way an item is refreshed.
*/
void invalidateItem( VIEW_ITEM* aItem, int aUpdateFlags );
///< Update colors that are used for an item to be drawn
void updateItemColor( VIEW_ITEM* aItem, int aLayer );
///< Update all information needed to draw an item
void updateItemGeometry( VIEW_ITEM* aItem, int aLayer );
///< Update bounding box of an item
void updateBbox( VIEW_ITEM* aItem );
///< Update set of layers that an item occupies
void updateLayers( VIEW_ITEM* aItem );
///< Determine rendering order of layers. Used in display order sorting function.
static bool compareRenderingOrder( VIEW_LAYER* aI, VIEW_LAYER* aJ )
{
return aI->renderingOrder > aJ->renderingOrder;
}
///< Check if every layer required by the aLayerId layer is enabled.
bool areRequiredLayersEnabled( int aLayerId ) const;
// Function objects that need to access VIEW/VIEW_ITEM private/protected members // Function objects that need to access VIEW/VIEW_ITEM private/protected members
struct clearLayerCache; struct clearLayerCache;
struct recacheItem; struct recacheItem;
@ -717,150 +800,70 @@ protected:
std::unique_ptr<KIGFX::VIEW_GROUP> m_preview; std::unique_ptr<KIGFX::VIEW_GROUP> m_preview;
std::vector<EDA_ITEM *> m_ownedItems; std::vector<EDA_ITEM *> m_ownedItems;
///* Redraws contents within rect aRect ///< Whether to use rendering order modifier or not.
void redrawRect( const BOX2I& aRect );
inline void markTargetClean( int aTarget )
{
wxCHECK( aTarget < TARGETS_NUMBER, /* void */ );
m_dirtyTargets[aTarget] = false;
}
/**
* Function draw()
* Draws an item, but on a specified layers. It has to be marked that some of drawing settings
* are based on the layer on which an item is drawn.
*
* @param aItem is the item to be drawn.
* @param aLayer is the layer which should be drawn.
* @param aImmediate dictates the way of drawing - it allows one to force
* immediate drawing mode for cached items.
*/
void draw( VIEW_ITEM* aItem, int aLayer, bool aImmediate = false );
/**
* Function draw()
* Draws an item on all layers that the item uses.
*
* @param aItem is the item to be drawn.
* @param aImmediate dictates the way of drawing - it allows one to force
* immediate drawing mode for cached items.
*/
void draw( VIEW_ITEM* aItem, bool aImmediate = false );
/**
* Function draw()
* Draws a group of items on all layers that those items use.
*
* @param aGroup is the group to be drawn.
* @param aImmediate dictates the way of drawing - it allows one to force
* immediate drawing mode for cached items.
*/
void draw( VIEW_GROUP* aGroup, bool aImmediate = false );
///* Sorts m_orderedLayers when layer rendering order has changed
void sortLayers();
///* Clears cached GAL group numbers (*ONLY* numbers stored in VIEW_ITEMs, not group objects
///* used by GAL)
void clearGroupCache();
/**
* Function invalidateItem()
* Manages dirty flags & redraw queueing when updating an item.
* @param aItem is the item to be updated.
* @param aUpdateFlags determines the way an item is refreshed.
*/
void invalidateItem( VIEW_ITEM* aItem, int aUpdateFlags );
/// Updates colors that are used for an item to be drawn
void updateItemColor( VIEW_ITEM* aItem, int aLayer );
/// Updates all informations needed to draw an item
void updateItemGeometry( VIEW_ITEM* aItem, int aLayer );
/// Updates bounding box of an item
void updateBbox( VIEW_ITEM* aItem );
/// Updates set of layers that an item occupies
void updateLayers( VIEW_ITEM* aItem );
/// Determines rendering order of layers. Used in display order sorting function.
static bool compareRenderingOrder( VIEW_LAYER* aI, VIEW_LAYER* aJ )
{
return aI->renderingOrder > aJ->renderingOrder;
}
/// Checks if every layer required by the aLayerId layer is enabled.
bool areRequiredLayersEnabled( int aLayerId ) const;
///* Whether to use rendering order modifier or not
bool m_enableOrderModifier; bool m_enableOrderModifier;
/// Contains set of possible displayed layers and its properties ///< The set of possible displayed layers and its properties.
std::vector<VIEW_LAYER> m_layers; std::vector<VIEW_LAYER> m_layers;
/// Sorted list of pointers to members of m_layers ///< Sorted list of pointers to members of m_layers.
std::vector<VIEW_LAYER*> m_orderedLayers; std::vector<VIEW_LAYER*> m_orderedLayers;
/// Flat list of all items ///< Flat list of all items.
std::shared_ptr<std::vector<VIEW_ITEM*>> m_allItems; std::shared_ptr<std::vector<VIEW_ITEM*>> m_allItems;
/// Stores set of layers that are displayed on the top ///< The set of layers that are displayed on the top.
std::set<unsigned int> m_topLayers; std::set<unsigned int> m_topLayers;
/// Center point of the VIEW (the point at which we are looking at) ///< Center point of the VIEW (the point at which we are looking at).
VECTOR2D m_center; VECTOR2D m_center;
/// Scale of displayed VIEW_ITEMs ///< Scale of displayed VIEW_ITEMs.
double m_scale; double m_scale;
/// View boundaries ///< View boundaries.
BOX2D m_boundary; BOX2D m_boundary;
/// Scale lower limit ///< Scale lower limit.
double m_minScale; double m_minScale;
/// Scale upper limit ///< Scale upper limit.
double m_maxScale; double m_maxScale;
///> Horizontal flip flag ///< Horizontal flip flag.
bool m_mirrorX; bool m_mirrorX;
///> Vertical flip flag ///< Vertical flip flag.
bool m_mirrorY; bool m_mirrorY;
/// PAINTER contains information how do draw items ///< PAINTER contains information how do draw items.
PAINTER* m_painter; PAINTER* m_painter;
/// Gives interface to PAINTER, that is used to draw items ///< Interface to #PAINTER that is used to draw items.
GAL* m_gal; GAL* m_gal;
/// Dynamic VIEW (eg. display PCB in window) allows changes once it is built, ///< Dynamic VIEW (eg. display PCB in window) allows changes once it is built,
/// static (eg. image/PDF) - does not. ///< static (eg. image/PDF) - does not.
bool m_dynamic; bool m_dynamic;
/// Flags to mark targets as dirty, so they have to be redrawn on the next refresh event ///< Flag to mark targets as dirty so they have to be redrawn on the next refresh event.
bool m_dirtyTargets[TARGETS_NUMBER]; bool m_dirtyTargets[TARGETS_NUMBER];
/// Rendering order modifier for layers that are marked as top layers ///< Rendering order modifier for layers that are marked as top layers.
static const int TOP_LAYER_MODIFIER; static const int TOP_LAYER_MODIFIER;
/// Flat list of all items ///< Flag to respect draw priority when drawing items.
/// Flag to respect draw priority when drawing items
bool m_useDrawPriority; bool m_useDrawPriority;
/// The next sequential drawing priority ///< The next sequential drawing priority.
int m_nextDrawPriority; int m_nextDrawPriority;
/// Flag to reverse the draw order when using draw priority ///< Flag to reverse the draw order when using draw priority.
bool m_reverseDrawOrder; bool m_reverseDrawOrder;
/// A control for printing: m_printMode <= 0 means no printing mode (normal draw mode ///< A control for printing: m_printMode <= 0 means no printing mode (normal draw mode
/// m_printMode > 0 is a printing mode (currently means "we are in printing mode") ///< m_printMode > 0 is a printing mode (currently means "we are in printing mode").
int m_printMode; int m_printMode;
VIEW( const VIEW& ) = delete;
}; };
} // namespace KIGFX } // namespace KIGFX

View File

@ -3,7 +3,7 @@
* *
* Copyright (C) 2012 Torsten Hueter, torstenhtr <at> gmx.de * Copyright (C) 2012 Torsten Hueter, torstenhtr <at> gmx.de
* Copyright (C) 2013 CERN * Copyright (C) 2013 CERN
* Copyright (C) 2013-2019 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 2013-2020 KiCad Developers, see AUTHORS.txt for contributors.
* *
* @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch> * @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
* *
@ -41,7 +41,7 @@ namespace KIGFX
class VIEW; class VIEW;
///> Action to perform when the mouse is dragged ///< Action to perform when the mouse is dragged
enum class MOUSE_DRAG_ACTION enum class MOUSE_DRAG_ACTION
{ {
SELECT, SELECT,
@ -51,7 +51,7 @@ enum class MOUSE_DRAG_ACTION
}; };
///> Structure to keep VIEW_CONTROLS settings for easy store/restore operations ///< Structure to keep VIEW_CONTROLS settings for easy store/restore operations
struct VC_SETTINGS struct VC_SETTINGS
{ {
VC_SETTINGS() VC_SETTINGS()
@ -59,87 +59,86 @@ struct VC_SETTINGS
Reset(); Reset();
} }
///> Restores the default settings ///< Restore the default settings.
void Reset(); void Reset();
///> Flag determining the cursor visibility ///< Flag determining the cursor visibility.
bool m_showCursor; bool m_showCursor;
///> Forced cursor position (world coordinates) ///< Forced cursor position (world coordinates).
VECTOR2D m_forcedPosition; VECTOR2D m_forcedPosition;
///> Is the forced cursor position enabled ///< Is the forced cursor position enabled.
bool m_forceCursorPosition; bool m_forceCursorPosition;
///> Should the cursor be locked within the parent window area ///< Should the cursor be locked within the parent window area.
bool m_cursorCaptured; bool m_cursorCaptured;
///> Should the cursor snap to grid or move freely ///< Should the cursor snap to grid or move freely.
bool m_snappingEnabled; bool m_snappingEnabled;
///> Flag for grabbing the mouse cursor ///< Flag for grabbing the mouse cursor.
bool m_grabMouse; bool m_grabMouse;
///> Flag for turning on autopanning ///< Flag for turning on autopanning.
bool m_autoPanEnabled; bool m_autoPanEnabled;
///> Flag for turning on autopanning ///< Flag for turning on autopanning.
bool m_autoPanSettingEnabled; bool m_autoPanSettingEnabled;
///> Distance from cursor to VIEW edge when panning is active ///< Distance from cursor to VIEW edge when panning is active.
float m_autoPanMargin; float m_autoPanMargin;
///> How fast is panning when in auto mode ///< How fast is panning when in auto mode.
float m_autoPanSpeed; float m_autoPanSpeed;
///> How fast does panning accelerate when approaching the window boundary ///< How fast does panning accelerate when approaching the window boundary.
float m_autoPanAcceleration; float m_autoPanAcceleration;
///> If the cursor is allowed to be warped ///< If the cursor is allowed to be warped.
bool m_warpCursor; bool m_warpCursor;
///> Enable horizontal panning with the horizontal scroll/trackpad input ///< Enable horizontal panning with the horizontal scroll/trackpad input.
bool m_horizontalPan; bool m_horizontalPan;
///> Enable the accelerating zoom controller ///< Enable the accelerating zoom controller.
bool m_zoomAcceleration; bool m_zoomAcceleration;
///> Zoom speed for the non-accelerating zoom controller ///< Zoom speed for the non-accelerating zoom controller.
int m_zoomSpeed; int m_zoomSpeed;
///> When true, ignore zoom_speed and pick a platform-specific default ///< When true, ignore zoom_speed and pick a platform-specific default.
bool m_zoomSpeedAuto; bool m_zoomSpeedAuto;
///> What modifier key to enable zoom with the (vertical) scroll wheel ///< What modifier key to enable zoom with the (vertical) scroll wheel.
int m_scrollModifierZoom; int m_scrollModifierZoom;
///> What modifier key to enable horizontal pan with the (vertical) scroll wheel ///< What modifier key to enable horizontal pan with the (vertical) scroll wheel.
int m_scrollModifierPanH; int m_scrollModifierPanH;
///> What modifier key to enable vertical with the (vertical) scroll wheel ///< What modifier key to enable vertical with the (vertical) scroll wheel.
int m_scrollModifierPanV; int m_scrollModifierPanV;
///> What drag action to perform when the middle button is pressed ///< What drag action to perform when the middle button is pressed.
MOUSE_DRAG_ACTION m_dragMiddle; MOUSE_DRAG_ACTION m_dragMiddle;
///> What drag action to perform when the right button is pressed ///< What drag action to perform when the right button is pressed.
MOUSE_DRAG_ACTION m_dragRight; MOUSE_DRAG_ACTION m_dragRight;
///> Is last cursor motion event coming from keyboard arrow cursor motion action ///< Is last cursor motion event coming from keyboard arrow cursor motion action.
bool m_lastKeyboardCursorPositionValid; bool m_lastKeyboardCursorPositionValid;
///> ACTIONS::CURSOR_UP, ACTIONS::CURSOR_DOWN, etc. ///< ACTIONS::CURSOR_UP, ACTIONS::CURSOR_DOWN, etc.
long m_lastKeyboardCursorCommand; long m_lastKeyboardCursorCommand;
///> Position of the above event ///< Position of the above event.
VECTOR2D m_lastKeyboardCursorPosition; VECTOR2D m_lastKeyboardCursorPosition;
}; };
/** /**
* VIEW_CONTROLS * An interface for classes handling user events controlling the view behavior such as
* is an interface for classes handling user events controlling the view behaviour * zooming, panning, mouse grab, etc.
* (such as zooming, panning, mouse grab, etc.)
*/ */
class VIEW_CONTROLS class VIEW_CONTROLS
{ {
@ -154,8 +153,9 @@ public:
} }
/** /**
* Function SetGrabMouse * Turn on/off mouse grabbing.
* Turns on/off mouse grabbing. When the mouse is grabbed, it cannot go outside the VIEW. * When the mouse is grabbed, it cannot go outside the VIEW.
*
* @param aEnabled tells if mouse should be grabbed or not. * @param aEnabled tells if mouse should be grabbed or not.
*/ */
virtual void SetGrabMouse( bool aEnabled ) virtual void SetGrabMouse( bool aEnabled )
@ -164,9 +164,9 @@ public:
} }
/** /**
* Function SetAutoPan * Turn on/off auto panning (this feature is used when there is a tool active (eg. drawing a
* Turns on/off auto panning (this feature is used when there is a tool active (eg. drawing a
* track) and user moves mouse to the VIEW edge - then the view can be translated or not). * track) and user moves mouse to the VIEW edge - then the view can be translated or not).
*
* @param aEnabled tells if the autopanning should be active. * @param aEnabled tells if the autopanning should be active.
*/ */
virtual void SetAutoPan( bool aEnabled ) virtual void SetAutoPan( bool aEnabled )
@ -175,8 +175,8 @@ public:
} }
/** /**
* Function EnableAutoPan * Turn on/off auto panning (user setting to disable it entirely).
* Turns on/off auto panning (user setting to disable it entirely). *
* @param aEnabled tells if the autopanning should be enabled. * @param aEnabled tells if the autopanning should be enabled.
*/ */
virtual void EnableAutoPan( bool aEnabled ) virtual void EnableAutoPan( bool aEnabled )
@ -185,8 +185,8 @@ public:
} }
/** /**
* Function SetAutoPanSpeed() * Set the speed of autopanning.
* Sets speed of autopanning. *
* @param aSpeed is a new speed for autopanning. * @param aSpeed is a new speed for autopanning.
*/ */
virtual void SetAutoPanSpeed( float aSpeed ) virtual void SetAutoPanSpeed( float aSpeed )
@ -195,8 +195,8 @@ public:
} }
/** /**
* Function SetAutoPanSpeed() * Set the speed of autopanning.
* Sets speed of autopanning. *
* @param aSpeed is a new speed for autopanning. * @param aSpeed is a new speed for autopanning.
*/ */
virtual void SetAutoPanAcceleration( float aAcceleration ) virtual void SetAutoPanAcceleration( float aAcceleration )
@ -205,8 +205,8 @@ public:
} }
/** /**
* Function SetAutoPanMArgin() * Set the margin for autopanning (ie. the area when autopanning becomes active).
* Sets margin for autopanning (ie. the area when autopanning becomes active). *
* @param aMargin is a new margin for autopanning. * @param aMargin is a new margin for autopanning.
*/ */
virtual void SetAutoPanMargin( float aMargin ) virtual void SetAutoPanMargin( float aMargin )
@ -215,20 +215,22 @@ public:
} }
/** /**
* Function GetMousePosition() * Return the current mouse pointer position.
* Returns the current mouse pointer position. Note, that it may be *
* different from the cursor position if snapping is enabled (@see GetCursorPosition()). * @note The position may be different from the cursor position if snapping is
* enabled (@see GetCursorPosition()).
* *
* @param aWorldCoordinates if true, the result is given in world coordinates, otherwise * @param aWorldCoordinates if true, the result is given in world coordinates, otherwise
* it is given in screen coordinates. * it is given in screen coordinates.
* @return The current mouse pointer position in either world or screen coordinates. * @return The current mouse pointer position in either world or screen coordinates.
*/ */
virtual VECTOR2D GetMousePosition( bool aWorldCoordinates = true ) const = 0; virtual VECTOR2D GetMousePosition( bool aWorldCoordinates = true ) const = 0;
/** /**
* Returns the current cursor position in world coordinates. Note, that it may be * Return the current cursor position in world coordinates.
* different from the mouse pointer position if snapping is enabled or cursor position *
* is forced to a specific point. * @note The position may be different from the mouse pointer position if snapping is
* enabled or cursor position is forced to a specific point.
* *
* @return The current cursor position in world coordinates. * @return The current cursor position in world coordinates.
*/ */
@ -238,7 +240,7 @@ public:
} }
/** /**
* Returns the current cursor position in world coordinates - ingoring the cursorUp * Return the current cursor position in world coordinates ignoring the cursorUp
* position force mode. * position force mode.
* *
* @return The current cursor position in world coordinates. * @return The current cursor position in world coordinates.
@ -246,9 +248,10 @@ public:
virtual VECTOR2D GetRawCursorPosition( bool aSnappingEnabled = true ) const = 0; virtual VECTOR2D GetRawCursorPosition( bool aSnappingEnabled = true ) const = 0;
/** /**
* Returns the current cursor position in world coordinates. Note, that it may be * Return the current cursor position in world coordinates.
* different from the mouse pointer position if snapping is enabled or cursor position *
* is forced to a specific point. * @note The position may be different from the mouse pointer position if snapping is
* enabled or cursor position is forced to a specific point.
* *
* @param aEnableSnapping selects whether cursor position should be snapped to the grid. * @param aEnableSnapping selects whether cursor position should be snapped to the grid.
* @return The current cursor position in world coordinates. * @return The current cursor position in world coordinates.
@ -256,8 +259,8 @@ public:
virtual VECTOR2D GetCursorPosition( bool aEnableSnapping ) const = 0; virtual VECTOR2D GetCursorPosition( bool aEnableSnapping ) const = 0;
/** /**
* Function ForceCursorPosition() * Place the cursor immediately at a given point. Mouse movement is ignored.
* Places the cursor immediately at a given point. Mouse movement is ignored. *
* @param aEnabled enable forced cursor position * @param aEnabled enable forced cursor position
* @param aPosition the position (world coordinates). * @param aPosition the position (world coordinates).
*/ */
@ -268,9 +271,11 @@ public:
} }
/** /**
* Moves cursor to the requested position expressed in world coordinates. The position is not * Move cursor to the requested position expressed in world coordinates.
* forced and will be overridden with the next mouse motion event. Mouse cursor follows the *
* world cursor. * The position is not forced and will be overridden with the next mouse motion event.
* Mouse cursor follows the world cursor.
*
* @param aPosition is the requested cursor position in the world coordinates. * @param aPosition is the requested cursor position in the world coordinates.
* @param aWarpView enables/disables view warp if the cursor is outside the current viewport. * @param aWarpView enables/disables view warp if the cursor is outside the current viewport.
*/ */
@ -279,16 +284,15 @@ public:
/** /**
* Moves the graphic crosshair cursor to the requested position expressed in world coordinates. * Move the graphic crosshair cursor to the requested position expressed in world coordinates.
*
* @param aPosition is the requested cursor position in the world coordinates. * @param aPosition is the requested cursor position in the world coordinates.
* @param aWarpView enables/disables view warp if the cursor is outside the current viewport. * @param aWarpView enables/disables view warp if the cursor is outside the current viewport.
*/ */
virtual void SetCrossHairCursorPosition( const VECTOR2D& aPosition, bool aWarpView = true ) = 0; virtual void SetCrossHairCursorPosition( const VECTOR2D& aPosition, bool aWarpView = true ) = 0;
/** /**
* Function ForcedCursorPosition() * Return true if the current cursor position is forced to a specific location, ignoring
* Returns true if the current cursor position is forced to a specific location, ignoring
* the mouse cursor position. * the mouse cursor position.
*/ */
bool ForcedCursorPosition() const bool ForcedCursorPosition() const
@ -297,22 +301,22 @@ public:
} }
/** /**
* Function ShowCursor() * Enable or disables display of cursor.
* Enables or disables display of cursor. *
* @param aEnabled decides if the cursor should be shown. * @param aEnabled decides if the cursor should be shown.
*/ */
virtual void ShowCursor( bool aEnabled ); virtual void ShowCursor( bool aEnabled );
/** /**
* Function IsCursorShown() * Return true when cursor is visible.
* Returns true when cursor is visible. *
* @return True if cursor is visible. * @return True if cursor is visible.
*/ */
bool IsCursorShown() const; bool IsCursorShown() const;
/** /**
* Function CaptureCursor() * Force the cursor to stay within the drawing panel area.
* Forces the cursor to stay within the drawing panel area. *
* @param aEnabled determines if the cursor should be captured. * @param aEnabled determines if the cursor should be captured.
*/ */
virtual void CaptureCursor( bool aEnabled ) virtual void CaptureCursor( bool aEnabled )
@ -321,9 +325,9 @@ public:
} }
/** /**
* Function IsCursorPositionForced() * Return true if the cursor position is set by one of the tools.
* Returns true if the cursor position is set by one of the tools. Forced cursor position *
* means it does not react to mouse movement. * A forced cursor position means it does not react to mouse movement.
*/ */
inline bool IsCursorPositionForced() const inline bool IsCursorPositionForced() const
{ {
@ -331,21 +335,22 @@ public:
} }
/** /**
* Function WarpCursor()
* If enabled (@see SetEnableCursorWarping(), warps the cursor to the specified position, * If enabled (@see SetEnableCursorWarping(), warps the cursor to the specified position,
* expressed either in the screen coordinates or the world coordinates. * expressed either in the screen coordinates or the world coordinates.
*
* @param aPosition is the position where the cursor should be warped. * @param aPosition is the position where the cursor should be warped.
* @param aWorldCoordinates if true treats aPosition as the world coordinates, otherwise it * @param aWorldCoordinates if true treats aPosition as the world coordinates, otherwise it
* uses it as the screen coordinates. * uses it as the screen coordinates.
* @param aWarpView determines if the view can be warped too (only matters if the position is * @param aWarpView determines if the view can be warped too (only matters if the position is
* specified in the world coordinates and its not visible in the current viewport). * specified in the world coordinates and its not visible in the current
* viewport).
*/ */
virtual void WarpCursor( const VECTOR2D& aPosition, bool aWorldCoordinates = false, virtual void WarpCursor( const VECTOR2D& aPosition, bool aWorldCoordinates = false,
bool aWarpView = false ) = 0; bool aWarpView = false ) = 0;
/** /**
* Function EnableCursorWarping() * Enable or disable warping the cursor.
* Enables or disables warping the cursor. *
* @param aEnable is true if the cursor is allowed to be warped. * @param aEnable is true if the cursor is allowed to be warped.
*/ */
void EnableCursorWarping( bool aEnable ) void EnableCursorWarping( bool aEnable )
@ -354,7 +359,6 @@ public:
} }
/** /**
* Function IsCursorWarpingEnabled()
* @return the current setting for cursor warping. * @return the current setting for cursor warping.
*/ */
bool IsCursorWarpingEnabled() const bool IsCursorWarpingEnabled() const
@ -363,38 +367,36 @@ public:
} }
/** /**
* Function CenterOnCursor() * Set the viewport center to the current cursor position and warps the cursor to the
* Sets the viewport center to the current cursor position and warps the cursor to the
* screen center. * screen center.
*/ */
virtual void CenterOnCursor() const = 0; virtual void CenterOnCursor() const = 0;
/** /**
* Function Reset() * Restore the default VIEW_CONTROLS settings.
* Restores the default VIEW_CONTROLS settings.
*/ */
virtual void Reset(); virtual void Reset();
///> Returns the current VIEW_CONTROLS settings ///< Return the current VIEW_CONTROLS settings.
const VC_SETTINGS& GetSettings() const const VC_SETTINGS& GetSettings() const
{ {
return m_settings; return m_settings;
} }
///> Applies VIEW_CONTROLS settings from an object ///< Apply VIEW_CONTROLS settings from an object.
void ApplySettings( const VC_SETTINGS& aSettings ); void ApplySettings( const VC_SETTINGS& aSettings );
///> Load new settings from program common settings ///< Load new settings from program common settings.
virtual void LoadSettings() {} virtual void LoadSettings() {}
protected: protected:
///> Pointer to controlled VIEW. ///< Pointer to controlled VIEW.
VIEW* m_view; VIEW* m_view;
///> Application warped the cursor, not the user (keyboard) ///< Application warped the cursor, not the user (keyboard).
bool m_cursorWarped; bool m_cursorWarped;
///> Current VIEW_CONTROLS settings ///< Current VIEW_CONTROLS settings.
VC_SETTINGS m_settings; VC_SETTINGS m_settings;
}; };
} // namespace KIGFX } // namespace KIGFX

View File

@ -2,6 +2,8 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2013 CERN * Copyright (C) 2013 CERN
* Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors.
*
* @author Maciej Suminski <maciej.suminski@cern.ch> * @author Maciej Suminski <maciej.suminski@cern.ch>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
@ -25,9 +27,6 @@
/** /**
* @file view_group.h * @file view_group.h
* @brief VIEW_GROUP extends VIEW_ITEM by possibility of grouping items into a single object.
* VIEW_GROUP does not take over ownership of the held items. The main purpose of this class is
* to group items and draw them on a single layer (in particular the overlay).
*/ */
#ifndef VIEW_GROUP_H_ #ifndef VIEW_GROUP_H_
@ -38,59 +37,55 @@
namespace KIGFX namespace KIGFX
{ {
/**
* Extend #VIEW_ITEM by possibility of grouping items into a single object.
*
* VIEW_GROUP does not take over ownership of the held items. The main purpose of this class is
* to group items and draw them on a single layer (in particular the overlay).
*/
class VIEW_GROUP : public VIEW_ITEM class VIEW_GROUP : public VIEW_ITEM
{ {
protected:
typedef std::vector<VIEW_ITEM*> ITEMS;
public: public:
VIEW_GROUP( VIEW* aView = NULL ); VIEW_GROUP( VIEW* aView = NULL );
virtual ~VIEW_GROUP(); virtual ~VIEW_GROUP();
/** /**
* Function GetSize() * Return the number of stored items.
* Returns the number of stored items.
* *
* @return Number of stored items. * @return Number of stored items.
*/ */
virtual unsigned int GetSize() const; virtual unsigned int GetSize() const;
/** /**
* Function Add() * Add an item to the group.
* Adds an item to the group.
* *
* @param aItem is the item to be added. * @param aItem is the item to be added.
*/ */
virtual void Add( VIEW_ITEM* aItem ); virtual void Add( VIEW_ITEM* aItem );
/** /**
* Function Remove() * Remove an item from the group.
* Removes an item from the group.
* *
* @param aItem is the item to be removed. * @param aItem is the item to be removed.
*/ */
virtual void Remove( VIEW_ITEM* aItem ); virtual void Remove( VIEW_ITEM* aItem );
/** /**
* Function Clear() * Remove all the stored items from the group.
* Removes all the stored items from the group.
*/ */
virtual void Clear(); virtual void Clear();
virtual VIEW_ITEM* GetItem( unsigned int aIdx ) const; virtual VIEW_ITEM* GetItem( unsigned int aIdx ) const;
/** /**
* Function ViewBBox() * Return the bounding box for all stored items covering all its layers.
* Returns the bounding box for all stored items covering all its layers.
* *
* @return The current bounding box * @return The current bounding box
*/ */
virtual const BOX2I ViewBBox() const override; virtual const BOX2I ViewBBox() const override;
/** /**
* Function ViewDraw() * Draw all the stored items in the group on the given layer.
* Draws all the stored items in the group on the given layer.
* *
* @param aLayer is the layer which should be drawn. * @param aLayer is the layer which should be drawn.
* @param aView is the VIEW that should be used for drawing. * @param aView is the VIEW that should be used for drawing.
@ -98,8 +93,7 @@ public:
virtual void ViewDraw( int aLayer, VIEW* aView ) const override; virtual void ViewDraw( int aLayer, VIEW* aView ) const override;
/** /**
* Function ViewGetLayers() * Return all the layers used by the stored items.
* Returns all the layers used by the stored items.
* *
* @param aLayers[] is the output layer index array. * @param aLayers[] is the output layer index array.
* @param aCount is the number of layer indices in aLayers[]. * @param aCount is the number of layer indices in aLayers[].
@ -107,8 +101,7 @@ public:
virtual void ViewGetLayers( int aLayers[], int& aCount ) const override; virtual void ViewGetLayers( int aLayers[], int& aCount ) const override;
/** /**
* Function SetLayer() * Set layer used to draw the group.
* Sets layer used to draw the group.
* *
* @param aLayer is the layer used for drawing. * @param aLayer is the layer used for drawing.
*/ */
@ -118,20 +111,19 @@ public:
} }
/** /**
* Function FreeItems() * Free all the items that were added to the group.
* Frees all the items that were added to the group.
*/ */
void FreeItems(); void FreeItems();
protected: protected:
typedef std::vector<VIEW_ITEM*> ITEMS;
virtual const ITEMS updateDrawList() const; virtual const ITEMS updateDrawList() const;
/// Layer on which the group is drawn ///< Layer on which the group is drawn.
int m_layer; int m_layer;
protected: ///< Container for storing VIEW_ITEMs.
/// Container for storing VIEW_ITEMs
ITEMS m_groupItems; ITEMS m_groupItems;
}; };

View File

@ -2,6 +2,8 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2013-2016 CERN * Copyright (C) 2013-2016 CERN
* Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors.
*
* @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch> * @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
@ -43,43 +45,37 @@ class VIEW;
class VIEW_ITEM_DATA; class VIEW_ITEM_DATA;
/** /**
* Enum VIEW_UPDATE_FLAGS. * Define the how severely the appearance of the item has been changed.
* Defines the how severely the shape/appearance of the item has been changed: */
* - NONE: TODO
* - APPEARANCE: shape or layer set of the item have not been affected,
* only colors or visibility.
* - COLOR:
* - GEOMETRY: shape or layer set of the item have changed, VIEW may need to reindex it.
* - LAYERS: TODO
* - ALL: all the flags above */
enum VIEW_UPDATE_FLAGS { enum VIEW_UPDATE_FLAGS {
NONE = 0x00, /// No updates are required NONE = 0x00, ///< No updates are required.
APPEARANCE = 0x01, /// Visibility flag has changed APPEARANCE = 0x01, ///< Visibility flag has changed.
COLOR = 0x02, /// Color has changed COLOR = 0x02, ///< Color has changed.
GEOMETRY = 0x04, /// Position or shape has changed GEOMETRY = 0x04, ///< Position or shape has changed.
LAYERS = 0x08, /// Layers have changed LAYERS = 0x08, ///< Layers have changed.
INITIAL_ADD = 0x10, /// Item is being added to the view INITIAL_ADD = 0x10, ///< Item is being added to the view.
REPAINT = 0x20, /// Item needs to be redrawn REPAINT = 0x20, ///< Item needs to be redrawn.
ALL = 0xef /// All except INITIAL_ADD ALL = 0xef ///< All except INITIAL_ADD.
}; };
/** /**
* Enum VIEW_VISIBILITY_FLAGS. * Define the visibility of the item (temporarily hidden, invisible, etc).
* Defines the visibility of the item (temporarily hidden, invisible, etc).
*/ */
enum VIEW_VISIBILITY_FLAGS { enum VIEW_VISIBILITY_FLAGS {
VISIBLE = 0x01, /// Item is visible (in general) VISIBLE = 0x01, ///< Item is visible (in general)
HIDDEN = 0x02 /// Item is temporarily hidden (e.g. being used by a tool). Overrides VISIBLE flag. HIDDEN = 0x02 ///< Item is temporarily hidden (e.g. being used by a tool).
///< Overrides VISIBLE flag.
}; };
/** /**
* VIEW_ITEM - * An abstract base class for deriving all objects that can be added to a VIEW.
* is an abstract base class for deriving all objects that can be added to a VIEW. *
* It's role is to: * It's role is to:
* - communicte geometry, appearance and visibility updates to the associated dynamic VIEW, * - communicate geometry, appearance and visibility updates to the associated dynamic VIEW,
* - provide a bounding box for redraw area calculation, * - provide a bounding box for redraw area calculation,
* - (optional) draw the object using the GAL API functions for PAINTER-less implementations. * - (optional) draw the object using the #GAL API functions for #PAINTER-less implementations.
* VIEW_ITEM objects are never owned by a VIEW. A single VIEW_ITEM can belong to any number of *
* VIEW_ITEM objects are never owned by a #VIEW. A single VIEW_ITEM can belong to any number of
* static VIEWs, but only one dynamic VIEW due to storage of only one VIEW reference. * static VIEWs, but only one dynamic VIEW due to storage of only one VIEW reference.
*/ */
class VIEW_ITEM : public INSPECTABLE class VIEW_ITEM : public INSPECTABLE
@ -95,48 +91,48 @@ public:
VIEW_ITEM& operator=( const VIEW_ITEM& aOther ) = delete; VIEW_ITEM& operator=( const VIEW_ITEM& aOther ) = delete;
/** /**
* Function ViewBBox() * Return the bounding box of the item covering all its layers.
* returns the bounding box of the item covering all its layers. *
* @return BOX2I - the current bounding box * @return the current bounding box.
*/ */
virtual const BOX2I ViewBBox() const = 0; virtual const BOX2I ViewBBox() const = 0;
/** /**
* Function ViewDraw() * Draw the parts of the object belonging to layer aLayer.
* Draws the parts of the object belonging to layer aLayer.
* viewDraw() is an alternative way for drawing objects if
* if there is no PAINTER assigned for the view or if the PAINTER
* doesn't know how to paint this particular implementation of
* VIEW_ITEM. The preferred way of drawing is to design an
* appropriate PAINTER object, the method below is intended only
* for quick hacks and debugging purposes.
* *
* @param aLayer: current drawing layer * An alternative way for drawing objects if there is no #PAINTER assigned for the view
* @param aView: pointer to the VIEW device we are drawing on * or if the PAINTER doesn't know how to paint this particular implementation of VIEW_ITEM.
* The preferred way of drawing is to design an appropriate PAINTER object, the method
* below is intended only for quick hacks and debugging purposes.
*
* @param aLayer is the current drawing layer.
* @param aView is a pointer to the #VIEW device we are drawing on.
*/ */
virtual void ViewDraw( int aLayer, VIEW* aView ) const virtual void ViewDraw( int aLayer, VIEW* aView ) const
{} {}
/** /**
* Function ViewGetLayers() * Return the all the layers within the VIEW the object is painted on.
* Returns the all the layers within the VIEW the object is painted on. For instance, a PAD *
* spans zero or more copper layers and a few technical layers. ViewDraw() or PAINTER::Draw() * For instance, a #PAD spans zero or more copper layers and a few technical layers.
* is repeatedly called for each of the layers returned by ViewGetLayers(), depending on the * ViewDraw() or PAINTER::Draw() is repeatedly called for each of the layers returned
* rendering order. * by ViewGetLayers(), depending on the rendering order.
* @param aLayers[]: output layer index array *
* @param aCount: number of layer indices in aLayers[] * @param aLayers[] is the output layer index array.
* @param aCount is the number of layer indices in aLayers[].
*/ */
virtual void ViewGetLayers( int aLayers[], int& aCount ) const = 0; virtual void ViewGetLayers( int aLayers[], int& aCount ) const = 0;
/** /**
* Function ViewGetLOD() * Return the level of detail (LOD) of the item.
* Returns the level of detail (LOD) of the item. *
* A level of detail is the minimal VIEW scale that * A level of detail is the minimal #VIEW scale that is sufficient for an item to be shown
* is sufficient for an item to be shown on a given layer. * on a given layer.
* @param aLayer: current drawing layer *
* @param aView: pointer to the VIEW device we are drawing on * @param aLayer is the current drawing layer.
* @return the level of detail. 0 always show the item, because the * @param aView is a pointer to the #VIEW device we are drawing on.
* actual zoom level (or VIEW scale) is always > 0 * @return the level of detail. 0 always show the item, because the actual zoom level
* (or VIEW scale) is always > 0
*/ */
virtual double ViewGetLOD( int aLayer, VIEW* aView ) const virtual double ViewGetLOD( int aLayer, VIEW* aView ) const
{ {
@ -144,8 +140,6 @@ public:
return 0.0; return 0.0;
} }
public:
VIEW_ITEM_DATA* viewPrivData() const VIEW_ITEM_DATA* viewPrivData() const
{ {
return m_viewPrivData; return m_viewPrivData;
@ -153,7 +147,7 @@ public:
void ClearViewPrivData() void ClearViewPrivData()
{ {
m_viewPrivData = NULL; m_viewPrivData = nullptr;
} }
private: private:

View File

@ -2,6 +2,8 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2013 CERN * Copyright (C) 2013 CERN
* Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors.
*
* @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch> * @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
@ -34,17 +36,15 @@ namespace KIGFX
typedef RTree<VIEW_ITEM*, int, 2, double> VIEW_RTREE_BASE; typedef RTree<VIEW_ITEM*, int, 2, double> VIEW_RTREE_BASE;
/** /**
* VIEW_RTREE - * Implement an non-owning R-tree for fast spatial indexing of VIEW items.
* Implements an R-tree for fast spatial indexing of VIEW items.
* Non-owning.
*/ */
class VIEW_RTREE : public VIEW_RTREE_BASE class VIEW_RTREE : public VIEW_RTREE_BASE
{ {
public: public:
/** /**
* Function Insert() * Insert an item into the tree.
* Inserts an item into the tree. Item's bounding box is taken via its ViewBBox() method. *
* Item's bounding box is taken via its ViewBBox() method.
*/ */
void Insert( VIEW_ITEM* aItem ) void Insert( VIEW_ITEM* aItem )
{ {
@ -56,9 +56,9 @@ public:
} }
/** /**
* Function Remove() * Remove an item from the tree.
* Removes an item from the tree. Removal is done by comparing pointers, attepmting to remove a copy *
* of the item will fail. * Removal is done by comparing pointers, attempting to remove a copy of the item will fail.
*/ */
void Remove( VIEW_ITEM* aItem ) void Remove( VIEW_ITEM* aItem )
{ {
@ -72,9 +72,8 @@ public:
} }
/** /**
* Function Query() * Execute a function object \a aVisitor for each item whose bounding box intersects
* Executes a function object aVisitor for each item whose bounding box intersects * with \a aBounds.
* with aBounds.
*/ */
template <class Visitor> template <class Visitor>
void Query( const BOX2I& aBounds, Visitor& aVisitor ) const void Query( const BOX2I& aBounds, Visitor& aVisitor ) const

View File

@ -3,6 +3,8 @@
* *
* Copyright (C) 2012 Torsten Hueter, torstenhtr <at> gmx.de * Copyright (C) 2012 Torsten Hueter, torstenhtr <at> gmx.de
* Copyright (C) 2013 CERN * Copyright (C) 2013 CERN
* Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors.
*
* @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch> * @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
@ -43,8 +45,7 @@ namespace KIGFX
class ZOOM_CONTROLLER; class ZOOM_CONTROLLER;
/** /**
* WX_VIEW_CONTROLS * An implementation of class #VIEW_CONTROLS for wxWidgets library.
* is a specific implementation of class VIEW_CONTROLS for wxWidgets library.
*/ */
class WX_VIEW_CONTROLS : public VIEW_CONTROLS, public wxEvtHandler class WX_VIEW_CONTROLS : public VIEW_CONTROLS, public wxEvtHandler
{ {
@ -65,120 +66,121 @@ public:
void onScroll( wxScrollWinEvent& aEvent ); void onScroll( wxScrollWinEvent& aEvent );
/** /**
* Function SetGrabMouse() * Enable or disable mouse cursor grabbing (limits the movement field only to the panel area).
* Enables/disables mouse cursor grabbing (limits the movement field only to the panel area).
* *
* @param aEnabled says whether the option should be enabled or disabled. * @param aEnabled says whether the option should be enabled or disabled.
*/ */
void SetGrabMouse( bool aEnabled ) override; void SetGrabMouse( bool aEnabled ) override;
/// @copydoc VIEW_CONTROLS::GetMousePosition() ///< @copydoc VIEW_CONTROLS::GetMousePosition()
VECTOR2D GetMousePosition( bool aWorldCoordinates = true ) const override; VECTOR2D GetMousePosition( bool aWorldCoordinates = true ) const override;
using VIEW_CONTROLS::GetCursorPosition; using VIEW_CONTROLS::GetCursorPosition;
/// @copydoc VIEW_CONTROLS::GetCursorPosition() ///< @copydoc VIEW_CONTROLS::GetCursorPosition()
VECTOR2D GetCursorPosition( bool aSnappingEnabled ) const override; VECTOR2D GetCursorPosition( bool aSnappingEnabled ) const override;
/// @copydoc VIEW_CONTROLS::GetRawCursorPosition() ///< @copydoc VIEW_CONTROLS::GetRawCursorPosition()
VECTOR2D GetRawCursorPosition( bool aSnappingEnabled = true ) const override; VECTOR2D GetRawCursorPosition( bool aSnappingEnabled = true ) const override;
void SetCursorPosition( const VECTOR2D& aPosition, bool warpView, void SetCursorPosition( const VECTOR2D& aPosition, bool warpView,
bool aTriggeredByArrows, long aArrowCommand ) override; bool aTriggeredByArrows, long aArrowCommand ) override;
/// @copydoc VIEW_CONTROLS::SetCrossHairCursorPosition() ///< @copydoc VIEW_CONTROLS::SetCrossHairCursorPosition()
void SetCrossHairCursorPosition( const VECTOR2D& aPosition, bool aWarpView ) override; void SetCrossHairCursorPosition( const VECTOR2D& aPosition, bool aWarpView ) override;
/// @copydoc VIEW_CONTROLS::CursorWarp() ///< @copydoc VIEW_CONTROLS::CursorWarp()
void WarpCursor( const VECTOR2D& aPosition, bool aWorldCoordinates = false, void WarpCursor( const VECTOR2D& aPosition, bool aWorldCoordinates = false,
bool aWarpView = false ) override; bool aWarpView = false ) override;
/// @copydoc VIEW_CONTROLS::CenterOnCursor() ///< @copydoc VIEW_CONTROLS::CenterOnCursor()
void CenterOnCursor() const override; void CenterOnCursor() const override;
/// Adjusts the scrollbars position to match the current viewport. ///< Adjusts the scrollbars position to match the current viewport.
void UpdateScrollbars(); void UpdateScrollbars();
void ForceCursorPosition( bool aEnabled, const VECTOR2D& aPosition = VECTOR2D( 0, 0 ) ) override; void ForceCursorPosition( bool aEnabled,
const VECTOR2D& aPosition = VECTOR2D( 0, 0 ) ) override;
///> Applies VIEW_CONTROLS settings from the program COMMON_SETTINGS ///< Applies VIEW_CONTROLS settings from the program COMMON_SETTINGS
void LoadSettings() override; void LoadSettings() override;
/// Event that forces mouse move event in the dispatcher (eg. used in autopanning, when mouse ///< Event that forces mouse move event in the dispatcher (eg. used in autopanning, when
/// cursor does not move in screen coordinates, but does in world coordinates) ///< mouse cursor does not move in screen coordinates, but does in world coordinates)
static const wxEventType EVT_REFRESH_MOUSE; static const wxEventType EVT_REFRESH_MOUSE;
private: private:
/// Possible states for WX_VIEW_CONTROLS ///< Possible states for WX_VIEW_CONTROLS.
enum STATE enum STATE
{ {
IDLE = 1, /// Nothing is happening IDLE = 1, ///< Nothing is happening.
DRAG_PANNING, /// Panning with mouse button pressed DRAG_PANNING, ///< Panning with mouse button pressed.
AUTO_PANNING, /// Panning on approaching borders of the frame AUTO_PANNING, ///< Panning on approaching borders of the frame.
DRAG_ZOOMING, /// Zooming with mouse button pressed DRAG_ZOOMING, ///< Zooming with mouse button pressed.
}; };
/** /**
* Function handleAutoPanning() * Compute new viewport settings while in autopanning mode.
* Computes new viewport settings while in autopanning mode.
* *
* @param aEvent is an event to be processed and decide if autopanning should happen. * @param aEvent is an event to be processed and decide if autopanning should happen.
* @return true if it is currently autopanning (ie. autopanning is active and mouse cursor * @return true if it is currently autopanning (ie. autopanning is active and mouse cursor
* is in the area that causes autopanning to happen). * is in the area that causes autopanning to happen).
*/ */
bool handleAutoPanning( const wxMouseEvent& aEvent ); bool handleAutoPanning( const wxMouseEvent& aEvent );
/** /**
* Sends an event to refresh mouse position. It is mostly used for notifying the tools * Send an event to refresh mouse position.
* that the cursor position in the world coordinates has changed, whereas the screen coordinates *
* remained the same (e.g. frame edge autopanning). * It is mostly used for notifying the tools that the cursor position in the world
* coordinates has changed, whereas the screen coordinates remained the same (e.g.
* frame edge autopanning).
*/ */
void refreshMouse(); void refreshMouse();
/** /**
* Gets the cursor position in the screen coordinates. * Get the cursor position in the screen coordinates.
*/ */
wxPoint getMouseScreenPosition() const; wxPoint getMouseScreenPosition() const;
/// Current state of VIEW_CONTROLS ///< Current state of VIEW_CONTROLS.
STATE m_state; STATE m_state;
/// Panel that is affected by VIEW_CONTROLS ///< Panel that is affected by VIEW_CONTROLS.
wxScrolledCanvas* m_parentPanel; wxScrolledCanvas* m_parentPanel;
/// Stores information about point where dragging has started ///< Store information about point where dragging has started.
VECTOR2D m_dragStartPoint; VECTOR2D m_dragStartPoint;
/// Stores information about the center of viewport when dragging has started ///< Stores information about the center of viewport when dragging has started.
VECTOR2D m_lookStartPoint; VECTOR2D m_lookStartPoint;
/// Current direction of panning (only autopanning mode) ///< Current direction of panning (only autopanning mode).
VECTOR2D m_panDirection; VECTOR2D m_panDirection;
/// Timer repsonsible for handling autopanning ///< Timer responsible for handling autopanning.
wxTimer m_panTimer; wxTimer m_panTimer;
/// Ratio used for scaling world coordinates to scrollbar position. ///< Ratio used for scaling world coordinates to scrollbar position.
VECTOR2D m_scrollScale; VECTOR2D m_scrollScale;
/// Current scrollbar position ///< Current scrollbar position.
VECTOR2I m_scrollPos; VECTOR2I m_scrollPos;
/// The zoom scale when a drag zoom started ///< The zoom scale when a drag zoom started.
double m_initialZoomScale; double m_initialZoomScale;
#ifdef __WXGTK3__ #ifdef __WXGTK3__
/// Last event timestamp used to de-bounce mouse wheel ///< Last event timestamp used to de-bounce mouse wheel.
long int m_lastTimestamp; long int m_lastTimestamp;
#endif #endif
/// Current cursor position (world coordinates) ///< Current cursor position (world coordinates).
VECTOR2D m_cursorPos; VECTOR2D m_cursorPos;
/// Flag deciding whether the cursor position should be calculated using the mouse position ///< Flag deciding whether the cursor position should be calculated using the mouse position.
bool m_updateCursor; bool m_updateCursor;
/// a ZOOM_CONTROLLER that determines zoom steps. This is platform-specific. ///< A #ZOOM_CONTROLLER that determines zoom steps. This is platform-specific.
std::unique_ptr<ZOOM_CONTROLLER> m_zoomController; std::unique_ptr<ZOOM_CONTROLLER> m_zoomController;
}; };
} // namespace KIGFX } // namespace KIGFX

View File

@ -1,7 +1,7 @@
/* /*
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2013-2018 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 2013-2020 KiCad Developers, see AUTHORS.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -37,7 +37,7 @@ namespace KIGFX
{ {
/** /**
* Class that handles the response of the zoom scale to external inputs * Handle the response of the zoom scale to external inputs.
*/ */
class ZOOM_CONTROLLER class ZOOM_CONTROLLER
{ {
@ -45,10 +45,11 @@ public:
virtual ~ZOOM_CONTROLLER() = default; virtual ~ZOOM_CONTROLLER() = default;
/** /**
* Gets the scale factor produced by a given mousewheel rotation * Get the scale factor produced by a given mousewheel rotation.
* @param aRotation rotation of the mouse wheel (this comes from *
* wxMouseEvent::GetWheelRotation()) * @param aRotation rotation of the mouse wheel (this comes from
* @return the scale factor to scroll by * wxMouseEvent::GetWheelRotation()).
* @return the scale factor to scroll by.
*/ */
virtual double GetScaleForRotation( int aRotation ) = 0; virtual double GetScaleForRotation( int aRotation ) = 0;
}; };
@ -60,23 +61,23 @@ public:
class ACCELERATING_ZOOM_CONTROLLER : public ZOOM_CONTROLLER class ACCELERATING_ZOOM_CONTROLLER : public ZOOM_CONTROLLER
{ {
public: public:
/// The type of the acceleration timeout ///< The type of the acceleration timeout.
using TIMEOUT = std::chrono::milliseconds; using TIMEOUT = std::chrono::milliseconds;
/// The clock used for the timestamp (guaranteed to be monotonic) ///< The clock used for the timestamp (guaranteed to be monotonic).
using CLOCK = std::chrono::steady_clock; using CLOCK = std::chrono::steady_clock;
/// The type of the time stamps ///< The type of the time stamps.
using TIME_PT = std::chrono::time_point<CLOCK>; using TIME_PT = std::chrono::time_point<CLOCK>;
/// The default timeout, after which a another scroll will not be accelerated ///< The default timeout, after which a another scroll will not be accelerated.
static constexpr TIMEOUT DEFAULT_TIMEOUT = std::chrono::milliseconds( 500 ); static constexpr TIMEOUT DEFAULT_TIMEOUT = std::chrono::milliseconds( 500 );
/// The default minimum step factor for accelerating controller ///< The default minimum step factor for accelerating controller.
static constexpr double DEFAULT_ACCELERATION_SCALE = 5.0; static constexpr double DEFAULT_ACCELERATION_SCALE = 5.0;
/* /*
* A class interface that provides timestamps for events * A class interface that provides timestamps for events.
*/ */
class TIMESTAMP_PROVIDER class TIMESTAMP_PROVIDER
{ {
@ -84,7 +85,7 @@ public:
virtual ~TIMESTAMP_PROVIDER() = default; virtual ~TIMESTAMP_PROVIDER() = default;
/* /*
* @return the timestamp at the current time * @return the timestamp at the current time.
*/ */
virtual TIME_PT GetTimestamp() = 0; virtual TIME_PT GetTimestamp() = 0;
}; };
@ -92,9 +93,9 @@ public:
/** /**
* @param aAccTimeout the timeout - if a scroll happens within this timeframe, * @param aAccTimeout the timeout - if a scroll happens within this timeframe,
* the zoom will be faster * the zoom will be faster
* @param aTimestampProv a provider for timestamps. If null, a default will * @param aTimestampProv a provider for timestamps. If null, a default will be provided,
* be provided, which is the main steady_clock (this is probably what you * which is the main steady_clock (this is probably what you want
* want for real usage) * for real usage)
*/ */
ACCELERATING_ZOOM_CONTROLLER( double aScale = DEFAULT_ACCELERATION_SCALE, ACCELERATING_ZOOM_CONTROLLER( double aScale = DEFAULT_ACCELERATION_SCALE,
const TIMEOUT& aAccTimeout = DEFAULT_TIMEOUT, const TIMEOUT& aAccTimeout = DEFAULT_TIMEOUT,
@ -113,15 +114,16 @@ public:
} }
private: private:
/// The timestamp provider to use (might be provided externally) ///< The timestamp provider to use (might be provided externally).
TIMESTAMP_PROVIDER* m_timestampProv; TIMESTAMP_PROVIDER* m_timestampProv;
/// Any provider owned by this class (the default one, if used) ///< Any provider owned by this class (the default one, if used).
std::unique_ptr<TIMESTAMP_PROVIDER> m_ownTimestampProv; std::unique_ptr<TIMESTAMP_PROVIDER> m_ownTimestampProv;
/// The timestamp of the last event ///< The timestamp of the last event.
TIME_PT m_lastTimestamp; TIME_PT m_lastTimestamp;
/// The timeout value
///< The timeout value.
TIMEOUT m_accTimeout; TIMEOUT m_accTimeout;
/// A multiplier for the minimum zoom step size /// A multiplier for the minimum zoom step size
@ -130,31 +132,31 @@ private:
/** /**
* A ZOOM_CONTROLLER that zooms by a fixed factor based only on the magnitude * A #ZOOM_CONTROLLER that zooms by a fixed factor based only on the magnitude of the scroll
* of the scroll wheel rotation. * wheel rotation.
*/ */
class CONSTANT_ZOOM_CONTROLLER : public ZOOM_CONTROLLER class CONSTANT_ZOOM_CONTROLLER : public ZOOM_CONTROLLER
{ {
public: public:
/** /**
* @param aScale a scaling parameter that adjusts the magnitude of the * @param aScale a scaling parameter that adjusts the magnitude of the scroll. This factor
* scroll. This factor might be dependent on the platform for comfort. * might be dependent on the platform for comfort.
*/ */
CONSTANT_ZOOM_CONTROLLER( double aScale ); CONSTANT_ZOOM_CONTROLLER( double aScale );
double GetScaleForRotation( int aRotation ) override; double GetScaleForRotation( int aRotation ) override;
/// A suitable (magic) scale factor for GTK3 systems ///< A suitable (magic) scale factor for GTK3 systems.
static constexpr double GTK3_SCALE = 0.002; static constexpr double GTK3_SCALE = 0.002;
/// A suitable (magic) scale factor for Mac systems ///< A suitable (magic) scale factor for Mac systems.
static constexpr double MAC_SCALE = 0.01; static constexpr double MAC_SCALE = 0.01;
/// Multipler for manual scale ssetting ///< Multiplier for manual scale ssetting.
static constexpr double MANUAL_SCALE_FACTOR = 0.001; static constexpr double MANUAL_SCALE_FACTOR = 0.001;
private: private:
/// The scale factor set by the constructor. ///< The scale factor set by the constructor.
double m_scale; double m_scale;
}; };