diff --git a/eeschema/symbol_editor/symbol_edit_frame.cpp b/eeschema/symbol_editor/symbol_edit_frame.cpp index 6a7dde2673..77648b0760 100644 --- a/eeschema/symbol_editor/symbol_edit_frame.cpp +++ b/eeschema/symbol_editor/symbol_edit_frame.cpp @@ -425,6 +425,7 @@ void SYMBOL_EDIT_FRAME::setupUIConditions() mgr->SetConditions( ACTIONS::revert, ENABLE( symbolModifiedCondition ) ); mgr->SetConditions( ACTIONS::toggleGrid, CHECK( cond.GridVisible() ) ); + mgr->SetConditions( ACTIONS::toggleGridOverrides, CHECK( cond.GridOverrides() ) ); mgr->SetConditions( ACTIONS::toggleCursorStyle, CHECK( cond.FullscreenCursor() ) ); mgr->SetConditions( ACTIONS::millimetersUnits, CHECK( cond.Units( EDA_UNITS::MILLIMETRES ) ) ); mgr->SetConditions( ACTIONS::inchesUnits, CHECK( cond.Units( EDA_UNITS::INCHES ) ) ); diff --git a/eeschema/symbol_editor/toolbars_symbol_editor.cpp b/eeschema/symbol_editor/toolbars_symbol_editor.cpp index f77db39a9c..a4fdbf76d5 100644 --- a/eeschema/symbol_editor/toolbars_symbol_editor.cpp +++ b/eeschema/symbol_editor/toolbars_symbol_editor.cpp @@ -160,6 +160,7 @@ void SYMBOL_EDIT_FRAME::ReCreateOptToolbar() } m_optionsToolBar->Add( ACTIONS::toggleGrid, ACTION_TOOLBAR::TOGGLE ); + m_optionsToolBar->Add( ACTIONS::toggleGridOverrides, ACTION_TOOLBAR::TOGGLE ); m_optionsToolBar->Add( ACTIONS::inchesUnits, ACTION_TOOLBAR::TOGGLE ); m_optionsToolBar->Add( ACTIONS::milsUnits, ACTION_TOOLBAR::TOGGLE ); m_optionsToolBar->Add( ACTIONS::millimetersUnits, ACTION_TOOLBAR::TOGGLE ); diff --git a/eeschema/tools/ee_grid_helper.cpp b/eeschema/tools/ee_grid_helper.cpp index d7420574d2..de4d5aa032 100644 --- a/eeschema/tools/ee_grid_helper.cpp +++ b/eeschema/tools/ee_grid_helper.cpp @@ -336,12 +336,12 @@ std::set EE_GRID_HELPER::queryVisible( const BOX2I& aArea, GRID_HELPER_GRIDS EE_GRID_HELPER::GetSelectionGrid( const EE_SELECTION& aSelection ) { - GRID_HELPER_GRIDS grid = GetItemGrid( static_cast( aSelection.Front() ) ); + 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( static_cast( item ) ); + GRID_HELPER_GRIDS itemGrid = GetItemGrid( item ); if( GetGridSize( itemGrid ) > GetGridSize( grid ) ) grid = itemGrid; @@ -351,13 +351,15 @@ GRID_HELPER_GRIDS EE_GRID_HELPER::GetSelectionGrid( const EE_SELECTION& aSelecti } -GRID_HELPER_GRIDS EE_GRID_HELPER::GetItemGrid( const SCH_ITEM* aItem ) const +GRID_HELPER_GRIDS EE_GRID_HELPER::GetItemGrid( const EDA_ITEM* aItem ) const { if( !aItem ) return GRID_CURRENT; switch( aItem->Type() ) { + case LIB_SYMBOL_T: + case LIB_PIN_T: case SCH_SYMBOL_T: case SCH_PIN_T: case SCH_SHEET_PIN_T: @@ -369,21 +371,25 @@ GRID_HELPER_GRIDS EE_GRID_HELPER::GetItemGrid( const SCH_ITEM* aItem ) const case SCH_DIRECTIVE_LABEL_T: return GRID_CONNECTABLE; - case SCH_TEXT_T: + case LIB_FIELD_T: case SCH_FIELD_T: + case LIB_TEXT_T: + case SCH_TEXT_T: return GRID_TEXT; + case LIB_SHAPE_T: case SCH_SHAPE_T: - case SCH_BITMAP_T: // The text box's border lines are what need to be on the graphic grid + case LIB_TEXTBOX_T: case SCH_TEXTBOX_T: + case SCH_BITMAP_T: return GRID_GRAPHICS; case SCH_JUNCTION_T: return GRID_WIRES; case SCH_LINE_T: - if( aItem->IsConnectable() ) + if( static_cast( aItem )->IsConnectable() ) return GRID_WIRES; else return GRID_GRAPHICS; diff --git a/eeschema/tools/ee_grid_helper.h b/eeschema/tools/ee_grid_helper.h index d70ec78fd7..34a215aeea 100644 --- a/eeschema/tools/ee_grid_helper.h +++ b/eeschema/tools/ee_grid_helper.h @@ -32,6 +32,7 @@ #include class SCH_ITEM; +class LIB_ITEM; enum GRID_HELPER_GRIDS : int @@ -69,14 +70,20 @@ public: VECTOR2D GetGridSize( GRID_HELPER_GRIDS aGrid ) const; using GRID_HELPER::GetGrid; + /** + * Gets the coarsest grid that applies to a selecion of items. + */ GRID_HELPER_GRIDS GetSelectionGrid( const EE_SELECTION& aItem ); - GRID_HELPER_GRIDS GetItemGrid( const SCH_ITEM* aItem ) const; + + /** + * Gets the coarsest grid that applies to an item. + */ + GRID_HELPER_GRIDS GetItemGrid( const EDA_ITEM* aItem ) const; VECTOR2I BestDragOrigin( const VECTOR2I& aMousePos, GRID_HELPER_GRIDS aGrid, const EE_SELECTION& aItems ); - VECTOR2I BestSnapAnchor( const VECTOR2I& aOrigin, GRID_HELPER_GRIDS aGrid, - SCH_ITEM* aDraggedItem ); + VECTOR2I BestSnapAnchor( const VECTOR2I& aOrigin, GRID_HELPER_GRIDS aGrid, SCH_ITEM* aSkip ); VECTOR2I BestSnapAnchor( const VECTOR2I& aOrigin, GRID_HELPER_GRIDS aGrid, const EE_SELECTION& aSkip = {} ); diff --git a/eeschema/tools/sch_drawing_tools.cpp b/eeschema/tools/sch_drawing_tools.cpp index 67d0c2bb91..3a6d4a5890 100644 --- a/eeschema/tools/sch_drawing_tools.cpp +++ b/eeschema/tools/sch_drawing_tools.cpp @@ -317,13 +317,14 @@ int SCH_DRAWING_TOOLS::PlaceSymbol( const TOOL_EVENT& aEvent ) // boundaries. if( evt->IsPrime() && !ignorePrimePosition ) { - cursorPos = grid.Align( evt->Position() ); + cursorPos = grid.Align( evt->Position(), GRID_HELPER_GRIDS::GRID_CONNECTABLE ); getViewControls()->WarpMouseCursor( cursorPos, true ); } else { getViewControls()->PinCursorInsideNonAutoscrollArea( true ); - cursorPos = getViewControls()->GetMousePosition(); + cursorPos = grid.Align( getViewControls()->GetMousePosition(), + GRID_HELPER_GRIDS::GRID_CONNECTABLE ); } symbol = new SCH_SYMBOL( *libSymbol, &m_frame->GetCurrentSheet(), sel, cursorPos, diff --git a/eeschema/tools/symbol_editor_drawing_tools.cpp b/eeschema/tools/symbol_editor_drawing_tools.cpp index 4a5ca582c0..b5557ebb92 100644 --- a/eeschema/tools/symbol_editor_drawing_tools.cpp +++ b/eeschema/tools/symbol_editor_drawing_tools.cpp @@ -142,7 +142,7 @@ int SYMBOL_EDITOR_DRAWING_TOOLS::TwoClickPlace( const TOOL_EVENT& aEvent ) grid.SetSnap( !evt->Modifier( MD_SHIFT ) ); grid.SetUseGrid( getView()->GetGAL()->GetGridSnapping() && !evt->DisableGridSnapping() ); - cursorPos = grid.Align( controls->GetMousePosition() ); + cursorPos = grid.Align( controls->GetMousePosition(), grid.GetItemGrid( item ) ); controls->ForceCursorPosition( true, cursorPos ); // The tool hotkey is interpreted as a click when drawing @@ -246,7 +246,7 @@ int SYMBOL_EDITOR_DRAWING_TOOLS::TwoClickPlace( const TOOL_EVENT& aEvent ) // boundaries. if( evt->IsPrime() && !ignorePrimePosition ) { - cursorPos = grid.Align( evt->Position() ); + cursorPos = grid.Align( evt->Position(), grid.GetItemGrid( item ) ); getViewControls()->WarpMouseCursor( cursorPos, true ); } else @@ -350,8 +350,11 @@ int SYMBOL_EDITOR_DRAWING_TOOLS::doDrawShape( const TOOL_EVENT& aEvent, std::opt bool isTextBox = !aDrawingShape.has_value(); SHAPE_T toolType = aDrawingShape.value_or( SHAPE_T::SEGMENT ); + KIGFX::VIEW_CONTROLS* controls = getViewControls(); SETTINGS_MANAGER& settingsMgr = Pgm().GetSettingsManager(); SYMBOL_EDITOR_SETTINGS* settings = settingsMgr.GetAppSettings(); + EE_GRID_HELPER grid( m_toolMgr ); + VECTOR2I cursorPos; SHAPE_T shapeType = toolType == SHAPE_T::SEGMENT ? SHAPE_T::POLY : toolType; LIB_SYMBOL* symbol = m_frame->GetCurSymbol(); LIB_SHAPE* item = nullptr; @@ -387,7 +390,7 @@ int SYMBOL_EDITOR_DRAWING_TOOLS::doDrawShape( const TOOL_EVENT& aEvent, std::opt Activate(); // Must be done after Activate() so that it gets set into the correct context - getViewControls()->ShowCursor( true ); + controls->ShowCursor( true ); // Set initial cursor setCursor(); @@ -398,8 +401,11 @@ int SYMBOL_EDITOR_DRAWING_TOOLS::doDrawShape( const TOOL_EVENT& aEvent, std::opt while( TOOL_EVENT* evt = Wait() ) { setCursor(); + grid.SetSnap( !evt->Modifier( MD_SHIFT ) ); + grid.SetUseGrid( getView()->GetGAL()->GetGridSnapping() && !evt->DisableGridSnapping() ); - VECTOR2I cursorPos = getViewControls()->GetCursorPosition( !evt->DisableGridSnapping() ); + cursorPos = grid.Align( controls->GetMousePosition(), grid.GetItemGrid( item ) ); + controls->ForceCursorPosition( true, cursorPos ); // The tool hotkey is interpreted as a click when drawing bool isSyntheticClick = item && evt->IsActivate() && evt->HasPosition() @@ -567,12 +573,12 @@ int SYMBOL_EDITOR_DRAWING_TOOLS::doDrawShape( const TOOL_EVENT& aEvent, std::opt } // Enable autopanning and cursor capture only when there is a shape being drawn - getViewControls()->SetAutoPan( item != nullptr ); - getViewControls()->CaptureCursor( item != nullptr ); + controls->SetAutoPan( item != nullptr ); + controls->CaptureCursor( item != nullptr ); } - getViewControls()->SetAutoPan( false ); - getViewControls()->CaptureCursor( false ); + controls->SetAutoPan( false ); + controls->CaptureCursor( false ); m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::ARROW ); return 0; } diff --git a/eeschema/tools/symbol_editor_move_tool.cpp b/eeschema/tools/symbol_editor_move_tool.cpp index f76bc29e48..362bb30f07 100644 --- a/eeschema/tools/symbol_editor_move_tool.cpp +++ b/eeschema/tools/symbol_editor_move_tool.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -113,6 +114,7 @@ int SYMBOL_EDITOR_MOVE_TOOL::Main( const TOOL_EVENT& aEvent ) bool SYMBOL_EDITOR_MOVE_TOOL::doMoveSelection( const TOOL_EVENT& aEvent, SCH_COMMIT* aCommit ) { KIGFX::VIEW_CONTROLS* controls = getViewControls(); + EE_GRID_HELPER grid( m_toolMgr ); m_anchorPos = { 0, 0 }; @@ -155,6 +157,8 @@ bool SYMBOL_EDITOR_MOVE_TOOL::doMoveSelection( const TOOL_EVENT& aEvent, SCH_COM do { m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::MOVING ); + grid.SetSnap( !evt->Modifier( MD_SHIFT ) ); + grid.SetUseGrid( getView()->GetGAL()->GetGridSnapping() && !evt->DisableGridSnapping() ); if( evt->IsAction( &EE_ACTIONS::move ) || evt->IsMotion() @@ -234,7 +238,8 @@ bool SYMBOL_EDITOR_MOVE_TOOL::doMoveSelection( const TOOL_EVENT& aEvent, SCH_COM else if( m_frame->GetMoveWarpsCursor() ) { VECTOR2I itemPos = selection.GetTopLeftItem()->GetPosition(); - m_anchorPos = VECTOR2I( itemPos.x, -itemPos.y ); + m_anchorPos = grid.AlignGrid( VECTOR2I( itemPos.x, -itemPos.y ), + grid.GetSelectionGrid( selection ) ); getViewControls()->WarpMouseCursor( m_anchorPos, true, true ); m_cursor = m_anchorPos; @@ -255,7 +260,8 @@ bool SYMBOL_EDITOR_MOVE_TOOL::doMoveSelection( const TOOL_EVENT& aEvent, SCH_COM //------------------------------------------------------------------------ // Follow the mouse // - m_cursor = controls->GetCursorPosition( !evt->DisableGridSnapping() ); + m_cursor = grid.BestSnapAnchor( controls->GetCursorPosition( false ), + grid.GetSelectionGrid( selection ), selection ); VECTOR2I delta( m_cursor - prevPos ); m_anchorPos = m_cursor;