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.

112 lines
3.5 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2019 KiCad Developers, see AUTHORS.txt for contributors.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version 2
  9. * of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, you may find one here:
  18. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  19. * or you may search the http://www.gnu.org website for the version 2 license,
  20. * or you may write to the Free Software Foundation, Inc.,
  21. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  22. */
  23. #include <pcbnew_utils/board_construction_utils.h>
  24. #include <class_edge_mod.h>
  25. #include <class_module.h>
  26. #include <drc/drc.h>
  27. #include <geometry/seg.h>
  28. #include <math/vector2d.h>
  29. namespace KI_TEST
  30. {
  31. void DrawSegment( MODULE& aMod, const SEG& aSeg, int aWidth, PCB_LAYER_ID aLayer )
  32. {
  33. auto seg = std::make_unique<EDGE_MODULE>( &aMod, STROKE_T::S_SEGMENT );
  34. seg->SetStart0( (wxPoint) aSeg.A );
  35. seg->SetEnd0( (wxPoint) aSeg.B );
  36. seg->SetWidth( aWidth );
  37. seg->SetLayer( aLayer );
  38. aMod.Add( seg.release() );
  39. }
  40. void DrawPolyline(
  41. MODULE& aMod, const std::vector<VECTOR2I>& aPts, int aWidth, PCB_LAYER_ID aLayer )
  42. {
  43. for( unsigned i = 0; i < aPts.size() - 1; ++i )
  44. {
  45. DrawSegment( aMod, { aPts[i], aPts[i + 1] }, aWidth, aLayer );
  46. }
  47. }
  48. void DrawArc( MODULE& aMod, const VECTOR2I& aCentre, const VECTOR2I& aStart, double aAngle,
  49. int aWidth, PCB_LAYER_ID aLayer )
  50. {
  51. auto seg = std::make_unique<EDGE_MODULE>( &aMod, STROKE_T::S_ARC );
  52. seg->SetStart0( (wxPoint) aCentre );
  53. seg->SetEnd0( (wxPoint) aStart );
  54. seg->SetAngle( aAngle * 10 );
  55. seg->SetWidth( aWidth );
  56. seg->SetLayer( aLayer );
  57. aMod.Add( seg.release() );
  58. }
  59. void DrawRect( MODULE& aMod, const VECTOR2I& aPos, const VECTOR2I& aSize, int aRadius, int aWidth,
  60. PCB_LAYER_ID aLayer )
  61. {
  62. const auto x_r = aPos.x + aSize.x / 2;
  63. const auto x_l = aPos.x - aSize.x / 2;
  64. const auto y_t = aPos.y + aSize.y / 2;
  65. const auto y_b = aPos.y - aSize.y / 2;
  66. const auto xin_r = x_r - aRadius;
  67. const auto xin_l = x_l + aRadius;
  68. const auto yin_t = y_t - aRadius;
  69. const auto yin_b = y_b + aRadius;
  70. // If non-zero (could be zero if it's a stadium shape)
  71. if( xin_l != xin_r )
  72. {
  73. DrawSegment( aMod, { { xin_l, y_t }, { xin_r, y_t } }, aWidth, aLayer );
  74. DrawSegment( aMod, { { xin_l, y_b }, { xin_r, y_b } }, aWidth, aLayer );
  75. }
  76. if( yin_b != yin_t )
  77. {
  78. DrawSegment( aMod, { { x_l, yin_b }, { x_l, yin_t } }, aWidth, aLayer );
  79. DrawSegment( aMod, { { x_r, yin_b }, { x_r, yin_t } }, aWidth, aLayer );
  80. }
  81. if( aRadius > 0 )
  82. {
  83. DrawArc( aMod, { xin_r, yin_t }, { x_r, yin_t }, 90, aWidth, aLayer );
  84. DrawArc( aMod, { xin_l, yin_t }, { xin_l, y_t }, 90, aWidth, aLayer );
  85. DrawArc( aMod, { xin_l, yin_b }, { x_l, yin_b }, 90, aWidth, aLayer );
  86. DrawArc( aMod, { xin_r, yin_b }, { xin_r, y_b }, 90, aWidth, aLayer );
  87. }
  88. }
  89. } // namespace KI_TEST