KiCad PCB EDA Suite
Loading...
Searching...
No Matches
bezier_geom_manager.cpp
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 * 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, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
25
26using namespace KIGFX::PREVIEW;
27
28
30{
31 switch( getStep() )
32 {
33 case SET_START: return setStart( aPt );
34 case SET_CONTROL1: return setControlC1( aPt );
35 case SET_END: return setEnd( aPt );
36 case SET_CONTROL2: return setControlC2( aPt );
37 case COMPLETE: return false;
38 }
39
40 return false;
41}
42
43
45{
46 return m_start;
47}
48
50{
51 return m_controlC1;
52}
53
55{
56 return m_end;
57}
58
60{
61 // The actual bezier C2 point is the reflection over the end point
62 // so that the cursor will be on the C1 point of the next bezier.
63 return m_end - ( m_controlC2 - m_end );
64}
65
67{
68 m_start = aStart;
69 // Prevents wierd-looking loops if the control points aren't initialized
70 m_end = aStart;
71 m_controlC1 = aStart;
72 m_controlC2 = aStart;
73 return true;
74}
75
76
78{
79 m_controlC1 = aControlC1;
82 // It's possible to set the control 1 point to the same as the start point
83 return true;
84}
85
87{
88 m_end = aEnd;
90 return m_end != m_start;
91}
92
94{
95 m_controlC2 = aControlC2;
96 // It's possible to set the control 2 point to the same as the end point
97 return true;
98}
VECTOR2I GetControlC2() const
Get the coordinates of the arc end point.
VECTOR2I GetStart() const
< Get the center point of the arc (valid when state > SET_ORIGIN)
bool acceptPoint(const VECTOR2I &aPt) override
< Function that accepts a point for a stage, or rejects it to return to the previous stage
bool setEnd(const VECTOR2I &aCursor)
@ SET_CONTROL2
Waiting to lock in the second control point.
@ SET_END
Waiting to lock in the end point.
@ SET_CONTROL1
Waiting to lock in the first control point.
@ SET_START
Waiting to lock in the start point.
bool setControlC1(const VECTOR2I &aControl)
bool setControlC2(const VECTOR2I &aControl)
bool setStart(const VECTOR2I &aOrigin)
< Set the center point of the arc