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.

106 lines
2.7 KiB

5 years ago
  1. /*
  2. * KiRouter - a push-and-(sometimes-)shove PCB router
  3. *
  4. * Copyright (C) 2013-2014 CERN
  5. * Copyright (C) 2016-2023 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. #include <math/vector2d.h>
  22. #include <geometry/shape.h>
  23. #include <geometry/shape_line_chain.h>
  24. #include <geometry/shape_circle.h>
  25. #include <geometry/shape_compound.h>
  26. #include <geometry/shape_poly_set.h>
  27. #include <wx/log.h>
  28. #include "pns_router.h"
  29. #include "pns_solid.h"
  30. #include "pns_utils.h"
  31. namespace PNS {
  32. const SHAPE_LINE_CHAIN SOLID::Hull( int aClearance, int aWalkaroundThickness, int aLayer ) const
  33. {
  34. if( !m_shape )
  35. return SHAPE_LINE_CHAIN();
  36. if( m_shape->Type() == SH_COMPOUND )
  37. {
  38. SHAPE_COMPOUND* cmpnd = static_cast<SHAPE_COMPOUND*>( m_shape );
  39. if ( cmpnd->Shapes().size() == 1 )
  40. {
  41. return BuildHullForPrimitiveShape( cmpnd->Shapes()[0], aClearance,
  42. aWalkaroundThickness );
  43. }
  44. else
  45. {
  46. SHAPE_POLY_SET hullSet;
  47. for( SHAPE* shape : cmpnd->Shapes() )
  48. {
  49. hullSet.AddOutline( BuildHullForPrimitiveShape( shape, aClearance,
  50. aWalkaroundThickness ) );
  51. }
  52. hullSet.Simplify( SHAPE_POLY_SET::PM_STRICTLY_SIMPLE );
  53. return hullSet.Outline( 0 );
  54. }
  55. }
  56. else
  57. {
  58. return BuildHullForPrimitiveShape( m_shape, aClearance, aWalkaroundThickness );
  59. }
  60. }
  61. ITEM* SOLID::Clone() const
  62. {
  63. ITEM* solid = new SOLID( *this );
  64. return solid;
  65. }
  66. void SOLID::SetPos( const VECTOR2I& aCenter )
  67. {
  68. VECTOR2I delta = aCenter - m_pos;
  69. if( m_shape )
  70. m_shape->Move( delta );
  71. if( m_hole )
  72. m_hole->Move( delta );
  73. m_pos = aCenter;
  74. }
  75. VECTOR2I SOLID::Anchor( int aN ) const
  76. {
  77. return m_anchorPoints.empty() ? m_pos : m_anchorPoints[aN];
  78. }
  79. int SOLID::AnchorCount() const
  80. {
  81. return m_anchorPoints.empty() ? 1 : m_anchorPoints.size();
  82. }
  83. }