Пример #1
0
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();
}
Пример #2
0
// This function is a callback function, called by the mouse cursor movin event
// when an item is currently moved
static void moveItemWithMouseCursor( EDA_DRAW_PANEL* aPanel, wxDC* aDC,
                                     const wxPoint& aPosition, bool aErase )
{
    SCH_SCREEN* screen = (SCH_SCREEN*) aPanel->GetScreen();
    SCH_ITEM*   item   = screen->GetCurItem();

    wxCHECK_RET( (item != NULL), wxT( "Cannot move invalid schematic item." ) );

    SCH_COMPONENT* cmp = NULL;

    if( item->Type() == SCH_COMPONENT_T )
        cmp = static_cast< SCH_COMPONENT* >( item );

#ifndef USE_WX_OVERLAY
    // Erase the current item at its current position.
    if( aErase )
    {
        if( cmp )   // Use fast mode (do not draw pin texts)
            cmp->Draw( aPanel, aDC, wxPoint( 0, 0 ), g_XorMode, UNSPECIFIED_COLOR, false );
        else
            item->Draw( aPanel, aDC, wxPoint( 0, 0 ), g_XorMode );
    }
#endif

    wxPoint cpos = aPanel->GetParent()->GetCrossHairPosition();
    cpos -= item->GetStoredPos();

    item->SetPosition( cpos );

    // Draw the item item at it's new position.
    item->SetWireImage();  // While moving, the item may choose to render differently

    if( cmp )   // Use fast mode (do not draw pin texts)
        cmp->Draw( aPanel, aDC, wxPoint( 0, 0 ), g_XorMode, UNSPECIFIED_COLOR, false );
    else
        item->Draw( aPanel, aDC, wxPoint( 0, 0 ), g_XorMode );
}
void SCH_EDIT_FRAME::OnCopySchematicItemRequest( wxCommandEvent& event )
{
    SCH_ITEM * curr_item = GetScreen()->GetCurItem();

    if( !curr_item || curr_item->GetFlags() )
        return;

    INSTALL_UNBUFFERED_DC( dc, m_canvas );

    switch( curr_item->Type() )
    {
    case SCH_COMPONENT_T:
    {
        SCH_COMPONENT* newitem;
        newitem = new SCH_COMPONENT( *( (SCH_COMPONENT*) curr_item ) );
        newitem->SetTimeStamp( GetNewTimeStamp() );
        newitem->ClearAnnotation( NULL );
        newitem->SetFlags( IS_NEW );
        // Draw the new part, MoveItem() expects it to be already on screen.
        newitem->Draw( m_canvas, &dc, wxPoint( 0, 0 ), g_XorMode );
        PrepareMoveItem( newitem, &dc );
    }
    break;

    case SCH_TEXT_T:
    case SCH_LABEL_T:
    case SCH_GLOBAL_LABEL_T:
    case SCH_HIERARCHICAL_LABEL_T:
    {
        SCH_TEXT* newitem = (SCH_TEXT*) curr_item->Clone();
        newitem->SetFlags( IS_NEW );
        // Draw the new item, MoveItem() expects it to be already on screen.
        newitem->Draw( m_canvas, &dc, wxPoint( 0, 0 ), g_XorMode );
        PrepareMoveItem( newitem, &dc );
    }
        break;

    default:
        break;
    }
}
Пример #4
0
SCH_COMPONENT* SCH_EDIT_FRAME::Load_Component( wxDC*                          aDC,
                                               const SCHLIB_FILTER*           aFilter,
                                               SCH_BASE_FRAME::HISTORY_LIST&  aHistoryList,
                                               bool                           aUseLibBrowser )
{
    wxString msg;

    SetRepeatItem( NULL );
    m_canvas->SetIgnoreMouseEvents( true );

    auto sel = SelectComponentFromLibrary( aFilter, aHistoryList, aUseLibBrowser, 1, 1,
                                           m_footprintPreview );

    if( !sel.LibId.IsValid() )
    {
        m_canvas->SetIgnoreMouseEvents( false );
        m_canvas->MoveCursorToCrossHair();
        return NULL;
    }

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

    wxString libsource;     // the library name to use. If empty, load from any lib

    if( aFilter )
        libsource = aFilter->GetLibSource();

    LIB_ID libId = sel.LibId;

    LIB_PART* part = GetLibPart( libId, true );

    if( !part )
        return NULL;

    SCH_COMPONENT* component = new SCH_COMPONENT( *part, m_CurrentSheet, sel.Unit, sel.Convert,
                                                  GetCrossHairPosition(), true );

    // Set the m_ChipName value, from component name in lib, for aliases
    // Note if part is found, and if name is an alias of a component,
    // alias exists because its root component was found
    component->SetLibId( libId );

    // Be sure the link to the corresponding LIB_PART is OK:
    component->Resolve( *Prj().SchSymbolLibTable() );

    // Set any fields that have been modified
    for( auto const& i : sel.Fields )
    {
        auto field = component->GetField( i.first );

        if( field )
            field->SetText( i.second );
    }

    // Set the component value that can differ from component name in lib, for aliases
    component->GetField( VALUE )->SetText( sel.LibId.GetLibItemName() );

    // If there is no field defined in the component, copy one over from the library
    // ( from the .dcm file )
    // This way the Datasheet field will not be empty and can be changed from the schematic
    if( component->GetField( DATASHEET )->GetText().IsEmpty() )
    {
        LIB_ALIAS* entry = GetLibAlias( component->GetLibId(), true, true );

        if( entry && !!entry->GetDocFileName() )
            component->GetField( DATASHEET )->SetText( entry->GetDocFileName() );
    }

    MSG_PANEL_ITEMS items;

    component->SetCurrentSheetPath( &GetCurrentSheet() );
    component->GetMsgPanelInfo( items );

    SetMsgPanel( items );
    component->Draw( m_canvas, aDC, wxPoint( 0, 0 ), g_XorMode );
    component->SetFlags( IS_NEW );

    if( m_autoplaceFields )
        component->AutoplaceFields( /* aScreen */ NULL, /* aManual */ false );

    PrepareMoveItem( (SCH_ITEM*) component, aDC );

    return component;
}