Ignore:
Timestamp:
Jun 22, 2009 3:16:39 PM (15 years ago)
Author:
dkearney
Message:

updating the objects code and adding some more examples describing how i want developers to use the objects. some of the objects don't work yet, like the tree, anything with an example should work

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/objects/RpPlot.cc

    r1386 r1528  
    1616using namespace Rappture;
    1717
    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";
     18const char Plot::format[]  = "RAPPTURE::PLOT::FORMAT";
     19const char Plot::id[]      = "RAPPTURE::PLOT::ID";
     20const char Plot::xaxis[]   = "xaxis";
     21const char Plot::yaxis[]   = "yaxis";
     22const char Plot::creator[] = "RAPPTURE::PLOT::CREATOR";
     23
     24/*
     25const char *Plot::creator[] = {
     26    "plot",
     27    "user"
     28};
     29*/
    2230
    2331Plot::Plot ()
    24     :   Variable    (),
     32    :   Object    (),
    2533        _curveList  (NULL)
    2634{
     
    3341// copy constructor
    3442Plot::Plot ( const Plot& o )
    35     :   Variable(o)
     43    :   Object(o)
    3644{
    3745    _curveList = Rp_ChainCreate();
     
    4856    Rp_ChainLink *l = Rp_ChainFirstLink(_curveList);
    4957    while (l != NULL) {
    50         char *str = NULL;
    5158        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);
    5961        delete c;
    6062        c = NULL;
     
    8991    }
    9092
     93    Path cpath;
     94    cpath.id(name);
     95    c->path(cpath.path());
     96
    9197    // 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");
    96102
    97103    if (_curveList == NULL) {
     
    109115
    110116/**********************************************************************/
     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
     124Plot&
     125Plot::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/**********************************************************************/
    111150// METHOD: count()
    112151/// return number of curves in this object
     
    143182    }
    144183    return c;
     184}
     185
     186/**********************************************************************/
     187// METHOD: getNthCurve()
     188/// Return the Nth Curve object
     189/**
     190 * Return the Nth Curve
     191 */
     192
     193Curve *
     194Plot::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);
    145204}
    146205
     
    163222    while (l != NULL) {
    164223        Curve *c = (Curve *) Rp_ChainGetValue(l);
    165         const char *cname = (const char *) c->property(id,NULL);
     224        const char *cname = c->propstr(Plot::id);
    166225        if (cname != NULL) {
    167226            if((*cname == *name) && (strcmp(cname,name) == 0)) {
     
    191250}
    192251
     252/**********************************************************************/
     253// METHOD: xml()
     254/// Return the xml of this object
     255/**
     256 * returns the xml of this object
     257 */
     258
     259const char *
     260Plot::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
     324const int
     325Plot::is() const
     326{
     327    // return "plot" in hex
     328    return 0x706C6F74;
     329}
     330
    193331// -------------------------------------------------------------------- //
Note: See TracChangeset for help on using the changeset viewer.