Hook up a bit more of the EE_GRID_HELPER.

Fixes https://gitlab.com/kicad/code/kicad/issues/5985
This commit is contained in:
Jeff Young 2020-12-02 23:17:56 +00:00
parent 599a33a9c6
commit 43fe228367
4 changed files with 46 additions and 54 deletions

View File

@ -174,12 +174,12 @@ VECTOR2I EE_GRID_HELPER::AlignToWire( const VECTOR2I& aPoint, const SEG& aSeg )
return nearest;
}
VECTOR2I EE_GRID_HELPER::BestDragOrigin( const VECTOR2I &aMousePos, const std::vector<SCH_ITEM*>& aItems )
VECTOR2I EE_GRID_HELPER::BestDragOrigin( const VECTOR2I &aMousePos, const EE_SELECTION& aItems )
{
clearAnchors();
for( SCH_ITEM* item : aItems )
computeAnchors( item, aMousePos, true );
for( EDA_ITEM* item : aItems )
computeAnchors( static_cast<SCH_ITEM*>( item ), aMousePos, true );
double worldScale = m_toolMgr->GetView()->GetGAL()->GetWorldScale();
double lineSnapMinCornerDistance = 50.0 / worldScale;
@ -220,12 +220,12 @@ VECTOR2I EE_GRID_HELPER::BestDragOrigin( const VECTOR2I &aMousePos, const std::v
std::set<SCH_ITEM*> EE_GRID_HELPER::queryVisible( const BOX2I& aArea,
const std::vector<SCH_ITEM*>& aSkip ) const
const EE_SELECTION& aSkip ) const
{
std::set<SCH_ITEM*> items;
std::set<SCH_ITEM*> items;
std::vector<KIGFX::VIEW::LAYER_ITEM_PAIR> selectedItems;
KIGFX::VIEW* view = m_toolMgr->GetView();
KIGFX::VIEW* view = m_toolMgr->GetView();
view->Query( aArea, selectedItems );
@ -234,16 +234,12 @@ std::set<SCH_ITEM*> EE_GRID_HELPER::queryVisible( const BOX2I& aArea,
SCH_ITEM* item = static_cast<SCH_ITEM*>( it.first );
// The item must be visible and on an active layer
if( view->IsVisible( item )
&& item->ViewGetLOD( it.second, view ) < view->GetScale() )
{
if( view->IsVisible( item ) && item->ViewGetLOD( it.second, view ) < view->GetScale() )
items.insert ( item );
}
}
for( SCH_ITEM* skipItem : aSkip )
items.erase( skipItem );
for( EDA_ITEM* skipItem : aSkip )
items.erase( static_cast<SCH_ITEM*>( skipItem ) );
return items;
}
@ -251,12 +247,15 @@ std::set<SCH_ITEM*> EE_GRID_HELPER::queryVisible( const BOX2I& aArea,
VECTOR2I EE_GRID_HELPER::BestSnapAnchor( const VECTOR2I& aOrigin, SCH_ITEM* aDraggedItem )
{
return BestSnapAnchor( aOrigin, LSET::AllLayersMask(), { aDraggedItem } );
EE_SELECTION draggedItems;
draggedItems.Add( aDraggedItem );
return BestSnapAnchor( aOrigin, LSET::AllLayersMask(), draggedItems );
}
VECTOR2I EE_GRID_HELPER::BestSnapAnchor( const VECTOR2I& aOrigin, const LSET& aLayers,
const std::vector<SCH_ITEM*>& aSkip )
const EE_SELECTION& aSkip )
{
int snapDist = GetGrid().x;
int snapRange = snapDist;
@ -270,7 +269,7 @@ VECTOR2I EE_GRID_HELPER::BestSnapAnchor( const VECTOR2I& aOrigin, const LSET& aL
computeAnchors( item, aOrigin );
ANCHOR* nearest = nearestAnchor( aOrigin, SNAPPABLE, aLayers );
VECTOR2I nearestGrid = Align( aOrigin );
VECTOR2I nearestGrid = m_enableGrid ? Align( aOrigin ) : aOrigin;
if( nearest )
snapDist = nearest->Distance( aOrigin );
@ -309,7 +308,6 @@ VECTOR2I EE_GRID_HELPER::BestSnapAnchor( const VECTOR2I& aOrigin, const LSET& aL
if( nearest && m_enableSnap )
{
if( snapDist <= snapRange )
{
m_viewSnapPoint.SetPosition( wxPoint( nearest->pos ) );

View File

@ -29,6 +29,7 @@
#include <vector>
#include <math/vector2d.h>
#include <origin_viewitem.h>
#include <ee_selection.h>
class LSET;
class SCH_ITEM;
@ -60,11 +61,11 @@ public:
VECTOR2I AlignToWire( const VECTOR2I& aPoint, const SEG& aSeg );
VECTOR2I BestDragOrigin( const VECTOR2I& aMousePos, const std::vector<SCH_ITEM*>& aItem );
VECTOR2I BestDragOrigin( const VECTOR2I& aMousePos, const EE_SELECTION& aItems );
VECTOR2I BestSnapAnchor( const VECTOR2I& aOrigin, SCH_ITEM* aDraggedItem );
VECTOR2I BestSnapAnchor( const VECTOR2I& aOrigin, const LSET& aLayers,
const std::vector<SCH_ITEM*>& aSkip = {} );
const EE_SELECTION& aSkip = {} );
void SetSkipPoint( const VECTOR2I& aPoint )
{
@ -79,15 +80,9 @@ public:
m_skipPoint = VECTOR2I( std::numeric_limits<int>::min(), std::numeric_limits<int>::min() );
}
void SetSnap( bool aSnap )
{
m_enableSnap = aSnap;
}
void SetSnapLine( bool aSnap )
{
m_enableSnapLine = aSnap;
}
void SetSnap( bool aSnap ) { m_enableSnap = aSnap; }
void SetUseGrid( bool aSnapToGrid ) { m_enableGrid = aSnapToGrid; }
void SetSnapLine( bool aSnap ) { m_enableSnapLine = aSnap; }
private:
enum ANCHOR_FLAGS {
@ -117,10 +112,7 @@ private:
}
};
std::vector<ANCHOR> m_anchors;
std::set<SCH_ITEM*> queryVisible( const BOX2I& aArea,
const std::vector<SCH_ITEM*>& aSkip ) const;
std::set<SCH_ITEM*> queryVisible( const BOX2I& aArea, const EE_SELECTION& aSkip ) const;
void addAnchor( const VECTOR2I& aPos, int aFlags, SCH_ITEM* aItem )
{
@ -144,15 +136,18 @@ private:
m_anchors.clear();
}
TOOL_MANAGER* m_toolMgr;
OPT<VECTOR2I> m_auxAxis;
std::vector<ANCHOR> m_anchors;
bool m_enableSnap; // If true, allow snapping to other items on the layers
bool m_enableSnapLine; // If true, allow drawing lines from snap points
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
TOOL_MANAGER* m_toolMgr;
OPT<VECTOR2I> m_auxAxis;
bool m_enableSnap; // Allow snapping to other items on the layers
bool m_enableGrid; // If true, allow snapping to grid
bool m_enableSnapLine; // Allow drawing lines from snap points
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
KIGFX::ORIGIN_VIEWITEM m_viewSnapPoint;
KIGFX::ORIGIN_VIEWITEM m_viewSnapLine;
KIGFX::ORIGIN_VIEWITEM m_viewAxis;

View File

@ -109,9 +109,9 @@ static const KICAD_T movableItems[] =
int SCH_MOVE_TOOL::Main( const TOOL_EVENT& aEvent )
{
EESCHEMA_SETTINGS* cfg = Pgm().GetSettingsManager().GetAppSettings<EESCHEMA_SETTINGS>();
EESCHEMA_SETTINGS* cfg = Pgm().GetSettingsManager().GetAppSettings<EESCHEMA_SETTINGS>();
KIGFX::VIEW_CONTROLS* controls = getViewControls();
EE_GRID_HELPER grid( m_toolMgr );
EE_GRID_HELPER grid( m_toolMgr );
m_anchorPos.reset();
@ -179,10 +179,15 @@ int SCH_MOVE_TOOL::Main( const TOOL_EVENT& aEvent )
do
{
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::MOVING );
grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
grid.SetUseGrid( !evt->Modifier( MD_ALT ) );
if( evt->IsAction( &EE_ACTIONS::moveActivate ) || evt->IsAction( &EE_ACTIONS::restartMove )
|| evt->IsAction( &EE_ACTIONS::move ) || evt->IsAction( &EE_ACTIONS::drag )
|| evt->IsMotion() || evt->IsDrag( BUT_LEFT )
if( evt->IsAction( &EE_ACTIONS::moveActivate )
|| evt->IsAction( &EE_ACTIONS::restartMove )
|| evt->IsAction( &EE_ACTIONS::move )
|| evt->IsAction( &EE_ACTIONS::drag )
|| evt->IsMotion()
|| evt->IsDrag( BUT_LEFT )
|| evt->IsAction( &ACTIONS::refreshPreview ) )
{
if( !m_moveInProgress ) // Prepare to start moving/dragging
@ -312,12 +317,7 @@ int SCH_MOVE_TOOL::Main( const TOOL_EVENT& aEvent )
if( m_frame->GetMoveWarpsCursor() )
{
// User wants to warp the mouse
std::vector<SCH_ITEM*> items;
for( EDA_ITEM* item : selection )
items.push_back( static_cast<SCH_ITEM*>( item ) );
m_cursor = grid.BestDragOrigin( m_cursor, items );
m_cursor = grid.BestDragOrigin( m_cursor, selection );
}
else
{
@ -326,7 +326,6 @@ int SCH_MOVE_TOOL::Main( const TOOL_EVENT& aEvent )
}
}
controls->SetCursorPosition( m_cursor, false );
m_toolMgr->PostEvent( EVENTS::SelectedItemsModified );
@ -338,7 +337,9 @@ int SCH_MOVE_TOOL::Main( const TOOL_EVENT& aEvent )
//------------------------------------------------------------------------
// Follow the mouse
//
m_cursor = controls->GetCursorPosition();
m_cursor = grid.BestSnapAnchor( controls->GetCursorPosition( false ),
LSET::AllLayersMask(), selection );
VECTOR2I delta( m_cursor - prevPos );
m_anchorPos = m_cursor;

View File

@ -614,12 +614,10 @@ int EDIT_TOOL::doMoveSelection( TOOL_EVENT aEvent, bool aPickReference )
break; // finish -- we moved exactly, so we are finished
}
else if( evt->IsMouseUp( BUT_LEFT ) || evt->IsClick( BUT_LEFT ) )
{
break; // finish
}
else
{
evt->SetPassEvent();