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.

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