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 (C) 2024 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 <vector>
28#include <deque>
29
31
32class EDA_ITEM;
33
41{
42public:
44
52 enum class SOURCE
53 {
56 };
57
59 {
62 std::vector<KIGFX::CONSTRUCTION_GEOM::DRAWABLE> Constructions;
63 };
64
65 // A single batch of construction items. Once batch contains all the items (and associated
66 // construction geometry) that should be shown for one point of interest.
67 // More than one batch may be shown on the screen at the same time.
68 using CONSTRUCTION_ITEM_BATCH = std::vector<CONSTRUCTION_ITEM>;
69
78 void AddConstructionItems( CONSTRUCTION_ITEM_BATCH aBatch, bool aIsPersistent );
79
84 bool InvolvesAllGivenRealItems( const std::vector<EDA_ITEM*>& aItems ) const;
85
90 void SetReferenceOnlyPoints( std::vector<VECTOR2I> aPoints )
91 {
92 m_referenceOnlyPoints = std::move( aPoints );
93 }
94
95 const std::vector<VECTOR2I>& GetReferenceOnlyPoints() const { return m_referenceOnlyPoints; }
96
103 void SetSnapLineOrigin( const VECTOR2I& aOrigin );
104
110 void SetSnapLineEnd( const OPT_VECTOR2I& aSnapPoint );
111
115 void ClearSnapLine();
116
117 std::optional<VECTOR2I> GetSnapLineOrigin() const { return m_snapLineOrigin; }
118
124 void SetSnappedAnchor( const VECTOR2I& aAnchorPos );
125
126 // Get the list of additional geometry items that should be considered
127 std::vector<CONSTRUCTION_ITEM_BATCH> GetConstructionItems() const;
128
144 OPT_VECTOR2I GetNearestSnapLinePoint( const VECTOR2I& aCursor, const VECTOR2I& aNearestGrid,
145 std::optional<int> aDistToNearest, int snapRange ) const;
146
147 using GFX_UPDATE_CALLBACK = std::function<void( bool )>;
151 void SetUpdateCallback( GFX_UPDATE_CALLBACK aCallback ) { m_updateCallback = aCallback; }
152
153private:
154 void updateView();
155
156 // An (external) construction helper view item, that this manager adds/removes
157 // construction objects to/from.
159
160 // Within one "operation", there is one set of construction items that are
161 // "persistent", and are always shown. Usually the original item and any
162 // extensions.
163 std::optional<CONSTRUCTION_ITEM_BATCH> m_persistentConstructionBatch;
164
165 // Temporary construction items are added and removed as needed
166 std::deque<CONSTRUCTION_ITEM_BATCH> m_temporaryConstructionBatches;
167
168 // Set of all items for which construction geometry has been added
169 std::set<EDA_ITEM*> m_involvedItems;
170
171 std::vector<VECTOR2I> m_referenceOnlyPoints;
172
173 // If a snap point is "active", extra construction geometry is added to the helper
174 // extending from the snap point to the cursor.
177
179};
A class that mananges "construction" objects and geometry.
KIGFX::CONSTRUCTION_GEOM & m_constructionGeomPreview
void AddConstructionItems(CONSTRUCTION_ITEM_BATCH aBatch, bool aIsPersistent)
Add a batch of construction items to the helper.
void ClearSnapLine()
Clear the snap line origin and end points.
SOURCE
Items to be used for the construction of "virtual" anchors, for example, when snapping to a point inv...
const std::vector< VECTOR2I > & GetReferenceOnlyPoints() const
std::deque< CONSTRUCTION_ITEM_BATCH > m_temporaryConstructionBatches
GFX_UPDATE_CALLBACK m_updateCallback
void SetSnappedAnchor(const VECTOR2I &aAnchorPos)
Inform the construction manager that an anchor snap is wanted.
std::vector< CONSTRUCTION_ITEM_BATCH > GetConstructionItems() const
OPT_VECTOR2I GetNearestSnapLinePoint(const VECTOR2I &aCursor, const VECTOR2I &aNearestGrid, std::optional< int > aDistToNearest, int snapRange) const
If the snap line is active, return the best snap point that is closest to the cursor.
std::vector< CONSTRUCTION_ITEM > CONSTRUCTION_ITEM_BATCH
std::optional< CONSTRUCTION_ITEM_BATCH > m_persistentConstructionBatch
std::vector< VECTOR2I > m_referenceOnlyPoints
void SetSnapLineOrigin(const VECTOR2I &aOrigin)
The snap point is a special point that is located at the last point the cursor snapped to.
void SetSnapLineEnd(const OPT_VECTOR2I &aSnapPoint)
Set the end point of the snap line.
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...
std::optional< VECTOR2I > GetSnapLineOrigin() const
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::function< void(bool)> GFX_UPDATE_CALLBACK
void SetUpdateCallback(GFX_UPDATE_CALLBACK aCallback)
Set the callback to call when the construction geometry changes and a view may need updating.
std::set< EDA_ITEM * > m_involvedItems
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:89
Shows construction geometry for things like line extensions, arc centers, etc.
std::optional< VECTOR2I > OPT_VECTOR2I
Definition: seg.h:39
std::vector< KIGFX::CONSTRUCTION_GEOM::DRAWABLE > Constructions