121 std::vector<SCH_PIN*> pins;
123 for(
SCH_ITEM& item : symbol->GetDrawItems() )
126 pins.push_back(
static_cast<SCH_PIN*
>( &item ) );
129 BOOST_REQUIRE_GE( pins.size(), 2 );
132 std::vector<TRANSFORM> rotations = {
137 std::vector<wxString> rotationNames = { wxT(
"0°" ), wxT(
"90°" ) };
139 for(
size_t r = 0; r < rotations.size(); r++ )
141 const TRANSFORM& transform = rotations[r];
142 const wxString& rotName = rotationNames[r];
158 std::vector<PinTextBoxes> pinBoxes;
163 boxes.pinNumber =
pin->GetNumber();
164 boxes.hasName =
false;
165 boxes.hasNumber =
false;
175 boxes.nameBBox = *nameBox;
176 boxes.nameBBox.Move( shift );
177 boxes.hasName =
true;
182 boxes.numberBBox = *numberBox;
183 boxes.numberBBox.Move( shift );
184 boxes.hasNumber =
true;
187 pinBoxes.push_back( boxes );
190 BOOST_REQUIRE_GE( pinBoxes.size(), 2 );
195 BOX2I collided = pinBoxes[0].nameBBox;
196 collided.
Move( pinBoxes[1].nameBBox.GetCenter() - pinBoxes[0].nameBBox.GetCenter() );
198 BOOST_CHECK_MESSAGE( collided.
Intersects( pinBoxes[1].nameBBox ),
199 "At " << rotName <<
": coincident name boxes were not reported as overlapping" );
203 for(
size_t i = 0; i < pinBoxes.size(); i++ )
205 for(
size_t j = i + 1; j < pinBoxes.size(); j++ )
207 const PinTextBoxes&
pinA = pinBoxes[i];
208 const PinTextBoxes& pinB = pinBoxes[j];
211 if(
pinA.hasName && pinB.hasName )
213 bool namesOverlap =
pinA.nameBBox.Intersects( pinB.nameBBox );
216 "At " << rotName <<
": Pin " <<
pinA.pinNumber <<
" name overlaps with pin "
217 << pinB.pinNumber <<
" name. "
218 <<
"BBoxA=(" <<
pinA.nameBBox.GetLeft() <<
","
219 <<
pinA.nameBBox.GetTop() <<
")-(" <<
pinA.nameBBox.GetRight()
220 <<
"," <<
pinA.nameBBox.GetBottom() <<
") "
221 <<
"BBoxB=(" << pinB.nameBBox.GetLeft() <<
","
222 << pinB.nameBBox.GetTop() <<
")-(" << pinB.nameBBox.GetRight()
223 <<
"," << pinB.nameBBox.GetBottom() <<
")" );
227 if(
pinA.hasNumber && pinB.hasNumber )
229 bool numbersOverlap =
pinA.numberBBox.Intersects( pinB.numberBBox );
232 "At " << rotName <<
": Pin " <<
pinA.pinNumber
233 <<
" number overlaps with pin " << pinB.pinNumber <<
" number. "
234 <<
"BBoxA=(" <<
pinA.numberBBox.GetLeft() <<
","
235 <<
pinA.numberBBox.GetTop() <<
")-("
236 <<
pinA.numberBBox.GetRight() <<
","
237 <<
pinA.numberBBox.GetBottom() <<
") "
238 <<
"BBoxB=(" << pinB.numberBBox.GetLeft() <<
","
239 << pinB.numberBBox.GetTop() <<
")-("
240 << pinB.numberBBox.GetRight() <<
","
241 << pinB.numberBBox.GetBottom() <<
")" );
245 if(
pinA.hasName && pinB.hasNumber )
247 bool overlap =
pinA.nameBBox.Intersects( pinB.numberBBox );
250 "At " << rotName <<
": Pin " <<
pinA.pinNumber
251 <<
" name overlaps with pin " << pinB.pinNumber <<
" number." );
254 if(
pinA.hasNumber && pinB.hasName )
256 bool overlap =
pinA.numberBBox.Intersects( pinB.nameBBox );
259 "At " << rotName <<
": Pin " <<
pinA.pinNumber
260 <<
" number overlaps with pin " << pinB.pinNumber <<
" name." );
286 for(
SCH_ITEM& item : symbol->GetDrawItems() )
290 testPin =
static_cast<SCH_PIN*
>( &item );
306 std::optional<PIN_LAYOUT_CACHE::TEXT_INFO> nameInfo0 = cache0.
GetPinNameInfo( 0 );
307 std::optional<PIN_LAYOUT_CACHE::TEXT_INFO> numberInfo0 = cache0.
GetPinNumberInfo( 0 );
309 int nameDistance0 = 0;
310 int numberDistance0 = 0;
312 if( nameInfo0.has_value() )
315 if( numberInfo0.has_value() )
322 std::optional<PIN_LAYOUT_CACHE::TEXT_INFO> nameInfo90 = cache90.
GetPinNameInfo( 0 );
323 std::optional<PIN_LAYOUT_CACHE::TEXT_INFO> numberInfo90 = cache90.
GetPinNumberInfo( 0 );
325 int nameDistance90 = 0;
326 int numberDistance90 = 0;
328 if( nameInfo90.has_value() )
331 if( numberInfo90.has_value() )
338 const int tolerance =
schIUScale.MilsToIU( 5 );
341 if( nameInfo0.has_value() && nameInfo90.has_value() )
343 int nameDiff =
std::abs( nameDistance0 - nameDistance90 );
345 nameDiff <= tolerance,
346 "Pin name perpendicular distance changed across rotation. "
347 <<
"At 0°: " << nameDistance0 <<
", at 90°: " << nameDistance90
348 <<
", difference: " << nameDiff <<
" (tolerance: " << tolerance <<
")" );
352 if( numberInfo0.has_value() && numberInfo90.has_value() )
354 int numberDiff =
std::abs( numberDistance0 - numberDistance90 );
356 numberDiff <= tolerance,
357 "Pin number perpendicular distance changed across rotation. "
358 <<
"At 0°: " << numberDistance0 <<
", at 90°: " << numberDistance90
359 <<
", difference: " << numberDiff <<
" (tolerance: " << tolerance <<
")" );
379 for(
SCH_ITEM& item : symbol->GetDrawItems() )
383 testPin =
static_cast<SCH_PIN*
>( &item );
391 std::vector<TRANSFORM> rotations = {
TRANSFORM( 1, 0, 0, 1 ),
TRANSFORM( 0, -1, 1, 0 ) };
392 std::vector<wxString> rotationNames = { wxT(
"0°" ), wxT(
"90°" ) };
394 for(
size_t r = 0; r < rotations.size(); r++ )
396 const TRANSFORM& transform = rotations[r];
397 const wxString& rotName = rotationNames[r];
403 std::optional<PIN_LAYOUT_CACHE::TEXT_INFO> nameInfo = cache.
GetPinNameInfo( 0 );
404 std::optional<PIN_LAYOUT_CACHE::TEXT_INFO> numberInfo = cache.
GetPinNumberInfo( 0 );
406 BOOST_REQUIRE_MESSAGE( nameInfo.has_value(),
"Pin should have name at " << rotName );
407 BOOST_REQUIRE_MESSAGE( numberInfo.has_value(),
"Pin should have number at " << rotName );
415 bool nameAbove = nameInfo->m_TextPosition.y < pinPos.
y;
416 bool numberAbove = numberInfo->m_TextPosition.y < pinPos.
y;
419 nameAbove != numberAbove,
420 "At " << rotName <<
" (horizontal pin): name and number should be on opposite "
421 <<
"Y sides of pin. Name Y=" << nameInfo->m_TextPosition.y
422 <<
", Number Y=" << numberInfo->m_TextPosition.y
423 <<
", Pin Y=" << pinPos.
y );
428 bool nameLeft = nameInfo->m_TextPosition.x < pinPos.
x;
429 bool numberLeft = numberInfo->m_TextPosition.x < pinPos.
x;
432 nameLeft != numberLeft,
433 "At " << rotName <<
" (vertical pin): name and number should be on opposite "
434 <<
"X sides of pin. Name X=" << nameInfo->m_TextPosition.x
435 <<
", Number X=" << numberInfo->m_TextPosition.x
436 <<
", Pin X=" << pinPos.
x );
PIN_ORIENTATION PinDrawOrient(const TRANSFORM &aTransform) const
Return the pin real orientation (PIN_UP, PIN_DOWN, PIN_RIGHT, PIN_LEFT), according to its orientation...
static std::unique_ptr< LIB_SYMBOL > createAdjacentPinsSymbol()
Create a test symbol with adjacent pins for testing overlap.
static int getPerpendicularDistance(const SCH_PIN *pin, const VECTOR2I &textPos, const TRANSFORM &transform)
Calculate perpendicular distance from pin line to text center.
BOOST_AUTO_TEST_CASE(AdjacentPinTextNoOverlap)
Test that pin names and numbers don't overlap with adjacent pins at 0° and 90°.