Symbol Editor: support grid overrides
This commit is contained in:
parent
6166a96b8e
commit
a44dd4d88f
|
@ -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 ) ) );
|
||||
|
|
|
@ -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 );
|
||||
|
|
|
@ -336,12 +336,12 @@ std::set<SCH_ITEM*> 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<const SCH_ITEM*>( 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<SCH_ITEM*>( 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<const SCH_LINE*>( aItem )->IsConnectable() )
|
||||
return GRID_WIRES;
|
||||
else
|
||||
return GRID_GRAPHICS;
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
#include <ee_selection.h>
|
||||
|
||||
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 = {} );
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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<SYMBOL_EDITOR_SETTINGS>();
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#include <tool/tool_manager.h>
|
||||
#include <tools/ee_selection_tool.h>
|
||||
#include <ee_actions.h>
|
||||
#include <ee_grid_helper.h>
|
||||
#include <eda_item.h>
|
||||
#include <sch_commit.h>
|
||||
#include <wx/log.h>
|
||||
|
@ -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;
|
||||
|
||||
|
|
Loading…
Reference in New Issue