diff --git a/common/tool/common_tools.cpp b/common/tool/common_tools.cpp index 743c0afc52..e96593d298 100644 --- a/common/tool/common_tools.cpp +++ b/common/tool/common_tools.cpp @@ -153,7 +153,7 @@ int COMMON_TOOLS::CursorControl( const TOOL_EVENT& aEvent ) TOOL_EVENT evt( TC_MOUSE, action, button | modifiers ); evt.SetParameter( type ); - evt.SetMousePosition( getViewControls()->GetCursorPosition() ); + evt.SetMousePosition( getViewControls()->GetMousePosition() ); m_toolMgr->ProcessEvent( evt ); return 0; diff --git a/common/tool/grid_helper.cpp b/common/tool/grid_helper.cpp index 90677fabe8..d8f25cc279 100644 --- a/common/tool/grid_helper.cpp +++ b/common/tool/grid_helper.cpp @@ -30,6 +30,7 @@ using namespace std::placeholders; #include #include #include +#include GRID_HELPER::GRID_HELPER( TOOL_MANAGER* aToolMgr ) : @@ -70,6 +71,29 @@ VECTOR2I GRID_HELPER::GetOrigin() const } +GRID_HELPER_GRIDS GRID_HELPER::GetSelectionGrid( const SELECTION& aSelection ) const +{ + GRID_HELPER_GRIDS grid = GetItemGrid( aSelection.Front() ); + + // Find the largest grid of all the items and use that + for( EDA_ITEM* item : aSelection ) + { + GRID_HELPER_GRIDS itemGrid = GetItemGrid( item ); + + if( GetGridSize( itemGrid ) > GetGridSize( grid ) ) + grid = itemGrid; + } + + return grid; +} + + +VECTOR2D GRID_HELPER::GetGridSize( GRID_HELPER_GRIDS aGrid ) const +{ + return m_toolMgr->GetView()->GetGAL()->GetGridSize(); +} + + void GRID_HELPER::SetAuxAxes( bool aEnable, const VECTOR2I& aOrigin ) { if( aEnable ) diff --git a/eeschema/tools/ee_grid_helper.cpp b/eeschema/tools/ee_grid_helper.cpp index de4d5aa032..873f6928b2 100644 --- a/eeschema/tools/ee_grid_helper.cpp +++ b/eeschema/tools/ee_grid_helper.cpp @@ -61,18 +61,6 @@ EE_GRID_HELPER::EE_GRID_HELPER( TOOL_MANAGER* aToolMgr ) : } -VECTOR2I EE_GRID_HELPER::AlignGrid( const VECTOR2I& aPoint, GRID_HELPER_GRIDS aGrid ) const -{ - return AlignGrid( aPoint, GetGridSize( aGrid ), GetOrigin() ); -} - - -VECTOR2I EE_GRID_HELPER::Align( const VECTOR2I& aPoint, GRID_HELPER_GRIDS aGrid ) const -{ - return Align( aPoint, GetGridSize( aGrid ), GetOrigin() ); -} - - VECTOR2I EE_GRID_HELPER::BestDragOrigin( const VECTOR2I& aMousePos, GRID_HELPER_GRIDS aGrid, const EE_SELECTION& aItems ) { @@ -334,7 +322,7 @@ std::set EE_GRID_HELPER::queryVisible( const BOX2I& aArea, } -GRID_HELPER_GRIDS EE_GRID_HELPER::GetSelectionGrid( const EE_SELECTION& aSelection ) +GRID_HELPER_GRIDS EE_GRID_HELPER::GetSelectionGrid( const SELECTION& aSelection ) const { GRID_HELPER_GRIDS grid = GetItemGrid( aSelection.Front() ); @@ -403,6 +391,7 @@ GRID_HELPER_GRIDS EE_GRID_HELPER::GetItemGrid( const EDA_ITEM* aItem ) const } } + void EE_GRID_HELPER::computeAnchors( SCH_ITEM *aItem, const VECTOR2I &aRefPos, bool aFrom, bool aIncludeText ) { @@ -480,7 +469,7 @@ void EE_GRID_HELPER::computeAnchors( SCH_ITEM *aItem, const VECTOR2I &aRefPos, b EE_GRID_HELPER::ANCHOR* EE_GRID_HELPER::nearestAnchor( const VECTOR2I& aPos, int aFlags, - int aMatchLayer ) + GRID_HELPER_GRIDS aGrid ) { double minDist = std::numeric_limits::max(); ANCHOR* best = nullptr; @@ -492,9 +481,9 @@ EE_GRID_HELPER::ANCHOR* EE_GRID_HELPER::nearestAnchor( const VECTOR2I& aPos, int if( ( aFlags & a.flags ) != aFlags ) continue; - if( aMatchLayer == LAYER_NOCONNECT && !item->IsConnectable() ) + if( aGrid == GRID_CONNECTABLE && !item->IsConnectable() ) continue; - else if( aMatchLayer == GRID_GRAPHICS && item->IsConnectable() ) + else if( aGrid == GRID_GRAPHICS && item->IsConnectable() ) continue; double dist = a.Distance( aPos ); diff --git a/eeschema/tools/ee_grid_helper.h b/eeschema/tools/ee_grid_helper.h index 34a215aeea..3ce2b515cd 100644 --- a/eeschema/tools/ee_grid_helper.h +++ b/eeschema/tools/ee_grid_helper.h @@ -35,29 +35,12 @@ class SCH_ITEM; class LIB_ITEM; -enum GRID_HELPER_GRIDS : int -{ - // When the item doesn't match an override, use the current user grid - GRID_CURRENT, - - GRID_CONNECTABLE, - GRID_WIRES, - GRID_TEXT, - GRID_GRAPHICS -}; - - class EE_GRID_HELPER : public GRID_HELPER { public: EE_GRID_HELPER( TOOL_MANAGER* aToolMgr ); - using GRID_HELPER::Align; - using GRID_HELPER::AlignGrid; - VECTOR2I Align( const VECTOR2I& aPoint, GRID_HELPER_GRIDS aGrid ) const; - VECTOR2I AlignGrid( const VECTOR2I& aPoint, GRID_HELPER_GRIDS aGrid ) const; - /** * Function GetSnapped * If the EE_GRID_HELPER has highlighted a snap point (target shown), this function @@ -67,18 +50,11 @@ public: */ SCH_ITEM* GetSnapped() const; - VECTOR2D GetGridSize( GRID_HELPER_GRIDS aGrid ) const; + VECTOR2D GetGridSize( GRID_HELPER_GRIDS aGrid ) const override; using GRID_HELPER::GetGrid; - /** - * Gets the coarsest grid that applies to a selecion of items. - */ - GRID_HELPER_GRIDS GetSelectionGrid( const EE_SELECTION& aItem ); - - /** - * Gets the coarsest grid that applies to an item. - */ - GRID_HELPER_GRIDS GetItemGrid( const EDA_ITEM* aItem ) const; + GRID_HELPER_GRIDS GetSelectionGrid( const SELECTION& aItem ) const override; + GRID_HELPER_GRIDS GetItemGrid( const EDA_ITEM* aItem ) const override; VECTOR2I BestDragOrigin( const VECTOR2I& aMousePos, GRID_HELPER_GRIDS aGrid, const EE_SELECTION& aItems ); @@ -90,7 +66,7 @@ public: private: std::set queryVisible( const BOX2I& aArea, const EE_SELECTION& aSkipList ) const; - ANCHOR* nearestAnchor( const VECTOR2I& aPos, int aFlags, int aMatchLayer ); + ANCHOR* nearestAnchor( const VECTOR2I& aPos, int aFlags, GRID_HELPER_GRIDS aGrid ); /** * Insert the local anchor points in to the grid helper for the specified diff --git a/include/tool/grid_helper.h b/include/tool/grid_helper.h index 313c025f4c..25ff4e6f54 100644 --- a/include/tool/grid_helper.h +++ b/include/tool/grid_helper.h @@ -24,6 +24,7 @@ #ifndef GRID_HELPER_H #define GRID_HELPER_H +#include "tool/selection.h" #include #include #include @@ -32,6 +33,16 @@ class TOOL_MANAGER; class EDA_ITEM; +enum GRID_HELPER_GRIDS : int +{ + // When the item doesn't match an override, use the current user grid + GRID_CURRENT, + + GRID_CONNECTABLE, + GRID_WIRES, + GRID_TEXT, + GRID_GRAPHICS +}; class GRID_HELPER { @@ -45,6 +56,16 @@ public: void SetAuxAxes( bool aEnable, const VECTOR2I& aOrigin = VECTOR2I( 0, 0 ) ); + virtual VECTOR2I Align( const VECTOR2I& aPoint, GRID_HELPER_GRIDS aGrid ) const + { + return Align( aPoint, GetGridSize( aGrid ), GetOrigin() ); + } + + virtual VECTOR2I AlignGrid( const VECTOR2I& aPoint, GRID_HELPER_GRIDS aGrid ) const + { + return AlignGrid( aPoint, GetGridSize( aGrid ), GetOrigin() ); + } + virtual VECTOR2I Align( const VECTOR2I& aPoint ) const; virtual VECTOR2I Align( const VECTOR2I& aPoint, const VECTOR2D& aGrid, const VECTOR2D& aOffset ) const; @@ -53,6 +74,21 @@ public: VECTOR2I AlignGrid( const VECTOR2I& aPoint, const VECTOR2D& aGrid, const VECTOR2D& aOffset ) const; + /** + * Gets the coarsest grid that applies to a selecion of items. + */ + virtual GRID_HELPER_GRIDS GetSelectionGrid( const SELECTION& aSelection ) const; + + /** + * Gets the coarsest grid that applies to an item. + */ + virtual GRID_HELPER_GRIDS GetItemGrid( const EDA_ITEM* aItem ) const { return GRID_CURRENT; } + + /** + * Return the size of the specified grid + */ + virtual VECTOR2D GetGridSize( GRID_HELPER_GRIDS aGrid ) const; + void SetSkipPoint( const VECTOR2I& aPoint ) { m_skipPoint = aPoint; diff --git a/pcbnew/tools/pcb_grid_helper.h b/pcbnew/tools/pcb_grid_helper.h index 4180410347..5d71867060 100644 --- a/pcbnew/tools/pcb_grid_helper.h +++ b/pcbnew/tools/pcb_grid_helper.h @@ -31,6 +31,8 @@ #include class TOOL_MANAGER; +struct MAGNETIC_SETTINGS; +struct SELECTION_FILTER_OPTIONS; class PCB_GRID_HELPER : public GRID_HELPER { @@ -47,6 +49,9 @@ public: */ BOARD_ITEM* GetSnapped() const; + using GRID_HELPER::Align; + using GRID_HELPER::AlignGrid; + VECTOR2I AlignToSegment ( const VECTOR2I& aPoint, const SEG& aSeg ); VECTOR2I BestDragOrigin( const VECTOR2I& aMousePos, std::vector& aItem,