Divorce GRID_HELPER from the parent frame.

This moves GRID_HELPER fully into the tool framework.
This commit is contained in:
Jeff Young 2020-06-13 13:33:29 +01:00
parent a02d8a5993
commit 47ab7c78a6
8 changed files with 53 additions and 53 deletions

View File

@ -115,7 +115,7 @@ void TOOL_BASE::Reset( RESET_REASON aReason )
m_router->LoadSettings( settings->m_PnsSettings.get() ); m_router->LoadSettings( settings->m_PnsSettings.get() );
m_gridHelper = new GRID_HELPER( frame() ); m_gridHelper = new GRID_HELPER( m_toolMgr, frame()->GetMagneticItemsSettings() );
} }

View File

@ -477,7 +477,7 @@ int DRAWING_TOOL::DrawDimension( const TOOL_EVENT& aEvent )
POINT_EDITOR* pointEditor = m_toolMgr->GetTool<POINT_EDITOR>(); POINT_EDITOR* pointEditor = m_toolMgr->GetTool<POINT_EDITOR>();
DIMENSION* dimension = NULL; DIMENSION* dimension = NULL;
BOARD_COMMIT commit( m_frame ); BOARD_COMMIT commit( m_frame );
GRID_HELPER grid( m_frame ); GRID_HELPER grid( m_toolMgr, m_frame->GetMagneticItemsSettings() );
const BOARD_DESIGN_SETTINGS& boardSettings = m_board->GetDesignSettings(); const BOARD_DESIGN_SETTINGS& boardSettings = m_board->GetDesignSettings();
@ -859,7 +859,7 @@ int DRAWING_TOOL::SetAnchor( const TOOL_EVENT& aEvent )
return 0; return 0;
SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::ANCHOR ); SCOPED_DRAW_MODE scopedDrawMode( m_mode, MODE::ANCHOR );
GRID_HELPER grid( m_frame ); GRID_HELPER grid( m_toolMgr, m_frame->GetMagneticItemsSettings() );
std::string tool = aEvent.GetCommandStr().get(); std::string tool = aEvent.GetCommandStr().get();
m_frame->PushTool( tool ); m_frame->PushTool( tool );
@ -920,7 +920,7 @@ bool DRAWING_TOOL::drawSegment( const std::string& aTool, int aShape, DRAWSEGMEN
{ {
// Only two shapes are currently supported // Only two shapes are currently supported
assert( aShape == S_SEGMENT || aShape == S_CIRCLE ); assert( aShape == S_SEGMENT || aShape == S_CIRCLE );
GRID_HELPER grid( m_frame ); GRID_HELPER grid( m_toolMgr, m_frame->GetMagneticItemsSettings() );
POINT_EDITOR* pointEditor = m_toolMgr->GetTool<POINT_EDITOR>(); POINT_EDITOR* pointEditor = m_toolMgr->GetTool<POINT_EDITOR>();
m_lineWidth = getSegmentWidth( getDrawingLayer() ); m_lineWidth = getSegmentWidth( getDrawingLayer() );
@ -1192,7 +1192,7 @@ bool DRAWING_TOOL::drawArc( const std::string& aTool, DRAWSEGMENT*& aGraphic, bo
PCBNEW_SELECTION preview; PCBNEW_SELECTION preview;
m_view->Add( &preview ); m_view->Add( &preview );
m_view->Add( &arcAsst ); m_view->Add( &arcAsst );
GRID_HELPER grid( m_frame ); GRID_HELPER grid( m_toolMgr, m_frame->GetMagneticItemsSettings() );
m_controls->ShowCursor( true ); m_controls->ShowCursor( true );
m_controls->SetSnapping( true ); m_controls->SetSnapping( true );
@ -1440,7 +1440,7 @@ int DRAWING_TOOL::DrawZone( const TOOL_EVENT& aEvent )
m_controls->SetSnapping( true ); m_controls->SetSnapping( true );
bool started = false; bool started = false;
GRID_HELPER grid( m_frame ); GRID_HELPER grid( m_toolMgr, m_frame->GetMagneticItemsSettings() );
STATUS_TEXT_POPUP status( m_frame ); STATUS_TEXT_POPUP status( m_frame );
status.SetTextColor( wxColour( 255, 0, 0 ) ); status.SetTextColor( wxColour( 255, 0, 0 ) );
status.SetText( _( "Self-intersecting polygons are not allowed" ) ); status.SetText( _( "Self-intersecting polygons are not allowed" ) );
@ -1595,7 +1595,8 @@ int DRAWING_TOOL::DrawVia( const TOOL_EVENT& aEvent )
{ {
GRID_HELPER m_gridHelper; GRID_HELPER m_gridHelper;
VIA_PLACER( PCB_BASE_EDIT_FRAME* aFrame ) : m_gridHelper( aFrame ) VIA_PLACER( PCB_BASE_EDIT_FRAME* aFrame ) :
m_gridHelper( aFrame->GetToolManager(), aFrame->GetMagneticItemsSettings() )
{} {}
virtual ~VIA_PLACER() virtual ~VIA_PLACER()

View File

@ -334,7 +334,7 @@ int EDIT_TOOL::Move( const TOOL_EVENT& aEvent )
bool restore_state = false; bool restore_state = false;
VECTOR2I totalMovement; VECTOR2I totalMovement;
GRID_HELPER grid( editFrame ); GRID_HELPER grid( m_toolMgr, editFrame->GetMagneticItemsSettings() );
TOOL_EVENT* evt = const_cast<TOOL_EVENT*>( &aEvent ); TOOL_EVENT* evt = const_cast<TOOL_EVENT*>( &aEvent );
VECTOR2I prevPos; VECTOR2I prevPos;

View File

@ -26,7 +26,6 @@
#include <functional> #include <functional>
using namespace std::placeholders; using namespace std::placeholders;
#include <pcb_edit_frame.h>
#include <class_board.h> #include <class_board.h>
#include <class_dimension.h> #include <class_dimension.h>
#include <class_edge_mod.h> #include <class_edge_mod.h>
@ -46,9 +45,9 @@ using namespace std::placeholders;
#include "grid_helper.h" #include "grid_helper.h"
GRID_HELPER::GRID_HELPER( PCB_BASE_FRAME* aFrame ) : GRID_HELPER::GRID_HELPER( TOOL_MANAGER* aToolMgr, MAGNETIC_SETTINGS* aMagneticSettings ) :
m_frame( aFrame ), m_toolMgr( aToolMgr ),
m_toolMgr( aFrame->GetToolManager() ) m_magneticSettings( aMagneticSettings )
{ {
m_enableSnap = true; m_enableSnap = true;
m_enableGrid = true; m_enableGrid = true;
@ -179,8 +178,6 @@ VECTOR2I GRID_HELPER::AlignToSegment( const VECTOR2I& aPoint, const SEG& aSeg )
VECTOR2I GRID_HELPER::AlignToArc( const VECTOR2I& aPoint, const SHAPE_ARC& aArc ) VECTOR2I GRID_HELPER::AlignToArc( const VECTOR2I& aPoint, const SHAPE_ARC& aArc )
{ {
OPT_VECTOR2I pts[6];
if( !m_enableSnap ) if( !m_enableSnap )
return aPoint; return aPoint;
@ -213,7 +210,7 @@ VECTOR2I GRID_HELPER::BestDragOrigin( const VECTOR2I &aMousePos, std::vector<BOA
{ {
clearAnchors(); clearAnchors();
for( auto item : aItems ) for( BOARD_ITEM* item : aItems )
computeAnchors( item, aMousePos, true ); computeAnchors( item, aMousePos, true );
double worldScale = m_toolMgr->GetView()->GetGAL()->GetWorldScale(); double worldScale = m_toolMgr->GetView()->GetGAL()->GetWorldScale();
@ -267,7 +264,7 @@ std::set<BOARD_ITEM*> GRID_HELPER::queryVisible( const BOX2I& aArea,
view->Query( aArea, selectedItems ); view->Query( aArea, selectedItems );
for( auto it : selectedItems ) for( const KIGFX::VIEW::LAYER_ITEM_PAIR& it : selectedItems )
{ {
BOARD_ITEM* item = static_cast<BOARD_ITEM*>( it.first ); BOARD_ITEM* item = static_cast<BOARD_ITEM*>( it.first );
@ -281,8 +278,8 @@ std::set<BOARD_ITEM*> GRID_HELPER::queryVisible( const BOX2I& aArea,
} }
for( auto ii : aSkip ) for( BOARD_ITEM* skipItem : aSkip )
items.erase( ii ); items.erase( skipItem );
return items; return items;
} }
@ -311,7 +308,8 @@ VECTOR2I GRID_HELPER::BestSnapAnchor( const VECTOR2I& aOrigin, const LSET& aLaye
double worldScale = m_toolMgr->GetView()->GetGAL()->GetWorldScale(); double worldScale = m_toolMgr->GetView()->GetGAL()->GetWorldScale();
int snapRange = (int) ( m_snapSize / worldScale ); int snapRange = (int) ( m_snapSize / worldScale );
BOX2I bb( VECTOR2I( aOrigin.x - snapRange / 2, aOrigin.y - snapRange / 2 ), VECTOR2I( snapRange, snapRange ) ); BOX2I bb( VECTOR2I( aOrigin.x - snapRange / 2, aOrigin.y - snapRange / 2 ),
VECTOR2I( snapRange, snapRange ) );
clearAnchors(); clearAnchors();
@ -379,7 +377,7 @@ VECTOR2I GRID_HELPER::BestSnapAnchor( const VECTOR2I& aOrigin, const LSET& aLaye
} }
BOARD_ITEM* GRID_HELPER::GetSnapped( void ) const BOARD_ITEM* GRID_HELPER::GetSnapped() const
{ {
if( !m_snapItem ) if( !m_snapItem )
return nullptr; return nullptr;
@ -405,8 +403,7 @@ void GRID_HELPER::computeAnchors( BOARD_ITEM* aItem, const VECTOR2I& aRefPos, bo
for( D_PAD* pad : mod->Pads() ) for( D_PAD* pad : mod->Pads() )
{ {
// Getting pads from the module requires re-checking that the pad is shown // Getting pads from the module requires re-checking that the pad is shown
if( ( aFrom || if( ( aFrom || m_magneticSettings->pads == MAGNETIC_OPTIONS::CAPTURE_ALWAYS )
m_frame->GetMagneticItemsSettings()->pads == MAGNETIC_OPTIONS::CAPTURE_ALWAYS )
&& pad->GetBoundingBox().Contains( wxPoint( aRefPos.x, aRefPos.y ) ) && pad->GetBoundingBox().Contains( wxPoint( aRefPos.x, aRefPos.y ) )
&& view->IsVisible( pad ) && view->IsVisible( pad )
&& ( !isHighContrast || activeLayers.count( pad->GetLayer() ) ) && ( !isHighContrast || activeLayers.count( pad->GetLayer() ) )
@ -424,7 +421,7 @@ void GRID_HELPER::computeAnchors( BOARD_ITEM* aItem, const VECTOR2I& aRefPos, bo
case PCB_PAD_T: case PCB_PAD_T:
{ {
if( aFrom || m_frame->GetMagneticItemsSettings()->pads == MAGNETIC_OPTIONS::CAPTURE_ALWAYS ) if( aFrom || m_magneticSettings->pads == MAGNETIC_OPTIONS::CAPTURE_ALWAYS )
{ {
D_PAD* pad = static_cast<D_PAD*>( aItem ); D_PAD* pad = static_cast<D_PAD*>( aItem );
addAnchor( pad->GetPosition(), CORNER | SNAPPABLE, pad ); addAnchor( pad->GetPosition(), CORNER | SNAPPABLE, pad );
@ -436,7 +433,7 @@ void GRID_HELPER::computeAnchors( BOARD_ITEM* aItem, const VECTOR2I& aRefPos, bo
case PCB_MODULE_EDGE_T: case PCB_MODULE_EDGE_T:
case PCB_LINE_T: case PCB_LINE_T:
{ {
if( !m_frame->GetMagneticItemsSettings()->graphics ) if( !m_magneticSettings->graphics )
break; break;
DRAWSEGMENT* dseg = static_cast<DRAWSEGMENT*>( aItem ); DRAWSEGMENT* dseg = static_cast<DRAWSEGMENT*>( aItem );
@ -480,7 +477,7 @@ void GRID_HELPER::computeAnchors( BOARD_ITEM* aItem, const VECTOR2I& aRefPos, bo
break; break;
case S_POLYGON: case S_POLYGON:
for( const auto& p : dseg->BuildPolyPointsList() ) for( const VECTOR2I& p : dseg->BuildPolyPointsList() )
addAnchor( p, CORNER | SNAPPABLE, dseg ); addAnchor( p, CORNER | SNAPPABLE, dseg );
break; break;
@ -501,7 +498,7 @@ void GRID_HELPER::computeAnchors( BOARD_ITEM* aItem, const VECTOR2I& aRefPos, bo
case PCB_TRACE_T: case PCB_TRACE_T:
case PCB_ARC_T: case PCB_ARC_T:
{ {
if( aFrom || m_frame->GetMagneticItemsSettings()->tracks == MAGNETIC_OPTIONS::CAPTURE_ALWAYS ) if( aFrom || m_magneticSettings->tracks == MAGNETIC_OPTIONS::CAPTURE_ALWAYS )
{ {
TRACK* track = static_cast<TRACK*>( aItem ); TRACK* track = static_cast<TRACK*>( aItem );
VECTOR2I start = track->GetStart(); VECTOR2I start = track->GetStart();
@ -523,7 +520,7 @@ void GRID_HELPER::computeAnchors( BOARD_ITEM* aItem, const VECTOR2I& aRefPos, bo
case PCB_VIA_T: case PCB_VIA_T:
{ {
if( aFrom || m_frame->GetMagneticItemsSettings()->tracks == MAGNETIC_OPTIONS::CAPTURE_ALWAYS ) if( aFrom || m_magneticSettings->tracks == MAGNETIC_OPTIONS::CAPTURE_ALWAYS )
addAnchor( aItem->GetPosition(), ORIGIN | CORNER | SNAPPABLE, aItem ); addAnchor( aItem->GetPosition(), ORIGIN | CORNER | SNAPPABLE, aItem );
break; break;
@ -568,7 +565,8 @@ void GRID_HELPER::computeAnchors( BOARD_ITEM* aItem, const VECTOR2I& aRefPos, bo
} }
GRID_HELPER::ANCHOR* GRID_HELPER::nearestAnchor( const VECTOR2I& aPos, int aFlags, LSET aMatchLayers ) GRID_HELPER::ANCHOR* GRID_HELPER::nearestAnchor( const VECTOR2I& aPos, int aFlags,
LSET aMatchLayers )
{ {
double minDist = std::numeric_limits<double>::max(); double minDist = std::numeric_limits<double>::max();
ANCHOR* best = NULL; ANCHOR* best = NULL;

View File

@ -34,12 +34,11 @@
#include <geometry/seg.h> #include <geometry/seg.h>
#include <geometry/shape_arc.h> #include <geometry/shape_arc.h>
class PCB_BASE_FRAME;
class GRID_HELPER { class GRID_HELPER {
public: public:
GRID_HELPER( PCB_BASE_FRAME* aFrame ); GRID_HELPER( TOOL_MANAGER* aToolMgr, MAGNETIC_SETTINGS* aMagneticSettings );
~GRID_HELPER(); ~GRID_HELPER();
VECTOR2I GetGrid() const; VECTOR2I GetGrid() const;
@ -149,16 +148,18 @@ private:
m_anchors.clear(); m_anchors.clear();
} }
PCB_BASE_FRAME* m_frame;
TOOL_MANAGER* m_toolMgr; TOOL_MANAGER* m_toolMgr;
OPT<VECTOR2I> m_auxAxis; OPT<VECTOR2I> m_auxAxis;
bool m_enableSnap; ///< If true, allow snapping to other items on the layers bool m_enableSnap; // If true, allow snapping to other items on the layers
bool m_enableGrid; ///< If true, allow snapping to grid bool m_enableGrid; // If true, allow snapping to grid
bool m_enableSnapLine; ///< If true, allow drawing lines from snap points bool m_enableSnapLine; // If true, allow drawing lines from snap points
int m_snapSize; ///< Sets the radius in screen units for snapping to items 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) ANCHOR* m_snapItem; // Pointer to the currently snapped item in m_anchors
VECTOR2I m_skipPoint; ///< When drawing a line, we avoid snapping to the source point // (NULL if not snapped)
VECTOR2I m_skipPoint; // When drawing a line, we avoid snapping to the source point
MAGNETIC_SETTINGS* m_magneticSettings;
KIGFX::ORIGIN_VIEWITEM m_viewSnapPoint; KIGFX::ORIGIN_VIEWITEM m_viewSnapPoint;
KIGFX::ORIGIN_VIEWITEM m_viewSnapLine; KIGFX::ORIGIN_VIEWITEM m_viewSnapLine;

View File

@ -216,7 +216,7 @@ int PCB_VIEWER_TOOLS::MeasureTool( const TOOL_EVENT& aEvent )
view.Add( &ruler ); view.Add( &ruler );
view.SetVisible( &ruler, false ); view.SetVisible( &ruler, false );
GRID_HELPER grid( frame() ); GRID_HELPER grid( m_toolMgr, frame()->GetMagneticItemsSettings() );
bool originSet = false; bool originSet = false;

View File

@ -41,18 +41,18 @@ PCBNEW_PICKER_TOOL::PCBNEW_PICKER_TOOL()
int PCBNEW_PICKER_TOOL::Main( const TOOL_EVENT& aEvent ) int PCBNEW_PICKER_TOOL::Main( const TOOL_EVENT& aEvent )
{ {
KIGFX::VIEW_CONTROLS* controls = getViewControls(); KIGFX::VIEW_CONTROLS* controls = getViewControls();
auto tool_frame = getEditFrame<PCB_BASE_FRAME>(); PCB_BASE_FRAME* frame = getEditFrame<PCB_BASE_FRAME>();
GRID_HELPER grid( tool_frame ); GRID_HELPER grid( m_toolMgr, frame->GetMagneticItemsSettings() );
int finalize_state = WAIT_CANCEL; int finalize_state = WAIT_CANCEL;
std::string tool = *aEvent.Parameter<std::string*>(); std::string tool = *aEvent.Parameter<std::string*>();
tool_frame->PushTool( tool ); frame->PushTool( tool );
Activate(); Activate();
setControls(); setControls();
while( TOOL_EVENT* evt = Wait() ) while( TOOL_EVENT* evt = Wait() )
{ {
tool_frame->GetCanvas()->SetCursor( m_cursor ); frame->GetCanvas()->SetCursor( m_cursor );
grid.SetSnap( !evt->Modifier( MD_SHIFT ) ); grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
grid.SetUseGrid( !evt->Modifier( MD_ALT ) ); grid.SetUseGrid( !evt->Modifier( MD_ALT ) );
@ -156,7 +156,7 @@ int PCBNEW_PICKER_TOOL::Main( const TOOL_EVENT& aEvent )
reset(); reset();
controls->ForceCursorPosition( false ); controls->ForceCursorPosition( false );
tool_frame->PopTool( tool ); frame->PopTool( tool );
return 0; return 0;
} }

View File

@ -303,7 +303,7 @@ int POINT_EDITOR::OnSelectionChange( const TOOL_EVENT& aEvent )
controls->ShowCursor( true ); controls->ShowCursor( true );
GRID_HELPER grid( editFrame ); GRID_HELPER grid( m_toolMgr, editFrame->GetMagneticItemsSettings() );
BOARD_ITEM* item = static_cast<BOARD_ITEM*>( selection.Front() ); BOARD_ITEM* item = static_cast<BOARD_ITEM*>( selection.Front() );
if( !item ) if( !item )