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>
27
28struct EDA_IU_SCALE;
29class EDA_SHAPE;
30
31
35class ARC_DRAW_BEHAVIOR : public MANAGED_DRAW_BEHAVIOR<KIGFX::PREVIEW::ARC_GEOM_MANAGER, KIGFX::PREVIEW::ARC_ASSISTANT>
36{
37public:
39
42
43 void SetAngleSnap( bool aSnap ) override { m_manager.SetAngleSnap( aSnap ); }
44 void ToggleClockwise() override { m_manager.ToggleClockwise(); }
45
46 bool OnProperties( EDA_SHAPE& aShape ) override
47 {
49 {
51 return true;
52 }
53
55 && m_manager.GetStartRadiusEnd() != m_manager.GetEndRadiusEnd() )
56 {
57 return true;
58 }
59
60 return false;
61 }
62
63 void ApplyToShape( EDA_SHAPE& aShape ) const override
64 {
65 const VECTOR2I center = m_manager.GetOrigin();
66 aShape.SetCenter( center );
67
68 // Swap start/end when clockwise so EDA_SHAPE stores them in geometric order.
69 if( m_manager.GetSubtended() < ANGLE_0 )
70 {
71 aShape.SetStart( m_manager.GetStartRadiusEnd() );
72 aShape.SetEnd( m_manager.GetEndRadiusEnd() );
73 }
74 else
75 {
76 aShape.SetStart( m_manager.GetEndRadiusEnd() );
77 aShape.SetEnd( m_manager.GetStartRadiusEnd() );
78 }
79 }
80};
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 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:244
void SetCenter(const VECTOR2I &aCenter)
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:194
@ SET_ANGLE
Waiting to lock in the arc end point.
@ SET_START
Waiting to lock in the arc start point.
MANAGED_DRAW_BEHAVIOR(const EDA_IU_SCALE &aIuScale, EDA_UNITS aUnits)
static constexpr EDA_ANGLE ANGLE_0
Definition eda_angle.h:411
static constexpr EDA_ANGLE ANGLE_90
Definition eda_angle.h:413
VECTOR2I center
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683