EDA_ITEM* SELECTION::GetTopLeftItem( bool onlyModules ) const { SCH_ITEM* topLeftItem = nullptr; SCH_ITEM* currentItem; wxPoint pos; // find the leftmost (smallest x coord) and highest (smallest y with the smallest x) item in the selection for( auto item : m_items ) { currentItem = static_cast<SCH_ITEM*>( item ); pos = currentItem->GetPosition(); if( topLeftItem == nullptr ) topLeftItem = currentItem; else if( pos.x < topLeftItem->GetPosition().x ) topLeftItem = currentItem; else if( topLeftItem->GetPosition().x == pos.x && pos.y < topLeftItem->GetPosition().y ) topLeftItem = currentItem; } return static_cast<EDA_ITEM*>( topLeftItem ); }
bool SCH_SCREEN::SchematicCleanUp() { bool modified = false; for( SCH_ITEM* item = m_drawList.begin() ; item; item = item->Next() ) { if( ( item->Type() != SCH_LINE_T ) && ( item->Type() != SCH_JUNCTION_T ) ) continue; bool restart; for( SCH_ITEM* testItem = item->Next(); testItem; testItem = restart ? m_drawList.begin() : testItem->Next() ) { restart = false; if( ( item->Type() == SCH_LINE_T ) && ( testItem->Type() == SCH_LINE_T ) ) { SCH_LINE* line = (SCH_LINE*) item; if( line->MergeOverlap( (SCH_LINE*) testItem ) ) { // Keep the current flags, because the deleted segment can be flagged. item->SetFlags( testItem->GetFlags() ); DeleteItem( testItem ); restart = true; modified = true; } } else if ( ( ( item->Type() == SCH_JUNCTION_T ) && ( testItem->Type() == SCH_JUNCTION_T ) ) && ( testItem != item ) ) { if ( testItem->HitTest( item->GetPosition() ) ) { // Keep the current flags, because the deleted segment can be flagged. item->SetFlags( testItem->GetFlags() ); DeleteItem( testItem ); restart = true; modified = true; } } } } TestDanglingEnds(); return modified; }