26using namespace std::placeholders;
100 std::shared_ptr<EDIT_POINTS> points = std::make_shared<EDIT_POINTS>( aItem );
106 switch( aItem->
Type() )
120 case SHAPE_T::CIRCLE:
125 case SHAPE_T::RECTANGLE:
132 points->AddPoint( topLeft );
133 points->AddPoint(
VECTOR2I( botRight.
x, topLeft.
y ) );
134 points->AddPoint(
VECTOR2I( topLeft.
x, botRight.
y ) );
135 points->AddPoint( botRight );
155 case SHAPE_T::BEZIER:
178 points->AddPoint( topLeft );
179 points->AddPoint(
VECTOR2I( botRight.
x, topLeft.
y ) );
180 points->AddPoint(
VECTOR2I( topLeft.
x, botRight.
y ) );
181 points->AddPoint( botRight );
203 points->AddPoint( shape->
GetStart() );
204 points->AddPoint( shape->
GetEnd() );
207 case SHAPE_T::CIRCLE:
209 points->AddPoint( shape->
GetEnd() );
212 case SHAPE_T::RECTANGLE:
219 points->AddPoint( topLeft );
220 points->AddPoint(
VECTOR2I( botRight.
x, topLeft.
y ) );
221 points->AddPoint(
VECTOR2I( topLeft.
x, botRight.
y ) );
222 points->AddPoint( botRight );
238 points->AddPoint( pt );
242 case SHAPE_T::BEZIER:
243 points->AddPoint( shape->
GetStart() );
246 points->AddPoint( shape->
GetEnd() );
265 points->AddPoint( topLeft );
266 points->AddPoint(
VECTOR2I( botRight.
x, topLeft.
y ) );
267 points->AddPoint(
VECTOR2I( topLeft.
x, botRight.
y ) );
268 points->AddPoint( botRight );
296 points->AddPoint( topLeft );
297 points->AddPoint(
VECTOR2I( botRight.
x, topLeft.
y ) );
298 points->AddPoint(
VECTOR2I( topLeft.
x, botRight.
y ) );
299 points->AddPoint( botRight );
319 points->AddPoint( topLeft );
320 points->AddPoint(
VECTOR2I( botRight.
x, topLeft.
y ) );
321 points->AddPoint(
VECTOR2I( topLeft.
x, botRight.
y ) );
322 points->AddPoint( botRight );
329 std::pair<EDA_ITEM*, int> connectedStart = {
nullptr,
STARTPOINT };
330 std::pair<EDA_ITEM*, int> connectedEnd = {
nullptr,
STARTPOINT };
348 connectedStart = { testLine,
ENDPOINT };
356 connectedEnd = { testLine,
ENDPOINT };
361 points->AddPoint( line->
GetEndPoint(), connectedEnd );
380 m_editedPoint( nullptr ),
381 m_inPointEditor( false )
457 if( !
editor->IsSymbolEditable() ||
editor->IsSymbolAlias() )
463 if( selection.
Size() != 1 || !selection.
Front()->
IsType( { LIB_SHAPE_T, SCH_SHAPE_T,
464 LIB_TEXTBOX_T, SCH_TEXTBOX_T,
467 SCH_ITEM_LOCATE_GRAPHIC_LINE_T,
500 grid->SetUseGrid(
getView()->GetGAL()->GetGridSnapping()
501 && !evt->DisableGridSnapping() );
526 if( connected.first )
531 if( connected.first )
545 bool snap = !evt->DisableGridSnapping();
556 else if( inDrag && evt->IsMouseUp(
BUT_LEFT ) )
558 if( !commit.
Empty() )
559 commit.
Push(
_(
"Move Point" ) );
564 else if( evt->IsCancelInteractive() || evt->IsActivate() )
583 else if( evt->IsCancelInteractive() )
588 if( evt->IsActivate() )
634 topLeft.
x = std::min( topLeft.
x, botRight.
x - minWidth );
635 topLeft.
y = std::min( topLeft.
y, botRight.
y - minHeight );
638 topLeft = aGrid->
AlignGrid( topLeft, GRID_HELPER_GRIDS::GRID_GRAPHICS );
641 topRight.
y = topLeft.
y;
642 botLeft.
x = topLeft.
x;
647 topRight.
x = std::max( topRight.
x, botLeft.
x + minWidth );
648 topRight.
y = std::min( topRight.
y, botLeft.
y - minHeight );
651 topRight = aGrid->
AlignGrid( topRight, GRID_HELPER_GRIDS::GRID_GRAPHICS );
654 topLeft.
y = topRight.
y;
655 botRight.
x = topRight.
x;
660 botLeft.
x = std::min( botLeft.
x, topRight.
x - minWidth );
661 botLeft.
y = std::max( botLeft.
y, topRight.
y + minHeight );
664 botLeft = aGrid->
AlignGrid( botLeft, GRID_HELPER_GRIDS::GRID_GRAPHICS );
667 botRight.
y = botLeft.
y;
668 topLeft.
x = botLeft.
x;
673 botRight.
x = std::max( botRight.
x, topLeft.
x + minWidth );
674 botRight.
y = std::max( botRight.
y, topLeft.
y + minHeight );
677 botRight = aGrid->
AlignGrid( botRight, GRID_HELPER_GRIDS::GRID_GRAPHICS );
680 botLeft.
y = botRight.
y;
681 topRight.
x = botRight.
x;
685 topLeft.
y = std::min( topLeft.
y, botRight.
y - minHeight );
688 topLeft = aGrid->
AlignGrid( topLeft, GRID_HELPER_GRIDS::GRID_GRAPHICS );
692 topLeft.
x = std::min( topLeft.
x, botRight.
x - minWidth );
695 topLeft = aGrid->
AlignGrid( topLeft, GRID_HELPER_GRIDS::GRID_GRAPHICS );
699 botRight.
y = std::max( botRight.
y, topLeft.
y + minHeight );
702 botRight = aGrid->
AlignGrid( botRight, GRID_HELPER_GRIDS::GRID_GRAPHICS );
706 botRight.
x = std::max( botRight.
x, topLeft.
x + minWidth );
709 botRight = aGrid->
AlignGrid( botRight, GRID_HELPER_GRIDS::GRID_GRAPHICS );
721 switch( item->
Type() )
747 case SHAPE_T::CIRCLE:
756 for(
unsigned i = 0; i <
m_editPoints->PointsSize(); ++i )
764 case SHAPE_T::RECTANGLE:
772 gridHelper.
SetSnap( aSnapToGrid );
775 botLeft, botRight, &gridHelper );
802 for(
unsigned i = 0; i <
m_editPoints->LinesSize(); ++i )
814 case SHAPE_T::BEZIER:
839 gridHelper.
SetSnap( aSnapToGrid );
842 botLeft, botRight, &gridHelper );
869 for(
unsigned i = 0; i <
m_editPoints->LinesSize(); ++i )
906 case SHAPE_T::CIRCLE:
915 for(
unsigned i = 0; i <
m_editPoints->PointsSize(); ++i )
923 case SHAPE_T::RECTANGLE:
931 gridHelper.
SetSnap( aSnapToGrid );
934 botLeft, botRight, &gridHelper );
942 shape->
SetEnd( botRight );
961 for(
unsigned i = 0; i <
m_editPoints->LinesSize(); ++i )
973 case SHAPE_T::BEZIER:
998 gridHelper.
SetSnap( aSnapToGrid );
1001 botLeft, botRight, &gridHelper );
1009 textBox->
SetEnd( botRight );
1028 for(
unsigned i = 0; i <
m_editPoints->LinesSize(); ++i )
1052 for(
int ii = 0; ii < cell->
GetColSpan() - 1; ++ii )
1064 for(
int ii = 0; ii < cell->
GetRowSpan() - 1; ++ii )
1083 gridHelper.
SetSnap( aSnapToGrid );
1086 botLeft, botRight, &gridHelper );
1088 double oldWidth = bitmap->
GetSize().
x;
1089 double newWidth = topRight.
x - topLeft.
x;
1090 double widthRatio = newWidth / oldWidth;
1092 double oldHeight = bitmap->
GetSize().
y;
1093 double newHeight = botLeft.
y - topLeft.
y;
1094 double heightRatio = newHeight / oldHeight;
1111 gridHelper.
SetSnap( aSnapToGrid );
1120 gridHelper.
SetSnap( aSnapToGrid );
1124 topLeft, topRight, botLeft, botRight, &gridHelper );
1131 sheetNewPos = topLeft;
1132 sheetNewSize =
VECTOR2I( botRight.
x - topLeft.
x, botRight.
y - topLeft.
y );
1153 for(
unsigned i = 0; i <
m_editPoints->LinesSize(); ++i )
1165 if( sheet->
GetSize() != sheetNewSize )
1166 sheet->
Resize( sheetNewSize );
1180 if( connected.first )
1184 else if( connected.second ==
ENDPOINT )
1192 if( connected.first )
1196 else if( connected.second ==
ENDPOINT )
1224 switch( item->
Type() )
1238 case SHAPE_T::CIRCLE:
1263 case SHAPE_T::RECTANGLE:
1282 case SHAPE_T::BEZIER:
1329 case SHAPE_T::CIRCLE:
1354 case SHAPE_T::RECTANGLE:
1373 case SHAPE_T::BEZIER:
1516 if( shape->
GetShape() != SHAPE_T::POLY )
1522 return shape->
HitTest( cursorPos, (
int) threshold );
1539 int currentMinDistance = INT_MAX;
1540 int closestLineStart = 0;
1545 poly.
CPoint( i + 1 ), pos );
1547 if(
distance < currentMinDistance )
1550 closestLineStart = i;
1554 poly.
Insert( closestLineStart + 1, pos );
1559 commit.
Push(
_(
"Add Corner" ) );
1583 commit.
Push(
_(
"Remove Corner" ) );
VECTOR2D mapCoords(const VECTOR2D &aSource)
constexpr EDA_IU_SCALE schIUScale
static TOOL_ACTION activatePointEditor
COMMIT & Modify(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Create an undo entry for an item that has been already modified.
bool Empty() const
Returns status of an item.
EDIT_CONSTRAINT for a EDIT_LINE, that constrains the line to move perpendicular to the line itself.
void SetMsgPanel(const std::vector< MSG_PANEL_ITEM > &aList)
Clear the message panel and populates it with the contents of aList.
void SetCurrentCursor(KICURSOR aCursor)
Set the current cursor shape for this panel.
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=nullptr) override
A base class for most all the KiCad significant classes used in schematics and boards.
KICAD_T Type() const
Returns the type of object.
virtual bool IsType(const std::vector< KICAD_T > &aScanTypes) const
Check whether the item is one of the listed types.
EDA_ITEM * GetParent() const
const VECTOR2I & GetBezierC2() const
void SetBezierC2(const VECTOR2I &aPt)
void RebuildBezierToSegmentsPointsList(int aMinSegLen)
Rebuild the m_bezierPoints vertex list that approximate the Bezier curve by a list of segments.
int GetRectangleWidth() const
SHAPE_POLY_SET & GetPolyShape()
int GetPointCount() const
const VECTOR2I & GetEnd() const
Return the ending point of the graphic.
void SetStart(const VECTOR2I &aStart)
const VECTOR2I & GetStart() const
Return the starting point of the graphic.
void SetEnd(const VECTOR2I &aEnd)
void SetBezierC1(const VECTOR2I &aPt)
wxString SHAPE_T_asString() const
const VECTOR2I & GetBezierC1() const
int GetRectangleHeight() const
virtual int GetWidth() const
virtual void ClearRenderCache()
static std::shared_ptr< EDIT_POINTS > Make(EDA_ITEM *aItem, SCH_BASE_FRAME *frame)
Represent a single point that can be used for modifying items.
static const int POINT_SIZE
virtual void SetPosition(const VECTOR2I &aPosition)
Set new coordinates for an EDIT_POINT.
virtual VECTOR2I GetPosition() const
Return coordinates of an EDIT_POINT.
static TOOL_ACTION pointEditorRemoveCorner
static TOOL_ACTION pointEditorAddCorner
void updatePoints()
Update which point is being edited.
bool m_inPointEditor
Currently available edit points.
int Main(const TOOL_EVENT &aEvent)
void updateEditedPoint(const TOOL_EVENT &aEvent)
Clear references to the points.
void setEditedPoint(EDIT_POINT *aPoint)
Return true if aPoint is the currently modified point.
int modifiedSelection(const TOOL_EVENT &aEvent)
bool Init() override
Init() is called once upon a registration of the tool.
EDIT_POINT * m_editedPoint
< Currently edited point, NULL if there is none.
bool addCornerCondition(const SELECTION &aSelection)
void setTransitions() override
This method is meant to be overridden in order to specify handlers for events.
void pinEditedCorner(int minWidth, int minHeight, VECTOR2I &topLeft, VECTOR2I &topRight, VECTOR2I &botLeft, VECTOR2I &botRight, EE_GRID_HELPER *aGrid) const
Update the coordinates of 4 corners of a rectangle, according to constraints and the moved corner.
bool isModified(const EDIT_POINT &aPoint) const
int addCorner(const TOOL_EVENT &aEvent)
TOOL_ACTION handlers.
std::shared_ptr< EDIT_POINTS > m_editPoints
bool removeCornerCondition(const SELECTION &aSelection)
int removeCorner(const TOOL_EVENT &aEvent)
void Reset(RESET_REASON aReason) override
Bring the tool to a known, initial state.
int getEditedPointIndex() const
int clearEditedPoints(const TOOL_EVENT &aEvent)
Set the current point being edited. NULL means none.
void updateParentItem(bool aSnapToGrid) const
< Update item's points with edit points.
EE_TYPE OfType(KICAD_T aType) const
static const TOOL_EVENT ClearedEvent
static const TOOL_EVENT SelectedEvent
static const TOOL_EVENT SelectedItemsModified
Selected items were moved, this can be very high frequency on the canvas, use with care.
static const TOOL_EVENT PointSelectedEvent
virtual VECTOR2I AlignGrid(const VECTOR2I &aPoint, GRID_HELPER_GRIDS aGrid) const
An interface for classes handling user events controlling the view behavior such as zooming,...
virtual void CaptureCursor(bool aEnabled)
Force the cursor to stay within the drawing panel area.
virtual void ForceCursorPosition(bool aEnabled, const VECTOR2D &aPosition=VECTOR2D(0, 0))
Place the cursor immediately at a given point.
virtual void ShowCursor(bool aEnabled)
Enable or disables display of cursor.
VECTOR2D GetCursorPosition() const
Return the current cursor position in world coordinates.
virtual VECTOR2D GetMousePosition(bool aWorldCoordinates=true) const =0
Return the current mouse pointer position.
virtual void SetAutoPan(bool aEnabled)
Turn on/off auto panning (this feature is used when there is a tool active (eg.
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Add a VIEW_ITEM to the view.
virtual void Remove(VIEW_ITEM *aItem)
Remove a VIEW_ITEM from the view.
virtual void Update(const VIEW_ITEM *aItem, int aUpdateFlags) const
For dynamic VIEWs, inform the associated VIEW that the graphical representation of this item has chan...
VECTOR2D ToWorld(const VECTOR2D &aCoord, bool aAbsolute=true) const
Converts a screen space point/vector to a point/vector in world space coordinates.
bool HitTest(const VECTOR2I &aPosition, int aAccuracy=0) const override
Test if aPosition is inside or on the boundary of this item.
void AddPoint(const VECTOR2I &aPosition)
void SetEditState(int aState)
void SetPosition(const VECTOR2I &aPosition) override
void CalcEdit(const VECTOR2I &aPosition) override
Calculate the attributes of an item at aPosition when it is being edited.
VECTOR2I GetPosition() const override
A shim class between EDA_DRAW_FRAME and several derived classes: SYMBOL_EDIT_FRAME,...
SCH_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
SCH_DRAW_PANEL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
Object to handle a bitmap image that can be inserted in a schematic.
double GetImageScale() const
VECTOR2I GetPosition() const override
void SetImageScale(double aScale)
virtual void Push(const wxString &aMessage=wxT("A commit"), int aCommitFlags=0) override
Revert the commit by restoring the modified items state.
virtual void Revert() override
Base class for any item which can be embedded within the SCHEMATIC container class,...
Segment description base class to describe items which have 2 end points (track, wire,...
void SetStartPoint(const VECTOR2I &aPosition)
VECTOR2I GetEndPoint() const
VECTOR2I GetStartPoint() const
void SetEndPoint(const VECTOR2I &aPosition)
EE_RTREE & Items()
Gets the full RTree, usually for iterating.
void SetPosition(const VECTOR2I &aPos) override
void CalcEdit(const VECTOR2I &aPosition)
void SetEditState(int aState)
void AddPoint(const VECTOR2I &aPosition)
VECTOR2I GetPosition() const override
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
void SetPositionIgnoringPins(const VECTOR2I &aPosition)
int GetMinWidth(bool aFromLeft) const
Return the minimum width of the sheet based on the widths of the sheet pin text.
VECTOR2I GetPosition() const override
int GetMinHeight(bool aFromTop) const
Return the minimum height that the sheet can be resized based on the sheet pin positions.
void Resize(const VECTOR2I &aSize)
Resize this sheet to aSize and adjust all of the labels accordingly.
void SetRowHeight(int aRow, int aHeight)
int GetRowHeight(int aRow) const
void SetColWidth(int aCol, int aWidth)
int GetColWidth(int aCol) const
int Size() const
Returns the number of selected parts.
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
virtual size_t GetPointCount() const override
const VECTOR2I & CPoint(int aIndex) const
Return a reference to a given point in the line chain.
void Remove(int aStartIndex, int aEndIndex)
Remove the range of points [start_index, end_index] from the line chain.
void Insert(size_t aVertex, const VECTOR2I &aP)
const std::vector< VECTOR2I > & CPoints() const
void RemoveAllContours()
Remove all outlines & holes (clears) the polygon set.
bool IsEmpty() const
Return true if the set is empty (no polygons at all)
int Append(int x, int y, int aOutline=-1, int aHole=-1, bool aAllowDuplication=false)
Appends a vertex at the end of the given outline/hole (default: the last outline)
SHAPE_LINE_CHAIN & Outline(int aIndex)
Return the reference to aIndex-th outline in the set.
int NewOutline()
Creates a new empty polygon in the set and returns its index.
The symbol library editor main window.
#define ENDPOINT
ends. (Used to support dragging.)
#define STARTPOINT
When a line is selected, these flags indicate which.
@ BEZIER_CURVE_CONTROL_POINT2
@ BEZIER_CURVE_CONTROL_POINT1
#define UNIMPLEMENTED_FOR(type)
static float distance(const SFVEC2UI &a, const SFVEC2UI &b)
std::vector< FAB_LAYER_COLOR > dummy
constexpr int MilsToIU(int mils) const
double DistanceLinePoint(const VECTOR2I &linePointA, const VECTOR2I &linePointB, const VECTOR2I &referencePoint)
Compute the distance between a line and a reference point.