Commit 9769c9b6 authored by Wayne Stambaugh's avatar Wayne Stambaugh
Browse files

Minor EESchema code improvements.

* Factor change schematic component orientation code out of switch statement
  into separate function.
* Remove redundant command events from schematic editor hot key handler.
parent 098a20a0
Loading
Loading
Loading
Loading
+7 −5
Original line number Original line Diff line number Diff line
@@ -61,11 +61,6 @@ enum id_eeschema_frm
    ID_POPUP_SCH_ENTRY_SELECT_ANTISLASH,
    ID_POPUP_SCH_ENTRY_SELECT_ANTISLASH,


    ID_POPUP_SCH_EDIT_CMP,
    ID_POPUP_SCH_EDIT_CMP,
    ID_POPUP_SCH_MIROR_X_CMP,
    ID_POPUP_SCH_MIROR_Y_CMP,
    ID_POPUP_SCH_ROTATE_CMP_CLOCKWISE,
    ID_POPUP_SCH_ROTATE_CMP_COUNTERCLOCKWISE,
    ID_POPUP_SCH_ORIENT_NORMAL_CMP,
    ID_POPUP_SCH_INIT_CMP,
    ID_POPUP_SCH_INIT_CMP,


    ID_POPUP_SCH_EDIT_TEXT,
    ID_POPUP_SCH_EDIT_TEXT,
@@ -132,6 +127,13 @@ enum id_eeschema_frm
    ID_POPUP_SCH_CHANGE_TYPE_TEXT_TO_HLABEL,
    ID_POPUP_SCH_CHANGE_TYPE_TEXT_TO_HLABEL,
    ID_POPUP_SCH_CHANGE_TYPE_TEXT_TO_COMMENT,
    ID_POPUP_SCH_CHANGE_TYPE_TEXT_TO_COMMENT,


    // Change component orientation context menu command IDs.
    ID_POPUP_SCH_MIROR_X_CMP,
    ID_POPUP_SCH_MIROR_Y_CMP,
    ID_POPUP_SCH_ROTATE_CMP_CLOCKWISE,
    ID_POPUP_SCH_ROTATE_CMP_COUNTERCLOCKWISE,
    ID_POPUP_SCH_ORIENT_NORMAL_CMP,

    // Schematic editor commmands.  These are command IDs that are generated by multiple
    // Schematic editor commmands.  These are command IDs that are generated by multiple
    // events (menus, toolbar, context menu, etc.) that result in the same event handler.
    // events (menus, toolbar, context menu, etc.) that result in the same event handler.
    ID_CANCEL_CURRENT_COMMAND,
    ID_CANCEL_CURRENT_COMMAND,
+58 −22
Original line number Original line Diff line number Diff line
@@ -244,37 +244,73 @@ static void ShowWhileMoving( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& a
 *
 *
 ** If DC == NULL: no repaint
 ** If DC == NULL: no repaint
 */
 */
void SCH_EDIT_FRAME::CmpRotationMiroir( SCH_COMPONENT* DrawComponent, wxDC* DC, int type_rotate )
void SCH_EDIT_FRAME::OnChangeComponentOrientation( wxCommandEvent& aEvent )
{
{
    if( DrawComponent == NULL )
    SCH_SCREEN* screen = GetScreen();
        return;


    /* Deletes the previous component. */
    // Ensure the struct is a component (could be a struct of a
    if( DC )
    // component, like Field, text..)
    if( screen->GetCurItem() == NULL || screen->GetCurItem()->Type() != SCH_COMPONENT_T )
    {
    {
        DrawPanel->CrossHairOff( DC );
        screen->SetCurItem( LocateSmallestComponent( screen ) );


        if( DrawComponent->m_Flags )
        if( screen->GetCurItem() == NULL || screen->GetCurItem()->Type() != SCH_COMPONENT_T )
            DrawComponent->Draw( DrawPanel, DC, wxPoint( 0, 0 ), g_XorMode, g_GhostColor );
            return;
        else
        {
            DrawPanel->RefreshDrawingRect( DrawComponent->GetBoundingBox() );
    }
    }

    SCH_COMPONENT* component = (SCH_COMPONENT*) screen->GetCurItem();

    int orientation;

    switch( aEvent.GetId() )
    {
    case ID_POPUP_SCH_MIROR_X_CMP:
        orientation = CMP_MIRROR_X;
        break;

    case ID_POPUP_SCH_MIROR_Y_CMP:
        orientation = CMP_MIRROR_Y;
        break;

    case ID_POPUP_SCH_ROTATE_CMP_COUNTERCLOCKWISE:
        orientation = CMP_ROTATE_COUNTERCLOCKWISE;
        break;

    case ID_POPUP_SCH_ROTATE_CMP_CLOCKWISE:
        orientation = CMP_ROTATE_CLOCKWISE;
        break;

    case ID_POPUP_SCH_ORIENT_NORMAL_CMP:
    default:
        orientation = CMP_NORMAL;
    }
    }


    DrawComponent->SetOrientation( type_rotate );
    DrawPanel->MoveCursorToCrossHair();

    if( screen->GetCurItem()->GetFlags() == 0 )
        SaveCopyInUndoList( screen->GetCurItem(), UR_CHANGED );

    INSTALL_UNBUFFERED_DC( dc, DrawPanel );

    // Erase the previous component in it's current orientation.

    DrawPanel->CrossHairOff( &dc );

    if( component->GetFlags() )
        component->Draw( DrawPanel, &dc, wxPoint( 0, 0 ), g_XorMode, g_GhostColor );
    else
        DrawPanel->RefreshDrawingRect( component->GetBoundingBox() );

    component->SetOrientation( orientation );


    /* Redraw the component in the new position. */
    /* Redraw the component in the new position. */
    if( DC )
    if( component->GetFlags() )
    {
        component->Draw( DrawPanel, &dc, wxPoint( 0, 0 ), g_XorMode, g_GhostColor );
        if( DrawComponent->m_Flags )
            DrawComponent->Draw( DrawPanel, DC, wxPoint( 0, 0 ), g_XorMode, g_GhostColor );
    else
    else
            DrawComponent->Draw( DrawPanel, DC, wxPoint( 0, 0 ), GR_DEFAULT_DRAWMODE );
        component->Draw( DrawPanel, &dc, wxPoint( 0, 0 ), GR_DEFAULT_DRAWMODE );
        DrawPanel->CrossHairOn( DC );
    }


    GetScreen()->TestDanglingEnds( DrawPanel, DC );
    DrawPanel->CrossHairOn( &dc );
    GetScreen()->TestDanglingEnds( DrawPanel, &dc );
    OnModify();
    OnModify();
}
}


+24 −45
Original line number Original line Diff line number Diff line
@@ -584,14 +584,6 @@ void SCH_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition,
        {
        {
            GetScreen()->SetCurItem( (SCH_ITEM*) aItem );
            GetScreen()->SetCurItem( (SCH_ITEM*) aItem );


            // Create the events for rotating a component or other schematic item
            wxCommandEvent eventRotateComponent( wxEVT_COMMAND_TOOL_CLICKED,
                                                 ID_POPUP_SCH_ROTATE_CMP_COUNTERCLOCKWISE );
            wxCommandEvent eventRotateText( wxEVT_COMMAND_TOOL_CLICKED,
                                            ID_POPUP_SCH_ROTATE_TEXT );
            wxCommandEvent eventRotateField( wxEVT_COMMAND_TOOL_CLICKED,
                                             ID_POPUP_SCH_ROTATE_FIELD );

            switch( aItem->Type() )
            switch( aItem->Type() )
            {
            {
            case SCH_SHEET_T: //TODO allow sheet rotate on hotkey
            case SCH_SHEET_T: //TODO allow sheet rotate on hotkey
@@ -599,18 +591,21 @@ void SCH_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition,
                break;
                break;


            case SCH_COMPONENT_T:
            case SCH_COMPONENT_T:
                wxPostEvent( this, eventRotateComponent );
                cmd.SetId( ID_POPUP_SCH_ROTATE_CMP_COUNTERCLOCKWISE );
                wxPostEvent( this, cmd );
                break;
                break;


            case SCH_TEXT_T:
            case SCH_TEXT_T:
            case SCH_LABEL_T:
            case SCH_LABEL_T:
            case SCH_GLOBAL_LABEL_T:
            case SCH_GLOBAL_LABEL_T:
            case SCH_HIERARCHICAL_LABEL_T:
            case SCH_HIERARCHICAL_LABEL_T:
                wxPostEvent( this, eventRotateText );
                cmd.SetId( ID_POPUP_SCH_ROTATE_TEXT );
                wxPostEvent( this, cmd );
                break;
                break;


            case SCH_FIELD_T:
            case SCH_FIELD_T:
                wxPostEvent( this, eventRotateField );
                cmd.SetId( ID_POPUP_SCH_ROTATE_FIELD );
                wxPostEvent( this, cmd );


            default:
            default:
                ;
                ;
@@ -631,12 +626,9 @@ void SCH_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition,


        if( aItem )
        if( aItem )
        {
        {
            if( aItem->m_Flags == 0 )
            screen->SetCurItem( (SCH_ITEM*) aItem );
            {
            cmd.SetId( ID_POPUP_SCH_MIROR_Y_CMP );
                SaveCopyInUndoList( (SCH_ITEM*) aItem, UR_CHANGED );
            GetEventHandler()->ProcessEvent( cmd );
            }

            CmpRotationMiroir( (SCH_COMPONENT*) aItem, aDC, CMP_MIRROR_Y );
        }
        }
        break;
        break;


@@ -652,12 +644,9 @@ void SCH_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition,


        if( aItem )
        if( aItem )
        {
        {
            if( aItem->m_Flags == 0 )
            screen->SetCurItem( (SCH_ITEM*) aItem );
            {
            cmd.SetId( ID_POPUP_SCH_MIROR_X_CMP );
                SaveCopyInUndoList( (SCH_ITEM*) aItem, UR_CHANGED );
            GetEventHandler()->ProcessEvent( cmd );
            }

            CmpRotationMiroir( (SCH_COMPONENT*) aItem, aDC, CMP_MIRROR_X );
        }
        }
        break;
        break;


@@ -667,13 +656,9 @@ void SCH_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition,


        if( aItem )
        if( aItem )
        {
        {
            if( aItem->m_Flags == 0 )
            screen->SetCurItem( (SCH_ITEM*) aItem );
            {
            cmd.SetId( ID_POPUP_SCH_ORIENT_NORMAL_CMP );
                SaveCopyInUndoList( (SCH_ITEM*) aItem, UR_CHANGED );
            GetEventHandler()->ProcessEvent( cmd );
            }

            CmpRotationMiroir( (SCH_COMPONENT*) aItem, aDC, CMP_NORMAL );
            GetScreen()->TestDanglingEnds( DrawPanel, aDC );
        }
        }


        break;
        break;
@@ -736,8 +721,6 @@ void SCH_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition,
            GetScreen()->SetCurItem( (SCH_ITEM*) aItem );
            GetScreen()->SetCurItem( (SCH_ITEM*) aItem );


            // Create the events for moving a component or other schematic item
            // Create the events for moving a component or other schematic item
            wxCommandEvent eventMoveOrDragComponent( wxEVT_COMMAND_TOOL_CLICKED,
                                                     HK_Descr->m_IdMenuEvent );
            wxCommandEvent eventMoveItem( wxEVT_COMMAND_TOOL_CLICKED,
            wxCommandEvent eventMoveItem( wxEVT_COMMAND_TOOL_CLICKED,
                                          ID_POPUP_SCH_MOVE_ITEM_REQUEST );
                                          ID_POPUP_SCH_MOVE_ITEM_REQUEST );
            wxCommandEvent eventMovePinsheet( wxEVT_COMMAND_TOOL_CLICKED,
            wxCommandEvent eventMovePinsheet( wxEVT_COMMAND_TOOL_CLICKED,
@@ -751,13 +734,11 @@ void SCH_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition,
            // and add it to the event queue
            // and add it to the event queue
            case SCH_SHEET_T:
            case SCH_SHEET_T:
            case SCH_COMPONENT_T:
            case SCH_COMPONENT_T:
                wxPostEvent( this, eventMoveOrDragComponent );
                break;

            case SCH_LABEL_T:
            case SCH_LABEL_T:
            case SCH_GLOBAL_LABEL_T:
            case SCH_GLOBAL_LABEL_T:
            case SCH_HIERARCHICAL_LABEL_T:
            case SCH_HIERARCHICAL_LABEL_T:
                wxPostEvent( this, eventMoveOrDragComponent );
                cmd.SetId( HK_Descr->m_IdMenuEvent );
                wxPostEvent( this, cmd );
                break;
                break;


            case SCH_TEXT_T:
            case SCH_TEXT_T:
@@ -810,9 +791,6 @@ void SCH_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition,


        if( aItem )
        if( aItem )
        {
        {
            wxCommandEvent eventEditPinsheet( wxEVT_COMMAND_TOOL_CLICKED,
                                              ID_POPUP_SCH_EDIT_SHEET );

            switch( aItem->Type() )
            switch( aItem->Type() )
            {
            {
            case SCH_COMPONENT_T:
            case SCH_COMPONENT_T:
@@ -821,7 +799,8 @@ void SCH_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition,


            case SCH_SHEET_T:
            case SCH_SHEET_T:
                GetScreen()->SetCurItem( (SCH_ITEM*) aItem );
                GetScreen()->SetCurItem( (SCH_ITEM*) aItem );
                wxPostEvent( this, eventEditPinsheet );
                cmd.SetId( ID_POPUP_SCH_EDIT_SHEET );
                wxPostEvent( this, cmd );
                break;
                break;


            case SCH_TEXT_T:
            case SCH_TEXT_T:
+0 −49
Original line number Original line Diff line number Diff line
@@ -56,11 +56,6 @@ void SCH_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event )
    case ID_POPUP_SCH_DRAG_CMP_REQUEST:
    case ID_POPUP_SCH_DRAG_CMP_REQUEST:
    case ID_POPUP_SCH_DRAG_WIRE_REQUEST:
    case ID_POPUP_SCH_DRAG_WIRE_REQUEST:
    case ID_POPUP_SCH_EDIT_CMP:
    case ID_POPUP_SCH_EDIT_CMP:
    case ID_POPUP_SCH_MIROR_X_CMP:
    case ID_POPUP_SCH_MIROR_Y_CMP:
    case ID_POPUP_SCH_ROTATE_CMP_CLOCKWISE:
    case ID_POPUP_SCH_ROTATE_CMP_COUNTERCLOCKWISE:
    case ID_POPUP_SCH_ORIENT_NORMAL_CMP:
    case ID_POPUP_SCH_INIT_CMP:
    case ID_POPUP_SCH_INIT_CMP:
    case ID_POPUP_SCH_DISPLAYDOC_CMP:
    case ID_POPUP_SCH_DISPLAYDOC_CMP:
    case ID_POPUP_SCH_EDIT_VALUE_CMP:
    case ID_POPUP_SCH_EDIT_VALUE_CMP:
@@ -341,50 +336,6 @@ void SCH_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event )
        InstallCmpeditFrame( this, (SCH_COMPONENT*) screen->GetCurItem() );
        InstallCmpeditFrame( this, (SCH_COMPONENT*) screen->GetCurItem() );
        break;
        break;


    case ID_POPUP_SCH_MIROR_X_CMP:
    case ID_POPUP_SCH_MIROR_Y_CMP:
    case ID_POPUP_SCH_ROTATE_CMP_CLOCKWISE:
    case ID_POPUP_SCH_ROTATE_CMP_COUNTERCLOCKWISE:
    case ID_POPUP_SCH_ORIENT_NORMAL_CMP:

        // Ensure the struct is a component (could be a struct of a
        // component, like Field, text..)
        if( screen->GetCurItem()->Type() != SCH_COMPONENT_T )
            screen->SetCurItem( LocateSmallestComponent( screen ) );

        if( screen->GetCurItem() == NULL )
            break;
        {
            int option;

            switch( id )
            {
            case ID_POPUP_SCH_MIROR_X_CMP:
                option = CMP_MIRROR_X; break;

            case ID_POPUP_SCH_MIROR_Y_CMP:
                option = CMP_MIRROR_Y; break;

            case ID_POPUP_SCH_ROTATE_CMP_COUNTERCLOCKWISE:
                option = CMP_ROTATE_COUNTERCLOCKWISE; break;

            case ID_POPUP_SCH_ROTATE_CMP_CLOCKWISE:
                option = CMP_ROTATE_CLOCKWISE; break;

            default:
            case ID_POPUP_SCH_ORIENT_NORMAL_CMP:
                option = CMP_NORMAL; break;
            }

            DrawPanel->MoveCursorToCrossHair();

            if( screen->GetCurItem()->m_Flags == 0 )
                SaveCopyInUndoList( (SCH_ITEM*) screen->GetCurItem(), UR_CHANGED );

            CmpRotationMiroir( (SCH_COMPONENT*) screen->GetCurItem(), &dc, option );
            break;
        }

    case ID_POPUP_SCH_INIT_CMP:
    case ID_POPUP_SCH_INIT_CMP:
        DrawPanel->MoveCursorToCrossHair();
        DrawPanel->MoveCursorToCrossHair();
        break;
        break;
+2 −0
Original line number Original line Diff line number Diff line
@@ -122,6 +122,8 @@ BEGIN_EVENT_TABLE( SCH_EDIT_FRAME, EDA_DRAW_FRAME )
                    SCH_EDIT_FRAME::OnSelectUnit )
                    SCH_EDIT_FRAME::OnSelectUnit )
    EVT_MENU_RANGE( ID_POPUP_SCH_CHANGE_TYPE_TEXT, ID_POPUP_SCH_CHANGE_TYPE_TEXT_TO_COMMENT,
    EVT_MENU_RANGE( ID_POPUP_SCH_CHANGE_TYPE_TEXT, ID_POPUP_SCH_CHANGE_TYPE_TEXT_TO_COMMENT,
                    SCH_EDIT_FRAME::OnConvertTextType )
                    SCH_EDIT_FRAME::OnConvertTextType )
    EVT_MENU_RANGE( ID_POPUP_SCH_MIROR_X_CMP, ID_POPUP_SCH_ORIENT_NORMAL_CMP,
                    SCH_EDIT_FRAME::OnChangeComponentOrientation )


    /* Handle user interface update events. */
    /* Handle user interface update events. */
    EVT_UPDATE_UI( wxID_CUT, SCH_EDIT_FRAME::OnUpdateBlockSelected )
    EVT_UPDATE_UI( wxID_CUT, SCH_EDIT_FRAME::OnUpdateBlockSelected )
Loading