Don't assume the grid size.
Fixes https://gitlab.com/kicad/code/kicad/issues/9013
This commit is contained in:
parent
cec788d454
commit
9f806d9304
|
@ -26,6 +26,7 @@
|
||||||
using namespace std::placeholders;
|
using namespace std::placeholders;
|
||||||
|
|
||||||
#include "ee_point_editor.h"
|
#include "ee_point_editor.h"
|
||||||
|
#include <ee_grid_helper.h>
|
||||||
#include <tool/tool_manager.h>
|
#include <tool/tool_manager.h>
|
||||||
#include <view/view_controls.h>
|
#include <view/view_controls.h>
|
||||||
#include <geometry/seg.h>
|
#include <geometry/seg.h>
|
||||||
|
@ -401,20 +402,11 @@ int EE_POINT_EDITOR::Main( const TOOL_EVENT& aEvent )
|
||||||
* @param topRight is the RECT_TOPRIGHT to constraint
|
* @param topRight is the RECT_TOPRIGHT to constraint
|
||||||
* @param botLeft is the RECT_BOTLEFT to constraint
|
* @param botLeft is the RECT_BOTLEFT to constraint
|
||||||
* @param botRight is the RECT_BOTRIGHT to constraint
|
* @param botRight is the RECT_BOTRIGHT to constraint
|
||||||
* @param aGridSize is the a constraint: if > 1 new coordinates are on this grid
|
|
||||||
*/
|
*/
|
||||||
static void pinEditedCorner( int aEditedPointIndex, int minWidth, int minHeight,
|
static void pinEditedCorner( int aEditedPointIndex, int minWidth, int minHeight,
|
||||||
VECTOR2I& topLeft, VECTOR2I& topRight,
|
VECTOR2I& topLeft, VECTOR2I& topRight, VECTOR2I& botLeft,
|
||||||
VECTOR2I& botLeft, VECTOR2I& botRight,
|
VECTOR2I& botRight, EE_GRID_HELPER* aGrid )
|
||||||
int aGridSize = 0 )
|
|
||||||
{
|
{
|
||||||
auto alignToGrid =
|
|
||||||
[&]( const VECTOR2I& aPoint ) -> VECTOR2I
|
|
||||||
{
|
|
||||||
return VECTOR2I( KiROUND( aPoint.x / aGridSize ) * aGridSize,
|
|
||||||
KiROUND( aPoint.y / aGridSize ) * aGridSize );
|
|
||||||
};
|
|
||||||
|
|
||||||
switch( aEditedPointIndex )
|
switch( aEditedPointIndex )
|
||||||
{
|
{
|
||||||
case RECT_TOPLEFT:
|
case RECT_TOPLEFT:
|
||||||
|
@ -422,8 +414,7 @@ static void pinEditedCorner( int aEditedPointIndex, int minWidth, int minHeight,
|
||||||
topLeft.x = std::min( topLeft.x, botRight.x - minWidth );
|
topLeft.x = std::min( topLeft.x, botRight.x - minWidth );
|
||||||
topLeft.y = std::min( topLeft.y, botRight.y - minHeight );
|
topLeft.y = std::min( topLeft.y, botRight.y - minHeight );
|
||||||
|
|
||||||
if( aGridSize > 1 ) // Keep point on specified grid size
|
topLeft = aGrid->AlignGrid( topLeft );
|
||||||
topLeft = alignToGrid( topLeft );
|
|
||||||
|
|
||||||
// push edited point edges to adjacent corners
|
// push edited point edges to adjacent corners
|
||||||
topRight.y = topLeft.y;
|
topRight.y = topLeft.y;
|
||||||
|
@ -436,8 +427,7 @@ static void pinEditedCorner( int aEditedPointIndex, int minWidth, int minHeight,
|
||||||
topRight.x = std::max( topRight.x, botLeft.x + minWidth );
|
topRight.x = std::max( topRight.x, botLeft.x + minWidth );
|
||||||
topRight.y = std::min( topRight.y, botLeft.y - minHeight );
|
topRight.y = std::min( topRight.y, botLeft.y - minHeight );
|
||||||
|
|
||||||
if( aGridSize > 1 ) // Keep point on specified grid size
|
topRight = aGrid->AlignGrid( topRight );
|
||||||
topRight = alignToGrid( topRight );
|
|
||||||
|
|
||||||
// push edited point edges to adjacent corners
|
// push edited point edges to adjacent corners
|
||||||
topLeft.y = topRight.y;
|
topLeft.y = topRight.y;
|
||||||
|
@ -450,8 +440,7 @@ static void pinEditedCorner( int aEditedPointIndex, int minWidth, int minHeight,
|
||||||
botLeft.x = std::min( botLeft.x, topRight.x - minWidth );
|
botLeft.x = std::min( botLeft.x, topRight.x - minWidth );
|
||||||
botLeft.y = std::max( botLeft.y, topRight.y + minHeight );
|
botLeft.y = std::max( botLeft.y, topRight.y + minHeight );
|
||||||
|
|
||||||
if( aGridSize > 1 ) // Keep point on specified grid size
|
botLeft = aGrid->AlignGrid( botLeft );
|
||||||
botLeft = alignToGrid( botLeft );
|
|
||||||
|
|
||||||
// push edited point edges to adjacent corners
|
// push edited point edges to adjacent corners
|
||||||
botRight.y = botLeft.y;
|
botRight.y = botLeft.y;
|
||||||
|
@ -464,8 +453,7 @@ static void pinEditedCorner( int aEditedPointIndex, int minWidth, int minHeight,
|
||||||
botRight.x = std::max( botRight.x, topLeft.x + minWidth );
|
botRight.x = std::max( botRight.x, topLeft.x + minWidth );
|
||||||
botRight.y = std::max( botRight.y, topLeft.y + minHeight );
|
botRight.y = std::max( botRight.y, topLeft.y + minHeight );
|
||||||
|
|
||||||
if( aGridSize > 1 ) // Keep point on specified grid size
|
botRight = aGrid->AlignGrid( botRight );
|
||||||
botRight = alignToGrid( botRight );
|
|
||||||
|
|
||||||
// push edited point edges to adjacent corners
|
// push edited point edges to adjacent corners
|
||||||
botLeft.y = botRight.y;
|
botLeft.y = botRight.y;
|
||||||
|
@ -525,13 +513,14 @@ void EE_POINT_EDITOR::updateParentItem() const
|
||||||
|
|
||||||
case SHAPE_T::RECT:
|
case SHAPE_T::RECT:
|
||||||
{
|
{
|
||||||
|
EE_GRID_HELPER gridHelper( m_toolMgr );
|
||||||
VECTOR2I topLeft = m_editPoints->Point( RECT_TOPLEFT ).GetPosition();
|
VECTOR2I topLeft = m_editPoints->Point( RECT_TOPLEFT ).GetPosition();
|
||||||
VECTOR2I topRight = m_editPoints->Point( RECT_TOPRIGHT ).GetPosition();
|
VECTOR2I topRight = m_editPoints->Point( RECT_TOPRIGHT ).GetPosition();
|
||||||
VECTOR2I botLeft = m_editPoints->Point( RECT_BOTLEFT ).GetPosition();
|
VECTOR2I botLeft = m_editPoints->Point( RECT_BOTLEFT ).GetPosition();
|
||||||
VECTOR2I botRight = m_editPoints->Point( RECT_BOTRIGHT ).GetPosition();
|
VECTOR2I botRight = m_editPoints->Point( RECT_BOTRIGHT ).GetPosition();
|
||||||
|
|
||||||
pinEditedCorner( getEditedPointIndex(), Mils2iu( 1 ), Mils2iu( 1 ),
|
pinEditedCorner( getEditedPointIndex(), Mils2iu( 1 ), Mils2iu( 1 ),
|
||||||
topLeft, topRight, botLeft, botRight );
|
topLeft, topRight, botLeft, botRight, &gridHelper );
|
||||||
|
|
||||||
shape->SetPosition( mapCoords( topLeft ) );
|
shape->SetPosition( mapCoords( topLeft ) );
|
||||||
shape->SetEnd( mapCoords( botRight ) );
|
shape->SetEnd( mapCoords( botRight ) );
|
||||||
|
@ -551,6 +540,7 @@ void EE_POINT_EDITOR::updateParentItem() const
|
||||||
|
|
||||||
case SCH_BITMAP_T:
|
case SCH_BITMAP_T:
|
||||||
{
|
{
|
||||||
|
EE_GRID_HELPER gridHelper( m_toolMgr );
|
||||||
SCH_BITMAP* bitmap = (SCH_BITMAP*) item;
|
SCH_BITMAP* bitmap = (SCH_BITMAP*) item;
|
||||||
VECTOR2I topLeft = m_editPoints->Point( RECT_TOPLEFT ).GetPosition();
|
VECTOR2I topLeft = m_editPoints->Point( RECT_TOPLEFT ).GetPosition();
|
||||||
VECTOR2I topRight = m_editPoints->Point( RECT_TOPRIGHT ).GetPosition();
|
VECTOR2I topRight = m_editPoints->Point( RECT_TOPRIGHT ).GetPosition();
|
||||||
|
@ -558,7 +548,7 @@ void EE_POINT_EDITOR::updateParentItem() const
|
||||||
VECTOR2I botRight = m_editPoints->Point( RECT_BOTRIGHT ).GetPosition();
|
VECTOR2I botRight = m_editPoints->Point( RECT_BOTRIGHT ).GetPosition();
|
||||||
|
|
||||||
pinEditedCorner( getEditedPointIndex(), Mils2iu( 50 ), Mils2iu( 50 ),
|
pinEditedCorner( getEditedPointIndex(), Mils2iu( 50 ), Mils2iu( 50 ),
|
||||||
topLeft, topRight, botLeft, botRight );
|
topLeft, topRight, botLeft, botRight, &gridHelper );
|
||||||
|
|
||||||
double oldWidth = bitmap->GetSize().x;
|
double oldWidth = bitmap->GetSize().x;
|
||||||
double newWidth = topRight.x - topLeft.x;
|
double newWidth = topRight.x - topLeft.x;
|
||||||
|
@ -575,21 +565,17 @@ void EE_POINT_EDITOR::updateParentItem() const
|
||||||
case SCH_SHEET_T:
|
case SCH_SHEET_T:
|
||||||
{
|
{
|
||||||
SCH_SHEET* sheet = (SCH_SHEET*) item;
|
SCH_SHEET* sheet = (SCH_SHEET*) item;
|
||||||
|
EE_GRID_HELPER gridHelper( m_toolMgr );
|
||||||
VECTOR2I topLeft = m_editPoints->Point( RECT_TOPLEFT ).GetPosition();
|
VECTOR2I topLeft = m_editPoints->Point( RECT_TOPLEFT ).GetPosition();
|
||||||
VECTOR2I topRight = m_editPoints->Point( RECT_TOPRIGHT ).GetPosition();
|
VECTOR2I topRight = m_editPoints->Point( RECT_TOPRIGHT ).GetPosition();
|
||||||
VECTOR2I botLeft = m_editPoints->Point( RECT_BOTLEFT ).GetPosition();
|
VECTOR2I botLeft = m_editPoints->Point( RECT_BOTLEFT ).GetPosition();
|
||||||
VECTOR2I botRight = m_editPoints->Point( RECT_BOTRIGHT ).GetPosition();
|
VECTOR2I botRight = m_editPoints->Point( RECT_BOTRIGHT ).GetPosition();
|
||||||
|
|
||||||
// The grid size used to place connected items. because a sheet contains
|
|
||||||
// connected items (sheet pins), keep corners coordinates on this grid.
|
|
||||||
// Otherwise, some sheet pins can be moved off grid
|
|
||||||
int grid_size = Mils2iu( 50 );
|
|
||||||
int edited = getEditedPointIndex();
|
int edited = getEditedPointIndex();
|
||||||
|
|
||||||
pinEditedCorner( getEditedPointIndex(),
|
pinEditedCorner( getEditedPointIndex(),
|
||||||
sheet->GetMinWidth( edited == RECT_TOPRIGHT || edited == RECT_BOTRIGHT ),
|
sheet->GetMinWidth( edited == RECT_TOPRIGHT || edited == RECT_BOTRIGHT ),
|
||||||
sheet->GetMinHeight( edited == RECT_BOTLEFT || edited == RECT_BOTRIGHT ),
|
sheet->GetMinHeight( edited == RECT_BOTLEFT || edited == RECT_BOTRIGHT ),
|
||||||
topLeft, topRight, botLeft, botRight, grid_size );
|
topLeft, topRight, botLeft, botRight, &gridHelper );
|
||||||
|
|
||||||
// Pin positions are relative to origin. Attempt to leave them where they
|
// Pin positions are relative to origin. Attempt to leave them where they
|
||||||
// are if the origin moves.
|
// are if the origin moves.
|
||||||
|
|
Loading…
Reference in New Issue