2014-02-27 16:29:08 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KICAD, a free EDA CAD application.
|
|
|
|
*
|
2017-02-08 07:45:52 +00:00
|
|
|
* Copyright (C) 2014-2017 CERN
|
2021-07-15 19:26:35 +00:00
|
|
|
* Copyright (C) 2020-2021 KiCad Developers, see AUTHORS.txt for contributors.
|
2020-12-27 00:41:04 +00:00
|
|
|
*
|
2014-02-27 16:29:08 +00:00
|
|
|
* @author Maciej Suminski <maciej.suminski@cern.ch>
|
|
|
|
*
|
|
|
|
* 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 EDIT_POINTS_H_
|
|
|
|
#define EDIT_POINTS_H_
|
|
|
|
|
2020-10-14 01:06:53 +00:00
|
|
|
#include <eda_item.h>
|
2014-02-27 16:29:08 +00:00
|
|
|
#include <layers_id_colors_and_visibility.h>
|
|
|
|
|
2016-05-28 16:46:29 +00:00
|
|
|
#include <list>
|
|
|
|
#include <deque>
|
2016-06-29 15:09:55 +00:00
|
|
|
#include <memory>
|
|
|
|
|
2020-12-03 19:53:39 +00:00
|
|
|
#include "edit_constraints.h"
|
2016-12-02 17:58:12 +00:00
|
|
|
#include <view/view.h>
|
2016-06-29 15:09:55 +00:00
|
|
|
|
2020-12-03 19:53:39 +00:00
|
|
|
|
2014-03-07 09:26:33 +00:00
|
|
|
/**
|
2020-12-27 00:41:04 +00:00
|
|
|
* Represent a single point that can be used for modifying items.
|
2014-03-07 09:26:33 +00:00
|
|
|
*
|
2020-12-27 00:41:04 +00:00
|
|
|
* It is directly related to one of points in a graphical item (e.g. vertex of a zone or
|
|
|
|
* center of a circle).
|
2014-03-07 09:26:33 +00:00
|
|
|
*/
|
2014-02-27 16:29:08 +00:00
|
|
|
class EDIT_POINT
|
|
|
|
{
|
|
|
|
public:
|
2014-03-07 09:26:33 +00:00
|
|
|
/**
|
|
|
|
* @param aPoint stores coordinates for EDIT_POINT.
|
|
|
|
*/
|
2020-11-30 19:27:31 +00:00
|
|
|
EDIT_POINT( const VECTOR2I& aPoint, std::pair<EDA_ITEM*, int> aConnected = { nullptr, 0 } ) :
|
|
|
|
m_position( aPoint ),
|
|
|
|
m_isActive( false ),
|
|
|
|
m_isHover( false ),
|
2020-12-03 19:53:39 +00:00
|
|
|
m_gridConstraint( SNAP_TO_GRID ),
|
2020-11-30 19:27:31 +00:00
|
|
|
m_connected( aConnected )
|
2019-05-08 18:56:03 +00:00
|
|
|
{
|
|
|
|
}
|
2014-02-28 15:53:28 +00:00
|
|
|
|
2014-03-14 14:15:38 +00:00
|
|
|
virtual ~EDIT_POINT() {}
|
2014-02-27 16:29:08 +00:00
|
|
|
|
2014-03-07 09:26:33 +00:00
|
|
|
/**
|
2020-12-27 00:41:04 +00:00
|
|
|
* Return coordinates of an EDIT_POINT.
|
2014-03-07 09:26:33 +00:00
|
|
|
*
|
2020-12-27 00:41:04 +00:00
|
|
|
* @note It may be different than coordinates of a graphical item that is bound to the
|
|
|
|
* EDIT_POINT.
|
2014-03-07 09:26:33 +00:00
|
|
|
*/
|
2014-03-06 16:34:04 +00:00
|
|
|
virtual VECTOR2I GetPosition() const
|
2014-02-27 16:29:08 +00:00
|
|
|
{
|
2014-03-06 16:34:04 +00:00
|
|
|
return m_position;
|
2014-02-27 16:29:08 +00:00
|
|
|
}
|
|
|
|
|
2020-11-30 19:27:31 +00:00
|
|
|
/**
|
|
|
|
* Return a connected item record comprising an EDA_ITEM* and a STARTPOINT/ENDPOINT flag.
|
|
|
|
*/
|
|
|
|
virtual std::pair<EDA_ITEM*, int> GetConnected() const
|
2019-05-08 18:56:03 +00:00
|
|
|
{
|
2020-11-30 19:27:31 +00:00
|
|
|
return m_connected;
|
2019-05-08 18:56:03 +00:00
|
|
|
}
|
|
|
|
|
2014-03-12 09:46:11 +00:00
|
|
|
/**
|
2020-12-27 00:41:04 +00:00
|
|
|
* Return X coordinate of an EDIT_POINT.
|
2014-03-12 09:46:11 +00:00
|
|
|
*/
|
2015-06-19 15:32:33 +00:00
|
|
|
inline int GetX() const
|
2014-03-12 09:46:11 +00:00
|
|
|
{
|
|
|
|
return GetPosition().x;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-12-27 00:41:04 +00:00
|
|
|
* Return Y coordinate of an EDIT_POINT.
|
2014-03-12 09:46:11 +00:00
|
|
|
*/
|
2015-06-19 15:32:33 +00:00
|
|
|
inline int GetY() const
|
2014-03-12 09:46:11 +00:00
|
|
|
{
|
|
|
|
return GetPosition().y;
|
|
|
|
}
|
|
|
|
|
2014-03-07 09:26:33 +00:00
|
|
|
/**
|
2020-12-27 00:41:04 +00:00
|
|
|
* Set new coordinates for an EDIT_POINT.
|
|
|
|
*
|
|
|
|
* It does not change the coordinates of a graphical item.
|
2014-03-07 09:26:33 +00:00
|
|
|
*
|
|
|
|
* @param aPosition are new coordinates.
|
|
|
|
*/
|
2014-03-06 16:34:04 +00:00
|
|
|
virtual void SetPosition( const VECTOR2I& aPosition )
|
2014-02-27 16:29:08 +00:00
|
|
|
{
|
2014-03-06 16:34:04 +00:00
|
|
|
m_position = aPosition;
|
2014-02-27 16:29:08 +00:00
|
|
|
}
|
|
|
|
|
2019-05-08 18:56:03 +00:00
|
|
|
virtual void SetPosition( int x, int y )
|
|
|
|
{
|
|
|
|
m_position.x = x;
|
|
|
|
m_position.y = y;
|
|
|
|
}
|
|
|
|
|
2014-03-07 09:26:33 +00:00
|
|
|
/**
|
2020-12-27 00:41:04 +00:00
|
|
|
* Check if given point is within a square centered in the EDIT_POINT position.
|
2014-03-07 09:26:33 +00:00
|
|
|
*
|
|
|
|
* @param aPoint is point to be checked.
|
|
|
|
* @param aSize is length of the square side.
|
|
|
|
*/
|
|
|
|
bool WithinPoint( const VECTOR2I& aPoint, unsigned int aSize ) const;
|
2014-02-27 16:29:08 +00:00
|
|
|
|
2014-03-07 09:26:33 +00:00
|
|
|
/**
|
2020-12-27 00:41:04 +00:00
|
|
|
* Set a constraint for and EDIT_POINT.
|
2014-03-07 09:26:33 +00:00
|
|
|
*
|
|
|
|
* @param aConstraint is the constraint to be set.
|
|
|
|
*/
|
2014-03-14 14:15:38 +00:00
|
|
|
void SetConstraint( EDIT_CONSTRAINT<EDIT_POINT>* aConstraint )
|
2014-02-27 16:29:08 +00:00
|
|
|
{
|
2014-03-14 14:15:38 +00:00
|
|
|
m_constraint.reset( aConstraint );
|
2014-02-27 16:29:08 +00:00
|
|
|
}
|
|
|
|
|
2014-03-12 09:46:11 +00:00
|
|
|
/**
|
2020-12-27 00:41:04 +00:00
|
|
|
* Return the constraint imposed on an EDIT_POINT. If there are no constraints, NULL is
|
2014-03-12 09:46:11 +00:00
|
|
|
* returned.
|
|
|
|
*/
|
2014-03-14 14:15:38 +00:00
|
|
|
EDIT_CONSTRAINT<EDIT_POINT>* GetConstraint() const
|
2014-03-12 09:46:11 +00:00
|
|
|
{
|
2014-03-14 14:15:38 +00:00
|
|
|
return m_constraint.get();
|
2014-03-12 09:46:11 +00:00
|
|
|
}
|
|
|
|
|
2014-03-07 09:26:33 +00:00
|
|
|
/**
|
2020-12-27 00:41:04 +00:00
|
|
|
* Remove previously set constraint.
|
2014-03-07 09:26:33 +00:00
|
|
|
*/
|
2015-06-19 15:32:33 +00:00
|
|
|
inline void ClearConstraint()
|
2014-02-27 16:29:08 +00:00
|
|
|
{
|
2014-03-14 14:15:38 +00:00
|
|
|
m_constraint.reset();
|
2014-02-27 16:29:08 +00:00
|
|
|
}
|
|
|
|
|
2014-03-07 09:26:33 +00:00
|
|
|
/**
|
2020-12-27 00:41:04 +00:00
|
|
|
* Check if point is constrained.
|
2014-03-07 09:26:33 +00:00
|
|
|
*
|
|
|
|
* @return True is point is constrained, false otherwise.
|
|
|
|
*/
|
2015-06-19 15:32:33 +00:00
|
|
|
inline bool IsConstrained() const
|
2014-03-06 13:41:25 +00:00
|
|
|
{
|
2021-07-15 19:26:35 +00:00
|
|
|
return m_constraint != nullptr;
|
2014-03-06 13:41:25 +00:00
|
|
|
}
|
|
|
|
|
2014-03-07 09:26:33 +00:00
|
|
|
/**
|
2020-12-27 00:41:04 +00:00
|
|
|
* Correct coordinates of an EDIT_POINT by applying previously set constraint.
|
2014-03-07 09:26:33 +00:00
|
|
|
*/
|
2014-03-14 14:15:38 +00:00
|
|
|
virtual void ApplyConstraint()
|
2014-02-27 16:29:08 +00:00
|
|
|
{
|
|
|
|
if( m_constraint )
|
|
|
|
m_constraint->Apply();
|
|
|
|
}
|
|
|
|
|
2020-09-24 01:27:23 +00:00
|
|
|
bool IsActive() const { return m_isActive; }
|
|
|
|
void SetActive( bool aActive = true ) { m_isActive = aActive; }
|
2020-06-21 18:43:33 +00:00
|
|
|
|
2020-09-24 01:27:23 +00:00
|
|
|
bool IsHover() const { return m_isHover; }
|
|
|
|
void SetHover( bool aHover = true ) { m_isHover = aHover; }
|
2020-06-21 18:43:33 +00:00
|
|
|
|
2020-12-03 19:53:39 +00:00
|
|
|
GRID_CONSTRAINT_TYPE GetGridConstraint() const { return m_gridConstraint; }
|
|
|
|
void SetGridConstraint( GRID_CONSTRAINT_TYPE aConstraint ) { m_gridConstraint = aConstraint; }
|
2020-10-08 09:59:17 +00:00
|
|
|
|
2014-03-06 13:41:25 +00:00
|
|
|
bool operator==( const EDIT_POINT& aOther ) const
|
|
|
|
{
|
2014-03-06 16:34:04 +00:00
|
|
|
return m_position == aOther.m_position;
|
2014-03-06 13:41:25 +00:00
|
|
|
}
|
|
|
|
|
2020-12-27 00:41:04 +00:00
|
|
|
///< Single point size in pixels
|
2014-02-27 16:29:08 +00:00
|
|
|
static const int POINT_SIZE = 10;
|
|
|
|
|
2020-12-27 00:41:04 +00:00
|
|
|
///< Border size when not hovering
|
2020-09-24 01:27:23 +00:00
|
|
|
static const int BORDER_SIZE = 2;
|
|
|
|
|
2020-12-27 00:41:04 +00:00
|
|
|
///< Border size when hovering
|
2020-09-24 01:27:23 +00:00
|
|
|
static const int HOVER_SIZE = 5;
|
|
|
|
|
2014-04-02 07:31:35 +00:00
|
|
|
private:
|
2020-12-27 00:41:04 +00:00
|
|
|
VECTOR2I m_position; ///< Position of EDIT_POINT.
|
|
|
|
bool m_isActive; ///< True if this point is being manipulated.
|
|
|
|
bool m_isHover; ///< True if this point is being hovered over.
|
|
|
|
GRID_CONSTRAINT_TYPE m_gridConstraint; ///< Describe the grid snapping behavior.
|
2014-03-14 14:15:38 +00:00
|
|
|
|
2020-12-27 00:41:04 +00:00
|
|
|
///< An optional connected item record used to mimic polyLine behavior with individual
|
|
|
|
///< line segments.
|
2020-11-30 19:27:31 +00:00
|
|
|
std::pair<EDA_ITEM*, int> m_connected;
|
|
|
|
|
2020-12-27 00:41:04 +00:00
|
|
|
///< Constraint for the point, NULL if none
|
2016-06-29 15:09:55 +00:00
|
|
|
std::shared_ptr<EDIT_CONSTRAINT<EDIT_POINT> > m_constraint;
|
2014-02-27 16:29:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-03-07 09:26:33 +00:00
|
|
|
/**
|
2020-12-27 00:41:04 +00:00
|
|
|
* Represent a line connecting two EDIT_POINTs.
|
2014-03-07 09:26:33 +00:00
|
|
|
*
|
2020-12-27 00:41:04 +00:00
|
|
|
* This allows one to move them both by dragging the EDIT_POINT in the middle. It uses
|
|
|
|
* references to EDIT_POINTs, all coordinates are automatically synchronized.
|
2014-03-07 09:26:33 +00:00
|
|
|
*/
|
2014-03-06 16:34:04 +00:00
|
|
|
class EDIT_LINE : public EDIT_POINT
|
|
|
|
{
|
|
|
|
public:
|
2014-03-07 09:26:33 +00:00
|
|
|
/**
|
|
|
|
* @param aOrigin is the origin of EDIT_LINE.
|
|
|
|
* @param aEnd is the end of EDIT_LINE.
|
|
|
|
*/
|
2014-03-06 16:34:04 +00:00
|
|
|
EDIT_LINE( EDIT_POINT& aOrigin, EDIT_POINT& aEnd ) :
|
|
|
|
EDIT_POINT( aOrigin.GetPosition() + ( aEnd.GetPosition() - aOrigin.GetPosition() ) / 2 ),
|
2020-10-08 09:59:17 +00:00
|
|
|
m_origin( aOrigin ),
|
|
|
|
m_end( aEnd )
|
2014-03-06 16:34:04 +00:00
|
|
|
{
|
2020-12-03 19:53:39 +00:00
|
|
|
SetGridConstraint( SNAP_BY_GRID );
|
2014-03-06 16:34:04 +00:00
|
|
|
}
|
|
|
|
|
2020-12-27 00:41:04 +00:00
|
|
|
///< @copydoc EDIT_POINT::GetPosition()
|
2016-09-25 17:06:49 +00:00
|
|
|
virtual VECTOR2I GetPosition() const override
|
2014-03-06 16:34:04 +00:00
|
|
|
{
|
2014-03-18 10:05:24 +00:00
|
|
|
return ( m_origin.GetPosition() + m_end.GetPosition() ) / 2;
|
2014-03-06 16:34:04 +00:00
|
|
|
}
|
|
|
|
|
2020-12-27 00:41:04 +00:00
|
|
|
///< @copydoc EDIT_POINT::GetPosition()
|
2016-09-25 17:06:49 +00:00
|
|
|
virtual void SetPosition( const VECTOR2I& aPosition ) override
|
2014-03-06 16:34:04 +00:00
|
|
|
{
|
|
|
|
VECTOR2I difference = aPosition - GetPosition();
|
|
|
|
|
|
|
|
m_origin.SetPosition( m_origin.GetPosition() + difference );
|
|
|
|
m_end.SetPosition( m_end.GetPosition() + difference );
|
|
|
|
}
|
|
|
|
|
2020-12-27 00:41:04 +00:00
|
|
|
///< @copydoc EDIT_POINT::ApplyConstraint()
|
2016-09-25 17:06:49 +00:00
|
|
|
virtual void ApplyConstraint() override
|
2014-03-14 14:15:38 +00:00
|
|
|
{
|
|
|
|
if( m_constraint )
|
|
|
|
m_constraint->Apply();
|
2019-08-26 13:30:03 +00:00
|
|
|
|
|
|
|
m_origin.ApplyConstraint();
|
|
|
|
m_end.ApplyConstraint();
|
2014-03-14 14:15:38 +00:00
|
|
|
}
|
|
|
|
|
2014-04-02 07:31:35 +00:00
|
|
|
/**
|
2020-12-27 00:41:04 +00:00
|
|
|
* Set a constraint for and EDIT_POINT.
|
2014-04-02 07:31:35 +00:00
|
|
|
*
|
|
|
|
* @param aConstraint is the constraint to be set.
|
|
|
|
*/
|
|
|
|
void SetConstraint( EDIT_CONSTRAINT<EDIT_LINE>* aConstraint )
|
|
|
|
{
|
|
|
|
m_constraint.reset( aConstraint );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-12-27 00:41:04 +00:00
|
|
|
* Return the constraint imposed on an EDIT_POINT. If there are no constraints, NULL is
|
2014-04-02 07:31:35 +00:00
|
|
|
* returned.
|
|
|
|
*/
|
|
|
|
EDIT_CONSTRAINT<EDIT_LINE>* GetConstraint() const
|
|
|
|
{
|
|
|
|
return m_constraint.get();
|
|
|
|
}
|
|
|
|
|
2014-03-14 14:15:38 +00:00
|
|
|
/**
|
2020-12-27 00:41:04 +00:00
|
|
|
* Return the origin EDIT_POINT.
|
2014-03-14 14:15:38 +00:00
|
|
|
*/
|
|
|
|
EDIT_POINT& GetOrigin()
|
|
|
|
{
|
|
|
|
return m_origin;
|
|
|
|
}
|
|
|
|
|
2014-03-18 10:05:24 +00:00
|
|
|
const EDIT_POINT& GetOrigin() const
|
|
|
|
{
|
|
|
|
return m_origin;
|
|
|
|
}
|
|
|
|
|
2014-03-14 14:15:38 +00:00
|
|
|
/**
|
2020-12-27 00:41:04 +00:00
|
|
|
* Return the end EDIT_POINT.
|
2014-03-14 14:15:38 +00:00
|
|
|
*/
|
|
|
|
EDIT_POINT& GetEnd()
|
|
|
|
{
|
|
|
|
return m_end;
|
|
|
|
}
|
|
|
|
|
2014-03-18 10:05:24 +00:00
|
|
|
const EDIT_POINT& GetEnd() const
|
|
|
|
{
|
|
|
|
return m_end;
|
|
|
|
}
|
|
|
|
|
2014-03-06 16:34:04 +00:00
|
|
|
bool operator==( const EDIT_POINT& aOther ) const
|
|
|
|
{
|
|
|
|
return GetPosition() == aOther.GetPosition();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator==( const EDIT_LINE& aOther ) const
|
|
|
|
{
|
|
|
|
return m_origin == aOther.m_origin && m_end == aOther.m_end;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2014-03-07 09:26:33 +00:00
|
|
|
EDIT_POINT& m_origin; ///< Origin point for a line
|
|
|
|
EDIT_POINT& m_end; ///< End point for a line
|
2014-04-02 07:31:35 +00:00
|
|
|
|
2020-12-27 00:41:04 +00:00
|
|
|
///< Constraint for the point, NULL if none
|
2016-06-29 15:09:55 +00:00
|
|
|
std::shared_ptr<EDIT_CONSTRAINT<EDIT_LINE> > m_constraint;
|
2014-03-06 16:34:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-03-07 09:26:33 +00:00
|
|
|
/**
|
2020-12-27 00:41:04 +00:00
|
|
|
* EDIT_POINTS is a #VIEW_ITEM that manages EDIT_POINTs and EDIT_LINEs and draws them.
|
2014-03-07 09:26:33 +00:00
|
|
|
*/
|
2014-02-27 16:29:08 +00:00
|
|
|
class EDIT_POINTS : public EDA_ITEM
|
|
|
|
{
|
|
|
|
public:
|
2014-03-07 09:26:33 +00:00
|
|
|
/**
|
|
|
|
* @param aParent is the item to which EDIT_POINTs are related.
|
|
|
|
*/
|
2014-02-27 16:29:08 +00:00
|
|
|
EDIT_POINTS( EDA_ITEM* aParent );
|
|
|
|
|
|
|
|
/**
|
2020-12-27 00:41:04 +00:00
|
|
|
* Return a point that is at given coordinates or NULL if there is no such point.
|
2014-03-07 09:26:33 +00:00
|
|
|
*
|
2014-02-27 16:29:08 +00:00
|
|
|
* @param aLocation is the location for searched point.
|
|
|
|
*/
|
2016-12-02 17:58:12 +00:00
|
|
|
EDIT_POINT* FindPoint( const VECTOR2I& aLocation, KIGFX::VIEW *aView );
|
2014-02-27 16:29:08 +00:00
|
|
|
|
2014-03-07 09:26:33 +00:00
|
|
|
/**
|
2020-12-27 00:41:04 +00:00
|
|
|
* Return parent of the EDIT_POINTS.
|
2014-03-07 09:26:33 +00:00
|
|
|
*/
|
2014-02-28 15:53:28 +00:00
|
|
|
EDA_ITEM* GetParent() const
|
|
|
|
{
|
|
|
|
return m_parent;
|
|
|
|
}
|
|
|
|
|
2014-03-07 09:26:33 +00:00
|
|
|
/**
|
2020-12-27 00:41:04 +00:00
|
|
|
* Add an EDIT_POINT.
|
2014-03-07 09:26:33 +00:00
|
|
|
*
|
|
|
|
* @param aPoint is the new point.
|
|
|
|
*/
|
2014-03-06 16:34:04 +00:00
|
|
|
void AddPoint( const EDIT_POINT& aPoint )
|
2014-02-27 16:29:08 +00:00
|
|
|
{
|
|
|
|
m_points.push_back( aPoint );
|
|
|
|
}
|
|
|
|
|
2014-03-07 09:26:33 +00:00
|
|
|
/**
|
2020-12-27 00:41:04 +00:00
|
|
|
* Add an EDIT_POINT.
|
2014-03-07 09:26:33 +00:00
|
|
|
*
|
|
|
|
* @param aPoint are coordinates of the new point.
|
|
|
|
*/
|
2020-11-30 19:27:31 +00:00
|
|
|
void AddPoint( const VECTOR2I& aPoint, std::pair<EDA_ITEM*, int> aConnected = { nullptr, 0 } )
|
2014-03-06 16:34:04 +00:00
|
|
|
{
|
2020-11-30 19:27:31 +00:00
|
|
|
AddPoint( EDIT_POINT( aPoint, aConnected ) );
|
2014-03-06 16:34:04 +00:00
|
|
|
}
|
|
|
|
|
2014-03-07 09:26:33 +00:00
|
|
|
/**
|
|
|
|
* Adds an EDIT_LINE.
|
2020-12-27 00:41:04 +00:00
|
|
|
*
|
2014-03-07 09:26:33 +00:00
|
|
|
* @param aLine is the new line.
|
|
|
|
*/
|
2014-03-06 16:34:04 +00:00
|
|
|
void AddLine( const EDIT_LINE& aLine )
|
2014-02-27 16:29:08 +00:00
|
|
|
{
|
2014-03-06 16:34:04 +00:00
|
|
|
m_lines.push_back( aLine );
|
|
|
|
}
|
|
|
|
|
2014-03-07 09:26:33 +00:00
|
|
|
/**
|
|
|
|
* Adds an EDIT_LINE.
|
2020-12-27 00:41:04 +00:00
|
|
|
*
|
2014-03-07 09:26:33 +00:00
|
|
|
* @param aOrigin is the origin for a new line.
|
|
|
|
* @param aEnd is the end for a new line.
|
|
|
|
*/
|
2014-03-06 16:34:04 +00:00
|
|
|
void AddLine( EDIT_POINT& aOrigin, EDIT_POINT& aEnd )
|
|
|
|
{
|
2019-12-05 15:41:21 +00:00
|
|
|
m_lines.emplace_back( aOrigin, aEnd );
|
2014-03-06 13:41:25 +00:00
|
|
|
}
|
|
|
|
|
2015-01-16 15:44:42 +00:00
|
|
|
/**
|
|
|
|
* Adds a break, indicating the end of a contour.
|
|
|
|
*/
|
|
|
|
void AddBreak()
|
|
|
|
{
|
|
|
|
assert( m_points.size() > 0 );
|
|
|
|
m_contours.push_back( m_points.size() - 1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-12-27 00:41:04 +00:00
|
|
|
* Return index of the contour origin for a point with given index.
|
2015-01-16 15:44:42 +00:00
|
|
|
*
|
|
|
|
* @param aPointIdx is the index of point for which the contour origin is searched.
|
|
|
|
* @return Index of the contour origin point.
|
|
|
|
*/
|
|
|
|
int GetContourStartIdx( int aPointIdx ) const;
|
|
|
|
|
|
|
|
/**
|
2020-12-27 00:41:04 +00:00
|
|
|
* Return index of the contour finish for a point with given index.
|
2015-01-16 15:44:42 +00:00
|
|
|
*
|
|
|
|
* @param aPointIdx is the index of point for which the contour finish is searched.
|
|
|
|
* @return Index of the contour finish point.
|
|
|
|
*/
|
|
|
|
int GetContourEndIdx( int aPointIdx ) const;
|
|
|
|
|
|
|
|
/**
|
2020-12-27 00:41:04 +00:00
|
|
|
* Check if a point with given index is a contour origin.
|
2015-01-16 15:44:42 +00:00
|
|
|
*
|
|
|
|
* @param aPointIdx is the index of the point to be checked.
|
|
|
|
* @return True if the point is an origin of a contour.
|
|
|
|
*/
|
|
|
|
bool IsContourStart( int aPointIdx ) const;
|
|
|
|
|
|
|
|
/**
|
2020-12-27 00:41:04 +00:00
|
|
|
* Check is a point with given index is a contour finish.
|
2015-01-16 15:44:42 +00:00
|
|
|
*
|
|
|
|
* @param aPointIdx is the index of the point to be checked.
|
|
|
|
* @return True if the point is a finish of a contour.
|
|
|
|
*/
|
|
|
|
bool IsContourEnd( int aPointIdx ) const;
|
|
|
|
|
2014-03-07 09:26:33 +00:00
|
|
|
/**
|
2020-12-27 00:41:04 +00:00
|
|
|
* Return the point that is after the given point in the list.
|
2014-03-07 09:26:33 +00:00
|
|
|
*
|
|
|
|
* @param aPoint is the point that is supposed to be preceding the searched point.
|
2015-01-16 15:44:42 +00:00
|
|
|
* @param aTraverseContours decides if in case of breaks should we return to the origin
|
2020-12-27 00:41:04 +00:00
|
|
|
* of contour or continue with the next contour.
|
2014-03-07 09:26:33 +00:00
|
|
|
* @return The point following aPoint in the list. If aPoint is the first in
|
2020-12-27 00:41:04 +00:00
|
|
|
* the list, the last from the list will be returned. If there are no points at
|
|
|
|
* all, NULL is returned.
|
2014-03-07 09:26:33 +00:00
|
|
|
*/
|
2015-01-16 15:44:42 +00:00
|
|
|
EDIT_POINT* Previous( const EDIT_POINT& aPoint, bool aTraverseContours = true );
|
2014-03-06 13:41:25 +00:00
|
|
|
|
2014-04-01 15:18:43 +00:00
|
|
|
EDIT_LINE* Previous( const EDIT_LINE& aLine );
|
|
|
|
|
2014-03-07 09:26:33 +00:00
|
|
|
/**
|
2020-12-27 00:41:04 +00:00
|
|
|
* Return the point that is before the given point in the list.
|
2014-03-07 09:26:33 +00:00
|
|
|
*
|
|
|
|
* @param aPoint is the point that is supposed to be following the searched point.
|
2015-01-16 15:44:42 +00:00
|
|
|
* @param aTraverseContours decides if in case of breaks should we return to the origin
|
2020-12-27 00:41:04 +00:00
|
|
|
* of contour or continue with the next contour.
|
|
|
|
* @return The point preceding aPoint in the list. If aPoint is the last in the list, the
|
|
|
|
* first point from the list will be returned. If there are no points at all,
|
|
|
|
* NULL is returned.
|
2014-03-07 09:26:33 +00:00
|
|
|
*/
|
2015-01-16 15:44:42 +00:00
|
|
|
EDIT_POINT* Next( const EDIT_POINT& aPoint, bool aTraverseContours = true );
|
2014-02-27 16:29:08 +00:00
|
|
|
|
2014-04-01 15:18:43 +00:00
|
|
|
EDIT_LINE* Next( const EDIT_LINE& aLine );
|
|
|
|
|
|
|
|
EDIT_POINT& Point( unsigned int aIndex )
|
2014-02-27 16:29:08 +00:00
|
|
|
{
|
|
|
|
return m_points[aIndex];
|
|
|
|
}
|
|
|
|
|
2014-04-01 15:18:43 +00:00
|
|
|
const EDIT_POINT& Point( unsigned int aIndex ) const
|
2014-02-27 16:29:08 +00:00
|
|
|
{
|
|
|
|
return m_points[aIndex];
|
|
|
|
}
|
|
|
|
|
2014-04-01 15:18:43 +00:00
|
|
|
EDIT_LINE& Line( unsigned int aIndex )
|
|
|
|
{
|
|
|
|
return m_lines[aIndex];
|
|
|
|
}
|
|
|
|
|
|
|
|
const EDIT_LINE& Line( unsigned int aIndex ) const
|
|
|
|
{
|
|
|
|
return m_lines[aIndex];
|
|
|
|
}
|
|
|
|
|
2014-03-07 09:26:33 +00:00
|
|
|
/**
|
2020-12-27 00:41:04 +00:00
|
|
|
* Return number of stored EDIT_POINTs.
|
2014-03-07 09:26:33 +00:00
|
|
|
*/
|
2014-04-02 13:57:21 +00:00
|
|
|
unsigned int PointsSize() const
|
2014-02-27 16:29:08 +00:00
|
|
|
{
|
|
|
|
return m_points.size();
|
|
|
|
}
|
|
|
|
|
2014-04-02 13:57:21 +00:00
|
|
|
/**
|
2020-12-27 00:41:04 +00:00
|
|
|
* Return number of stored EDIT_LINEs.
|
2014-04-02 13:57:21 +00:00
|
|
|
*/
|
|
|
|
unsigned int LinesSize() const
|
|
|
|
{
|
|
|
|
return m_lines.size();
|
|
|
|
}
|
|
|
|
|
2020-12-27 00:41:04 +00:00
|
|
|
///< @copydoc VIEW_ITEM::ViewBBox()
|
2017-02-08 07:45:52 +00:00
|
|
|
virtual const BOX2I ViewBBox() const override;
|
2014-02-27 16:29:08 +00:00
|
|
|
|
2020-12-27 00:41:04 +00:00
|
|
|
///< @copydoc VIEW_ITEM::ViewDraw()
|
2016-12-02 17:58:12 +00:00
|
|
|
virtual void ViewDraw( int aLayer, KIGFX::VIEW* aView ) const override;
|
2014-02-27 16:29:08 +00:00
|
|
|
|
2020-12-27 00:41:04 +00:00
|
|
|
///< @copydoc VIEW_ITEM::ViewGetLayers()
|
2016-09-25 17:06:49 +00:00
|
|
|
virtual void ViewGetLayers( int aLayers[], int& aCount ) const override
|
2014-02-27 16:29:08 +00:00
|
|
|
{
|
|
|
|
aCount = 1;
|
2017-03-13 03:19:33 +00:00
|
|
|
aLayers[0] = LAYER_GP_OVERLAY ;
|
2014-02-27 16:29:08 +00:00
|
|
|
}
|
|
|
|
|
2015-03-06 08:58:32 +00:00
|
|
|
#if defined(DEBUG)
|
2016-09-25 17:06:49 +00:00
|
|
|
void Show( int x, std::ostream& st ) const override
|
2014-02-27 16:29:08 +00:00
|
|
|
{
|
|
|
|
}
|
2015-03-06 08:58:32 +00:00
|
|
|
#endif
|
|
|
|
|
2020-12-27 00:41:04 +00:00
|
|
|
/**
|
|
|
|
* Get the class name.
|
|
|
|
*
|
|
|
|
* @return string "EDIT_POINTS".
|
2015-03-06 08:58:32 +00:00
|
|
|
*/
|
2016-09-25 17:06:49 +00:00
|
|
|
virtual wxString GetClass() const override
|
2015-03-06 08:58:32 +00:00
|
|
|
{
|
|
|
|
return wxT( "EDIT_POINTS" );
|
|
|
|
}
|
2014-02-27 16:29:08 +00:00
|
|
|
|
|
|
|
private:
|
2020-12-27 00:41:04 +00:00
|
|
|
EDA_ITEM* m_parent; ///< Parent of the EDIT_POINTs.
|
|
|
|
std::deque<EDIT_POINT> m_points; ///< EDIT_POINTs for modifying m_parent.
|
|
|
|
std::deque<EDIT_LINE> m_lines; ///< EDIT_LINEs for modifying m_parent.
|
|
|
|
std::list<int> m_contours; ///< Indices of end contour points.
|
|
|
|
bool m_allowPoints; ///< If false, only allow editing of EDIT_LINES.
|
2014-02-27 16:29:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* EDIT_POINTS_H_ */
|