AllAreModulesAndReturnSmallestIfSo()

This commit is contained in:
dickelbeck 2007-09-14 16:15:27 +00:00
parent bfa36f3142
commit df754ad508
3 changed files with 57 additions and 1 deletions

View File

@ -4,6 +4,14 @@ Started 2007-June-11
Please add newer entries at the top, list the date and your name with
email address.
2007-Sep-14 UPDATE Dick Hollenbeck <dick@softplc.com>
================================================================================
+ pcbnew
* controle.cpp, added Function AllAreModulesAndReturnSmallestIfSo() which is
called from PcbGeneralLocateAndDisplay()
2007-Sep-13 UPDATE Dick Hollenbeck <dick@softplc.com>
================================================================================
+ kicad

View File

@ -1,6 +1,6 @@
MAKEGTK = $(MAKE) -f makefile.gtk
KICAD_SUBDIRS = common 3d-viewer pcbnew eeschema eeschema/plugins cvpcb kicad gerbview
KICAD_SUBDIRS = common 3d-viewer pcbnew #eeschema eeschema/plugins cvpcb kicad gerbview
KICAD_SUBDIRS_BIN = eeschema eeschema/plugins pcbnew cvpcb kicad gerbview
KICAD_SUBDIRS_RES = internat modules template library
KICAD_SUBDIRS_HELP = help

View File

@ -286,6 +286,47 @@ const char** BOARD_ITEM::MenuIcon() const
}
/**
* Function AllAreModulesAndReturnSmallestIfSo
* tests that all items in the collection are MODULEs and if so, returns the
* smallest MODULE.
* @return BOARD_ITEM* - The smallest or NULL.
*/
static BOARD_ITEM* AllAreModulesAndReturnSmallestIfSo( GENERAL_COLLECTOR* aCollector )
{
int count = aCollector->GetCount();
for( int i=0; i<count; ++i )
{
if( (*aCollector)[i]->Type() != TYPEMODULE )
return NULL;
}
// all are modules, now find smallest MODULE
int minDim = 0x7FFFFFFF;
int minNdx = 0;
for( int i=0; i<count; ++i )
{
MODULE* module = (MODULE*) (*aCollector)[i];
int lx = module->m_BoundaryBox.GetWidth();
int ly = module->m_BoundaryBox.GetHeight();
int lmin = MIN( lx, ly );
if( lmin <= minDim )
{
minDim = lmin;
minNdx = i;
}
}
return (*aCollector)[minNdx];
}
/***********************************************************************/
BOARD_ITEM* WinEDA_BasePcbFrame::PcbGeneralLocateAndDisplay()
@ -355,6 +396,13 @@ BOARD_ITEM* WinEDA_BasePcbFrame::PcbGeneralLocateAndDisplay()
item = (*m_Collector)[0];
SetCurItem( item );
}
// if all are modules, find the smallest one amoung the primary choices
else if( (item = AllAreModulesAndReturnSmallestIfSo(m_Collector) ) != NULL )
{
SetCurItem( item );
}
else // show a popup menu
{
wxMenu itemMenu;