2015-02-18 00:10:20 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2014 CERN
|
2020-01-19 04:42:10 +00:00
|
|
|
* Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors.
|
2015-02-18 00:10:20 +00:00
|
|
|
* @author Tomasz Wlostowski <tomasz.wlostowski@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 __GRID_HELPER_H
|
|
|
|
#define __GRID_HELPER_H
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
#include <math/vector2d.h>
|
2017-11-01 11:14:16 +00:00
|
|
|
#include <core/optional.h>
|
2017-08-02 10:16:59 +00:00
|
|
|
#include <origin_viewitem.h>
|
2015-02-18 00:10:20 +00:00
|
|
|
#include <layers_id_colors_and_visibility.h>
|
2015-11-03 16:19:42 +00:00
|
|
|
#include <geometry/seg.h>
|
2019-05-17 00:13:21 +00:00
|
|
|
#include <geometry/shape_arc.h>
|
2015-11-03 16:19:42 +00:00
|
|
|
|
2015-02-18 00:10:20 +00:00
|
|
|
class PCB_BASE_FRAME;
|
|
|
|
|
|
|
|
class GRID_HELPER {
|
|
|
|
public:
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
GRID_HELPER( PCB_BASE_FRAME* aFrame );
|
|
|
|
~GRID_HELPER();
|
2015-02-18 00:10:20 +00:00
|
|
|
|
2015-06-30 12:08:03 +00:00
|
|
|
VECTOR2I GetGrid() const;
|
|
|
|
VECTOR2I GetOrigin() const;
|
2015-02-18 00:10:20 +00:00
|
|
|
|
2018-11-24 15:58:33 +00:00
|
|
|
/**
|
|
|
|
* Function GetSnapped
|
|
|
|
* If the GRID_HELPER has highlighted a snap point (target shown), this function
|
|
|
|
* will return a pointer to the item to which it snapped.
|
|
|
|
*
|
|
|
|
* @return NULL if not snapped. Pointer to snapped item otherwise
|
|
|
|
*/
|
|
|
|
BOARD_ITEM* GetSnapped() const;
|
|
|
|
|
2019-07-15 23:44:01 +00:00
|
|
|
void SetAuxAxes( bool aEnable, const VECTOR2I& aOrigin = VECTOR2I( 0, 0 ) );
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2015-06-30 12:08:03 +00:00
|
|
|
VECTOR2I Align( const VECTOR2I& aPoint ) const;
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2015-11-03 16:19:42 +00:00
|
|
|
VECTOR2I AlignToSegment ( const VECTOR2I& aPoint, const SEG& aSeg );
|
|
|
|
|
2019-08-21 04:31:11 +00:00
|
|
|
VECTOR2I BestDragOrigin( const VECTOR2I& aMousePos, std::vector<BOARD_ITEM*>& aItem );
|
2019-05-17 00:13:21 +00:00
|
|
|
|
|
|
|
VECTOR2I AlignToArc ( const VECTOR2I& aPoint, const SHAPE_ARC& aSeg );
|
|
|
|
|
2015-06-30 12:08:03 +00:00
|
|
|
VECTOR2I BestSnapAnchor( const VECTOR2I& aOrigin, BOARD_ITEM* aDraggedItem );
|
2018-11-16 18:01:54 +00:00
|
|
|
VECTOR2I BestSnapAnchor( const VECTOR2I& aOrigin, const LSET& aLayers,
|
2019-08-21 04:31:11 +00:00
|
|
|
const std::vector<BOARD_ITEM*>& aSkip = {} );
|
2018-10-04 00:15:54 +00:00
|
|
|
|
2020-01-19 04:42:10 +00:00
|
|
|
void SetSkipPoint( const VECTOR2I& aPoint )
|
|
|
|
{
|
|
|
|
m_skipPoint = aPoint;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* We clear the skip point by setting it to an unreachable position, thereby preventing matching
|
|
|
|
*/
|
|
|
|
void ClearSkipPoint()
|
|
|
|
{
|
|
|
|
m_skipPoint = VECTOR2I( std::numeric_limits<int>::min(), std::numeric_limits<int>::min() );
|
|
|
|
}
|
|
|
|
|
2018-10-04 00:15:54 +00:00
|
|
|
void SetSnap( bool aSnap )
|
|
|
|
{
|
|
|
|
m_enableSnap = aSnap;
|
|
|
|
}
|
2015-02-18 00:10:20 +00:00
|
|
|
|
2020-01-19 04:42:10 +00:00
|
|
|
void SetSnapLine( bool aSnap )
|
|
|
|
{
|
|
|
|
m_enableSnapLine = aSnap;
|
|
|
|
}
|
|
|
|
|
2018-10-05 03:42:58 +00:00
|
|
|
void SetUseGrid( bool aGrid = true )
|
|
|
|
{
|
|
|
|
m_enableGrid = aGrid;
|
|
|
|
}
|
|
|
|
|
2015-02-18 00:10:20 +00:00
|
|
|
private:
|
2015-02-18 16:53:46 +00:00
|
|
|
enum ANCHOR_FLAGS {
|
|
|
|
CORNER = 0x1,
|
|
|
|
OUTLINE = 0x2,
|
|
|
|
SNAPPABLE = 0x4,
|
|
|
|
ORIGIN = 0x8
|
|
|
|
};
|
2015-02-18 00:10:20 +00:00
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
struct ANCHOR
|
|
|
|
{
|
2019-07-15 23:44:01 +00:00
|
|
|
ANCHOR( VECTOR2I aPos, int aFlags = CORNER | SNAPPABLE, BOARD_ITEM* aItem = NULL ) :
|
|
|
|
pos( aPos ),
|
|
|
|
flags( aFlags ),
|
|
|
|
item( aItem )
|
|
|
|
{ };
|
2015-02-18 00:10:20 +00:00
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
VECTOR2I pos;
|
|
|
|
int flags;
|
|
|
|
BOARD_ITEM* item;
|
2015-02-18 00:10:20 +00:00
|
|
|
|
2015-06-30 12:08:03 +00:00
|
|
|
double Distance( const VECTOR2I& aP ) const
|
2015-02-18 16:53:46 +00:00
|
|
|
{
|
|
|
|
return ( aP - pos ).EuclideanNorm();
|
|
|
|
}
|
|
|
|
};
|
2015-02-18 00:10:20 +00:00
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
std::vector<ANCHOR> m_anchors;
|
2015-02-18 00:10:20 +00:00
|
|
|
|
2018-11-16 18:01:54 +00:00
|
|
|
std::set<BOARD_ITEM*> queryVisible( const BOX2I& aArea,
|
2019-08-21 04:31:11 +00:00
|
|
|
const std::vector<BOARD_ITEM*>& aSkip ) const;
|
2015-02-18 00:10:20 +00:00
|
|
|
|
2019-07-15 23:44:01 +00:00
|
|
|
void addAnchor( const VECTOR2I& aPos, int aFlags, BOARD_ITEM* aItem )
|
2015-02-18 16:53:46 +00:00
|
|
|
{
|
2019-07-15 23:44:01 +00:00
|
|
|
m_anchors.emplace_back( ANCHOR( aPos, aFlags, aItem ) );
|
2015-02-18 16:53:46 +00:00
|
|
|
}
|
2015-02-18 00:10:20 +00:00
|
|
|
|
2015-06-30 12:08:03 +00:00
|
|
|
ANCHOR* nearestAnchor( const VECTOR2I& aPos, int aFlags, LSET aMatchLayers );
|
2015-02-18 00:10:20 +00:00
|
|
|
|
2019-02-03 03:20:53 +00:00
|
|
|
/**
|
|
|
|
* computeAnchors inserts the local anchor points in to the grid helper for the specified
|
|
|
|
* board item, given the reference point and the direction of use for the point.
|
|
|
|
*
|
|
|
|
* @param aItem The board item for which to compute the anchors
|
|
|
|
* @param aRefPos The point for which to compute the anchors (if used by the component)
|
|
|
|
* @param aFrom Is this for an anchor that is designating a source point (aFrom=true) or not
|
|
|
|
*/
|
2019-07-15 23:44:01 +00:00
|
|
|
void computeAnchors( BOARD_ITEM* aItem, const VECTOR2I& aRefPos, bool aFrom = false );
|
2015-02-18 00:10:20 +00:00
|
|
|
|
2015-06-30 12:08:03 +00:00
|
|
|
void clearAnchors()
|
2015-02-18 16:53:46 +00:00
|
|
|
{
|
|
|
|
m_anchors.clear();
|
|
|
|
}
|
2015-02-18 00:10:20 +00:00
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
PCB_BASE_FRAME* m_frame;
|
2020-01-19 04:42:10 +00:00
|
|
|
OPT<VECTOR2I> m_auxAxis;
|
2018-10-04 00:15:54 +00:00
|
|
|
|
2020-01-19 04:42:10 +00:00
|
|
|
bool m_enableSnap; ///< If true, allow snapping to other items on the layers
|
|
|
|
bool m_enableGrid; ///< If true, allow snapping to grid
|
|
|
|
bool m_enableSnapLine; ///< If true, allow drawing lines from snap points
|
|
|
|
int m_snapSize; ///< Sets the radius in screen units for snapping to items
|
|
|
|
ANCHOR* m_snapItem; ///< Pointer to the currently snapped item in m_anchors (NULL if not snapped)
|
|
|
|
VECTOR2I m_skipPoint; ///< When drawing a line, we avoid snapping to the source point
|
2018-10-04 00:15:54 +00:00
|
|
|
|
|
|
|
KIGFX::ORIGIN_VIEWITEM m_viewSnapPoint;
|
2020-01-19 04:42:10 +00:00
|
|
|
KIGFX::ORIGIN_VIEWITEM m_viewSnapLine;
|
2018-10-04 00:15:54 +00:00
|
|
|
KIGFX::ORIGIN_VIEWITEM m_viewAxis;
|
2015-02-18 00:10:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|