KiCad PCB EDA Suite
ee_point_editor.cpp File Reference
#include <functional>
#include "ee_point_editor.h"
#include <tool/tool_manager.h>
#include <view/view_controls.h>
#include <geometry/seg.h>
#include <tools/ee_actions.h>
#include <tools/ee_selection_tool.h>
#include <bitmaps.h>
#include <sch_edit_frame.h>
#include <sch_line.h>
#include <sch_bitmap.h>
#include <sch_sheet.h>
#include <sch_sheet_pin.h>
#include <symbol_edit_frame.h>
#include <lib_shape.h>

Go to the source code of this file.

Classes

class  EDIT_POINTS_FACTORY
 

Enumerations

enum  ARC_POINTS {
  ARC_CENTER, ARC_START, ARC_END, ARC_CENTER,
  ARC_START, ARC_MID, ARC_END
}
 
enum  CIRCLE_POINTS { CIRC_CENTER, CIRC_END, CIRC_CENTER, CIRC_END }
 
enum  RECTANGLE_POINTS {
  RECT_TOPLEFT, RECT_TOPRIGHT, RECT_BOTLEFT, RECT_BOTRIGHT,
  RECT_TOPLEFT, RECT_TOPRIGHT, RECT_BOTLEFT, RECT_BOTRIGHT
}
 
enum  LINE_POINTS { LINE_START, LINE_END, LINE_START, LINE_END }
 

Functions

static void pinEditedCorner (int aEditedPointIndex, int minWidth, int minHeight, VECTOR2I &topLeft, VECTOR2I &topRight, VECTOR2I &botLeft, VECTOR2I &botRight, int aGridSize=0)
 Update the coordinates of 4 corners of a rectangle, according to constraints and the moved corner. More...
 

Enumeration Type Documentation

◆ ARC_POINTS

enum ARC_POINTS
Enumerator
ARC_CENTER 
ARC_START 
ARC_END 
ARC_CENTER 
ARC_START 
ARC_MID 
ARC_END 

Definition at line 45 of file ee_point_editor.cpp.

◆ CIRCLE_POINTS

Enumerator
CIRC_CENTER 
CIRC_END 
CIRC_CENTER 
CIRC_END 

Definition at line 50 of file ee_point_editor.cpp.

◆ LINE_POINTS

Enumerator
LINE_START 
LINE_END 
LINE_START 
LINE_END 

Definition at line 60 of file ee_point_editor.cpp.

◆ RECTANGLE_POINTS

Enumerator
RECT_TOPLEFT 
RECT_TOPRIGHT 
RECT_BOTLEFT 
RECT_BOTRIGHT 
RECT_TOPLEFT 
RECT_TOPRIGHT 
RECT_BOTLEFT 
RECT_BOTRIGHT 

Definition at line 55 of file ee_point_editor.cpp.

Function Documentation

◆ pinEditedCorner()

static void pinEditedCorner ( int  aEditedPointIndex,
int  minWidth,
int  minHeight,
VECTOR2I topLeft,
VECTOR2I topRight,
VECTOR2I botLeft,
VECTOR2I botRight,
int  aGridSize = 0 
)
static

Update the coordinates of 4 corners of a rectangle, according to constraints and the moved corner.

Parameters
aEditedPointIndexis the corner id
minWidthis the minimal width constraint
minHeightis the minimal height constraint
topLeftis the RECT_TOPLEFT to constraint
topRightis the RECT_TOPRIGHT to constraint
botLeftis the RECT_BOTLEFT to constraint
botRightis the RECT_BOTRIGHT to constraint
aGridSizeis the a constraint: if > 1 new coordinates are on this grid

Definition at line 406 of file ee_point_editor.cpp.

410 {
411  auto alignToGrid =
412  [&]( const VECTOR2I& aPoint ) -> VECTOR2I
413  {
414  return VECTOR2I( KiROUND( aPoint.x / aGridSize ) * aGridSize,
415  KiROUND( aPoint.y / aGridSize ) * aGridSize );
416  };
417 
418  switch( aEditedPointIndex )
419  {
420  case RECT_TOPLEFT:
421  // pin edited point within opposite corner
422  topLeft.x = std::min( topLeft.x, botRight.x - minWidth );
423  topLeft.y = std::min( topLeft.y, botRight.y - minHeight );
424 
425  if( aGridSize > 1 ) // Keep point on specified grid size
426  topLeft = alignToGrid( topLeft );
427 
428  // push edited point edges to adjacent corners
429  topRight.y = topLeft.y;
430  botLeft.x = topLeft.x;
431 
432  break;
433 
434  case RECT_TOPRIGHT:
435  // pin edited point within opposite corner
436  topRight.x = std::max( topRight.x, botLeft.x + minWidth );
437  topRight.y = std::min( topRight.y, botLeft.y - minHeight );
438 
439  if( aGridSize > 1 ) // Keep point on specified grid size
440  topRight = alignToGrid( topRight );
441 
442  // push edited point edges to adjacent corners
443  topLeft.y = topRight.y;
444  botRight.x = topRight.x;
445 
446  break;
447 
448  case RECT_BOTLEFT:
449  // pin edited point within opposite corner
450  botLeft.x = std::min( botLeft.x, topRight.x - minWidth );
451  botLeft.y = std::max( botLeft.y, topRight.y + minHeight );
452 
453  if( aGridSize > 1 ) // Keep point on specified grid size
454  botLeft = alignToGrid( botLeft );
455 
456  // push edited point edges to adjacent corners
457  botRight.y = botLeft.y;
458  topLeft.x = botLeft.x;
459 
460  break;
461 
462  case RECT_BOTRIGHT:
463  // pin edited point within opposite corner
464  botRight.x = std::max( botRight.x, topLeft.x + minWidth );
465  botRight.y = std::max( botRight.y, topLeft.y + minHeight );
466 
467  if( aGridSize > 1 ) // Keep point on specified grid size
468  botRight = alignToGrid( botRight );
469 
470  // push edited point edges to adjacent corners
471  botLeft.y = botRight.y;
472  topRight.x = botRight.x;
473 
474  break;
475  }
476 }
VECTOR2< int > VECTOR2I
Definition: vector2d.h:623
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:73

References KiROUND(), RECT_BOTLEFT, RECT_BOTRIGHT, RECT_TOPLEFT, RECT_TOPRIGHT, VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by EE_POINT_EDITOR::updateParentItem().