From 9769c9b63cdcfa9ac4c152078770477890b6c428 Mon Sep 17 00:00:00 2001 From: Wayne Stambaugh Date: Thu, 3 Mar 2011 14:55:44 -0500 Subject: [PATCH] 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. --- eeschema/eeschema_id.h | 12 +++--- eeschema/getpart.cpp | 82 ++++++++++++++++++++++++++----------- eeschema/hotkeys.cpp | 69 +++++++++++-------------------- eeschema/schedit.cpp | 49 ---------------------- eeschema/schframe.cpp | 2 + gerbview/gerberframe.cpp | 2 +- include/class_base_screen.h | 4 +- include/class_sch_screen.h | 7 +--- include/wxEeschemaStruct.h | 3 +- 9 files changed, 98 insertions(+), 132 deletions(-) diff --git a/eeschema/eeschema_id.h b/eeschema/eeschema_id.h index 2e6c24570f..09ecc07a61 100644 --- a/eeschema/eeschema_id.h +++ b/eeschema/eeschema_id.h @@ -61,11 +61,6 @@ enum id_eeschema_frm ID_POPUP_SCH_ENTRY_SELECT_ANTISLASH, 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_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_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 // events (menus, toolbar, context menu, etc.) that result in the same event handler. ID_CANCEL_CURRENT_COMMAND, diff --git a/eeschema/getpart.cpp b/eeschema/getpart.cpp index 01c2a5e800..6bfab4da88 100644 --- a/eeschema/getpart.cpp +++ b/eeschema/getpart.cpp @@ -244,38 +244,74 @@ static void ShowWhileMoving( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& a * ** 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 ) - return; + SCH_SCREEN* screen = GetScreen(); - /* Deletes the previous component. */ - if( DC ) + // Ensure the struct is a component (could be a struct of a + // 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 ) - DrawComponent->Draw( DrawPanel, DC, wxPoint( 0, 0 ), g_XorMode, g_GhostColor ); - else - { - DrawPanel->RefreshDrawingRect( DrawComponent->GetBoundingBox() ); - } + if( screen->GetCurItem() == NULL || screen->GetCurItem()->Type() != SCH_COMPONENT_T ) + return; } - DrawComponent->SetOrientation( type_rotate ); + 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; + } + + 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. */ - if( DC ) - { - if( DrawComponent->m_Flags ) - DrawComponent->Draw( DrawPanel, DC, wxPoint( 0, 0 ), g_XorMode, g_GhostColor ); - else - DrawComponent->Draw( DrawPanel, DC, wxPoint( 0, 0 ), GR_DEFAULT_DRAWMODE ); - DrawPanel->CrossHairOn( DC ); - } + if( component->GetFlags() ) + component->Draw( DrawPanel, &dc, wxPoint( 0, 0 ), g_XorMode, g_GhostColor ); + else + component->Draw( DrawPanel, &dc, wxPoint( 0, 0 ), GR_DEFAULT_DRAWMODE ); - GetScreen()->TestDanglingEnds( DrawPanel, DC ); - OnModify( ); + DrawPanel->CrossHairOn( &dc ); + GetScreen()->TestDanglingEnds( DrawPanel, &dc ); + OnModify(); } diff --git a/eeschema/hotkeys.cpp b/eeschema/hotkeys.cpp index ead1a91ebc..148352e825 100644 --- a/eeschema/hotkeys.cpp +++ b/eeschema/hotkeys.cpp @@ -559,7 +559,7 @@ void SCH_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition, break; case HK_ROTATE: // Component or other schematic item rotation - if ( screen->m_BlockLocate.m_State != STATE_NO_BLOCK)//allows bloc operation on hotkey + if ( screen->m_BlockLocate.m_State != STATE_NO_BLOCK )//allows bloc operation on hotkey { HandleBlockEndByPopUp(BLOCK_ROTATE, aDC ); break; @@ -584,14 +584,6 @@ void SCH_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition, { 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() ) { 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; case SCH_COMPONENT_T: - wxPostEvent( this, eventRotateComponent ); + cmd.SetId( ID_POPUP_SCH_ROTATE_CMP_COUNTERCLOCKWISE ); + wxPostEvent( this, cmd ); break; case SCH_TEXT_T: case SCH_LABEL_T: case SCH_GLOBAL_LABEL_T: case SCH_HIERARCHICAL_LABEL_T: - wxPostEvent( this, eventRotateText ); + cmd.SetId( ID_POPUP_SCH_ROTATE_TEXT ); + wxPostEvent( this, cmd ); break; case SCH_FIELD_T: - wxPostEvent( this, eventRotateField ); + cmd.SetId( ID_POPUP_SCH_ROTATE_FIELD ); + wxPostEvent( this, cmd ); default: ; @@ -620,9 +615,9 @@ void SCH_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition, break; case HK_MIRROR_Y_COMPONENT: // Mirror Y (Component) - if ( screen->m_BlockLocate.m_State != STATE_NO_BLOCK ) + if( screen->m_BlockLocate.m_State != STATE_NO_BLOCK ) { - HandleBlockEndByPopUp(BLOCK_MIRROR_Y, aDC ); + HandleBlockEndByPopUp( BLOCK_MIRROR_Y, aDC ); break; } @@ -631,19 +626,16 @@ void SCH_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition, if( aItem ) { - if( aItem->m_Flags == 0 ) - { - SaveCopyInUndoList( (SCH_ITEM*) aItem, UR_CHANGED ); - } - - CmpRotationMiroir( (SCH_COMPONENT*) aItem, aDC, CMP_MIRROR_Y ); + screen->SetCurItem( (SCH_ITEM*) aItem ); + cmd.SetId( ID_POPUP_SCH_MIROR_Y_CMP ); + GetEventHandler()->ProcessEvent( cmd ); } break; case HK_MIRROR_X_COMPONENT: // Mirror X (Component) - if ( screen->m_BlockLocate.m_State != STATE_NO_BLOCK ) //allows bloc operation on hotkey + if( screen->m_BlockLocate.m_State != STATE_NO_BLOCK ) //allows bloc operation on hotkey { - HandleBlockEndByPopUp(BLOCK_MIRROR_X, aDC ); + HandleBlockEndByPopUp( BLOCK_MIRROR_X, aDC ); break; } @@ -652,12 +644,9 @@ void SCH_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition, if( aItem ) { - if( aItem->m_Flags == 0 ) - { - SaveCopyInUndoList( (SCH_ITEM*) aItem, UR_CHANGED ); - } - - CmpRotationMiroir( (SCH_COMPONENT*) aItem, aDC, CMP_MIRROR_X ); + screen->SetCurItem( (SCH_ITEM*) aItem ); + cmd.SetId( ID_POPUP_SCH_MIROR_X_CMP ); + GetEventHandler()->ProcessEvent( cmd ); } break; @@ -667,13 +656,9 @@ void SCH_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition, if( aItem ) { - if( aItem->m_Flags == 0 ) - { - SaveCopyInUndoList( (SCH_ITEM*) aItem, UR_CHANGED ); - } - - CmpRotationMiroir( (SCH_COMPONENT*) aItem, aDC, CMP_NORMAL ); - GetScreen()->TestDanglingEnds( DrawPanel, aDC ); + screen->SetCurItem( (SCH_ITEM*) aItem ); + cmd.SetId( ID_POPUP_SCH_ORIENT_NORMAL_CMP ); + GetEventHandler()->ProcessEvent( cmd ); } break; @@ -736,8 +721,6 @@ void SCH_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition, GetScreen()->SetCurItem( (SCH_ITEM*) aItem ); // 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, ID_POPUP_SCH_MOVE_ITEM_REQUEST ); 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 case SCH_SHEET_T: case SCH_COMPONENT_T: - wxPostEvent( this, eventMoveOrDragComponent ); - break; - case SCH_LABEL_T: case SCH_GLOBAL_LABEL_T: case SCH_HIERARCHICAL_LABEL_T: - wxPostEvent( this, eventMoveOrDragComponent ); + cmd.SetId( HK_Descr->m_IdMenuEvent ); + wxPostEvent( this, cmd ); break; case SCH_TEXT_T: @@ -810,9 +791,6 @@ void SCH_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition, if( aItem ) { - wxCommandEvent eventEditPinsheet( wxEVT_COMMAND_TOOL_CLICKED, - ID_POPUP_SCH_EDIT_SHEET ); - switch( aItem->Type() ) { case SCH_COMPONENT_T: @@ -821,7 +799,8 @@ void SCH_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition, case SCH_SHEET_T: GetScreen()->SetCurItem( (SCH_ITEM*) aItem ); - wxPostEvent( this, eventEditPinsheet ); + cmd.SetId( ID_POPUP_SCH_EDIT_SHEET ); + wxPostEvent( this, cmd ); break; case SCH_TEXT_T: diff --git a/eeschema/schedit.cpp b/eeschema/schedit.cpp index e411890964..998f4325e3 100644 --- a/eeschema/schedit.cpp +++ b/eeschema/schedit.cpp @@ -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_WIRE_REQUEST: 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_DISPLAYDOC_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() ); 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: DrawPanel->MoveCursorToCrossHair(); break; diff --git a/eeschema/schframe.cpp b/eeschema/schframe.cpp index 775fba3417..ef8a3f4aa1 100644 --- a/eeschema/schframe.cpp +++ b/eeschema/schframe.cpp @@ -122,6 +122,8 @@ BEGIN_EVENT_TABLE( SCH_EDIT_FRAME, EDA_DRAW_FRAME ) SCH_EDIT_FRAME::OnSelectUnit ) EVT_MENU_RANGE( ID_POPUP_SCH_CHANGE_TYPE_TEXT, ID_POPUP_SCH_CHANGE_TYPE_TEXT_TO_COMMENT, 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. */ EVT_UPDATE_UI( wxID_CUT, SCH_EDIT_FRAME::OnUpdateBlockSelected ) diff --git a/gerbview/gerberframe.cpp b/gerbview/gerberframe.cpp index d763c211c8..3b9eb93ed4 100644 --- a/gerbview/gerberframe.cpp +++ b/gerbview/gerberframe.cpp @@ -243,8 +243,8 @@ int WinEDA_GerberFrame::BestZoom() double x, y; EDA_Rect bbox; - BOARD_ITEM* item = GetBoard()->m_Drawings; + bbox = ( (GERBER_DRAW_ITEM*) item )->GetBoundingBox(); for( ; item; item = item->Next() ) diff --git a/include/class_base_screen.h b/include/class_base_screen.h index 33f9e6ac6e..00875faf1c 100644 --- a/include/class_base_screen.h +++ b/include/class_base_screen.h @@ -134,9 +134,9 @@ public: /** * Function setCurItem * sets the currently selected object, m_CurrentItem. - * @param current Any object derived from EDA_ITEM + * @param aItem Any object derived from EDA_ITEM */ - void SetCurItem( EDA_ITEM* current ) { m_CurrentItem = current; } + void SetCurItem( EDA_ITEM* aItem ) { m_CurrentItem = aItem; } EDA_ITEM* GetCurItem() const { return m_CurrentItem; } /** diff --git a/include/class_sch_screen.h b/include/class_sch_screen.h index 9985269a94..8a706e986f 100644 --- a/include/class_sch_screen.h +++ b/include/class_sch_screen.h @@ -66,17 +66,14 @@ public: * returns the currently selected SCH_ITEM, overriding BASE_SCREEN::GetCurItem(). * @return SCH_ITEM* - the one selected, or NULL. */ - SCH_ITEM* GetCurItem() const { return (SCH_ITEM*) BASE_SCREEN::GetCurItem(); } + SCH_ITEM* GetCurItem() const { return (SCH_ITEM*) BASE_SCREEN::GetCurItem(); } /** * Function SetCurItem * sets the currently selected object, m_CurrentItem. * @param aItem Any object derived from SCH_ITEM */ - void SetCurItem( SCH_ITEM* aItem ) - { - BASE_SCREEN::SetCurItem( (BASE_SCREEN*) aItem ); - } + void SetCurItem( SCH_ITEM* aItem ) { BASE_SCREEN::SetCurItem( (EDA_ITEM*) aItem ); } /** * Free all the items from the schematic associated with the screen. diff --git a/include/wxEeschemaStruct.h b/include/wxEeschemaStruct.h index 60bc03e0a4..3d54477625 100644 --- a/include/wxEeschemaStruct.h +++ b/include/wxEeschemaStruct.h @@ -523,8 +523,7 @@ private: void StartMovePart( SCH_COMPONENT* DrawLibItem, wxDC* DC ); public: - void CmpRotationMiroir( SCH_COMPONENT* DrawComponent, - wxDC* DC, int type_rotate ); + void OnChangeComponentOrientation( wxCommandEvent& aEvent ); private: void OnSelectUnit( wxCommandEvent& aEvent );