📄 tree_utils.h
字号:
/*------------------------------------------------------------------------------*
* File Name: Tree_utils.h *
* Creation: CPY 3/17/03 *
* Purpose: Origin C header for Tree and vsFlexGrid utilities that are *
* implemented in GetNBox.c *
* Copyright (c) OriginLab Corp.2003 *
* All Rights Reserved *
* *
* Modification Log: *
* RVD 9/3/2003 QA70-5078 v7.0682 PLOT_RANGE_APPLY *
* CPY 10/21/03 QA70-4680 v7.5727 TREE_BRANCHESOPEN_CLOSE_REMEMBERED *
*------------------------------------------------------------------------------*/
#ifndef _TREE_UTILS.H
#define _TREE_UTILS.H
#include <Tree.h>
#include <settings.h>
#include <storage.h>
// const used in GetNBox for general purpose data type const
#define TRGP_CHECK ONODETYPE_CHECKBOX
#define TRGP_ENUM_COMBO ONODETYPE_DROPDOWN_NUMERIC_FLOAT
#define TRGP_STR_LIST ONODETYPE_DROPLIST_STRINGS
#define TRGP_STR ONODETYPE_EDIT_BOX_ONELINE_TEXT
#define TRGP_DOUBLE ONODETYPE_EDIT_BOX_NUMERIC_FLOAT
#define TRGP_COLOR ONODETYPE_DROPLIST_COLORS
#define TRGP_RANGE ONODETYPE_EDIT_RANGE
#define TRGP_BRANCH ONODETYPE_BRANCH
/** >Basic I/O
quick display of a tree, only the tagName and Text are shown
Parameters:
tr = TreeNode to dump to output
nLevel = 0, this function is called recursively inside, so there is no need to use this parameter from your code
Returns:
TRUE if given tree is a valid TreeNode
See Also:
tree_dump
*/
bool out_tree(TreeNode& tr, int nLevel = 0);
/** >Basic I/O
dump a tree to a specified output, also show standard attributes if any
Parameters:
tr = TreeNode to dump to output
lpcsz = optional string to diplay before the dump
nOutput = one of the constants defined in oc_const.h,
enum {WRITE_SCRIPT_WINDOW, WRITE_STATUS_BAR, WRITE_OUTPUT_LOG, WRITE_MESSAGE_BOX, WRITE_COMPILER_OUTPUT};
nLevel = 0, this function is called recursively inside, so there is no need to use this parameter from your code
Returns:
TRUE if given tree is a valid TreeNode
See Also:
out_tree
*/
bool tree_dump(const TreeNode& tr, LPCSTR lpcsz = NULL, int nOutput = WRITE_SCRIPT_WINDOW); // = NULL, 0, 0
/** >Tree
count number of leafs in the given tree
Parameters:
tr = TreeNode to count
lpnSections = if given, then count the number of branches that contain these leafs
Returns:
total number of leafs
*/
int tree_count_items(TreeNode& tr, int* lpnSections = NULL);
/** >Tree
*/
TreeNode tree_get_node(TreeNode& trRoot, int nRow, int* lpInc = NULL);
enum {TREE_COPY_SKIP_HIDDEN = 0x0001, TREE_COPY_ATTRIB_ENABLE = 0x0002};
/** >Tree
*/
int tree_copy_values(TreeNode& trSrc, const TreeNode& trDest, WORD wOptions = TREE_COPY_SKIP_HIDDEN | TREE_COPY_ATTRIB_ENABLE);
/** >Tree
walk all tree nodes to delete specified attribute
Parameters:
tr = TreeNode to walk
lpcszAttribute = attribute name to delete
Returns:
total number of nodes the specified attribute is deleted
*/
int tree_remove_attribute(TreeNode& tr, LPCSTR lpcszAttribute);
#define STR_ENABLE_ATTRIB "Enable"
#define STR_SHOW_ATTRIB "Show"
#define STR_CHANGED_ATTRIB "OldValue"
/// RVD 9/3/2003 QA70-5078 v7.0682 PLOT_RANGE_APPLY
#define STR_PLOT_VIEW "View"
#define STR_PLOT_SETUP_DLG "PlotSetupDlg"
/// end PLOT_RANGE_APPLY
/** >Tree
if bSet, then NULL will clear changed
*/
bool tree_node_changed(TreeNode& trNode, bool bSet = false, LPCSTR lpcszOldValue = NULL);
/** >Tree
walk tree and store attribute "OldValue" into all the nodes that has different value then the specified string
Parameters:
tr = TreeNode to walk
vs = a linearized array of string values that should map to every tree node
Returns:
total number of nodes that has OldValue attributes added (changed)
Remark:
the vs array can be obtained by tree_get_values.
*/
int tree_update_changes(TreeNode& tr, const vector<string>& vs);
/**
set numeric value as well as putting a descriptive string to the node
Parameters:
tr = TreeNode to set
dVal = a numerical value to set
lpcszLabel = a text label to associate
Example:
tree_node_set_value(trCalculation.t, tvalue, "t-Value");
Returns:
false if tr is invalid
bool tree_node_set_double(TreeNode& tr, double dVal, LPCSTR lpcszLabel);
*/
/** >Tree
get both the numeric value of a tree node as well as its associated label
Parameters:
tr = TreeNode to get
strLabel = the text label if present, otherwise the tagName
dDefault = default value in case node is not a valid node
*/
double tree_node_get_double(TreeNode& tr, string& strLabel, double dDefault = _ONAN);
/** >Tree
get int value from a tree node, whether it is valid or not
Parameters:
tr = TreeNode to get
nDefault = default value in case node is not a valid node
*/
int tree_node_get_int(TreeNode& tr, int nDefault = 0);
/** >Tree
walk tree and copy all the values into given string vector
Parameters:
tr = TreeNode to walk
vs = a linearized array of string values that should map to every tree node
*/
void tree_get_values(TreeNode& tr, vector<string>& vs);
#ifdef _ORGOBJ_H
/** >Tree
add all Info storage into given treenode
Parameters:
trNode = tree node to add info storage
orgObj = Origin object, can be Page, Layer, Column
lpcszObjName = name of the Origin object, if NULL, will use GetName
lpcszObjLabel = label of the Origin object, if NULL, will use GetLabel
nObjIndex = index >= 0 for additional info to be stored in the StrData of the tree node for each item, use NPLOT_FOR_WKS if this is for text label display in a worksheet
Return:
TRUE for success
*/
bool tree_add_info(TreeNode& trNode, const OriginObject& orgObj, LPCSTR lpcszObjName = NULL, LPCSTR lpcszObjLabel = NULL, int nObjIndex = -1);
#define NPLOT_FOR_WKS 100000 // a large enough number that is impossible for plot index
#endif //_ORGOBJ_H
// For reading/writing to/from ini files
#define SZ_TREE_INI_SECTION_NODE_PREFIX "section"
#define SZ_TREE_INI_KEY_NODE_PREFIX "key"
/** >Tree
Get the tree node that represents a specified ini section.
Parameters:
trIni = tree node that represents an ini file
lpcszSection = pointer to an ini section name
Return:
If a tree node representing the specified ini section then it is returned, else an invalid tree node is returned.
*/
TreeNode tree_get_ini_section(TreeNode &trIni, LPCSTR lpcszSection);
/** >Tree
Read an ini file into a tree node.
Parameters:
trIni = tree node to receive the ini file
lpcszSection = pointer to an ini file name
Return:
true for success, false for error
*/
bool tree_read_ini(TreeNode &trIni, LPCSTR lpcszFile);
/** >Tree
Read an ini file into a tree node.
Parameters:
trIni = tree node to receive the ini file
iniFile = the ini file to read from
Return:
true for success, false for error
*/
bool tree_read_ini(TreeNode &trIni, INIFile &iniFile);
/** >Tree
Read an ini section into a tree node.
Parameters:
trIni = tree node to receive the ini section
lpcszFile = pointer to an ini file name
lpcszSection = pointer to an ini section name
Return:
true for success, false for error
*/
bool tree_read_ini_section(TreeNode &trIni, LPCSTR lpcszFile, LPCSTR lpcszSection);
/** >Tree
Read an ini section into a tree node.
Parameters:
trIni = tree node to receive the ini section
iniFile = the ini file to read from
lpcszSection = pointer to an ini section name
Return:
true for success, false for error
*/
bool tree_read_ini_section(TreeNode &trIni, INIFile &iniFile, LPCSTR lpcszSection);
/** >Tree
Write a tree node, that represents an ini file, to an ini file.
Parameters:
trIni = tree node representing an ini file
lpcszFile = pointer to an ini file name
Return:
true for success, false for error.
*/
bool tree_write_ini(TreeNode &trIni, LPCSTR lpcszFile, bool bClearSections=false);
/** >Tree
Write a tree node, that represents an ini file, to an ini file.
Parameters:
trIni = tree node representing an ini file
iniFile = ini file to be written to
Return:
true for success, false for error
*/
bool tree_write_ini(TreeNode &trIni, INIFile &iniFile, bool bClearSections=false);
/** >Tree
Write a tree node, that represents an ini section, to an ini file.
Parameters:
trIniSection = tree node representing an ini section
iniFile = ini file to be written to
Return:
true for success, false for error
*/
bool tree_write_ini_section(TreeNode &trIniSection, INIFile &iniFile, bool bClearSection=false);
/** >Import Export
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -