← Back to team overview

kicad-developers team mailing list archive

Module ref/val moving/rotation hotkey patch

 

Hi,

The attached patch allows moving and rotating module reference and value
text fields using hotkeys in pcbnew. Rotate/move directly on a pad actually
rotates/moves the parent module. Todo related to this: the collector seems
to return reference/val items even when they are not rendered on screen.

Regards,

Marco
=== modified file 'pcbnew/hotkeys.cpp'
--- pcbnew/hotkeys.cpp	2010-08-24 18:50:23 +0000
+++ pcbnew/hotkeys.cpp	2010-08-24 22:10:37 +0000
@@ -614,91 +614,118 @@
         }
         else if( !exit )
         {
-            if( ItemFree )
-            {
-                module = Locate_Prefered_Module( GetBoard(), CURSEUR_OFF_GRILLE
-                                                 | IGNORE_LOCKED | VISIBLE_ONLY
-#if defined(USE_MATCH_LAYER)
-                                                 | MATCH_LAYER
-#endif
-                                                 );
-
-                if( module == NULL ) // no footprint found
-                {
-                    module = Locate_Prefered_Module( GetBoard(),
-                                                     CURSEUR_OFF_GRILLE | VISIBLE_ONLY );
-                    if( module )
-                    {
-                        // a footprint is found, but locked or on an other layer
-                        if( module->IsLocked() )
-                        {
-                            wxString msg;
-
-                            msg.Printf( _( "Footprint %s found, but locked" ),
-                                       module->m_Reference->m_Text.GetData() );
-
-                            DisplayInfoMessage( this, msg );
-                        }
-                        module = NULL;
-                    }
-                }
-            }
-            else if( GetCurItem()->Type() == TYPE_MODULE )
-            {
-                module = (MODULE*) GetCurItem();
-
-                // @todo: might need to add a layer check in if() below
-                if( (GetCurItem()->m_Flags == 0) && module->IsLocked() )
-                    module = NULL; // do not move, rotate ... it.
-            }
-            if( module == NULL )
-                break;
-
-            /*  I'd like to make sending to EESCHEMA edge triggered, but the
-             *  simple mouse click on a module when the arrow icon is in play
-             *  does not set GetCurItem() at this time, nor does a mouse click
-             *  when the local ratsnest icon is in play set GetCurItem(), and these
-             *  actions also call SendMessageToEESCHEMA().
-             *  if( GetCurItem() != module )
-             */
-            {
-                // Send the module via socket to EESCHEMA's search facility.
-                SendMessageToEESCHEMA( module );
-                SetCurItem( module );
-            }
-
-            switch( HK_Descr->m_Idcommand )
-            {
-            case HK_ROTATE_FOOTPRINT:           // Rotation
-                if( module->m_Flags == 0 )      // not currently in edit, prepare undo command
-                    SaveCopyInUndoList( module, UR_ROTATED, module->m_Pos );
-                Rotate_Module( DC, module, 900, TRUE );
-                break;
-
-            case HK_FLIP_FOOTPRINT:             // move to other side
-                if( module->m_Flags == 0 )      // not currently in edit, prepare undo command
-                    SaveCopyInUndoList( module, UR_FLIPPED, module->m_Pos );
-                Change_Side_Module( module, DC );
-                break;
-
-            case HK_DRAG_FOOTPRINT_OR_TRACK: // Start move (and drag) module
-                g_Drag_Pistes_On = TRUE;
-
-            // fall through
-            case HK_MOVE_FOOTPRINT_OR_TRACK: // Start move module
-                GetScreen()->m_Curseur = module->m_Pos;
-                DrawPanel->MouseToCursorSchema();
-                StartMove_Module( module, DC );
-                break;
-            }
-
-            module->DisplayInfo( this );
-            break;
-        }
+	  if( ItemFree )
+          {
+ 	      DrawStruct = PcbGeneralLocateAndDisplay();
+	    
+	      /* Nothing was found, exit */
+	      if( DrawStruct == NULL)
+		  break;
+	      
+	      if( DrawStruct->Type() == TYPE_MODULE || 
+		  DrawStruct->Type() == TYPE_PAD )
+	      {
+		  module = (MODULE*)DrawStruct;
+		  // a footprint is found, but locked
+		  if( module->IsLocked() )
+		  {
+		      wxString msg;
+		      msg.Printf( _( "Footprint %s found, but it is locked" ),
+				  module->m_Reference->m_Text.GetData() );
+		      DisplayInfoMessage( this, msg );
+		      return;
+		  }
+	      }
+	    
+	      /*  I'd like to make sending to EESCHEMA edge triggered, but the
+	       *  simple mouse click on a module when the arrow icon is in play
+	       *  does not set GetCurItem() at this time, nor does a mouse click
+	       *  when the local ratsnest icon is in play set GetCurItem(), and these
+	       *  actions also call SendMessageToEESCHEMA().
+	       *  if( GetCurItem() != module )
+	       */
+	      // Send the module via socket to EESCHEMA's search facility.
+	      SendMessageToEESCHEMA( (BOARD_ITEM*) DrawStruct );
+	  }
+	  else if ( GetCurItem()->m_Flags & IS_MOVED )
+	  {
+	      /* Transform the item currently being moved */
+	      DrawStruct = GetCurItem();
+	  }
+	  else
+	      return;
+	  switch( DrawStruct->Type() )
+	  {
+	  case TYPE_MODULE:
+	      module = (MODULE*) DrawStruct;
+	      switch( HK_Descr->m_Idcommand )
+	      {
+	      case HK_ROTATE_FOOTPRINT:           // Rotation
+		  if( module->m_Flags == 0 )      // not currently in edit, prepare undo command
+		      SaveCopyInUndoList( module, UR_ROTATED, module->m_Pos );
+		  Rotate_Module( DC, module, 900, TRUE );
+		  break;
+
+	      case HK_FLIP_FOOTPRINT:             // move to other side
+		  if( module->m_Flags == 0 )      // not currently in edit, prepare undo command
+		      SaveCopyInUndoList( module, UR_FLIPPED, module->m_Pos );
+		  Change_Side_Module( module, DC );
+		  break;
+		
+	      case HK_DRAG_FOOTPRINT_OR_TRACK: // Start move (and drag) module
+		  g_Drag_Pistes_On = TRUE;
+	      
+		  // fall through
+	      case HK_MOVE_FOOTPRINT_OR_TRACK: // Start move module
+		  GetScreen()->m_Curseur = module->m_Pos;
+		  DrawPanel->MouseToCursorSchema();
+		  StartMove_Module( module, DC );
+		  break;
+	      }
+	      module->DisplayInfo( this );
+	      break;
+	    
+	  case TYPE_TEXTE_MODULE:
+	      switch( HK_Descr->m_Idcommand )
+	      {
+	      case HK_ROTATE_FOOTPRINT:
+		  /* Don't re-center if already in edit */
+		 if( DrawStruct->m_Flags == 0 )
+		     GetScreen()->m_Curseur = ((TEXTE_MODULE*) DrawStruct)->GetPosition();
+		 cmd.SetId( ID_POPUP_PCB_ROTATE_TEXTMODULE );
+		 Process_Special_Functions( cmd );
+		 break;
+		
+	      case HK_MOVE_FOOTPRINT_OR_TRACK:
+		  GetScreen()->m_Curseur = ((TEXTE_MODULE*) DrawStruct)->GetPosition();
+		  cmd.SetId( ID_POPUP_PCB_MOVE_TEXTMODULE_REQUEST );
+		  Process_Special_Functions( cmd );
+		  break;
+	      }
+	      ( (TEXTE_MODULE*) DrawStruct )->DisplayInfo( this );
+	      break;
+	    
+	  case TYPE_PAD:
+	      switch( HK_Descr->m_Idcommand )
+	      {
+	      case HK_ROTATE_FOOTPRINT:
+		  /* Actually rotate footprint instead of pad */
+		cmd.SetId( ID_POPUP_PCB_ROTATE_MODULE_COUNTERCLOCKWISE );
+		Process_Special_Functions( cmd );
+		break;
+		
+	      case HK_MOVE_FOOTPRINT_OR_TRACK:
+		  /* Actually move footprint instead of pad */
+		cmd.SetId( ID_POPUP_PCB_MOVE_MODULE_REQUEST );
+		Process_Special_Functions( cmd );
+		break;
+	      }
+	      break;
+	  }
+	}
     }
 }
 
-
 /***********************************************************/
 void WinEDA_ModuleEditFrame::OnHotKey( wxDC* DC, int hotkey,
                                        EDA_BaseStruct* DrawStruct )

=== modified file 'pcbnew/onrightclick.cpp'
--- pcbnew/onrightclick.cpp	2010-08-10 18:34:26 +0000
+++ pcbnew/onrightclick.cpp	2010-08-24 22:06:04 +0000
@@ -681,11 +681,15 @@
     ADD_MENUITEM_WITH_SUBMENU( menu, sub_menu_Fp_text, -1, msg, footprint_text_xpm );
 
     if( !flags )
-        ADD_MENUITEM( sub_menu_Fp_text, ID_POPUP_PCB_MOVE_TEXTMODULE_REQUEST,
-                      _( "Move" ), move_field_xpm );
+    {
+      msg = AddHotkeyName( _( "Move" ), s_Board_Editor_Hokeys_Descr, HK_MOVE_FOOTPRINT_OR_TRACK );
+      ADD_MENUITEM( sub_menu_Fp_text, ID_POPUP_PCB_MOVE_TEXTMODULE_REQUEST,
+		    msg, move_field_xpm );
+    }
 
+    msg = AddHotkeyName( _( "Rotate" ), s_Board_Editor_Hokeys_Descr, HK_ROTATE_FOOTPRINT );
     ADD_MENUITEM( sub_menu_Fp_text, ID_POPUP_PCB_ROTATE_TEXTMODULE,
-                  _( "Rotate" ), rotate_field_xpm );
+                  msg, rotate_field_xpm );
     if( !flags )
     {
         msg = AddHotkeyName( _( "Edit" ), s_Board_Editor_Hokeys_Descr, HK_EDIT_ITEM );
@@ -734,8 +738,9 @@
     sub_menu_Pad = new wxMenu;
     ADD_MENUITEM_WITH_SUBMENU( menu, sub_menu_Pad, -1, msg, pad_xpm );
 
+    msg = AddHotkeyName( _( "Move" ), s_Board_Editor_Hokeys_Descr, HK_MOVE_FOOTPRINT_OR_TRACK );
     ADD_MENUITEM( sub_menu_Pad, ID_POPUP_PCB_MOVE_PAD_REQUEST,
-                  _( "Move" ), move_pad_xpm );
+                  msg, move_pad_xpm );
     ADD_MENUITEM( sub_menu_Pad, ID_POPUP_PCB_DRAG_PAD_REQUEST,
                   _( "Drag" ), drag_pad_xpm );
 


Follow ups