void LIB_EDIT_FRAME::pasteClipboard( const wxPoint& aOffset )
{
    LIB_PART* part = GetCurPart();

    if( !part || m_clipboard.GetCount() == 0 )
        return;

    for( unsigned int i = 0; i < m_clipboard.GetCount(); i++ )
    {
        // Append a copy to the current part, so the clipboard buffer might be pasted multiple times
        LIB_ITEM* item = (LIB_ITEM*) m_clipboard.GetItem( i )->Clone();
        item->SetParent( part );
        item->SetSelected();
        item->SetUnit( GetUnit() );
        part->AddDrawItem( item );
    }

    BlockMoveSelectedItems( aOffset, GetCurPart(), &GetScreen()->m_BlockLocate );
    RebuildView();
    GetCanvas()->Refresh();
    OnModify();
}
void LIB_EDIT_FRAME::InitBlockPasteInfos()
{
    BLOCK_SELECTOR& block = GetScreen()->m_BlockLocate;

    // Copy the clipboard contents to the screen block selector
    // (only the copy, the new instances will be appended to the part once the items are placed)
    block.GetItems().CopyList( m_clipboard.GetItems() );

    // Set block items to the current unit & DeMorgan variant
    for( size_t i = 0; i < m_clipboard.GetItems().GetCount(); ++i )
    {
        LIB_ITEM* item = dynamic_cast<LIB_ITEM*>( m_clipboard.GetItem( i ) );

        if( item )
        {
            item->SetUnit( m_unit );
            item->SetConvert( m_convert );
        }
    }

    // Set the paste reference point
    block.SetLastCursorPosition( m_clipboard.GetLastCursorPosition() );
    m_canvas->SetMouseCaptureCallback( DrawMovingBlockOutlines );
}
Esempio n. 3
0
LIB_ITEM* LIB_EDIT_FRAME::CreateGraphicItem( LIB_PART* LibEntry, wxDC* DC )
{
    LIB_ITEM* item = GetDrawItem();
    m_canvas->SetMouseCapture( SymbolDisplayDraw, AbortSymbolTraceOn );
    wxPoint drawPos = GetCrossHairPosition( true );

    // no temp copy -> the current version of symbol will be used for Undo
    // This is normal when adding new items to the current symbol
    ClearTempCopyComponent();

    switch( GetToolId() )
    {
    case ID_LIBEDIT_BODY_ARC_BUTT:
        item = new LIB_ARC( LibEntry );
        break;

    case ID_LIBEDIT_BODY_CIRCLE_BUTT:
        item = new LIB_CIRCLE( LibEntry );
        break;

    case ID_LIBEDIT_BODY_RECT_BUTT:
        item = new LIB_RECTANGLE( LibEntry );
        break;

    case ID_LIBEDIT_BODY_LINE_BUTT:
        item = new LIB_POLYLINE( LibEntry );
        break;

    case ID_LIBEDIT_BODY_TEXT_BUTT:
        {
            LIB_TEXT* text = new LIB_TEXT( LibEntry );
            text->SetTextSize( wxSize( m_textSize, m_textSize ) );
            text->SetTextAngle( m_current_text_angle );

            // Enter the graphic text info
            m_canvas->SetIgnoreMouseEvents( true );
            EditSymbolText( NULL, text );

            m_canvas->SetIgnoreMouseEvents( false );
            m_canvas->MoveCursorToCrossHair();

            if( text->GetText().IsEmpty() )
            {
                delete text;
                item = NULL;
            }
            else
            {
                item = text;
            }
        }
        break;

    default:
        DisplayError( this, wxT( "LIB_EDIT_FRAME::CreateGraphicItem() error" ) );
        return NULL;
    }

    if( item )
    {
        item->BeginEdit( IS_NEW, drawPos );

        // Don't set line parameters for text objects.
        if( item->Type() != LIB_TEXT_T )
        {
            item->SetWidth( m_drawLineWidth );
            item->SetFillMode( m_drawFillStyle );
        }

        if( m_drawSpecificUnit )
            item->SetUnit( m_unit );

        if( m_drawSpecificConvert )
            item->SetConvert( m_convert );

        // Draw initial symbol:
        m_canvas->CallMouseCapture( DC, wxDefaultPosition, false );
    }
    else
    {
        m_canvas->EndMouseCapture();
        return NULL;
    }

    m_canvas->MoveCursorToCrossHair();
    m_canvas->SetIgnoreMouseEvents( false );
    SetDrawItem( item );

    return item;
}