2014-02-27 16:29:08 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2017-01-18 08:04:11 +00:00
|
|
|
* Copyright (C) 2013-2017 CERN
|
2014-02-27 16:29:08 +00:00
|
|
|
* @author Maciej Suminski <maciej.suminski@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
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __POINT_EDITOR_H
|
|
|
|
#define __POINT_EDITOR_H
|
|
|
|
|
|
|
|
#include <tool/tool_interactive.h>
|
|
|
|
#include "edit_points.h"
|
2018-02-22 11:28:01 +00:00
|
|
|
#include <status_popup.h>
|
2014-02-27 16:29:08 +00:00
|
|
|
|
2016-06-29 15:09:55 +00:00
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
|
2014-02-27 16:29:08 +00:00
|
|
|
class SELECTION_TOOL;
|
2018-02-22 11:28:01 +00:00
|
|
|
class SHAPE_POLY_SET;
|
2014-02-27 16:29:08 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Class POINT_EDITOR
|
|
|
|
*
|
|
|
|
* Tool that displays edit points allowing to modify items by dragging the points.
|
|
|
|
*/
|
2017-11-30 16:21:51 +00:00
|
|
|
class POINT_EDITOR : public PCB_TOOL
|
2014-02-27 16:29:08 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
POINT_EDITOR();
|
|
|
|
|
|
|
|
/// @copydoc TOOL_INTERACTIVE::Reset()
|
2016-09-24 18:53:15 +00:00
|
|
|
void Reset( RESET_REASON aReason ) override;
|
2014-02-27 16:29:08 +00:00
|
|
|
|
|
|
|
/// @copydoc TOOL_INTERACTIVE::Init()
|
2016-09-24 18:53:15 +00:00
|
|
|
bool Init() override;
|
2014-02-27 16:29:08 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function OnSelected()
|
|
|
|
*
|
|
|
|
* Change selection event handler.
|
|
|
|
*/
|
2015-02-14 20:28:47 +00:00
|
|
|
int OnSelectionChange( const TOOL_EVENT& aEvent );
|
2014-02-27 16:29:08 +00:00
|
|
|
|
2015-04-30 08:46:03 +00:00
|
|
|
///> Sets up handlers for various events.
|
2017-07-31 12:30:51 +00:00
|
|
|
void setTransitions() override;
|
2015-04-30 08:46:03 +00:00
|
|
|
|
2014-02-27 16:29:08 +00:00
|
|
|
private:
|
|
|
|
///> Selection tool used for obtaining selected items
|
|
|
|
SELECTION_TOOL* m_selectionTool;
|
|
|
|
|
|
|
|
///> Currently edited point, NULL if there is none.
|
2015-06-19 15:32:33 +00:00
|
|
|
EDIT_POINT* m_editedPoint;
|
2014-02-27 16:29:08 +00:00
|
|
|
|
2014-03-13 10:48:19 +00:00
|
|
|
///> Original position for the current drag point.
|
|
|
|
EDIT_POINT m_original;
|
|
|
|
|
2014-02-28 15:53:28 +00:00
|
|
|
///> Currently available edit points.
|
2016-06-29 15:09:55 +00:00
|
|
|
std::shared_ptr<EDIT_POINTS> m_editPoints;
|
2014-02-28 15:53:28 +00:00
|
|
|
|
2014-03-14 14:37:55 +00:00
|
|
|
// Alternative constraint, enabled while a modifier key is held
|
2016-06-29 15:09:55 +00:00
|
|
|
std::shared_ptr<EDIT_CONSTRAINT<EDIT_POINT> > m_altConstraint;
|
2014-03-14 14:37:55 +00:00
|
|
|
|
|
|
|
// EDIT_POINT for alternative constraint mode
|
|
|
|
EDIT_POINT m_altConstrainer;
|
|
|
|
|
2018-04-03 20:26:01 +00:00
|
|
|
// Flag indicating whether the selected zone needs to be refilled
|
|
|
|
bool m_refill;
|
|
|
|
|
2018-02-22 11:28:01 +00:00
|
|
|
std::unique_ptr<STATUS_TEXT_POPUP> m_statusPopup;
|
|
|
|
|
2014-02-27 16:29:08 +00:00
|
|
|
///> Updates item's points with edit points.
|
2014-02-28 15:53:28 +00:00
|
|
|
void updateItem() const;
|
2014-02-27 16:29:08 +00:00
|
|
|
|
2014-03-06 10:49:08 +00:00
|
|
|
///> Applies the last changes to the edited item.
|
2017-11-30 16:21:51 +00:00
|
|
|
void finishItem();
|
2014-03-06 10:49:08 +00:00
|
|
|
|
2018-02-22 11:28:01 +00:00
|
|
|
/**
|
|
|
|
* Validates a polygon and restores it to its original version if available.
|
|
|
|
* @param aModified is the polygon to be checked.
|
|
|
|
* @param aOriginal is the original copy that will be used to restore its state.
|
|
|
|
* @return True if polygon is valid.
|
|
|
|
*/
|
|
|
|
bool validatePolygon( SHAPE_POLY_SET& aModified, const SHAPE_POLY_SET* aOriginal = nullptr ) const;
|
|
|
|
|
2014-02-27 16:29:08 +00:00
|
|
|
///> Updates edit points with item's points.
|
2014-07-09 14:50:31 +00:00
|
|
|
void updatePoints();
|
2014-02-27 16:29:08 +00:00
|
|
|
|
2015-08-12 08:15:45 +00:00
|
|
|
///> Updates which point is being edited.
|
|
|
|
void updateEditedPoint( const TOOL_EVENT& aEvent );
|
|
|
|
|
2015-06-19 15:32:33 +00:00
|
|
|
///> Sets the current point being edited. NULL means none.
|
|
|
|
void setEditedPoint( EDIT_POINT* aPoint );
|
|
|
|
|
2014-03-10 15:25:40 +00:00
|
|
|
///> Returns true if aPoint is the currently modified point.
|
|
|
|
inline bool isModified( const EDIT_POINT& aPoint ) const
|
|
|
|
{
|
2015-06-19 15:32:33 +00:00
|
|
|
return m_editedPoint == &aPoint;
|
2014-03-10 15:25:40 +00:00
|
|
|
}
|
|
|
|
|
2014-03-14 14:37:55 +00:00
|
|
|
///> Sets up an alternative constraint (typically enabled upon a modifier key being pressed).
|
|
|
|
void setAltConstraint( bool aEnabled );
|
|
|
|
|
2014-03-06 16:34:04 +00:00
|
|
|
///> Returns a point that should be used as a constrainer for 45 degrees mode.
|
|
|
|
EDIT_POINT get45DegConstrainer() const;
|
|
|
|
|
2014-07-09 14:50:31 +00:00
|
|
|
///> Adds a new edit point on a zone outline/line.
|
2015-06-19 15:32:33 +00:00
|
|
|
void addCorner( const VECTOR2I& aPoint );
|
|
|
|
|
|
|
|
///> Removes a corner.
|
|
|
|
void removeCorner( EDIT_POINT* aPoint );
|
2014-03-18 13:52:22 +00:00
|
|
|
|
2014-07-09 14:50:31 +00:00
|
|
|
///> Condition to display "Create corner" context menu entry.
|
2015-06-19 15:32:33 +00:00
|
|
|
static bool addCornerCondition( const SELECTION& aSelection );
|
|
|
|
|
|
|
|
///> Condition to display "Remove corner" context menu entry.
|
|
|
|
bool removeCornerCondition( const SELECTION& aSelection );
|
2017-01-18 08:04:11 +00:00
|
|
|
|
|
|
|
/// TOOL_ACTION handlers
|
|
|
|
int addCorner( const TOOL_EVENT& aEvent );
|
|
|
|
int removeCorner( const TOOL_EVENT& aEvent );
|
|
|
|
int modifiedSelection( const TOOL_EVENT& aEvent );
|
2014-02-27 16:29:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|