From 173b4ff588754877a5c9be8256bd02c25b1958f9 Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Tue, 8 Sep 2020 19:54:17 -0700 Subject: [PATCH] Add snapping to eeschema This generalizes both the SetPosition() function and ORIGIN_VIEWITEM class away from the pcbnew-centric. --- common/CMakeLists.txt | 3 +- common/origin_viewitem.cpp | 6 +- common/page_layout/ws_draw_item.cpp | 2 +- common/view/view_controls.cpp | 2 +- cvpcb/display_footprints_frame.h | 2 +- eeschema/CMakeLists.txt | 1 + eeschema/lib_item.h | 2 +- eeschema/lib_pin.h | 2 +- eeschema/lib_view_frame.cpp | 2 +- eeschema/libedit/lib_edit_frame.cpp | 2 +- eeschema/sch_draw_panel.cpp | 2 +- eeschema/sch_item.h | 7 - eeschema/sch_preview_panel.cpp | 2 +- eeschema/tools/ee_grid_helper.cpp | 385 +++++++++++++++++++++ eeschema/tools/ee_grid_helper.h | 160 +++++++++ eeschema/tools/lib_drawing_tools.cpp | 2 +- eeschema/tools/lib_move_tool.cpp | 6 +- eeschema/tools/sch_drawing_tools.cpp | 2 +- eeschema/tools/sch_line_wire_bus_tool.cpp | 19 +- eeschema/tools/sch_move_tool.cpp | 6 +- gerbview/gerber_draw_item.h | 4 +- gerbview/tools/gerbview_selection_tool.cpp | 2 +- include/base_struct.h | 1 + include/class_board_item.h | 2 - include/origin_viewitem.h | 14 +- include/pcb_base_frame.h | 2 +- include/view/view_controls.h | 6 +- include/ws_draw_item.h | 13 +- pagelayout_editor/tools/pl_edit_tool.cpp | 6 +- pcbnew/footprint_viewer_frame.h | 2 +- pcbnew/footprint_wizard_frame.h | 2 +- pcbnew/microwave/microwave_tool.cpp | 2 +- pcbnew/pcb_base_edit_frame.h | 2 +- pcbnew/router/length_tuner_tool.cpp | 2 +- pcbnew/tools/drawing_tool.cpp | 22 +- pcbnew/tools/edit_tool.cpp | 4 +- pcbnew/tools/grid_helper.cpp | 6 +- pcbnew/tools/pcb_editor_control.cpp | 8 +- pcbnew/tools/pcb_editor_control.h | 2 +- pcbnew/tools/pcb_tool_base.cpp | 2 +- pcbnew/tools/pcb_viewer_tools.cpp | 2 +- pcbnew/tools/pcbnew_control.cpp | 2 +- pcbnew/tools/pcbnew_control.h | 2 +- pcbnew/tools/pcbnew_picker_tool.cpp | 4 +- pcbnew/tools/point_editor.cpp | 2 +- pcbnew/undo_redo.cpp | 2 +- 46 files changed, 637 insertions(+), 96 deletions(-) create mode 100644 eeschema/tools/ee_grid_helper.cpp create mode 100644 eeschema/tools/ee_grid_helper.h diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index 95951e000e..6441939f78 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -398,6 +398,8 @@ list( APPEND COMMON_SRCS set( COMMON_SRCS ${COMMON_SRCS} + origin_viewitem.cpp + view/view.cpp view/view_item.cpp view/view_group.cpp @@ -477,7 +479,6 @@ set( PCB_COMMON_SRCS eda_text.cpp fp_lib_table.cpp hash_eda.cpp - origin_viewitem.cpp page_info.cpp ${CMAKE_SOURCE_DIR}/pcbnew/pcb_base_frame.cpp ${CMAKE_SOURCE_DIR}/pcbnew/pcb_expr_evaluator.cpp diff --git a/common/origin_viewitem.cpp b/common/origin_viewitem.cpp index f5be7af1ef..1f3aa63177 100644 --- a/common/origin_viewitem.cpp +++ b/common/origin_viewitem.cpp @@ -32,7 +32,7 @@ using namespace KIGFX; ORIGIN_VIEWITEM::ORIGIN_VIEWITEM( const COLOR4D& aColor, MARKER_STYLE aStyle, int aSize, const VECTOR2D& aPosition ) : - BOARD_ITEM( nullptr, NOT_USED ), // this item is never added to a BOARD so it needs no type + EDA_ITEM( nullptr, NOT_USED ), // this item is never added to a BOARD/SCHEMATIC so it needs no type m_position( aPosition ), m_size( aSize ), m_color( aColor ), @@ -43,7 +43,7 @@ ORIGIN_VIEWITEM::ORIGIN_VIEWITEM( const COLOR4D& aColor, MARKER_STYLE aStyle, in ORIGIN_VIEWITEM::ORIGIN_VIEWITEM( const VECTOR2D& aPosition, STATUS_FLAGS flags ) : - BOARD_ITEM( nullptr, NOT_USED ), // this item is never added to a BOARD so it needs no type + EDA_ITEM( nullptr, NOT_USED ), // this item is never added to a BOARD/SCHEMATIC so it needs no type m_position( aPosition ), m_size( NOT_USED ), m_color( UNSPECIFIED_COLOR ), @@ -108,7 +108,7 @@ void ORIGIN_VIEWITEM::ViewDraw( int, VIEW* aView ) const clip.Normalize(); double theta = atan2( end.y - start.y, end.x - start.x ); - std::array strokes = { DASH_MARK_LEN( 1 ), DASH_GAP_LEN( 1 ) }; + std::array strokes = { scaledSize.x, scaledSize.x / 2 }; for( size_t i = 0; i < 10000; ++i ) { diff --git a/common/page_layout/ws_draw_item.cpp b/common/page_layout/ws_draw_item.cpp index 5d7923f182..b444e84030 100644 --- a/common/page_layout/ws_draw_item.cpp +++ b/common/page_layout/ws_draw_item.cpp @@ -216,7 +216,7 @@ void WS_DRAW_ITEM_POLYPOLYGONS::PrintWsItem( RENDER_SETTINGS* aSettings, const w } -void WS_DRAW_ITEM_POLYPOLYGONS::SetPosition( wxPoint aPos ) +void WS_DRAW_ITEM_POLYPOLYGONS::SetPosition( const wxPoint& aPos ) { // Note: m_pos is the anchor point of the shape. wxPoint move_vect = aPos - m_pos; diff --git a/common/view/view_controls.cpp b/common/view/view_controls.cpp index 1df66fb316..9d366ab47c 100644 --- a/common/view/view_controls.cpp +++ b/common/view/view_controls.cpp @@ -87,7 +87,7 @@ void VIEW_CONTROLS::ApplySettings( const VC_SETTINGS& aSettings ) { ShowCursor( aSettings.m_showCursor ); CaptureCursor( aSettings.m_cursorCaptured ); - SetSnapping( aSettings.m_snappingEnabled ); + SetGridSnapping( aSettings.m_snappingEnabled ); SetGrabMouse( aSettings.m_grabMouse ); SetAutoPan( aSettings.m_autoPanEnabled ); SetAutoPanMargin( aSettings.m_autoPanMargin ); diff --git a/cvpcb/display_footprints_frame.h b/cvpcb/display_footprints_frame.h index 08e07ec942..ae6f711b35 100644 --- a/cvpcb/display_footprints_frame.h +++ b/cvpcb/display_footprints_frame.h @@ -93,7 +93,7 @@ public: * currently: do nothing in CvPcb. * but but be defined because it is a pure virtual in PCB_BASE_FRAME */ - void SaveCopyInUndoList( BOARD_ITEM* aItemToCopy, UNDO_REDO aTypeCommand = UNDO_REDO::UNSPECIFIED, + void SaveCopyInUndoList( EDA_ITEM* aItemToCopy, UNDO_REDO aTypeCommand = UNDO_REDO::UNSPECIFIED, const wxPoint& aTransformPoint = wxPoint( 0, 0 ) ) override { } diff --git a/eeschema/CMakeLists.txt b/eeschema/CMakeLists.txt index 1e617b2125..b06fc7f31b 100644 --- a/eeschema/CMakeLists.txt +++ b/eeschema/CMakeLists.txt @@ -243,6 +243,7 @@ set( EESCHEMA_SRCS tools/backannotate.cpp tools/backanno.cpp tools/ee_actions.cpp + tools/ee_grid_helper.cpp tools/ee_inspection_tool.cpp tools/ee_point_editor.cpp tools/ee_selection.cpp diff --git a/eeschema/lib_item.h b/eeschema/lib_item.h index 909271383d..32c6f561c1 100644 --- a/eeschema/lib_item.h +++ b/eeschema/lib_item.h @@ -245,7 +245,7 @@ public: */ virtual void MoveTo( const wxPoint& aPosition ) = 0; - void SetPosition( const wxPoint& aPosition ) { MoveTo( aPosition ); } + void SetPosition( const wxPoint& aPosition ) override { MoveTo( aPosition ); } /** * Mirror the draw object along the horizontal (X) axis about \a aCenter point. diff --git a/eeschema/lib_pin.h b/eeschema/lib_pin.h index a8f070b952..4113cd1542 100644 --- a/eeschema/lib_pin.h +++ b/eeschema/lib_pin.h @@ -252,7 +252,7 @@ public: void MoveTo( const wxPoint& aPosition ) override; wxPoint GetPosition() const override { return m_position; } - void SetPosition( const wxPoint& aPos ) { m_position = aPos; } + void SetPosition( const wxPoint& aPos ) override { m_position = aPos; } void MirrorHorizontal( const wxPoint& aCenter ) override; void MirrorVertical( const wxPoint& aCenter ) override; diff --git a/eeschema/lib_view_frame.cpp b/eeschema/lib_view_frame.cpp index af86d1cd56..7d907a494f 100644 --- a/eeschema/lib_view_frame.cpp +++ b/eeschema/lib_view_frame.cpp @@ -194,7 +194,7 @@ LIB_VIEW_FRAME::LIB_VIEW_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrame } SyncView(); - GetCanvas()->GetViewControls()->SetSnapping( true ); + GetCanvas()->GetViewControls()->SetGridSnapping( true ); GetCanvas()->SetCanFocus( false ); // Set the working/draw area size to display a symbol to a reasonable value: diff --git a/eeschema/libedit/lib_edit_frame.cpp b/eeschema/libedit/lib_edit_frame.cpp index a5a64e08bb..ed47fe347f 100644 --- a/eeschema/libedit/lib_edit_frame.cpp +++ b/eeschema/libedit/lib_edit_frame.cpp @@ -175,7 +175,7 @@ LIB_EDIT_FRAME::LIB_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) : Show( true ); SyncView(); - GetCanvas()->GetViewControls()->SetSnapping( true ); + GetCanvas()->GetViewControls()->SetGridSnapping( true ); GetCanvas()->GetView()->UseDrawPriority( true ); GetCanvas()->GetGAL()->SetAxesEnabled( true ); diff --git a/eeschema/sch_draw_panel.cpp b/eeschema/sch_draw_panel.cpp index 29a03b4821..9e762fa301 100644 --- a/eeschema/sch_draw_panel.cpp +++ b/eeschema/sch_draw_panel.cpp @@ -91,7 +91,7 @@ SCH_DRAW_PANEL::SCH_DRAW_PANEL( wxWindow* aParentWindow, wxWindowID aWindowId, // on updated viewport data. m_viewControls = new KIGFX::WX_VIEW_CONTROLS( m_view, this ); - m_viewControls->SetSnapping( true ); + m_viewControls->SetGridSnapping( true ); SetEvtHandlerEnabled( true ); SetFocus(); diff --git a/eeschema/sch_item.h b/eeschema/sch_item.h index f284b1f2ad..55c3e4c803 100644 --- a/eeschema/sch_item.h +++ b/eeschema/sch_item.h @@ -482,13 +482,6 @@ public: */ virtual void Plot( PLOTTER* aPlotter ); - /** - * Set the schematic item position to \a aPosition. - * - * @param aPosition A reference to a wxPoint object containing the new position. - */ - virtual void SetPosition( const wxPoint& aPosition ) = 0; - virtual bool operator <( const SCH_ITEM& aItem ) const; private: diff --git a/eeschema/sch_preview_panel.cpp b/eeschema/sch_preview_panel.cpp index 4a6c58212d..e9a91fd459 100644 --- a/eeschema/sch_preview_panel.cpp +++ b/eeschema/sch_preview_panel.cpp @@ -70,7 +70,7 @@ SCH_PREVIEW_PANEL::SCH_PREVIEW_PANEL( wxWindow* aParentWindow, wxWindowID aWindo m_gal->SetCursorEnabled( false ); m_gal->SetGridSize( VECTOR2D( Mils2iu( 100.0 ), Mils2iu( 100.0 ) ) ); - m_viewControls->SetSnapping( true ); + m_viewControls->SetGridSnapping( true ); SetEvtHandlerEnabled( true ); SetFocus(); diff --git a/eeschema/tools/ee_grid_helper.cpp b/eeschema/tools/ee_grid_helper.cpp new file mode 100644 index 0000000000..db382b0054 --- /dev/null +++ b/eeschema/tools/ee_grid_helper.cpp @@ -0,0 +1,385 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2014 CERN + * Copyright (C) 2018-2020 KiCad Developers, see AUTHORS.txt for contributors. + * @author Tomasz Wlostowski + * + * 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 +using namespace std::placeholders; + +#include +#include +#include // for KiROUND +#include +#include +#include +#include +#include +#include + +#include "ee_grid_helper.h" + + +EE_GRID_HELPER::EE_GRID_HELPER( TOOL_MANAGER* aToolMgr ) : + m_toolMgr( aToolMgr ) +{ + m_enableSnap = true; + m_enableSnapLine = true; + m_snapSize = 100; + m_snapItem = nullptr; + 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 ); +} + + +EE_GRID_HELPER::~EE_GRID_HELPER() +{ +} + + +VECTOR2I EE_GRID_HELPER::GetGrid() const +{ + VECTOR2D size = m_toolMgr->GetView()->GetGAL()->GetGridSize(); + + return VECTOR2I( KiROUND( size.x ), KiROUND( size.y ) ); +} + + +VECTOR2I EE_GRID_HELPER::GetOrigin() const +{ + VECTOR2D origin = m_toolMgr->GetView()->GetGAL()->GetGridOrigin(); + + return VECTOR2I( origin ); +} + + +void EE_GRID_HELPER::SetAuxAxes( bool aEnable, const VECTOR2I& aOrigin ) +{ + if( aEnable ) + { + m_auxAxis = aOrigin; + m_viewAxis.SetPosition( wxPoint( aOrigin ) ); + m_toolMgr->GetView()->SetVisible( &m_viewAxis, true ); + } + else + { + m_auxAxis = OPT(); + m_toolMgr->GetView()->SetVisible( &m_viewAxis, false ); + } +} + + +VECTOR2I EE_GRID_HELPER::Align( const VECTOR2I& aPoint ) const +{ + if( !m_toolMgr->GetView()->GetGAL()->GetGridVisibility() ) + return aPoint; + + const VECTOR2D gridOffset( GetOrigin() ); + const VECTOR2D grid( GetGrid() ); + + VECTOR2I nearest( KiROUND( ( aPoint.x - gridOffset.x ) / grid.x ) * grid.x + gridOffset.x, + KiROUND( ( aPoint.y - gridOffset.y ) / grid.y ) * grid.y + gridOffset.y ); + + if( !m_auxAxis ) + return nearest; + + if( std::abs( m_auxAxis->x - aPoint.x ) < std::abs( nearest.x - aPoint.x ) ) + nearest.x = m_auxAxis->x; + + if( std::abs( m_auxAxis->y - aPoint.y ) < std::abs( nearest.y - aPoint.y ) ) + nearest.y = m_auxAxis->y; + + return nearest; +} + + +VECTOR2I EE_GRID_HELPER::AlignToWire( const VECTOR2I& aPoint, const SEG& aSeg ) +{ + OPT_VECTOR2I pts[6]; + + 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 ); + + pts[0] = aSeg.A; + pts[1] = aSeg.B; + pts[2] = aSeg.IntersectLines( SEG( nearest + VECTOR2I( -1, 0 ), nearest + VECTOR2I( 1, 0 ) ) ); + pts[3] = aSeg.IntersectLines( SEG( nearest + VECTOR2I( 0, -1 ), nearest + VECTOR2I( 0, 1 ) ) ); + + int min_d = std::numeric_limits::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; +} + +VECTOR2I EE_GRID_HELPER::BestDragOrigin( const VECTOR2I &aMousePos, std::vector& aItems ) +{ + clearAnchors(); + + for( SCH_ITEM* item : aItems ) + computeAnchors( item, aMousePos, true ); + + double worldScale = m_toolMgr->GetView()->GetGAL()->GetWorldScale(); + double lineSnapMinCornerDistance = 50.0 / worldScale; + + 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::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; +} + + +std::set EE_GRID_HELPER::queryVisible( const BOX2I& aArea, + const std::vector& aSkip ) const +{ + std::set items; + std::vector 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( 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( SCH_ITEM* skipItem : aSkip ) + items.erase( skipItem ); + + return items; +} + + +VECTOR2I EE_GRID_HELPER::BestSnapAnchor( const VECTOR2I& aOrigin, SCH_ITEM* aDraggedItem ) +{ + return BestSnapAnchor( aOrigin, LSET::AllLayersMask(), { aDraggedItem } ); +} + + +VECTOR2I EE_GRID_HELPER::BestSnapAnchor( const VECTOR2I& aOrigin, const LSET& aLayers, + const std::vector& aSkip ) +{ + double worldScale = m_toolMgr->GetView()->GetGAL()->GetWorldScale(); + int snapRange = (int) ( m_snapSize / worldScale ); + + BOX2I bb( VECTOR2I( aOrigin.x - snapRange / 2, aOrigin.y - snapRange / 2 ), + VECTOR2I( snapRange, snapRange ) ); + + clearAnchors(); + + for( SCH_ITEM* item : queryVisible( bb, aSkip ) ) + computeAnchors( item, aOrigin ); + + ANCHOR* nearest = nearestAnchor( aOrigin, SNAPPABLE, aLayers ); + VECTOR2I nearestGrid = Align( aOrigin ); + + if( nearest && m_enableSnap ) + { + double snapDist = nearest->Distance( aOrigin ); + + if( snapDist <= 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; + } + } + + if( m_snapItem && m_enableSnapLine && m_enableSnap ) + { + bool snapLine = false; + + if( std::abs( m_viewSnapLine.GetPosition().x - aOrigin.x ) < snapRange ) + { + nearestGrid.x = m_viewSnapLine.GetPosition().x; + snapLine = true; + } + + if( std::abs( m_viewSnapLine.GetPosition().y - aOrigin.y ) < snapRange ) + { + nearestGrid.y = m_viewSnapLine.GetPosition().y; + snapLine = true; + } + + if( snapLine && m_skipPoint != VECTOR2I( m_viewSnapLine.GetPosition() ) ) + { + m_viewSnapLine.SetEndPosition( nearestGrid ); + m_toolMgr->GetView()->SetVisible( &m_viewSnapPoint, false ); + + if( m_toolMgr->GetView()->IsVisible( &m_viewSnapLine ) ) + m_toolMgr->GetView()->Update( &m_viewSnapLine, KIGFX::GEOMETRY ); + else + m_toolMgr->GetView()->SetVisible( &m_viewSnapLine, true ); + + return nearestGrid; + } + } + + m_snapItem = nullptr; + m_toolMgr->GetView()->SetVisible( &m_viewSnapPoint, false ); + m_toolMgr->GetView()->SetVisible( &m_viewSnapLine, false ); + return nearestGrid; +} + + +SCH_ITEM* EE_GRID_HELPER::GetSnapped() const +{ + if( !m_snapItem ) + return nullptr; + + return m_snapItem->item; +} + + +void EE_GRID_HELPER::computeAnchors( SCH_ITEM* aItem, const VECTOR2I& aRefPos, bool aFrom ) +{ + switch( aItem->Type() ) + { + case SCH_COMPONENT_T: + case SCH_SHEET_T: + addAnchor( aItem->GetPosition(), ORIGIN, aItem ); + KI_FALLTHROUGH; + case SCH_JUNCTION_T: + case SCH_NO_CONNECT_T: + case SCH_LINE_T: + case SCH_GLOBAL_LABEL_T: + case SCH_HIER_LABEL_T: + case SCH_LABEL_T: + case SCH_BUS_WIRE_ENTRY_T: + { + std::vector pts = aItem->GetConnectionPoints(); + + for( auto pt : pts ) + addAnchor( VECTOR2I( pt ), SNAPPABLE | CORNER, aItem ); + + break; + } + + default: + break; + } +} + + +EE_GRID_HELPER::ANCHOR* EE_GRID_HELPER::nearestAnchor( const VECTOR2I& aPos, int aFlags, + LSET aMatchLayers ) +{ + double minDist = std::numeric_limits::max(); + ANCHOR* best = NULL; + + for( ANCHOR& a : m_anchors ) + { + if( ( aFlags & a.flags ) != aFlags ) + continue; + + double dist = a.Distance( aPos ); + + if( dist < minDist ) + { + minDist = dist; + best = &a; + } + } + + return best; +} diff --git a/eeschema/tools/ee_grid_helper.h b/eeschema/tools/ee_grid_helper.h new file mode 100644 index 0000000000..3b9dd7322f --- /dev/null +++ b/eeschema/tools/ee_grid_helper.h @@ -0,0 +1,160 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2014 CERN + * Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors. + * @author Tomasz Wlostowski + * + * 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 +#include +#include + +class LSET; +class SCH_ITEM; +class SEG; + +class EE_GRID_HELPER { +public: + + EE_GRID_HELPER( TOOL_MANAGER* aToolMgr ); + ~EE_GRID_HELPER(); + + VECTOR2I GetGrid() const; + VECTOR2I GetOrigin() const; + + /** + * Function GetSnapped + * If the EE_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 + */ + SCH_ITEM* GetSnapped() const; + + void SetAuxAxes( bool aEnable, const VECTOR2I& aOrigin = VECTOR2I( 0, 0 ) ); + + VECTOR2I Align( const VECTOR2I& aPoint ) const; + + VECTOR2I AlignToWire( const VECTOR2I& aPoint, const SEG& aSeg ); + + VECTOR2I BestDragOrigin( const VECTOR2I& aMousePos, std::vector& aItem ); + + VECTOR2I BestSnapAnchor( const VECTOR2I& aOrigin, SCH_ITEM* aDraggedItem ); + VECTOR2I BestSnapAnchor( const VECTOR2I& aOrigin, const LSET& aLayers, + const std::vector& aSkip = {} ); + + void SetSkipPoint( const VECTOR2I& aPoint ) + { + m_skipPoint = aPoint; + } + + /** + * We clear the skip point by setting it to an unreachable position, thereby preventing matching + */ + void ClearSkipPoint() + { + m_skipPoint = VECTOR2I( std::numeric_limits::min(), std::numeric_limits::min() ); + } + + void SetSnap( bool aSnap ) + { + m_enableSnap = aSnap; + } + + void SetSnapLine( bool aSnap ) + { + m_enableSnapLine = aSnap; + } + +private: + enum ANCHOR_FLAGS { + CORNER = 1, + OUTLINE = 2, + SNAPPABLE = 4, + ORIGIN = 8, + VERTICAL = 16, + HORIZONTAL = 32 + }; + + struct ANCHOR + { + ANCHOR( VECTOR2I aPos, int aFlags = CORNER | SNAPPABLE, SCH_ITEM* aItem = NULL ) : + pos( aPos ), + flags( aFlags ), + item( aItem ) + { }; + + VECTOR2I pos; + int flags; + SCH_ITEM* item; + + double Distance( const VECTOR2I& aP ) const + { + return ( aP - pos ).EuclideanNorm(); + } + }; + + std::vector m_anchors; + + std::set queryVisible( const BOX2I& aArea, + const std::vector& aSkip ) const; + + void addAnchor( const VECTOR2I& aPos, int aFlags, SCH_ITEM* aItem ) + { + m_anchors.emplace_back( ANCHOR( aPos, aFlags, aItem ) ); + } + + ANCHOR* nearestAnchor( const VECTOR2I& aPos, int aFlags, LSET aMatchLayers ); + + /** + * computeAnchors inserts the local anchor points in to the grid helper for the specified + * schematic item, given the reference point and the direction of use for the point. + * + * @param aItem The schematic 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( SCH_ITEM* aItem, const VECTOR2I& aRefPos, bool aFrom = false ); + + void clearAnchors() + { + m_anchors.clear(); + } + + TOOL_MANAGER* m_toolMgr; + OPT m_auxAxis; + + bool m_enableSnap; // If true, allow snapping to other items on the layers + bool m_enableSnapLine; // If true, allow drawing lines from snap points + int m_snapSize; // Sets the radius in screen units for snapping to items + ANCHOR* m_snapItem; // Pointer to the currently snapped item in m_anchors + // (NULL if not snapped) + VECTOR2I m_skipPoint; // When drawing a line, we avoid snapping to the source point + + KIGFX::ORIGIN_VIEWITEM m_viewSnapPoint; + KIGFX::ORIGIN_VIEWITEM m_viewSnapLine; + KIGFX::ORIGIN_VIEWITEM m_viewAxis; +}; + +#endif diff --git a/eeschema/tools/lib_drawing_tools.cpp b/eeschema/tools/lib_drawing_tools.cpp index c55efc7f2a..553058d2d1 100644 --- a/eeschema/tools/lib_drawing_tools.cpp +++ b/eeschema/tools/lib_drawing_tools.cpp @@ -397,7 +397,7 @@ int LIB_DRAWING_TOOLS::DrawShape( const TOOL_EVENT& aEvent ) int LIB_DRAWING_TOOLS::PlaceAnchor( const TOOL_EVENT& aEvent ) { getViewControls()->ShowCursor( true ); - getViewControls()->SetSnapping( true ); + getViewControls()->SetGridSnapping( true ); std::string tool = aEvent.GetCommandStr().get(); m_frame->PushTool( tool ); diff --git a/eeschema/tools/lib_move_tool.cpp b/eeschema/tools/lib_move_tool.cpp index 5c58f49bf6..7bc856add1 100644 --- a/eeschema/tools/lib_move_tool.cpp +++ b/eeschema/tools/lib_move_tool.cpp @@ -70,7 +70,7 @@ void LIB_MOVE_TOOL::Reset( RESET_REASON aReason ) int LIB_MOVE_TOOL::Main( const TOOL_EVENT& aEvent ) { KIGFX::VIEW_CONTROLS* controls = getViewControls(); - controls->SetSnapping( true ); + controls->SetGridSnapping( true ); m_anchorPos = { 0, 0 }; @@ -103,7 +103,7 @@ int LIB_MOVE_TOOL::Main( const TOOL_EVENT& aEvent ) do { m_frame->GetCanvas()->SetCurrentCursor( wxCURSOR_ARROW ); - controls->SetSnapping( !evt->Modifier( MD_ALT ) ); + controls->SetGridSnapping( !evt->Modifier( MD_ALT ) ); if( evt->IsAction( &EE_ACTIONS::move ) || evt->IsMotion() || evt->IsDrag( BUT_LEFT ) || evt->IsAction( &ACTIONS::refreshPreview ) @@ -271,7 +271,7 @@ int LIB_MOVE_TOOL::Main( const TOOL_EVENT& aEvent ) controls->ForceCursorPosition( false ); controls->ShowCursor( false ); - controls->SetSnapping( false ); + controls->SetGridSnapping( false ); controls->SetAutoPan( false ); if( !chain_commands ) diff --git a/eeschema/tools/sch_drawing_tools.cpp b/eeschema/tools/sch_drawing_tools.cpp index ac067a62a4..58fa4c600c 100644 --- a/eeschema/tools/sch_drawing_tools.cpp +++ b/eeschema/tools/sch_drawing_tools.cpp @@ -449,7 +449,7 @@ int SCH_DRAWING_TOOLS::SingleClickPlace( const TOOL_EVENT& aEvent ) m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true ); getViewControls()->ShowCursor( true ); - getViewControls()->SetSnapping( true ); + getViewControls()->SetGridSnapping( true ); SCH_ITEM* previewItem; switch( type ) diff --git a/eeschema/tools/sch_line_wire_bus_tool.cpp b/eeschema/tools/sch_line_wire_bus_tool.cpp index 7d56a1c745..979cd7267b 100644 --- a/eeschema/tools/sch_line_wire_bus_tool.cpp +++ b/eeschema/tools/sch_line_wire_bus_tool.cpp @@ -63,6 +63,7 @@ #include #include +#include #include #include #include @@ -462,9 +463,14 @@ int SCH_LINE_WIRE_BUS_TOOL::doDrawSegments( const std::string& aTool, int aType SCH_SCREEN* screen = m_frame->GetScreen(); EE_POINT_EDITOR* pointEditor = m_toolMgr->GetTool(); SCH_LINE* segment = nullptr; + EE_GRID_HELPER grid( m_toolMgr ); + + KIGFX::VIEW_CONTROLS* controls = getViewControls(); m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true ); - getViewControls()->ShowCursor( true ); + controls->ShowCursor( true ); + controls->SetGridSnapping( m_frame->IsGridVisible() ); + Activate(); @@ -482,7 +488,12 @@ int SCH_LINE_WIRE_BUS_TOOL::doDrawSegments( const std::string& aTool, int aType if( !pointEditor->HasPoint() ) // Set wxCursor shape when starting the tool m_frame->GetCanvas()->SetCurrentCursor( wxCURSOR_PENCIL ); - wxPoint cursorPos = (wxPoint) getViewControls()->GetCursorPosition( !evt->Modifier( MD_ALT ) ); + grid.SetSnap( !evt->Modifier( MD_SHIFT ) ); + controls->SetGridSnapping( m_frame->IsGridVisible() ); + wxPoint cursorPos = wxPoint( grid.BestSnapAnchor( + evt->IsPrime() ? evt->Position() : controls->GetMousePosition(), nullptr ) ); + controls->ForceCursorPosition( true, cursorPos ); + bool forceHV = m_frame->eeconfig()->m_Drawing.hv_lines_only; //------------------------------------------------------------------------ @@ -692,8 +703,8 @@ int SCH_LINE_WIRE_BUS_TOOL::doDrawSegments( const std::string& aTool, int aType evt->SetPassEvent(); // Enable autopanning and cursor capture only when there is a segment to be placed - getViewControls()->SetAutoPan( segment != nullptr ); - getViewControls()->CaptureCursor( segment != nullptr ); + controls->SetAutoPan( segment != nullptr ); + controls->CaptureCursor( segment != nullptr ); } return 0; diff --git a/eeschema/tools/sch_move_tool.cpp b/eeschema/tools/sch_move_tool.cpp index abb967290d..9c14e11ac6 100644 --- a/eeschema/tools/sch_move_tool.cpp +++ b/eeschema/tools/sch_move_tool.cpp @@ -109,7 +109,7 @@ int SCH_MOVE_TOOL::Main( const TOOL_EVENT& aEvent ) EESCHEMA_SETTINGS* cfg = Pgm().GetSettingsManager().GetAppSettings(); KIGFX::VIEW_CONTROLS* controls = getViewControls(); - controls->SetSnapping( true ); + controls->SetGridSnapping( true ); m_anchorPos.reset(); @@ -171,7 +171,7 @@ int SCH_MOVE_TOOL::Main( const TOOL_EVENT& aEvent ) do { m_frame->GetCanvas()->SetCurrentCursor( wxCURSOR_ARROW ); - controls->SetSnapping( !evt->Modifier( MD_ALT ) ); + controls->SetGridSnapping( !evt->Modifier( MD_ALT ) ); if( evt->IsAction( &EE_ACTIONS::moveActivate ) || evt->IsAction( &EE_ACTIONS::restartMove ) || evt->IsAction( &EE_ACTIONS::move ) || evt->IsAction( &EE_ACTIONS::drag ) @@ -428,7 +428,7 @@ int SCH_MOVE_TOOL::Main( const TOOL_EVENT& aEvent ) controls->ForceCursorPosition( false ); controls->ShowCursor( false ); - controls->SetSnapping( false ); + controls->SetGridSnapping( false ); controls->SetAutoPan( false ); if( !chain_commands ) diff --git a/gerbview/gerber_draw_item.h b/gerbview/gerber_draw_item.h index 2446742880..4ab4ae9eee 100644 --- a/gerbview/gerber_draw_item.h +++ b/gerbview/gerber_draw_item.h @@ -194,8 +194,8 @@ public: * @return const wxPoint& - The position of this object. * This function exists mainly to satisfy the virtual GetPosition() in parent class */ - wxPoint GetPosition() const override { return m_Start; } - void SetPosition( const wxPoint& aPos ) { m_Start = aPos; } + wxPoint GetPosition() const override { return m_Start; } + void SetPosition( const wxPoint& aPos ) override { m_Start = aPos; } /** * Function GetABPosition diff --git a/gerbview/tools/gerbview_selection_tool.cpp b/gerbview/tools/gerbview_selection_tool.cpp index b61361ad86..f59e3a38e7 100644 --- a/gerbview/tools/gerbview_selection_tool.cpp +++ b/gerbview/tools/gerbview_selection_tool.cpp @@ -571,7 +571,7 @@ int GERBVIEW_SELECTION_TOOL::MeasureTool( const TOOL_EVENT& aEvent ) bool originSet = false; controls.ShowCursor( true ); - controls.SetSnapping( true ); + controls.SetGridSnapping( true ); while( TOOL_EVENT* evt = Wait() ) { diff --git a/include/base_struct.h b/include/base_struct.h index a10047d83b..e573c9964c 100644 --- a/include/base_struct.h +++ b/include/base_struct.h @@ -335,6 +335,7 @@ public: virtual const EDA_RECT GetBoundingBox() const; virtual wxPoint GetPosition() const { return wxPoint(); } + virtual void SetPosition( const wxPoint& aPos ) {}; /** * Function GetFocusPosition diff --git a/include/class_board_item.h b/include/class_board_item.h index 98dbcd047f..681a7c02b9 100644 --- a/include/class_board_item.h +++ b/include/class_board_item.h @@ -144,8 +144,6 @@ public: */ virtual wxPoint GetCenter() const { return GetPosition(); } - virtual void SetPosition( const wxPoint& aPos ) = 0; - void SetX( int aX ) { wxPoint p( aX, GetY() ); diff --git a/include/origin_viewitem.h b/include/origin_viewitem.h index cf96ab8f47..18583d4ec5 100644 --- a/include/origin_viewitem.h +++ b/include/origin_viewitem.h @@ -28,12 +28,9 @@ #include #include -#include #include #include -class PCB_BASE_FRAME; - /** * ORIGIN_VIEWITEM * @@ -41,7 +38,7 @@ class PCB_BASE_FRAME; */ namespace KIGFX { -class ORIGIN_VIEWITEM : public BOARD_ITEM +class ORIGIN_VIEWITEM : public EDA_ITEM { public: ///> Marker symbol styles @@ -93,17 +90,12 @@ public: m_drawAtZero = aDrawFlag; } - inline void SetPosition( const VECTOR2D& aPosition ) - { - m_position = aPosition; - } - - inline void SetPosition( const wxPoint& aPosition ) override + void SetPosition( const wxPoint& aPosition ) override { m_position = VECTOR2D( aPosition ); } - inline wxPoint GetPosition() const override + wxPoint GetPosition() const override { return wxPoint( m_position.x, m_position.y ); } diff --git a/include/pcb_base_frame.h b/include/pcb_base_frame.h index c2b0df0bfc..430ed7fad8 100644 --- a/include/pcb_base_frame.h +++ b/include/pcb_base_frame.h @@ -340,7 +340,7 @@ public: * @param aTransformPoint = the reference point of the transformation, for * commands like move */ - virtual void SaveCopyInUndoList( BOARD_ITEM* aItemToCopy, UNDO_REDO aTypeCommand, + virtual void SaveCopyInUndoList( EDA_ITEM* aItemToCopy, UNDO_REDO aTypeCommand, const wxPoint& aTransformPoint = wxPoint( 0, 0 ) ) = 0; /** diff --git a/include/view/view_controls.h b/include/view/view_controls.h index 2d485370b6..cd7b209ce8 100644 --- a/include/view/view_controls.h +++ b/include/view/view_controls.h @@ -154,12 +154,12 @@ public: } /** - * Function SetSnapping() + * Function SetGridSnapping() * Enables/disables snapping cursor to grid. * * @param aEnabled says whether the opion should be enabled or disabled. */ - virtual void SetSnapping( bool aEnabled ) + virtual void SetGridSnapping( bool aEnabled ) { m_settings.m_snappingEnabled = aEnabled; } @@ -167,7 +167,7 @@ public: /** * @return the current state of the snapping cursor to grid. */ - virtual bool GetSnappingState() + virtual bool GetGridSnapping() { return m_settings.m_snappingEnabled; } diff --git a/include/ws_draw_item.h b/include/ws_draw_item.h index f2038662b2..14018b4cfc 100644 --- a/include/ws_draw_item.h +++ b/include/ws_draw_item.h @@ -72,7 +72,6 @@ public: void ViewGetLayers( int aLayers[], int& aCount ) const override; - virtual void SetPosition( wxPoint aPos ) = 0; virtual void SetEnd( wxPoint aPos ) { /* not all types will need this */ } virtual int GetPenWidth() const @@ -134,7 +133,7 @@ public: void SetEnd( wxPoint aPos ) override { m_end = aPos; } wxPoint GetPosition() const override { return GetStart(); } - void SetPosition( wxPoint aPos ) override { SetStart( aPos ); } + void SetPosition( const wxPoint& aPos ) override { SetStart( aPos ); } const EDA_RECT GetBoundingBox() const override; bool HitTest( const wxPoint& aPosition, int aAccuracy = 0 ) const override; @@ -174,7 +173,7 @@ public: // Accessors: SHAPE_POLY_SET& GetPolygons() { return m_Polygons; } wxPoint GetPosition() const override { return m_pos; } - void SetPosition( wxPoint aPos ) override; + void SetPosition( const wxPoint& aPos ) override; const EDA_RECT GetBoundingBox() const override; bool HitTest( const wxPoint& aPosition, int aAccuracy = 0 ) const override; @@ -214,7 +213,7 @@ public: void SetEnd( wxPoint aPos ) override { m_end = aPos; } wxPoint GetPosition() const override { return GetStart(); } - void SetPosition( wxPoint aPos ) override { SetStart( aPos ); } + void SetPosition( const wxPoint& aPos ) override { SetStart( aPos ); } void PrintWsItem( RENDER_SETTINGS* aSettings, const wxPoint& aOffset ) override; @@ -256,7 +255,7 @@ public: double GetMarkerSize() const { return m_markerSize; } wxPoint GetPosition() const override { return wxPoint( 0, 0 ); } - void SetPosition( wxPoint aPos ) override { /* do nothing */ } + void SetPosition( const wxPoint& aPos ) override { /* do nothing */ } void PrintWsItem( RENDER_SETTINGS* , const wxPoint& ) override { /* do nothing */ } @@ -299,7 +298,7 @@ public: } wxPoint GetPosition() const override { return GetTextPos(); } - void SetPosition( wxPoint aPos ) override { SetTextPos( aPos ); } + void SetPosition( const wxPoint& aPos ) override { SetTextPos( aPos ); } const EDA_RECT GetBoundingBox() const override; bool HitTest( const wxPoint& aPosition, int aAccuracy = 0 ) const override; @@ -329,7 +328,7 @@ public: virtual wxString GetClass() const override { return wxT( "WS_DRAW_ITEM_BITMAP" ); } wxPoint GetPosition() const override { return m_pos; } - void SetPosition( wxPoint aPos ) override { m_pos = aPos; } + void SetPosition( const wxPoint& aPos ) override { m_pos = aPos; } void PrintWsItem( RENDER_SETTINGS* aSettings, const wxPoint& aOffset ) override; diff --git a/pagelayout_editor/tools/pl_edit_tool.cpp b/pagelayout_editor/tools/pl_edit_tool.cpp index 03b5f6d079..8a9ee0559b 100644 --- a/pagelayout_editor/tools/pl_edit_tool.cpp +++ b/pagelayout_editor/tools/pl_edit_tool.cpp @@ -93,7 +93,7 @@ int PL_EDIT_TOOL::Main( const TOOL_EVENT& aEvent ) { KIGFX::VIEW_CONTROLS* controls = getViewControls(); - controls->SetSnapping( true ); + controls->SetGridSnapping( true ); VECTOR2I originalCursorPos = controls->GetCursorPosition(); // Be sure that there is at least one item that we can move. If there's no selection try @@ -123,7 +123,7 @@ int PL_EDIT_TOOL::Main( const TOOL_EVENT& aEvent ) do { m_frame->GetCanvas()->SetCurrentCursor( wxCURSOR_ARROW ); - controls->SetSnapping( !evt->Modifier( MD_ALT ) ); + controls->SetGridSnapping( !evt->Modifier( MD_ALT ) ); if( evt->IsAction( &PL_ACTIONS::move ) || evt->IsMotion() || evt->IsDrag( BUT_LEFT ) || evt->IsAction( &ACTIONS::refreshPreview ) ) @@ -236,7 +236,7 @@ int PL_EDIT_TOOL::Main( const TOOL_EVENT& aEvent ) controls->ForceCursorPosition( false ); controls->ShowCursor( false ); - controls->SetSnapping( false ); + controls->SetGridSnapping( false ); controls->SetAutoPan( false ); if( !chain_commands ) diff --git a/pcbnew/footprint_viewer_frame.h b/pcbnew/footprint_viewer_frame.h index ec2ec206d9..bda14e697d 100644 --- a/pcbnew/footprint_viewer_frame.h +++ b/pcbnew/footprint_viewer_frame.h @@ -181,7 +181,7 @@ private: * Virtual functions, not used here, but needed by PCB_BASE_FRAME * (virtual pure functions ) */ - void SaveCopyInUndoList( BOARD_ITEM*, UNDO_REDO, const wxPoint& ) override {} + void SaveCopyInUndoList( EDA_ITEM*, UNDO_REDO, const wxPoint& ) override {} void SaveCopyInUndoList( const PICKED_ITEMS_LIST&, UNDO_REDO, const wxPoint &) override {} void updateView(); diff --git a/pcbnew/footprint_wizard_frame.h b/pcbnew/footprint_wizard_frame.h index 003b10e829..3506b7639a 100644 --- a/pcbnew/footprint_wizard_frame.h +++ b/pcbnew/footprint_wizard_frame.h @@ -220,7 +220,7 @@ private: * Virtual functions, not used here, but needed by PCB_BASE_FRAME * (virtual pure functions ) */ - void SaveCopyInUndoList( BOARD_ITEM*, UNDO_REDO, const wxPoint& ) override {} + void SaveCopyInUndoList( EDA_ITEM*, UNDO_REDO, const wxPoint& ) override {} void SaveCopyInUndoList( const PICKED_ITEMS_LIST&, UNDO_REDO, const wxPoint& ) override {} diff --git a/pcbnew/microwave/microwave_tool.cpp b/pcbnew/microwave/microwave_tool.cpp index b28d1d5024..c89b5a93fd 100644 --- a/pcbnew/microwave/microwave_tool.cpp +++ b/pcbnew/microwave/microwave_tool.cpp @@ -130,7 +130,7 @@ int MICROWAVE_TOOL::drawMicrowaveInductor( const TOOL_EVENT& aEvent ) bool originSet = false; controls.ShowCursor( true ); - controls.SetSnapping( true ); + controls.SetGridSnapping( true ); controls.CaptureCursor( false ); controls.SetAutoPan( false ); diff --git a/pcbnew/pcb_base_edit_frame.h b/pcbnew/pcb_base_edit_frame.h index 0d5cd009da..54ba2192da 100644 --- a/pcbnew/pcb_base_edit_frame.h +++ b/pcbnew/pcb_base_edit_frame.h @@ -90,7 +90,7 @@ public: * @param aTransformPoint = the reference point of the transformation, for * commands like move */ - void SaveCopyInUndoList( BOARD_ITEM* aItemToCopy, UNDO_REDO aTypeCommand, + void SaveCopyInUndoList( EDA_ITEM* aItemToCopy, UNDO_REDO aTypeCommand, const wxPoint& aTransformPoint = wxPoint( 0, 0 ) ) override; /** diff --git a/pcbnew/router/length_tuner_tool.cpp b/pcbnew/router/length_tuner_tool.cpp index 1ed0d60b91..d0a37d0f40 100644 --- a/pcbnew/router/length_tuner_tool.cpp +++ b/pcbnew/router/length_tuner_tool.cpp @@ -270,7 +270,7 @@ int LENGTH_TUNER_TOOL::MainLoop( const TOOL_EVENT& aEvent ) m_router->SetMode( aEvent.Parameter() ); - controls()->SetSnapping( true ); + controls()->SetGridSnapping( true ); controls()->ShowCursor( true ); frame()->UndoRedoBlock( true ); diff --git a/pcbnew/tools/drawing_tool.cpp b/pcbnew/tools/drawing_tool.cpp index 60f8f46b3d..fb48f55c0f 100644 --- a/pcbnew/tools/drawing_tool.cpp +++ b/pcbnew/tools/drawing_tool.cpp @@ -408,7 +408,7 @@ int DRAWING_TOOL::PlaceText( const TOOL_EVENT& aEvent ) m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true ); m_controls->ShowCursor( true ); - m_controls->SetSnapping( true ); + m_controls->SetGridSnapping( true ); // do not capture or auto-pan until we start placing some text SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::TEXT ); @@ -620,7 +620,7 @@ int DRAWING_TOOL::DrawDimension( const TOOL_EVENT& aEvent ) m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true ); m_controls->ShowCursor( true ); - m_controls->SetSnapping( true ); + m_controls->SetGridSnapping( true ); SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::DIMENSION ); @@ -651,7 +651,7 @@ int DRAWING_TOOL::DrawDimension( const TOOL_EVENT& aEvent ) grid.SetSnap( !evt->Modifier( MD_SHIFT ) ); grid.SetUseGrid( !evt->Modifier( MD_ALT ) ); - m_controls->SetSnapping( !evt->Modifier( MD_ALT ) ); + m_controls->SetGridSnapping( !evt->Modifier( MD_ALT ) ); VECTOR2I cursorPos = grid.BestSnapAnchor( evt->IsPrime() ? evt->Position() : m_controls->GetMousePosition(), nullptr ); m_controls->ForceCursorPosition( true, cursorPos ); @@ -916,7 +916,7 @@ int DRAWING_TOOL::PlaceImportedGraphics( const TOOL_EVENT& aEvent ) m_toolMgr->RunAction( PCB_ACTIONS::selectItems, true, &newItems ); m_controls->ShowCursor( true ); - m_controls->SetSnapping( true ); + m_controls->SetGridSnapping( true ); m_controls->ForceCursorPosition( false ); SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::DXF ); @@ -1011,7 +1011,7 @@ int DRAWING_TOOL::SetAnchor( const TOOL_EVENT& aEvent ) m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true ); m_controls->ShowCursor( true ); - m_controls->SetSnapping( true ); + m_controls->SetGridSnapping( true ); m_controls->SetAutoPan( true ); m_controls->CaptureCursor( false ); @@ -1021,7 +1021,7 @@ int DRAWING_TOOL::SetAnchor( const TOOL_EVENT& aEvent ) grid.SetSnap( !evt->Modifier( MD_SHIFT ) ); grid.SetUseGrid( !evt->Modifier( MD_ALT ) ); - m_controls->SetSnapping( !evt->Modifier( MD_ALT ) ); + m_controls->SetGridSnapping( !evt->Modifier( MD_ALT ) ); VECTOR2I cursorPos = grid.BestSnapAnchor( m_controls->GetMousePosition(), LSET::AllLayersMask() ); m_controls->ForceCursorPosition( true, cursorPos ); @@ -1125,7 +1125,7 @@ bool DRAWING_TOOL::drawSegment( const std::string& aTool, int aShape, DRAWSEGMEN grid.SetSnap( !evt->Modifier( MD_SHIFT ) ); grid.SetUseGrid( !evt->Modifier( MD_ALT ) ); - m_controls->SetSnapping( !evt->Modifier( MD_ALT ) ); + m_controls->SetGridSnapping( !evt->Modifier( MD_ALT ) ); cursorPos = grid.BestSnapAnchor( m_controls->GetMousePosition(), m_frame->GetActiveLayer() ); m_controls->ForceCursorPosition( true, cursorPos ); @@ -1383,7 +1383,7 @@ bool DRAWING_TOOL::drawArc( const std::string& aTool, DRAWSEGMENT** aGraphic, bo GRID_HELPER grid( m_toolMgr, m_frame->GetMagneticItemsSettings() ); m_controls->ShowCursor( true ); - m_controls->SetSnapping( true ); + m_controls->SetGridSnapping( true ); bool firstPoint = false; bool cancelled = false; @@ -1403,7 +1403,7 @@ bool DRAWING_TOOL::drawArc( const std::string& aTool, DRAWSEGMENT** aGraphic, bo m_frame->GetCanvas()->SetCurrentCursor( wxCURSOR_PENCIL ); grid.SetSnap( !evt->Modifier( MD_SHIFT ) ); grid.SetUseGrid( !evt->Modifier( MD_ALT ) ); - m_controls->SetSnapping( !evt->Modifier( MD_ALT ) ); + m_controls->SetGridSnapping( !evt->Modifier( MD_ALT ) ); VECTOR2I cursorPos = grid.BestSnapAnchor( m_controls->GetMousePosition(), graphic ); m_controls->ForceCursorPosition( true, cursorPos ); @@ -1623,7 +1623,7 @@ int DRAWING_TOOL::DrawZone( const TOOL_EVENT& aEvent ) Activate(); // register for events m_controls->ShowCursor( true ); - m_controls->SetSnapping( true ); + m_controls->SetGridSnapping( true ); bool started = false; GRID_HELPER grid( m_toolMgr, m_frame->GetMagneticItemsSettings() ); @@ -1642,7 +1642,7 @@ int DRAWING_TOOL::DrawZone( const TOOL_EVENT& aEvent ) LSET layers( m_frame->GetActiveLayer() ); grid.SetSnap( !evt->Modifier( MD_SHIFT ) ); grid.SetUseGrid( !evt->Modifier( MD_ALT ) ); - m_controls->SetSnapping( !evt->Modifier( MD_ALT ) ); + m_controls->SetGridSnapping( !evt->Modifier( MD_ALT ) ); VECTOR2I cursorPos = grid.BestSnapAnchor( evt->IsPrime() ? evt->Position() : m_controls->GetMousePosition(), layers ); diff --git a/pcbnew/tools/edit_tool.cpp b/pcbnew/tools/edit_tool.cpp index 5b462428fd..b107e44e36 100644 --- a/pcbnew/tools/edit_tool.cpp +++ b/pcbnew/tools/edit_tool.cpp @@ -409,7 +409,7 @@ int EDIT_TOOL::doMoveSelection( TOOL_EVENT aEvent, bool aPickReference ) editFrame->GetCanvas()->SetCurrentCursor( wxCURSOR_ARROW ); grid.SetSnap( !evt->Modifier( MD_SHIFT ) ); grid.SetUseGrid( !evt->Modifier( MD_ALT ) ); - controls->SetSnapping( !evt->Modifier( MD_ALT ) ); + controls->SetGridSnapping( !evt->Modifier( MD_ALT ) ); if( evt->IsAction( &PCB_ACTIONS::move ) || evt->IsMotion() || evt->IsDrag( BUT_LEFT ) || evt->IsAction( &ACTIONS::refreshPreview ) @@ -616,7 +616,7 @@ int EDIT_TOOL::doMoveSelection( TOOL_EVENT aEvent, bool aPickReference ) m_lockedSelected = false; controls->ForceCursorPosition( false ); controls->ShowCursor( false ); - controls->SetSnapping( false ); + controls->SetGridSnapping( false ); controls->SetAutoPan( false ); m_dragging = false; diff --git a/pcbnew/tools/grid_helper.cpp b/pcbnew/tools/grid_helper.cpp index d199668f25..b60aec376d 100644 --- a/pcbnew/tools/grid_helper.cpp +++ b/pcbnew/tools/grid_helper.cpp @@ -103,7 +103,7 @@ void GRID_HELPER::SetAuxAxes( bool aEnable, const VECTOR2I& aOrigin ) if( aEnable ) { m_auxAxis = aOrigin; - m_viewAxis.SetPosition( aOrigin ); + m_viewAxis.SetPosition( wxPoint( aOrigin ) ); m_toolMgr->GetView()->SetVisible( &m_viewAxis, true ); } else @@ -326,8 +326,8 @@ VECTOR2I GRID_HELPER::BestSnapAnchor( const VECTOR2I& aOrigin, const LSET& aLaye if( !m_enableGrid || snapDist <= gridDist ) { - m_viewSnapPoint.SetPosition( nearest->pos ); - m_viewSnapLine.SetPosition( nearest->pos ); + 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 ) ) diff --git a/pcbnew/tools/pcb_editor_control.cpp b/pcbnew/tools/pcb_editor_control.cpp index 9661487aad..d35c808e98 100644 --- a/pcbnew/tools/pcb_editor_control.cpp +++ b/pcbnew/tools/pcb_editor_control.cpp @@ -797,7 +797,7 @@ int PCB_EDITOR_CONTROL::PlaceModule( const TOOL_EVENT& aEvent ) m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true ); controls->ShowCursor( true ); - controls->SetSnapping( true ); + controls->SetGridSnapping( true ); std::string tool = aEvent.GetCommandStr().get(); m_frame->PushTool( tool ); @@ -1280,7 +1280,7 @@ int PCB_EDITOR_CONTROL::PlaceTarget( const TOOL_EVENT& aEvent ) view->Add( &preview ); m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true ); - controls->SetSnapping( true ); + controls->SetGridSnapping( true ); std::string tool = aEvent.GetCommandStr().get(); m_frame->PushTool( tool ); @@ -1363,7 +1363,7 @@ int PCB_EDITOR_CONTROL::PlaceTarget( const TOOL_EVENT& aEvent ) preview.Clear(); delete target; view->Remove( &preview ); - controls->SetSnapping( false ); + controls->SetGridSnapping( false ); return 0; } @@ -1544,7 +1544,7 @@ int PCB_EDITOR_CONTROL::EditFpInFpEditor( const TOOL_EVENT& aEvent ) void PCB_EDITOR_CONTROL::DoSetDrillOrigin( KIGFX::VIEW* aView, PCB_BASE_FRAME* aFrame, - BOARD_ITEM* originViewItem, const VECTOR2D& aPosition ) + EDA_ITEM* originViewItem, const VECTOR2D& aPosition ) { aFrame->GetDesignSettings().m_AuxOrigin = (wxPoint) aPosition; originViewItem->SetPosition( (wxPoint) aPosition ); diff --git a/pcbnew/tools/pcb_editor_control.h b/pcbnew/tools/pcb_editor_control.h index e69a9b7268..89014c7197 100644 --- a/pcbnew/tools/pcb_editor_control.h +++ b/pcbnew/tools/pcb_editor_control.h @@ -136,7 +136,7 @@ public: ///> Low-level access (below undo) to setting the drill origin static void DoSetDrillOrigin( KIGFX::VIEW* aView, PCB_BASE_FRAME* aFrame, - BOARD_ITEM* aItem, const VECTOR2D& aPoint ); + EDA_ITEM* aItem, const VECTOR2D& aPoint ); int FlipPcbView( const TOOL_EVENT& aEvent ); diff --git a/pcbnew/tools/pcb_tool_base.cpp b/pcbnew/tools/pcb_tool_base.cpp index 9eea0537c7..d594de16cf 100644 --- a/pcbnew/tools/pcb_tool_base.cpp +++ b/pcbnew/tools/pcb_tool_base.cpp @@ -50,7 +50,7 @@ void PCB_TOOL_BASE::doInteractiveItemPlacement( const std::string& aTool, // do not capture or auto-pan until we start placing an item controls()->ShowCursor( true ); - controls()->SetSnapping( true ); + controls()->SetGridSnapping( true ); // Add a VIEW_GROUP that serves as a preview for the new item PCBNEW_SELECTION preview; diff --git a/pcbnew/tools/pcb_viewer_tools.cpp b/pcbnew/tools/pcb_viewer_tools.cpp index 8c71a9bf36..ee22700cfc 100644 --- a/pcbnew/tools/pcb_viewer_tools.cpp +++ b/pcbnew/tools/pcb_viewer_tools.cpp @@ -225,7 +225,7 @@ int PCB_VIEWER_TOOLS::MeasureTool( const TOOL_EVENT& aEvent ) frame()->GetCanvas()->SetCurrentCursor( wxCURSOR_ARROW ); grid.SetSnap( !evt->Modifier( MD_SHIFT ) ); grid.SetUseGrid( !evt->Modifier( MD_ALT ) ); - controls.SetSnapping( !evt->Modifier( MD_ALT ) ); + controls.SetGridSnapping( !evt->Modifier( MD_ALT ) ); const VECTOR2I cursorPos = grid.BestSnapAnchor( controls.GetMousePosition(), nullptr ); controls.ForceCursorPosition(true, cursorPos ); diff --git a/pcbnew/tools/pcbnew_control.cpp b/pcbnew/tools/pcbnew_control.cpp index 12d6ef6f04..43742b4bae 100644 --- a/pcbnew/tools/pcbnew_control.cpp +++ b/pcbnew/tools/pcbnew_control.cpp @@ -385,7 +385,7 @@ int PCBNEW_CONTROL::LayerAlphaDec( const TOOL_EVENT& aEvent ) // Grid control void PCBNEW_CONTROL::DoSetGridOrigin( KIGFX::VIEW* aView, PCB_BASE_FRAME* aFrame, - BOARD_ITEM* originViewItem, const VECTOR2D& aPoint ) + EDA_ITEM* originViewItem, const VECTOR2D& aPoint ) { aFrame->GetDesignSettings().m_GridOrigin = (wxPoint) aPoint; aView->GetGAL()->SetGridOrigin( aPoint ); diff --git a/pcbnew/tools/pcbnew_control.h b/pcbnew/tools/pcbnew_control.h index d9029d4d1f..1f75bb7163 100644 --- a/pcbnew/tools/pcbnew_control.h +++ b/pcbnew/tools/pcbnew_control.h @@ -80,7 +80,7 @@ public: // Low-level access (below undo) to setting the grid origin static void DoSetGridOrigin( KIGFX::VIEW* aView, PCB_BASE_FRAME* aFrame, - BOARD_ITEM* originViewItem, const VECTOR2D& aPoint ); + EDA_ITEM* originViewItem, const VECTOR2D& aPoint ); int Undo( const TOOL_EVENT& aEvent ); int Redo( const TOOL_EVENT& aEvent ); diff --git a/pcbnew/tools/pcbnew_picker_tool.cpp b/pcbnew/tools/pcbnew_picker_tool.cpp index 166c412f00..0c2e0ac6d6 100644 --- a/pcbnew/tools/pcbnew_picker_tool.cpp +++ b/pcbnew/tools/pcbnew_picker_tool.cpp @@ -59,7 +59,7 @@ int PCBNEW_PICKER_TOOL::Main( const TOOL_EVENT& aEvent ) grid.SetSnap( !evt->Modifier( MD_SHIFT ) ); grid.SetUseGrid( !evt->Modifier( MD_ALT ) ); - controls->SetSnapping( !evt->Modifier( MD_ALT ) ); + controls->SetGridSnapping( !evt->Modifier( MD_ALT ) ); VECTOR2I cursorPos = grid.BestSnapAnchor( controls->GetMousePosition(), nullptr ); controls->ForceCursorPosition(true, cursorPos ); @@ -187,7 +187,7 @@ void PCBNEW_PICKER_TOOL::setControls() KIGFX::VIEW_CONTROLS* controls = getViewControls(); // Ensure that the view controls do not handle our snapping as we use the GRID_HELPER - controls->SetSnapping( false ); + controls->SetGridSnapping( false ); controls->CaptureCursor( false ); controls->SetAutoPan( false ); diff --git a/pcbnew/tools/point_editor.cpp b/pcbnew/tools/point_editor.cpp index 2f3e0c48ee..10aa674d8a 100644 --- a/pcbnew/tools/point_editor.cpp +++ b/pcbnew/tools/point_editor.cpp @@ -383,7 +383,7 @@ int POINT_EDITOR::OnSelectionChange( const TOOL_EVENT& aEvent ) { grid.SetSnap( !evt->Modifier( MD_SHIFT ) ); grid.SetUseGrid( !evt->Modifier( MD_ALT ) ); - controls->SetSnapping( !evt->Modifier( MD_ALT ) ); + controls->SetGridSnapping( !evt->Modifier( MD_ALT ) ); if( !m_editPoints || evt->IsSelectionEvent() ) break; diff --git a/pcbnew/undo_redo.cpp b/pcbnew/undo_redo.cpp index fb63e6dfae..10d6f6e50e 100644 --- a/pcbnew/undo_redo.cpp +++ b/pcbnew/undo_redo.cpp @@ -181,7 +181,7 @@ static void SwapItemData( BOARD_ITEM* aItem, BOARD_ITEM* aImage ) aItem->SetParent( parent ); } -void PCB_BASE_EDIT_FRAME::SaveCopyInUndoList( BOARD_ITEM* aItem, UNDO_REDO aCommandType, +void PCB_BASE_EDIT_FRAME::SaveCopyInUndoList( EDA_ITEM* aItem, UNDO_REDO aCommandType, const wxPoint& aTransformPoint ) { PICKED_ITEMS_LIST commandToUndo;