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 <lib_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
 

Macros

#define MOVE_TO_GRID(z)
 

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...
 

Macro Definition Documentation

◆ MOVE_TO_GRID

#define MOVE_TO_GRID (   z)
Value:
{ z.x = ( (z.x +1 ) / aGridSize ) * aGridSize;\
z.y = ( (z.y +1 ) / aGridSize ) * aGridSize; }

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 47 of file ee_point_editor.cpp.

◆ CIRCLE_POINTS

Enumerator
CIRC_CENTER 
CIRC_END 
CIRC_CENTER 
CIRC_END 

Definition at line 52 of file ee_point_editor.cpp.

◆ LINE_POINTS

Enumerator
LINE_START 
LINE_END 
LINE_START 
LINE_END 

Definition at line 62 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 57 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 386 of file ee_point_editor.cpp.

390 {
391  // A macro to keep a coordinate on the grid:
392  #define MOVE_TO_GRID(z) { z.x = ( (z.x +1 ) / aGridSize ) * aGridSize;\
393  z.y = ( (z.y +1 ) / aGridSize ) * aGridSize; }
394  switch( aEditedPointIndex )
395  {
396  case RECT_TOPLEFT:
397  // pin edited point within opposite corner
398  topLeft.x = std::min( topLeft.x, botRight.x - minWidth );
399  topLeft.y = std::min( topLeft.y, botRight.y - minHeight );
400 
401  if( aGridSize > 1 ) // Keep point on specified grid size
402  {
403  topLeft.x = ( topLeft.x / aGridSize ) * aGridSize;
404  topLeft.y = ( topLeft.y / aGridSize ) * aGridSize;
405  }
406 
407  // push edited point edges to adjacent corners
408  topRight.y = topLeft.y;
409  botLeft.x = topLeft.x;
410 
411  break;
412 
413  case RECT_TOPRIGHT:
414  // pin edited point within opposite corner
415  topRight.x = std::max( topRight.x, botLeft.x + minWidth );
416  topRight.y = std::min( topRight.y, botLeft.y - minHeight );
417 
418  if( aGridSize > 1 ) // Keep point on specified grid size
419  {
420  topRight.x = ( ( topRight.x+1 ) / aGridSize ) * aGridSize;
421  topRight.y = ( topRight.y / aGridSize ) * aGridSize;
422  }
423 
424  // push edited point edges to adjacent corners
425  topLeft.y = topRight.y;
426  botRight.x = topRight.x;
427 
428  break;
429 
430  case RECT_BOTLEFT:
431  // pin edited point within opposite corner
432  botLeft.x = std::min( botLeft.x, topRight.x - minWidth );
433  botLeft.y = std::max( botLeft.y, topRight.y + minHeight );
434 
435  if( aGridSize > 1 ) // Keep point on specified grid size
436  {
437  botLeft.x = ( botLeft.x / aGridSize ) * aGridSize;
438  botLeft.y = ( ( botLeft.y+1 ) / aGridSize ) * aGridSize;
439  }
440 
441  // push edited point edges to adjacent corners
442  botRight.y = botLeft.y;
443  topLeft.x = botLeft.x;
444 
445  break;
446 
447  case RECT_BOTRIGHT:
448  // pin edited point within opposite corner
449  botRight.x = std::max( botRight.x, topLeft.x + minWidth );
450  botRight.y = std::max( botRight.y, topLeft.y + minHeight );
451 
452  if( aGridSize > 1 ) // Keep point on specified grid size
453  {
454  botRight.x = ( ( botRight.x+1 ) / aGridSize ) * aGridSize;
455  botRight.y = ( ( botRight.y+1 ) / aGridSize ) * aGridSize;
456  }
457 
458  // push edited point edges to adjacent corners
459  botLeft.y = botRight.y;
460  topRight.x = botRight.x;
461 
462  break;
463  }
464 }

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

Referenced by EE_POINT_EDITOR::updateItem().