← Back to team overview

kicad-developers team mailing list archive

Footprint reference/value text size patch

 

Hi,

I've attached a patch that allows reseting footprint reference or value text
sizes and widths to the defaults set in the Dimensions->Texts and Drawings
dialog. The functions "Reset size" and "Reset all sizes" are added into
Reference and Value submenus of the right-click context menu (not sure if
that's the correct place for these). Reset size resets the selected field
only, all sizes resets all similar fields (reference or value).

Regards,

Marco
=== modified file 'include/wxBasePcbFrame.h'
--- include/wxBasePcbFrame.h	2010-08-11 13:15:30 +0000
+++ include/wxBasePcbFrame.h	2010-08-29 17:54:41 +0000
@@ -251,6 +251,8 @@
     void          StartMoveTexteModule( TEXTE_MODULE* Text,
                                         wxDC*         DC );
     TEXTE_MODULE* CreateTextModule( MODULE* Module, wxDC* DC );
+    void          ResetTextModuleSizes( TEXTE_MODULE* Text, bool changeAll,
+                                        wxDC* DC );
 
     void          InstallPadOptionsFrame( D_PAD*         pad );
     void          InstallTextModOptionsFrame( TEXTE_MODULE* TextMod,

=== modified file 'pcbnew/edit.cpp'
--- pcbnew/edit.cpp	2010-08-17 10:41:44 +0000
+++ pcbnew/edit.cpp	2010-08-29 17:54:14 +0000
@@ -737,6 +737,14 @@
         DrawPanel->MouseToCursorSchema();
         break;
 
+    case ID_POPUP_PCB_RESET_TEXTMODULE_SIZE:
+        ResetTextModuleSizes( (TEXTE_MODULE*) GetCurItem(), false, &dc );
+        break;
+
+    case ID_POPUP_PCB_RESET_TEXTMODULE_SIZES:
+        ResetTextModuleSizes( (TEXTE_MODULE*) GetCurItem(), true, &dc );
+        break;
+
     case ID_POPUP_PCB_MOVE_TEXTMODULE_REQUEST:
         DrawPanel->MouseToCursorSchema();
         StartMoveTexteModule( (TEXTE_MODULE*) GetCurItem(), &dc );

=== modified file 'pcbnew/edtxtmod.cpp'
--- pcbnew/edtxtmod.cpp	2010-07-20 18:11:34 +0000
+++ pcbnew/edtxtmod.cpp	2010-08-29 18:40:23 +0000
@@ -232,7 +232,6 @@
     DrawPanel->ForceCloseManageCurseur = NULL;
 }
 
-
 static void Show_MoveTexte_Module( WinEDA_DrawPanel* panel, wxDC* DC,
                                    bool erase )
 {
@@ -251,3 +250,83 @@
     /* Redraw the text */
     Text->Draw( panel, DC, GR_XOR, MoveVector );
 }
+
+/* Reset (all) module reference/value text sizes (and widths) to */
+/* values set in Dimensions->Texts and Drawings dialog. */
+/* If changeAll == true, all similar fields are reset. */
+void WinEDA_BasePcbFrame::ResetTextModuleSizes( TEXTE_MODULE* Text, bool changeAll, wxDC* DC )
+{
+    MODULE* module;
+    TEXTE_MODULE* item;
+    ITEM_PICKER itemWrapper( NULL, UR_CHANGED );
+    itemWrapper.m_PickedItemType = TYPE_MODULE;
+    PICKED_ITEMS_LIST undoItemList;
+    int ii;
+
+    if( changeAll )
+        module = GetBoard()->m_Modules;
+    else
+        module = (MODULE*) Text->GetParent();
+
+    /* Prepare undo list */
+    while( module )
+    {
+        itemWrapper.m_PickedItem = module;
+        switch( Text->m_Type )
+        {
+        case 0:
+            item = module->m_Reference;
+            break;
+        case 1:
+            item = module->m_Value;
+            break;
+        default:
+            item = NULL;
+            break;
+        }
+        module = module->Next();
+        if( item )
+        {
+            /* Check if there will be any change */
+            if( item->m_Size != g_ModuleTextSize ||
+                item->m_Width != g_ModuleTextWidth )
+                undoItemList.PushItem( itemWrapper );
+        }
+        /* Get out of the loop if changing only current footprint */
+        if( !changeAll )
+            break;
+    }
+
+    if( !undoItemList.GetCount() )
+        return;
+
+    SaveCopyInUndoList( undoItemList, UR_CHANGED );
+
+    /* Apply changes to modules in the list */
+    for( ii = 0; ii < undoItemList.GetCount(); ii++ )
+    {
+        module = (MODULE*) undoItemList.GetPickedItem( ii );
+        switch( Text->m_Type )
+        {
+        case 0:
+            item = module->m_Reference;
+            break;
+        case 1:
+            item = module->m_Value;
+            break;
+        default:
+            item = NULL;
+            break;
+        }
+        if( item )
+        {
+            item->SetWidth( g_ModuleTextWidth );
+            item->m_Size = g_ModuleTextSize;
+        }
+    }
+
+    if( DC )
+        DrawPanel->Refresh();
+
+    OnModify();
+}

=== modified file 'pcbnew/onrightclick.cpp'
--- pcbnew/onrightclick.cpp	2010-08-17 17:45:45 +0000
+++ pcbnew/onrightclick.cpp	2010-08-29 17:52:52 +0000
@@ -698,6 +698,11 @@
         msg = AddHotkeyName( _( "Edit" ), s_Board_Editor_Hokeys_Descr, HK_EDIT_ITEM );
         ADD_MENUITEM( sub_menu_Fp_text, ID_POPUP_PCB_EDIT_TEXTMODULE,
                       msg, edit_text_xpm );
+        ADD_MENUITEM( sub_menu_Fp_text, ID_POPUP_PCB_RESET_TEXTMODULE_SIZE,
+                      _( "Reset size" ), edit_text_xpm);
+        sub_menu_Fp_text->AppendSeparator();
+        ADD_MENUITEM( sub_menu_Fp_text, ID_POPUP_PCB_RESET_TEXTMODULE_SIZES,
+                      _( "Reset all sizes" ), edit_text_xpm);
     }
 
     if( !flags && FpText->m_Type == TEXT_is_DIVERS )    // Graphic texts can be deleted only if are not currently edited

=== modified file 'pcbnew/pcbnew_id.h'
--- pcbnew/pcbnew_id.h	2010-08-17 10:41:44 +0000
+++ pcbnew/pcbnew_id.h	2010-08-29 17:53:18 +0000
@@ -52,6 +52,8 @@
     ID_POPUP_PCB_ROTATE_TEXTMODULE,
     ID_POPUP_PCB_EDIT_TEXTMODULE,
     ID_POPUP_PCB_DELETE_TEXTMODULE,
+    ID_POPUP_PCB_RESET_TEXTMODULE_SIZE,
+    ID_POPUP_PCB_RESET_TEXTMODULE_SIZES,
 
     ID_POPUP_PCB_MOVE_TEXTEPCB_REQUEST,
     ID_POPUP_PCB_ROTATE_TEXTEPCB,


Follow ups