You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

135 lines
2.9 KiB

11 years ago
11 years ago
11 years ago
  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. #ifndef __PNS_SEGMENT_H
  22. #define __PNS_SEGMENT_H
  23. #include <math/vector2d.h>
  24. #include <geometry/seg.h>
  25. #include <geometry/shape_segment.h>
  26. #include <geometry/shape_line_chain.h>
  27. #include "pns_item.h"
  28. #include "pns_line.h"
  29. namespace PNS {
  30. class NODE;
  31. class SEGMENT : public ITEM
  32. {
  33. public:
  34. SEGMENT() :
  35. ITEM( SEGMENT_T )
  36. {}
  37. SEGMENT( const SEG& aSeg, int aNet ) :
  38. ITEM( SEGMENT_T ), m_seg( aSeg, 0 )
  39. {
  40. m_net = aNet;
  41. }
  42. SEGMENT( const LINE& aParentLine, const SEG& aSeg ) :
  43. ITEM( SEGMENT_T ),
  44. m_seg( aSeg, aParentLine.Width() )
  45. {
  46. m_net = aParentLine.Net();
  47. m_layers = aParentLine.Layers();
  48. m_marker = aParentLine.Marker();
  49. m_rank = aParentLine.Rank();
  50. }
  51. static inline bool ClassOf( const ITEM* aItem )
  52. {
  53. return aItem && SEGMENT_T == aItem->Kind();
  54. }
  55. SEGMENT* Clone() const override;
  56. const SHAPE* Shape() const override
  57. {
  58. return static_cast<const SHAPE*>( &m_seg );
  59. }
  60. void SetLayer( int aLayer )
  61. {
  62. SetLayers( LAYER_RANGE( aLayer ) );
  63. }
  64. int Layer() const override
  65. {
  66. return Layers().Start();
  67. }
  68. void SetWidth( int aWidth )
  69. {
  70. m_seg.SetWidth(aWidth);
  71. }
  72. int Width() const
  73. {
  74. return m_seg.GetWidth();
  75. }
  76. const SEG& Seg() const
  77. {
  78. return m_seg.GetSeg();
  79. }
  80. const SHAPE_LINE_CHAIN CLine() const
  81. {
  82. return SHAPE_LINE_CHAIN( m_seg.GetSeg().A, m_seg.GetSeg().B );
  83. }
  84. void SetEnds( const VECTOR2I& a, const VECTOR2I& b )
  85. {
  86. m_seg.SetSeg( SEG ( a, b ) );
  87. }
  88. void SwapEnds()
  89. {
  90. SEG tmp = m_seg.GetSeg();
  91. m_seg.SetSeg( SEG (tmp.B , tmp.A ) );
  92. }
  93. const SHAPE_LINE_CHAIN Hull( int aClearance, int aWalkaroundThickness ) const override;
  94. virtual VECTOR2I Anchor( int n ) const override
  95. {
  96. if( n == 0 )
  97. return m_seg.GetSeg().A;
  98. else
  99. return m_seg.GetSeg().B;
  100. }
  101. virtual int AnchorCount() const override
  102. {
  103. return 2;
  104. }
  105. private:
  106. SHAPE_SEGMENT m_seg;
  107. };
  108. }
  109. #endif