2017-02-23 06:23:17 +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-23 06:23:17 +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_TWO_POINT_GEOMETRY_MANAGER_H
|
|
|
|
#define PREVIEW_ITEMS_TWO_POINT_GEOMETRY_MANAGER_H
|
|
|
|
|
|
|
|
#include <math/vector2d.h>
|
2018-07-12 12:05:18 +00:00
|
|
|
#include <geometry/geometry_utils.h>
|
2017-02-23 06:23:17 +00:00
|
|
|
|
|
|
|
namespace KIGFX
|
|
|
|
{
|
|
|
|
class GAL;
|
|
|
|
|
|
|
|
namespace PREVIEW
|
|
|
|
{
|
|
|
|
|
|
|
|
/**
|
2021-01-25 12:42:36 +00:00
|
|
|
* Represent a very simple geometry manager for items that have a start and end point.
|
2017-02-23 06:23:17 +00:00
|
|
|
*/
|
|
|
|
class TWO_POINT_GEOMETRY_MANAGER
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2021-01-25 12:42:36 +00:00
|
|
|
///< Set the origin of the ruler (the fixed end)
|
2017-02-23 06:23:17 +00:00
|
|
|
void SetOrigin( const VECTOR2I& aOrigin )
|
|
|
|
{
|
|
|
|
m_origin = aOrigin;
|
2020-07-03 15:05:17 +00:00
|
|
|
m_originSet = true;
|
|
|
|
setGeometryChanged();
|
2017-02-23 06:23:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
VECTOR2I GetOrigin() const
|
|
|
|
{
|
|
|
|
return m_origin;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-01-25 12:42:36 +00:00
|
|
|
* Set the current end of the rectangle (the end that moves with the cursor.
|
2017-02-23 06:23:17 +00:00
|
|
|
*/
|
|
|
|
void SetEnd( const VECTOR2I& aEnd )
|
|
|
|
{
|
|
|
|
if( m_angleSnap )
|
|
|
|
{
|
2018-07-12 12:05:18 +00:00
|
|
|
m_end = GetVectorSnapped45( aEnd - m_origin ) + m_origin;
|
2017-02-23 06:23:17 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_end = aEnd;
|
|
|
|
}
|
2020-07-03 15:05:17 +00:00
|
|
|
setGeometryChanged();
|
2017-02-23 06:23:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
VECTOR2I GetEnd() const
|
|
|
|
{
|
|
|
|
return m_end;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetAngleSnap( bool aSnap )
|
|
|
|
{
|
|
|
|
m_angleSnap = aSnap;
|
|
|
|
}
|
|
|
|
|
2020-07-03 15:05:17 +00:00
|
|
|
bool GetAngleSnap() const
|
|
|
|
{
|
|
|
|
return m_angleSnap;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return true if the manager is in the initial state
|
|
|
|
*/
|
|
|
|
bool IsReset() const
|
|
|
|
{
|
|
|
|
return !m_originSet;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reset the manager to the initial state
|
|
|
|
*/
|
|
|
|
void Reset()
|
|
|
|
{
|
|
|
|
m_originSet = false;
|
|
|
|
setGeometryChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-01-25 12:42:36 +00:00
|
|
|
* @return true if the geometry has changed, eg such that a client should redraw.
|
2020-07-03 15:05:17 +00:00
|
|
|
*/
|
|
|
|
bool HasGeometryChanged() const
|
|
|
|
{
|
|
|
|
return m_changed;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-01-25 12:42:36 +00:00
|
|
|
* Clear the geometry changed flag, call after the client code has updated everything as
|
|
|
|
* needed.
|
2020-07-03 15:05:17 +00:00
|
|
|
*/
|
|
|
|
void ClearGeometryChanged()
|
|
|
|
{
|
|
|
|
m_changed = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2021-01-25 12:42:36 +00:00
|
|
|
///< Mark the geometry as changed for clients to notice
|
2020-07-03 15:05:17 +00:00
|
|
|
void setGeometryChanged()
|
|
|
|
{
|
|
|
|
m_changed = true;
|
|
|
|
}
|
|
|
|
|
2017-02-23 06:23:17 +00:00
|
|
|
private:
|
|
|
|
|
|
|
|
VECTOR2I m_origin, m_end;
|
|
|
|
bool m_angleSnap = false;
|
2020-07-03 15:05:17 +00:00
|
|
|
|
2021-01-25 12:42:36 +00:00
|
|
|
///< Has the geometry changed such that a client should redraw?
|
2020-07-03 15:05:17 +00:00
|
|
|
bool m_changed = false;
|
|
|
|
bool m_originSet = false;
|
2017-02-23 06:23:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // PREVIEW
|
|
|
|
} // KIGFX
|
|
|
|
|
|
|
|
#endif // PREVIEW_ITEMS_TWO_POINT_GEOMETRY_MANAGER_H
|