KiCad PCB EDA Suite
point_editor.h
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2013-2017 CERN
5  * @author Maciej Suminski <maciej.suminski@cern.ch>
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
25 #ifndef __POINT_EDITOR_H
26 #define __POINT_EDITOR_H
27 
28 #include <tool/tool_interactive.h>
29 #include "edit_points.h"
30 #include <status_popup.h>
31 
32 #include <memory>
33 
34 
35 class SELECTION_TOOL;
36 class SHAPE_POLY_SET;
37 
43 class POINT_EDITOR : public PCB_TOOL
44 {
45 public:
46  POINT_EDITOR();
47 
49  void Reset( RESET_REASON aReason ) override;
50 
52  bool Init() override;
53 
59  int OnSelectionChange( const TOOL_EVENT& aEvent );
60 
62  void setTransitions() override;
63 
64 private:
67 
70 
73 
75  std::shared_ptr<EDIT_POINTS> m_editPoints;
76 
77  // Alternative constraint, enabled while a modifier key is held
78  std::shared_ptr<EDIT_CONSTRAINT<EDIT_POINT> > m_altConstraint;
79 
80  // EDIT_POINT for alternative constraint mode
82 
83  // Flag indicating whether the selected zone needs to be refilled
84  bool m_refill;
85 
86  std::unique_ptr<STATUS_TEXT_POPUP> m_statusPopup;
87 
89  void updateItem() const;
90 
92  void finishItem();
93 
100  bool validatePolygon( SHAPE_POLY_SET& aModified, const SHAPE_POLY_SET* aOriginal = nullptr ) const;
101 
103  void updatePoints();
104 
106  void updateEditedPoint( const TOOL_EVENT& aEvent );
107 
109  void setEditedPoint( EDIT_POINT* aPoint );
110 
112  inline bool isModified( const EDIT_POINT& aPoint ) const
113  {
114  return m_editedPoint == &aPoint;
115  }
116 
118  void setAltConstraint( bool aEnabled );
119 
122 
124  void addCorner( const VECTOR2I& aPoint );
125 
127  void removeCorner( EDIT_POINT* aPoint );
128 
130  static bool addCornerCondition( const SELECTION& aSelection );
131 
133  static bool canAddCorner( const EDA_ITEM& aItem );
134 
136  bool removeCornerCondition( const SELECTION& aSelection );
137 
139  int addCorner( const TOOL_EVENT& aEvent );
140  int removeCorner( const TOOL_EVENT& aEvent );
141  int modifiedSelection( const TOOL_EVENT& aEvent );
142 };
143 
144 #endif
int OnSelectionChange(const TOOL_EVENT &aEvent)
Function OnSelected()
void setTransitions() override
Sets up handlers for various events.
void updateItem() const
Updates item&#39;s points with edit points.
void addCorner(const VECTOR2I &aPoint)
Adds a new edit point on a zone outline/line.
void updateEditedPoint(const TOOL_EVENT &aEvent)
Updates which point is being edited.
Class SELECTION_TOOL.
void setAltConstraint(bool aEnabled)
Sets up an alternative constraint (typically enabled upon a modifier key being pressed).
std::unique_ptr< STATUS_TEXT_POPUP > m_statusPopup
Definition: point_editor.h:86
bool removeCornerCondition(const SELECTION &aSelection)
Condition to display "Remove corner" context menu entry.
std::shared_ptr< EDIT_POINTS > m_editPoints
Currently available edit points.
Definition: point_editor.h:75
void finishItem()
Applies the last changes to the edited item.
Class SHAPE_POLY_SET.
Class TOOL_EVENT.
Definition: tool_event.h:168
std::shared_ptr< EDIT_CONSTRAINT< EDIT_POINT > > m_altConstraint
Definition: point_editor.h:78
EDIT_POINT get45DegConstrainer() const
Returns a point that should be used as a constrainer for 45 degrees mode.
bool isModified(const EDIT_POINT &aPoint) const
Returns true if aPoint is the currently modified point.
Definition: point_editor.h:112
SELECTION_TOOL * m_selectionTool
Selection tool used for obtaining selected items
Definition: point_editor.h:66
static bool canAddCorner(const EDA_ITEM &aItem)
Determine if the tool can currently add a corner to the given item
Class POINT_EDITOR.
Definition: point_editor.h:43
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:154
void removeCorner(EDIT_POINT *aPoint)
Removes a corner.
RESET_REASON
Determines the reason of reset for a tool
Definition: tool_base.h:80
void updatePoints()
Updates edit points with item&#39;s points.
EDIT_POINT m_original
Original position for the current drag point.
Definition: point_editor.h:72
bool Init() override
Function Init() Init() is called once upon a registration of the tool.
Class EDIT_POINT.
Definition: edit_points.h:46
EDIT_POINT m_altConstrainer
Definition: point_editor.h:81
EDIT_POINT * m_editedPoint
Currently edited point, NULL if there is none.
Definition: point_editor.h:69
void Reset(RESET_REASON aReason) override
Function Reset() Brings the tool to a known, initial state.
void setEditedPoint(EDIT_POINT *aPoint)
Sets the current point being edited. NULL means none.
int modifiedSelection(const TOOL_EVENT &aEvent)
static bool addCornerCondition(const SELECTION &aSelection)
Condition to display "Create corner" context menu entry.
bool validatePolygon(SHAPE_POLY_SET &aModified, const SHAPE_POLY_SET *aOriginal=nullptr) const
Validates a polygon and restores it to its original version if available.