KiCad PCB EDA Suite
ee_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) 2019 CERN
5  * Copyright (C) 2019 KiCad Developers, see AUTHORS.txt for contributors.
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 EE_POINT_EDITOR_H
26 #define EE_POINT_EDITOR_H
27 
28 #include <tools/ee_tool_base.h>
29 #include <tool/edit_points.h>
30 #include <tool/selection.h>
31 
32 class EE_SELECTION_TOOL;
33 class SCH_BASE_FRAME;
34 
40 class EE_POINT_EDITOR : public EE_TOOL_BASE<SCH_BASE_FRAME>
41 {
42 public:
44 
46  void Reset( RESET_REASON aReason ) override;
47 
49  bool Init() override;
50 
51  int Main( const TOOL_EVENT& aEvent );
52 
57  bool HasPoint() { return m_editedPoint != nullptr; }
58 
60  void setTransitions() override;
61 
62 private:
64  void updateItem() const;
65 
67  void updatePoints();
68 
70  void updateEditedPoint( const TOOL_EVENT& aEvent );
71 
73  void setEditedPoint( EDIT_POINT* aPoint );
74 
76  inline bool isModified( const EDIT_POINT& aPoint ) const
77  {
78  return m_editedPoint == &aPoint;
79  }
80 
81  inline int getEditedPointIndex() const
82  {
83  for( unsigned i = 0; i < m_editPoints->PointsSize(); ++i )
84  {
85  if( m_editedPoint == &m_editPoints->Point( i ) )
86  return i;
87  }
88 
89  return wxNOT_FOUND;
90  }
91 
92  bool addCornerCondition( const SELECTION& aSelection );
93  bool removeCornerCondition( const SELECTION& aSelection );
94 
96  int addCorner( const TOOL_EVENT& aEvent );
97  int removeCorner( const TOOL_EVENT& aEvent );
98  int modifiedSelection( const TOOL_EVENT& aEvent );
99 
100  void saveItemsToUndo();
101  void rollbackFromUndo();
102 
103 private:
106 
108  std::shared_ptr<EDIT_POINTS> m_editPoints;
109 };
110 
111 #endif // EE_POINT_EDITOR_H
int Main(const TOOL_EVENT &aEvent)
bool HasPoint()
Indicates the cursor is over an edit point.
void updateEditedPoint(const TOOL_EVENT &aEvent)
Updates which point is being edited.
EDIT_POINT * m_editedPoint
Currently edited point, NULL if there is none.
void updatePoints()
Updates edit points with item's points.
int modifiedSelection(const TOOL_EVENT &aEvent)
bool addCornerCondition(const SELECTION &aSelection)
bool Init() override
Function Init() Init() is called once upon a registration of the tool.
Class TOOL_EVENT.
Definition: tool_event.h:171
int removeCorner(const TOOL_EVENT &aEvent)
int addCorner(const TOOL_EVENT &aEvent)
TOOL_ACTION handlers.
bool removeCornerCondition(const SELECTION &aSelection)
void Reset(RESET_REASON aReason) override
Function Reset() Brings the tool to a known, initial state.
std::shared_ptr< EDIT_POINTS > m_editPoints
Currently available edit points.
void updateItem() const
Updates item's points with edit points.
int getEditedPointIndex() const
Class EE_POINT_EDITOR.
size_t i
Definition: json11.cpp:649
void setEditedPoint(EDIT_POINT *aPoint)
Sets the current point being edited. NULL means none.
RESET_REASON
Determines the reason of reset for a tool
Definition: tool_base.h:79
Class EE_TOOL_BASE.
Definition: ee_tool_base.h:50
Class EDIT_POINT.
Definition: edit_points.h:46
void setTransitions() override
Sets up handlers for various events.
A shim class between EDA_DRAW_FRAME and several derived classes: LIB_EDIT_FRAME, LIB_VIEW_FRAME,...
bool isModified(const EDIT_POINT &aPoint) const
Returns true if aPoint is the currently modified point.