void SCH_EDIT_FRAME::DeleteItem( SCH_ITEM* aItem )
{
    wxCHECK_RET( aItem != NULL, wxT( "Cannot delete invalid item." ) );

    // Here, aItem is not null.

    SCH_SCREEN* screen = GetScreen();

    if( aItem->Type() == SCH_SHEET_PIN_T )
    {
        // This iten is attached to a node, and is not accessible by the global list directly.
        SCH_SHEET* sheet = (SCH_SHEET*) aItem->GetParent();
        wxCHECK_RET( (sheet != NULL) && (sheet->Type() == SCH_SHEET_T),
                     wxT( "Sheet label has invalid parent item." ) );
        SaveCopyInUndoList( (SCH_ITEM*) sheet, UR_CHANGED );
        sheet->RemovePin( (SCH_SHEET_PIN*) aItem );
        m_canvas->RefreshDrawingRect( sheet->GetBoundingBox() );
    }
    else
    {
        screen->Remove( aItem );
        SaveCopyInUndoList( aItem, UR_DELETED );
        m_canvas->RefreshDrawingRect( aItem->GetBoundingBox() );
    }
}
Ejemplo n.º 2
0
void SCH_EDIT_FRAME::DeleteItem( SCH_ITEM* aItem, bool aAppend )
{
    wxCHECK_RET( aItem != NULL, wxT( "Cannot delete invalid item." ) );
    wxCHECK_RET( !( aItem->GetFlags() & STRUCT_DELETED ),
                 wxT( "Cannot delete item that is already deleted." ) );

    // Here, aItem is not null.
    SCH_SCREEN* screen = GetScreen();

    if( aItem->Type() == SCH_SHEET_PIN_T )
    {
        // This item is attached to a node, and is not accessible by the global list directly.
        SCH_SHEET* sheet = (SCH_SHEET*) aItem->GetParent();
        wxCHECK_RET( (sheet != NULL) && (sheet->Type() == SCH_SHEET_T),
                     wxT( "Sheet label has invalid parent item." ) );
        SaveCopyInUndoList( (SCH_ITEM*) sheet, UR_CHANGED, aAppend );
        sheet->RemovePin( (SCH_SHEET_PIN*) aItem );
        m_canvas->RefreshDrawingRect( sheet->GetBoundingBox() );
    }
    else
    {
        PICKED_ITEMS_LIST itemsList;
        ITEM_PICKER picker( aItem, UR_DELETED );

        aItem->SetFlags( STRUCT_DELETED );
        itemsList.PushItem( picker );
        screen->Remove( aItem );

        if( aItem->IsConnectable() && aItem->Type() != SCH_JUNCTION_T )
        {
            std::vector< wxPoint > pts;
            aItem->GetConnectionPoints( pts );
            for( auto point : pts )
            {
                SCH_ITEM* junction;
                if( !screen->IsJunctionNeeded( point )
                        && ( junction = screen->GetItem( point, 0, SCH_JUNCTION_T ) ) )
                {
                    ITEM_PICKER picker_juction( junction, UR_DELETED );
                    junction->SetFlags( STRUCT_DELETED );
                    itemsList.PushItem( picker_juction );
                    screen->Remove( junction );
                }
            }
        }

        SaveCopyInUndoList( itemsList, UR_DELETED, aAppend );
        m_canvas->RefreshDrawingRect( aItem->GetBoundingBox() );
    }
}
Ejemplo n.º 3
0
void SCH_EDIT_FRAME::addCurrentItemToList( wxDC* aDC )
{
    SCH_SCREEN* screen = GetScreen();
    SCH_ITEM*   item = screen->GetCurItem();

    wxCHECK_RET( item != NULL, wxT( "Cannot add current item to list." ) );

    m_canvas->SetAutoPanRequest( false );

    SCH_ITEM* undoItem = item;

    if( item->Type() == SCH_SHEET_PIN_T )
    {
        SCH_SHEET* sheet = (SCH_SHEET*) item->GetParent();

        wxCHECK_RET( (sheet != NULL) && (sheet->Type() == SCH_SHEET_T),
                     wxT( "Cannot place sheet pin in invalid schematic sheet object." ) );

        undoItem = sheet;
    }

    else if( item->Type() == SCH_FIELD_T )
    {
        SCH_COMPONENT* cmp = (SCH_COMPONENT*) item->GetParent();

        wxCHECK_RET( (cmp != NULL) && (cmp->Type() == SCH_COMPONENT_T),
                     wxT( "Cannot place field in invalid schematic component object." ) );

        undoItem = cmp;
    }

    if( item->IsNew() )
    {
        if( item->Type() == SCH_SHEET_T )
        {
            // Fix the size and position of the new sheet using the last values set by
            // the m_mouseCaptureCallback function.
            m_canvas->SetMouseCapture( NULL, NULL );

            if( !EditSheet( (SCH_SHEET*)item, aDC ) )
            {
                screen->SetCurItem( NULL );
                item->Draw( m_canvas, aDC, wxPoint( 0, 0 ), g_XorMode );
                delete item;
                return;
            }

            SetSheetNumberAndCount();
        }

        if( undoItem == item )
        {
            if( !screen->CheckIfOnDrawList( item ) )  // don't want a loop!
                screen->Append( item );

            SetRepeatItem( item );

            SaveCopyInUndoList( undoItem, UR_NEW );
        }
        else
        {
            // Here, item is not a basic schematic item, but an item inside
            // a parent basic schematic item,
            // currently: sheet pin or component field.
            // currently, only a sheet pin can be found as new item,
            // because new component fields have a specific handling, and do not appears here
            SaveCopyInUndoList( undoItem, UR_CHANGED );

            if( item->Type() == SCH_SHEET_PIN_T )
                ( (SCH_SHEET*)undoItem )->AddPin( (SCH_SHEET_PIN*) item );
            else
                wxLogMessage(wxT( "addCurrentItemToList: expected type = SCH_SHEET_PIN_T, actual type = %d" ),
                            item->Type() );
        }
    }
    else
    {
        SaveUndoItemInUndoList( undoItem );
    }

    // Erase the wire representation before the 'normal' view is drawn.
    if ( item->IsWireImage() )
        item->Draw( m_canvas, aDC, wxPoint( 0, 0 ), g_XorMode );

    item->ClearFlags();
    screen->SetModify();
    screen->SetCurItem( NULL );
    m_canvas->SetMouseCapture( NULL, NULL );
    m_canvas->EndMouseCapture();

    if( item->IsConnectable() )
        screen->TestDanglingEnds();

    if( aDC )
    {
        EDA_CROSS_HAIR_MANAGER( m_canvas, aDC );  // Erase schematic cursor
        undoItem->Draw( m_canvas, aDC, wxPoint( 0, 0 ), GR_DEFAULT_DRAWMODE );
    }
}