← Back to team overview

kicad-developers team mailing list archive

PATCH: Unify mirror and copy block functions between schematic editor and library aditor

 

Hi guys,

Here are two patches:
unifyCopyBlock.patch: makes the CopyBlock function in library editor match
the behaviour of the one in schematic editor
addMirrorHotkeys.patch:
- adds the HkMirrorX and HkMirrorY hotkeys to library editor
- allor the HkRotate hotkey to rotate blocks and not only items

Regards,
Mikael
=== modified file 'eeschema/libeditframe.cpp'
--- eeschema/libeditframe.cpp	2016-01-16 23:51:56 +0000
+++ eeschema/libeditframe.cpp	2016-02-24 17:19:51 +0000
@@ -873,7 +873,7 @@
         m_canvas->SetAutoPanRequest( false );
         GetScreen()->m_BlockLocate.SetCommand( BLOCK_COPY );
         m_canvas->MoveCursorToCrossHair();
-        HandleBlockPlace( &dc );
+        HandleBlockEnd( &dc );
         break;
 
     case ID_POPUP_SELECT_ITEMS_BLOCK:

=== modified file 'eeschema/eeschema_id.h'
--- eeschema/eeschema_id.h	2016-01-29 10:24:39 +0000
+++ eeschema/eeschema_id.h	2016-02-24 02:15:23 +0000
@@ -209,7 +209,11 @@
     ID_LIBEDIT_EXPORT_BODY_BUTT,
     ID_LIBEDIT_DELETE_ITEM_BUTT,
 
+    // Change orientation command IDs.
     ID_LIBEDIT_ROTATE_ITEM,
+    ID_LIBEDIT_MIRROR_X,
+    ID_LIBEDIT_MIRROR_Y,
+    ID_LIBEDIT_ORIENT_NORMAL,
 
     /* Library editor context menu IDs */
     ID_LIBEDIT_EDIT_PIN,

=== modified file 'eeschema/hotkeys.cpp'
--- eeschema/hotkeys.cpp	2016-01-29 14:43:40 +0000
+++ eeschema/hotkeys.cpp	2016-02-24 17:29:42 +0000
@@ -311,6 +311,8 @@
     &HkCreatePin,
     &HkInsertPin,
     &HkMoveLibItem,
+    &HkMirrorX,
+    &HkMirrorY,
     NULL
 };
 
@@ -782,6 +784,18 @@
             }
         }
         break;
+
+    case HK_MIRROR_Y:                       // Mirror Y
+        m_drawItem = LocateItemUsingCursor( aPosition );
+        cmd.SetId( ID_LIBEDIT_MIRROR_Y );
+        GetEventHandler()->ProcessEvent(cmd);
+        break;
+
+    case HK_MIRROR_X:                       // Mirror X
+        m_drawItem = LocateItemUsingCursor( aPosition );
+        cmd.SetId( ID_LIBEDIT_MIRROR_X );
+        GetEventHandler()->ProcessEvent(cmd);
+        break;
     }
 
     // Hot key handled.

=== modified file 'eeschema/libedit_onrightclick.cpp'
--- eeschema/libedit_onrightclick.cpp	2014-10-15 11:40:38 +0000
+++ eeschema/libedit_onrightclick.cpp	2016-02-24 17:05:18 +0000
@@ -320,6 +320,7 @@
 
 void AddMenusForBlock( wxMenu* PopMenu, LIB_EDIT_FRAME* frame )
 {
+    wxString msg;
     AddMenuItem( PopMenu, ID_POPUP_LIBEDIT_CANCEL_EDITING, _( "Cancel Block" ),
                  KiBitmap( cancel_xpm ) );
 
@@ -337,11 +338,14 @@
         AddMenuItem( PopMenu, ID_POPUP_SELECT_ITEMS_BLOCK, _( "Select Items" ),
                      KiBitmap( green_xpm ) );
         AddMenuItem( PopMenu, ID_POPUP_COPY_BLOCK, _( "Copy Block" ), KiBitmap( copyblock_xpm ) );
-        AddMenuItem( PopMenu, ID_POPUP_MIRROR_Y_BLOCK, _( "Mirror Block ||" ),
+        msg = AddHotkeyName( _( "Mirror Block ||" ), g_Libedit_Hokeys_Descr, HK_MIRROR_Y );
+        AddMenuItem( PopMenu, ID_POPUP_MIRROR_Y_BLOCK, msg,
                      KiBitmap( mirror_h_xpm ) );
-        AddMenuItem( PopMenu, ID_POPUP_MIRROR_X_BLOCK, _( "Mirror Block --" ),
+        msg = AddHotkeyName( _( "Mirror Block --" ), g_Libedit_Hokeys_Descr, HK_MIRROR_X );
+        AddMenuItem( PopMenu, ID_POPUP_MIRROR_X_BLOCK, msg, 
                      KiBitmap( mirror_v_xpm ) );
-        AddMenuItem( PopMenu, ID_POPUP_ROTATE_BLOCK, _( "Rotate Block ccw" ),
+        msg = AddHotkeyName( _( "Rotate Block CCW" ), g_Libedit_Hokeys_Descr, HK_ROTATE );
+        AddMenuItem( PopMenu, ID_POPUP_ROTATE_BLOCK, msg,
                      KiBitmap( rotate_ccw_xpm ) );
         AddMenuItem( PopMenu, ID_POPUP_DELETE_BLOCK, _( "Delete Block" ), KiBitmap( delete_xpm ) );
     }

=== modified file 'eeschema/libeditframe.cpp'
--- eeschema/libeditframe.cpp	2016-01-16 23:51:56 +0000
+++ eeschema/libeditframe.cpp	2016-02-24 17:30:12 +0000
@@ -150,6 +150,9 @@
     EVT_MENU_RANGE( ID_POPUP_GENERAL_START_RANGE, ID_POPUP_GENERAL_END_RANGE,
                     LIB_EDIT_FRAME::Process_Special_Functions )
 
+    // Mirror hotkeys
+    EVT_MENU_RANGE( ID_LIBEDIT_MIRROR_X, ID_LIBEDIT_ORIENT_NORMAL, LIB_EDIT_FRAME::OnOrient )
+
     // Update user interface elements.
     EVT_UPDATE_UI( ExportPartId, LIB_EDIT_FRAME::OnUpdateEditingPart )
     EVT_UPDATE_UI( CreateNewLibAndSavePartId, LIB_EDIT_FRAME::OnUpdateEditingPart )
@@ -1175,30 +1178,72 @@
 
 void LIB_EDIT_FRAME::OnRotateItem( wxCommandEvent& aEvent )
 {
-    if( m_drawItem == NULL )
+    SCH_SCREEN* screen = GetScreen();
+    if( screen->m_BlockLocate.GetState() == STATE_NO_BLOCK )
+    {
+        if( m_drawItem == NULL )
+            return;
+    
+        if( !m_drawItem->InEditMode() )
+        {
+            LIB_PART*      part = GetCurPart();
+    
+            SaveCopyInUndoList( part );
+            m_drawItem->SetUnit( m_unit );
+        }
+    
+        m_drawItem->Rotate();
+        OnModify();
+    
+        if( !m_drawItem->InEditMode() )
+            m_drawItem->ClearFlags();
+    
+        m_canvas->Refresh();
+    
+        if( GetToolId() == ID_NO_TOOL_SELECTED )
+            m_lastDrawItem = NULL;
+    }
+    else{
+        INSTALL_UNBUFFERED_DC( dc, m_canvas );
+        m_canvas->SetAutoPanRequest( false );
+        screen->m_BlockLocate.SetCommand( BLOCK_ROTATE );
+        m_canvas->MoveCursorToCrossHair();
+        HandleBlockPlace( &dc );
+    }
+}
+
+void LIB_EDIT_FRAME::OnOrient( wxCommandEvent& aEvent )
+{
+    INSTALL_UNBUFFERED_DC( dc, m_canvas );
+    SCH_SCREEN* screen = GetScreen();
+    // Allows block rotate operation on hot key.
+    if( screen->m_BlockLocate.GetState() != STATE_NO_BLOCK )
+    {
+        if( aEvent.GetId() == ID_LIBEDIT_MIRROR_X )
+        {
+            m_canvas->MoveCursorToCrossHair();
+            screen->m_BlockLocate.SetMessageBlock( this );
+            screen->m_BlockLocate.SetCommand( BLOCK_MIRROR_X );
+            HandleBlockEnd( &dc );
+        }
+        else if( aEvent.GetId() == ID_LIBEDIT_MIRROR_Y )
+        {
+            m_canvas->MoveCursorToCrossHair();
+            screen->m_BlockLocate.SetMessageBlock( this );
+            screen->m_BlockLocate.SetCommand( BLOCK_MIRROR_Y );
+            HandleBlockEnd( &dc );
+        }
+        else if( aEvent.GetId() == ID_LIBEDIT_ROTATE_ITEM )
+        {
+            screen->m_BlockLocate.SetCommand( BLOCK_ROTATE );
+            HandleBlockEnd( &dc );
+            return;
+        }
+
         return;
-
-    if( !m_drawItem->InEditMode() )
-    {
-        LIB_PART*      part = GetCurPart();
-
-        SaveCopyInUndoList( part );
-        m_drawItem->SetUnit( m_unit );
     }
-
-    m_drawItem->Rotate();
-    OnModify();
-
-    if( !m_drawItem->InEditMode() )
-        m_drawItem->ClearFlags();
-
-    m_canvas->Refresh();
-
-    if( GetToolId() == ID_NO_TOOL_SELECTED )
-        m_lastDrawItem = NULL;
 }
 
-
 LIB_ITEM* LIB_EDIT_FRAME::LocateItemUsingCursor( const wxPoint& aPosition,
                                                  const KICAD_T aFilterList[] )
 {

=== modified file 'eeschema/libeditframe.h'
--- eeschema/libeditframe.h	2016-01-20 12:11:17 +0000
+++ eeschema/libeditframe.h	2016-02-24 17:31:12 +0000
@@ -510,6 +510,12 @@
     void OnRotateItem( wxCommandEvent& aEvent );
 
     /**
+     * Function OnOrient
+     * Handles the ID_LIBEDIT_MIRROR_X and ID_LIBEDIT_MIRROR_Y events.
+     */
+    void OnOrient( wxCommandEvent& aEvent );
+
+    /**
      * Function deleteItem
      * deletes the currently selected draw item.
      * @param aDC The device context to draw upon when removing item.


Follow ups