From 74a635c127da5cbb2dcbbb85915890bf6bfaef0c Mon Sep 17 00:00:00 2001
From: dickelbeck <Unknown>
Date: Wed, 5 Sep 2007 04:48:47 +0000
Subject: [PATCH] see 2007-Sep-4 change_log.txt

---
 change_log.txt            |  14 ++-
 cvpcb/makefile.include    |   6 +-
 gerbview/makefile.include |   6 +-
 include/wxstruct.h        |  23 +++--
 pcbnew/basepcbframe.cpp   | 181 +++++++++++++++++++++++---------------
 pcbnew/collectors.cpp     | 151 +++++++++++++++----------------
 pcbnew/collectors.h       |  26 +++---
 pcbnew/controle.cpp       |   5 +-
 pcbnew/ioascii.cpp        |   6 +-
 pcbnew/onrightclick.cpp   |   5 +-
 pcbnew/pcbframe.cpp       |  13 +--
 todo.txt                  |  10 +--
 12 files changed, 251 insertions(+), 195 deletions(-)

diff --git a/change_log.txt b/change_log.txt
index 2a3f562b4c..a216546a22 100644
--- a/change_log.txt
+++ b/change_log.txt
@@ -4,6 +4,18 @@ Started 2007-June-11
 Please add newer entries at the top, list the date and your name with 
 email address.
 
+
+2007-Sep-4 UPDATE   Dick Hollenbeck <dick@softplc.com>
+================================================================================
++ pcbnew
+  * Made GENERAL_COLLECTORS_GUIDE and GENERAL_COLLECTOR useable.  They can now
+    serve as a fully functional replacement for PcbGeneralLocateAndDisplay(),
+    see DEBUG code in BOARD_ITEM* WinEDA_BasePcbFrame::PcbGeneralLocateAndDisplay().
+  * Made GENERAL_COLLECTOR capable of Collect()ing from a MODULE as well as a BOARD.
+  * pcbnew/onrightclick.cpp changed English from "Free Module" to "Unlock Module".
+  Next I hope to add some UI to handle multiple items under the mouse in onrightclick.cpp
+    
+
 2007-sept-04 UPDATE   Jean-Pierre Charras <jean-pierre.charras@inpg.fr>
 ================================================================================
 + pcbnew
@@ -39,8 +51,6 @@ email address.
     be instantiated.  This was not happening in ioascii.cpp when reading 
     the vias.  Bug fixed.
   * GENERAL_COLLECTOR getting closer to useable.
-    @todo search further for new TRACK( TRACK* ) and make sure no vias are
-    being made this way.
 
 
 2007-aug-30 UPDATE   Jean-Pierre Charras <jean-pierre.charras@inpg.fr>
diff --git a/cvpcb/makefile.include b/cvpcb/makefile.include
index 865d031d62..1de52de6f1 100644
--- a/cvpcb/makefile.include
+++ b/cvpcb/makefile.include
@@ -43,7 +43,8 @@ OBJECTS = $(TARGET).o \
 			class_edge_mod.o \
 			class_equipot.o \
 			class_track.o\
-			basepcbframe.o
+			basepcbframe.o\
+            collectors.o
 
 cvpcb.o: cvpcb.cpp cvpcb.h $(DEPEND)
 
@@ -99,6 +100,9 @@ class_equipot.o: ../pcbnew/class_equipot.cpp $(DEPEND)
 basepcbframe.o: ../pcbnew/basepcbframe.cpp $(DEPEND)
 	$(CC) -c $(EDACPPFLAGS) -o $@ ../pcbnew/$*.cpp
 
+collectors.o: ../pcbnew/collectors.cpp $(COMMON)
+	$(CC) -c $(EDACPPFLAGS) -o $@ ../pcbnew/$*.cpp
+    
 readschematicnetlist.o: readschematicnetlist.cpp $(DEPEND)
 
 viewlogi.o: viewlogi.cpp $(DEPEND)
diff --git a/gerbview/makefile.include b/gerbview/makefile.include
index dd25abb029..aab02dfbf1 100644
--- a/gerbview/makefile.include
+++ b/gerbview/makefile.include
@@ -45,7 +45,8 @@ OBJECTS= \
 		block.o\
 		controle.o\
 		basepcbframe.o\
-		export_to_pcbnew.o
+		export_to_pcbnew.o\
+        collectors.o
 
 setpage.o: ../share/setpage.cpp
 	$(CC) -c $(EDACPPFLAGS) -o $@ ../share/$*.cpp
@@ -85,6 +86,9 @@ class_board.o: ../pcbnew/class_board.cpp $(DEPEND)
 basepcbframe.o: ../pcbnew/basepcbframe.cpp $(COMMON)
 	$(CC) -c $(EDACPPFLAGS) -o $@ ../pcbnew/$*.cpp
 
+collectors.o: ../pcbnew/collectors.cpp $(COMMON)
+	$(CC) -c $(EDACPPFLAGS) -o $@ ../pcbnew/$*.cpp
+    
 class_track.o: ../pcbnew/class_track.cpp $(COMMON)
 	$(CC) -c $(EDACPPFLAGS) -o $@ ../pcbnew/$*.cpp
 
diff --git a/include/wxstruct.h b/include/wxstruct.h
index d5185b3396..7e2e973050 100644
--- a/include/wxstruct.h
+++ b/include/wxstruct.h
@@ -97,6 +97,7 @@ class PARAM_CFG_BASE;
 class Ki_PageDescr;
 class Ki_HotkeyInfo;
 class GENERAL_COLLECTOR;
+class GENERAL_COLLECTORS_GUIDE;
 
 
 enum id_librarytype {
@@ -338,6 +339,12 @@ public:
     bool   m_DisplayPcbTrackFill;   /* FALSE = sketch , TRUE = rempli */
     WinEDA3D_DrawFrame* m_Draw3DFrame;
 
+protected:    
+#if defined(DEBUG)
+    GENERAL_COLLECTOR*  m_Collector;
+#endif
+    
+    
 public:
     WinEDA_BasePcbFrame( wxWindow* father, WinEDA_App* parent, int idtype,
                          const wxString& title,
@@ -372,11 +379,6 @@ private:
     virtual void    GetComponentFromUndoList();
     virtual void    GetComponentFromRedoList();
 
-#if defined(DEBUG)
-protected:
-    GENERAL_COLLECTOR*  m_Collector;
-#endif
-   
     
 public:
     // Read/write fonctions:
@@ -393,6 +395,14 @@ public:
     BOARD_ITEM*     PcbGeneralLocateAndDisplay();
     BOARD_ITEM*     Locate( int typeloc, int LayerSearch );
 
+#if defined(DEBUG)
+    /**
+     * Function GetCollectorsGuide
+     * @return GENERAL_COLLECTORS_GUIDE - that considers the global configuration options.
+     */
+    GENERAL_COLLECTORS_GUIDE GetCollectorsGuide();
+#endif
+    
     // Gestion du curseur
     void            place_marqueur( wxDC* DC, const wxPoint& pos, char* pt_bitmap,
                                     int DrawMode, int color, int type );
@@ -522,6 +532,7 @@ private:
     bool             m_SelViaSizeBox_Changed;
     wxMenu*          m_FilesMenu;
 
+    
 public:
     WinEDA_PcbFrame( wxWindow* father, WinEDA_App* parent, const wxString& title,
                      const wxPoint& pos, const wxSize& size );
@@ -764,6 +775,8 @@ public:
 
     EDA_BaseStruct* GerberGeneralLocateAndDisplay();
     EDA_BaseStruct* Locate( int typeloc );
+    
+    
 
     void            SetToolbars();
     void            Process_Settings( wxCommandEvent& event );
diff --git a/pcbnew/basepcbframe.cpp b/pcbnew/basepcbframe.cpp
index 1118208074..66a95f4675 100644
--- a/pcbnew/basepcbframe.cpp
+++ b/pcbnew/basepcbframe.cpp
@@ -1,6 +1,6 @@
-	/************************************************************************/
-	/* basepcbframe.cpp - fonctions des classes du type WinEDA_BasePcbFrame */
-	/************************************************************************/
+/************************************************************************/
+/* basepcbframe.cpp - fonctions des classes du type WinEDA_BasePcbFrame */
+/************************************************************************/
 
 #ifdef __GNUG__
 #pragma implementation
@@ -15,89 +15,108 @@
 #include "protos.h"
 #include "id.h"
 
+#if defined(DEBUG)
+#include "collectors.h"
+#endif
 
 
-	/*******************************/
-	/* class WinEDA_BasePcbFrame */
-	/*******************************/
+/*******************************/
+/* class WinEDA_BasePcbFrame */
+/*******************************/
 
-	/****************/
-	/* Constructeur */
-	/****************/
+/****************/
+/* Constructeur */
+/****************/
 
-WinEDA_BasePcbFrame::WinEDA_BasePcbFrame(wxWindow * father, WinEDA_App *parent,
-					int idtype,
-					const wxString & title, const wxPoint& pos, const wxSize& size) :
-					WinEDA_DrawFrame(father, idtype, parent, title, pos, size)
+WinEDA_BasePcbFrame::WinEDA_BasePcbFrame( wxWindow* father,
+                                          WinEDA_App* parent,
+                                          int idtype,
+                                          const wxString& title,
+                                          const wxPoint& pos,
+                                          const wxSize& size ) :
+    WinEDA_DrawFrame( father, idtype, parent, title, pos, size )
 {
-	m_InternalUnits = 10000;		// Internal unit = 1/10000 inch
-	m_CurrentScreen = NULL;
-	m_Pcb = NULL;
+    m_InternalUnits = 10000;        // Internal unit = 1/10000 inch
+    m_CurrentScreen = NULL;
+    m_Pcb = NULL;
 
-	m_DisplayPadFill = TRUE;		// How to draw pads
-	m_DisplayPadNum = TRUE;			// show pads number
+    m_DisplayPadFill = TRUE;        // How to draw pads
+    m_DisplayPadNum  = TRUE;        // show pads number
 
-	m_DisplayModEdge = FILLED;		// How to show module drawings
-	m_DisplayModText = FILLED;		// How to show module texts
-	m_DisplayPcbTrackFill = TRUE;	/* FALSE = sketch , TRUE = filled */
-	m_Draw3DFrame = NULL;			// Display Window in 3D mode (OpenGL)
+    m_DisplayModEdge      = FILLED; // How to show module drawings
+    m_DisplayModText      = FILLED; // How to show module texts
+    m_DisplayPcbTrackFill = TRUE;   /* FALSE = sketch , TRUE = filled */
+    m_Draw3DFrame = NULL;           // Display Window in 3D mode (OpenGL)
+    
+#if defined(DEBUG)    
+    m_Collector                = new GENERAL_COLLECTOR();
+#endif    
+    
 }
 
-WinEDA_BasePcbFrame::~WinEDA_BasePcbFrame(void)
+
+WinEDA_BasePcbFrame::~WinEDA_BasePcbFrame( void )
 {
+#if defined(DEBUG)    
+    delete m_Collector;
+#endif    
 }
 
 
 /**************************************/
-int WinEDA_BasePcbFrame::BestZoom(void)
+int WinEDA_BasePcbFrame::BestZoom( void )
 /**************************************/
 {
-int dx, dy, ii,jj ;
-int bestzoom;
-wxSize size;
+    int    dx, dy, ii, jj;
+    int    bestzoom;
+    wxSize size;
 
-	if ( m_Pcb == NULL ) return 32;
+    if( m_Pcb == NULL )
+        return 32;
 
-	m_Pcb->ComputeBoundaryBox();
+    m_Pcb->ComputeBoundaryBox();
 
-	/* calcul du zoom montrant tout le dessim */
-	dx = m_Pcb->m_BoundaryBox.GetWidth();
-	dy = m_Pcb->m_BoundaryBox.GetHeight();
+    /* calcul du zoom montrant tout le dessim */
+    dx = m_Pcb->m_BoundaryBox.GetWidth();
+    dy = m_Pcb->m_BoundaryBox.GetHeight();
 
-	size =  DrawPanel->GetClientSize();
-	ii = (dx + (size.x/2)) / size.x;
-	jj = (dy + (size.y/2)) / size.y;
-	bestzoom = MAX(ii, jj) + 1;
+    size     = DrawPanel->GetClientSize();
+    ii       = ( dx + (size.x / 2) ) / size.x;
+    jj       = ( dy + (size.y / 2) ) / size.y;
+    bestzoom = MAX( ii, jj ) + 1;
 
-	m_CurrentScreen->m_Curseur = m_Pcb->m_BoundaryBox.Centre();
+    m_CurrentScreen->m_Curseur = m_Pcb->m_BoundaryBox.Centre();
 
-	return(bestzoom);
+    return bestzoom;
 }
 
 
-void WinEDA_BasePcbFrame::ReCreateMenuBar(void)	// fonction virtuelle
+void WinEDA_BasePcbFrame::ReCreateMenuBar( void ) // fonction virtuelle
 {
 }
 
+
 #include "3d_viewer.h"
 
 /***********************************************************/
-void WinEDA_BasePcbFrame::Show3D_Frame(wxCommandEvent& event)
+void WinEDA_BasePcbFrame::Show3D_Frame( wxCommandEvent& event )
 /***********************************************************/
+
 /* Ouvre la frame d'affichage 3D
-*/
+ */
 {
 #ifndef GERBVIEW
-	// Create the main frame window
-	if ( m_Draw3DFrame )
-	{
-		DisplayInfo(this, _("3D Frame already opened") );
-		return;
-	}
-	m_Draw3DFrame = new WinEDA3D_DrawFrame(this, m_Parent, _("3D Viewer") );
 
-	// Show the frame
-	m_Draw3DFrame->Show(TRUE);
+    // Create the main frame window
+    if( m_Draw3DFrame )
+    {
+        DisplayInfo( this, _( "3D Frame already opened" ) );
+        return;
+    }
+    m_Draw3DFrame = new WinEDA3D_DrawFrame( this, m_Parent, _( "3D Viewer" ) );
+
+    // Show the frame
+    m_Draw3DFrame->Show( TRUE );
 #endif
 }
 
@@ -105,43 +124,67 @@ void WinEDA_BasePcbFrame::Show3D_Frame(wxCommandEvent& event)
 /* Virtual functions: Do nothing for WinEDA_BasePcbFrame window */
 
 /***********************************************************************************/
-void WinEDA_BasePcbFrame::SaveCopyInUndoList(EDA_BaseStruct * ItemToCopy, int flag)
+void WinEDA_BasePcbFrame::SaveCopyInUndoList( EDA_BaseStruct* ItemToCopy, int flag )
 /***********************************************************************************/
 {
 }
 
+
 /********************************************************/
-void WinEDA_BasePcbFrame::GetComponentFromUndoList(void)
+void WinEDA_BasePcbFrame::GetComponentFromUndoList( void )
 /********************************************************/
 {
 }
 
+
 /********************************************************/
-void WinEDA_BasePcbFrame::GetComponentFromRedoList(void)
+void WinEDA_BasePcbFrame::GetComponentFromRedoList( void )
 /********************************************************/
 {
 }
 
 
 /****************************************************************/
-void WinEDA_BasePcbFrame::SwitchLayer(wxDC *DC, int layer)
+void WinEDA_BasePcbFrame::SwitchLayer( wxDC* DC, int layer )
 /*****************************************************************/
 {
-	//Note: virtual, overridden in WinEDA_PcbFrame;
-	int preslayer = GetScreen()->m_Active_Layer; 
-	//if there is only one layer, don't switch. 
-	if ( m_Pcb->m_BoardSettings->m_CopperLayerCount <= 1)
-		layer = LAYER_CUIVRE_N;	// Of course we select the copper layer
-	//otherwise, we select the requested layer only if it is possible
-	if( layer != LAYER_CMP_N && layer >= m_Pcb->m_BoardSettings->m_CopperLayerCount-1 )
-		return;
-	if(preslayer == layer)
-		return; 
-	
-	GetScreen()->m_Active_Layer = layer; 
-	
-	if ( DisplayOpt.ContrastModeDisplay )
-		GetScreen()->SetRefreshReq();
+    //Note: virtual, overridden in WinEDA_PcbFrame;
+    int preslayer = GetScreen()->m_Active_Layer;
+
+    //if there is only one layer, don't switch.
+    if( m_Pcb->m_BoardSettings->m_CopperLayerCount <= 1 )
+        layer = LAYER_CUIVRE_N; // Of course we select the copper layer
+    
+    //otherwise, we select the requested layer only if it is possible
+    if( layer != LAYER_CMP_N && layer >= m_Pcb->m_BoardSettings->m_CopperLayerCount - 1 )
+        return;
+    
+    if( preslayer == layer )
+        return;
+
+    GetScreen()->m_Active_Layer = layer;
+
+    if( DisplayOpt.ContrastModeDisplay )
+        GetScreen()->SetRefreshReq();
 }
 
+#if defined(DEBUG)
+/****************************************************************/
+GENERAL_COLLECTORS_GUIDE WinEDA_BasePcbFrame::GetCollectorsGuide()
+/****************************************************************/
+{
+    GENERAL_COLLECTORS_GUIDE    guide( m_Pcb->m_BoardSettings->GetVisibleLayers(), 
+                                      GetScreen()->m_Active_Layer ); 
+
+    // account for the globals
+    guide.SetIgnoreMTextsMarkedNoShow( g_ModuleTextNOVColor & ITEM_NOT_SHOW );
+    guide.SetIgnoreMTextsOnCopper( g_ModuleTextCUColor & ITEM_NOT_SHOW );
+    guide.SetIgnoreMTextsOnCmp( g_ModuleTextCMPColor & ITEM_NOT_SHOW );
+    guide.SetIgnoreModulesOnCu( !DisplayOpt.Show_Modules_Cu );
+    guide.SetIgnoreModulesOnCmp( !DisplayOpt.Show_Modules_Cmp );
+
+    return guide;
+}
+
+#endif
 
diff --git a/pcbnew/collectors.cpp b/pcbnew/collectors.cpp
index 65ddbe6358..2b47499577 100644
--- a/pcbnew/collectors.cpp
+++ b/pcbnew/collectors.cpp
@@ -68,62 +68,95 @@ SEARCH_RESULT GENERAL_COLLECTOR::Inspect( EDA_BaseStruct* testItem, const void*
     switch( item->Type() )
     {
     case TYPEPAD:
-            breakhere++;
-            break;
+        breakhere++;
+        break;
     case TYPEVIA:
-            breakhere++;
-            break;
+        breakhere++;
+        break;
     case TYPETRACK:
-            breakhere++;
-            break;
+        breakhere++;
+        break;
     case TYPETEXTE: 
-            breakhere++;
-            break;
+        breakhere++;
+        break;
     case TYPEDRAWSEGMENT: 
-            breakhere++;
-            break;
+        breakhere++;
+        break;
     case TYPECOTATION:
-            breakhere++;
-            break;
+        breakhere++;
+        break;
     case TYPETEXTEMODULE:
-            TEXTE_MODULE* tm;
-            tm = (TEXTE_MODULE*) item;
+        {            
+            TEXTE_MODULE* tm = (TEXTE_MODULE*) item;
             if( tm->m_Text == wxT("10uH") )
             {
                 breakhere++;
             }
-            break;
+        }            
+        break;
     case TYPEMODULE:
-            MODULE* m;
-            m = (MODULE*) item;
-            if( m->GetReference() == wxT("L1") )
+        {
+            MODULE* m = (MODULE*) item;
+            if( m->GetReference() == wxT("C98") )
             {
                 breakhere++;
             }
-            break;
+        }
+        break;
+        
     default:
-            breakhere++;
-            break;
+        breakhere++;
+        break;
     }
 #endif
-    
 
-#if 1
 
-/*
-    int     m_PreferredLayer;             x
-    bool    m_IgnorePreferredLayer    
-    int     m_LayerVisible;               x
-    bool    m_IgnoreNonVisibleLayers;
+    switch( item->Type() )
+    {
+    case TYPEPAD:
+        break;
+    case TYPEVIA:
+        break;
+    case TYPETRACK:
+        break;
+    case TYPETEXTE: 
+        break;
+    case TYPEDRAWSEGMENT: 
+        break;
+    case TYPECOTATION:
+        break;
+    case TYPETEXTEMODULE:
+        {
+            TEXTE_MODULE*   tm = (TEXTE_MODULE*) item;
+            MODULE*         parent = (MODULE*)tm->GetParent();
+            if( m_Guide->IgnoreMTextsMarkedNoShow() && tm->m_NoShow )
+                goto exit;
+
+            if( parent )
+            {
+                if( m_Guide->IgnoreMTextsOnCopper() && parent->GetLayer()==LAYER_CUIVRE_N )
+                    goto exit;
+                
+                if( m_Guide->IgnoreMTextsOnCmp() && parent->GetLayer()==LAYER_CMP_N )
+                    goto exit;
+            }
+        }
+        break;
+        
+    case TYPEMODULE:
+        if( m_Guide->IgnoreModulesOnCu() && item->GetLayer()==LAYER_CUIVRE_N )
+            goto exit;
+        if( m_Guide->IgnoreModulesOnCmp() && item->GetLayer()==LAYER_CMP_N )
+            goto exit;
+        break;
+        
+    default:
+        break;
+    }
+
     
-    int     m_LayerLocked;                x
-    bool    m_IgnoreLockedLayers;
+    // common tests:
     
-    bool    m_IgnoreLockedItems;          x
-    
-    bool    m_IncludeSecondary;
-*/    
-   
     if( item->IsOnLayer( m_Guide->GetPreferredLayer() ) || m_Guide->IgnorePreferredLayer() )
     {
         int layer = item->GetLayer();
@@ -144,6 +177,7 @@ SEARCH_RESULT GENERAL_COLLECTOR::Inspect( EDA_BaseStruct* testItem, const void*
         }
     }
 
+    
     if( m_Guide->IncludeSecondary() )
     {
         // for now, "secondary" means "tolerate any layer".  It has
@@ -168,27 +202,6 @@ SEARCH_RESULT GENERAL_COLLECTOR::Inspect( EDA_BaseStruct* testItem, const void*
         }
     }
     
-#else
-    // The primary search criteria:
-    if( item->IsOnLayer( m_PreferredLayer ) )
-    {
-        if( item->HitTest( m_RefPos ) )
-        {
-            if( !item->IsLocked() )
-                Append( item );
-            else
-                Append2nd( item );      // 2nd if locked.
-        }
-    }
-    
-    // The secondary search criteria
-    else if( item->IsOnOneOfTheseLayers( m_LayerMask ) )
-    {
-        if( item->HitTest( m_RefPos ) )
-            Append2nd( item );
-    }
-#endif        
-
 exit:
     return SEARCH_CONTINUE;     // always when collecting
 }
@@ -229,21 +242,21 @@ void GENERAL_COLLECTOR::Collect( BOARD* board, const wxPoint& refPos,
 
 
 // see collectors.h 
-void GENERAL_COLLECTOR::Collect( BOARD* board, const wxPoint& refPos, 
-                            const COLLECTORS_GUIDE* guide )
+void GENERAL_COLLECTOR::Collect( BOARD_ITEM* aItem, const wxPoint& refPos, 
+                            const COLLECTORS_GUIDE* aGuide )
 {
     Empty();        // empty the collection, primary criteria list
     Empty2nd();     // empty the collection, secondary criteria list
 
     // remember guide, pass it to Inspect()
-    SetGuide( guide );
+    SetGuide( aGuide );
     
     // remember where the snapshot was taken from and pass refPos to
     // the Inspect() function.
     SetRefPos( refPos );
 
     // visit the board with the INSPECTOR (me).
-    board->Visit(   this,       // INSPECTOR* inspector
+    aItem->Visit(   this,       // INSPECTOR* inspector
                     NULL,       // const void* testData, not used here 
                     m_ScanTypes);
     
@@ -257,24 +270,6 @@ void GENERAL_COLLECTOR::Collect( BOARD* board, const wxPoint& refPos,
 }
 
 
-/** is still inline
- * Constructor GENERAL_COLLECTORS_GUIDE
- * grabs stuff from global preferences and uses reasonable defaults.
- * Add more constructors as needed.
-GENERAL_COLLECTORS_GUIDE::GENERAL_COLLECTORS_GUIDE()
-{
-    
-    m_LayerLocked;    
-    m_LayerVisible;       
-    m_IgnoreLockedLayers;
-    m_IgnoreNonVisibleLayers;
-    m_PreferredLayer;    
-    m_IgnoreLockedItems;    
-    m_IncludeSecondary;
-}
- */
-
-
 #endif  // DEBUG
 
 //EOF
diff --git a/pcbnew/collectors.h b/pcbnew/collectors.h
index 001002d65c..c31a4264b0 100644
--- a/pcbnew/collectors.h
+++ b/pcbnew/collectors.h
@@ -280,11 +280,11 @@ public:
     /**
      * Function Collect
      * scans a BOARD using this class's Inspector method, which does the collection.
-     * @param aBoard A BOARD to scan.
+     * @param aItem A BOARD_ITEM to scan, may be a BOARD or MODULE, or whatever. 
      * @param aRefPos A wxPoint to use in hit-testing.
      * @param aGuide The COLLECTORS_GUIDE to use in collecting items.
      */
-    void Collect( BOARD* aBoard, const wxPoint& aRefPos, const COLLECTORS_GUIDE* aGuide ); 
+    void Collect( BOARD_ITEM* aItem, const wxPoint& aRefPos, const COLLECTORS_GUIDE* aGuide ); 
 };
 
 
@@ -325,29 +325,31 @@ public:
      * Add more constructors as needed.
      * @param settings The EDA_BoardDesignSettings to reference.
      */
-    GENERAL_COLLECTORS_GUIDE( const EDA_BoardDesignSettings* settings )
+    GENERAL_COLLECTORS_GUIDE( int aVisibleLayerMask, int aPreferredLayer )
     {
         m_PreferredLayer            = LAYER_CMP_N;
         m_IgnorePreferredLayer      = false;
         m_LayerLocked               = 0;
-        m_LayerVisible              = settings->GetVisibleLayers();    
+        m_LayerVisible              = aVisibleLayerMask;    
         m_IgnoreLockedLayers        = true;
         m_IgnoreNonVisibleLayers    = true;
-        m_IgnoreLockedItems         = true;
+        m_IgnoreLockedItems         = false;
         
 #if defined(USE_MATCH_LAYER)
         m_IncludeSecondary          = false;
 #else        
         m_IncludeSecondary          = true;
-#endif        
+#endif  
 
-//        m_IgnoreMTextsMarkedNoShow = g_ModuleTextNOVColor;
-        m_IgnoreMTextsOnCopper;
-        m_IgnoreMTextsOnCmp;
-        m_IgnoreModulesOnCu;
-//        m_IgnoreModulesOnCmp = !settings->Show_Modules_Cmp;
+        m_PreferredLayer            = aPreferredLayer;
+
+        m_IgnoreMTextsMarkedNoShow  = true; // g_ModuleTextNOVColor;
+        m_IgnoreMTextsOnCopper      = true;
+        m_IgnoreMTextsOnCmp         = false;
+        m_IgnoreModulesOnCu         = true; // !Show_Modules_Cmp;
+        m_IgnoreModulesOnCmp        = false;
     }
-
+    
     
     /**
      * Function IsLayerLocked
diff --git a/pcbnew/controle.cpp b/pcbnew/controle.cpp
index c41bb6453c..76fe3573a8 100644
--- a/pcbnew/controle.cpp
+++ b/pcbnew/controle.cpp
@@ -131,10 +131,7 @@ BOARD_ITEM* WinEDA_BasePcbFrame::PcbGeneralLocateAndDisplay()
 #if defined(DEBUG)
 
     // test scaffolding for Collect():
-    GENERAL_COLLECTORS_GUIDE    guide( m_Pcb->m_BoardSettings );
-    
-    guide.SetIgnoreLockedItems( false );
-    guide.SetPreferredLayer( GetScreen()->m_Active_Layer );    
+    GENERAL_COLLECTORS_GUIDE  guide = GetCollectorsGuide();
     
     m_Collector->Collect( m_Pcb, 
                        GetScreen()->RefPos(true), 
diff --git a/pcbnew/ioascii.cpp b/pcbnew/ioascii.cpp
index 936952d3e7..c76bb08178 100644
--- a/pcbnew/ioascii.cpp
+++ b/pcbnew/ioascii.cpp
@@ -423,6 +423,7 @@ int WinEDA_BasePcbFrame::ReadSetup( FILE* File, int* LineNum )
             }
             else
                 continue;
+            
             data = strtok( NULL, " =\n\r" );
             if( data )
             {
@@ -431,6 +432,7 @@ int WinEDA_BasePcbFrame::ReadSetup( FILE* File, int* LineNum )
             }
             else
                 g_UserGrid.y = g_UserGrid.x;
+            
             GetScreen()->m_UserGrid = g_UserGrid;
             data = strtok( NULL, " =\n\r" );
             if( data )
@@ -565,6 +567,7 @@ static int WriteSetup( FILE* File, WinEDA_BasePcbFrame* frame )
         ii = frame->GetScreen()->GetGrid().x;
         jj = frame->GetScreen()->GetGrid().y;
     }
+    
     sprintf( text, "GridSize %d %d\n", ii, jj );
     fprintf( File, text );
 
@@ -602,6 +605,7 @@ static int WriteSetup( FILE* File, WinEDA_BasePcbFrame* frame )
     fprintf( File, "TextPcbWidth %d\n", g_DesignSettings.m_PcbTextWidth );
     fprintf( File, "TextPcbSize %d %d\n",
              g_DesignSettings.m_PcbTextSize.x, g_DesignSettings.m_PcbTextSize.y );
+    
     fprintf( File, "EdgeModWidth %d\n", ModuleSegmentWidth );
     fprintf( File, "TextModSize %d %d\n", ModuleTextSize.x, ModuleTextSize.y );
     fprintf( File, "TextModWidth %d\n", ModuleTextWidth );
@@ -613,11 +617,11 @@ static int WriteSetup( FILE* File, WinEDA_BasePcbFrame* frame )
 
     fprintf( File, "AuxiliaryAxisOrg %d %d\n",
              frame->m_Auxiliary_Axis_Position.x, frame->m_Auxiliary_Axis_Position.y );
+    
     fprintf( File, "$EndSETUP\n\n" );
     return 1;
 }
 
-
 #endif
 
 
diff --git a/pcbnew/onrightclick.cpp b/pcbnew/onrightclick.cpp
index bcc2f50ffa..967b44dfca 100644
--- a/pcbnew/onrightclick.cpp
+++ b/pcbnew/onrightclick.cpp
@@ -187,7 +187,8 @@ void WinEDA_PcbFrame::OnRightClick( const wxPoint& MousePos, wxMenu* PopMenu )
 
     if( BlockActive )
     {
-        DrawPanel->CursorOn( &dc ); return;
+        DrawPanel->CursorOn( &dc ); 
+        return;
     }
 
     m_CurrentScreen->SetCurItem( DrawStruct );
@@ -218,7 +219,7 @@ void WinEDA_PcbFrame::OnRightClick( const wxPoint& MousePos, wxMenu* PopMenu )
                 PopMenu->AppendSeparator();
                 ADD_MENUITEM( PopMenu, ID_POPUP_PCB_AUTOPLACE_FIXE_MODULE, _( "Lock Module" ),
                               Locked_xpm );
-                ADD_MENUITEM( PopMenu, ID_POPUP_PCB_AUTOPLACE_FREE_MODULE, _( "Free Module" ),
+                ADD_MENUITEM( PopMenu, ID_POPUP_PCB_AUTOPLACE_FREE_MODULE, _( "Unlock Module" ),
                               Unlocked_xpm );
                 if( !flags )
                     PopMenu->Append( ID_POPUP_PCB_AUTOPLACE_CURRENT_MODULE,
diff --git a/pcbnew/pcbframe.cpp b/pcbnew/pcbframe.cpp
index df8955b126..1b5f41cfec 100644
--- a/pcbnew/pcbframe.cpp
+++ b/pcbnew/pcbframe.cpp
@@ -11,10 +11,6 @@
 #include "protos.h"
 #include "id.h"
 
-#if defined(DEBUG)
-#include "collectors.h"
-#endif
-
 
 /*******************************/
 /* class WinEDA_PcbFrame */
@@ -192,10 +188,6 @@ WinEDA_PcbFrame::WinEDA_PcbFrame( wxWindow* father, WinEDA_App* parent,
     m_SelTrackWidthBox_Changed = FALSE;
     m_SelViaSizeBox_Changed    = FALSE;
     
-#if defined(DEBUG)    
-    m_Collector                = new GENERAL_COLLECTOR();
-#endif    
-
     m_DisplayPcbTrackFill = DisplayOpt.DisplayPcbTrackFill;
     m_DisplayPadFill = DisplayOpt.DisplayPadFill;
     m_DisplayPadNum  = DisplayOpt.DisplayPadNum;
@@ -241,10 +233,6 @@ WinEDA_PcbFrame::~WinEDA_PcbFrame()
 {
     m_Parent->m_PcbFrame = NULL;
     m_CurrentScreen = ScreenPcb;
-    
-#if defined(DEBUG)    
-    delete m_Collector;
-#endif    
 }
 
 
@@ -551,3 +539,4 @@ void WinEDA_PcbFrame::SetToolbars()
 
     DisplayUnitsMsg();
 }
+
diff --git a/todo.txt b/todo.txt
index f21eef88bc..6d9cc3568d 100644
--- a/todo.txt
+++ b/todo.txt
@@ -4,14 +4,8 @@ folks will see these items and volunteer to do them.
 
 
 
-*** Look at @todo in editrack-part2.cpp.  Is this is a bug?  ** Done (JP Charras)  **
-Concerns:
-a) Isn't there a problem with losing the memory of the original?
-b) If this is supposed to duplicate a SEGVIA to, then this call should be changed
-   to the new TRACK::Copy(), i.e. g_CurrentTrackSegment->Copy() 
->> (JP Charras:) No problem. the code is correct.
-	I have put comments to explain this code section and modified some line for a more intelligible code
-
+*** Add hierarchical menu to right mouse click in PCBNEW for the case when
+multiple items are under the mouse cursor.
 
    
 *** Set up a DOXYGEN environment starting with a configuration file that: