← Back to team overview

kicad-developers team mailing list archive

[PATCH] hiding nets from ratsnest

 

This patch adds support to hide individual nets from ratsnest by adding an extra tickbox to the 'List nets' dialog.

The ratsnest visibility is stored in NETINFO_ITEM, which I'm not sure is the right place to put it. I tried using IsVisible/SetVisible from RN_NET, but that doesn't work because RN_NET items are constantly deleted and recreated and I couldn't see a straightforward way to make this information permanent.

This fixes lp:1457668.

aiju
diff --git a/pcbnew/class_netinfo.h b/pcbnew/class_netinfo.h
index f77b0e3..b7898e2 100644
--- a/pcbnew/class_netinfo.h
+++ b/pcbnew/class_netinfo.h
@@ -140,6 +140,8 @@ private:

     BOARD*  m_parent;           ///< The parent board the net belongs to.

+    bool m_ratsnest_visible;
+
 public:

     D_PADS& Pads()              { return m_PadInNetList; }
@@ -353,6 +355,16 @@ public:
     {
         return m_parent;
     }
+
+    bool IsRatsnestVisible(void)
+    {
+        return m_ratsnest_visible;
+    }
+
+    void SetRatsnestVisible(bool aVis)
+    {
+        m_ratsnest_visible = aVis;
+    }
 };


diff --git a/pcbnew/class_netinfo_item.cpp b/pcbnew/class_netinfo_item.cpp
index c52e973..e789fa9 100644
--- a/pcbnew/class_netinfo_item.cpp
+++ b/pcbnew/class_netinfo_item.cpp
@@ -58,6 +58,8 @@ NETINFO_ITEM::NETINFO_ITEM( BOARD* aParent, const wxString& aNetName, int aNetCo
                                 // general buffer of ratsnest
     m_RatsnestEndIdx   = 0;     // Ending point of ratsnests of this net

+    m_ratsnest_visible = true;
+
     m_NetClassName = NETCLASS::Default;
 }

diff --git a/pcbnew/dialogs/dialog_select_net_from_list.cpp b/pcbnew/dialogs/dialog_select_net_from_list.cpp
index 01ad563..f4539aa 100644
--- a/pcbnew/dialogs/dialog_select_net_from_list.cpp
+++ b/pcbnew/dialogs/dialog_select_net_from_list.cpp
@@ -42,13 +42,16 @@
 #include <view/view.h>
 #include <view/view_controls.h>
 #include <pcb_painter.h>
+#include <ratsnest_data.h>

 #define COL_NETNAME 0
 #define COL_NETINFO 1
+#define COL_RATSVIS 2

 class DIALOG_SELECT_NET_FROM_LIST: public DIALOG_SELECT_NET_FROM_LIST_BASE
 {
 private:
+    PCB_EDIT_FRAME * m_parent;
     wxString m_selection;
     bool m_wasSelected;
     BOARD* m_brd;
@@ -106,6 +109,10 @@ void PCB_EDIT_FRAME::ListNetsAndSelect( wxCommandEvent& event )
 DIALOG_SELECT_NET_FROM_LIST::DIALOG_SELECT_NET_FROM_LIST( PCB_EDIT_FRAME* aParent )
     : DIALOG_SELECT_NET_FROM_LIST_BASE( aParent )
 {
+
+    m_parent = aParent;
+    m_netsListGrid->SetColFormatBool(COL_RATSVIS);
+
     m_brd = aParent->GetBoard();
     m_wasSelected = false;

@@ -159,6 +166,8 @@ void DIALOG_SELECT_NET_FROM_LIST::buildNetsList()
         }
         else    // For the net 0 (unconnected pads), the pad count is not known
             m_netsListGrid->SetCellValue( row_idx, COL_NETINFO, "---" );
+
+        m_netsListGrid->SetCellValue( row_idx, COL_RATSVIS, net->IsRatsnestVisible() ? "1" : "" );

         row_idx++;
     }
@@ -195,7 +204,27 @@ void DIALOG_SELECT_NET_FROM_LIST::onCellClick( wxGridEvent& event )

     // Select the full row when clicking on any cell off the row
     m_netsListGrid->SelectRow( selected_row, false );
-    m_netsListGrid->SetGridCursor(selected_row, COL_NETNAME );
+    m_netsListGrid->SetGridCursor(selected_row, event.GetCol() );
+
+    if( event.GetCol() == COL_RATSVIS )
+    {
+        NETINFO_ITEM *net = m_brd->FindNet(m_selection);
+        if( net != NULL )
+        {
+            net->SetRatsnestVisible(!net->IsRatsnestVisible());
+            m_netsListGrid->SetCellValue( selected_row, COL_RATSVIS, net->IsRatsnestVisible() ? "1" : "" );
+            m_parent->Compile_Ratsnest(NULL, true);
+            if( m_parent->IsGalCanvasActive() )
+            {
+                m_parent->GetGalCanvas()->GetView()->UpdateAllLayersColor();
+                m_parent->GetGalCanvas()->Refresh();
+            }
+            else
+            {
+                m_parent->GetCanvas()->Refresh();
+            }
+        }
+    }
 }


diff --git a/pcbnew/dialogs/dialog_select_net_from_list_base.cpp b/pcbnew/dialogs/dialog_select_net_from_list_base.cpp
index 4b200e7..3928f95 100644
--- a/pcbnew/dialogs/dialog_select_net_from_list_base.cpp
+++ b/pcbnew/dialogs/dialog_select_net_from_list_base.cpp
@@ -1,5 +1,5 @@
 ///////////////////////////////////////////////////////////////////////////
-// C++ code generated with wxFormBuilder (version Jan  1 2016)
+// C++ code generated with wxFormBuilder (version Feb  8 2017)
 // http://www.wxformbuilder.org/
 //
 // PLEASE DO "NOT" EDIT THIS FILE!
@@ -11,7 +11,7 @@

 DIALOG_SELECT_NET_FROM_LIST_BASE::DIALOG_SELECT_NET_FROM_LIST_BASE( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : DIALOG_SHIM( parent, id, title, pos, size, style )
 {
-        this->SetSizeHints( wxSize( 400,200 ), wxDefaultSize );
+        this->SetSizeHints( wxSize( 600,200 ), wxDefaultSize );

         wxBoxSizer* bSizerMain;
         bSizerMain = new wxBoxSizer( wxVERTICAL );
@@ -39,7 +39,7 @@ DIALOG_SELECT_NET_FROM_LIST_BASE::DIALOG_SELECT_NET_FROM_LIST_BASE( wxWindow* pa
         m_netsListGrid = new wxGrid( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 );

         // Grid
-        m_netsListGrid->CreateGrid( 1, 2 );
+        m_netsListGrid->CreateGrid( 1, 3 );
         m_netsListGrid->EnableEditing( false );
         m_netsListGrid->EnableGridLines( true );
         m_netsListGrid->EnableDragGridSize( false );
@@ -48,11 +48,13 @@ DIALOG_SELECT_NET_FROM_LIST_BASE::DIALOG_SELECT_NET_FROM_LIST_BASE( wxWindow* pa
         // Columns
         m_netsListGrid->SetColSize( 0, 325 );
         m_netsListGrid->SetColSize( 1, 100 );
+        m_netsListGrid->SetColSize( 2, 87 );
         m_netsListGrid->EnableDragColMove( false );
         m_netsListGrid->EnableDragColSize( true );
         m_netsListGrid->SetColLabelSize( 20 );
         m_netsListGrid->SetColLabelValue( 0, _("Net name") );
         m_netsListGrid->SetColLabelValue( 1, _("Number of pads") );
+        m_netsListGrid->SetColLabelValue( 2, _("Show ratsnest") );
         m_netsListGrid->SetColLabelAlignment( wxALIGN_LEFT, wxALIGN_CENTRE );

         // Rows
diff --git a/pcbnew/dialogs/dialog_select_net_from_list_base.fbp b/pcbnew/dialogs/dialog_select_net_from_list_base.fbp
index d3784f8..038dc40 100644
--- a/pcbnew/dialogs/dialog_select_net_from_list_base.fbp
+++ b/pcbnew/dialogs/dialog_select_net_from_list_base.fbp
@@ -41,10 +41,10 @@
             <property name="hidden">0</property>
             <property name="id">wxID_ANY</property>
             <property name="maximum_size"></property>
-            <property name="minimum_size">400,200</property>
+            <property name="minimum_size">600,200</property>
             <property name="name">DIALOG_SELECT_NET_FROM_LIST_BASE</property>
             <property name="pos"></property>
-            <property name="size">477,278</property>
+            <property name="size">577,279</property>
             <property name="style">wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER</property>
             <property name="subclass">DIALOG_SHIM; dialog_shim.h</property>
             <property name="title">Nets</property>
@@ -401,10 +401,10 @@
                         <property name="close_button">1</property>
                         <property name="col_label_horiz_alignment">wxALIGN_LEFT</property>
                         <property name="col_label_size">20</property>
-                        <property name="col_label_values">&quot;Net name&quot; &quot;Number of pads&quot;</property>
+                        <property name="col_label_values">&quot;Net name&quot; &quot;Number of pads&quot; &quot;Show ratsnest&quot;</property>
                         <property name="col_label_vert_alignment">wxALIGN_CENTRE</property>
-                        <property name="cols">2</property>
-                        <property name="column_sizes">325,100</property>
+                        <property name="cols">3</property>
+                        <property name="column_sizes">325,100,87</property>
                         <property name="context_help"></property>
                         <property name="context_menu">1</property>
                         <property name="default_pane">0</property>
diff --git a/pcbnew/dialogs/dialog_select_net_from_list_base.h b/pcbnew/dialogs/dialog_select_net_from_list_base.h
index db3dc18..9544148 100644
--- a/pcbnew/dialogs/dialog_select_net_from_list_base.h
+++ b/pcbnew/dialogs/dialog_select_net_from_list_base.h
@@ -1,5 +1,5 @@
 ///////////////////////////////////////////////////////////////////////////
-// C++ code generated with wxFormBuilder (version Jan  1 2016)
+// C++ code generated with wxFormBuilder (version Feb  8 2017)
 // http://www.wxformbuilder.org/
 //
 // PLEASE DO "NOT" EDIT THIS FILE!
@@ -55,7 +55,7 @@ class DIALOG_SELECT_NET_FROM_LIST_BASE : public DIALOG_SHIM

         public:

-                DIALOG_SELECT_NET_FROM_LIST_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Nets"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 477,278 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER );
+                DIALOG_SELECT_NET_FROM_LIST_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Nets"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 600,279 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER );
                 ~DIALOG_SELECT_NET_FROM_LIST_BASE();

 };
diff --git a/pcbnew/ratsnest.cpp b/pcbnew/ratsnest.cpp
index fcd3be2..5293464 100644
--- a/pcbnew/ratsnest.cpp
+++ b/pcbnew/ratsnest.cpp
@@ -42,6 +42,7 @@
 #include <pcbnew.h>

 #include <minimun_spanning_tree.h>
+#include <ratsnest_data.h>

 /**
  * @brief class MIN_SPAN_TREE_PADS (derived from MIN_SPAN_TREE) specializes
@@ -276,6 +277,9 @@ void PCB_BASE_FRAME::Build_Board_Ratsnest()
         min_spanning_tree.BuildTree();
         min_spanning_tree.AddTreeToRatsnest( &m_Pcb->m_FullRatsnest );
         net->m_RatsnestEndIdx = m_Pcb->GetRatsnestsCount();
+        if( !net->IsRatsnestVisible() )
+            for( unsigned jj = net->m_RatsnestStartIdx; jj < net->m_RatsnestEndIdx; jj++ )
+                m_Pcb->m_FullRatsnest[jj].m_Status &= ~CH_VISIBLE;
     }

     m_Pcb->SetUnconnectedNetCount( noconn );
diff --git a/pcbnew/ratsnest_data.h b/pcbnew/ratsnest_data.h
index 5497c23..2547918 100644
--- a/pcbnew/ratsnest_data.h
+++ b/pcbnew/ratsnest_data.h
@@ -782,6 +782,8 @@ public:
      */
     int GetUnconnectedCount() const;

+    const BOARD *GetBoard() const { return m_board; }
+
 protected:
     /**
      * Function updateNet()
diff --git a/pcbnew/ratsnest_viewitem.cpp b/pcbnew/ratsnest_viewitem.cpp
index cdeba78..f505436 100644
--- a/pcbnew/ratsnest_viewitem.cpp
+++ b/pcbnew/ratsnest_viewitem.cpp
@@ -32,6 +32,7 @@
 #include <gal/graphics_abstraction_layer.h>
 #include <pcb_painter.h>
 #include <layers_id_colors_and_visibility.h>
+#include <class_board.h>

 #include <view/view.h>

@@ -92,6 +93,10 @@ void RATSNEST_VIEWITEM::ViewDraw( int aLayer, KIGFX::VIEW* aView ) const
             }
         }

+        NETINFO_ITEM *neti = m_data->GetBoard()->FindNet( i );
+        if(neti != NULL && !neti->IsRatsnestVisible())
+                continue;
+
         // Draw the "static" ratsnest
         if( i != highlightedNet )
             gal->SetStrokeColor( color );  // using the default ratsnest color for not highlighted

Follow ups