KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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 The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * @author Maciej Suminski <[email protected]>
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, see <https://www.gnu.org/licenses/>.
21 */
22
23#ifndef PCB_POINT_EDITOR_H
24#define PCB_POINT_EDITOR_H
25
27#include <tools/pcb_selection.h>
28#include "tool/edit_points.h"
29#include <pcbnew_settings.h>
30#include <status_popup.h>
31
32#include <memory>
33
34namespace KIGFX { namespace PREVIEW { class ANGLE_ITEM; } }
35
36
40class SHAPE_POLY_SET;
42
47{
48public:
50
52 void Reset( RESET_REASON aReason ) override;
53
55 bool Init() override;
56
60 int OnSelectionChange( const TOOL_EVENT& aEvent );
61
67 bool HasPoint() { return m_editedPoint != nullptr; }
68 bool HasMidpoint() { return HasPoint() && dynamic_cast<EDIT_LINE*>( m_editedPoint ); }
69 bool HasCorner() { return HasPoint() && !HasMidpoint() && ( !m_editPoints || m_editPoints->GetParent()->Type() != PCB_GROUP_T ); }
70
74 static bool CanAddCorner( const EDA_ITEM& aItem );
75
79 static bool CanChamferCorner( const EDA_ITEM& aItem );
80
84 bool CanRemoveCorner( const SELECTION& aSelection );
85
86private:
88 void setTransitions() override;
89
90 std::shared_ptr<EDIT_POINTS> makePoints( EDA_ITEM* aItem );
91
93 void updateItem( BOARD_COMMIT& aCommit );
94
96 void updatePoints();
97
99 void updateEditedPoint( const TOOL_EVENT& aEvent );
100
102 void setEditedPoint( EDIT_POINT* aPoint );
103
104 inline int getEditedPointIndex() const
105 {
106 for( unsigned i = 0; i < m_editPoints->PointsSize(); ++i )
107 {
108 if( m_editedPoint == &m_editPoints->Point( i ) )
109 return i;
110 }
111
112 return wxNOT_FOUND;
113 }
114
116 inline bool isModified( const EDIT_POINT& aPoint ) const
117 {
118 return m_editedPoint == &aPoint;
119 }
120
122 void setAltConstraint( bool aEnabled );
123
126
128 int movePoint( const TOOL_EVENT& aEvent );
129 int addCorner( const TOOL_EVENT& aEvent );
130 int removeCorner( const TOOL_EVENT& aEvent );
131 int chamferCorner( const TOOL_EVENT& aEvent );
132 int modifiedSelection( const TOOL_EVENT& aEvent );
133
135 int changeArcEditMode( const TOOL_EVENT& aEvent );
136
137private:
140 std::shared_ptr<EDIT_POINTS> m_editPoints;
141 std::unique_ptr<KIGFX::PREVIEW::ANGLE_ITEM> m_angleItem;
142
145
147
149
152
153 // Alternative constraint, enabled while a modifier key is held
154 std::unique_ptr<EDIT_RELATION> m_altConstraint;
156
157 bool m_inPointEditorTool; // Re-entrancy guard
158
162
163 // This handles the edit process for a specific tpye of item (not
164 // just C++ type, because PCB_SHAPE is one type that has many subtypes)
165 std::unique_ptr<POINT_EDIT_BEHAVIOR> m_editorBehavior;
166 std::shared_ptr<BOARD_CONSTRAINT_DRAG_SESSION> m_constraintDragSession;
167
168 static const unsigned int COORDS_PADDING; // Padding from coordinates limits for this tool
169};
170
171#endif
ARC_EDIT_MODE
Settings for arc editing.
A base class for most all the KiCad significant classes used in schematics and boards.
Definition eda_item.h:96
Represent a line connecting two EDIT_POINTs.
Represent a single point that can be used for modifying items.
Definition edit_points.h:44
Base PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
int changeArcEditMode(const TOOL_EVENT &aEvent)
bool CanRemoveCorner(const SELECTION &aSelection)
Condition to display "Remove Corner" context menu entry.
void updateItem(BOARD_COMMIT &aCommit)
Update edit points with item's points.
VECTOR2I m_stickyDisplacement
int OnSelectionChange(const TOOL_EVENT &aEvent)
Change selection event handler.
void setAltConstraint(bool aEnabled)
Return a point that should be used as a constrainer for 45 degrees mode.
static const unsigned int COORDS_PADDING
EDIT_POINT * m_hoveredPoint
int addCorner(const TOOL_EVENT &aEvent)
bool HasPoint()
Indicate the cursor is over an edit point.
EDIT_POINT m_original
Original pos for the current drag point.
static bool CanChamferCorner(const EDA_ITEM &aItem)
Check if a corner of the given item can be chamfered (zones, polys only).
EDIT_POINT get45DegConstrainer() const
int modifiedSelection(const TOOL_EVENT &aEvent)
Change the edit method for arcs.
std::unique_ptr< POINT_EDIT_BEHAVIOR > m_editorBehavior
int removeCorner(const TOOL_EVENT &aEvent)
bool Init() override
Init() is called once upon a registration of the tool.
std::shared_ptr< BOARD_CONSTRAINT_DRAG_SESSION > m_constraintDragSession
std::unique_ptr< EDIT_RELATION > m_altConstraint
RECT_RADIUS_TEXT_ITEM * m_radiusHelper
PCB_SELECTION m_preview
int movePoint(const TOOL_EVENT &aEvent)
TOOL_ACTION handlers.
static bool CanAddCorner(const EDA_ITEM &aItem)
Check if a corner can be added to the given item (zones, polys, segments, arcs).
void setEditedPoint(EDIT_POINT *aPoint)
EDIT_POINT m_altConstrainer
bool isModified(const EDIT_POINT &aPoint) const
Set up an alternative constraint (typically enabled upon a modifier key being pressed).
ARC_EDIT_MODE m_arcEditMode
std::unique_ptr< KIGFX::PREVIEW::ANGLE_ITEM > m_angleItem
EDIT_POINT * m_editedPoint
void updateEditedPoint(const TOOL_EVENT &aEvent)
Set the current point being edited. NULL means none.
int getEditedPointIndex() const
Return true if aPoint is the currently modified point.
void updatePoints()
Update which point is being edited.
int chamferCorner(const TOOL_EVENT &aEvent)
void setTransitions() override
< Set up handlers for various events.
std::shared_ptr< EDIT_POINTS > m_editPoints
PCB_BASE_FRAME * m_frame
std::shared_ptr< EDIT_POINTS > makePoints(EDA_ITEM *aItem)
Update item's points with edit points.
PCB_SELECTION_TOOL * m_selectionTool
The selection tool: currently supports:
PCB_TOOL_BASE(TOOL_ID aId, const std::string &aName)
Constructor.
A helper class interface to manage the edit points for a single item.
Represent a set of closed polygons.
RESET_REASON
Determine the reason of reset for a tool.
Definition tool_base.h:74
Generic, UI-independent tool event.
Definition tool_event.h:167
void Reset() override
The Cairo implementation of the graphics abstraction layer.
Definition eda_group.h:29
@ PCB_GROUP_T
class PCB_GROUP, a set of BOARD_ITEMs
Definition typeinfo.h:104
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683