PCB: start of grid overrides

Only works for moves.
This commit is contained in:
Mike Williams 2023-08-24 10:13:59 -04:00
parent 0f781f328e
commit d9c2e0ab54
17 changed files with 409 additions and 21 deletions

View File

@ -45,6 +45,8 @@ DIALOG_GRID_SETTINGS::DIALOG_GRID_SETTINGS( EDA_DRAW_FRAME* aParent ) :
m_GridOverrideConnectablesSize, m_staticTextConnectablesUnits ),
m_gridOverrideWires( aParent, m_staticTextWires, m_GridOverrideWiresSize,
m_staticTextWiresUnits ),
m_gridOverrideVias( aParent, m_staticTextVias, m_GridOverrideViasSize,
m_staticTextViasUnits ),
m_gridOverrideText( aParent, m_staticTextText, m_GridOverrideTextSize,
m_staticTextTextUnits ),
m_gridOverrideGraphics( aParent, m_staticTextGraphics, m_GridOverrideGraphicsSize,
@ -65,10 +67,17 @@ DIALOG_GRID_SETTINGS::DIALOG_GRID_SETTINGS( EDA_DRAW_FRAME* aParent ) :
// Eeschema and friends don't use grid origin
m_buttonResetOrigin->Hide();
sbGridOriginSizer->ShowItems( false );
// No vias in the schematics
m_checkGridOverrideVias->Hide();
m_staticTextVias->Hide();
m_GridOverrideViasSize->Hide();
m_staticTextViasUnits->Hide();
}
else
{
sbGridOverridesSizer->ShowItems( false );
m_staticTextConnectables->SetLabel( wxT( "Footprints/Pads:" ) );
m_staticTextWires->SetLabel( wxT( "Tracks:" ) );
}
int hk1 = ACTIONS::gridFast1.GetHotKey();
@ -129,7 +138,7 @@ bool DIALOG_GRID_SETTINGS::TransferDataFromWindow()
// Validate new settings
for( UNIT_BINDER* entry :
{ &m_userGridX, &m_userGridY, &m_gridOverrideConnectables, &m_gridOverrideWires,
&m_gridOverrideText, &m_gridOverrideGraphics } )
&m_gridOverrideVias, &m_gridOverrideText, &m_gridOverrideGraphics } )
{
if( !entry->Validate( 0.001, 1000.0, EDA_UNITS::MILLIMETRES ) )
return false;
@ -151,6 +160,8 @@ bool DIALOG_GRID_SETTINGS::TransferDataFromWindow()
m_parent->StringFromValue( m_gridOverrideConnectables.GetValue(), true );
gridCfg.override_wires = m_checkGridOverrideWires->GetValue();
gridCfg.override_wires_size = m_parent->StringFromValue( m_gridOverrideWires.GetValue(), true );
gridCfg.override_vias = m_checkGridOverrideVias->GetValue();
gridCfg.override_vias_size = m_parent->StringFromValue( m_gridOverrideVias.GetValue(), true );
gridCfg.override_text = m_checkGridOverrideText->GetValue();
gridCfg.override_text_size = m_parent->StringFromValue( m_gridOverrideText.GetValue(), true );
gridCfg.override_graphics = m_checkGridOverrideGraphics->GetValue();
@ -187,11 +198,13 @@ bool DIALOG_GRID_SETTINGS::TransferDataToWindow()
m_gridOverrideConnectables.SetValue(
m_parent->ValueFromString( gridCfg.override_connectables_size ) );
m_gridOverrideWires.SetValue( m_parent->ValueFromString( gridCfg.override_wires_size ) );
m_gridOverrideVias.SetValue( m_parent->ValueFromString( gridCfg.override_vias_size ) );
m_gridOverrideText.SetValue( m_parent->ValueFromString( gridCfg.override_text_size ) );
m_gridOverrideGraphics.SetValue( m_parent->ValueFromString( gridCfg.override_graphics_size ) );
m_checkGridOverrideConnectables->SetValue( gridCfg.override_connectables );
m_checkGridOverrideWires->SetValue( gridCfg.override_wires );
m_checkGridOverrideVias->SetValue( gridCfg.override_vias );
m_checkGridOverrideText->SetValue( gridCfg.override_text );
m_checkGridOverrideGraphics->SetValue( gridCfg.override_graphics );

View File

@ -156,7 +156,7 @@ DIALOG_GRID_SETTINGS_BASE::DIALOG_GRID_SETTINGS_BASE( wxWindow* parent, wxWindow
sbGridOverridesSizer = new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY, _("Grid Overrides") ), wxVERTICAL );
wxFlexGridSizer* fgGridOverrides;
fgGridOverrides = new wxFlexGridSizer( 4, 4, 0, 0 );
fgGridOverrides = new wxFlexGridSizer( 0, 4, 0, 0 );
fgGridOverrides->AddGrowableCol( 2 );
fgGridOverrides->SetFlexibleDirection( wxBOTH );
fgGridOverrides->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED );
@ -189,6 +189,20 @@ DIALOG_GRID_SETTINGS_BASE::DIALOG_GRID_SETTINGS_BASE( wxWindow* parent, wxWindow
m_staticTextWiresUnits->Wrap( -1 );
fgGridOverrides->Add( m_staticTextWiresUnits, 0, wxALIGN_CENTER_VERTICAL|wxALIGN_LEFT|wxRIGHT, 5 );
m_checkGridOverrideVias = new wxCheckBox( sbGridOverridesSizer->GetStaticBox(), wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
fgGridOverrides->Add( m_checkGridOverrideVias, 0, wxALIGN_CENTER|wxALIGN_CENTER_HORIZONTAL|wxALL|wxLEFT|wxRIGHT, 5 );
m_staticTextVias = new wxStaticText( sbGridOverridesSizer->GetStaticBox(), wxID_ANY, _("Vias:"), wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT );
m_staticTextVias->Wrap( -1 );
fgGridOverrides->Add( m_staticTextVias, 0, wxALIGN_CENTER_VERTICAL, 5 );
m_GridOverrideViasSize = new wxTextCtrl( sbGridOverridesSizer->GetStaticBox(), wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
fgGridOverrides->Add( m_GridOverrideViasSize, 0, wxBOTTOM|wxEXPAND|wxLEFT|wxRIGHT, 5 );
m_staticTextViasUnits = new wxStaticText( sbGridOverridesSizer->GetStaticBox(), wxID_ANY, _("mm"), wxDefaultPosition, wxDefaultSize, 0 );
m_staticTextViasUnits->Wrap( -1 );
fgGridOverrides->Add( m_staticTextViasUnits, 0, wxALIGN_CENTER_VERTICAL|wxALIGN_LEFT|wxRIGHT, 5 );
m_checkGridOverrideText = new wxCheckBox( sbGridOverridesSizer->GetStaticBox(), wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
fgGridOverrides->Add( m_checkGridOverrideText, 0, wxALIGN_CENTER|wxALL|wxLEFT|wxRIGHT, 5 );

View File

@ -1515,7 +1515,7 @@
<property name="border">10</property>
<property name="flag">wxALL|wxEXPAND</property>
<property name="proportion">0</property>
<object class="wxStaticBoxSizer" expanded="0">
<object class="wxStaticBoxSizer" expanded="1">
<property name="id">wxID_ANY</property>
<property name="label">Grid Overrides</property>
<property name="minimum_size"></property>
@ -1523,11 +1523,11 @@
<property name="orient">wxVERTICAL</property>
<property name="parent">1</property>
<property name="permission">protected</property>
<object class="sizeritem" expanded="0">
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxBOTTOM|wxEXPAND</property>
<property name="proportion">1</property>
<object class="wxFlexGridSizer" expanded="0">
<object class="wxFlexGridSizer" expanded="1">
<property name="cols">4</property>
<property name="flexible_direction">wxBOTH</property>
<property name="growablecols">2</property>
@ -1537,7 +1537,7 @@
<property name="name">fgGridOverrides</property>
<property name="non_flexible_grow_mode">wxFLEX_GROWMODE_SPECIFIED</property>
<property name="permission">none</property>
<property name="rows">4</property>
<property name="rows">0</property>
<property name="vgap">0</property>
<object class="sizeritem" expanded="0">
<property name="border">10</property>
@ -2039,6 +2039,256 @@
<property name="wrap">-1</property>
</object>
</object>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxALIGN_CENTER|wxALIGN_CENTER_HORIZONTAL|wxALL|wxLEFT|wxRIGHT</property>
<property name="proportion">0</property>
<object class="wxCheckBox" expanded="1">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
<property name="TopDockable">1</property>
<property name="aui_layer"></property>
<property name="aui_name"></property>
<property name="aui_position"></property>
<property name="aui_row"></property>
<property name="best_size"></property>
<property name="bg"></property>
<property name="caption"></property>
<property name="caption_visible">1</property>
<property name="center_pane">0</property>
<property name="checked">0</property>
<property name="close_button">1</property>
<property name="context_help"></property>
<property name="context_menu">1</property>
<property name="default_pane">0</property>
<property name="dock">Dock</property>
<property name="dock_fixed">0</property>
<property name="docking">Left</property>
<property name="enabled">1</property>
<property name="fg"></property>
<property name="floatable">1</property>
<property name="font"></property>
<property name="gripper">0</property>
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="label"></property>
<property name="max_size"></property>
<property name="maximize_button">0</property>
<property name="maximum_size"></property>
<property name="min_size"></property>
<property name="minimize_button">0</property>
<property name="minimum_size"></property>
<property name="moveable">1</property>
<property name="name">m_checkGridOverrideVias</property>
<property name="pane_border">1</property>
<property name="pane_position"></property>
<property name="pane_size"></property>
<property name="permission">protected</property>
<property name="pin_button">1</property>
<property name="pos"></property>
<property name="resize">Resizable</property>
<property name="show">1</property>
<property name="size"></property>
<property name="style"></property>
<property name="subclass">; ; forward_declare</property>
<property name="toolbar_pane">0</property>
<property name="tooltip"></property>
<property name="validator_data_type"></property>
<property name="validator_style">wxFILTER_NONE</property>
<property name="validator_type">wxDefaultValidator</property>
<property name="validator_variable"></property>
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style"></property>
</object>
</object>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxALIGN_CENTER_VERTICAL</property>
<property name="proportion">0</property>
<object class="wxStaticText" expanded="1">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
<property name="TopDockable">1</property>
<property name="aui_layer"></property>
<property name="aui_name"></property>
<property name="aui_position"></property>
<property name="aui_row"></property>
<property name="best_size"></property>
<property name="bg"></property>
<property name="caption"></property>
<property name="caption_visible">1</property>
<property name="center_pane">0</property>
<property name="close_button">1</property>
<property name="context_help"></property>
<property name="context_menu">1</property>
<property name="default_pane">0</property>
<property name="dock">Dock</property>
<property name="dock_fixed">0</property>
<property name="docking">Left</property>
<property name="enabled">1</property>
<property name="fg"></property>
<property name="floatable">1</property>
<property name="font"></property>
<property name="gripper">0</property>
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="label">Vias:</property>
<property name="markup">0</property>
<property name="max_size"></property>
<property name="maximize_button">0</property>
<property name="maximum_size"></property>
<property name="min_size"></property>
<property name="minimize_button">0</property>
<property name="minimum_size"></property>
<property name="moveable">1</property>
<property name="name">m_staticTextVias</property>
<property name="pane_border">1</property>
<property name="pane_position"></property>
<property name="pane_size"></property>
<property name="permission">protected</property>
<property name="pin_button">1</property>
<property name="pos"></property>
<property name="resize">Resizable</property>
<property name="show">1</property>
<property name="size"></property>
<property name="style">wxALIGN_LEFT</property>
<property name="subclass">; ; forward_declare</property>
<property name="toolbar_pane">0</property>
<property name="tooltip"></property>
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style"></property>
<property name="wrap">-1</property>
</object>
</object>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxBOTTOM|wxEXPAND|wxLEFT|wxRIGHT</property>
<property name="proportion">0</property>
<object class="wxTextCtrl" expanded="1">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
<property name="TopDockable">1</property>
<property name="aui_layer"></property>
<property name="aui_name"></property>
<property name="aui_position"></property>
<property name="aui_row"></property>
<property name="best_size"></property>
<property name="bg"></property>
<property name="caption"></property>
<property name="caption_visible">1</property>
<property name="center_pane">0</property>
<property name="close_button">1</property>
<property name="context_help"></property>
<property name="context_menu">1</property>
<property name="default_pane">0</property>
<property name="dock">Dock</property>
<property name="dock_fixed">0</property>
<property name="docking">Left</property>
<property name="enabled">1</property>
<property name="fg"></property>
<property name="floatable">1</property>
<property name="font"></property>
<property name="gripper">0</property>
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="max_size"></property>
<property name="maximize_button">0</property>
<property name="maximum_size"></property>
<property name="maxlength">0</property>
<property name="min_size"></property>
<property name="minimize_button">0</property>
<property name="minimum_size"></property>
<property name="moveable">1</property>
<property name="name">m_GridOverrideViasSize</property>
<property name="pane_border">1</property>
<property name="pane_position"></property>
<property name="pane_size"></property>
<property name="permission">protected</property>
<property name="pin_button">1</property>
<property name="pos"></property>
<property name="resize">Resizable</property>
<property name="show">1</property>
<property name="size"></property>
<property name="style"></property>
<property name="subclass"></property>
<property name="toolbar_pane">0</property>
<property name="tooltip"></property>
<property name="validator_data_type"></property>
<property name="validator_style">wxFILTER_NONE</property>
<property name="validator_type">wxDefaultValidator</property>
<property name="validator_variable"></property>
<property name="value"></property>
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style"></property>
</object>
</object>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxALIGN_CENTER_VERTICAL|wxALIGN_LEFT|wxRIGHT</property>
<property name="proportion">0</property>
<object class="wxStaticText" expanded="1">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
<property name="TopDockable">1</property>
<property name="aui_layer"></property>
<property name="aui_name"></property>
<property name="aui_position"></property>
<property name="aui_row"></property>
<property name="best_size"></property>
<property name="bg"></property>
<property name="caption"></property>
<property name="caption_visible">1</property>
<property name="center_pane">0</property>
<property name="close_button">1</property>
<property name="context_help"></property>
<property name="context_menu">1</property>
<property name="default_pane">0</property>
<property name="dock">Dock</property>
<property name="dock_fixed">0</property>
<property name="docking">Left</property>
<property name="enabled">1</property>
<property name="fg"></property>
<property name="floatable">1</property>
<property name="font"></property>
<property name="gripper">0</property>
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="label">mm</property>
<property name="markup">0</property>
<property name="max_size"></property>
<property name="maximize_button">0</property>
<property name="maximum_size"></property>
<property name="min_size"></property>
<property name="minimize_button">0</property>
<property name="minimum_size"></property>
<property name="moveable">1</property>
<property name="name">m_staticTextViasUnits</property>
<property name="pane_border">1</property>
<property name="pane_position"></property>
<property name="pane_size"></property>
<property name="permission">protected</property>
<property name="pin_button">1</property>
<property name="pos"></property>
<property name="resize">Resizable</property>
<property name="show">1</property>
<property name="size"></property>
<property name="style"></property>
<property name="subclass">; ; forward_declare</property>
<property name="toolbar_pane">0</property>
<property name="tooltip"></property>
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style"></property>
<property name="wrap">-1</property>
</object>
</object>
<object class="sizeritem" expanded="0">
<property name="border">5</property>
<property name="flag">wxALIGN_CENTER|wxALL|wxLEFT|wxRIGHT</property>

View File

@ -71,6 +71,10 @@ class DIALOG_GRID_SETTINGS_BASE : public DIALOG_SHIM
wxStaticText* m_staticTextWires;
wxTextCtrl* m_GridOverrideWiresSize;
wxStaticText* m_staticTextWiresUnits;
wxCheckBox* m_checkGridOverrideVias;
wxStaticText* m_staticTextVias;
wxTextCtrl* m_GridOverrideViasSize;
wxStaticText* m_staticTextViasUnits;
wxCheckBox* m_checkGridOverrideText;
wxStaticText* m_staticTextText;
wxTextCtrl* m_GridOverrideTextSize;

View File

@ -385,15 +385,18 @@ void APP_SETTINGS_BASE::addParamsForWindow( WINDOW_SETTINGS* aWindow, const std:
m_params.emplace_back( new PARAM<wxString>( aJsonPath + ".grid.override_connectables_size",
&aWindow->grid.override_connectables_size,
"100 mil" ) );
"0.25 mm" ) );
m_params.emplace_back( new PARAM<wxString>( aJsonPath + ".grid.override_text_size",
&aWindow->grid.override_text_size, "10 mil" ) );
&aWindow->grid.override_text_size, ".05 mm" ) );
m_params.emplace_back( new PARAM<wxString>( aJsonPath + ".grid.override_wires_size",
&aWindow->grid.override_wires_size,
"10 mil" ) );
"0.05 mm" ) );
m_params.emplace_back( new PARAM<wxString>( aJsonPath + ".grid.override_vias_size",
&aWindow->grid.override_vias_size,
"0.1 mm" ) );
m_params.emplace_back( new PARAM<wxString>( aJsonPath + ".grid.override_graphics_size",
&aWindow->grid.override_graphics_size,
"10 mil" ) );
"1 mm" ) );
}

View File

@ -279,7 +279,7 @@ VECTOR2D EE_GRID_HELPER::GetGridSize( GRID_HELPER_GRIDS aGrid ) const
grid.override_graphics_size );
break;
case GRID_CURRENT:
default:
break;
}

View File

@ -52,6 +52,7 @@ private:
UNIT_BINDER m_userGridY;
UNIT_BINDER m_gridOverrideConnectables;
UNIT_BINDER m_gridOverrideWires;
UNIT_BINDER m_gridOverrideVias;
UNIT_BINDER m_gridOverrideText;
UNIT_BINDER m_gridOverrideGraphics;
};

View File

@ -67,6 +67,8 @@ struct GRID_SETTINGS
wxString override_connectables_size;
bool override_wires;
wxString override_wires_size;
bool override_vias;
wxString override_vias_size;
bool override_text;
wxString override_text_size;
bool override_graphics;

View File

@ -40,6 +40,7 @@ enum GRID_HELPER_GRIDS : int
GRID_CONNECTABLE,
GRID_WIRES,
GRID_VIAS,
GRID_TEXT,
GRID_GRAPHICS
};

View File

@ -1158,6 +1158,7 @@ void FOOTPRINT_EDIT_FRAME::setupUIConditions()
mgr->SetConditions( ACTIONS::redo, ENABLE( cond.RedoAvailable() ) );
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 ) ) );

View File

@ -701,6 +701,7 @@ void PCB_EDIT_FRAME::setupUIConditions()
mgr->SetConditions( ACTIONS::redo, ENABLE( cond.RedoAvailable() ) );
mgr->SetConditions( ACTIONS::toggleGrid, CHECK( cond.GridVisible() ) );
mgr->SetConditions( ACTIONS::toggleGridOverrides, CHECK( cond.GridOverrides() ) );
mgr->SetConditions( ACTIONS::toggleCursorStyle, CHECK( cond.FullscreenCursor() ) );
mgr->SetConditions( ACTIONS::togglePolarCoords, CHECK( cond.PolarCoordinates() ) );
mgr->SetConditions( ACTIONS::millimetersUnits, CHECK( cond.Units( EDA_UNITS::MILLIMETRES ) ) );

View File

@ -228,6 +228,7 @@ void FOOTPRINT_EDIT_FRAME::ReCreateOptToolbar()
}
m_optionsToolBar->Add( ACTIONS::toggleGrid, ACTION_TOOLBAR::TOGGLE );
m_optionsToolBar->Add( ACTIONS::toggleGridOverrides, ACTION_TOOLBAR::TOGGLE );
m_optionsToolBar->Add( PCB_ACTIONS::togglePolarCoords, ACTION_TOOLBAR::TOGGLE );
m_optionsToolBar->Add( ACTIONS::inchesUnits, ACTION_TOOLBAR::TOGGLE );
m_optionsToolBar->Add( ACTIONS::milsUnits, ACTION_TOOLBAR::TOGGLE );

View File

@ -316,6 +316,7 @@ void PCB_EDIT_FRAME::ReCreateOptToolbar()
}
m_optionsToolBar->Add( ACTIONS::toggleGrid, ACTION_TOOLBAR::TOGGLE );
m_optionsToolBar->Add( ACTIONS::toggleGridOverrides, ACTION_TOOLBAR::TOGGLE );
m_optionsToolBar->Add( PCB_ACTIONS::togglePolarCoords, ACTION_TOOLBAR::TOGGLE );
m_optionsToolBar->Add( ACTIONS::inchesUnits, ACTION_TOOLBAR::TOGGLE );

View File

@ -475,7 +475,8 @@ bool EDIT_TOOL::doMoveSelection( const TOOL_EVENT& aEvent, BOARD_COMMIT* aCommit
VECTOR2I mousePos( controls->GetMousePosition() );
m_cursor = grid.BestSnapAnchor( mousePos, item_layers, sel_items );
m_cursor = grid.BestSnapAnchor( mousePos, item_layers,
grid.GetSelectionGrid( selection ), sel_items );
if( controls->GetSettings().m_lastKeyboardCursorPositionValid )
{
@ -620,6 +621,7 @@ bool EDIT_TOOL::doMoveSelection( const TOOL_EVENT& aEvent, BOARD_COMMIT* aCommit
}
m_cursor = grid.BestDragOrigin( originalCursorPos, sel_items,
grid.GetSelectionGrid( selection ),
&m_selectionTool->GetFilter() );
// Set the current cursor position to the first dragged item origin, so the

View File

@ -211,6 +211,7 @@ VECTOR2I PCB_GRID_HELPER::AlignToNearestPad( const VECTOR2I& aMousePos, PADS& aP
VECTOR2I PCB_GRID_HELPER::BestDragOrigin( const VECTOR2I &aMousePos,
std::vector<BOARD_ITEM*>& aItems,
GRID_HELPER_GRIDS aGrid,
const SELECTION_FILTER_OPTIONS* aSelectionFilter )
{
clearAnchors();
@ -256,7 +257,8 @@ VECTOR2I PCB_GRID_HELPER::BestDragOrigin( const VECTOR2I &aMousePos,
}
VECTOR2I PCB_GRID_HELPER::BestSnapAnchor( const VECTOR2I& aOrigin, BOARD_ITEM* aReferenceItem )
VECTOR2I PCB_GRID_HELPER::BestSnapAnchor( const VECTOR2I& aOrigin, BOARD_ITEM* aReferenceItem,
GRID_HELPER_GRIDS aGrid )
{
LSET layers;
std::vector<BOARD_ITEM*> item;
@ -271,11 +273,12 @@ VECTOR2I PCB_GRID_HELPER::BestSnapAnchor( const VECTOR2I& aOrigin, BOARD_ITEM* a
layers = LSET::AllLayersMask();
}
return BestSnapAnchor( aOrigin, layers, item );
return BestSnapAnchor( aOrigin, layers, aGrid, item );
}
VECTOR2I PCB_GRID_HELPER::BestSnapAnchor( const VECTOR2I& aOrigin, const LSET& aLayers,
GRID_HELPER_GRIDS aGrid,
const std::vector<BOARD_ITEM*>& aSkip )
{
// Tuning constant: snap radius in screen space
@ -303,7 +306,7 @@ VECTOR2I PCB_GRID_HELPER::BestSnapAnchor( const VECTOR2I& aOrigin, const LSET& a
computeAnchors( item, aOrigin );
ANCHOR* nearest = nearestAnchor( aOrigin, SNAPPABLE, aLayers );
VECTOR2I nearestGrid = Align( aOrigin );
VECTOR2I nearestGrid = Align( aOrigin, aGrid );
if( nearest )
snapDist = nearest->Distance( aOrigin );
@ -375,6 +378,88 @@ BOARD_ITEM* PCB_GRID_HELPER::GetSnapped() const
}
GRID_HELPER_GRIDS PCB_GRID_HELPER::GetItemGrid( const EDA_ITEM* aItem ) const
{
if( !aItem )
return GRID_CURRENT;
switch( aItem->Type() )
{
case PCB_FOOTPRINT_T:
case PCB_PAD_T:
return GRID_CONNECTABLE;
case PCB_TEXT_T:
case PCB_FIELD_T:
return GRID_TEXT;
case PCB_SHAPE_T:
case PCB_DIMENSION_T:
case PCB_BITMAP_T:
case PCB_TEXTBOX_T:
return GRID_GRAPHICS;
case PCB_TRACE_T:
case PCB_ARC_T:
return GRID_WIRES;
case PCB_VIA_T:
return GRID_VIAS;
default:
return GRID_CURRENT;
}
}
VECTOR2D PCB_GRID_HELPER::GetGridSize( GRID_HELPER_GRIDS aGrid ) const
{
const GRID_SETTINGS& grid = m_toolMgr->GetSettings()->m_Window.grid;
VECTOR2D g = m_toolMgr->GetView()->GetGAL()->GetGridSize();
if( !grid.overrides_enabled )
return g;
switch( aGrid )
{
case GRID_CONNECTABLE:
if( grid.override_connectables )
g.x = g.y = EDA_UNIT_UTILS::UI::DoubleValueFromString(
pcbIUScale, EDA_UNITS::MILLIMETRES, grid.override_connectables_size );
break;
case GRID_WIRES:
if( grid.override_wires )
g.x = g.y = EDA_UNIT_UTILS::UI::DoubleValueFromString( pcbIUScale, EDA_UNITS::MILLIMETRES,
grid.override_wires_size );
break;
case GRID_VIAS:
if( grid.override_vias )
g.x = g.y = EDA_UNIT_UTILS::UI::DoubleValueFromString( pcbIUScale, EDA_UNITS::MILLIMETRES,
grid.override_vias_size );
break;
case GRID_TEXT:
if( grid.override_text )
g.x = g.y = EDA_UNIT_UTILS::UI::DoubleValueFromString( pcbIUScale, EDA_UNITS::MILLIMETRES,
grid.override_text_size );
break;
case GRID_GRAPHICS:
if( grid.override_graphics )
g.x = g.y = EDA_UNIT_UTILS::UI::DoubleValueFromString( pcbIUScale, EDA_UNITS::MILLIMETRES,
grid.override_graphics_size );
break;
default:
break;
}
return g;
}
std::set<BOARD_ITEM*> PCB_GRID_HELPER::queryVisible( const BOX2I& aArea,
const std::vector<BOARD_ITEM*>& aSkip ) const
{

View File

@ -55,6 +55,7 @@ public:
VECTOR2I AlignToSegment ( const VECTOR2I& aPoint, const SEG& aSeg );
VECTOR2I BestDragOrigin( const VECTOR2I& aMousePos, std::vector<BOARD_ITEM*>& aItem,
GRID_HELPER_GRIDS aGrid = GRID_HELPER_GRIDS::GRID_CURRENT,
const SELECTION_FILTER_OPTIONS* aSelectionFilter = nullptr );
VECTOR2I AlignToArc ( const VECTOR2I& aPoint, const SHAPE_ARC& aSeg );
@ -69,10 +70,17 @@ public:
* @param aReferenceItem Reference item for layer/type special casing
* @return snapped screen point
*/
VECTOR2I BestSnapAnchor( const VECTOR2I& aOrigin, BOARD_ITEM* aReferenceItem );
VECTOR2I BestSnapAnchor( const VECTOR2I& aOrigin, BOARD_ITEM* aReferenceItem,
GRID_HELPER_GRIDS aGrid = GRID_HELPER_GRIDS::GRID_CURRENT );
VECTOR2I BestSnapAnchor( const VECTOR2I& aOrigin, const LSET& aLayers,
GRID_HELPER_GRIDS aGrid = GRID_HELPER_GRIDS::GRID_CURRENT,
const std::vector<BOARD_ITEM*>& aSkip = {} );
GRID_HELPER_GRIDS GetItemGrid( const EDA_ITEM* aItem ) const override;
VECTOR2D GetGridSize( GRID_HELPER_GRIDS aGrid ) const override;
private:
std::set<BOARD_ITEM*> queryVisible( const BOX2I& aArea,
const std::vector<BOARD_ITEM*>& aSkip ) const;

View File

@ -558,11 +558,11 @@ int PCB_POINT_EDITOR::OnSelectionChange( const TOOL_EVENT& aEvent )
{
if( grid.GetUseGrid() )
{
VECTOR2I gridPt = grid.BestSnapAnchor( pos, {}, { item } );
VECTOR2I gridPt = grid.BestSnapAnchor( pos, {}, grid.GetItemGrid( item ), { item } );
VECTOR2I last = m_editedPoint->GetPosition();
VECTOR2I delta = pos - last;
VECTOR2I deltaGrid = gridPt - grid.BestSnapAnchor( last, {}, { item } );
VECTOR2I deltaGrid = gridPt - grid.BestSnapAnchor( last, {}, grid.GetItemGrid( item ), { item } );
if( abs( delta.x ) > grid.GetGrid().x / 2 )
pos.x = last.x + deltaGrid.x;
@ -589,8 +589,9 @@ int PCB_POINT_EDITOR::OnSelectionChange( const TOOL_EVENT& aEvent )
}
else if( m_editedPoint->GetGridConstraint() == SNAP_TO_GRID )
{
m_editedPoint->SetPosition( grid.BestSnapAnchor( m_editedPoint->GetPosition(),
snapLayers, { item } ) );
m_editedPoint->SetPosition(
grid.BestSnapAnchor( m_editedPoint->GetPosition(), snapLayers,
grid.GetItemGrid( item ), { item } ) );
}
updateItem();