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) 2018-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
|
|
|
|
*/
|
|
|
|
|
2016-06-29 10:23:11 +00:00
|
|
|
#include <functional>
|
|
|
|
using namespace std::placeholders;
|
2015-02-18 00:10:20 +00:00
|
|
|
|
2020-11-12 20:19:22 +00:00
|
|
|
#include <board.h>
|
2020-11-11 23:05:59 +00:00
|
|
|
#include <dimension.h>
|
2020-10-04 23:34:59 +00:00
|
|
|
#include <fp_shape.h>
|
2020-11-12 20:19:22 +00:00
|
|
|
#include <footprint.h>
|
|
|
|
#include <track.h>
|
2020-11-11 23:05:59 +00:00
|
|
|
#include <zone.h>
|
2020-09-29 03:59:44 +00:00
|
|
|
#include <geometry/shape_circle.h>
|
2019-10-10 13:33:21 +00:00
|
|
|
#include <geometry/shape_line_chain.h>
|
2020-09-29 03:59:44 +00:00
|
|
|
#include <geometry/shape_rect.h>
|
|
|
|
#include <geometry/shape_segment.h>
|
|
|
|
#include <geometry/shape_simple.h>
|
2020-04-24 23:44:09 +00:00
|
|
|
#include <macros.h>
|
2020-09-29 03:59:44 +00:00
|
|
|
#include <math/util.h> // for KiROUND
|
2019-10-10 13:33:21 +00:00
|
|
|
#include <math/vector2d.h>
|
2018-10-06 16:31:00 +00:00
|
|
|
#include <painter.h>
|
2020-01-13 01:44:19 +00:00
|
|
|
#include <pcbnew_settings.h>
|
2020-09-29 03:59:44 +00:00
|
|
|
#include <tool/tool_manager.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 "grid_helper.h"
|
|
|
|
|
2017-08-02 10:16:59 +00:00
|
|
|
|
2020-06-13 12:33:29 +00:00
|
|
|
GRID_HELPER::GRID_HELPER( TOOL_MANAGER* aToolMgr, MAGNETIC_SETTINGS* aMagneticSettings ) :
|
|
|
|
m_toolMgr( aToolMgr ),
|
|
|
|
m_magneticSettings( aMagneticSettings )
|
2015-02-18 00:10:20 +00:00
|
|
|
{
|
2018-10-04 00:15:54 +00:00
|
|
|
m_enableSnap = true;
|
2018-10-05 03:42:58 +00:00
|
|
|
m_enableGrid = true;
|
2020-01-19 04:42:10 +00:00
|
|
|
m_enableSnapLine = true;
|
2019-10-10 13:33:21 +00:00
|
|
|
m_snapItem = nullptr;
|
2020-06-12 10:58:56 +00:00
|
|
|
KIGFX::VIEW* view = m_toolMgr->GetView();
|
2017-08-02 10:16:59 +00:00
|
|
|
|
|
|
|
m_viewAxis.SetSize( 20000 );
|
|
|
|
m_viewAxis.SetStyle( KIGFX::ORIGIN_VIEWITEM::CROSS );
|
|
|
|
m_viewAxis.SetColor( COLOR4D( 1.0, 1.0, 1.0, 0.4 ) );
|
|
|
|
m_viewAxis.SetDrawAtZero( true );
|
|
|
|
view->Add( &m_viewAxis );
|
|
|
|
view->SetVisible( &m_viewAxis, false );
|
|
|
|
|
|
|
|
m_viewSnapPoint.SetStyle( KIGFX::ORIGIN_VIEWITEM::CIRCLE_CROSS );
|
|
|
|
m_viewSnapPoint.SetColor( COLOR4D( 1.0, 1.0, 1.0, 1.0 ) );
|
|
|
|
m_viewSnapPoint.SetDrawAtZero( true );
|
|
|
|
view->Add( &m_viewSnapPoint );
|
|
|
|
view->SetVisible( &m_viewSnapPoint, false );
|
2020-01-19 04:42:10 +00:00
|
|
|
|
|
|
|
m_viewSnapLine.SetStyle( KIGFX::ORIGIN_VIEWITEM::DASH_LINE );
|
|
|
|
m_viewSnapLine.SetColor( COLOR4D( 0.33, 0.55, 0.95, 1.0 ) );
|
|
|
|
m_viewSnapLine.SetDrawAtZero( true );
|
|
|
|
view->Add( &m_viewSnapLine );
|
|
|
|
view->SetVisible( &m_viewSnapLine, false );
|
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
|
|
|
|
2015-06-30 12:08:03 +00:00
|
|
|
VECTOR2I GRID_HELPER::GetGrid() const
|
2015-02-18 00:10:20 +00:00
|
|
|
{
|
2020-06-12 10:58:56 +00:00
|
|
|
VECTOR2D size = m_toolMgr->GetView()->GetGAL()->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
|
|
|
{
|
2020-06-12 10:58:56 +00:00
|
|
|
VECTOR2D origin = m_toolMgr->GetView()->GetGAL()->GetGridOrigin();
|
|
|
|
|
|
|
|
return VECTOR2I( origin );
|
2015-02-18 00:10:20 +00:00
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2019-07-15 23:44:01 +00:00
|
|
|
void GRID_HELPER::SetAuxAxes( bool aEnable, const VECTOR2I& aOrigin )
|
2015-02-18 00:10:20 +00:00
|
|
|
{
|
2015-02-18 16:53:46 +00:00
|
|
|
if( aEnable )
|
2017-08-02 10:16:59 +00:00
|
|
|
{
|
2015-02-18 16:53:46 +00:00
|
|
|
m_auxAxis = aOrigin;
|
2020-09-09 02:54:17 +00:00
|
|
|
m_viewAxis.SetPosition( wxPoint( aOrigin ) );
|
2020-06-12 10:58:56 +00:00
|
|
|
m_toolMgr->GetView()->SetVisible( &m_viewAxis, true );
|
2017-08-02 10:16:59 +00:00
|
|
|
}
|
2015-02-18 16:53:46 +00:00
|
|
|
else
|
2017-08-02 10:16:59 +00:00
|
|
|
{
|
2017-11-01 11:14:16 +00:00
|
|
|
m_auxAxis = OPT<VECTOR2I>();
|
2020-06-12 10:58:56 +00:00
|
|
|
m_toolMgr->GetView()->SetVisible( &m_viewAxis, false );
|
2017-08-02 10:16:59 +00:00
|
|
|
}
|
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
|
|
|
{
|
2018-10-05 03:42:58 +00:00
|
|
|
if( !m_enableGrid )
|
|
|
|
return aPoint;
|
|
|
|
|
2015-06-30 12:08:03 +00:00
|
|
|
const VECTOR2D gridOffset( GetOrigin() );
|
2019-07-15 23:44:01 +00:00
|
|
|
const VECTOR2D grid( GetGrid() );
|
2015-02-18 00:10:20 +00:00
|
|
|
|
2019-07-15 23:44:01 +00:00
|
|
|
VECTOR2I nearest( KiROUND( ( aPoint.x - gridOffset.x ) / grid.x ) * grid.x + gridOffset.x,
|
|
|
|
KiROUND( ( aPoint.y - gridOffset.y ) / grid.y ) * grid.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];
|
|
|
|
|
2018-10-04 00:15:54 +00:00
|
|
|
if( !m_enableSnap )
|
|
|
|
return aPoint;
|
|
|
|
|
2015-11-03 16:19:42 +00:00
|
|
|
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;
|
2019-01-25 15:12:04 +00:00
|
|
|
pts[2] = aSeg.IntersectLines( SEG( nearest + VECTOR2I( -1, 1 ), nearest + VECTOR2I( 1, -1 ) ) );
|
|
|
|
pts[3] = aSeg.IntersectLines( SEG( nearest + VECTOR2I( -1, -1 ), nearest + VECTOR2I( 1, 1 ) ) );
|
2015-11-03 16:19:42 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
2019-05-17 00:13:21 +00:00
|
|
|
VECTOR2I GRID_HELPER::AlignToArc( const VECTOR2I& aPoint, const SHAPE_ARC& aArc )
|
|
|
|
{
|
|
|
|
if( !m_enableSnap )
|
|
|
|
return aPoint;
|
|
|
|
|
|
|
|
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 );
|
|
|
|
|
|
|
|
int min_d = std::numeric_limits<int>::max();
|
|
|
|
|
2020-06-12 22:00:28 +00:00
|
|
|
for( auto pt : { aArc.GetP0(), aArc.GetP1() } )
|
2019-05-17 00:13:21 +00:00
|
|
|
{
|
|
|
|
int d = ( pt - aPoint ).EuclideanNorm();
|
|
|
|
|
|
|
|
if( d < min_d )
|
|
|
|
{
|
|
|
|
min_d = d;
|
|
|
|
nearest = pt;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nearest;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-08-21 04:31:11 +00:00
|
|
|
VECTOR2I GRID_HELPER::BestDragOrigin( const VECTOR2I &aMousePos, std::vector<BOARD_ITEM*>& aItems )
|
2015-02-18 00:10:20 +00:00
|
|
|
{
|
|
|
|
clearAnchors();
|
2019-08-21 04:31:11 +00:00
|
|
|
|
2020-06-13 12:33:29 +00:00
|
|
|
for( BOARD_ITEM* item : aItems )
|
2019-08-21 04:31:11 +00:00
|
|
|
computeAnchors( item, aMousePos, true );
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2020-06-12 10:58:56 +00:00
|
|
|
double worldScale = m_toolMgr->GetView()->GetGAL()->GetWorldScale();
|
2015-02-18 00:10:20 +00:00
|
|
|
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
|
|
|
|
2018-11-16 18:01:54 +00:00
|
|
|
std::set<BOARD_ITEM*> GRID_HELPER::queryVisible( const BOX2I& aArea,
|
2020-06-13 12:33:29 +00:00
|
|
|
const std::vector<BOARD_ITEM*>& aSkip ) 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;
|
|
|
|
|
2020-06-12 10:58:56 +00:00
|
|
|
KIGFX::VIEW* view = m_toolMgr->GetView();
|
|
|
|
RENDER_SETTINGS* settings = view->GetPainter()->GetSettings();
|
2020-10-03 21:26:44 +00:00
|
|
|
const std::set<unsigned int>& activeLayers = settings->GetHighContrastLayers();
|
2020-06-12 10:58:56 +00:00
|
|
|
bool isHighContrast = settings->GetHighContrast();
|
|
|
|
|
2018-10-06 16:31:00 +00:00
|
|
|
view->Query( aArea, selectedItems );
|
2015-02-18 00:10:20 +00:00
|
|
|
|
2020-06-13 12:33:29 +00:00
|
|
|
for( const KIGFX::VIEW::LAYER_ITEM_PAIR& it : selectedItems )
|
2015-02-18 00:10:20 +00:00
|
|
|
{
|
2018-10-06 16:31:00 +00:00
|
|
|
BOARD_ITEM* item = static_cast<BOARD_ITEM*>( it.first );
|
2016-12-09 11:04:32 +00:00
|
|
|
|
2018-10-07 02:36:49 +00:00
|
|
|
// The item must be visible and on an active layer
|
2020-06-12 10:58:56 +00:00
|
|
|
if( view->IsVisible( item )
|
|
|
|
&& ( !isHighContrast || activeLayers.count( it.second ) )
|
2019-10-10 13:33:21 +00:00
|
|
|
&& item->ViewGetLOD( it.second, view ) < view->GetScale() )
|
2020-06-12 10:58:56 +00:00
|
|
|
{
|
2015-02-18 16:53:46 +00:00
|
|
|
items.insert ( item );
|
2020-06-12 10:58:56 +00:00
|
|
|
}
|
2015-02-18 00:10:20 +00:00
|
|
|
}
|
|
|
|
|
2018-11-16 18:01:54 +00:00
|
|
|
|
2020-06-13 12:33:29 +00:00
|
|
|
for( BOARD_ITEM* skipItem : aSkip )
|
|
|
|
items.erase( skipItem );
|
2018-11-16 18:01:54 +00:00
|
|
|
|
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 )
|
2018-10-04 00:15:54 +00:00
|
|
|
{
|
|
|
|
LSET layers;
|
2018-11-16 18:01:54 +00:00
|
|
|
std::vector<BOARD_ITEM*> item;
|
2018-10-04 00:15:54 +00:00
|
|
|
|
|
|
|
if( aDraggedItem )
|
2018-11-16 18:01:54 +00:00
|
|
|
{
|
2018-10-04 05:45:10 +00:00
|
|
|
layers = aDraggedItem->GetLayerSet();
|
2018-11-16 18:01:54 +00:00
|
|
|
item.push_back( aDraggedItem );
|
|
|
|
}
|
2018-10-04 00:15:54 +00:00
|
|
|
else
|
|
|
|
layers = LSET::AllLayersMask();
|
|
|
|
|
2018-11-16 18:01:54 +00:00
|
|
|
return BestSnapAnchor( aOrigin, layers, item );
|
2018-10-04 00:15:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-11-16 18:01:54 +00:00
|
|
|
VECTOR2I GRID_HELPER::BestSnapAnchor( const VECTOR2I& aOrigin, const LSET& aLayers,
|
2020-06-13 12:33:29 +00:00
|
|
|
const std::vector<BOARD_ITEM*>& aSkip )
|
2015-02-18 00:10:20 +00:00
|
|
|
{
|
2020-09-15 18:30:53 +00:00
|
|
|
int snapDist = GetGrid().x;
|
|
|
|
int snapRange = snapDist;
|
2015-02-18 00:10:20 +00:00
|
|
|
|
2020-06-13 12:33:29 +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();
|
|
|
|
|
2018-11-16 18:01:54 +00:00
|
|
|
for( BOARD_ITEM* item : queryVisible( bb, aSkip ) )
|
2015-02-18 16:53:46 +00:00
|
|
|
computeAnchors( item, aOrigin );
|
2015-02-18 00:10:20 +00:00
|
|
|
|
2020-06-13 12:33:29 +00:00
|
|
|
ANCHOR* nearest = nearestAnchor( aOrigin, SNAPPABLE, aLayers );
|
2015-02-18 16:53:46 +00:00
|
|
|
VECTOR2I nearestGrid = Align( aOrigin );
|
2017-04-20 14:37:36 +00:00
|
|
|
|
2020-09-11 17:33:12 +00:00
|
|
|
if( nearest )
|
|
|
|
snapDist = nearest->Distance( aOrigin );
|
2018-11-09 14:11:44 +00:00
|
|
|
|
2020-09-11 17:33:12 +00:00
|
|
|
// Existing snap lines need priority over new snaps
|
|
|
|
if( m_snapItem && m_enableSnapLine && m_enableSnap )
|
2020-01-19 04:42:10 +00:00
|
|
|
{
|
|
|
|
bool snapLine = false;
|
2020-09-11 17:33:12 +00:00
|
|
|
int x_dist = std::abs( m_viewSnapLine.GetPosition().x - aOrigin.x );
|
|
|
|
int y_dist = std::abs( m_viewSnapLine.GetPosition().y - aOrigin.y );
|
2020-01-19 04:42:10 +00:00
|
|
|
|
2020-09-11 17:33:12 +00:00
|
|
|
/// Allows de-snapping from the line if you are closer to another snap point
|
2020-09-29 01:37:48 +00:00
|
|
|
if( x_dist < snapRange && ( !nearest || snapDist > snapRange ) )
|
2020-01-19 04:42:10 +00:00
|
|
|
{
|
|
|
|
nearestGrid.x = m_viewSnapLine.GetPosition().x;
|
|
|
|
snapLine = true;
|
|
|
|
}
|
|
|
|
|
2020-09-29 01:37:48 +00:00
|
|
|
if( y_dist < snapRange && ( !nearest || snapDist > snapRange ) )
|
2020-01-19 04:42:10 +00:00
|
|
|
{
|
|
|
|
nearestGrid.y = m_viewSnapLine.GetPosition().y;
|
|
|
|
snapLine = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( snapLine && m_skipPoint != VECTOR2I( m_viewSnapLine.GetPosition() ) )
|
|
|
|
{
|
|
|
|
m_viewSnapLine.SetEndPosition( nearestGrid );
|
|
|
|
|
2020-06-12 10:58:56 +00:00
|
|
|
if( m_toolMgr->GetView()->IsVisible( &m_viewSnapLine ) )
|
|
|
|
m_toolMgr->GetView()->Update( &m_viewSnapLine, KIGFX::GEOMETRY );
|
2020-01-19 04:42:10 +00:00
|
|
|
else
|
2020-06-12 10:58:56 +00:00
|
|
|
m_toolMgr->GetView()->SetVisible( &m_viewSnapLine, true );
|
2020-01-19 04:42:10 +00:00
|
|
|
|
|
|
|
return nearestGrid;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-11 17:33:12 +00:00
|
|
|
if( nearest && m_enableSnap )
|
|
|
|
{
|
|
|
|
if( nearest->Distance( aOrigin ) <= snapRange )
|
|
|
|
{
|
|
|
|
m_viewSnapPoint.SetPosition( wxPoint( nearest->pos ) );
|
|
|
|
m_viewSnapLine.SetPosition( wxPoint( nearest->pos ) );
|
|
|
|
m_toolMgr->GetView()->SetVisible( &m_viewSnapLine, false );
|
|
|
|
|
|
|
|
if( m_toolMgr->GetView()->IsVisible( &m_viewSnapPoint ) )
|
|
|
|
m_toolMgr->GetView()->Update( &m_viewSnapPoint, KIGFX::GEOMETRY);
|
|
|
|
else
|
|
|
|
m_toolMgr->GetView()->SetVisible( &m_viewSnapPoint, true );
|
|
|
|
|
|
|
|
m_snapItem = nearest;
|
|
|
|
return nearest->pos;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-24 15:58:33 +00:00
|
|
|
m_snapItem = nullptr;
|
2020-06-12 10:58:56 +00:00
|
|
|
m_toolMgr->GetView()->SetVisible( &m_viewSnapPoint, false );
|
|
|
|
m_toolMgr->GetView()->SetVisible( &m_viewSnapLine, false );
|
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
|
|
|
|
2020-06-13 12:33:29 +00:00
|
|
|
BOARD_ITEM* GRID_HELPER::GetSnapped() const
|
2018-11-24 15:58:33 +00:00
|
|
|
{
|
|
|
|
if( !m_snapItem )
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
return m_snapItem->item;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-07-15 23:44:01 +00:00
|
|
|
void GRID_HELPER::computeAnchors( BOARD_ITEM* aItem, const VECTOR2I& aRefPos, bool aFrom )
|
2015-02-18 00:10:20 +00:00
|
|
|
{
|
2020-06-13 12:33:29 +00:00
|
|
|
VECTOR2I origin;
|
2020-06-12 10:58:56 +00:00
|
|
|
KIGFX::VIEW* view = m_toolMgr->GetView();
|
|
|
|
RENDER_SETTINGS* settings = view->GetPainter()->GetSettings();
|
2020-10-03 21:26:44 +00:00
|
|
|
const std::set<unsigned int>& activeLayers = settings->GetHighContrastLayers();
|
2020-06-12 10:58:56 +00:00
|
|
|
bool isHighContrast = settings->GetHighContrast();
|
2015-02-18 00:10:20 +00:00
|
|
|
|
2020-09-29 01:03:19 +00:00
|
|
|
auto handlePadShape =
|
2020-11-12 22:30:02 +00:00
|
|
|
[&]( PAD* aPad )
|
2020-09-29 01:03:19 +00:00
|
|
|
{
|
|
|
|
addAnchor( aPad->GetPosition(), CORNER | SNAPPABLE, aPad );
|
|
|
|
|
2020-09-29 03:59:44 +00:00
|
|
|
const std::shared_ptr<SHAPE> eshape = aPad->GetEffectiveShape( aPad->GetLayer() );
|
|
|
|
|
|
|
|
wxASSERT( eshape->Type() == SH_COMPOUND );
|
|
|
|
const std::vector<SHAPE*> shapes =
|
|
|
|
static_cast<const SHAPE_COMPOUND*>( eshape.get() )->Shapes();
|
2020-09-29 01:03:19 +00:00
|
|
|
|
2020-09-29 03:59:44 +00:00
|
|
|
for( const SHAPE* shape : shapes )
|
2020-09-29 01:03:19 +00:00
|
|
|
{
|
2020-09-29 03:59:44 +00:00
|
|
|
switch( shape->Type() )
|
|
|
|
{
|
|
|
|
case SH_RECT:
|
|
|
|
{
|
|
|
|
const SHAPE_RECT* rect = static_cast<const SHAPE_RECT*>( shape );
|
|
|
|
SHAPE_LINE_CHAIN outline = rect->Outline();
|
|
|
|
|
|
|
|
for( int i = 0; i < outline.SegmentCount(); i++ )
|
|
|
|
{
|
|
|
|
const SEG& seg = outline.CSegment( i );
|
|
|
|
addAnchor( seg.A, OUTLINE | SNAPPABLE, aPad );
|
|
|
|
addAnchor( seg.Center(), OUTLINE | SNAPPABLE, aPad );
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case SH_SEGMENT:
|
|
|
|
{
|
|
|
|
const SHAPE_SEGMENT* segment = static_cast<const SHAPE_SEGMENT*>( shape );
|
|
|
|
|
|
|
|
int offset = segment->GetWidth() / 2;
|
|
|
|
SEG seg = segment->GetSeg();
|
|
|
|
VECTOR2I normal = ( seg.B - seg.A ).Resize( offset ).Rotate( -M_PI_2 );
|
|
|
|
|
|
|
|
/*
|
|
|
|
* TODO: This creates more snap points than necessary for rounded rect pads
|
|
|
|
* because they are built up of overlapping segments. We could fix this if
|
|
|
|
* desired by testing these to see if they are "inside" the pad.
|
|
|
|
*/
|
|
|
|
|
|
|
|
addAnchor( seg.A + normal, OUTLINE | SNAPPABLE, aPad );
|
|
|
|
addAnchor( seg.A - normal, OUTLINE | SNAPPABLE, aPad );
|
|
|
|
addAnchor( seg.B + normal, OUTLINE | SNAPPABLE, aPad );
|
|
|
|
addAnchor( seg.B - normal, OUTLINE | SNAPPABLE, aPad );
|
|
|
|
addAnchor( seg.Center() + normal, OUTLINE | SNAPPABLE, aPad );
|
|
|
|
addAnchor( seg.Center() - normal, OUTLINE | SNAPPABLE, aPad );
|
|
|
|
|
|
|
|
normal = normal.Rotate( M_PI_2 );
|
|
|
|
|
|
|
|
addAnchor( seg.A - normal, OUTLINE | SNAPPABLE, aPad );
|
|
|
|
addAnchor( seg.B + normal, OUTLINE | SNAPPABLE, aPad );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case SH_CIRCLE:
|
|
|
|
{
|
|
|
|
const SHAPE_CIRCLE* circle = static_cast<const SHAPE_CIRCLE*>( shape );
|
|
|
|
|
|
|
|
int r = circle->GetRadius();
|
|
|
|
VECTOR2I start = circle->GetCenter();
|
|
|
|
|
|
|
|
addAnchor( start + VECTOR2I( -r, 0 ), OUTLINE | SNAPPABLE, aPad );
|
|
|
|
addAnchor( start + VECTOR2I( r, 0 ), OUTLINE | SNAPPABLE, aPad );
|
|
|
|
addAnchor( start + VECTOR2I( 0, -r ), OUTLINE | SNAPPABLE, aPad );
|
|
|
|
addAnchor( start + VECTOR2I( 0, r ), OUTLINE | SNAPPABLE, aPad );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case SH_ARC:
|
|
|
|
{
|
|
|
|
const SHAPE_ARC* arc = static_cast<const SHAPE_ARC*>( shape );
|
2020-09-29 01:03:19 +00:00
|
|
|
|
2020-09-29 03:59:44 +00:00
|
|
|
addAnchor( arc->GetP0(), OUTLINE | SNAPPABLE, aPad );
|
|
|
|
addAnchor( arc->GetP1(), OUTLINE | SNAPPABLE, aPad );
|
|
|
|
addAnchor( arc->GetArcMid(), OUTLINE | SNAPPABLE, aPad );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case SH_SIMPLE:
|
2020-09-29 01:03:19 +00:00
|
|
|
{
|
2020-09-29 03:59:44 +00:00
|
|
|
const SHAPE_SIMPLE* poly = static_cast<const SHAPE_SIMPLE*>( shape );
|
|
|
|
|
|
|
|
for( size_t i = 0; i < poly->GetSegmentCount(); i++ )
|
|
|
|
{
|
|
|
|
const SEG& seg = poly->GetSegment( i );
|
2020-09-29 01:03:19 +00:00
|
|
|
|
2020-09-29 03:59:44 +00:00
|
|
|
addAnchor( seg.A, OUTLINE | SNAPPABLE, aPad );
|
|
|
|
addAnchor( seg.Center(), OUTLINE | SNAPPABLE, aPad );
|
|
|
|
|
|
|
|
if( i == poly->GetSegmentCount() - 1 )
|
|
|
|
addAnchor( seg.B, OUTLINE | SNAPPABLE, aPad );
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2020-09-29 01:03:19 +00:00
|
|
|
|
2020-09-29 03:59:44 +00:00
|
|
|
case SH_POLY_SET:
|
|
|
|
case SH_LINE_CHAIN:
|
|
|
|
case SH_COMPOUND:
|
|
|
|
case SH_POLY_SET_TRIANGLE:
|
|
|
|
case SH_NULL:
|
|
|
|
default:
|
|
|
|
break;
|
2020-09-29 01:03:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
switch( aItem->Type() )
|
2015-02-18 00:10:20 +00:00
|
|
|
{
|
2020-11-13 12:21:02 +00:00
|
|
|
case PCB_FOOTPRINT_T:
|
2015-02-18 00:10:20 +00:00
|
|
|
{
|
2020-11-13 15:15:52 +00:00
|
|
|
FOOTPRINT* footprint = static_cast<FOOTPRINT*>( aItem );
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2020-11-13 12:21:02 +00:00
|
|
|
for( PAD* pad : footprint->Pads() )
|
2017-07-27 09:13:25 +00:00
|
|
|
{
|
2020-11-13 12:21:02 +00:00
|
|
|
// Getting pads from the footprint requires re-checking that the pad is shown
|
2020-06-13 12:33:29 +00:00
|
|
|
if( ( aFrom || m_magneticSettings->pads == MAGNETIC_OPTIONS::CAPTURE_ALWAYS )
|
2020-11-13 12:21:02 +00:00
|
|
|
&& pad->GetBoundingBox().Contains( wxPoint( aRefPos.x, aRefPos.y ) )
|
|
|
|
&& view->IsVisible( pad )
|
|
|
|
&& ( !isHighContrast || activeLayers.count( pad->GetLayer() ) )
|
|
|
|
&& pad->ViewGetLOD( pad->GetLayer(), view ) < view->GetScale() )
|
2017-07-27 09:13:25 +00:00
|
|
|
{
|
2020-09-29 01:03:19 +00:00
|
|
|
handlePadShape( pad );
|
2017-07-27 09:13:25 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2015-02-18 00:10:20 +00:00
|
|
|
|
2020-11-13 12:21:02 +00:00
|
|
|
// if the cursor is not over a pad, then drag the footprint by its origin
|
|
|
|
addAnchor( footprint->GetPosition(), ORIGIN | SNAPPABLE, footprint );
|
2015-02-18 00:10:20 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-03-11 17:06:44 +00:00
|
|
|
case PCB_PAD_T:
|
|
|
|
{
|
2020-06-13 12:33:29 +00:00
|
|
|
if( aFrom || m_magneticSettings->pads == MAGNETIC_OPTIONS::CAPTURE_ALWAYS )
|
2019-01-29 14:04:12 +00:00
|
|
|
{
|
2020-11-12 22:30:02 +00:00
|
|
|
PAD* pad = static_cast<PAD*>( aItem );
|
2020-09-29 01:03:19 +00:00
|
|
|
handlePadShape( pad );
|
2019-01-29 14:04:12 +00:00
|
|
|
}
|
|
|
|
|
2015-03-11 17:06:44 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-10-04 14:19:33 +00:00
|
|
|
case PCB_FP_SHAPE_T:
|
|
|
|
case PCB_SHAPE_T:
|
2015-02-18 00:10:20 +00:00
|
|
|
{
|
2020-06-13 12:33:29 +00:00
|
|
|
if( !m_magneticSettings->graphics )
|
2019-01-29 14:04:12 +00:00
|
|
|
break;
|
|
|
|
|
2020-10-04 23:34:59 +00:00
|
|
|
PCB_SHAPE* shape = static_cast<PCB_SHAPE*>( aItem );
|
|
|
|
VECTOR2I start = shape->GetStart();
|
|
|
|
VECTOR2I end = shape->GetEnd();
|
2015-02-18 00:10:20 +00:00
|
|
|
|
2020-10-04 23:34:59 +00:00
|
|
|
switch( shape->GetShape() )
|
2015-02-18 00:10:20 +00:00
|
|
|
{
|
|
|
|
case S_CIRCLE:
|
|
|
|
{
|
2015-02-18 16:53:46 +00:00
|
|
|
int r = ( start - end ).EuclideanNorm();
|
|
|
|
|
2020-10-04 23:34:59 +00:00
|
|
|
addAnchor( start, ORIGIN | SNAPPABLE, shape );
|
|
|
|
addAnchor( start + VECTOR2I( -r, 0 ), OUTLINE | SNAPPABLE, shape );
|
|
|
|
addAnchor( start + VECTOR2I( r, 0 ), OUTLINE | SNAPPABLE, shape );
|
|
|
|
addAnchor( start + VECTOR2I( 0, -r ), OUTLINE | SNAPPABLE, shape );
|
|
|
|
addAnchor( start + VECTOR2I( 0, r ), OUTLINE | SNAPPABLE, shape );
|
2015-02-18 00:10:20 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case S_ARC:
|
2020-10-04 23:34:59 +00:00
|
|
|
origin = shape->GetCenter();
|
|
|
|
addAnchor( shape->GetArcStart(), CORNER | SNAPPABLE, shape );
|
|
|
|
addAnchor( shape->GetArcEnd(), CORNER | SNAPPABLE, shape );
|
|
|
|
addAnchor( shape->GetArcMid(), CORNER | SNAPPABLE, shape );
|
|
|
|
addAnchor( origin, ORIGIN | SNAPPABLE, shape );
|
2015-02-18 16:53:46 +00:00
|
|
|
break;
|
2018-10-05 03:23:05 +00:00
|
|
|
|
|
|
|
case S_RECT:
|
2020-09-29 01:03:19 +00:00
|
|
|
{
|
|
|
|
VECTOR2I point2( end.x, start.y );
|
|
|
|
VECTOR2I point3( start.x, end.y );
|
|
|
|
SEG first( start, point2 );
|
|
|
|
SEG second( point2, end );
|
|
|
|
SEG third( end, point3 );
|
|
|
|
SEG fourth( point3, start );
|
|
|
|
|
2020-10-04 23:34:59 +00:00
|
|
|
addAnchor( first.A, CORNER | SNAPPABLE, shape );
|
|
|
|
addAnchor( first.Center(), CORNER | SNAPPABLE, shape );
|
|
|
|
addAnchor( second.A, CORNER | SNAPPABLE, shape );
|
|
|
|
addAnchor( second.Center(), CORNER | SNAPPABLE, shape );
|
|
|
|
addAnchor( third.A, CORNER | SNAPPABLE, shape );
|
|
|
|
addAnchor( third.Center(), CORNER | SNAPPABLE, shape );
|
|
|
|
addAnchor( fourth.A, CORNER | SNAPPABLE, shape );
|
|
|
|
addAnchor( fourth.Center(), CORNER | SNAPPABLE, shape );
|
2018-10-05 03:23:05 +00:00
|
|
|
break;
|
2020-09-29 01:03:19 +00:00
|
|
|
}
|
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;
|
2020-10-04 23:34:59 +00:00
|
|
|
addAnchor( start, CORNER | SNAPPABLE, shape );
|
|
|
|
addAnchor( end, CORNER | SNAPPABLE, shape );
|
|
|
|
addAnchor( SEG( start, end ).Center(), CORNER | SNAPPABLE, shape );
|
|
|
|
addAnchor( origin, ORIGIN, shape );
|
2015-02-18 00:10:20 +00:00
|
|
|
break;
|
|
|
|
|
2017-10-19 21:14:01 +00:00
|
|
|
case S_POLYGON:
|
2020-10-04 23:34:59 +00:00
|
|
|
for( const VECTOR2I& p : shape->BuildPolyPointsList() )
|
|
|
|
addAnchor( p, CORNER | SNAPPABLE, shape );
|
2018-10-05 03:23:05 +00:00
|
|
|
|
2017-10-19 21:14:01 +00:00
|
|
|
break;
|
|
|
|
|
2018-10-05 03:23:05 +00:00
|
|
|
case S_CURVE:
|
2020-10-04 23:34:59 +00:00
|
|
|
addAnchor( start, CORNER | SNAPPABLE, shape );
|
|
|
|
addAnchor( end, CORNER | SNAPPABLE, shape );
|
2020-04-24 23:44:09 +00:00
|
|
|
KI_FALLTHROUGH;
|
|
|
|
|
2015-02-18 00:10:20 +00:00
|
|
|
default:
|
2020-10-04 23:34:59 +00:00
|
|
|
origin = shape->GetStart();
|
|
|
|
addAnchor( origin, ORIGIN | SNAPPABLE, shape );
|
2015-02-18 00:10:20 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case PCB_TRACE_T:
|
2019-05-17 00:13:21 +00:00
|
|
|
case PCB_ARC_T:
|
2015-02-18 00:10:20 +00:00
|
|
|
{
|
2020-06-13 12:33:29 +00:00
|
|
|
if( aFrom || m_magneticSettings->tracks == MAGNETIC_OPTIONS::CAPTURE_ALWAYS )
|
2019-01-29 14:04:12 +00:00
|
|
|
{
|
|
|
|
TRACK* track = static_cast<TRACK*>( aItem );
|
|
|
|
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;
|
|
|
|
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
|
|
|
|
2018-10-05 03:23:05 +00:00
|
|
|
case PCB_MARKER_T:
|
|
|
|
case PCB_TARGET_T:
|
|
|
|
addAnchor( aItem->GetPosition(), ORIGIN | CORNER | SNAPPABLE, aItem );
|
2015-07-07 16:36:32 +00:00
|
|
|
break;
|
|
|
|
|
2019-01-29 14:04:12 +00:00
|
|
|
case PCB_VIA_T:
|
|
|
|
{
|
2020-06-13 12:33:29 +00:00
|
|
|
if( aFrom || m_magneticSettings->tracks == MAGNETIC_OPTIONS::CAPTURE_ALWAYS )
|
2019-01-29 14:04:12 +00:00
|
|
|
addAnchor( aItem->GetPosition(), ORIGIN | CORNER | SNAPPABLE, aItem );
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
case PCB_ZONE_T:
|
2015-02-18 00:10:20 +00:00
|
|
|
{
|
2020-11-11 23:05:59 +00:00
|
|
|
const SHAPE_POLY_SET* outline = static_cast<const ZONE*>( 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;
|
|
|
|
}
|
|
|
|
|
2020-09-12 20:09:40 +00:00
|
|
|
case PCB_DIM_ALIGNED_T:
|
2020-09-22 02:32:40 +00:00
|
|
|
case PCB_DIM_ORTHOGONAL_T:
|
2018-10-05 03:23:05 +00:00
|
|
|
{
|
2020-09-09 03:17:08 +00:00
|
|
|
const ALIGNED_DIMENSION* dim = static_cast<const ALIGNED_DIMENSION*>( aItem );
|
|
|
|
addAnchor( dim->GetCrossbarStart(), CORNER | SNAPPABLE, aItem );
|
|
|
|
addAnchor( dim->GetCrossbarEnd(), CORNER | SNAPPABLE, aItem );
|
|
|
|
addAnchor( dim->GetStart(), CORNER | SNAPPABLE, aItem );
|
|
|
|
addAnchor( dim->GetEnd(), CORNER | SNAPPABLE, aItem );
|
2018-10-05 03:23:05 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-09-17 00:54:58 +00:00
|
|
|
case PCB_DIM_CENTER_T:
|
|
|
|
{
|
|
|
|
const CENTER_DIMENSION* dim = static_cast<const CENTER_DIMENSION*>( aItem );
|
|
|
|
addAnchor( dim->GetStart(), CORNER | SNAPPABLE, aItem );
|
|
|
|
addAnchor( dim->GetEnd(), CORNER | SNAPPABLE, aItem );
|
|
|
|
|
|
|
|
VECTOR2I start( dim->GetStart() );
|
|
|
|
VECTOR2I radial( dim->GetEnd() - dim->GetStart() );
|
|
|
|
|
|
|
|
for( int i = 0; i < 2; i++ )
|
|
|
|
{
|
|
|
|
radial = radial.Rotate( DEG2RAD( 90 ) );
|
|
|
|
addAnchor( start + radial, CORNER | SNAPPABLE, aItem );
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-09-12 20:09:40 +00:00
|
|
|
case PCB_DIM_LEADER_T:
|
|
|
|
{
|
|
|
|
const LEADER* leader = static_cast<const LEADER*>( aItem );
|
|
|
|
addAnchor( leader->GetStart(), CORNER | SNAPPABLE, aItem );
|
|
|
|
addAnchor( leader->GetEnd(), CORNER | SNAPPABLE, aItem );
|
|
|
|
addAnchor( leader->Text().GetPosition(), CORNER | SNAPPABLE, aItem );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-10-04 14:19:33 +00:00
|
|
|
case PCB_FP_TEXT_T:
|
2015-02-18 00:10:20 +00:00
|
|
|
case PCB_TEXT_T:
|
2015-02-18 16:53:46 +00:00
|
|
|
addAnchor( aItem->GetPosition(), ORIGIN, aItem );
|
2018-10-05 03:23:05 +00:00
|
|
|
break;
|
2015-02-18 00:10:20 +00:00
|
|
|
|
2018-10-05 03:23:05 +00:00
|
|
|
default:
|
|
|
|
break;
|
2015-02-18 00:10:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-06-13 12:33:29 +00:00
|
|
|
GRID_HELPER::ANCHOR* GRID_HELPER::nearestAnchor( const VECTOR2I& aPos, int aFlags,
|
|
|
|
LSET aMatchLayers )
|
2015-02-18 16:53:46 +00:00
|
|
|
{
|
2020-06-13 12:33:29 +00:00
|
|
|
double minDist = std::numeric_limits<double>::max();
|
2017-04-20 14:37:36 +00:00
|
|
|
ANCHOR* best = NULL;
|
2015-02-18 00:10:20 +00:00
|
|
|
|
2017-04-20 14:37:36 +00:00
|
|
|
for( ANCHOR& a : m_anchors )
|
|
|
|
{
|
2018-10-05 03:41:17 +00:00
|
|
|
if( ( aMatchLayers & a.item->GetLayerSet() ) == 0 )
|
2017-04-20 14:37:36 +00:00
|
|
|
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
|
|
|
}
|