X-Functions support wizard dialogs. To create a wizard dialog, you need n+1 X-Functions, where n is the number of wizard pages. One is the main X-Function. The main X-Function is used to construct wizard pages and then open the wizard dialog if script mode is off, or run without dialog when script mode is on.
The following shows how to create a two page wizard. Page 1 is used to select an XY range, and to specify the sub x range of the selected data range. Page 2 is used to add a rectangle with the specified fill color onto the source graph. The left x and right x of this rectangle are equal to the values of x from/to in Page 1.
#ifndef __WIZ_DLG_H__ #define __WIZ_DLG_H__ #include <..\OriginLab\XFWiz.h> #include <..\OriginLab\XFCore.h> #include <..\OriginLab\WizOperation.h> #include <..\OriginLab\XFWizNavigation.h> #include <..\OriginLab\XFWizManager.h> #include <..\OriginLab\XFWizScript.h> #include <..\OriginLab\XFWizDlg.h> #include <..\OriginLab\XFWizard_utils.h> /////////////////////////////////////////////////////////////////////////// class WizDlgCore : public XFCore { public: WizDlgCore() { } void SetXRange(double from, double to) { m_dFrom = from; m_dTo = to; } void GetXRange(double& from, double& to) { from = m_dFrom; to = m_dTo; } private: double m_dFrom; double m_dTo; }; /////////////////////////////////////////////////////////////////////////// class WizDlgTheme : public XFWizTheme { }; /////////////////////////////////////////////////////////////////////////// class WizDlgInputOutputRange : public XFWizInputOutputRange { }; /////////////////////////////////////////////////////////////////////////// class WizDlgManager : public XFWizManager { public: WizDlgManager(LPCSTR lpcszThemeName = NULL, const XFWizTheme *pXFWizTheme = NULL, const XFWizInputOutputRange *pXFWizIO = NULL, DWORD dwUIDOp = 0); protected: virtual XFCore* CreateXFCore() { return new WizDlgCore; } virtual XFWizTheme* CreateXFWizTheme() { return new WizDlgTheme; } virtual XFWizInputOutputRange* CreateXFWizInputOutputRange() { return new WizDlgInputOutputRange; } virtual string GetClassName() { return "WizDlgExample"; } }; #define STR_XFNAME_PAGE_1 "wizPage1" #define STR_XFNAME_PAGE_2 "wizPage2" #define STR_LABEL_XFNAME_PAGE_1 "Page 1" #define STR_LABEL_XFNAME_PAGE_2 "Page 2" WizDlgManager::WizDlgManager(LPCSTR lpcszThemeName, const XFWizTheme *pXFWizTheme, const XFWizInputOutputRange *pXFWizIO, DWORD dwUIDOp) // = NULL, NULL, NULL, 0 : XFWizManager(lpcszThemeName, pXFWizTheme, pXFWizIO, dwUIDOp) { StringArray saMapXFNames = {STR_XFNAME_PAGE_1, STR_XFNAME_PAGE_2}; StringArray saMapXFLabels = {STR_LABEL_XFNAME_PAGE_1, STR_LABEL_XFNAME_PAGE_2}; m_saMapXFNames = saMapXFNames; m_saMapXFLabels = saMapXFLabels; ASSERT( m_saMapXFNames.GetSize() == m_saMapXFLabels.GetSize() ); m_saDefaultXFNames = saMapXFNames; } /////////////////////////////////////////////////////////////////////////// int run_wiz_nodlg(LPCSTR lpcszThemeName = NULL, const XFWizTheme *pXFWizTheme = NULL, const XFWizInputOutputRange *pXFWizIO = NULL, DWORD dwOPUID = 0) { TEMPLATE_run_wiz_nodlg(WizDlgManager, lpcszThemeName, pXFWizTheme, pXFWizIO, dwOPUID) } int open_wiz_dlg(LPCSTR lpcszThemeName = NULL, const XFWizTheme *pXFWizTheme = NULL, const XFWizInputOutputRange *pXFWizIO = NULL, DWORD dwOPUID = 0) { TEMPLATE_open_wiz_dlg(WizDlgManager, lpcszThemeName, pXFWizTheme, pXFWizIO, dwOPUID) } #endif //__WIZ_DLG_H__
#include <..\OriginLab\XFWiz.h> #include <event_utils.h> #include <..\OriginLab\WksOperation.h> #include <..\OriginLab\WizOperation.h> #include <..\OriginLab\XFCore.h> #include <..\OriginLab\XFWizNavigation.h> #include <..\OriginLab\XFWizManager.h> #include <..\OriginLab\XFWizScript.h> #include <..\OriginLab\XFWizDlg.h> #include <..\OriginLab\XFWizard_utils.h> #include <..\Originlab\wizDlg.h> // user added header file for this example
WizDlgInputOutputRange objXFWizIO; if(!xfwiz_construct_input_range(&objXFWizIO, STR_XFNAME_PAGE_1, iy)) { XF_THROW(XFERR_FAIL_TO_UPDATE_GETN_TREE); } if( script ) { run_wiz_nodlg(theme, NULL, &objXFWizIO); } else { open_wiz_dlg(theme, NULL, &objXFWizIO); }
#include <..\Originlab\wizDlg.h> // user added header file for this example
WizDlgCore* pWizCore = (WizDlgCore*)get_xf_core_handler(NODE_NAME_XF_WIZ_CORE_POINTER); ASSERT(pWizCore); // Set X From/To to WizCore class object pWizCore->SetXRange(xfrom, xto);
if( PDS_AUTO == okutil_cvt_str_to_predefined_type(trGetN.xfrom.strVal) || PDS_AUTO == okutil_cvt_str_to_predefined_type(trGetN.xto.strVal) ) { DataRange dr; TreeNode trRange = trGetN.iy; okxf_resolve_tree_construct_range(&trRange, &dr); vector vx; dr.GetData(DRR_GET_DEPENDENT, 0, NULL, NULL, NULL, &vx); double from, to; vx.GetMinMax(from, to); trGetN.xfrom.dVal = from; trGetN.xto.dVal = to; }
//put additional include files here #include <..\Originlab\wizDlg.h> #include <..\Originlab\grobj_utils.h>
WizDlgCore* pWizCore = (WizDlgCore*)get_xf_core_handler(NODE_NAME_XF_WIZ_CORE_POINTER); ASSERT(pWizCore); // Get the x from/to values that are specified in Page 1 double xfrom, xto; pWizCore->GetXRange(xfrom, xto); // To get input range. XFWizNavigation* pXFWizNavg = (XFWizNavigation*)(pWizCore->GetXFWizNavigation()); WizDlgInputOutputRange* pwizInputOutputRange = (WizDlgInputOutputRange*)(pXFWizNavg->GetXFWizInputOutputRange()); // Get input ranges from Page 1 Array<DataRange&> arrdr; if( pwizInputOutputRange->Get(&arrdr, STR_XFNAME_PAGE_1, true) ) { DataRange& dr = arrdr.GetAt(0); vector<uint> vUIDs; DataPlot dp; if( dr.GetPlots(vUIDs) > 0 ) { // Get source graph layer from input range dp = (DataPlot)Project.GetObject(vUIDs[0]); GraphLayer gl; dp.GetParent(gl); // To add rectangle to graph GraphObject go; add_rect(gl, go, xfrom, 0, xto, 0, color, 2, LN_VERTICAL, true, false); } }
Before running the example wizard, you need to create a new worksheet, fill two columns with data, and plot a line graph with two columns.
Keep the graph window active. Run "wizDlg s:=1 t:=theme1" in the Command window. No dialog opens and a rectangle will be added to the active graph with the settings specified in the theme file.