KiCad PCB EDA Suite
|
A class that mananges "construction" objects and geometry. More...
#include <construction_manager.h>
Classes | |
struct | CONSTRUCTION_ITEM |
Public Types | |
enum class | SOURCE { FROM_ITEMS , FROM_SNAP_LINE } |
Items to be used for the construction of "virtual" anchors, for example, when snapping to a point involving an extension of an existing line or arc. More... | |
using | CONSTRUCTION_ITEM_BATCH = std::vector< CONSTRUCTION_ITEM > |
using | GFX_UPDATE_CALLBACK = std::function< void(bool)> |
Public Member Functions | |
CONSTRUCTION_MANAGER (KIGFX::CONSTRUCTION_GEOM &aHelper) | |
void | AddConstructionItems (CONSTRUCTION_ITEM_BATCH aBatch, bool aIsPersistent) |
Add a batch of construction items to the helper. | |
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 currently 'involved' in an active construction. | |
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 connection to the snap line. | |
const std::vector< VECTOR2I > & | GetReferenceOnlyPoints () const |
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. | |
void | ClearSnapLine () |
Clear the snap line origin and end points. | |
std::optional< VECTOR2I > | GetSnapLineOrigin () const |
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. | |
void | SetUpdateCallback (GFX_UPDATE_CALLBACK aCallback) |
Set the callback to call when the construction geometry changes and a view may need updating. | |
Private Member Functions | |
void | updateView () |
Private Attributes | |
KIGFX::CONSTRUCTION_GEOM & | m_constructionGeomPreview |
std::optional< CONSTRUCTION_ITEM_BATCH > | m_persistentConstructionBatch |
std::deque< CONSTRUCTION_ITEM_BATCH > | m_temporaryConstructionBatches |
std::set< EDA_ITEM * > | m_involvedItems |
std::vector< VECTOR2I > | m_referenceOnlyPoints |
OPT_VECTOR2I | m_snapLineOrigin |
OPT_VECTOR2I | m_snapLineEnd |
GFX_UPDATE_CALLBACK | m_updateCallback |
A class that mananges "construction" objects and geometry.
Probably only used by GRID_HELPERs, but it's neater to keep it separate, as there's quite a bit of state to manage.
Definition at line 40 of file construction_manager.h.
using CONSTRUCTION_MANAGER::CONSTRUCTION_ITEM_BATCH = std::vector<CONSTRUCTION_ITEM> |
Definition at line 68 of file construction_manager.h.
using CONSTRUCTION_MANAGER::GFX_UPDATE_CALLBACK = std::function<void( bool )> |
Definition at line 147 of file construction_manager.h.
|
strong |
Items to be used for the construction of "virtual" anchors, for example, when snapping to a point involving an extension of an existing line or arc.
One item can have multiple construction items (e.g. an arc can have a circle and centre point).
Enumerator | |
---|---|
FROM_ITEMS | |
FROM_SNAP_LINE |
Definition at line 52 of file construction_manager.h.
CONSTRUCTION_MANAGER::CONSTRUCTION_MANAGER | ( | KIGFX::CONSTRUCTION_GEOM & | aHelper | ) |
Definition at line 27 of file construction_manager.cpp.
void CONSTRUCTION_MANAGER::AddConstructionItems | ( | CONSTRUCTION_ITEM_BATCH | aBatch, |
bool | aIsPersistent | ||
) |
Add a batch of construction items to the helper.
aBatch | The batch of construction items to add. |
aIsPersistent | If true, the batch is considered "persistent" and will always be shown (and it will replace any previous persistent batch). If false, the batch is temporary and may be pushed out by other batches. |
Definition at line 43 of file construction_manager.cpp.
References KIGFX::CONSTRUCTION_GEOM::AddDrawable(), KIGFX::CONSTRUCTION_GEOM::ClearDrawables(), m_constructionGeomPreview, m_involvedItems, m_persistentConstructionBatch, m_temporaryConstructionBatches, and updateView().
Referenced by PCB_GRID_HELPER::AddConstructionItems().
void CONSTRUCTION_MANAGER::ClearSnapLine | ( | ) |
Clear the snap line origin and end points.
Definition at line 153 of file construction_manager.cpp.
References KIGFX::CONSTRUCTION_GEOM::ClearSnapLine(), m_constructionGeomPreview, m_snapLineEnd, m_snapLineOrigin, and updateView().
Referenced by EE_GRID_HELPER::BestSnapAnchor(), and SetSnapLineOrigin().
std::vector< CONSTRUCTION_MANAGER::CONSTRUCTION_ITEM_BATCH > CONSTRUCTION_MANAGER::GetConstructionItems | ( | ) | const |
Definition at line 184 of file construction_manager.cpp.
References CONSTRUCTION_MANAGER::CONSTRUCTION_ITEM::Constructions, FROM_SNAP_LINE, m_persistentConstructionBatch, m_snapLineOrigin, and m_temporaryConstructionBatches.
OPT_VECTOR2I CONSTRUCTION_MANAGER::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.
If there's no active snap line, return std::nullopt.
If there's a snap very near, use that otherwise, use the grid point. With this point, snap to it on an H/V axis.
Then, if there's a grid point near, snap to it on an H/V axis
aCursor | The cursor position |
aNearestGrid | The nearest grid point to the cursor |
aDistToNearest | The distance to the nearest non-grid snap point, if any |
snapRange | The snap range |
Allows de-snapping from the line if you are closer to another snap point Or if you have moved far enough away from the line
Definition at line 253 of file construction_manager.cpp.
References DEGREES_T, m_snapLineOrigin, pointHasEscapedSnapLineX(), pointHasEscapedSnapLineY(), VECTOR2< T >::x, and VECTOR2< T >::y.
Referenced by PCB_GRID_HELPER::BestSnapAnchor().
|
inline |
Definition at line 95 of file construction_manager.h.
References m_referenceOnlyPoints.
Referenced by PCB_GRID_HELPER::BestSnapAnchor().
|
inline |
Definition at line 117 of file construction_manager.h.
References m_snapLineOrigin.
Referenced by EE_GRID_HELPER::BestSnapAnchor().
bool CONSTRUCTION_MANAGER::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 currently 'involved' in an active construction.
Definition at line 117 of file construction_manager.cpp.
References m_involvedItems.
Referenced by PCB_GRID_HELPER::BestSnapAnchor().
|
inline |
Set the reference-only points - these are points that are not snapped to, but can still be used for connection to the snap line.
Definition at line 90 of file construction_manager.h.
References m_referenceOnlyPoints.
Referenced by PCB_GRID_HELPER::AddConstructionItems().
void CONSTRUCTION_MANAGER::SetSnapLineEnd | ( | const OPT_VECTOR2I & | aSnapPoint | ) |
Set the end point of the snap line.
Passing std::nullopt will unset the end point, but keep the origin.
Definition at line 138 of file construction_manager.cpp.
References KIGFX::CONSTRUCTION_GEOM::ClearSnapLine(), m_constructionGeomPreview, m_snapLineEnd, m_snapLineOrigin, KIGFX::CONSTRUCTION_GEOM::SetSnapLine(), and updateView().
Referenced by PCB_GRID_HELPER::BestSnapAnchor(), EE_GRID_HELPER::BestSnapAnchor(), and SetSnappedAnchor().
void CONSTRUCTION_MANAGER::SetSnapLineOrigin | ( | const VECTOR2I & | aOrigin | ) |
The snap point is a special point that is located at the last point the cursor snapped to.
If it is set, the construction manager may add extra construction geometry to the helper extending from the snap point origin to the cursor, which is the 'snap line'.
Definition at line 131 of file construction_manager.cpp.
References ClearSnapLine(), and m_snapLineOrigin.
Referenced by PCB_GRID_HELPER::BestSnapAnchor(), EE_GRID_HELPER::BestSnapAnchor(), and SetSnappedAnchor().
void CONSTRUCTION_MANAGER::SetSnappedAnchor | ( | const VECTOR2I & | aAnchorPos | ) |
Inform the construction manager that an anchor snap is wanted.
This will also update the snap line if appropriate.
Definition at line 161 of file construction_manager.cpp.
References m_snapLineOrigin, SetSnapLineEnd(), SetSnapLineOrigin(), VECTOR2< T >::x, and VECTOR2< T >::y.
Referenced by PCB_GRID_HELPER::BestSnapAnchor().
|
inline |
Set the callback to call when the construction geometry changes and a view may need updating.
Definition at line 151 of file construction_manager.h.
References m_updateCallback.
Referenced by GRID_HELPER::GRID_HELPER().
|
private |
Definition at line 32 of file construction_manager.cpp.
References m_persistentConstructionBatch, m_snapLineEnd, m_snapLineOrigin, m_temporaryConstructionBatches, and m_updateCallback.
Referenced by AddConstructionItems(), ClearSnapLine(), and SetSnapLineEnd().
|
private |
Definition at line 158 of file construction_manager.h.
Referenced by AddConstructionItems(), ClearSnapLine(), and SetSnapLineEnd().
|
private |
Definition at line 169 of file construction_manager.h.
Referenced by AddConstructionItems(), and InvolvesAllGivenRealItems().
|
private |
Definition at line 163 of file construction_manager.h.
Referenced by AddConstructionItems(), GetConstructionItems(), and updateView().
|
private |
Definition at line 171 of file construction_manager.h.
Referenced by GetReferenceOnlyPoints(), and SetReferenceOnlyPoints().
|
private |
Definition at line 176 of file construction_manager.h.
Referenced by ClearSnapLine(), SetSnapLineEnd(), and updateView().
|
private |
Definition at line 175 of file construction_manager.h.
Referenced by ClearSnapLine(), GetConstructionItems(), GetNearestSnapLinePoint(), GetSnapLineOrigin(), SetSnapLineEnd(), SetSnapLineOrigin(), SetSnappedAnchor(), and updateView().
|
private |
Definition at line 166 of file construction_manager.h.
Referenced by AddConstructionItems(), GetConstructionItems(), and updateView().
|
private |
Definition at line 178 of file construction_manager.h.
Referenced by SetUpdateCallback(), and updateView().