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
|
|
|
|
* @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>
|
|
|
|
|
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-02-18 16:53:46 +00:00
|
|
|
void SetGrid( int aSize );
|
|
|
|
void SetOrigin( const VECTOR2I& aOrigin );
|
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;
|
|
|
|
|
2015-06-30 12:08:03 +00:00
|
|
|
void SetAuxAxes( bool aEnable, const VECTOR2I& aOrigin = VECTOR2I( 0, 0 ), bool aEnableDiagonal = false );
|
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 );
|
|
|
|
|
2015-06-30 12:08:03 +00:00
|
|
|
VECTOR2I BestDragOrigin( const VECTOR2I& aMousePos, BOARD_ITEM* aItem );
|
|
|
|
VECTOR2I BestSnapAnchor( const VECTOR2I& aOrigin, BOARD_ITEM* aDraggedItem );
|
2018-11-16 18:01:54 +00:00
|
|
|
VECTOR2I BestSnapAnchor( const VECTOR2I& aOrigin, const LSET& aLayers,
|
|
|
|
const std::vector<BOARD_ITEM*> aSkip = {} );
|
2018-10-04 00:15:54 +00:00
|
|
|
|
|
|
|
void SetSnap( bool aSnap )
|
|
|
|
{
|
|
|
|
m_enableSnap = aSnap;
|
|
|
|
}
|
2015-02-18 00:10:20 +00:00
|
|
|
|
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
|
|
|
|
{
|
|
|
|
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,
|
|
|
|
const std::vector<BOARD_ITEM*> aSkip ) const;
|
2015-02-18 00:10:20 +00:00
|
|
|
|
2015-06-30 12:08:03 +00:00
|
|
|
void addAnchor( const VECTOR2I& aPos, int aFlags = CORNER | SNAPPABLE, BOARD_ITEM* aItem = NULL )
|
2015-02-18 16:53:46 +00:00
|
|
|
{
|
|
|
|
m_anchors.push_back( ANCHOR( aPos, aFlags, aItem ) );
|
|
|
|
}
|
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
|
|
|
|
*/
|
|
|
|
void computeAnchors( BOARD_ITEM* aItem, const VECTOR2I& aRefPos, const 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;
|
2017-11-01 11:14:16 +00:00
|
|
|
OPT<VECTOR2I> m_auxAxis;
|
2018-10-04 00:15:54 +00:00
|
|
|
|
|
|
|
bool m_diagonalAuxAxesEnable; ///< If true, use the aux axis for snapping as well
|
|
|
|
bool m_enableSnap; ///< If true, allow snapping to other items on the layers
|
2018-10-05 03:42:58 +00:00
|
|
|
bool m_enableGrid; ///< If true, allow snapping to grid
|
2018-10-04 00:15:54 +00:00
|
|
|
int m_snapSize; ///< Sets the radius in screen units for snapping to items
|
2018-11-24 15:58:33 +00:00
|
|
|
ANCHOR* m_snapItem; ///< Pointer to the currently snapped item in m_anchors (NULL if not snapped)
|
2018-10-04 00:15:54 +00:00
|
|
|
|
|
|
|
KIGFX::ORIGIN_VIEWITEM m_viewSnapPoint;
|
|
|
|
KIGFX::ORIGIN_VIEWITEM m_viewAxis;
|
2015-02-18 00:10:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|