← Back to team overview

kicad-developers team mailing list archive

Re: Locked module really locked patch

 

Sorry about the formatting issues (and double posting to you Dick). My emacs
c-style should now be correct for Kicad. However, the previous patch didn't
quite get fixed to that style yet. I think that this patch has no tabs or
extra whitespace. I also removed the superfluous else statements you pointed
out.

The locked module checking code was removed from hotkeys.cpp since the
methods there (OnHotkeyRotateITem & OnHotkeyMoveItem) broadcast events with
ids such as  ID_POPUP_PCB_MOVE_MODULE_REQUEST. The events are then handled
in edit.cpp by Process_Special_Functions into which the locked module
checking was added. No need to have checking in two places. Or did I miss
something?'

Regards,

Marco
=== modified file 'pcbnew/edit.cpp'
--- pcbnew/edit.cpp	2010-08-17 10:41:44 +0000
+++ pcbnew/edit.cpp	2010-08-29 19:09:39 +0000
@@ -38,6 +38,7 @@
     int         itmp;
     INSTALL_DC( dc, DrawPanel );
     BOARD_ITEM* DrawStruct = GetCurItem();
+    MODULE* module;
 
     DrawPanel->CursorOff( &dc );
 
@@ -608,6 +609,15 @@
             g_Drag_Pistes_On = false;
             break;
         }
+        module = (MODULE*) GetCurItem();
+        if( module->IsLocked() )
+        {
+            wxString msg;
+            msg.Printf( _( "Footprint %s found, but it is locked" ),
+                        module->m_Reference->m_Text.GetData() );
+            DisplayInfoMessage( this, msg );
+            break;
+        }
         GetScreen()->m_Curseur = ((MODULE*) GetCurItem())->m_Pos;
         DrawPanel->MouseToCursorSchema();
         StartMove_Module( (MODULE*) GetCurItem(), &dc );
@@ -615,6 +625,15 @@
 
     case ID_POPUP_PCB_GET_AND_MOVE_MODULE_REQUEST:      /* get module by name and move it */
         SetCurItem( GetModuleByName() );
+        module = (MODULE*) GetCurItem();
+        if( module->IsLocked() )
+        {
+            wxString msg;
+            msg.Printf( _( "Footprint %s found, but it is locked" ),
+                        module->m_Reference->m_Text.GetData() );
+            DisplayInfoMessage( this, msg );
+            break;
+        }
         if( GetCurItem() )
         {
             DrawPanel->MouseToCursorSchema();
@@ -631,6 +650,15 @@
 
         if( !GetCurItem() || GetCurItem()->Type() != TYPE_MODULE )
             break;
+        module = (MODULE*) GetCurItem();
+        if( module->IsLocked() )
+        {
+            wxString msg;
+            msg.Printf( _( "Footprint %s found, but it is locked" ),
+                        module->m_Reference->m_Text.GetData() );
+            DisplayInfoMessage( this, msg );
+            break;
+        }
         if( Delete_Module( (MODULE*) GetCurItem(), &dc, true ) )
         {
             SetCurItem( NULL );
@@ -646,7 +674,15 @@
 
         if( !GetCurItem() || GetCurItem()->Type() != TYPE_MODULE )
             break;
-
+        module = (MODULE*) GetCurItem();
+        if( module->IsLocked() )
+        {
+            wxString msg;
+            msg.Printf( _( "Footprint %s found, but it is locked" ),
+                        module->m_Reference->m_Text.GetData() );
+            DisplayInfoMessage( this, msg );
+            break;
+        }
         if( !(GetCurItem()->m_Flags & IS_MOVED) ) /* This is a simple rotation, no other edition in progress */
             SaveCopyInUndoList(GetCurItem(), UR_ROTATED, ((MODULE*)GetCurItem())->m_Pos);
         Rotate_Module( &dc, (MODULE*) GetCurItem(), 900, true );
@@ -661,6 +697,15 @@
 
         if( !GetCurItem() || GetCurItem()->Type() != TYPE_MODULE )
             break;
+        module = (MODULE*) GetCurItem();
+        if( module->IsLocked() )
+        {
+            wxString msg;
+            msg.Printf( _( "Footprint %s found, but it is locked" ),
+                        module->m_Reference->m_Text.GetData() );
+            DisplayInfoMessage( this, msg );
+            break;
+        }
         if( !(GetCurItem()->m_Flags & IS_MOVED) ) /* This is a simple rotation, no other edition in progress */
             SaveCopyInUndoList(GetCurItem(), UR_ROTATED_CLOCKWISE, ((MODULE*)GetCurItem())->m_Pos);
         Rotate_Module( &dc, (MODULE*) GetCurItem(), -900, true );
@@ -674,10 +719,17 @@
             SetCurItem( GetCurItem()->GetParent() );
         if( !GetCurItem() || GetCurItem()->Type() != TYPE_MODULE )
             break;
-
+        module = (MODULE*) GetCurItem();
+        if( module->IsLocked() )
+        {
+            wxString msg;
+            msg.Printf( _( "Footprint %s found, but it is locked" ),
+                        module->m_Reference->m_Text.GetData() );
+            DisplayInfoMessage( this, msg );
+            break;
+        }
         if( !(GetCurItem()->m_Flags & IS_MOVED) ) /* This is a simple flip, no other edition in progress */
             SaveCopyInUndoList(GetCurItem(), UR_FLIPPED, ((MODULE*)GetCurItem())->m_Pos);
-
         Change_Side_Module( (MODULE*) GetCurItem(), &dc );
         break;
 
@@ -693,12 +745,34 @@
         break;
 
     case ID_POPUP_PCB_DRAG_PAD_REQUEST:
+        module = (MODULE*) GetCurItem()->GetParent();
+        if( !module || module->Type() != TYPE_MODULE )
+            break;
+        if( module->IsLocked() )
+        {
+            wxString msg;
+            msg.Printf( _( "The parent (%s) of the pad is locked" ),
+                        module->m_Reference->m_Text.GetData() );
+            DisplayInfoMessage( this, msg );
+            break;
+        }
         g_Drag_Pistes_On = true;
         DrawPanel->MouseToCursorSchema();
         StartMovePad( (D_PAD*) GetCurItem(), &dc );
         break;
 
     case ID_POPUP_PCB_MOVE_PAD_REQUEST:
+        module = (MODULE*) GetCurItem()->GetParent();
+        if( !module || module->Type() != TYPE_MODULE )
+            break;
+        if( module->IsLocked() )
+        {
+            wxString msg;
+            msg.Printf( _( "The parent (%s) of the pad is locked" ),
+                        module->m_Reference->m_Text.GetData() );
+            DisplayInfoMessage( this, msg );
+            break;
+        }
         g_Drag_Pistes_On = false;
         DrawPanel->MouseToCursorSchema();
         StartMovePad( (D_PAD*) GetCurItem(), &dc );

=== modified file 'pcbnew/hotkeys.cpp'
--- pcbnew/hotkeys.cpp	2010-08-29 17:55:53 +0000
+++ pcbnew/hotkeys.cpp	2010-08-29 19:10:14 +0000
@@ -945,17 +945,6 @@
 
     case TYPE_MODULE:
     {
-        MODULE* module = (MODULE*) item;
-
-        // 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 );
-            break;
-        }
         if( aIdCommand == HK_MOVE_ITEM )
             evt_type = ID_POPUP_PCB_MOVE_MODULE_REQUEST;
         if( aIdCommand == HK_DRAG_ITEM )
@@ -1040,15 +1029,6 @@
     {
     case TYPE_MODULE:
     {
-         MODULE* module = (MODULE*) item;
-        if( module->IsLocked() )
-        {
-            wxString msg;
-            msg.Printf( _( "Footprint %s is locked" ),
-                       module->m_Reference->m_Text.GetData() );
-            DisplayInfoMessage( this, msg );
-            break;
-        }
         if( aIdCommand == HK_ROTATE_ITEM )                      // Rotation
             evt_type = ID_POPUP_PCB_ROTATE_MODULE_COUNTERCLOCKWISE;
         if( aIdCommand == HK_FLIP_FOOTPRINT )                   // move to other side


Follow ups

References