Fixed alignment to grid when there is a grid offset (GAL).
This commit is contained in:
parent
5ca8e0b9d6
commit
b5ef511063
|
@ -39,6 +39,7 @@
|
||||||
#include <gal/graphics_abstraction_layer.h>
|
#include <gal/graphics_abstraction_layer.h>
|
||||||
#include <class_draw_panel_gal.h>
|
#include <class_draw_panel_gal.h>
|
||||||
#include <tool/tool_manager.h>
|
#include <tool/tool_manager.h>
|
||||||
|
#include <tools/common_actions.h>
|
||||||
|
|
||||||
// Max values for grid size
|
// Max values for grid size
|
||||||
#define MAX_GRID_SIZE ( 50.0 * IU_PER_MM )
|
#define MAX_GRID_SIZE ( 50.0 * IU_PER_MM )
|
||||||
|
@ -282,9 +283,15 @@ bool PCB_BASE_FRAME::InvokeDialogGrid()
|
||||||
TOOL_MANAGER* mgr = GetToolManager();
|
TOOL_MANAGER* mgr = GetToolManager();
|
||||||
|
|
||||||
if( mgr && IsGalCanvasActive() )
|
if( mgr && IsGalCanvasActive() )
|
||||||
|
{
|
||||||
mgr->RunAction( "common.Control.gridPreset", true,
|
mgr->RunAction( "common.Control.gridPreset", true,
|
||||||
screen->GetGridCmdId() - ID_POPUP_GRID_LEVEL_1000 );
|
screen->GetGridCmdId() - ID_POPUP_GRID_LEVEL_1000 );
|
||||||
|
|
||||||
|
TOOL_EVENT gridOriginUpdate = COMMON_ACTIONS::gridSetOrigin.MakeEvent();
|
||||||
|
gridOriginUpdate.SetParameter( new VECTOR2D( grid_origin ) );
|
||||||
|
mgr->ProcessEvent( gridOriginUpdate );
|
||||||
|
}
|
||||||
|
|
||||||
m_canvas->Refresh();
|
m_canvas->Refresh();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -228,7 +228,7 @@ int EDIT_TOOL::Main( const TOOL_EVENT& aEvent )
|
||||||
if( m_dragging )
|
if( m_dragging )
|
||||||
{
|
{
|
||||||
m_cursor = grid.BestSnapAnchor( evt->Position(), selection.Item<BOARD_ITEM>( 0 ) );
|
m_cursor = grid.BestSnapAnchor( evt->Position(), selection.Item<BOARD_ITEM>( 0 ) );
|
||||||
getViewControls()->ForceCursorPosition ( true, m_cursor );
|
getViewControls()->ForceCursorPosition( true, m_cursor );
|
||||||
|
|
||||||
wxPoint movement = wxPoint( m_cursor.x, m_cursor.y ) -
|
wxPoint movement = wxPoint( m_cursor.x, m_cursor.y ) -
|
||||||
selection.Item<BOARD_ITEM>( 0 )->GetPosition();
|
selection.Item<BOARD_ITEM>( 0 )->GetPosition();
|
||||||
|
|
|
@ -60,26 +60,27 @@ void GRID_HELPER::SetGrid( int aSize )
|
||||||
|
|
||||||
void GRID_HELPER::SetOrigin( const VECTOR2I& aOrigin )
|
void GRID_HELPER::SetOrigin( const VECTOR2I& aOrigin )
|
||||||
{
|
{
|
||||||
|
assert( false );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
VECTOR2I GRID_HELPER::GetGrid()
|
VECTOR2I GRID_HELPER::GetGrid() const
|
||||||
{
|
{
|
||||||
PCB_SCREEN* screen = m_frame->GetScreen();
|
PCB_SCREEN* screen = m_frame->GetScreen();
|
||||||
|
|
||||||
const wxRealPoint& size = screen->GetGridSize();
|
const wxRealPoint& size = screen->GetGridSize();
|
||||||
|
|
||||||
return VECTOR2I ( KiROUND( size.x ), KiROUND( size.y ) );
|
return VECTOR2I( KiROUND( size.x ), KiROUND( size.y ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
VECTOR2I GRID_HELPER::GetOrigin()
|
VECTOR2I GRID_HELPER::GetOrigin() const
|
||||||
{
|
{
|
||||||
return VECTOR2I( 0, 0 );
|
return VECTOR2I( m_frame->GetGridOrigin() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void GRID_HELPER::SetAuxAxes( bool aEnable, const VECTOR2I aOrigin, bool aEnableDiagonal )
|
void GRID_HELPER::SetAuxAxes( bool aEnable, const VECTOR2I& aOrigin, bool aEnableDiagonal )
|
||||||
{
|
{
|
||||||
if( aEnable )
|
if( aEnable )
|
||||||
m_auxAxis = aOrigin;
|
m_auxAxis = aOrigin;
|
||||||
|
@ -90,13 +91,13 @@ void GRID_HELPER::SetAuxAxes( bool aEnable, const VECTOR2I aOrigin, bool aEnable
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
VECTOR2I GRID_HELPER::Align( const VECTOR2I& aPoint )
|
VECTOR2I GRID_HELPER::Align( const VECTOR2I& aPoint ) const
|
||||||
{
|
{
|
||||||
const VECTOR2D gridOffset( GetOrigin () );
|
const VECTOR2D gridOffset( GetOrigin() );
|
||||||
const VECTOR2D gridSize( GetGrid() );
|
const VECTOR2D gridSize( GetGrid() );
|
||||||
|
|
||||||
VECTOR2I nearest( round( ( aPoint.x - gridOffset.x ) / gridSize.x ) * gridSize.x + gridOffset.x,
|
VECTOR2I nearest( round( ( aPoint.x - gridOffset.x ) / gridSize.x ) * gridSize.x + gridOffset.x,
|
||||||
round( ( aPoint.y - gridOffset.y ) / gridSize.y ) * gridSize.y + gridOffset.y );
|
round( ( aPoint.y - gridOffset.y ) / gridSize.y ) * gridSize.y + gridOffset.y );
|
||||||
|
|
||||||
if( !m_auxAxis )
|
if( !m_auxAxis )
|
||||||
return nearest;
|
return nearest;
|
||||||
|
@ -152,7 +153,7 @@ VECTOR2I GRID_HELPER::BestDragOrigin( const VECTOR2I &aMousePos, BOARD_ITEM* aIt
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::set<BOARD_ITEM*> GRID_HELPER::queryVisible( const BOX2I& aArea )
|
std::set<BOARD_ITEM*> GRID_HELPER::queryVisible( const BOX2I& aArea ) const
|
||||||
{
|
{
|
||||||
std::set<BOARD_ITEM*> items;
|
std::set<BOARD_ITEM*> items;
|
||||||
|
|
||||||
|
@ -172,12 +173,12 @@ std::set<BOARD_ITEM*> GRID_HELPER::queryVisible( const BOX2I& aArea )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
VECTOR2I GRID_HELPER::BestSnapAnchor( const VECTOR2I &aOrigin, BOARD_ITEM* aDraggedItem )
|
VECTOR2I GRID_HELPER::BestSnapAnchor( const VECTOR2I& aOrigin, BOARD_ITEM* aDraggedItem )
|
||||||
{
|
{
|
||||||
double worldScale = m_frame->GetGalCanvas()->GetGAL()->GetWorldScale();
|
double worldScale = m_frame->GetGalCanvas()->GetGAL()->GetWorldScale();
|
||||||
int snapRange = (int) ( 100.0 / worldScale );
|
int snapRange = (int) ( 100.0 / 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();
|
||||||
|
|
||||||
|
@ -197,9 +198,9 @@ VECTOR2I GRID_HELPER::BestSnapAnchor( const VECTOR2I &aOrigin, BOARD_ITEM* aDrag
|
||||||
|
|
||||||
if( nearest && snapDist < gridDist )
|
if( nearest && snapDist < gridDist )
|
||||||
return nearest->pos;
|
return nearest->pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
return nearestGrid;
|
return nearestGrid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -323,7 +324,7 @@ void GRID_HELPER::computeAnchors( BOARD_ITEM* aItem, const VECTOR2I& aRefPos )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
GRID_HELPER::ANCHOR* GRID_HELPER::nearestAnchor( 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;
|
||||||
|
|
|
@ -43,15 +43,15 @@ public:
|
||||||
void SetGrid( int aSize );
|
void SetGrid( int aSize );
|
||||||
void SetOrigin( const VECTOR2I& aOrigin );
|
void SetOrigin( const VECTOR2I& aOrigin );
|
||||||
|
|
||||||
VECTOR2I GetGrid();
|
VECTOR2I GetGrid() const;
|
||||||
VECTOR2I GetOrigin();
|
VECTOR2I GetOrigin() const;
|
||||||
|
|
||||||
void SetAuxAxes( bool aEnable, const VECTOR2I aOrigin = VECTOR2I( 0, 0 ), bool aEnableDiagonal = false );
|
void SetAuxAxes( bool aEnable, const VECTOR2I& aOrigin = VECTOR2I( 0, 0 ), bool aEnableDiagonal = false );
|
||||||
|
|
||||||
VECTOR2I Align( const VECTOR2I& aPoint );
|
VECTOR2I Align( const VECTOR2I& aPoint ) const;
|
||||||
|
|
||||||
VECTOR2I BestDragOrigin ( const VECTOR2I &aMousePos, BOARD_ITEM* aItem );
|
VECTOR2I BestDragOrigin( const VECTOR2I& aMousePos, BOARD_ITEM* aItem );
|
||||||
VECTOR2I BestSnapAnchor ( const VECTOR2I &aOrigin, BOARD_ITEM* aDraggedItem );
|
VECTOR2I BestSnapAnchor( const VECTOR2I& aOrigin, BOARD_ITEM* aDraggedItem );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
enum ANCHOR_FLAGS {
|
enum ANCHOR_FLAGS {
|
||||||
|
@ -70,28 +70,28 @@ private:
|
||||||
int flags;
|
int flags;
|
||||||
BOARD_ITEM* item;
|
BOARD_ITEM* item;
|
||||||
|
|
||||||
double Distance( const VECTOR2I& aP )
|
double Distance( const VECTOR2I& aP ) const
|
||||||
{
|
{
|
||||||
return ( aP - pos ).EuclideanNorm();
|
return ( aP - pos ).EuclideanNorm();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CanSnapItem( const BOARD_ITEM* aItem );
|
//bool CanSnapItem( const BOARD_ITEM* aItem ) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
std::vector<ANCHOR> m_anchors;
|
std::vector<ANCHOR> m_anchors;
|
||||||
|
|
||||||
std::set<BOARD_ITEM*> queryVisible( const BOX2I& aArea );
|
std::set<BOARD_ITEM*> queryVisible( const BOX2I& aArea ) const;
|
||||||
|
|
||||||
void addAnchor( VECTOR2I aPos, int aFlags = CORNER | SNAPPABLE, BOARD_ITEM* aItem = NULL )
|
void addAnchor( const VECTOR2I& aPos, int aFlags = CORNER | SNAPPABLE, BOARD_ITEM* aItem = NULL )
|
||||||
{
|
{
|
||||||
m_anchors.push_back( ANCHOR( aPos, aFlags, aItem ) );
|
m_anchors.push_back( ANCHOR( aPos, aFlags, aItem ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
ANCHOR* nearestAnchor( VECTOR2I aPos, int aFlags, LSET aMatchLayers );
|
ANCHOR* nearestAnchor( const VECTOR2I& aPos, int aFlags, LSET aMatchLayers );
|
||||||
|
|
||||||
void computeAnchors( BOARD_ITEM* aItem, const VECTOR2I& aRefPos );
|
void computeAnchors( BOARD_ITEM* aItem, const VECTOR2I& aRefPos );
|
||||||
|
|
||||||
void clearAnchors ()
|
void clearAnchors()
|
||||||
{
|
{
|
||||||
m_anchors.clear();
|
m_anchors.clear();
|
||||||
}
|
}
|
||||||
|
|
|
@ -472,13 +472,23 @@ static bool setOrigin( KIGFX::VIEW* aView, PCB_BASE_FRAME* aFrame,
|
||||||
|
|
||||||
int PCBNEW_CONTROL::GridSetOrigin( const TOOL_EVENT& aEvent )
|
int PCBNEW_CONTROL::GridSetOrigin( const TOOL_EVENT& aEvent )
|
||||||
{
|
{
|
||||||
PICKER_TOOL* picker = m_toolMgr->GetTool<PICKER_TOOL>();
|
VECTOR2D* origin = aEvent.Parameter<VECTOR2D*>();
|
||||||
assert( picker );
|
|
||||||
|
|
||||||
// TODO it will not check the toolbar button in module editor, as it uses a different ID..
|
if( origin )
|
||||||
m_frame->SetToolID( ID_PCB_PLACE_GRID_COORD_BUTT, wxCURSOR_PENCIL, _( "Adjust grid origin" ) );
|
{
|
||||||
picker->SetClickHandler( boost::bind( setOrigin, getView(), m_frame, m_gridOrigin, _1 ) );
|
setOrigin( getView(), m_frame, m_gridOrigin, *origin );
|
||||||
picker->Activate();
|
delete origin;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
PICKER_TOOL* picker = m_toolMgr->GetTool<PICKER_TOOL>();
|
||||||
|
assert( picker );
|
||||||
|
|
||||||
|
// TODO it will not check the toolbar button in module editor, as it uses a different ID..
|
||||||
|
m_frame->SetToolID( ID_PCB_PLACE_GRID_COORD_BUTT, wxCURSOR_PENCIL, _( "Adjust grid origin" ) );
|
||||||
|
picker->SetClickHandler( boost::bind( setOrigin, getView(), m_frame, m_gridOrigin, _1 ) );
|
||||||
|
picker->Activate();
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue