2016-05-10 18:09:39 +02:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2016 CERN
|
|
|
|
* @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2019-05-12 12:49:58 +01:00
|
|
|
#ifndef PCB_TOOL_BASE_H
|
|
|
|
#define PCB_TOOL_BASE_H
|
2016-05-10 18:09:39 +02:00
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#include <tool/tool_event.h>
|
|
|
|
#include <tool/tool_interactive.h>
|
2018-01-29 21:58:58 +01:00
|
|
|
#include <pcb_edit_frame.h>
|
2016-05-10 18:09:39 +02:00
|
|
|
#include <class_board.h>
|
2016-11-04 22:29:47 +01:00
|
|
|
#include <view/view_group.h>
|
2017-10-30 20:17:23 +01:00
|
|
|
#include <pcb_view.h>
|
2019-01-08 03:36:35 -08:00
|
|
|
#include <pcb_draw_panel_gal.h>
|
2016-05-10 18:09:39 +02:00
|
|
|
|
2017-02-23 14:23:17 +08:00
|
|
|
#include <functional>
|
2018-08-01 17:58:27 +01:00
|
|
|
#include <tool/tool_menu.h>
|
2017-02-23 14:23:17 +08:00
|
|
|
|
2016-05-10 18:09:39 +02:00
|
|
|
/**
|
2019-05-12 12:49:58 +01:00
|
|
|
* Class PCB_TOOL_BASE
|
2016-05-10 18:09:39 +02:00
|
|
|
*
|
|
|
|
* A tool operating on a BOARD object
|
|
|
|
**/
|
|
|
|
|
2019-05-12 12:49:58 +01:00
|
|
|
class PCB_TOOL_BASE;
|
2017-04-22 17:46:31 +02:00
|
|
|
class PCB_EDIT_FRAME;
|
2017-10-30 20:17:23 +01:00
|
|
|
class PCB_DISPLAY_OPTIONS;
|
2019-06-08 22:48:22 +01:00
|
|
|
class PCBNEW_SELECTION;
|
2017-04-22 17:46:31 +02:00
|
|
|
|
|
|
|
struct INTERACTIVE_PLACER_BASE
|
|
|
|
{
|
|
|
|
virtual std::unique_ptr<BOARD_ITEM> CreateItem() = 0;
|
2018-04-08 17:47:39 +01:00
|
|
|
virtual void SnapItem( BOARD_ITEM *aItem );
|
2019-01-23 07:18:44 -08:00
|
|
|
virtual bool PlaceItem( BOARD_ITEM *aItem, BOARD_COMMIT& aCommit );
|
2017-04-22 17:46:31 +02:00
|
|
|
|
2019-06-10 00:21:50 +01:00
|
|
|
PCB_BASE_EDIT_FRAME* m_frame;
|
2017-06-23 13:56:28 +02:00
|
|
|
BOARD* m_board;
|
2018-05-07 13:49:36 -07:00
|
|
|
int m_modifiers;
|
2017-04-22 17:46:31 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2019-05-12 12:49:58 +01:00
|
|
|
class PCB_TOOL_BASE : public TOOL_INTERACTIVE
|
2016-05-10 18:09:39 +02:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*
|
|
|
|
* Creates a tool with given id & name. The name must be unique. */
|
2019-05-12 12:49:58 +01:00
|
|
|
PCB_TOOL_BASE( TOOL_ID aId, const std::string& aName ) :
|
2016-05-10 18:09:39 +02:00
|
|
|
TOOL_INTERACTIVE ( aId, aName ),
|
2019-06-05 20:15:57 +01:00
|
|
|
m_editModules( false )
|
|
|
|
{};
|
2016-05-10 18:09:39 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*
|
|
|
|
* Creates a tool with given name. The name must be unique. */
|
2019-05-12 12:49:58 +01:00
|
|
|
PCB_TOOL_BASE( const std::string& aName ) :
|
2016-05-10 18:09:39 +02:00
|
|
|
TOOL_INTERACTIVE ( aName ),
|
2019-06-05 20:15:57 +01:00
|
|
|
m_editModules( false )
|
|
|
|
{};
|
2016-05-10 18:09:39 +02:00
|
|
|
|
2019-05-12 12:49:58 +01:00
|
|
|
virtual ~PCB_TOOL_BASE() {};
|
2016-05-10 18:09:39 +02:00
|
|
|
|
2018-08-01 17:58:27 +01:00
|
|
|
virtual bool Init() override;
|
2017-10-31 12:01:59 +01:00
|
|
|
virtual void Reset( RESET_REASON aReason ) override;
|
|
|
|
|
2016-05-10 18:09:39 +02:00
|
|
|
/**
|
|
|
|
* Function SetEditModules()
|
|
|
|
*
|
|
|
|
* Toggles edit module mode. When enabled, one may select parts of modules individually
|
|
|
|
* (graphics, pads, etc.), so they can be modified.
|
|
|
|
* @param aEnabled decides if the mode should be enabled.
|
|
|
|
*/
|
|
|
|
void SetEditModules( bool aEnabled )
|
|
|
|
{
|
|
|
|
m_editModules = aEnabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool EditingModules() const
|
|
|
|
{
|
|
|
|
return m_editModules;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2017-02-23 14:23:17 +08:00
|
|
|
|
2017-04-22 17:46:31 +02:00
|
|
|
enum INTERACTIVE_PLACEMENT_OPTIONS {
|
|
|
|
IPO_ROTATE = 1,
|
|
|
|
IPO_FLIP = 2,
|
2019-07-01 22:01:33 +01:00
|
|
|
IPO_SINGLE_CLICK = 4,
|
|
|
|
IPO_REPEAT = 8
|
2017-04-22 17:46:31 +02:00
|
|
|
};
|
|
|
|
|
2017-02-23 14:23:17 +08: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 13:15:58 +01:00
|
|
|
void doInteractiveItemPlacement( const std::string& aTool, INTERACTIVE_PLACER_BASE *aPlacer,
|
2017-04-22 17:46:31 +02:00
|
|
|
const wxString& aCommitMessage,
|
|
|
|
int aOptions = IPO_ROTATE | IPO_FLIP | IPO_REPEAT );
|
2017-02-23 14:23:17 +08:00
|
|
|
|
2017-10-31 12:01:59 +01:00
|
|
|
virtual void setTransitions() override;
|
|
|
|
|
|
|
|
|
2019-06-10 00:21:50 +01:00
|
|
|
KIGFX::PCB_VIEW* view() const
|
|
|
|
{
|
|
|
|
return static_cast<KIGFX::PCB_VIEW*>( getView() );
|
|
|
|
}
|
|
|
|
|
|
|
|
KIGFX::VIEW_CONTROLS* controls() const
|
|
|
|
{
|
|
|
|
return getViewControls();
|
|
|
|
}
|
|
|
|
|
|
|
|
PCB_BASE_EDIT_FRAME* frame() const
|
|
|
|
{
|
2019-10-26 08:25:19 -07:00
|
|
|
return getEditFrame<PCB_BASE_EDIT_FRAME>();
|
2019-06-10 00:21:50 +01:00
|
|
|
}
|
|
|
|
|
2016-05-10 18:09:39 +02:00
|
|
|
BOARD* board() const { return getModel<BOARD>(); }
|
2019-06-10 00:21:50 +01:00
|
|
|
|
|
|
|
MODULE* module() const
|
2019-05-30 17:15:57 -07:00
|
|
|
{
|
2019-06-02 12:57:56 -07:00
|
|
|
return board()->GetFirstModule();
|
2019-05-30 17:15:57 -07:00
|
|
|
}
|
2019-06-10 00:21:50 +01:00
|
|
|
|
2017-10-30 20:17:23 +01:00
|
|
|
PCB_DISPLAY_OPTIONS* displayOptions() const;
|
|
|
|
PCB_DRAW_PANEL_GAL* canvas() const;
|
2019-06-08 22:48:22 +01:00
|
|
|
const PCBNEW_SELECTION& selection() const;
|
|
|
|
PCBNEW_SELECTION& selection();
|
2017-09-22 17:17:38 +02:00
|
|
|
|
2016-05-10 18:09:39 +02:00
|
|
|
bool m_editModules;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|