2014-02-27 16:29:08 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2021-01-16 23:17:32 +00:00
|
|
|
* Copyright (C) 2013-2021 CERN
|
2023-03-04 23:15:43 +00:00
|
|
|
* Copyright (C) 2018-2023 KiCad Developers, see AUTHORS.txt for contributors.
|
2014-02-27 16:29:08 +00:00
|
|
|
* @author Maciej Suminski <maciej.suminski@cern.ch>
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2016-06-29 10:23:11 +00:00
|
|
|
#include <functional>
|
2019-12-05 13:43:55 +00:00
|
|
|
#include <memory>
|
2021-01-18 17:39:13 +00:00
|
|
|
|
2016-06-29 10:23:11 +00:00
|
|
|
using namespace std::placeholders;
|
2021-01-18 17:39:13 +00:00
|
|
|
#include <advanced_config.h>
|
2014-02-27 16:29:08 +00:00
|
|
|
#include <tool/tool_manager.h>
|
|
|
|
#include <view/view_controls.h>
|
2023-09-18 23:52:27 +00:00
|
|
|
#include <gal/graphics_abstraction_layer.h>
|
2014-03-18 13:52:22 +00:00
|
|
|
#include <geometry/seg.h>
|
2014-02-27 16:29:08 +00:00
|
|
|
#include <confirm.h>
|
2022-01-30 10:52:52 +00:00
|
|
|
#include <tools/pcb_actions.h>
|
|
|
|
#include <tools/pcb_selection_tool.h>
|
|
|
|
#include <tools/pcb_point_editor.h>
|
|
|
|
#include <tools/pcb_grid_helper.h>
|
2023-08-05 15:43:10 +00:00
|
|
|
#include <dialogs/dialog_unit_entry.h>
|
2016-06-21 15:06:28 +00:00
|
|
|
#include <board_commit.h>
|
2018-01-29 20:58:58 +00:00
|
|
|
#include <pcb_edit_frame.h>
|
2022-02-08 19:29:54 +00:00
|
|
|
#include <pcb_bitmap.h>
|
2023-10-06 17:04:00 +00:00
|
|
|
#include <pcb_generator.h>
|
2021-06-11 16:59:28 +00:00
|
|
|
#include <pcb_dimension.h>
|
2022-04-04 16:39:33 +00:00
|
|
|
#include <pcb_textbox.h>
|
2021-06-06 19:03:10 +00:00
|
|
|
#include <pad.h>
|
2020-11-11 23:05:59 +00:00
|
|
|
#include <zone.h>
|
2022-09-14 10:34:10 +00:00
|
|
|
#include <footprint.h>
|
2022-11-11 09:47:28 +00:00
|
|
|
#include <footprint_editor_settings.h>
|
2018-10-12 06:17:15 +00:00
|
|
|
#include <connectivity/connectivity_data.h>
|
2021-08-14 20:05:21 +00:00
|
|
|
#include <progress_reporter.h>
|
2014-02-27 16:29:08 +00:00
|
|
|
|
2022-09-16 11:33:56 +00:00
|
|
|
const unsigned int PCB_POINT_EDITOR::COORDS_PADDING = pcbIUScale.mmToIU( 20 );
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2014-04-01 15:41:24 +00:00
|
|
|
// Few constants to avoid using bare numbers for point indices
|
|
|
|
enum SEG_POINTS
|
|
|
|
{
|
|
|
|
SEG_START, SEG_END
|
|
|
|
};
|
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2020-06-15 19:50:20 +00:00
|
|
|
enum RECT_POINTS
|
|
|
|
{
|
|
|
|
RECT_TOP_LEFT, RECT_TOP_RIGHT, RECT_BOT_RIGHT, RECT_BOT_LEFT
|
|
|
|
};
|
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2021-01-13 22:03:31 +00:00
|
|
|
enum RECT_LINES
|
|
|
|
{
|
|
|
|
RECT_TOP, RECT_RIGHT, RECT_BOT, RECT_LEFT
|
|
|
|
};
|
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2014-04-01 15:41:24 +00:00
|
|
|
enum ARC_POINTS
|
|
|
|
{
|
2018-12-08 15:26:47 +00:00
|
|
|
ARC_CENTER, ARC_START, ARC_MID, ARC_END
|
2014-04-01 15:41:24 +00:00
|
|
|
};
|
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2014-04-01 15:41:24 +00:00
|
|
|
enum CIRCLE_POINTS
|
|
|
|
{
|
|
|
|
CIRC_CENTER, CIRC_END
|
|
|
|
};
|
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2018-07-22 12:50:35 +00:00
|
|
|
enum BEZIER_CURVE_POINTS
|
|
|
|
{
|
|
|
|
BEZIER_CURVE_START,
|
|
|
|
BEZIER_CURVE_CONTROL_POINT1,
|
|
|
|
BEZIER_CURVE_CONTROL_POINT2,
|
|
|
|
BEZIER_CURVE_END
|
|
|
|
};
|
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2014-04-01 15:41:24 +00:00
|
|
|
enum DIMENSION_POINTS
|
|
|
|
{
|
2020-09-09 03:17:08 +00:00
|
|
|
DIM_START,
|
|
|
|
DIM_END,
|
2020-09-12 20:09:40 +00:00
|
|
|
DIM_TEXT,
|
|
|
|
DIM_CROSSBARSTART,
|
|
|
|
DIM_CROSSBAREND,
|
2021-07-13 18:46:33 +00:00
|
|
|
DIM_KNEE = DIM_CROSSBARSTART
|
2014-04-01 15:41:24 +00:00
|
|
|
};
|
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2021-01-16 23:17:32 +00:00
|
|
|
PCB_POINT_EDITOR::PCB_POINT_EDITOR() :
|
2020-12-19 15:16:14 +00:00
|
|
|
PCB_TOOL_BASE( "pcbnew.PointEditor" ),
|
|
|
|
m_selectionTool( nullptr ),
|
|
|
|
m_editedPoint( nullptr ),
|
|
|
|
m_hoveredPoint( nullptr ),
|
|
|
|
m_original( VECTOR2I( 0, 0 ) ),
|
|
|
|
m_refill( false ),
|
2022-12-05 18:27:00 +00:00
|
|
|
m_arcEditMode( ARC_EDIT_MODE::KEEP_CENTER_ADJUST_ANGLE_RADIUS ),
|
2023-10-07 00:43:38 +00:00
|
|
|
m_altConstrainer( VECTOR2I( 0, 0 ) ),
|
|
|
|
m_inPointEditorTool( false )
|
2014-02-27 16:29:08 +00:00
|
|
|
{
|
2020-12-19 15:16:14 +00:00
|
|
|
}
|
2017-10-19 21:14:01 +00:00
|
|
|
|
|
|
|
|
2021-01-16 23:17:32 +00:00
|
|
|
void PCB_POINT_EDITOR::Reset( RESET_REASON aReason )
|
2020-12-19 15:16:14 +00:00
|
|
|
{
|
|
|
|
m_refill = false;
|
|
|
|
m_editPoints.reset();
|
|
|
|
m_altConstraint.reset();
|
|
|
|
getViewControls()->SetAutoPan( false );
|
|
|
|
}
|
2017-10-19 21:14:01 +00:00
|
|
|
|
|
|
|
|
2021-01-16 23:17:32 +00:00
|
|
|
bool PCB_POINT_EDITOR::Init()
|
2020-12-19 15:16:14 +00:00
|
|
|
{
|
|
|
|
// Find the selection tool, so they can cooperate
|
|
|
|
m_selectionTool = m_toolMgr->GetTool<PCB_SELECTION_TOOL>();
|
2017-10-19 21:14:01 +00:00
|
|
|
|
2022-02-05 13:25:43 +00:00
|
|
|
wxASSERT_MSG( m_selectionTool, wxT( "pcbnew.InteractiveSelection tool is not available" ) );
|
2017-10-19 21:14:01 +00:00
|
|
|
|
2020-12-19 15:16:14 +00:00
|
|
|
auto& menu = m_selectionTool->GetToolMenu().GetMenu();
|
2021-01-16 23:17:32 +00:00
|
|
|
menu.AddItem( PCB_ACTIONS::pointEditorAddCorner, PCB_POINT_EDITOR::addCornerCondition );
|
2020-12-19 15:16:14 +00:00
|
|
|
menu.AddItem( PCB_ACTIONS::pointEditorRemoveCorner,
|
2021-01-16 23:17:32 +00:00
|
|
|
std::bind( &PCB_POINT_EDITOR::removeCornerCondition, this, _1 ) );
|
2017-10-19 21:14:01 +00:00
|
|
|
|
2020-12-19 15:16:14 +00:00
|
|
|
return true;
|
|
|
|
}
|
2017-10-19 21:14:01 +00:00
|
|
|
|
2014-02-27 16:29:08 +00:00
|
|
|
|
2021-01-16 23:17:32 +00:00
|
|
|
void PCB_POINT_EDITOR::buildForPolyOutline( std::shared_ptr<EDIT_POINTS> points,
|
|
|
|
const SHAPE_POLY_SET* aOutline )
|
2020-12-19 15:16:14 +00:00
|
|
|
{
|
|
|
|
int cornersCount = aOutline->TotalVertices();
|
2017-05-16 09:38:00 +00:00
|
|
|
|
2020-12-19 15:16:14 +00:00
|
|
|
for( auto iterator = aOutline->CIterateWithHoles(); iterator; iterator++ )
|
|
|
|
{
|
|
|
|
points->AddPoint( *iterator );
|
2014-02-27 16:29:08 +00:00
|
|
|
|
2020-12-19 15:16:14 +00:00
|
|
|
if( iterator.IsEndContour() )
|
|
|
|
points->AddBreak();
|
|
|
|
}
|
2020-06-15 19:50:20 +00:00
|
|
|
|
2022-01-30 10:52:52 +00:00
|
|
|
// Lines have to be added after creating edit points, as they use EDIT_POINT references
|
2020-12-19 15:16:14 +00:00
|
|
|
for( int i = 0; i < cornersCount - 1; ++i )
|
|
|
|
{
|
|
|
|
if( points->IsContourEnd( i ) )
|
|
|
|
points->AddLine( points->Point( i ), points->Point( points->GetContourStartIdx( i ) ) );
|
|
|
|
else
|
|
|
|
points->AddLine( points->Point( i ), points->Point( i + 1 ) );
|
2014-02-27 16:29:08 +00:00
|
|
|
|
2020-12-19 15:16:14 +00:00
|
|
|
points->Line( i ).SetConstraint( new EC_PERPLINE( points->Line( i ) ) );
|
|
|
|
}
|
2018-12-08 15:26:47 +00:00
|
|
|
|
2020-12-19 15:16:14 +00:00
|
|
|
// The last missing line, connecting the last and the first polygon point
|
|
|
|
points->AddLine( points->Point( cornersCount - 1 ),
|
|
|
|
points->Point( points->GetContourStartIdx( cornersCount - 1 ) ) );
|
2014-02-27 16:29:08 +00:00
|
|
|
|
2020-12-19 15:16:14 +00:00
|
|
|
points->Line( points->LinesSize() - 1 )
|
|
|
|
.SetConstraint( new EC_PERPLINE( points->Line( points->LinesSize() - 1 ) ) );
|
|
|
|
}
|
2020-10-08 09:59:17 +00:00
|
|
|
|
2014-02-28 17:24:13 +00:00
|
|
|
|
2021-01-16 23:17:32 +00:00
|
|
|
std::shared_ptr<EDIT_POINTS> PCB_POINT_EDITOR::makePoints( EDA_ITEM* aItem )
|
2020-12-19 15:16:14 +00:00
|
|
|
{
|
|
|
|
std::shared_ptr<EDIT_POINTS> points = std::make_shared<EDIT_POINTS>( aItem );
|
2018-07-22 12:50:35 +00:00
|
|
|
|
2020-12-19 15:16:14 +00:00
|
|
|
if( !aItem )
|
|
|
|
return points;
|
2017-10-19 21:14:01 +00:00
|
|
|
|
2023-03-30 11:49:23 +00:00
|
|
|
if( aItem->Type() == PCB_TEXTBOX_T )
|
2022-01-30 10:52:52 +00:00
|
|
|
{
|
|
|
|
const PCB_SHAPE* shape = static_cast<const PCB_SHAPE*>( aItem );
|
|
|
|
|
|
|
|
// We can't currently handle TEXTBOXes that have been turned into SHAPE_T::POLYs due
|
|
|
|
// to non-cardinal rotations
|
2023-07-24 16:07:56 +00:00
|
|
|
if( shape->GetShape() != SHAPE_T::RECTANGLE )
|
2022-01-30 10:52:52 +00:00
|
|
|
return points;
|
|
|
|
}
|
|
|
|
|
2020-12-19 15:16:14 +00:00
|
|
|
// Generate list of edit points basing on the item type
|
|
|
|
switch( aItem->Type() )
|
|
|
|
{
|
2022-02-08 19:29:54 +00:00
|
|
|
case PCB_BITMAP_T:
|
|
|
|
{
|
|
|
|
PCB_BITMAP* bitmap = (PCB_BITMAP*) aItem;
|
|
|
|
VECTOR2I topLeft = bitmap->GetPosition() - bitmap->GetSize() / 2;
|
|
|
|
VECTOR2I botRight = bitmap->GetPosition() + bitmap->GetSize() / 2;
|
|
|
|
|
|
|
|
points->AddPoint( topLeft );
|
|
|
|
points->AddPoint( VECTOR2I( botRight.x, topLeft.y ) );
|
|
|
|
points->AddPoint( botRight );
|
|
|
|
points->AddPoint( VECTOR2I( topLeft.x, botRight.y ) );
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2022-01-30 10:52:52 +00:00
|
|
|
case PCB_TEXTBOX_T:
|
2020-12-19 15:16:14 +00:00
|
|
|
case PCB_SHAPE_T:
|
|
|
|
{
|
|
|
|
const PCB_SHAPE* shape = static_cast<const PCB_SHAPE*>( aItem );
|
2014-02-28 17:24:29 +00:00
|
|
|
|
2020-12-19 15:16:14 +00:00
|
|
|
switch( shape->GetShape() )
|
|
|
|
{
|
2021-07-21 18:31:25 +00:00
|
|
|
case SHAPE_T::SEGMENT:
|
2020-12-19 15:16:14 +00:00
|
|
|
points->AddPoint( shape->GetStart() );
|
|
|
|
points->AddPoint( shape->GetEnd() );
|
|
|
|
break;
|
2014-02-28 17:24:29 +00:00
|
|
|
|
2023-07-24 16:07:56 +00:00
|
|
|
case SHAPE_T::RECTANGLE:
|
2022-06-02 09:42:13 +00:00
|
|
|
points->AddPoint( shape->GetTopLeft() );
|
|
|
|
points->AddPoint( VECTOR2I( shape->GetBotRight().x, shape->GetTopLeft().y ) );
|
|
|
|
points->AddPoint( shape->GetBotRight() );
|
|
|
|
points->AddPoint( VECTOR2I( shape->GetTopLeft().x, shape->GetBotRight().y ) );
|
2021-01-13 22:03:31 +00:00
|
|
|
|
|
|
|
points->AddLine( points->Point( RECT_TOP_LEFT ), points->Point( RECT_TOP_RIGHT ) );
|
|
|
|
points->Line( RECT_TOP ).SetConstraint( new EC_PERPLINE( points->Line( RECT_TOP ) ) );
|
|
|
|
points->AddLine( points->Point( RECT_TOP_RIGHT ), points->Point( RECT_BOT_RIGHT ) );
|
|
|
|
points->Line( RECT_RIGHT ).SetConstraint( new EC_PERPLINE( points->Line( RECT_RIGHT ) ) );
|
|
|
|
points->AddLine( points->Point( RECT_BOT_RIGHT ), points->Point( RECT_BOT_LEFT ) );
|
|
|
|
points->Line( RECT_BOT ).SetConstraint( new EC_PERPLINE( points->Line( RECT_BOT ) ) );
|
|
|
|
points->AddLine( points->Point( RECT_BOT_LEFT ), points->Point( RECT_TOP_LEFT ) );
|
|
|
|
points->Line( RECT_LEFT ).SetConstraint( new EC_PERPLINE( points->Line( RECT_LEFT ) ) );
|
|
|
|
|
2020-06-28 22:34:10 +00:00
|
|
|
break;
|
|
|
|
|
2021-07-21 18:31:25 +00:00
|
|
|
case SHAPE_T::ARC:
|
2020-12-19 15:16:14 +00:00
|
|
|
points->AddPoint( shape->GetCenter() );
|
2021-07-17 19:56:18 +00:00
|
|
|
points->AddPoint( shape->GetStart() );
|
2020-12-19 15:16:14 +00:00
|
|
|
points->AddPoint( shape->GetArcMid() );
|
2021-07-17 19:56:18 +00:00
|
|
|
points->AddPoint( shape->GetEnd() );
|
2020-12-19 15:16:14 +00:00
|
|
|
break;
|
2014-03-12 09:46:11 +00:00
|
|
|
|
2021-07-21 18:31:25 +00:00
|
|
|
case SHAPE_T::CIRCLE:
|
2020-12-19 15:16:14 +00:00
|
|
|
points->AddPoint( shape->GetCenter() );
|
|
|
|
points->AddPoint( shape->GetEnd() );
|
|
|
|
break;
|
2014-03-12 09:46:11 +00:00
|
|
|
|
2021-07-21 18:31:25 +00:00
|
|
|
case SHAPE_T::POLY:
|
2020-12-19 15:16:14 +00:00
|
|
|
buildForPolyOutline( points, &shape->GetPolyShape() );
|
|
|
|
break;
|
2014-02-28 17:24:29 +00:00
|
|
|
|
2021-07-21 18:31:25 +00:00
|
|
|
case SHAPE_T::BEZIER:
|
2020-12-19 15:16:14 +00:00
|
|
|
points->AddPoint( shape->GetStart() );
|
2021-07-18 12:31:56 +00:00
|
|
|
points->AddPoint( shape->GetBezierC1() );
|
|
|
|
points->AddPoint( shape->GetBezierC2() );
|
2020-12-19 15:16:14 +00:00
|
|
|
points->AddPoint( shape->GetEnd() );
|
2020-06-28 22:34:10 +00:00
|
|
|
break;
|
2014-02-27 16:29:08 +00:00
|
|
|
|
2020-12-19 15:16:14 +00:00
|
|
|
default: // suppress warnings
|
2020-06-28 22:34:10 +00:00
|
|
|
break;
|
2020-12-19 15:16:14 +00:00
|
|
|
}
|
2020-06-28 22:34:10 +00:00
|
|
|
|
2020-12-19 15:16:14 +00:00
|
|
|
break;
|
|
|
|
}
|
2020-06-28 22:34:10 +00:00
|
|
|
|
2020-12-19 15:16:14 +00:00
|
|
|
case PCB_PAD_T:
|
|
|
|
{
|
|
|
|
const PAD* pad = static_cast<const PAD*>( aItem );
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I shapePos = pad->ShapePos();
|
|
|
|
VECTOR2I halfSize( pad->GetSize().x / 2, pad->GetSize().y / 2 );
|
2020-06-28 22:34:10 +00:00
|
|
|
|
2021-01-08 16:32:28 +00:00
|
|
|
if( !m_isFootprintEditor || pad->IsLocked() )
|
2020-09-17 00:54:58 +00:00
|
|
|
break;
|
|
|
|
|
2020-12-19 15:16:14 +00:00
|
|
|
switch( pad->GetShape() )
|
2020-09-17 00:54:58 +00:00
|
|
|
{
|
2021-05-01 12:22:35 +00:00
|
|
|
case PAD_SHAPE::CIRCLE:
|
2022-01-01 17:11:21 +00:00
|
|
|
points->AddPoint( VECTOR2I( shapePos.x + halfSize.x, shapePos.y ) );
|
2020-06-28 22:34:10 +00:00
|
|
|
break;
|
|
|
|
|
2021-05-01 12:22:35 +00:00
|
|
|
case PAD_SHAPE::OVAL:
|
|
|
|
case PAD_SHAPE::TRAPEZOID:
|
2023-06-02 09:10:48 +00:00
|
|
|
case PAD_SHAPE::RECTANGLE:
|
2021-05-01 12:22:35 +00:00
|
|
|
case PAD_SHAPE::ROUNDRECT:
|
|
|
|
case PAD_SHAPE::CHAMFERED_RECT:
|
2020-09-12 20:09:40 +00:00
|
|
|
{
|
2022-01-13 13:45:48 +00:00
|
|
|
if( !pad->GetOrientation().IsCardinal() )
|
2020-12-19 15:16:14 +00:00
|
|
|
break;
|
2020-09-12 20:09:40 +00:00
|
|
|
|
2022-01-13 13:45:48 +00:00
|
|
|
if( pad->GetOrientation() == ANGLE_90 || pad->GetOrientation() == ANGLE_270 )
|
2020-12-19 15:16:14 +00:00
|
|
|
std::swap( halfSize.x, halfSize.y );
|
2020-09-12 20:09:40 +00:00
|
|
|
|
2020-12-19 15:16:14 +00:00
|
|
|
points->AddPoint( shapePos - halfSize );
|
2022-01-01 17:11:21 +00:00
|
|
|
points->AddPoint( VECTOR2I( shapePos.x + halfSize.x, shapePos.y - halfSize.y ) );
|
2020-12-19 15:16:14 +00:00
|
|
|
points->AddPoint( shapePos + halfSize );
|
2022-01-01 17:11:21 +00:00
|
|
|
points->AddPoint( VECTOR2I( shapePos.x - halfSize.x, shapePos.y + halfSize.y ) );
|
2020-09-12 20:09:40 +00:00
|
|
|
}
|
2020-12-19 15:16:14 +00:00
|
|
|
break;
|
2020-09-12 20:09:40 +00:00
|
|
|
|
2020-12-19 15:16:14 +00:00
|
|
|
default: // suppress warnings
|
2020-06-28 22:34:10 +00:00
|
|
|
break;
|
2014-02-27 16:29:08 +00:00
|
|
|
}
|
2023-03-30 11:49:23 +00:00
|
|
|
|
2020-12-19 15:16:14 +00:00
|
|
|
break;
|
2023-03-30 11:49:23 +00:00
|
|
|
}
|
2014-02-27 16:29:08 +00:00
|
|
|
|
2020-12-19 15:16:14 +00:00
|
|
|
case PCB_ZONE_T:
|
|
|
|
{
|
|
|
|
const ZONE* zone = static_cast<const ZONE*>( aItem );
|
|
|
|
buildForPolyOutline( points, zone->Outline() );
|
|
|
|
break;
|
2023-03-30 11:49:23 +00:00
|
|
|
}
|
2014-02-27 16:29:08 +00:00
|
|
|
|
2023-10-06 17:04:00 +00:00
|
|
|
case PCB_GENERATOR_T:
|
|
|
|
{
|
|
|
|
const PCB_GENERATOR* generator = static_cast<const PCB_GENERATOR*>( aItem );
|
|
|
|
generator->MakeEditPoints( points );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-12-19 15:16:14 +00:00
|
|
|
case PCB_DIM_ALIGNED_T:
|
|
|
|
case PCB_DIM_ORTHOGONAL_T:
|
|
|
|
{
|
2021-06-11 16:59:28 +00:00
|
|
|
const PCB_DIM_ALIGNED* dimension = static_cast<const PCB_DIM_ALIGNED*>( aItem );
|
2014-02-27 16:29:08 +00:00
|
|
|
|
2020-12-19 15:16:14 +00:00
|
|
|
points->AddPoint( dimension->GetStart() );
|
|
|
|
points->AddPoint( dimension->GetEnd() );
|
2023-03-04 23:15:43 +00:00
|
|
|
points->AddPoint( dimension->GetTextPos() );
|
2020-12-19 15:16:14 +00:00
|
|
|
points->AddPoint( dimension->GetCrossbarStart() );
|
|
|
|
points->AddPoint( dimension->GetCrossbarEnd() );
|
2014-02-27 16:29:08 +00:00
|
|
|
|
2022-02-22 21:00:48 +00:00
|
|
|
points->Point( DIM_START ).SetSnapConstraint( ALL_LAYERS );
|
|
|
|
points->Point( DIM_END ).SetSnapConstraint( ALL_LAYERS );
|
|
|
|
|
2020-12-19 15:16:14 +00:00
|
|
|
if( aItem->Type() == PCB_DIM_ALIGNED_T )
|
|
|
|
{
|
|
|
|
// Dimension height setting - edit points should move only along the feature lines
|
|
|
|
points->Point( DIM_CROSSBARSTART )
|
|
|
|
.SetConstraint( new EC_LINE( points->Point( DIM_CROSSBARSTART ),
|
|
|
|
points->Point( DIM_START ) ) );
|
|
|
|
points->Point( DIM_CROSSBAREND )
|
|
|
|
.SetConstraint( new EC_LINE( points->Point( DIM_CROSSBAREND ),
|
|
|
|
points->Point( DIM_END ) ) );
|
|
|
|
}
|
2014-02-27 16:29:08 +00:00
|
|
|
|
2020-12-19 15:16:14 +00:00
|
|
|
break;
|
|
|
|
}
|
2014-02-27 16:29:08 +00:00
|
|
|
|
2020-12-19 15:16:14 +00:00
|
|
|
case PCB_DIM_CENTER_T:
|
|
|
|
{
|
2021-06-11 16:59:28 +00:00
|
|
|
const PCB_DIM_CENTER* dimension = static_cast<const PCB_DIM_CENTER*>( aItem );
|
2018-03-02 09:55:59 +00:00
|
|
|
|
2020-12-19 15:16:14 +00:00
|
|
|
points->AddPoint( dimension->GetStart() );
|
|
|
|
points->AddPoint( dimension->GetEnd() );
|
2014-02-28 16:20:10 +00:00
|
|
|
|
2022-02-22 21:00:48 +00:00
|
|
|
points->Point( DIM_START ).SetSnapConstraint( ALL_LAYERS );
|
|
|
|
|
2020-12-19 15:16:14 +00:00
|
|
|
points->Point( DIM_END ).SetConstraint( new EC_45DEGREE( points->Point( DIM_END ),
|
|
|
|
points->Point( DIM_START ) ) );
|
2022-02-22 21:00:48 +00:00
|
|
|
points->Point( DIM_END ).SetSnapConstraint( IGNORE_SNAPS );
|
2014-02-28 16:20:10 +00:00
|
|
|
|
2020-12-19 15:16:14 +00:00
|
|
|
break;
|
|
|
|
}
|
2014-02-27 16:29:08 +00:00
|
|
|
|
2021-07-13 18:46:33 +00:00
|
|
|
case PCB_DIM_RADIAL_T:
|
|
|
|
{
|
|
|
|
const PCB_DIM_RADIAL* dimension = static_cast<const PCB_DIM_RADIAL*>( aItem );
|
|
|
|
|
|
|
|
points->AddPoint( dimension->GetStart() );
|
|
|
|
points->AddPoint( dimension->GetEnd() );
|
2023-03-04 23:15:43 +00:00
|
|
|
points->AddPoint( dimension->GetTextPos() );
|
2021-07-13 18:46:33 +00:00
|
|
|
points->AddPoint( dimension->GetKnee() );
|
|
|
|
|
2022-02-22 21:00:48 +00:00
|
|
|
points->Point( DIM_START ).SetSnapConstraint( ALL_LAYERS );
|
|
|
|
points->Point( DIM_END ).SetSnapConstraint( ALL_LAYERS );
|
|
|
|
|
2021-07-13 18:46:33 +00:00
|
|
|
points->Point( DIM_KNEE ).SetConstraint( new EC_LINE( points->Point( DIM_START ),
|
|
|
|
points->Point( DIM_END ) ) );
|
2022-02-22 21:00:48 +00:00
|
|
|
points->Point( DIM_KNEE ).SetSnapConstraint( IGNORE_SNAPS );
|
2021-07-13 18:46:33 +00:00
|
|
|
|
|
|
|
points->Point( DIM_TEXT ).SetConstraint( new EC_45DEGREE( points->Point( DIM_TEXT ),
|
|
|
|
points->Point( DIM_KNEE ) ) );
|
2022-02-22 21:00:48 +00:00
|
|
|
points->Point( DIM_TEXT ).SetSnapConstraint( IGNORE_SNAPS );
|
2021-07-13 18:46:33 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-12-19 15:16:14 +00:00
|
|
|
case PCB_DIM_LEADER_T:
|
|
|
|
{
|
2021-06-11 16:59:28 +00:00
|
|
|
const PCB_DIM_LEADER* dimension = static_cast<const PCB_DIM_LEADER*>( aItem );
|
2014-02-27 16:29:08 +00:00
|
|
|
|
2020-12-19 15:16:14 +00:00
|
|
|
points->AddPoint( dimension->GetStart() );
|
|
|
|
points->AddPoint( dimension->GetEnd() );
|
2023-03-04 23:15:43 +00:00
|
|
|
points->AddPoint( dimension->GetTextPos() );
|
2014-07-09 14:50:31 +00:00
|
|
|
|
2022-02-22 21:00:48 +00:00
|
|
|
points->Point( DIM_START ).SetSnapConstraint( ALL_LAYERS );
|
|
|
|
points->Point( DIM_END ).SetSnapConstraint( ALL_LAYERS );
|
|
|
|
|
2021-07-13 15:10:18 +00:00
|
|
|
points->Point( DIM_TEXT ).SetConstraint( new EC_45DEGREE( points->Point( DIM_TEXT ),
|
|
|
|
points->Point( DIM_END ) ) );
|
2022-02-22 21:00:48 +00:00
|
|
|
points->Point( DIM_TEXT ).SetSnapConstraint( IGNORE_SNAPS );
|
2021-07-13 15:10:18 +00:00
|
|
|
|
2020-12-19 15:16:14 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
points.reset();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return points;
|
2014-02-27 16:29:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-01-16 23:17:32 +00:00
|
|
|
void PCB_POINT_EDITOR::updateEditedPoint( const TOOL_EVENT& aEvent )
|
2015-08-12 08:15:45 +00:00
|
|
|
{
|
2019-06-27 21:33:48 +00:00
|
|
|
EDIT_POINT* point;
|
2020-09-24 01:27:23 +00:00
|
|
|
EDIT_POINT* hovered = nullptr;
|
2015-08-12 08:15:45 +00:00
|
|
|
|
|
|
|
if( aEvent.IsMotion() )
|
|
|
|
{
|
2016-12-02 17:58:12 +00:00
|
|
|
point = m_editPoints->FindPoint( aEvent.Position(), getView() );
|
2020-09-24 01:27:23 +00:00
|
|
|
hovered = point;
|
2015-08-12 08:15:45 +00:00
|
|
|
}
|
|
|
|
else if( aEvent.IsDrag( BUT_LEFT ) )
|
|
|
|
{
|
2016-12-02 17:58:12 +00:00
|
|
|
point = m_editPoints->FindPoint( aEvent.DragOrigin(), getView() );
|
2015-08-12 08:15:45 +00:00
|
|
|
}
|
2019-06-27 21:33:48 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
point = m_editPoints->FindPoint( getViewControls()->GetCursorPosition(), getView() );
|
|
|
|
}
|
2015-08-12 08:15:45 +00:00
|
|
|
|
2020-09-24 01:27:23 +00:00
|
|
|
if( hovered )
|
|
|
|
{
|
|
|
|
if( m_hoveredPoint != hovered )
|
|
|
|
{
|
|
|
|
if( m_hoveredPoint )
|
|
|
|
m_hoveredPoint->SetHover( false );
|
|
|
|
|
|
|
|
m_hoveredPoint = hovered;
|
|
|
|
m_hoveredPoint->SetHover();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( m_hoveredPoint )
|
|
|
|
{
|
|
|
|
m_hoveredPoint->SetHover( false );
|
|
|
|
m_hoveredPoint = nullptr;
|
|
|
|
}
|
|
|
|
|
2015-08-12 08:15:45 +00:00
|
|
|
if( m_editedPoint != point )
|
|
|
|
setEditedPoint( point );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-01-16 23:17:32 +00:00
|
|
|
int PCB_POINT_EDITOR::OnSelectionChange( const TOOL_EVENT& aEvent )
|
2014-02-27 16:29:08 +00:00
|
|
|
{
|
2020-10-25 16:13:25 +00:00
|
|
|
if( !m_selectionTool || aEvent.Matches( EVENTS::InhibitSelectionEditing ) )
|
2018-09-17 11:31:57 +00:00
|
|
|
return 0;
|
|
|
|
|
2023-10-07 00:43:38 +00:00
|
|
|
if( m_inPointEditorTool )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
REENTRANCY_GUARD guard( &m_inPointEditorTool );
|
|
|
|
|
2021-05-25 17:12:49 +00:00
|
|
|
PCB_BASE_EDIT_FRAME* editFrame = getEditFrame<PCB_BASE_EDIT_FRAME>();
|
2020-12-16 13:31:32 +00:00
|
|
|
const PCB_SELECTION& selection = m_selectionTool->GetSelection();
|
2014-02-27 16:29:08 +00:00
|
|
|
|
2019-06-12 16:14:55 +00:00
|
|
|
if( selection.Size() != 1 || selection.Front()->GetEditFlags() )
|
2017-03-06 09:55:32 +00:00
|
|
|
return 0;
|
|
|
|
|
2018-10-07 02:55:20 +00:00
|
|
|
BOARD_ITEM* item = static_cast<BOARD_ITEM*>( selection.Front() );
|
2014-03-06 13:41:25 +00:00
|
|
|
|
2021-05-25 17:12:49 +00:00
|
|
|
if( !item || item->IsLocked() )
|
2019-05-30 00:51:22 +00:00
|
|
|
return 0;
|
|
|
|
|
2021-05-25 17:12:49 +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
|
2021-05-25 17:12:49 +00:00
|
|
|
getViewControls()->ShowCursor( true );
|
|
|
|
|
|
|
|
PCB_GRID_HELPER grid( m_toolMgr, editFrame->GetMagneticItemsSettings() );
|
2020-12-19 15:16:14 +00:00
|
|
|
m_editPoints = makePoints( item );
|
2015-04-30 08:46:03 +00:00
|
|
|
|
2017-03-06 09:55:32 +00:00
|
|
|
if( !m_editPoints )
|
|
|
|
return 0;
|
2014-03-06 13:41:25 +00:00
|
|
|
|
2021-05-25 17:12:49 +00:00
|
|
|
getView()->Add( m_editPoints.get() );
|
2018-02-02 15:20:14 +00:00
|
|
|
setEditedPoint( nullptr );
|
2019-06-27 21:33:48 +00:00
|
|
|
updateEditedPoint( aEvent );
|
2018-04-03 20:26:01 +00:00
|
|
|
m_refill = false;
|
2019-06-17 13:43:22 +00:00
|
|
|
bool inDrag = false;
|
2022-11-11 09:47:28 +00:00
|
|
|
bool useAltContraint = false;
|
2014-03-06 11:36:20 +00:00
|
|
|
|
2017-03-06 09:55:32 +00:00
|
|
|
BOARD_COMMIT commit( editFrame );
|
2016-06-21 15:06:28 +00:00
|
|
|
|
2017-03-06 09:55:32 +00:00
|
|
|
// Main loop: keep receiving events
|
2019-06-17 13:43:22 +00:00
|
|
|
while( TOOL_EVENT* evt = Wait() )
|
2017-03-06 09:55:32 +00:00
|
|
|
{
|
2018-10-04 00:15:54 +00:00
|
|
|
grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
|
2021-05-25 17:12:49 +00:00
|
|
|
grid.SetUseGrid( getView()->GetGAL()->GetGridSnapping() && !evt->DisableGridSnapping() );
|
2018-10-04 00:15:54 +00:00
|
|
|
|
2022-11-11 09:47:28 +00:00
|
|
|
if( editFrame->IsType( FRAME_PCB_EDITOR ) )
|
2022-12-05 18:27:00 +00:00
|
|
|
{
|
2022-11-11 09:47:28 +00:00
|
|
|
useAltContraint = editFrame->GetPcbNewSettings()->m_Use45DegreeLimit;
|
2022-12-05 18:27:00 +00:00
|
|
|
m_arcEditMode = editFrame->GetPcbNewSettings()->m_ArcEditMode;
|
|
|
|
}
|
2022-11-11 09:47:28 +00:00
|
|
|
else
|
2022-12-05 18:27:00 +00:00
|
|
|
{
|
2022-11-11 09:47:28 +00:00
|
|
|
useAltContraint = editFrame->GetFootprintEditorSettings()->m_Use45Limit;
|
2022-12-05 18:27:00 +00:00
|
|
|
m_arcEditMode = editFrame->GetFootprintEditorSettings()->m_ArcEditMode;
|
|
|
|
}
|
2022-11-11 09:47:28 +00:00
|
|
|
|
2020-10-25 16:13:25 +00:00
|
|
|
if( !m_editPoints || evt->IsSelectionEvent() ||
|
|
|
|
evt->Matches( EVENTS::InhibitSelectionEditing ) )
|
2020-12-03 19:53:39 +00:00
|
|
|
{
|
2017-03-06 09:55:32 +00:00
|
|
|
break;
|
2020-12-03 19:53:39 +00:00
|
|
|
}
|
2015-12-14 21:20:54 +00:00
|
|
|
|
2020-09-24 01:27:23 +00:00
|
|
|
EDIT_POINT* prevHover = m_hoveredPoint;
|
|
|
|
|
|
|
|
if( !inDrag )
|
2017-03-06 09:55:32 +00:00
|
|
|
updateEditedPoint( *evt );
|
2014-02-28 16:20:10 +00:00
|
|
|
|
2020-09-24 01:27:23 +00:00
|
|
|
if( prevHover != m_hoveredPoint )
|
|
|
|
getView()->Update( m_editPoints.get() );
|
|
|
|
|
2017-03-06 09:55:32 +00:00
|
|
|
if( evt->IsDrag( BUT_LEFT ) && m_editedPoint )
|
|
|
|
{
|
2019-06-17 13:43:22 +00:00
|
|
|
if( !inDrag )
|
2014-02-27 16:29:08 +00:00
|
|
|
{
|
2020-10-08 09:59:17 +00:00
|
|
|
frame()->UndoRedoBlock( true );
|
|
|
|
|
2023-10-06 17:04:00 +00:00
|
|
|
if( item->Type() == PCB_GENERATOR_T )
|
|
|
|
{
|
|
|
|
m_toolMgr->RunSynchronousAction<PCB_GENERATOR*>(
|
|
|
|
PCB_ACTIONS::genStartEdit, &commit,
|
|
|
|
static_cast<PCB_GENERATOR*>( item ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
commit.StageItems( selection, CHT_MODIFY );
|
|
|
|
}
|
2016-06-08 09:24:46 +00:00
|
|
|
|
2021-05-25 17:12:49 +00:00
|
|
|
getViewControls()->ForceCursorPosition( false );
|
2017-03-06 09:55:32 +00:00
|
|
|
m_original = *m_editedPoint; // Save the original position
|
2021-05-25 17:12:49 +00:00
|
|
|
getViewControls()->SetAutoPan( true );
|
2019-06-17 13:43:22 +00:00
|
|
|
inDrag = true;
|
2021-01-18 22:31:48 +00:00
|
|
|
|
|
|
|
if( m_editedPoint->GetGridConstraint() != SNAP_BY_GRID )
|
|
|
|
grid.SetAuxAxes( true, m_original.GetPosition() );
|
|
|
|
|
2020-08-27 17:31:53 +00:00
|
|
|
setAltConstraint( true );
|
2020-06-21 18:43:33 +00:00
|
|
|
m_editedPoint->SetActive();
|
2021-11-01 16:17:33 +00:00
|
|
|
|
|
|
|
for( size_t ii = 0; ii < m_editPoints->PointsSize(); ++ii )
|
|
|
|
{
|
|
|
|
EDIT_POINT& point = m_editPoints->Point( ii );
|
|
|
|
|
|
|
|
if( &point != m_editedPoint )
|
|
|
|
point.SetActive( false );
|
|
|
|
}
|
2017-03-06 09:55:32 +00:00
|
|
|
}
|
2016-06-21 15:06:28 +00:00
|
|
|
|
2021-12-11 23:57:51 +00:00
|
|
|
// Keep point inside of limits with some padding
|
|
|
|
VECTOR2I pos = GetClampedCoords<double, int>( evt->Position(), COORDS_PADDING );
|
2022-02-22 21:00:48 +00:00
|
|
|
LSET snapLayers;
|
2021-01-18 22:31:48 +00:00
|
|
|
|
2022-02-22 21:00:48 +00:00
|
|
|
switch( m_editedPoint->GetSnapConstraint() )
|
2020-10-08 09:59:17 +00:00
|
|
|
{
|
2022-02-22 21:00:48 +00:00
|
|
|
case IGNORE_SNAPS: break;
|
|
|
|
case OBJECT_LAYERS: snapLayers = item->GetLayerSet(); break;
|
|
|
|
case ALL_LAYERS: snapLayers = LSET::AllLayersMask(); break;
|
|
|
|
}
|
2020-12-03 19:53:39 +00:00
|
|
|
|
2022-02-22 21:00:48 +00:00
|
|
|
if( m_editedPoint->GetGridConstraint() == SNAP_BY_GRID )
|
2020-12-03 19:53:39 +00:00
|
|
|
{
|
2021-01-18 22:31:48 +00:00
|
|
|
if( grid.GetUseGrid() )
|
2020-12-03 19:53:39 +00:00
|
|
|
{
|
2023-08-24 14:13:59 +00:00
|
|
|
VECTOR2I gridPt = grid.BestSnapAnchor( pos, {}, grid.GetItemGrid( item ), { item } );
|
2020-12-03 19:53:39 +00:00
|
|
|
|
2021-01-18 22:31:48 +00:00
|
|
|
VECTOR2I last = m_editedPoint->GetPosition();
|
|
|
|
VECTOR2I delta = pos - last;
|
2023-08-24 14:13:59 +00:00
|
|
|
VECTOR2I deltaGrid = gridPt - grid.BestSnapAnchor( last, {}, grid.GetItemGrid( item ), { item } );
|
2021-01-18 22:31:48 +00:00
|
|
|
|
|
|
|
if( abs( delta.x ) > grid.GetGrid().x / 2 )
|
2022-02-26 15:55:21 +00:00
|
|
|
pos.x = last.x + deltaGrid.x;
|
2021-01-18 22:31:48 +00:00
|
|
|
else
|
|
|
|
pos.x = last.x;
|
2020-12-03 19:53:39 +00:00
|
|
|
|
2021-01-19 10:56:43 +00:00
|
|
|
if( abs( delta.y ) > grid.GetGrid().y / 2 )
|
2022-02-26 15:55:21 +00:00
|
|
|
pos.y = last.y + deltaGrid.y;
|
2021-01-18 22:31:48 +00:00
|
|
|
else
|
|
|
|
pos.y = last.y;
|
2020-12-03 19:53:39 +00:00
|
|
|
}
|
2021-07-19 23:56:05 +00:00
|
|
|
}
|
2019-08-26 13:30:03 +00:00
|
|
|
|
2022-02-22 21:00:48 +00:00
|
|
|
m_editedPoint->SetPosition( pos );
|
|
|
|
|
2021-01-05 07:42:52 +00:00
|
|
|
// The alternative constraint limits to 45 degrees
|
2022-11-11 09:47:28 +00:00
|
|
|
if( useAltContraint )
|
2022-02-22 21:00:48 +00:00
|
|
|
{
|
|
|
|
m_altConstraint->Apply( grid );
|
|
|
|
}
|
|
|
|
else if( m_editedPoint->IsConstrained() )
|
|
|
|
{
|
|
|
|
m_editedPoint->ApplyConstraint( grid );
|
|
|
|
}
|
|
|
|
else if( m_editedPoint->GetGridConstraint() == SNAP_TO_GRID )
|
2021-07-13 15:10:18 +00:00
|
|
|
{
|
2023-08-24 14:13:59 +00:00
|
|
|
m_editedPoint->SetPosition(
|
|
|
|
grid.BestSnapAnchor( m_editedPoint->GetPosition(), snapLayers,
|
|
|
|
grid.GetItemGrid( item ), { item } ) );
|
2021-07-13 15:10:18 +00:00
|
|
|
}
|
2018-10-04 00:15:54 +00:00
|
|
|
|
2023-10-06 17:04:00 +00:00
|
|
|
updateItem( &commit );
|
2021-05-25 17:12:49 +00:00
|
|
|
getViewControls()->ForceCursorPosition( true, m_editedPoint->GetPosition() );
|
2017-03-06 09:55:32 +00:00
|
|
|
updatePoints();
|
|
|
|
}
|
2020-09-24 01:27:23 +00:00
|
|
|
else if( m_editedPoint && evt->Action() == TA_MOUSE_DOWN && evt->Buttons() == BUT_LEFT )
|
|
|
|
{
|
|
|
|
m_editedPoint->SetActive();
|
2021-11-01 16:17:33 +00:00
|
|
|
|
|
|
|
for( size_t ii = 0; ii < m_editPoints->PointsSize(); ++ii )
|
|
|
|
{
|
|
|
|
EDIT_POINT& point = m_editPoints->Point( ii );
|
|
|
|
|
|
|
|
if( &point != m_editedPoint )
|
|
|
|
point.SetActive( false );
|
|
|
|
}
|
|
|
|
|
2020-09-24 01:27:23 +00:00
|
|
|
getView()->Update( m_editPoints.get() );
|
|
|
|
}
|
2019-06-17 13:43:22 +00:00
|
|
|
else if( inDrag && evt->IsMouseUp( BUT_LEFT ) )
|
2017-03-06 09:55:32 +00:00
|
|
|
{
|
2020-06-21 18:43:33 +00:00
|
|
|
if( m_editedPoint )
|
|
|
|
{
|
|
|
|
m_editedPoint->SetActive( false );
|
|
|
|
getView()->Update( m_editPoints.get() );
|
|
|
|
}
|
|
|
|
|
2021-05-25 17:12:49 +00:00
|
|
|
getViewControls()->SetAutoPan( false );
|
2017-03-06 09:55:32 +00:00
|
|
|
setAltConstraint( false );
|
2014-03-06 11:36:20 +00:00
|
|
|
|
2023-10-06 17:04:00 +00:00
|
|
|
if( item->Type() == PCB_GENERATOR_T )
|
|
|
|
{
|
|
|
|
m_toolMgr->RunSynchronousAction<PCB_GENERATOR*>(
|
|
|
|
PCB_ACTIONS::genPushEdit, &commit, static_cast<PCB_GENERATOR*>( item ) );
|
|
|
|
}
|
|
|
|
|
2023-08-05 15:43:10 +00:00
|
|
|
commit.Push( _( "Drag Corner" ) );
|
2023-10-06 17:04:00 +00:00
|
|
|
|
2019-06-17 13:43:22 +00:00
|
|
|
inDrag = false;
|
2020-10-08 09:59:17 +00:00
|
|
|
frame()->UndoRedoBlock( false );
|
|
|
|
|
2023-10-06 17:04:00 +00:00
|
|
|
m_toolMgr->PostAction<EDA_ITEM*>( PCB_ACTIONS::reselectItem,
|
|
|
|
item ); // FIXME: Needed for generators
|
2019-06-17 13:43:22 +00:00
|
|
|
m_refill = true;
|
2017-03-06 09:55:32 +00:00
|
|
|
}
|
2019-07-01 21:01:33 +00:00
|
|
|
else if( evt->IsCancelInteractive() || evt->IsActivate() )
|
2017-03-06 09:55:32 +00:00
|
|
|
{
|
2019-06-17 13:43:22 +00:00
|
|
|
if( inDrag ) // Restore the last change
|
2020-10-08 09:59:17 +00:00
|
|
|
{
|
2023-10-06 17:04:00 +00:00
|
|
|
if( item->Type() == PCB_GENERATOR_T )
|
|
|
|
{
|
|
|
|
m_toolMgr->RunSynchronousAction<PCB_GENERATOR*>(
|
|
|
|
PCB_ACTIONS::genRevertEdit, &commit,
|
|
|
|
static_cast<PCB_GENERATOR*>( item ) );
|
|
|
|
}
|
2019-06-16 00:06:43 +00:00
|
|
|
commit.Revert();
|
2023-10-06 17:04:00 +00:00
|
|
|
|
2020-10-08 09:59:17 +00:00
|
|
|
inDrag = false;
|
|
|
|
frame()->UndoRedoBlock( false );
|
|
|
|
}
|
2017-03-06 09:55:32 +00:00
|
|
|
|
2021-05-25 23:45:57 +00:00
|
|
|
// Only cancel point editor when activating a new tool
|
|
|
|
// Otherwise, allow the points to persist when moving up the
|
|
|
|
// tool stack
|
2019-07-01 21:01:33 +00:00
|
|
|
if( evt->IsActivate() && !evt->IsMoveTool() )
|
|
|
|
break;
|
2014-02-27 16:29:08 +00:00
|
|
|
}
|
2020-10-29 22:38:16 +00:00
|
|
|
else if( evt->Action() == TA_UNDO_REDO_POST )
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2017-03-06 09:55:32 +00:00
|
|
|
else
|
2020-10-29 22:38:16 +00:00
|
|
|
{
|
2019-06-16 11:06:49 +00:00
|
|
|
evt->SetPassEvent();
|
2020-10-29 22:38:16 +00:00
|
|
|
}
|
2017-03-06 09:55:32 +00:00
|
|
|
}
|
2014-02-27 16:29:08 +00:00
|
|
|
|
2017-03-06 09:55:32 +00:00
|
|
|
if( m_editPoints )
|
|
|
|
{
|
2021-05-25 17:12:49 +00:00
|
|
|
getView()->Remove( m_editPoints.get() );
|
2017-03-06 09:55:32 +00:00
|
|
|
m_editPoints.reset();
|
2014-03-06 13:41:25 +00:00
|
|
|
}
|
2014-02-27 16:29:08 +00:00
|
|
|
|
2021-10-10 15:24:45 +00:00
|
|
|
m_editedPoint = nullptr;
|
|
|
|
|
2014-02-27 16:29:08 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-08-05 15:43:10 +00:00
|
|
|
|
|
|
|
int PCB_POINT_EDITOR::movePoint( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
if( !m_editPoints || !m_editPoints->GetParent() || !HasPoint() )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
BOARD_COMMIT commit( frame() );
|
|
|
|
commit.Stage( m_editPoints->GetParent(), CHT_MODIFY );
|
|
|
|
|
|
|
|
wxString title;
|
|
|
|
wxString msg;
|
|
|
|
|
|
|
|
if( dynamic_cast<EDIT_LINE*>( m_editedPoint ) )
|
|
|
|
{
|
|
|
|
title = _( "Move Midpoint to Location" );
|
|
|
|
msg = _( "Move Midpoint" );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
title = _( "Move Corner to Location" );
|
|
|
|
msg = _( "Move Corner" );
|
|
|
|
}
|
|
|
|
|
|
|
|
WX_PT_ENTRY_DIALOG dlg( frame(), title, _( "X:" ), _( "Y:" ), m_editedPoint->GetPosition() );
|
|
|
|
|
|
|
|
if( dlg.ShowModal() == wxID_OK )
|
|
|
|
{
|
|
|
|
m_editedPoint->SetPosition( dlg.GetValue() );
|
2023-10-06 17:04:00 +00:00
|
|
|
updateItem( &commit );
|
2023-08-05 15:43:10 +00:00
|
|
|
commit.Push( msg );
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-07-26 23:47:26 +00:00
|
|
|
void PCB_POINT_EDITOR::editArcEndpointKeepTangent( PCB_SHAPE* aArc, const VECTOR2I& aCenter,
|
|
|
|
const VECTOR2I& aStart, const VECTOR2I& aMid,
|
|
|
|
const VECTOR2I& aEnd,
|
|
|
|
const VECTOR2I& aCursor ) const
|
2021-01-18 17:39:13 +00:00
|
|
|
{
|
2021-07-26 23:47:26 +00:00
|
|
|
VECTOR2I center = aCenter;
|
2021-10-14 23:39:31 +00:00
|
|
|
bool movingStart;
|
|
|
|
bool arcValid = true;
|
2021-01-18 17:39:13 +00:00
|
|
|
|
2021-07-26 23:47:26 +00:00
|
|
|
VECTOR2I p1, p2, p3;
|
2021-01-18 17:39:13 +00:00
|
|
|
// p1 does not move, p2 does.
|
|
|
|
|
2021-07-17 19:56:18 +00:00
|
|
|
if( aStart != aArc->GetStart() )
|
2021-01-18 17:39:13 +00:00
|
|
|
{
|
2021-07-26 23:47:26 +00:00
|
|
|
p1 = aEnd;
|
|
|
|
p2 = aStart;
|
|
|
|
p3 = aMid;
|
2021-01-18 17:39:13 +00:00
|
|
|
movingStart = true;
|
|
|
|
}
|
2021-07-17 19:56:18 +00:00
|
|
|
else if( aEnd != aArc->GetEnd() )
|
2021-01-18 17:39:13 +00:00
|
|
|
{
|
2021-07-26 23:47:26 +00:00
|
|
|
p1 = aStart;
|
|
|
|
p2 = aEnd;
|
|
|
|
p3 = aMid;
|
2021-01-18 17:39:13 +00:00
|
|
|
movingStart = false;
|
|
|
|
}
|
2021-02-03 23:50:46 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2021-01-18 17:39:13 +00:00
|
|
|
|
|
|
|
VECTOR2D v1, v2, v3, v4;
|
|
|
|
|
|
|
|
// Move the coordinate system
|
2021-07-26 23:47:26 +00:00
|
|
|
v1 = p1 - aCenter;
|
|
|
|
v2 = p2 - aCenter;
|
|
|
|
v3 = p3 - aCenter;
|
2021-01-18 17:39:13 +00:00
|
|
|
|
|
|
|
VECTOR2D u1, u2, u3;
|
|
|
|
|
|
|
|
// A point cannot be both the center and on the arc.
|
|
|
|
if( ( v1.EuclideanNorm() == 0 ) || ( v2.EuclideanNorm() == 0 ) )
|
|
|
|
return;
|
|
|
|
|
|
|
|
u1 = v1 / v1.EuclideanNorm();
|
|
|
|
u2 = v3 - ( u1.x * v3.x + u1.y * v3.y ) * u1;
|
|
|
|
u2 = u2 / u2.EuclideanNorm();
|
|
|
|
|
|
|
|
// [ u1, u3 ] is a base centered on the circle with:
|
|
|
|
// u1 : unit vector toward the point that does not move
|
|
|
|
// u2 : unit vector toward the mid point.
|
|
|
|
|
|
|
|
// Get vectors v1, and v2 in that coordinate system.
|
|
|
|
|
|
|
|
double det = u1.x * u2.y - u2.x * u1.y;
|
|
|
|
|
|
|
|
// u1 and u2 are unit vectors, and perpendicular.
|
|
|
|
// det should not be 0. In case it is, do not change the arc.
|
|
|
|
if( det == 0 )
|
|
|
|
return;
|
|
|
|
|
|
|
|
double tmpx = v1.x * u2.y - v1.y * u2.x;
|
|
|
|
double tmpy = -v1.x * u1.y + v1.y * u1.x;
|
|
|
|
v1.x = tmpx;
|
|
|
|
v1.y = tmpy;
|
|
|
|
v1 = v1 / det;
|
|
|
|
|
|
|
|
tmpx = v2.x * u2.y - v2.y * u2.x;
|
|
|
|
tmpy = -v2.x * u1.y + v2.y * u1.x;
|
|
|
|
v2.x = tmpx;
|
|
|
|
v2.y = tmpy;
|
|
|
|
v2 = v2 / det;
|
|
|
|
|
|
|
|
double R = v1.EuclideanNorm();
|
|
|
|
bool transformCircle = false;
|
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
/* p2
|
|
|
|
* X***
|
|
|
|
* ** <---- This is the arc
|
|
|
|
* y ^ **
|
|
|
|
* | R *
|
|
|
|
* | <-----------> *
|
|
|
|
* x------x------>--------x p1
|
|
|
|
* C' <----> C x
|
|
|
|
* delta
|
|
|
|
*
|
|
|
|
* p1 does not move, and the tangent at p1 remains the same.
|
|
|
|
* => The new center, C', will be on the C-p1 axis.
|
|
|
|
* p2 moves
|
|
|
|
*
|
|
|
|
* The radius of the new circle is delta + R
|
|
|
|
*
|
|
|
|
* || C' p2 || = || C' P1 ||
|
|
|
|
* is the same as :
|
|
|
|
* ( delta + p2.x ) ^ 2 + p2.y ^ 2 = ( R + delta ) ^ 2
|
|
|
|
*
|
|
|
|
* delta = ( R^2 - p2.x ^ 2 - p2.y ^2 ) / ( 2 * p2.x - 2 * R )
|
|
|
|
*
|
|
|
|
* We can use this equation for any point p2 with p2.x < R
|
|
|
|
*/
|
2021-01-18 17:39:13 +00:00
|
|
|
|
|
|
|
if( v2.x == R )
|
|
|
|
{
|
|
|
|
// Straight line, do nothing
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( v2.x > R )
|
|
|
|
{
|
|
|
|
// If we need to invert the curvature.
|
|
|
|
// We modify the input so we can use the same equation
|
|
|
|
transformCircle = true;
|
|
|
|
v2.x = 2 * R - v2.x;
|
|
|
|
}
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2021-01-18 17:39:13 +00:00
|
|
|
// We can keep the tangent constraint.
|
|
|
|
double delta = ( R * R - v2.x * v2.x - v2.y * v2.y ) / ( 2 * v2.x - 2 * R );
|
|
|
|
|
|
|
|
// This is just to limit the radius, so nothing overflows later when drawing.
|
|
|
|
if( abs( v2.y / ( R - v2.x ) ) > ADVANCED_CFG::GetCfg().m_DrawArcCenterMaxAngle )
|
|
|
|
arcValid = false;
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2021-01-18 17:39:13 +00:00
|
|
|
// Never recorded a problem, but still checking.
|
|
|
|
if( !std::isfinite( delta ) )
|
|
|
|
arcValid = false;
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2021-01-18 17:39:13 +00:00
|
|
|
// v4 is the new center
|
|
|
|
v4 = ( !transformCircle ) ? VECTOR2D( -delta, 0 ) : VECTOR2D( 2 * R + delta, 0 );
|
|
|
|
|
|
|
|
tmpx = v4.x * u1.x + v4.y * u2.x;
|
|
|
|
tmpy = v4.x * u1.y + v4.y * u2.y;
|
|
|
|
v4.x = tmpx;
|
|
|
|
v4.y = tmpy;
|
|
|
|
|
2021-07-26 23:47:26 +00:00
|
|
|
center = v4 + aCenter;
|
2021-01-18 17:39:13 +00:00
|
|
|
|
|
|
|
if( arcValid )
|
|
|
|
{
|
2022-01-01 17:11:21 +00:00
|
|
|
aArc->SetCenter( center );
|
2021-01-18 17:39:13 +00:00
|
|
|
|
|
|
|
if( movingStart )
|
2022-12-12 06:39:50 +00:00
|
|
|
aArc->SetStart( aStart );
|
2021-01-18 17:39:13 +00:00
|
|
|
else
|
2022-12-12 06:39:50 +00:00
|
|
|
aArc->SetEnd( aEnd );
|
2021-01-18 17:39:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-12-12 08:57:04 +00:00
|
|
|
void PCB_POINT_EDITOR::editArcCenterKeepEndpoints( PCB_SHAPE* aArc, const VECTOR2I& aCenter,
|
|
|
|
const VECTOR2I& aStart, const VECTOR2I& aMid,
|
|
|
|
const VECTOR2I& aEnd ) const
|
|
|
|
{
|
|
|
|
const int c_snapEpsilon_sq = 4;
|
|
|
|
|
|
|
|
VECTOR2I m = ( aStart / 2 + aEnd / 2 );
|
|
|
|
VECTOR2I perp = ( aEnd - aStart ).Perpendicular().Resize( INT_MAX / 2 );
|
|
|
|
|
|
|
|
SEG legal( m - perp, m + perp );
|
|
|
|
|
|
|
|
const SEG testSegments[] = { SEG( aCenter, aCenter + VECTOR2( 1, 0 ) ),
|
|
|
|
SEG( aCenter, aCenter + VECTOR2( 0, 1 ) ) };
|
|
|
|
|
|
|
|
std::vector<VECTOR2I> points = { legal.A, legal.B };
|
|
|
|
|
|
|
|
for( const SEG& seg : testSegments )
|
|
|
|
{
|
|
|
|
OPT_VECTOR2I vec = legal.IntersectLines( seg );
|
|
|
|
|
|
|
|
if( vec && legal.SquaredDistance( *vec ) <= c_snapEpsilon_sq )
|
|
|
|
points.push_back( *vec );
|
|
|
|
}
|
|
|
|
|
|
|
|
OPT_VECTOR2I nearest;
|
|
|
|
SEG::ecoord min_d_sq = VECTOR2I::ECOORD_MAX;
|
|
|
|
|
|
|
|
// Snap by distance between cursor and intersections
|
|
|
|
for( const VECTOR2I& pt : points )
|
|
|
|
{
|
|
|
|
SEG::ecoord d_sq = ( pt - aCenter ).SquaredEuclideanNorm();
|
|
|
|
|
|
|
|
if( d_sq < min_d_sq - c_snapEpsilon_sq )
|
|
|
|
{
|
|
|
|
min_d_sq = d_sq;
|
|
|
|
nearest = pt;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( nearest )
|
|
|
|
aArc->SetCenter( *nearest );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-08-19 22:26:36 +00:00
|
|
|
/**
|
2020-08-22 19:27:17 +00:00
|
|
|
* Update the coordinates of 4 corners of a rectangle, according to pad constraints and the
|
|
|
|
* moved corner
|
|
|
|
* @param aTopLeft [in/out] is the RECT_TOPLEFT to constraint
|
|
|
|
* @param aTopRight [in/out] is the RECT_TOPRIGHT to constraint
|
|
|
|
* @param aBotLeft [in/out] is the RECT_BOTLEFT to constraint
|
|
|
|
* @param aBotRight [in/out] is the RECT_BOTRIGHT to constraint
|
|
|
|
* @param aHole the location of the pad's hole
|
|
|
|
* @param aHoleSize the pad's hole size (or {0,0} if it has no hole)
|
2020-08-19 22:26:36 +00:00
|
|
|
*/
|
2022-04-07 10:51:00 +00:00
|
|
|
void PCB_POINT_EDITOR::pinEditedCorner( VECTOR2I& aTopLeft, VECTOR2I& aTopRight,
|
|
|
|
VECTOR2I& aBotLeft, VECTOR2I& aBotRight,
|
|
|
|
const VECTOR2I& aHole, const VECTOR2I& aHoleSize ) const
|
2020-08-19 22:26:36 +00:00
|
|
|
{
|
2022-09-16 04:38:10 +00:00
|
|
|
int minWidth = EDA_UNIT_UTILS::Mils2IU( pcbIUScale, 1 );
|
|
|
|
int minHeight = EDA_UNIT_UTILS::Mils2IU( pcbIUScale, 1 );
|
2022-04-07 10:51:00 +00:00
|
|
|
|
|
|
|
if( isModified( m_editPoints->Point( RECT_TOP_LEFT ) ) )
|
2020-08-19 22:26:36 +00:00
|
|
|
{
|
2020-08-22 19:27:17 +00:00
|
|
|
if( aHoleSize.x )
|
|
|
|
{
|
|
|
|
// pin edited point to the top/left of the hole
|
2022-04-07 10:51:00 +00:00
|
|
|
aTopLeft.x = std::min( aTopLeft.x, aHole.x - aHoleSize.x / 2 - minWidth );
|
|
|
|
aTopLeft.y = std::min( aTopLeft.y, aHole.y - aHoleSize.y / 2 - minHeight );
|
2020-08-22 19:27:17 +00:00
|
|
|
}
|
|
|
|
else
|
2020-08-19 22:26:36 +00:00
|
|
|
{
|
2020-08-22 19:27:17 +00:00
|
|
|
// pin edited point within opposite corner
|
2022-04-07 10:51:00 +00:00
|
|
|
aTopLeft.x = std::min( aTopLeft.x, aBotRight.x - minWidth );
|
|
|
|
aTopLeft.y = std::min( aTopLeft.y, aBotRight.y - minHeight );
|
2020-08-19 22:26:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// push edited point edges to adjacent corners
|
2020-08-22 19:27:17 +00:00
|
|
|
aTopRight.y = aTopLeft.y;
|
|
|
|
aBotLeft.x = aTopLeft.x;
|
2022-04-07 10:51:00 +00:00
|
|
|
}
|
|
|
|
else if( isModified( m_editPoints->Point( RECT_TOP_RIGHT ) ) )
|
|
|
|
{
|
2020-08-22 19:27:17 +00:00
|
|
|
if( aHoleSize.x )
|
|
|
|
{
|
|
|
|
// pin edited point to the top/right of the hole
|
2022-04-07 10:51:00 +00:00
|
|
|
aTopRight.x = std::max( aTopRight.x, aHole.x + aHoleSize.x / 2 + minWidth );
|
|
|
|
aTopRight.y = std::min( aTopRight.y, aHole.y - aHoleSize.y / 2 - minHeight );
|
2020-08-22 19:27:17 +00:00
|
|
|
}
|
|
|
|
else
|
2020-08-19 22:26:36 +00:00
|
|
|
{
|
2020-08-22 19:27:17 +00:00
|
|
|
// pin edited point within opposite corner
|
2022-04-07 10:51:00 +00:00
|
|
|
aTopRight.x = std::max( aTopRight.x, aBotLeft.x + minWidth );
|
|
|
|
aTopRight.y = std::min( aTopRight.y, aBotLeft.y - minHeight );
|
2020-08-19 22:26:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// push edited point edges to adjacent corners
|
2020-08-22 19:27:17 +00:00
|
|
|
aTopLeft.y = aTopRight.y;
|
|
|
|
aBotRight.x = aTopRight.x;
|
2022-04-07 10:51:00 +00:00
|
|
|
}
|
|
|
|
else if( isModified( m_editPoints->Point( RECT_BOT_LEFT ) ) )
|
|
|
|
{
|
2020-08-22 19:27:17 +00:00
|
|
|
if( aHoleSize.x )
|
|
|
|
{
|
|
|
|
// pin edited point to the bottom/left of the hole
|
2022-04-07 10:51:00 +00:00
|
|
|
aBotLeft.x = std::min( aBotLeft.x, aHole.x - aHoleSize.x / 2 - minWidth );
|
|
|
|
aBotLeft.y = std::max( aBotLeft.y, aHole.y + aHoleSize.y / 2 + minHeight );
|
2020-08-22 19:27:17 +00:00
|
|
|
}
|
|
|
|
else
|
2020-08-19 22:26:36 +00:00
|
|
|
{
|
2020-08-22 19:27:17 +00:00
|
|
|
// pin edited point within opposite corner
|
2022-04-07 10:51:00 +00:00
|
|
|
aBotLeft.x = std::min( aBotLeft.x, aTopRight.x - minWidth );
|
|
|
|
aBotLeft.y = std::max( aBotLeft.y, aTopRight.y + minHeight );
|
2020-08-19 22:26:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// push edited point edges to adjacent corners
|
2020-08-22 19:27:17 +00:00
|
|
|
aBotRight.y = aBotLeft.y;
|
|
|
|
aTopLeft.x = aBotLeft.x;
|
2022-04-07 10:51:00 +00:00
|
|
|
}
|
|
|
|
else if( isModified( m_editPoints->Point( RECT_BOT_RIGHT ) ) )
|
|
|
|
{
|
2020-08-22 19:27:17 +00:00
|
|
|
if( aHoleSize.x )
|
|
|
|
{
|
|
|
|
// pin edited point to the bottom/right of the hole
|
2022-04-07 10:51:00 +00:00
|
|
|
aBotRight.x = std::max( aBotRight.x, aHole.x + aHoleSize.x / 2 + minWidth );
|
|
|
|
aBotRight.y = std::max( aBotRight.y, aHole.y + aHoleSize.y / 2 + minHeight );
|
2020-08-22 19:27:17 +00:00
|
|
|
}
|
|
|
|
else
|
2020-08-19 22:26:36 +00:00
|
|
|
{
|
2020-08-22 19:27:17 +00:00
|
|
|
// pin edited point within opposite corner
|
2022-04-07 10:51:00 +00:00
|
|
|
aBotRight.x = std::max( aBotRight.x, aTopLeft.x + minWidth );
|
|
|
|
aBotRight.y = std::max( aBotRight.y, aTopLeft.y + minHeight );
|
2020-08-19 22:26:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// push edited point edges to adjacent corners
|
2020-08-22 19:27:17 +00:00
|
|
|
aBotLeft.y = aBotRight.y;
|
|
|
|
aTopRight.x = aBotRight.x;
|
2022-04-07 10:51:00 +00:00
|
|
|
}
|
|
|
|
else if( isModified( m_editPoints->Line( RECT_TOP ) ) )
|
|
|
|
{
|
|
|
|
aTopLeft.y = std::min( aTopLeft.y, aBotRight.y - minHeight );
|
|
|
|
}
|
|
|
|
else if( isModified( m_editPoints->Line( RECT_LEFT ) ) )
|
|
|
|
{
|
|
|
|
aTopLeft.x = std::min( aTopLeft.x, aBotRight.x - minWidth );
|
|
|
|
}
|
|
|
|
else if( isModified( m_editPoints->Line( RECT_BOT ) ) )
|
|
|
|
{
|
|
|
|
aBotRight.y = std::max( aBotRight.y, aTopLeft.y + minHeight );
|
|
|
|
}
|
|
|
|
else if( isModified( m_editPoints->Line( RECT_RIGHT ) ) )
|
|
|
|
{
|
|
|
|
aBotRight.x = std::max( aBotRight.x, aTopLeft.x + minWidth );
|
2020-08-19 22:26:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-07-26 23:47:26 +00:00
|
|
|
void PCB_POINT_EDITOR::editArcEndpointKeepCenter( PCB_SHAPE* aArc, const VECTOR2I& aCenter,
|
|
|
|
const VECTOR2I& aStart, const VECTOR2I& aMid,
|
|
|
|
const VECTOR2I& aEnd,
|
|
|
|
const VECTOR2I& aCursor ) const
|
2020-08-29 22:59:11 +00:00
|
|
|
{
|
2022-11-11 09:59:09 +00:00
|
|
|
int minRadius = EDA_UNIT_UTILS::Mils2IU( pcbIUScale, 1 );
|
2020-08-29 22:59:11 +00:00
|
|
|
bool movingStart;
|
|
|
|
|
2022-11-11 09:59:09 +00:00
|
|
|
VECTOR2I p1, p2, prev_p1;
|
2020-08-29 22:59:11 +00:00
|
|
|
|
2022-11-11 09:59:09 +00:00
|
|
|
// user is moving p1, we want to move p2 to the new radius.
|
2020-08-29 22:59:11 +00:00
|
|
|
|
2021-07-17 19:56:18 +00:00
|
|
|
if( aStart != aArc->GetStart() )
|
2020-08-29 22:59:11 +00:00
|
|
|
{
|
2022-11-11 09:59:09 +00:00
|
|
|
prev_p1 = aArc->GetStart();
|
|
|
|
p1 = aStart;
|
|
|
|
p2 = aEnd;
|
2020-08-29 22:59:11 +00:00
|
|
|
movingStart = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-11-11 09:59:09 +00:00
|
|
|
prev_p1 = aArc->GetEnd();
|
|
|
|
p1 = aEnd;
|
|
|
|
p2 = aStart;
|
2020-08-29 22:59:11 +00:00
|
|
|
movingStart = false;
|
|
|
|
}
|
|
|
|
|
2021-07-26 23:47:26 +00:00
|
|
|
p1 = p1 - aCenter;
|
|
|
|
p2 = p2 - aCenter;
|
2020-08-29 22:59:11 +00:00
|
|
|
|
2022-11-11 09:59:09 +00:00
|
|
|
if( p1.x == 0 && p1.y == 0 )
|
|
|
|
p1 = prev_p1 - aCenter;
|
2020-08-29 22:59:11 +00:00
|
|
|
|
2022-11-11 09:59:09 +00:00
|
|
|
if( p2.x == 0 && p2.y == 0 )
|
|
|
|
p2 = { 1, 0 };
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2022-11-11 09:59:09 +00:00
|
|
|
double radius = p1.EuclideanNorm();
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2022-11-11 09:59:09 +00:00
|
|
|
if( radius < minRadius )
|
|
|
|
radius = minRadius;
|
2020-08-29 22:59:11 +00:00
|
|
|
|
2022-11-11 09:59:09 +00:00
|
|
|
p1 = aCenter + p1.Resize( radius );
|
|
|
|
p2 = aCenter + p2.Resize( radius );
|
2020-08-29 22:59:11 +00:00
|
|
|
|
2022-01-01 17:11:21 +00:00
|
|
|
aArc->SetCenter( aCenter );
|
2020-08-29 22:59:11 +00:00
|
|
|
|
|
|
|
if( movingStart )
|
2022-11-11 09:59:09 +00:00
|
|
|
{
|
|
|
|
aArc->SetStart( p1 );
|
|
|
|
aArc->SetEnd( p2 );
|
|
|
|
}
|
2020-08-29 22:59:11 +00:00
|
|
|
else
|
2022-11-11 09:59:09 +00:00
|
|
|
{
|
|
|
|
aArc->SetStart( p2 );
|
|
|
|
aArc->SetEnd( p1 );
|
|
|
|
}
|
2020-08-29 22:59:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-07-26 23:47:26 +00:00
|
|
|
void PCB_POINT_EDITOR::editArcMidKeepCenter( PCB_SHAPE* aArc, const VECTOR2I& aCenter,
|
|
|
|
const VECTOR2I& aStart, const VECTOR2I& aMid,
|
|
|
|
const VECTOR2I& aEnd, const VECTOR2I& aCursor ) const
|
2020-08-29 22:59:11 +00:00
|
|
|
{
|
2022-11-11 09:59:09 +00:00
|
|
|
int minRadius = EDA_UNIT_UTILS::Mils2IU( pcbIUScale, 1 );
|
|
|
|
|
|
|
|
SEG chord( aStart, aEnd );
|
|
|
|
|
2020-08-29 22:59:11 +00:00
|
|
|
// Now, update the edit point position
|
2021-07-19 23:56:05 +00:00
|
|
|
// Express the point in a circle-centered coordinate system.
|
2021-07-26 23:47:26 +00:00
|
|
|
VECTOR2I start = aStart - aCenter;
|
2022-11-11 09:59:09 +00:00
|
|
|
VECTOR2I end = aEnd - aCenter;
|
2020-08-29 22:59:11 +00:00
|
|
|
|
2022-11-11 09:59:09 +00:00
|
|
|
double radius = ( aCursor - aCenter ).EuclideanNorm();
|
2020-08-29 22:59:11 +00:00
|
|
|
|
2022-11-11 09:59:09 +00:00
|
|
|
if( radius < minRadius )
|
|
|
|
radius = minRadius;
|
2020-08-29 22:59:11 +00:00
|
|
|
|
2022-11-11 09:59:09 +00:00
|
|
|
start = start.Resize( radius );
|
|
|
|
end = end.Resize( radius );
|
2020-08-29 22:59:11 +00:00
|
|
|
|
2021-07-26 23:47:26 +00:00
|
|
|
start = start + aCenter;
|
2022-11-11 09:59:09 +00:00
|
|
|
end = end + aCenter;
|
2020-08-29 22:59:11 +00:00
|
|
|
|
2022-01-01 17:11:21 +00:00
|
|
|
aArc->SetStart( start );
|
|
|
|
aArc->SetEnd( end );
|
2020-08-29 22:59:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-07-26 23:47:26 +00:00
|
|
|
void PCB_POINT_EDITOR::editArcMidKeepEndpoints( PCB_SHAPE* aArc, const VECTOR2I& aStart,
|
|
|
|
const VECTOR2I& aEnd,
|
|
|
|
const VECTOR2I& aCursor ) const
|
2020-08-29 22:59:11 +00:00
|
|
|
{
|
2021-01-19 23:07:31 +00:00
|
|
|
// Let 'm' be the middle point of the chord between the start and end points
|
|
|
|
VECTOR2I m = ( aStart + aEnd ) / 2;
|
2021-01-18 17:39:13 +00:00
|
|
|
|
2021-01-19 23:07:31 +00:00
|
|
|
// Legal midpoints lie on a vector starting just off the chord midpoint and extending out
|
|
|
|
// past the existing midpoint. We do not allow arc inflection while point editing.
|
|
|
|
const int JUST_OFF = ( aStart - aEnd ).EuclideanNorm() / 100;
|
|
|
|
VECTOR2I v = (VECTOR2I) aArc->GetArcMid() - m;
|
|
|
|
SEG legal( m + v.Resize( JUST_OFF ), m + v.Resize( INT_MAX / 2 ) );
|
|
|
|
VECTOR2I mid = legal.NearestPoint( aCursor );
|
2021-01-18 17:39:13 +00:00
|
|
|
|
2022-01-01 17:11:21 +00:00
|
|
|
aArc->SetArcGeometry( aStart, mid, aEnd );
|
2020-08-29 22:59:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-10-06 17:04:00 +00:00
|
|
|
void PCB_POINT_EDITOR::updateItem( BOARD_COMMIT* aCommit )
|
2014-02-27 16:29:08 +00:00
|
|
|
{
|
2014-02-28 15:53:28 +00:00
|
|
|
EDA_ITEM* item = m_editPoints->GetParent();
|
2014-02-27 16:29:08 +00:00
|
|
|
|
2017-05-16 09:38:00 +00:00
|
|
|
if( !item )
|
|
|
|
return;
|
|
|
|
|
2014-02-28 15:53:28 +00:00
|
|
|
switch( item->Type() )
|
2014-02-27 16:29:08 +00:00
|
|
|
{
|
2022-02-08 19:29:54 +00:00
|
|
|
case PCB_BITMAP_T:
|
|
|
|
{
|
|
|
|
PCB_BITMAP* bitmap = (PCB_BITMAP*) item;
|
|
|
|
VECTOR2I topLeft = m_editPoints->Point( RECT_TOP_LEFT ).GetPosition();
|
|
|
|
VECTOR2I topRight = m_editPoints->Point( RECT_TOP_RIGHT ).GetPosition();
|
|
|
|
VECTOR2I botLeft = m_editPoints->Point( RECT_BOT_LEFT ).GetPosition();
|
|
|
|
VECTOR2I botRight = m_editPoints->Point( RECT_BOT_RIGHT ).GetPosition();
|
|
|
|
|
|
|
|
pinEditedCorner( topLeft, topRight, botLeft, botRight );
|
|
|
|
|
|
|
|
double oldWidth = bitmap->GetSize().x;
|
2022-09-16 04:38:10 +00:00
|
|
|
double newWidth = std::max( topRight.x - topLeft.x, EDA_UNIT_UTILS::Mils2IU( pcbIUScale, 50 ) );
|
2022-02-08 19:29:54 +00:00
|
|
|
double widthRatio = newWidth / oldWidth;
|
|
|
|
|
|
|
|
double oldHeight = bitmap->GetSize().y;
|
2022-09-16 04:38:10 +00:00
|
|
|
double newHeight =
|
|
|
|
std::max( botLeft.y - topLeft.y, EDA_UNIT_UTILS::Mils2IU( pcbIUScale, 50 ) );
|
2022-02-08 19:29:54 +00:00
|
|
|
double heightRatio = newHeight / oldHeight;
|
|
|
|
|
|
|
|
bitmap->SetImageScale( bitmap->GetImageScale() * std::min( widthRatio, heightRatio ) );
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2022-01-30 10:52:52 +00:00
|
|
|
case PCB_TEXTBOX_T:
|
2020-10-04 14:19:33 +00:00
|
|
|
case PCB_SHAPE_T:
|
2014-02-27 16:29:08 +00:00
|
|
|
{
|
2020-10-04 23:34:59 +00:00
|
|
|
PCB_SHAPE* shape = static_cast<PCB_SHAPE*>( item );
|
2020-06-28 22:34:10 +00:00
|
|
|
|
2020-10-04 23:34:59 +00:00
|
|
|
switch( shape->GetShape() )
|
2014-02-27 16:29:08 +00:00
|
|
|
{
|
2021-07-21 18:31:25 +00:00
|
|
|
case SHAPE_T::SEGMENT:
|
2014-04-01 15:41:24 +00:00
|
|
|
if( isModified( m_editPoints->Point( SEG_START ) ) )
|
2022-01-01 17:11:21 +00:00
|
|
|
shape->SetStart( m_editPoints->Point( SEG_START ).GetPosition() );
|
2014-04-01 15:41:24 +00:00
|
|
|
else if( isModified( m_editPoints->Point( SEG_END ) ) )
|
2022-01-01 17:11:21 +00:00
|
|
|
shape->SetEnd( m_editPoints->Point( SEG_END ).GetPosition() );
|
2014-02-27 16:29:08 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
2023-07-24 16:07:56 +00:00
|
|
|
case SHAPE_T::RECTANGLE:
|
2020-06-15 19:50:20 +00:00
|
|
|
{
|
2022-04-07 10:51:00 +00:00
|
|
|
VECTOR2I topLeft = m_editPoints->Point( RECT_TOP_LEFT ).GetPosition();
|
|
|
|
VECTOR2I topRight = m_editPoints->Point( RECT_TOP_RIGHT ).GetPosition();
|
|
|
|
VECTOR2I botLeft = m_editPoints->Point( RECT_BOT_LEFT ).GetPosition();
|
|
|
|
VECTOR2I botRight = m_editPoints->Point( RECT_BOT_RIGHT ).GetPosition();
|
|
|
|
|
|
|
|
pinEditedCorner( topLeft, topRight, botLeft, botRight );
|
|
|
|
|
|
|
|
if( isModified( m_editPoints->Point( RECT_TOP_LEFT ) )
|
|
|
|
|| isModified( m_editPoints->Point( RECT_TOP_RIGHT ) )
|
|
|
|
|| isModified( m_editPoints->Point( RECT_BOT_RIGHT ) )
|
|
|
|
|| isModified( m_editPoints->Point( RECT_BOT_LEFT ) ) )
|
2020-06-15 19:50:20 +00:00
|
|
|
{
|
2022-06-02 09:42:13 +00:00
|
|
|
shape->SetLeft( topLeft.x );
|
|
|
|
shape->SetTop( topLeft.y );
|
|
|
|
shape->SetRight( botRight.x );
|
|
|
|
shape->SetBottom( botRight.y );
|
2020-06-15 19:50:20 +00:00
|
|
|
}
|
2021-01-13 22:03:31 +00:00
|
|
|
else if( isModified( m_editPoints->Line( RECT_TOP ) ) )
|
|
|
|
{
|
2022-06-02 09:42:13 +00:00
|
|
|
shape->SetTop( topLeft.y );
|
2021-01-13 22:03:31 +00:00
|
|
|
}
|
|
|
|
else if( isModified( m_editPoints->Line( RECT_LEFT ) ) )
|
|
|
|
{
|
2022-06-02 09:42:13 +00:00
|
|
|
shape->SetLeft( topLeft.x );
|
2021-01-13 22:03:31 +00:00
|
|
|
}
|
|
|
|
else if( isModified( m_editPoints->Line( RECT_BOT ) ) )
|
|
|
|
{
|
2022-06-02 09:42:13 +00:00
|
|
|
shape->SetBottom( botRight.y );
|
2021-01-13 22:03:31 +00:00
|
|
|
}
|
|
|
|
else if( isModified( m_editPoints->Line( RECT_RIGHT ) ) )
|
|
|
|
{
|
2022-06-02 09:42:13 +00:00
|
|
|
shape->SetRight( botRight.x );
|
2021-01-13 22:03:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for( unsigned i = 0; i < m_editPoints->LinesSize(); ++i )
|
|
|
|
{
|
|
|
|
if( !isModified( m_editPoints->Line( i ) ) )
|
2022-01-30 10:52:52 +00:00
|
|
|
{
|
2021-07-19 23:56:05 +00:00
|
|
|
m_editPoints->Line( i ).SetConstraint(
|
|
|
|
new EC_PERPLINE( m_editPoints->Line( i ) ) );
|
2022-01-30 10:52:52 +00:00
|
|
|
}
|
2021-01-13 22:03:31 +00:00
|
|
|
}
|
2022-01-30 10:52:52 +00:00
|
|
|
|
2020-06-15 19:50:20 +00:00
|
|
|
break;
|
2022-01-30 10:52:52 +00:00
|
|
|
}
|
2020-06-15 19:50:20 +00:00
|
|
|
|
2021-07-21 18:31:25 +00:00
|
|
|
case SHAPE_T::ARC:
|
2014-02-27 16:29:08 +00:00
|
|
|
{
|
2018-12-08 15:26:47 +00:00
|
|
|
VECTOR2I center = m_editPoints->Point( ARC_CENTER ).GetPosition();
|
|
|
|
VECTOR2I mid = m_editPoints->Point( ARC_MID ).GetPosition();
|
|
|
|
VECTOR2I start = m_editPoints->Point( ARC_START ).GetPosition();
|
|
|
|
VECTOR2I end = m_editPoints->Point( ARC_END ).GetPosition();
|
2014-02-27 16:29:08 +00:00
|
|
|
|
2020-08-29 22:59:11 +00:00
|
|
|
if( isModified( m_editPoints->Point( ARC_CENTER ) ) )
|
2014-02-27 16:29:08 +00:00
|
|
|
{
|
2022-12-12 08:57:04 +00:00
|
|
|
if( m_arcEditMode == ARC_EDIT_MODE::KEEP_ENDPOINTS_OR_START_DIRECTION )
|
|
|
|
{
|
|
|
|
editArcCenterKeepEndpoints( shape, center, start, mid, end );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
VECTOR2I moveVector = VECTOR2I( center.x, center.y ) - shape->GetCenter();
|
|
|
|
shape->Move( moveVector );
|
|
|
|
}
|
2014-02-27 16:29:08 +00:00
|
|
|
}
|
2020-08-29 22:59:11 +00:00
|
|
|
else if( isModified( m_editPoints->Point( ARC_MID ) ) )
|
2014-02-27 16:29:08 +00:00
|
|
|
{
|
2020-10-08 09:59:17 +00:00
|
|
|
const VECTOR2I& cursorPos = getViewControls()->GetCursorPosition( false );
|
|
|
|
|
2022-12-05 18:27:00 +00:00
|
|
|
if( m_arcEditMode == ARC_EDIT_MODE::KEEP_ENDPOINTS_OR_START_DIRECTION )
|
2021-01-19 23:07:31 +00:00
|
|
|
editArcMidKeepEndpoints( shape, start, end, cursorPos );
|
2022-11-11 09:32:02 +00:00
|
|
|
else
|
|
|
|
editArcMidKeepCenter( shape, center, start, mid, end, cursorPos );
|
2020-08-29 22:59:11 +00:00
|
|
|
}
|
|
|
|
else if( isModified( m_editPoints->Point( ARC_START ) )
|
|
|
|
|| isModified( m_editPoints->Point( ARC_END ) ) )
|
|
|
|
{
|
2020-10-08 09:59:17 +00:00
|
|
|
const VECTOR2I& cursorPos = getViewControls()->GetCursorPosition();
|
|
|
|
|
2022-12-05 18:27:00 +00:00
|
|
|
if( m_arcEditMode == ARC_EDIT_MODE::KEEP_ENDPOINTS_OR_START_DIRECTION )
|
2021-01-18 17:39:13 +00:00
|
|
|
editArcEndpointKeepTangent( shape, center, start, mid, end, cursorPos );
|
2022-11-11 09:32:02 +00:00
|
|
|
else
|
|
|
|
editArcEndpointKeepCenter( shape, center, start, mid, end, cursorPos );
|
2014-02-27 16:29:08 +00:00
|
|
|
}
|
2022-01-30 10:52:52 +00:00
|
|
|
|
2020-06-15 19:50:20 +00:00
|
|
|
break;
|
2022-01-30 10:52:52 +00:00
|
|
|
}
|
2014-02-28 17:24:13 +00:00
|
|
|
|
2021-07-21 18:31:25 +00:00
|
|
|
case SHAPE_T::CIRCLE:
|
2014-02-28 17:24:13 +00:00
|
|
|
{
|
2014-04-01 15:41:24 +00:00
|
|
|
const VECTOR2I& center = m_editPoints->Point( CIRC_CENTER ).GetPosition();
|
|
|
|
const VECTOR2I& end = m_editPoints->Point( CIRC_END ).GetPosition();
|
2014-02-28 17:24:13 +00:00
|
|
|
|
2014-04-01 15:41:24 +00:00
|
|
|
if( isModified( m_editPoints->Point( CIRC_CENTER ) ) )
|
2014-02-28 17:24:13 +00:00
|
|
|
{
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I moveVector = VECTOR2I( center.x, center.y ) - shape->GetCenter();
|
2020-10-04 23:34:59 +00:00
|
|
|
shape->Move( moveVector );
|
2014-02-28 17:24:13 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-01-01 06:04:08 +00:00
|
|
|
shape->SetEnd( VECTOR2I( end.x, end.y ) );
|
2014-02-28 17:24:13 +00:00
|
|
|
}
|
2022-01-30 10:52:52 +00:00
|
|
|
|
2020-06-15 19:50:20 +00:00
|
|
|
break;
|
2022-01-30 10:52:52 +00:00
|
|
|
}
|
2014-02-27 16:29:08 +00:00
|
|
|
|
2021-07-21 18:31:25 +00:00
|
|
|
case SHAPE_T::POLY:
|
2017-10-19 21:14:01 +00:00
|
|
|
{
|
2020-10-04 23:34:59 +00:00
|
|
|
SHAPE_POLY_SET& outline = shape->GetPolyShape();
|
2017-10-19 21:14:01 +00:00
|
|
|
|
2018-02-22 11:28:01 +00:00
|
|
|
for( int i = 0; i < outline.TotalVertices(); ++i )
|
2019-03-23 18:26:44 +00:00
|
|
|
outline.SetVertex( i, m_editPoints->Point( i ).GetPosition() );
|
2018-02-22 11:28:01 +00:00
|
|
|
|
2020-08-27 17:31:53 +00:00
|
|
|
for( unsigned i = 0; i < m_editPoints->LinesSize(); ++i )
|
|
|
|
{
|
|
|
|
if( !isModified( m_editPoints->Line( i ) ) )
|
2021-07-19 23:56:05 +00:00
|
|
|
m_editPoints->Line( i ).SetConstraint(
|
|
|
|
new EC_PERPLINE( m_editPoints->Line( i ) ) );
|
2020-08-27 17:31:53 +00:00
|
|
|
}
|
|
|
|
|
2018-03-02 09:55:59 +00:00
|
|
|
validatePolygon( outline );
|
2020-06-15 19:50:20 +00:00
|
|
|
break;
|
2022-01-30 10:52:52 +00:00
|
|
|
}
|
2017-10-19 21:14:01 +00:00
|
|
|
|
2021-07-21 18:31:25 +00:00
|
|
|
case SHAPE_T::BEZIER:
|
2018-07-22 12:50:35 +00:00
|
|
|
if( isModified( m_editPoints->Point( BEZIER_CURVE_START ) ) )
|
2022-06-01 22:55:59 +00:00
|
|
|
shape->SetStart( m_editPoints->Point( BEZIER_CURVE_START ).GetPosition() );
|
2018-07-22 12:50:35 +00:00
|
|
|
else if( isModified( m_editPoints->Point( BEZIER_CURVE_CONTROL_POINT1 ) ) )
|
2022-06-01 22:55:59 +00:00
|
|
|
shape->SetBezierC1( m_editPoints->Point( BEZIER_CURVE_CONTROL_POINT1 ).GetPosition() );
|
2018-07-22 12:50:35 +00:00
|
|
|
else if( isModified( m_editPoints->Point( BEZIER_CURVE_CONTROL_POINT2 ) ) )
|
2022-06-01 22:55:59 +00:00
|
|
|
shape->SetBezierC2( m_editPoints->Point( BEZIER_CURVE_CONTROL_POINT2 ).GetPosition() );
|
2018-07-22 12:50:35 +00:00
|
|
|
else if( isModified( m_editPoints->Point( BEZIER_CURVE_END ) ) )
|
2022-01-01 17:11:21 +00:00
|
|
|
shape->SetEnd( m_editPoints->Point( BEZIER_CURVE_END ).GetPosition() );
|
2018-07-22 12:50:35 +00:00
|
|
|
|
2020-10-04 23:34:59 +00:00
|
|
|
shape->RebuildBezierToSegmentsPointsList( shape->GetWidth() );
|
2018-07-22 12:50:35 +00:00
|
|
|
break;
|
|
|
|
|
2014-02-27 16:29:08 +00:00
|
|
|
default: // suppress warnings
|
|
|
|
break;
|
|
|
|
}
|
2014-02-28 17:24:29 +00:00
|
|
|
|
2023-09-13 10:27:04 +00:00
|
|
|
if( shape->IsProxyItem() )
|
2022-09-14 10:34:10 +00:00
|
|
|
{
|
2023-03-30 11:49:23 +00:00
|
|
|
for( PAD* pad : shape->GetParentFootprint()->Pads() )
|
2022-09-14 10:34:10 +00:00
|
|
|
{
|
2023-09-01 17:46:51 +00:00
|
|
|
if( pad->IsEntered() )
|
2023-03-30 11:49:23 +00:00
|
|
|
view()->Update( pad );
|
2022-09-14 10:34:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-04 16:39:33 +00:00
|
|
|
// Nuke outline font render caches
|
|
|
|
if( PCB_TEXTBOX* textBox = dynamic_cast<PCB_TEXTBOX*>( item ) )
|
|
|
|
textBox->ClearRenderCache();
|
|
|
|
|
2014-02-28 17:24:29 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-06-28 22:34:10 +00:00
|
|
|
case PCB_PAD_T:
|
|
|
|
{
|
2020-11-12 22:30:02 +00:00
|
|
|
PAD* pad = static_cast<PAD*>( item );
|
2020-06-28 22:34:10 +00:00
|
|
|
|
|
|
|
switch( pad->GetShape() )
|
|
|
|
{
|
2021-05-01 12:22:35 +00:00
|
|
|
case PAD_SHAPE::CIRCLE:
|
2020-06-28 22:34:10 +00:00
|
|
|
{
|
2022-01-01 17:11:21 +00:00
|
|
|
VECTOR2I end = m_editPoints->Point( 0 ).GetPosition();
|
2022-06-01 22:55:59 +00:00
|
|
|
int diameter = (int) EuclideanNorm( end - pad->GetPosition() ) * 2;
|
2020-06-28 22:34:10 +00:00
|
|
|
|
2023-02-19 03:40:07 +00:00
|
|
|
pad->SetSize( VECTOR2I( diameter, diameter ) );
|
2020-06-28 22:34:10 +00:00
|
|
|
break;
|
2022-01-30 10:52:52 +00:00
|
|
|
}
|
2020-06-28 22:34:10 +00:00
|
|
|
|
2021-05-01 12:22:35 +00:00
|
|
|
case PAD_SHAPE::OVAL:
|
|
|
|
case PAD_SHAPE::TRAPEZOID:
|
2023-06-02 09:10:48 +00:00
|
|
|
case PAD_SHAPE::RECTANGLE:
|
2021-05-01 12:22:35 +00:00
|
|
|
case PAD_SHAPE::ROUNDRECT:
|
|
|
|
case PAD_SHAPE::CHAMFERED_RECT:
|
2020-06-28 22:34:10 +00:00
|
|
|
{
|
2020-08-19 22:26:36 +00:00
|
|
|
VECTOR2I topLeft = m_editPoints->Point( RECT_TOP_LEFT ).GetPosition();
|
|
|
|
VECTOR2I topRight = m_editPoints->Point( RECT_TOP_RIGHT ).GetPosition();
|
|
|
|
VECTOR2I botLeft = m_editPoints->Point( RECT_BOT_LEFT ).GetPosition();
|
|
|
|
VECTOR2I botRight = m_editPoints->Point( RECT_BOT_RIGHT ).GetPosition();
|
2021-07-26 23:47:26 +00:00
|
|
|
VECTOR2I holeCenter = pad->GetPosition();
|
|
|
|
VECTOR2I holeSize = pad->GetDrillSize();
|
2020-08-19 22:26:36 +00:00
|
|
|
|
2022-04-07 10:51:00 +00:00
|
|
|
pinEditedCorner( topLeft, topRight, botLeft, botRight, holeCenter, holeSize );
|
2020-08-19 22:26:36 +00:00
|
|
|
|
2020-06-29 18:14:51 +00:00
|
|
|
if( ( pad->GetOffset().x || pad->GetOffset().y )
|
|
|
|
|| ( pad->GetDrillSize().x && pad->GetDrillSize().y ) )
|
|
|
|
{
|
2020-06-29 22:25:13 +00:00
|
|
|
// Keep hole pinned at the current location; adjust the pad around the hole
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I center = pad->GetPosition();
|
|
|
|
int dist[4];
|
2020-06-29 22:25:13 +00:00
|
|
|
|
|
|
|
if( isModified( m_editPoints->Point( RECT_TOP_LEFT ) )
|
|
|
|
|| isModified( m_editPoints->Point( RECT_BOT_RIGHT ) ) )
|
|
|
|
{
|
2021-02-01 00:33:00 +00:00
|
|
|
dist[0] = center.x - topLeft.x;
|
|
|
|
dist[1] = center.y - topLeft.y;
|
|
|
|
dist[2] = botRight.x - center.x;
|
|
|
|
dist[3] = botRight.y - center.y;
|
2020-06-29 22:25:13 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-02-01 00:33:00 +00:00
|
|
|
dist[0] = center.x - botLeft.x;
|
|
|
|
dist[1] = center.y - topRight.y;
|
|
|
|
dist[2] = topRight.x - center.x;
|
|
|
|
dist[3] = botLeft.y - center.y;
|
2020-06-29 22:25:13 +00:00
|
|
|
}
|
|
|
|
|
2023-02-19 03:40:07 +00:00
|
|
|
VECTOR2I padSize( dist[0] + dist[2], dist[1] + dist[3] );
|
2022-01-01 17:11:21 +00:00
|
|
|
VECTOR2I deltaOffset( padSize.x / 2 - dist[2], padSize.y / 2 - dist[3] );
|
2020-06-28 22:34:10 +00:00
|
|
|
|
2022-01-13 13:45:48 +00:00
|
|
|
if( pad->GetOrientation() == ANGLE_90 || pad->GetOrientation() == ANGLE_270 )
|
2020-06-29 18:14:51 +00:00
|
|
|
std::swap( padSize.x, padSize.y );
|
|
|
|
|
2022-01-01 17:11:21 +00:00
|
|
|
RotatePoint( deltaOffset, -pad->GetOrientation() );
|
2020-06-29 18:14:51 +00:00
|
|
|
|
|
|
|
pad->SetSize( padSize );
|
|
|
|
pad->SetOffset( -deltaOffset );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-06-29 22:25:13 +00:00
|
|
|
// Keep pad position at the center of the pad shape
|
|
|
|
|
|
|
|
int left, top, right, bottom;
|
|
|
|
|
|
|
|
if( isModified( m_editPoints->Point( RECT_TOP_LEFT ) )
|
|
|
|
|| isModified( m_editPoints->Point( RECT_BOT_RIGHT ) ) )
|
|
|
|
{
|
2021-02-01 00:33:00 +00:00
|
|
|
left = topLeft.x;
|
|
|
|
top = topLeft.y;
|
|
|
|
right = botRight.x;
|
|
|
|
bottom = botRight.y;
|
2020-06-29 22:25:13 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-02-01 00:33:00 +00:00
|
|
|
left = botLeft.x;
|
|
|
|
top = topRight.y;
|
|
|
|
right = topRight.x;
|
|
|
|
bottom = botLeft.y;
|
2020-06-29 22:25:13 +00:00
|
|
|
}
|
|
|
|
|
2023-02-19 03:40:07 +00:00
|
|
|
VECTOR2I padSize( abs( right - left ), abs( bottom - top ) );
|
2020-06-29 22:25:13 +00:00
|
|
|
|
2022-01-13 13:45:48 +00:00
|
|
|
if( pad->GetOrientation() == ANGLE_90 || pad->GetOrientation() == ANGLE_270 )
|
2020-06-29 18:14:51 +00:00
|
|
|
std::swap( padSize.x, padSize.y );
|
2020-06-28 22:34:10 +00:00
|
|
|
|
2020-06-29 18:14:51 +00:00
|
|
|
pad->SetSize( padSize );
|
2022-01-01 17:11:21 +00:00
|
|
|
pad->SetPosition( VECTOR2I( ( left + right ) / 2, ( top + bottom ) / 2 ) );
|
2020-06-29 18:14:51 +00:00
|
|
|
}
|
2020-06-28 22:34:10 +00:00
|
|
|
break;
|
2022-01-30 10:52:52 +00:00
|
|
|
}
|
2020-06-28 22:34:10 +00:00
|
|
|
|
|
|
|
default: // suppress warnings
|
|
|
|
break;
|
|
|
|
}
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2020-06-28 22:34:10 +00:00
|
|
|
break;
|
2021-07-19 23:56:05 +00:00
|
|
|
}
|
2020-06-28 22:34:10 +00:00
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
case PCB_ZONE_T:
|
2014-02-28 17:24:29 +00:00
|
|
|
{
|
2020-11-11 23:05:59 +00:00
|
|
|
ZONE* zone = static_cast<ZONE*>( item );
|
2021-03-19 19:32:44 +00:00
|
|
|
zone->UnFill();
|
2018-02-22 11:28:01 +00:00
|
|
|
SHAPE_POLY_SET& outline = *zone->Outline();
|
2014-02-28 17:24:29 +00:00
|
|
|
|
2018-02-22 11:28:01 +00:00
|
|
|
for( int i = 0; i < outline.TotalVertices(); ++i )
|
2019-03-14 13:35:55 +00:00
|
|
|
{
|
2019-03-23 18:26:44 +00:00
|
|
|
if( outline.CVertex( i ) != m_editPoints->Point( i ).GetPosition() )
|
2019-03-14 13:35:55 +00:00
|
|
|
zone->SetNeedRefill( true );
|
|
|
|
|
2019-03-23 18:26:44 +00:00
|
|
|
outline.SetVertex( i, m_editPoints->Point( i ).GetPosition() );
|
2021-03-19 11:34:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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-03-14 13:35:55 +00:00
|
|
|
}
|
2014-02-28 17:24:29 +00:00
|
|
|
|
2018-03-02 09:55:59 +00:00
|
|
|
validatePolygon( outline );
|
2020-08-07 14:04:34 +00:00
|
|
|
zone->HatchBorder();
|
2021-07-26 23:47:26 +00:00
|
|
|
|
2021-03-19 19:07:16 +00:00
|
|
|
// TODO Refill zone when KiCad supports auto re-fill
|
2014-02-27 16:29:08 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2023-10-06 17:04:00 +00:00
|
|
|
case PCB_GENERATOR_T:
|
|
|
|
{
|
|
|
|
PCB_GENERATOR* generator = static_cast<PCB_GENERATOR*>( item );
|
|
|
|
generator->UpdateFromEditPoints( m_editPoints, aCommit );
|
|
|
|
|
|
|
|
m_toolMgr->RunSynchronousAction<PCB_GENERATOR*>( PCB_ACTIONS::genUpdateEdit, aCommit,
|
|
|
|
generator );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-09-12 20:09:40 +00:00
|
|
|
case PCB_DIM_ALIGNED_T:
|
2014-03-12 09:46:11 +00:00
|
|
|
{
|
2021-06-11 16:59:28 +00:00
|
|
|
PCB_DIM_ALIGNED* dimension = static_cast<PCB_DIM_ALIGNED*>( item );
|
2014-03-12 09:46:11 +00:00
|
|
|
|
|
|
|
// Check which point is currently modified and updated dimension's points respectively
|
2020-09-09 03:17:08 +00:00
|
|
|
if( isModified( m_editPoints->Point( DIM_CROSSBARSTART ) ) )
|
2014-03-12 09:46:11 +00:00
|
|
|
{
|
2020-09-09 03:17:08 +00:00
|
|
|
VECTOR2D featureLine( m_editedPoint->GetPosition() - dimension->GetStart() );
|
|
|
|
VECTOR2D crossBar( dimension->GetEnd() - dimension->GetStart() );
|
2014-03-12 09:46:11 +00:00
|
|
|
|
|
|
|
if( featureLine.Cross( crossBar ) > 0 )
|
2020-09-09 03:17:08 +00:00
|
|
|
dimension->SetHeight( -featureLine.EuclideanNorm() );
|
2014-03-12 09:46:11 +00:00
|
|
|
else
|
2020-09-09 03:17:08 +00:00
|
|
|
dimension->SetHeight( featureLine.EuclideanNorm() );
|
2014-03-12 09:53:42 +00:00
|
|
|
|
2021-01-19 16:08:37 +00:00
|
|
|
dimension->Update();
|
|
|
|
}
|
2020-09-09 03:17:08 +00:00
|
|
|
else if( isModified( m_editPoints->Point( DIM_CROSSBAREND ) ) )
|
2014-03-12 09:46:11 +00:00
|
|
|
{
|
2015-06-19 15:32:33 +00:00
|
|
|
VECTOR2D featureLine( m_editedPoint->GetPosition() - dimension->GetEnd() );
|
2020-09-09 03:17:08 +00:00
|
|
|
VECTOR2D crossBar( dimension->GetEnd() - dimension->GetStart() );
|
2014-03-12 09:46:11 +00:00
|
|
|
|
|
|
|
if( featureLine.Cross( crossBar ) > 0 )
|
2020-09-09 03:17:08 +00:00
|
|
|
dimension->SetHeight( -featureLine.EuclideanNorm() );
|
2014-03-12 09:46:11 +00:00
|
|
|
else
|
2020-09-09 03:17:08 +00:00
|
|
|
dimension->SetHeight( featureLine.EuclideanNorm() );
|
2014-03-12 09:46:11 +00:00
|
|
|
|
2021-01-19 16:08:37 +00:00
|
|
|
dimension->Update();
|
|
|
|
}
|
2020-09-09 03:17:08 +00:00
|
|
|
else if( isModified( m_editPoints->Point( DIM_START ) ) )
|
2014-03-12 09:53:42 +00:00
|
|
|
{
|
2022-01-01 17:11:21 +00:00
|
|
|
dimension->SetStart( m_editedPoint->GetPosition() );
|
2021-01-19 16:08:37 +00:00
|
|
|
dimension->Update();
|
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
m_editPoints->Point( DIM_CROSSBARSTART ).
|
|
|
|
SetConstraint( new EC_LINE( m_editPoints->Point( DIM_CROSSBARSTART ),
|
|
|
|
m_editPoints->Point( DIM_START ) ) );
|
|
|
|
m_editPoints->Point( DIM_CROSSBAREND ).
|
|
|
|
SetConstraint( new EC_LINE( m_editPoints->Point( DIM_CROSSBAREND ),
|
|
|
|
m_editPoints->Point( DIM_END ) ) );
|
2014-03-12 09:53:42 +00:00
|
|
|
}
|
2020-09-09 03:17:08 +00:00
|
|
|
else if( isModified( m_editPoints->Point( DIM_END ) ) )
|
2014-03-12 09:53:42 +00:00
|
|
|
{
|
2022-01-01 17:11:21 +00:00
|
|
|
dimension->SetEnd( m_editedPoint->GetPosition() );
|
2021-01-19 16:08:37 +00:00
|
|
|
dimension->Update();
|
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
m_editPoints->Point( DIM_CROSSBARSTART ).
|
|
|
|
SetConstraint( new EC_LINE( m_editPoints->Point( DIM_CROSSBARSTART ),
|
|
|
|
m_editPoints->Point( DIM_START ) ) );
|
|
|
|
m_editPoints->Point( DIM_CROSSBAREND ).
|
|
|
|
SetConstraint( new EC_LINE( m_editPoints->Point( DIM_CROSSBAREND ),
|
|
|
|
m_editPoints->Point( DIM_END ) ) );
|
2014-03-12 09:53:42 +00:00
|
|
|
}
|
2020-09-11 23:52:45 +00:00
|
|
|
else if( isModified( m_editPoints->Point(DIM_TEXT ) ) )
|
|
|
|
{
|
|
|
|
// Force manual mode if we weren't already in it
|
|
|
|
dimension->SetTextPositionMode( DIM_TEXT_POSITION::MANUAL );
|
2023-03-04 23:15:43 +00:00
|
|
|
dimension->SetTextPos( m_editedPoint->GetPosition() );
|
2020-09-11 23:52:45 +00:00
|
|
|
dimension->Update();
|
|
|
|
}
|
|
|
|
|
2014-03-12 09:46:11 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-09-22 02:32:40 +00:00
|
|
|
case PCB_DIM_ORTHOGONAL_T:
|
|
|
|
{
|
2021-06-11 16:59:28 +00:00
|
|
|
PCB_DIM_ORTHOGONAL* dimension = static_cast<PCB_DIM_ORTHOGONAL*>( item );
|
2020-09-22 02:32:40 +00:00
|
|
|
|
|
|
|
if( isModified( m_editPoints->Point( DIM_CROSSBARSTART ) ) ||
|
|
|
|
isModified( m_editPoints->Point( DIM_CROSSBAREND ) ) )
|
|
|
|
{
|
2021-03-05 14:40:02 +00:00
|
|
|
BOX2I bounds( dimension->GetStart(), dimension->GetEnd() - dimension->GetStart() );
|
|
|
|
|
|
|
|
const VECTOR2I& cursorPos = m_editedPoint->GetPosition();
|
|
|
|
|
|
|
|
// Find vector from nearest dimension point to edit position
|
|
|
|
VECTOR2I directionA( cursorPos - dimension->GetStart() );
|
|
|
|
VECTOR2I directionB( cursorPos - dimension->GetEnd() );
|
|
|
|
VECTOR2I direction = ( directionA < directionB ) ? directionA : directionB;
|
|
|
|
|
|
|
|
bool vert;
|
|
|
|
VECTOR2D featureLine( cursorPos - dimension->GetStart() );
|
|
|
|
|
2020-09-22 02:32:40 +00:00
|
|
|
// Only change the orientation when we move outside the bounds
|
2021-03-05 14:40:02 +00:00
|
|
|
if( !bounds.Contains( cursorPos ) )
|
2020-09-22 02:32:40 +00:00
|
|
|
{
|
2021-03-05 14:40:02 +00:00
|
|
|
// If the dimension is horizontal or vertical, set correct orientation
|
|
|
|
// otherwise, test if we're left/right of the bounding box or above/below it
|
|
|
|
if( bounds.GetWidth() == 0 )
|
|
|
|
vert = true;
|
|
|
|
else if( bounds.GetHeight() == 0 )
|
|
|
|
vert = false;
|
|
|
|
else if( cursorPos.x > bounds.GetLeft() && cursorPos.x < bounds.GetRight() )
|
|
|
|
vert = false;
|
|
|
|
else if( cursorPos.y > bounds.GetTop() && cursorPos.y < bounds.GetBottom() )
|
|
|
|
vert = true;
|
|
|
|
else
|
|
|
|
vert = std::abs( direction.y ) < std::abs( direction.x );
|
2021-07-13 15:10:18 +00:00
|
|
|
|
2021-06-11 16:59:28 +00:00
|
|
|
dimension->SetOrientation( vert ? PCB_DIM_ORTHOGONAL::DIR::VERTICAL
|
|
|
|
: PCB_DIM_ORTHOGONAL::DIR::HORIZONTAL );
|
2021-03-05 14:40:02 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-06-11 16:59:28 +00:00
|
|
|
vert = dimension->GetOrientation() == PCB_DIM_ORTHOGONAL::DIR::VERTICAL;
|
2020-09-22 02:32:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
dimension->SetHeight( vert ? featureLine.x : featureLine.y );
|
|
|
|
}
|
|
|
|
else if( isModified( m_editPoints->Point( DIM_START ) ) )
|
|
|
|
{
|
2022-01-01 17:11:21 +00:00
|
|
|
dimension->SetStart( m_editedPoint->GetPosition() );
|
2020-09-22 02:32:40 +00:00
|
|
|
}
|
|
|
|
else if( isModified( m_editPoints->Point( DIM_END ) ) )
|
|
|
|
{
|
2022-01-01 17:11:21 +00:00
|
|
|
dimension->SetEnd( m_editedPoint->GetPosition() );
|
2020-09-22 02:32:40 +00:00
|
|
|
}
|
|
|
|
else if( isModified( m_editPoints->Point(DIM_TEXT ) ) )
|
|
|
|
{
|
|
|
|
// Force manual mode if we weren't already in it
|
|
|
|
dimension->SetTextPositionMode( DIM_TEXT_POSITION::MANUAL );
|
2023-03-04 23:15:43 +00:00
|
|
|
dimension->SetTextPos( VECTOR2I( m_editedPoint->GetPosition() ) );
|
2020-09-22 02:32:40 +00:00
|
|
|
}
|
|
|
|
|
2021-01-19 16:08:37 +00:00
|
|
|
dimension->Update();
|
|
|
|
|
2020-09-22 02:32:40 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-09-17 00:54:58 +00:00
|
|
|
case PCB_DIM_CENTER_T:
|
|
|
|
{
|
2021-06-11 16:59:28 +00:00
|
|
|
PCB_DIM_CENTER* dimension = static_cast<PCB_DIM_CENTER*>( item );
|
2020-09-17 00:54:58 +00:00
|
|
|
|
|
|
|
if( isModified( m_editPoints->Point( DIM_START ) ) )
|
2022-01-01 17:11:21 +00:00
|
|
|
dimension->SetStart( m_editedPoint->GetPosition() );
|
2020-09-17 00:54:58 +00:00
|
|
|
else if( isModified( m_editPoints->Point( DIM_END ) ) )
|
2022-01-01 17:11:21 +00:00
|
|
|
dimension->SetEnd( m_editedPoint->GetPosition() );
|
2020-09-17 00:54:58 +00:00
|
|
|
|
|
|
|
dimension->Update();
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-07-13 18:46:33 +00:00
|
|
|
case PCB_DIM_RADIAL_T:
|
|
|
|
{
|
|
|
|
PCB_DIM_RADIAL* dimension = static_cast<PCB_DIM_RADIAL*>( item );
|
|
|
|
|
|
|
|
if( isModified( m_editPoints->Point( DIM_START ) ) )
|
|
|
|
{
|
2022-01-01 17:11:21 +00:00
|
|
|
dimension->SetStart( m_editedPoint->GetPosition() );
|
2021-07-13 18:46:33 +00:00
|
|
|
dimension->Update();
|
|
|
|
|
|
|
|
m_editPoints->Point( DIM_KNEE ).SetConstraint( new EC_LINE( m_editPoints->Point( DIM_START ),
|
|
|
|
m_editPoints->Point( DIM_END ) ) );
|
|
|
|
}
|
|
|
|
else if( isModified( m_editPoints->Point( DIM_END ) ) )
|
|
|
|
{
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I oldKnee = dimension->GetKnee();
|
2021-07-13 18:46:33 +00:00
|
|
|
|
2022-01-01 17:11:21 +00:00
|
|
|
dimension->SetEnd( m_editedPoint->GetPosition() );
|
2021-07-13 18:46:33 +00:00
|
|
|
dimension->Update();
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I kneeDelta = dimension->GetKnee() - oldKnee;
|
2023-03-04 23:15:43 +00:00
|
|
|
dimension->SetTextPos( dimension->GetTextPos() + kneeDelta );
|
2021-07-13 18:46:33 +00:00
|
|
|
dimension->Update();
|
|
|
|
|
|
|
|
m_editPoints->Point( DIM_KNEE ).SetConstraint( new EC_LINE( m_editPoints->Point( DIM_START ),
|
|
|
|
m_editPoints->Point( DIM_END ) ) );
|
|
|
|
}
|
|
|
|
else if( isModified( m_editPoints->Point( DIM_KNEE ) ) )
|
|
|
|
{
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I oldKnee = dimension->GetKnee();
|
2021-07-13 18:46:33 +00:00
|
|
|
VECTOR2I arrowVec = m_editPoints->Point( DIM_KNEE ).GetPosition()
|
|
|
|
- m_editPoints->Point( DIM_END ).GetPosition();
|
|
|
|
|
|
|
|
dimension->SetLeaderLength( arrowVec.EuclideanNorm() );
|
|
|
|
dimension->Update();
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I kneeDelta = dimension->GetKnee() - oldKnee;
|
2023-03-04 23:15:43 +00:00
|
|
|
dimension->SetTextPos( dimension->GetTextPos() + kneeDelta );
|
2021-07-13 18:46:33 +00:00
|
|
|
dimension->Update();
|
|
|
|
}
|
|
|
|
else if( isModified( m_editPoints->Point( DIM_TEXT ) ) )
|
|
|
|
{
|
2023-03-04 23:15:43 +00:00
|
|
|
dimension->SetTextPos( m_editedPoint->GetPosition() );
|
2021-07-13 18:46:33 +00:00
|
|
|
dimension->Update();
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-09-12 20:09:40 +00:00
|
|
|
case PCB_DIM_LEADER_T:
|
|
|
|
{
|
2021-06-11 16:59:28 +00:00
|
|
|
PCB_DIM_LEADER* dimension = static_cast<PCB_DIM_LEADER*>( item );
|
2020-09-12 20:09:40 +00:00
|
|
|
|
|
|
|
if( isModified( m_editPoints->Point( DIM_START ) ) )
|
|
|
|
{
|
2022-01-01 06:04:08 +00:00
|
|
|
dimension->SetStart( (VECTOR2I) m_editedPoint->GetPosition() );
|
2020-09-12 20:09:40 +00:00
|
|
|
}
|
|
|
|
else if( isModified( m_editPoints->Point( DIM_END ) ) )
|
|
|
|
{
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I newPoint( m_editedPoint->GetPosition() );
|
|
|
|
VECTOR2I delta = newPoint - dimension->GetEnd();
|
2020-09-12 20:09:40 +00:00
|
|
|
|
|
|
|
dimension->SetEnd( newPoint );
|
2023-03-04 23:15:43 +00:00
|
|
|
dimension->SetTextPos( dimension->GetTextPos() + delta );
|
2020-09-12 20:09:40 +00:00
|
|
|
}
|
|
|
|
else if( isModified( m_editPoints->Point( DIM_TEXT ) ) )
|
|
|
|
{
|
2023-03-04 23:15:43 +00:00
|
|
|
dimension->SetTextPos( (VECTOR2I) m_editedPoint->GetPosition() );
|
2020-09-12 20:09:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
dimension->Update();
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-02-27 16:29:08 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2018-04-12 16:08:45 +00:00
|
|
|
|
2020-06-21 18:43:33 +00:00
|
|
|
getView()->Update( item );
|
2017-05-16 09:38:00 +00:00
|
|
|
|
2022-03-20 15:57:18 +00:00
|
|
|
frame()->SetMsgPanel( item );
|
2014-03-06 10:49:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-01-16 23:17:32 +00:00
|
|
|
bool PCB_POINT_EDITOR::validatePolygon( SHAPE_POLY_SET& aPoly ) const
|
2018-02-22 11:28:01 +00:00
|
|
|
{
|
2022-11-09 00:03:59 +00:00
|
|
|
return true;
|
2018-02-22 11:28:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-01-16 23:17:32 +00:00
|
|
|
void PCB_POINT_EDITOR::updatePoints()
|
2014-02-27 16:29:08 +00:00
|
|
|
{
|
2017-01-18 08:04:11 +00:00
|
|
|
if( !m_editPoints )
|
|
|
|
return;
|
|
|
|
|
2014-02-28 15:53:28 +00:00
|
|
|
EDA_ITEM* item = m_editPoints->GetParent();
|
|
|
|
|
2017-05-16 09:38:00 +00:00
|
|
|
if( !item )
|
|
|
|
return;
|
|
|
|
|
2022-04-01 15:11:42 +00:00
|
|
|
switch( item->Type() )
|
|
|
|
{
|
2022-02-08 19:29:54 +00:00
|
|
|
case PCB_BITMAP_T:
|
|
|
|
{
|
|
|
|
PCB_BITMAP* bitmap = (PCB_BITMAP*) item;
|
|
|
|
VECTOR2I topLeft = bitmap->GetPosition() - bitmap->GetSize() / 2;
|
|
|
|
VECTOR2I botRight = bitmap->GetPosition() + bitmap->GetSize() / 2;
|
|
|
|
|
|
|
|
m_editPoints->Point( RECT_TOP_LEFT ).SetPosition( topLeft );
|
|
|
|
m_editPoints->Point( RECT_TOP_RIGHT ).SetPosition( botRight.x, topLeft.y );
|
|
|
|
m_editPoints->Point( RECT_BOT_LEFT ).SetPosition( topLeft.x, botRight.y );
|
|
|
|
m_editPoints->Point( RECT_BOT_RIGHT ).SetPosition( botRight );
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2022-04-01 15:11:42 +00:00
|
|
|
case PCB_TEXTBOX_T:
|
2022-01-30 10:52:52 +00:00
|
|
|
{
|
|
|
|
const PCB_SHAPE* shape = static_cast<const PCB_SHAPE*>( item );
|
2023-07-24 16:07:56 +00:00
|
|
|
int target = shape->GetShape() == SHAPE_T::RECTANGLE ? 4 : 0;
|
2022-01-30 10:52:52 +00:00
|
|
|
|
2022-04-01 15:11:42 +00:00
|
|
|
// Careful; textbox shape is mutable between cardinal and non-cardinal rotations...
|
|
|
|
if( int( m_editPoints->PointsSize() ) != target )
|
|
|
|
{
|
|
|
|
getView()->Remove( m_editPoints.get() );
|
|
|
|
m_editedPoint = nullptr;
|
|
|
|
|
|
|
|
m_editPoints = makePoints( item );
|
|
|
|
|
|
|
|
if( m_editPoints )
|
|
|
|
getView()->Add( m_editPoints.get() );
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2023-07-24 16:07:56 +00:00
|
|
|
if( shape->GetShape() == SHAPE_T::RECTANGLE )
|
2022-01-30 10:52:52 +00:00
|
|
|
{
|
2022-06-02 09:42:13 +00:00
|
|
|
m_editPoints->Point( RECT_TOP_LEFT ).SetPosition( shape->GetTopLeft() );
|
|
|
|
m_editPoints->Point( RECT_TOP_RIGHT ).SetPosition( shape->GetBotRight().x,
|
|
|
|
shape->GetTopLeft().y );
|
|
|
|
m_editPoints->Point( RECT_BOT_RIGHT ).SetPosition( shape->GetBotRight() );
|
|
|
|
m_editPoints->Point( RECT_BOT_LEFT ).SetPosition( shape->GetTopLeft().x,
|
|
|
|
shape->GetBotRight().y );
|
2022-01-30 10:52:52 +00:00
|
|
|
}
|
2022-04-01 15:11:42 +00:00
|
|
|
else if( shape->GetShape() == SHAPE_T::POLY )
|
|
|
|
{
|
|
|
|
// Not currently editable while rotated.
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
2022-01-30 10:52:52 +00:00
|
|
|
}
|
|
|
|
|
2020-10-04 14:19:33 +00:00
|
|
|
case PCB_SHAPE_T:
|
2014-02-27 16:29:08 +00:00
|
|
|
{
|
2020-10-04 23:34:59 +00:00
|
|
|
const PCB_SHAPE* shape = static_cast<const PCB_SHAPE*>( item );
|
2017-12-18 13:07:17 +00:00
|
|
|
|
2020-10-04 23:34:59 +00:00
|
|
|
switch( shape->GetShape() )
|
2014-02-27 16:29:08 +00:00
|
|
|
{
|
2021-07-21 18:31:25 +00:00
|
|
|
case SHAPE_T::SEGMENT:
|
2020-10-04 23:34:59 +00:00
|
|
|
m_editPoints->Point( SEG_START ).SetPosition( shape->GetStart() );
|
|
|
|
m_editPoints->Point( SEG_END ).SetPosition( shape->GetEnd() );
|
2017-12-18 13:07:17 +00:00
|
|
|
break;
|
2014-02-27 16:29:08 +00:00
|
|
|
|
2023-07-24 16:07:56 +00:00
|
|
|
case SHAPE_T::RECTANGLE:
|
2022-06-02 09:42:13 +00:00
|
|
|
m_editPoints->Point( RECT_TOP_LEFT ).SetPosition( shape->GetTopLeft() );
|
|
|
|
m_editPoints->Point( RECT_TOP_RIGHT ).SetPosition( shape->GetBotRight().x,
|
|
|
|
shape->GetTopLeft().y );
|
|
|
|
m_editPoints->Point( RECT_BOT_RIGHT ).SetPosition( shape->GetBotRight() );
|
|
|
|
m_editPoints->Point( RECT_BOT_LEFT ).SetPosition( shape->GetTopLeft().x,
|
|
|
|
shape->GetBotRight().y );
|
2020-06-15 19:50:20 +00:00
|
|
|
break;
|
|
|
|
|
2021-07-21 18:31:25 +00:00
|
|
|
case SHAPE_T::ARC:
|
2020-10-04 23:34:59 +00:00
|
|
|
m_editPoints->Point( ARC_CENTER ).SetPosition( shape->GetCenter() );
|
2021-07-17 19:56:18 +00:00
|
|
|
m_editPoints->Point( ARC_START ).SetPosition( shape->GetStart() );
|
2020-10-04 23:34:59 +00:00
|
|
|
m_editPoints->Point( ARC_MID ).SetPosition( shape->GetArcMid() );
|
2021-07-17 19:56:18 +00:00
|
|
|
m_editPoints->Point( ARC_END ).SetPosition( shape->GetEnd() );
|
2017-12-18 13:07:17 +00:00
|
|
|
break;
|
2014-02-27 16:29:08 +00:00
|
|
|
|
2021-07-21 18:31:25 +00:00
|
|
|
case SHAPE_T::CIRCLE:
|
2020-10-04 23:34:59 +00:00
|
|
|
m_editPoints->Point( CIRC_CENTER ).SetPosition( shape->GetCenter() );
|
|
|
|
m_editPoints->Point( CIRC_END ).SetPosition( shape->GetEnd() );
|
2017-12-18 13:07:17 +00:00
|
|
|
break;
|
2014-02-28 17:24:13 +00:00
|
|
|
|
2021-07-21 18:31:25 +00:00
|
|
|
case SHAPE_T::POLY:
|
2017-12-18 13:07:17 +00:00
|
|
|
{
|
2022-01-01 06:04:08 +00:00
|
|
|
std::vector<VECTOR2I> points;
|
2021-09-11 12:21:36 +00:00
|
|
|
shape->DupPolyPointsList( points );
|
2018-09-15 16:51:35 +00:00
|
|
|
|
|
|
|
if( m_editPoints->PointsSize() != (unsigned) points.size() )
|
|
|
|
{
|
|
|
|
getView()->Remove( m_editPoints.get() );
|
|
|
|
m_editedPoint = nullptr;
|
2020-12-19 15:16:14 +00:00
|
|
|
|
|
|
|
m_editPoints = makePoints( item );
|
|
|
|
|
|
|
|
if( m_editPoints )
|
|
|
|
getView()->Add( m_editPoints.get() );
|
2018-09-15 16:51:35 +00:00
|
|
|
}
|
|
|
|
else
|
2017-12-18 17:24:25 +00:00
|
|
|
{
|
2018-09-15 16:51:35 +00:00
|
|
|
for( unsigned i = 0; i < points.size(); i++ )
|
|
|
|
m_editPoints->Point( i ).SetPosition( points[i] );
|
2014-02-27 16:29:08 +00:00
|
|
|
}
|
2021-07-26 23:47:26 +00:00
|
|
|
|
2017-12-18 13:07:17 +00:00
|
|
|
break;
|
|
|
|
}
|
2014-02-28 17:24:29 +00:00
|
|
|
|
2021-07-21 18:31:25 +00:00
|
|
|
case SHAPE_T::BEZIER:
|
2020-10-04 23:34:59 +00:00
|
|
|
m_editPoints->Point( BEZIER_CURVE_START ).SetPosition( shape->GetStart() );
|
2021-07-18 12:31:56 +00:00
|
|
|
m_editPoints->Point( BEZIER_CURVE_CONTROL_POINT1 ).SetPosition( shape->GetBezierC1() );
|
|
|
|
m_editPoints->Point( BEZIER_CURVE_CONTROL_POINT2 ).SetPosition( shape->GetBezierC2() );
|
2020-10-04 23:34:59 +00:00
|
|
|
m_editPoints->Point( BEZIER_CURVE_END ).SetPosition( shape->GetEnd() );
|
2018-07-22 12:50:35 +00:00
|
|
|
break;
|
|
|
|
|
2017-12-18 13:07:17 +00:00
|
|
|
default: // suppress warnings
|
2014-02-28 17:24:29 +00:00
|
|
|
break;
|
2014-02-27 16:29:08 +00:00
|
|
|
}
|
2017-12-18 13:07:17 +00:00
|
|
|
|
|
|
|
break;
|
2014-02-28 17:24:29 +00:00
|
|
|
}
|
|
|
|
|
2020-06-28 22:34:10 +00:00
|
|
|
case PCB_PAD_T:
|
|
|
|
{
|
2020-11-12 22:30:02 +00:00
|
|
|
const PAD* pad = static_cast<const PAD*>( item );
|
2021-01-08 16:32:28 +00:00
|
|
|
bool locked = pad->GetParent() && pad->IsLocked();
|
2022-01-01 06:04:08 +00:00
|
|
|
VECTOR2I shapePos = pad->ShapePos();
|
|
|
|
VECTOR2I halfSize( pad->GetSize().x / 2, pad->GetSize().y / 2 );
|
2020-06-28 22:34:10 +00:00
|
|
|
|
|
|
|
switch( pad->GetShape() )
|
|
|
|
{
|
2021-05-01 12:22:35 +00:00
|
|
|
case PAD_SHAPE::CIRCLE:
|
2020-06-28 22:34:10 +00:00
|
|
|
{
|
2021-09-29 12:53:54 +00:00
|
|
|
int target = locked ? 0 : 1;
|
2020-06-29 18:14:51 +00:00
|
|
|
|
2020-06-28 22:34:10 +00:00
|
|
|
// Careful; pad shape is mutable...
|
2020-07-01 16:41:50 +00:00
|
|
|
if( int( m_editPoints->PointsSize() ) != target )
|
2020-06-28 22:34:10 +00:00
|
|
|
{
|
|
|
|
getView()->Remove( m_editPoints.get() );
|
|
|
|
m_editedPoint = nullptr;
|
2020-12-19 15:16:14 +00:00
|
|
|
|
|
|
|
m_editPoints = makePoints( item );
|
|
|
|
|
|
|
|
if( m_editPoints )
|
|
|
|
getView()->Add( m_editPoints.get() );
|
2020-06-28 22:34:10 +00:00
|
|
|
}
|
2021-09-29 12:53:54 +00:00
|
|
|
else if( target == 1 )
|
2020-06-28 22:34:10 +00:00
|
|
|
{
|
2021-11-09 13:09:06 +00:00
|
|
|
shapePos.x += halfSize.x;
|
|
|
|
m_editPoints->Point( 0 ).SetPosition( shapePos );
|
2020-06-28 22:34:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2021-05-01 12:22:35 +00:00
|
|
|
case PAD_SHAPE::OVAL:
|
|
|
|
case PAD_SHAPE::TRAPEZOID:
|
2023-06-02 09:10:48 +00:00
|
|
|
case PAD_SHAPE::RECTANGLE:
|
2021-05-01 12:22:35 +00:00
|
|
|
case PAD_SHAPE::ROUNDRECT:
|
|
|
|
case PAD_SHAPE::CHAMFERED_RECT:
|
2020-06-28 22:34:10 +00:00
|
|
|
{
|
|
|
|
// Careful; pad shape and orientation are mutable...
|
2022-01-13 13:45:48 +00:00
|
|
|
int target = locked || !pad->GetOrientation().IsCardinal() ? 0 : 4;
|
2020-06-28 22:34:10 +00:00
|
|
|
|
2020-07-01 16:41:50 +00:00
|
|
|
if( int( m_editPoints->PointsSize() ) != target )
|
2020-06-28 22:34:10 +00:00
|
|
|
{
|
|
|
|
getView()->Remove( m_editPoints.get() );
|
|
|
|
m_editedPoint = nullptr;
|
2020-12-19 15:16:14 +00:00
|
|
|
|
|
|
|
m_editPoints = makePoints( item );
|
|
|
|
|
|
|
|
if( m_editPoints )
|
|
|
|
getView()->Add( m_editPoints.get() );
|
2020-06-28 22:34:10 +00:00
|
|
|
}
|
|
|
|
else if( target == 4 )
|
|
|
|
{
|
2022-01-13 13:45:48 +00:00
|
|
|
if( pad->GetOrientation() == ANGLE_90 || pad->GetOrientation() == ANGLE_270 )
|
2020-06-28 22:34:10 +00:00
|
|
|
std::swap( halfSize.x, halfSize.y );
|
|
|
|
|
|
|
|
m_editPoints->Point( RECT_TOP_LEFT ).SetPosition( shapePos - halfSize );
|
2022-01-01 17:11:21 +00:00
|
|
|
m_editPoints->Point( RECT_TOP_RIGHT )
|
|
|
|
.SetPosition(
|
|
|
|
VECTOR2I( shapePos.x + halfSize.x, shapePos.y - halfSize.y ) );
|
2020-06-28 22:34:10 +00:00
|
|
|
m_editPoints->Point( RECT_BOT_RIGHT ).SetPosition( shapePos + halfSize );
|
2022-01-01 17:11:21 +00:00
|
|
|
m_editPoints->Point( RECT_BOT_LEFT )
|
|
|
|
.SetPosition(
|
|
|
|
VECTOR2I( shapePos.x - halfSize.x, shapePos.y + halfSize.y ) );
|
2020-06-28 22:34:10 +00:00
|
|
|
}
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2020-06-28 22:34:10 +00:00
|
|
|
break;
|
2021-07-19 23:56:05 +00:00
|
|
|
}
|
2020-06-28 22:34:10 +00:00
|
|
|
|
|
|
|
default: // suppress warnings
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2020-11-11 23:05:59 +00:00
|
|
|
case PCB_ZONE_T:
|
2014-02-28 17:24:29 +00:00
|
|
|
{
|
2020-11-11 23:05:59 +00:00
|
|
|
ZONE* zone = static_cast<ZONE*>( item );
|
2017-03-07 12:06:00 +00:00
|
|
|
const SHAPE_POLY_SET* outline = zone->Outline();
|
2014-02-28 17:24:29 +00:00
|
|
|
|
2017-03-07 12:06:00 +00:00
|
|
|
if( m_editPoints->PointsSize() != (unsigned) outline->TotalVertices() )
|
2014-07-09 14:50:31 +00:00
|
|
|
{
|
|
|
|
getView()->Remove( m_editPoints.get() );
|
2018-03-26 21:30:56 +00:00
|
|
|
m_editedPoint = nullptr;
|
2020-12-19 15:16:14 +00:00
|
|
|
|
|
|
|
m_editPoints = makePoints( item );
|
|
|
|
|
|
|
|
if( m_editPoints )
|
|
|
|
getView()->Add( m_editPoints.get() );
|
2014-07-09 14:50:31 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-03-07 12:06:00 +00:00
|
|
|
for( int i = 0; i < outline->TotalVertices(); ++i )
|
|
|
|
m_editPoints->Point( i ).SetPosition( outline->CVertex( i ) );
|
2014-07-09 14:50:31 +00:00
|
|
|
}
|
2014-02-28 17:24:29 +00:00
|
|
|
|
2014-02-27 16:29:08 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2023-10-06 17:04:00 +00:00
|
|
|
case PCB_GENERATOR_T:
|
|
|
|
{
|
|
|
|
PCB_GENERATOR* generator = static_cast<PCB_GENERATOR*>( item );
|
|
|
|
generator->UpdateEditPoints( m_editPoints );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-09-12 20:09:40 +00:00
|
|
|
case PCB_DIM_ALIGNED_T:
|
2020-09-22 02:32:40 +00:00
|
|
|
case PCB_DIM_ORTHOGONAL_T:
|
2014-03-12 09:46:11 +00:00
|
|
|
{
|
2021-06-11 16:59:28 +00:00
|
|
|
const PCB_DIM_ALIGNED* dimension = static_cast<const PCB_DIM_ALIGNED*>( item );
|
2014-03-12 09:46:11 +00:00
|
|
|
|
2020-09-12 20:09:40 +00:00
|
|
|
m_editPoints->Point( DIM_START ).SetPosition( dimension->GetStart() );
|
|
|
|
m_editPoints->Point( DIM_END ).SetPosition( dimension->GetEnd() );
|
2023-03-04 23:15:43 +00:00
|
|
|
m_editPoints->Point( DIM_TEXT ).SetPosition( dimension->GetTextPos() );
|
2020-09-09 03:17:08 +00:00
|
|
|
m_editPoints->Point( DIM_CROSSBARSTART ).SetPosition( dimension->GetCrossbarStart() );
|
|
|
|
m_editPoints->Point( DIM_CROSSBAREND ).SetPosition( dimension->GetCrossbarEnd() );
|
2020-09-12 20:09:40 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-09-17 00:54:58 +00:00
|
|
|
case PCB_DIM_CENTER_T:
|
|
|
|
{
|
2021-06-11 16:59:28 +00:00
|
|
|
const PCB_DIM_CENTER* dimension = static_cast<const PCB_DIM_CENTER*>( item );
|
2020-09-17 00:54:58 +00:00
|
|
|
|
|
|
|
m_editPoints->Point( DIM_START ).SetPosition( dimension->GetStart() );
|
|
|
|
m_editPoints->Point( DIM_END ).SetPosition( dimension->GetEnd() );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-07-13 18:46:33 +00:00
|
|
|
case PCB_DIM_RADIAL_T:
|
|
|
|
{
|
|
|
|
const PCB_DIM_RADIAL* dimension = static_cast<const PCB_DIM_RADIAL*>( item );
|
|
|
|
|
|
|
|
m_editPoints->Point( DIM_START ).SetPosition( dimension->GetStart() );
|
|
|
|
m_editPoints->Point( DIM_END ).SetPosition( dimension->GetEnd() );
|
2023-03-04 23:15:43 +00:00
|
|
|
m_editPoints->Point( DIM_TEXT ).SetPosition( dimension->GetTextPos() );
|
2021-07-13 18:46:33 +00:00
|
|
|
m_editPoints->Point( DIM_KNEE ).SetPosition( dimension->GetKnee() );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-09-12 20:09:40 +00:00
|
|
|
case PCB_DIM_LEADER_T:
|
|
|
|
{
|
2021-06-11 16:59:28 +00:00
|
|
|
const PCB_DIM_LEADER* dimension = static_cast<const PCB_DIM_LEADER*>( item );
|
2020-09-12 20:09:40 +00:00
|
|
|
|
2020-09-09 03:17:08 +00:00
|
|
|
m_editPoints->Point( DIM_START ).SetPosition( dimension->GetStart() );
|
|
|
|
m_editPoints->Point( DIM_END ).SetPosition( dimension->GetEnd() );
|
2023-03-04 23:15:43 +00:00
|
|
|
m_editPoints->Point( DIM_TEXT ).SetPosition( dimension->GetTextPos() );
|
2014-03-12 09:46:11 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-02-27 16:29:08 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2016-06-21 15:06:28 +00:00
|
|
|
|
2016-12-02 17:58:12 +00:00
|
|
|
getView()->Update( m_editPoints.get() );
|
2014-02-27 16:29:08 +00:00
|
|
|
}
|
2014-03-06 16:34:04 +00:00
|
|
|
|
|
|
|
|
2021-01-16 23:17:32 +00:00
|
|
|
void PCB_POINT_EDITOR::setEditedPoint( EDIT_POINT* aPoint )
|
2015-06-19 15:32:33 +00:00
|
|
|
{
|
|
|
|
KIGFX::VIEW_CONTROLS* controls = getViewControls();
|
|
|
|
|
|
|
|
if( aPoint )
|
|
|
|
{
|
2020-10-08 00:50:28 +00:00
|
|
|
frame()->GetCanvas()->SetCurrentCursor( KICURSOR::ARROW );
|
2015-06-19 15:32:33 +00:00
|
|
|
controls->ForceCursorPosition( true, aPoint->GetPosition() );
|
|
|
|
controls->ShowCursor( true );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-06-29 13:39:46 +00:00
|
|
|
if( frame()->ToolStackIsEmpty() )
|
|
|
|
controls->ShowCursor( false );
|
|
|
|
|
2015-06-19 15:32:33 +00:00
|
|
|
controls->ForceCursorPosition( false );
|
|
|
|
}
|
|
|
|
|
|
|
|
m_editedPoint = aPoint;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-01-16 23:17:32 +00:00
|
|
|
void PCB_POINT_EDITOR::setAltConstraint( bool aEnabled )
|
2014-03-14 14:37:55 +00:00
|
|
|
{
|
|
|
|
if( aEnabled )
|
|
|
|
{
|
2021-07-21 18:31:25 +00:00
|
|
|
EDA_ITEM* parent = m_editPoints->GetParent();
|
2015-06-19 15:32:33 +00:00
|
|
|
EDIT_LINE* line = dynamic_cast<EDIT_LINE*>( m_editedPoint );
|
2021-03-08 12:57:33 +00:00
|
|
|
bool isPoly;
|
2020-08-27 17:31:53 +00:00
|
|
|
|
2021-07-21 18:31:25 +00:00
|
|
|
switch( parent->Type() )
|
2020-10-04 14:19:33 +00:00
|
|
|
{
|
2021-03-08 12:57:33 +00:00
|
|
|
case PCB_ZONE_T:
|
2020-08-27 17:31:53 +00:00
|
|
|
isPoly = true;
|
2021-03-08 12:57:33 +00:00
|
|
|
break;
|
2020-08-27 17:31:53 +00:00
|
|
|
|
2021-03-08 12:57:33 +00:00
|
|
|
case PCB_SHAPE_T:
|
2021-07-21 18:31:25 +00:00
|
|
|
isPoly = static_cast<PCB_SHAPE*>( parent )->GetShape() == SHAPE_T::POLY;
|
2021-03-08 12:57:33 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
isPoly = false;
|
|
|
|
break;
|
2020-08-27 17:31:53 +00:00
|
|
|
}
|
2014-04-02 07:31:35 +00:00
|
|
|
|
2020-08-27 17:31:53 +00:00
|
|
|
if( line && isPoly )
|
2014-03-14 14:37:55 +00:00
|
|
|
{
|
2020-12-19 15:16:14 +00:00
|
|
|
EC_CONVERGING* altConstraint = new EC_CONVERGING( *line, *m_editPoints );
|
|
|
|
m_altConstraint.reset( (EDIT_CONSTRAINT<EDIT_POINT>*) altConstraint );
|
2014-03-14 14:37:55 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Find a proper constraining point for 45 degrees mode
|
|
|
|
m_altConstrainer = get45DegConstrainer();
|
2015-06-19 15:32:33 +00:00
|
|
|
m_altConstraint.reset( new EC_45DEGREE( *m_editedPoint, m_altConstrainer ) );
|
2014-03-14 14:37:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_altConstraint.reset();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-01-16 23:17:32 +00:00
|
|
|
EDIT_POINT PCB_POINT_EDITOR::get45DegConstrainer() const
|
2014-03-06 16:34:04 +00:00
|
|
|
{
|
|
|
|
EDA_ITEM* item = m_editPoints->GetParent();
|
|
|
|
|
2014-03-13 10:48:19 +00:00
|
|
|
switch( item->Type() )
|
|
|
|
{
|
2020-10-04 14:19:33 +00:00
|
|
|
case PCB_SHAPE_T:
|
2020-10-04 23:34:59 +00:00
|
|
|
switch( static_cast<const PCB_SHAPE*>( item )->GetShape() )
|
2014-03-06 16:34:04 +00:00
|
|
|
{
|
2021-07-21 18:31:25 +00:00
|
|
|
case SHAPE_T::SEGMENT:
|
2020-10-04 23:34:59 +00:00
|
|
|
return *( m_editPoints->Next( *m_editedPoint ) ); // select the other end of line
|
2014-03-06 16:34:04 +00:00
|
|
|
|
2021-07-21 18:31:25 +00:00
|
|
|
case SHAPE_T::ARC:
|
|
|
|
case SHAPE_T::CIRCLE:
|
2020-10-04 23:34:59 +00:00
|
|
|
return m_editPoints->Point( CIRC_CENTER );
|
2014-03-06 16:34:04 +00:00
|
|
|
|
2020-10-04 23:34:59 +00:00
|
|
|
default: // suppress warnings
|
|
|
|
break;
|
2014-03-06 16:34:04 +00:00
|
|
|
}
|
2014-03-13 10:48:19 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
2020-09-12 20:09:40 +00:00
|
|
|
case PCB_DIM_ALIGNED_T:
|
2014-03-12 09:46:11 +00:00
|
|
|
{
|
|
|
|
// Constraint for crossbar
|
2020-09-09 03:17:08 +00:00
|
|
|
if( isModified( m_editPoints->Point( DIM_START ) ) )
|
|
|
|
return m_editPoints->Point( DIM_END );
|
2014-03-12 09:53:42 +00:00
|
|
|
|
2020-09-09 03:17:08 +00:00
|
|
|
else if( isModified( m_editPoints->Point( DIM_END ) ) )
|
|
|
|
return m_editPoints->Point( DIM_START );
|
2014-03-13 10:48:19 +00:00
|
|
|
|
|
|
|
else
|
2015-06-19 15:32:33 +00:00
|
|
|
return EDIT_POINT( m_editedPoint->GetPosition() ); // no constraint
|
2014-03-13 10:48:19 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-09-17 00:54:58 +00:00
|
|
|
case PCB_DIM_CENTER_T:
|
|
|
|
{
|
|
|
|
if( isModified( m_editPoints->Point( DIM_END ) ) )
|
|
|
|
return m_editPoints->Point( DIM_START );
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-07-13 18:46:33 +00:00
|
|
|
case PCB_DIM_RADIAL_T:
|
|
|
|
{
|
|
|
|
if( isModified( m_editPoints->Point( DIM_TEXT ) ) )
|
|
|
|
return m_editPoints->Point( DIM_KNEE );
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-03-13 10:48:19 +00:00
|
|
|
default:
|
|
|
|
break;
|
2014-03-12 09:46:11 +00:00
|
|
|
}
|
2014-03-06 16:34:04 +00:00
|
|
|
|
2014-03-14 14:15:38 +00:00
|
|
|
// In any other case we may align item to its original position
|
2014-03-13 10:48:19 +00:00
|
|
|
return m_original;
|
2014-03-06 16:34:04 +00:00
|
|
|
}
|
2014-03-18 13:52:22 +00:00
|
|
|
|
|
|
|
|
2021-01-16 23:17:32 +00:00
|
|
|
bool PCB_POINT_EDITOR::canAddCorner( const EDA_ITEM& aItem )
|
2018-07-24 15:15:05 +00:00
|
|
|
{
|
|
|
|
const auto type = aItem.Type();
|
|
|
|
|
|
|
|
// Works only for zones and line segments
|
2023-03-30 11:49:23 +00:00
|
|
|
if( type == PCB_ZONE_T )
|
2020-10-04 14:19:33 +00:00
|
|
|
return true;
|
|
|
|
|
2023-03-30 11:49:23 +00:00
|
|
|
if( type == PCB_SHAPE_T )
|
2020-10-04 14:19:33 +00:00
|
|
|
{
|
2020-10-04 23:34:59 +00:00
|
|
|
const PCB_SHAPE& shape = static_cast<const PCB_SHAPE&>( aItem );
|
2021-07-21 18:31:25 +00:00
|
|
|
return shape.GetShape() == SHAPE_T::SEGMENT || shape.GetShape() == SHAPE_T::POLY;
|
2020-10-04 14:19:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2018-07-24 15:15:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-01-16 23:17:32 +00:00
|
|
|
bool PCB_POINT_EDITOR::addCornerCondition( const SELECTION& aSelection )
|
2017-01-18 08:04:11 +00:00
|
|
|
{
|
|
|
|
if( aSelection.Size() != 1 )
|
|
|
|
return false;
|
|
|
|
|
2018-07-24 15:15:05 +00:00
|
|
|
const EDA_ITEM* item = aSelection.Front();
|
2017-01-18 08:04:11 +00:00
|
|
|
|
2018-07-24 15:15:05 +00:00
|
|
|
return ( item != nullptr ) && canAddCorner( *item );
|
2017-01-18 08:04:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-06 14:51:47 +00:00
|
|
|
// Finds a corresponding vertex in a polygon set
|
|
|
|
static std::pair<bool, SHAPE_POLY_SET::VERTEX_INDEX>
|
|
|
|
findVertex( SHAPE_POLY_SET& aPolySet, const EDIT_POINT& aPoint )
|
|
|
|
{
|
|
|
|
for( auto it = aPolySet.IterateWithHoles(); it; ++it )
|
|
|
|
{
|
|
|
|
auto vertexIdx = it.GetIndex();
|
|
|
|
|
2019-03-23 18:26:44 +00:00
|
|
|
if( aPolySet.CVertex( vertexIdx ) == aPoint.GetPosition() )
|
2017-12-06 14:51:47 +00:00
|
|
|
return std::make_pair( true, vertexIdx );
|
|
|
|
}
|
|
|
|
|
|
|
|
return std::make_pair( false, SHAPE_POLY_SET::VERTEX_INDEX() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-01-16 23:17:32 +00:00
|
|
|
bool PCB_POINT_EDITOR::removeCornerCondition( const SELECTION& )
|
2017-01-18 08:04:11 +00:00
|
|
|
{
|
2017-12-06 14:51:47 +00:00
|
|
|
if( !m_editPoints || !m_editedPoint )
|
2017-01-18 08:04:11 +00:00
|
|
|
return false;
|
|
|
|
|
2021-03-08 12:57:33 +00:00
|
|
|
EDA_ITEM* item = m_editPoints->GetParent();
|
|
|
|
SHAPE_POLY_SET* polyset = nullptr;
|
2017-01-18 08:04:11 +00:00
|
|
|
|
2020-10-04 14:19:33 +00:00
|
|
|
if( !item )
|
|
|
|
return false;
|
|
|
|
|
2021-03-08 12:57:33 +00:00
|
|
|
switch( item->Type() )
|
2021-01-19 23:07:31 +00:00
|
|
|
{
|
2021-03-08 12:57:33 +00:00
|
|
|
case PCB_ZONE_T:
|
|
|
|
polyset = static_cast<ZONE*>( item )->Outline();
|
|
|
|
break;
|
2017-01-18 08:04:11 +00:00
|
|
|
|
2021-03-08 12:57:33 +00:00
|
|
|
case PCB_SHAPE_T:
|
2021-07-21 18:31:25 +00:00
|
|
|
if( static_cast<PCB_SHAPE*>( item )->GetShape() == SHAPE_T::POLY )
|
2021-03-08 12:57:33 +00:00
|
|
|
polyset = &static_cast<PCB_SHAPE*>( item )->GetPolyShape();
|
|
|
|
else
|
|
|
|
return false;
|
2018-09-16 17:20:53 +00:00
|
|
|
|
2021-03-08 12:57:33 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
2018-09-16 17:20:53 +00:00
|
|
|
|
2022-06-01 22:55:59 +00:00
|
|
|
std::pair<bool, SHAPE_POLY_SET::VERTEX_INDEX> vertex = findVertex( *polyset, *m_editedPoint );
|
2017-12-06 14:51:47 +00:00
|
|
|
|
|
|
|
if( !vertex.first )
|
|
|
|
return false;
|
|
|
|
|
2022-06-01 22:55:59 +00:00
|
|
|
const SHAPE_POLY_SET::VERTEX_INDEX& vertexIdx = vertex.second;
|
2017-01-18 08:04:11 +00:00
|
|
|
|
2017-12-06 14:51:47 +00:00
|
|
|
// Check if there are enough vertices so one can be removed without
|
|
|
|
// degenerating the polygon.
|
2018-07-08 12:12:38 +00:00
|
|
|
// The first condition allows one to remove all corners from holes (when
|
|
|
|
// there are only 2 vertices left, a hole is removed).
|
2021-07-19 23:56:05 +00:00
|
|
|
if( vertexIdx.m_contour == 0 &&
|
|
|
|
polyset->Polygon( vertexIdx.m_polygon )[vertexIdx.m_contour].PointCount() <= 3 )
|
2022-06-01 22:55:59 +00:00
|
|
|
{
|
2017-01-18 08:04:11 +00:00
|
|
|
return false;
|
2022-06-01 22:55:59 +00:00
|
|
|
}
|
2017-01-18 08:04:11 +00:00
|
|
|
|
|
|
|
// Remove corner does not work with lines
|
|
|
|
if( dynamic_cast<EDIT_LINE*>( m_editedPoint ) )
|
|
|
|
return false;
|
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
return m_editedPoint != nullptr;
|
2017-01-18 08:04:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-01-16 23:17:32 +00:00
|
|
|
int PCB_POINT_EDITOR::addCorner( const TOOL_EVENT& aEvent )
|
2014-03-18 13:52:22 +00:00
|
|
|
{
|
2018-07-24 15:15:05 +00:00
|
|
|
if( !m_editPoints )
|
|
|
|
return 0;
|
|
|
|
|
2022-06-01 22:55:59 +00:00
|
|
|
EDA_ITEM* item = m_editPoints->GetParent();
|
2016-06-08 09:24:46 +00:00
|
|
|
PCB_BASE_EDIT_FRAME* frame = getEditFrame<PCB_BASE_EDIT_FRAME>();
|
2022-06-01 22:55:59 +00:00
|
|
|
const VECTOR2I& cursorPos = getViewControls()->GetCursorPosition();
|
2018-07-24 15:15:05 +00:00
|
|
|
|
|
|
|
// called without an active edited polygon
|
|
|
|
if( !item || !canAddCorner( *item ) )
|
|
|
|
return 0;
|
|
|
|
|
2020-10-04 23:34:59 +00:00
|
|
|
PCB_SHAPE* graphicItem = dynamic_cast<PCB_SHAPE*>( item );
|
2016-06-21 15:06:28 +00:00
|
|
|
BOARD_COMMIT commit( frame );
|
2014-03-18 13:52:22 +00:00
|
|
|
|
2023-03-30 11:49:23 +00:00
|
|
|
if( item->Type() == PCB_ZONE_T || ( graphicItem && graphicItem->GetShape() == SHAPE_T::POLY ) )
|
2018-09-15 16:51:35 +00:00
|
|
|
{
|
2017-04-06 17:04:47 +00:00
|
|
|
unsigned int nearestIdx = 0;
|
|
|
|
unsigned int nextNearestIdx = 0;
|
|
|
|
unsigned int nearestDist = INT_MAX;
|
2017-04-14 12:38:59 +00:00
|
|
|
unsigned int firstPointInContour = 0;
|
2018-09-15 16:51:35 +00:00
|
|
|
SHAPE_POLY_SET* zoneOutline;
|
|
|
|
|
2023-03-30 11:49:23 +00:00
|
|
|
if( item->Type() == PCB_ZONE_T )
|
2019-03-14 13:35:55 +00:00
|
|
|
{
|
2020-11-11 23:05:59 +00:00
|
|
|
ZONE* zone = static_cast<ZONE*>( item );
|
2019-03-14 13:35:55 +00:00
|
|
|
zoneOutline = zone->Outline();
|
|
|
|
zone->SetNeedRefill( true );
|
|
|
|
}
|
2018-10-01 11:15:12 +00:00
|
|
|
else
|
2022-06-01 22:55:59 +00:00
|
|
|
{
|
2018-10-01 11:15:12 +00:00
|
|
|
zoneOutline = &( graphicItem->GetPolyShape() );
|
2022-06-01 22:55:59 +00:00
|
|
|
}
|
2018-09-15 16:51:35 +00:00
|
|
|
|
|
|
|
commit.Modify( item );
|
2014-03-18 13:52:22 +00:00
|
|
|
|
2017-04-14 12:38:59 +00:00
|
|
|
// Search the best outline segment to add a new corner
|
|
|
|
// and therefore break this segment into two segments
|
|
|
|
|
|
|
|
// Object to iterate through the corners of the outlines (main contour and its holes)
|
2021-01-19 23:07:31 +00:00
|
|
|
SHAPE_POLY_SET::ITERATOR iterator = zoneOutline->Iterate( 0, zoneOutline->OutlineCount()-1,
|
|
|
|
/* IterateHoles */ true );
|
2017-04-14 12:38:59 +00:00
|
|
|
int curr_idx = 0;
|
|
|
|
|
|
|
|
// Iterate through all the corners of the outlines and search the best segment
|
|
|
|
for( ; iterator; iterator++, curr_idx++ )
|
2014-03-18 13:52:22 +00:00
|
|
|
{
|
2017-04-14 12:38:59 +00:00
|
|
|
int jj = curr_idx+1;
|
2017-04-06 17:04:47 +00:00
|
|
|
|
2017-04-14 12:38:59 +00:00
|
|
|
if( iterator.IsEndContour() )
|
|
|
|
{ // We reach the last point of the current contour (main or hole)
|
|
|
|
jj = firstPointInContour;
|
|
|
|
firstPointInContour = curr_idx+1; // Prepare next contour analysis
|
|
|
|
}
|
2017-04-06 17:04:47 +00:00
|
|
|
|
2019-03-23 18:26:44 +00:00
|
|
|
SEG curr_segment( zoneOutline->CVertex( curr_idx ), zoneOutline->CVertex( jj ) );
|
2014-03-18 13:52:22 +00:00
|
|
|
|
2017-04-14 12:38:59 +00:00
|
|
|
unsigned int distance = curr_segment.Distance( cursorPos );
|
2017-04-06 17:04:47 +00:00
|
|
|
|
2014-03-18 13:52:22 +00:00
|
|
|
if( distance < nearestDist )
|
|
|
|
{
|
|
|
|
nearestDist = distance;
|
2017-04-14 12:38:59 +00:00
|
|
|
nearestIdx = curr_idx;
|
|
|
|
nextNearestIdx = jj;
|
2014-03-18 13:52:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Find the point on the closest segment
|
2022-06-01 22:55:59 +00:00
|
|
|
const VECTOR2I& sideOrigin = zoneOutline->CVertex( nearestIdx );
|
|
|
|
const VECTOR2I& sideEnd = zoneOutline->CVertex( nextNearestIdx );
|
|
|
|
SEG nearestSide( sideOrigin, sideEnd );
|
|
|
|
VECTOR2I nearestPoint = nearestSide.NearestPoint( cursorPos );
|
2014-03-18 13:52:22 +00:00
|
|
|
|
2014-03-18 16:02:10 +00:00
|
|
|
// Do not add points that have the same coordinates as ones that already belong to polygon
|
|
|
|
// instead, add a point in the middle of the side
|
|
|
|
if( nearestPoint == sideOrigin || nearestPoint == sideEnd )
|
|
|
|
nearestPoint = ( sideOrigin + sideEnd ) / 2;
|
|
|
|
|
2017-04-14 12:38:59 +00:00
|
|
|
zoneOutline->InsertVertex( nextNearestIdx, nearestPoint );
|
2018-09-15 16:51:35 +00:00
|
|
|
|
2018-10-01 11:15:12 +00:00
|
|
|
// We re-hatch the filled zones but not polygons
|
2023-03-30 11:49:23 +00:00
|
|
|
if( item->Type() == PCB_ZONE_T )
|
2020-11-11 23:05:59 +00:00
|
|
|
static_cast<ZONE*>( item )->HatchBorder();
|
2018-09-15 16:51:35 +00:00
|
|
|
|
2016-06-21 15:06:28 +00:00
|
|
|
|
2023-08-05 15:43:10 +00:00
|
|
|
commit.Push( _( "Add Zone Corner" ) );
|
2014-03-18 13:52:22 +00:00
|
|
|
}
|
2021-07-21 18:31:25 +00:00
|
|
|
else if( graphicItem && graphicItem->GetShape() == SHAPE_T::SEGMENT )
|
2014-03-18 14:46:38 +00:00
|
|
|
{
|
2018-10-01 11:15:12 +00:00
|
|
|
commit.Modify( graphicItem );
|
2014-03-18 14:46:38 +00:00
|
|
|
|
2022-06-01 22:55:59 +00:00
|
|
|
SEG seg( graphicItem->GetStart(), graphicItem->GetEnd() );
|
2018-10-01 11:15:12 +00:00
|
|
|
VECTOR2I nearestPoint = seg.NearestPoint( cursorPos );
|
2014-03-18 14:46:38 +00:00
|
|
|
|
2018-10-01 11:15:12 +00:00
|
|
|
// Move the end of the line to the break point..
|
2022-01-01 17:11:21 +00:00
|
|
|
graphicItem->SetEnd( VECTOR2I( nearestPoint.x, nearestPoint.y ) );
|
2014-03-18 14:46:38 +00:00
|
|
|
|
2018-10-01 11:15:12 +00:00
|
|
|
// and add another one starting from the break point
|
2023-03-30 11:49:23 +00:00
|
|
|
PCB_SHAPE* newSegment = new PCB_SHAPE( *graphicItem );
|
2014-07-09 13:02:56 +00:00
|
|
|
|
2018-10-01 11:15:12 +00:00
|
|
|
newSegment->ClearSelected();
|
2022-01-01 17:11:21 +00:00
|
|
|
newSegment->SetStart( VECTOR2I( nearestPoint.x, nearestPoint.y ) );
|
|
|
|
newSegment->SetEnd( VECTOR2I( seg.B.x, seg.B.y ) );
|
2014-03-18 14:46:38 +00:00
|
|
|
|
2018-10-01 11:15:12 +00:00
|
|
|
commit.Add( newSegment );
|
2023-08-05 15:43:10 +00:00
|
|
|
commit.Push( _( "Split Segment" ) );
|
2014-03-18 14:46:38 +00:00
|
|
|
}
|
2017-04-06 17:04:47 +00:00
|
|
|
|
2017-01-18 08:04:11 +00:00
|
|
|
updatePoints();
|
|
|
|
return 0;
|
2014-03-18 13:52:22 +00:00
|
|
|
}
|
2014-07-09 14:50:31 +00:00
|
|
|
|
|
|
|
|
2021-01-16 23:17:32 +00:00
|
|
|
int PCB_POINT_EDITOR::removeCorner( const TOOL_EVENT& aEvent )
|
2015-06-19 15:32:33 +00:00
|
|
|
{
|
2018-09-17 11:31:57 +00:00
|
|
|
if( !m_editPoints || !m_editedPoint )
|
2017-01-18 08:04:11 +00:00
|
|
|
return 0;
|
|
|
|
|
2015-06-19 15:32:33 +00:00
|
|
|
EDA_ITEM* item = m_editPoints->GetParent();
|
|
|
|
|
2017-05-16 09:38:00 +00:00
|
|
|
if( !item )
|
|
|
|
return 0;
|
|
|
|
|
2017-12-06 14:51:47 +00:00
|
|
|
SHAPE_POLY_SET* polygon = nullptr;
|
2017-10-19 21:14:01 +00:00
|
|
|
|
2023-03-30 11:49:23 +00:00
|
|
|
if( item->Type() == PCB_ZONE_T )
|
2015-06-19 15:32:33 +00:00
|
|
|
{
|
2020-11-11 23:05:59 +00:00
|
|
|
ZONE* zone = static_cast<ZONE*>( item );
|
2017-12-06 14:51:47 +00:00
|
|
|
polygon = zone->Outline();
|
2019-03-14 13:35:55 +00:00
|
|
|
zone->SetNeedRefill( true );
|
2017-10-19 21:14:01 +00:00
|
|
|
}
|
2023-03-30 11:49:23 +00:00
|
|
|
else if( item->Type() == PCB_SHAPE_T )
|
2017-10-19 21:14:01 +00:00
|
|
|
{
|
2021-01-19 23:07:31 +00:00
|
|
|
PCB_SHAPE* shape = static_cast<PCB_SHAPE*>( item );
|
2017-12-06 14:51:47 +00:00
|
|
|
|
2021-07-21 18:31:25 +00:00
|
|
|
if( shape->GetShape() == SHAPE_T::POLY )
|
2021-01-19 23:07:31 +00:00
|
|
|
polygon = &shape->GetPolyShape();
|
2017-10-19 21:14:01 +00:00
|
|
|
}
|
2015-06-19 15:32:33 +00:00
|
|
|
|
2017-12-06 14:51:47 +00:00
|
|
|
if( !polygon )
|
2017-10-19 21:14:01 +00:00
|
|
|
return 0;
|
2015-06-19 15:32:33 +00:00
|
|
|
|
2017-10-19 21:14:01 +00:00
|
|
|
PCB_BASE_FRAME* frame = getEditFrame<PCB_BASE_FRAME>();
|
|
|
|
BOARD_COMMIT commit( frame );
|
2017-12-06 14:51:47 +00:00
|
|
|
auto vertex = findVertex( *polygon, *m_editedPoint );
|
2017-10-19 21:14:01 +00:00
|
|
|
|
2017-12-06 14:51:47 +00:00
|
|
|
if( vertex.first )
|
2017-10-19 21:14:01 +00:00
|
|
|
{
|
2017-12-06 14:51:47 +00:00
|
|
|
const auto& vertexIdx = vertex.second;
|
|
|
|
auto& outline = polygon->Polygon( vertexIdx.m_polygon )[vertexIdx.m_contour];
|
|
|
|
|
|
|
|
if( outline.PointCount() > 3 )
|
2015-06-19 15:32:33 +00:00
|
|
|
{
|
2017-12-06 14:51:47 +00:00
|
|
|
// the usual case: remove just the corner when there are >3 vertices
|
|
|
|
commit.Modify( item );
|
|
|
|
polygon->RemoveVertex( vertexIdx );
|
2019-07-14 12:46:59 +00:00
|
|
|
validatePolygon( *polygon );
|
2017-12-06 14:51:47 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// either remove a hole or the polygon when there are <= 3 corners
|
|
|
|
if( vertexIdx.m_contour > 0 )
|
|
|
|
{
|
|
|
|
// remove hole
|
|
|
|
commit.Modify( item );
|
|
|
|
polygon->RemoveContour( vertexIdx.m_contour );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear );
|
2017-12-06 14:51:47 +00:00
|
|
|
commit.Remove( item );
|
|
|
|
}
|
2015-06-19 15:32:33 +00:00
|
|
|
}
|
2017-10-19 21:14:01 +00:00
|
|
|
|
2017-12-06 14:51:47 +00:00
|
|
|
setEditedPoint( nullptr );
|
2018-02-22 11:28:01 +00:00
|
|
|
|
2023-08-05 15:43:10 +00:00
|
|
|
if( item->Type() == PCB_ZONE_T )
|
|
|
|
commit.Push( _( "Remove Zone Corner" ) );
|
|
|
|
else
|
|
|
|
commit.Push( _( "Remove Polygon Corner" ) );
|
2018-02-22 11:28:01 +00:00
|
|
|
|
2019-07-14 12:46:59 +00:00
|
|
|
// Refresh zone hatching
|
2023-03-30 11:49:23 +00:00
|
|
|
if( item->Type() == PCB_ZONE_T )
|
2020-11-11 23:05:59 +00:00
|
|
|
static_cast<ZONE*>( item )->HatchBorder();
|
2018-02-22 11:28:01 +00:00
|
|
|
|
2019-07-14 12:46:59 +00:00
|
|
|
updatePoints();
|
2017-12-06 14:51:47 +00:00
|
|
|
}
|
2017-10-19 21:14:01 +00:00
|
|
|
|
2017-01-18 08:04:11 +00:00
|
|
|
return 0;
|
2014-07-09 14:50:31 +00:00
|
|
|
}
|
2015-06-19 15:32:33 +00:00
|
|
|
|
|
|
|
|
2021-01-16 23:17:32 +00:00
|
|
|
int PCB_POINT_EDITOR::modifiedSelection( const TOOL_EVENT& aEvent )
|
2015-06-19 15:32:33 +00:00
|
|
|
{
|
2017-01-18 08:04:11 +00:00
|
|
|
updatePoints();
|
|
|
|
return 0;
|
2015-06-19 15:32:33 +00:00
|
|
|
}
|
2019-05-24 11:39:30 +00:00
|
|
|
|
2021-07-26 23:47:26 +00:00
|
|
|
|
2022-12-05 18:27:00 +00:00
|
|
|
int PCB_POINT_EDITOR::changeArcEditMode( const TOOL_EVENT& aEvent )
|
2020-08-29 22:59:11 +00:00
|
|
|
{
|
2022-12-05 18:27:00 +00:00
|
|
|
PCB_BASE_EDIT_FRAME* editFrame = getEditFrame<PCB_BASE_EDIT_FRAME>();
|
|
|
|
|
|
|
|
if( aEvent.Matches( ACTIONS::cycleArcEditMode.MakeEvent() ) )
|
|
|
|
{
|
|
|
|
if( editFrame->IsType( FRAME_PCB_EDITOR ) )
|
|
|
|
m_arcEditMode = editFrame->GetPcbNewSettings()->m_ArcEditMode;
|
|
|
|
else
|
|
|
|
m_arcEditMode = editFrame->GetFootprintEditorSettings()->m_ArcEditMode;
|
|
|
|
|
|
|
|
switch( m_arcEditMode )
|
|
|
|
{
|
|
|
|
case ARC_EDIT_MODE::KEEP_CENTER_ADJUST_ANGLE_RADIUS:
|
|
|
|
m_arcEditMode = ARC_EDIT_MODE::KEEP_ENDPOINTS_OR_START_DIRECTION;
|
|
|
|
break;
|
|
|
|
case ARC_EDIT_MODE::KEEP_ENDPOINTS_OR_START_DIRECTION:
|
|
|
|
m_arcEditMode = ARC_EDIT_MODE::KEEP_CENTER_ADJUST_ANGLE_RADIUS;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_arcEditMode = aEvent.Parameter<ARC_EDIT_MODE>();
|
|
|
|
}
|
|
|
|
|
|
|
|
if( editFrame->IsType( FRAME_PCB_EDITOR ) )
|
|
|
|
editFrame->GetPcbNewSettings()->m_ArcEditMode = m_arcEditMode;
|
|
|
|
else
|
|
|
|
editFrame->GetFootprintEditorSettings()->m_ArcEditMode = m_arcEditMode;
|
|
|
|
|
2020-08-29 22:59:11 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2019-05-24 11:39:30 +00:00
|
|
|
|
2021-07-26 23:47:26 +00:00
|
|
|
|
2021-01-16 23:17:32 +00:00
|
|
|
void PCB_POINT_EDITOR::setTransitions()
|
2019-05-24 11:39:30 +00:00
|
|
|
{
|
2021-01-16 23:17:32 +00:00
|
|
|
Go( &PCB_POINT_EDITOR::OnSelectionChange, ACTIONS::activatePointEditor.MakeEvent() );
|
2023-08-05 15:43:10 +00:00
|
|
|
Go( &PCB_POINT_EDITOR::movePoint, PCB_ACTIONS::pointEditorMoveCorner.MakeEvent() );
|
|
|
|
Go( &PCB_POINT_EDITOR::movePoint, PCB_ACTIONS::pointEditorMoveMidpoint.MakeEvent() );
|
2021-11-09 13:09:06 +00:00
|
|
|
Go( &PCB_POINT_EDITOR::addCorner, PCB_ACTIONS::pointEditorAddCorner.MakeEvent() );
|
2022-12-12 04:04:03 +00:00
|
|
|
Go( &PCB_POINT_EDITOR::removeCorner, PCB_ACTIONS::pointEditorRemoveCorner.MakeEvent() );
|
2022-12-05 18:27:00 +00:00
|
|
|
Go( &PCB_POINT_EDITOR::changeArcEditMode, PCB_ACTIONS::pointEditorArcKeepCenter.MakeEvent() );
|
|
|
|
Go( &PCB_POINT_EDITOR::changeArcEditMode, PCB_ACTIONS::pointEditorArcKeepEndpoint.MakeEvent() );
|
|
|
|
Go( &PCB_POINT_EDITOR::changeArcEditMode, ACTIONS::cycleArcEditMode.MakeEvent() );
|
2021-01-16 23:17:32 +00:00
|
|
|
Go( &PCB_POINT_EDITOR::modifiedSelection, EVENTS::SelectedItemsModified );
|
2022-11-05 16:36:10 +00:00
|
|
|
Go( &PCB_POINT_EDITOR::modifiedSelection, EVENTS::SelectedItemsMoved );
|
2022-07-19 15:00:35 +00:00
|
|
|
Go( &PCB_POINT_EDITOR::OnSelectionChange, EVENTS::PointSelectedEvent );
|
2021-01-16 23:17:32 +00:00
|
|
|
Go( &PCB_POINT_EDITOR::OnSelectionChange, EVENTS::SelectedEvent );
|
|
|
|
Go( &PCB_POINT_EDITOR::OnSelectionChange, EVENTS::UnselectedEvent );
|
|
|
|
Go( &PCB_POINT_EDITOR::OnSelectionChange, EVENTS::InhibitSelectionEditing );
|
|
|
|
Go( &PCB_POINT_EDITOR::OnSelectionChange, EVENTS::UninhibitSelectionEditing );
|
2019-05-24 11:39:30 +00:00
|
|
|
}
|