Exemplo n.º 1
0
void LIB_EDIT_FRAME::EndDrawGraphicItem( wxDC* DC )
{
    LIB_ITEM* item = GetDrawItem();

    if( item == NULL )
        return;

    if( LIB_PART* part = GetCurPart() )
    {
        if( GetToolId() != ID_NO_TOOL_SELECTED )
            SetCursor( wxCURSOR_PENCIL );
        else
            SetCursor( (wxStockCursor) m_canvas->GetDefaultCursor() );

        if( GetTempCopyComponent() )    // used when editing an existing item
            SaveCopyInUndoList( GetTempCopyComponent() );
        else
        {
            // When creating a new item, there is still no change for the
            // current symbol. So save it.
            SaveCopyInUndoList( part );
        }

        if( item->IsNew() )
            part->AddDrawItem( item );

        item->EndEdit( GetCrossHairPosition( true ) );

        SetDrawItem( NULL );

        OnModify();

        m_canvas->SetMouseCapture( NULL, NULL );
        m_canvas->Refresh();
    }
}
Exemplo n.º 2
0
/**
 * Managed cursor callback for placing component pins.
 */
void LIB_EDIT_FRAME::PlacePin()
{
    LIB_PIN* cur_pin  = (LIB_PIN*) m_drawItem;
    bool     ask_for_pin = true;
    wxPoint  newpos;
    bool     status;

    // Some tests
    if( !cur_pin || cur_pin->Type() != LIB_PIN_T )
    {
        wxMessageBox( wxT( "LIB_EDIT_FRAME::PlacePin() error" ) );
        return;
    }

    newpos = GetCrossHairPosition( true );

    LIB_PART*      part = GetCurPart();

    // Test for an other pin in same new position:
    for( LIB_PIN* pin = part->GetNextPin();  pin;  pin = part->GetNextPin( pin ) )
    {
        if( pin == cur_pin || newpos != pin->GetPosition() || pin->GetFlags() )
            continue;

        if( ask_for_pin && SynchronizePins() )
        {
            m_canvas->SetIgnoreMouseEvents( true );

            status = IsOK( this, _( "This position is already occupied by another pin. Continue?" ) );

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

            if( !status )
                return;
            else
                ask_for_pin = false;
        }
    }

    // Create Undo from GetTempCopyComponent() if exists ( i.e. after a pin move)
    // or from m_component (pin add ...)
    if( GetTempCopyComponent() )
        SaveCopyInUndoList( GetTempCopyComponent() );
    else
        SaveCopyInUndoList( part );

    m_canvas->SetMouseCapture( NULL, NULL );
    OnModify();
    cur_pin->Move( newpos );

    if( cur_pin->IsNew() )
    {
        LastPinOrient = cur_pin->GetOrientation();
        LastPinType   = cur_pin->GetType();
        LastPinShape  = cur_pin->GetShape();

        if( SynchronizePins() )
            CreateImagePins( cur_pin, m_unit, m_convert, m_showDeMorgan );

        m_lastDrawItem = cur_pin;
        part->AddDrawItem( m_drawItem );
    }

    // Put linked pins in new position, and clear flags
    for( LIB_PIN* pin = part->GetNextPin();  pin;  pin = part->GetNextPin( pin ) )
    {
        if( pin->GetFlags() == 0 )
            continue;

        pin->Move( cur_pin->GetPosition() );
        pin->ClearFlags();
    }

    m_drawItem = NULL;

    m_canvas->Refresh();
}