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_arc.h>
#include <lib_circle.h>
#include <lib_rectangle.h>
#include <lib_polyline.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, accordint 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 48 of file ee_point_editor.cpp.

◆ CIRCLE_POINTS

Enumerator
CIRC_CENTER 
CIRC_END 
CIRC_CENTER 
CIRC_END 

Definition at line 53 of file ee_point_editor.cpp.

◆ LINE_POINTS

Enumerator
LINE_START 
LINE_END 
LINE_START 
LINE_END 

Definition at line 63 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 58 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, accordint 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 389 of file ee_point_editor.cpp.

393 {
394  auto alignToGrid =
395  [&]( const VECTOR2I& aPoint ) -> VECTOR2I
396  {
397  return VECTOR2I( KiROUND( aPoint.x / aGridSize ) * aGridSize,
398  KiROUND( aPoint.y / aGridSize ) * aGridSize );
399  };
400 
401  switch( aEditedPointIndex )
402  {
403  case RECT_TOPLEFT:
404  // pin edited point within opposite corner
405  topLeft.x = std::min( topLeft.x, botRight.x - minWidth );
406  topLeft.y = std::min( topLeft.y, botRight.y - minHeight );
407 
408  if( aGridSize > 1 ) // Keep point on specified grid size
409  topLeft = alignToGrid( topLeft );
410 
411  // push edited point edges to adjacent corners
412  topRight.y = topLeft.y;
413  botLeft.x = topLeft.x;
414 
415  break;
416 
417  case RECT_TOPRIGHT:
418  // pin edited point within opposite corner
419  topRight.x = std::max( topRight.x, botLeft.x + minWidth );
420  topRight.y = std::min( topRight.y, botLeft.y - minHeight );
421 
422  if( aGridSize > 1 ) // Keep point on specified grid size
423  topRight = alignToGrid( topRight );
424 
425  // push edited point edges to adjacent corners
426  topLeft.y = topRight.y;
427  botRight.x = topRight.x;
428 
429  break;
430 
431  case RECT_BOTLEFT:
432  // pin edited point within opposite corner
433  botLeft.x = std::min( botLeft.x, topRight.x - minWidth );
434  botLeft.y = std::max( botLeft.y, topRight.y + minHeight );
435 
436  if( aGridSize > 1 ) // Keep point on specified grid size
437  botLeft = alignToGrid( botLeft );
438 
439  // push edited point edges to adjacent corners
440  botRight.y = botLeft.y;
441  topLeft.x = botLeft.x;
442 
443  break;
444 
445  case RECT_BOTRIGHT:
446  // pin edited point within opposite corner
447  botRight.x = std::max( botRight.x, topLeft.x + minWidth );
448  botRight.y = std::max( botRight.y, topLeft.y + minHeight );
449 
450  if( aGridSize > 1 ) // Keep point on specified grid size
451  botRight = alignToGrid( botRight );
452 
453  // push edited point edges to adjacent corners
454  botLeft.y = botRight.y;
455  topRight.x = botRight.x;
456 
457  break;
458  }
459 }
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:68

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

Referenced by EE_POINT_EDITOR::updateParentItem().