Commit f37812f8 authored by Lorenzo Marcantonio's avatar Lorenzo Marcantonio
Browse files

Refactoring: split in two the SCH_BUS_ENTRY class

parent 0dd413a7
Loading
Loading
Loading
Loading
+14 −6
Original line number Diff line number Diff line
@@ -43,28 +43,36 @@
static int     s_LastShape = '\\';


SCH_BUS_ENTRY* SCH_EDIT_FRAME::CreateBusEntry( wxDC* aDC, int aType )
SCH_BUS_BUS_ENTRY* SCH_EDIT_FRAME::CreateBusBusEntry( wxDC* aDC )
{
    SCH_SCREEN* screen = GetScreen();

    // Create and place a new bus entry at cursor position
    SCH_BUS_ENTRY* busEntry = new SCH_BUS_ENTRY( screen->GetCrossHairPosition(), s_LastShape,
                                                 aType );
    SCH_BUS_BUS_ENTRY* busEntry = new SCH_BUS_BUS_ENTRY( screen->GetCrossHairPosition(), s_LastShape );
    busEntry->SetFlags( IS_NEW );
    GetScreen()->SetCurItem( busEntry );
    addCurrentItemToList( aDC );
    return busEntry;
}

SCH_BUS_WIRE_ENTRY* SCH_EDIT_FRAME::CreateBusWireEntry( wxDC* aDC )
{
    SCH_SCREEN* screen = GetScreen();

    // Create and place a new bus entry at cursor position
    SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( screen->GetCrossHairPosition(), s_LastShape );
    busEntry->SetFlags( IS_NEW );
    GetScreen()->SetCurItem( busEntry );
    addCurrentItemToList( aDC );
    return busEntry;
}

/* set the shape of BusEntry (shape = / or \ )
 */
void SCH_EDIT_FRAME::SetBusEntryShape( wxDC* DC, SCH_BUS_ENTRY* BusEntry, int entry_shape )
void SCH_EDIT_FRAME::SetBusEntryShape( wxDC* DC, SCH_BUS_ENTRY_BASE* BusEntry, char entry_shape )
{
    if( BusEntry == NULL )
        return;

    if( BusEntry->Type() != SCH_BUS_ENTRY_T )
    {
        DisplayError( this, wxT( "SetBusEntryType: Bad StructType" ) );
        return;
+8 −1
Original line number Diff line number Diff line
@@ -147,6 +147,7 @@ again." );

    while( reader.ReadLine() )
    {
        itemLoaded = false;
        line = reader.Line();

        item = NULL;
@@ -167,6 +168,8 @@ again." );
                itemLoaded = ReadSchemaDescr( &reader, msgDiag, aScreen );
            else if( line[1] == 'B' )
                item = new SCH_BITMAP();
            else if( line[1] == 'E' )
                itemLoaded = true; // The EOF marker
            break;

        case 'L':        // Its a library item.
@@ -178,7 +181,9 @@ again." );
            break;

        case 'E':        // Its a WIRE or BUS item.
            item = new SCH_BUS_ENTRY();
            /* The bus entry can be represented by two different
             * classes, so we need a factory function */
            itemLoaded = SCH_BUS_ENTRY_BASE::Load( reader, msgDiag, &item );
            break;

        case 'C':        // It is a connection item.
@@ -220,6 +225,8 @@ again." );

        if( item )
        {
            // Load it if it wasn't by a factory
            if( !itemLoaded )
            itemLoaded = item->Load( reader, msgDiag );

            if( !itemLoaded )
+13 −3
Original line number Diff line number Diff line
@@ -70,7 +70,8 @@ void SCH_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition )
            case SCH_TEXT_T:
            case SCH_SHEET_PIN_T:
            case SCH_SHEET_T:
            case SCH_BUS_ENTRY_T:
            case SCH_BUS_WIRE_ENTRY_T:
            case SCH_BUS_BUS_ENTRY_T:
            case SCH_JUNCTION_T:
            case SCH_COMPONENT_T:
            case SCH_FIELD_T:
@@ -157,11 +158,20 @@ void SCH_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition )
        break;

    case ID_WIRETOBUS_ENTRY_BUTT:
        if( ( item == NULL ) || ( item->GetFlags() == 0 ) )
        {
            CreateBusWireEntry( aDC );
            m_canvas->SetAutoPanRequest( true );
        }
        else
        {
            addCurrentItemToList( aDC );
        }
        break;
    case ID_BUSTOBUS_ENTRY_BUTT:
        if( ( item == NULL ) || ( item->GetFlags() == 0 ) )
        {
            CreateBusEntry( aDC, ( GetToolId() == ID_WIRETOBUS_ENTRY_BUTT ) ?
                            WIRE_TO_BUS : BUS_TO_BUS );
            CreateBusBusEntry( aDC );
            m_canvas->SetAutoPanRequest( true );
        }
        else
+5 −4
Original line number Diff line number Diff line
@@ -64,7 +64,7 @@ static void AddMenusForComponent( wxMenu* PopMenu, SCH_COMPONENT* Component );
static void AddMenusForComponentField( wxMenu* PopMenu, SCH_FIELD* Field );
static void AddMenusForMarkers( wxMenu* aPopMenu, SCH_MARKER* aMarker, SCH_EDIT_FRAME* aFrame );
static void AddMenusForBitmap( wxMenu* aPopMenu, SCH_BITMAP * aBitmap );
static void AddMenusForBusEntry( wxMenu* aPopMenu, SCH_BUS_ENTRY * aBusEntry );
static void AddMenusForBusEntry( wxMenu* aPopMenu, SCH_BUS_ENTRY_BASE * aBusEntry );



@@ -219,8 +219,9 @@ bool SCH_EDIT_FRAME::OnRightClick( const wxPoint& aPosition, wxMenu* PopMenu )
        addJunctionMenuEntries( PopMenu, (SCH_JUNCTION*) item );
        break;

    case SCH_BUS_ENTRY_T:
        AddMenusForBusEntry( PopMenu, (SCH_BUS_ENTRY*) item );
    case SCH_BUS_BUS_ENTRY_T:
    case SCH_BUS_WIRE_ENTRY_T:
        AddMenusForBusEntry( PopMenu, dynamic_cast<SCH_BUS_ENTRY_BASE*>( item ) );
        break;

    case SCH_MARKER_T:
@@ -873,7 +874,7 @@ void AddMenusForBitmap( wxMenu* aPopMenu, SCH_BITMAP * aBitmap )
    }
}

void AddMenusForBusEntry( wxMenu* aPopMenu, SCH_BUS_ENTRY * aBusEntry )
void AddMenusForBusEntry( wxMenu* aPopMenu, SCH_BUS_ENTRY_BASE* aBusEntry )
{
    wxString msg;
    if( !aBusEntry->GetFlags() )
+4 −2
Original line number Diff line number Diff line
@@ -31,7 +31,8 @@ void SetSchItemParent( SCH_ITEM* Struct, SCH_SCREEN* Screen )
    case SCH_HIERARCHICAL_LABEL_T:
    case SCH_COMPONENT_T:
    case SCH_LINE_T:
    case SCH_BUS_ENTRY_T:
    case SCH_BUS_BUS_ENTRY_T:
    case SCH_BUS_WIRE_ENTRY_T:
    case SCH_SHEET_T:
    case SCH_MARKER_T:
    case SCH_NO_CONNECT_T:
@@ -185,7 +186,8 @@ void DuplicateItemsInList( SCH_SCREEN* screen, PICKED_ITEMS_LIST& aItemsList,
            {
            case SCH_JUNCTION_T:
            case SCH_LINE_T:
            case SCH_BUS_ENTRY_T:
            case SCH_BUS_BUS_ENTRY_T:
            case SCH_BUS_WIRE_ENTRY_T:
            case SCH_TEXT_T:
            case SCH_LABEL_T:
            case SCH_GLOBAL_LABEL_T:
Loading