KiCad PCB EDA Suite
pcb_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  * Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * @author Maciej Suminski <maciej.suminski@cern.ch>
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; either version 2
12  * of the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, you may find one here:
21  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
22  * or you may search the http://www.gnu.org website for the version 2 license,
23  * or you may write to the Free Software Foundation, Inc.,
24  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
25  */
26 
27 #ifndef PCB_POINT_EDITOR_H
28 #define PCB_POINT_EDITOR_H
29 
30 #include <tool/tool_interactive.h>
31 #include "tool/edit_points.h"
32 #include <status_popup.h>
33 
34 #include <memory>
35 
36 
37 class PCB_SELECTION_TOOL;
38 class SHAPE_POLY_SET;
39 
44 {
45 public:
47 
49  void Reset( RESET_REASON aReason ) override;
50 
52  bool Init() override;
53 
57  int OnSelectionChange( const TOOL_EVENT& aEvent );
58 
64  bool HasPoint() { return m_editedPoint != nullptr; }
65 
66 private:
68  void setTransitions() override;
69 
70  void buildForPolyOutline( std::shared_ptr<EDIT_POINTS> points, const SHAPE_POLY_SET* aOutline );
71 
72  std::shared_ptr<EDIT_POINTS> makePoints( EDA_ITEM* aItem );
73 
75  void updateItem() const;
76 
78  void finishItem();
79 
86  bool validatePolygon( SHAPE_POLY_SET& aModified ) const;
87 
89  void updatePoints();
90 
92  void updateEditedPoint( const TOOL_EVENT& aEvent );
93 
95  void setEditedPoint( EDIT_POINT* aPoint );
96 
97  inline int getEditedPointIndex() const
98  {
99  for( unsigned i = 0; i < m_editPoints->PointsSize(); ++i )
100  {
101  if( m_editedPoint == &m_editPoints->Point( i ) )
102  return i;
103  }
104 
105  return wxNOT_FOUND;
106  }
107 
109  inline bool isModified( const EDIT_POINT& aPoint ) const
110  {
111  return m_editedPoint == &aPoint;
112  }
113 
115  void setAltConstraint( bool aEnabled );
116 
119 
121  static bool addCornerCondition( const SELECTION& aSelection );
122 
124  static bool canAddCorner( const EDA_ITEM& aItem );
125 
127  bool removeCornerCondition( const SELECTION& aSelection );
128 
130  int addCorner( const TOOL_EVENT& aEvent );
131  int removeCorner( const TOOL_EVENT& aEvent );
132  int modifiedSelection( const TOOL_EVENT& aEvent );
133 
137  void editArcEndpointKeepTangent( PCB_SHAPE* aArc, const VECTOR2I& aCenter,
138  const VECTOR2I& aStart, const VECTOR2I& aMid,
139  const VECTOR2I& aEnd, const VECTOR2I& aCursor ) const;
140 
144  void editArcEndpointKeepCenter( PCB_SHAPE* aArc, const VECTOR2I& aCenter,
145  const VECTOR2I& aStart, const VECTOR2I& aMid,
146  const VECTOR2I& aEnd, const VECTOR2I& aCursor ) const;
147 
151  void editArcMidKeepEndpoints( PCB_SHAPE* aArc, const VECTOR2I& aStart, const VECTOR2I& aEnd,
152  const VECTOR2I& aCursor ) const;
153 
157  void editArcMidKeepCenter( PCB_SHAPE* aArc, const VECTOR2I& aCenter, const VECTOR2I& aStart,
158  const VECTOR2I& aMid, const VECTOR2I& aEnd,
159  const VECTOR2I& aCursor ) const;
160 
162  int changeEditMethod( const TOOL_EVENT& aEvent );
163 
165  std::unique_ptr<STATUS_TEXT_POPUP> m_statusPopup;
166  std::shared_ptr<EDIT_POINTS> m_editPoints;
167 
170 
172 
173  bool m_refill;
175 
176  // Alternative constraint, enabled while a modifier key is held
177  std::shared_ptr<EDIT_CONSTRAINT<EDIT_POINT>> m_altConstraint;
179 };
180 
181 #endif
int removeCorner(const TOOL_EVENT &aEvent)
void editArcEndpointKeepTangent(PCB_SHAPE *aArc, const VECTOR2I &aCenter, const VECTOR2I &aStart, const VECTOR2I &aMid, const VECTOR2I &aEnd, const VECTOR2I &aCursor) const
Move an end point of the arc, while keeping the tangent at the other endpoint.
void editArcMidKeepEndpoints(PCB_SHAPE *aArc, const VECTOR2I &aStart, const VECTOR2I &aEnd, const VECTOR2I &aCursor) const
Move the mid point of the arc, while keeping the two endpoints.
void setTransitions() override
< Set up handlers for various events.
EDIT_POINT get45DegConstrainer() const
Condition to display "Create corner" context menu entry.
void updatePoints()
Update which point is being edited.
void updateEditedPoint(const TOOL_EVENT &aEvent)
Set the current point being edited. NULL means none.
int addCorner(const TOOL_EVENT &aEvent)
TOOL_ACTION handlers.
bool removeCornerCondition(const SELECTION &aSelection)
void buildForPolyOutline(std::shared_ptr< EDIT_POINTS > points, const SHAPE_POLY_SET *aOutline)
void setEditedPoint(EDIT_POINT *aPoint)
std::unique_ptr< STATUS_TEXT_POPUP > m_statusPopup
std::shared_ptr< EDIT_POINTS > m_editPoints
int modifiedSelection(const TOOL_EVENT &aEvent)
bool HasPoint()
Indicate the cursor is over an edit point.
EDIT_POINT * m_editedPoint
EDIT_POINT m_altConstrainer
std::shared_ptr< EDIT_POINTS > makePoints(EDA_ITEM *aItem)
Update item's points with edit points.
int getEditedPointIndex() const
Return true if aPoint is the currently modified point.
static bool canAddCorner(const EDA_ITEM &aItem)
Condition to display "Remove corner" context menu entry.
void editArcEndpointKeepCenter(PCB_SHAPE *aArc, const VECTOR2I &aCenter, const VECTOR2I &aStart, const VECTOR2I &aMid, const VECTOR2I &aEnd, const VECTOR2I &aCursor) const
Move an end point of the arc around the circumference.
int OnSelectionChange(const TOOL_EVENT &aEvent)
Change selection event handler.
PCB_SELECTION_TOOL * m_selectionTool
Represent a set of closed polygons.
void setAltConstraint(bool aEnabled)
Return a point that should be used as a constrainer for 45 degrees mode.
Generic, UI-independent tool event.
Definition: tool_event.h:152
int changeEditMethod(const TOOL_EVENT &aEvent)
std::shared_ptr< EDIT_CONSTRAINT< EDIT_POINT > > m_altConstraint
EDIT_POINT m_original
Original position for the current drag point.
bool Init() override
Init() is called once upon a registration of the tool.
Tool that displays edit points allowing to modify items by dragging the points.
void editArcMidKeepCenter(PCB_SHAPE *aArc, const VECTOR2I &aCenter, const VECTOR2I &aStart, const VECTOR2I &aMid, const VECTOR2I &aEnd, const VECTOR2I &aCursor) const
Move the mid point of the arc, while keeping the angle.
The selection tool: currently supports:
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:100
RESET_REASON
Determine the reason of reset for a tool.
Definition: tool_base.h:77
bool isModified(const EDIT_POINT &aPoint) const
Set up an alternative constraint (typically enabled upon a modifier key being pressed).
void Reset(RESET_REASON aReason) override
Bring the tool to a known, initial state.
static bool addCornerCondition(const SELECTION &aSelection)
Determine if the tool can currently add a corner to the given item.
EDIT_POINT * m_hoveredPoint
Represent a single point that can be used for modifying items.
Definition: edit_points.h:47
bool validatePolygon(SHAPE_POLY_SET &aModified) const
Validate a polygon and displays a popup warning if invalid.
void updateItem() const
Apply the last changes to the edited item.