GRID_HELPER: push code to parent class
Prep'ing for PCB grid overrides
This commit is contained in:
parent
0f621f9af9
commit
0f781f328e
|
@ -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;
|
||||
|
|
|
@ -30,6 +30,7 @@ using namespace std::placeholders;
|
|||
#include <tool/tool_manager.h>
|
||||
#include <view/view.h>
|
||||
#include <tool/grid_helper.h>
|
||||
#include <settings/app_settings.h>
|
||||
|
||||
|
||||
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 )
|
||||
|
|
|
@ -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<SCH_ITEM*> 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<double>::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 );
|
||||
|
|
|
@ -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<SCH_ITEM*> 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
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#ifndef GRID_HELPER_H
|
||||
#define GRID_HELPER_H
|
||||
|
||||
#include "tool/selection.h"
|
||||
#include <tool/tool_manager.h>
|
||||
#include <vector>
|
||||
#include <math/vector2d.h>
|
||||
|
@ -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;
|
||||
|
|
|
@ -31,6 +31,8 @@
|
|||
#include <tool/grid_helper.h>
|
||||
|
||||
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<BOARD_ITEM*>& aItem,
|
||||
|
|
Loading…
Reference in New Issue