Accessing X-Function GetN Tree

 

Version Info

Minimum Origin Version Required: Origin 8 SR5

Access MDF X-Function GetN Tree(Origin80 SR0)

We may want to write Origin C codes to access X-Function GUI tree. The following function is an example to access impMDF X-Function GUI tree to check/uncheck some checkboxes and then import file.

Different X-Function the struct of trGetN will be different. So before update trGetN, you need to set a break point at InvokeBeforeExecute function, after running this function to see the struct of trGetN in Local Variables window.

#include <XFBase.h>

void AccessImpMDF()
{
        XFBase xf;
        string strXFName = "impMDF";
        xf.Load(strXFName, LTXF_USE_FAST_ACCESS);
        
        Tree tr;
        TreeNode trGetN;        
        xf.GetGUI(tr, trGetN); // get GUI tree of xfunction
        
        // set file name to GUI tree
        trGetN.fname.strVal = GetAppPath(true) + "Samples\\Import and Export\\ETAS INCA MDF\\ZZP164_CPSSW_3_MS_0_SREC_0_shot43_20060227_151554.dat";
        
        // read data selection information from import file to GUI tree, after running, trGetN.trfiles.file1.DataSelection node will not be empty.
        xf.InvokeBeforeExecute(trGetN, 0);  
        
        TreeNode trDataSelection = trGetN.trfiles.file1.DataSelection;
        if( !trDataSelection )
                return;    //err     
        
        // DataSelection treenode contains many hidden node and will disappear on GUI, this count is the number of checkbox that appear on GUI.
        int nCount = tree_count_items_by_attribute(trDataSelection, STR_SHOW_ATTRIB, "1"); //returns count ignored hidden node 
        if( nCount == 0 )
                return; //err
        
        vector vCheck(nCount);
        vCheck = 0; // set all items to 0 to uncheck    
        // the following index 0, 2, 3 are the index of checkbox on GUI, set these checkboxes to 1
        vCheck[0] = 1;
        vCheck[2] = 1;
        vCheck[3] = 1;
        
        //specify Data Selection checkboxes by vector
        int index=0;
        foreach(TreeNode trNode in trDataSelection.Children)
        {
                if( trNode.Show )//ignore hidden node
                        trNode.nVal = vCheck[index++];         
        }
        
        xf.SetGUI(trGetN); // set changed GUI tree back to xf
        
        xf.Evaluate();
}

Access NetCDF X-Function GetN Tree(Origin80 SR0)

NOTE:

  • We assume that there is a NetCDF file, madis-profiler.nc, in Origin sample folder. There are 3 dimensionality, 1D, 2D, 3D, in this file.
#include <XFBase.h>
 
void AccessImpNetCDF()
{
    XFBase xf;
    string strXFName = "impNetCDF";
    xf.Load(strXFName, LTXF_USE_FAST_ACCESS);
    
    Tree tr;
    TreeNode trGetN;    
    xf.GetGUI(tr, trGetN); // get GUI tree of xfunction
    
    // set file name to GUI tree
    trGetN.fname.strVal = GetAppPath(true) + "Samples\\Import and Export\\madis-profiler.nc";
    
    // read data selection information from import file to GUI tree, after running, trGetN.trfiles.file1.DataSelection node will not be empty.
    xf.InvokeBeforeExecute(trGetN, 0);  
    
    TreeNode trDataSelection = trGetN.trfiles.file1.DataSelection;
    if( !trDataSelection )
        return; //err   
    
    // only import following variables
    // 1D : lastRecord, invTime
    // 2D : staName, ICT
    // 3D : consensusNumBeam, radVelocity
        TreeNode trVar1D = trDataSelection.Var1D;
        if ( trVar1D )
        {
                uncheck_all_children(trVar1D);
                trVar1D.lastRecord.nVal = 1;
                trVar1D.invTime.nVal = 1;
                
    }
    TreeNode trVar2D = trDataSelection.Var2D;
    if ( trVar2D )
    {
                uncheck_all_children(trVar2D);
                trVar2D.staName.nVal = 1;
        trVar2D.ICT.nVal = 1;
        
    }
    TreeNode trVar3D = trDataSelection.Var3D;
    if ( trVar3D )
    {
                uncheck_all_children(trVar3D);
        trVar3D.consensusNumBeam.nVal = 1;
        trVar3D.radVelocity.nVal = 1;
    }
   
    xf.SetGUI(trGetN); // set changed GUI tree back to xf
    
    xf.Evaluate();
}

void uncheck_all_children(TreeNode& trBranch)
{
        foreach(TreeNode trNode in trBranch.Children)
        {
                trNode.nVal = 0;
        }
}