2020-09-09 02:54:17 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2014 CERN
|
2023-08-26 12:29:24 +00:00
|
|
|
* Copyright (C) 2018-2023 KiCad Developers, see AUTHORS.txt for contributors.
|
2020-09-09 02:54:17 +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
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <functional>
|
2021-03-20 15:35:37 +00:00
|
|
|
#include <macros.h>
|
2023-09-18 23:52:27 +00:00
|
|
|
#include <gal/graphics_abstraction_layer.h>
|
2020-09-09 02:54:17 +00:00
|
|
|
#include <sch_item.h>
|
2021-02-02 17:40:04 +00:00
|
|
|
#include <sch_line.h>
|
2023-11-25 12:38:24 +00:00
|
|
|
#include <sch_table.h>
|
|
|
|
#include <sch_tablecell.h>
|
2020-09-09 02:54:17 +00:00
|
|
|
#include <sch_painter.h>
|
|
|
|
#include <tool/tool_manager.h>
|
2023-07-23 17:51:42 +00:00
|
|
|
#include <settings/app_settings.h>
|
2021-02-02 17:40:04 +00:00
|
|
|
#include <trigo.h>
|
2020-09-09 02:54:17 +00:00
|
|
|
#include <view/view.h>
|
|
|
|
#include "ee_grid_helper.h"
|
|
|
|
|
|
|
|
|
|
|
|
EE_GRID_HELPER::EE_GRID_HELPER( TOOL_MANAGER* aToolMgr ) :
|
2021-01-16 23:17:32 +00:00
|
|
|
GRID_HELPER( aToolMgr )
|
2020-09-09 02:54:17 +00:00
|
|
|
{
|
|
|
|
KIGFX::VIEW* view = m_toolMgr->GetView();
|
|
|
|
|
|
|
|
m_viewAxis.SetSize( 20000 );
|
|
|
|
m_viewAxis.SetStyle( KIGFX::ORIGIN_VIEWITEM::CROSS );
|
|
|
|
m_viewAxis.SetColor( COLOR4D( 0.0, 0.1, 0.4, 0.8 ) );
|
|
|
|
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( 0.0, 0.1, 0.4, 1.0 ) );
|
|
|
|
m_viewSnapPoint.SetDrawAtZero( true );
|
|
|
|
view->Add( &m_viewSnapPoint );
|
|
|
|
view->SetVisible( &m_viewSnapPoint, false );
|
|
|
|
|
|
|
|
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 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-10-23 13:39:08 +00:00
|
|
|
EE_GRID_HELPER::~EE_GRID_HELPER()
|
|
|
|
{
|
|
|
|
KIGFX::VIEW* view = m_toolMgr->GetView();
|
|
|
|
|
|
|
|
view->Remove( &m_viewAxis );
|
|
|
|
view->Remove( &m_viewSnapPoint );
|
|
|
|
view->Remove( &m_viewSnapLine );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-07-23 17:51:42 +00:00
|
|
|
VECTOR2I EE_GRID_HELPER::BestDragOrigin( const VECTOR2I& aMousePos, GRID_HELPER_GRIDS aGrid,
|
2020-12-03 15:10:23 +00:00
|
|
|
const EE_SELECTION& aItems )
|
2020-09-09 02:54:17 +00:00
|
|
|
{
|
|
|
|
clearAnchors();
|
|
|
|
|
2023-08-21 14:32:44 +00:00
|
|
|
// If we're working with any connectable objects, skip non-connectable objects
|
|
|
|
// since they are often off-grid, e.g. text anchors
|
|
|
|
bool hasConnectables = false;
|
2021-11-14 16:54:04 +00:00
|
|
|
|
2020-12-02 23:17:56 +00:00
|
|
|
for( EDA_ITEM* item : aItems )
|
2023-08-21 14:32:44 +00:00
|
|
|
{
|
|
|
|
GRID_HELPER_GRIDS grid = GetItemGrid( static_cast<SCH_ITEM*>( item ) );
|
|
|
|
if( grid == GRID_CONNECTABLE || grid == GRID_WIRES )
|
|
|
|
{
|
|
|
|
hasConnectables = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for( EDA_ITEM* item : aItems )
|
|
|
|
computeAnchors( static_cast<SCH_ITEM*>( item ), aMousePos, true, !hasConnectables );
|
2020-09-09 02:54:17 +00:00
|
|
|
|
|
|
|
double worldScale = m_toolMgr->GetView()->GetGAL()->GetWorldScale();
|
|
|
|
double lineSnapMinCornerDistance = 50.0 / worldScale;
|
|
|
|
|
2023-07-23 17:51:42 +00:00
|
|
|
ANCHOR* nearestOutline = nearestAnchor( aMousePos, OUTLINE, aGrid );
|
|
|
|
ANCHOR* nearestCorner = nearestAnchor( aMousePos, CORNER, aGrid );
|
|
|
|
ANCHOR* nearestOrigin = nearestAnchor( aMousePos, ORIGIN, aGrid );
|
2021-07-16 20:13:26 +00:00
|
|
|
ANCHOR* best = nullptr;
|
2020-09-09 02:54:17 +00:00
|
|
|
double minDist = std::numeric_limits<double>::max();
|
|
|
|
|
|
|
|
if( nearestOrigin )
|
|
|
|
{
|
|
|
|
minDist = nearestOrigin->Distance( aMousePos );
|
|
|
|
best = nearestOrigin;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( nearestCorner )
|
|
|
|
{
|
|
|
|
double dist = nearestCorner->Distance( aMousePos );
|
|
|
|
|
|
|
|
if( dist < minDist )
|
|
|
|
{
|
|
|
|
minDist = dist;
|
|
|
|
best = nearestCorner;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( nearestOutline )
|
|
|
|
{
|
|
|
|
double dist = nearestOutline->Distance( aMousePos );
|
|
|
|
|
|
|
|
if( minDist > lineSnapMinCornerDistance && dist < minDist )
|
|
|
|
best = nearestOutline;
|
|
|
|
}
|
|
|
|
|
|
|
|
return best ? best->pos : aMousePos;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-07-23 17:51:42 +00:00
|
|
|
VECTOR2I EE_GRID_HELPER::BestSnapAnchor( const VECTOR2I& aOrigin, GRID_HELPER_GRIDS aGrid,
|
|
|
|
SCH_ITEM* aSkip )
|
2020-09-09 02:54:17 +00:00
|
|
|
{
|
2020-12-03 15:10:23 +00:00
|
|
|
EE_SELECTION skipItems;
|
|
|
|
skipItems.Add( aSkip );
|
2020-12-02 23:17:56 +00:00
|
|
|
|
2023-07-23 17:51:42 +00:00
|
|
|
return BestSnapAnchor( aOrigin, aGrid, skipItems );
|
2020-09-09 02:54:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-07-23 17:51:42 +00:00
|
|
|
VECTOR2I EE_GRID_HELPER::BestSnapAnchor( const VECTOR2I& aOrigin, GRID_HELPER_GRIDS aGrid,
|
2020-12-02 23:17:56 +00:00
|
|
|
const EE_SELECTION& aSkip )
|
2020-09-09 02:54:17 +00:00
|
|
|
{
|
2022-09-16 23:25:07 +00:00
|
|
|
constexpr int snapRange = SNAP_RANGE * schIUScale.IU_PER_MILS;
|
2020-09-09 02:54:17 +00:00
|
|
|
|
2020-12-04 22:48:13 +00:00
|
|
|
VECTOR2I pt = aOrigin;
|
|
|
|
VECTOR2I snapDist( snapRange, snapRange );
|
|
|
|
bool snapLineX = false;
|
|
|
|
bool snapLineY = false;
|
|
|
|
bool snapPoint = false;
|
|
|
|
bool gridChecked = false;
|
|
|
|
|
|
|
|
BOX2I bb( VECTOR2I( aOrigin.x - snapRange / 2, aOrigin.y - snapRange / 2 ),
|
|
|
|
VECTOR2I( snapRange, snapRange ) );
|
2020-09-09 02:54:17 +00:00
|
|
|
|
|
|
|
clearAnchors();
|
|
|
|
|
|
|
|
for( SCH_ITEM* item : queryVisible( bb, aSkip ) )
|
|
|
|
computeAnchors( item, aOrigin );
|
|
|
|
|
2023-07-23 17:51:42 +00:00
|
|
|
ANCHOR* nearest = nearestAnchor( aOrigin, SNAPPABLE, aGrid );
|
|
|
|
VECTOR2I nearestGrid = Align( aOrigin, aGrid );
|
2020-09-09 02:54:17 +00:00
|
|
|
|
2020-12-04 22:48:13 +00:00
|
|
|
if( m_enableSnapLine && m_snapItem && m_skipPoint != VECTOR2I( m_viewSnapLine.GetPosition() ) )
|
2020-09-09 02:54:17 +00:00
|
|
|
{
|
2020-12-04 22:48:13 +00:00
|
|
|
if( std::abs( m_viewSnapLine.GetPosition().x - aOrigin.x ) < snapDist.x )
|
|
|
|
{
|
|
|
|
pt.x = m_viewSnapLine.GetPosition().x;
|
|
|
|
snapDist.x = std::abs( m_viewSnapLine.GetPosition().x - aOrigin.x );
|
|
|
|
snapLineX = true;
|
|
|
|
}
|
2020-09-09 02:54:17 +00:00
|
|
|
|
2020-12-04 22:48:13 +00:00
|
|
|
if( std::abs( m_viewSnapLine.GetPosition().y - aOrigin.y ) < snapDist.y )
|
2020-09-09 02:54:17 +00:00
|
|
|
{
|
2020-12-04 22:48:13 +00:00
|
|
|
pt.y = m_viewSnapLine.GetPosition().y;
|
|
|
|
snapDist.y = std::abs( m_viewSnapLine.GetPosition().y - aOrigin.y );
|
|
|
|
snapLineY = true;
|
2020-09-09 02:54:17 +00:00
|
|
|
}
|
|
|
|
|
2021-02-10 00:01:36 +00:00
|
|
|
if( canUseGrid() && std::abs( nearestGrid.x - aOrigin.x ) < snapDist.x )
|
2020-09-09 02:54:17 +00:00
|
|
|
{
|
2020-12-04 22:48:13 +00:00
|
|
|
pt.x = nearestGrid.x;
|
|
|
|
snapDist.x = std::abs( nearestGrid.x - aOrigin.x );
|
|
|
|
snapLineX = false;
|
2020-09-09 02:54:17 +00:00
|
|
|
}
|
|
|
|
|
2021-02-10 00:01:36 +00:00
|
|
|
if( canUseGrid() && std::abs( nearestGrid.y - aOrigin.y ) < snapDist.y )
|
2020-09-09 02:54:17 +00:00
|
|
|
{
|
2020-12-04 22:48:13 +00:00
|
|
|
pt.y = nearestGrid.y;
|
2020-12-16 23:54:53 +00:00
|
|
|
snapDist.y = std::abs( nearestGrid.y - aOrigin.y );
|
2020-12-04 22:48:13 +00:00
|
|
|
snapLineY = false;
|
|
|
|
}
|
2020-09-09 02:54:17 +00:00
|
|
|
|
2020-12-04 22:48:13 +00:00
|
|
|
gridChecked = true;
|
|
|
|
}
|
2020-09-09 02:54:17 +00:00
|
|
|
|
2020-12-04 22:48:13 +00:00
|
|
|
if( m_enableSnap && nearest && nearest->Distance( aOrigin ) < snapDist.EuclideanNorm() )
|
|
|
|
{
|
|
|
|
|
2021-02-10 00:01:36 +00:00
|
|
|
if( canUseGrid() && ( nearestGrid - aOrigin ).EuclideanNorm() < snapDist.EuclideanNorm() )
|
2020-12-04 22:48:13 +00:00
|
|
|
{
|
|
|
|
pt = nearestGrid;
|
|
|
|
snapDist.x = std::abs( nearestGrid.x - aOrigin.x );
|
|
|
|
snapDist.y = std::abs( nearestGrid.y - aOrigin.y );
|
|
|
|
snapPoint = false;
|
2020-09-09 02:54:17 +00:00
|
|
|
}
|
2021-02-10 00:01:36 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
pt = nearest->pos;
|
|
|
|
snapDist.x = std::abs( nearest->pos.x - aOrigin.x );
|
|
|
|
snapDist.y = std::abs( nearest->pos.y - aOrigin.y );
|
|
|
|
snapPoint = true;
|
|
|
|
}
|
2020-12-04 22:48:13 +00:00
|
|
|
|
2021-02-10 00:01:36 +00:00
|
|
|
snapLineX = snapLineY = false;
|
2020-12-04 22:48:13 +00:00
|
|
|
gridChecked = true;
|
2020-09-09 02:54:17 +00:00
|
|
|
}
|
|
|
|
|
2021-02-10 00:01:36 +00:00
|
|
|
if( canUseGrid() && !gridChecked )
|
2020-12-04 22:48:13 +00:00
|
|
|
pt = nearestGrid;
|
|
|
|
|
|
|
|
if( snapLineX || snapLineY )
|
2020-09-11 17:33:12 +00:00
|
|
|
{
|
2020-12-04 22:48:13 +00:00
|
|
|
m_viewSnapLine.SetEndPosition( pt );
|
2020-09-11 17:33:12 +00:00
|
|
|
|
2020-12-04 22:48:13 +00:00
|
|
|
if( m_toolMgr->GetView()->IsVisible( &m_viewSnapLine ) )
|
|
|
|
m_toolMgr->GetView()->Update( &m_viewSnapLine, KIGFX::GEOMETRY );
|
|
|
|
else
|
|
|
|
m_toolMgr->GetView()->SetVisible( &m_viewSnapLine, true );
|
|
|
|
}
|
|
|
|
else if( snapPoint )
|
|
|
|
{
|
|
|
|
m_snapItem = nearest;
|
2022-01-01 18:57:44 +00:00
|
|
|
m_viewSnapPoint.SetPosition( pt );
|
|
|
|
m_viewSnapLine.SetPosition( pt );
|
2020-09-11 17:33:12 +00:00
|
|
|
|
2020-12-04 22:48:13 +00:00
|
|
|
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 );
|
2020-09-11 17:33:12 +00:00
|
|
|
}
|
2020-12-04 22:48:13 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
m_toolMgr->GetView()->SetVisible( &m_viewSnapPoint, false );
|
|
|
|
m_toolMgr->GetView()->SetVisible( &m_viewSnapLine, false );
|
|
|
|
}
|
|
|
|
|
|
|
|
return pt;
|
2020-09-09 02:54:17 +00:00
|
|
|
}
|
|
|
|
|
2023-07-23 17:51:42 +00:00
|
|
|
|
|
|
|
VECTOR2D EE_GRID_HELPER::GetGridSize( GRID_HELPER_GRIDS aGrid ) const
|
|
|
|
{
|
|
|
|
const GRID_SETTINGS& grid = m_toolMgr->GetSettings()->m_Window.grid;
|
2023-08-30 17:33:04 +00:00
|
|
|
int idx = -1;
|
2023-07-23 17:51:42 +00:00
|
|
|
|
|
|
|
VECTOR2D g = m_toolMgr->GetView()->GetGAL()->GetGridSize();
|
|
|
|
|
|
|
|
if( !grid.overrides_enabled )
|
|
|
|
return g;
|
|
|
|
|
|
|
|
switch( aGrid )
|
|
|
|
{
|
|
|
|
case GRID_CONNECTABLE:
|
2023-08-26 12:29:24 +00:00
|
|
|
if( grid.override_connected )
|
2023-08-30 17:33:04 +00:00
|
|
|
idx = grid.override_connected_idx;
|
2023-07-23 17:51:42 +00:00
|
|
|
|
|
|
|
break;
|
2023-08-26 12:29:24 +00:00
|
|
|
|
2023-07-23 17:51:42 +00:00
|
|
|
case GRID_WIRES:
|
|
|
|
if( grid.override_wires )
|
2023-08-30 17:33:04 +00:00
|
|
|
idx = grid.override_wires_idx;
|
2023-07-23 17:51:42 +00:00
|
|
|
|
|
|
|
break;
|
2023-08-26 12:29:24 +00:00
|
|
|
|
2023-07-23 17:51:42 +00:00
|
|
|
case GRID_TEXT:
|
|
|
|
if( grid.override_text )
|
2023-08-30 17:33:04 +00:00
|
|
|
idx = grid.override_text_idx;
|
2023-07-23 17:51:42 +00:00
|
|
|
|
|
|
|
break;
|
2023-08-26 12:29:24 +00:00
|
|
|
|
2023-07-23 17:51:42 +00:00
|
|
|
case GRID_GRAPHICS:
|
|
|
|
if( grid.override_graphics )
|
2023-08-30 17:33:04 +00:00
|
|
|
idx = grid.override_graphics_idx;
|
2023-07-23 17:51:42 +00:00
|
|
|
|
|
|
|
break;
|
2023-08-26 12:29:24 +00:00
|
|
|
|
2023-08-24 14:13:59 +00:00
|
|
|
default:
|
2023-07-23 17:51:42 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2023-08-30 17:33:04 +00:00
|
|
|
if( idx >= 0 && idx < (int) grid.grids.size() )
|
|
|
|
g = grid.grids[idx].ToDouble( schIUScale );
|
|
|
|
|
2023-07-23 17:51:42 +00:00
|
|
|
return g;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-09-09 02:54:17 +00:00
|
|
|
SCH_ITEM* EE_GRID_HELPER::GetSnapped() const
|
|
|
|
{
|
|
|
|
if( !m_snapItem )
|
|
|
|
return nullptr;
|
|
|
|
|
2021-01-16 23:17:32 +00:00
|
|
|
return static_cast<SCH_ITEM*>( m_snapItem->item );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::set<SCH_ITEM*> EE_GRID_HELPER::queryVisible( const BOX2I& aArea,
|
|
|
|
const EE_SELECTION& aSkipList ) const
|
|
|
|
{
|
|
|
|
std::set<SCH_ITEM*> items;
|
|
|
|
std::vector<KIGFX::VIEW::LAYER_ITEM_PAIR> selectedItems;
|
|
|
|
|
|
|
|
KIGFX::VIEW* view = m_toolMgr->GetView();
|
|
|
|
|
|
|
|
view->Query( aArea, selectedItems );
|
|
|
|
|
|
|
|
for( const KIGFX::VIEW::LAYER_ITEM_PAIR& it : selectedItems )
|
|
|
|
{
|
|
|
|
SCH_ITEM* item = static_cast<SCH_ITEM*>( it.first );
|
|
|
|
|
|
|
|
// The item must be visible and on an active layer
|
|
|
|
if( view->IsVisible( item ) && item->ViewGetLOD( it.second, view ) < view->GetScale() )
|
|
|
|
items.insert ( item );
|
|
|
|
}
|
|
|
|
|
|
|
|
for( EDA_ITEM* skipItem : aSkipList )
|
|
|
|
items.erase( static_cast<SCH_ITEM*>( skipItem ) );
|
|
|
|
|
|
|
|
return items;
|
2020-09-09 02:54:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-08-23 17:05:08 +00:00
|
|
|
GRID_HELPER_GRIDS EE_GRID_HELPER::GetSelectionGrid( const SELECTION& aSelection ) const
|
2023-07-23 17:51:42 +00:00
|
|
|
{
|
2023-08-22 14:09:04 +00:00
|
|
|
GRID_HELPER_GRIDS grid = GetItemGrid( aSelection.Front() );
|
2023-07-23 17:51:42 +00:00
|
|
|
|
|
|
|
// Find the largest grid of all the items and use that
|
|
|
|
for( EDA_ITEM* item : aSelection )
|
|
|
|
{
|
2023-08-22 14:09:04 +00:00
|
|
|
GRID_HELPER_GRIDS itemGrid = GetItemGrid( item );
|
2023-07-23 17:51:42 +00:00
|
|
|
|
|
|
|
if( GetGridSize( itemGrid ) > GetGridSize( grid ) )
|
|
|
|
grid = itemGrid;
|
|
|
|
}
|
|
|
|
|
|
|
|
return grid;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-08-22 14:09:04 +00:00
|
|
|
GRID_HELPER_GRIDS EE_GRID_HELPER::GetItemGrid( const EDA_ITEM* aItem ) const
|
2023-07-23 17:51:42 +00:00
|
|
|
{
|
|
|
|
if( !aItem )
|
|
|
|
return GRID_CURRENT;
|
|
|
|
|
|
|
|
switch( aItem->Type() )
|
|
|
|
{
|
2023-08-22 14:09:04 +00:00
|
|
|
case LIB_SYMBOL_T:
|
|
|
|
case LIB_PIN_T:
|
2023-07-23 17:51:42 +00:00
|
|
|
case SCH_SYMBOL_T:
|
|
|
|
case SCH_PIN_T:
|
|
|
|
case SCH_SHEET_PIN_T:
|
|
|
|
case SCH_SHEET_T:
|
|
|
|
case SCH_NO_CONNECT_T:
|
|
|
|
case SCH_GLOBAL_LABEL_T:
|
|
|
|
case SCH_HIER_LABEL_T:
|
|
|
|
case SCH_LABEL_T:
|
|
|
|
case SCH_DIRECTIVE_LABEL_T:
|
|
|
|
return GRID_CONNECTABLE;
|
|
|
|
|
2023-08-22 14:09:04 +00:00
|
|
|
case LIB_FIELD_T:
|
2023-07-23 17:51:42 +00:00
|
|
|
case SCH_FIELD_T:
|
2023-08-22 14:09:04 +00:00
|
|
|
case LIB_TEXT_T:
|
|
|
|
case SCH_TEXT_T:
|
2023-07-23 17:51:42 +00:00
|
|
|
return GRID_TEXT;
|
|
|
|
|
2023-08-22 14:09:04 +00:00
|
|
|
case LIB_SHAPE_T:
|
2023-07-23 17:51:42 +00:00
|
|
|
case SCH_SHAPE_T:
|
2023-07-27 14:42:38 +00:00
|
|
|
// The text box's border lines are what need to be on the graphic grid
|
2023-08-22 14:09:04 +00:00
|
|
|
case LIB_TEXTBOX_T:
|
2023-07-27 14:42:38 +00:00
|
|
|
case SCH_TEXTBOX_T:
|
2023-08-22 14:09:04 +00:00
|
|
|
case SCH_BITMAP_T:
|
2023-07-23 17:51:42 +00:00
|
|
|
return GRID_GRAPHICS;
|
|
|
|
|
|
|
|
case SCH_JUNCTION_T:
|
|
|
|
return GRID_WIRES;
|
|
|
|
|
|
|
|
case SCH_LINE_T:
|
2023-08-22 14:09:04 +00:00
|
|
|
if( static_cast<const SCH_LINE*>( aItem )->IsConnectable() )
|
2023-07-23 17:51:42 +00:00
|
|
|
return GRID_WIRES;
|
|
|
|
else
|
|
|
|
return GRID_GRAPHICS;
|
|
|
|
|
|
|
|
case SCH_BUS_BUS_ENTRY_T:
|
|
|
|
case SCH_BUS_WIRE_ENTRY_T:
|
|
|
|
return GRID_WIRES;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return GRID_CURRENT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-23 17:05:08 +00:00
|
|
|
|
2021-11-14 16:54:04 +00:00
|
|
|
void EE_GRID_HELPER::computeAnchors( SCH_ITEM *aItem, const VECTOR2I &aRefPos, bool aFrom,
|
|
|
|
bool aIncludeText )
|
2020-09-09 02:54:17 +00:00
|
|
|
{
|
2023-08-21 14:32:44 +00:00
|
|
|
bool isGraphicLine =
|
|
|
|
aItem->Type() == SCH_LINE_T && static_cast<SCH_LINE*>( aItem )->IsGraphicLine();
|
|
|
|
|
2021-11-06 15:18:40 +00:00
|
|
|
switch( aItem->Type() )
|
2020-09-09 02:54:17 +00:00
|
|
|
{
|
2021-11-06 15:18:40 +00:00
|
|
|
case SCH_TEXT_T:
|
|
|
|
case SCH_FIELD_T:
|
2021-11-14 16:54:04 +00:00
|
|
|
{
|
|
|
|
if( aIncludeText )
|
|
|
|
addAnchor( aItem->GetPosition(), ORIGIN, aItem );
|
|
|
|
|
2021-11-06 15:18:40 +00:00
|
|
|
break;
|
2021-11-14 16:54:04 +00:00
|
|
|
}
|
2021-11-06 15:18:40 +00:00
|
|
|
|
2023-11-25 12:38:24 +00:00
|
|
|
case SCH_TABLE_T:
|
|
|
|
{
|
|
|
|
if( aIncludeText )
|
|
|
|
{
|
|
|
|
addAnchor( aItem->GetPosition(), SNAPPABLE | CORNER, aItem );
|
|
|
|
addAnchor( static_cast<SCH_TABLE*>( aItem )->GetEnd(), SNAPPABLE | CORNER, aItem );
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case SCH_TEXTBOX_T:
|
|
|
|
case SCH_TABLECELL_T:
|
|
|
|
{
|
|
|
|
if( aIncludeText )
|
|
|
|
{
|
|
|
|
addAnchor( aItem->GetPosition(), SNAPPABLE | CORNER, aItem );
|
|
|
|
addAnchor( dynamic_cast<SCH_SHAPE*>( aItem )->GetEnd(), SNAPPABLE | CORNER, aItem );
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
case SCH_SYMBOL_T:
|
2021-11-06 15:18:40 +00:00
|
|
|
case SCH_SHEET_T:
|
2020-09-09 02:54:17 +00:00
|
|
|
addAnchor( aItem->GetPosition(), ORIGIN, aItem );
|
|
|
|
KI_FALLTHROUGH;
|
2021-11-06 15:18:40 +00:00
|
|
|
|
2020-09-09 02:54:17 +00:00
|
|
|
case SCH_JUNCTION_T:
|
2021-11-06 15:18:40 +00:00
|
|
|
case SCH_NO_CONNECT_T:
|
|
|
|
case SCH_LINE_T:
|
2023-08-21 14:32:44 +00:00
|
|
|
// Don't add anchors for graphic lines unless we're including text,
|
|
|
|
// they may be on a non-connectable grid
|
|
|
|
if( isGraphicLine && !aIncludeText )
|
|
|
|
break;
|
|
|
|
|
|
|
|
KI_FALLTHROUGH;
|
2021-11-06 15:18:40 +00:00
|
|
|
case SCH_GLOBAL_LABEL_T:
|
|
|
|
case SCH_HIER_LABEL_T:
|
|
|
|
case SCH_LABEL_T:
|
2022-01-24 13:40:39 +00:00
|
|
|
case SCH_DIRECTIVE_LABEL_T:
|
2021-11-06 15:18:40 +00:00
|
|
|
case SCH_BUS_WIRE_ENTRY_T:
|
2022-08-01 03:01:55 +00:00
|
|
|
case SCH_SHEET_PIN_T:
|
2021-11-06 15:18:40 +00:00
|
|
|
{
|
2022-01-01 06:04:08 +00:00
|
|
|
std::vector<VECTOR2I> pts = aItem->GetConnectionPoints();
|
2020-09-09 02:54:17 +00:00
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
for( const VECTOR2I& pt : pts )
|
2020-09-09 02:54:17 +00:00
|
|
|
addAnchor( VECTOR2I( pt ), SNAPPABLE | CORNER, aItem );
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2021-02-02 17:40:04 +00:00
|
|
|
}
|
|
|
|
|
2023-08-21 14:32:44 +00:00
|
|
|
// Don't add anchors for graphic lines unless we're including text,
|
|
|
|
// they may be on a non-connectable grid
|
|
|
|
if( aItem->Type() == SCH_LINE_T && ( aIncludeText || !isGraphicLine ) )
|
2021-02-02 17:40:04 +00:00
|
|
|
{
|
2023-06-24 18:54:50 +00:00
|
|
|
SCH_LINE* line = static_cast<SCH_LINE*>( aItem );
|
|
|
|
VECTOR2I pt = Align( aRefPos );
|
2021-02-02 17:40:04 +00:00
|
|
|
|
|
|
|
if( line->GetStartPoint().x == line->GetEndPoint().x )
|
|
|
|
{
|
|
|
|
VECTOR2I possible( line->GetStartPoint().x, pt.y );
|
|
|
|
|
2022-01-01 18:57:44 +00:00
|
|
|
if( TestSegmentHit( possible, line->GetStartPoint(), line->GetEndPoint(), 0 ) )
|
2021-02-02 17:40:04 +00:00
|
|
|
addAnchor( possible, SNAPPABLE | VERTICAL, aItem );
|
|
|
|
}
|
|
|
|
else if( line->GetStartPoint().y == line->GetEndPoint().y )
|
|
|
|
{
|
|
|
|
VECTOR2I possible( pt.x, line->GetStartPoint().y );
|
|
|
|
|
2022-01-01 18:57:44 +00:00
|
|
|
if( TestSegmentHit( possible, line->GetStartPoint(), line->GetEndPoint(), 0 ) )
|
2021-02-02 17:40:04 +00:00
|
|
|
addAnchor( possible, SNAPPABLE | HORIZONTAL, aItem );
|
|
|
|
}
|
|
|
|
}
|
2020-09-09 02:54:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
EE_GRID_HELPER::ANCHOR* EE_GRID_HELPER::nearestAnchor( const VECTOR2I& aPos, int aFlags,
|
2023-08-23 17:05:08 +00:00
|
|
|
GRID_HELPER_GRIDS aGrid )
|
2020-09-09 02:54:17 +00:00
|
|
|
{
|
|
|
|
double minDist = std::numeric_limits<double>::max();
|
2021-07-16 20:13:26 +00:00
|
|
|
ANCHOR* best = nullptr;
|
2020-09-09 02:54:17 +00:00
|
|
|
|
|
|
|
for( ANCHOR& a : m_anchors )
|
|
|
|
{
|
2021-01-16 23:17:32 +00:00
|
|
|
SCH_ITEM* item = static_cast<SCH_ITEM*>( a.item );
|
|
|
|
|
2020-09-09 02:54:17 +00:00
|
|
|
if( ( aFlags & a.flags ) != aFlags )
|
|
|
|
continue;
|
|
|
|
|
2023-08-23 17:05:08 +00:00
|
|
|
if( aGrid == GRID_CONNECTABLE && !item->IsConnectable() )
|
2020-12-03 15:10:23 +00:00
|
|
|
continue;
|
2023-08-23 17:05:08 +00:00
|
|
|
else if( aGrid == GRID_GRAPHICS && item->IsConnectable() )
|
2020-12-03 15:10:23 +00:00
|
|
|
continue;
|
|
|
|
|
2020-09-09 02:54:17 +00:00
|
|
|
double dist = a.Distance( aPos );
|
|
|
|
|
|
|
|
if( dist < minDist )
|
|
|
|
{
|
|
|
|
minDist = dist;
|
|
|
|
best = &a;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return best;
|
|
|
|
}
|