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.

193 lines
5.4 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2007, 2008 Lubo Racko <developer@lura.sk>
  5. * Copyright (C) 2007, 2008, 2012-2013 Alexander Lunev <al.lunev@yahoo.com>
  6. * Copyright (C) 2012 KiCad Developers, see CHANGELOG.TXT for contributors.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version 2
  11. * of the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, you may find one here:
  20. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  21. * or you may search the http://www.gnu.org website for the version 2 license,
  22. * or you may write to the Free Software Foundation, Inc.,
  23. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  24. */
  25. /**
  26. * @file pcb_arc.cpp
  27. */
  28. #include <wx/wx.h>
  29. #include <wx/config.h>
  30. #include <common.h>
  31. #include <trigo.h>
  32. #include <pcb_arc.h>
  33. namespace PCAD2KICAD {
  34. PCB_ARC::PCB_ARC( PCB_CALLBACKS* aCallbacks, BOARD* aBoard ) : PCB_COMPONENT( aCallbacks, aBoard )
  35. {
  36. m_objType = wxT( 'A' );
  37. m_startX = 0;
  38. m_startY = 0;
  39. m_angle = 0;
  40. m_width = 0;
  41. }
  42. PCB_ARC::~PCB_ARC()
  43. {
  44. }
  45. void PCB_ARC::Parse( XNODE* aNode,
  46. int aLayer,
  47. wxString aDefaultMeasurementUnit,
  48. wxString aActualConversion )
  49. {
  50. XNODE* lNode;
  51. double a = 0.0;
  52. int r = 0;
  53. int endX = 0;
  54. int endY = 0;
  55. m_PCadLayer = aLayer;
  56. m_KiCadLayer = GetKiCadLayer();
  57. if( FindNode( aNode, wxT( "width" ) ) )
  58. SetWidth( FindNode( aNode, wxT( "width" ) )->GetNodeContent(),
  59. aDefaultMeasurementUnit, &m_width, aActualConversion );
  60. if( aNode->GetName() == wxT( "triplePointArc" ) )
  61. {
  62. // center point
  63. lNode = FindNode( aNode, wxT( "pt" ) );
  64. if( lNode )
  65. SetPosition( lNode->GetNodeContent(), aDefaultMeasurementUnit,
  66. &m_positionX, &m_positionY, aActualConversion );
  67. // start point
  68. if( lNode )
  69. lNode = lNode->GetNext();
  70. if( lNode )
  71. SetPosition( lNode->GetNodeContent(), aDefaultMeasurementUnit,
  72. &m_startX, &m_startY, aActualConversion );
  73. // end point
  74. if( lNode )
  75. lNode = lNode->GetNext();
  76. if( lNode )
  77. SetPosition( lNode->GetNodeContent(), aDefaultMeasurementUnit,
  78. &endX, &endY, aActualConversion );
  79. if( m_startX == endX && m_startY == endY )
  80. {
  81. m_angle = 3600;
  82. }
  83. else
  84. {
  85. double alpha1 = ArcTangente( m_startY - m_positionY, m_startX - m_positionX );
  86. double alpha2 = ArcTangente( endY - m_positionY, endX - m_positionX );
  87. m_angle = alpha1 - alpha2;
  88. NORMALIZE_ANGLE_POS( m_angle );
  89. }
  90. }
  91. else if( aNode->GetName() == wxT( "arc" ) )
  92. {
  93. lNode = FindNode( aNode, wxT( "pt" ) );
  94. if( lNode )
  95. SetPosition( lNode->GetNodeContent(), aDefaultMeasurementUnit,
  96. &m_positionX, &m_positionY, aActualConversion );
  97. lNode = FindNode( aNode, wxT( "radius" ) );
  98. if( lNode)
  99. SetWidth( FindNode( aNode, wxT( "radius" ) )->GetNodeContent(),
  100. aDefaultMeasurementUnit, &r, aActualConversion );
  101. lNode = FindNode( aNode, wxT( "startAngle" ) );
  102. if( lNode )
  103. a = StrToInt1Units( lNode->GetNodeContent() );
  104. lNode = FindNode( aNode, wxT( "sweepAngle" ) );
  105. if( lNode )
  106. m_angle = StrToInt1Units( lNode->GetNodeContent() );
  107. m_startX = m_positionX + KiROUND( cosdecideg( r, a ) );
  108. m_startY = m_positionY - KiROUND( sindecideg( r, a ) );
  109. }
  110. }
  111. void PCB_ARC::SetPosOffset( int aX_offs, int aY_offs )
  112. {
  113. PCB_COMPONENT::SetPosOffset( aX_offs, aY_offs );
  114. m_startX += aX_offs;
  115. m_startY += aY_offs;
  116. }
  117. void PCB_ARC::Flip()
  118. {
  119. PCB_COMPONENT::Flip();
  120. m_startX = -m_startX;
  121. m_angle = -m_angle;
  122. m_KiCadLayer = FlipLayer( m_KiCadLayer );
  123. }
  124. void PCB_ARC::AddToModule( MODULE* aModule )
  125. {
  126. if( IsNonCopperLayer( m_KiCadLayer ) )
  127. {
  128. EDGE_MODULE* arc = new EDGE_MODULE( aModule, S_ARC );
  129. aModule->GraphicalItems().PushBack( arc );
  130. arc->SetAngle( -m_angle );
  131. arc->m_Start0 = wxPoint( m_positionX, m_positionY );
  132. arc->m_End0 = wxPoint( m_startX, m_startY );
  133. arc->SetWidth( m_width );
  134. arc->SetLayer( m_KiCadLayer );
  135. arc->SetDrawCoord();
  136. }
  137. }
  138. void PCB_ARC::AddToBoard()
  139. {
  140. DRAWSEGMENT* dseg = new DRAWSEGMENT( m_board );
  141. m_board->Add( dseg, ADD_APPEND );
  142. dseg->SetShape( S_ARC );
  143. dseg->SetTimeStamp( m_timestamp );
  144. dseg->SetLayer( m_KiCadLayer );
  145. dseg->SetStart( wxPoint( m_positionX, m_positionY ) );
  146. dseg->SetEnd( wxPoint( m_startX, m_startY ) );
  147. dseg->SetAngle( -m_angle );
  148. dseg->SetWidth( m_width );
  149. }
  150. } // namespace PCAD2KICAD