// program to read in a GRS (short for 'gross' : my homegrown primitive // file format for polyline drawings ), and draw the polylines in a window // Sandy Hill, September, 1997 - revised Sept. 22, 1998 #include #include #include #include #include #include #include //###################### CLASSES ################### //$$$$$$ Point $$$$$$$ class Point{ public: float x, y; void set(float xx, float yy){x=xx; y=yy;} }; //$$$$$$ Rect $$$$$$ class Rect{ public: float left, top, right, bott; void set(float ll, float tt, float rr, float bb){left = ll; top = tt; right = rr; bott = bb;} }; //$$$$$$ PolyPoint $$$$$$ class PolyPoint{ public: int num; Point* pt; }; //$$$$$$ PolyPointArray $$$$$$ class PolyPointArray{ public: Rect window; int numPolys; PolyPoint* poly; void readGRS(char* fname); void draw(); void print(); }; //<<<<<<<<<<<<<<<<<<<<<<< PolyPointArray::draw >>>>>>>>>>>>>>>>>>> void PolyPointArray::draw() { for(int j = 0; j >>>>>>>>>>>>>>>>>>>>>>>> void PolyPointArray::readGRS(char* fname) { fstream inStream; inStream.open(fname, ios ::in); if(inStream.fail()) { cout << "can't open it!"; return;} while(1) / infinite loop - with a break { char buff[80]; if(!inStream.getline(buff,80)) // at end of file prematurely { cout << "at end of file, with no *** terminator!\n";exit(0);} if(buff[0] == '*') break; // detect end of comment block } inStream >> window.left >> window.top >> window.right >> window.bott; inStream >> numPolys; poly = new PolyPoint[numPolys]; // make array of PolyPoints for(int j = 0; j < numPolys; j++) { int numThisPoly; inStream >> numThisPoly; poly[j].num = numThisPoly; poly[j].pt = new Point[numThisPoly]; for (int i = 0; i < numThisPoly; i++) inStream >> poly[j].pt[i].x >> poly[j].pt[i].y; } inStream.close(); }