3.2 Open Graph Browser Dialog in X-Function

Summary

This example demonstrates how to add a button to open the Graph Browser dialog to pick a graph in the X-Function GetN dialog, and then how to customize the Graph Browser dialog by filter function.

You will learn

  1. How to add a button to open a Graph Browser in the X-Function dialog.
  2. How to customize the Graph Browser dialog by filter function.

Steps

The following three steps will show how to add a button in the X-Function dialog to open a Graph Browser dialog without the use of a filter function. This is the simplest process, and all settings in the Graph Browser dialog will be set to their defaults.

  1. Select Tools: X-Function Builder from the Origin menu. Create an X-Function GraphFilterTest as follows.
    XFProgramming Control Graph Browser.png
    Note the control string is ...Graph GraphBrowserFilter.
  2. Click Edit X-Function in the Code Builder toolbar, and type out_str(pages); in the main function, GraphFilterTest. Click the Compile button and then click Return to Dialog.
  3. Click the Save OXF File toolbar button to save. Run GraphFilterTest -d in the Command window, and when a dialog shows, click the ... button to choose a graph, then click OK to close the dialog. The name of the selected graph window will be printed in the Command window.
  4. If you do NOT want to customize the Graph Browser Dialog, then there is no need to go on; the following steps are all about customizing the Graph Browser dialog, for example, setting the default view mode to Tree view. Create a GraphFilter.c file and save it in <Origin installation folder>\OriginC\OriginLab. The source file should include the following code.
    #include <..\Originlab\GraphFilter.h> // this is an Origin built-in file
    int GraphBrowserFilter(int nMsg, Page& pg = NULL) 
    { 
    	switch(nMsg) 
    	{ 
    	case GBFM_IS_USE_PAGE: // return 1 for true. 
    		if(!pg) 
    			return -1; 
    		// filter page including multiple layers 
    		return pg.Layers.Count() > 1? 0 : 1; 
    		
    	case GBFM_SHOW_EMBED_PAGE_CHKBOX: 
    		// see other options in GraphFilter.h
    		return EMBED_CHECKBOX_ENABLE; 
    		
    	case GBFM_SHOW_SWITCH_MODE: 
    		// see other options in GraphFilter.h	
    		return VIEW_MODE_BOTH_WITH_TREE_DEFAULT; 
    		
    	case GBFM_SORT_PAGES:
    		return 1; // return 0 or 1
    	} 
    	return -1; // error 
    }
  5. Create a header file named MyGraphFilter.h and save it in <Origin installation folder>\OriginC\OriginLab.
  6. Open this X-Function in X-Function Builder, and click the Edit X-Function in Code Builder button, to include the newly created header file, from above. Note that MyGraphFilter.c and MyGraphFilter.h can also be put in another folder, but you have to make sure that they are in the same folder as each other. If they are in another folder, an absolute path should be used to include the header file, e.g.
    //Case 1. if header file is located in the OriginC\Originlab\ folder
    //put additional include files here
    #include <..\Originlab\MyGraphFilter.h> 
    
    //Case 2. if header file is NOT located in the OriginC\Originlab\ folder
    //put additional include files here
    #include "D:\MyFolder\MyGraphFilter.h"
  7. Run GraphFilterTest -d in the Command Window, and click the Browse button in the GraphFilterTest dialog. You can see that the Show Embedded Graph check box is enabled and selected, and the embedded graph is listed in the tree browser.
    XFProgramming Control Graph Browser2.png
  8. Open MyGraphFilter.c from <Origin installation folder>\OriginC\Originlab\ with the Code Builder. Change the return value from EMBED_CHECKBOX_ENABLE to EMBED_CHECKBOX_DISABLE_EMBEDDING_PAGE_NEVER_ENABLE for the GBFM_SHOW_EMBED_PAGE_CHKBOX case. Click the Compile button to compile MyGraphFilter.c. Then run GraphFilterTest -d in the Command Window again. The Show Embedded Graph check box is disabled and unchecked now, and the embedded graph is not listed in the tree browser.
    XFProgramming Control Graph Browser3.png
  9. You can try to use other enum values in <Origin installation folder>\OriginC\Originlab\GraphFilter.h as the return value for other cases in MyGraphFilter.c. Please remember to compile MyGraphFilter.c after each change.
  10. The built-in X-Functions containing Graph Browsers (e.g. Import and Export X-Function expGraph) can be customized using the same method.