diff --git a/vlsisapd/CMakeLists.txt b/vlsisapd/CMakeLists.txt new file mode 100644 index 00000000..9180b1bc --- /dev/null +++ b/vlsisapd/CMakeLists.txt @@ -0,0 +1,8 @@ +PROJECT(IO) + +CMAKE_MINIMUM_REQUIRED(VERSION 2.4.0) + +SET(CMAKE_MODULE_PATH "${IO_SOURCE_DIR}/cmake_modules/") + +ADD_SUBDIRECTORY(agds) +ADD_SUBDIRECTORY(cmake_modules) diff --git a/vlsisapd/agds/CMakeLists.txt b/vlsisapd/agds/CMakeLists.txt new file mode 100644 index 00000000..33c4228f --- /dev/null +++ b/vlsisapd/agds/CMakeLists.txt @@ -0,0 +1,9 @@ +INCLUDE_DIRECTORIES(${CHAMS_SOURCE_DIR}/agds) + +SET ( includes GdsLibrary.h GdsStructure.h GdsElement.h GdsRectangle.h ) +SET ( cpps GdsLibrary.cpp GdsStructure.cpp GdsRectangle.cpp ) + +ADD_LIBRARY(agds SHARED ${cpps}) +INSTALL(TARGETS agds DESTINATION /lib) + +INSTALL(FILES ${includes} DESTINATION /include/io/agds) diff --git a/vlsisapd/agds/GdSStructure.h b/vlsisapd/agds/GdSStructure.h new file mode 100644 index 00000000..85db0221 --- /dev/null +++ b/vlsisapd/agds/GdSStructure.h @@ -0,0 +1,29 @@ +#ifndef __GDS_STRUCTURE_H +#define __GDS_STRUCTURE_H + +#include +#include +#include +using namespace std; + +#include "GdsElement.h" + +namespace IO { +class GdsStructure { + public: + GdsStructure(string strName); + + bool addElement ( GdsElement* ); + bool write ( ofstream &file ); + + inline string getName(); + + private: + string _strName; + + vector _elements; +}; + +inline string GdsStructure::getName() { return _strName; }; +} +#endif diff --git a/vlsisapd/agds/GdsElement.h b/vlsisapd/agds/GdsElement.h new file mode 100644 index 00000000..fb355ef8 --- /dev/null +++ b/vlsisapd/agds/GdsElement.h @@ -0,0 +1,19 @@ +#ifndef __GDS_ELEMENT_H +#define __GDS_ELEMENT_H + +namespace IO { +class GdsElement { + protected: + inline GdsElement(int layer); + + public: + virtual bool write ( ofstream &file ) = 0; + + protected: + int _layer; +}; + +inline GdsElement::GdsElement(int layer) : _layer(layer) {} +} +#endif + diff --git a/vlsisapd/agds/GdsLibrary.cpp b/vlsisapd/agds/GdsLibrary.cpp new file mode 100644 index 00000000..b200f6e2 --- /dev/null +++ b/vlsisapd/agds/GdsLibrary.cpp @@ -0,0 +1,58 @@ +#include +#include +#include +using namespace std; + +#include "GdsLibrary.h" + +namespace IO { + +GdsLibrary::GdsLibrary(string libName) + : _libName(libName) + , _userUnits(0.00) + , _physUnits(0.00) {} + + +bool GdsLibrary::addStructure(GdsStructure* gdsStruct) { + if(gdsStruct) + _structs.push_back(gdsStruct); + else { + cerr << "[GDS DRIVE ERROR]: cannot hold GdsStructure: " << gdsStruct->getName() << endl; + return false; + } + return true; +} + +bool GdsLibrary::write(string filename) { + time_t curtime = time(0); + tm now = *localtime(&curtime); + char date[BUFSIZ]={0}; + const char format[]="%y-%m-%d %H:%M:%S"; + if (!strftime(date, sizeof(date)-1, format, &now)>0) + cerr << "[GDS DRIVE ERROR]: cannot build current date." << endl; + + ofstream file; + file.open(filename.c_str(), ios::out); + // Header + file << "HEADER 5;" << endl + << "BGNLIB;" << endl + << " LASTMOD {" << date << "};" << endl + << " LASTACC {" << date << "};" << endl + << "LIBNAME " << _libName << ".DB;" << endl + << "UNITS;" << endl + << " USERUNITS " << _userUnits << ";" << endl + << " PHYSUNITS " << _physUnits << ";" << endl + << endl; + + // For each Struct : write struct. + for ( vector::iterator it = _structs.begin() ; it < _structs.end() ; it++ ) { + (*it)->write(file); + } + + // Footer + file << "ENDLIB;" << endl; + + file.close(); + return true; +} +} // namespace diff --git a/vlsisapd/agds/GdsLibrary.h b/vlsisapd/agds/GdsLibrary.h new file mode 100644 index 00000000..1254c54e --- /dev/null +++ b/vlsisapd/agds/GdsLibrary.h @@ -0,0 +1,31 @@ +#ifndef __GDS_LIBRARY_H +#define __GDS_LIBRARY_H + +#include +using namespace std; + +#include "GdsStructure.h" + +namespace IO { +class GdsLibrary { + public: + GdsLibrary(string libName); + + inline void setUserUnits ( double userUnits ); + inline void setPhysUnits ( double physUnits ); + + bool addStructure ( GdsStructure* ); + bool write ( string fileName ); + + private: + string _libName; + double _userUnits; + double _physUnits; + + vector _structs; +}; + +inline void GdsLibrary::setUserUnits(double userUnits) { _userUnits = userUnits; }; +inline void GdsLibrary::setPhysUnits(double physUnits) { _physUnits = physUnits; }; +} // namespace +#endif diff --git a/vlsisapd/agds/GdsRectangle.cpp b/vlsisapd/agds/GdsRectangle.cpp new file mode 100644 index 00000000..4b82a3ee --- /dev/null +++ b/vlsisapd/agds/GdsRectangle.cpp @@ -0,0 +1,30 @@ +#include +#include +using namespace std; + +#include "GdsRectangle.h" + +namespace IO { +GdsRectangle::GdsRectangle(int layer, double xmin, double ymin, double xmax, double ymax) + : GdsElement(layer) + , _xmin(xmin) + , _ymin(ymin) + , _xmax(xmax) + , _ymax(ymax) {} + +bool GdsRectangle::write(ofstream &file) { + file << "BOUNDARY;" << endl + << "LAYER " << _layer << ";" << endl + << "DATATYPE 0;" << endl + << "XY 5;" << endl + << " X: " << _xmin << ";\tY: " << _ymin << ";" << endl + << " X: " << _xmin << ";\tY: " << _ymax << ";" << endl + << " X: " << _xmax << ";\tY: " << _ymax << ";" << endl + << " X: " << _xmax << ";\tY: " << _ymin << ";" << endl + << " X: " << _xmin << ";\tY: " << _ymin << ";" << endl + << "ENDEL;" << endl + << endl; + + return true; +} +} diff --git a/vlsisapd/agds/GdsRectangle.h b/vlsisapd/agds/GdsRectangle.h new file mode 100644 index 00000000..2c9a190e --- /dev/null +++ b/vlsisapd/agds/GdsRectangle.h @@ -0,0 +1,23 @@ +#ifndef __GDS_RECTANGLE_H +#define __GDS_RECTANGLE_H + +#include + +#include "GdsElement.h" + +namespace IO { +class GdsRectangle : public GdsElement { + public: + GdsRectangle(int layer, double xmin, double ymin, double xmax, double ymax); + + virtual bool write ( ofstream &file ); + + private: + double _xmin; + double _ymin; + double _xmax; + double _ymax; +}; +} +#endif + diff --git a/vlsisapd/agds/GdsStructure.cpp b/vlsisapd/agds/GdsStructure.cpp new file mode 100644 index 00000000..ad287420 --- /dev/null +++ b/vlsisapd/agds/GdsStructure.cpp @@ -0,0 +1,47 @@ +#include +#include +using namespace std; + +#include "GdsStructure.h" + +namespace IO { +GdsStructure::GdsStructure(string strName) + : _strName(strName) {} + + +bool GdsStructure::addElement(GdsElement* gdsElement) { + if(gdsElement) + _elements.push_back(gdsElement); + else { + cerr << "[GDS DRIVE ERROR]: cannot hold GdsElement." << endl; + return false; + } + return true; +} + +bool GdsStructure::write(ofstream &file) { + time_t curtime = time(0); + tm now = *localtime(&curtime); + char date[BUFSIZ]={0}; + const char format[]="%y-%m-%d %H:%M:%S"; + if (!strftime(date, sizeof(date)-1, format, &now)>0) + cerr << "[GDS DRIVE ERROR]: cannot build current date." << endl; + + // Header + file << "BGNSTR;" << endl + << " CREATION {" << date << "};" << endl + << " LASTMOD {" << date << "};" << endl + << "STRNAME " << _strName << ";" << endl + << endl; + + // For each Element : write element. + for ( vector::iterator it = _elements.begin() ; it < _elements.end() ; it++ ) { + (*it)->write(file); + } + + // Footer + file << "ENDSTR;" << endl; + + return true; +} +} // namespace diff --git a/vlsisapd/cmake_modules/CMakeLists.txt b/vlsisapd/cmake_modules/CMakeLists.txt new file mode 100644 index 00000000..9257ab4c --- /dev/null +++ b/vlsisapd/cmake_modules/CMakeLists.txt @@ -0,0 +1,2 @@ +install(FILES FindIO.cmake + DESTINATION /share/cmake_modules) diff --git a/vlsisapd/cmake_modules/FindIO.cmake b/vlsisapd/cmake_modules/FindIO.cmake new file mode 100644 index 00000000..349b4276 --- /dev/null +++ b/vlsisapd/cmake_modules/FindIO.cmake @@ -0,0 +1,44 @@ +# - Try to find the IO libraries +# Once done this will define +# +# IO_FOUND - system has the IO library +# IO_INCLUDE_DIR - the IO include directory +# IO_LIBRARIES - The libraries needed to use IO + +SET(IO_DIR_SEARCH $ENV{IO_TOP}) + +FIND_PATH(IO_INCLUDE_DIR + NAMES io/agds/GdsLibrary.h + PATHS ${IO_DIR_SEARCH} + PATH_SUFFIXES include +) + +FIND_LIBRARY(IO_AGDS_LIBRARY + NAMES agds + PATHS ${IO_DIR_SEARCH} + PATH_SUFFIXES lib +) + + +IF(IO_INCLUDE_DIR AND IO_AGDS_LIBRARY) + SET(IO_FOUND TRUE) + SET(IO_LIBRARIES ${IO_AGDS_LIBRARY}) +ELSE(IO_INCLUDE_DIR AND IO_AGDS_LIBRARY) + SET(IO_FOUND FALSE) + SET(IO_LIBRARIES) +ENDIF(IO_INCLUDE_DIR AND IO_AGDS_LIBRARY) + +IF (NOT IO_FOUND) + SET(IO_MESSAGE + "IO library was not found. Make sure IO_TOP env variable is set.") + IF (NOT IO_FIND_QUIETLY) + MESSAGE(STATUS "${IO_MESSAGE}") + ELSE(NOT IO_FIND_QUIETLY) + IF(IO_FIND_REQUIRED) + MESSAGE(FATAL_ERROR "${IO_MESSAGE}") + ENDIF(IO_FIND_REQUIRED) + ENDIF(NOT IO_FIND_QUIETLY) +ELSE (NOT IO_FOUND) + MESSAGE(STATUS "IO library was found in ${IO_DIR_SEARCH}") +ENDIF (NOT IO_FOUND) +