KiCad PCB EDA Suite
eda_item_test_utils.h
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) 2021 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 #ifndef EDA_ITEM_TEST_UTILS_H
25 #define EDA_ITEM_TEST_UTILS_H
26 
28 #include <convert_to_biu.h>
29 #include <eda_item.h>
30 
31 
32 template <typename T>
33 static void IterateOverPositionsAndReferences( T* aItem, void ( *aCallback )( T*, wxPoint ) )
34 {
35  constexpr int XSTEP = static_cast<int>( Millimeter2iu( 100 ) );
36  constexpr int YSTEP = static_cast<int>( Millimeter2iu( 50 ) );
37  constexpr int XMIN = -1 * XSTEP;
38  constexpr int XMAX = 1 * XSTEP;
39  constexpr int YMIN = -1 * YSTEP;
40  constexpr int YMAX = 1 * YSTEP;
41 
42  for( int posX = XMIN; posX <= XMAX; posX += XSTEP )
43  {
44  for( int posY = YMIN; posY <= YMAX; posY += YSTEP )
45  {
46  for( int refX = XMIN; refX <= XMAX; refX += XSTEP )
47  {
48  for( int refY = YMIN; refY <= YMAX; refY += YSTEP )
49  {
50  BOOST_TEST_CONTEXT( wxString::Format( "Position: %d %d, Reference: %d %d",
51  posX, posY, refX, refY ) )
52  {
53  aItem->SetPosition( wxPoint( posX, posY ) );
54  aCallback( aItem, wxPoint( refX, refY ) );
55  }
56  }
57  }
58  }
59  }
60 }
61 
62 #endif // EDA_ITEM_TEST_UTILS_H
#define BOOST_TEST_CONTEXT(A)
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
static void IterateOverPositionsAndReferences(T *aItem, void(*aCallback)(T *, wxPoint))
static constexpr int Millimeter2iu(double mm)