1 /* 2 * KiRouter - a push-and-(sometimes-)shove PCB router 3 * 4 * Copyright (C) 2013-2014 CERN 5 * Copyright (C) 2016 KiCad Developers, see AUTHORS.txt for contributors. 6 * Author: Tomasz Wlostowski <tomasz.wlostowski@cern.ch> 7 * 8 * This program is free software: you can redistribute it and/or modify it 9 * under the terms of the GNU General Public License as published by the 10 * Free Software Foundation, either version 3 of the License, or (at your 11 * option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, but 14 * WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 * General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License along 19 * with this program. If not, see <http://www.gnu.org/licenses/>. 20 */ 21 22 #ifndef __PNS_PLACEMENT_ALGO_H 23 #define __PNS_PLACEMENT_ALGO_H 24 25 #include <math/vector2d.h> 26 27 #include "pns_algo_base.h" 28 #include "pns_sizes_settings.h" 29 #include "pns_itemset.h" 30 31 namespace PNS { 32 33 class ROUTER; 34 class ITEM; 35 class NODE; 36 37 /** 38 * PLACEMENT_ALGO 39 * 40 * Abstract class for a P&S placement/dragging algorithm. 41 * All subtools (drag, single/diff pair routing and meandering) 42 * are derived from it. 43 */ 44 45 class PLACEMENT_ALGO : public ALGO_BASE 46 { 47 public: PLACEMENT_ALGO(ROUTER * aRouter)48 PLACEMENT_ALGO( ROUTER* aRouter ) : 49 ALGO_BASE( aRouter ) {}; 50 ~PLACEMENT_ALGO()51 virtual ~PLACEMENT_ALGO () {}; 52 53 /** 54 * Function Start() 55 * 56 * Starts placement/drag operation at point aP, taking item aStartItem as anchor 57 * (unless NULL). 58 */ 59 virtual bool Start( const VECTOR2I& aP, ITEM* aStartItem ) = 0; 60 61 /** 62 * Function Move() 63 * 64 * Moves the end of the currently routed primtive(s) to the point aP, taking 65 * aEndItem as the anchor (if not NULL). 66 * (unless NULL). 67 */ 68 virtual bool Move( const VECTOR2I& aP, ITEM* aEndItem ) = 0; 69 70 /** 71 * Function FixRoute() 72 * 73 * Commits the currently routed items to the parent node, taking 74 * aP as the final end point and aEndItem as the final anchor (if provided). 75 * @return true, if route has been committed. May return false if the routing 76 * result is violating design rules - in such case, the track is only committed 77 * if Settings.CanViolateDRC() is on. 78 */ 79 virtual bool FixRoute( const VECTOR2I& aP, ITEM* aEndItem, bool aForceFinish = false ) = 0; 80 UnfixRoute()81 virtual bool UnfixRoute() { return false; }; 82 CommitPlacement()83 virtual bool CommitPlacement() { return false; }; 84 AbortPlacement()85 virtual bool AbortPlacement() { return false; }; 86 HasPlacedAnything()87 virtual bool HasPlacedAnything() const { return false; } 88 89 /** 90 * Function ToggleVia() 91 * 92 * Enables/disables a via at the end of currently routed trace. 93 */ ToggleVia(bool aEnabled)94 virtual bool ToggleVia( bool aEnabled ) 95 { 96 return false; 97 } 98 99 /** 100 * Function IsPlacingVia() 101 * 102 * Returns true if the placer is placing a via (or more vias). 103 */ IsPlacingVia()104 virtual bool IsPlacingVia() const 105 { 106 return false; 107 } 108 109 /** 110 * Function SetLayer() 111 * 112 * Sets the current routing layer. 113 */ SetLayer(int aLayer)114 virtual bool SetLayer( int aLayer ) 115 { 116 return false; 117 } 118 119 /** 120 * Function Traces() 121 * 122 * Returns all routed/tuned traces. 123 */ 124 virtual const ITEM_SET Traces() = 0; 125 126 /** 127 * Function CurrentEnd() 128 * 129 * Returns the current end of the line(s) being placed/tuned. It may not be equal 130 * to the cursor position due to collisions. 131 */ 132 virtual const VECTOR2I& CurrentEnd() const = 0; 133 134 /** 135 * Function CurrentNets() 136 * 137 * Returns the net code(s) of currently routed track(s). 138 */ 139 virtual const std::vector<int> CurrentNets() const = 0; 140 141 /** 142 * Function CurrentLayer() 143 * 144 * Returns the layer of currently routed track. 145 */ 146 virtual int CurrentLayer() const = 0; 147 148 /** 149 * Function CurrentNode() 150 * 151 * Returns the most recent board state. 152 */ 153 virtual NODE* CurrentNode( bool aLoopsRemoved = false ) const = 0; 154 155 /** 156 * Function FlipPosture() 157 * 158 * Toggles the current posture (straight/diagonal) of the trace head. 159 */ FlipPosture()160 virtual void FlipPosture() 161 { 162 } 163 164 /** 165 * Function UpdateSizes() 166 * 167 * Performs on-the-fly update of the width, via diameter & drill size from 168 * a settings class. Used to dynamically change these parameters as 169 * the track is routed. 170 */ UpdateSizes(const SIZES_SETTINGS & aSizes)171 virtual void UpdateSizes( const SIZES_SETTINGS& aSizes ) 172 { 173 } 174 175 /** 176 * Function SetOrthoMode() 177 * 178 * Forces the router to place a straight 90/45 degree trace (with the end 179 * as near to the cursor as possible) instead of a standard 135 degree 180 * two-segment bend. 181 */ SetOrthoMode(bool aOrthoMode)182 virtual void SetOrthoMode ( bool aOrthoMode ) 183 { 184 } 185 186 /** 187 * Function GetModifiedNets 188 * 189 * Returns the net codes of all currently routed trace(s) 190 */ GetModifiedNets(std::vector<int> & aNets)191 virtual void GetModifiedNets( std::vector<int> &aNets ) const 192 { 193 } 194 195 196 }; 197 198 } 199 200 #endif 201