2014-02-27 16:29:08 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2019-03-14 09:18:50 +00:00
|
|
|
* Copyright (C) 2013-2019 CERN
|
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>
|
2016-06-29 10:23:11 +00:00
|
|
|
using namespace std::placeholders;
|
2020-08-09 23:03:31 +00:00
|
|
|
#include <advanced_config.h>
|
2014-02-27 16:29:08 +00:00
|
|
|
#include <tool/tool_manager.h>
|
|
|
|
#include <view/view_controls.h>
|
2014-03-06 13:41:25 +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>
|
2017-02-21 12:42:08 +00:00
|
|
|
#include "pcb_actions.h"
|
2014-02-27 16:29:08 +00:00
|
|
|
#include "selection_tool.h"
|
|
|
|
#include "point_editor.h"
|
2018-09-24 21:29:23 +00:00
|
|
|
#include "grid_helper.h"
|
2016-06-21 15:06:28 +00:00
|
|
|
#include <board_commit.h>
|
2017-02-20 18:10:20 +00:00
|
|
|
#include <bitmaps.h>
|
2018-02-22 11:28:01 +00:00
|
|
|
#include <status_popup.h>
|
2018-01-29 20:58:58 +00:00
|
|
|
#include <pcb_edit_frame.h>
|
2014-07-09 11:50:27 +00:00
|
|
|
#include <class_edge_mod.h>
|
2014-03-12 09:46:11 +00:00
|
|
|
#include <class_dimension.h>
|
2014-02-28 17:24:29 +00:00
|
|
|
#include <class_zone.h>
|
2018-10-12 06:17:15 +00:00
|
|
|
#include <connectivity/connectivity_data.h>
|
2019-03-14 09:18:50 +00:00
|
|
|
#include <widgets/progress_reporter.h>
|
2014-02-27 16:29:08 +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
|
|
|
|
};
|
|
|
|
|
2020-06-15 19:50:20 +00:00
|
|
|
enum RECT_POINTS
|
|
|
|
{
|
|
|
|
RECT_TOP_LEFT, RECT_TOP_RIGHT, RECT_BOT_RIGHT, RECT_BOT_LEFT
|
|
|
|
};
|
|
|
|
|
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
|
|
|
};
|
|
|
|
|
|
|
|
enum CIRCLE_POINTS
|
|
|
|
{
|
|
|
|
CIRC_CENTER, CIRC_END
|
|
|
|
};
|
|
|
|
|
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
|
|
|
|
};
|
|
|
|
|
2014-04-01 15:41:24 +00:00
|
|
|
enum DIMENSION_POINTS
|
|
|
|
{
|
|
|
|
DIM_CROSSBARO,
|
|
|
|
DIM_CROSSBARF,
|
|
|
|
DIM_FEATUREGO,
|
|
|
|
DIM_FEATUREDO,
|
|
|
|
};
|
|
|
|
|
2014-02-27 16:29:08 +00:00
|
|
|
class EDIT_POINTS_FACTORY
|
|
|
|
{
|
2017-10-19 21:14:01 +00:00
|
|
|
private:
|
|
|
|
|
2018-07-22 12:50:35 +00:00
|
|
|
static void buildForPolyOutline( std::shared_ptr<EDIT_POINTS> points,
|
|
|
|
const SHAPE_POLY_SET* aOutline, KIGFX::GAL* aGal )
|
2017-10-19 21:14:01 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
int cornersCount = aOutline->TotalVertices();
|
|
|
|
|
|
|
|
for( auto iterator = aOutline->CIterateWithHoles(); iterator; iterator++ )
|
|
|
|
{
|
|
|
|
points->AddPoint( *iterator );
|
|
|
|
|
|
|
|
if( iterator.IsEndContour() )
|
|
|
|
points->AddBreak();
|
|
|
|
}
|
|
|
|
|
2018-03-26 21:30:56 +00:00
|
|
|
// Lines have to be added after creating edit points,
|
|
|
|
// as they use EDIT_POINT references
|
2017-10-19 21:14:01 +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 ) );
|
|
|
|
}
|
|
|
|
|
2020-08-27 17:31:53 +00:00
|
|
|
points->Line( i ).SetConstraint( new EC_PERPLINE( points->Line( i ) ) );
|
2017-10-19 21:14:01 +00:00
|
|
|
}
|
|
|
|
|
2018-03-26 21:30:56 +00:00
|
|
|
// The last missing line, connecting the last and the first polygon point
|
2017-10-19 21:14:01 +00:00
|
|
|
points->AddLine( points->Point( cornersCount - 1 ),
|
|
|
|
points->Point( points->GetContourStartIdx( cornersCount - 1 ) ) );
|
|
|
|
|
|
|
|
points->Line( points->LinesSize() - 1 ).SetConstraint(
|
2020-08-27 17:31:53 +00:00
|
|
|
new EC_PERPLINE( points->Line( points->LinesSize() - 1 ) ) );
|
2017-10-19 21:14:01 +00:00
|
|
|
}
|
|
|
|
|
2014-02-27 16:29:08 +00:00
|
|
|
public:
|
2016-06-29 15:09:55 +00:00
|
|
|
static std::shared_ptr<EDIT_POINTS> Make( EDA_ITEM* aItem, KIGFX::GAL* aGal )
|
2014-02-27 16:29:08 +00:00
|
|
|
{
|
2016-06-29 15:09:55 +00:00
|
|
|
std::shared_ptr<EDIT_POINTS> points = std::make_shared<EDIT_POINTS>( aItem );
|
2014-02-27 16:29:08 +00:00
|
|
|
|
2017-05-16 09:38:00 +00:00
|
|
|
if( !aItem )
|
|
|
|
return points;
|
|
|
|
|
2014-03-06 11:36:20 +00:00
|
|
|
// Generate list of edit points basing on the item type
|
2014-02-27 16:29:08 +00:00
|
|
|
switch( aItem->Type() )
|
|
|
|
{
|
2020-06-28 22:34:10 +00:00
|
|
|
case PCB_LINE_T:
|
|
|
|
case PCB_MODULE_EDGE_T:
|
|
|
|
{
|
|
|
|
const DRAWSEGMENT* segment = static_cast<const DRAWSEGMENT*>( aItem );
|
2014-02-27 16:29:08 +00:00
|
|
|
|
2020-06-28 22:34:10 +00:00
|
|
|
switch( segment->GetShape() )
|
|
|
|
{
|
|
|
|
case S_SEGMENT:
|
|
|
|
points->AddPoint( segment->GetStart() );
|
|
|
|
points->AddPoint( segment->GetEnd() );
|
|
|
|
break;
|
2020-06-15 19:50:20 +00:00
|
|
|
|
2020-06-28 22:34:10 +00:00
|
|
|
case S_RECT:
|
|
|
|
points->AddPoint( segment->GetStart() );
|
|
|
|
points->AddPoint( wxPoint( segment->GetEnd().x, segment->GetStart().y ) );
|
|
|
|
points->AddPoint( segment->GetEnd() );
|
|
|
|
points->AddPoint( wxPoint( segment->GetStart().x, segment->GetEnd().y ) );
|
|
|
|
break;
|
2014-02-27 16:29:08 +00:00
|
|
|
|
2020-06-28 22:34:10 +00:00
|
|
|
case S_ARC:
|
|
|
|
points->AddPoint( segment->GetCenter() );
|
|
|
|
points->AddPoint( segment->GetArcStart() );
|
|
|
|
points->AddPoint( segment->GetArcMid() );
|
|
|
|
points->AddPoint( segment->GetArcEnd() );
|
2018-12-08 15:26:47 +00:00
|
|
|
|
2020-06-28 22:34:10 +00:00
|
|
|
// Set constraints
|
|
|
|
// Arc end has to stay at the same radius as the start
|
|
|
|
points->Point( ARC_END ).SetConstraint( new EC_CIRCLE( points->Point( ARC_END ),
|
|
|
|
points->Point( ARC_CENTER ),
|
|
|
|
points->Point( ARC_START ) ) );
|
2014-02-27 16:29:08 +00:00
|
|
|
|
2020-06-28 22:34:10 +00:00
|
|
|
points->Point( ARC_MID ).SetConstraint( new EC_LINE( points->Point( ARC_MID ),
|
|
|
|
points->Point( ARC_CENTER ) ) );
|
|
|
|
break;
|
2014-02-28 17:24:13 +00:00
|
|
|
|
2020-06-28 22:34:10 +00:00
|
|
|
case S_CIRCLE:
|
|
|
|
points->AddPoint( segment->GetCenter() );
|
|
|
|
points->AddPoint( segment->GetEnd() );
|
|
|
|
break;
|
2018-07-22 12:50:35 +00:00
|
|
|
|
2020-06-28 22:34:10 +00:00
|
|
|
case S_POLYGON:
|
|
|
|
buildForPolyOutline( points, &segment->GetPolyShape(), aGal );
|
|
|
|
break;
|
2017-10-19 21:14:01 +00:00
|
|
|
|
2020-06-28 22:34:10 +00:00
|
|
|
case S_CURVE:
|
|
|
|
points->AddPoint( segment->GetStart() );
|
|
|
|
points->AddPoint( segment->GetBezControl1() );
|
|
|
|
points->AddPoint( segment->GetBezControl2() );
|
|
|
|
points->AddPoint( segment->GetEnd() );
|
|
|
|
break;
|
2014-02-28 17:24:29 +00:00
|
|
|
|
2020-06-28 22:34:10 +00:00
|
|
|
default: // suppress warnings
|
2014-02-28 17:24:29 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-06-28 22:34:10 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case PCB_PAD_T:
|
|
|
|
{
|
|
|
|
const D_PAD* pad = static_cast<const D_PAD*>( aItem );
|
|
|
|
wxPoint shapePos = pad->ShapePos();
|
|
|
|
wxPoint halfSize( pad->GetSize().x / 2, pad->GetSize().y / 2 );
|
|
|
|
|
2020-06-29 18:14:51 +00:00
|
|
|
if( pad->GetParent() && pad->GetParent()->PadsLocked() )
|
|
|
|
break;
|
|
|
|
|
2020-06-28 22:34:10 +00:00
|
|
|
switch( pad->GetShape() )
|
2014-02-28 17:24:29 +00:00
|
|
|
{
|
2020-06-28 22:34:10 +00:00
|
|
|
case PAD_SHAPE_CIRCLE:
|
|
|
|
points->AddPoint( shapePos );
|
|
|
|
points->AddPoint( wxPoint( shapePos.x + halfSize.x, shapePos.y ) );
|
2014-03-12 09:46:11 +00:00
|
|
|
break;
|
|
|
|
|
2020-06-28 22:34:10 +00:00
|
|
|
case PAD_SHAPE_OVAL:
|
|
|
|
case PAD_SHAPE_TRAPEZOID:
|
|
|
|
case PAD_SHAPE_RECT:
|
|
|
|
case PAD_SHAPE_ROUNDRECT:
|
|
|
|
case PAD_SHAPE_CHAMFERED_RECT:
|
2014-03-12 09:46:11 +00:00
|
|
|
{
|
2020-06-28 22:34:10 +00:00
|
|
|
if( (int) pad->GetOrientation() % 900 != 0 )
|
|
|
|
break;
|
2014-03-12 09:46:11 +00:00
|
|
|
|
2020-06-28 22:34:10 +00:00
|
|
|
if( pad->GetOrientation() == 900 || pad->GetOrientation() == 2700 )
|
|
|
|
std::swap( halfSize.x, halfSize.y );
|
2014-03-12 09:46:11 +00:00
|
|
|
|
2020-06-28 22:34:10 +00:00
|
|
|
points->AddPoint( shapePos - halfSize );
|
|
|
|
points->AddPoint( wxPoint( shapePos.x + halfSize.x, shapePos.y - halfSize.y ) );
|
|
|
|
points->AddPoint( shapePos + halfSize );
|
|
|
|
points->AddPoint( wxPoint( shapePos.x - halfSize.x, shapePos.y + halfSize.y ) );
|
|
|
|
}
|
|
|
|
break;
|
2014-02-28 17:24:29 +00:00
|
|
|
|
2020-06-28 22:34:10 +00:00
|
|
|
default: // suppress warnings
|
2014-02-28 17:24:29 +00:00
|
|
|
break;
|
2014-02-27 16:29:08 +00:00
|
|
|
}
|
2020-06-28 22:34:10 +00:00
|
|
|
}
|
|
|
|
break;
|
2014-02-27 16:29:08 +00:00
|
|
|
|
2020-06-28 22:34:10 +00:00
|
|
|
case PCB_MODULE_ZONE_AREA_T:
|
|
|
|
case PCB_ZONE_AREA_T:
|
|
|
|
{
|
|
|
|
auto zone = static_cast<const ZONE_CONTAINER*>( aItem );
|
|
|
|
buildForPolyOutline( points, zone->Outline(), aGal );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PCB_DIMENSION_T:
|
|
|
|
{
|
|
|
|
const DIMENSION* dimension = static_cast<const DIMENSION*>( aItem );
|
|
|
|
|
|
|
|
points->AddPoint( dimension->m_crossBarO );
|
|
|
|
points->AddPoint( dimension->m_crossBarF );
|
|
|
|
points->AddPoint( dimension->m_featureLineGO );
|
|
|
|
points->AddPoint( dimension->m_featureLineDO );
|
|
|
|
|
|
|
|
// Dimension height setting - edit points should move only along the feature lines
|
|
|
|
points->Point( DIM_CROSSBARO ).SetConstraint( new EC_LINE( points->Point( DIM_CROSSBARO ),
|
|
|
|
points->Point( DIM_FEATUREGO ) ) );
|
|
|
|
points->Point( DIM_CROSSBARF ).SetConstraint( new EC_LINE( points->Point( DIM_CROSSBARF ),
|
|
|
|
points->Point( DIM_FEATUREDO ) ) );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
points.reset();
|
|
|
|
break;
|
2014-02-27 16:29:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return points;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
EDIT_POINTS_FACTORY() {};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2019-05-14 19:21:10 +00:00
|
|
|
POINT_EDITOR::POINT_EDITOR() :
|
2019-05-12 11:49:58 +00:00
|
|
|
PCB_TOOL_BASE( "pcbnew.PointEditor" ),
|
2019-05-08 18:56:03 +00:00
|
|
|
m_selectionTool( NULL ),
|
|
|
|
m_editedPoint( NULL ),
|
|
|
|
m_original( VECTOR2I( 0, 0 ) ),
|
|
|
|
m_altConstrainer( VECTOR2I( 0, 0 ) ),
|
|
|
|
m_refill( false )
|
2014-02-27 16:29:08 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-14 19:21:10 +00:00
|
|
|
void POINT_EDITOR::Reset( RESET_REASON aReason )
|
2014-02-28 16:20:10 +00:00
|
|
|
{
|
2018-04-03 20:26:01 +00:00
|
|
|
m_refill = false;
|
2014-02-28 16:20:10 +00:00
|
|
|
m_editPoints.reset();
|
2014-03-14 14:37:55 +00:00
|
|
|
m_altConstraint.reset();
|
2018-02-14 14:40:18 +00:00
|
|
|
getViewControls()->SetAutoPan( false );
|
2018-03-02 09:55:59 +00:00
|
|
|
|
2019-12-05 13:43:55 +00:00
|
|
|
m_statusPopup = std::make_unique<STATUS_TEXT_POPUP>( getEditFrame<PCB_BASE_EDIT_FRAME>() );
|
2018-03-02 09:55:59 +00:00
|
|
|
m_statusPopup->SetTextColor( wxColour( 255, 0, 0 ) );
|
2019-05-19 21:04:04 +00:00
|
|
|
m_statusPopup->SetText( _( "Self-intersecting polygons are not allowed." ) );
|
2014-02-28 16:20:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-14 19:21:10 +00:00
|
|
|
bool POINT_EDITOR::Init()
|
2014-02-27 16:29:08 +00:00
|
|
|
{
|
|
|
|
// Find the selection tool, so they can cooperate
|
2019-05-08 18:56:03 +00:00
|
|
|
m_selectionTool = m_toolMgr->GetTool<SELECTION_TOOL>();
|
2014-02-27 16:29:08 +00:00
|
|
|
|
2019-05-08 18:56:03 +00:00
|
|
|
wxASSERT_MSG( m_selectionTool, _( "pcbnew.InteractiveSelection tool is not available" ) );
|
2014-02-27 16:29:08 +00:00
|
|
|
|
2017-01-12 10:07:52 +00:00
|
|
|
auto& menu = m_selectionTool->GetToolMenu().GetMenu();
|
2019-05-14 19:21:10 +00:00
|
|
|
menu.AddItem( PCB_ACTIONS::pointEditorAddCorner, POINT_EDITOR::addCornerCondition );
|
2017-02-21 12:42:08 +00:00
|
|
|
menu.AddItem( PCB_ACTIONS::pointEditorRemoveCorner,
|
2019-05-14 19:21:10 +00:00
|
|
|
std::bind( &POINT_EDITOR::removeCornerCondition, this, _1 ) );
|
2014-07-09 14:50:31 +00:00
|
|
|
|
2014-02-27 16:29:08 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-14 19:21:10 +00:00
|
|
|
void 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;
|
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() );
|
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
|
|
|
|
|
|
|
if( m_editedPoint != point )
|
|
|
|
setEditedPoint( point );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-14 19:21:10 +00:00
|
|
|
int POINT_EDITOR::OnSelectionChange( const TOOL_EVENT& aEvent )
|
2014-02-27 16:29:08 +00:00
|
|
|
{
|
2018-09-17 11:31:57 +00:00
|
|
|
if( !m_selectionTool )
|
|
|
|
return 0;
|
|
|
|
|
2019-06-08 21:48:22 +00:00
|
|
|
const PCBNEW_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;
|
|
|
|
|
|
|
|
Activate();
|
2014-03-06 13:41:25 +00:00
|
|
|
|
2017-03-06 09:55:32 +00:00
|
|
|
KIGFX::VIEW_CONTROLS* controls = getViewControls();
|
|
|
|
KIGFX::VIEW* view = getView();
|
|
|
|
PCB_BASE_EDIT_FRAME* editFrame = getEditFrame<PCB_BASE_EDIT_FRAME>();
|
2018-09-24 21:29:23 +00:00
|
|
|
|
2018-10-07 02:55:20 +00:00
|
|
|
controls->ShowCursor( true );
|
2018-10-05 03:23:05 +00:00
|
|
|
|
2020-06-13 12:33:29 +00:00
|
|
|
GRID_HELPER grid( m_toolMgr, editFrame->GetMagneticItemsSettings() );
|
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
|
|
|
|
2019-05-30 00:51:22 +00:00
|
|
|
if( !item )
|
|
|
|
return 0;
|
|
|
|
|
2017-03-06 09:55:32 +00:00
|
|
|
m_editPoints = EDIT_POINTS_FACTORY::Make( item, getView()->GetGAL() );
|
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
|
|
|
|
2017-03-06 09:55:32 +00:00
|
|
|
view->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;
|
2014-03-06 11:36:20 +00:00
|
|
|
|
2017-03-06 09:55:32 +00:00
|
|
|
BOARD_COMMIT commit( editFrame );
|
2018-10-07 02:55:20 +00:00
|
|
|
LSET snapLayers = item->GetLayerSet();
|
|
|
|
|
|
|
|
if( item->Type() == PCB_DIMENSION_T )
|
|
|
|
snapLayers = LSET::AllLayersMask();
|
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 ) );
|
2018-10-05 04:08:15 +00:00
|
|
|
grid.SetUseGrid( !evt->Modifier( MD_ALT ) );
|
2018-10-07 03:20:38 +00:00
|
|
|
controls->SetSnapping( !evt->Modifier( MD_ALT ) );
|
2018-10-04 00:15:54 +00:00
|
|
|
|
2019-07-01 21:01:33 +00:00
|
|
|
if( !m_editPoints || evt->IsSelectionEvent() )
|
2017-03-06 09:55:32 +00:00
|
|
|
break;
|
2015-12-14 21:20:54 +00:00
|
|
|
|
2019-06-17 13:43:22 +00:00
|
|
|
if ( !inDrag )
|
2017-03-06 09:55:32 +00:00
|
|
|
updateEditedPoint( *evt );
|
2014-02-28 16:20:10 +00:00
|
|
|
|
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
|
|
|
{
|
2017-03-06 09:55:32 +00:00
|
|
|
commit.StageItems( selection, CHT_MODIFY );
|
2016-06-08 09:24:46 +00:00
|
|
|
|
2018-10-08 11:11:11 +00:00
|
|
|
controls->ForceCursorPosition( false );
|
2017-03-06 09:55:32 +00:00
|
|
|
m_original = *m_editedPoint; // Save the original position
|
|
|
|
controls->SetAutoPan( true );
|
2019-06-17 13:43:22 +00:00
|
|
|
inDrag = true;
|
2019-07-15 23:44:01 +00:00
|
|
|
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();
|
2017-03-06 09:55:32 +00:00
|
|
|
}
|
2016-06-21 15:06:28 +00:00
|
|
|
|
2018-10-07 15:00:41 +00:00
|
|
|
//TODO: unify the constraints to solve simultaneously instead of sequentially
|
2018-11-16 18:01:54 +00:00
|
|
|
m_editedPoint->SetPosition( grid.BestSnapAnchor( evt->Position(),
|
2019-06-17 13:43:22 +00:00
|
|
|
snapLayers, { item } ) );
|
2019-08-26 13:30:03 +00:00
|
|
|
|
|
|
|
// The alternative constraint limits to 45°
|
2019-10-20 16:07:46 +00:00
|
|
|
bool enableAltConstraint = !!evt->Modifier( MD_CTRL );
|
2014-03-06 13:41:25 +00:00
|
|
|
|
2020-08-27 17:31:53 +00:00
|
|
|
if( enableAltConstraint )
|
2017-03-06 09:55:32 +00:00
|
|
|
m_altConstraint->Apply();
|
2018-09-24 21:29:23 +00:00
|
|
|
else
|
|
|
|
m_editedPoint->ApplyConstraint();
|
2016-06-21 15:06:28 +00:00
|
|
|
|
2020-08-27 17:31:53 +00:00
|
|
|
// Don't snap the line center to the grid
|
|
|
|
if( !dynamic_cast<EDIT_LINE*>( m_editedPoint) )
|
|
|
|
m_editedPoint->SetPosition( grid.BestSnapAnchor( m_editedPoint->GetPosition(),
|
|
|
|
snapLayers, { item } ) );
|
2018-10-04 00:15:54 +00:00
|
|
|
|
2017-03-06 09:55:32 +00:00
|
|
|
updateItem();
|
|
|
|
updatePoints();
|
|
|
|
}
|
2016-06-21 15:06:28 +00:00
|
|
|
|
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() );
|
|
|
|
}
|
|
|
|
|
2017-03-06 09:55:32 +00:00
|
|
|
controls->SetAutoPan( false );
|
|
|
|
setAltConstraint( false );
|
2014-03-06 11:36:20 +00:00
|
|
|
|
2019-06-17 13:43:22 +00:00
|
|
|
commit.Push( _( "Drag a corner" ) );
|
|
|
|
inDrag = false;
|
|
|
|
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
|
2019-06-16 00:06:43 +00:00
|
|
|
commit.Revert();
|
2019-07-01 21:01:33 +00:00
|
|
|
else if( evt->IsCancelInteractive() )
|
|
|
|
break;
|
2017-03-06 09:55:32 +00:00
|
|
|
|
2019-07-01 21:01:33 +00:00
|
|
|
if( evt->IsActivate() && !evt->IsMoveTool() )
|
|
|
|
break;
|
2014-02-27 16:29:08 +00:00
|
|
|
}
|
|
|
|
|
2017-03-06 09:55:32 +00:00
|
|
|
else
|
2019-06-16 11:06:49 +00:00
|
|
|
evt->SetPassEvent();
|
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 )
|
|
|
|
{
|
|
|
|
view->Remove( m_editPoints.get() );
|
2017-05-16 09:38:00 +00:00
|
|
|
|
2018-04-03 20:26:01 +00:00
|
|
|
finishItem();
|
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
|
|
|
|
2018-10-30 11:32:42 +00:00
|
|
|
frame()->UpdateMsgPanel();
|
2018-04-12 16:08:45 +00:00
|
|
|
|
2014-02-27 16:29:08 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-08-29 22:59:11 +00:00
|
|
|
void POINT_EDITOR::editArcEndpointKeepTangent( DRAWSEGMENT* aArc, VECTOR2I aCenter, VECTOR2I aStart,
|
|
|
|
VECTOR2I aMid, VECTOR2I aEnd,
|
|
|
|
const VECTOR2I aCursor ) const
|
|
|
|
{
|
|
|
|
VECTOR2D startLine = aStart - aCenter;
|
|
|
|
VECTOR2D endLine = aEnd - aCenter;
|
|
|
|
double newAngle = RAD2DECIDEG( endLine.Angle() - startLine.Angle() );
|
|
|
|
|
|
|
|
bool clockwise;
|
|
|
|
bool movingStart;
|
|
|
|
bool arcValid = true;
|
|
|
|
|
|
|
|
VECTOR2I *p1, *p2, *p3;
|
|
|
|
// p1 does not move, p2 does.
|
|
|
|
|
|
|
|
if( aStart != aArc->GetArcStart() )
|
|
|
|
{
|
|
|
|
aStart = aCursor;
|
|
|
|
p1 = &aEnd;
|
|
|
|
p2 = &aStart;
|
|
|
|
p3 = &aMid;
|
|
|
|
movingStart = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
aEnd = aCursor;
|
|
|
|
p1 = &aStart;
|
|
|
|
p2 = &aEnd;
|
|
|
|
p3 = &aMid;
|
|
|
|
movingStart = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
VECTOR2D v1, v2, v3, v4;
|
|
|
|
|
|
|
|
// Move the coordinate system
|
|
|
|
v1 = *p1 - aCenter;
|
|
|
|
v2 = *p2 - aCenter;
|
|
|
|
v3 = *p3 - aCenter;
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
/* 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
|
|
|
|
*/
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
// Never recorded a problem, but still checking.
|
|
|
|
if( !std::isfinite( delta ) )
|
|
|
|
{
|
|
|
|
arcValid = false;
|
|
|
|
}
|
|
|
|
// v4 is the new center
|
|
|
|
v4 = ( !transformCircle ) ? VECTOR2D( -delta, 0 ) : VECTOR2D( 2 * R + delta, 0 );
|
|
|
|
|
|
|
|
clockwise = aArc->GetAngle() > 0;
|
|
|
|
|
|
|
|
if( transformCircle )
|
|
|
|
clockwise = !clockwise;
|
|
|
|
|
|
|
|
tmpx = v4.x * u1.x + v4.y * u2.x;
|
|
|
|
tmpy = v4.x * u1.y + v4.y * u2.y;
|
|
|
|
v4.x = tmpx;
|
|
|
|
v4.y = tmpy;
|
|
|
|
|
|
|
|
aCenter = v4 + aCenter;
|
|
|
|
|
|
|
|
startLine = aStart - aCenter;
|
|
|
|
endLine = aEnd - aCenter;
|
|
|
|
newAngle = RAD2DECIDEG( endLine.Angle() - startLine.Angle() );
|
|
|
|
|
|
|
|
if( clockwise && newAngle < 0.0 )
|
|
|
|
newAngle += 3600.0;
|
|
|
|
else if( !clockwise && newAngle > 0.0 )
|
|
|
|
newAngle -= 3600.0;
|
|
|
|
|
|
|
|
if( arcValid )
|
|
|
|
{
|
|
|
|
aArc->SetAngle( newAngle );
|
|
|
|
aArc->SetCenter( wxPoint( aCenter.x, aCenter.y ) );
|
|
|
|
|
|
|
|
if( movingStart )
|
|
|
|
{
|
|
|
|
aArc->SetArcStart( wxPoint( aStart.x, aStart.y ) );
|
|
|
|
// Set angle computes the end point, so re-force it now.
|
|
|
|
aArc->SetArcEnd( wxPoint( aEnd.x, aEnd.y ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
aArc->SetArcEnd( wxPoint( aEnd.x, aEnd.y ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-27 16:29:08 +00:00
|
|
|
|
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
|
2020-08-19 22:26:36 +00:00
|
|
|
* @param aEditedPointIndex is the corner id
|
2020-08-22 19:27:17 +00:00
|
|
|
* @param aMinWidth is the minimal width constraint
|
|
|
|
* @param aMinHeight is the minimal height constraint
|
|
|
|
* @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
|
|
|
*/
|
2020-08-22 19:27:17 +00:00
|
|
|
static void pinEditedCorner( int aEditedPointIndex, int aMinWidth, int aMinHeight,
|
|
|
|
VECTOR2I& aTopLeft, VECTOR2I& aTopRight, VECTOR2I& aBotLeft,
|
|
|
|
VECTOR2I& aBotRight, VECTOR2I aHole, VECTOR2I aHoleSize )
|
2020-08-19 22:26:36 +00:00
|
|
|
{
|
|
|
|
switch( aEditedPointIndex )
|
|
|
|
{
|
|
|
|
case RECT_TOP_LEFT:
|
2020-08-22 19:27:17 +00:00
|
|
|
if( aHoleSize.x )
|
|
|
|
{
|
|
|
|
// pin edited point to the top/left of the hole
|
|
|
|
aTopLeft.x = std::min( aTopLeft.x, aHole.x - aHoleSize.x / 2 - aMinWidth );
|
|
|
|
aTopLeft.y = std::min( aTopLeft.y, aHole.y - aHoleSize.y / 2 - aMinHeight );
|
|
|
|
}
|
|
|
|
else
|
2020-08-19 22:26:36 +00:00
|
|
|
{
|
2020-08-22 19:27:17 +00:00
|
|
|
// pin edited point within opposite corner
|
|
|
|
aTopLeft.x = std::min( aTopLeft.x, aBotRight.x - aMinWidth );
|
|
|
|
aTopLeft.y = std::min( aTopLeft.y, aBotRight.y - aMinHeight );
|
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;
|
2020-08-19 22:26:36 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RECT_TOP_RIGHT:
|
2020-08-22 19:27:17 +00:00
|
|
|
if( aHoleSize.x )
|
|
|
|
{
|
|
|
|
// pin edited point to the top/right of the hole
|
|
|
|
aTopRight.x = std::max( aTopRight.x, aHole.x + aHoleSize.x / 2 + aMinWidth );
|
|
|
|
aTopRight.y = std::min( aTopRight.y, aHole.y - aHoleSize.y / 2 - aMinHeight );
|
|
|
|
}
|
|
|
|
else
|
2020-08-19 22:26:36 +00:00
|
|
|
{
|
2020-08-22 19:27:17 +00:00
|
|
|
// pin edited point within opposite corner
|
|
|
|
aTopRight.x = std::max( aTopRight.x, aBotLeft.x + aMinWidth );
|
|
|
|
aTopRight.y = std::min( aTopRight.y, aBotLeft.y - aMinHeight );
|
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;
|
2020-08-19 22:26:36 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RECT_BOT_LEFT:
|
2020-08-22 19:27:17 +00:00
|
|
|
if( aHoleSize.x )
|
|
|
|
{
|
|
|
|
// pin edited point to the bottom/left of the hole
|
|
|
|
aBotLeft.x = std::min( aBotLeft.x, aHole.x - aHoleSize.x / 2 - aMinWidth );
|
|
|
|
aBotLeft.y = std::max( aBotLeft.y, aHole.y + aHoleSize.y / 2 + aMinHeight );
|
|
|
|
}
|
|
|
|
else
|
2020-08-19 22:26:36 +00:00
|
|
|
{
|
2020-08-22 19:27:17 +00:00
|
|
|
// pin edited point within opposite corner
|
|
|
|
aBotLeft.x = std::min( aBotLeft.x, aTopRight.x - aMinWidth );
|
|
|
|
aBotLeft.y = std::max( aBotLeft.y, aTopRight.y + aMinHeight );
|
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;
|
2020-08-19 22:26:36 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RECT_BOT_RIGHT:
|
2020-08-22 19:27:17 +00:00
|
|
|
if( aHoleSize.x )
|
|
|
|
{
|
|
|
|
// pin edited point to the bottom/right of the hole
|
|
|
|
aBotRight.x = std::max( aBotRight.x, aHole.x + aHoleSize.x / 2 + aMinWidth );
|
|
|
|
aBotRight.y = std::max( aBotRight.y, aHole.y + aHoleSize.y / 2 + aMinHeight );
|
|
|
|
}
|
|
|
|
else
|
2020-08-19 22:26:36 +00:00
|
|
|
{
|
2020-08-22 19:27:17 +00:00
|
|
|
// pin edited point within opposite corner
|
|
|
|
aBotRight.x = std::max( aBotRight.x, aTopLeft.x + aMinWidth );
|
|
|
|
aBotRight.y = std::max( aBotRight.y, aTopLeft.y + aMinHeight );
|
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;
|
2020-08-19 22:26:36 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-08-29 22:59:11 +00:00
|
|
|
void POINT_EDITOR::editArcEndpointKeepCenter( DRAWSEGMENT* aArc, VECTOR2I aCenter, VECTOR2I aStart,
|
|
|
|
VECTOR2I aMid, VECTOR2I aEnd,
|
|
|
|
const VECTOR2I aCursor ) const
|
|
|
|
{
|
|
|
|
bool clockwise;
|
|
|
|
bool movingStart;
|
|
|
|
|
|
|
|
VECTOR2I *p1, *p2;
|
|
|
|
VECTOR2I target;
|
|
|
|
|
|
|
|
// p1 does not move, p2 does.
|
|
|
|
|
|
|
|
if( aStart != aArc->GetArcStart() )
|
|
|
|
{
|
|
|
|
p1 = &aEnd;
|
|
|
|
p2 = &aStart;
|
|
|
|
movingStart = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
p1 = &aStart;
|
|
|
|
p2 = &aEnd;
|
|
|
|
movingStart = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
target = *p2 - aCenter;
|
|
|
|
|
|
|
|
double sqRadius = ( *p1 - aCenter ).SquaredEuclideanNorm();
|
|
|
|
|
|
|
|
*p1 = *p1 - aCenter;
|
|
|
|
*p2 = *p2 - aCenter;
|
|
|
|
|
|
|
|
// Circle : x^2 + y^2 = R ^ 2
|
|
|
|
// In this coordinate system, the angular position of the cursor is (r, theta)
|
|
|
|
// The line coming from the center of the circle is y = start.y / start.x * x
|
|
|
|
// The intersection fulfills : x^2 = R^2 / ( 1 + ( start.y / start.x ) ^ 2 )
|
|
|
|
|
|
|
|
if( target.x == 0 )
|
|
|
|
{
|
|
|
|
p2->x = 0;
|
|
|
|
p2->y = ( target.y > 0 ) ? sqrt( sqRadius ) : -sqrt( sqRadius );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
double tan = target.y / static_cast<double>( target.x );
|
|
|
|
// The divider is always greater than 1 ( cannot be 0 )
|
|
|
|
double tmp = sqrt( sqRadius / ( 1.0 + tan * tan ) );
|
|
|
|
// Move to the correct quadrant
|
|
|
|
tmp = target.x > 0 ? tmp : -tmp;
|
|
|
|
p2->y = target.y / static_cast<double>( target.x ) * tmp;
|
|
|
|
p2->x = tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
*p1 = *p1 + aCenter;
|
|
|
|
*p2 = *p2 + aCenter;
|
|
|
|
|
|
|
|
clockwise = aArc->GetAngle() > 0;
|
|
|
|
|
|
|
|
VECTOR2D startLine = aStart - aCenter;
|
|
|
|
VECTOR2D endLine = aEnd - aCenter;
|
|
|
|
double newAngle = RAD2DECIDEG( endLine.Angle() - startLine.Angle() );
|
|
|
|
|
|
|
|
if( clockwise && newAngle < 0.0 )
|
|
|
|
newAngle += 3600.0;
|
|
|
|
else if( !clockwise && newAngle > 0.0 )
|
|
|
|
newAngle -= 3600.0;
|
|
|
|
|
|
|
|
aArc->SetAngle( newAngle );
|
|
|
|
aArc->SetCenter( wxPoint( aCenter.x, aCenter.y ) );
|
|
|
|
|
|
|
|
if( movingStart )
|
|
|
|
{
|
|
|
|
aArc->SetArcStart( wxPoint( aStart.x, aStart.y ) );
|
|
|
|
// Set angle computes the end point, so re-force it now.
|
|
|
|
aArc->SetArcEnd( wxPoint( aEnd.x, aEnd.y ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
aArc->SetArcEnd( wxPoint( aEnd.x, aEnd.y ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void POINT_EDITOR::editArcMidKeepCenter( DRAWSEGMENT* aArc, VECTOR2I aCenter, VECTOR2I aStart,
|
|
|
|
VECTOR2I aMid, VECTOR2I aEnd, const VECTOR2I aCursor ) const
|
|
|
|
{
|
|
|
|
// Now, update the edit point position
|
|
|
|
// Express the point in a cercle-centered coordinate system.
|
|
|
|
aStart = aStart - aCenter;
|
|
|
|
aEnd = aEnd - aCenter;
|
|
|
|
|
|
|
|
double sqRadius = ( aCursor - aCenter ).SquaredEuclideanNorm();
|
|
|
|
|
|
|
|
// Special case, because the tangent would lead to +/- infinity
|
|
|
|
if( aStart.x == 0 )
|
|
|
|
{
|
|
|
|
aStart.y = aCursor.y > 0 ? sqrt( sqRadius ) : -sqrt( sqRadius );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Circle : x^2 + y^2 = R ^ 2
|
|
|
|
// In this coordinate system, the angular position of the cursor is (r, theta)
|
|
|
|
// The line coming from the center of the circle is y = start.y / start.x * x
|
|
|
|
// The intersection fulfills : x^2 = R^2 / ( 1 + ( start.y / start.x ) ^ 2 )
|
|
|
|
|
|
|
|
double tan = aStart.y / static_cast<double>( aStart.x );
|
|
|
|
double tmp = sqrt( sqRadius / ( 1.0 + tan * tan ) );
|
|
|
|
// Move to the correct quadrant
|
|
|
|
tmp = aStart.x > 0 ? tmp : -tmp;
|
|
|
|
aStart.y = aStart.y / static_cast<double>( aStart.x ) * tmp;
|
|
|
|
aStart.x = tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Special case, because the tangent would lead to +/- infinity
|
|
|
|
if( aEnd.x == 0 )
|
|
|
|
{
|
|
|
|
aEnd.y = aMid.y > 0 ? sqrt( sqRadius ) : -sqrt( sqRadius );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Circle : x^2 + y^2 = R ^ 2
|
|
|
|
// In this coordinate system, the angular position of the cursor is (r, theta)
|
|
|
|
// The line coming from the center of the circle is y = start.y / start.x * x
|
|
|
|
// The intersection fulfills : x^2 = R^2 / ( 1 + ( start.y / start.x ) ^ 2 )
|
|
|
|
|
|
|
|
double tan = aEnd.y / static_cast<double>( aEnd.x );
|
|
|
|
double tmp = sqrt( sqRadius / ( 1.0 + tan * tan ) );
|
|
|
|
// Move to the correct quadrant
|
|
|
|
tmp = aEnd.x > 0 ? tmp : -tmp;
|
|
|
|
aEnd.y = aEnd.y / static_cast<double>( aEnd.x ) * tmp;
|
|
|
|
aEnd.x = tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
aStart = aStart + aCenter;
|
|
|
|
aEnd = aEnd + aCenter;
|
|
|
|
|
|
|
|
aArc->SetArcStart( wxPoint( aStart.x, aStart.y ) );
|
|
|
|
aArc->SetArcEnd( wxPoint( aEnd.x, aEnd.y ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void POINT_EDITOR::editArcMidKeepEnpoints( DRAWSEGMENT* aArc, VECTOR2I aCenter, VECTOR2I aStart,
|
|
|
|
VECTOR2I aMid, VECTOR2I aEnd, const VECTOR2I aCursor ) const
|
|
|
|
{
|
|
|
|
bool clockwise;
|
|
|
|
VECTOR2I oldCenter = aArc->GetCenter();
|
|
|
|
|
|
|
|
|
|
|
|
// This allows the user to go on the sides of the arc
|
|
|
|
aMid = aCursor;
|
|
|
|
// Find the new center
|
|
|
|
aCenter = GetArcCenter( aStart, aMid, aEnd );
|
|
|
|
|
|
|
|
aArc->SetCenter( wxPoint( aCenter.x, aCenter.y ) );
|
|
|
|
|
|
|
|
// Check if the new arc is CW or CCW
|
|
|
|
VECTOR2D startLine = aStart - aCenter;
|
|
|
|
VECTOR2D endLine = aEnd - aCenter;
|
|
|
|
double newAngle = RAD2DECIDEG( endLine.Angle() - startLine.Angle() );
|
|
|
|
VECTOR2D v1, v2;
|
|
|
|
|
|
|
|
v1 = aStart - aMid;
|
|
|
|
v2 = aEnd - aMid;
|
|
|
|
double theta = RAD2DECIDEG( v1.Angle() );
|
|
|
|
RotatePoint( &( v1.x ), &( v1.y ), theta );
|
|
|
|
RotatePoint( &( v2.x ), &( v2.y ), theta );
|
|
|
|
clockwise = ( ( v1.Angle() - v2.Angle() ) > 0 );
|
|
|
|
|
|
|
|
// Normalize the angle
|
|
|
|
if( clockwise && newAngle < 0.0 )
|
|
|
|
newAngle += 3600.0;
|
|
|
|
else if( !clockwise && newAngle > 0.0 )
|
|
|
|
newAngle -= 3600.0;
|
|
|
|
|
|
|
|
// Accuracy test
|
|
|
|
// First, get the angle
|
|
|
|
VECTOR2I endTest = aStart;
|
|
|
|
RotatePoint( &( endTest.x ), &( endTest.y ), aCenter.x, aCenter.y, -newAngle );
|
|
|
|
double distance = ( endTest - aEnd ).SquaredEuclideanNorm();
|
|
|
|
|
|
|
|
if( distance > ADVANCED_CFG::GetCfg().m_drawArcAccuracy )
|
|
|
|
{
|
|
|
|
// Cancel Everything
|
|
|
|
// If the accuracy is low, we can't draw precisely the arc.
|
|
|
|
// It may happen when the radius is *high*
|
|
|
|
aArc->SetCenter( wxPoint( oldCenter.x, oldCenter.y ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
aArc->SetAngle( newAngle );
|
|
|
|
aArc->SetArcEnd( wxPoint( aEnd.x, aEnd.y ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now, update the edit point position
|
|
|
|
// Express the point in a cercle-centered coordinate system.
|
|
|
|
aMid = aCursor - aCenter;
|
|
|
|
|
|
|
|
double sqRadius = ( aEnd - aCenter ).SquaredEuclideanNorm();
|
|
|
|
|
|
|
|
// Special case, because the tangent would lead to +/- infinity
|
|
|
|
if( aMid.x == 0 )
|
|
|
|
{
|
|
|
|
aMid.y = aMid.y > 0 ? sqrt( sqRadius ) : -sqrt( sqRadius );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Circle : x^2 + y^2 = R ^ 2
|
|
|
|
// In this coordinate system, the angular position of the cursor is (r, theta)
|
|
|
|
// The line coming from the center of the circle is y = start.y / start.x * x
|
|
|
|
// The intersection fulfills : x^2 = R^2 / ( 1 + ( start.y / start.x ) ^ 2 )
|
|
|
|
|
|
|
|
double tan = aMid.y / static_cast<double>( aMid.x );
|
|
|
|
double tmp = sqrt( sqRadius / ( 1.0 + tan * tan ) );
|
|
|
|
// Move to the correct quadrant
|
|
|
|
tmp = aMid.x > 0 ? tmp : -tmp;
|
|
|
|
aMid.y = aMid.y / static_cast<double>( aMid.x ) * tmp;
|
|
|
|
aMid.x = tmp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-14 19:21:10 +00:00
|
|
|
void POINT_EDITOR::updateItem() const
|
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
|
|
|
|
2019-10-31 23:25:50 +00:00
|
|
|
const BOARD_DESIGN_SETTINGS& boardSettings = board()->GetDesignSettings();
|
|
|
|
|
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
|
|
|
{
|
|
|
|
case PCB_LINE_T:
|
2014-07-09 11:50:27 +00:00
|
|
|
case PCB_MODULE_EDGE_T:
|
2014-02-27 16:29:08 +00:00
|
|
|
{
|
2014-02-28 15:53:28 +00:00
|
|
|
DRAWSEGMENT* segment = static_cast<DRAWSEGMENT*>( item );
|
2020-06-28 22:34:10 +00:00
|
|
|
|
2014-02-27 16:29:08 +00:00
|
|
|
switch( segment->GetShape() )
|
|
|
|
{
|
|
|
|
case S_SEGMENT:
|
2014-04-01 15:41:24 +00:00
|
|
|
if( isModified( m_editPoints->Point( SEG_START ) ) )
|
|
|
|
segment->SetStart( wxPoint( m_editPoints->Point( SEG_START ).GetPosition().x,
|
|
|
|
m_editPoints->Point( SEG_START ).GetPosition().y ) );
|
2014-02-28 17:24:13 +00:00
|
|
|
|
2014-04-01 15:41:24 +00:00
|
|
|
else if( isModified( m_editPoints->Point( SEG_END ) ) )
|
|
|
|
segment->SetEnd( wxPoint( m_editPoints->Point( SEG_END ).GetPosition().x,
|
|
|
|
m_editPoints->Point( SEG_END ).GetPosition().y ) );
|
2014-02-27 16:29:08 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
2020-06-15 19:50:20 +00:00
|
|
|
case S_RECT:
|
|
|
|
{
|
|
|
|
if( isModified( m_editPoints->Point( RECT_TOP_LEFT ) ) )
|
|
|
|
{
|
|
|
|
segment->SetStart( (wxPoint) m_editPoints->Point( RECT_TOP_LEFT ).GetPosition() );
|
|
|
|
}
|
|
|
|
else if( isModified( m_editPoints->Point( RECT_TOP_RIGHT ) ) )
|
|
|
|
{
|
|
|
|
segment->SetStartY( m_editPoints->Point( RECT_TOP_RIGHT ).GetPosition().y );
|
|
|
|
segment->SetEndX( m_editPoints->Point( RECT_TOP_RIGHT ).GetPosition().x );
|
|
|
|
}
|
|
|
|
else if( isModified( m_editPoints->Point( RECT_BOT_RIGHT ) ) )
|
|
|
|
{
|
|
|
|
segment->SetEnd( (wxPoint) m_editPoints->Point( RECT_BOT_RIGHT ).GetPosition() );
|
|
|
|
}
|
|
|
|
else if( isModified( m_editPoints->Point( RECT_BOT_LEFT ) ) )
|
|
|
|
{
|
|
|
|
segment->SetStartX( m_editPoints->Point( RECT_BOT_LEFT ).GetPosition().x );
|
|
|
|
segment->SetEndY( m_editPoints->Point( RECT_BOT_LEFT ).GetPosition().y );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2014-02-27 16:29:08 +00:00
|
|
|
case S_ARC:
|
|
|
|
{
|
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
|
|
|
const VECTOR2I& cursorPos = getViewControls()->GetCursorPosition();
|
|
|
|
|
|
|
|
if( isModified( m_editPoints->Point( ARC_CENTER ) ) )
|
2014-02-27 16:29:08 +00:00
|
|
|
{
|
|
|
|
wxPoint moveVector = wxPoint( center.x, center.y ) - segment->GetCenter();
|
|
|
|
segment->Move( moveVector );
|
|
|
|
}
|
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-08-29 22:59:11 +00:00
|
|
|
if( m_altEditMethod )
|
2018-12-08 15:26:47 +00:00
|
|
|
{
|
2020-08-29 22:59:11 +00:00
|
|
|
editArcMidKeepCenter( segment, center, start, mid, end, cursorPos );
|
2020-08-09 23:03:31 +00:00
|
|
|
}
|
2020-08-29 22:59:11 +00:00
|
|
|
else
|
2020-08-09 23:03:31 +00:00
|
|
|
{
|
2020-08-29 22:59:11 +00:00
|
|
|
editArcMidKeepEnpoints( segment, center, start, mid, end, cursorPos );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( isModified( m_editPoints->Point( ARC_START ) )
|
|
|
|
|| isModified( m_editPoints->Point( ARC_END ) ) )
|
|
|
|
{
|
|
|
|
if( m_altEditMethod )
|
|
|
|
{
|
|
|
|
editArcEndpointKeepCenter( segment, center, start, mid, end, cursorPos );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
editArcEndpointKeepTangent( segment, center, start, mid, end, cursorPos );
|
2020-08-09 23:03:31 +00:00
|
|
|
}
|
2014-02-27 16:29:08 +00:00
|
|
|
}
|
2014-02-28 17:24:13 +00:00
|
|
|
}
|
2020-06-15 19:50:20 +00:00
|
|
|
break;
|
2014-02-28 17:24:13 +00:00
|
|
|
|
|
|
|
case S_CIRCLE:
|
|
|
|
{
|
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
|
|
|
{
|
|
|
|
wxPoint moveVector = wxPoint( center.x, center.y ) - segment->GetCenter();
|
|
|
|
segment->Move( moveVector );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
segment->SetEnd( wxPoint( end.x, end.y ) );
|
|
|
|
}
|
2014-02-27 16:29:08 +00:00
|
|
|
}
|
2020-06-15 19:50:20 +00:00
|
|
|
break;
|
2014-02-27 16:29:08 +00:00
|
|
|
|
2017-10-19 21:14:01 +00:00
|
|
|
case S_POLYGON:
|
|
|
|
{
|
2018-02-22 11:28:01 +00:00
|
|
|
SHAPE_POLY_SET& outline = segment->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 ) ) )
|
|
|
|
m_editPoints->Line( i ).SetConstraint( new EC_PERPLINE( m_editPoints->Line( i ) ) );
|
|
|
|
}
|
|
|
|
|
2018-03-02 09:55:59 +00:00
|
|
|
validatePolygon( outline );
|
2017-10-19 21:14:01 +00:00
|
|
|
}
|
2020-06-15 19:50:20 +00:00
|
|
|
break;
|
2017-10-19 21:14:01 +00:00
|
|
|
|
2018-07-22 12:50:35 +00:00
|
|
|
case S_CURVE:
|
|
|
|
if( isModified( m_editPoints->Point( BEZIER_CURVE_START ) ) )
|
|
|
|
segment->SetStart( wxPoint( m_editPoints->Point( BEZIER_CURVE_START ).GetPosition().x,
|
|
|
|
m_editPoints->Point( BEZIER_CURVE_START ).GetPosition().y ) );
|
|
|
|
else if( isModified( m_editPoints->Point( BEZIER_CURVE_CONTROL_POINT1 ) ) )
|
|
|
|
segment->SetBezControl1( wxPoint( m_editPoints->Point( BEZIER_CURVE_CONTROL_POINT1 ).GetPosition().x,
|
|
|
|
m_editPoints->Point( BEZIER_CURVE_CONTROL_POINT1 ).GetPosition().y ) );
|
|
|
|
else if( isModified( m_editPoints->Point( BEZIER_CURVE_CONTROL_POINT2 ) ) )
|
|
|
|
segment->SetBezControl2( wxPoint( m_editPoints->Point( BEZIER_CURVE_CONTROL_POINT2 ).GetPosition().x,
|
|
|
|
m_editPoints->Point( BEZIER_CURVE_CONTROL_POINT2 ).GetPosition().y ) );
|
|
|
|
else if( isModified( m_editPoints->Point( BEZIER_CURVE_END ) ) )
|
|
|
|
segment->SetEnd( wxPoint( m_editPoints->Point( BEZIER_CURVE_END ).GetPosition().x,
|
|
|
|
m_editPoints->Point( BEZIER_CURVE_END ).GetPosition().y ) );
|
|
|
|
|
|
|
|
segment->RebuildBezierToSegmentsPointsList( segment->GetWidth() );
|
|
|
|
break;
|
|
|
|
|
2014-02-27 16:29:08 +00:00
|
|
|
default: // suppress warnings
|
|
|
|
break;
|
|
|
|
}
|
2014-02-28 17:24:29 +00:00
|
|
|
|
2014-07-09 11:50:27 +00:00
|
|
|
// Update relative coordinates for module edges
|
|
|
|
if( EDGE_MODULE* edge = dyn_cast<EDGE_MODULE*>( item ) )
|
|
|
|
edge->SetLocalCoord();
|
|
|
|
|
2014-02-28 17:24:29 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-06-28 22:34:10 +00:00
|
|
|
case PCB_PAD_T:
|
|
|
|
{
|
|
|
|
D_PAD* pad = static_cast<D_PAD*>( item );
|
|
|
|
|
|
|
|
switch( pad->GetShape() )
|
|
|
|
{
|
|
|
|
case PAD_SHAPE_CIRCLE:
|
|
|
|
{
|
|
|
|
wxPoint center = (wxPoint) m_editPoints->Point( CIRC_CENTER ).GetPosition();
|
|
|
|
wxPoint end = (wxPoint) m_editPoints->Point( CIRC_END ).GetPosition();
|
|
|
|
|
|
|
|
if( isModified( m_editPoints->Point( CIRC_CENTER ) ) )
|
|
|
|
{
|
|
|
|
wxPoint moveVector = center - pad->ShapePos();
|
|
|
|
pad->SetOffset( pad->GetOffset() + moveVector );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int diameter = (int) EuclideanNorm( end - center ) * 2;
|
|
|
|
pad->SetSize( wxSize( diameter, diameter ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PAD_SHAPE_OVAL:
|
|
|
|
case PAD_SHAPE_TRAPEZOID:
|
|
|
|
case PAD_SHAPE_RECT:
|
|
|
|
case PAD_SHAPE_ROUNDRECT:
|
|
|
|
case PAD_SHAPE_CHAMFERED_RECT:
|
|
|
|
{
|
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();
|
|
|
|
|
2020-08-22 19:27:17 +00:00
|
|
|
pinEditedCorner( getEditedPointIndex(), Mils2iu( 1 ), Mils2iu( 1 ), topLeft, topRight,
|
|
|
|
botLeft, botRight,pad->GetPosition(), pad->GetDrillSize() );
|
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
|
|
|
|
|
|
|
|
wxPoint center = pad->GetPosition();
|
|
|
|
int dist[4];
|
|
|
|
|
|
|
|
if( isModified( m_editPoints->Point( RECT_TOP_LEFT ) )
|
|
|
|
|| isModified( m_editPoints->Point( RECT_BOT_RIGHT ) ) )
|
|
|
|
{
|
2020-08-29 22:59:11 +00:00
|
|
|
dist[0] = center.x - m_editPoints->Point( RECT_TOP_LEFT ).GetPosition().x;
|
|
|
|
dist[1] = center.y - m_editPoints->Point( RECT_TOP_LEFT ).GetPosition().y;
|
|
|
|
dist[2] = m_editPoints->Point( RECT_BOT_RIGHT ).GetPosition().x - center.x;
|
|
|
|
dist[3] = m_editPoints->Point( RECT_BOT_RIGHT ).GetPosition().y - center.y;
|
2020-06-29 22:25:13 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-08-29 22:59:11 +00:00
|
|
|
dist[0] = center.x - m_editPoints->Point( RECT_BOT_LEFT ).GetPosition().x;
|
|
|
|
dist[1] = center.y - m_editPoints->Point( RECT_TOP_RIGHT ).GetPosition().y;
|
|
|
|
dist[2] = m_editPoints->Point( RECT_TOP_RIGHT ).GetPosition().x - center.x;
|
|
|
|
dist[3] = m_editPoints->Point( RECT_BOT_LEFT ).GetPosition().y - center.y;
|
2020-06-29 22:25:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
wxSize padSize( dist[0] + dist[2], dist[1] + dist[3] );
|
2020-06-29 18:14:51 +00:00
|
|
|
wxPoint deltaOffset( padSize.x / 2 - dist[2], padSize.y / 2 - dist[3] );
|
2020-06-28 22:34:10 +00:00
|
|
|
|
2020-06-29 18:14:51 +00:00
|
|
|
if( pad->GetOrientation() == 900 || pad->GetOrientation() == 2700 )
|
|
|
|
std::swap( padSize.x, padSize.y );
|
|
|
|
|
|
|
|
RotatePoint( &deltaOffset, -pad->GetOrientation() );
|
|
|
|
|
|
|
|
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 ) ) )
|
|
|
|
{
|
2020-08-29 22:59:11 +00:00
|
|
|
left = m_editPoints->Point( RECT_TOP_LEFT ).GetPosition().x;
|
|
|
|
top = m_editPoints->Point( RECT_TOP_LEFT ).GetPosition().y;
|
|
|
|
right = m_editPoints->Point( RECT_BOT_RIGHT ).GetPosition().x;
|
|
|
|
bottom = m_editPoints->Point( RECT_BOT_RIGHT ).GetPosition().y;
|
2020-06-29 22:25:13 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-08-29 22:59:11 +00:00
|
|
|
left = m_editPoints->Point( RECT_BOT_LEFT ).GetPosition().x;
|
|
|
|
top = m_editPoints->Point( RECT_TOP_RIGHT ).GetPosition().y;
|
|
|
|
right = m_editPoints->Point( RECT_TOP_RIGHT ).GetPosition().x;
|
|
|
|
bottom = m_editPoints->Point( RECT_BOT_LEFT ).GetPosition().y;
|
2020-06-29 22:25:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
wxSize padSize( abs( right - left ), abs( bottom - top ) );
|
|
|
|
|
2020-06-29 18:14:51 +00:00
|
|
|
if( pad->GetOrientation() == 900 || pad->GetOrientation() == 2700 )
|
|
|
|
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 );
|
2020-06-29 22:25:13 +00:00
|
|
|
pad->SetPosition( wxPoint( ( left + right ) / 2, ( top + bottom ) / 2 ) );
|
2020-06-29 18:14:51 +00:00
|
|
|
}
|
2020-06-28 22:34:10 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: // suppress warnings
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2019-10-26 15:49:29 +00:00
|
|
|
case PCB_MODULE_ZONE_AREA_T:
|
2014-02-28 17:24:29 +00:00
|
|
|
case PCB_ZONE_AREA_T:
|
|
|
|
{
|
|
|
|
ZONE_CONTAINER* zone = static_cast<ZONE_CONTAINER*>( item );
|
2014-03-14 15:05:30 +00:00
|
|
|
zone->ClearFilledPolysList();
|
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() );
|
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();
|
2014-02-27 16:29:08 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-03-12 09:46:11 +00:00
|
|
|
case PCB_DIMENSION_T:
|
|
|
|
{
|
|
|
|
DIMENSION* dimension = static_cast<DIMENSION*>( item );
|
|
|
|
|
|
|
|
// Check which point is currently modified and updated dimension's points respectively
|
2014-04-01 15:41:24 +00:00
|
|
|
if( isModified( m_editPoints->Point( DIM_CROSSBARO ) ) )
|
2014-03-12 09:46:11 +00:00
|
|
|
{
|
2015-06-19 15:32:33 +00:00
|
|
|
VECTOR2D featureLine( m_editedPoint->GetPosition() - dimension->GetOrigin() );
|
2014-03-12 09:46:11 +00:00
|
|
|
VECTOR2D crossBar( dimension->GetEnd() - dimension->GetOrigin() );
|
|
|
|
|
|
|
|
if( featureLine.Cross( crossBar ) > 0 )
|
2019-10-31 23:25:50 +00:00
|
|
|
dimension->SetHeight( -featureLine.EuclideanNorm(), boardSettings.m_DimensionPrecision );
|
2014-03-12 09:46:11 +00:00
|
|
|
else
|
2019-10-31 23:25:50 +00:00
|
|
|
dimension->SetHeight( featureLine.EuclideanNorm(), boardSettings.m_DimensionPrecision );
|
2014-03-12 09:46:11 +00:00
|
|
|
}
|
2014-03-12 09:53:42 +00:00
|
|
|
|
2014-04-01 15:41:24 +00:00
|
|
|
else if( isModified( m_editPoints->Point( DIM_CROSSBARF ) ) )
|
2014-03-12 09:46:11 +00:00
|
|
|
{
|
2015-06-19 15:32:33 +00:00
|
|
|
VECTOR2D featureLine( m_editedPoint->GetPosition() - dimension->GetEnd() );
|
2014-03-12 09:46:11 +00:00
|
|
|
VECTOR2D crossBar( dimension->GetEnd() - dimension->GetOrigin() );
|
|
|
|
|
|
|
|
if( featureLine.Cross( crossBar ) > 0 )
|
2019-10-31 23:25:50 +00:00
|
|
|
dimension->SetHeight( -featureLine.EuclideanNorm(), boardSettings.m_DimensionPrecision );
|
2014-03-12 09:46:11 +00:00
|
|
|
else
|
2019-10-31 23:25:50 +00:00
|
|
|
dimension->SetHeight( featureLine.EuclideanNorm(), boardSettings.m_DimensionPrecision );
|
2014-03-12 09:46:11 +00:00
|
|
|
}
|
|
|
|
|
2014-04-01 15:41:24 +00:00
|
|
|
else if( isModified( m_editPoints->Point( DIM_FEATUREGO ) ) )
|
2014-03-12 09:53:42 +00:00
|
|
|
{
|
2019-10-31 23:25:50 +00:00
|
|
|
dimension->SetOrigin( wxPoint( m_editedPoint->GetPosition().x, m_editedPoint->GetPosition().y ),
|
|
|
|
boardSettings.m_DimensionPrecision );
|
2014-04-01 15:41:24 +00:00
|
|
|
m_editPoints->Point( DIM_CROSSBARO ).SetConstraint( new EC_LINE( m_editPoints->Point( DIM_CROSSBARO ),
|
|
|
|
m_editPoints->Point( DIM_FEATUREGO ) ) );
|
|
|
|
m_editPoints->Point( DIM_CROSSBARF ).SetConstraint( new EC_LINE( m_editPoints->Point( DIM_CROSSBARF ),
|
|
|
|
m_editPoints->Point( DIM_FEATUREDO ) ) );
|
2014-03-12 09:53:42 +00:00
|
|
|
}
|
|
|
|
|
2014-04-01 15:41:24 +00:00
|
|
|
else if( isModified( m_editPoints->Point( DIM_FEATUREDO ) ) )
|
2014-03-12 09:53:42 +00:00
|
|
|
{
|
2019-10-31 23:25:50 +00:00
|
|
|
dimension->SetEnd( wxPoint( m_editedPoint->GetPosition().x, m_editedPoint->GetPosition().y ) ,
|
|
|
|
boardSettings.m_DimensionPrecision );
|
2014-04-01 15:41:24 +00:00
|
|
|
m_editPoints->Point( DIM_CROSSBARO ).SetConstraint( new EC_LINE( m_editPoints->Point( DIM_CROSSBARO ),
|
|
|
|
m_editPoints->Point( DIM_FEATUREGO ) ) );
|
|
|
|
m_editPoints->Point( DIM_CROSSBARF ).SetConstraint( new EC_LINE( m_editPoints->Point( DIM_CROSSBARF ),
|
|
|
|
m_editPoints->Point( DIM_FEATUREDO ) ) );
|
2014-03-12 09:53:42 +00:00
|
|
|
}
|
|
|
|
|
2014-03-12 09:46:11 +00:00
|
|
|
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 );
|
2014-02-27 16:29:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-14 19:21:10 +00:00
|
|
|
void POINT_EDITOR::finishItem()
|
2014-03-06 10:49:08 +00:00
|
|
|
{
|
2017-11-30 16:21:51 +00:00
|
|
|
auto item = m_editPoints->GetParent();
|
2018-02-22 11:28:01 +00:00
|
|
|
|
2017-05-16 09:38:00 +00:00
|
|
|
if( !item )
|
|
|
|
return;
|
|
|
|
|
2019-10-26 15:49:29 +00:00
|
|
|
if( item->Type() == PCB_ZONE_AREA_T || item->Type() == PCB_MODULE_ZONE_AREA_T )
|
2014-03-06 10:49:08 +00:00
|
|
|
{
|
2017-11-30 16:21:51 +00:00
|
|
|
auto zone = static_cast<ZONE_CONTAINER*>( item );
|
2014-03-06 10:49:08 +00:00
|
|
|
|
2019-03-14 13:35:55 +00:00
|
|
|
if( zone->IsFilled() && m_refill && zone->NeedRefill() )
|
2019-06-29 19:14:43 +00:00
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::zoneFill, true, zone );
|
2014-03-06 10:49:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-07-14 12:46:59 +00:00
|
|
|
bool POINT_EDITOR::validatePolygon( SHAPE_POLY_SET& aPoly ) const
|
2018-02-22 11:28:01 +00:00
|
|
|
{
|
2019-07-14 12:46:59 +00:00
|
|
|
bool valid = !aPoly.IsSelfIntersecting();
|
2018-02-22 11:28:01 +00:00
|
|
|
|
|
|
|
if( m_statusPopup )
|
|
|
|
{
|
2019-07-14 12:46:59 +00:00
|
|
|
if( valid )
|
|
|
|
{
|
|
|
|
m_statusPopup->Hide();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wxPoint p = wxGetMousePosition() + wxPoint( 20, 20 );
|
|
|
|
m_statusPopup->Move( p );
|
|
|
|
m_statusPopup->PopupFor( 1500 );
|
|
|
|
}
|
2018-02-22 11:28:01 +00:00
|
|
|
}
|
|
|
|
|
2019-07-14 12:46:59 +00:00
|
|
|
return valid;
|
2018-02-22 11:28:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-14 19:21:10 +00:00
|
|
|
void 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;
|
|
|
|
|
2014-02-28 15:53:28 +00:00
|
|
|
switch( item->Type() )
|
2014-02-27 16:29:08 +00:00
|
|
|
{
|
|
|
|
case PCB_LINE_T:
|
2014-07-09 11:50:27 +00:00
|
|
|
case PCB_MODULE_EDGE_T:
|
2014-02-27 16:29:08 +00:00
|
|
|
{
|
2014-02-28 15:53:28 +00:00
|
|
|
const DRAWSEGMENT* segment = static_cast<const DRAWSEGMENT*>( item );
|
2017-12-18 13:07:17 +00:00
|
|
|
|
|
|
|
switch( segment->GetShape() )
|
2014-02-27 16:29:08 +00:00
|
|
|
{
|
2017-12-18 13:07:17 +00:00
|
|
|
case S_SEGMENT:
|
|
|
|
m_editPoints->Point( SEG_START ).SetPosition( segment->GetStart() );
|
|
|
|
m_editPoints->Point( SEG_END ).SetPosition( segment->GetEnd() );
|
|
|
|
break;
|
2014-02-27 16:29:08 +00:00
|
|
|
|
2020-06-15 19:50:20 +00:00
|
|
|
case S_RECT:
|
|
|
|
m_editPoints->Point( RECT_TOP_LEFT ).SetPosition( segment->GetStart() );
|
|
|
|
m_editPoints->Point( RECT_TOP_RIGHT ).SetPosition( segment->GetEnd().x,
|
|
|
|
segment->GetStart().y );
|
|
|
|
m_editPoints->Point( RECT_BOT_RIGHT ).SetPosition( segment->GetEnd() );
|
|
|
|
m_editPoints->Point( RECT_BOT_LEFT ).SetPosition( segment->GetStart().x,
|
|
|
|
segment->GetEnd().y );
|
|
|
|
break;
|
|
|
|
|
2017-12-18 13:07:17 +00:00
|
|
|
case S_ARC:
|
|
|
|
m_editPoints->Point( ARC_CENTER ).SetPosition( segment->GetCenter() );
|
2018-12-08 15:26:47 +00:00
|
|
|
m_editPoints->Point( ARC_START ).SetPosition( segment->GetArcStart() );
|
|
|
|
m_editPoints->Point( ARC_MID ).SetPosition( segment->GetArcMid() );
|
2017-12-18 13:07:17 +00:00
|
|
|
m_editPoints->Point( ARC_END ).SetPosition( segment->GetArcEnd() );
|
|
|
|
break;
|
2014-02-27 16:29:08 +00:00
|
|
|
|
2017-12-18 13:07:17 +00:00
|
|
|
case S_CIRCLE:
|
|
|
|
m_editPoints->Point( CIRC_CENTER ).SetPosition( segment->GetCenter() );
|
|
|
|
m_editPoints->Point( CIRC_END ).SetPosition( segment->GetEnd() );
|
|
|
|
break;
|
2014-02-28 17:24:13 +00:00
|
|
|
|
2017-12-18 13:07:17 +00:00
|
|
|
case S_POLYGON:
|
|
|
|
{
|
2018-01-24 13:22:43 +00:00
|
|
|
const auto& points = segment->BuildPolyPointsList();
|
2018-09-15 16:51:35 +00:00
|
|
|
|
|
|
|
if( m_editPoints->PointsSize() != (unsigned) points.size() )
|
|
|
|
{
|
|
|
|
getView()->Remove( m_editPoints.get() );
|
|
|
|
m_editedPoint = nullptr;
|
|
|
|
m_editPoints = EDIT_POINTS_FACTORY::Make( item, getView()->GetGAL() );
|
|
|
|
getView()->Add( m_editPoints.get() );
|
|
|
|
}
|
|
|
|
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
|
|
|
}
|
2017-12-18 13:07:17 +00:00
|
|
|
break;
|
|
|
|
}
|
2014-02-28 17:24:29 +00:00
|
|
|
|
2018-07-22 12:50:35 +00:00
|
|
|
case S_CURVE:
|
|
|
|
m_editPoints->Point( BEZIER_CURVE_START ).SetPosition( segment->GetStart() );
|
|
|
|
m_editPoints->Point( BEZIER_CURVE_CONTROL_POINT1 ).SetPosition( segment->GetBezControl1() );
|
|
|
|
m_editPoints->Point( BEZIER_CURVE_CONTROL_POINT2 ).SetPosition( segment->GetBezControl2() );
|
|
|
|
m_editPoints->Point( BEZIER_CURVE_END ).SetPosition( segment->GetEnd() );
|
|
|
|
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:
|
|
|
|
{
|
|
|
|
const D_PAD* pad = static_cast<const D_PAD*>( item );
|
2020-06-29 18:14:51 +00:00
|
|
|
bool locked = pad->GetParent() && pad->GetParent()->PadsLocked();
|
2020-06-28 22:34:10 +00:00
|
|
|
wxPoint shapePos = pad->ShapePos();
|
|
|
|
wxPoint halfSize( pad->GetSize().x / 2, pad->GetSize().y / 2 );
|
|
|
|
|
|
|
|
switch( pad->GetShape() )
|
|
|
|
{
|
|
|
|
case PAD_SHAPE_CIRCLE:
|
|
|
|
{
|
2020-06-29 18:14:51 +00:00
|
|
|
int target = locked ? 0 : 2;
|
|
|
|
|
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;
|
|
|
|
m_editPoints = EDIT_POINTS_FACTORY::Make( item, getView()->GetGAL() );
|
|
|
|
getView()->Add( m_editPoints.get() );
|
|
|
|
}
|
2020-06-29 18:14:51 +00:00
|
|
|
else if( target == 2 )
|
2020-06-28 22:34:10 +00:00
|
|
|
{
|
|
|
|
VECTOR2I vec = m_editPoints->Point( CIRC_END ).GetPosition()
|
|
|
|
- m_editPoints->Point( CIRC_CENTER ).GetPosition();
|
|
|
|
vec.Resize( halfSize.x );
|
|
|
|
|
|
|
|
m_editPoints->Point( CIRC_CENTER ).SetPosition( shapePos );
|
|
|
|
m_editPoints->Point( CIRC_END ).SetPosition( vec + shapePos );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PAD_SHAPE_OVAL:
|
|
|
|
case PAD_SHAPE_TRAPEZOID:
|
|
|
|
case PAD_SHAPE_RECT:
|
|
|
|
case PAD_SHAPE_ROUNDRECT:
|
|
|
|
case PAD_SHAPE_CHAMFERED_RECT:
|
|
|
|
{
|
|
|
|
// Careful; pad shape and orientation are mutable...
|
2020-06-29 18:14:51 +00:00
|
|
|
int target = locked || (int) pad->GetOrientation() % 900 > 0 ? 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;
|
|
|
|
m_editPoints = EDIT_POINTS_FACTORY::Make( item, getView()->GetGAL() );
|
|
|
|
getView()->Add( m_editPoints.get() );
|
|
|
|
}
|
|
|
|
else if( target == 4 )
|
|
|
|
{
|
|
|
|
if( pad->GetOrientation() == 900 || pad->GetOrientation() == 2700 )
|
|
|
|
std::swap( halfSize.x, halfSize.y );
|
|
|
|
|
|
|
|
m_editPoints->Point( RECT_TOP_LEFT ).SetPosition( shapePos - halfSize );
|
|
|
|
m_editPoints->Point( RECT_TOP_RIGHT ).SetPosition( wxPoint( shapePos.x + halfSize.x,
|
|
|
|
shapePos.y - halfSize.y ) );
|
|
|
|
m_editPoints->Point( RECT_BOT_RIGHT ).SetPosition( shapePos + halfSize );
|
|
|
|
m_editPoints->Point( RECT_BOT_LEFT ).SetPosition( wxPoint( shapePos.x - halfSize.x,
|
|
|
|
shapePos.y + halfSize.y ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: // suppress warnings
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2019-10-26 15:49:29 +00:00
|
|
|
case PCB_MODULE_ZONE_AREA_T:
|
2014-02-28 17:24:29 +00:00
|
|
|
case PCB_ZONE_AREA_T:
|
|
|
|
{
|
2019-03-14 13:35:55 +00:00
|
|
|
ZONE_CONTAINER* zone = static_cast<ZONE_CONTAINER*>( 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;
|
2014-07-09 14:50:31 +00:00
|
|
|
m_editPoints = EDIT_POINTS_FACTORY::Make( item, getView()->GetGAL() );
|
|
|
|
getView()->Add( m_editPoints.get() );
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2014-03-12 09:46:11 +00:00
|
|
|
case PCB_DIMENSION_T:
|
|
|
|
{
|
|
|
|
const DIMENSION* dimension = static_cast<const DIMENSION*>( item );
|
|
|
|
|
2014-04-01 15:41:24 +00:00
|
|
|
m_editPoints->Point( DIM_CROSSBARO ).SetPosition( dimension->m_crossBarO );
|
|
|
|
m_editPoints->Point( DIM_CROSSBARF ).SetPosition( dimension->m_crossBarF );
|
|
|
|
m_editPoints->Point( DIM_FEATUREGO ).SetPosition( dimension->m_featureLineGO );
|
|
|
|
m_editPoints->Point( DIM_FEATUREDO ).SetPosition( dimension->m_featureLineDO );
|
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
|
|
|
|
|
|
|
|
2019-05-14 19:21:10 +00:00
|
|
|
void POINT_EDITOR::setEditedPoint( EDIT_POINT* aPoint )
|
2015-06-19 15:32:33 +00:00
|
|
|
{
|
|
|
|
KIGFX::VIEW_CONTROLS* controls = getViewControls();
|
|
|
|
|
|
|
|
if( aPoint )
|
|
|
|
{
|
2019-06-29 13:39:46 +00:00
|
|
|
frame()->GetCanvas()->SetCurrentCursor( wxCURSOR_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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-14 19:21:10 +00:00
|
|
|
void POINT_EDITOR::setAltConstraint( bool aEnabled )
|
2014-03-14 14:37:55 +00:00
|
|
|
{
|
|
|
|
if( aEnabled )
|
|
|
|
{
|
2015-06-19 15:32:33 +00:00
|
|
|
EDIT_LINE* line = dynamic_cast<EDIT_LINE*>( m_editedPoint );
|
2020-08-27 17:31:53 +00:00
|
|
|
bool isPoly = false;
|
|
|
|
|
|
|
|
if( m_editPoints->GetParent()->Type() == PCB_ZONE_AREA_T
|
|
|
|
|| m_editPoints->GetParent()->Type() == PCB_MODULE_ZONE_AREA_T )
|
|
|
|
isPoly = true;
|
|
|
|
|
|
|
|
else if( m_editPoints->GetParent()->Type() == PCB_LINE_T
|
|
|
|
|| m_editPoints->GetParent()->Type() == PCB_MODULE_EDGE_T )
|
|
|
|
{
|
|
|
|
DRAWSEGMENT* seg = static_cast<DRAWSEGMENT*>( m_editPoints->GetParent() );
|
|
|
|
isPoly = seg->GetShape() == S_POLYGON;
|
|
|
|
}
|
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
|
|
|
{
|
2018-06-02 22:51:03 +00:00
|
|
|
m_altConstraint.reset( (EDIT_CONSTRAINT<EDIT_POINT>*)( new EC_CONVERGING( *line, *m_editPoints ) ) );
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-14 19:21:10 +00:00
|
|
|
EDIT_POINT 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() )
|
|
|
|
{
|
|
|
|
case PCB_LINE_T:
|
2014-07-09 11:50:27 +00:00
|
|
|
case PCB_MODULE_EDGE_T:
|
2014-03-06 16:34:04 +00:00
|
|
|
{
|
|
|
|
const DRAWSEGMENT* segment = static_cast<const DRAWSEGMENT*>( item );
|
|
|
|
{
|
|
|
|
switch( segment->GetShape() )
|
|
|
|
{
|
|
|
|
case S_SEGMENT:
|
2015-06-19 15:32:33 +00:00
|
|
|
return *( m_editPoints->Next( *m_editedPoint ) ); // select the other end of line
|
2014-03-06 16:34:04 +00:00
|
|
|
|
|
|
|
case S_ARC:
|
|
|
|
case S_CIRCLE:
|
2014-04-01 15:41:24 +00:00
|
|
|
return m_editPoints->Point( CIRC_CENTER );
|
2014-03-06 16:34:04 +00:00
|
|
|
|
|
|
|
default: // suppress warnings
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-03-13 10:48:19 +00:00
|
|
|
|
|
|
|
break;
|
2014-03-06 16:34:04 +00:00
|
|
|
}
|
2014-03-13 10:48:19 +00:00
|
|
|
|
|
|
|
case PCB_DIMENSION_T:
|
2014-03-12 09:46:11 +00:00
|
|
|
{
|
|
|
|
// Constraint for crossbar
|
2014-04-01 15:41:24 +00:00
|
|
|
if( isModified( m_editPoints->Point( DIM_FEATUREGO ) ) )
|
|
|
|
return m_editPoints->Point( DIM_FEATUREDO );
|
2014-03-12 09:53:42 +00:00
|
|
|
|
2014-04-01 15:41:24 +00:00
|
|
|
else if( isModified( m_editPoints->Point( DIM_FEATUREDO ) ) )
|
|
|
|
return m_editPoints->Point( DIM_FEATUREGO );
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
2019-05-14 19:21:10 +00:00
|
|
|
bool 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
|
2019-10-26 15:49:29 +00:00
|
|
|
return type == PCB_ZONE_AREA_T || type == PCB_MODULE_ZONE_AREA_T ||
|
2018-07-24 15:15:05 +00:00
|
|
|
( ( type == PCB_LINE_T || type == PCB_MODULE_EDGE_T ) &&
|
2018-09-15 16:51:35 +00:00
|
|
|
( static_cast<const DRAWSEGMENT&>( aItem ).GetShape() == S_SEGMENT ||
|
|
|
|
static_cast<const DRAWSEGMENT&>( aItem ).GetShape() == S_POLYGON ) );
|
2018-07-24 15:15:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-14 19:21:10 +00:00
|
|
|
bool 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() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-14 19:21:10 +00:00
|
|
|
bool 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;
|
|
|
|
|
|
|
|
EDA_ITEM* item = m_editPoints->GetParent();
|
|
|
|
|
2019-10-26 15:49:29 +00:00
|
|
|
if( !item || !( item->Type() == PCB_ZONE_AREA_T || item->Type() == PCB_MODULE_ZONE_AREA_T ||
|
2018-12-09 16:14:45 +00:00
|
|
|
( ( item->Type() == PCB_MODULE_EDGE_T || item->Type() == PCB_LINE_T ) &&
|
2018-09-16 17:20:53 +00:00
|
|
|
static_cast<DRAWSEGMENT*>( item )->GetShape() == S_POLYGON ) ) )
|
2017-01-18 08:04:11 +00:00
|
|
|
return false;
|
|
|
|
|
2018-09-16 17:20:53 +00:00
|
|
|
SHAPE_POLY_SET *polyset;
|
|
|
|
|
2019-10-26 15:49:29 +00:00
|
|
|
if( item->Type() == PCB_ZONE_AREA_T || item->Type() == PCB_MODULE_ZONE_AREA_T )
|
2018-09-16 17:20:53 +00:00
|
|
|
polyset = static_cast<ZONE_CONTAINER*>( item )->Outline();
|
|
|
|
else
|
|
|
|
polyset = &static_cast<DRAWSEGMENT*>( item )->GetPolyShape();
|
|
|
|
|
|
|
|
auto vertex = findVertex( *polyset, *m_editedPoint );
|
2017-12-06 14:51:47 +00:00
|
|
|
|
|
|
|
if( !vertex.first )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
const auto& 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).
|
2018-09-16 17:20:53 +00:00
|
|
|
if( vertexIdx.m_contour == 0 && polyset->Polygon( vertexIdx.m_polygon )[vertexIdx.m_contour].PointCount() <= 3 )
|
2017-01-18 08:04:11 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
// Remove corner does not work with lines
|
|
|
|
if( dynamic_cast<EDIT_LINE*>( m_editedPoint ) )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return m_editedPoint != NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-14 19:21:10 +00:00
|
|
|
int 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;
|
|
|
|
|
2014-03-18 13:52:22 +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>();
|
2017-01-18 08:04:11 +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;
|
|
|
|
|
2018-10-01 11:15:12 +00:00
|
|
|
DRAWSEGMENT* graphicItem = dynamic_cast<DRAWSEGMENT*>( item );
|
2016-06-21 15:06:28 +00:00
|
|
|
BOARD_COMMIT commit( frame );
|
2014-03-18 13:52:22 +00:00
|
|
|
|
2019-10-26 15:49:29 +00:00
|
|
|
if( item->Type() == PCB_ZONE_AREA_T || item->Type() == PCB_MODULE_ZONE_AREA_T ||
|
2018-10-01 11:15:12 +00:00
|
|
|
( graphicItem && graphicItem->GetShape() == S_POLYGON ) )
|
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;
|
|
|
|
|
2019-10-26 15:49:29 +00:00
|
|
|
if( item->Type() == PCB_ZONE_AREA_T || item->Type() == PCB_MODULE_ZONE_AREA_T )
|
2019-03-14 13:35:55 +00:00
|
|
|
{
|
|
|
|
ZONE_CONTAINER* zone = static_cast<ZONE_CONTAINER*>( item );
|
|
|
|
zoneOutline = zone->Outline();
|
|
|
|
zone->SetNeedRefill( true );
|
|
|
|
}
|
2018-10-01 11:15:12 +00:00
|
|
|
else
|
|
|
|
zoneOutline = &( graphicItem->GetPolyShape() );
|
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)
|
|
|
|
SHAPE_POLY_SET::ITERATOR iterator = zoneOutline->Iterate( 0,
|
|
|
|
zoneOutline->OutlineCount()-1, /* IterateHoles */ true );
|
|
|
|
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
|
2019-03-23 18:26:44 +00:00
|
|
|
auto& sideOrigin = zoneOutline->CVertex( nearestIdx );
|
|
|
|
auto& sideEnd = zoneOutline->CVertex( nextNearestIdx );
|
2014-03-18 16:02:10 +00:00
|
|
|
SEG nearestSide( sideOrigin, sideEnd );
|
2017-01-18 08:04:11 +00:00
|
|
|
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
|
2019-10-26 15:49:29 +00:00
|
|
|
if( item->Type() == PCB_ZONE_AREA_T || item->Type() == PCB_MODULE_ZONE_AREA_T )
|
2020-08-07 14:04:34 +00:00
|
|
|
static_cast<ZONE_CONTAINER*>( item )->HatchBorder();
|
2018-09-15 16:51:35 +00:00
|
|
|
|
2016-06-21 15:06:28 +00:00
|
|
|
|
|
|
|
commit.Push( _( "Add a zone corner" ) );
|
2014-03-18 13:52:22 +00:00
|
|
|
}
|
2014-03-18 14:46:38 +00:00
|
|
|
|
2018-10-01 11:15:12 +00:00
|
|
|
else if( graphicItem && graphicItem->GetShape() == S_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
|
|
|
|
2018-10-01 11:15:12 +00:00
|
|
|
SEG seg( graphicItem->GetStart(), graphicItem->GetEnd() );
|
|
|
|
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..
|
|
|
|
graphicItem->SetEnd( wxPoint( nearestPoint.x, nearestPoint.y ) );
|
2014-03-18 14:46:38 +00:00
|
|
|
|
2019-12-02 14:55:00 +00:00
|
|
|
if( graphicItem->Type() == PCB_MODULE_EDGE_T )
|
|
|
|
static_cast<EDGE_MODULE*>( graphicItem )->SetLocalCoord();
|
|
|
|
|
2018-10-01 11:15:12 +00:00
|
|
|
// and add another one starting from the break point
|
|
|
|
DRAWSEGMENT* newSegment;
|
2014-07-09 13:02:56 +00:00
|
|
|
|
2018-10-01 11:15:12 +00:00
|
|
|
if( item->Type() == PCB_MODULE_EDGE_T )
|
|
|
|
{
|
|
|
|
EDGE_MODULE* edge = static_cast<EDGE_MODULE*>( graphicItem );
|
|
|
|
assert( edge->GetParent()->Type() == PCB_MODULE_T );
|
|
|
|
newSegment = new EDGE_MODULE( *edge );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
newSegment = new DRAWSEGMENT( *graphicItem );
|
|
|
|
}
|
2014-07-09 13:02:56 +00:00
|
|
|
|
2018-10-01 11:15:12 +00:00
|
|
|
newSegment->ClearSelected();
|
|
|
|
newSegment->SetStart( wxPoint( nearestPoint.x, nearestPoint.y ) );
|
|
|
|
newSegment->SetEnd( wxPoint( seg.B.x, seg.B.y ) );
|
2014-03-18 14:46:38 +00:00
|
|
|
|
2019-12-02 14:55:00 +00:00
|
|
|
if( newSegment->Type() == PCB_MODULE_EDGE_T )
|
|
|
|
static_cast<EDGE_MODULE*>( newSegment )->SetLocalCoord();
|
|
|
|
|
2018-10-01 11:15:12 +00:00
|
|
|
commit.Add( newSegment );
|
|
|
|
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
|
|
|
|
|
|
|
|
2019-05-14 19:21:10 +00:00
|
|
|
int 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
|
|
|
|
2019-10-26 15:49:29 +00:00
|
|
|
if( item->Type() == PCB_ZONE_AREA_T || item->Type() == PCB_MODULE_ZONE_AREA_T )
|
2015-06-19 15:32:33 +00:00
|
|
|
{
|
2017-10-19 21:14:01 +00:00
|
|
|
auto zone = static_cast<ZONE_CONTAINER*>( 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
|
|
|
}
|
2018-09-16 17:20:53 +00:00
|
|
|
else if( (item->Type() == PCB_MODULE_EDGE_T ) || ( item->Type() == PCB_LINE_T ) )
|
2017-10-19 21:14:01 +00:00
|
|
|
{
|
|
|
|
auto ds = static_cast<DRAWSEGMENT*>( item );
|
2017-12-06 14:51:47 +00:00
|
|
|
|
2017-10-19 21:14:01 +00:00
|
|
|
if( ds->GetShape() == S_POLYGON )
|
2017-12-06 14:51:47 +00:00
|
|
|
polygon = &ds->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
|
|
|
|
{
|
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true );
|
|
|
|
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
|
|
|
|
2019-07-14 12:46:59 +00:00
|
|
|
commit.Push( _( "Remove a zone/polygon corner" ) );
|
2018-02-22 11:28:01 +00:00
|
|
|
|
2019-07-14 12:46:59 +00:00
|
|
|
// Refresh zone hatching
|
2019-10-26 15:49:29 +00:00
|
|
|
if( item->Type() == PCB_ZONE_AREA_T || item->Type() == PCB_MODULE_ZONE_AREA_T )
|
2020-08-07 14:04:34 +00:00
|
|
|
static_cast<ZONE_CONTAINER*>( 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
|
|
|
|
|
|
|
|
2019-05-14 19:21:10 +00:00
|
|
|
int 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
|
|
|
|
2020-08-29 22:59:11 +00:00
|
|
|
int POINT_EDITOR::changeEditMethod( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
m_altEditMethod = !m_altEditMethod;
|
|
|
|
return 0;
|
|
|
|
}
|
2019-05-24 11:39:30 +00:00
|
|
|
|
|
|
|
void POINT_EDITOR::setTransitions()
|
|
|
|
{
|
|
|
|
Go( &POINT_EDITOR::OnSelectionChange, ACTIONS::activatePointEditor.MakeEvent() );
|
|
|
|
Go( &POINT_EDITOR::addCorner, PCB_ACTIONS::pointEditorAddCorner.MakeEvent() );
|
|
|
|
Go( &POINT_EDITOR::removeCorner, PCB_ACTIONS::pointEditorRemoveCorner.MakeEvent() );
|
|
|
|
Go( &POINT_EDITOR::modifiedSelection, EVENTS::SelectedItemsModified );
|
|
|
|
Go( &POINT_EDITOR::OnSelectionChange, EVENTS::SelectedEvent );
|
|
|
|
Go( &POINT_EDITOR::OnSelectionChange, EVENTS::UnselectedEvent );
|
2020-08-29 22:59:11 +00:00
|
|
|
Go( &POINT_EDITOR::changeEditMethod, ACTIONS::changeEditMethod.MakeEvent() );
|
2019-05-24 11:39:30 +00:00
|
|
|
}
|