2017-02-26 20:08:45 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2021-01-25 12:42:36 +00:00
|
|
|
* Copyright (C) 2017-2021 Kicad Developers, see AUTHORS.txt for contributors.
|
2017-02-26 20:08:45 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef PREVIEW_ITEMS_ARC_GEOMETRY_MANAGER_H
|
|
|
|
#define PREVIEW_ITEMS_ARC_GEOMETRY_MANAGER_H
|
|
|
|
|
|
|
|
#include <preview_items/multistep_geom_manager.h>
|
2022-01-20 16:39:28 +00:00
|
|
|
#include <geometry/eda_angle.h>
|
2017-02-26 20:08:45 +00:00
|
|
|
|
|
|
|
namespace KIGFX {
|
|
|
|
namespace PREVIEW {
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2021-01-25 12:42:36 +00:00
|
|
|
* Manage the construction of a circular arc though sequential setting of critical points:
|
|
|
|
* center, arc start and arc end. The manager is driven by setting cursor points, which
|
2017-02-26 20:08:45 +00:00
|
|
|
* update the geometry, and optionally advance the manager state.
|
|
|
|
*
|
2021-01-25 12:42:36 +00:00
|
|
|
* Interfaces are provided to return both arc geometry (can be used to set up real arcs on
|
|
|
|
* PCBs, for example) as well as important control points for informational overlays.
|
2017-02-26 20:08:45 +00:00
|
|
|
*/
|
|
|
|
class ARC_GEOM_MANAGER: public MULTISTEP_GEOM_MANAGER
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ARC_GEOM_MANAGER()
|
|
|
|
{}
|
|
|
|
|
|
|
|
enum ARC_STEPS
|
|
|
|
{
|
2021-01-25 12:42:36 +00:00
|
|
|
SET_ORIGIN = 0, ///< Waiting to lock in origin point
|
|
|
|
SET_START, ///< Waiting to lock in the arc start point
|
|
|
|
SET_ANGLE, ///< Waiting to lock in the arc end point
|
2017-02-26 20:08:45 +00:00
|
|
|
COMPLETE
|
|
|
|
};
|
|
|
|
|
|
|
|
int getMaxStep() const override
|
|
|
|
{
|
|
|
|
return COMPLETE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-01-25 12:42:36 +00:00
|
|
|
* Get the current step the manager is on (useful when drawing
|
2017-02-26 20:08:45 +00:00
|
|
|
* something depends on the current state)
|
|
|
|
*/
|
|
|
|
ARC_STEPS GetStep() const
|
|
|
|
{
|
|
|
|
return static_cast<ARC_STEPS>( getStep() );
|
|
|
|
}
|
|
|
|
|
|
|
|
bool acceptPoint( const VECTOR2I& aPt ) override;
|
|
|
|
|
2021-06-09 19:32:58 +00:00
|
|
|
///< The arc to be clockwise from start
|
2017-02-26 20:08:45 +00:00
|
|
|
void SetClockwise( bool aCw );
|
|
|
|
|
2021-01-25 12:42:36 +00:00
|
|
|
///< Reverse the current are direction
|
2017-02-26 20:08:45 +00:00
|
|
|
void ToggleClockwise();
|
|
|
|
|
2021-01-25 12:42:36 +00:00
|
|
|
///< Set angle snapping (for the next point)
|
2017-02-26 20:08:45 +00:00
|
|
|
void SetAngleSnap( bool aSnap )
|
|
|
|
{
|
|
|
|
m_angleSnap = aSnap;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Geometry query interface - used by clients of the manager
|
|
|
|
*/
|
|
|
|
|
2021-01-25 12:42:36 +00:00
|
|
|
///< Get the center point of the arc (valid when state > SET_ORIGIN)
|
2017-02-26 20:08:45 +00:00
|
|
|
VECTOR2I GetOrigin() const;
|
|
|
|
|
2021-01-25 12:42:36 +00:00
|
|
|
///< Get the coordinates of the arc start
|
2017-02-26 20:08:45 +00:00
|
|
|
VECTOR2I GetStartRadiusEnd() const;
|
|
|
|
|
2021-01-25 12:42:36 +00:00
|
|
|
///< Get the coordinates of the arc end point
|
2017-02-26 20:08:45 +00:00
|
|
|
VECTOR2I GetEndRadiusEnd() const;
|
|
|
|
|
2021-01-25 12:42:36 +00:00
|
|
|
///< Get the radius of the arc (valid if step >= SET_START)
|
2017-02-26 20:08:45 +00:00
|
|
|
double GetRadius() const;
|
|
|
|
|
2021-01-25 12:42:36 +00:00
|
|
|
///< Get the angle of the vector leading to the start point (valid if step >= SET_START)
|
2022-01-20 16:39:28 +00:00
|
|
|
EDA_ANGLE GetStartAngle() const;
|
2017-02-26 20:08:45 +00:00
|
|
|
|
2021-01-25 12:42:36 +00:00
|
|
|
///< Get the angle of the vector leading to the end point (valid if step >= SET_ANGLE)
|
2022-01-20 16:39:28 +00:00
|
|
|
EDA_ANGLE GetSubtended() const;
|
2017-02-26 20:08:45 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Point acceptor functions
|
|
|
|
*/
|
|
|
|
|
2021-01-25 12:42:36 +00:00
|
|
|
///< Set the center point of the arc
|
2017-02-26 20:08:45 +00:00
|
|
|
bool setOrigin( const VECTOR2I& aOrigin );
|
|
|
|
|
2021-01-25 12:42:36 +00:00
|
|
|
///< Set the end of the first radius line (arc start)
|
2017-02-26 20:08:45 +00:00
|
|
|
bool setStart( const VECTOR2I& aEnd );
|
|
|
|
|
2021-01-25 12:42:36 +00:00
|
|
|
///< Set a point of the second radius line (collinear with arc end)
|
2017-02-26 20:08:45 +00:00
|
|
|
bool setEnd( const VECTOR2I& aCursor );
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Arc geometry
|
|
|
|
*/
|
2022-01-20 16:39:28 +00:00
|
|
|
bool m_clockwise = true;
|
|
|
|
VECTOR2I m_origin;
|
|
|
|
double m_radius = 0.0;
|
|
|
|
EDA_ANGLE m_startAngle;
|
|
|
|
EDA_ANGLE m_endAngle;
|
2017-02-26 20:08:45 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* construction parameters
|
|
|
|
*/
|
2018-01-06 05:02:28 +00:00
|
|
|
bool m_angleSnap = false;
|
2020-07-03 15:05:17 +00:00
|
|
|
bool m_directionLocked = false;
|
2017-02-26 20:08:45 +00:00
|
|
|
};
|
|
|
|
} // PREVIEW
|
|
|
|
} // KIGFX
|
|
|
|
|
|
|
|
#endif // PREVIEW_ITEMS_ARC_GEOMETRY_MANAGER_H
|