2014-05-14 13:53:54 +00:00
|
|
|
/*
|
|
|
|
* KiRouter - a push-and-(sometimes-)shove PCB router
|
|
|
|
*
|
|
|
|
* Copyright (C) 2013-2014 CERN
|
2019-05-17 00:13:21 +00:00
|
|
|
* Copyright (C) 2016-2019 KiCad Developers, see AUTHORS.txt for contributors.
|
2014-05-14 13:53:54 +00:00
|
|
|
* Author: Tomasz Wlostowski <tomasz.wlostowski@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 3 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, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2019-05-17 00:13:21 +00:00
|
|
|
#include "pns_arc.h"
|
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
#include "pns_dragger.h"
|
|
|
|
#include "pns_shove.h"
|
|
|
|
#include "pns_router.h"
|
2020-02-20 23:03:23 +00:00
|
|
|
#include "pns_debug_decorator.h"
|
2020-02-05 15:33:14 +00:00
|
|
|
#include "pns_walkaround.h"
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2016-08-29 14:38:11 +00:00
|
|
|
namespace PNS {
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
DRAGGER::DRAGGER( ROUTER* aRouter ) :
|
2020-02-28 22:08:34 +00:00
|
|
|
DRAG_ALGO( aRouter )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
|
|
|
m_world = NULL;
|
2015-03-10 14:38:27 +00:00
|
|
|
m_lastNode = NULL;
|
2017-08-03 15:53:07 +00:00
|
|
|
m_mode = DM_SEGMENT;
|
2015-03-10 14:38:27 +00:00
|
|
|
m_draggedSegmentIndex = 0;
|
|
|
|
m_dragStatus = false;
|
|
|
|
m_currentMode = RM_MarkObstacles;
|
2017-11-01 09:20:13 +00:00
|
|
|
m_freeAngleMode = false;
|
2014-05-16 11:37:31 +00:00
|
|
|
}
|
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
DRAGGER::~DRAGGER()
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
bool DRAGGER::startDragSegment( const VECTOR2D& aP, SEGMENT* aSeg )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
|
|
|
int w2 = aSeg->Width() / 2;
|
|
|
|
|
2014-11-14 19:19:00 +00:00
|
|
|
m_draggedLine = m_world->AssembleLine( aSeg, &m_draggedSegmentIndex );
|
2019-08-07 21:49:35 +00:00
|
|
|
|
|
|
|
if( m_shove )
|
|
|
|
{
|
|
|
|
m_shove->SetInitialLine( m_draggedLine );
|
|
|
|
}
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2017-08-03 15:53:07 +00:00
|
|
|
auto distA = ( aP - aSeg->Seg().A ).EuclideanNorm();
|
|
|
|
auto distB = ( aP - aSeg->Seg().B ).EuclideanNorm();
|
|
|
|
|
|
|
|
if( distA <= w2 )
|
|
|
|
{
|
|
|
|
m_mode = DM_CORNER;
|
|
|
|
}
|
|
|
|
else if( distB <= w2 )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2019-05-17 00:13:21 +00:00
|
|
|
//todo (snh) Adjust segment for arcs
|
2014-11-14 19:19:00 +00:00
|
|
|
m_draggedSegmentIndex++;
|
2017-08-03 15:53:07 +00:00
|
|
|
m_mode = DM_CORNER;
|
|
|
|
}
|
|
|
|
else if ( m_freeAngleMode )
|
|
|
|
{
|
|
|
|
if( distB < distA )
|
|
|
|
{
|
|
|
|
m_draggedSegmentIndex++;
|
|
|
|
}
|
|
|
|
m_mode = DM_CORNER;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_mode = DM_SEGMENT;
|
|
|
|
}
|
2014-05-16 11:37:31 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
|
2019-05-17 00:13:21 +00:00
|
|
|
|
|
|
|
bool DRAGGER::startDragArc( const VECTOR2D& aP, ARC* aArc )
|
|
|
|
{
|
|
|
|
m_draggedLine = m_world->AssembleLine( aArc, &m_draggedSegmentIndex );
|
|
|
|
m_shove->SetInitialLine( m_draggedLine );
|
|
|
|
m_mode = DM_ARC;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-08-07 21:49:35 +00:00
|
|
|
bool DRAGGER::startDragVia( VIA* aVia )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2019-08-07 21:49:35 +00:00
|
|
|
m_initialVia = aVia->MakeHandle();
|
|
|
|
m_draggedVia = m_initialVia;
|
|
|
|
|
2017-08-03 15:53:07 +00:00
|
|
|
m_mode = DM_VIA;
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2019-08-07 21:49:35 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
const ITEM_SET DRAGGER::findViaFanoutByHandle ( NODE *aNode, const VIA_HANDLE& handle )
|
|
|
|
{
|
|
|
|
ITEM_SET rv;
|
|
|
|
|
|
|
|
JOINT* jt = aNode->FindJoint( handle.pos, handle.layers.Start(), handle.net );
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2015-08-04 09:37:16 +00:00
|
|
|
if( !jt )
|
2019-08-07 21:49:35 +00:00
|
|
|
return rv;
|
2015-08-04 09:37:16 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
for( ITEM* item : jt->LinkList() )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2019-05-17 00:13:21 +00:00
|
|
|
if( item->OfKind( ITEM::SEGMENT_T | ITEM::ARC_T ) )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
|
|
|
int segIndex;
|
2019-05-17 00:13:21 +00:00
|
|
|
LINKED_ITEM* seg = ( LINKED_ITEM*) item;
|
2019-08-07 21:49:35 +00:00
|
|
|
LINE l = aNode->AssembleLine( seg, &segIndex );
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
if( segIndex != 0 )
|
2015-08-03 19:11:51 +00:00
|
|
|
l.Reverse();
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2019-08-07 21:49:35 +00:00
|
|
|
rv.Add( l );
|
|
|
|
} else if ( item->OfKind( ITEM::VIA_T ))
|
|
|
|
{
|
|
|
|
rv.Add( item );
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-07 21:49:35 +00:00
|
|
|
return rv;
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
|
|
|
|
2020-02-28 22:08:34 +00:00
|
|
|
bool DRAGGER::Start( const VECTOR2I& aP, ITEM_SET& aPrimitives )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2020-02-28 22:08:34 +00:00
|
|
|
if( aPrimitives.Empty() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
ITEM* startItem = aPrimitives[0];
|
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
m_lastNode = NULL;
|
|
|
|
m_draggedItems.Clear();
|
|
|
|
m_currentMode = Settings().Mode();
|
2017-08-22 17:33:38 +00:00
|
|
|
m_freeAngleMode = (m_mode & DM_FREE_ANGLE);
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2020-02-05 15:33:14 +00:00
|
|
|
if( m_currentMode == RM_Shove && !m_freeAngleMode )
|
|
|
|
{
|
2019-08-12 14:30:46 +00:00
|
|
|
m_shove = std::make_unique<SHOVE>( m_world, Router() );
|
2020-02-05 15:33:14 +00:00
|
|
|
m_shove->SetLogger( Logger() );
|
|
|
|
m_shove->SetDebugDecorator( Dbg() );
|
|
|
|
}
|
2019-08-07 21:49:35 +00:00
|
|
|
|
2020-02-28 22:08:34 +00:00
|
|
|
startItem->Unmark( MK_LOCKED );
|
2016-08-15 15:16:50 +00:00
|
|
|
|
2020-02-28 22:08:34 +00:00
|
|
|
wxLogTrace( "PNS", "StartDragging: item %p [kind %d]", startItem, (int) startItem->Kind() );
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2020-02-28 22:08:34 +00:00
|
|
|
switch( startItem->Kind() )
|
2014-11-14 19:19:00 +00:00
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
case ITEM::SEGMENT_T:
|
2020-02-28 22:08:34 +00:00
|
|
|
return startDragSegment( aP, static_cast<SEGMENT*>( startItem ) );
|
2014-05-16 11:37:31 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
case ITEM::VIA_T:
|
2020-02-28 22:08:34 +00:00
|
|
|
return startDragVia( static_cast<VIA*>( startItem ) );
|
2014-05-16 11:37:31 +00:00
|
|
|
|
2019-05-17 00:13:21 +00:00
|
|
|
case ITEM::ARC_T:
|
2020-02-28 22:08:34 +00:00
|
|
|
return startDragArc( aP, static_cast<ARC*>( startItem ) );
|
2019-05-17 00:13:21 +00:00
|
|
|
|
2015-10-05 16:28:41 +00:00
|
|
|
default:
|
|
|
|
return false;
|
2014-11-14 19:19:00 +00:00
|
|
|
}
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
|
|
|
|
2018-05-08 09:47:14 +00:00
|
|
|
|
2017-08-03 15:53:07 +00:00
|
|
|
void DRAGGER::SetMode( int aMode )
|
|
|
|
{
|
|
|
|
m_mode = aMode;
|
|
|
|
}
|
2014-05-16 11:37:31 +00:00
|
|
|
|
2018-05-08 09:47:14 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
bool DRAGGER::dragMarkObstacles( const VECTOR2I& aP )
|
2014-11-14 19:19:00 +00:00
|
|
|
{
|
2019-08-07 21:49:35 +00:00
|
|
|
// fixme: rewrite using shared_ptr...
|
2014-05-16 11:37:31 +00:00
|
|
|
if( m_lastNode )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
|
|
|
delete m_lastNode;
|
2019-08-07 21:49:35 +00:00
|
|
|
m_lastNode = nullptr;
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
|
|
|
|
2019-08-07 21:49:35 +00:00
|
|
|
m_lastNode = m_world->Branch();
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
switch( m_mode )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2017-08-03 15:53:07 +00:00
|
|
|
case DM_SEGMENT:
|
|
|
|
case DM_CORNER:
|
2015-10-05 16:28:41 +00:00
|
|
|
{
|
2019-05-17 00:13:21 +00:00
|
|
|
//TODO: Make threshhold configurable
|
|
|
|
int thresh = Settings().SmoothDraggedSegments() ? m_draggedLine.Width() / 4 : 0;
|
2019-08-07 21:49:35 +00:00
|
|
|
LINE origLine( m_draggedLine );
|
2016-08-29 17:31:13 +00:00
|
|
|
LINE dragged( m_draggedLine );
|
2019-05-17 00:13:21 +00:00
|
|
|
dragged.SetSnapThreshhold( thresh );
|
2020-04-15 20:16:24 +00:00
|
|
|
dragged.ClearLinks();
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2017-08-03 15:53:07 +00:00
|
|
|
if( m_mode == DM_SEGMENT )
|
2019-05-17 00:13:21 +00:00
|
|
|
dragged.DragSegment( aP, m_draggedSegmentIndex );
|
2015-10-05 16:28:41 +00:00
|
|
|
else
|
2019-05-17 00:13:21 +00:00
|
|
|
dragged.DragCorner( aP, m_draggedSegmentIndex, m_freeAngleMode );
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2019-08-07 21:49:35 +00:00
|
|
|
m_lastNode->Remove( origLine );
|
|
|
|
m_lastNode->Add( dragged );
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2015-10-05 16:28:41 +00:00
|
|
|
m_draggedItems.Clear();
|
2019-08-07 21:49:35 +00:00
|
|
|
m_draggedItems.Add( dragged );
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2015-10-05 16:28:41 +00:00
|
|
|
break;
|
|
|
|
}
|
2014-05-16 11:37:31 +00:00
|
|
|
|
2017-08-03 15:53:07 +00:00
|
|
|
case DM_VIA: // fixme...
|
2015-10-05 16:28:41 +00:00
|
|
|
{
|
2020-02-06 17:03:18 +00:00
|
|
|
dragViaMarkObstacles( m_initialVia, m_lastNode, aP );
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2015-10-05 16:28:41 +00:00
|
|
|
break;
|
|
|
|
}
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
if( Settings().CanViolateDRC() )
|
2014-05-14 13:53:54 +00:00
|
|
|
m_dragStatus = true;
|
|
|
|
else
|
|
|
|
m_dragStatus = !m_world->CheckColliding( m_draggedItems );
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
|
2020-02-06 17:03:18 +00:00
|
|
|
void DRAGGER::dragViaMarkObstacles( const VIA_HANDLE& aHandle, NODE* aNode, const VECTOR2I& aP )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2015-08-19 15:27:23 +00:00
|
|
|
m_draggedItems.Clear();
|
|
|
|
|
2019-08-07 21:49:35 +00:00
|
|
|
ITEM_SET fanout = findViaFanoutByHandle( aNode, aHandle );
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2019-08-07 21:49:35 +00:00
|
|
|
if( fanout.Empty() )
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for( ITEM* item : fanout.Items() )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
if( const LINE* l = dyn_cast<const LINE*>( item ) )
|
2015-08-03 19:11:51 +00:00
|
|
|
{
|
2016-08-29 17:31:13 +00:00
|
|
|
LINE origLine( *l );
|
|
|
|
LINE draggedLine( *l );
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2019-05-17 00:13:21 +00:00
|
|
|
draggedLine.DragCorner( aP, origLine.CLine().Find( aHandle.pos ), m_freeAngleMode );
|
2020-04-15 20:16:24 +00:00
|
|
|
draggedLine.ClearLinks();
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2015-08-03 19:11:51 +00:00
|
|
|
m_draggedItems.Add( draggedLine );
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2016-08-30 17:01:30 +00:00
|
|
|
m_lastNode->Remove( origLine );
|
2016-08-30 15:28:35 +00:00
|
|
|
m_lastNode->Add( draggedLine );
|
2015-08-03 19:11:51 +00:00
|
|
|
}
|
2019-08-07 21:49:35 +00:00
|
|
|
else if ( VIA *via = dyn_cast<VIA*>( item ) )
|
|
|
|
{
|
|
|
|
auto nvia = Clone( *via );
|
|
|
|
|
|
|
|
nvia->SetPos( aP );
|
|
|
|
m_draggedItems.Add( nvia.get() );
|
|
|
|
|
|
|
|
m_lastNode->Remove( via );
|
|
|
|
m_lastNode->Add( std::move( nvia ) );
|
|
|
|
}
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-06 17:03:18 +00:00
|
|
|
|
|
|
|
void DRAGGER::dragViaWalkaround( const VIA_HANDLE& aHandle, NODE* aNode, const VECTOR2I& aP )
|
|
|
|
{
|
|
|
|
m_draggedItems.Clear();
|
|
|
|
|
|
|
|
ITEM_SET fanout = findViaFanoutByHandle( aNode, aHandle );
|
|
|
|
|
|
|
|
if( fanout.Empty() )
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for( ITEM* item : fanout.Items() )
|
|
|
|
{
|
|
|
|
if( const LINE* l = dyn_cast<const LINE*>( item ) )
|
|
|
|
{
|
|
|
|
LINE origLine( *l );
|
|
|
|
LINE draggedLine( *l );
|
|
|
|
|
2020-02-07 19:57:24 +00:00
|
|
|
draggedLine.DragCorner( aP, origLine.CLine().Find( aHandle.pos ), m_freeAngleMode );
|
2020-04-15 20:16:24 +00:00
|
|
|
draggedLine.ClearLinks();
|
2020-02-06 17:03:18 +00:00
|
|
|
|
|
|
|
m_draggedItems.Add( draggedLine );
|
|
|
|
|
|
|
|
m_lastNode->Remove( origLine );
|
|
|
|
m_lastNode->Add( draggedLine );
|
|
|
|
}
|
|
|
|
else if ( VIA *via = dyn_cast<VIA*>( item ) )
|
|
|
|
{
|
|
|
|
auto nvia = Clone( *via );
|
|
|
|
|
|
|
|
nvia->SetPos( aP );
|
|
|
|
m_draggedItems.Add( nvia.get() );
|
|
|
|
|
|
|
|
m_lastNode->Remove( via );
|
|
|
|
m_lastNode->Add( std::move( nvia ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-08 22:00:12 +00:00
|
|
|
void DRAGGER::optimizeAndUpdateDraggedLine( LINE& dragged, SEG& aDraggedSeg, const VECTOR2I& aP )
|
2020-02-05 15:33:14 +00:00
|
|
|
{
|
|
|
|
VECTOR2D lockV;
|
2020-04-15 20:16:24 +00:00
|
|
|
dragged.ClearLinks();
|
2020-02-05 15:33:14 +00:00
|
|
|
dragged.Unmark();
|
2014-05-16 11:37:31 +00:00
|
|
|
|
2020-02-05 15:33:14 +00:00
|
|
|
lockV = dragged.CLine().NearestPoint( aP );
|
|
|
|
|
2020-02-27 21:02:45 +00:00
|
|
|
if( Settings().GetOptimizeDraggedTrack() )
|
|
|
|
{
|
2020-10-08 22:00:12 +00:00
|
|
|
OPTIMIZER optimizer( m_lastNode );
|
|
|
|
|
|
|
|
optimizer.SetEffortLevel( OPTIMIZER::MERGE_SEGMENTS | OPTIMIZER::KEEP_TOPOLOGY );
|
|
|
|
|
|
|
|
int startV = dragged.CLine().Find( aDraggedSeg.A );
|
|
|
|
int endV = dragged.CLine().Find( aDraggedSeg.B );
|
|
|
|
|
|
|
|
if ( endV > startV )
|
|
|
|
{
|
|
|
|
std::swap(endV, startV);
|
|
|
|
}
|
|
|
|
|
|
|
|
if( startV >= 0 && endV >= 0)
|
|
|
|
{
|
|
|
|
optimizer.SetPreserveVertex( aP );
|
|
|
|
optimizer.SetRestrictVertexRange( startV, endV );
|
|
|
|
optimizer.Optimize( &dragged );
|
|
|
|
}
|
2020-02-27 21:02:45 +00:00
|
|
|
}
|
2020-02-05 15:33:14 +00:00
|
|
|
|
|
|
|
m_lastNode->Add( dragged );
|
|
|
|
m_draggedItems.Clear();
|
|
|
|
m_draggedItems.Add( dragged );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool DRAGGER::dragWalkaround( const VECTOR2I& aP )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
|
|
|
bool ok = false;
|
2020-02-05 15:33:14 +00:00
|
|
|
// fixme: rewrite using shared_ptr...
|
|
|
|
if( m_lastNode )
|
|
|
|
{
|
|
|
|
delete m_lastNode;
|
|
|
|
m_lastNode = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_lastNode = m_world->Branch();
|
|
|
|
|
|
|
|
switch( m_mode )
|
|
|
|
{
|
|
|
|
case DM_SEGMENT:
|
|
|
|
case DM_CORNER:
|
|
|
|
{
|
|
|
|
int thresh = Settings().SmoothDraggedSegments() ? m_draggedLine.Width() / 4 : 0;
|
|
|
|
LINE dragged( m_draggedLine );
|
|
|
|
LINE origLine( m_draggedLine );
|
|
|
|
|
|
|
|
if( m_mode == DM_SEGMENT )
|
2020-07-22 23:04:52 +00:00
|
|
|
dragged.DragSegment( aP, m_draggedSegmentIndex );
|
2020-02-05 15:33:14 +00:00
|
|
|
else
|
2020-07-22 23:04:52 +00:00
|
|
|
dragged.DragCorner( aP, m_draggedSegmentIndex );
|
2020-02-05 15:33:14 +00:00
|
|
|
|
|
|
|
if ( m_world->CheckColliding( &dragged ) )
|
|
|
|
{
|
|
|
|
WALKAROUND walkaround( m_lastNode, Router() );
|
|
|
|
|
|
|
|
walkaround.SetSolidsOnly( false );
|
|
|
|
walkaround.SetDebugDecorator( Dbg() );
|
|
|
|
walkaround.SetLogger( Logger() );
|
|
|
|
walkaround.SetIterationLimit( Settings().WalkaroundIterationLimit() );
|
|
|
|
|
|
|
|
WALKAROUND::RESULT wr = walkaround.Route( dragged );
|
|
|
|
|
|
|
|
//Dbg()->AddLine( wr.lineCw.CLine(), 3, 200000 );
|
|
|
|
//Dbg()->AddLine( wr.lineCcw.CLine(), 2, 200000 );
|
|
|
|
|
|
|
|
if( wr.statusCcw == WALKAROUND::DONE && wr.statusCw == WALKAROUND::DONE )
|
|
|
|
{
|
|
|
|
dragged = ( wr.lineCw.CLine().Length() < wr.lineCcw.CLine().Length() ? wr.lineCw : wr.lineCcw );
|
|
|
|
ok = true;
|
|
|
|
}
|
|
|
|
else if ( wr.statusCw == WALKAROUND::DONE )
|
|
|
|
{
|
|
|
|
dragged = wr.lineCw;
|
|
|
|
ok = true;
|
|
|
|
}
|
|
|
|
else if ( wr.statusCcw == WALKAROUND::DONE )
|
|
|
|
{
|
|
|
|
dragged = wr.lineCcw;
|
|
|
|
ok = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ok = true;
|
|
|
|
}
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2020-02-05 15:33:14 +00:00
|
|
|
if(ok)
|
|
|
|
{
|
|
|
|
m_lastNode->Remove( origLine );
|
2020-10-08 22:00:12 +00:00
|
|
|
SEG dummy;
|
|
|
|
optimizeAndUpdateDraggedLine( dragged, dummy, aP );
|
2020-02-05 15:33:14 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2020-02-06 17:03:18 +00:00
|
|
|
case DM_VIA: // fixme...
|
|
|
|
{
|
|
|
|
dragViaWalkaround( m_initialVia, m_lastNode, aP );
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2020-02-05 15:33:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
m_dragStatus = ok;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DRAGGER::dragShove( const VECTOR2I& aP )
|
|
|
|
{
|
|
|
|
bool ok = false;
|
2020-02-07 19:57:24 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
if( m_lastNode )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
|
|
|
delete m_lastNode;
|
|
|
|
m_lastNode = NULL;
|
|
|
|
}
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
switch( m_mode )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2017-08-03 15:53:07 +00:00
|
|
|
case DM_SEGMENT:
|
|
|
|
case DM_CORNER:
|
2015-10-05 16:28:41 +00:00
|
|
|
{
|
2019-05-17 00:13:21 +00:00
|
|
|
//TODO: Make threshhold configurable
|
|
|
|
int thresh = Settings().SmoothDraggedSegments() ? m_draggedLine.Width() / 2 : 0;
|
2016-08-29 17:31:13 +00:00
|
|
|
LINE dragged( m_draggedLine );
|
2019-05-17 00:13:21 +00:00
|
|
|
dragged.SetSnapThreshhold( thresh );
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2017-08-03 15:53:07 +00:00
|
|
|
if( m_mode == DM_SEGMENT )
|
2019-05-17 00:13:21 +00:00
|
|
|
dragged.DragSegment( aP, m_draggedSegmentIndex );
|
2015-10-05 16:28:41 +00:00
|
|
|
else
|
2019-05-17 00:13:21 +00:00
|
|
|
dragged.DragCorner( aP, m_draggedSegmentIndex );
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
SHOVE::SHOVE_STATUS st = m_shove->ShoveLines( dragged );
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
if( st == SHOVE::SH_OK )
|
2015-10-05 16:28:41 +00:00
|
|
|
ok = true;
|
2016-08-29 17:31:13 +00:00
|
|
|
else if( st == SHOVE::SH_HEAD_MODIFIED )
|
2015-10-05 16:28:41 +00:00
|
|
|
{
|
|
|
|
dragged = m_shove->NewHead();
|
|
|
|
ok = true;
|
|
|
|
}
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2015-10-05 16:28:41 +00:00
|
|
|
m_lastNode = m_shove->CurrentNode()->Branch();
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2015-10-05 16:28:41 +00:00
|
|
|
if( ok )
|
2019-08-07 21:49:35 +00:00
|
|
|
{
|
2020-02-20 23:03:23 +00:00
|
|
|
VECTOR2D lockV;
|
2020-04-15 20:16:24 +00:00
|
|
|
dragged.ClearLinks();
|
2019-08-07 21:49:35 +00:00
|
|
|
dragged.Unmark();
|
2020-02-20 23:03:23 +00:00
|
|
|
|
|
|
|
lockV = dragged.CLine().NearestPoint( aP );
|
|
|
|
|
2020-02-27 21:02:45 +00:00
|
|
|
if( Settings().GetOptimizeDraggedTrack() )
|
|
|
|
{
|
|
|
|
OPTIMIZER::Optimize( &dragged, OPTIMIZER::MERGE_SEGMENTS
|
|
|
|
| OPTIMIZER::KEEP_TOPOLOGY
|
|
|
|
| OPTIMIZER::PRESERVE_VERTEX, m_lastNode, lockV );
|
|
|
|
}
|
2020-02-20 23:03:23 +00:00
|
|
|
|
2019-08-07 21:49:35 +00:00
|
|
|
m_lastNode->Add( dragged );
|
|
|
|
m_draggedItems.Clear();
|
|
|
|
m_draggedItems.Add( dragged );
|
|
|
|
}
|
2014-05-16 11:37:31 +00:00
|
|
|
|
2015-10-05 16:28:41 +00:00
|
|
|
break;
|
|
|
|
}
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2017-08-03 15:53:07 +00:00
|
|
|
case DM_VIA:
|
2015-10-05 16:28:41 +00:00
|
|
|
{
|
2019-08-07 21:49:35 +00:00
|
|
|
VIA_HANDLE newVia;
|
|
|
|
|
|
|
|
SHOVE::SHOVE_STATUS st = m_shove->ShoveDraggingVia( m_draggedVia, aP, newVia );
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
if( st == SHOVE::SH_OK || st == SHOVE::SH_HEAD_MODIFIED )
|
2015-10-05 16:28:41 +00:00
|
|
|
ok = true;
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2015-10-05 16:28:41 +00:00
|
|
|
m_lastNode = m_shove->CurrentNode()->Branch();
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2019-08-07 21:49:35 +00:00
|
|
|
if( newVia.valid )
|
|
|
|
m_draggedVia = newVia;
|
2015-10-05 16:28:41 +00:00
|
|
|
|
2019-08-07 21:49:35 +00:00
|
|
|
m_draggedItems.Clear();
|
2015-10-05 16:28:41 +00:00
|
|
|
break;
|
|
|
|
}
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
m_dragStatus = ok;
|
2014-05-16 11:37:31 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
bool DRAGGER::FixRoute()
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2018-05-08 09:47:14 +00:00
|
|
|
NODE* node = CurrentNode();
|
|
|
|
|
|
|
|
if( node )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2018-09-27 15:07:02 +00:00
|
|
|
// Collisions still prevent fixing unless "Allow DRC violations" is checked
|
|
|
|
if( !m_dragStatus )
|
|
|
|
return false;
|
|
|
|
|
2018-05-08 09:47:14 +00:00
|
|
|
Router()->CommitRouting( node );
|
2014-05-14 13:53:54 +00:00
|
|
|
return true;
|
2014-11-14 19:19:00 +00:00
|
|
|
}
|
2014-05-14 13:53:54 +00:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2014-05-16 11:37:31 +00:00
|
|
|
|
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
bool DRAGGER::Drag( const VECTOR2I& aP )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2017-08-03 15:53:07 +00:00
|
|
|
if( m_freeAngleMode )
|
|
|
|
return dragMarkObstacles( aP );
|
|
|
|
|
2014-11-14 19:19:00 +00:00
|
|
|
switch( m_currentMode )
|
|
|
|
{
|
2015-10-05 16:28:41 +00:00
|
|
|
case RM_MarkObstacles:
|
|
|
|
return dragMarkObstacles( aP );
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2015-10-05 16:28:41 +00:00
|
|
|
case RM_Shove:
|
|
|
|
case RM_Smart:
|
|
|
|
return dragShove( aP );
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2020-02-05 15:33:14 +00:00
|
|
|
case RM_Walkaround:
|
|
|
|
return dragWalkaround( aP );
|
|
|
|
|
2015-10-05 16:28:41 +00:00
|
|
|
default:
|
|
|
|
return false;
|
2014-11-14 19:19:00 +00:00
|
|
|
}
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
NODE* DRAGGER::CurrentNode() const
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
|
|
|
return m_lastNode;
|
|
|
|
}
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
|
2016-08-29 17:31:13 +00:00
|
|
|
const ITEM_SET DRAGGER::Traces()
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
|
|
|
return m_draggedItems;
|
|
|
|
}
|
|
|
|
|
2016-08-29 14:38:11 +00:00
|
|
|
}
|