void SCH_EDIT_FRAME::OnSelectUnit( wxCommandEvent& aEvent ) { SCH_SCREEN* screen = GetScreen(); SCH_ITEM* item = screen->GetCurItem(); wxCHECK_RET( item != NULL && item->Type() == SCH_COMPONENT_T, wxT( "Cannot select unit of invalid schematic item." ) ); INSTALL_UNBUFFERED_DC( dc, m_canvas ); m_canvas->MoveCursorToCrossHair(); SCH_COMPONENT* component = (SCH_COMPONENT*) item; int unit = aEvent.GetId() + 1 - ID_POPUP_SCH_SELECT_UNIT1; LIB_PART* part = GetLibPart( component->GetLibId() ); if( !part ) return; int unitCount = part->GetUnitCount(); wxCHECK_RET( (unit >= 1) && (unit <= unitCount), wxString::Format( wxT( "Cannot select unit %d from component " ), unit ) + part->GetName() ); if( unitCount <= 1 || component->GetUnit() == unit ) return; if( unit > unitCount ) unit = unitCount; STATUS_FLAGS flags = component->GetFlags(); if( !flags ) // No command in progress: save in undo list SaveCopyInUndoList( component, UR_CHANGED ); if( flags ) component->Draw( m_canvas, &dc, wxPoint( 0, 0 ), g_XorMode, g_GhostColor ); else component->Draw( m_canvas, &dc, wxPoint( 0, 0 ), g_XorMode ); /* Update the unit number. */ component->SetUnitSelection( m_CurrentSheet, unit ); component->SetUnit( unit ); component->ClearFlags(); component->SetFlags( flags ); // Restore m_Flag modified by SetUnit() if( m_autoplaceFields ) component->AutoAutoplaceFields( GetScreen() ); if( screen->TestDanglingEnds() ) m_canvas->Refresh(); OnModify(); }
void SCH_EDIT_FRAME::OnSelectUnit( wxCommandEvent& aEvent ) { SCH_SCREEN* screen = GetScreen(); SCH_ITEM* item = screen->GetCurItem(); SCH_COMPONENT* component = (SCH_COMPONENT*) item; GetCanvas()->MoveCursorToCrossHair(); int unit = aEvent.GetId() + 1 - ID_POPUP_SCH_SELECT_UNIT1; LIB_PART* part = GetLibPart( component->GetLibId() ); if( !part ) return; int unitCount = part->GetUnitCount(); if( unitCount <= 1 || component->GetUnit() == unit ) return; if( unit > unitCount ) unit = unitCount; STATUS_FLAGS flags = component->GetFlags(); if( !flags ) // No command in progress: save in undo list SaveCopyInUndoList( component, UR_CHANGED ); /* Update the unit number. */ component->SetUnitSelection( g_CurrentSheet, unit ); component->SetUnit( unit ); component->ClearFlags(); component->SetFlags( flags ); // Restore m_Flag modified by SetUnit() if( m_autoplaceFields ) component->AutoAutoplaceFields( GetScreen() ); TestDanglingEnds(); RefreshItem( component ); OnModify(); }