kicad/pcbnew/collectors.cpp

429 lines
11 KiB
C++
Raw Normal View History

2007-08-23 04:28:46 +00:00
/*
* This program source code file is part of KICAD, a free EDA CAD application.
*
* Copyright (C) 2007-2008 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
2007-08-23 04:28:46 +00:00
* Copyright (C) 2004-2007 Kicad Developers, see change_log.txt for contributors.
*
2007-08-23 04:28:46 +00:00
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
2007-08-23 04:28:46 +00:00
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
2007-08-23 04:28:46 +00:00
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
2007-08-23 04:28:46 +00:00
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include "collectors.h"
2007-08-23 04:28:46 +00:00
#include "pcbnew.h" // class BOARD
/* This module contains out of line member functions for classes given in
* collectors.h. Those classes augment the functionality of class PCB_EDIT_FRAME.
*/
2007-08-23 04:28:46 +00:00
// see collectors.h
2007-08-30 22:20:52 +00:00
const KICAD_T GENERAL_COLLECTOR::AllBoardItems[] = {
2007-10-03 19:45:32 +00:00
// there are some restrictions on the order of items in the general case.
// all items in m_Drawings for instance should be contiguous.
// *** all items in a same list (shown here) must be contiguous ****
TYPE_MARKER_PCB, // in m_markers
TYPE_TEXTE, // in m_Drawings
TYPE_DRAWSEGMENT, // in m_Drawings
TYPE_DIMENSION, // in m_Drawings
PCB_TARGET_T, // in m_Drawings
TYPE_VIA, // in m_Tracks
TYPE_TRACK, // in m_Tracks
TYPE_PAD, // in modules
TYPE_TEXTE_MODULE, // in modules
TYPE_MODULE, // in m_Modules
TYPE_ZONE, // in m_Zones
TYPE_ZONE_CONTAINER, // in m_ZoneDescriptorList
2007-08-23 04:28:46 +00:00
EOT
};
2007-08-23 04:28:46 +00:00
2007-10-10 14:08:26 +00:00
/*
* const KICAD_T GENERAL_COLLECTOR::PrimaryItems[] = {
* TYPE_TEXTE,
* TYPE_DRAWSEGMENT,
* TYPE_DIMENSION,
* TYPE_VIA,
* TYPE_TRACK,
* TYPE_MODULE,
* EOT
* };
*/
2007-09-06 04:34:03 +00:00
2007-09-25 15:10:01 +00:00
const KICAD_T GENERAL_COLLECTOR::AllButZones[] = {
2009-08-01 19:26:05 +00:00
TYPE_MARKER_PCB,
TYPE_TEXTE,
TYPE_DRAWSEGMENT,
TYPE_DIMENSION,
PCB_TARGET_T,
TYPE_VIA,
TYPE_TRACK,
TYPE_PAD,
TYPE_TEXTE_MODULE,
TYPE_MODULE,
TYPE_ZONE_CONTAINER, // if it is visible on screen, it should be selectable
2007-09-25 15:10:01 +00:00
EOT
};
2007-09-25 15:10:01 +00:00
const KICAD_T GENERAL_COLLECTOR::ModuleItems[] = {
TYPE_MODULE,
EOT
};
const KICAD_T GENERAL_COLLECTOR::PadsOrModules[] = {
TYPE_PAD,
TYPE_MODULE,
EOT
};
2008-02-19 16:54:57 +00:00
const KICAD_T GENERAL_COLLECTOR::PadsTracksOrZones[] = {
TYPE_PAD,
TYPE_VIA,
TYPE_TRACK,
TYPE_ZONE,
TYPE_ZONE_CONTAINER,
EOT
};
const KICAD_T GENERAL_COLLECTOR::ModulesAndTheirItems[] = {
TYPE_TEXTE_MODULE,
TYPE_EDGE_MODULE,
TYPE_PAD,
TYPE_MODULE,
EOT
};
const KICAD_T GENERAL_COLLECTOR::Tracks[] = {
TYPE_TRACK,
TYPE_VIA,
EOT
};
const KICAD_T GENERAL_COLLECTOR::Zones[] = {
TYPE_ZONE_CONTAINER,
EOT
};
2007-08-23 04:28:46 +00:00
/**
* Function Inspect
* is the examining function within the INSPECTOR which is passed to the
* Iterate function. Searches and collects all the objects that the old
2007-08-23 04:28:46 +00:00
* function PcbGeneralLocateAndDisplay() would find, except that it keeps all
* that it finds and does not do any displaying.
2007-08-23 04:28:46 +00:00
*
* @param testItem An EDA_ITEM to examine.
2010-12-29 17:47:32 +00:00
* @param testData The const void* testData, not used here.
2007-08-23 04:28:46 +00:00
* @return SEARCH_RESULT - SEARCH_QUIT if the Iterator is to stop the scan,
* else SCAN_CONTINUE;
*/
2010-12-29 17:47:32 +00:00
SEARCH_RESULT GENERAL_COLLECTOR::Inspect( EDA_ITEM* testItem, const void* testData )
2007-08-23 04:28:46 +00:00
{
BOARD_ITEM* item = (BOARD_ITEM*) testItem;
MODULE* module = NULL;
D_PAD* pad = NULL;
bool pad_through = false;
#if 0 // debugging
static int breakhere = 0;
2007-09-01 12:00:30 +00:00
switch( item->Type() )
{
case TYPE_PAD:
{
MODULE* m = (MODULE*) item->GetParent();
if( m->GetReference() == wxT( "Y2" ) )
{
breakhere++;
}
}
2007-09-05 04:48:47 +00:00
break;
case TYPE_VIA:
2007-09-05 04:48:47 +00:00
breakhere++;
break;
case TYPE_TRACK:
2007-09-05 04:48:47 +00:00
breakhere++;
break;
case TYPE_ZONE:
breakhere++;
break;
case TYPE_TEXTE:
2007-09-05 04:48:47 +00:00
breakhere++;
break;
case TYPE_DRAWSEGMENT:
2007-09-05 04:48:47 +00:00
breakhere++;
break;
case TYPE_DIMENSION:
2007-09-05 04:48:47 +00:00
breakhere++;
break;
case TYPE_TEXTE_MODULE:
{
TEXTE_MODULE* tm = (TEXTE_MODULE*) item;
if( tm->m_Text == wxT( "10uH" ) )
{
breakhere++;
}
}
2007-09-05 04:48:47 +00:00
break;
case TYPE_MODULE:
{
MODULE* m = (MODULE*) item;
if( m->GetReference() == wxT( "C98" ) )
2007-09-05 04:48:47 +00:00
{
breakhere++;
2007-09-05 04:48:47 +00:00
}
}
2007-09-05 04:48:47 +00:00
break;
default:
2007-09-05 04:48:47 +00:00
breakhere++;
break;
}
#endif
2007-08-30 22:20:52 +00:00
2007-09-05 04:48:47 +00:00
switch( item->Type() )
{
case TYPE_PAD:
// there are pad specific visibility controls.
// Criterias to select a pad is:
// for smd pads: the module parent must be seen, and pads on the corresponding
// board side must be seen
2007-09-22 04:33:44 +00:00
// if pad is a thru hole, then it can be visible when its parent module is not.
// for through pads: pads on Front or Back board sides must be seen
pad = (D_PAD*) item;
if( (pad->m_Attribut != PAD_SMD) &&
(pad->m_Attribut != PAD_CONN) ) // a hole is present, so multiple layers
2007-09-22 04:33:44 +00:00
{
// proceed to the common tests below, but without the parent module test,
// by leaving module==NULL, but having pad != null
pad_through = true;
2007-09-22 04:33:44 +00:00
}
else // smd, so use pads test after module test
{
2007-09-22 04:33:44 +00:00
module = (MODULE*) item->GetParent();
}
2007-09-05 04:48:47 +00:00
break;
case TYPE_VIA:
2007-09-05 04:48:47 +00:00
break;
case TYPE_TRACK:
2007-09-05 04:48:47 +00:00
break;
case TYPE_ZONE:
break;
case TYPE_ZONE_CONTAINER:
break;
case TYPE_TEXTE:
2007-09-05 04:48:47 +00:00
break;
case TYPE_DRAWSEGMENT:
2007-09-05 04:48:47 +00:00
break;
case TYPE_DIMENSION:
2007-09-05 04:48:47 +00:00
break;
case PCB_TARGET_T:
break;
case TYPE_TEXTE_MODULE:
2007-09-25 15:10:01 +00:00
module = (MODULE*) item->GetParent();
if( m_Guide->IgnoreMTextsMarkedNoShow() && ( (TEXTE_MODULE*) item )->m_NoShow )
2007-09-25 15:10:01 +00:00
goto exit;
2007-09-25 15:10:01 +00:00
if( module )
2007-09-05 04:48:47 +00:00
{
if( m_Guide->IgnoreMTextsOnCopper() && module->GetLayer()==LAYER_N_BACK )
2007-09-05 04:48:47 +00:00
goto exit;
if( m_Guide->IgnoreMTextsOnCmp() && module->GetLayer()==LAYER_N_FRONT )
2007-09-25 15:10:01 +00:00
goto exit;
2007-09-05 04:48:47 +00:00
}
break;
case TYPE_MODULE:
module = (MODULE*) item;
2007-09-05 04:48:47 +00:00
break;
2007-09-05 04:48:47 +00:00
default:
break;
}
2007-09-05 04:48:47 +00:00
// common tests:
if( module ) // true from case TYPE_PAD, TYPE_TEXTE_MODULE, or TYPE_MODULE
{
if( m_Guide->IgnoreModulesOnCu() && module->GetLayer()==LAYER_N_BACK )
goto exit;
if( m_Guide->IgnoreModulesOnCmp() && module->GetLayer()==LAYER_N_FRONT )
goto exit;
}
2007-09-15 04:25:54 +00:00
// Pads are not sensitive to the layer visibility controls.
// They all have their own separate visibility controls
// skip them if not visible
if ( pad )
{
if( m_Guide->IgnorePads() )
goto exit;
if( ! pad_through )
{
if( m_Guide->IgnorePadsOnFront() && pad->IsOnLayer(LAYER_N_FRONT ) )
goto exit;
if( m_Guide->IgnorePadsOnBack() && pad->IsOnLayer(LAYER_N_BACK ) )
goto exit;
}
}
2007-08-30 22:20:52 +00:00
if( item->IsOnLayer( m_Guide->GetPreferredLayer() ) || m_Guide->IgnorePreferredLayer() )
2007-08-23 04:28:46 +00:00
{
2007-08-30 22:20:52 +00:00
int layer = item->GetLayer();
2007-09-15 04:25:54 +00:00
// Modules and their subcomponents: text and pads are not sensitive to the layer
// visibility controls. They all have their own separate visibility controls
if( module || pad || m_Guide->IsLayerVisible( layer ) || !m_Guide->IgnoreNonVisibleLayers() )
2007-08-23 04:28:46 +00:00
{
if( !m_Guide->IsLayerLocked( layer ) || !m_Guide->IgnoreLockedLayers() )
{
2007-08-30 22:20:52 +00:00
if( !item->IsLocked() || !m_Guide->IgnoreLockedItems() )
{
if( item->HitTest( m_RefPos ) )
{
2007-09-25 15:10:01 +00:00
Append( item );
2007-08-30 22:20:52 +00:00
goto exit;
}
}
}
2007-08-23 04:28:46 +00:00
}
2007-08-30 22:20:52 +00:00
}
2007-08-30 22:20:52 +00:00
if( m_Guide->IncludeSecondary() )
{
// for now, "secondary" means "tolerate any layer". It has
// no effect on other criteria, since there is a separate "ignore" control for
2007-08-30 22:20:52 +00:00
// those in the COLLECTORS_GUIDE
2007-08-30 22:20:52 +00:00
int layer = item->GetLayer();
// Modules and their subcomponents: text and pads are not sensitive to the layer
// visibility controls. They all have their own separate visibility controls
if( module || pad || m_Guide->IsLayerVisible( layer ) || !m_Guide->IgnoreNonVisibleLayers() )
2007-08-23 04:28:46 +00:00
{
if( !m_Guide->IsLayerLocked( layer ) || !m_Guide->IgnoreLockedLayers() )
2007-08-30 22:20:52 +00:00
{
if( !item->IsLocked() || !m_Guide->IgnoreLockedItems() )
{
if( item->HitTest( m_RefPos ) )
{
2007-09-25 15:10:01 +00:00
Append2nd( item );
2007-08-30 22:20:52 +00:00
goto exit;
}
}
}
2007-08-23 04:28:46 +00:00
}
}
2007-08-30 22:20:52 +00:00
exit:
return SEARCH_CONTINUE; // always when collecting
2007-08-23 04:28:46 +00:00
}
// see collectors.h
2007-09-11 04:16:31 +00:00
void GENERAL_COLLECTOR::Collect( BOARD_ITEM* aItem, const KICAD_T aScanList[],
const wxPoint& aRefPos, const COLLECTORS_GUIDE& aGuide )
2007-08-30 03:53:26 +00:00
{
Empty(); // empty the collection, primary criteria list
Empty2nd(); // empty the collection, secondary criteria list
2007-08-30 22:20:52 +00:00
// remember guide, pass it to Inspect()
2007-09-11 04:16:31 +00:00
SetGuide( &aGuide );
SetScanTypes( aScanList );
2007-08-30 22:20:52 +00:00
// remember where the snapshot was taken from and pass refPos to
// the Inspect() function.
2007-09-06 04:34:03 +00:00
SetRefPos( aRefPos );
2007-08-30 03:53:26 +00:00
2007-09-06 04:34:03 +00:00
// visit the board or module with the INSPECTOR (me).
2007-09-05 04:48:47 +00:00
aItem->Visit( this, // INSPECTOR* inspector
NULL, // const void* testData, not used here
m_ScanTypes );
2007-08-30 03:53:26 +00:00
SetTimeNow(); // when snapshot was taken
// record the length of the primary list before concatonating on to it.
m_PrimaryLength = m_List.size();
// append 2nd list onto end of the first list
for( unsigned i = 0; i<m_List2nd.size(); ++i )
2007-08-30 22:20:52 +00:00
Append( m_List2nd[i] );
2007-08-30 03:53:26 +00:00
Empty2nd();
}
// see collectors.h
SEARCH_RESULT TYPE_COLLECTOR::Inspect( EDA_ITEM* testItem, const void* testData )
{
2008-02-19 16:54:57 +00:00
// The Vist() function only visits the testItem if its type was in the
// the scanList, so therefore we can collect anything given to us here.
Append( testItem );
2008-02-19 16:54:57 +00:00
return SEARCH_CONTINUE; // always when collecting
}
void TYPE_COLLECTOR::Collect( BOARD_ITEM* aBoard, const KICAD_T aScanList[] )
{
Empty(); // empty any existing collection
2008-02-19 16:54:57 +00:00
// visit the board with the INSPECTOR (me).
aBoard->Visit( this, // INSPECTOR* inspector
2008-02-19 16:54:57 +00:00
NULL, // const void* testData,
aScanList );
}
2007-08-23 04:28:46 +00:00
//EOF