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 272 of file test_ee_item.cpp.

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

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

References BOOST_TEST_CONTEXT, and MAX_STRUCT_TYPE_ID.

◆ BOOST_AUTO_TEST_CASE() [3/4]

BOOST_AUTO_TEST_CASE ( Move  )

Definition at line 144 of file test_ee_item.cpp.

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

References BOOST_TEST_CONTEXT, and MAX_STRUCT_TYPE_ID.

◆ BOOST_AUTO_TEST_CASE() [4/4]

BOOST_AUTO_TEST_CASE ( Rotate  )

Definition at line 193 of file test_ee_item.cpp.

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