Schematic component library editor rotate item improvements.

* Merge three separate rotate code paths into a single rotate item function.
* Reduce three separate rotate command IDs into a single rotate command ID.
* Move pin rotate code into pin object.
This commit is contained in:
Wayne Stambaugh 2011-02-28 08:53:49 -05:00
parent bc8f250b8b
commit ffa9feda69
10 changed files with 105 additions and 147 deletions

View File

@ -166,9 +166,10 @@ enum id_eeschema_frm
ID_LIBEDIT_EXPORT_BODY_BUTT,
ID_LIBEDIT_DELETE_ITEM_BUTT,
ID_LIBEDIT_ROTATE_ITEM,
/* Library editor context menu IDs */
ID_LIBEDIT_EDIT_PIN,
ID_LIBEDIT_ROTATE_PIN,
ID_POPUP_LIBEDIT_PIN_GLOBAL_CHANGE_ITEM,
ID_POPUP_LIBEDIT_PIN_GLOBAL_CHANGE_PINSIZE_ITEM,
ID_POPUP_LIBEDIT_PIN_GLOBAL_CHANGE_PINNAMESIZE_ITEM,
@ -180,9 +181,7 @@ enum id_eeschema_frm
ID_POPUP_LIBEDIT_CANCEL_EDITING,
ID_POPUP_LIBEDIT_MOVE_ITEM_REQUEST,
ID_POPUP_LIBEDIT_FIELD_EDIT_ITEM,
ID_POPUP_LIBEDIT_FIELD_ROTATE_ITEM,
ID_POPUP_LIBEDIT_DELETE_CURRENT_POLY_SEGMENT,
ID_POPUP_LIBEDIT_ROTATE_GRAPHIC_TEXT,
/* Library editor menubar IDs */
ID_LIBEDIT_SAVE_CURRENT_LIB_AS,

View File

@ -959,7 +959,8 @@ void LIB_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition,
break;
case HK_EDIT:
m_drawItem = LocateItemUsingCursor( aPosition );
if( itemInEdit )
m_drawItem = LocateItemUsingCursor( aPosition );
if( m_drawItem )
{
@ -991,30 +992,13 @@ void LIB_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition,
break;
case HK_ROTATE:
m_drawItem = LocateItemUsingCursor( aPosition );
if( m_drawItem == NULL )
m_drawItem = LocateItemUsingCursor( aPosition );
if( m_drawItem )
{
switch( m_drawItem->Type() )
{
case LIB_PIN_T:
cmd.SetId( ID_LIBEDIT_ROTATE_PIN );
GetEventHandler()->ProcessEvent( cmd );
break;
case LIB_TEXT_T:
cmd.SetId( ID_POPUP_LIBEDIT_ROTATE_GRAPHIC_TEXT );
GetEventHandler()->ProcessEvent( cmd );
break;
case LIB_FIELD_T:
cmd.SetId( ID_POPUP_LIBEDIT_FIELD_ROTATE_ITEM );
GetEventHandler()->ProcessEvent( cmd );
break;
default:
break;
}
cmd.SetId( ID_LIBEDIT_ROTATE_ITEM );
GetEventHandler()->ProcessEvent( cmd );
}
break;
@ -1024,7 +1008,8 @@ void LIB_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition,
break;
case HK_DELETE:
m_drawItem = LocateItemUsingCursor( aPosition );
if( !itemInEdit )
m_drawItem = LocateItemUsingCursor( aPosition );
if( m_drawItem && !m_drawItem->InEditMode() )
{
@ -1035,13 +1020,16 @@ void LIB_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition,
break;
case HK_LIBEDIT_MOVE_GRAPHIC_ITEM:
m_drawItem = LocateItemUsingCursor( aPosition );
if( m_drawItem && !m_drawItem->InEditMode() )
if( !itemInEdit )
{
wxCommandEvent evt;
evt.SetId( ID_POPUP_LIBEDIT_MOVE_ITEM_REQUEST );
Process_Special_Functions( evt );
m_drawItem = LocateItemUsingCursor( aPosition );
if( m_drawItem )
{
wxCommandEvent evt;
evt.SetId( ID_POPUP_LIBEDIT_MOVE_ITEM_REQUEST );
Process_Special_Functions( evt );
}
}
break;

View File

@ -1798,6 +1798,21 @@ int LIB_PIN::GetOrientationCodeIndex( int code )
}
void LIB_PIN::Rotate()
{
// Get the actual pin orientation index
int i = GetOrientationCodeIndex( GetOrientation() );
// Compute the next orientation, swap lower two bits for the right order
i = ((i & 2) >> 1) | ((i & 1) << 1);
i = i + 1;
i = ((i & 2) >> 1) | ((i & 1) << 1);
// Set the new orientation
SetOrientation( GetOrientationCode( i ) );
}
wxArrayString LIB_PIN::GetStyleNames( void )
{
wxArrayString tmp;

View File

@ -158,12 +158,12 @@ public:
wxPoint ReturnPinEndPoint() const;
/**
* Function ReturnPinDrawOrient
* Return the pin real orientation (PIN_UP, PIN_DOWN, PIN_RIGHT, PIN_LEFT),
* according to its orientation and the matrix transform (rot, mirror) \a aTransform
* @param aTransform = transform matrix
*/
/**
* Function ReturnPinDrawOrient
* returns the pin real orientation (PIN_UP, PIN_DOWN, PIN_RIGHT, PIN_LEFT),
* according to its orientation and the matrix transform (rot, mirror) \a aTransform
* @param aTransform = transform matrix
*/
int ReturnPinDrawOrient( const TRANSFORM& aTransform );
/**
@ -189,7 +189,7 @@ public:
*/
static wxString ReturnPinStringNum( long aPinNum );
void SetPinNumFromString( wxString& aBuffer );
void SetPinNumFromString( wxString& aBuffer );
wxString GetName() const { return m_name; }
@ -243,6 +243,8 @@ public:
*/
void SetOrientation( int aOrientation );
void Rotate();
int GetShape() const { return m_shape; }
/**

View File

@ -83,7 +83,9 @@ void LIB_EDIT_FRAME::OnLeftClick( wxDC* DC, const wxPoint& aPosition )
break;
case ID_LIBEDIT_DELETE_ITEM_BUTT:
if( LocateItemUsingCursor( aPosition ) )
m_drawItem = LocateItemUsingCursor( aPosition );
if( m_drawItem )
deleteItem( DC );
else
DisplayCmpDoc();

View File

@ -151,7 +151,7 @@ bool LIB_EDIT_FRAME::OnRightClick( const wxPoint& aPosition, wxMenu* PopMenu )
ADD_MENUITEM( PopMenu, ID_POPUP_LIBEDIT_BODY_EDIT_ITEM, msg, edit_text_xpm );
msg = AddHotkeyName( _( "Rotate Text" ), s_Libedit_Hokeys_Descr, HK_ROTATE );
ADD_MENUITEM( PopMenu, ID_POPUP_LIBEDIT_ROTATE_GRAPHIC_TEXT, msg, edit_text_xpm );
ADD_MENUITEM( PopMenu, ID_LIBEDIT_ROTATE_ITEM, msg, edit_text_xpm );
if( DrawEntry->m_Flags == 0 )
{
@ -203,7 +203,7 @@ bool LIB_EDIT_FRAME::OnRightClick( const wxPoint& aPosition, wxMenu* PopMenu )
ADD_MENUITEM( PopMenu, ID_POPUP_LIBEDIT_MOVE_ITEM_REQUEST, msg, move_field_xpm );
}
msg = AddHotkeyName( _( "Field Rotate" ), s_Libedit_Hokeys_Descr, HK_ROTATE );
ADD_MENUITEM( PopMenu, ID_POPUP_LIBEDIT_FIELD_ROTATE_ITEM, msg, rotate_field_xpm );
ADD_MENUITEM( PopMenu, ID_LIBEDIT_ROTATE_ITEM, msg, rotate_field_xpm );
msg = AddHotkeyName( _( "Field Edit" ), s_Libedit_Hokeys_Descr, HK_EDIT );
ADD_MENUITEM( PopMenu, ID_POPUP_LIBEDIT_FIELD_EDIT_ITEM, msg, edit_text_xpm );
break;
@ -240,7 +240,7 @@ void AddMenusForPin( wxMenu* PopMenu, LIB_PIN* Pin, LIB_EDIT_FRAME* frame )
ADD_MENUITEM( PopMenu, ID_LIBEDIT_EDIT_PIN, msg, edit_xpm );
msg = AddHotkeyName( _( "Rotate Pin " ), s_Libedit_Hokeys_Descr, HK_ROTATE );
ADD_MENUITEM( PopMenu, ID_LIBEDIT_ROTATE_PIN, msg, rotate_pin_xpm );
ADD_MENUITEM( PopMenu, ID_LIBEDIT_ROTATE_ITEM, msg, rotate_pin_xpm );
if( not_in_move )
{

View File

@ -128,12 +128,12 @@ BEGIN_EVENT_TABLE( LIB_EDIT_FRAME, EDA_DRAW_FRAME )
EVT_MENU_RANGE( ID_LANGUAGE_CHOICE, ID_LANGUAGE_CHOICE_END, LIB_EDIT_FRAME::SetLanguage )
/* Context menu events and commands. */
/* Context menu events and commands. */
EVT_MENU( ID_LIBEDIT_EDIT_PIN, LIB_EDIT_FRAME::OnEditPin )
EVT_MENU( ID_LIBEDIT_ROTATE_PIN, LIB_EDIT_FRAME::OnRotatePin )
EVT_MENU( ID_LIBEDIT_ROTATE_ITEM, LIB_EDIT_FRAME::OnRotateItem )
EVT_MENU_RANGE( ID_POPUP_LIBEDIT_PIN_GLOBAL_CHANGE_ITEM,
ID_POPUP_LIBEDIT_ROTATE_GRAPHIC_TEXT,
ID_POPUP_LIBEDIT_DELETE_CURRENT_POLY_SEGMENT,
LIB_EDIT_FRAME::Process_Special_Functions )
EVT_MENU_RANGE( ID_POPUP_GENERAL_START_RANGE, ID_POPUP_GENERAL_END_RANGE,
@ -618,7 +618,6 @@ void LIB_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event )
case ID_POPUP_LIBEDIT_END_CREATE_ITEM:
case ID_LIBEDIT_EDIT_PIN:
case ID_POPUP_LIBEDIT_BODY_EDIT_ITEM:
case ID_POPUP_LIBEDIT_FIELD_ROTATE_ITEM:
case ID_POPUP_LIBEDIT_FIELD_EDIT_ITEM:
case ID_POPUP_LIBEDIT_PIN_GLOBAL_CHANGE_PINSIZE_ITEM:
case ID_POPUP_LIBEDIT_PIN_GLOBAL_CHANGE_PINNAMESIZE_ITEM:
@ -630,7 +629,6 @@ void LIB_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event )
case ID_POPUP_MIRROR_Y_BLOCK:
case ID_POPUP_PLACE_BLOCK:
case ID_POPUP_LIBEDIT_DELETE_CURRENT_POLY_SEGMENT:
case ID_POPUP_LIBEDIT_ROTATE_GRAPHIC_TEXT:
break;
case ID_POPUP_LIBEDIT_CANCEL_EDITING:
@ -752,37 +750,6 @@ void LIB_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event )
break;
case ID_POPUP_LIBEDIT_ROTATE_GRAPHIC_TEXT:
if( m_drawItem == NULL && m_drawItem->Type() != LIB_TEXT_T )
break;
DrawPanel->MoveCursorToCrossHair();
if( !m_drawItem->InEditMode() )
{
SaveCopyInUndoList( m_component );
m_drawItem->SetUnit( m_unit );
}
m_drawItem->Rotate();
DrawPanel->Refresh();
break;
case ID_POPUP_LIBEDIT_FIELD_ROTATE_ITEM:
{
if( m_drawItem == NULL || ( m_drawItem->Type() != LIB_FIELD_T ) )
break;
DrawPanel->MoveCursorToCrossHair();
if( !m_drawItem->InEditMode() )
{
SaveCopyInUndoList( m_component );
m_drawItem->SetUnit( m_unit );
}
m_drawItem->Rotate();
DrawPanel->Refresh();
break;
}
case ID_POPUP_LIBEDIT_FIELD_EDIT_ITEM:
if( m_drawItem == NULL )
break;
@ -854,7 +821,6 @@ void LIB_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event )
if( GetToolId() == ID_NO_TOOL_SELECTED )
m_lastDrawItem = NULL;
}
@ -1093,6 +1059,43 @@ void LIB_EDIT_FRAME::OnSelectTool( wxCommandEvent& aEvent )
}
void LIB_EDIT_FRAME::OnRotateItem( wxCommandEvent& aEvent )
{
if( m_drawItem == NULL )
return;
if( !m_drawItem->InEditMode() )
{
SaveCopyInUndoList( m_component );
m_drawItem->SetUnit( m_unit );
}
m_drawItem->Rotate();
OnModify();
DrawPanel->Refresh();
if( GetToolId() == ID_NO_TOOL_SELECTED )
m_lastDrawItem = NULL;
}
LIB_DRAW_ITEM* LIB_EDIT_FRAME::LocateItemUsingCursor( const wxPoint& aPosition )
{
if( m_component == NULL )
return NULL;
LIB_DRAW_ITEM* item = m_component->LocateDrawItem( m_unit, m_convert, TYPE_NOT_INIT,
aPosition );
wxPoint pos = GetScreen()->GetNearestGridPosition( aPosition );
if( item == NULL && aPosition != pos )
item = m_component->LocateDrawItem( m_unit, m_convert, TYPE_NOT_INIT, pos );
return item;
}
void LIB_EDIT_FRAME::deleteItem( wxDC* aDC )
{
wxCHECK_RET( m_drawItem != NULL, wxT( "No drawing item selected to delete." ) );

View File

@ -74,7 +74,6 @@ public:
void OnCheckComponent( wxCommandEvent& event );
void OnSelectBodyStyle( wxCommandEvent& event );
void OnEditPin( wxCommandEvent& event );
void OnRotatePin( wxCommandEvent& event );
void OnUpdateSelectTool( wxUpdateUIEvent& aEvent );
void OnUpdateEditingPart( wxUpdateUIEvent& event );
@ -225,6 +224,12 @@ private:
void DisplayCmpDoc();
/**
* Function OnRotateItem
* rotates the current item.
*/
void OnRotateItem( wxCommandEvent& aEvent );
/**
* Function deleteItem
* deletes the currently selected draw item.

View File

@ -152,22 +152,3 @@ this component?" ),
OnModify();
UpdateAliasSelectList();
}
LIB_DRAW_ITEM* LIB_EDIT_FRAME::LocateItemUsingCursor( const wxPoint& aPosition )
{
if( m_component == NULL )
return NULL;
if( ( m_drawItem == NULL ) || ( m_drawItem->m_Flags == 0 ) )
{
m_drawItem = m_component->LocateDrawItem( m_unit, m_convert, TYPE_NOT_INIT, aPosition );
wxPoint pos = GetScreen()->GetNearestGridPosition( aPosition );
if( m_drawItem == NULL && aPosition != pos )
m_drawItem = m_component->LocateDrawItem( m_unit, m_convert, TYPE_NOT_INIT, pos );
}
return m_drawItem;
}

View File

@ -38,42 +38,6 @@ static bool LastPinCommonUnit = false;
static bool LastPinVisible = true;
void LIB_EDIT_FRAME::OnRotatePin( wxCommandEvent& event )
{
// Check, if the item is a pin, else return
if( m_drawItem == NULL || m_drawItem->Type() != LIB_PIN_T )
return;
// save flags to restore them after rotating
int item_flags = m_drawItem->m_Flags;
LIB_PIN* pin = (LIB_PIN*) m_drawItem;
// Save old pin orientation
LastPinOrient = pin->GetOrientation();
if( !pin->InEditMode() )
SaveCopyInUndoList( pin->GetParent() );
// Get the actual pin orientation index
int orientationIndex = pin->GetOrientationCodeIndex( pin->GetOrientation() );
// Compute the next orientation, swap lower two bits for the right order
orientationIndex = ((orientationIndex & 2) >> 1) | ((orientationIndex & 1) << 1);
orientationIndex = orientationIndex + 1;
orientationIndex = ((orientationIndex & 2) >> 1) | ((orientationIndex & 1) << 1);
// Set the new orientation
pin->SetOrientation( pin->GetOrientationCode( orientationIndex ) );
OnModify( );
pin->DisplayInfo( this );
DrawPanel->Refresh();
// Restore pin flags
pin->m_Flags = item_flags;
}
void LIB_EDIT_FRAME::OnEditPin( wxCommandEvent& event )
{
if( m_drawItem == NULL || m_drawItem->Type() != LIB_PIN_T )
@ -129,12 +93,8 @@ void LIB_EDIT_FRAME::OnEditPin( wxCommandEvent& event )
}
/* Save the pin properties to use for the next new pin. */
LastPinNameSize = ReturnValueFromString( g_UserUnit,
dlg.GetNameTextSize(),
m_InternalUnits );
LastPinNumSize = ReturnValueFromString( g_UserUnit,
dlg.GetNumberTextSize(),
m_InternalUnits );
LastPinNameSize = ReturnValueFromString( g_UserUnit, dlg.GetNameTextSize(), m_InternalUnits );
LastPinNumSize = ReturnValueFromString( g_UserUnit, dlg.GetNumberTextSize(), m_InternalUnits );
LastPinOrient = LIB_PIN::GetOrientationCode( dlg.GetOrientation() );
LastPinLength = ReturnValueFromString( g_UserUnit, dlg.GetLength(), m_InternalUnits );
LastPinShape = LIB_PIN::GetStyleCode( dlg.GetStyle() );
@ -220,7 +180,7 @@ void LIB_EDIT_FRAME::PlacePin( wxDC* DC )
newpos = GetScreen()->GetCrossHairPosition( true );
// Tst for an other pin in same new position:
// Test for an other pin in same new position:
for( Pin = m_component->GetNextPin(); Pin != NULL; Pin = m_component->GetNextPin( Pin ) )
{
if( Pin == CurrentPin || newpos != Pin->GetPosition() || Pin->m_Flags )
@ -302,11 +262,14 @@ void LIB_EDIT_FRAME::StartMovePin( wxDC* DC )
/* Mark pins for moving. */
Pin = m_component->GetNextPin();
for( ; Pin != NULL; Pin = m_component->GetNextPin( Pin ) )
{
Pin->m_Flags = 0;
if( Pin == CurrentPin )
continue;
if( ( Pin->GetPosition() == CurrentPin->GetPosition() )
&& ( Pin->GetOrientation() == CurrentPin->GetOrientation() )
&& ( g_EditPinByPinIsOn == false ) )
@ -483,7 +446,7 @@ static void CreateImagePins( LIB_PIN* Pin, int unit, int convert, bool asDeMorga
/* Depending on "id":
* - Change pin text size (name or num) (range 10 .. 1000 mil)
* - Change pin lenght.
* - Change pin length.
*
* If Pin is selected ( .m_flag == IS_SELECTED ) only the other selected
* pins are modified
@ -531,8 +494,8 @@ void LIB_EDIT_FRAME::GlobalSetPins( wxDC* DC, LIB_PIN* MasterPin, int id )
break;
}
( ( LIB_DRAW_ITEM* )Pin )->Draw( DrawPanel, DC, wxPoint( 0, 0 ), -1, GR_DEFAULT_DRAWMODE,
&showPinText, DefaultTransform );
Pin->Draw( DrawPanel, DC, wxPoint( 0, 0 ), -1, GR_DEFAULT_DRAWMODE, &showPinText,
DefaultTransform );
}
}
@ -690,7 +653,7 @@ void LIB_EDIT_FRAME::OnCheckComponent( wxCommandEvent& event )
( (Pin->GetPosition().y % MIN_GRID_SIZE) == 0 ) )
continue;
// A pin is foun here off grid
// A pin is found here off grid
offgrid_error++;
wxString stringPinNum;
Pin->ReturnPinStringNum( stringPinNum );