2014-02-27 16:29:08 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2017-01-18 08:04:11 +00:00
|
|
|
* Copyright (C) 2013-2017 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>
|
|
|
|
using namespace std::placeholders;
|
2014-02-28 15:53:28 +00:00
|
|
|
|
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"
|
2016-06-21 15:06:28 +00:00
|
|
|
#include <board_commit.h>
|
2017-02-20 18:10:20 +00:00
|
|
|
#include <bitmaps.h>
|
2014-02-27 16:29:08 +00:00
|
|
|
|
2014-03-06 10:49:08 +00:00
|
|
|
#include <wxPcbStruct.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>
|
2014-03-18 14:46:38 +00:00
|
|
|
#include <class_board.h>
|
2014-07-09 13:02:56 +00:00
|
|
|
#include <class_module.h>
|
2017-11-15 17:33:06 +00:00
|
|
|
#include <connectivity_data.h>
|
2014-02-27 16:29:08 +00:00
|
|
|
|
2017-11-30 16:21:51 +00:00
|
|
|
#include "zone_filler.h"
|
|
|
|
|
2017-02-20 18:10:20 +00:00
|
|
|
// Point editor
|
|
|
|
TOOL_ACTION PCB_ACTIONS::pointEditorAddCorner( "pcbnew.PointEditor.addCorner",
|
|
|
|
AS_GLOBAL, 0,
|
|
|
|
_( "Create Corner" ), _( "Create a corner" ), add_corner_xpm );
|
|
|
|
|
|
|
|
TOOL_ACTION PCB_ACTIONS::pointEditorRemoveCorner( "pcbnew.PointEditor.removeCorner",
|
|
|
|
AS_GLOBAL, 0,
|
|
|
|
_( "Remove Corner" ), _( "Remove corner" ), delete_xpm );
|
|
|
|
|
|
|
|
|
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
|
|
|
|
};
|
|
|
|
|
|
|
|
enum ARC_POINTS
|
|
|
|
{
|
|
|
|
ARC_CENTER, ARC_START, ARC_END
|
|
|
|
};
|
|
|
|
|
|
|
|
enum CIRCLE_POINTS
|
|
|
|
{
|
|
|
|
CIRC_CENTER, CIRC_END
|
|
|
|
};
|
|
|
|
|
|
|
|
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:
|
|
|
|
|
|
|
|
static void buildForPolyOutline( std::shared_ptr<EDIT_POINTS> points, const SHAPE_POLY_SET* aOutline, KIGFX::GAL* aGal )
|
|
|
|
{
|
|
|
|
|
|
|
|
int cornersCount = aOutline->TotalVertices();
|
|
|
|
|
|
|
|
for( auto iterator = aOutline->CIterateWithHoles(); iterator; iterator++ )
|
|
|
|
{
|
|
|
|
points->AddPoint( *iterator );
|
|
|
|
|
|
|
|
if( iterator.IsEndContour() )
|
|
|
|
points->AddBreak();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Lines have to be added after creating edit points,
|
|
|
|
// as they use EDIT_POINT references
|
|
|
|
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 ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
points->Line( i ).SetConstraint( new EC_SNAPLINE( points->Line( i ),
|
|
|
|
std::bind( &KIGFX::GAL::GetGridPoint, aGal, _1 ) ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
// The last missing line, connecting the last and the first polygon point
|
|
|
|
points->AddLine( points->Point( cornersCount - 1 ),
|
|
|
|
points->Point( points->GetContourStartIdx( cornersCount - 1 ) ) );
|
|
|
|
|
|
|
|
points->Line( points->LinesSize() - 1 ).SetConstraint(
|
|
|
|
new EC_SNAPLINE( points->Line( points->LinesSize() - 1 ),
|
|
|
|
std::bind( &KIGFX::GAL::GetGridPoint, aGal, _1 ) ) );
|
|
|
|
}
|
|
|
|
|
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() )
|
|
|
|
{
|
|
|
|
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 17:24:29 +00:00
|
|
|
const DRAWSEGMENT* segment = static_cast<const DRAWSEGMENT*>( aItem );
|
2014-02-27 16:29:08 +00:00
|
|
|
|
|
|
|
switch( segment->GetShape() )
|
|
|
|
{
|
|
|
|
case S_SEGMENT:
|
2014-04-01 15:41:24 +00:00
|
|
|
points->AddPoint( segment->GetStart() );
|
|
|
|
points->AddPoint( segment->GetEnd() );
|
2014-02-27 16:29:08 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case S_ARC:
|
2014-04-01 15:41:24 +00:00
|
|
|
points->AddPoint( segment->GetCenter() );
|
|
|
|
points->AddPoint( segment->GetArcStart() );
|
|
|
|
points->AddPoint( segment->GetArcEnd() );
|
2014-02-27 16:29:08 +00:00
|
|
|
|
|
|
|
// Set constraints
|
|
|
|
// Arc end has to stay at the same radius as the start
|
2014-04-01 15:41:24 +00:00
|
|
|
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
|
|
|
break;
|
|
|
|
|
2014-02-28 17:24:13 +00:00
|
|
|
case S_CIRCLE:
|
2014-04-01 15:41:24 +00:00
|
|
|
points->AddPoint( segment->GetCenter() );
|
|
|
|
points->AddPoint( segment->GetEnd() );
|
2014-03-06 16:34:04 +00:00
|
|
|
break;
|
2014-02-28 17:24:13 +00:00
|
|
|
|
2017-10-19 21:14:01 +00:00
|
|
|
case S_POLYGON:
|
|
|
|
{
|
|
|
|
buildForPolyOutline( points, &segment->GetPolyShape(), aGal );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-02-27 16:29:08 +00:00
|
|
|
default: // suppress warnings
|
|
|
|
break;
|
|
|
|
}
|
2014-02-28 17:24:29 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case PCB_ZONE_AREA_T:
|
|
|
|
{
|
2017-10-19 21:14:01 +00:00
|
|
|
auto zone = static_cast<const ZONE_CONTAINER*>( aItem );
|
|
|
|
buildForPolyOutline( points, zone->Outline(), aGal );
|
2014-03-12 09:46:11 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case PCB_DIMENSION_T:
|
|
|
|
{
|
|
|
|
const DIMENSION* dimension = static_cast<const DIMENSION*>( aItem );
|
|
|
|
|
|
|
|
points->AddPoint( dimension->m_crossBarO );
|
|
|
|
points->AddPoint( dimension->m_crossBarF );
|
2014-03-12 09:53:42 +00:00
|
|
|
points->AddPoint( dimension->m_featureLineGO );
|
|
|
|
points->AddPoint( dimension->m_featureLineDO );
|
2014-03-12 09:46:11 +00:00
|
|
|
|
|
|
|
// Dimension height setting - edit points should move only along the feature lines
|
2014-04-01 15:41:24 +00:00
|
|
|
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 ) ) );
|
2014-02-28 17:24:29 +00:00
|
|
|
|
|
|
|
break;
|
2014-02-27 16:29:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
2014-03-06 13:41:25 +00:00
|
|
|
points.reset();
|
2014-02-27 16:29:08 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return points;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
EDIT_POINTS_FACTORY() {};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
POINT_EDITOR::POINT_EDITOR() :
|
2017-11-30 16:21:51 +00:00
|
|
|
PCB_TOOL( "pcbnew.PointEditor" ), m_selectionTool( NULL ), m_editedPoint( NULL ),
|
2014-03-14 14:37:55 +00:00
|
|
|
m_original( VECTOR2I( 0, 0 ) ), m_altConstrainer( VECTOR2I( 0, 0 ) )
|
2014-02-27 16:29:08 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-02-28 16:20:10 +00:00
|
|
|
void POINT_EDITOR::Reset( RESET_REASON aReason )
|
|
|
|
{
|
|
|
|
m_editPoints.reset();
|
2014-03-14 14:37:55 +00:00
|
|
|
m_altConstraint.reset();
|
2014-02-28 16:20:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-02-27 16:29:08 +00:00
|
|
|
bool POINT_EDITOR::Init()
|
|
|
|
{
|
|
|
|
// Find the selection tool, so they can cooperate
|
|
|
|
m_selectionTool = static_cast<SELECTION_TOOL*>( m_toolMgr->FindTool( "pcbnew.InteractiveSelection" ) );
|
|
|
|
|
|
|
|
if( !m_selectionTool )
|
|
|
|
{
|
|
|
|
DisplayError( NULL, wxT( "pcbnew.InteractiveSelection tool is not available" ) );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-01-12 10:07:52 +00:00
|
|
|
auto& menu = m_selectionTool->GetToolMenu().GetMenu();
|
2017-02-21 12:42:08 +00:00
|
|
|
menu.AddItem( PCB_ACTIONS::pointEditorAddCorner, POINT_EDITOR::addCornerCondition );
|
|
|
|
menu.AddItem( PCB_ACTIONS::pointEditorRemoveCorner,
|
2017-01-12 10:07:52 +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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-08-12 08:15:45 +00:00
|
|
|
void POINT_EDITOR::updateEditedPoint( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
2015-08-15 13:28:48 +00:00
|
|
|
EDIT_POINT* point = m_editedPoint;
|
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
|
|
|
}
|
|
|
|
|
|
|
|
if( m_editedPoint != point )
|
|
|
|
setEditedPoint( point );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-02-14 20:28:47 +00:00
|
|
|
int POINT_EDITOR::OnSelectionChange( const TOOL_EVENT& aEvent )
|
2014-02-27 16:29:08 +00:00
|
|
|
{
|
2014-07-09 13:10:32 +00:00
|
|
|
const SELECTION& selection = m_selectionTool->GetSelection();
|
2014-02-27 16:29:08 +00:00
|
|
|
|
2017-03-06 09:55:32 +00:00
|
|
|
if( selection.Size() != 1 )
|
|
|
|
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>();
|
|
|
|
auto item = selection.Front();
|
2014-03-06 13:41:25 +00:00
|
|
|
|
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() );
|
|
|
|
m_editedPoint = NULL;
|
|
|
|
bool modified = false;
|
2017-05-16 09:38:00 +00:00
|
|
|
bool revert = 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
|
|
|
|
while( OPT_TOOL_EVENT evt = Wait() )
|
|
|
|
{
|
2017-05-16 09:38:00 +00:00
|
|
|
if( revert )
|
|
|
|
break;
|
|
|
|
|
2017-03-06 09:55:32 +00:00
|
|
|
if( !m_editPoints ||
|
|
|
|
evt->Matches( m_selectionTool->ClearedEvent ) ||
|
|
|
|
evt->Matches( m_selectionTool->UnselectedEvent ) ||
|
|
|
|
evt->Matches( m_selectionTool->SelectedEvent ) )
|
2014-02-27 16:29:08 +00:00
|
|
|
{
|
2017-03-06 09:55:32 +00:00
|
|
|
break;
|
|
|
|
}
|
2015-12-14 21:20:54 +00:00
|
|
|
|
2017-03-06 09:55:32 +00:00
|
|
|
if ( !modified )
|
|
|
|
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 )
|
|
|
|
{
|
|
|
|
if( !modified )
|
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
|
|
|
|
2017-03-06 09:55:32 +00:00
|
|
|
controls->ForceCursorPosition( false );
|
|
|
|
m_original = *m_editedPoint; // Save the original position
|
|
|
|
controls->SetAutoPan( true );
|
|
|
|
modified = true;
|
|
|
|
}
|
2016-06-21 15:06:28 +00:00
|
|
|
|
2017-03-06 09:55:32 +00:00
|
|
|
bool enableAltConstraint = !!evt->Modifier( MD_CTRL );
|
2014-03-06 13:41:25 +00:00
|
|
|
|
2017-03-06 09:55:32 +00:00
|
|
|
if( enableAltConstraint != (bool) m_altConstraint ) // alternative constraint
|
|
|
|
setAltConstraint( enableAltConstraint );
|
2014-03-13 10:48:19 +00:00
|
|
|
|
2017-03-06 09:55:32 +00:00
|
|
|
m_editedPoint->SetPosition( controls->GetCursorPosition() );
|
2014-03-13 10:48:19 +00:00
|
|
|
|
2017-03-06 09:55:32 +00:00
|
|
|
if( m_altConstraint )
|
|
|
|
m_altConstraint->Apply();
|
|
|
|
else
|
|
|
|
m_editedPoint->ApplyConstraint();
|
2016-06-21 15:06:28 +00:00
|
|
|
|
2017-03-06 09:55:32 +00:00
|
|
|
updateItem();
|
|
|
|
updatePoints();
|
|
|
|
}
|
2016-06-21 15:06:28 +00:00
|
|
|
|
2017-03-06 09:55:32 +00:00
|
|
|
else if( evt->IsMouseUp( BUT_LEFT ) )
|
|
|
|
{
|
|
|
|
controls->SetAutoPan( false );
|
|
|
|
setAltConstraint( false );
|
2014-03-06 11:36:20 +00:00
|
|
|
|
2017-03-06 09:55:32 +00:00
|
|
|
if( modified )
|
2014-03-06 11:36:20 +00:00
|
|
|
{
|
2017-03-06 09:55:32 +00:00
|
|
|
commit.Push( _( "Drag a line ending" ) );
|
|
|
|
modified = false;
|
2014-03-06 11:36:20 +00:00
|
|
|
}
|
|
|
|
|
2017-03-06 09:55:32 +00:00
|
|
|
m_toolMgr->PassEvent();
|
|
|
|
}
|
|
|
|
|
|
|
|
else if( evt->IsCancel() )
|
|
|
|
{
|
|
|
|
if( modified ) // Restore the last change
|
2017-05-16 09:38:00 +00:00
|
|
|
revert = true;
|
2017-03-06 09:55:32 +00:00
|
|
|
|
|
|
|
// Let the selection tool receive the event too
|
|
|
|
m_toolMgr->PassEvent();
|
|
|
|
|
2017-05-16 09:38:00 +00:00
|
|
|
// Do not exit right now, let the selection clear the selection
|
|
|
|
//break;
|
2014-02-27 16:29:08 +00:00
|
|
|
}
|
|
|
|
|
2017-03-06 09:55:32 +00:00
|
|
|
else
|
2014-02-28 16:20:10 +00:00
|
|
|
{
|
2017-03-06 09:55:32 +00:00
|
|
|
m_toolMgr->PassEvent();
|
2014-02-28 16:20:10 +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 )
|
|
|
|
{
|
|
|
|
view->Remove( m_editPoints.get() );
|
2017-05-16 09:38:00 +00:00
|
|
|
|
|
|
|
if( modified && revert )
|
|
|
|
commit.Revert();
|
|
|
|
else
|
|
|
|
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
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-02-28 15:53:28 +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
|
|
|
|
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 );
|
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;
|
|
|
|
|
|
|
|
case S_ARC:
|
|
|
|
{
|
2014-04-01 15:41:24 +00:00
|
|
|
const VECTOR2I& center = m_editPoints->Point( ARC_CENTER ).GetPosition();
|
|
|
|
const VECTOR2I& start = m_editPoints->Point( ARC_START ).GetPosition();
|
|
|
|
const VECTOR2I& end = m_editPoints->Point( ARC_END ).GetPosition();
|
2014-02-27 16:29:08 +00:00
|
|
|
|
|
|
|
if( center != segment->GetCenter() )
|
|
|
|
{
|
|
|
|
wxPoint moveVector = wxPoint( center.x, center.y ) - segment->GetCenter();
|
|
|
|
segment->Move( moveVector );
|
|
|
|
|
2014-04-01 15:41:24 +00:00
|
|
|
m_editPoints->Point( ARC_START ).SetPosition( segment->GetArcStart() );
|
|
|
|
m_editPoints->Point( ARC_END ).SetPosition( segment->GetArcEnd() );
|
2014-02-27 16:29:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
{
|
|
|
|
segment->SetArcStart( wxPoint( start.x, start.y ) );
|
|
|
|
|
|
|
|
VECTOR2D startLine = start - center;
|
|
|
|
VECTOR2I endLine = end - center;
|
|
|
|
double newAngle = RAD2DECIDEG( endLine.Angle() - startLine.Angle() );
|
|
|
|
|
|
|
|
// Adjust the new angle to (counter)clockwise setting
|
|
|
|
bool clockwise = ( segment->GetAngle() > 0 );
|
2014-02-28 17:24:13 +00:00
|
|
|
|
2014-02-27 16:29:08 +00:00
|
|
|
if( clockwise && newAngle < 0.0 )
|
|
|
|
newAngle += 3600.0;
|
|
|
|
else if( !clockwise && newAngle > 0.0 )
|
|
|
|
newAngle -= 3600.0;
|
|
|
|
|
|
|
|
segment->SetAngle( newAngle );
|
|
|
|
}
|
2014-02-28 17:24:13 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
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 ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
2014-02-27 16:29:08 +00:00
|
|
|
}
|
|
|
|
|
2017-10-19 21:14:01 +00:00
|
|
|
case S_POLYGON:
|
|
|
|
{
|
|
|
|
SHAPE_POLY_SET* outline = &segment->GetPolyShape();
|
|
|
|
|
|
|
|
for( int i = 0; i < outline->TotalVertices(); ++i )
|
|
|
|
{
|
|
|
|
VECTOR2I point = m_editPoints->Point( i ).GetPosition();
|
|
|
|
outline->Vertex( i ) = point;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
case PCB_ZONE_AREA_T:
|
|
|
|
{
|
|
|
|
ZONE_CONTAINER* zone = static_cast<ZONE_CONTAINER*>( item );
|
2014-03-14 15:05:30 +00:00
|
|
|
zone->ClearFilledPolysList();
|
2017-03-07 12:06:00 +00:00
|
|
|
SHAPE_POLY_SET* outline = zone->Outline();
|
2014-02-28 17:24:29 +00:00
|
|
|
|
2017-03-07 12:06:00 +00:00
|
|
|
for( int i = 0; i < outline->TotalVertices(); ++i )
|
2014-02-28 17:24:29 +00:00
|
|
|
{
|
2014-07-09 14:50:31 +00:00
|
|
|
VECTOR2I point = m_editPoints->Point( i ).GetPosition();
|
2017-03-07 12:06:00 +00:00
|
|
|
outline->Vertex( i ) = point;
|
2014-02-28 17:24:29 +00:00
|
|
|
}
|
|
|
|
|
2017-03-07 12:06:00 +00:00
|
|
|
zone->Hatch();
|
2017-02-24 12:26:25 +00:00
|
|
|
|
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 )
|
|
|
|
dimension->SetHeight( -featureLine.EuclideanNorm() );
|
|
|
|
else
|
|
|
|
dimension->SetHeight( featureLine.EuclideanNorm() );
|
|
|
|
}
|
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 )
|
|
|
|
dimension->SetHeight( -featureLine.EuclideanNorm() );
|
|
|
|
else
|
|
|
|
dimension->SetHeight( featureLine.EuclideanNorm() );
|
|
|
|
}
|
|
|
|
|
2014-04-01 15:41:24 +00:00
|
|
|
else if( isModified( m_editPoints->Point( DIM_FEATUREGO ) ) )
|
2014-03-12 09:53:42 +00:00
|
|
|
{
|
2015-06-19 15:32:33 +00:00
|
|
|
dimension->SetOrigin( wxPoint( m_editedPoint->GetPosition().x, m_editedPoint->GetPosition().y ) );
|
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
|
|
|
{
|
2015-06-19 15:32:33 +00:00
|
|
|
dimension->SetEnd( wxPoint( m_editedPoint->GetPosition().x, m_editedPoint->GetPosition().y ) );
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-11-30 16:21:51 +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();
|
2017-05-16 09:38:00 +00:00
|
|
|
if( !item )
|
|
|
|
return;
|
|
|
|
|
2014-03-06 10:49:08 +00:00
|
|
|
if( item->Type() == PCB_ZONE_AREA_T )
|
|
|
|
{
|
2017-11-30 16:21:51 +00:00
|
|
|
auto zone = static_cast<ZONE_CONTAINER*>( item );
|
2014-03-06 10:49:08 +00:00
|
|
|
|
|
|
|
if( zone->IsFilled() )
|
2017-02-13 23:38:14 +00:00
|
|
|
{
|
2017-11-30 16:21:51 +00:00
|
|
|
ZONE_FILLER filler( board() );
|
|
|
|
filler.Fill( { zone } );
|
2017-02-13 23:38:14 +00:00
|
|
|
}
|
2014-03-06 10:49:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-07-09 14:50:31 +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
|
|
|
|
2017-12-18 13:07:17 +00:00
|
|
|
case S_ARC:
|
|
|
|
m_editPoints->Point( ARC_CENTER ).SetPosition( segment->GetCenter() );
|
|
|
|
m_editPoints->Point( ARC_START).SetPosition( segment->GetArcStart() );
|
|
|
|
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();
|
2017-12-18 13:07:17 +00:00
|
|
|
for( unsigned i = 0; i < points.size(); i++ )
|
2017-12-18 17:24:25 +00:00
|
|
|
{
|
2017-12-18 13:07:17 +00:00
|
|
|
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
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
case PCB_ZONE_AREA_T:
|
|
|
|
{
|
|
|
|
const ZONE_CONTAINER* zone = static_cast<const 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() );
|
|
|
|
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
|
|
|
|
|
|
|
|
2015-06-19 15:32:33 +00:00
|
|
|
void POINT_EDITOR::setEditedPoint( EDIT_POINT* aPoint )
|
|
|
|
{
|
|
|
|
KIGFX::VIEW_CONTROLS* controls = getViewControls();
|
|
|
|
|
|
|
|
if( aPoint )
|
|
|
|
{
|
|
|
|
controls->ForceCursorPosition( true, aPoint->GetPosition() );
|
|
|
|
controls->ShowCursor( true );
|
|
|
|
controls->SetSnapping( true );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
controls->ShowCursor( false );
|
|
|
|
controls->SetSnapping( false );
|
|
|
|
controls->ForceCursorPosition( false );
|
|
|
|
}
|
|
|
|
|
|
|
|
m_editedPoint = aPoint;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-03-14 14:37:55 +00:00
|
|
|
void POINT_EDITOR::setAltConstraint( bool aEnabled )
|
|
|
|
{
|
|
|
|
if( aEnabled )
|
|
|
|
{
|
2015-06-19 15:32:33 +00:00
|
|
|
EDIT_LINE* line = dynamic_cast<EDIT_LINE*>( m_editedPoint );
|
2014-04-02 07:31:35 +00:00
|
|
|
|
2014-03-14 14:37:55 +00:00
|
|
|
if( line )
|
|
|
|
{
|
|
|
|
if( m_editPoints->GetParent()->Type() == PCB_ZONE_AREA_T )
|
2014-04-02 07:31:35 +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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-03-06 16:34:04 +00:00
|
|
|
EDIT_POINT POINT_EDITOR::get45DegConstrainer() const
|
|
|
|
{
|
|
|
|
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
|
|
|
|
|
|
|
|
2017-07-31 12:30:51 +00:00
|
|
|
void POINT_EDITOR::setTransitions()
|
2017-01-18 08:04:11 +00:00
|
|
|
{
|
2017-02-21 12:42:08 +00:00
|
|
|
Go( &POINT_EDITOR::addCorner, PCB_ACTIONS::pointEditorAddCorner.MakeEvent() );
|
|
|
|
Go( &POINT_EDITOR::removeCorner, PCB_ACTIONS::pointEditorRemoveCorner.MakeEvent() );
|
2017-04-20 10:10:53 +00:00
|
|
|
Go( &POINT_EDITOR::modifiedSelection, PCB_ACTIONS::selectionModified.MakeEvent() );
|
2017-01-18 08:04:11 +00:00
|
|
|
Go( &POINT_EDITOR::OnSelectionChange, SELECTION_TOOL::SelectedEvent );
|
|
|
|
Go( &POINT_EDITOR::OnSelectionChange, SELECTION_TOOL::UnselectedEvent );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool POINT_EDITOR::addCornerCondition( const SELECTION& aSelection )
|
|
|
|
{
|
|
|
|
if( aSelection.Size() != 1 )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
auto item = aSelection.Front();
|
|
|
|
|
|
|
|
// Works only for zones and line segments
|
|
|
|
return item->Type() == PCB_ZONE_AREA_T ||
|
|
|
|
( ( item->Type() == PCB_LINE_T || item->Type() == PCB_MODULE_EDGE_T ) &&
|
|
|
|
static_cast<DRAWSEGMENT*>( item )->GetShape() == S_SEGMENT );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
if( aPolySet.Vertex( vertexIdx ) == aPoint.GetPosition() )
|
|
|
|
return std::make_pair( true, vertexIdx );
|
|
|
|
}
|
|
|
|
|
|
|
|
return std::make_pair( false, SHAPE_POLY_SET::VERTEX_INDEX() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-01-18 08:04:11 +00:00
|
|
|
bool POINT_EDITOR::removeCornerCondition( const SELECTION& )
|
|
|
|
{
|
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();
|
|
|
|
|
2017-12-06 14:51:47 +00:00
|
|
|
if( !item || item->Type() != PCB_ZONE_AREA_T )
|
2017-01-18 08:04:11 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
ZONE_CONTAINER* zone = static_cast<ZONE_CONTAINER*>( item );
|
2017-12-06 14:51:47 +00:00
|
|
|
auto& polyset = *zone->Outline();
|
|
|
|
auto vertex = findVertex( polyset, *m_editedPoint );
|
|
|
|
|
|
|
|
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.
|
|
|
|
// The first condition allows to remove all corners from holes (when there
|
|
|
|
// are only 2 vertices left, a hole is removed).
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int POINT_EDITOR::addCorner( const TOOL_EVENT& aEvent )
|
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();
|
2016-06-21 15:06:28 +00:00
|
|
|
BOARD_COMMIT commit( frame );
|
2014-03-18 13:52:22 +00:00
|
|
|
|
|
|
|
if( item->Type() == PCB_ZONE_AREA_T )
|
|
|
|
{
|
|
|
|
ZONE_CONTAINER* zone = static_cast<ZONE_CONTAINER*>( item );
|
2017-04-14 12:38:59 +00:00
|
|
|
SHAPE_POLY_SET* zoneOutline = zone->Outline();
|
2014-03-18 13:52:22 +00:00
|
|
|
|
2016-06-21 15:06:28 +00:00
|
|
|
commit.Modify( zone );
|
|
|
|
|
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;
|
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
|
|
|
|
2017-04-14 12:38:59 +00:00
|
|
|
SEG curr_segment( zoneOutline->Vertex( curr_idx ), zoneOutline->Vertex( 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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-06 17:04:47 +00:00
|
|
|
|
2014-03-18 13:52:22 +00:00
|
|
|
// Find the point on the closest segment
|
2017-04-14 12:38:59 +00:00
|
|
|
VECTOR2I sideOrigin = zoneOutline->Vertex( nearestIdx );
|
|
|
|
VECTOR2I sideEnd = zoneOutline->Vertex( 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-06 17:04:47 +00:00
|
|
|
// Add corner between nearestIdx and nextNearestIdx:
|
2017-04-14 12:38:59 +00:00
|
|
|
zoneOutline->InsertVertex( nextNearestIdx, nearestPoint );
|
2017-04-06 17:04:47 +00:00
|
|
|
zone->Hatch();
|
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
|
|
|
|
2014-07-09 11:50:27 +00:00
|
|
|
else if( item->Type() == PCB_LINE_T || item->Type() == PCB_MODULE_EDGE_T )
|
2014-03-18 14:46:38 +00:00
|
|
|
{
|
2014-07-09 13:02:56 +00:00
|
|
|
bool moduleEdge = item->Type() == PCB_MODULE_EDGE_T;
|
2014-03-18 14:46:38 +00:00
|
|
|
|
|
|
|
DRAWSEGMENT* segment = static_cast<DRAWSEGMENT*>( item );
|
|
|
|
|
|
|
|
if( segment->GetShape() == S_SEGMENT )
|
|
|
|
{
|
2016-06-21 15:06:28 +00:00
|
|
|
commit.Modify( segment );
|
2016-06-08 09:24:46 +00:00
|
|
|
|
2014-03-18 14:46:38 +00:00
|
|
|
SEG seg( segment->GetStart(), segment->GetEnd() );
|
2017-01-18 08:04:11 +00:00
|
|
|
VECTOR2I nearestPoint = seg.NearestPoint( cursorPos );
|
2014-03-18 14:46:38 +00:00
|
|
|
|
|
|
|
// Move the end of the line to the break point..
|
|
|
|
segment->SetEnd( wxPoint( nearestPoint.x, nearestPoint.y ) );
|
|
|
|
|
|
|
|
// and add another one starting from the break point
|
2014-07-09 13:02:56 +00:00
|
|
|
DRAWSEGMENT* newSegment;
|
|
|
|
|
|
|
|
if( moduleEdge )
|
|
|
|
{
|
|
|
|
EDGE_MODULE* edge = static_cast<EDGE_MODULE*>( segment );
|
2016-06-08 09:24:46 +00:00
|
|
|
assert( edge->Type() == PCB_MODULE_EDGE_T );
|
|
|
|
assert( edge->GetParent()->Type() == PCB_MODULE_T );
|
2014-07-09 13:02:56 +00:00
|
|
|
newSegment = new EDGE_MODULE( *edge );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
newSegment = new DRAWSEGMENT( *segment );
|
|
|
|
}
|
|
|
|
|
2014-03-18 14:46:38 +00:00
|
|
|
newSegment->ClearSelected();
|
|
|
|
newSegment->SetStart( wxPoint( nearestPoint.x, nearestPoint.y ) );
|
|
|
|
newSegment->SetEnd( wxPoint( seg.B.x, seg.B.y ) );
|
|
|
|
|
2016-06-21 15:06:28 +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
|
|
|
|
|
|
|
|
2017-01-18 08:04:11 +00:00
|
|
|
int POINT_EDITOR::removeCorner( const TOOL_EVENT& aEvent )
|
2015-06-19 15:32:33 +00:00
|
|
|
{
|
2017-01-18 08:04:11 +00:00
|
|
|
if( !m_editedPoint )
|
|
|
|
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
|
|
|
|
|
|
|
if( item->Type() == PCB_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();
|
2017-10-19 21:14:01 +00:00
|
|
|
}
|
2017-12-06 14:51:47 +00:00
|
|
|
else if( 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 );
|
|
|
|
}
|
|
|
|
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 );
|
|
|
|
commit.Push( _( "Remove a zone/polygon corner" ) );
|
|
|
|
updatePoints();
|
|
|
|
}
|
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
|
|
|
|
|
|
|
|
2017-01-18 08:04:11 +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
|
|
|
}
|