KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_cadstar_archive_parser.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The 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, see <https://www.gnu.org/licenses/>.
18 */
19
24
26
28
29#include <qa_utils/geometry/geometry.h> // For KI_TEST::IsVecWithinTol
31#include <geometry/shape_arc.h> // For SHAPE_ARC::DefaultAccuracyForPCB()
32
33
34BOOST_AUTO_TEST_SUITE( CadstartArchiveParser )
35
36
44
45 std::function<wxPoint( const wxPoint& )> m_CadstarToKicadPointCallback;
46
48
49
50static const std::vector<VERTEX_APPEND_CASE> appendToChainCases
51{
52 {
53 "Append a point on x",
54 { vt::VT_POINT, { 500000, 0 } },
55 { /* BBOX Position: */ { 0, 0 }, /* Size:*/ { 500000, 0 } },
56 0
57 },
58 {
59 "Append a point on y",
60 { vt::VT_POINT, { 0, 500000 } },
61 { /* BBOX Position: */ { 0, 0 }, /* Size:*/ { 0, 500000 } },
62 0
63 },
64 {
65 "Append a Semicircle (clockwise)",
66 { vt::CLOCKWISE_SEMICIRCLE, { 500000, 0 } },
67 { /* BBOX Position: */ { 0, 0 }, /* Size: */ { 500000, 250000 } },
68 int( SHAPE_ARC::DefaultAccuracyForPCB() ) // acceptable error when converting to line segments
69 },
70 {
71 "Append a Semicircle (anticlockwise)",
72 { vt::ANTICLOCKWISE_SEMICIRCLE, { 500000, 0 } },
73 { /* BBOX Position: */ { 0, -250000 }, /* Size: */ { 500000, 250000 } },
74 int( SHAPE_ARC::DefaultAccuracyForPCB() ) // acceptable error when converting to line segments
75 },
76 {
77 "Append a 90 degree Arc (clockwise)",
78 { vt::CLOCKWISE_ARC, { 250000, 250000 }, { 250000, 0 } },
79 { /* BBOX Position: */ { 0, 0 }, /* Size: */ { 250000, 250000 } },
80 int( SHAPE_ARC::DefaultAccuracyForPCB() ) // acceptable error when converting to line segments
81 },
82 {
83 "Append a 90 degree Arc (anticlockwise)",
84 { vt::ANTICLOCKWISE_ARC, { 250000, -250000 }, { 250000, 0 } },
85 { /* BBOX Position: */ { 0, -250000 }, /* Size: */ { 250000, 250000 } },
86 int( SHAPE_ARC::DefaultAccuracyForPCB() ) // acceptable error when converting to line segments
87 },
88};
89
90
91
92BOOST_AUTO_TEST_CASE( AppendToChain )
93{
94 static const std::vector<VECTOR2D> coordinateMultipliers =
95 {
96 { 0.1, 0.1 },
97 { 0.1, -0.1 }, // y inversion
98 { 1, 1 },
99 { 1, -1 }, // y inversion
100 { 10, 10 },
101 { 10, -10 } // y inversion
102 };
103
104
105 for( const auto& c : appendToChainCases )
106 {
107 BOOST_TEST_INFO_SCOPE( c.m_CaseName );
108
109 for( const VECTOR2D& mult : coordinateMultipliers )
110 {
111 BOOST_TEST_INFO_SCOPE( "Applied scaling x=" << mult.x << " y=" << mult.y );
112
113 SHAPE_LINE_CHAIN chain( { 0, 0 } ); // starting chain contains a point at 0,0
114
115 auto transformCoord =
116 [&]( const VECTOR2I& aPt ) -> VECTOR2I
117 {
118 int x = double( aPt.x ) * mult.x;
119 int y = double( aPt.y ) * mult.y;
120 return { x, y };
121 };
122
123 c.m_VertexToAppend.AppendToChain( &chain, transformCoord, SCH_IU_PER_MM * 0.01 );
124
125 BOX2I expBoxTransformed;
126 expBoxTransformed.SetOrigin( transformCoord( c.m_ExpBBox.GetPosition() ) );
127 expBoxTransformed.SetSize( transformCoord( c.m_ExpBBox.GetSize() ) );
128 expBoxTransformed.Normalize();
129
132 ( chain.BBox().GetPosition() )( expBoxTransformed.GetPosition() ) ( c.m_ExpBBoxError ) );
133
136 ( chain.BBox().GetSize() )( expBoxTransformed.GetSize() ) ( c.m_ExpBBoxError ) );
137 }
138 }
139
140}
141
143
constexpr double SCH_IU_PER_MM
Schematic internal units 1=100nm.
Definition base_units.h:70
BOX2< VECTOR2I > BOX2I
Definition box2.h:918
Helper functions and common defines between schematic and PCB Archive files.
constexpr const Vec & GetPosition() const
Definition box2.h:207
constexpr void SetOrigin(const Vec &pos)
Definition box2.h:233
constexpr BOX2< Vec > & Normalize()
Ensure that the height and width are positive.
Definition box2.h:142
constexpr void SetSize(const SizeVec &size)
Definition box2.h:244
constexpr const SizeVec & GetSize() const
Definition box2.h:202
static int DefaultAccuracyForPCB()
Definition shape_arc.h:279
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
bool IsVecWithinTol(const VEC &aVec, const VEC &aExp, typename VEC::coord_type aTol)
Check that both x and y of a vector are within expected error.
Definition geometry.h:51
Represents a vertex in a shape.
CADSTAR_ARCHIVE_PARSER::VERTEX m_VertexToAppend
BOOST_AUTO_TEST_CASE(AppendToChain)
CADSTAR_ARCHIVE_PARSER::VERTEX_TYPE vt
static const std::vector< VERTEX_APPEND_CASE > appendToChainCases
std::function< wxPoint(const wxPoint &)> m_CadstarToKicadPointCallback
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_AUTO_TEST_SUITE_END()
const SHAPE_LINE_CHAIN chain
BOOST_CHECK_PREDICATE(ArePolylineEndPointsNearCircle,(chain)(c.m_geom.m_center_point)(radius)(accuracy+epsilon))
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683
VECTOR2< double > VECTOR2D
Definition vector2d.h:682