From b6e059f0180e7bde3ea38c5eb90b7197106c0599 Mon Sep 17 00:00:00 2001 From: Tomasz Wlostowski Date: Fri, 28 Feb 2020 23:08:34 +0100 Subject: [PATCH] router: use a common base class for all dragging algorithms --- pcbnew/router/pns_drag_algo.h | 115 ++++++++++++++++++++++++++++++++++ pcbnew/router/pns_dragger.cpp | 27 ++++---- pcbnew/router/pns_dragger.h | 24 +++---- 3 files changed, 136 insertions(+), 30 deletions(-) create mode 100644 pcbnew/router/pns_drag_algo.h diff --git a/pcbnew/router/pns_drag_algo.h b/pcbnew/router/pns_drag_algo.h new file mode 100644 index 0000000000..ca9b7beae8 --- /dev/null +++ b/pcbnew/router/pns_drag_algo.h @@ -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 + * + * 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 . + */ + +#ifndef __PNS_DRAG_ALGO_H +#define __PNS_DRAG_ALGO_H + +#include +#include + +#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 diff --git a/pcbnew/router/pns_dragger.cpp b/pcbnew/router/pns_dragger.cpp index 9f1eba4a0b..2f24803f74 100644 --- a/pcbnew/router/pns_dragger.cpp +++ b/pcbnew/router/pns_dragger.cpp @@ -30,7 +30,7 @@ namespace PNS { DRAGGER::DRAGGER( ROUTER* aRouter ) : - ALGO_BASE( aRouter ) + DRAG_ALGO( aRouter ) { m_world = 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 ) { int w2 = aSeg->Width() / 2; @@ -145,8 +139,13 @@ const ITEM_SET DRAGGER::findViaFanoutByHandle ( NODE *aNode, const VIA_HANDLE& h 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_draggedItems.Clear(); m_currentMode = Settings().Mode(); @@ -159,20 +158,20 @@ bool DRAGGER::Start( const VECTOR2I& aP, ITEM* aStartItem ) 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: - return startDragSegment( aP, static_cast( aStartItem ) ); + return startDragSegment( aP, static_cast( startItem ) ); case ITEM::VIA_T: - return startDragVia( static_cast( aStartItem ) ); + return startDragVia( static_cast( startItem ) ); case ITEM::ARC_T: - return startDragArc( aP, static_cast( aStartItem ) ); + return startDragArc( aP, static_cast( startItem ) ); default: return false; diff --git a/pcbnew/router/pns_dragger.h b/pcbnew/router/pns_dragger.h index 51f00968a0..b5be6f19a0 100644 --- a/pcbnew/router/pns_dragger.h +++ b/pcbnew/router/pns_dragger.h @@ -28,7 +28,7 @@ #include "pns_node.h" #include "pns_via.h" #include "pns_line.h" -#include "pns_algo_base.h" +#include "pns_drag_algo.h" #include "pns_itemset.h" #include "pns_layerset.h" @@ -44,26 +44,19 @@ class OPTIMIZER; * * Via, segment and corner dragging algorithm. */ -class DRAGGER : public ALGO_BASE +class DRAGGER : public DRAG_ALGO { public: DRAGGER( ROUTER* aRouter ); ~DRAGGER(); - /** - * Function SetWorld() - * - * Sets the board to work on. - */ - void SetWorld( NODE* 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. */ - bool Start( const VECTOR2I& aP, ITEM* aStartItem ); + virtual bool Start( const VECTOR2I& aP, ITEM_SET& aPrimitives ) override; /** * Function Drag() @@ -71,7 +64,7 @@ public: * Drags the current segment/corner/via to the point aP. * @return true, if dragging finished with success. */ - bool Drag( const VECTOR2I& aP ); + bool Drag( const VECTOR2I& aP ) override; /** * Function FixRoute() @@ -80,7 +73,7 @@ public: * and eventually commits it to the world. * @return true, if dragging finished with success. */ - bool FixRoute(); + bool FixRoute() override; /** * Function CurrentNode() @@ -88,16 +81,16 @@ public: * Returns the most recent world state, including all * items changed due to dragging operation. */ - NODE* CurrentNode() const; + NODE* CurrentNode() const override; /** * Function Traces() * * 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: @@ -116,7 +109,6 @@ private: VIA_HANDLE m_initialVia; VIA_HANDLE m_draggedVia; - NODE* m_world; NODE* m_lastNode; int m_mode; LINE m_draggedLine;