2012-12-29 09:54:25 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2007, 2008 Lubo Racko <developer@lura.sk>
|
2013-03-09 19:36:31 +00:00
|
|
|
* Copyright (C) 2007, 2008, 2012-2013 Alexander Lunev <al.lunev@yahoo.com>
|
2021-10-06 02:46:53 +00:00
|
|
|
* Copyright (C) 2012-2020 KiCad Developers, see AUTHORS.TXT for contributors.
|
2012-12-29 09:54:25 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2021-06-04 00:28:40 +00:00
|
|
|
#include <pcad/pcb_arc.h>
|
2012-12-29 09:54:25 +00:00
|
|
|
|
2021-06-04 00:28:40 +00:00
|
|
|
#include <board.h>
|
|
|
|
#include <footprint.h>
|
2020-10-04 23:34:59 +00:00
|
|
|
#include <fp_shape.h>
|
2021-06-04 00:28:40 +00:00
|
|
|
#include <math/util.h> // for KiROUND
|
2020-10-04 23:34:59 +00:00
|
|
|
#include <pcb_shape.h>
|
2021-06-04 00:28:40 +00:00
|
|
|
#include <trigo.h>
|
|
|
|
#include <xnode.h>
|
|
|
|
|
|
|
|
#include <wx/string.h>
|
2012-12-29 09:54:25 +00:00
|
|
|
|
|
|
|
namespace PCAD2KICAD {
|
|
|
|
|
2021-07-18 12:31:56 +00:00
|
|
|
PCB_ARC::PCB_ARC( PCB_CALLBACKS* aCallbacks, BOARD* aBoard ) :
|
|
|
|
PCB_COMPONENT( aCallbacks, aBoard )
|
2012-12-29 09:54:25 +00:00
|
|
|
{
|
2013-03-09 19:36:31 +00:00
|
|
|
m_objType = wxT( 'A' );
|
2020-11-13 15:15:52 +00:00
|
|
|
m_StartX = 0;
|
|
|
|
m_StartY = 0;
|
2022-01-16 16:15:07 +00:00
|
|
|
m_Angle = ANGLE_0;
|
2020-11-13 15:15:52 +00:00
|
|
|
m_Width = 0;
|
2012-12-29 09:54:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
PCB_ARC::~PCB_ARC()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-07-18 12:31:56 +00:00
|
|
|
void PCB_ARC::Parse( XNODE* aNode, int aLayer, const wxString& aDefaultUnits,
|
2017-09-23 09:20:10 +00:00
|
|
|
const wxString& aActualConversion )
|
2012-12-29 09:54:25 +00:00
|
|
|
{
|
|
|
|
XNODE* lNode;
|
2013-03-09 19:36:31 +00:00
|
|
|
int r = 0;
|
2022-01-16 16:15:07 +00:00
|
|
|
VECTOR2I end;
|
2012-12-29 09:54:25 +00:00
|
|
|
|
|
|
|
m_PCadLayer = aLayer;
|
|
|
|
m_KiCadLayer = GetKiCadLayer();
|
2013-03-09 19:36:31 +00:00
|
|
|
|
2012-12-29 09:54:25 +00:00
|
|
|
if( FindNode( aNode, wxT( "width" ) ) )
|
2021-07-18 12:31:56 +00:00
|
|
|
{
|
|
|
|
SetWidth( FindNode( aNode, wxT( "width" ) )->GetNodeContent(), aDefaultUnits, &m_Width,
|
|
|
|
aActualConversion );
|
|
|
|
}
|
2012-12-29 09:54:25 +00:00
|
|
|
|
|
|
|
if( aNode->GetName() == wxT( "triplePointArc" ) )
|
|
|
|
{
|
|
|
|
// center point
|
|
|
|
lNode = FindNode( aNode, wxT( "pt" ) );
|
|
|
|
|
|
|
|
if( lNode )
|
2021-07-18 12:31:56 +00:00
|
|
|
{
|
|
|
|
SetPosition( lNode->GetNodeContent(), aDefaultUnits, &m_positionX, &m_positionY,
|
|
|
|
aActualConversion );
|
|
|
|
}
|
2012-12-29 09:54:25 +00:00
|
|
|
|
|
|
|
// start point
|
2015-03-14 11:50:39 +00:00
|
|
|
if( lNode )
|
|
|
|
lNode = lNode->GetNext();
|
2012-12-29 09:54:25 +00:00
|
|
|
|
|
|
|
if( lNode )
|
2021-07-18 12:31:56 +00:00
|
|
|
{
|
|
|
|
SetPosition( lNode->GetNodeContent(), aDefaultUnits, &m_StartX, &m_StartY,
|
|
|
|
aActualConversion );
|
|
|
|
}
|
2012-12-29 09:54:25 +00:00
|
|
|
|
|
|
|
// end point
|
2015-03-13 16:48:42 +00:00
|
|
|
if( lNode )
|
|
|
|
lNode = lNode->GetNext();
|
2012-12-29 09:54:25 +00:00
|
|
|
|
|
|
|
if( lNode )
|
2022-01-16 16:15:07 +00:00
|
|
|
{
|
|
|
|
SetPosition( lNode->GetNodeContent(), aDefaultUnits, &end.x, &end.y,
|
|
|
|
aActualConversion );
|
|
|
|
}
|
|
|
|
|
|
|
|
VECTOR2I position( m_positionX, m_positionY );
|
|
|
|
VECTOR2I start( m_StartX, m_StartY );
|
2012-12-29 09:54:25 +00:00
|
|
|
|
2022-01-16 16:15:07 +00:00
|
|
|
if( start == end )
|
2015-06-28 14:02:47 +00:00
|
|
|
{
|
2022-01-16 16:15:07 +00:00
|
|
|
m_Angle = ANGLE_360;
|
2015-06-28 14:02:47 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-01-16 16:15:07 +00:00
|
|
|
EDA_ANGLE alpha1( start - position );
|
|
|
|
EDA_ANGLE alpha2( end - position );
|
2020-11-13 15:15:52 +00:00
|
|
|
m_Angle = alpha1 - alpha2;
|
2015-06-28 14:02:47 +00:00
|
|
|
|
2022-01-16 16:15:07 +00:00
|
|
|
m_Angle.Normalize();
|
2015-06-28 14:02:47 +00:00
|
|
|
}
|
2012-12-29 09:54:25 +00:00
|
|
|
}
|
2013-03-09 19:36:31 +00:00
|
|
|
else if( aNode->GetName() == wxT( "arc" ) )
|
2012-12-29 09:54:25 +00:00
|
|
|
{
|
|
|
|
lNode = FindNode( aNode, wxT( "pt" ) );
|
|
|
|
|
|
|
|
if( lNode )
|
2021-07-18 12:31:56 +00:00
|
|
|
{
|
|
|
|
SetPosition( lNode->GetNodeContent(), aDefaultUnits, &m_positionX, &m_positionY,
|
|
|
|
aActualConversion );
|
|
|
|
}
|
2012-12-29 09:54:25 +00:00
|
|
|
|
|
|
|
lNode = FindNode( aNode, wxT( "radius" ) );
|
2021-07-18 12:31:56 +00:00
|
|
|
|
2012-12-29 09:54:25 +00:00
|
|
|
if( lNode)
|
2021-07-18 12:31:56 +00:00
|
|
|
{
|
|
|
|
SetWidth( FindNode( aNode, wxT( "radius" ) )->GetNodeContent(), aDefaultUnits, &r,
|
|
|
|
aActualConversion );
|
|
|
|
}
|
2013-03-09 19:36:31 +00:00
|
|
|
|
2012-12-29 09:54:25 +00:00
|
|
|
|
|
|
|
lNode = FindNode( aNode, wxT( "startAngle" ) );
|
2021-07-18 12:31:56 +00:00
|
|
|
|
2022-01-16 01:06:25 +00:00
|
|
|
EDA_ANGLE a = ANGLE_0;
|
|
|
|
|
2012-12-29 09:54:25 +00:00
|
|
|
if( lNode )
|
2022-01-16 01:06:25 +00:00
|
|
|
a = EDA_ANGLE( StrToInt1Units( lNode->GetNodeContent() ), TENTHS_OF_A_DEGREE_T );
|
2012-12-29 09:54:25 +00:00
|
|
|
|
|
|
|
lNode = FindNode( aNode, wxT( "sweepAngle" ) );
|
2021-07-18 12:31:56 +00:00
|
|
|
|
2012-12-29 09:54:25 +00:00
|
|
|
if( lNode )
|
2022-01-16 16:15:07 +00:00
|
|
|
m_Angle = EDA_ANGLE( StrToInt1Units( lNode->GetNodeContent() ), TENTHS_OF_A_DEGREE_T );
|
2013-03-09 19:36:31 +00:00
|
|
|
|
2022-01-16 21:15:20 +00:00
|
|
|
m_StartX = m_positionX + KiROUND( r * a.Cos() );
|
|
|
|
m_StartY = m_positionY - KiROUND( r * a.Sin() );
|
2012-12-29 09:54:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PCB_ARC::SetPosOffset( int aX_offs, int aY_offs )
|
|
|
|
{
|
|
|
|
PCB_COMPONENT::SetPosOffset( aX_offs, aY_offs );
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
m_StartX += aX_offs;
|
|
|
|
m_StartY += aY_offs;
|
2012-12-29 09:54:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-09 19:36:31 +00:00
|
|
|
void PCB_ARC::Flip()
|
|
|
|
{
|
|
|
|
PCB_COMPONENT::Flip();
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
m_StartX = -m_StartX;
|
|
|
|
m_Angle = -m_Angle;
|
2013-03-09 19:36:31 +00:00
|
|
|
|
2013-04-05 19:04:58 +00:00
|
|
|
m_KiCadLayer = FlipLayer( m_KiCadLayer );
|
2013-03-09 19:36:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
void PCB_ARC::AddToFootprint( FOOTPRINT* aFootprint )
|
2012-12-29 09:54:25 +00:00
|
|
|
{
|
2013-04-09 16:00:46 +00:00
|
|
|
if( IsNonCopperLayer( m_KiCadLayer ) )
|
2012-12-29 09:54:25 +00:00
|
|
|
{
|
2021-07-21 18:31:25 +00:00
|
|
|
FP_SHAPE* arc = new FP_SHAPE( aFootprint, IsCircle() ? SHAPE_T::CIRCLE : SHAPE_T::ARC );
|
2020-11-13 15:15:52 +00:00
|
|
|
aFootprint->Add( arc );
|
2012-12-29 09:54:25 +00:00
|
|
|
|
2022-01-01 18:57:44 +00:00
|
|
|
arc->SetCenter0( VECTOR2I( m_positionX, m_positionY ) );
|
|
|
|
arc->SetStart0( VECTOR2I( m_StartX, m_StartY ) );
|
2022-01-28 18:20:18 +00:00
|
|
|
arc->SetArcAngleAndEnd0( -m_Angle, true );
|
2020-08-15 15:42:18 +00:00
|
|
|
|
2021-07-17 19:56:18 +00:00
|
|
|
arc->SetStroke( STROKE_PARAMS( m_Width, PLOT_DASH_TYPE::SOLID ) );
|
2012-12-29 09:54:25 +00:00
|
|
|
arc->SetLayer( m_KiCadLayer );
|
|
|
|
|
|
|
|
arc->SetDrawCoord();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PCB_ARC::AddToBoard()
|
|
|
|
{
|
2021-07-17 18:52:13 +00:00
|
|
|
PCB_SHAPE* arc = new PCB_SHAPE( m_board, IsCircle() ? SHAPE_T::CIRCLE : SHAPE_T::ARC );
|
2012-12-29 09:54:25 +00:00
|
|
|
|
2020-10-04 23:34:59 +00:00
|
|
|
m_board->Add( arc, ADD_MODE::APPEND );
|
2012-12-29 09:54:25 +00:00
|
|
|
|
2020-11-14 01:16:02 +00:00
|
|
|
arc->SetFilled( false );
|
2020-10-04 23:34:59 +00:00
|
|
|
arc->SetLayer( m_KiCadLayer );
|
2022-01-01 18:57:44 +00:00
|
|
|
arc->SetCenter( VECTOR2I( m_positionX, m_positionY ) );
|
|
|
|
arc->SetStart( VECTOR2I( m_StartX, m_StartY ) );
|
2022-01-28 18:20:18 +00:00
|
|
|
arc->SetArcAngleAndEnd( -m_Angle, true );
|
2021-07-17 19:56:18 +00:00
|
|
|
arc->SetStroke( STROKE_PARAMS( m_Width, PLOT_DASH_TYPE::SOLID ) );
|
2012-12-29 09:54:25 +00:00
|
|
|
}
|
|
|
|
|
2017-12-10 18:18:21 +00:00
|
|
|
|
|
|
|
bool PCB_ARC::IsCircle()
|
|
|
|
{
|
2022-01-16 16:15:07 +00:00
|
|
|
return ( m_Angle == ANGLE_360 );
|
2017-12-10 18:18:21 +00:00
|
|
|
}
|
|
|
|
|
2012-12-29 09:54:25 +00:00
|
|
|
} // namespace PCAD2KICAD
|