Dataset::Update

Description

Update an Origin C Dataset object from an Origin data set or vice-versa.

Syntax

void Update( BOOL bFromOrigin, int mode = -1 )

Parameters

bFromOrigin
[input] TRUE updates the Origin C Dataset object from the Origin data set, FALSE updates the Origin dataset from an Origin C Dataset object.
mode
[input]Dataset update mode, used only if bFromOrigin=FALSE. Supported values are
REDRAW_NONE, do not update
REDRAW_REALTIME_WKS, similar to REDRAW_REALTIME_SCOPE, but redraw the entire worksheet
REDRAW_REFRESH, do a simple refresh of the data
REDRAW_REALTIME_SCOPE, this is used to do realtime drawing for the entire range of data.
To see effect in plots, must set dataplots to animate mode

Return

Examples

EX1

///Update OC when Origin Changed.
// a Worksheet with at least 1 column must exist prior to execution
void Dataset_Update_ex1()
{
    Worksheet wks=Project.ActiveLayer();
    if (wks)
    {     
        Dataset    dsA(wks, 0);
        string strWksColname = dsA.GetName();
        dsA.SetSize(10);
        dsA=1;
        string strExecute = "set " + strWksColname + " -e 20;" + strWksColname + "=2;";
        LT_execute(strExecute); // Note Dataset size is not updated but Dataset values change in Local Variables windows of Debug mode 
        dsA.Update(TRUE); // Note Dataset dsA size is now updated in Local Variables windows of Debug mode
        ASSERT(dsA.GetSize()==20);
    }
}

EX2

///Update Origin when OC data changed.
// Assumes a worksheet with  2 columns
// This example shows how to update Origin from inside Origin C program before it returns
void Dataset_Update_ex2()
{
    Worksheet wks=Project.ActiveLayer();
    if (wks)
    {
        Dataset aa(wks, 0);
        string strWksColname = aa.GetName();
        // in case column is empty
        if(aa.GetSize()<1)
        {
            aa.SetSize(10);
            aa=0;
        }
        
        aa[0]+= 1;
        aa.Update(FALSE, REDRAW_REFRESH);
        MessageBox(GetWindow(),strWksColname + " increment 1, click OK to increment again");
        aa[0]+=1;
    }
}

EX3

// Demonstrate the usage of REDRAW_REALTIME_SCOPE and REDRAW_REALTIME_WKS
// Assumes:
//    1) Worksheet's first column is filled with row numbers
//    2) Worksheet's A(X) vs. B(Y) is plotted as line plot
//    3) The line plot is set to animate mode so that the effect is fully visualized
//       (set plot active and then execute LabTalk script command "set %C -an 1")
/// Realtime update Origin from OC
void Dataset_Update_ex3()
{
        int imax = 20;
        Worksheet wks=Project.ActiveLayer();
        if (wks)
        {                     
                Dataset aa(wks, 0);
                int    nMaxRows = 10;
                if ( aa.GetSize() < nMaxRows )
                {
                        aa.SetSize(nMaxRows);
                        aa=0;
                }
                
                int ic = 0;//current cell
                
                for ( int ii = 0; ii < imax; ii++ )
                {
                        for(int jj = 0; jj < nMaxRows; jj++)
                        aa[jj] = 1;
                        
                        aa[ic++] = 2;
                        if(ic >= nMaxRows)
                        ic = 0;
                        //aa.Update(FALSE, REDRAW_REALTIME_WKS);
                        aa.Update(FALSE, REDRAW_REALTIME_SCOPE);
                        LT_execute("sec -w 0.1;");// hard wait 
                }
        }
}

Remark

Update an Origin C Dataset object from an Origin data set or update an Origin data set from an Origin C Dataset object. The number of elements and memory allocated are primarily affected by this method.

See Also

vectorbase::Append, Matrix::Update

header to Include

origin.h