KiCad PCB EDA Suite
Loading...
Searching...
No Matches
arc_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 <geometry/eda_angle.h>
23#include <math/vector2d.h>
24#include <eda_units.h>
25#include <eda_shape.h>
28
29
30struct EDA_IU_SCALE;
31
32
37class ARC_DRAW_BEHAVIOR : public MANAGED_DRAW_BEHAVIOR<KIGFX::PREVIEW::ARC_GEOM_MANAGER, KIGFX::PREVIEW::ARC_ASSISTANT>
38{
39public:
41
44
45 void SetAngleSnap( bool aSnap ) override { m_manager.SetAngleSnap( aSnap ); }
46 void ToggleClockwise() override { m_manager.ToggleClockwise(); }
47
48 void SetArcDrawMode( ARC_DRAW_MODE aMode ) override { m_manager.SetMode( aMode ); }
49
50 void SetTangentSeed( const VECTOR2I& aStart, const VECTOR2D& aDirection, bool aDirectionIsAxis = false ) override
51 {
52 m_manager.SetTangentSeed( aStart, aDirection, aDirectionIsAxis );
53 }
54
55 bool OnProperties( EDA_SHAPE& aShape ) override
56 {
57 if( m_manager.UsesExactEndpoints() )
58 {
59 // Once the arc is determined, hand over what the preview shows
60 if( !m_manager.GetSolution().valid )
61 return false;
62
63 ApplyToShape( aShape );
64 return true;
65 }
66
68 {
70 return true;
71 }
72
74 && m_manager.GetStartRadiusEnd() != m_manager.GetEndRadiusEnd() )
75 {
76 return true;
77 }
78
79 return false;
80 }
81
82 void ApplyToShape( EDA_SHAPE& aShape ) const override
83 {
84 // Winding follows the midpoint, and the clicked endpoints are kept exactly
85 if( m_manager.UsesExactEndpoints() && m_manager.GetSolution().valid )
86 {
87 const KIGEOM::ARC_SOLUTION& solution = m_manager.GetSolution();
88
89 aShape.SetArcGeometry( solution.start, solution.mid, solution.end );
90 return;
91 }
92
93 const VECTOR2I center = m_manager.GetOrigin();
94 aShape.SetCenter( center );
95
96 // Swap start/end when clockwise so EDA_SHAPE stores them in geometric order.
97 if( m_manager.GetSubtended() < ANGLE_0 )
98 {
99 aShape.SetStart( m_manager.GetStartRadiusEnd() );
100 aShape.SetEnd( m_manager.GetEndRadiusEnd() );
101 }
102 else
103 {
104 aShape.SetStart( m_manager.GetEndRadiusEnd() );
105 aShape.SetEnd( m_manager.GetStartRadiusEnd() );
106 }
107 }
108};
ARC_DRAW_MODE
Construction sequence used when interactively drawing a circular arc.
void SetTangentSeed(const VECTOR2I &aStart, const VECTOR2D &aDirection, bool aDirectionIsAxis=false) override
Preload the start point and departure direction for ARC_DRAW_MODE::TANGENT.
bool OnProperties(EDA_SHAPE &aShape) override
Called when the user invokes the properties action mid-draw.
void ToggleClockwise() override
Flip arc direction (applies only when the shape has such a concept of directionality,...
ARC_DRAW_BEHAVIOR(const ARC_DRAW_BEHAVIOR &)=delete
ARC_DRAW_BEHAVIOR & operator=(const ARC_DRAW_BEHAVIOR &)=delete
void ApplyToShape(EDA_SHAPE &aShape) const override
Transfer the current geometry to an EDA_SHAPE.
MANAGED_DRAW_BEHAVIOR(const EDA_IU_SCALE &aIuScale, EDA_UNITS aUnits)
void SetArcDrawMode(ARC_DRAW_MODE aMode) override
Select the construction sequence (circular arcs only; no-op for others).
void SetAngleSnap(bool aSnap) override
Enable or disable angle snapping (circular arcs only; no-op for others).
virtual void SetEnd(const VECTOR2I &aEnd)
Definition eda_shape.h:329
void SetCenter(const VECTOR2I &aCenter)
virtual void SetArcGeometry(const VECTOR2I &aStart, const VECTOR2I &aMid, const VECTOR2I &aEnd)
Set the three controlling points for an arc.
void SetArcAngleAndEnd(const EDA_ANGLE &aAngle, bool aCheckNegativeAngle=false)
Set the end point from the angle center and start.
virtual void SetStart(const VECTOR2I &aStart)
Definition eda_shape.h:279
@ THIRD_POINT
Waiting to lock in the third point.
@ SECOND_POINT
Waiting to lock in the second point.
MANAGED_DRAW_BEHAVIOR(const EDA_IU_SCALE &aIuScale, EDA_UNITS aUnits)
static constexpr EDA_ANGLE ANGLE_0
Definition eda_angle.h:448
static constexpr EDA_ANGLE ANGLE_90
Definition eda_angle.h:450
VECTOR2I mid
The point on the arc halfway along the sweep.
VECTOR2I center
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708
VECTOR2< double > VECTOR2D
Definition vector2d.h:707