Loading change_log.txt +6 −0 Original line number Diff line number Diff line Loading @@ -5,6 +5,12 @@ Please add newer entries at the top, list the date and your name with email address. 2007-Aug-06 UPDATE Dick Hollenbeck <dick@softplc.com> ================================================================================ + pcbnew & common Started sketching out a new search architecture. To learn more: look for "INSPECTOR" text in base_struct.h. 2007-Aug-05 UPDATE Dick Hollenbeck <dick@softplc.com> ================================================================================ Loading common/base_struct.cpp +37 −1 Original line number Diff line number Diff line Loading @@ -224,10 +224,46 @@ void EDA_BaseStruct::Show( int nestLevel, std::ostream& os ) std::ostream& EDA_BaseStruct::NestedSpace( int nestLevel, std::ostream& os ) { for( int i=0; i<nestLevel; ++i ) os << ' '; // number of spaces here controls indent per nest level os << " "; // number of spaces here controls indent per nest level return os; } // see base_struct.h SEARCH_RESULT EDA_BaseStruct::IterateForward( EDA_BaseStruct* listStart, INSPECTOR* inspector, void* testData, const KICAD_T scanTypes[] ) { EDA_BaseStruct* p = listStart; for( ; p; p = p->Pnext ) { if( SEARCH_QUIT == p->Traverse( inspector, testData, scanTypes ) ) return SEARCH_QUIT; } return SEARCH_CONTINUE; } // see base_struct.h SEARCH_RESULT EDA_BaseStruct::Traverse( INSPECTOR* inspector, void* testData, const KICAD_T scanTypes[] ) { KICAD_T stype; for( const KICAD_T* p = scanTypes; (stype=*p) != EOT; ++p ) { // If caller wants to inspect my type if( stype == m_StructType ) { if( SEARCH_QUIT == inspector->Inspect( this, testData ) ) return SEARCH_QUIT; break; } } return SEARCH_CONTINUE; } #endif Loading include/base_struct.h +101 −0 Original line number Diff line number Diff line Loading @@ -13,6 +13,9 @@ /* Id for class identification, at run time */ enum DrawStructureType { EOT = 0, // search types array terminator (End Of Types) TYPE_NOT_INIT = 0, TYPEPCB, Loading Loading @@ -70,6 +73,49 @@ enum DrawStructureType { }; #if defined(DEBUG) // new searching technique incubator enum SEARCH_RESULT { SEARCH_QUIT, SEARCH_CONTINUE }; typedef DrawStructureType KICAD_T; // shorter name class EDA_BaseStruct; /** * Class INSPECTOR * is an abstract class that is used to inspect and possibly collect the * (search) results of Iterating over a list or tree of KICAD_T objects. * Extend from this class and implment the Inspect function and provide for * a way for the extension to collect the results of the search/scan data and * provide them to the caller. */ class INSPECTOR { public: virtual ~INSPECTOR() {} /** * Function Inspect * is the function type that can be passed to the Iterate function, * used primarily for searching, but not exclusively. * @param testData is arbitrary data needed by the inspector to determine * if the EDA_BaseStruct under test meets its match criteria. * @return SEARCH_RESULT - SEARCH_QUIT if the Iterator is to stop the scan, * else SCAN_CONTINUE; */ SEARCH_RESULT virtual Inspect( EDA_BaseStruct* testItem, void* testData ) = 0; // derived classes add more functions for collecting and subsequent // retrieval here. }; #endif /********************************************************************/ /* Classes de base: servent a deriver les classes reellement utiles */ /********************************************************************/ Loading Loading @@ -139,6 +185,7 @@ public: */ virtual void Show( int nestLevel, std::ostream& os ); /** * Function NestedSpace * outputs nested space for pretty indenting. Loading @@ -147,6 +194,60 @@ public: * @return std::ostream& - for continuation. **/ static std::ostream& NestedSpace( int nestLevel, std::ostream& os ); /** * Function IterateForward * walks through the object tree calling the testFunc on each object * type requested in structTypes. * * @param listStart The first in a list of EDA_BaseStructs to iterate over. * @param inspector Is an INSPECTOR to call on each object that is of one of * the requested itemTypes. * @param testData Is an aid to testFunc, and should be sufficient to * allow it to fully determine if an item meets the match criteria, but it * may also be used to collect output. * @param scanTypes Is a char array of KICAD_T that is EOT * terminated, and provides both the order and interest level of of * the types of objects to be iterated over. * @return SEARCH_RESULT - SEARCH_QUIT if the Iterator is to stop the scan, * else SCAN_CONTINUE; */ static SEARCH_RESULT IterateForward( EDA_BaseStruct* listStart, INSPECTOR* inspector, void* testData, const KICAD_T scanTypes[] ); /** * Function Traverse * should be re-implemented for each derrived class in order to handle * all the types given by its member data. Implementations should call * inspector->Inspect() on types in scanTypes[], and may use IterateForward() * to do so on lists of such data. * @param inspector An INSPECTOR instance to use in the inspection. * @param testData Arbitrary data used by the inspector. * @param scanTypes Which KICAD_T types are of interest and the order * is significant too, terminated by EOT. * @return SEARCH_RESULT - SEARCH_QUIT if the Iterator is to stop the scan, * else SCAN_CONTINUE; */ virtual SEARCH_RESULT Traverse( INSPECTOR* inspector, void* testData, const KICAD_T scanTypes[] ); /** * Function ListHas * scans the given array and detects if the given type t is present. * @param list An array of KICAD_T, terminated with EOT. * @param t A KICAD_T to check for. * @return bool - true if present, else false. */ static bool ListHas( const KICAD_T list[], KICAD_T t ) { for( const KICAD_T* p = list; *p != EOT; ++p ) if( *p == t ) return true; return false; } #endif }; Loading include/pcbstruct.h +10 −0 Original line number Diff line number Diff line Loading @@ -242,6 +242,16 @@ public: * @param os The ostream& to output to. */ virtual void Show( int nestLevel, std::ostream& os ); /** * Function FindModuleOrPad * searches for either a module or a pad, giving precedence to pads. * @param refPos The wxPoint to hit-test. * @return EDA_BaseStruct* - if a direct hit, else NULL. */ EDA_BaseStruct* FindModuleOrPad( const wxPoint& refPos ); #endif }; Loading pcbnew/class_board.cpp +58 −0 Original line number Diff line number Diff line Loading @@ -286,4 +286,62 @@ void BOARD::Show( int nestLevel, std::ostream& os ) NestedSpace( nestLevel, os ) << "</" << ReturnClassName().mb_str() << ">\n"; } class ModuleOrPad : public INSPECTOR { public: EDA_BaseStruct* found; ModuleOrPad() : found(0) { } SEARCH_RESULT Inspect( EDA_BaseStruct* testItem, void* testData ) { const wxPoint* refPos = (const wxPoint*) testData; if( testItem->m_StructType == TYPEMODULE ) { /* not finished if( testItem->HitTest( &refPos ) ) { found = testItem; return SEARCH_QUIT; } */ } else if( testItem->m_StructType == TYPEPAD ) { /* not finished if( testItem->HitTest( &refPos ) ) { found = testItem; return SEARCH_QUIT; } */ } return SEARCH_CONTINUE; } }; // see pcbstruct.h EDA_BaseStruct* BOARD::FindModuleOrPad( const wxPoint& refPos ) { ModuleOrPad inspector; static const KICAD_T scanTypes[] = { TYPEMODULE, TYPEPAD, EOT }; if( SEARCH_QUIT == IterateForward( m_Modules, &inspector, (void*) &refPos, scanTypes ) ) return inspector.found; return NULL; } #endif Loading
change_log.txt +6 −0 Original line number Diff line number Diff line Loading @@ -5,6 +5,12 @@ Please add newer entries at the top, list the date and your name with email address. 2007-Aug-06 UPDATE Dick Hollenbeck <dick@softplc.com> ================================================================================ + pcbnew & common Started sketching out a new search architecture. To learn more: look for "INSPECTOR" text in base_struct.h. 2007-Aug-05 UPDATE Dick Hollenbeck <dick@softplc.com> ================================================================================ Loading
common/base_struct.cpp +37 −1 Original line number Diff line number Diff line Loading @@ -224,10 +224,46 @@ void EDA_BaseStruct::Show( int nestLevel, std::ostream& os ) std::ostream& EDA_BaseStruct::NestedSpace( int nestLevel, std::ostream& os ) { for( int i=0; i<nestLevel; ++i ) os << ' '; // number of spaces here controls indent per nest level os << " "; // number of spaces here controls indent per nest level return os; } // see base_struct.h SEARCH_RESULT EDA_BaseStruct::IterateForward( EDA_BaseStruct* listStart, INSPECTOR* inspector, void* testData, const KICAD_T scanTypes[] ) { EDA_BaseStruct* p = listStart; for( ; p; p = p->Pnext ) { if( SEARCH_QUIT == p->Traverse( inspector, testData, scanTypes ) ) return SEARCH_QUIT; } return SEARCH_CONTINUE; } // see base_struct.h SEARCH_RESULT EDA_BaseStruct::Traverse( INSPECTOR* inspector, void* testData, const KICAD_T scanTypes[] ) { KICAD_T stype; for( const KICAD_T* p = scanTypes; (stype=*p) != EOT; ++p ) { // If caller wants to inspect my type if( stype == m_StructType ) { if( SEARCH_QUIT == inspector->Inspect( this, testData ) ) return SEARCH_QUIT; break; } } return SEARCH_CONTINUE; } #endif Loading
include/base_struct.h +101 −0 Original line number Diff line number Diff line Loading @@ -13,6 +13,9 @@ /* Id for class identification, at run time */ enum DrawStructureType { EOT = 0, // search types array terminator (End Of Types) TYPE_NOT_INIT = 0, TYPEPCB, Loading Loading @@ -70,6 +73,49 @@ enum DrawStructureType { }; #if defined(DEBUG) // new searching technique incubator enum SEARCH_RESULT { SEARCH_QUIT, SEARCH_CONTINUE }; typedef DrawStructureType KICAD_T; // shorter name class EDA_BaseStruct; /** * Class INSPECTOR * is an abstract class that is used to inspect and possibly collect the * (search) results of Iterating over a list or tree of KICAD_T objects. * Extend from this class and implment the Inspect function and provide for * a way for the extension to collect the results of the search/scan data and * provide them to the caller. */ class INSPECTOR { public: virtual ~INSPECTOR() {} /** * Function Inspect * is the function type that can be passed to the Iterate function, * used primarily for searching, but not exclusively. * @param testData is arbitrary data needed by the inspector to determine * if the EDA_BaseStruct under test meets its match criteria. * @return SEARCH_RESULT - SEARCH_QUIT if the Iterator is to stop the scan, * else SCAN_CONTINUE; */ SEARCH_RESULT virtual Inspect( EDA_BaseStruct* testItem, void* testData ) = 0; // derived classes add more functions for collecting and subsequent // retrieval here. }; #endif /********************************************************************/ /* Classes de base: servent a deriver les classes reellement utiles */ /********************************************************************/ Loading Loading @@ -139,6 +185,7 @@ public: */ virtual void Show( int nestLevel, std::ostream& os ); /** * Function NestedSpace * outputs nested space for pretty indenting. Loading @@ -147,6 +194,60 @@ public: * @return std::ostream& - for continuation. **/ static std::ostream& NestedSpace( int nestLevel, std::ostream& os ); /** * Function IterateForward * walks through the object tree calling the testFunc on each object * type requested in structTypes. * * @param listStart The first in a list of EDA_BaseStructs to iterate over. * @param inspector Is an INSPECTOR to call on each object that is of one of * the requested itemTypes. * @param testData Is an aid to testFunc, and should be sufficient to * allow it to fully determine if an item meets the match criteria, but it * may also be used to collect output. * @param scanTypes Is a char array of KICAD_T that is EOT * terminated, and provides both the order and interest level of of * the types of objects to be iterated over. * @return SEARCH_RESULT - SEARCH_QUIT if the Iterator is to stop the scan, * else SCAN_CONTINUE; */ static SEARCH_RESULT IterateForward( EDA_BaseStruct* listStart, INSPECTOR* inspector, void* testData, const KICAD_T scanTypes[] ); /** * Function Traverse * should be re-implemented for each derrived class in order to handle * all the types given by its member data. Implementations should call * inspector->Inspect() on types in scanTypes[], and may use IterateForward() * to do so on lists of such data. * @param inspector An INSPECTOR instance to use in the inspection. * @param testData Arbitrary data used by the inspector. * @param scanTypes Which KICAD_T types are of interest and the order * is significant too, terminated by EOT. * @return SEARCH_RESULT - SEARCH_QUIT if the Iterator is to stop the scan, * else SCAN_CONTINUE; */ virtual SEARCH_RESULT Traverse( INSPECTOR* inspector, void* testData, const KICAD_T scanTypes[] ); /** * Function ListHas * scans the given array and detects if the given type t is present. * @param list An array of KICAD_T, terminated with EOT. * @param t A KICAD_T to check for. * @return bool - true if present, else false. */ static bool ListHas( const KICAD_T list[], KICAD_T t ) { for( const KICAD_T* p = list; *p != EOT; ++p ) if( *p == t ) return true; return false; } #endif }; Loading
include/pcbstruct.h +10 −0 Original line number Diff line number Diff line Loading @@ -242,6 +242,16 @@ public: * @param os The ostream& to output to. */ virtual void Show( int nestLevel, std::ostream& os ); /** * Function FindModuleOrPad * searches for either a module or a pad, giving precedence to pads. * @param refPos The wxPoint to hit-test. * @return EDA_BaseStruct* - if a direct hit, else NULL. */ EDA_BaseStruct* FindModuleOrPad( const wxPoint& refPos ); #endif }; Loading
pcbnew/class_board.cpp +58 −0 Original line number Diff line number Diff line Loading @@ -286,4 +286,62 @@ void BOARD::Show( int nestLevel, std::ostream& os ) NestedSpace( nestLevel, os ) << "</" << ReturnClassName().mb_str() << ">\n"; } class ModuleOrPad : public INSPECTOR { public: EDA_BaseStruct* found; ModuleOrPad() : found(0) { } SEARCH_RESULT Inspect( EDA_BaseStruct* testItem, void* testData ) { const wxPoint* refPos = (const wxPoint*) testData; if( testItem->m_StructType == TYPEMODULE ) { /* not finished if( testItem->HitTest( &refPos ) ) { found = testItem; return SEARCH_QUIT; } */ } else if( testItem->m_StructType == TYPEPAD ) { /* not finished if( testItem->HitTest( &refPos ) ) { found = testItem; return SEARCH_QUIT; } */ } return SEARCH_CONTINUE; } }; // see pcbstruct.h EDA_BaseStruct* BOARD::FindModuleOrPad( const wxPoint& refPos ) { ModuleOrPad inspector; static const KICAD_T scanTypes[] = { TYPEMODULE, TYPEPAD, EOT }; if( SEARCH_QUIT == IterateForward( m_Modules, &inspector, (void*) &refPos, scanTypes ) ) return inspector.found; return NULL; } #endif