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

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
......@@ -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,
......
......@@ -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;
}
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. */
if( DC )
{
if( DrawComponent->m_Flags )
DrawComponent->Draw( DrawPanel, DC, wxPoint( 0, 0 ), g_XorMode, g_GhostColor );
if( component->GetFlags() )
component->Draw( DrawPanel, &dc, wxPoint( 0, 0 ), g_XorMode, g_GhostColor );
else
DrawComponent->Draw( DrawPanel, DC, wxPoint( 0, 0 ), GR_DEFAULT_DRAWMODE );
DrawPanel->CrossHairOn( DC );
}
component->Draw( DrawPanel, &dc, wxPoint( 0, 0 ), GR_DEFAULT_DRAWMODE );
GetScreen()->TestDanglingEnds( DrawPanel, DC );
OnModify( );
DrawPanel->CrossHairOn( &dc );
GetScreen()->TestDanglingEnds( DrawPanel, &dc );
OnModify();
}
......
......@@ -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:
......
......@@ -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;
......
......@@ -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 )
......
......@@ -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() )
......
......@@ -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; }
/**
......
......@@ -73,10 +73,7 @@ public:
* 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.
......
......@@ -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 );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment