2019-05-08 18:56:03 +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
|
2022-01-25 22:33:37 +00:00
|
|
|
* Copyright (C) 2019-2022 KiCad Developers, see AUTHORS.txt for contributors.
|
2019-05-08 18:56:03 +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;
|
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
#include "ee_point_editor.h"
|
2021-11-01 15:26:09 +00:00
|
|
|
#include <ee_grid_helper.h>
|
2019-05-08 18:56:03 +00:00
|
|
|
#include <tool/tool_manager.h>
|
|
|
|
#include <view/view_controls.h>
|
|
|
|
#include <geometry/seg.h>
|
2019-05-10 17:19:48 +00:00
|
|
|
#include <tools/ee_actions.h>
|
|
|
|
#include <tools/ee_selection_tool.h>
|
2019-05-08 18:56:03 +00:00
|
|
|
#include <sch_edit_frame.h>
|
|
|
|
#include <sch_line.h>
|
2019-06-19 10:31:21 +00:00
|
|
|
#include <sch_bitmap.h>
|
2019-05-08 18:56:03 +00:00
|
|
|
#include <sch_sheet.h>
|
2022-01-25 22:33:37 +00:00
|
|
|
#include <sch_textbox.h>
|
2021-07-17 19:56:18 +00:00
|
|
|
#include <sch_shape.h>
|
2021-04-06 21:15:49 +00:00
|
|
|
#include <sch_sheet_pin.h>
|
2020-10-31 01:27:16 +00:00
|
|
|
#include <symbol_edit_frame.h>
|
2021-07-18 23:08:54 +00:00
|
|
|
#include <lib_shape.h>
|
2022-01-25 22:33:37 +00:00
|
|
|
#include <lib_textbox.h>
|
2019-05-08 18:56:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
// Few constants to avoid using bare numbers for point indices
|
|
|
|
enum ARC_POINTS
|
|
|
|
{
|
|
|
|
ARC_CENTER, ARC_START, ARC_END
|
|
|
|
};
|
|
|
|
|
|
|
|
enum CIRCLE_POINTS
|
|
|
|
{
|
|
|
|
CIRC_CENTER, CIRC_END
|
|
|
|
};
|
|
|
|
|
|
|
|
enum RECTANGLE_POINTS
|
|
|
|
{
|
|
|
|
RECT_TOPLEFT, RECT_TOPRIGHT, RECT_BOTLEFT, RECT_BOTRIGHT
|
|
|
|
};
|
|
|
|
|
2022-03-27 13:23:18 +00:00
|
|
|
enum RECTANGLE_LINES
|
|
|
|
{
|
|
|
|
RECT_TOP, RECT_RIGHT, RECT_BOT, RECT_LEFT
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2019-05-08 18:56:03 +00:00
|
|
|
enum LINE_POINTS
|
|
|
|
{
|
|
|
|
LINE_START, LINE_END
|
|
|
|
};
|
|
|
|
|
|
|
|
class EDIT_POINTS_FACTORY
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static std::shared_ptr<EDIT_POINTS> Make( EDA_ITEM* aItem, SCH_BASE_FRAME* frame )
|
|
|
|
{
|
|
|
|
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() )
|
|
|
|
{
|
2021-07-18 23:08:54 +00:00
|
|
|
case LIB_SHAPE_T:
|
2019-05-08 18:56:03 +00:00
|
|
|
{
|
2021-07-18 23:08:54 +00:00
|
|
|
LIB_SHAPE* shape = static_cast<LIB_SHAPE*>( aItem );
|
2019-05-08 18:56:03 +00:00
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
switch( shape->GetShape() )
|
|
|
|
{
|
|
|
|
case SHAPE_T::ARC:
|
|
|
|
points->AddPoint( mapCoords( shape->GetPosition() ) );
|
|
|
|
points->AddPoint( mapCoords( shape->GetStart() ) );
|
|
|
|
points->AddPoint( mapCoords( shape->GetEnd() ) );
|
|
|
|
break;
|
2019-05-08 18:56:03 +00:00
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
case SHAPE_T::CIRCLE:
|
|
|
|
points->AddPoint( mapCoords( shape->GetPosition() ) );
|
|
|
|
points->AddPoint( mapCoords( shape->GetEnd() ) );
|
|
|
|
break;
|
2019-05-08 18:56:03 +00:00
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
case SHAPE_T::RECT:
|
|
|
|
{
|
2022-04-06 17:18:01 +00:00
|
|
|
shape->Normalize();
|
|
|
|
|
|
|
|
VECTOR2I topLeft = mapCoords( shape->GetPosition() );
|
|
|
|
VECTOR2I botRight = mapCoords( shape->GetEnd() );
|
2021-07-18 23:08:54 +00:00
|
|
|
|
|
|
|
points->AddPoint( topLeft );
|
|
|
|
points->AddPoint( VECTOR2I( botRight.x, topLeft.y ) );
|
|
|
|
points->AddPoint( VECTOR2I( topLeft.x, botRight.y ) );
|
|
|
|
points->AddPoint( botRight );
|
2022-03-27 13:23:18 +00:00
|
|
|
|
|
|
|
points->AddLine( points->Point( RECT_TOPLEFT ), points->Point( RECT_TOPRIGHT ) );
|
|
|
|
points->Line( RECT_TOP ).SetConstraint( new EC_PERPLINE( points->Line( RECT_TOP ) ) );
|
|
|
|
points->AddLine( points->Point( RECT_TOPRIGHT ), points->Point( RECT_BOTRIGHT ) );
|
|
|
|
points->Line( RECT_RIGHT ).SetConstraint( new EC_PERPLINE( points->Line( RECT_RIGHT ) ) );
|
|
|
|
points->AddLine( points->Point( RECT_BOTRIGHT ), points->Point( RECT_BOTLEFT ) );
|
|
|
|
points->Line( RECT_BOT ).SetConstraint( new EC_PERPLINE( points->Line( RECT_BOT ) ) );
|
|
|
|
points->AddLine( points->Point( RECT_BOTLEFT ), points->Point( RECT_TOPLEFT ) );
|
|
|
|
points->Line( RECT_LEFT ).SetConstraint( new EC_PERPLINE( points->Line( RECT_LEFT ) ) );
|
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
break;
|
2022-01-25 22:33:37 +00:00
|
|
|
}
|
2019-05-08 18:56:03 +00:00
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
case SHAPE_T::POLY:
|
|
|
|
for( const VECTOR2I& pt : shape->GetPolyShape().Outline( 0 ).CPoints() )
|
|
|
|
points->AddPoint( mapCoords( pt ) );
|
2019-07-26 08:40:40 +00:00
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SHAPE_T::BEZIER:
|
|
|
|
// TODO
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2021-07-17 19:56:18 +00:00
|
|
|
UNIMPLEMENTED_FOR( shape->SHAPE_T_asString() );
|
|
|
|
}
|
2022-01-25 22:33:37 +00:00
|
|
|
|
|
|
|
break;
|
2021-07-17 19:56:18 +00:00
|
|
|
}
|
2022-01-25 22:33:37 +00:00
|
|
|
|
|
|
|
case LIB_TEXTBOX_T:
|
|
|
|
{
|
|
|
|
LIB_TEXTBOX* textBox = static_cast<LIB_TEXTBOX*>( aItem );
|
|
|
|
|
2022-04-06 17:18:01 +00:00
|
|
|
textBox->Normalize();
|
|
|
|
|
|
|
|
VECTOR2I topLeft = mapCoords( textBox->GetPosition() );
|
|
|
|
VECTOR2I botRight = mapCoords( textBox->GetEnd() );
|
2022-01-25 22:33:37 +00:00
|
|
|
|
|
|
|
points->AddPoint( topLeft );
|
|
|
|
points->AddPoint( VECTOR2I( botRight.x, topLeft.y ) );
|
|
|
|
points->AddPoint( VECTOR2I( topLeft.x, botRight.y ) );
|
|
|
|
points->AddPoint( botRight );
|
2022-03-27 13:23:18 +00:00
|
|
|
|
|
|
|
points->AddLine( points->Point( RECT_TOPLEFT ), points->Point( RECT_TOPRIGHT ) );
|
|
|
|
points->Line( RECT_TOP ).SetConstraint( new EC_PERPLINE( points->Line( RECT_TOP ) ) );
|
|
|
|
points->AddLine( points->Point( RECT_TOPRIGHT ), points->Point( RECT_BOTRIGHT ) );
|
|
|
|
points->Line( RECT_RIGHT ).SetConstraint( new EC_PERPLINE( points->Line( RECT_RIGHT ) ) );
|
|
|
|
points->AddLine( points->Point( RECT_BOTRIGHT ), points->Point( RECT_BOTLEFT ) );
|
|
|
|
points->Line( RECT_BOT ).SetConstraint( new EC_PERPLINE( points->Line( RECT_BOT ) ) );
|
|
|
|
points->AddLine( points->Point( RECT_BOTLEFT ), points->Point( RECT_TOPLEFT ) );
|
|
|
|
points->Line( RECT_LEFT ).SetConstraint( new EC_PERPLINE( points->Line( RECT_LEFT ) ) );
|
|
|
|
|
2021-07-17 19:56:18 +00:00
|
|
|
break;
|
2022-01-25 22:33:37 +00:00
|
|
|
}
|
2021-07-17 19:56:18 +00:00
|
|
|
|
|
|
|
case SCH_SHAPE_T:
|
|
|
|
{
|
|
|
|
SCH_SHAPE* shape = static_cast<SCH_SHAPE*>( aItem );
|
|
|
|
|
|
|
|
switch( shape->GetShape() )
|
|
|
|
{
|
|
|
|
case SHAPE_T::ARC:
|
|
|
|
points->AddPoint( shape->GetPosition() );
|
|
|
|
points->AddPoint( shape->GetStart() );
|
|
|
|
points->AddPoint( shape->GetEnd() );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SHAPE_T::CIRCLE:
|
|
|
|
points->AddPoint( shape->GetPosition() );
|
|
|
|
points->AddPoint( shape->GetEnd() );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SHAPE_T::RECT:
|
|
|
|
{
|
2022-04-06 17:18:01 +00:00
|
|
|
shape->Normalize();
|
|
|
|
|
|
|
|
VECTOR2I topLeft = shape->GetPosition();
|
|
|
|
VECTOR2I botRight = shape->GetEnd();
|
2021-07-17 19:56:18 +00:00
|
|
|
|
|
|
|
points->AddPoint( topLeft );
|
|
|
|
points->AddPoint( VECTOR2I( botRight.x, topLeft.y ) );
|
|
|
|
points->AddPoint( VECTOR2I( topLeft.x, botRight.y ) );
|
|
|
|
points->AddPoint( botRight );
|
2022-03-27 13:23:18 +00:00
|
|
|
|
|
|
|
points->AddLine( points->Point( RECT_TOPLEFT ), points->Point( RECT_TOPRIGHT ) );
|
|
|
|
points->Line( RECT_TOP ).SetConstraint( new EC_PERPLINE( points->Line( RECT_TOP ) ) );
|
|
|
|
points->AddLine( points->Point( RECT_TOPRIGHT ), points->Point( RECT_BOTRIGHT ) );
|
|
|
|
points->Line( RECT_RIGHT ).SetConstraint( new EC_PERPLINE( points->Line( RECT_RIGHT ) ) );
|
|
|
|
points->AddLine( points->Point( RECT_BOTRIGHT ), points->Point( RECT_BOTLEFT ) );
|
|
|
|
points->Line( RECT_BOT ).SetConstraint( new EC_PERPLINE( points->Line( RECT_BOT ) ) );
|
|
|
|
points->AddLine( points->Point( RECT_BOTLEFT ), points->Point( RECT_TOPLEFT ) );
|
|
|
|
points->Line( RECT_LEFT ).SetConstraint( new EC_PERPLINE( points->Line( RECT_LEFT ) ) );
|
|
|
|
|
2021-07-17 19:56:18 +00:00
|
|
|
break;
|
2022-01-25 22:33:37 +00:00
|
|
|
}
|
2021-07-17 19:56:18 +00:00
|
|
|
|
|
|
|
case SHAPE_T::POLY:
|
|
|
|
for( const VECTOR2I& pt : shape->GetPolyShape().Outline( 0 ).CPoints() )
|
|
|
|
points->AddPoint( pt );
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SHAPE_T::BEZIER:
|
|
|
|
// TODO
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
UNIMPLEMENTED_FOR( shape->SHAPE_T_asString() );
|
2021-07-18 23:08:54 +00:00
|
|
|
}
|
2022-01-25 22:33:37 +00:00
|
|
|
|
|
|
|
break;
|
2019-05-08 18:56:03 +00:00
|
|
|
}
|
2022-01-25 22:33:37 +00:00
|
|
|
|
|
|
|
case SCH_TEXTBOX_T:
|
|
|
|
{
|
|
|
|
SCH_TEXTBOX* textBox = static_cast<SCH_TEXTBOX*>( aItem );
|
|
|
|
|
2022-04-06 17:18:01 +00:00
|
|
|
textBox->Normalize();
|
|
|
|
|
|
|
|
VECTOR2I topLeft = textBox->GetPosition();
|
|
|
|
VECTOR2I botRight = textBox->GetEnd();
|
2022-01-25 22:33:37 +00:00
|
|
|
|
|
|
|
points->AddPoint( topLeft );
|
|
|
|
points->AddPoint( VECTOR2I( botRight.x, topLeft.y ) );
|
|
|
|
points->AddPoint( VECTOR2I( topLeft.x, botRight.y ) );
|
|
|
|
points->AddPoint( botRight );
|
2022-03-27 13:23:18 +00:00
|
|
|
|
|
|
|
points->AddLine( points->Point( RECT_TOPLEFT ), points->Point( RECT_TOPRIGHT ) );
|
|
|
|
points->Line( RECT_TOP ).SetConstraint( new EC_PERPLINE( points->Line( RECT_TOP ) ) );
|
|
|
|
points->AddLine( points->Point( RECT_TOPRIGHT ), points->Point( RECT_BOTRIGHT ) );
|
|
|
|
points->Line( RECT_RIGHT ).SetConstraint( new EC_PERPLINE( points->Line( RECT_RIGHT ) ) );
|
|
|
|
points->AddLine( points->Point( RECT_BOTRIGHT ), points->Point( RECT_BOTLEFT ) );
|
|
|
|
points->Line( RECT_BOT ).SetConstraint( new EC_PERPLINE( points->Line( RECT_BOT ) ) );
|
|
|
|
points->AddLine( points->Point( RECT_BOTLEFT ), points->Point( RECT_TOPLEFT ) );
|
|
|
|
points->Line( RECT_LEFT ).SetConstraint( new EC_PERPLINE( points->Line( RECT_LEFT ) ) );
|
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
break;
|
2022-01-25 22:33:37 +00:00
|
|
|
}
|
2021-07-18 23:08:54 +00:00
|
|
|
|
2019-05-08 18:56:03 +00:00
|
|
|
case SCH_SHEET_T:
|
|
|
|
{
|
|
|
|
SCH_SHEET* sheet = (SCH_SHEET*) aItem;
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I topLeft = sheet->GetPosition();
|
|
|
|
VECTOR2I botRight = sheet->GetPosition() + sheet->GetSize();
|
2019-05-08 18:56:03 +00:00
|
|
|
|
2022-01-01 17:11:21 +00:00
|
|
|
points->AddPoint( topLeft );
|
|
|
|
points->AddPoint( VECTOR2I( botRight.x, topLeft.y ) );
|
|
|
|
points->AddPoint( VECTOR2I( topLeft.x, botRight.y ) );
|
|
|
|
points->AddPoint( botRight );
|
2022-07-23 22:57:04 +00:00
|
|
|
|
|
|
|
points->AddLine( points->Point( RECT_TOPLEFT ), points->Point( RECT_TOPRIGHT ) );
|
|
|
|
points->Line( RECT_TOP ).SetConstraint( new EC_PERPLINE( points->Line( RECT_TOP ) ) );
|
|
|
|
points->AddLine( points->Point( RECT_TOPRIGHT ), points->Point( RECT_BOTRIGHT ) );
|
|
|
|
points->Line( RECT_RIGHT ).SetConstraint( new EC_PERPLINE( points->Line( RECT_RIGHT ) ) );
|
|
|
|
points->AddLine( points->Point( RECT_BOTRIGHT ), points->Point( RECT_BOTLEFT ) );
|
|
|
|
points->Line( RECT_BOT ).SetConstraint( new EC_PERPLINE( points->Line( RECT_BOT ) ) );
|
|
|
|
points->AddLine( points->Point( RECT_BOTLEFT ), points->Point( RECT_TOPLEFT ) );
|
|
|
|
points->Line( RECT_LEFT ).SetConstraint( new EC_PERPLINE( points->Line( RECT_LEFT ) ) );
|
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
break;
|
2022-01-25 22:33:37 +00:00
|
|
|
}
|
2021-07-18 23:08:54 +00:00
|
|
|
|
2019-06-19 10:31:21 +00:00
|
|
|
case SCH_BITMAP_T:
|
|
|
|
{
|
|
|
|
SCH_BITMAP* bitmap = (SCH_BITMAP*) aItem;
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I topLeft = bitmap->GetPosition() - bitmap->GetSize() / 2;
|
|
|
|
VECTOR2I botRight = bitmap->GetPosition() + bitmap->GetSize() / 2;
|
2019-06-19 10:31:21 +00:00
|
|
|
|
2022-01-01 17:11:21 +00:00
|
|
|
points->AddPoint( topLeft );
|
|
|
|
points->AddPoint( VECTOR2I( botRight.x, topLeft.y ) );
|
|
|
|
points->AddPoint( VECTOR2I( topLeft.x, botRight.y ) );
|
|
|
|
points->AddPoint( botRight );
|
2021-07-18 23:08:54 +00:00
|
|
|
break;
|
2022-01-25 22:33:37 +00:00
|
|
|
}
|
2021-07-18 23:08:54 +00:00
|
|
|
|
2019-05-08 18:56:03 +00:00
|
|
|
case SCH_LINE_T:
|
|
|
|
{
|
|
|
|
SCH_LINE* line = (SCH_LINE*) aItem;
|
2020-11-30 19:27:31 +00:00
|
|
|
std::pair<EDA_ITEM*, int> connectedStart = { nullptr, STARTPOINT };
|
|
|
|
std::pair<EDA_ITEM*, int> connectedEnd = { nullptr, STARTPOINT };
|
2019-05-08 18:56:03 +00:00
|
|
|
|
2020-11-30 19:27:31 +00:00
|
|
|
for( SCH_ITEM* test : frame->GetScreen()->Items().OfType( SCH_LINE_T ) )
|
2019-05-08 18:56:03 +00:00
|
|
|
{
|
2019-06-25 23:39:58 +00:00
|
|
|
if( test->GetLayer() != LAYER_NOTES )
|
2019-05-08 18:56:03 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if( test == aItem )
|
|
|
|
continue;
|
|
|
|
|
2020-11-30 19:27:31 +00:00
|
|
|
SCH_LINE* testLine = static_cast<SCH_LINE*>( test );
|
2019-05-08 18:56:03 +00:00
|
|
|
|
|
|
|
if( testLine->GetStartPoint() == line->GetStartPoint() )
|
|
|
|
{
|
2020-11-30 19:27:31 +00:00
|
|
|
connectedStart = { testLine, STARTPOINT };
|
2019-05-08 18:56:03 +00:00
|
|
|
}
|
|
|
|
else if( testLine->GetEndPoint() == line->GetStartPoint() )
|
|
|
|
{
|
2020-11-30 19:27:31 +00:00
|
|
|
connectedStart = { testLine, ENDPOINT };
|
2019-05-08 18:56:03 +00:00
|
|
|
}
|
|
|
|
else if( testLine->GetStartPoint() == line->GetEndPoint() )
|
|
|
|
{
|
2020-11-30 19:27:31 +00:00
|
|
|
connectedEnd = { testLine, STARTPOINT };
|
2019-05-08 18:56:03 +00:00
|
|
|
}
|
|
|
|
else if( testLine->GetEndPoint() == line->GetEndPoint() )
|
|
|
|
{
|
2020-11-30 19:27:31 +00:00
|
|
|
connectedEnd = { testLine, ENDPOINT };
|
2019-05-08 18:56:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
points->AddPoint( line->GetStartPoint(), connectedStart );
|
|
|
|
points->AddPoint( line->GetEndPoint(), connectedEnd );
|
2021-07-18 23:08:54 +00:00
|
|
|
break;
|
2022-01-25 22:33:37 +00:00
|
|
|
}
|
2021-07-18 23:08:54 +00:00
|
|
|
|
2019-05-08 18:56:03 +00:00
|
|
|
default:
|
|
|
|
points.reset();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return points;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
EDIT_POINTS_FACTORY() {};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
EE_POINT_EDITOR::EE_POINT_EDITOR() :
|
2019-05-12 11:49:58 +00:00
|
|
|
EE_TOOL_BASE<SCH_BASE_FRAME>( "eeschema.PointEditor" ),
|
2019-05-08 18:56:03 +00:00
|
|
|
m_editedPoint( nullptr )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
void EE_POINT_EDITOR::Reset( RESET_REASON aReason )
|
2019-05-08 18:56:03 +00:00
|
|
|
{
|
2019-05-12 11:49:58 +00:00
|
|
|
EE_TOOL_BASE::Reset( aReason );
|
|
|
|
|
2019-05-08 18:56:03 +00:00
|
|
|
m_editPoints.reset();
|
2021-10-06 17:20:07 +00:00
|
|
|
m_editedPoint = nullptr;
|
2019-05-08 18:56:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
bool EE_POINT_EDITOR::Init()
|
2019-05-08 18:56:03 +00:00
|
|
|
{
|
2019-05-12 11:49:58 +00:00
|
|
|
EE_TOOL_BASE::Init();
|
2019-05-08 18:56:03 +00:00
|
|
|
|
|
|
|
auto& menu = m_selectionTool->GetToolMenu().GetMenu();
|
2019-05-10 17:19:48 +00:00
|
|
|
menu.AddItem( EE_ACTIONS::pointEditorAddCorner,
|
|
|
|
std::bind( &EE_POINT_EDITOR::addCornerCondition, this, _1 ) );
|
|
|
|
menu.AddItem( EE_ACTIONS::pointEditorRemoveCorner,
|
|
|
|
std::bind( &EE_POINT_EDITOR::removeCornerCondition, this, _1 ) );
|
2019-05-08 18:56:03 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-10-06 17:20:07 +00:00
|
|
|
int EE_POINT_EDITOR::clearEditedPoints( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
setEditedPoint( nullptr );
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
void EE_POINT_EDITOR::updateEditedPoint( const TOOL_EVENT& aEvent )
|
2019-05-08 18:56:03 +00:00
|
|
|
{
|
|
|
|
EDIT_POINT* point = m_editedPoint;
|
|
|
|
|
2021-10-06 17:20:07 +00:00
|
|
|
if( !m_editPoints )
|
|
|
|
{
|
|
|
|
point = nullptr;
|
|
|
|
}
|
|
|
|
else if( aEvent.IsMotion() )
|
2019-05-08 18:56:03 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
|
{
|
2022-10-24 10:35:51 +00:00
|
|
|
point = m_editPoints->FindPoint( getViewControls()->GetCursorPosition( false ), getView() );
|
2019-06-27 21:33:48 +00:00
|
|
|
}
|
2019-05-08 18:56:03 +00:00
|
|
|
|
|
|
|
if( m_editedPoint != point )
|
|
|
|
setEditedPoint( point );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
int EE_POINT_EDITOR::Main( const TOOL_EVENT& aEvent )
|
2019-05-08 18:56:03 +00:00
|
|
|
{
|
|
|
|
if( !m_selectionTool )
|
|
|
|
return 0;
|
|
|
|
|
2021-11-18 15:33:05 +00:00
|
|
|
if( m_isSymbolEditor )
|
|
|
|
{
|
|
|
|
SYMBOL_EDIT_FRAME* editor = getEditFrame<SYMBOL_EDIT_FRAME>();
|
|
|
|
|
|
|
|
if( !editor->IsSymbolEditable() || editor->IsSymbolAlias() )
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-06-08 21:48:22 +00:00
|
|
|
const EE_SELECTION& selection = m_selectionTool->GetSelection();
|
2019-05-08 18:56:03 +00:00
|
|
|
|
2022-08-20 09:27:35 +00:00
|
|
|
if( selection.Size() != 1 || !selection.Front()->IsType( { LIB_SHAPE_T, SCH_SHAPE_T,
|
|
|
|
LIB_TEXTBOX_T, SCH_TEXTBOX_T,
|
|
|
|
SCH_SHEET_T,
|
|
|
|
SCH_ITEM_LOCATE_GRAPHIC_LINE_T,
|
|
|
|
SCH_BITMAP_T } ) )
|
|
|
|
{
|
2019-05-08 18:56:03 +00:00
|
|
|
return 0;
|
2022-08-20 09:27:35 +00:00
|
|
|
}
|
2019-05-08 18:56:03 +00:00
|
|
|
|
2019-05-24 11:39:30 +00:00
|
|
|
// Wait till drawing tool is done
|
|
|
|
if( selection.Front()->IsNew() )
|
|
|
|
return 0;
|
|
|
|
|
2019-05-08 18:56:03 +00:00
|
|
|
Activate();
|
|
|
|
|
|
|
|
KIGFX::VIEW_CONTROLS* controls = getViewControls();
|
|
|
|
KIGFX::VIEW* view = getView();
|
|
|
|
EDA_ITEM* item = (EDA_ITEM*) selection.Front();
|
|
|
|
|
|
|
|
controls->ShowCursor( true );
|
|
|
|
|
|
|
|
m_editPoints = EDIT_POINTS_FACTORY::Make( item, m_frame );
|
|
|
|
view->Add( m_editPoints.get() );
|
|
|
|
setEditedPoint( nullptr );
|
2019-06-27 21:33:48 +00:00
|
|
|
updateEditedPoint( aEvent );
|
2019-05-08 18:56:03 +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-08 18:56:03 +00:00
|
|
|
{
|
2019-07-01 21:01:33 +00:00
|
|
|
if( !m_editPoints || evt->IsSelectionEvent() )
|
2019-05-08 18:56:03 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
if ( !inDrag )
|
|
|
|
updateEditedPoint( *evt );
|
|
|
|
|
|
|
|
if( evt->IsDrag( BUT_LEFT ) && m_editedPoint )
|
|
|
|
{
|
|
|
|
if( !inDrag )
|
|
|
|
{
|
|
|
|
saveItemsToUndo();
|
|
|
|
controls->ForceCursorPosition( false );
|
|
|
|
inDrag = true;
|
|
|
|
modified = true;
|
|
|
|
}
|
|
|
|
|
2021-10-14 23:39:31 +00:00
|
|
|
bool snap = !evt->DisableGridSnapping();
|
|
|
|
EDA_SHAPE* shape = dynamic_cast<EDA_SHAPE*>( item );
|
2019-06-29 18:56:07 +00:00
|
|
|
|
2021-10-14 23:39:31 +00:00
|
|
|
if( shape && shape->GetShape() == SHAPE_T::ARC && getEditedPointIndex() == ARC_CENTER )
|
2019-06-29 18:56:07 +00:00
|
|
|
snap = false;
|
|
|
|
|
|
|
|
m_editedPoint->SetPosition( controls->GetCursorPosition( snap ) );
|
2019-05-08 18:56:03 +00:00
|
|
|
|
2022-10-24 10:35:51 +00:00
|
|
|
updateParentItem( snap );
|
2019-05-08 18:56:03 +00:00
|
|
|
updatePoints();
|
|
|
|
}
|
2019-06-17 13:43:22 +00:00
|
|
|
else if( inDrag && evt->IsMouseUp( BUT_LEFT ) )
|
2019-05-08 18:56:03 +00:00
|
|
|
{
|
2021-01-26 17:46:10 +00:00
|
|
|
if( modified )
|
|
|
|
{
|
|
|
|
m_frame->OnModify();
|
|
|
|
modified = false;
|
|
|
|
}
|
|
|
|
|
2019-05-08 18:56:03 +00:00
|
|
|
controls->SetAutoPan( false );
|
|
|
|
inDrag = false;
|
|
|
|
}
|
2019-07-01 21:01:33 +00:00
|
|
|
else if( evt->IsCancelInteractive() || evt->IsActivate() )
|
2019-05-08 18:56:03 +00:00
|
|
|
{
|
|
|
|
if( inDrag ) // Restore the last change
|
|
|
|
{
|
|
|
|
rollbackFromUndo();
|
2019-06-18 17:56:40 +00:00
|
|
|
inDrag = false;
|
2019-05-08 18:56:03 +00:00
|
|
|
modified = false;
|
2019-07-16 00:09:10 +00:00
|
|
|
break;
|
2019-05-08 18:56:03 +00:00
|
|
|
}
|
2019-07-01 21:01:33 +00:00
|
|
|
else if( evt->IsCancelInteractive() )
|
2021-01-26 17:46:10 +00:00
|
|
|
{
|
2019-07-01 21:01:33 +00:00
|
|
|
break;
|
2021-01-26 17:46:10 +00:00
|
|
|
}
|
2019-05-08 18:56:03 +00:00
|
|
|
|
2021-01-24 17:59:26 +00:00
|
|
|
if( evt->IsActivate() )
|
2019-07-01 21:01:33 +00:00
|
|
|
break;
|
2019-05-08 18:56:03 +00:00
|
|
|
}
|
|
|
|
else
|
2021-01-26 17:46:10 +00:00
|
|
|
{
|
2019-06-16 11:06:49 +00:00
|
|
|
evt->SetPassEvent();
|
2021-01-26 17:46:10 +00:00
|
|
|
}
|
2019-05-08 18:56:03 +00:00
|
|
|
|
|
|
|
controls->SetAutoPan( inDrag );
|
|
|
|
controls->CaptureCursor( inDrag );
|
|
|
|
}
|
|
|
|
|
|
|
|
controls->SetAutoPan( false );
|
|
|
|
controls->CaptureCursor( false );
|
2022-01-07 16:21:41 +00:00
|
|
|
setEditedPoint( nullptr );
|
2019-05-08 18:56:03 +00:00
|
|
|
|
|
|
|
if( m_editPoints )
|
|
|
|
{
|
|
|
|
view->Remove( m_editPoints.get() );
|
|
|
|
|
|
|
|
if( modified )
|
|
|
|
m_frame->OnModify();
|
|
|
|
|
|
|
|
m_editPoints.reset();
|
|
|
|
m_frame->GetCanvas()->Refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-02-07 09:06:01 +00:00
|
|
|
/**
|
2021-06-09 19:32:58 +00:00
|
|
|
* Update the coordinates of 4 corners of a rectangle, according to constraints
|
2020-02-07 09:06:01 +00:00
|
|
|
* and the moved corner
|
|
|
|
* @param minWidth is the minimal width constraint
|
|
|
|
* @param minHeight is the minimal height constraint
|
|
|
|
* @param topLeft is the RECT_TOPLEFT to constraint
|
|
|
|
* @param topRight is the RECT_TOPRIGHT to constraint
|
|
|
|
* @param botLeft is the RECT_BOTLEFT to constraint
|
|
|
|
* @param botRight is the RECT_BOTRIGHT to constraint
|
|
|
|
*/
|
2022-04-07 10:51:00 +00:00
|
|
|
void EE_POINT_EDITOR::pinEditedCorner( int minWidth, int minHeight, VECTOR2I& topLeft,
|
|
|
|
VECTOR2I& topRight, VECTOR2I& botLeft, VECTOR2I& botRight,
|
|
|
|
EE_GRID_HELPER* aGrid ) const
|
2019-05-08 18:56:03 +00:00
|
|
|
{
|
2022-04-07 10:51:00 +00:00
|
|
|
if( isModified( m_editPoints->Point( RECT_TOPLEFT ) ) )
|
2019-05-08 18:56:03 +00:00
|
|
|
{
|
|
|
|
// pin edited point within opposite corner
|
|
|
|
topLeft.x = std::min( topLeft.x, botRight.x - minWidth );
|
|
|
|
topLeft.y = std::min( topLeft.y, botRight.y - minHeight );
|
|
|
|
|
2022-10-24 10:35:51 +00:00
|
|
|
if( aGrid->GetSnap() )
|
|
|
|
topLeft = aGrid->AlignGrid( topLeft );
|
2020-02-07 09:06:01 +00:00
|
|
|
|
2019-05-08 18:56:03 +00:00
|
|
|
// push edited point edges to adjacent corners
|
|
|
|
topRight.y = topLeft.y;
|
|
|
|
botLeft.x = topLeft.x;
|
2022-04-07 10:51:00 +00:00
|
|
|
}
|
|
|
|
else if( isModified( m_editPoints->Point( RECT_TOPRIGHT ) ) )
|
|
|
|
{
|
2019-05-08 18:56:03 +00:00
|
|
|
// pin edited point within opposite corner
|
|
|
|
topRight.x = std::max( topRight.x, botLeft.x + minWidth );
|
|
|
|
topRight.y = std::min( topRight.y, botLeft.y - minHeight );
|
|
|
|
|
2022-10-24 10:35:51 +00:00
|
|
|
if( aGrid->GetSnap() )
|
|
|
|
topRight = aGrid->AlignGrid( topRight );
|
2020-02-07 09:06:01 +00:00
|
|
|
|
2019-05-08 18:56:03 +00:00
|
|
|
// push edited point edges to adjacent corners
|
|
|
|
topLeft.y = topRight.y;
|
|
|
|
botRight.x = topRight.x;
|
2022-04-07 10:51:00 +00:00
|
|
|
}
|
|
|
|
else if( isModified( m_editPoints->Point( RECT_BOTLEFT ) ) )
|
|
|
|
{
|
2019-05-08 18:56:03 +00:00
|
|
|
// pin edited point within opposite corner
|
|
|
|
botLeft.x = std::min( botLeft.x, topRight.x - minWidth );
|
|
|
|
botLeft.y = std::max( botLeft.y, topRight.y + minHeight );
|
|
|
|
|
2022-10-24 10:35:51 +00:00
|
|
|
if( aGrid->GetSnap() )
|
|
|
|
botLeft = aGrid->AlignGrid( botLeft );
|
2020-02-07 09:06:01 +00:00
|
|
|
|
2019-05-08 18:56:03 +00:00
|
|
|
// push edited point edges to adjacent corners
|
|
|
|
botRight.y = botLeft.y;
|
|
|
|
topLeft.x = botLeft.x;
|
2022-04-07 10:51:00 +00:00
|
|
|
}
|
|
|
|
else if( isModified( m_editPoints->Point( RECT_BOTRIGHT ) ) )
|
|
|
|
{
|
2019-05-08 18:56:03 +00:00
|
|
|
// pin edited point within opposite corner
|
|
|
|
botRight.x = std::max( botRight.x, topLeft.x + minWidth );
|
|
|
|
botRight.y = std::max( botRight.y, topLeft.y + minHeight );
|
|
|
|
|
2022-10-24 10:35:51 +00:00
|
|
|
if( aGrid->GetSnap() )
|
|
|
|
botRight = aGrid->AlignGrid( botRight );
|
2020-02-07 09:06:01 +00:00
|
|
|
|
2019-05-08 18:56:03 +00:00
|
|
|
// push edited point edges to adjacent corners
|
|
|
|
botLeft.y = botRight.y;
|
|
|
|
topRight.x = botRight.x;
|
2022-04-07 10:51:00 +00:00
|
|
|
}
|
|
|
|
else if( isModified( m_editPoints->Line( RECT_TOP ) ) )
|
|
|
|
{
|
|
|
|
topLeft.y = std::min( topLeft.y, botRight.y - minHeight );
|
2022-10-24 10:35:51 +00:00
|
|
|
|
|
|
|
if( aGrid->GetSnap() )
|
|
|
|
topLeft = aGrid->AlignGrid( topLeft );
|
2022-04-07 10:51:00 +00:00
|
|
|
}
|
|
|
|
else if( isModified( m_editPoints->Line( RECT_LEFT ) ) )
|
|
|
|
{
|
|
|
|
topLeft.x = std::min( topLeft.x, botRight.x - minWidth );
|
2022-10-24 10:35:51 +00:00
|
|
|
|
|
|
|
if( aGrid->GetSnap() )
|
|
|
|
topLeft = aGrid->AlignGrid( topLeft );
|
2022-04-07 10:51:00 +00:00
|
|
|
}
|
|
|
|
else if( isModified( m_editPoints->Line( RECT_BOT ) ) )
|
|
|
|
{
|
|
|
|
botRight.y = std::max( botRight.y, topLeft.y + minHeight );
|
2022-10-24 10:35:51 +00:00
|
|
|
|
|
|
|
if( aGrid->GetSnap() )
|
|
|
|
botRight = aGrid->AlignGrid( botRight );
|
2022-04-07 10:51:00 +00:00
|
|
|
}
|
|
|
|
else if( isModified( m_editPoints->Line( RECT_RIGHT ) ) )
|
|
|
|
{
|
|
|
|
botRight.x = std::max( botRight.x, topLeft.x + minWidth );
|
2022-10-24 10:35:51 +00:00
|
|
|
|
|
|
|
if( aGrid->GetSnap() )
|
|
|
|
botRight = aGrid->AlignGrid( botRight );
|
2019-05-08 18:56:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-10-24 10:35:51 +00:00
|
|
|
void EE_POINT_EDITOR::updateParentItem( bool aSnapToGrid ) const
|
2019-05-08 18:56:03 +00:00
|
|
|
{
|
|
|
|
EDA_ITEM* item = m_editPoints->GetParent();
|
|
|
|
|
|
|
|
if( !item )
|
|
|
|
return;
|
|
|
|
|
|
|
|
switch( item->Type() )
|
|
|
|
{
|
2021-07-18 23:08:54 +00:00
|
|
|
case LIB_SHAPE_T:
|
2019-05-08 18:56:03 +00:00
|
|
|
{
|
2021-07-18 23:08:54 +00:00
|
|
|
LIB_SHAPE* shape = static_cast<LIB_SHAPE*>( item );
|
2019-06-29 13:39:46 +00:00
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
switch( shape->GetShape() )
|
2019-06-29 13:39:46 +00:00
|
|
|
{
|
2021-07-18 23:08:54 +00:00
|
|
|
case SHAPE_T::ARC:
|
|
|
|
if( getEditedPointIndex() == ARC_CENTER )
|
|
|
|
{
|
|
|
|
shape->SetEditState( 4 );
|
|
|
|
shape->CalcEdit( mapCoords( m_editPoints->Point( ARC_CENTER ).GetPosition() ) );
|
|
|
|
}
|
|
|
|
else if( getEditedPointIndex() == ARC_START )
|
|
|
|
{
|
|
|
|
shape->SetEditState( 2 );
|
|
|
|
shape->CalcEdit( mapCoords( m_editPoints->Point( ARC_START ).GetPosition() ) );
|
|
|
|
}
|
|
|
|
else if( getEditedPointIndex() == ARC_END )
|
|
|
|
{
|
|
|
|
shape->SetEditState( 3 );
|
|
|
|
shape->CalcEdit( mapCoords( m_editPoints->Point( ARC_END ).GetPosition() ) );
|
|
|
|
}
|
|
|
|
break;
|
2019-05-08 18:56:03 +00:00
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
case SHAPE_T::CIRCLE:
|
|
|
|
shape->SetPosition( mapCoords( m_editPoints->Point( CIRC_CENTER ).GetPosition() ) );
|
|
|
|
shape->SetEnd( mapCoords( m_editPoints->Point( CIRC_END ).GetPosition() ) );
|
|
|
|
break;
|
2019-05-08 18:56:03 +00:00
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
case SHAPE_T::POLY:
|
|
|
|
shape->GetPolyShape().RemoveAllContours();
|
|
|
|
shape->GetPolyShape().NewOutline();
|
2019-05-08 18:56:03 +00:00
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
for( unsigned i = 0; i < m_editPoints->PointsSize(); ++i )
|
2022-01-07 16:23:39 +00:00
|
|
|
{
|
2022-01-07 16:37:37 +00:00
|
|
|
VECTOR2I pt = mapCoords( m_editPoints->Point( i ).GetPosition() );
|
2022-01-07 16:23:39 +00:00
|
|
|
shape->GetPolyShape().Append( pt.x, pt.y, -1, -1, true );
|
|
|
|
}
|
2019-05-08 18:56:03 +00:00
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
break;
|
2019-05-08 18:56:03 +00:00
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
case SHAPE_T::RECT:
|
|
|
|
{
|
2021-11-01 15:26:09 +00:00
|
|
|
EE_GRID_HELPER gridHelper( m_toolMgr );
|
|
|
|
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();
|
2019-05-08 18:56:03 +00:00
|
|
|
|
2022-10-24 10:35:51 +00:00
|
|
|
gridHelper.SetSnap( aSnapToGrid );
|
|
|
|
|
|
|
|
pinEditedCorner( schIUScale.MilsToIU( 1 ), schIUScale.MilsToIU( 1 ), topLeft, topRight,
|
|
|
|
botLeft, botRight, &gridHelper );
|
2022-04-07 10:51:00 +00:00
|
|
|
|
2022-03-27 13:23:18 +00:00
|
|
|
if( isModified( m_editPoints->Point( RECT_TOPLEFT ) )
|
|
|
|
|| isModified( m_editPoints->Point( RECT_TOPRIGHT ) )
|
|
|
|
|| isModified( m_editPoints->Point( RECT_BOTRIGHT ) )
|
|
|
|
|| isModified( m_editPoints->Point( RECT_BOTLEFT ) ) )
|
|
|
|
{
|
|
|
|
shape->SetPosition( mapCoords( topLeft ) );
|
|
|
|
shape->SetEnd( mapCoords( botRight ) );
|
|
|
|
}
|
|
|
|
else if( isModified( m_editPoints->Line( RECT_TOP ) ) )
|
|
|
|
{
|
|
|
|
shape->SetStartY( mapCoords( topLeft ).y );
|
|
|
|
}
|
|
|
|
else if( isModified( m_editPoints->Line( RECT_LEFT ) ) )
|
|
|
|
{
|
|
|
|
shape->SetStartX( mapCoords( topLeft ).x );
|
|
|
|
}
|
|
|
|
else if( isModified( m_editPoints->Line( RECT_BOT ) ) )
|
|
|
|
{
|
|
|
|
shape->SetEndY( mapCoords( botRight ).y );
|
|
|
|
}
|
|
|
|
else if( isModified( m_editPoints->Line( RECT_RIGHT ) ) )
|
|
|
|
{
|
|
|
|
shape->SetEndX( mapCoords( botRight ).x );
|
|
|
|
}
|
|
|
|
|
|
|
|
for( unsigned i = 0; i < m_editPoints->LinesSize(); ++i )
|
|
|
|
{
|
|
|
|
if( !isModified( m_editPoints->Line( i ) ) )
|
|
|
|
{
|
|
|
|
m_editPoints->Line( i ).SetConstraint(
|
|
|
|
new EC_PERPLINE( m_editPoints->Line( i ) ) );
|
|
|
|
}
|
|
|
|
}
|
2019-05-08 18:56:03 +00:00
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
break;
|
2022-01-25 22:33:37 +00:00
|
|
|
}
|
2019-05-08 18:56:03 +00:00
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
case SHAPE_T::BEZIER:
|
|
|
|
// TODO
|
|
|
|
break;
|
2019-05-08 18:56:03 +00:00
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
default:
|
2021-07-17 19:56:18 +00:00
|
|
|
UNIMPLEMENTED_FOR( shape->SHAPE_T_asString() );
|
|
|
|
}
|
2022-01-25 22:33:37 +00:00
|
|
|
|
|
|
|
break;
|
2021-07-17 19:56:18 +00:00
|
|
|
}
|
2022-01-25 22:33:37 +00:00
|
|
|
|
|
|
|
case LIB_TEXTBOX_T:
|
|
|
|
{
|
|
|
|
LIB_TEXTBOX* textbox = static_cast<LIB_TEXTBOX*>( item );
|
|
|
|
EE_GRID_HELPER gridHelper( m_toolMgr );
|
|
|
|
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-10-24 10:35:51 +00:00
|
|
|
gridHelper.SetSnap( aSnapToGrid );
|
|
|
|
|
|
|
|
pinEditedCorner( schIUScale.MilsToIU( 1 ), schIUScale.MilsToIU( 1 ), topLeft, topRight,
|
|
|
|
botLeft, botRight, &gridHelper );
|
2022-04-07 10:51:00 +00:00
|
|
|
|
2022-03-27 13:23:18 +00:00
|
|
|
if( isModified( m_editPoints->Point( RECT_TOPLEFT ) )
|
|
|
|
|| isModified( m_editPoints->Point( RECT_TOPRIGHT ) )
|
|
|
|
|| isModified( m_editPoints->Point( RECT_BOTRIGHT ) )
|
|
|
|
|| isModified( m_editPoints->Point( RECT_BOTLEFT ) ) )
|
|
|
|
{
|
|
|
|
textbox->SetPosition( mapCoords( topLeft ) );
|
|
|
|
textbox->SetEnd( mapCoords( botRight ) );
|
|
|
|
}
|
|
|
|
else if( isModified( m_editPoints->Line( RECT_TOP ) ) )
|
|
|
|
{
|
|
|
|
textbox->SetStartY( mapCoords( topLeft ).y );
|
|
|
|
}
|
|
|
|
else if( isModified( m_editPoints->Line( RECT_LEFT ) ) )
|
|
|
|
{
|
|
|
|
textbox->SetStartX( mapCoords( topLeft ).x );
|
|
|
|
}
|
|
|
|
else if( isModified( m_editPoints->Line( RECT_BOT ) ) )
|
|
|
|
{
|
|
|
|
textbox->SetEndY( mapCoords( botRight ).y );
|
|
|
|
}
|
|
|
|
else if( isModified( m_editPoints->Line( RECT_RIGHT ) ) )
|
|
|
|
{
|
|
|
|
textbox->SetEndX( mapCoords( botRight ).x );
|
|
|
|
}
|
|
|
|
|
|
|
|
for( unsigned i = 0; i < m_editPoints->LinesSize(); ++i )
|
|
|
|
{
|
|
|
|
if( !isModified( m_editPoints->Line( i ) ) )
|
|
|
|
{
|
|
|
|
m_editPoints->Line( i ).SetConstraint(
|
|
|
|
new EC_PERPLINE( m_editPoints->Line( i ) ) );
|
|
|
|
}
|
|
|
|
}
|
2022-01-25 22:33:37 +00:00
|
|
|
|
2022-03-30 14:19:48 +00:00
|
|
|
textbox->ClearRenderCache();
|
2021-07-17 19:56:18 +00:00
|
|
|
break;
|
2022-01-25 22:33:37 +00:00
|
|
|
}
|
2021-07-17 19:56:18 +00:00
|
|
|
|
|
|
|
case SCH_SHAPE_T:
|
|
|
|
{
|
|
|
|
SCH_SHAPE* shape = static_cast<SCH_SHAPE*>( item );
|
|
|
|
|
|
|
|
switch( shape->GetShape() )
|
|
|
|
{
|
|
|
|
case SHAPE_T::ARC:
|
|
|
|
if( getEditedPointIndex() == ARC_CENTER )
|
|
|
|
{
|
|
|
|
shape->SetEditState( 4 );
|
2022-01-01 17:11:21 +00:00
|
|
|
shape->CalcEdit( m_editPoints->Point( ARC_CENTER ).GetPosition() );
|
2021-07-17 19:56:18 +00:00
|
|
|
}
|
|
|
|
else if( getEditedPointIndex() == ARC_START )
|
|
|
|
{
|
|
|
|
shape->SetEditState( 2 );
|
2022-01-01 17:11:21 +00:00
|
|
|
shape->CalcEdit( m_editPoints->Point( ARC_START ).GetPosition() );
|
2021-07-17 19:56:18 +00:00
|
|
|
}
|
|
|
|
else if( getEditedPointIndex() == ARC_END )
|
|
|
|
{
|
|
|
|
shape->SetEditState( 3 );
|
2022-01-01 17:11:21 +00:00
|
|
|
shape->CalcEdit( m_editPoints->Point( ARC_END ).GetPosition() );
|
2021-07-17 19:56:18 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SHAPE_T::CIRCLE:
|
2022-01-01 17:11:21 +00:00
|
|
|
shape->SetPosition( m_editPoints->Point( CIRC_CENTER ).GetPosition() );
|
|
|
|
shape->SetEnd( m_editPoints->Point( CIRC_END ).GetPosition() );
|
2021-07-17 19:56:18 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SHAPE_T::POLY:
|
|
|
|
shape->GetPolyShape().RemoveAllContours();
|
|
|
|
shape->GetPolyShape().NewOutline();
|
|
|
|
|
|
|
|
for( unsigned i = 0; i < m_editPoints->PointsSize(); ++i )
|
2022-01-07 16:29:34 +00:00
|
|
|
{
|
|
|
|
VECTOR2I pt = m_editPoints->Point( i ).GetPosition();
|
|
|
|
shape->GetPolyShape().Append( pt.x, pt.y, -1, -1, true );
|
|
|
|
}
|
2021-07-17 19:56:18 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SHAPE_T::RECT:
|
|
|
|
{
|
|
|
|
EE_GRID_HELPER gridHelper( m_toolMgr );
|
|
|
|
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-10-24 10:35:51 +00:00
|
|
|
gridHelper.SetSnap( aSnapToGrid );
|
|
|
|
|
|
|
|
pinEditedCorner( schIUScale.MilsToIU( 1 ), schIUScale.MilsToIU( 1 ), topLeft, topRight,
|
|
|
|
botLeft, botRight, &gridHelper );
|
2022-04-07 10:51:00 +00:00
|
|
|
|
2022-03-27 13:23:18 +00:00
|
|
|
if( isModified( m_editPoints->Point( RECT_TOPLEFT ) )
|
|
|
|
|| isModified( m_editPoints->Point( RECT_TOPRIGHT ) )
|
|
|
|
|| isModified( m_editPoints->Point( RECT_BOTRIGHT ) )
|
|
|
|
|| isModified( m_editPoints->Point( RECT_BOTLEFT ) ) )
|
|
|
|
{
|
|
|
|
shape->SetPosition( topLeft );
|
|
|
|
shape->SetEnd( botRight );
|
|
|
|
}
|
|
|
|
else if( isModified( m_editPoints->Line( RECT_TOP ) ) )
|
|
|
|
{
|
|
|
|
shape->SetStartY( topLeft.y );
|
|
|
|
}
|
|
|
|
else if( isModified( m_editPoints->Line( RECT_LEFT ) ) )
|
|
|
|
{
|
|
|
|
shape->SetStartX( topLeft.x );
|
|
|
|
}
|
|
|
|
else if( isModified( m_editPoints->Line( RECT_BOT ) ) )
|
|
|
|
{
|
|
|
|
shape->SetEndY( botRight.y );
|
|
|
|
}
|
|
|
|
else if( isModified( m_editPoints->Line( RECT_RIGHT ) ) )
|
|
|
|
{
|
|
|
|
shape->SetEndX( botRight.x );
|
|
|
|
}
|
|
|
|
|
|
|
|
for( unsigned i = 0; i < m_editPoints->LinesSize(); ++i )
|
|
|
|
{
|
|
|
|
if( !isModified( m_editPoints->Line( i ) ) )
|
|
|
|
{
|
|
|
|
m_editPoints->Line( i ).SetConstraint(
|
|
|
|
new EC_PERPLINE( m_editPoints->Line( i ) ) );
|
|
|
|
}
|
|
|
|
}
|
2021-07-17 19:56:18 +00:00
|
|
|
|
|
|
|
break;
|
2022-01-25 22:33:37 +00:00
|
|
|
}
|
2021-07-17 19:56:18 +00:00
|
|
|
|
|
|
|
case SHAPE_T::BEZIER:
|
|
|
|
// TODO
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
UNIMPLEMENTED_FOR( shape->SHAPE_T_asString() );
|
2021-07-18 23:08:54 +00:00
|
|
|
}
|
2022-01-25 22:33:37 +00:00
|
|
|
|
|
|
|
break;
|
2019-05-08 18:56:03 +00:00
|
|
|
}
|
2022-01-25 22:33:37 +00:00
|
|
|
|
|
|
|
case SCH_TEXTBOX_T:
|
|
|
|
{
|
|
|
|
SCH_TEXTBOX* textBox = static_cast<SCH_TEXTBOX*>( item );
|
|
|
|
EE_GRID_HELPER gridHelper( m_toolMgr );
|
|
|
|
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-10-24 10:35:51 +00:00
|
|
|
gridHelper.SetSnap( aSnapToGrid );
|
|
|
|
|
|
|
|
pinEditedCorner( schIUScale.MilsToIU( 1 ), schIUScale.MilsToIU( 1 ), topLeft, topRight,
|
|
|
|
botLeft, botRight, &gridHelper );
|
2022-04-07 10:51:00 +00:00
|
|
|
|
2022-03-27 13:23:18 +00:00
|
|
|
if( isModified( m_editPoints->Point( RECT_TOPLEFT ) )
|
|
|
|
|| isModified( m_editPoints->Point( RECT_TOPRIGHT ) )
|
|
|
|
|| isModified( m_editPoints->Point( RECT_BOTRIGHT ) )
|
|
|
|
|| isModified( m_editPoints->Point( RECT_BOTLEFT ) ) )
|
|
|
|
{
|
|
|
|
textBox->SetPosition( topLeft );
|
|
|
|
textBox->SetEnd( botRight );
|
|
|
|
}
|
|
|
|
else if( isModified( m_editPoints->Line( RECT_TOP ) ) )
|
|
|
|
{
|
|
|
|
textBox->SetStartY( topLeft.y );
|
|
|
|
}
|
|
|
|
else if( isModified( m_editPoints->Line( RECT_LEFT ) ) )
|
|
|
|
{
|
|
|
|
textBox->SetStartX( topLeft.x );
|
|
|
|
}
|
|
|
|
else if( isModified( m_editPoints->Line( RECT_BOT ) ) )
|
|
|
|
{
|
|
|
|
textBox->SetEndY( botRight.y );
|
|
|
|
}
|
|
|
|
else if( isModified( m_editPoints->Line( RECT_RIGHT ) ) )
|
|
|
|
{
|
|
|
|
textBox->SetEndX( botRight.x );
|
|
|
|
}
|
|
|
|
|
|
|
|
for( unsigned i = 0; i < m_editPoints->LinesSize(); ++i )
|
|
|
|
{
|
|
|
|
if( !isModified( m_editPoints->Line( i ) ) )
|
|
|
|
{
|
|
|
|
m_editPoints->Line( i ).SetConstraint(
|
|
|
|
new EC_PERPLINE( m_editPoints->Line( i ) ) );
|
|
|
|
}
|
|
|
|
}
|
2022-01-25 22:33:37 +00:00
|
|
|
|
2022-03-30 14:19:48 +00:00
|
|
|
textBox->ClearRenderCache();
|
2021-07-18 23:08:54 +00:00
|
|
|
break;
|
2022-01-25 22:33:37 +00:00
|
|
|
}
|
2019-05-08 18:56:03 +00:00
|
|
|
|
2019-06-19 10:31:21 +00:00
|
|
|
case SCH_BITMAP_T:
|
|
|
|
{
|
2021-11-01 15:26:09 +00:00
|
|
|
EE_GRID_HELPER gridHelper( m_toolMgr );
|
|
|
|
SCH_BITMAP* bitmap = (SCH_BITMAP*) item;
|
|
|
|
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();
|
2019-06-19 10:31:21 +00:00
|
|
|
|
2022-10-24 10:35:51 +00:00
|
|
|
gridHelper.SetSnap( aSnapToGrid );
|
|
|
|
|
|
|
|
pinEditedCorner( schIUScale.MilsToIU( 50 ), schIUScale.MilsToIU( 50 ), topLeft, topRight,
|
|
|
|
botLeft, botRight, &gridHelper );
|
2019-06-19 10:31:21 +00:00
|
|
|
|
|
|
|
double oldWidth = bitmap->GetSize().x;
|
|
|
|
double newWidth = topRight.x - topLeft.x;
|
|
|
|
double widthRatio = newWidth / oldWidth;
|
|
|
|
|
|
|
|
double oldHeight = bitmap->GetSize().y;
|
|
|
|
double newHeight = botLeft.y - topLeft.y;
|
|
|
|
double heightRatio = newHeight / oldHeight;
|
|
|
|
|
|
|
|
bitmap->SetImageScale( bitmap->GetImageScale() * std::min( widthRatio, heightRatio ) );
|
2021-07-18 23:08:54 +00:00
|
|
|
break;
|
2022-01-25 22:33:37 +00:00
|
|
|
}
|
2019-06-19 10:31:21 +00:00
|
|
|
|
2019-05-08 18:56:03 +00:00
|
|
|
case SCH_SHEET_T:
|
|
|
|
{
|
2021-11-01 15:26:09 +00:00
|
|
|
SCH_SHEET* sheet = (SCH_SHEET*) item;
|
|
|
|
EE_GRID_HELPER gridHelper( m_toolMgr );
|
|
|
|
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();
|
|
|
|
int edited = getEditedPointIndex();
|
2021-03-16 20:00:07 +00:00
|
|
|
|
2022-07-23 22:57:04 +00:00
|
|
|
if( isModified( m_editPoints->Line( RECT_RIGHT ) ) )
|
|
|
|
edited = RECT_TOPRIGHT;
|
|
|
|
else if( isModified( m_editPoints->Line( RECT_BOT ) ) )
|
|
|
|
edited = RECT_BOTLEFT;
|
|
|
|
|
2022-10-24 10:35:51 +00:00
|
|
|
gridHelper.SetSnap( aSnapToGrid );
|
|
|
|
|
2022-04-07 10:51:00 +00:00
|
|
|
pinEditedCorner( sheet->GetMinWidth( edited == RECT_TOPRIGHT || edited == RECT_BOTRIGHT ),
|
2021-03-16 20:00:07 +00:00
|
|
|
sheet->GetMinHeight( edited == RECT_BOTLEFT || edited == RECT_BOTRIGHT ),
|
2021-11-01 15:26:09 +00:00
|
|
|
topLeft, topRight, botLeft, botRight, &gridHelper );
|
2019-05-08 18:56:03 +00:00
|
|
|
|
2020-10-31 11:48:29 +00:00
|
|
|
// Pin positions are relative to origin. Attempt to leave them where they
|
|
|
|
// are if the origin moves.
|
2022-01-01 17:11:21 +00:00
|
|
|
VECTOR2I originDelta = sheet->GetPosition() - topLeft;
|
2020-10-31 11:48:29 +00:00
|
|
|
|
2022-07-23 22:57:04 +00:00
|
|
|
if( isModified( m_editPoints->Point( RECT_TOPLEFT ) )
|
|
|
|
|| isModified( m_editPoints->Point( RECT_TOPRIGHT ) )
|
|
|
|
|| isModified( m_editPoints->Point( RECT_BOTRIGHT ) )
|
|
|
|
|| isModified( m_editPoints->Point( RECT_BOTLEFT ) ) )
|
|
|
|
{
|
|
|
|
sheet->SetPosition( topLeft );
|
|
|
|
sheet->SetSize( wxSize( botRight.x - topLeft.x, botRight.y - topLeft.y ) );
|
|
|
|
}
|
|
|
|
else if( isModified( m_editPoints->Line( RECT_TOP ) ) )
|
|
|
|
{
|
|
|
|
sheet->SetPosition( VECTOR2I( sheet->GetPosition().x, topLeft.y ) );
|
|
|
|
sheet->SetSize( wxSize( sheet->GetSize().x, botRight.y - topLeft.y ) );
|
|
|
|
}
|
|
|
|
else if( isModified( m_editPoints->Line( RECT_LEFT ) ) )
|
|
|
|
{
|
|
|
|
sheet->SetPosition( VECTOR2I( topLeft.x, sheet->GetPosition().y ) );
|
|
|
|
sheet->SetSize( wxSize( botRight.x - topLeft.x, sheet->GetSize().y ) );
|
|
|
|
}
|
|
|
|
else if( isModified( m_editPoints->Line( RECT_BOT ) ) )
|
|
|
|
{
|
|
|
|
sheet->SetSize( wxSize( sheet->GetSize().x, botRight.y - topLeft.y ) );
|
|
|
|
}
|
|
|
|
else if( isModified( m_editPoints->Line( RECT_RIGHT ) ) )
|
|
|
|
{
|
|
|
|
sheet->SetSize( wxSize( botRight.x - topLeft.x, sheet->GetSize().y ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
for( unsigned i = 0; i < m_editPoints->LinesSize(); ++i )
|
|
|
|
{
|
|
|
|
if( !isModified( m_editPoints->Line( i ) ) )
|
|
|
|
{
|
|
|
|
m_editPoints->Line( i ).SetConstraint(
|
|
|
|
new EC_PERPLINE( m_editPoints->Line( i ) ) );
|
|
|
|
}
|
|
|
|
}
|
2019-05-16 21:27:03 +00:00
|
|
|
|
2020-03-06 12:05:21 +00:00
|
|
|
// Update the fields if we're in autoplace mode
|
|
|
|
if( sheet->GetFieldsAutoplaced() == FIELDS_AUTOPLACED_AUTO )
|
2021-07-16 20:13:26 +00:00
|
|
|
sheet->AutoplaceFields( /* aScreen */ nullptr, /* aManual */ false );
|
2020-03-06 12:05:21 +00:00
|
|
|
|
2019-05-16 21:27:03 +00:00
|
|
|
// Keep sheet pins attached to edges:
|
2020-01-12 18:40:50 +00:00
|
|
|
for( SCH_SHEET_PIN* pin : sheet->GetPins() )
|
2019-05-16 21:27:03 +00:00
|
|
|
{
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I pos = pin->GetPosition();
|
2019-05-16 21:27:03 +00:00
|
|
|
|
2020-10-31 11:48:29 +00:00
|
|
|
pos += originDelta;
|
|
|
|
|
2021-11-28 19:06:08 +00:00
|
|
|
switch( pin->GetSide() )
|
2019-05-16 21:27:03 +00:00
|
|
|
{
|
2021-11-01 15:26:09 +00:00
|
|
|
case SHEET_SIDE::LEFT: pos.x = topLeft.x; break;
|
|
|
|
case SHEET_SIDE::RIGHT: pos.x = topRight.x; break;
|
|
|
|
case SHEET_SIDE::TOP: pos.y = topLeft.y; break;
|
|
|
|
case SHEET_SIDE::BOTTOM: pos.y = botLeft.y; break;
|
|
|
|
case SHEET_SIDE::UNDEFINED: break;
|
2019-05-16 21:27:03 +00:00
|
|
|
}
|
|
|
|
|
2020-01-12 18:40:50 +00:00
|
|
|
pin->SetPosition( pos );
|
2019-05-16 21:27:03 +00:00
|
|
|
}
|
2022-01-25 22:33:37 +00:00
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
break;
|
2022-01-25 22:33:37 +00:00
|
|
|
}
|
2019-05-08 18:56:03 +00:00
|
|
|
|
|
|
|
case SCH_LINE_T:
|
|
|
|
{
|
|
|
|
SCH_LINE* line = (SCH_LINE*) item;
|
|
|
|
|
2022-01-01 17:11:21 +00:00
|
|
|
line->SetStartPoint( m_editPoints->Point( LINE_START ).GetPosition() );
|
|
|
|
line->SetEndPoint( m_editPoints->Point( LINE_END ).GetPosition() );
|
2019-05-08 18:56:03 +00:00
|
|
|
|
2020-11-30 19:27:31 +00:00
|
|
|
std::pair<EDA_ITEM*, int> connected = m_editPoints->Point( LINE_START ).GetConnected();
|
2019-05-08 18:56:03 +00:00
|
|
|
|
2020-11-30 19:27:31 +00:00
|
|
|
if( connected.first )
|
2019-05-08 18:56:03 +00:00
|
|
|
{
|
2020-11-30 19:27:31 +00:00
|
|
|
if( connected.second == STARTPOINT )
|
2022-03-03 14:35:57 +00:00
|
|
|
static_cast<SCH_LINE*>( connected.first )->SetStartPoint( line->GetStartPoint() );
|
2020-11-30 19:27:31 +00:00
|
|
|
else if( connected.second == ENDPOINT )
|
2022-03-03 14:35:57 +00:00
|
|
|
static_cast<SCH_LINE*>( connected.first )->SetEndPoint( line->GetStartPoint() );
|
2019-05-08 18:56:03 +00:00
|
|
|
|
2021-12-22 12:59:40 +00:00
|
|
|
updateItem( connected.first, true );
|
2019-05-08 18:56:03 +00:00
|
|
|
}
|
|
|
|
|
2020-11-30 19:27:31 +00:00
|
|
|
connected = m_editPoints->Point( LINE_END ).GetConnected();
|
2019-05-08 18:56:03 +00:00
|
|
|
|
2020-11-30 19:27:31 +00:00
|
|
|
if( connected.first )
|
2019-05-08 18:56:03 +00:00
|
|
|
{
|
2020-11-30 19:27:31 +00:00
|
|
|
if( connected.second == STARTPOINT )
|
|
|
|
static_cast<SCH_LINE*>( connected.first )->SetStartPoint( line->GetEndPoint() );
|
|
|
|
else if( connected.second == ENDPOINT )
|
|
|
|
static_cast<SCH_LINE*>( connected.first )->SetEndPoint( line->GetEndPoint() );
|
2019-05-08 18:56:03 +00:00
|
|
|
|
2021-12-22 12:59:40 +00:00
|
|
|
updateItem( connected.first, true );
|
2019-05-08 18:56:03 +00:00
|
|
|
}
|
2022-01-25 22:33:37 +00:00
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
break;
|
2022-01-25 22:33:37 +00:00
|
|
|
}
|
2019-05-08 18:56:03 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-10-30 15:15:20 +00:00
|
|
|
updateItem( item, true );
|
2019-05-08 18:56:03 +00:00
|
|
|
m_frame->SetMsgPanel( item );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
void EE_POINT_EDITOR::updatePoints()
|
2019-05-08 18:56:03 +00:00
|
|
|
{
|
|
|
|
if( !m_editPoints )
|
|
|
|
return;
|
|
|
|
|
|
|
|
EDA_ITEM* item = m_editPoints->GetParent();
|
|
|
|
|
|
|
|
if( !item )
|
|
|
|
return;
|
|
|
|
|
|
|
|
switch( item->Type() )
|
|
|
|
{
|
2021-07-18 23:08:54 +00:00
|
|
|
case LIB_SHAPE_T:
|
2019-05-08 18:56:03 +00:00
|
|
|
{
|
2021-07-18 23:08:54 +00:00
|
|
|
LIB_SHAPE* shape = static_cast<LIB_SHAPE*>( item );
|
2019-05-08 18:56:03 +00:00
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
switch( shape->GetShape() )
|
|
|
|
{
|
|
|
|
case SHAPE_T::ARC:
|
|
|
|
m_editPoints->Point( ARC_CENTER ).SetPosition( mapCoords( shape->GetPosition() ) );
|
|
|
|
m_editPoints->Point( ARC_START ).SetPosition( mapCoords( shape->GetStart() ) );
|
|
|
|
m_editPoints->Point( ARC_END ).SetPosition( mapCoords( shape->GetEnd() ) );
|
|
|
|
break;
|
2019-05-08 18:56:03 +00:00
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
case SHAPE_T::CIRCLE:
|
|
|
|
m_editPoints->Point( CIRC_CENTER ).SetPosition( mapCoords( shape->GetPosition() ) );
|
|
|
|
m_editPoints->Point( CIRC_END ).SetPosition( mapCoords( shape->GetEnd() ) );
|
|
|
|
break;
|
2019-05-08 18:56:03 +00:00
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
case SHAPE_T::POLY:
|
|
|
|
{
|
|
|
|
if( (int) m_editPoints->PointsSize() != shape->GetPointCount() )
|
|
|
|
{
|
|
|
|
getView()->Remove( m_editPoints.get() );
|
|
|
|
m_editedPoint = nullptr;
|
|
|
|
m_editPoints = EDIT_POINTS_FACTORY::Make( item, m_frame );
|
|
|
|
getView()->Add( m_editPoints.get() );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int ii = 0;
|
2019-05-08 18:56:03 +00:00
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
for( const VECTOR2I& pt : shape->GetPolyShape().Outline( 0 ).CPoints() )
|
|
|
|
m_editPoints->Point( ii++ ).SetPosition( mapCoords( pt ) );
|
|
|
|
}
|
2019-05-08 18:56:03 +00:00
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
break;
|
2019-05-08 18:56:03 +00:00
|
|
|
}
|
2021-07-18 23:08:54 +00:00
|
|
|
|
|
|
|
case SHAPE_T::RECT:
|
2019-05-08 18:56:03 +00:00
|
|
|
{
|
2021-07-18 23:08:54 +00:00
|
|
|
// point editor works only with rectangles having width and height > 0
|
|
|
|
// Some symbols can have rectangles with width or height < 0
|
|
|
|
// So normalize the size:
|
|
|
|
BOX2I dummy;
|
|
|
|
dummy.SetOrigin( mapCoords( shape->GetPosition() ) );
|
|
|
|
dummy.SetEnd( mapCoords( shape->GetEnd() ) );
|
|
|
|
dummy.Normalize();
|
|
|
|
VECTOR2I topLeft = dummy.GetPosition();
|
|
|
|
VECTOR2I botRight = dummy.GetEnd();
|
2019-05-08 18:56:03 +00:00
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
m_editPoints->Point( RECT_TOPLEFT ).SetPosition( 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( botRight );
|
|
|
|
break;
|
2022-01-25 22:33:37 +00:00
|
|
|
}
|
2019-05-08 18:56:03 +00:00
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
case SHAPE_T::BEZIER:
|
|
|
|
// TODO
|
|
|
|
break;
|
2019-07-26 08:40:40 +00:00
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
default:
|
2021-07-17 19:56:18 +00:00
|
|
|
UNIMPLEMENTED_FOR( shape->SHAPE_T_asString() );
|
|
|
|
}
|
2022-01-25 22:33:37 +00:00
|
|
|
|
|
|
|
break;
|
2021-07-17 19:56:18 +00:00
|
|
|
}
|
2022-01-25 22:33:37 +00:00
|
|
|
|
|
|
|
case LIB_TEXTBOX_T:
|
|
|
|
{
|
|
|
|
LIB_TEXTBOX* textbox = static_cast<LIB_TEXTBOX*>( item );
|
|
|
|
|
|
|
|
// point editor works only with rectangles having width and height > 0
|
|
|
|
// Some symbols can have rectangles with width or height < 0
|
|
|
|
// So normalize the size:
|
|
|
|
BOX2I dummy;
|
|
|
|
dummy.SetOrigin( mapCoords( textbox->GetPosition() ) );
|
|
|
|
dummy.SetEnd( mapCoords( textbox->GetEnd() ) );
|
|
|
|
dummy.Normalize();
|
|
|
|
VECTOR2I topLeft = dummy.GetPosition();
|
|
|
|
VECTOR2I botRight = dummy.GetEnd();
|
|
|
|
|
|
|
|
m_editPoints->Point( RECT_TOPLEFT ).SetPosition( 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( botRight );
|
2021-07-17 19:56:18 +00:00
|
|
|
break;
|
2022-01-25 22:33:37 +00:00
|
|
|
}
|
2021-07-17 19:56:18 +00:00
|
|
|
|
|
|
|
case SCH_SHAPE_T:
|
|
|
|
{
|
|
|
|
SCH_SHAPE* shape = static_cast<SCH_SHAPE*>( item );
|
|
|
|
|
|
|
|
switch( shape->GetShape() )
|
|
|
|
{
|
|
|
|
case SHAPE_T::ARC:
|
|
|
|
m_editPoints->Point( ARC_CENTER ).SetPosition( shape->GetPosition() );
|
|
|
|
m_editPoints->Point( ARC_START ).SetPosition( shape->GetStart() );
|
|
|
|
m_editPoints->Point( ARC_END ).SetPosition( shape->GetEnd() );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SHAPE_T::CIRCLE:
|
|
|
|
m_editPoints->Point( CIRC_CENTER ).SetPosition( shape->GetPosition() );
|
|
|
|
m_editPoints->Point( CIRC_END ).SetPosition( shape->GetEnd() );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SHAPE_T::POLY:
|
|
|
|
{
|
|
|
|
if( (int) m_editPoints->PointsSize() != shape->GetPointCount() )
|
|
|
|
{
|
|
|
|
getView()->Remove( m_editPoints.get() );
|
|
|
|
m_editedPoint = nullptr;
|
|
|
|
m_editPoints = EDIT_POINTS_FACTORY::Make( item, m_frame );
|
|
|
|
getView()->Add( m_editPoints.get() );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int ii = 0;
|
|
|
|
|
|
|
|
for( const VECTOR2I& pt : shape->GetPolyShape().Outline( 0 ).CPoints() )
|
|
|
|
m_editPoints->Point( ii++ ).SetPosition( pt );
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case SHAPE_T::RECT:
|
|
|
|
{
|
|
|
|
// point editor works only with rectangles having width and height > 0
|
|
|
|
// Some symbols can have rectangles with width or height < 0
|
|
|
|
// So normalize the size:
|
|
|
|
BOX2I dummy;
|
|
|
|
dummy.SetOrigin( shape->GetPosition() );
|
|
|
|
dummy.SetEnd( shape->GetEnd() );
|
|
|
|
dummy.Normalize();
|
|
|
|
VECTOR2I topLeft = dummy.GetPosition();
|
|
|
|
VECTOR2I botRight = dummy.GetEnd();
|
|
|
|
|
|
|
|
m_editPoints->Point( RECT_TOPLEFT ).SetPosition( 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( botRight );
|
|
|
|
break;
|
2022-01-25 22:33:37 +00:00
|
|
|
}
|
2021-07-17 19:56:18 +00:00
|
|
|
|
|
|
|
case SHAPE_T::BEZIER:
|
|
|
|
// TODO
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
UNIMPLEMENTED_FOR( shape->SHAPE_T_asString() );
|
2021-07-18 23:08:54 +00:00
|
|
|
}
|
2022-01-25 22:33:37 +00:00
|
|
|
|
|
|
|
break;
|
2019-05-08 18:56:03 +00:00
|
|
|
}
|
2022-01-25 22:33:37 +00:00
|
|
|
|
|
|
|
case SCH_TEXTBOX_T:
|
|
|
|
{
|
|
|
|
SCH_TEXTBOX* textBox = static_cast<SCH_TEXTBOX*>( item );
|
|
|
|
|
|
|
|
// point editor works only with rectangles having width and height > 0
|
|
|
|
// Some symbols can have rectangles with width or height < 0
|
|
|
|
// So normalize the size:
|
|
|
|
BOX2I dummy;
|
|
|
|
dummy.SetOrigin( textBox->GetPosition() );
|
|
|
|
dummy.SetEnd( textBox->GetEnd() );
|
|
|
|
dummy.Normalize();
|
|
|
|
VECTOR2I topLeft = dummy.GetPosition();
|
|
|
|
VECTOR2I botRight = dummy.GetEnd();
|
|
|
|
|
|
|
|
m_editPoints->Point( RECT_TOPLEFT ).SetPosition( 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( botRight );
|
2021-07-18 23:08:54 +00:00
|
|
|
break;
|
2022-01-25 22:33:37 +00:00
|
|
|
}
|
2019-05-08 18:56:03 +00:00
|
|
|
|
2019-06-19 10:31:21 +00:00
|
|
|
case SCH_BITMAP_T:
|
|
|
|
{
|
|
|
|
SCH_BITMAP* bitmap = (SCH_BITMAP*) item;
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I topLeft = bitmap->GetPosition() - bitmap->GetSize() / 2;
|
|
|
|
VECTOR2I botRight = bitmap->GetPosition() + bitmap->GetSize() / 2;
|
2019-06-19 10:31:21 +00:00
|
|
|
|
|
|
|
m_editPoints->Point( RECT_TOPLEFT ).SetPosition( topLeft );
|
|
|
|
m_editPoints->Point( RECT_TOPRIGHT ).SetPosition( botRight.x, topLeft.y );
|
|
|
|
m_editPoints->Point( RECT_BOTLEFT ).SetPosition( topLeft.x, botRight.y );
|
|
|
|
m_editPoints->Point( RECT_BOTRIGHT ).SetPosition( botRight );
|
2021-07-18 23:08:54 +00:00
|
|
|
break;
|
2022-01-25 22:33:37 +00:00
|
|
|
}
|
2019-06-19 10:31:21 +00:00
|
|
|
|
2019-05-08 18:56:03 +00:00
|
|
|
case SCH_SHEET_T:
|
|
|
|
{
|
|
|
|
SCH_SHEET* sheet = (SCH_SHEET*) item;
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I topLeft = sheet->GetPosition();
|
|
|
|
VECTOR2I botRight = sheet->GetPosition() + sheet->GetSize();
|
2019-05-08 18:56:03 +00:00
|
|
|
|
|
|
|
m_editPoints->Point( RECT_TOPLEFT ).SetPosition( topLeft );
|
|
|
|
m_editPoints->Point( RECT_TOPRIGHT ).SetPosition( botRight.x, topLeft.y );
|
|
|
|
m_editPoints->Point( RECT_BOTLEFT ).SetPosition( topLeft.x, botRight.y );
|
|
|
|
m_editPoints->Point( RECT_BOTRIGHT ).SetPosition( botRight );
|
2021-07-18 23:08:54 +00:00
|
|
|
break;
|
2022-01-25 22:33:37 +00:00
|
|
|
}
|
2019-05-08 18:56:03 +00:00
|
|
|
|
|
|
|
case SCH_LINE_T:
|
|
|
|
{
|
|
|
|
SCH_LINE* line = (SCH_LINE*) item;
|
|
|
|
|
|
|
|
m_editPoints->Point( LINE_START ).SetPosition( line->GetStartPoint() );
|
|
|
|
m_editPoints->Point( LINE_END ).SetPosition( line->GetEndPoint() );
|
2021-07-18 23:08:54 +00:00
|
|
|
break;
|
2022-01-25 22:33:37 +00:00
|
|
|
}
|
2019-05-08 18:56:03 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
getView()->Update( m_editPoints.get() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
void EE_POINT_EDITOR::setEditedPoint( EDIT_POINT* aPoint )
|
2019-05-08 18:56:03 +00:00
|
|
|
{
|
|
|
|
KIGFX::VIEW_CONTROLS* controls = getViewControls();
|
|
|
|
|
|
|
|
if( aPoint )
|
|
|
|
{
|
2020-10-08 00:50:28 +00:00
|
|
|
m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::ARROW );
|
2019-05-08 18:56:03 +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-08 18:56:03 +00:00
|
|
|
controls->ForceCursorPosition( false );
|
|
|
|
}
|
|
|
|
|
|
|
|
m_editedPoint = aPoint;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
bool EE_POINT_EDITOR::removeCornerCondition( const SELECTION& )
|
2019-05-08 18:56:03 +00:00
|
|
|
{
|
2021-07-18 23:08:54 +00:00
|
|
|
if( !m_editPoints || !m_editedPoint || m_editPoints->GetParent()->Type() != LIB_SHAPE_T )
|
2019-05-08 18:56:03 +00:00
|
|
|
return false;
|
|
|
|
|
2021-10-30 17:09:59 +00:00
|
|
|
LIB_SHAPE* shape = static_cast<LIB_SHAPE*>( m_editPoints->GetParent() );
|
|
|
|
|
|
|
|
if( shape->GetPolyShape().IsEmpty() )
|
|
|
|
return false;
|
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
SHAPE_LINE_CHAIN& poly = shape->GetPolyShape().Outline( 0 );
|
2019-05-08 18:56:03 +00:00
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
if( poly.GetPointCount() < 3 )
|
2019-05-08 18:56:03 +00:00
|
|
|
return false;
|
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
for( const VECTOR2I& pt : poly.CPoints() )
|
2019-05-08 18:56:03 +00:00
|
|
|
{
|
2021-07-18 23:08:54 +00:00
|
|
|
if( pt == mapCoords( m_editedPoint->GetPosition() ) )
|
2019-05-08 18:56:03 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
bool EE_POINT_EDITOR::addCornerCondition( const SELECTION& )
|
2019-05-08 18:56:03 +00:00
|
|
|
{
|
2021-07-18 23:08:54 +00:00
|
|
|
if( !m_editPoints || m_editPoints->GetParent()->Type() != LIB_SHAPE_T )
|
2019-05-08 18:56:03 +00:00
|
|
|
return false;
|
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
LIB_SHAPE* shape = static_cast<LIB_SHAPE*>( m_editPoints->GetParent() );
|
2019-05-08 18:56:03 +00:00
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
if( shape->GetShape() != SHAPE_T::POLY )
|
2019-05-08 18:56:03 +00:00
|
|
|
return false;
|
|
|
|
|
2022-10-24 10:35:51 +00:00
|
|
|
VECTOR2I cursorPos = getViewControls()->GetCursorPosition( false );
|
2019-05-08 18:56:03 +00:00
|
|
|
double threshold = getView()->ToWorld( EDIT_POINT::POINT_SIZE );
|
|
|
|
|
2022-01-01 17:11:21 +00:00
|
|
|
return shape->HitTest( cursorPos, (int) threshold );
|
2019-05-08 18:56:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
int EE_POINT_EDITOR::addCorner( const TOOL_EVENT& aEvent )
|
2019-05-08 18:56:03 +00:00
|
|
|
{
|
2021-07-18 23:08:54 +00:00
|
|
|
if( !m_editPoints || m_editPoints->GetParent()->Type() != LIB_SHAPE_T )
|
2019-05-08 18:56:03 +00:00
|
|
|
return 0;
|
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
LIB_SHAPE* shape = static_cast<LIB_SHAPE*>( m_editPoints->GetParent() );
|
|
|
|
SHAPE_LINE_CHAIN& poly = shape->GetPolyShape().Outline( 0 );
|
2019-05-08 18:56:03 +00:00
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
VECTOR2I cursor = getViewControls()->GetCursorPosition( !aEvent.DisableGridSnapping() );
|
2022-01-01 17:11:21 +00:00
|
|
|
VECTOR2I pos = mapCoords( cursor );
|
2021-07-18 23:08:54 +00:00
|
|
|
int currentMinDistance = INT_MAX;
|
|
|
|
int closestLineStart = 0;
|
|
|
|
|
|
|
|
for( unsigned i = 0; i < poly.GetPointCount() - 1; ++i )
|
|
|
|
{
|
2022-01-01 17:11:21 +00:00
|
|
|
int distance = (int) DistanceLinePoint( poly.CPoint( i ),
|
|
|
|
poly.CPoint( i + 1 ), pos );
|
2021-07-18 23:08:54 +00:00
|
|
|
|
|
|
|
if( distance < currentMinDistance )
|
|
|
|
{
|
|
|
|
currentMinDistance = distance;
|
|
|
|
closestLineStart = i;
|
|
|
|
}
|
|
|
|
}
|
2019-05-08 18:56:03 +00:00
|
|
|
|
2021-12-10 23:06:32 +00:00
|
|
|
saveItemsToUndo();
|
2021-12-11 00:38:50 +00:00
|
|
|
poly.Insert( closestLineStart + 1, pos );
|
2019-05-08 18:56:03 +00:00
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
updateItem( shape, true );
|
2019-05-08 18:56:03 +00:00
|
|
|
updatePoints();
|
|
|
|
|
2021-12-11 01:08:50 +00:00
|
|
|
m_frame->OnModify();
|
|
|
|
|
2019-05-08 18:56:03 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
int EE_POINT_EDITOR::removeCorner( const TOOL_EVENT& aEvent )
|
2019-05-08 18:56:03 +00:00
|
|
|
{
|
2021-07-18 23:08:54 +00:00
|
|
|
if( !m_editPoints || !m_editedPoint || m_editPoints->GetParent()->Type() != LIB_SHAPE_T )
|
2019-05-08 18:56:03 +00:00
|
|
|
return 0;
|
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
LIB_SHAPE* shape = static_cast<LIB_SHAPE*>( m_editPoints->GetParent() );
|
|
|
|
SHAPE_LINE_CHAIN& poly = shape->GetPolyShape().Outline( 0 );
|
2019-05-08 18:56:03 +00:00
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
if( poly.GetPointCount() < 3 )
|
2019-05-08 18:56:03 +00:00
|
|
|
return 0;
|
|
|
|
|
2021-12-10 23:06:32 +00:00
|
|
|
saveItemsToUndo();
|
2021-07-18 23:08:54 +00:00
|
|
|
poly.Remove( getEditedPointIndex() );
|
2019-05-08 18:56:03 +00:00
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
updateItem( shape, true );
|
2019-05-08 18:56:03 +00:00
|
|
|
updatePoints();
|
|
|
|
|
2021-12-11 01:08:50 +00:00
|
|
|
m_frame->OnModify();
|
|
|
|
|
2019-05-08 18:56:03 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
int EE_POINT_EDITOR::modifiedSelection( const TOOL_EVENT& aEvent )
|
2019-05-08 18:56:03 +00:00
|
|
|
{
|
|
|
|
updatePoints();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
void EE_POINT_EDITOR::saveItemsToUndo()
|
2019-05-08 18:56:03 +00:00
|
|
|
{
|
2020-10-31 01:27:16 +00:00
|
|
|
if( m_isSymbolEditor )
|
2019-05-08 18:56:03 +00:00
|
|
|
{
|
2020-08-26 18:04:32 +00:00
|
|
|
saveCopyInUndoList( m_editPoints->GetParent()->GetParent(), UNDO_REDO::LIBEDIT );
|
2019-05-08 18:56:03 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-08-26 18:04:32 +00:00
|
|
|
saveCopyInUndoList( (SCH_ITEM*) m_editPoints->GetParent(), UNDO_REDO::CHANGED );
|
2019-05-08 18:56:03 +00:00
|
|
|
|
|
|
|
if( m_editPoints->GetParent()->Type() == SCH_LINE_T )
|
|
|
|
{
|
2020-11-30 19:27:31 +00:00
|
|
|
std::pair<EDA_ITEM*, int> connected = m_editPoints->Point( LINE_START ).GetConnected();
|
2019-05-08 18:56:03 +00:00
|
|
|
|
2020-11-30 19:27:31 +00:00
|
|
|
if( connected.first )
|
|
|
|
saveCopyInUndoList( (SCH_ITEM*) connected.first, UNDO_REDO::CHANGED, true );
|
2019-05-08 18:56:03 +00:00
|
|
|
|
2020-11-30 19:27:31 +00:00
|
|
|
connected = m_editPoints->Point( LINE_END ).GetConnected();
|
2019-05-08 18:56:03 +00:00
|
|
|
|
2020-11-30 19:27:31 +00:00
|
|
|
if( connected.first )
|
|
|
|
saveCopyInUndoList( (SCH_ITEM*) connected.first, UNDO_REDO::CHANGED, true );
|
2019-05-08 18:56:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
void EE_POINT_EDITOR::rollbackFromUndo()
|
2019-05-08 18:56:03 +00:00
|
|
|
{
|
2020-10-31 01:27:16 +00:00
|
|
|
if( m_isSymbolEditor )
|
2020-11-15 16:08:31 +00:00
|
|
|
static_cast<SYMBOL_EDIT_FRAME*>( m_frame )->RollbackSymbolFromUndo();
|
2019-05-08 18:56:03 +00:00
|
|
|
else
|
|
|
|
static_cast<SCH_EDIT_FRAME*>( m_frame )->RollbackSchematicFromUndo();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
void EE_POINT_EDITOR::setTransitions()
|
2019-05-08 18:56:03 +00:00
|
|
|
{
|
2022-07-19 15:00:35 +00:00
|
|
|
Go( &EE_POINT_EDITOR::Main, EVENTS::PointSelectedEvent );
|
2019-05-24 11:39:30 +00:00
|
|
|
Go( &EE_POINT_EDITOR::Main, EVENTS::SelectedEvent );
|
|
|
|
Go( &EE_POINT_EDITOR::Main, ACTIONS::activatePointEditor.MakeEvent() );
|
2019-05-10 17:19:48 +00:00
|
|
|
Go( &EE_POINT_EDITOR::addCorner, EE_ACTIONS::pointEditorAddCorner.MakeEvent() );
|
|
|
|
Go( &EE_POINT_EDITOR::removeCorner, EE_ACTIONS::pointEditorRemoveCorner.MakeEvent() );
|
|
|
|
Go( &EE_POINT_EDITOR::modifiedSelection, EVENTS::SelectedItemsModified );
|
2021-10-06 17:20:07 +00:00
|
|
|
Go( &EE_POINT_EDITOR::clearEditedPoints, EVENTS::ClearedEvent );
|
2019-05-08 18:56:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|