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