2017-02-26 17:45:52 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KICAD, a free EDA CAD application.
|
|
|
|
*
|
2022-12-09 16:11:56 +00:00
|
|
|
* Copyright (C) 2017-2022 Kicad Developers, see AUTHORS.txt for contributors.
|
2017-02-26 17:45:52 +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_POLYGON_GEOM_MANAGER__H_
|
|
|
|
#define PREVIEW_POLYGON_GEOM_MANAGER__H_
|
|
|
|
|
2018-02-19 10:20:52 +00:00
|
|
|
#include <geometry/shape_line_chain.h>
|
2017-02-26 17:45:52 +00:00
|
|
|
|
|
|
|
/**
|
2021-01-25 12:42:36 +00:00
|
|
|
* Class that handles the drawing of a polygon, including management of last corner deletion
|
|
|
|
* and drawing of leader lines with various constraints (eg 45 deg only).
|
2017-02-26 17:45:52 +00:00
|
|
|
*
|
|
|
|
* This class handles only the geometry of the process.
|
|
|
|
*/
|
|
|
|
class POLYGON_GEOM_MANAGER
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
/**
|
|
|
|
* "Listener" interface for a class that wants to be updated about
|
|
|
|
* polygon geometry changes
|
|
|
|
*/
|
|
|
|
class CLIENT
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Called before the first point is added - clients can do
|
2021-01-25 12:42:36 +00:00
|
|
|
* initialization here, and can veto the start of the process
|
2018-02-19 10:20:52 +00:00
|
|
|
* (e.g. if user cancels a dialog)
|
2017-02-26 17:45:52 +00:00
|
|
|
*
|
|
|
|
* @return false to veto start of new polygon
|
|
|
|
*/
|
2018-02-20 14:51:40 +00:00
|
|
|
virtual bool OnFirstPoint( POLYGON_GEOM_MANAGER& aMgr ) = 0;
|
2017-02-26 17:45:52 +00:00
|
|
|
|
2021-01-25 12:42:36 +00:00
|
|
|
///< Sent when the polygon geometry changes
|
2017-02-26 17:45:52 +00:00
|
|
|
virtual void OnGeometryChange( const POLYGON_GEOM_MANAGER& aMgr ) = 0;
|
|
|
|
|
2021-01-25 12:42:36 +00:00
|
|
|
///< Called when the polygon is complete
|
2017-02-26 17:45:52 +00:00
|
|
|
virtual void OnComplete( const POLYGON_GEOM_MANAGER& aMgr ) = 0;
|
2020-02-05 22:19:14 +00:00
|
|
|
|
|
|
|
virtual ~CLIENT()
|
|
|
|
{
|
|
|
|
}
|
2017-02-26 17:45:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The kind of the leader line
|
|
|
|
*/
|
|
|
|
enum class LEADER_MODE
|
|
|
|
{
|
2021-01-25 12:42:36 +00:00
|
|
|
DIRECT, ///< Unconstrained point-to-point
|
|
|
|
DEG45, ///< 45 Degree only
|
2017-02-26 17:45:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2017-06-21 07:32:19 +00:00
|
|
|
* @param aClient is the client to pass the results onto
|
2017-02-26 17:45:52 +00:00
|
|
|
*/
|
|
|
|
POLYGON_GEOM_MANAGER( CLIENT& aClient );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Lock in a polygon point.
|
|
|
|
*/
|
2018-01-01 21:14:08 +00:00
|
|
|
bool AddPoint( const VECTOR2I& aPt );
|
2017-02-26 17:45:52 +00:00
|
|
|
|
|
|
|
/**
|
2021-01-25 12:42:36 +00:00
|
|
|
* Mark the polygon finished and update the client.
|
2017-02-26 17:45:52 +00:00
|
|
|
*/
|
|
|
|
void SetFinished();
|
|
|
|
|
|
|
|
/**
|
2021-01-25 12:42:36 +00:00
|
|
|
* Clear the manager state and start again.
|
2017-02-26 17:45:52 +00:00
|
|
|
*/
|
|
|
|
void Reset();
|
|
|
|
|
|
|
|
/**
|
2021-01-25 12:42:36 +00:00
|
|
|
* Set the leader mode to use when calculating the leader/returner lines.
|
2017-02-26 17:45:52 +00:00
|
|
|
*/
|
|
|
|
void SetLeaderMode( LEADER_MODE aMode );
|
|
|
|
|
2019-08-26 13:30:03 +00:00
|
|
|
LEADER_MODE GetLeaderMode() const
|
|
|
|
{
|
|
|
|
return m_leaderMode;
|
|
|
|
}
|
|
|
|
|
2018-02-19 14:25:07 +00:00
|
|
|
/**
|
|
|
|
* Enables/disables self-intersecting polygons.
|
2021-01-25 12:42:36 +00:00
|
|
|
*
|
2018-02-19 14:25:07 +00:00
|
|
|
* @param aEnabled true if self-intersecting polygons are enabled.
|
|
|
|
*/
|
|
|
|
void AllowIntersections( bool aEnabled )
|
|
|
|
{
|
|
|
|
m_intersectionsAllowed = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-01-25 12:42:36 +00:00
|
|
|
* Check whether self-intersecting polygons are enabled.
|
|
|
|
*
|
2018-02-19 14:25:07 +00:00
|
|
|
* @return true if self-intersecting polygons are enabled.
|
|
|
|
*/
|
|
|
|
bool IntersectionsAllowed() const
|
|
|
|
{
|
|
|
|
return m_intersectionsAllowed;
|
|
|
|
}
|
|
|
|
|
2018-03-02 09:55:59 +00:00
|
|
|
/**
|
2021-01-25 12:42:36 +00:00
|
|
|
* Check whether the locked points constitute a self-intersecting outline.
|
|
|
|
*
|
2018-03-02 09:55:59 +00:00
|
|
|
* @param aIncludeLeaderPts when true, also the leading points (not placed ones) will be tested.
|
|
|
|
* @return True when the outline is self-intersecting.
|
|
|
|
*/
|
|
|
|
bool IsSelfIntersecting( bool aIncludeLeaderPts ) const;
|
|
|
|
|
2017-02-26 17:45:52 +00:00
|
|
|
/**
|
|
|
|
* Set the current cursor position
|
|
|
|
*/
|
2019-10-20 16:27:44 +00:00
|
|
|
void SetCursorPosition( const VECTOR2I& aPos );
|
2017-02-26 17:45:52 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return true if the polygon in "in progress", i.e. it has at least
|
|
|
|
* one locked-in point
|
|
|
|
*/
|
|
|
|
bool IsPolygonInProgress() const;
|
|
|
|
|
|
|
|
/**
|
2021-01-25 12:42:36 +00:00
|
|
|
* @return true if locking in the given point would close the current polygon.
|
2017-02-26 17:45:52 +00:00
|
|
|
*/
|
|
|
|
bool NewPointClosesOutline( const VECTOR2I& aPt ) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove the last-added point from the polygon
|
|
|
|
*/
|
|
|
|
void DeleteLastCorner();
|
|
|
|
|
|
|
|
/* =================================================================
|
|
|
|
* Interfaces for users of the geometry
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the "locked-in" points that describe the polygon itself
|
|
|
|
*/
|
2018-02-19 10:20:52 +00:00
|
|
|
const SHAPE_LINE_CHAIN& GetLockedInPoints() const
|
|
|
|
{
|
|
|
|
return m_lockedPoints;
|
|
|
|
}
|
2017-02-26 17:45:52 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the points comprising the leader line (the line from the
|
|
|
|
* last locked-in point to the current cursor position
|
|
|
|
*
|
|
|
|
* How this is drawn will depend on the LEADER_MODE
|
|
|
|
*/
|
2018-02-19 10:20:52 +00:00
|
|
|
const SHAPE_LINE_CHAIN& GetLeaderLinePoints() const
|
|
|
|
{
|
|
|
|
return m_leaderPts;
|
|
|
|
}
|
2017-02-26 17:45:52 +00:00
|
|
|
|
2022-12-09 16:11:56 +00:00
|
|
|
/**
|
|
|
|
* Get the points from the current cursor position
|
|
|
|
* to the polygon start point
|
|
|
|
*/
|
|
|
|
const SHAPE_LINE_CHAIN& GetLoopLinePoints() const
|
|
|
|
{
|
|
|
|
return m_loopPts;
|
|
|
|
}
|
|
|
|
|
2017-02-26 17:45:52 +00:00
|
|
|
private:
|
|
|
|
|
|
|
|
/**
|
2022-12-09 16:11:56 +00:00
|
|
|
* Update the leader and loop lines points based on a new endpoint (probably
|
2017-02-26 17:45:52 +00:00
|
|
|
* a cursor position)
|
|
|
|
*/
|
2022-12-09 16:11:56 +00:00
|
|
|
void updateTemporaryLines( const VECTOR2I& aEndPoint,
|
|
|
|
LEADER_MODE aModifier = LEADER_MODE::DIRECT );
|
2017-02-26 17:45:52 +00:00
|
|
|
|
2021-01-25 12:42:36 +00:00
|
|
|
///< The "user" of the polygon data that is informed when the geometry changes
|
2017-02-26 17:45:52 +00:00
|
|
|
CLIENT& m_client;
|
|
|
|
|
2021-01-25 12:42:36 +00:00
|
|
|
///< The current mode of the leader line
|
2017-02-26 17:45:52 +00:00
|
|
|
LEADER_MODE m_leaderMode;
|
|
|
|
|
2021-01-25 12:42:36 +00:00
|
|
|
///< Flag enabling self-intersecting polygons
|
2018-02-19 14:25:07 +00:00
|
|
|
bool m_intersectionsAllowed;
|
|
|
|
|
2021-01-25 12:42:36 +00:00
|
|
|
///< Point that have been "locked in"
|
2018-02-19 10:20:52 +00:00
|
|
|
SHAPE_LINE_CHAIN m_lockedPoints;
|
2017-02-26 17:45:52 +00:00
|
|
|
|
2021-01-25 12:42:36 +00:00
|
|
|
///< Points in the temporary "leader" line(s)
|
2018-02-19 10:20:52 +00:00
|
|
|
SHAPE_LINE_CHAIN m_leaderPts;
|
2022-12-09 16:11:56 +00:00
|
|
|
|
|
|
|
///< Points between the cursor and start point
|
|
|
|
SHAPE_LINE_CHAIN m_loopPts;
|
2017-02-26 17:45:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // PREVIEW_POLYGON_GEOM_MANAGER__H_
|