2019-05-20 10:23:32 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2019-08-14 08:28:07 +00:00
|
|
|
* Copyright (C) 2019 CERN
|
2021-09-16 09:55:21 +00:00
|
|
|
* Copyright (C) 2019-2021 KiCad Developers, see AUTHORS.txt for contributors.
|
2019-05-20 10:23:32 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <functional>
|
|
|
|
using namespace std::placeholders;
|
|
|
|
|
|
|
|
#include <tool/tool_manager.h>
|
|
|
|
#include <tool/actions.h>
|
|
|
|
#include <view/view_controls.h>
|
|
|
|
#include <gal/graphics_abstraction_layer.h>
|
|
|
|
#include <confirm.h>
|
|
|
|
#include <bitmaps.h>
|
|
|
|
#include <status_popup.h>
|
2021-02-22 23:47:17 +00:00
|
|
|
#include <drawing_sheet/ds_draw_item.h>
|
|
|
|
#include <drawing_sheet/ds_data_item.h>
|
2020-10-13 05:04:31 +00:00
|
|
|
#include "pl_editor_frame.h"
|
|
|
|
#include "pl_point_editor.h"
|
2020-11-26 11:41:41 +00:00
|
|
|
#include "properties_frame.h"
|
2020-10-13 05:04:31 +00:00
|
|
|
#include "tools/pl_selection_tool.h"
|
2019-05-20 10:23:32 +00:00
|
|
|
|
|
|
|
// Few constants to avoid using bare numbers for point indices
|
|
|
|
enum RECTANGLE_POINTS
|
|
|
|
{
|
|
|
|
RECT_TOPLEFT, RECT_TOPRIGHT, RECT_BOTLEFT, RECT_BOTRIGHT
|
|
|
|
};
|
|
|
|
|
|
|
|
enum LINE_POINTS
|
|
|
|
{
|
|
|
|
LINE_START, LINE_END
|
|
|
|
};
|
|
|
|
|
|
|
|
class EDIT_POINTS_FACTORY
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static std::shared_ptr<EDIT_POINTS> Make( EDA_ITEM* aItem )
|
|
|
|
{
|
|
|
|
std::shared_ptr<EDIT_POINTS> points = std::make_shared<EDIT_POINTS>( aItem );
|
|
|
|
|
|
|
|
if( !aItem )
|
|
|
|
return points;
|
|
|
|
|
|
|
|
// Generate list of edit points based on the item type
|
|
|
|
switch( aItem->Type() )
|
|
|
|
{
|
|
|
|
case WSG_LINE_T:
|
|
|
|
{
|
2021-02-22 23:47:17 +00:00
|
|
|
DS_DRAW_ITEM_LINE* line = static_cast<DS_DRAW_ITEM_LINE*>( aItem );
|
2019-05-20 10:23:32 +00:00
|
|
|
points->AddPoint( line->GetStart() );
|
|
|
|
points->AddPoint( line->GetEnd() );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case WSG_RECT_T:
|
|
|
|
{
|
2021-02-22 23:47:17 +00:00
|
|
|
DS_DRAW_ITEM_RECT* rect = static_cast<DS_DRAW_ITEM_RECT*>( aItem );
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I topLeft = rect->GetStart();
|
|
|
|
VECTOR2I botRight = rect->GetEnd();
|
2019-05-20 10:23:32 +00:00
|
|
|
|
2021-09-16 09:55:21 +00:00
|
|
|
if( topLeft.y > botRight.y )
|
|
|
|
std::swap( topLeft.y, botRight.y );
|
|
|
|
|
|
|
|
if( topLeft.x > botRight.x )
|
|
|
|
std::swap( topLeft.x, botRight.x );
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
points->AddPoint( topLeft );
|
2019-05-20 10:23:32 +00:00
|
|
|
points->AddPoint( VECTOR2I( botRight.x, topLeft.y ) );
|
|
|
|
points->AddPoint( VECTOR2I( topLeft.x, botRight.y ) );
|
2022-01-01 06:04:08 +00:00
|
|
|
points->AddPoint( botRight );
|
2019-05-20 10:23:32 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
points.reset();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return points;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
EDIT_POINTS_FACTORY() {};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
PL_POINT_EDITOR::PL_POINT_EDITOR() :
|
|
|
|
TOOL_INTERACTIVE( "plEditor.PointEditor" ),
|
2020-01-11 00:18:27 +00:00
|
|
|
m_frame( nullptr ),
|
|
|
|
m_selectionTool( nullptr ),
|
2019-05-20 10:23:32 +00:00
|
|
|
m_editedPoint( nullptr )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PL_POINT_EDITOR::Reset( RESET_REASON aReason )
|
|
|
|
{
|
|
|
|
if( aReason == MODEL_RELOAD )
|
|
|
|
{
|
|
|
|
// Init variables used by every drawing tool
|
|
|
|
m_frame = getEditFrame<PL_EDITOR_FRAME>();
|
|
|
|
}
|
|
|
|
|
|
|
|
m_editPoints.reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool PL_POINT_EDITOR::Init()
|
|
|
|
{
|
|
|
|
m_frame = getEditFrame<PL_EDITOR_FRAME>();
|
|
|
|
m_selectionTool = m_toolMgr->GetTool<PL_SELECTION_TOOL>();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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() );
|
2019-06-27 21:33:48 +00:00
|
|
|
else
|
|
|
|
point = m_editPoints->FindPoint( getViewControls()->GetCursorPosition(), getView() );
|
2019-05-20 10:23:32 +00:00
|
|
|
|
|
|
|
if( m_editedPoint != point )
|
|
|
|
setEditedPoint( point );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int PL_POINT_EDITOR::Main( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
2021-09-13 12:23:10 +00:00
|
|
|
KIGFX::VIEW_CONTROLS* controls = getViewControls();
|
|
|
|
const PL_SELECTION& selection = m_selectionTool->GetSelection();
|
2019-05-20 10:23:32 +00:00
|
|
|
|
2022-08-20 09:27:35 +00:00
|
|
|
if( selection.Size() != 1 || !selection.Front()->IsType( { WSG_LINE_T, WSG_RECT_T } ) )
|
2019-05-20 10:23:32 +00:00
|
|
|
return 0;
|
|
|
|
|
2021-09-13 12:23:10 +00:00
|
|
|
EDA_ITEM* item = (EDA_ITEM*) selection.Front();
|
|
|
|
|
2019-05-24 11:39:30 +00:00
|
|
|
// Wait till drawing tool is done
|
2021-09-13 12:23:10 +00:00
|
|
|
if( item->IsNew() )
|
2019-05-24 11:39:30 +00:00
|
|
|
return 0;
|
|
|
|
|
2019-05-20 10:23:32 +00:00
|
|
|
Activate();
|
2021-09-13 12:23:10 +00:00
|
|
|
// Must be done after Activate() so that it gets set into the correct context
|
2019-05-20 10:23:32 +00:00
|
|
|
controls->ShowCursor( true );
|
|
|
|
|
|
|
|
m_editPoints = EDIT_POINTS_FACTORY::Make( item );
|
|
|
|
|
|
|
|
if( !m_editPoints )
|
|
|
|
return 0;
|
|
|
|
|
2021-09-13 12:23:10 +00:00
|
|
|
getView()->Add( m_editPoints.get() );
|
2019-05-20 10:23:32 +00:00
|
|
|
setEditedPoint( nullptr );
|
2019-06-27 21:33:48 +00:00
|
|
|
updateEditedPoint( aEvent );
|
2019-05-20 10:23:32 +00:00
|
|
|
bool inDrag = false;
|
|
|
|
bool modified = false;
|
|
|
|
|
|
|
|
// Main loop: keep receiving events
|
2019-06-17 13:43:22 +00:00
|
|
|
while( TOOL_EVENT* evt = Wait() )
|
2019-05-20 10:23:32 +00:00
|
|
|
{
|
2019-07-01 21:01:33 +00:00
|
|
|
if( !m_editPoints || evt->IsSelectionEvent() )
|
2019-05-20 10:23:32 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
if ( !inDrag )
|
|
|
|
updateEditedPoint( *evt );
|
|
|
|
|
|
|
|
if( evt->IsDrag( BUT_LEFT ) && m_editedPoint )
|
|
|
|
{
|
|
|
|
if( !inDrag )
|
|
|
|
{
|
|
|
|
m_frame->SaveCopyInUndoList();
|
|
|
|
controls->ForceCursorPosition( false );
|
|
|
|
inDrag = true;
|
|
|
|
modified = true;
|
|
|
|
}
|
|
|
|
|
2021-05-09 19:17:01 +00:00
|
|
|
m_editedPoint->SetPosition( controls->GetCursorPosition( !evt->DisableGridSnapping() ) );
|
2019-05-20 10:23:32 +00:00
|
|
|
|
|
|
|
updateItem();
|
|
|
|
updatePoints();
|
|
|
|
}
|
|
|
|
|
2019-06-17 13:43:22 +00:00
|
|
|
else if( inDrag && evt->IsMouseUp( BUT_LEFT ) )
|
2019-05-20 10:23:32 +00:00
|
|
|
{
|
|
|
|
controls->SetAutoPan( false );
|
|
|
|
inDrag = false;
|
2019-06-16 00:06:43 +00:00
|
|
|
}
|
2019-05-20 10:23:32 +00:00
|
|
|
|
2019-07-01 21:01:33 +00:00
|
|
|
else if( evt->IsCancelInteractive() || evt->IsActivate() )
|
2019-06-16 00:06:43 +00:00
|
|
|
{
|
|
|
|
if( inDrag ) // Restore the last change
|
|
|
|
{
|
|
|
|
m_frame->RollbackFromUndo();
|
|
|
|
inDrag = false;
|
|
|
|
modified = false;
|
|
|
|
}
|
2019-07-01 21:01:33 +00:00
|
|
|
else if( evt->IsCancelInteractive() )
|
|
|
|
break;
|
2019-06-16 00:06:43 +00:00
|
|
|
|
2019-07-01 21:01:33 +00:00
|
|
|
if( evt->IsActivate() && !evt->IsMoveTool() )
|
|
|
|
break;
|
2019-05-20 10:23:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
else
|
2019-06-16 11:06:49 +00:00
|
|
|
evt->SetPassEvent();
|
2019-05-20 10:23:32 +00:00
|
|
|
|
|
|
|
controls->SetAutoPan( inDrag );
|
|
|
|
controls->CaptureCursor( inDrag );
|
|
|
|
}
|
|
|
|
|
|
|
|
controls->SetAutoPan( false );
|
|
|
|
controls->CaptureCursor( false );
|
|
|
|
|
|
|
|
if( m_editPoints )
|
|
|
|
{
|
2021-09-13 12:23:10 +00:00
|
|
|
getView()->Remove( m_editPoints.get() );
|
2019-05-20 10:23:32 +00:00
|
|
|
|
|
|
|
if( modified )
|
|
|
|
m_frame->OnModify();
|
|
|
|
|
|
|
|
m_editPoints.reset();
|
2019-06-13 17:28:55 +00:00
|
|
|
m_frame->GetCanvas()->Refresh();
|
2019-05-20 10:23:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void pinEditedCorner( int editedPointIndex, int minWidth, int minHeight, VECTOR2I& topLeft,
|
|
|
|
VECTOR2I& topRight, VECTOR2I& botLeft, VECTOR2I& botRight )
|
|
|
|
{
|
|
|
|
switch( editedPointIndex )
|
|
|
|
{
|
|
|
|
case RECT_TOPLEFT:
|
|
|
|
// pin edited point within opposite corner
|
|
|
|
topLeft.x = std::min( topLeft.x, botRight.x - minWidth );
|
|
|
|
topLeft.y = std::min( topLeft.y, botRight.y - minHeight );
|
|
|
|
|
|
|
|
// push edited point edges to adjacent corners
|
|
|
|
topRight.y = topLeft.y;
|
|
|
|
botLeft.x = topLeft.x;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RECT_TOPRIGHT:
|
|
|
|
// pin edited point within opposite corner
|
|
|
|
topRight.x = std::max( topRight.x, botLeft.x + minWidth );
|
|
|
|
topRight.y = std::min( topRight.y, botLeft.y - minHeight );
|
|
|
|
|
|
|
|
// push edited point edges to adjacent corners
|
|
|
|
topLeft.y = topRight.y;
|
|
|
|
botRight.x = topRight.x;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RECT_BOTLEFT:
|
|
|
|
// pin edited point within opposite corner
|
|
|
|
botLeft.x = std::min( botLeft.x, topRight.x - minWidth );
|
|
|
|
botLeft.y = std::max( botLeft.y, topRight.y + minHeight );
|
|
|
|
|
|
|
|
// push edited point edges to adjacent corners
|
|
|
|
botRight.y = botLeft.y;
|
|
|
|
topLeft.x = botLeft.x;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RECT_BOTRIGHT:
|
|
|
|
// pin edited point within opposite corner
|
|
|
|
botRight.x = std::max( botRight.x, topLeft.x + minWidth );
|
|
|
|
botRight.y = std::max( botRight.y, topLeft.y + minHeight );
|
|
|
|
|
|
|
|
// push edited point edges to adjacent corners
|
|
|
|
botLeft.y = botRight.y;
|
|
|
|
topRight.x = botRight.x;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PL_POINT_EDITOR::updateItem() const
|
|
|
|
{
|
|
|
|
EDA_ITEM* item = m_editPoints->GetParent();
|
|
|
|
|
|
|
|
if( !item )
|
|
|
|
return;
|
|
|
|
|
2021-02-22 23:47:17 +00:00
|
|
|
DS_DATA_ITEM* dataItem = static_cast<DS_DRAW_ITEM_BASE*>( item )->GetPeer();
|
2020-11-26 11:41:41 +00:00
|
|
|
|
2021-09-16 09:55:21 +00:00
|
|
|
// 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.
|
2020-11-26 11:41:41 +00:00
|
|
|
|
2019-05-20 10:23:32 +00:00
|
|
|
switch( item->Type() )
|
|
|
|
{
|
|
|
|
case WSG_LINE_T:
|
|
|
|
{
|
2021-02-22 23:47:17 +00:00
|
|
|
DS_DRAW_ITEM_LINE* line = static_cast<DS_DRAW_ITEM_LINE*>( item );
|
2019-05-20 10:23:32 +00:00
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I move_startpoint = m_editPoints->Point( LINE_START ).GetPosition() - line->GetStart();
|
|
|
|
VECTOR2I move_endpoint = m_editPoints->Point( LINE_END ).GetPosition() - line->GetEnd();
|
2020-11-26 11:41:41 +00:00
|
|
|
|
|
|
|
dataItem->MoveStartPointToUi( dataItem->GetStartPosUi() + move_startpoint );
|
|
|
|
dataItem->MoveEndPointToUi( dataItem->GetEndPosUi() + move_endpoint );
|
|
|
|
|
2021-02-22 23:47:17 +00:00
|
|
|
for( DS_DRAW_ITEM_BASE* draw_item : dataItem->GetDrawItems() )
|
2020-11-26 11:41:41 +00:00
|
|
|
{
|
2021-02-22 23:47:17 +00:00
|
|
|
DS_DRAW_ITEM_LINE* draw_line = static_cast<DS_DRAW_ITEM_LINE*>( draw_item );
|
2020-11-26 11:41:41 +00:00
|
|
|
|
|
|
|
draw_line->SetStart( draw_line->GetStart() + move_startpoint );
|
|
|
|
draw_line->SetEnd( draw_line->GetEnd() + move_endpoint );
|
|
|
|
getView()->Update( draw_item );
|
|
|
|
}
|
|
|
|
|
2019-05-20 10:23:32 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case WSG_RECT_T:
|
|
|
|
{
|
2021-02-22 23:47:17 +00:00
|
|
|
DS_DRAW_ITEM_RECT* rect = static_cast<DS_DRAW_ITEM_RECT*>( item );
|
2019-05-20 10:23:32 +00:00
|
|
|
VECTOR2I topLeft = m_editPoints->Point( RECT_TOPLEFT ).GetPosition();
|
|
|
|
VECTOR2I topRight = m_editPoints->Point( RECT_TOPRIGHT ).GetPosition();
|
|
|
|
VECTOR2I botLeft = m_editPoints->Point( RECT_BOTLEFT ).GetPosition();
|
|
|
|
VECTOR2I botRight = m_editPoints->Point( RECT_BOTRIGHT ).GetPosition();
|
|
|
|
|
2022-09-16 23:42:20 +00:00
|
|
|
pinEditedCorner( getEditedPointIndex(), drawSheetIUScale.MilsToIU( 1 ),
|
|
|
|
drawSheetIUScale.MilsToIU( 1 ),
|
2019-05-20 10:23:32 +00:00
|
|
|
topLeft, topRight, botLeft, botRight );
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I start_delta, end_delta;
|
2021-09-16 09:55:21 +00:00
|
|
|
|
|
|
|
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 );
|
2020-11-26 11:41:41 +00:00
|
|
|
|
2021-02-22 23:47:17 +00:00
|
|
|
for( DS_DRAW_ITEM_BASE* draw_item : dataItem->GetDrawItems() )
|
2020-11-26 11:41:41 +00:00
|
|
|
{
|
2021-02-22 23:47:17 +00:00
|
|
|
DS_DRAW_ITEM_RECT* draw_rect = static_cast<DS_DRAW_ITEM_RECT*>( draw_item );
|
2020-11-26 11:41:41 +00:00
|
|
|
|
2021-09-16 09:55:21 +00:00
|
|
|
draw_rect->SetStart( draw_rect->GetStart() + start_delta );
|
|
|
|
draw_rect->SetEnd( draw_rect->GetEnd() + end_delta );
|
2020-11-26 11:41:41 +00:00
|
|
|
getView()->Update( draw_item );
|
|
|
|
}
|
|
|
|
|
2019-05-20 10:23:32 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_frame->SetMsgPanel( item );
|
2020-11-26 11:41:41 +00:00
|
|
|
|
|
|
|
// The Properties frame will be updated. Avoid flicker during update:
|
|
|
|
m_frame->GetPropertiesFrame()->Freeze();
|
|
|
|
m_frame->GetPropertiesFrame()->CopyPrmsFromItemToPanel( dataItem );
|
|
|
|
m_frame->GetPropertiesFrame()->Thaw();
|
2019-05-20 10:23:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PL_POINT_EDITOR::updatePoints()
|
|
|
|
{
|
|
|
|
if( !m_editPoints )
|
|
|
|
return;
|
|
|
|
|
|
|
|
EDA_ITEM* item = m_editPoints->GetParent();
|
|
|
|
|
|
|
|
if( !item )
|
|
|
|
return;
|
|
|
|
|
|
|
|
switch( item->Type() )
|
|
|
|
{
|
|
|
|
case WSG_LINE_T:
|
|
|
|
{
|
2021-02-22 23:47:17 +00:00
|
|
|
DS_DRAW_ITEM_LINE* line = static_cast<DS_DRAW_ITEM_LINE*>( item );
|
2019-05-20 10:23:32 +00:00
|
|
|
|
|
|
|
m_editPoints->Point( LINE_START ).SetPosition( line->GetStart() );
|
|
|
|
m_editPoints->Point( LINE_END ).SetPosition( line->GetEnd() );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case WSG_RECT_T:
|
|
|
|
{
|
2021-02-22 23:47:17 +00:00
|
|
|
DS_DRAW_ITEM_RECT* rect = static_cast<DS_DRAW_ITEM_RECT*>( item );
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I topLeft = rect->GetPosition();
|
|
|
|
VECTOR2I botRight = rect->GetEnd();
|
2019-05-20 10:23:32 +00:00
|
|
|
|
2021-09-16 09:55:21 +00:00
|
|
|
if( topLeft.y > botRight.y )
|
|
|
|
std::swap( topLeft.y, botRight.y );
|
|
|
|
|
|
|
|
if( topLeft.x > botRight.x )
|
|
|
|
std::swap( topLeft.x, botRight.x );
|
|
|
|
|
2019-05-20 10:23:32 +00:00
|
|
|
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 ) );
|
|
|
|
m_editPoints->Point( RECT_BOTRIGHT ).SetPosition( (VECTOR2I) botRight );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
getView()->Update( m_editPoints.get() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PL_POINT_EDITOR::setEditedPoint( EDIT_POINT* aPoint )
|
|
|
|
{
|
|
|
|
KIGFX::VIEW_CONTROLS* controls = getViewControls();
|
|
|
|
|
|
|
|
if( aPoint )
|
|
|
|
{
|
2020-10-08 00:50:28 +00:00
|
|
|
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::ARROW );
|
2019-05-20 10:23:32 +00:00
|
|
|
controls->ForceCursorPosition( true, aPoint->GetPosition() );
|
|
|
|
controls->ShowCursor( true );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-06-29 13:39:46 +00:00
|
|
|
if( m_frame->ToolStackIsEmpty() )
|
|
|
|
controls->ShowCursor( false );
|
|
|
|
|
2019-05-20 10:23:32 +00:00
|
|
|
controls->ForceCursorPosition( false );
|
|
|
|
}
|
|
|
|
|
|
|
|
m_editedPoint = aPoint;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int PL_POINT_EDITOR::modifiedSelection( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
updatePoints();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PL_POINT_EDITOR::setTransitions()
|
|
|
|
{
|
|
|
|
Go( &PL_POINT_EDITOR::Main, EVENTS::SelectedEvent );
|
2019-05-24 11:39:30 +00:00
|
|
|
Go( &PL_POINT_EDITOR::Main, ACTIONS::activatePointEditor.MakeEvent() );
|
2019-05-20 10:23:32 +00:00
|
|
|
Go( &PL_POINT_EDITOR::modifiedSelection, EVENTS::SelectedItemsModified );
|
|
|
|
}
|
|
|
|
|
|
|
|
|