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>
29#include "tool/edit_points.h"
30#include <pcbnew_settings.h>
31#include <status_popup.h>
32
33#include <functional>
34#include <memory>
35#include <set>
36#include <unordered_set>
37
38namespace KIGFX { namespace PREVIEW { class ANGLE_ITEM; } }
39
40
44class SHAPE_POLY_SET;
47
52{
53public:
55
57 void Reset( RESET_REASON aReason ) override;
58
60 bool Init() override;
61
65 int OnSelectionChange( const TOOL_EVENT& aEvent );
66
72 bool HasPoint() { return m_editedPoint != nullptr; }
73 bool HasMidpoint() { return HasPoint() && dynamic_cast<EDIT_LINE*>( m_editedPoint ); }
74 bool HasCorner() { return HasPoint() && !HasMidpoint() && ( !m_editPoints || m_editPoints->GetParent()->Type() != PCB_GROUP_T ); }
75
82 bool HasBlockHandle() const;
83
85 bool HasBlockHandles() const { return !m_blockHandles.empty(); }
86
90 static bool CanAddCorner( const EDA_ITEM& aItem );
91
95 static bool CanChamferCorner( const EDA_ITEM& aItem );
96
100 bool CanRemoveCorner( const SELECTION& aSelection );
101
102private:
104 void setTransitions() override;
105
106 std::shared_ptr<EDIT_POINTS> makePoints( EDA_ITEM* aItem );
107
110 std::unique_ptr<POINT_EDIT_BEHAVIOR> makeBehavior( EDA_ITEM* aItem, bool& aRejected );
111
113 bool blockAnchorEditingEnabled() const;
114
116 void buildBlockHandles( const PCB_SELECTION& aSelection );
117
119 void clearBlockHandles();
120
123
125 void updateBlockHandleHover( const VECTOR2I& aPosition );
126
129 int bboxHandleInflation() const;
130
132 std::vector<EDIT_POINTS*> pickableCollections();
133
135 bool pickHandleAt( const VECTOR2I& aPosition, bool aAccumulate );
136
138 void clearPickedHandles();
139
141 void setPickedHandles( std::set<PCB_HANDLE_KEY> aPicked );
142
144 void applyPickedFlags();
145
147 void updateItem( BOARD_COMMIT& aCommit );
148
150 void updatePoints();
151
153 void updateEditedPoint( const TOOL_EVENT& aEvent );
154
156 void setEditedPoint( EDIT_POINT* aPoint );
157
158 inline int getEditedPointIndex() const
159 {
160 for( unsigned i = 0; i < m_editPoints->PointsSize(); ++i )
161 {
162 if( m_editedPoint == &m_editPoints->Point( i ) )
163 return i;
164 }
165
166 return wxNOT_FOUND;
167 }
168
170 inline bool isModified( const EDIT_POINT& aPoint ) const
171 {
172 return m_editedPoint == &aPoint;
173 }
174
176 void setAltConstraint( bool aEnabled );
177
180
182 int movePoint( const TOOL_EVENT& aEvent );
183 int addCorner( const TOOL_EVENT& aEvent );
184 int removeCorner( const TOOL_EVENT& aEvent );
185 int chamferCorner( const TOOL_EVENT& aEvent );
186 int modifiedSelection( const TOOL_EVENT& aEvent );
187
189 int changeArcEditMode( const TOOL_EVENT& aEvent );
190
191private:
194 std::shared_ptr<EDIT_POINTS> m_editPoints;
195 std::unique_ptr<KIGFX::PREVIEW::ANGLE_ITEM> m_angleItem;
196
199
201
203
206
207 // Alternative constraint, enabled while a modifier key is held
208 std::unique_ptr<EDIT_RELATION> m_altConstraint;
210
211 bool m_inPointEditorTool; // Re-entrancy guard
212
216
217 // This handles the edit process for a specific tpye of item (not
218 // just C++ type, because PCB_SHAPE is one type that has many subtypes)
219 std::unique_ptr<POINT_EDIT_BEHAVIOR> m_editorBehavior;
220 std::shared_ptr<BOARD_CONSTRAINT_DRAG_SESSION> m_constraintDragSession;
221
222 // Handles shown for the reshapeable members of a multi-selection or group, one
223 // collection per item
225 {
226 std::unique_ptr<POINT_EDIT_BEHAVIOR> behavior;
227 std::shared_ptr<EDIT_POINTS> points;
228 };
229
230 std::vector<BLOCK_HANDLE_ENTRY> m_blockHandles;
233 std::set<PCB_HANDLE_KEY> m_pickedHandles;
234
235 // The selection with each group replaced by its members, kept in selection order
236 // so a refusal message always names the same item
237 std::vector<BOARD_ITEM*> m_expandedSelection;
238
239 // Undoes a block drag that is still running. Set only while OnSelectionChange is
240 // parked in its loop, because it reads that call's locals. Reset() calls it before
241 // it clears any collection, so the drag is undone while the items still exist
242 std::function<void()> m_blockDragAbort;
243
244 static const unsigned int COORDS_PADDING; // Padding from coordinates limits for this tool
245
246 // Runs the block drag gesture. It works on the handle collections, the picked set and
247 // the expanded selection this tool builds, and runs its area picks through its Wait()
248 friend class BLOCK_DRAG_SESSION;
249};
250
251#endif
ARC_EDIT_MODE
Settings for arc editing.
The block drag gesture, with the state it holds while it runs.
A base class for most all the KiCad significant classes used in schematics and boards.
Definition eda_item.h:98
Represent a line connecting two EDIT_POINTs.
EDIT_POINTS is a VIEW_ITEM that manages EDIT_POINTs and EDIT_LINEs and draws them.
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.
friend class BLOCK_DRAG_SESSION
int changeArcEditMode(const TOOL_EVENT &aEvent)
Change the edit method for arcs.
void updateBlockHandlePoints()
Move those handles back onto their items after the geometry changed.
bool CanRemoveCorner(const SELECTION &aSelection)
Condition to display "Remove Corner" context menu entry.
void updateItem(BOARD_COMMIT &aCommit)
Update item's points with edit points.
void setPickedHandles(std::set< PCB_HANDLE_KEY > aPicked)
Replace the picked set and repaint the handles to match it.
VECTOR2I m_stickyDisplacement
void updateBlockHandleHover(const VECTOR2I &aPosition)
Highlight the handle under the cursor, if there is one.
int OnSelectionChange(const TOOL_EVENT &aEvent)
Change selection event handler.
void applyPickedFlags()
Paint the picked handles, dropping keys whose handle has gone.
void setAltConstraint(bool aEnabled)
Set up an alternative constraint (typically enabled upon a modifier key being pressed).
static const unsigned int COORDS_PADDING
bool HasBlockHandle() const
True when the cursor sits on a handle the user can pick.
EDIT_POINT * m_hoveredPoint
bool blockAnchorEditingEnabled() const
Whether the user has turned on anchor point handles for multi-selections.
int addCorner(const TOOL_EVENT &aEvent)
EDIT_POINTS * m_blockHoveredOwner
bool HasPoint()
Indicate the cursor is over an edit point.
EDIT_POINT m_original
Original pos for the current drag point.
bool HasBlockHandles() const
True while handles are shown for the members of a multi-selection or group.
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
Return a point that should be used as a constrainer for 45 degrees mode.
int modifiedSelection(const TOOL_EVENT &aEvent)
EDIT_POINT * m_blockHoveredPoint
std::unique_ptr< POINT_EDIT_BEHAVIOR > makeBehavior(EDA_ITEM *aItem, bool &aRejected)
Create the point edit behavior for an item.
void clearPickedHandles()
Unpick everything and redraw.
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
std::set< PCB_HANDLE_KEY > m_pickedHandles
int bboxHandleInflation() const
Gap to leave between the scaling box handles and the shapes' own handles, in board units for the curr...
std::vector< BLOCK_HANDLE_ENTRY > m_blockHandles
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)
Set the current point being edited. NULL means none.
bool pickHandleAt(const VECTOR2I &aPosition, bool aAccumulate)
Pick the handle under aPosition. Returns false when there is no handle to pick.
EDIT_POINT m_altConstrainer
bool isModified(const EDIT_POINT &aPoint) const
Return true if aPoint is the currently modified point.
std::vector< EDIT_POINTS * > pickableCollections()
The handle collections the user can pick from.
ARC_EDIT_MODE m_arcEditMode
std::unique_ptr< KIGFX::PREVIEW::ANGLE_ITEM > m_angleItem
EDIT_POINT * m_editedPoint
void updateEditedPoint(const TOOL_EVENT &aEvent)
Update which point is being edited.
int getEditedPointIndex() const
void updatePoints()
Update edit points with item's points.
int chamferCorner(const TOOL_EVENT &aEvent)
void clearBlockHandles()
Take those handles off the view and throw them away.
std::vector< BOARD_ITEM * > m_expandedSelection
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)
void buildBlockHandles(const PCB_SELECTION &aSelection)
Build the handles shown for every reshapeable item in a multi-selection or group.
std::function< void()> m_blockDragAbort
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:30
std::unique_ptr< POINT_EDIT_BEHAVIOR > behavior
std::shared_ptr< EDIT_POINTS > points
@ PCB_GROUP_T
class PCB_GROUP, a set of BOARD_ITEMs
Definition typeinfo.h:103
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708