Divorce GRID_HELPER from the parent frame.
This moves GRID_HELPER fully into the tool framework.
This commit is contained in:
parent
a02d8a5993
commit
47ab7c78a6
|
@ -115,7 +115,7 @@ void TOOL_BASE::Reset( RESET_REASON aReason )
|
|||
|
||||
m_router->LoadSettings( settings->m_PnsSettings.get() );
|
||||
|
||||
m_gridHelper = new GRID_HELPER( frame() );
|
||||
m_gridHelper = new GRID_HELPER( m_toolMgr, frame()->GetMagneticItemsSettings() );
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -477,7 +477,7 @@ int DRAWING_TOOL::DrawDimension( const TOOL_EVENT& aEvent )
|
|||
POINT_EDITOR* pointEditor = m_toolMgr->GetTool<POINT_EDITOR>();
|
||||
DIMENSION* dimension = NULL;
|
||||
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();
|
||||
|
||||
|
@ -859,7 +859,7 @@ int DRAWING_TOOL::SetAnchor( const TOOL_EVENT& aEvent )
|
|||
return 0;
|
||||
|
||||
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();
|
||||
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
|
||||
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>();
|
||||
|
||||
m_lineWidth = getSegmentWidth( getDrawingLayer() );
|
||||
|
@ -1192,7 +1192,7 @@ bool DRAWING_TOOL::drawArc( const std::string& aTool, DRAWSEGMENT*& aGraphic, bo
|
|||
PCBNEW_SELECTION preview;
|
||||
m_view->Add( &preview );
|
||||
m_view->Add( &arcAsst );
|
||||
GRID_HELPER grid( m_frame );
|
||||
GRID_HELPER grid( m_toolMgr, m_frame->GetMagneticItemsSettings() );
|
||||
|
||||
m_controls->ShowCursor( true );
|
||||
m_controls->SetSnapping( true );
|
||||
|
@ -1440,7 +1440,7 @@ int DRAWING_TOOL::DrawZone( const TOOL_EVENT& aEvent )
|
|||
m_controls->SetSnapping( true );
|
||||
|
||||
bool started = false;
|
||||
GRID_HELPER grid( m_frame );
|
||||
GRID_HELPER grid( m_toolMgr, m_frame->GetMagneticItemsSettings() );
|
||||
STATUS_TEXT_POPUP status( m_frame );
|
||||
status.SetTextColor( wxColour( 255, 0, 0 ) );
|
||||
status.SetText( _( "Self-intersecting polygons are not allowed" ) );
|
||||
|
@ -1595,7 +1595,8 @@ int DRAWING_TOOL::DrawVia( const TOOL_EVENT& aEvent )
|
|||
{
|
||||
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()
|
||||
|
|
|
@ -334,7 +334,7 @@ int EDIT_TOOL::Move( const TOOL_EVENT& aEvent )
|
|||
|
||||
bool restore_state = false;
|
||||
VECTOR2I totalMovement;
|
||||
GRID_HELPER grid( editFrame );
|
||||
GRID_HELPER grid( m_toolMgr, editFrame->GetMagneticItemsSettings() );
|
||||
TOOL_EVENT* evt = const_cast<TOOL_EVENT*>( &aEvent );
|
||||
VECTOR2I prevPos;
|
||||
|
||||
|
|
|
@ -26,7 +26,6 @@
|
|||
#include <functional>
|
||||
using namespace std::placeholders;
|
||||
|
||||
#include <pcb_edit_frame.h>
|
||||
#include <class_board.h>
|
||||
#include <class_dimension.h>
|
||||
#include <class_edge_mod.h>
|
||||
|
@ -46,9 +45,9 @@ using namespace std::placeholders;
|
|||
#include "grid_helper.h"
|
||||
|
||||
|
||||
GRID_HELPER::GRID_HELPER( PCB_BASE_FRAME* aFrame ) :
|
||||
m_frame( aFrame ),
|
||||
m_toolMgr( aFrame->GetToolManager() )
|
||||
GRID_HELPER::GRID_HELPER( TOOL_MANAGER* aToolMgr, MAGNETIC_SETTINGS* aMagneticSettings ) :
|
||||
m_toolMgr( aToolMgr ),
|
||||
m_magneticSettings( aMagneticSettings )
|
||||
{
|
||||
m_enableSnap = 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 )
|
||||
{
|
||||
OPT_VECTOR2I pts[6];
|
||||
|
||||
if( !m_enableSnap )
|
||||
return aPoint;
|
||||
|
||||
|
@ -213,7 +210,7 @@ VECTOR2I GRID_HELPER::BestDragOrigin( const VECTOR2I &aMousePos, std::vector<BOA
|
|||
{
|
||||
clearAnchors();
|
||||
|
||||
for( auto item : aItems )
|
||||
for( BOARD_ITEM* item : aItems )
|
||||
computeAnchors( item, aMousePos, true );
|
||||
|
||||
double worldScale = m_toolMgr->GetView()->GetGAL()->GetWorldScale();
|
||||
|
@ -255,7 +252,7 @@ VECTOR2I GRID_HELPER::BestDragOrigin( const VECTOR2I &aMousePos, std::vector<BOA
|
|||
|
||||
|
||||
std::set<BOARD_ITEM*> GRID_HELPER::queryVisible( const BOX2I& aArea,
|
||||
const std::vector<BOARD_ITEM*>& aSkip ) const
|
||||
const std::vector<BOARD_ITEM*>& aSkip ) const
|
||||
{
|
||||
std::set<BOARD_ITEM*> items;
|
||||
std::vector<KIGFX::VIEW::LAYER_ITEM_PAIR> selectedItems;
|
||||
|
@ -267,7 +264,7 @@ std::set<BOARD_ITEM*> GRID_HELPER::queryVisible( const BOX2I& aArea,
|
|||
|
||||
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 );
|
||||
|
||||
|
@ -281,8 +278,8 @@ std::set<BOARD_ITEM*> GRID_HELPER::queryVisible( const BOX2I& aArea,
|
|||
}
|
||||
|
||||
|
||||
for( auto ii : aSkip )
|
||||
items.erase( ii );
|
||||
for( BOARD_ITEM* skipItem : aSkip )
|
||||
items.erase( skipItem );
|
||||
|
||||
return items;
|
||||
}
|
||||
|
@ -306,21 +303,22 @@ VECTOR2I GRID_HELPER::BestSnapAnchor( const VECTOR2I& aOrigin, BOARD_ITEM* aDrag
|
|||
|
||||
|
||||
VECTOR2I GRID_HELPER::BestSnapAnchor( const VECTOR2I& aOrigin, const LSET& aLayers,
|
||||
const std::vector<BOARD_ITEM*>& aSkip )
|
||||
const std::vector<BOARD_ITEM*>& 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 ) );
|
||||
BOX2I bb( VECTOR2I( aOrigin.x - snapRange / 2, aOrigin.y - snapRange / 2 ),
|
||||
VECTOR2I( snapRange, snapRange ) );
|
||||
|
||||
clearAnchors();
|
||||
|
||||
for( BOARD_ITEM* item : queryVisible( bb, aSkip ) )
|
||||
computeAnchors( item, aOrigin );
|
||||
|
||||
ANCHOR* nearest = nearestAnchor( aOrigin, SNAPPABLE, aLayers );
|
||||
ANCHOR* nearest = nearestAnchor( aOrigin, SNAPPABLE, aLayers );
|
||||
VECTOR2I nearestGrid = Align( aOrigin );
|
||||
double gridDist = ( nearestGrid - aOrigin ).EuclideanNorm();
|
||||
double gridDist = ( nearestGrid - aOrigin ).EuclideanNorm();
|
||||
|
||||
if( nearest && m_enableSnap )
|
||||
{
|
||||
|
@ -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 )
|
||||
return nullptr;
|
||||
|
@ -390,7 +388,7 @@ BOARD_ITEM* GRID_HELPER::GetSnapped( void ) const
|
|||
|
||||
void GRID_HELPER::computeAnchors( BOARD_ITEM* aItem, const VECTOR2I& aRefPos, bool aFrom )
|
||||
{
|
||||
VECTOR2I origin;
|
||||
VECTOR2I origin;
|
||||
KIGFX::VIEW* view = m_toolMgr->GetView();
|
||||
RENDER_SETTINGS* settings = view->GetPainter()->GetSettings();
|
||||
const std::set<unsigned int>& activeLayers = settings->GetActiveLayers();
|
||||
|
@ -405,8 +403,7 @@ void GRID_HELPER::computeAnchors( BOARD_ITEM* aItem, const VECTOR2I& aRefPos, bo
|
|||
for( D_PAD* pad : mod->Pads() )
|
||||
{
|
||||
// Getting pads from the module requires re-checking that the pad is shown
|
||||
if( ( aFrom ||
|
||||
m_frame->GetMagneticItemsSettings()->pads == MAGNETIC_OPTIONS::CAPTURE_ALWAYS )
|
||||
if( ( aFrom || m_magneticSettings->pads == MAGNETIC_OPTIONS::CAPTURE_ALWAYS )
|
||||
&& pad->GetBoundingBox().Contains( wxPoint( aRefPos.x, aRefPos.y ) )
|
||||
&& view->IsVisible( pad )
|
||||
&& ( !isHighContrast || activeLayers.count( pad->GetLayer() ) )
|
||||
|
@ -424,7 +421,7 @@ void GRID_HELPER::computeAnchors( BOARD_ITEM* aItem, const VECTOR2I& aRefPos, bo
|
|||
|
||||
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 );
|
||||
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_LINE_T:
|
||||
{
|
||||
if( !m_frame->GetMagneticItemsSettings()->graphics )
|
||||
if( !m_magneticSettings->graphics )
|
||||
break;
|
||||
|
||||
DRAWSEGMENT* dseg = static_cast<DRAWSEGMENT*>( aItem );
|
||||
|
@ -480,7 +477,7 @@ void GRID_HELPER::computeAnchors( BOARD_ITEM* aItem, const VECTOR2I& aRefPos, bo
|
|||
break;
|
||||
|
||||
case S_POLYGON:
|
||||
for( const auto& p : dseg->BuildPolyPointsList() )
|
||||
for( const VECTOR2I& p : dseg->BuildPolyPointsList() )
|
||||
addAnchor( p, CORNER | SNAPPABLE, dseg );
|
||||
|
||||
break;
|
||||
|
@ -501,7 +498,7 @@ void GRID_HELPER::computeAnchors( BOARD_ITEM* aItem, const VECTOR2I& aRefPos, bo
|
|||
case PCB_TRACE_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 );
|
||||
VECTOR2I start = track->GetStart();
|
||||
|
@ -523,7 +520,7 @@ void GRID_HELPER::computeAnchors( BOARD_ITEM* aItem, const VECTOR2I& aRefPos, bo
|
|||
|
||||
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 );
|
||||
|
||||
break;
|
||||
|
@ -568,9 +565,10 @@ 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;
|
||||
|
||||
for( ANCHOR& a : m_anchors )
|
||||
|
|
|
@ -34,12 +34,11 @@
|
|||
#include <geometry/seg.h>
|
||||
#include <geometry/shape_arc.h>
|
||||
|
||||
class PCB_BASE_FRAME;
|
||||
|
||||
class GRID_HELPER {
|
||||
public:
|
||||
|
||||
GRID_HELPER( PCB_BASE_FRAME* aFrame );
|
||||
GRID_HELPER( TOOL_MANAGER* aToolMgr, MAGNETIC_SETTINGS* aMagneticSettings );
|
||||
~GRID_HELPER();
|
||||
|
||||
VECTOR2I GetGrid() const;
|
||||
|
@ -149,16 +148,18 @@ private:
|
|||
m_anchors.clear();
|
||||
}
|
||||
|
||||
PCB_BASE_FRAME* m_frame;
|
||||
TOOL_MANAGER* m_toolMgr;
|
||||
OPT<VECTOR2I> m_auxAxis;
|
||||
TOOL_MANAGER* m_toolMgr;
|
||||
OPT<VECTOR2I> m_auxAxis;
|
||||
|
||||
bool m_enableSnap; ///< If true, allow snapping to other items on the layers
|
||||
bool m_enableGrid; ///< If true, allow snapping to grid
|
||||
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
|
||||
bool m_enableSnap; // If true, allow snapping to other items on the layers
|
||||
bool m_enableGrid; // If true, allow snapping to grid
|
||||
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
|
||||
|
||||
MAGNETIC_SETTINGS* m_magneticSettings;
|
||||
|
||||
KIGFX::ORIGIN_VIEWITEM m_viewSnapPoint;
|
||||
KIGFX::ORIGIN_VIEWITEM m_viewSnapLine;
|
||||
|
|
|
@ -216,7 +216,7 @@ int PCB_VIEWER_TOOLS::MeasureTool( const TOOL_EVENT& aEvent )
|
|||
view.Add( &ruler );
|
||||
view.SetVisible( &ruler, false );
|
||||
|
||||
GRID_HELPER grid( frame() );
|
||||
GRID_HELPER grid( m_toolMgr, frame()->GetMagneticItemsSettings() );
|
||||
|
||||
bool originSet = false;
|
||||
|
||||
|
|
|
@ -41,18 +41,18 @@ PCBNEW_PICKER_TOOL::PCBNEW_PICKER_TOOL()
|
|||
int PCBNEW_PICKER_TOOL::Main( const TOOL_EVENT& aEvent )
|
||||
{
|
||||
KIGFX::VIEW_CONTROLS* controls = getViewControls();
|
||||
auto tool_frame = getEditFrame<PCB_BASE_FRAME>();
|
||||
GRID_HELPER grid( tool_frame );
|
||||
int finalize_state = WAIT_CANCEL;
|
||||
PCB_BASE_FRAME* frame = getEditFrame<PCB_BASE_FRAME>();
|
||||
GRID_HELPER grid( m_toolMgr, frame->GetMagneticItemsSettings() );
|
||||
int finalize_state = WAIT_CANCEL;
|
||||
|
||||
std::string tool = *aEvent.Parameter<std::string*>();
|
||||
tool_frame->PushTool( tool );
|
||||
frame->PushTool( tool );
|
||||
Activate();
|
||||
setControls();
|
||||
|
||||
while( TOOL_EVENT* evt = Wait() )
|
||||
{
|
||||
tool_frame->GetCanvas()->SetCursor( m_cursor );
|
||||
frame->GetCanvas()->SetCursor( m_cursor );
|
||||
|
||||
grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
|
||||
grid.SetUseGrid( !evt->Modifier( MD_ALT ) );
|
||||
|
@ -156,7 +156,7 @@ int PCBNEW_PICKER_TOOL::Main( const TOOL_EVENT& aEvent )
|
|||
|
||||
reset();
|
||||
controls->ForceCursorPosition( false );
|
||||
tool_frame->PopTool( tool );
|
||||
frame->PopTool( tool );
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -303,7 +303,7 @@ int POINT_EDITOR::OnSelectionChange( const TOOL_EVENT& aEvent )
|
|||
|
||||
controls->ShowCursor( true );
|
||||
|
||||
GRID_HELPER grid( editFrame );
|
||||
GRID_HELPER grid( m_toolMgr, editFrame->GetMagneticItemsSettings() );
|
||||
BOARD_ITEM* item = static_cast<BOARD_ITEM*>( selection.Front() );
|
||||
|
||||
if( !item )
|
||||
|
|
Loading…
Reference in New Issue