Skip to content

Commit

Permalink
update processing of text strings to allow all printable characters e…
Browse files Browse the repository at this point in the history
…xcept comma and doublequote
  • Loading branch information
HomerReid committed Jun 25, 2018
1 parent 8a1faa1 commit fe93c1d
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 7 deletions.
6 changes: 2 additions & 4 deletions lib/ReadGDSIIFile.cc
Original file line number Diff line number Diff line change
Expand Up @@ -529,13 +529,11 @@ double ConvertReal(BYTE *Bytes, DataType DType)
}


// The allowed characters are [a-zA-Z?$_].
// The allowed characters are all ASCII-printable characters, including space, except comma (,) and double quote (").
// Non-allowed characters at the end of the string are removed.
// Non-allowed characters not at the end of the string are converted to underscores.
bool IsAllowedChar(char c)
{ c=tolower(c);
return ('a' <= c && c <= 'z') || c=='$' || c=='_' || c=='?';
}
{ return isprint(c) && c!='"' && c!=','; }

string *MakeGDSIIString(char *Original, int Size)
{
Expand Down
26 changes: 25 additions & 1 deletion lib/libGDSII.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ GDSIIData::GDSIIData(const string FileName)
UnitInMeters = 1.0e-6;
FileUnits[0] = FileUnits[1]=0.0;
GDSIIFileName = new string(FileName);

ReadGDSIIFile(FileName);

// at this point ErrMsg is non-null if an error occurred
Expand Down Expand Up @@ -124,6 +123,26 @@ PolygonList GDSIIData::GetPolygons(const char *Text, int Layer)
PolygonList GDSIIData::GetPolygons(int Layer)
{ return GetPolygons(0,Layer); }

TextString NewTextString(Entity E, int Layer)
{ TextString TS;
TS.Text = E.Text;
TS.XY = dVec(E.XY);
TS.Layer = Layer;
return TS;
}

TextStringList GDSIIData::GetTextStrings(int Layer)
{
TextStringList TextStrings;
for(size_t nl=0; nl<Layers.size(); nl++)
{ if (Layer!=-1 && Layers[nl]!=Layer) continue;
for(size_t ne=0; ne<ETable[nl].size(); ne++)
if ( ETable[nl][ne].Text )
TextStrings.push_back( NewTextString( ETable[nl][ne], Layers[nl] ) );
}
return TextStrings;
}

/***************************************************************/
/* the next few routines implement a mechanism by which an API */
/* code can make multiple calls to GetPolygons() for a given */
Expand Down Expand Up @@ -157,6 +176,11 @@ PolygonList GetPolygons(const char *GDSIIFile, const char *Label, int Layer)
PolygonList GetPolygons(const char *GDSIIFile, int Layer)
{ return GetPolygons(GDSIIFile, 0, Layer); }

TextStringList GetTextStrings(const char *GDSIIFile, int Layer)
{ OpenGDSIIFile(GDSIIFile);
return CachedGDSIIData->GetTextStrings(Layer);
}

/***************************************************************/
/* find the value of s at which the line p+s*d intersects the */
/* line segment connecting v1 to v2 (in 2 dimensions) */
Expand Down
9 changes: 7 additions & 2 deletions lib/libGDSII.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ using namespace std;
/****************************************************************************************/
typedef vector<dVec> PolygonList;

typedef struct { char *Text; dVec XY; int Layer; } TextString;
typedef vector<TextString> TextStringList;

/***************************************************************/
/* Data structures used to process GDSII files: */
/* (a) GDSIIElement and GDSIIStruct are used to store info */
Expand Down Expand Up @@ -142,7 +145,8 @@ namespace libGDSII
// If Layer==-1, search all layers.
// If Text==NULL, return a list of all polygons on the given layer.
PolygonList GetPolygons(const char *Text, int Layer=-1);
PolygonList GetPolygons(int Layer);
PolygonList GetPolygons(int Layer=-1);
TextStringList GetTextStrings(int Layer=-1);

/*--------------------------------------------------------*/
/* API data fields */
Expand Down Expand Up @@ -201,7 +205,8 @@ bool PointInPolygon(dVec Vertices, double X, double Y);
/* to free memory allocated for the cache. */
/***********************************************************************/
PolygonList GetPolygons(const char *GDSIIFile, const char *Text, int Layer=-1);
PolygonList GetPolygons(const char *GDSIIFile, int Layer);
PolygonList GetPolygons(const char *GDSIIFile, int Layer=-1);
TextStringList GetTextStrings(const char *GDSIIFile, int Layer=-1);
void ClearGDSIICache();

/***************************************************************/
Expand Down

0 comments on commit fe93c1d

Please sign in to comment.