From 4f956712e2a0d27cf1a47958373e750bd762c27c Mon Sep 17 00:00:00 2001 From: Dick Hollenbeck Date: Mon, 27 Dec 2010 10:49:39 -0600 Subject: [PATCH] fill out more /new files --- .bzrignore | 2 + CMakeLists.txt | 1 + CMakeModules/TokenList2DsnLexer.cmake | 12 +- common/CMakeLists.txt | 24 +-- eeschema/CMakeLists.txt | 51 ++---- eeschema/template_fieldnames.cpp | 1 + include/dsnlexer.h | 2 +- new/CMakeLists.txt | 19 ++- new/design.h | 218 -------------------------- new/make-dir-lib-source-test-data.sh | 23 +++ new/sch_dir_lib_source.cpp | 45 ++++-- new/sch_lib.h | 7 +- new/sch_lib_table.cpp | 31 ++++ new/sch_lib_table.h | 207 ++++++++++++++++++++++++ new/sch_lib_table.keywords | 5 + new/sch_part.cpp | 42 +++++ new/sch_part.h | 113 +++++++++++++ 17 files changed, 497 insertions(+), 306 deletions(-) create mode 100755 new/make-dir-lib-source-test-data.sh create mode 100644 new/sch_lib_table.cpp create mode 100644 new/sch_lib_table.h create mode 100644 new/sch_lib_table.keywords create mode 100644 new/sch_part.cpp create mode 100644 new/sch_part.h diff --git a/.bzrignore b/.bzrignore index 3bfbcf7455..42800d2f87 100644 --- a/.bzrignore +++ b/.bzrignore @@ -6,6 +6,8 @@ eeschema/cmp_library_keywords.* eeschema/template_fieldnames_keywords.* eeschema/template_fieldnames_lexer.h new/html +new/sch_lib_table_keywords.cpp +new/sch_lib_table_lexer.h pcbnew/dialogs/dialog_freeroute_exchange_help_html.h Makefile CMakeFiles diff --git a/CMakeLists.txt b/CMakeLists.txt index ab2990c16a..7c08d59b15 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -120,6 +120,7 @@ mark_as_advanced(KICAD_BIN KICAD_DEMOS KICAD_TEMPLATE) +include(Functions) #================================================ # Find libraries that are needed to build KiCad. diff --git a/CMakeModules/TokenList2DsnLexer.cmake b/CMakeModules/TokenList2DsnLexer.cmake index 5e464c1af6..2aa7508c7e 100644 --- a/CMakeModules/TokenList2DsnLexer.cmake +++ b/CMakeModules/TokenList2DsnLexer.cmake @@ -144,8 +144,8 @@ set( sourceFileHeader * your DSN lexer. */ -#include \"fctsys.h\" -#include \"macros.h\" +//#include \"fctsys.h\" +//#include \"macros.h\" #include \"${result}_lexer.h\" @@ -241,9 +241,9 @@ public: /** * Constructor ${RESULT}_LEXER * takes @a aFile already opened for reading and @a aFilename as parameters. - * The opened file is not closed by this class, and is assumed to be positioned - * at the beginning of the file for purposes of accurate line number reporting - * in error messages. + * The opened file is assumed to be positioned at the beginning of the file + * for purposes of accurate line number reporting in error messages. The + * FILE is closed by this instance when its destructor is called. * @param aFile is a FILE already opened for reading. * @param aFilename is the name of the opened file, needed for error reporting. */ @@ -333,7 +333,7 @@ class ${RESULT}_PARSER : public ${RESULT}_LEXER file( APPEND "${outCppFile}" "}; -const unsigned ${result}_keyword_count = DIM( ${result}_keywords ); +const unsigned ${result}_keyword_count = unsigned( sizeof( ${result}_keywords )/sizeof( ${result}_keywords[0] ) ); } // End namespace DSN " diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index d124949229..8137ca0851 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -105,25 +105,11 @@ set(PCB_COMMON_SRCS add_library(pcbcommon ${PCB_COMMON_SRCS}) # auto-generate netlist_lexer.h and netlist_keywords.cpp -set( inputFile ${CMAKE_CURRENT_SOURCE_DIR}/netlist.keywords ) -set( outHeaderFile ${PROJECT_SOURCE_DIR}/include/netlist_lexer.h ) -set( outCppFile ${CMAKE_CURRENT_SOURCE_DIR}/netlist_keywords.cpp ) -set( enum NL_T ) -add_custom_command( - OUTPUT ${outHeaderFile} - ${outCppFile} - COMMAND ${CMAKE_COMMAND} - -Denum=${enum} - -DinputFile=${inputFile} - -DoutHeaderFile=${outHeaderFile} - -DoutCppFile=${outCppFile} - -P ${CMAKE_MODULE_PATH}/TokenList2DsnLexer.cmake - DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/netlist.keywords - ${CMAKE_MODULE_PATH}/TokenList2DsnLexer.cmake - COMMENT "TokenList2DsnLexer.cmake creating: - ${outHeaderFile} and - ${outCppFile} from - ${inputFile}" +make_lexer( + ${CMAKE_CURRENT_SOURCE_DIR}/netlist.keywords + ${PROJECT_SOURCE_DIR}/include/netlist_lexer.h + ${CMAKE_CURRENT_SOURCE_DIR}/netlist_keywords.cpp + NL_T ) # The dsntest may not build properly using MS Visual Studio. diff --git a/eeschema/CMakeLists.txt b/eeschema/CMakeLists.txt index 9897ecd1db..b4c6fc7de0 100644 --- a/eeschema/CMakeLists.txt +++ b/eeschema/CMakeLists.txt @@ -170,47 +170,18 @@ endif(APPLE) # auto-generate cmp_library_lexer.h and cmp_library_keywords.cpp for the component # library format. -set( inputFile ${CMAKE_CURRENT_SOURCE_DIR}/cmp_library.keywords ) -set( outHeaderFile ${CMAKE_CURRENT_SOURCE_DIR}/cmp_library_lexer.h ) -set( outCppFile ${CMAKE_CURRENT_SOURCE_DIR}/cmp_library_keywords.cpp ) -set( enum TLIB_T ) -add_custom_command( - OUTPUT ${outHeaderFile} - ${outCppFile} - COMMAND ${CMAKE_COMMAND} - -Denum=${enum} - -DinputFile=${inputFile} - -DoutHeaderFile=${outHeaderFile} - -DoutCppFile=${outCppFile} - -P ${CMAKE_MODULE_PATH}/TokenList2DsnLexer.cmake - DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/cmp_library.keywords - ${CMAKE_MODULE_PATH}/TokenList2DsnLexer.cmake - COMMENT "TokenList2DsnLexer.cmake creating: - ${outHeaderFile} and - ${outCppFile} from - ${inputFile}" - ) +make_lexer( + ${CMAKE_CURRENT_SOURCE_DIR}/cmp_library.keywords + ${CMAKE_CURRENT_SOURCE_DIR}/cmp_library_lexer.h + ${CMAKE_CURRENT_SOURCE_DIR}/cmp_library_keywords.cpp + TLIB_T + ) - -set( inputFile ${CMAKE_CURRENT_SOURCE_DIR}/template_fieldnames.keywords ) -set( outHeaderFile ${CMAKE_CURRENT_SOURCE_DIR}/template_fieldnames_lexer.h ) -set( outCppFile ${CMAKE_CURRENT_SOURCE_DIR}/template_fieldnames_keywords.cpp ) -set( enum TFIELD_T ) -add_custom_command( - OUTPUT ${outHeaderFile} - ${outCppFile} - COMMAND ${CMAKE_COMMAND} - -Denum=${enum} - -DinputFile=${inputFile} - -DoutHeaderFile=${outHeaderFile} - -DoutCppFile=${outCppFile} - -P ${CMAKE_MODULE_PATH}/TokenList2DsnLexer.cmake - DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/cmp_library.keywords - ${CMAKE_MODULE_PATH}/TokenList2DsnLexer.cmake - COMMENT "TokenList2DsnLexer.cmake creating: - ${outHeaderFile} and - ${outCppFile} from - ${inputFile}" +make_lexer( + ${CMAKE_CURRENT_SOURCE_DIR}/template_fieldnames.keywords + ${CMAKE_CURRENT_SOURCE_DIR}/template_fieldnames_lexer.h + ${CMAKE_CURRENT_SOURCE_DIR}/template_fieldnames_keywords.cpp + TFIELD_T ) add_executable(eeschema WIN32 MACOSX_BUNDLE ${EESCHEMA_SRCS} ${EESCHEMA_EXTRA_SRCS} diff --git a/eeschema/template_fieldnames.cpp b/eeschema/template_fieldnames.cpp index 5463c46bf4..421495e11a 100644 --- a/eeschema/template_fieldnames.cpp +++ b/eeschema/template_fieldnames.cpp @@ -2,6 +2,7 @@ #include "template_fieldnames.h" #include "dsnlexer.h" +#include "fctsys.h" #include "macros.h" using namespace DSN; // enum TFIELD_T is in this namespace diff --git a/include/dsnlexer.h b/include/dsnlexer.h index 3a39d20113..457ec97d0f 100644 --- a/include/dsnlexer.h +++ b/include/dsnlexer.h @@ -29,7 +29,7 @@ #include #include -#include "fctsys.h" +//#include "fctsys.h" #include "richio.h" diff --git a/new/CMakeLists.txt b/new/CMakeLists.txt index 25cdfc5349..fe3ea262f9 100644 --- a/new/CMakeLists.txt +++ b/new/CMakeLists.txt @@ -40,6 +40,8 @@ if( STAND_ALONE ) set(CMAKE_CXX_FLAGS_DEBUG "-Wall -g3 -ggdb3 -DDEBUG") endif(CMAKE_COMPILER_IS_GNUCXX) + include(Functions) + endif() @@ -59,8 +61,19 @@ endif() include_directories( ${CMAKE_CURRENT_SOURCE_DIR} ) add_executable( test_dir_lib_source sch_dir_lib_source.cpp ) -#add_executable( test_dir_lib_source EXCLUDE_FROM_ALL sch_dir_lib_source.cpp ) - target_link_libraries( test_dir_lib_source ${wxWidgets_LIBRARIES} ) -#target_link_libraries( test_dir_lib_source common ${wxWidgets_LIBRARIES} ) + +add_executable( test_lib_table sch_lib_table.cpp sch_lib_table_keywords.cpp ) +target_link_libraries( test_lib_table ${wxWidgets_LIBRARIES} ) + +add_executable( test_sch_part sch_part.cpp ) +target_link_libraries( test_lib_table ${wxWidgets_LIBRARIES} ) + + +make_lexer( + ${CMAKE_CURRENT_SOURCE_DIR}/sch_lib_table.keywords + ${CMAKE_CURRENT_SOURCE_DIR}/sch_lib_table_lexer.h + ${CMAKE_CURRENT_SOURCE_DIR}/sch_lib_table_keywords.cpp + ELT_T + ) diff --git a/new/design.h b/new/design.h index e13d6038bb..b4bf5704a1 100644 --- a/new/design.h +++ b/new/design.h @@ -371,84 +371,6 @@ const STRING StrEmpty = ""; /** @} exception_types Exception Types */ -/** - * Class PART - * will have to be unified with what Wayne is doing. I want a separate copy - - * here until I can get the state management correct. Since a PART only lives - * within a cache called a LIB, its constructor is private (only a LIB - * can instantiate one), and it exists in various states of freshness and - * completeness relative to the LIB_SOURCE within the LIB. - */ -class PART -{ - /// LIB class has great license to modify what's in here, nobody else does. - /// Modification is done through the LIB so it can track the state of the - /// PART and take action as needed. Actually most of the modification will - /// be done by PARTS_LIST, a class derived from LIB. - friend class LIB; - - - /// a private constructor, only a LIB can instantiate a PART. - PART() {} - - -protected: // not likely to have C++ descendants, but protected none-the-less. - - bool parsed; ///< true if the body as been parsed already. - - LIB* owner; ///< which LIB am I a part of (pun if you want) - STRING extends; ///< LPID of base part - - STRING name; ///< example "passives/R", immutable. - - /// s-expression text for the part, initially empty, and read in as this part - /// actually becomes cached in RAM. - STRING body; - - // 3 separate lists for speed: - - /// A property list. - PROPERTIES properties; - - /// A drawing list for graphics - DRAWINGS drawings; - - /// A pin list - PINS pins; - - /// Alternate body forms. - ALTERNATES alternates; - - // lots of other stuff, like the mandatory properties. - - -public: - - /** - * Function Inherit - * is a specialized assignment function that copies a specific subset, enough - * to fulfill the requirements of the Sweet s-expression language. - */ - void Inherit( const PART& aBasePart ); - - - /** - * Function Owner - * returns the LIB* owner of this part. - */ - LIB Owner() { return owner; } - - /** - * Function Parse - * translates the \a body string into a binary form that is represented - * by the normal fields of this class. Parse is expected to call Inherit() - * if this part extends any other. - */ - void Parse( DSN_LEXER* aLexer ) throw( PARSE_EXCEPTION ); - -}; - /** * Class LPID (aka GUID) @@ -601,8 +523,6 @@ public: }; - - /** * Class SVN_LIB_SOURCE * implements a LIB_SOURCE in a subversion repository. @@ -651,56 +571,6 @@ protected: }; -/** - * Class LIBS - * houses a handful of functions that manage all the RAM resident LIBs, and - * provide for a global part lookup function, GetPart(), which can be the basis - * of a cross LIB hyperlink. - */ -class LIBS -{ -public: - - /** - * Function GetPart - * finds and loads a PART, and parses it. As long as the part is - * accessible in any LIB_SOURCE, opened or not opened, this function - * will find it and load it into its containing LIB, even if that means - * having to load a new LIB as given in the library table. - */ - static PART* GetPart( const LPID& aLogicalPartID ) throw( IO_ERROR ); - - /** - * Function GetLib - * is first a lookup function and then if needed, a factory function. - * If aLogicalLibraryName has been opened, then return the already opened - * LIB. If not, then instantiate the library and fill the initial - * library PARTs (unparsed) and categories, and add it to LIB::libraries - * for future reference. - */ - static LIB* GetLib( const STRING& aLogicalLibraryName ) throw( IO_ERROR ); - - /** - * Function GetOpenedLibNames - * returns the logical library names of LIBs that are already opened. - * @see LPID::GetLogicalLibraries() - */ - static STRINGS GetOpendedLogicalLibNames(); - - /** - * Function CloseLibrary - * closes an open library @a aLibrary and removes it from class LIBS. - */ - static void CloseLibrary( LIB* aLibrary ) throw( IO_ERROR ); - - -private: - - /// collection of LIBs, searchable by logical name. - static std::map< STRING, LIB* > libraries; // owns the LIBs. -}; - - /** * Class PARTS_LIST * is a LIB which resides in a SCHEMATIC, and it is a table model for a @@ -721,94 +591,6 @@ public: }; -/** - * Class LIB_TABLE_ROW - * holds a record identifying a LIB in the LIB_TABLE. - */ -class LIB_TABLE_ROW -{ - -protected: - - /** - * Function SetLogicalName - * changes the logical name of this library, useful for an editor. - */ - void SetLogicalName( const STRING& aLogicalName ); - - /** - * Function SetType - * changes the type represented by this record. - */ - void SetType( const STRING& aType ); - - /** - * Function SetFullURI - * changes the full URI for the library, useful from a library table editor. - */ - void SetFullURI( const STRING& aFullURI ); - - /** - * Function SetOptions - * changes the options string for this record, and is useful from - * the library table editor. - */ - void SetOptions( const STRING& aOptions ); - - -public: - - /** - * Function GetLogicalName - * returns the logical name of this library table entry. - */ - const STRING& GetLogicalName(); - - - /** - * Function GetType - * returns the type of LIB represented by this record. - */ - const STRING& GetType(); - - /** - * Function GetFullURI - * returns the full location specifying URI for the LIB. - */ - const STRING& GetFullURI(); - - /** - * Function GetOptions - * returns the options string, which may hold a password or anything else needed to - * instantiate the underlying LIB_SOURCE. - */ - const STRING& GetOptions(); -}; - -/** - * Class LIB_TABLE - * holds LIB_TABLE_ROW records, and can be searched in a very high speed way based on - * logical library name. - */ -class LIB_TABLE -{ -public: - - /** - * Constructor LIB_TABLE - * builds a library table from an s-expression form of the library table. - * @param aLibraryTable is an s-expression form of all the rows in a library - * table fragment. These rows take presedence over rows in @a aFallBackTable. - * @param aFallBackTable is another LIB_TABLE which is searched only when - * a record is not found in this table. - */ - LIB_TABLE( const STRING& aLibraryTable, LIB_TABLE* aFallBackTable = NULL ) - { - // s-expression is chosen so we can read a table fragment from either - // a schematic or a disk file, for schematic resident or - // personal table, respectively. - } -}; } // namespace SCH diff --git a/new/make-dir-lib-source-test-data.sh b/new/make-dir-lib-source-test-data.sh new file mode 100755 index 0000000000..54bd70bbea --- /dev/null +++ b/new/make-dir-lib-source-test-data.sh @@ -0,0 +1,23 @@ +#!/bin/sh + +BASEDIR=/tmp/eeschema-lib + +CATEGORIES="lions tigers kitties" + +PARTS="eyes ears feet" + +REVS="rev1 rev5 rev10" + + + +for C in ${CATEGORIES}; do + + mkdir -p $BASEDIR/$C + + for P in ${PARTS}; do + for R in ${REVS}; do + echo "#$R: (part $C/$P)" > $BASEDIR/$C/$P.part.$R + done + done +done + diff --git a/new/sch_dir_lib_source.cpp b/new/sch_dir_lib_source.cpp index 252555dc82..5f80269b69 100644 --- a/new/sch_dir_lib_source.cpp +++ b/new/sch_dir_lib_source.cpp @@ -62,6 +62,20 @@ using namespace SCH; #include using namespace std; +/// This file extension is an implementation detail specific to this LIB_SOURCE +/// implementation, and to a corresponding LIB_SINK. +/// Core EESCHEMA should never have to see this. +#define SWEET_EXT ".part" + + +/* __func__ is C99 prescribed, but just in case: +http://www.informit.com/guides/content.aspx?g=cplusplus&seqNum=338 +#if defined(__GNUG__) // The GNU C++ compiler defines this +#define FUNC_NAME(x) // nothing, GNU C++ defines __func__ just fine. +#else +#define FUNC_NAME(x) static const char __func__[] = #x; +#endif +*/ /** @@ -140,7 +154,7 @@ static const char* endsWithRev( const char* start, const char* tail, char separa { bool sawDigit = false; - while( tail>start && isdigit(*--tail) ) + while( tail > start && isdigit( *--tail ) ) { sawDigit = true; } @@ -202,6 +216,7 @@ bool BY_REV::operator() ( const STRING& s1, const STRING& s2 ) const int rnum1 = atoi( rev1+3 ); int rnum2 = atoi( rev2+3 ); + // higher numbered revs are "less" so that they bubble to top. return rnum1 > rnum2; } @@ -212,9 +227,9 @@ bool BY_REV::operator() ( const STRING& s1, const STRING& s2 ) const bool DIR_LIB_SOURCE::makePartName( STRING* aPartName, const char* aEntry, const STRING& aCategory ) { - const char* cp = strrstr( aEntry, ".part" ); + const char* cp = strrstr( aEntry, SWEET_EXT ); - // if base name is not empty, contains ".part", && cp is not NULL + // if base name is not empty, contains SWEET_EXT, && cp is not NULL if( cp > aEntry ) { const char* limit = cp + strlen( cp ); @@ -222,7 +237,7 @@ bool DIR_LIB_SOURCE::makePartName( STRING* aPartName, const char* aEntry, // If versioning, then must find a trailing "revN.." type of string. if( useVersioning ) { - const char* rev = endsWithRev( cp + sizeof(".part") - 1, limit, '.' ); + const char* rev = endsWithRev( cp + sizeof(SWEET_EXT) - 1, limit, '.' ); if( rev ) { if( aCategory.size() ) @@ -241,7 +256,7 @@ bool DIR_LIB_SOURCE::makePartName( STRING* aPartName, const char* aEntry, // so we don't even bother to try and load any other partfile down here. else { - // if file extension is exactly ".part", and no rev + // if file extension is exactly SWEET_EXT, and no rev if( cp==limit-5 ) { if( aCategory.size() ) @@ -272,13 +287,14 @@ STRING DIR_LIB_SOURCE::makeFileName( const STRING& aPartName ) { int basePartLen = rev - aPartName.c_str() - 1; // omit '/' separator fileName.append( aPartName, 0, basePartLen ); - fileName += ".part."; // add '.' separator before rev + fileName += SWEET_EXT; + fileName += '.'; fileName += rev; } else { fileName += aPartName; - fileName += ".part"; + fileName += SWEET_EXT; } return fileName; @@ -370,7 +386,7 @@ void DIR_LIB_SOURCE::GetCategoricalPartNames( STRINGS* aResults, const STRING& a partnames.end(); PN_ITER it = aCategory.size() ? - partnames.lower_bound( aCategory + "/" ) : + partnames.upper_bound( aCategory + "/" ) : partnames.begin(); aResults->clear(); @@ -408,7 +424,6 @@ void DIR_LIB_SOURCE::GetCategoricalPartNames( STRINGS* aResults, const STRING& a void DIR_LIB_SOURCE::ReadPart( STRING* aResult, const STRING& aPartName, const STRING& aRev ) throw( IO_ERROR ) { - STRING fileName; STRING partName = aPartName; // appended with aRev too if not empty const char* rev = endsWithRev( partName, '/' ); @@ -441,8 +456,9 @@ void DIR_LIB_SOURCE::ReadPart( STRING* aResult, const STRING& aPartName, const S { STRING search = partName + '/'; - // no rev on partName string. First the first, which should be - // the highnest numbered rev because of BY_REV compare method. + // There's no rev on partName string. Find the most recent rev, i.e. highest, + // which will be first because of the BY_REV compare method, which treats + // higher numbered revs as first. PN_ITER it = partnames.upper_bound( search ); // verify that this one that is greater than partName is a match and not @@ -582,9 +598,9 @@ int main( int argc, char** argv ) // initially, only the NAME_CACHE sweets and STRING categories are loaded: uut.Show(); - uut.GetCategoricalPartNames( &partnames, "Category" ); + uut.GetCategoricalPartNames( &partnames, "lions" ); - printf( "\nGetCategoricalPartNames( aCatagory = 'Category' ):\n" ); + printf( "\nGetCategoricalPartNames( aCatagory = 'lions' ):\n" ); for( STRINGS::const_iterator it = partnames.begin(); it!=partnames.end(); ++it ) { printf( " '%s'\n", it->c_str() ); @@ -592,7 +608,7 @@ int main( int argc, char** argv ) uut.ReadParts( &sweets, partnames ); - printf( "\nSweets for Category = 'Category' parts:\n" ); + printf( "\nSweets for Category = 'lions' parts:\n" ); pn = partnames.begin(); for( STRINGS::const_iterator it = sweets.begin(); it!=sweets.end(); ++it, ++pn ) { @@ -632,4 +648,3 @@ int main( int argc, char** argv ) } #endif - diff --git a/new/sch_lib.h b/new/sch_lib.h index 2002d62c0a..84157c4476 100644 --- a/new/sch_lib.h +++ b/new/sch_lib.h @@ -231,6 +231,8 @@ protected: // constructor is not public, called from LIBS only. { } +public: + ~LIB() { delete source; @@ -238,8 +240,6 @@ protected: // constructor is not public, called from LIBS only. } -public: - /** * Function HasSink * returns true if this library has write/save capability. Most LIBs @@ -348,5 +348,4 @@ protected: const STRING StrEmpty = ""; -#endif // SCH_LIB_H_ - +#endif // SCH_LIB_H_ diff --git a/new/sch_lib_table.cpp b/new/sch_lib_table.cpp new file mode 100644 index 0000000000..085814f9e9 --- /dev/null +++ b/new/sch_lib_table.cpp @@ -0,0 +1,31 @@ +/* + * This program source code file is part of KICAD, a free EDA CAD application. + * + * Copyright (C) 2010-2011 SoftPLC Corporation, Dick Hollenbeck + * Copyright (C) 2010 Kicad Developers, see change_log.txt for contributors. + * + * 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. + * + * 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. + * + * 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., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#include + + +int main( int argc, char** argv ) +{ + return 0; +} diff --git a/new/sch_lib_table.h b/new/sch_lib_table.h new file mode 100644 index 0000000000..80683ee669 --- /dev/null +++ b/new/sch_lib_table.h @@ -0,0 +1,207 @@ +/* + * This program source code file is part of KICAD, a free EDA CAD application. + * + * Copyright (C) 2010 SoftPLC Corporation, Dick Hollenbeck + * Copyright (C) 2010 Kicad Developers, see change_log.txt for contributors. + * + * 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. + * + * 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. + * + * 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., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#ifndef SCH_LIB_TABLE_H_ +#define SCH_LIB_TABLE_H_ + +#include +#include +#include + + +namespace SCH { + +class LIB_TABLE_LEXER; + + +/** + * Class LIB_TABLE + * holds LIB_TABLE::ROW records, and can be searched in a very high speed + * way based on logical library name. + * + * @author Dick Hollenbeck + */ +class LIB_TABLE +{ +public: + + /** + * Class ROW + * holds a record identifying a LIB in the LIB_TABLE. + */ + class ROW + { + public: + + bool operator<( const ROW& other ) const + { + return logicalName < other.logicalName; + } + + /** + * Function GetLogicalName + * returns the logical name of this library table entry. + */ + const STRING& GetLogicalName() const + { + return logicalName; + } + + /** + * Function GetType + * returns the type of LIB represented by this record. + */ + const STRING& GetType() const + { + return libType; + } + + /** + * Function GetFullURI + * returns the full location specifying URI for the LIB. + */ + const STRING& GetFullURI() const + { + return fullURI; + } + + /** + * Function GetOptions + * returns the options string, which may hold a password or anything else needed to + * instantiate the underlying LIB_SOURCE. + */ + const STRING& GetOptions() const + { + return options; + } + + ~ROW() + { + delete lib; + } + + protected: + + ROW() : + lib( 0 ) + {} + + /** + * Function SetLogicalName + * changes the logical name of this library, useful for an editor. + */ + void SetLogicalName( const STRING& aLogicalName ) + { + logicalName = aLogicalName; + } + + /** + * Function SetType + * changes the type represented by this record. + */ + void SetType( const STRING& aType ) + { + libType = aType; + } + + /** + * Function SetFullURI + * changes the full URI for the library, useful from a library table editor. + */ + void SetFullURI( const STRING& aFullURI ) + { + fullURI = aFullURI; + } + + /** + * Function SetOptions + * changes the options string for this record, and is useful from + * the library table editor. + */ + void SetOptions( const STRING& aOptions ) + { + options = aOptions; + } + + private: + STRING logicalName; + STRING libType; + STRING fullURI; + STRING options; + + LIB* lib; + }; + + + /** + * Constructor LIB_TABLE + * builds a library table from an s-expression form of the library table. + * @param aLibraryTable is an s-expression form of all the rows in a library + * table fragment. These rows take presedence over rows in @a aFallBackTable. + * @param aFallBackTable is another LIB_TABLE which is searched only when + * a record is not found in this table. + */ + LIB_TABLE( const STRING& aLibraryTable, LIB_TABLE* aFallBackTable = NULL ) + throw( PARSE_ERROR ) + { + // s-expression is chosen so we can read a table fragment from either + // a schematic or a disk file, for schematic resident or + // personal table, respectively. + } + + +protected: + /** + * Function Parse + * fills this object from information in the input stream \a aSpec, which + * is a DSN_LEXER customized for the grammar needed to describe instances of this object. + * The entire textual element spec is
+ * (lib_table (logical _yourfieldname_)(value _yourvalue_) visible)) + * + *
+     * (lib_table
+     *   (lib (logical "LOGICAL")(type "TYPE")(fullURI "FULL_URI")(options "OPTIONS"))
+     *   (lib (logical "LOGICAL")(type "TYPE")(fullURI "FULL_URI")(options "OPTIONS"))
+         (lib (logical "LOGICAL")(type "TYPE")(fullURI "FULL_URI")(options "OPTIONS"))
+     * 
+ * + * When this function is called, the input token stream given by \a aSpec + * is assumed to be positioned at the '^' in the following example, i.e. just after the + * identifying keyword and before the content specifying stuff.
+ * (lib_table ^ (....) ) + * + * @param aSpec is the input token stream of keywords and symbols. + */ + void Parse( LIB_TABLE_LEXER* aLexer ) throw( PARSE_ERROR ); + +private: + + typedef boost::ptr_set ROWS; + + ROWS rows; +}; + +} // namespace SCH + +#endif // SCH_LIB_TABLE_H_ diff --git a/new/sch_lib_table.keywords b/new/sch_lib_table.keywords new file mode 100644 index 0000000000..003abdebeb --- /dev/null +++ b/new/sch_lib_table.keywords @@ -0,0 +1,5 @@ +lib_table +logical +type +full_uri +options diff --git a/new/sch_part.cpp b/new/sch_part.cpp new file mode 100644 index 0000000000..9a93109811 --- /dev/null +++ b/new/sch_part.cpp @@ -0,0 +1,42 @@ +/* + * This program source code file is part of KICAD, a free EDA CAD application. + * + * Copyright (C) 2010 Kicad Developers, see change_log.txt for contributors. + * + * 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. + * + * 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. + * + * 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., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + + +#include "sch_part.h" + +using namespace SCH; + +void PART::Parse( LIB* aLexer ) throw( PARSE_ERROR ) +{ +} + + +#if 1 + +int main( int argc, char** argv ) +{ + return 0; +} + +#endif + diff --git a/new/sch_part.h b/new/sch_part.h new file mode 100644 index 0000000000..9c7c1b7630 --- /dev/null +++ b/new/sch_part.h @@ -0,0 +1,113 @@ +/* + * This program source code file is part of KICAD, a free EDA CAD application. + * + * Copyright (C) 2010 Kicad Developers, see change_log.txt for contributors. + * + * 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. + * + * 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. + * + * 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., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + + +#ifndef SCH_PART_H_ +#define SCH_PART_H_ + +#include + + +namespace SCH { + +/** + * Class PART + * will have to be unified with what Wayne is doing. I want a separate copy + + * here until I can get the state management correct. Since a PART only lives + * within a cache called a LIB, its constructor is private (only a LIB + * can instantiate one), and it exists in various states of freshness and + * completeness relative to the LIB_SOURCE within the LIB. + */ +class PART +{ + /// LIB class has great license to modify what's in here, nobody else does. + /// Modification is done through the LIB so it can track the state of the + /// PART and take action as needed. Actually most of the modification will + /// be done by PARTS_LIST, a class derived from LIB. + friend class LIB; + + + /// a private constructor, only a LIB can instantiate a PART. + PART() {} + + +protected: // not likely to have C++ descendants, but protected none-the-less. + + bool parsed; ///< true if the body as been parsed already. + + LIB* owner; ///< which LIB am I a part of (pun if you want) + STRING extends; ///< LPID of base part + + STRING name; ///< example "passives/R", immutable. + + /// s-expression text for the part, initially empty, and read in as this part + /// actually becomes cached in RAM. + STRING body; + + // 3 separate lists for speed: + + /// A property list. + //PROPERTIES properties; + + /// A drawing list for graphics + //DRAWINGS drawings; + + /// A pin list + //PINS pins; + + /// Alternate body forms. + //ALTERNATES alternates; + + // lots of other stuff, like the mandatory properties. + + +public: + + /** + * Function Inherit + * is a specialized assignment function that copies a specific subset, enough + * to fulfill the requirements of the Sweet s-expression language. + */ + void Inherit( const PART& aBasePart ); + + + /** + * Function Owner + * returns the LIB* owner of this part. + */ + LIB* Owner() { return owner; } + + /** + * Function Parse + * translates the \a body string into a binary form that is represented + * by the normal fields of this class. Parse is expected to call Inherit() + * if this part extends any other. + */ + void Parse( LIB* aLexer ) throw( PARSE_ERROR ); + +}; + +} // namespace PART + +#endif // SCH_PART_