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 (C) 2023 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
30
32
33#include <qa_utils/geometry/geometry.h> // For KI_TEST::IsVecWithinTol
35#include <geometry/shape_arc.h> // For SHAPE_ARC::DefaultAccuracyForPCB()
36
37
38BOOST_AUTO_TEST_SUITE( CadstartArchiveParser )
39
40
42{
43 std::string m_CaseName;
47};
48
49 std::function<wxPoint( const wxPoint& )> m_CadstarToKicadPointCallback;
50
52
53
54static const std::vector<VERTEX_APPEND_CASE> appendToChainCases
55{
56 {
57 "Append a point on x",
58 { vt::POINT, { 500000, 0 } },
59 { /* BBOX Position: */ { 0, 0 }, /* Size:*/ { 500000, 0 } },
60 0
61 },
62 {
63 "Append a point on y",
64 { vt::POINT, { 0, 500000 } },
65 { /* BBOX Position: */ { 0, 0 }, /* Size:*/ { 0, 500000 } },
66 0
67 },
68 {
69 "Append a Semicircle (clockwise)",
70 { vt::CLOCKWISE_SEMICIRCLE, { 500000, 0 } },
71 { /* BBOX Position: */ { 0, 0 }, /* Size: */ { 500000, 250000 } },
72 int( SHAPE_ARC::DefaultAccuracyForPCB() ) // acceptable error when converting to line segments
73 },
74 {
75 "Append a Semicircle (anticlockwise)",
76 { vt::ANTICLOCKWISE_SEMICIRCLE, { 500000, 0 } },
77 { /* BBOX Position: */ { 0, -250000 }, /* Size: */ { 500000, 250000 } },
78 int( SHAPE_ARC::DefaultAccuracyForPCB() ) // acceptable error when converting to line segments
79 },
80 {
81 "Append a 90 degree Arc (clockwise)",
82 { vt::CLOCKWISE_ARC, { 250000, 250000 }, { 250000, 0 } },
83 { /* BBOX Position: */ { 0, 0 }, /* Size: */ { 250000, 250000 } },
84 int( SHAPE_ARC::DefaultAccuracyForPCB() ) // acceptable error when converting to line segments
85 },
86 {
87 "Append a 90 degree Arc (anticlockwise)",
88 { vt::ANTICLOCKWISE_ARC, { 250000, -250000 }, { 250000, 0 } },
89 { /* BBOX Position: */ { 0, -250000 }, /* Size: */ { 250000, 250000 } },
90 int( SHAPE_ARC::DefaultAccuracyForPCB() ) // acceptable error when converting to line segments
91 },
92};
93
94
95
96BOOST_AUTO_TEST_CASE( AppendToChain )
97{
98 static const std::vector<VECTOR2D> coordinateMultipliers =
99 {
100 { 0.1, 0.1 },
101 { 0.1, -0.1 }, // y inversion
102 { 1, 1 },
103 { 1, -1 }, // y inversion
104 { 10, 10 },
105 { 10, -10 } // y inversion
106 };
107
108
109 for( const auto& c : appendToChainCases )
110 {
111 BOOST_TEST_INFO_SCOPE( c.m_CaseName );
112
113 for( const VECTOR2D& mult : coordinateMultipliers )
114 {
115 BOOST_TEST_INFO_SCOPE( "Applied scaling x=" << mult.x << " y=" << mult.y );
116
117 SHAPE_LINE_CHAIN chain( { 0, 0 } ); // starting chain contains a point at 0,0
118
119 auto transformCoord =
120 [&]( const VECTOR2I& aPt ) -> VECTOR2I
121 {
122 int x = double( aPt.x ) * mult.x;
123 int y = double( aPt.y ) * mult.y;
124 return { x, y };
125 };
126
127 c.m_VertexToAppend.AppendToChain( &chain, transformCoord, SCH_IU_PER_MM * 0.01 );
128
129 BOX2I expBoxTransformed;
130 expBoxTransformed.SetOrigin( transformCoord( c.m_ExpBBox.GetPosition() ) );
131 expBoxTransformed.SetSize( transformCoord( c.m_ExpBBox.GetSize() ) );
132 expBoxTransformed.Normalize();
133
134 BOOST_CHECK_PREDICATE(
135 KI_TEST::IsVecWithinTol<VECTOR2I>,
136 ( chain.BBox().GetPosition() )( expBoxTransformed.GetPosition() ) ( c.m_ExpBBoxError ) );
137
138 BOOST_CHECK_PREDICATE(
139 KI_TEST::IsVecWithinTol<VECTOR2I>,
140 ( chain.BBox().GetSize() )( expBoxTransformed.GetSize() ) ( c.m_ExpBBoxError ) );
141 }
142 }
143
144}
145
147
constexpr double SCH_IU_PER_MM
Definition: base_units.h:72
Helper functions and common defines between schematic and PCB Archive files.
constexpr const Vec & GetPosition() const
Definition: box2.h:211
constexpr void SetOrigin(const Vec &pos)
Definition: box2.h:237
constexpr BOX2< Vec > & Normalize()
Ensure that the height and width are positive.
Definition: box2.h:146
constexpr void SetSize(const SizeVec &size)
Definition: box2.h:248
constexpr const SizeVec & GetSize() const
Definition: box2.h:206
static double DefaultAccuracyForPCB()
Definition: shape_arc.h:232
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
Represents a vertex in a shape.
CADSTAR_ARCHIVE_PARSER::VERTEX m_VertexToAppend
BOOST_AUTO_TEST_CASE(AppendToChain)
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()