Keep order of rect corners in PLEditor.

Fixes https://gitlab.com/kicad/code/kicad/issues/9168
This commit is contained in:
Jeff Young 2021-09-16 10:55:21 +01:00
parent 4663da4709
commit 92e97d1285
2 changed files with 45 additions and 25 deletions

View File

@ -128,8 +128,7 @@ void PL_DRAW_PANEL_GAL::DisplayDrawingSheet()
// (Note: no need to have a large working area: nothing can be drawn outside th page size).
double size_x = m_edaFrame->GetPageSizeIU().x;
double size_y = m_edaFrame->GetPageSizeIU().y;
BOX2D boundary( VECTOR2D( -size_x/4 , -size_y/4 ),
VECTOR2D( size_x * 1.5, size_y * 1.5) );
BOX2D boundary( VECTOR2D( -size_x/4 , -size_y/4 ), VECTOR2D( size_x * 1.5, size_y * 1.5) );
m_view->SetBoundary( boundary );
m_pageDrawItem->SetPageSize( m_edaFrame->GetPageSizeIU() );

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2019 CERN
* Copyright (C) 2019 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2019-2021 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -29,20 +29,14 @@ using namespace std::placeholders;
#include <tool/actions.h>
#include <view/view_controls.h>
#include <gal/graphics_abstraction_layer.h>
#include <geometry/seg.h>
#include <confirm.h>
#include <bitmaps.h>
#include <status_popup.h>
#include <drawing_sheet/ds_draw_item.h>
#include <drawing_sheet/ds_data_item.h>
#include <progress_reporter.h>
#include "pl_editor_frame.h"
#include "pl_editor_id.h"
#include "pl_point_editor.h"
#include "properties_frame.h"
#include "tools/pl_actions.h"
#include "tools/pl_selection_tool.h"
// Few constants to avoid using bare numbers for point indices
@ -82,6 +76,12 @@ public:
wxPoint topLeft = rect->GetStart();
wxPoint botRight = rect->GetEnd();
if( topLeft.y > botRight.y )
std::swap( topLeft.y, botRight.y );
if( topLeft.x > botRight.x )
std::swap( topLeft.x, botRight.x );
points->AddPoint( (VECTOR2I) topLeft );
points->AddPoint( VECTOR2I( botRight.x, topLeft.y ) );
points->AddPoint( VECTOR2I( topLeft.x, botRight.y ) );
@ -135,17 +135,11 @@ void PL_POINT_EDITOR::updateEditedPoint( const TOOL_EVENT& aEvent )
EDIT_POINT* point = m_editedPoint;
if( aEvent.IsMotion() )
{
point = m_editPoints->FindPoint( aEvent.Position(), getView() );
}
else if( aEvent.IsDrag( BUT_LEFT ) )
{
point = m_editPoints->FindPoint( aEvent.DragOrigin(), getView() );
}
else
{
point = m_editPoints->FindPoint( getViewControls()->GetCursorPosition(), getView() );
}
if( m_editedPoint != point )
setEditedPoint( point );
@ -315,10 +309,9 @@ void PL_POINT_EDITOR::updateItem() const
DS_DATA_ITEM* dataItem = static_cast<DS_DRAW_ITEM_BASE*>( item )->GetPeer();
// the current item is perhaps not the main item if we have a set of
// repeated items.
// So we change the coordinate references in dataItem using move vectors
// of the start and end points that are the same for each repeated item
// The current item is perhaps not the main item if we have a set of repeated items.
// So we change the coordinate references in dataItem using move vectors of the start and
// end points that are the same for each repeated item.
switch( item->Type() )
{
@ -357,17 +350,39 @@ void PL_POINT_EDITOR::updateItem() const
pinEditedCorner( getEditedPointIndex(), Mils2iu( 1 ), Mils2iu( 1 ),
topLeft, topRight, botLeft, botRight );
wxPoint move_startpoint = (wxPoint) topLeft - rect->GetStart();
wxPoint move_endpoint = (wxPoint) botRight - rect->GetEnd();
wxPoint start_delta, end_delta;
if( rect->GetStart().y > rect->GetEnd().y )
{
start_delta.y = botRight.y - rect->GetStart().y;
end_delta.y = topLeft.y - rect->GetEnd().y;
}
else
{
start_delta.y = topLeft.y - rect->GetStart().y;
end_delta.y = botRight.y - rect->GetEnd().y;
}
if( rect->GetStart().x > rect->GetEnd().x )
{
start_delta.x = botRight.x - rect->GetStart().x;
end_delta.x = topLeft.x - rect->GetEnd().x;
}
else
{
start_delta.x = topLeft.x - rect->GetStart().x;
end_delta.x = botRight.x - rect->GetEnd().x;
}
dataItem->MoveStartPointToUi( dataItem->GetStartPosUi() + start_delta );
dataItem->MoveEndPointToUi( dataItem->GetEndPosUi() + end_delta );
dataItem->MoveStartPointToUi( dataItem->GetStartPosUi() + move_startpoint );
dataItem->MoveEndPointToUi( dataItem->GetEndPosUi() + move_endpoint );
for( DS_DRAW_ITEM_BASE* draw_item : dataItem->GetDrawItems() )
{
DS_DRAW_ITEM_RECT* draw_rect = static_cast<DS_DRAW_ITEM_RECT*>( draw_item );
draw_rect->SetStart( draw_rect->GetStart() + move_startpoint );
draw_rect->SetEnd( draw_rect->GetEnd() + move_endpoint );
draw_rect->SetStart( draw_rect->GetStart() + start_delta );
draw_rect->SetEnd( draw_rect->GetEnd() + end_delta );
getView()->Update( draw_item );
}
@ -414,6 +429,12 @@ void PL_POINT_EDITOR::updatePoints()
wxPoint topLeft = rect->GetPosition();
wxPoint botRight = rect->GetEnd();
if( topLeft.y > botRight.y )
std::swap( topLeft.y, botRight.y );
if( topLeft.x > botRight.x )
std::swap( topLeft.x, botRight.x );
m_editPoints->Point( RECT_TOPLEFT ).SetPosition( (VECTOR2I) topLeft );
m_editPoints->Point( RECT_TOPRIGHT ).SetPosition( VECTOR2I( botRight.x, topLeft.y ) );
m_editPoints->Point( RECT_BOTLEFT ).SetPosition( VECTOR2I( topLeft.x, botRight.y ) );