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>
|
|
|
|
#include <boost/optional.hpp>
|
|
|
|
|
|
|
|
#include <layers_id_colors_and_visibility.h>
|
|
|
|
|
|
|
|
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
|
|
|
|
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-06-30 12:08:03 +00:00
|
|
|
VECTOR2I BestDragOrigin( const VECTOR2I& aMousePos, BOARD_ITEM* aItem );
|
|
|
|
VECTOR2I BestSnapAnchor( const VECTOR2I& aOrigin, BOARD_ITEM* aDraggedItem );
|
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-06-30 12:08:03 +00:00
|
|
|
//bool CanSnapItem( const BOARD_ITEM* aItem ) const;
|
2015-02-18 16:53:46 +00:00
|
|
|
};
|
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
|
|
|
|
2015-06-30 12:08:03 +00:00
|
|
|
std::set<BOARD_ITEM*> queryVisible( const BOX2I& aArea ) 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
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
void computeAnchors( BOARD_ITEM* aItem, const VECTOR2I& aRefPos );
|
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;
|
|
|
|
boost::optional<VECTOR2I> m_auxAxis;
|
|
|
|
bool m_diagonalAuxAxesEnable;
|
2015-02-18 00:10:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|