2017-05-10 13:55:03 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2021-01-27 22:15:38 +00:00
|
|
|
* Copyright (C) 2017-2021 KiCad Developers, see AUTHORS.txt for contributors.
|
2017-05-10 13:55:03 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __POSITION_RELATIVE_TOOL_H
|
|
|
|
#define __POSITION_RELATIVE_TOOL_H
|
|
|
|
|
|
|
|
#include <math/vector2d.h>
|
2019-05-12 11:49:58 +00:00
|
|
|
#include <tools/pcb_tool_base.h>
|
2020-12-16 13:31:32 +00:00
|
|
|
#include "pcb_selection_tool.h"
|
2017-05-10 13:55:03 +00:00
|
|
|
#include "dialogs/dialog_position_relative.h"
|
|
|
|
#include "dialogs/dialog_position_relative_base.h"
|
|
|
|
|
|
|
|
class BOARD_COMMIT;
|
|
|
|
class BOARD_ITEM;
|
2020-12-16 13:31:32 +00:00
|
|
|
class PCB_SELECTION_TOOL;
|
2017-05-10 13:55:03 +00:00
|
|
|
class DIALOG_POSITION_RELATIVE;
|
|
|
|
|
|
|
|
/**
|
2021-01-27 22:15:38 +00:00
|
|
|
* The interactive edit tool.
|
2017-05-10 13:55:03 +00:00
|
|
|
*
|
2021-01-27 22:15:38 +00:00
|
|
|
* Allows one to move, rotate, flip and change properties of items selected using the
|
|
|
|
* pcbnew.InteractiveSelection tool.
|
2017-05-10 13:55:03 +00:00
|
|
|
*/
|
|
|
|
|
2019-05-12 11:49:58 +00:00
|
|
|
class POSITION_RELATIVE_TOOL : public PCB_TOOL_BASE
|
2017-05-10 13:55:03 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
POSITION_RELATIVE_TOOL();
|
|
|
|
|
2017-06-12 14:21:06 +00:00
|
|
|
void Reset( RESET_REASON aReason ) override;
|
2017-05-10 13:55:03 +00:00
|
|
|
|
2017-06-22 07:01:29 +00:00
|
|
|
/// @copydoc TOOL_BASE::Init()
|
2017-05-10 13:55:03 +00:00
|
|
|
bool Init() override;
|
|
|
|
|
|
|
|
/**
|
2021-01-27 22:15:38 +00:00
|
|
|
* Invoke a dialog box to allow positioning of the item relative to another by an exact amount.
|
2017-05-10 13:55:03 +00:00
|
|
|
*/
|
|
|
|
int PositionRelative( const TOOL_EVENT& aEvent );
|
|
|
|
|
|
|
|
/**
|
2021-01-27 22:15:38 +00:00
|
|
|
* Invoke the picker tool to select the item to which the previous selection will be placed
|
2018-09-23 23:42:22 +00:00
|
|
|
* relative to.
|
2017-05-10 13:55:03 +00:00
|
|
|
*/
|
|
|
|
int SelectPositionRelativeItem( const TOOL_EVENT& aEvent );
|
|
|
|
|
2020-03-02 20:55:06 +00:00
|
|
|
/**
|
2021-01-27 22:15:38 +00:00
|
|
|
* Return the position of the selected item(s)
|
2020-03-02 20:55:06 +00:00
|
|
|
*/
|
2021-12-29 21:30:11 +00:00
|
|
|
VECTOR2I GetSelectionAnchorPosition() const { return m_selectionAnchor; }
|
2020-03-02 20:55:06 +00:00
|
|
|
|
2017-05-10 13:55:03 +00:00
|
|
|
/**
|
2021-01-27 22:15:38 +00:00
|
|
|
* Position the m_position_relative_selection selection relative to anchor position using
|
2018-09-23 23:42:22 +00:00
|
|
|
* the given translation.
|
2017-05-10 13:55:03 +00:00
|
|
|
*/
|
2021-12-29 21:30:11 +00:00
|
|
|
int RelativeItemSelectionMove( const VECTOR2I& anchor, const VECTOR2I& translation );
|
2017-05-10 13:55:03 +00:00
|
|
|
|
2021-01-27 22:15:38 +00:00
|
|
|
///< Set up handlers for various events.
|
2017-07-31 12:30:51 +00:00
|
|
|
void setTransitions() override;
|
2017-05-10 13:55:03 +00:00
|
|
|
|
2017-06-12 14:21:06 +00:00
|
|
|
private:
|
2020-12-16 13:31:32 +00:00
|
|
|
DIALOG_POSITION_RELATIVE* m_dialog;
|
2017-05-10 13:55:03 +00:00
|
|
|
|
2020-12-16 13:31:32 +00:00
|
|
|
PCB_SELECTION_TOOL* m_selectionTool;
|
|
|
|
PCB_SELECTION m_selection;
|
2021-12-29 21:30:11 +00:00
|
|
|
VECTOR2I m_selectionAnchor;
|
2017-05-10 13:55:03 +00:00
|
|
|
|
|
|
|
std::unique_ptr<BOARD_COMMIT> m_commit;
|
|
|
|
|
2020-12-16 13:31:32 +00:00
|
|
|
EDA_ITEM* m_anchor_item;
|
2021-12-29 21:30:11 +00:00
|
|
|
VECTOR2I m_anchor;
|
2017-05-10 13:55:03 +00:00
|
|
|
|
2021-12-29 21:30:11 +00:00
|
|
|
VECTOR2I m_translation;
|
2017-05-10 13:55:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|