2016-05-10 16:09:39 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2016 CERN
|
2020-11-07 17:50:22 +00:00
|
|
|
* Copyright (C) 2017-2020 KiCad Developers, see AUTHORS.txt for contributors.
|
2016-05-10 16:09:39 +00:00
|
|
|
* @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2019-05-12 11:49:58 +00:00
|
|
|
#ifndef PCB_TOOL_BASE_H
|
|
|
|
#define PCB_TOOL_BASE_H
|
2016-05-10 16:09:39 +00:00
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#include <tool/tool_interactive.h>
|
2018-01-29 20:58:58 +00:00
|
|
|
#include <pcb_edit_frame.h>
|
2020-11-12 20:19:22 +00:00
|
|
|
#include <board.h>
|
2016-11-04 21:29:47 +00:00
|
|
|
#include <view/view_group.h>
|
2017-10-30 19:17:23 +00:00
|
|
|
#include <pcb_view.h>
|
2019-01-08 11:36:35 +00:00
|
|
|
#include <pcb_draw_panel_gal.h>
|
2016-05-10 16:09:39 +00:00
|
|
|
|
2017-02-23 06:23:17 +00:00
|
|
|
#include <functional>
|
2018-08-01 16:58:27 +00:00
|
|
|
#include <tool/tool_menu.h>
|
2017-02-23 06:23:17 +00:00
|
|
|
|
2016-05-10 16:09:39 +00:00
|
|
|
/**
|
2020-01-10 14:31:00 +00:00
|
|
|
* PCB_TOOL_BASE
|
2016-05-10 16:09:39 +00:00
|
|
|
*
|
|
|
|
* A tool operating on a BOARD object
|
|
|
|
**/
|
|
|
|
|
2019-05-12 11:49:58 +00:00
|
|
|
class PCB_TOOL_BASE;
|
2017-04-22 15:46:31 +00:00
|
|
|
class PCB_EDIT_FRAME;
|
2017-10-30 19:17:23 +00:00
|
|
|
class PCB_DISPLAY_OPTIONS;
|
2020-12-16 13:31:32 +00:00
|
|
|
class PCB_SELECTION;
|
2017-04-22 15:46:31 +00:00
|
|
|
|
|
|
|
struct INTERACTIVE_PLACER_BASE
|
|
|
|
{
|
2020-02-05 22:19:14 +00:00
|
|
|
virtual ~INTERACTIVE_PLACER_BASE()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-04-22 15:46:31 +00:00
|
|
|
virtual std::unique_ptr<BOARD_ITEM> CreateItem() = 0;
|
2020-11-07 17:50:22 +00:00
|
|
|
|
2018-04-08 16:47:39 +00:00
|
|
|
virtual void SnapItem( BOARD_ITEM *aItem );
|
2020-11-07 17:50:22 +00:00
|
|
|
|
2019-01-23 15:18:44 +00:00
|
|
|
virtual bool PlaceItem( BOARD_ITEM *aItem, BOARD_COMMIT& aCommit );
|
2017-04-22 15:46:31 +00:00
|
|
|
|
2019-06-09 23:21:50 +00:00
|
|
|
PCB_BASE_EDIT_FRAME* m_frame;
|
2020-11-07 17:50:22 +00:00
|
|
|
BOARD* m_board;
|
|
|
|
int m_modifiers;
|
2017-04-22 15:46:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2019-05-12 11:49:58 +00:00
|
|
|
class PCB_TOOL_BASE : public TOOL_INTERACTIVE
|
2016-05-10 16:09:39 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*
|
|
|
|
* Creates a tool with given id & name. The name must be unique. */
|
2019-05-12 11:49:58 +00:00
|
|
|
PCB_TOOL_BASE( TOOL_ID aId, const std::string& aName ) :
|
2020-11-07 17:50:22 +00:00
|
|
|
TOOL_INTERACTIVE ( aId, aName ),
|
|
|
|
m_isFootprintEditor( false )
|
2019-06-05 19:15:57 +00:00
|
|
|
{};
|
2016-05-10 16:09:39 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*
|
|
|
|
* Creates a tool with given name. The name must be unique. */
|
2019-05-12 11:49:58 +00:00
|
|
|
PCB_TOOL_BASE( const std::string& aName ) :
|
2020-11-07 17:50:22 +00:00
|
|
|
TOOL_INTERACTIVE ( aName ),
|
|
|
|
m_isFootprintEditor( false )
|
2019-06-05 19:15:57 +00:00
|
|
|
{};
|
2016-05-10 16:09:39 +00:00
|
|
|
|
2019-05-12 11:49:58 +00:00
|
|
|
virtual ~PCB_TOOL_BASE() {};
|
2016-05-10 16:09:39 +00:00
|
|
|
|
2018-08-01 16:58:27 +00:00
|
|
|
virtual bool Init() override;
|
2017-10-31 11:01:59 +00:00
|
|
|
virtual void Reset( RESET_REASON aReason ) override;
|
|
|
|
|
2016-05-10 16:09:39 +00:00
|
|
|
/**
|
2020-11-07 17:50:22 +00:00
|
|
|
* Function SetIsFootprintEditor()
|
2016-05-10 16:09:39 +00:00
|
|
|
*
|
2020-11-14 21:21:54 +00:00
|
|
|
* Toggles edit footprint mode. When enabled, one may select parts of footprints individually
|
2016-05-10 16:09:39 +00:00
|
|
|
* (graphics, pads, etc.), so they can be modified.
|
|
|
|
* @param aEnabled decides if the mode should be enabled.
|
|
|
|
*/
|
2020-11-07 17:50:22 +00:00
|
|
|
void SetIsFootprintEditor( bool aEnabled ) { m_isFootprintEditor = aEnabled; }
|
|
|
|
bool IsFootprintEditor() const { return m_isFootprintEditor; }
|
2016-05-10 16:09:39 +00:00
|
|
|
|
2021-09-02 22:32:15 +00:00
|
|
|
/**
|
|
|
|
* Should the tool use its 45° mode option?
|
|
|
|
* @return True if set to use 45°
|
|
|
|
*/
|
2021-11-17 23:36:39 +00:00
|
|
|
virtual bool Is45Limited() const;
|
2021-09-02 22:32:15 +00:00
|
|
|
|
2016-05-10 16:09:39 +00:00
|
|
|
protected:
|
2020-04-01 17:24:58 +00:00
|
|
|
/**
|
|
|
|
* Options for placing items interactively.
|
|
|
|
*/
|
2017-04-22 15:46:31 +00:00
|
|
|
enum INTERACTIVE_PLACEMENT_OPTIONS {
|
2020-04-01 17:24:58 +00:00
|
|
|
/// Handle the rotate action in the loop by calling the item's rotate method
|
|
|
|
IPO_ROTATE = 0x01,
|
|
|
|
|
|
|
|
/// Handle flip action in the loop by calling the item's flip method
|
|
|
|
IPO_FLIP = 0x02,
|
|
|
|
|
|
|
|
/// Create an item immediately on placement starting, otherwise show the pencil cursor
|
|
|
|
/// until the item is created
|
|
|
|
IPO_SINGLE_CLICK = 0x04,
|
|
|
|
|
|
|
|
/// Allow repeat placement of the item
|
|
|
|
IPO_REPEAT = 0x08
|
2017-04-22 15:46:31 +00:00
|
|
|
};
|
|
|
|
|
2017-02-23 06:23:17 +00:00
|
|
|
/**
|
|
|
|
* Helper function for performing a common interactive idiom:
|
|
|
|
* wait for a left click, place an item there (perhaps with a
|
|
|
|
* dialog or other user interaction), then have it move with
|
|
|
|
* the mouse and respond to rotate/flip, etc
|
|
|
|
*
|
|
|
|
* More complex interactive processes are not supported here, you
|
|
|
|
* should implement a customised event loop for those.
|
|
|
|
*
|
|
|
|
* @param aItemCreator the callable that will attempt to create the item
|
|
|
|
* @param aCommitMessage the message used on a successful commit
|
|
|
|
*/
|
2019-07-15 12:15:58 +00:00
|
|
|
void doInteractiveItemPlacement( const std::string& aTool, INTERACTIVE_PLACER_BASE *aPlacer,
|
2017-04-22 15:46:31 +00:00
|
|
|
const wxString& aCommitMessage,
|
|
|
|
int aOptions = IPO_ROTATE | IPO_FLIP | IPO_REPEAT );
|
2017-02-23 06:23:17 +00:00
|
|
|
|
2017-10-31 11:01:59 +00:00
|
|
|
virtual void setTransitions() override;
|
|
|
|
|
|
|
|
|
2020-02-05 22:19:14 +00:00
|
|
|
KIGFX::PCB_VIEW* view() const
|
|
|
|
{
|
|
|
|
return static_cast<KIGFX::PCB_VIEW*>( getView() );
|
2019-06-09 23:21:50 +00:00
|
|
|
}
|
2020-02-05 22:19:14 +00:00
|
|
|
|
|
|
|
KIGFX::VIEW_CONTROLS* controls() const
|
|
|
|
{
|
|
|
|
return getViewControls();
|
2019-06-09 23:21:50 +00:00
|
|
|
}
|
2020-02-05 22:19:14 +00:00
|
|
|
|
|
|
|
PCB_BASE_EDIT_FRAME* frame() const
|
|
|
|
{
|
2019-10-26 15:25:19 +00:00
|
|
|
return getEditFrame<PCB_BASE_EDIT_FRAME>();
|
2019-06-09 23:21:50 +00:00
|
|
|
}
|
2020-02-05 22:19:14 +00:00
|
|
|
|
2016-05-10 16:09:39 +00:00
|
|
|
BOARD* board() const { return getModel<BOARD>(); }
|
2020-02-05 22:19:14 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
FOOTPRINT* footprint() const
|
2019-05-31 00:15:57 +00:00
|
|
|
{
|
2020-11-08 21:29:04 +00:00
|
|
|
return board()->GetFirstFootprint();
|
2019-05-31 00:15:57 +00:00
|
|
|
}
|
2020-02-05 22:19:14 +00:00
|
|
|
|
2019-11-07 14:23:09 +00:00
|
|
|
const PCB_DISPLAY_OPTIONS& displayOptions() const;
|
2020-11-07 17:50:22 +00:00
|
|
|
|
2017-10-30 19:17:23 +00:00
|
|
|
PCB_DRAW_PANEL_GAL* canvas() const;
|
2020-11-07 17:50:22 +00:00
|
|
|
|
2020-12-16 13:31:32 +00:00
|
|
|
const PCB_SELECTION& selection() const;
|
2020-11-07 17:50:22 +00:00
|
|
|
|
2020-12-16 13:31:32 +00:00
|
|
|
PCB_SELECTION& selection();
|
2017-09-22 15:17:38 +00:00
|
|
|
|
2020-11-07 17:50:22 +00:00
|
|
|
protected:
|
|
|
|
bool m_isFootprintEditor;
|
2021-09-02 22:32:15 +00:00
|
|
|
|
2016-05-10 16:09:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|