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 
31 #include <memory>
32 
33 
34 class SELECTION_TOOL;
35 
41 class POINT_EDITOR : public PCB_TOOL
42 {
43 public:
44  POINT_EDITOR();
45 
47  void Reset( RESET_REASON aReason ) override;
48 
50  bool Init() override;
51 
57  int OnSelectionChange( const TOOL_EVENT& aEvent );
58 
60  void setTransitions() override;
61 
62 private:
65 
68 
71 
73  std::shared_ptr<EDIT_POINTS> m_editPoints;
74 
75  // Alternative constraint, enabled while a modifier key is held
76  std::shared_ptr<EDIT_CONSTRAINT<EDIT_POINT> > m_altConstraint;
77 
78  // EDIT_POINT for alternative constraint mode
80 
82  void updateItem() const;
83 
85  void finishItem();
86 
88  void updatePoints();
89 
91  void updateEditedPoint( const TOOL_EVENT& aEvent );
92 
94  void setEditedPoint( EDIT_POINT* aPoint );
95 
97  inline bool isModified( const EDIT_POINT& aPoint ) const
98  {
99  return m_editedPoint == &aPoint;
100  }
101 
103  void setAltConstraint( bool aEnabled );
104 
107 
109  void addCorner( const VECTOR2I& aPoint );
110 
112  void removeCorner( EDIT_POINT* aPoint );
113 
115  static bool addCornerCondition( const SELECTION& aSelection );
116 
118  bool removeCornerCondition( const SELECTION& aSelection );
119 
121  int addCorner( const TOOL_EVENT& aEvent );
122  int removeCorner( const TOOL_EVENT& aEvent );
123  int modifiedSelection( const TOOL_EVENT& aEvent );
124 };
125 
126 #endif
int OnSelectionChange(const TOOL_EVENT &aEvent)
Function OnSelected()
void setTransitions() override
Sets up handlers for various events.
void updateItem() const
Updates item'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).
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:73
void finishItem()
Applies the last changes to the edited item.
Class TOOL_EVENT.
Definition: tool_event.h:162
std::shared_ptr< EDIT_CONSTRAINT< EDIT_POINT > > m_altConstraint
Definition: point_editor.h:76
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:97
SELECTION_TOOL * m_selectionTool
Selection tool used for obtaining selected items
Definition: point_editor.h:64
Class POINT_EDITOR.
Definition: point_editor.h:41
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's points.
EDIT_POINT m_original
Original position for the current drag point.
Definition: point_editor.h:70
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:79
EDIT_POINT * m_editedPoint
Currently edited point, NULL if there is none.
Definition: point_editor.h:67
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.