KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_step_and_repeat.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, 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
24
#include <boost/test/unit_test.hpp>
25
26
#include <wx/filefn.h>
27
#include <wx/filename.h>
28
29
#include <
gerber_file_image.h
>
30
#include <
gerber_draw_item.h
>
31
#include <
qa_utils/wx_utils/unit_test_utils.h
>
32
33
34
static
std::string
GetGerbviewTestDataDir
()
35
{
36
std::string dir =
KI_TEST::GetTestDataRootDir
();
37
dir +=
"gerbview/"
;
38
return
dir;
39
}
40
41
42
BOOST_AUTO_TEST_SUITE
( StepAndRepeat )
43
44
45
54
BOOST_AUTO_TEST_CASE
( BlockReplication )
55
{
56
GERBER_FILE_IMAGE
image
( 0 );
57
58
std::string fn =
GetGerbviewTestDataDir
() +
"step_and_repeat_block.gbr"
;
59
bool
loaded =
image
.LoadGerberFile( wxString::FromUTF8( fn ) );
60
BOOST_REQUIRE_MESSAGE( loaded,
"Failed to load test gerber file"
);
61
62
GERBER_DRAW_ITEMS
& items =
image
.GetItems();
63
64
// The file has 2 region items in the SR block, X repeat = 3, Y repeat = 1.
65
// Total items = 2 original + 2*2 copies = 6
66
BOOST_CHECK_EQUAL
( items.size(), 6 );
67
68
if
( items.size() != 6 )
69
return
;
70
71
// Original block items (indices 0,1) at X offset 0
72
// Copy 1 items (indices 2,3) at X offset 10mm
73
// Copy 2 items (indices 4,5) at X offset 20mm
74
//
75
// Within each pair, first item must be positive (LPD), second negative (LPC).
76
// This ordering is what distinguishes correct block-level replication from
77
// the old per-item replication which would produce:
78
// [pos0, pos1, pos2, neg0, neg1, neg2]
79
80
// Verify the block ordering: items alternate as [pos, neg, pos, neg, pos, neg]
81
for
(
int
copy
= 0;
copy
< 3;
copy
++ )
82
{
83
int
posIdx =
copy
* 2;
84
int
negIdx =
copy
* 2 + 1;
85
86
BOOST_CHECK_MESSAGE
( !items[posIdx]->GetLayerPolarity(),
87
"Item "
<< posIdx <<
" (copy "
<<
copy
<<
" positive) "
88
<<
"should have positive polarity"
);
89
90
BOOST_CHECK_MESSAGE
( items[negIdx]->GetLayerPolarity(),
91
"Item "
<< negIdx <<
" (copy "
<<
copy
<<
" negative) "
92
<<
"should have negative polarity"
);
93
}
94
95
// Verify spatial offsets: each copy should be shifted by 10mm in X.
96
// Gerbview IU is 10nm, so 10mm = 10 * 1e5 = 1000000 IU.
97
int
stepX = 1000000;
98
99
for
(
int
copy
= 1;
copy
< 3;
copy
++ )
100
{
101
VECTOR2I
origPos = items[0]->GetPosition();
102
VECTOR2I
copyPos = items[
copy
* 2]->GetPosition();
103
int
expectedDx =
copy
* stepX;
104
105
BOOST_CHECK_EQUAL
( copyPos.
x
- origPos.
x
, expectedDx );
106
BOOST_CHECK_EQUAL
( copyPos.
y
- origPos.
y
, 0 );
107
}
108
}
109
110
114
BOOST_AUTO_TEST_CASE
( NoStepAndRepeat )
115
{
116
wxString
path
= wxFileName::CreateTempFileName( wxS(
"kicad_gbr_no_sr"
) );
117
BOOST_REQUIRE
( !
path
.IsEmpty() );
118
119
FILE* file = wxFopen(
path
, wxT(
"wt"
) );
120
BOOST_REQUIRE
( file );
121
122
fputs(
"%MOMM*%\n%FSLAX26Y26*%\n%ADD10C,1.00000*%\nD10*\nX0Y0D03*\nM02*\n"
, file );
123
fclose( file );
124
125
GERBER_FILE_IMAGE
image
( 0 );
126
BOOST_REQUIRE
(
image
.LoadGerberFile(
path
) );
127
128
BOOST_CHECK_EQUAL
(
image
.GetItems().size(), 1 );
129
BOOST_CHECK_EQUAL
(
image
.GetLayerParams().m_XRepeatCount, 1 );
130
BOOST_CHECK_EQUAL
(
image
.GetLayerParams().m_YRepeatCount, 1 );
131
BOOST_CHECK_EQUAL
(
image
.m_SRBlockCollecting,
false
);
132
133
wxRemoveFile(
path
);
134
}
135
136
137
BOOST_AUTO_TEST_SUITE_END
()
BITMAPS::copy
@ copy
Definition
bitmaps_list.h:140
BITMAPS::image
@ image
Definition
bitmaps_list.h:307
GERBER_FILE_IMAGE
Hold the image data and parameters for one gerber file and layer parameters.
Definition
gerber_file_image.h:112
VECTOR2::x
T x
Definition
vector2d.h:75
VECTOR2::y
T y
Definition
vector2d.h:75
gerber_draw_item.h
gerber_file_image.h
GERBER_DRAW_ITEMS
std::vector< GERBER_DRAW_ITEM * > GERBER_DRAW_ITEMS
Definition
gerber_file_image.h:33
KI_TEST::GetTestDataRootDir
std::string GetTestDataRootDir()
Definition
unit_test_utils.cpp:64
BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
Definition
test_api_enums.cpp:71
BOOST_AUTO_TEST_SUITE
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_REQUIRE
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_AUTO_TEST_SUITE_END
BOOST_AUTO_TEST_SUITE_END()
path
std::string path
Definition
test_kibis.cpp:100
BOOST_CHECK_MESSAGE
BOOST_CHECK_MESSAGE(totalMismatches==0, std::to_string(totalMismatches)+" board(s) with strategy disagreements")
BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(BlockReplication)
Verifies that an SR block replicates all items as a unit rather than replicating each item individual...
Definition
test_step_and_repeat.cpp:54
GetGerbviewTestDataDir
static std::string GetGerbviewTestDataDir()
Definition
test_step_and_repeat.cpp:34
BOOST_CHECK_EQUAL
BOOST_CHECK_EQUAL(result, "25.4")
unit_test_utils.h
VECTOR2I
VECTOR2< int32_t > VECTOR2I
Definition
vector2d.h:683
src
qa
tests
gerbview
test_step_and_repeat.cpp
Generated on Tue Jul 7 2026 00:07:28 for KiCad PCB EDA Suite by
1.13.2