← Back to team overview

kicad-developers team mailing list archive

Re: Footprint reference/value text size patch

 

Wayne,

Thanks for the comments. This new patch adds only "Reset Size" items
into reference, value and text submenus of a module. Global reset of
reference and value sizes is added into the edit menu. There's no menu
item for resetting other module text items globally, although code for
that exists. New methods are added to TEXTE_MODULE class for
retrieving and setting text sizes and widths. Capitalization should be
correct, and the new methods are commented for doxygen in the headers
(the existing SetWidth is also commented and edited to follow the
kicad coding guidelines).

marco

On Mon, Sep 13, 2010 at 5:22 PM, Wayne Stambaugh <stambaughw@xxxxxxxxxxx> wrote:
> On 9/10/2010 9:19 AM, Marco Mattila wrote:
>> Hi,
>>
>> Do you have any input regarding this patch proposal? Is there something that
>> should be done differently for this to be considered?
>
> Marco,
>
> I apologize for not responding sooner but I've been very busy.  I reviewed your
> patch and have a few comments before I would commit it.
>
> 1) Modify the context menu so that selecting a module will only display the
> "Reset Size" menu entry.  "Reset All Sizes" doesn't make sense when selecting a
> module.  "Reset All Sizes" should probably be displayed when selecting an empty
> region of the board.
>
> 2) Menu entries are to have header (Title) capitalization per the UI guidelines
> not sentence capitalization.
>
> 3) Avoid direct manipulation of the module object in your code.  Why not add a
> SetTextSize( aHeight, aWidth ) method to the module class and hide all direct
> manipulation of the module's text objects?  This would make the code easier to
> maintain and understand.
>
> 4) If there are any other text items besides m_Reference and m_Value reset them
> as well.  As a user I would expect all of the module text to get reset not just
> the value and reference text.
>
> I know some of this seems trivial but I have spent a lot of time cleaning up
> these kinds of issues would prefer that the patch submitter clean them up
> before committing it.  Thanks for taking the time to help improve Kicad.
>
> Wayne
>
>>
>> Regards,
>>
>> Marco
>>
>> On Sun, Aug 29, 2010 at 9:50 PM, Marco Mattila wrote:
>>
>>     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
>>
>>
>>
>>
>> _______________________________________________
>> Mailing list: https://launchpad.net/~kicad-developers
>> Post to     : kicad-developers@xxxxxxxxxxxxxxxxxxx
>> Unsubscribe : https://launchpad.net/~kicad-developers
>> More help   : https://help.launchpad.net/ListHelp
>
> _______________________________________________
> Mailing list: https://launchpad.net/~kicad-developers
> Post to     : kicad-developers@xxxxxxxxxxxxxxxxxxx
> Unsubscribe : https://launchpad.net/~kicad-developers
> More help   : https://help.launchpad.net/ListHelp
>
=== modified file 'include/wxBasePcbFrame.h'
--- include/wxBasePcbFrame.h	2010-08-11 13:15:30 +0000
+++ include/wxBasePcbFrame.h	2010-10-17 19:58:49 +0000
@@ -251,6 +251,20 @@
     void          StartMoveTexteModule( TEXTE_MODULE* Text,
                                         wxDC*         DC );
     TEXTE_MODULE* CreateTextModule( MODULE* Module, wxDC* DC );
+    /** Function ResetTextModuleSize
+     * resets given field text size and width to current settings in
+     * Preferences->Dimensions->Texts and Drawings.
+     * @param aText = field to be reset
+     * @param aDC = drawing context
+     */
+    void          ResetTextModuleSize( TEXTE_MODULE* aText, wxDC* aDC );
+    /** Function ResetTextModuleSizes
+     * resets text size and width of all fields of given field type 
+     * to current settings in Preferences->Dimensions->Texts and Drawings.
+     * @param aType = field type (0 for reference, 1 for value)
+     * @param aDC = drawing context
+     */
+    void          ResetTextModuleSizes( int aType, wxDC* aDC );
 
     void          InstallPadOptionsFrame( D_PAD*         pad );
     void          InstallTextModOptionsFrame( TEXTE_MODULE* TextMod,

=== modified file 'pcbnew/class_text_mod.cpp'
--- pcbnew/class_text_mod.cpp	2010-02-08 18:15:42 +0000
+++ pcbnew/class_text_mod.cpp	2010-10-22 21:06:57 +0000
@@ -200,11 +200,25 @@
 }
 
 
-void TEXTE_MODULE:: SetWidth( int new_width )
-{
-    m_Width = new_width;
-}
-
+void TEXTE_MODULE::SetWidth( int aNewWidth )
+{
+    m_Width = aNewWidth;
+}
+
+int TEXTE_MODULE::GetWidth()
+{
+    return m_Width;
+}
+
+void TEXTE_MODULE::SetSize( wxSize aNewSize )
+{
+    m_Size = aNewSize;
+}
+
+wxSize TEXTE_MODULE::GetSize()
+{
+    return m_Size;
+}
 
 // Update draw coordinates
 void TEXTE_MODULE:: SetDrawCoord()

=== modified file 'pcbnew/class_text_mod.h'
--- pcbnew/class_text_mod.h	2009-11-12 15:43:38 +0000
+++ pcbnew/class_text_mod.h	2010-10-22 20:55:54 +0000
@@ -45,7 +45,26 @@
     void     Copy( TEXTE_MODULE* source ); // copy structure
 
     /* Gestion du texte */
-    void     SetWidth( int new_width );
+    /** Function SetWidth
+     * sets text width
+     * @param aNewWidth = new text width
+     */
+    void     SetWidth( int aNewWidth );
+    /** Function GetWidth
+     * returns text width
+     * @return int - text width
+     */
+    int      GetWidth();
+    /** Function SetSize
+     * sets text size
+     * @param aNewSize = new text size
+     */
+    void     SetSize( wxSize aNewSize );
+    /** Function GetSize
+     * returns text size
+     * @return wxSize - text size
+     */
+    wxSize   GetSize();
     int      GetLength();           /* text length */
     int      GetDrawRotation();     // Return text rotation for drawings and
                                     // plotting

=== modified file 'pcbnew/edit.cpp'
--- pcbnew/edit.cpp	2010-09-15 17:50:47 +0000
+++ pcbnew/edit.cpp	2010-10-17 20:58:11 +0000
@@ -814,6 +814,10 @@
         DrawPanel->MouseToCursorSchema();
         break;
 
+    case ID_POPUP_PCB_RESET_TEXTMODULE_SIZE:
+        ResetTextModuleSize( (TEXTE_MODULE*) GetCurItem(), &dc );
+        break;
+
     case ID_POPUP_PCB_MOVE_TEXTMODULE_REQUEST:
         DrawPanel->MouseToCursorSchema();
         StartMoveTexteModule( (TEXTE_MODULE*) GetCurItem(), &dc );
@@ -1016,6 +1020,14 @@
         Swap_Layers( event );
         break;
 
+    case ID_MENU_PCB_RESET_TEXTMODULE_REFERENCE_SIZES:
+        ResetTextModuleSizes( TEXT_is_REFERENCE, &dc );
+        break;
+
+    case ID_MENU_PCB_RESET_TEXTMODULE_VALUE_SIZES:
+        ResetTextModuleSizes( TEXT_is_VALUE, &dc );
+        break;
+
     case ID_PCB_USER_GRID_SETUP:
         InstallGridFrame( pos );
         break;

=== modified file 'pcbnew/edtxtmod.cpp'
--- pcbnew/edtxtmod.cpp	2010-07-20 18:11:34 +0000
+++ pcbnew/edtxtmod.cpp	2010-10-22 20:25:24 +0000
@@ -251,3 +251,129 @@
     /* Redraw the text */
     Text->Draw( panel, DC, GR_XOR, MoveVector );
 }
+
+void WinEDA_BasePcbFrame::ResetTextModuleSize( TEXTE_MODULE* aText, wxDC* aDC )
+{
+    MODULE* module;
+    TEXTE_MODULE* item;
+    ITEM_PICKER itemWrapper( NULL, UR_CHANGED );
+    itemWrapper.m_PickedItemType = TYPE_MODULE;
+    PICKED_ITEMS_LIST undoItemList;
+    int ii;
+
+    module = (MODULE*) aText->GetParent();
+
+    // Prepare undo list
+    itemWrapper.m_PickedItem = module;
+    // Check if there will be any change
+    if( aText->GetSize() != g_ModuleTextSize ||
+        aText->GetWidth() != g_ModuleTextWidth )
+        undoItemList.PushItem( itemWrapper );
+
+    // Exit if there's nothing to do
+    if( !undoItemList.GetCount() )
+        return;
+
+    SaveCopyInUndoList( undoItemList, UR_CHANGED );
+
+    // Apply changes
+    aText->SetWidth( g_ModuleTextWidth );
+    aText->SetSize( g_ModuleTextSize );
+
+    if( aDC )
+        DrawPanel->Refresh();
+
+    OnModify();
+}
+
+void WinEDA_BasePcbFrame::ResetTextModuleSizes( int aType, wxDC* aDC )
+{
+    MODULE* module;
+    BOARD_ITEM* boardItem;
+    TEXTE_MODULE* item;
+    ITEM_PICKER itemWrapper( NULL, UR_CHANGED );
+    itemWrapper.m_PickedItemType = TYPE_MODULE;
+    PICKED_ITEMS_LIST undoItemList;
+    int ii;
+
+    module = GetBoard()->m_Modules;
+
+    // Prepare undo list
+    while( module )
+    {
+        itemWrapper.m_PickedItem = module;
+        switch( aType )
+        {
+        case TEXT_is_REFERENCE:
+            item = module->m_Reference;
+            if( item->GetSize() != g_ModuleTextSize ||
+                item->GetWidth() != g_ModuleTextWidth )
+                undoItemList.PushItem( itemWrapper );
+            break;
+        case TEXT_is_VALUE:
+            item = module->m_Value;
+            if( item->GetSize() != g_ModuleTextSize ||
+                item->GetWidth() != g_ModuleTextWidth )
+                undoItemList.PushItem( itemWrapper );
+            break;
+        default:
+            // Go through all other module texts
+            for( boardItem = module->m_Drawings; boardItem;
+                 boardItem = boardItem->Next() )
+            {
+                if( boardItem->Type() == TYPE_TEXTE_MODULE )
+                {
+                    item = (TEXTE_MODULE*) boardItem;
+                    if( item->GetSize() != g_ModuleTextSize ||
+                        item->GetWidth() != g_ModuleTextWidth )
+                    {
+                        undoItemList.PushItem( itemWrapper );
+                        break;
+                    }
+                }
+            }
+            break;
+        }
+        module = module->Next();
+    }
+
+    // Exit if there's nothing to do
+    if( !undoItemList.GetCount() )
+        return;
+
+    SaveCopyInUndoList( undoItemList, UR_CHANGED );
+
+    // Apply changes to modules in the undo list
+    for( ii = 0; ii < undoItemList.GetCount(); ii++ )
+    {
+        module = (MODULE*) undoItemList.GetPickedItem( ii );
+        switch( aType )
+        {
+        case TEXT_is_REFERENCE:
+            module->m_Reference->SetWidth( g_ModuleTextWidth );
+            module->m_Reference->SetSize( g_ModuleTextSize );
+            break;
+        case TEXT_is_VALUE:
+            module->m_Value->SetWidth( g_ModuleTextWidth );
+            module->m_Value->SetSize( g_ModuleTextSize );
+            break;
+        default:
+            for( boardItem = module->m_Drawings; boardItem;
+                 boardItem = boardItem->Next() )
+            {
+                if( boardItem->Type() == TYPE_TEXTE_MODULE )
+                {
+                    item = (TEXTE_MODULE*) boardItem;
+                    item->SetWidth( g_ModuleTextWidth );
+                    item->SetSize( g_ModuleTextSize );
+                }
+            }
+            break;
+        }
+    }
+
+    if( aDC )
+        DrawPanel->Refresh();
+
+    OnModify();
+}

=== modified file 'pcbnew/menubar_pcbframe.cpp'
--- pcbnew/menubar_pcbframe.cpp	2010-10-09 08:08:29 +0000
+++ pcbnew/menubar_pcbframe.cpp	2010-10-17 20:57:00 +0000
@@ -295,6 +295,19 @@
     item->SetBitmap( swap_layer_xpm );
     editMenu->Append( item );
 
+    // Reset module reference sizes
+    item = new wxMenuItem( editMenu,
+                           ID_MENU_PCB_RESET_TEXTMODULE_REFERENCE_SIZES,
+                           _( "Reset Module &Reference Sizes" ),
+                           _( "Reset text size and width of all module references to current defaults" ) );
+    editMenu->Append( item );
+
+    // Reset module value sizes
+    item = new wxMenuItem( editMenu,
+                           ID_MENU_PCB_RESET_TEXTMODULE_VALUE_SIZES,
+                           _( "Reset Module &Value Sizes" ),
+                           _( "Reset text size and width of all module values to current defaults" ) );
+    editMenu->Append( item );
 
     /**
      * View menu

=== modified file 'pcbnew/onrightclick.cpp'
--- pcbnew/onrightclick.cpp	2010-09-03 14:33:09 +0000
+++ pcbnew/onrightclick.cpp	2010-10-16 22:29:40 +0000
@@ -705,6 +705,8 @@
         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);
     }
 
     if( !flags && FpText->m_Type == TEXT_is_DIVERS )    // Graphic texts can be deleted only if are not currently edited

=== modified file 'pcbnew/pcbframe.cpp'
--- pcbnew/pcbframe.cpp	2010-08-17 10:41:44 +0000
+++ pcbnew/pcbframe.cpp	2010-10-17 21:09:39 +0000
@@ -147,6 +147,10 @@
     EVT_MENU( ID_MENU_PCB_CLEAN, WinEDA_PcbFrame::Process_Special_Functions )
     EVT_MENU( ID_MENU_PCB_SWAP_LAYERS,
               WinEDA_PcbFrame::Process_Special_Functions )
+    EVT_MENU( ID_MENU_PCB_RESET_TEXTMODULE_REFERENCE_SIZES,
+              WinEDA_PcbFrame::Process_Special_Functions )
+    EVT_MENU( ID_MENU_PCB_RESET_TEXTMODULE_VALUE_SIZES,
+              WinEDA_PcbFrame::Process_Special_Functions )
 
     // Menu Help
     EVT_MENU( ID_GENERAL_HELP, WinEDA_DrawFrame::GetKicadHelp )

=== modified file 'pcbnew/pcbnew_id.h'
--- pcbnew/pcbnew_id.h	2010-08-17 10:41:44 +0000
+++ pcbnew/pcbnew_id.h	2010-10-17 20:52:54 +0000
@@ -52,6 +52,7 @@
     ID_POPUP_PCB_ROTATE_TEXTMODULE,
     ID_POPUP_PCB_EDIT_TEXTMODULE,
     ID_POPUP_PCB_DELETE_TEXTMODULE,
+    ID_POPUP_PCB_RESET_TEXTMODULE_SIZE,
 
     ID_POPUP_PCB_MOVE_TEXTEPCB_REQUEST,
     ID_POPUP_PCB_ROTATE_TEXTEPCB,
@@ -213,6 +214,8 @@
     ID_MENU_LIST_NETS,
     ID_MENU_PCB_CLEAN,
     ID_MENU_PCB_SWAP_LAYERS,
+    ID_MENU_PCB_RESET_TEXTMODULE_REFERENCE_SIZES,
+    ID_MENU_PCB_RESET_TEXTMODULE_VALUE_SIZES,
     ID_GEN_EXPORT_FILE_VRML,
 
     ID_TOOLBARH_PCB_MODE_MODULE,


References