KiCad PCB EDA Suite
test_ee_item.cpp File Reference
#include <qa_utils/wx_utils/unit_test_utils.h>
#include <eda_item_test_utils.h>
#include <core/typeinfo.h>
#include <eda_item.h>
#include <sch_item.h>
#include <lib_item.h>
#include <sch_marker.h>
#include <sch_junction.h>
#include <sch_no_connect.h>
#include <sch_bus_entry.h>
#include <sch_line.h>
#include <sch_shape.h>
#include <sch_bitmap.h>
#include <sch_text.h>
#include <sch_textbox.h>
#include <sch_field.h>
#include <sch_symbol.h>
#include <sch_sheet_pin.h>
#include <sch_sheet.h>
#include <lib_shape.h>
#include <lib_text.h>
#include <lib_textbox.h>
#include <lib_pin.h>
#include <lib_field.h>
#include <erc_settings.h>

Go to the source code of this file.

Classes

class  TEST_EE_ITEM_FIXTURE
 

Functions

 BOOST_AUTO_TEST_CASE (Move)
 
 BOOST_AUTO_TEST_CASE (Rotate)
 
 BOOST_AUTO_TEST_CASE (MirrorHorizontally)
 
 BOOST_AUTO_TEST_CASE (MirrorVertically)
 

Function Documentation

◆ BOOST_AUTO_TEST_CASE() [1/4]

BOOST_AUTO_TEST_CASE ( MirrorHorizontally  )

Definition at line 273 of file test_ee_item.cpp.

274{
275 for( int i = 0; i < MAX_STRUCT_TYPE_ID; i++ )
276 {
277 KICAD_T type = static_cast<KICAD_T>( i );
278
279 auto item = std::unique_ptr<EDA_ITEM>( Instantiate( type ) );
280
281 if( item == nullptr )
282 continue;
283
284 BOOST_TEST_CONTEXT( "Class: " << item->GetClass() )
285 {
286 IterateOverPositionsAndReferences<EDA_ITEM>(
287 item.get(),
288 []( EDA_ITEM* aOriginalItem, wxPoint aRef )
289 {
290 auto item = std::unique_ptr<EDA_ITEM>( aOriginalItem->Clone() );
291
292 SCH_ITEM* schItem = dynamic_cast<SCH_ITEM*>( item.get() );
293 LIB_ITEM* libItem = dynamic_cast<LIB_ITEM*>( item.get() );
294
295 // Two mirrorings are an identity
296 // (warning: only for text items having no autoplaced fields).
297 if( schItem != nullptr )
298 {
299 schItem->ClearFieldsAutoplaced();
300 schItem->MirrorHorizontally( aRef.x );
301 schItem->MirrorHorizontally( aRef.x );
302 }
303
304 if( libItem != nullptr )
305 {
306 libItem->MirrorHorizontal( aRef );
307 libItem->MirrorHorizontal( aRef );
308 }
309
310 CompareItems( item.get(), aOriginalItem );
311 } );
312 }
313 }
314}
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:100
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition: typeinfo.h:78
@ MAX_STRUCT_TYPE_ID
Definition: typeinfo.h:233
#define BOOST_TEST_CONTEXT(A)

References BOOST_TEST_CONTEXT, and MAX_STRUCT_TYPE_ID.

◆ BOOST_AUTO_TEST_CASE() [2/4]

BOOST_AUTO_TEST_CASE ( MirrorVertically  )

Definition at line 317 of file test_ee_item.cpp.

318{
319 for( int i = 0; i < MAX_STRUCT_TYPE_ID; i++ )
320 {
321 KICAD_T type = static_cast<KICAD_T>( i );
322
323 auto item = std::unique_ptr<EDA_ITEM>( Instantiate( type ) );
324
325 if( item == nullptr )
326 continue;
327
328 BOOST_TEST_CONTEXT( "Class: " << item->GetClass() )
329 {
330 IterateOverPositionsAndReferences<EDA_ITEM>(
331 item.get(),
332 []( EDA_ITEM* aOriginalItem, wxPoint aRef )
333 {
334 auto item = std::unique_ptr<EDA_ITEM>( aOriginalItem->Clone() );
335
336 SCH_ITEM* schItem = dynamic_cast<SCH_ITEM*>( item.get() );
337 LIB_ITEM* libItem = dynamic_cast<LIB_ITEM*>( item.get() );
338
339 // Two mirrorings are an identity
340 // (warning only for text items having no autoplaced fields).
341
342 if( schItem != nullptr )
343 {
344 schItem->ClearFieldsAutoplaced();
345 schItem->MirrorVertically( aRef.y );
346 schItem->MirrorVertically( aRef.y );
347 }
348
349 if( libItem != nullptr )
350 {
351 libItem->MirrorVertical( aRef );
352 libItem->MirrorVertical( aRef );
353 }
354
355 CompareItems( item.get(), aOriginalItem );
356 } );
357 }
358 }
359}

References BOOST_TEST_CONTEXT, and MAX_STRUCT_TYPE_ID.

◆ BOOST_AUTO_TEST_CASE() [3/4]

BOOST_AUTO_TEST_CASE ( Move  )

Definition at line 145 of file test_ee_item.cpp.

146{
147 for( int i = 0; i < MAX_STRUCT_TYPE_ID; i++ )
148 {
149 KICAD_T type = static_cast<KICAD_T>( i );
150
151 auto item = std::unique_ptr<EDA_ITEM>( Instantiate( type ) );
152
153 if( item == nullptr )
154 continue;
155
156 BOOST_TEST_CONTEXT( "Class: " << item->GetClass() )
157 {
158 IterateOverPositionsAndReferences<EDA_ITEM>(
159 item.get(),
160 []( EDA_ITEM* aOriginalItem, wxPoint aRef )
161 {
162 auto item = std::unique_ptr<EDA_ITEM>( aOriginalItem->Clone() );
163 VECTOR2I originalPos = item->GetPosition();
164
165 SCH_ITEM* schItem = dynamic_cast<SCH_ITEM*>( item.get() );
166 LIB_ITEM* libItem = dynamic_cast<LIB_ITEM*>( item.get() );
167
168 // Move to a point, then go back.
169 // This has to be an identity transformation.
170
171 if( schItem != nullptr )
172 {
173 schItem->Move( aRef );
174 BOOST_CHECK_EQUAL( schItem->GetPosition(), originalPos + aRef );
175
176 schItem->Move( -aRef );
177 }
178
179 if( libItem != nullptr )
180 {
181 libItem->MoveTo( libItem->GetPosition() + aRef );
182 BOOST_CHECK_EQUAL( libItem->GetPosition(), originalPos + aRef );
183
184 libItem->MoveTo( libItem->GetPosition() - aRef );
185 }
186
187 CompareItems( item.get(), aOriginalItem );
188 } );
189 }
190 }
191}

References BOOST_TEST_CONTEXT, and MAX_STRUCT_TYPE_ID.

◆ BOOST_AUTO_TEST_CASE() [4/4]

BOOST_AUTO_TEST_CASE ( Rotate  )

Definition at line 194 of file test_ee_item.cpp.

195{
196 for( int i = 0; i < MAX_STRUCT_TYPE_ID; i++ )
197 {
198 KICAD_T type = static_cast<KICAD_T>( i );
199
200 auto item = std::unique_ptr<EDA_ITEM>( Instantiate( type ) );
201
202 if( item == nullptr )
203 continue;
204
205 BOOST_TEST_CONTEXT( "Class: " << item->GetClass() )
206 {
207 // Four equivalent 90 degree rotations are an identity.
208 // (warning: only for items having no autoplaced fields).
209
210 if( item->GetClass() == "SCH_SHEET_PIN" )
211 {
212 auto newItem = std::unique_ptr<EDA_ITEM>( item->Clone() );
213
214 SCH_ITEM* schItem = dynamic_cast<SCH_ITEM*>( newItem.get() );
215 LIB_ITEM* libItem = dynamic_cast<LIB_ITEM*>( newItem.get() );
216
217 if( schItem != nullptr )
218 {
219 schItem->ClearFieldsAutoplaced();
220 // Only rotating pins around the center of parent sheet works.
221 schItem->Rotate( m_sheet.GetBodyBoundingBox().GetCenter() );
222 schItem->Rotate( m_sheet.GetBodyBoundingBox().GetCenter() );
223 schItem->Rotate( m_sheet.GetBodyBoundingBox().GetCenter() );
224 schItem->Rotate( m_sheet.GetBodyBoundingBox().GetCenter() );
225 }
226
227 if( libItem != nullptr )
228 {
229 libItem->Rotate( m_sheet.GetBodyBoundingBox().GetCenter() );
230 libItem->Rotate( m_sheet.GetBodyBoundingBox().GetCenter() );
231 libItem->Rotate( m_sheet.GetBodyBoundingBox().GetCenter() );
232 libItem->Rotate( m_sheet.GetBodyBoundingBox().GetCenter() );
233 }
234
235 CompareItems( newItem.get(), item.get() );
236 }
237 else
238 {
239 IterateOverPositionsAndReferences<EDA_ITEM>(
240 item.get(),
241 []( EDA_ITEM* aOriginalItem, wxPoint aRef )
242 {
243 auto item = std::unique_ptr<EDA_ITEM>( aOriginalItem->Clone() );
244
245 SCH_ITEM* schItem = dynamic_cast<SCH_ITEM*>( item.get() );
246 LIB_ITEM* libItem = dynamic_cast<LIB_ITEM*>( item.get() );
247
248 if( schItem != nullptr )
249 {
250 schItem->ClearFieldsAutoplaced();
251 schItem->Rotate( aRef );
252 schItem->Rotate( aRef );
253 schItem->Rotate( aRef );
254 schItem->Rotate( aRef );
255 }
256
257 if( libItem != nullptr )
258 {
259 libItem->Rotate( aRef );
260 libItem->Rotate( aRef );
261 libItem->Rotate( aRef );
262 libItem->Rotate( aRef );
263 }
264
265 CompareItems( item.get(), aOriginalItem );
266 } );
267 }
268 }
269 }
270}
The base class for drawable items used by schematic library symbols.
Definition: lib_item.h:62
virtual void Rotate(const VECTOR2I &aCenter, bool aRotateCCW=true)=0
Rotate the object about aCenter point.
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:145
void ClearFieldsAutoplaced()
Definition: sch_item.h:416
virtual void Rotate(const VECTOR2I &aCenter)=0
Rotate the item around aCenter 90 degrees in the clockwise direction.

References BOOST_TEST_CONTEXT, SCH_ITEM::ClearFieldsAutoplaced(), MAX_STRUCT_TYPE_ID, SCH_ITEM::Rotate(), and LIB_ITEM::Rotate().