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
|
|
|
|
*/
|
|
|
|
|
2016-06-29 10:23:11 +00:00
|
|
|
#include <functional>
|
|
|
|
using namespace std::placeholders;
|
2015-02-18 00:10:20 +00:00
|
|
|
|
|
|
|
#include <wxPcbStruct.h>
|
|
|
|
|
|
|
|
#include <class_board.h>
|
|
|
|
#include <class_module.h>
|
|
|
|
#include <class_edge_mod.h>
|
|
|
|
#include <class_zone.h>
|
|
|
|
#include <class_draw_panel_gal.h>
|
|
|
|
|
2016-12-02 17:58:12 +00:00
|
|
|
#include <view/view.h>
|
2015-02-18 00:10:20 +00:00
|
|
|
#include <view/view_controls.h>
|
|
|
|
#include <gal/graphics_abstraction_layer.h>
|
|
|
|
|
|
|
|
#include <geometry/shape_line_chain.h>
|
|
|
|
|
|
|
|
#include "grid_helper.h"
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
GRID_HELPER::GRID_HELPER( PCB_BASE_FRAME* aFrame ) :
|
|
|
|
m_frame( aFrame )
|
2015-02-18 00:10:20 +00:00
|
|
|
{
|
2015-03-14 11:50:39 +00:00
|
|
|
m_diagonalAuxAxesEnable = true;
|
2015-02-18 00:10:20 +00:00
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
|
|
|
GRID_HELPER::~GRID_HELPER()
|
|
|
|
{
|
2015-02-18 00:10:20 +00:00
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
|
|
|
void GRID_HELPER::SetGrid( int aSize )
|
2015-02-18 00:10:20 +00:00
|
|
|
{
|
2015-02-18 16:53:46 +00:00
|
|
|
assert( false );
|
2015-02-18 00:10:20 +00:00
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
|
|
|
void GRID_HELPER::SetOrigin( const VECTOR2I& aOrigin )
|
2015-02-18 00:10:20 +00:00
|
|
|
{
|
2015-06-30 12:08:03 +00:00
|
|
|
assert( false );
|
2015-02-18 00:10:20 +00:00
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2015-06-30 12:08:03 +00:00
|
|
|
VECTOR2I GRID_HELPER::GetGrid() const
|
2015-02-18 00:10:20 +00:00
|
|
|
{
|
2015-02-18 16:53:46 +00:00
|
|
|
PCB_SCREEN* screen = m_frame->GetScreen();
|
2015-02-18 00:10:20 +00:00
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
const wxRealPoint& size = screen->GetGridSize();
|
2015-02-18 00:10:20 +00:00
|
|
|
|
2015-06-30 12:08:03 +00:00
|
|
|
return VECTOR2I( KiROUND( size.x ), KiROUND( size.y ) );
|
2015-02-18 00:10:20 +00:00
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2015-06-30 12:08:03 +00:00
|
|
|
VECTOR2I GRID_HELPER::GetOrigin() const
|
2015-02-18 00:10:20 +00:00
|
|
|
{
|
2015-06-30 12:08:03 +00:00
|
|
|
return VECTOR2I( m_frame->GetGridOrigin() );
|
2015-02-18 00:10:20 +00:00
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2015-06-30 12:08:03 +00:00
|
|
|
void GRID_HELPER::SetAuxAxes( bool aEnable, const VECTOR2I& aOrigin, bool aEnableDiagonal )
|
2015-02-18 00:10:20 +00:00
|
|
|
{
|
2015-02-18 16:53:46 +00:00
|
|
|
if( aEnable )
|
|
|
|
m_auxAxis = aOrigin;
|
|
|
|
else
|
|
|
|
m_auxAxis = boost::optional<VECTOR2I>();
|
2015-02-18 00:10:20 +00:00
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
m_diagonalAuxAxesEnable = aEnable;
|
2015-02-18 00:10:20 +00:00
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2015-06-30 12:08:03 +00:00
|
|
|
VECTOR2I GRID_HELPER::Align( const VECTOR2I& aPoint ) const
|
2015-02-18 00:10:20 +00:00
|
|
|
{
|
2015-06-30 12:08:03 +00:00
|
|
|
const VECTOR2D gridOffset( GetOrigin() );
|
2015-02-18 16:53:46 +00:00
|
|
|
const VECTOR2D gridSize( GetGrid() );
|
2015-02-18 00:10:20 +00:00
|
|
|
|
2015-07-17 08:26:48 +00:00
|
|
|
VECTOR2I nearest( KiROUND( ( aPoint.x - gridOffset.x ) / gridSize.x ) * gridSize.x + gridOffset.x,
|
|
|
|
KiROUND( ( aPoint.y - gridOffset.y ) / gridSize.y ) * gridSize.y + gridOffset.y );
|
2015-02-18 00:10:20 +00:00
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
if( !m_auxAxis )
|
|
|
|
return nearest;
|
2015-02-18 00:10:20 +00:00
|
|
|
|
2015-07-07 16:36:32 +00:00
|
|
|
if( std::abs( m_auxAxis->x - aPoint.x ) < std::abs( nearest.x - aPoint.x ) )
|
2015-02-18 16:53:46 +00:00
|
|
|
nearest.x = m_auxAxis->x;
|
2015-02-18 00:10:20 +00:00
|
|
|
|
2015-07-07 16:36:32 +00:00
|
|
|
if( std::abs( m_auxAxis->y - aPoint.y ) < std::abs( nearest.y - aPoint.y ) )
|
2015-02-18 16:53:46 +00:00
|
|
|
nearest.y = m_auxAxis->y;
|
2015-02-18 00:10:20 +00:00
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
return nearest;
|
2015-02-18 00:10:20 +00:00
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2017-04-20 14:37:36 +00:00
|
|
|
VECTOR2I GRID_HELPER::AlignToSegment( const VECTOR2I& aPoint, const SEG& aSeg )
|
2015-11-03 16:19:42 +00:00
|
|
|
{
|
|
|
|
OPT_VECTOR2I pts[6];
|
|
|
|
|
|
|
|
const VECTOR2D gridOffset( GetOrigin() );
|
|
|
|
const VECTOR2D gridSize( GetGrid() );
|
|
|
|
|
|
|
|
VECTOR2I nearest( KiROUND( ( aPoint.x - gridOffset.x ) / gridSize.x ) * gridSize.x + gridOffset.x,
|
|
|
|
KiROUND( ( aPoint.y - gridOffset.y ) / gridSize.y ) * gridSize.y + gridOffset.y );
|
|
|
|
|
|
|
|
pts[0] = aSeg.A;
|
|
|
|
pts[1] = aSeg.B;
|
|
|
|
pts[2] = aSeg.IntersectLines( SEG( nearest, nearest + VECTOR2I( 1, 0 ) ) );
|
|
|
|
pts[3] = aSeg.IntersectLines( SEG( nearest, nearest + VECTOR2I( 0, 1 ) ) );
|
|
|
|
|
|
|
|
int min_d = std::numeric_limits<int>::max();
|
|
|
|
|
|
|
|
for( int i = 0; i < 4; i++ )
|
|
|
|
{
|
|
|
|
if( pts[i] && aSeg.Contains( *pts[i] ) )
|
|
|
|
{
|
|
|
|
int d = (*pts[i] - aPoint).EuclideanNorm();
|
|
|
|
|
|
|
|
if( d < min_d )
|
|
|
|
{
|
|
|
|
min_d = d;
|
|
|
|
nearest = *pts[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nearest;
|
|
|
|
}
|
|
|
|
|
2017-04-20 14:37:36 +00:00
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
VECTOR2I GRID_HELPER::BestDragOrigin( const VECTOR2I &aMousePos, BOARD_ITEM* aItem )
|
2015-02-18 00:10:20 +00:00
|
|
|
{
|
|
|
|
clearAnchors();
|
2015-02-18 16:53:46 +00:00
|
|
|
computeAnchors( aItem, aMousePos );
|
|
|
|
|
2015-02-18 00:10:20 +00:00
|
|
|
double worldScale = m_frame->GetGalCanvas()->GetGAL()->GetWorldScale();
|
|
|
|
double lineSnapMinCornerDistance = 50.0 / worldScale;
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
ANCHOR* nearestOutline = nearestAnchor( aMousePos, OUTLINE, LSET::AllLayersMask() );
|
|
|
|
ANCHOR* nearestCorner = nearestAnchor( aMousePos, CORNER, LSET::AllLayersMask() );
|
|
|
|
ANCHOR* nearestOrigin = nearestAnchor( aMousePos, ORIGIN, LSET::AllLayersMask() );
|
|
|
|
ANCHOR* best = NULL;
|
|
|
|
double minDist = std::numeric_limits<double>::max();
|
|
|
|
|
|
|
|
if( nearestOrigin )
|
|
|
|
{
|
|
|
|
minDist = nearestOrigin->Distance( aMousePos );
|
|
|
|
best = nearestOrigin;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( nearestCorner )
|
|
|
|
{
|
|
|
|
double dist = nearestCorner->Distance( aMousePos );
|
2015-11-03 16:19:42 +00:00
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
if( dist < minDist )
|
|
|
|
{
|
|
|
|
minDist = dist;
|
|
|
|
best = nearestCorner;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( nearestOutline )
|
2015-02-18 00:10:20 +00:00
|
|
|
{
|
2015-02-18 16:53:46 +00:00
|
|
|
double dist = nearestOutline->Distance( aMousePos );
|
2015-11-03 16:19:42 +00:00
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
if( minDist > lineSnapMinCornerDistance && dist < minDist )
|
|
|
|
best = nearestOutline;
|
2015-02-18 00:10:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return best ? best->pos : aMousePos;
|
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2015-06-30 12:08:03 +00:00
|
|
|
std::set<BOARD_ITEM*> GRID_HELPER::queryVisible( const BOX2I& aArea ) const
|
2015-02-18 00:10:20 +00:00
|
|
|
{
|
2015-02-18 16:53:46 +00:00
|
|
|
std::set<BOARD_ITEM*> items;
|
2015-02-18 00:10:20 +00:00
|
|
|
|
|
|
|
std::vector<KIGFX::VIEW::LAYER_ITEM_PAIR> selectedItems;
|
2015-02-18 16:53:46 +00:00
|
|
|
std::vector<KIGFX::VIEW::LAYER_ITEM_PAIR>::iterator it, it_end;
|
2015-02-18 00:10:20 +00:00
|
|
|
|
2016-12-02 17:58:12 +00:00
|
|
|
auto view = m_frame->GetGalCanvas()->GetView();
|
|
|
|
view->Query( aArea, selectedItems ); // Get the list of selected items
|
2015-02-18 00:10:20 +00:00
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
for( it = selectedItems.begin(), it_end = selectedItems.end(); it != it_end; ++it )
|
2015-02-18 00:10:20 +00:00
|
|
|
{
|
2015-02-18 16:53:46 +00:00
|
|
|
BOARD_ITEM* item = static_cast<BOARD_ITEM*>( it->first );
|
2016-12-09 11:04:32 +00:00
|
|
|
|
2016-12-02 17:58:12 +00:00
|
|
|
if( view->IsVisible( item ) )
|
2015-02-18 16:53:46 +00:00
|
|
|
items.insert ( item );
|
2015-02-18 00:10:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return items;
|
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2015-06-30 12:08:03 +00:00
|
|
|
VECTOR2I GRID_HELPER::BestSnapAnchor( const VECTOR2I& aOrigin, BOARD_ITEM* aDraggedItem )
|
2015-02-18 00:10:20 +00:00
|
|
|
{
|
2015-02-18 16:53:46 +00:00
|
|
|
double worldScale = m_frame->GetGalCanvas()->GetGAL()->GetWorldScale();
|
|
|
|
int snapRange = (int) ( 100.0 / worldScale );
|
2015-02-18 00:10:20 +00:00
|
|
|
|
2015-06-30 12:08:03 +00:00
|
|
|
BOX2I bb( VECTOR2I( aOrigin.x - snapRange / 2, aOrigin.y - snapRange / 2 ), VECTOR2I( snapRange, snapRange ) );
|
2015-02-18 00:10:20 +00:00
|
|
|
|
|
|
|
clearAnchors();
|
|
|
|
|
2016-06-29 20:07:55 +00:00
|
|
|
for( BOARD_ITEM* item : queryVisible( bb ) )
|
2015-02-18 00:10:20 +00:00
|
|
|
{
|
2015-02-18 16:53:46 +00:00
|
|
|
computeAnchors( item, aOrigin );
|
2015-02-18 00:10:20 +00:00
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
LSET layers( aDraggedItem->GetLayer() );
|
|
|
|
ANCHOR* nearest = nearestAnchor( aOrigin, CORNER | SNAPPABLE, layers );
|
2015-02-18 00:10:20 +00:00
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
VECTOR2I nearestGrid = Align( aOrigin );
|
|
|
|
double gridDist = ( nearestGrid - aOrigin ).EuclideanNorm();
|
2017-04-20 14:37:36 +00:00
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
if( nearest )
|
2015-02-18 00:10:20 +00:00
|
|
|
{
|
2015-02-18 16:53:46 +00:00
|
|
|
double snapDist = nearest->Distance( aOrigin );
|
2015-02-18 00:10:20 +00:00
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
if( nearest && snapDist < gridDist )
|
2017-04-20 14:37:36 +00:00
|
|
|
return nearest->pos;
|
2015-06-30 12:08:03 +00:00
|
|
|
}
|
2015-02-18 00:10:20 +00:00
|
|
|
|
2015-06-30 12:08:03 +00:00
|
|
|
return nearestGrid;
|
2015-02-18 00:10:20 +00:00
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
|
|
|
void GRID_HELPER::computeAnchors( BOARD_ITEM* aItem, const VECTOR2I& aRefPos )
|
2015-02-18 00:10:20 +00:00
|
|
|
{
|
2015-02-18 16:53:46 +00:00
|
|
|
VECTOR2I origin;
|
2015-02-18 00:10:20 +00:00
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
switch( aItem->Type() )
|
2015-02-18 00:10:20 +00:00
|
|
|
{
|
|
|
|
case PCB_MODULE_T:
|
|
|
|
{
|
2015-02-18 16:53:46 +00:00
|
|
|
MODULE* mod = static_cast<MODULE*>( aItem );
|
|
|
|
addAnchor( mod->GetPosition(), ORIGIN | SNAPPABLE, mod );
|
|
|
|
|
2017-04-25 09:06:24 +00:00
|
|
|
for( auto pad : mod->Pads() )
|
2015-02-18 16:53:46 +00:00
|
|
|
addAnchor( pad->GetPosition(), CORNER | SNAPPABLE, pad );
|
2015-02-18 00:10:20 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-03-11 17:06:44 +00:00
|
|
|
case PCB_PAD_T:
|
|
|
|
{
|
|
|
|
D_PAD* pad = static_cast<D_PAD*>( aItem );
|
|
|
|
addAnchor( pad->GetPosition(), CORNER | SNAPPABLE, pad );
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-02-18 00:10:20 +00:00
|
|
|
case PCB_MODULE_EDGE_T:
|
|
|
|
case PCB_LINE_T:
|
|
|
|
{
|
2015-02-18 16:53:46 +00:00
|
|
|
DRAWSEGMENT* dseg = static_cast<DRAWSEGMENT*>( aItem );
|
2015-02-18 00:10:20 +00:00
|
|
|
VECTOR2I start = dseg->GetStart();
|
|
|
|
VECTOR2I end = dseg->GetEnd();
|
2017-03-13 03:19:33 +00:00
|
|
|
//PCB_LAYER_ID layer = dseg->GetLayer();
|
2015-02-18 00:10:20 +00:00
|
|
|
|
|
|
|
switch( dseg->GetShape() )
|
|
|
|
{
|
|
|
|
case S_CIRCLE:
|
|
|
|
{
|
2015-02-18 16:53:46 +00:00
|
|
|
int r = ( start - end ).EuclideanNorm();
|
|
|
|
|
|
|
|
addAnchor( start, ORIGIN | SNAPPABLE, dseg );
|
2015-07-07 16:36:32 +00:00
|
|
|
addAnchor( start + VECTOR2I( -r, 0 ), OUTLINE | SNAPPABLE, dseg );
|
|
|
|
addAnchor( start + VECTOR2I( r, 0 ), OUTLINE | SNAPPABLE, dseg );
|
|
|
|
addAnchor( start + VECTOR2I( 0, -r ), OUTLINE | SNAPPABLE, dseg );
|
|
|
|
addAnchor( start + VECTOR2I( 0, r ), OUTLINE | SNAPPABLE, dseg );
|
2015-02-18 00:10:20 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case S_ARC:
|
|
|
|
{
|
|
|
|
origin = dseg->GetCenter();
|
2015-02-18 16:53:46 +00:00
|
|
|
addAnchor( dseg->GetArcStart(), CORNER | SNAPPABLE, dseg );
|
|
|
|
addAnchor( dseg->GetArcEnd(), CORNER | SNAPPABLE, dseg );
|
|
|
|
addAnchor( origin, ORIGIN | SNAPPABLE, dseg );
|
|
|
|
break;
|
2015-02-18 00:10:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
case S_SEGMENT:
|
|
|
|
{
|
|
|
|
origin.x = start.x + ( start.x - end.x ) / 2;
|
|
|
|
origin.y = start.y + ( start.y - end.y ) / 2;
|
2015-02-18 16:53:46 +00:00
|
|
|
addAnchor( start, CORNER | SNAPPABLE, dseg );
|
|
|
|
addAnchor( end, CORNER | SNAPPABLE, dseg );
|
|
|
|
addAnchor( origin, ORIGIN, dseg );
|
2015-02-18 00:10:20 +00:00
|
|
|
break;
|
2015-02-18 16:53:46 +00:00
|
|
|
}
|
2015-02-18 00:10:20 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
origin = dseg->GetStart();
|
2015-02-18 16:53:46 +00:00
|
|
|
addAnchor( origin, ORIGIN | SNAPPABLE, dseg );
|
2015-02-18 00:10:20 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case PCB_TRACE_T:
|
|
|
|
{
|
2015-02-18 16:53:46 +00:00
|
|
|
TRACK* track = static_cast<TRACK*>( aItem );
|
2015-02-18 00:10:20 +00:00
|
|
|
VECTOR2I start = track->GetStart();
|
|
|
|
VECTOR2I end = track->GetEnd();
|
|
|
|
origin.x = start.x + ( start.x - end.x ) / 2;
|
|
|
|
origin.y = start.y + ( start.y - end.y ) / 2;
|
2015-02-18 16:53:46 +00:00
|
|
|
addAnchor( start, CORNER | SNAPPABLE, track );
|
|
|
|
addAnchor( end, CORNER | SNAPPABLE, track );
|
|
|
|
addAnchor( origin, ORIGIN, track);
|
2015-02-18 00:10:20 +00:00
|
|
|
break;
|
2015-02-18 16:53:46 +00:00
|
|
|
}
|
2015-02-18 00:10:20 +00:00
|
|
|
|
2015-07-07 16:36:32 +00:00
|
|
|
case PCB_VIA_T:
|
|
|
|
addAnchor( aItem->GetPosition(), CORNER | SNAPPABLE, aItem );
|
|
|
|
break;
|
|
|
|
|
2015-02-18 00:10:20 +00:00
|
|
|
case PCB_ZONE_AREA_T:
|
|
|
|
{
|
2017-03-07 12:06:00 +00:00
|
|
|
const SHAPE_POLY_SET* outline = static_cast<const ZONE_CONTAINER*>( aItem )->Outline();
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2015-02-18 00:10:20 +00:00
|
|
|
SHAPE_LINE_CHAIN lc;
|
2015-02-18 16:53:46 +00:00
|
|
|
lc.SetClosed( true );
|
|
|
|
|
2017-03-07 12:06:00 +00:00
|
|
|
for( auto iter = outline->CIterateWithHoles(); iter; iter++ )
|
2015-02-18 00:10:20 +00:00
|
|
|
{
|
2017-03-07 12:06:00 +00:00
|
|
|
addAnchor( *iter, CORNER, aItem );
|
|
|
|
lc.Append( *iter );
|
2015-02-18 16:53:46 +00:00
|
|
|
}
|
2015-02-18 00:10:20 +00:00
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
addAnchor( lc.NearestPoint( aRefPos ), OUTLINE, aItem );
|
2015-02-18 00:10:20 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case PCB_MODULE_TEXT_T:
|
|
|
|
case PCB_TEXT_T:
|
2015-02-18 16:53:46 +00:00
|
|
|
addAnchor( aItem->GetPosition(), ORIGIN, aItem );
|
2015-02-18 00:10:20 +00:00
|
|
|
default:
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-06-30 12:08:03 +00:00
|
|
|
GRID_HELPER::ANCHOR* GRID_HELPER::nearestAnchor( const VECTOR2I& aPos, int aFlags, LSET aMatchLayers )
|
2015-02-18 16:53:46 +00:00
|
|
|
{
|
2017-04-20 14:37:36 +00:00
|
|
|
double minDist = std::numeric_limits<double>::max();
|
|
|
|
ANCHOR* best = NULL;
|
2015-02-18 00:10:20 +00:00
|
|
|
|
2017-04-20 14:37:36 +00:00
|
|
|
for( ANCHOR& a : m_anchors )
|
|
|
|
{
|
|
|
|
if( !aMatchLayers[a.item->GetLayer()] )
|
|
|
|
continue;
|
2015-02-18 00:10:20 +00:00
|
|
|
|
2017-04-20 14:37:36 +00:00
|
|
|
if( ( aFlags & a.flags ) != aFlags )
|
|
|
|
continue;
|
2015-02-18 00:10:20 +00:00
|
|
|
|
2017-04-20 14:37:36 +00:00
|
|
|
double dist = a.Distance( aPos );
|
2015-02-18 00:10:20 +00:00
|
|
|
|
2017-04-20 14:37:36 +00:00
|
|
|
if( dist < minDist )
|
|
|
|
{
|
|
|
|
minDist = dist;
|
|
|
|
best = &a;
|
|
|
|
}
|
|
|
|
}
|
2015-02-18 00:10:20 +00:00
|
|
|
|
2017-04-20 14:37:36 +00:00
|
|
|
return best;
|
2015-02-18 16:53:46 +00:00
|
|
|
}
|