KiCad PCB EDA Suite
Loading...
Searching...
No Matches
managed_draw_behavior.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 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20#pragma once
21
22#include <eda_units.h>
23#include <math/vector2d.h>
25
26struct EDA_IU_SCALE;
27
28
40template <typename ManagerT, typename AssistantT>
42{
43 static_assert( std::is_base_of_v<EDA_ITEM, AssistantT>, "AssistantT must derive from EDA_ITEM" );
44
45public:
46 MANAGED_DRAW_BEHAVIOR( const EDA_IU_SCALE& aIuScale, EDA_UNITS aUnits ) :
47 m_manager(),
48 m_assistant( m_manager, aIuScale, aUnits )
49 {
50 }
51
52 //
53 // Non-geometry state interfaces
54 //
55
56 bool IsComplete() const override { return m_manager.IsComplete(); }
57 bool HasGeometryChanged() const override { return m_manager.HasGeometryChanged(); }
58 void ClearGeometryChanged() override { m_manager.ClearGeometryChanged(); }
59 void Reset() override { m_manager.Reset(); }
60
61 int GetStep() const override { return static_cast<int>( m_manager.GetStep() ); }
62
63 //
64 // Interactive geometry operations
65 //
66
67 void AddPoint( const VECTOR2I& aP ) override { m_manager.AddPoint( aP, true ); }
68 void SetCursorPosition( const VECTOR2I& aP ) override { m_manager.AddPoint( aP, false ); }
69 void RemoveLastPoint() override { m_manager.RemoveLastPoint(); }
70
71 // Assistant stuff
72
73 AssistantT& GetAssistant() override { return m_assistant; }
74 void SetUnits( EDA_UNITS aUnits ) override { m_assistant.SetUnits( aUnits ); }
75
76protected:
77 ManagerT m_manager;
78 AssistantT m_assistant;
79};
void RemoveLastPoint() override
Undo the last locked-in point.
void Reset() override
Reset the behaviour to its initial state for chained object creation loops.
bool IsComplete() const override
True when all points have been locked in.
void SetCursorPosition(const VECTOR2I &aP) override
Preview the cursor position without advancing state.
AssistantT & GetAssistant() override
Return the visual assistant overlay item.
void ClearGeometryChanged() override
Reset the geometry-changed flag (call after updating the preview).
bool HasGeometryChanged() const override
True if the geometry changed since the last call to ClearGeometryChanged().
int GetStep() const override
Return the current construction step (0-based, shape-specific meaning).
void SetUnits(EDA_UNITS aUnits) override
Forward a units change to the assistant overlay.
MANAGED_DRAW_BEHAVIOR(const EDA_IU_SCALE &aIuScale, EDA_UNITS aUnits)
void AddPoint(const VECTOR2I &aP) override
Lock in a point and advance the construction state.
Abstract interface for interactive shape-drawing behaviours.
EDA_UNITS
Definition eda_units.h:44
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683