KiCad PCB EDA Suite
Loading...
Searching...
No Matches
construction_manager.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 The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * @author Maciej Suminski <[email protected]>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, you may find one here:
20 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21 * or you may search the http://www.gnu.org website for the version 2 license,
22 * or you may write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 */
25#pragma once
26
27#include <deque>
28#include <memory>
29#include <mutex>
30#include <vector>
31
33
34template <typename T>
36class EDA_ITEM;
37
38
44{
45public:
50
51 virtual void updateView() = 0;
52
54
55private:
56 // An (external) construction helper view item, that this manager adds/removes
57 // construction objects to/from.
59};
60
61
68class SNAP_MANAGER;
69
70
72{
73public:
75
83 void SetSnapLineOrigin( const VECTOR2I& aOrigin );
84
90 void SetSnapLineEnd( const OPT_VECTOR2I& aSnapPoint );
91
95 void ClearSnapLine();
96
98
100
106 void SetSnappedAnchor( const VECTOR2I& aAnchorPos );
107
125 OPT_VECTOR2I GetNearestSnapLinePoint( const VECTOR2I& aCursor, const VECTOR2I& aNearestGrid,
126 std::optional<int> aDistToNearest, int snapRange,
127 const VECTOR2D& aGridSize = VECTOR2D( 0, 0 ),
128 const VECTOR2I& aGridOrigin = VECTOR2I( 0, 0 ) ) const;
129
130 void SetDirections( const std::vector<VECTOR2I>& aDirections );
131
132 const std::vector<VECTOR2I>& GetDirections() const { return m_directions; }
133
134 std::optional<int> GetActiveDirection() const { return m_activeDirection; }
135
136private:
137 // If a snap point is "active", extra construction geometry is added to the helper
138 // extending from the snap point to the cursor.
141
142 std::vector<VECTOR2I> m_directions;
143 std::optional<int> m_activeDirection;
144
145 // The view handler to update when the snap line changes
148
149 void notifyGuideChange();
150};
151
152
159{
160public:
163
164 enum class SOURCE
165 {
168 };
169
178 {
181
187
188 std::vector<DRAWABLE_ENTRY> Constructions;
189 };
190
191 // A single batch of construction items. Once batch contains all the items (and associated
192 // construction geometry) that should be shown for one point of interest.
193 // More than one batch may be shown on the screen at the same time.
194 using CONSTRUCTION_ITEM_BATCH = std::vector<CONSTRUCTION_ITEM>;
195
204 void ProposeConstructionItems( std::unique_ptr<CONSTRUCTION_ITEM_BATCH> aBatch,
205 bool aIsPersistent );
206
210 void CancelProposal();
211
216 bool InvolvesAllGivenRealItems( const std::vector<EDA_ITEM*>& aItems ) const;
217
221 void GetConstructionItems( std::vector<CONSTRUCTION_ITEM_BATCH>& aToExtend ) const;
222
223 bool HasActiveConstruction() const;
224
225private:
226 struct PENDING_BATCH;
227
228 void acceptConstructionItems( std::unique_ptr<PENDING_BATCH> aAcceptedBatchHash );
229
235 unsigned getMaxTemporaryBatches() const;
236
238
242 std::optional<CONSTRUCTION_ITEM_BATCH> m_persistentConstructionBatch;
243
245 std::deque<CONSTRUCTION_ITEM_BATCH> m_temporaryConstructionBatches;
246
248 std::set<EDA_ITEM*> m_involvedItems;
249
250 std::unique_ptr<ACTIVATION_HELPER<std::unique_ptr<PENDING_BATCH>>> m_activationHelper;
251
253 mutable std::mutex m_batchesMutex;
254};
255
256
270{
271public:
272 using GFX_UPDATE_CALLBACK = std::function<void( bool aShowAnything )>;
273
275
279 void SetUpdateCallback( GFX_UPDATE_CALLBACK aCallback ) { m_updateCallback = aCallback; }
280
283
285
290 void SetReferenceOnlyPoints( std::vector<VECTOR2I> aPoints )
291 {
292 m_referenceOnlyPoints = std::move( aPoints );
293 }
294
295 const std::vector<VECTOR2I>& GetReferenceOnlyPoints() const { return m_referenceOnlyPoints; }
296
303 std::vector<CONSTRUCTION_MANAGER::CONSTRUCTION_ITEM_BATCH> GetConstructionItems() const;
304
305 void SetSnapGuideColors( const KIGFX::COLOR4D& aBase, const KIGFX::COLOR4D& aHighlight );
306 void UpdateSnapGuides();
307
308public:
309 void updateView() override;
310
312
315
316 std::vector<VECTOR2I> m_referenceOnlyPoints;
319};
A helper class to manage the activation of a "proposal" after a timeout.
A class that manages "construction" objects and geometry.
void GetConstructionItems(std::vector< CONSTRUCTION_ITEM_BATCH > &aToExtend) const
Get the list of additional geometry items that should be considered.
void ProposeConstructionItems(std::unique_ptr< CONSTRUCTION_ITEM_BATCH > aBatch, bool aIsPersistent)
Add a batch of construction items to the helper.
CONSTRUCTION_VIEW_HANDLER & m_viewHandler
CONSTRUCTION_MANAGER(CONSTRUCTION_VIEW_HANDLER &aViewHandler)
void CancelProposal()
Cancel outstanding proposals for new geometry.
std::deque< CONSTRUCTION_ITEM_BATCH > m_temporaryConstructionBatches
Temporary construction items are added and removed as needed.
std::vector< CONSTRUCTION_ITEM > CONSTRUCTION_ITEM_BATCH
std::optional< CONSTRUCTION_ITEM_BATCH > m_persistentConstructionBatch
Within one "operation", there is one set of construction items that are "persistent",...
std::unique_ptr< ACTIVATION_HELPER< std::unique_ptr< PENDING_BATCH > > > m_activationHelper
unsigned getMaxTemporaryBatches() const
How many batches of temporary construction items can be active at once.
std::mutex m_batchesMutex
Protects the persistent and temporary construction batches.
bool InvolvesAllGivenRealItems(const std::vector< EDA_ITEM * > &aItems) const
Check if all 'real' (non-null = constructed) the items in the batch are in the list of items currentl...
void acceptConstructionItems(std::unique_ptr< PENDING_BATCH > aAcceptedBatchHash)
std::set< EDA_ITEM * > m_involvedItems
Set of all items for which construction geometry has been added.
Interface wrapper for the construction geometry preview with a callback to signal the view owner that...
KIGFX::CONSTRUCTION_GEOM & m_constructionGeomPreview
CONSTRUCTION_VIEW_HANDLER(KIGFX::CONSTRUCTION_GEOM &aHelper)
virtual void updateView()=0
KIGFX::CONSTRUCTION_GEOM & GetViewItem()
A base class for most all the KiCad significant classes used in schematics and boards.
Definition eda_item.h:98
A color representation with 4 components: red, green, blue, alpha.
Definition color4d.h:104
Shows construction geometry for things like line extensions, arc centers, etc.
std::variant< SEG, LINE, HALF_LINE, CIRCLE, SHAPE_ARC, VECTOR2I > DRAWABLE
OPT_VECTOR2I GetNearestSnapLinePoint(const VECTOR2I &aCursor, const VECTOR2I &aNearestGrid, std::optional< int > aDistToNearest, int snapRange, const VECTOR2D &aGridSize=VECTOR2D(0, 0), const VECTOR2I &aGridOrigin=VECTOR2I(0, 0)) const
If the snap line is active, return the best snap point that is closest to the cursor.
void SetDirections(const std::vector< VECTOR2I > &aDirections)
void SetSnappedAnchor(const VECTOR2I &aAnchorPos)
Inform this manager that an anchor snap has been made.
const std::vector< VECTOR2I > & GetDirections() const
CONSTRUCTION_VIEW_HANDLER & m_viewHandler
void ClearSnapLine()
Clear the snap line origin and end points.
std::vector< VECTOR2I > m_directions
SNAP_MANAGER * m_snapManager
bool HasCompleteSnapLine() const
SNAP_LINE_MANAGER(CONSTRUCTION_VIEW_HANDLER &aViewHandler)
std::optional< int > GetActiveDirection() const
void SetSnapLineOrigin(const VECTOR2I &aOrigin)
The snap point is a special point that is located at the last point the cursor snapped to.
std::optional< int > m_activeDirection
void SetSnapLineEnd(const OPT_VECTOR2I &aSnapPoint)
Set the end point of the snap line.
const OPT_VECTOR2I & GetSnapLineOrigin() const
A SNAP_MANAGER glues together the snap line manager and construction manager., along with some other ...
const SNAP_LINE_MANAGER & GetSnapLineManager() const
SNAP_LINE_MANAGER & GetSnapLineManager()
void SetSnapGuideColors(const KIGFX::COLOR4D &aBase, const KIGFX::COLOR4D &aHighlight)
KIGFX::COLOR4D m_snapGuideColor
KIGFX::COLOR4D m_snapGuideHighlightColor
CONSTRUCTION_MANAGER & GetConstructionManager()
GFX_UPDATE_CALLBACK m_updateCallback
std::vector< VECTOR2I > m_referenceOnlyPoints
CONSTRUCTION_MANAGER m_constructionManager
void SetUpdateCallback(GFX_UPDATE_CALLBACK aCallback)
Set the callback to call when the construction geometry changes and a view may need updating.
const std::vector< VECTOR2I > & GetReferenceOnlyPoints() const
std::function< void(bool aShowAnything)> GFX_UPDATE_CALLBACK
std::vector< CONSTRUCTION_MANAGER::CONSTRUCTION_ITEM_BATCH > GetConstructionItems() const
Get a list of all the active construction geometry, computed from the combined state of the snap line...
void updateView() override
SNAP_LINE_MANAGER m_snapLineManager
SNAP_MANAGER(KIGFX::CONSTRUCTION_GEOM &aHelper)
void SetReferenceOnlyPoints(std::vector< VECTOR2I > aPoints)
Set the reference-only points - these are points that are not snapped to, but can still be used for c...
std::optional< VECTOR2I > OPT_VECTOR2I
Definition seg.h:39
KIGFX::CONSTRUCTION_GEOM::DRAWABLE Drawable
int LineWidth
Items to be used for the construction of "virtual" anchors, for example, when snapping to a point inv...
std::vector< DRAWABLE_ENTRY > Constructions
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:695
VECTOR2< double > VECTOR2D
Definition vector2d.h:694