Changeset 1528 for trunk/src/objects/RpPlot.cc
- Timestamp:
- Jun 22, 2009 3:16:39 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/objects/RpPlot.cc
r1386 r1528 16 16 using namespace Rappture; 17 17 18 const char Plot::format[] = "RAPPTURE::PLOT::FORMAT"; 19 const char Plot::id[] = "RAPPTURE::PLOT::ID"; 20 const char Plot::xaxis[] = "RAPPTURE::PLOT::XAXIS"; 21 const char Plot::yaxis[] = "RAPPTURE::PLOT::YAXIS"; 18 const char Plot::format[] = "RAPPTURE::PLOT::FORMAT"; 19 const char Plot::id[] = "RAPPTURE::PLOT::ID"; 20 const char Plot::xaxis[] = "xaxis"; 21 const char Plot::yaxis[] = "yaxis"; 22 const char Plot::creator[] = "RAPPTURE::PLOT::CREATOR"; 23 24 /* 25 const char *Plot::creator[] = { 26 "plot", 27 "user" 28 }; 29 */ 22 30 23 31 Plot::Plot () 24 : Variable(),32 : Object (), 25 33 _curveList (NULL) 26 34 { … … 33 41 // copy constructor 34 42 Plot::Plot ( const Plot& o ) 35 : Variable(o)43 : Object(o) 36 44 { 37 45 _curveList = Rp_ChainCreate(); … … 48 56 Rp_ChainLink *l = Rp_ChainFirstLink(_curveList); 49 57 while (l != NULL) { 50 char *str = NULL;51 58 Curve * c = (Curve *) Rp_ChainGetValue(l); 52 53 str = (char *) c->propremove(Plot::format); 54 delete str; 55 56 str = (char *) c->propremove(Plot::id); 57 delete str; 58 59 c->propremove(Plot::format); 60 c->propremove(Plot::id); 59 61 delete c; 60 62 c = NULL; … … 89 91 } 90 92 93 Path cpath; 94 cpath.id(name); 95 c->path(cpath.path()); 96 91 97 // can't use "xaxis" kinda strings here have to allocate it forreal 92 c->axis( xaxis,"xdesc","xunits","xcale",x,nPts);93 c->axis( yaxis,"ydesc","yunits","ycale",y,nPts);94 c->propstr( format,fmt);95 c->propstr( id,name);98 c->axis(Plot::xaxis,"","","","",x,nPts); 99 c->axis(Plot::yaxis,"","","","",y,nPts); 100 c->propstr(Plot::format,fmt); 101 c->propstr(Plot::creator,"plot"); 96 102 97 103 if (_curveList == NULL) { … … 109 115 110 116 /**********************************************************************/ 117 // METHOD: add() 118 /// Add an xy curve to the object 119 /** 120 * Add an xy curve to the object. 121 * returns curve id 122 */ 123 124 Plot& 125 Plot::add( 126 Curve *c, 127 const char *name) 128 { 129 if (c == NULL) { 130 // raise memory error and exit 131 return *this; 132 } 133 134 c->propstr(Plot::id,name); 135 136 if (_curveList == NULL) { 137 _curveList = Rp_ChainCreate(); 138 if (_curveList == NULL) { 139 // raise error and exit 140 } 141 } 142 143 Rp_ChainAppend(_curveList,c); 144 145 return *this; 146 } 147 148 149 /**********************************************************************/ 111 150 // METHOD: count() 112 151 /// return number of curves in this object … … 143 182 } 144 183 return c; 184 } 185 186 /**********************************************************************/ 187 // METHOD: getNthCurve() 188 /// Return the Nth Curve object 189 /** 190 * Return the Nth Curve 191 */ 192 193 Curve * 194 Plot::getNthCurve(size_t n) const 195 { 196 Rp_ChainLink *l = NULL; 197 l = Rp_ChainGetNthLink(_curveList,n); 198 199 if (l == NULL) { 200 return NULL; 201 } 202 203 return (Curve *) Rp_ChainGetValue(l); 145 204 } 146 205 … … 163 222 while (l != NULL) { 164 223 Curve *c = (Curve *) Rp_ChainGetValue(l); 165 const char *cname = (const char *) c->property(id,NULL);224 const char *cname = c->propstr(Plot::id); 166 225 if (cname != NULL) { 167 226 if((*cname == *name) && (strcmp(cname,name) == 0)) { … … 191 250 } 192 251 252 /**********************************************************************/ 253 // METHOD: xml() 254 /// Return the xml of this object 255 /** 256 * returns the xml of this object 257 */ 258 259 const char * 260 Plot::xml() 261 { 262 263 Rp_ChainLink *l = NULL; 264 265 _tmpBuf.clear(); 266 267 l = Rp_ChainFirstLink(_curveList); 268 while (l != NULL) { 269 Curve *c = (Curve *) Rp_ChainGetValue(l); 270 271 //find who created the curve 272 const char *ccreator = c->propstr(Plot::creator); 273 if ((ccreator != NULL) && 274 (*ccreator == 'p') && 275 (strcmp(ccreator,"plot") == 0)) { 276 // FIXME: check fields to see if the user specified value 277 // plot defined curve, use plot's labels in curve's xml 278 const char *xlabel = propstr("xlabel"); 279 const char *xdesc = propstr("xdesc"); 280 const char *xunits = propstr("xunits"); 281 const char *xscale = propstr("xscale"); 282 const char *ylabel = propstr("ylabel"); 283 const char *ydesc = propstr("ydesc"); 284 const char *yunits = propstr("yunits"); 285 const char *yscale = propstr("yscale"); 286 287 if (xlabel || xdesc || xunits || xscale) { 288 Array1D *cxaxis = c->getAxis(Plot::xaxis); 289 cxaxis->label(xlabel); 290 cxaxis->desc(xdesc); 291 cxaxis->units(xunits); 292 cxaxis->scale(xscale); 293 } 294 295 if (ylabel || ydesc || yunits || yscale) { 296 Array1D *cyaxis = c->getAxis(Plot::yaxis); 297 cyaxis->label(ylabel); 298 cyaxis->desc(ydesc); 299 cyaxis->units(yunits); 300 cyaxis->scale(yscale); 301 } 302 } 303 304 _tmpBuf.append(c->xml()); 305 _tmpBuf.append("\n",1); 306 l = Rp_ChainNextLink(l); 307 } 308 309 // remove trailing newline 310 _tmpBuf.remove(1); 311 // append terminating null character 312 _tmpBuf.append("\0",1); 313 314 return _tmpBuf.bytes(); 315 } 316 317 /**********************************************************************/ 318 // METHOD: is() 319 /// what kind of object is this 320 /** 321 * return hex value telling what kind of object this is. 322 */ 323 324 const int 325 Plot::is() const 326 { 327 // return "plot" in hex 328 return 0x706C6F74; 329 } 330 193 331 // -------------------------------------------------------------------- //
Note: See TracChangeset
for help on using the changeset viewer.