KiCad PCB EDA Suite
common_tools.cpp File Reference
#include <bitmaps.h>
#include <tool/actions.h>
#include <tool/tool_manager.h>
#include <eda_draw_frame.h>
#include <class_draw_panel_gal.h>
#include <view/view.h>
#include <view/view_controls.h>
#include <gal/graphics_abstraction_layer.h>
#include <base_screen.h>
#include <tool/common_tools.h>
#include <id.h>
#include <project.h>
#include <kiface_i.h>
#include <dialog_configure_paths.h>

Go to the source code of this file.

Functions

static OPT< int > getNextPreviousGrid (const BASE_SCREEN &aScreen, int aOffset)
 Advance a BASE_SCREEN's grid forwards or backwards by the given offset and return the cmd ID of that grid (doesn't change the grid). More...
 

Function Documentation

◆ getNextPreviousGrid()

static OPT<int> getNextPreviousGrid ( const BASE_SCREEN aScreen,
int  aOffset 
)
static

Advance a BASE_SCREEN's grid forwards or backwards by the given offset and return the cmd ID of that grid (doesn't change the grid).

This works even if the base screen's grid do not have consecutive command IDs.

Parameters
aScreenthe base screen to use
aOffsethow many grids to advance by (negative to go backwards)
Returns
the cmd ID of the requested grid, or empty if it can't be found

Definition at line 349 of file common_tools.cpp.

350 {
351  const GRIDS& grids = aScreen.GetGrids();
352  const GRID_TYPE& currGrid = aScreen.GetGrid();
353 
354  auto iter = std::find_if( grids.begin(), grids.end(),
355  [&]( const GRID_TYPE& aCandidate ) { return aCandidate.m_CmdId == currGrid.m_CmdId; } );
356 
357  wxCHECK_MSG( iter != grids.end(), {}, "Grid not found in screen's grid list" );
358 
359  int index = std::distance( grids.begin(), iter ) + aOffset;
360 
361  // If we go off the end, return invalid, but we could also wrap around if wanted.
362  if( index < 0 || static_cast<size_t>( index ) >= grids.size() )
363  return {};
364 
365  return grids[index].m_CmdId;
366 }
const GRID_TYPE & GetGrid() const
Return the grid object of the currently selected grid.
Definition: base_screen.h:286
std::vector< GRID_TYPE > GRIDS
Definition: base_screen.h:67
const GRIDS & GetGrids() const
Function GetGrids().
Definition: base_screen.h:339
GRID_TYPE is for grid arrays.
Definition: base_screen.h:43
static float distance(const SFVEC2UI &a, const SFVEC2UI &b)
int m_CmdId
Definition: base_screen.h:46

References distance(), BASE_SCREEN::GetGrid(), BASE_SCREEN::GetGrids(), and GRID_TYPE::m_CmdId.

Referenced by COMMON_TOOLS::GridNext(), and COMMON_TOOLS::GridPrev().