router: use a common base class for all dragging algorithms
This commit is contained in:
parent
1d0ee66187
commit
b6e059f018
|
@ -0,0 +1,115 @@
|
||||||
|
/*
|
||||||
|
* KiRouter - a push-and-(sometimes-)shove PCB router
|
||||||
|
*
|
||||||
|
* Copyright (C) 2013-2020 CERN
|
||||||
|
* Copyright (C) 2016 KiCad Developers, see AUTHORS.txt for contributors.
|
||||||
|
* 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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __PNS_DRAG_ALGO_H
|
||||||
|
#define __PNS_DRAG_ALGO_H
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
#include <math/vector2d.h>
|
||||||
|
|
||||||
|
#include "pns_algo_base.h"
|
||||||
|
#include "pns_itemset.h"
|
||||||
|
#include "pns_layerset.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace PNS {
|
||||||
|
|
||||||
|
class NODE;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* DRAG_ALGO
|
||||||
|
*
|
||||||
|
* Base class for item dragging algorithms.
|
||||||
|
*/
|
||||||
|
class DRAG_ALGO : public ALGO_BASE
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
DRAG_ALGO( ROUTER* aRouter ) :
|
||||||
|
ALGO_BASE( aRouter )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
~DRAG_ALGO()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function SetWorld()
|
||||||
|
*
|
||||||
|
* Sets the board to work on.
|
||||||
|
*/
|
||||||
|
virtual void SetWorld( NODE* aWorld )
|
||||||
|
{
|
||||||
|
m_world = aWorld;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function Start()
|
||||||
|
*
|
||||||
|
* Starts routing a single track at point aP, taking item aStartItem as anchor
|
||||||
|
* (unless NULL). Returns true if a dragging operation has started.
|
||||||
|
*/
|
||||||
|
virtual bool Start( const VECTOR2I& aP, ITEM_SET& aPrimitives ) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function Drag()
|
||||||
|
*
|
||||||
|
* Drags the current segment/corner/via to the point aP.
|
||||||
|
* @return true, if dragging finished with success.
|
||||||
|
*/
|
||||||
|
virtual bool Drag( const VECTOR2I& aP ) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function FixRoute()
|
||||||
|
*
|
||||||
|
* Checks if the result of current dragging operation is correct
|
||||||
|
* and eventually commits it to the world.
|
||||||
|
* @return true, if dragging finished with success.
|
||||||
|
*/
|
||||||
|
virtual bool FixRoute() = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function CurrentNode()
|
||||||
|
*
|
||||||
|
* Returns the most recent world state, including all
|
||||||
|
* items changed due to dragging operation.
|
||||||
|
*/
|
||||||
|
virtual NODE* CurrentNode() const = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function Traces()
|
||||||
|
*
|
||||||
|
* Returns the set of dragged items.
|
||||||
|
*/
|
||||||
|
virtual const ITEM_SET Traces() = 0;
|
||||||
|
|
||||||
|
virtual void SetMode( int aDragMode ) {};
|
||||||
|
|
||||||
|
protected:
|
||||||
|
NODE* m_world;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace PNS
|
||||||
|
|
||||||
|
#endif
|
|
@ -30,7 +30,7 @@
|
||||||
namespace PNS {
|
namespace PNS {
|
||||||
|
|
||||||
DRAGGER::DRAGGER( ROUTER* aRouter ) :
|
DRAGGER::DRAGGER( ROUTER* aRouter ) :
|
||||||
ALGO_BASE( aRouter )
|
DRAG_ALGO( aRouter )
|
||||||
{
|
{
|
||||||
m_world = NULL;
|
m_world = NULL;
|
||||||
m_lastNode = NULL;
|
m_lastNode = NULL;
|
||||||
|
@ -47,12 +47,6 @@ DRAGGER::~DRAGGER()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void DRAGGER::SetWorld( NODE* aWorld )
|
|
||||||
{
|
|
||||||
m_world = aWorld;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool DRAGGER::startDragSegment( const VECTOR2D& aP, SEGMENT* aSeg )
|
bool DRAGGER::startDragSegment( const VECTOR2D& aP, SEGMENT* aSeg )
|
||||||
{
|
{
|
||||||
int w2 = aSeg->Width() / 2;
|
int w2 = aSeg->Width() / 2;
|
||||||
|
@ -145,8 +139,13 @@ const ITEM_SET DRAGGER::findViaFanoutByHandle ( NODE *aNode, const VIA_HANDLE& h
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DRAGGER::Start( const VECTOR2I& aP, ITEM* aStartItem )
|
bool DRAGGER::Start( const VECTOR2I& aP, ITEM_SET& aPrimitives )
|
||||||
{
|
{
|
||||||
|
if( aPrimitives.Empty() )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
ITEM* startItem = aPrimitives[0];
|
||||||
|
|
||||||
m_lastNode = NULL;
|
m_lastNode = NULL;
|
||||||
m_draggedItems.Clear();
|
m_draggedItems.Clear();
|
||||||
m_currentMode = Settings().Mode();
|
m_currentMode = Settings().Mode();
|
||||||
|
@ -159,20 +158,20 @@ bool DRAGGER::Start( const VECTOR2I& aP, ITEM* aStartItem )
|
||||||
m_shove->SetDebugDecorator( Dbg() );
|
m_shove->SetDebugDecorator( Dbg() );
|
||||||
}
|
}
|
||||||
|
|
||||||
aStartItem->Unmark( MK_LOCKED );
|
startItem->Unmark( MK_LOCKED );
|
||||||
|
|
||||||
wxLogTrace( "PNS", "StartDragging: item %p [kind %d]", aStartItem, (int) aStartItem->Kind() );
|
wxLogTrace( "PNS", "StartDragging: item %p [kind %d]", startItem, (int) startItem->Kind() );
|
||||||
|
|
||||||
switch( aStartItem->Kind() )
|
switch( startItem->Kind() )
|
||||||
{
|
{
|
||||||
case ITEM::SEGMENT_T:
|
case ITEM::SEGMENT_T:
|
||||||
return startDragSegment( aP, static_cast<SEGMENT*>( aStartItem ) );
|
return startDragSegment( aP, static_cast<SEGMENT*>( startItem ) );
|
||||||
|
|
||||||
case ITEM::VIA_T:
|
case ITEM::VIA_T:
|
||||||
return startDragVia( static_cast<VIA*>( aStartItem ) );
|
return startDragVia( static_cast<VIA*>( startItem ) );
|
||||||
|
|
||||||
case ITEM::ARC_T:
|
case ITEM::ARC_T:
|
||||||
return startDragArc( aP, static_cast<ARC*>( aStartItem ) );
|
return startDragArc( aP, static_cast<ARC*>( startItem ) );
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
#include "pns_node.h"
|
#include "pns_node.h"
|
||||||
#include "pns_via.h"
|
#include "pns_via.h"
|
||||||
#include "pns_line.h"
|
#include "pns_line.h"
|
||||||
#include "pns_algo_base.h"
|
#include "pns_drag_algo.h"
|
||||||
#include "pns_itemset.h"
|
#include "pns_itemset.h"
|
||||||
#include "pns_layerset.h"
|
#include "pns_layerset.h"
|
||||||
|
|
||||||
|
@ -44,26 +44,19 @@ class OPTIMIZER;
|
||||||
*
|
*
|
||||||
* Via, segment and corner dragging algorithm.
|
* Via, segment and corner dragging algorithm.
|
||||||
*/
|
*/
|
||||||
class DRAGGER : public ALGO_BASE
|
class DRAGGER : public DRAG_ALGO
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
DRAGGER( ROUTER* aRouter );
|
DRAGGER( ROUTER* aRouter );
|
||||||
~DRAGGER();
|
~DRAGGER();
|
||||||
|
|
||||||
/**
|
|
||||||
* Function SetWorld()
|
|
||||||
*
|
|
||||||
* Sets the board to work on.
|
|
||||||
*/
|
|
||||||
void SetWorld( NODE* aWorld );
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function Start()
|
* Function Start()
|
||||||
*
|
*
|
||||||
* Starts routing a single track at point aP, taking item aStartItem as anchor
|
* Starts routing a single track at point aP, taking item aStartItem as anchor
|
||||||
* (unless NULL). Returns true if a dragging operation has started.
|
* (unless NULL). Returns true if a dragging operation has started.
|
||||||
*/
|
*/
|
||||||
bool Start( const VECTOR2I& aP, ITEM* aStartItem );
|
virtual bool Start( const VECTOR2I& aP, ITEM_SET& aPrimitives ) override;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function Drag()
|
* Function Drag()
|
||||||
|
@ -71,7 +64,7 @@ public:
|
||||||
* Drags the current segment/corner/via to the point aP.
|
* Drags the current segment/corner/via to the point aP.
|
||||||
* @return true, if dragging finished with success.
|
* @return true, if dragging finished with success.
|
||||||
*/
|
*/
|
||||||
bool Drag( const VECTOR2I& aP );
|
bool Drag( const VECTOR2I& aP ) override;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function FixRoute()
|
* Function FixRoute()
|
||||||
|
@ -80,7 +73,7 @@ public:
|
||||||
* and eventually commits it to the world.
|
* and eventually commits it to the world.
|
||||||
* @return true, if dragging finished with success.
|
* @return true, if dragging finished with success.
|
||||||
*/
|
*/
|
||||||
bool FixRoute();
|
bool FixRoute() override;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function CurrentNode()
|
* Function CurrentNode()
|
||||||
|
@ -88,16 +81,16 @@ public:
|
||||||
* Returns the most recent world state, including all
|
* Returns the most recent world state, including all
|
||||||
* items changed due to dragging operation.
|
* items changed due to dragging operation.
|
||||||
*/
|
*/
|
||||||
NODE* CurrentNode() const;
|
NODE* CurrentNode() const override;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function Traces()
|
* Function Traces()
|
||||||
*
|
*
|
||||||
* Returns the set of dragged items.
|
* Returns the set of dragged items.
|
||||||
*/
|
*/
|
||||||
const ITEM_SET Traces();
|
const ITEM_SET Traces() override;
|
||||||
|
|
||||||
void SetMode( int aDragMode );
|
void SetMode( int aDragMode ) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
@ -116,7 +109,6 @@ private:
|
||||||
VIA_HANDLE m_initialVia;
|
VIA_HANDLE m_initialVia;
|
||||||
VIA_HANDLE m_draggedVia;
|
VIA_HANDLE m_draggedVia;
|
||||||
|
|
||||||
NODE* m_world;
|
|
||||||
NODE* m_lastNode;
|
NODE* m_lastNode;
|
||||||
int m_mode;
|
int m_mode;
|
||||||
LINE m_draggedLine;
|
LINE m_draggedLine;
|
||||||
|
|
Loading…
Reference in New Issue