📄 filter_utils.c
字号:
BOOL fuGetFilterFileNameFromListItem(LPCSTR lpcszFilterListItem, String &strFileName, LPCSTR lpcszDataPath)
{
string str = lpcszFilterListItem;
int i = str.Find(':');
if( i < 1 )
return FALSE;
string strItemPrefix = str.Left(i); // everything before the colon
string strItemName = str.Mid(i + 2); // everything after the colon and space
string strPrefixes(FILTER_LOCATION_PREFIX);
int iTokens = strPrefixes.GetNumTokens('|');
for( i = 0; i < iTokens; i++ )
{
str = strPrefixes.GetToken(i, '|');
if( 0 == str.CompareNoCase(strItemPrefix) )
break;
}
if( !IS_FILTER_PATH_ID(i) )
return FALSE;
switch( i )
{
case FILTER_PATH_USER:
str = GetAppPath() + FILTERS_FOLDER_NAME;
break;
case FILTER_PATH_ORIGIN:
str = GetAppPath(TRUE) + FILTERS_FOLDER_NAME;
break;
default: // Data path
if( lpcszDataPath )
str = lpcszDataPath;
else
str.Empty();
break;
}
strFileName.Format("%s%s.%s", str, strItemName, IMPORT_FILTER_EXTENSION);
return TRUE;
}
//--------------------------------------------------------------------------
void fuSetPlotID(TreeNode& trFilter, int nPlotID)
{
trFilter.Common.PlotType.nVal = nPlotID;
}
int fuGetPlotID(TreeNode& trFilter)
{
if( trFilter.Common.PlotType )
return trFilter.Common.PlotType.nVal;
return IDM_PLOT_LINE; // default plot type
}
void fuSetPlotTemplate(TreeNode& trFilter, LPCSTR lpcszTemplate)
{
trFilter.Common.PlotTemplate.strVal = lpcszTemplate;
}
string fuGetPlotTemplate(TreeNode& trFilter)
{
string str;
if( trFilter.Common.PlotTemplate )
str = trFilter.Common.PlotTemplate.strVal;
return str;
}
//--------------------------------------------------------------------------
int fuGetTargetPageType(TreeNode& trFilter)
{
/*
int iType;
if( trFilter.Common.TargetWindowType )
{
iType = trFilter.Common.TargetWindowType.nVal;
if( EXIST_WKS != iType && EXIST_MATRIX != iType )
iType = EXIST_WKS;
}
else
iType = EXIST_WKS;
return iType;
*/
int iTargetWndType = tree_node_get_int(trFilter.Common.TargetWindowType, EXIST_NONE);
if( EXIST_NONE == iTargetWndType )
{
int iFilterType = fuGetFilterType(trFilter);
if( FILTER_TYPE_ASCII == iFilterType || FILTER_TYPE_BINARY == iFilterType )
iTargetWndType = EXIST_WKS;
}
return iTargetWndType;
}
BOOL fuIsTargetPageType(TreeNode& trFilter, int iPageType)
{
return (iPageType == fuGetTargetPageType(trFilter));
}
BOOL fuGetTargetWindow(TreeNode& trFilter, int& iType, string& strTemplate)
{
iType = fuGetTargetPageType(trFilter);
if( trFilter.Common.TargetWindowTemplate )
strTemplate = trFilter.Common.TargetWindowTemplate.strVal;
else
/*
{
string strType;
if( EXIST_MATRIX == iType )
strType = "System.Matrix.DefTemplate$";
else
strType = "System.Wks.DefTemplate$";
char szDefTemplate[NAME_SIZE];
if( !LT_get_str(strType, szDefTemplate, NAME_SIZE) )
lstrcpy(szDefTemplate, "Origin");
strTemplate = szDefTemplate;
}
*/
strTemplate.Empty();
return TRUE;
}
BOOL fuSetTargetWindow(TreeNode& trFilter, int iType, LPCSTR lpcszTemplate)
{
trFilter.Common.TargetWindowType.nVal = iType;
string strTemplate;
if( lpcszTemplate )
strTemplate = lpcszTemplate;
trFilter.Common.TargetWindowTemplate.strVal = strTemplate;
return TRUE;
}
Page fuCreateTargetPage(TreeNode& trFilter, int iOption)
{
int iType;
string strTemplate;
fuGetTargetWindow(trFilter, iType, strTemplate);
Page pgTarget;
if( EXIST_MATRIX == iType )
{
MatrixPage pgMat;
if( strTemplate.IsEmpty() )
strTemplate = LabTalk.System.Matrix.DefTemplate$;
pgMat.Create(strTemplate, iOption);
pgTarget = pgMat;
}
else if( EXIST_WKS == iType )
{
WorksheetPage pgWks;
if( strTemplate.IsEmpty() )
strTemplate = LabTalk.System.Wks.DefTemplate$;
pgWks.Create(strTemplate, iOption);
pgTarget = pgWks;
}
return pgTarget;
}
//--------------------------------------------------------------------------
int fuGetDragDropGraph(TreeNode &trFilter)
{
if( trFilter.Common.DragAndDrop.Graph )
{
if( IS_FILTER_DDGRAPH(trFilter.Common.DragAndDrop.Graph.nVal) )
return trFilter.Common.DragAndDrop.Graph.nVal;
}
return FILTER_DDGRAPH_OPENONLY;
}
void fuSetDragDropGraph(TreeNode& trFilter, int iMode)
{
if( !IS_FILTER_DDGRAPH(iMode) )
iMode = FILTER_DDGRAPH_OPENONLY;
trFilter.Common.DragAndDrop.Graph.nVal = iMode;
}
int fuGetDragDropWorkspace(TreeNode &trFilter)
{
if( trFilter.Common.DragAndDrop.Workspace )
{
if( IS_FILTER_DDWORKSPACE(trFilter.Common.DragAndDrop.Workspace.nVal) )
return trFilter.Common.DragAndDrop.Workspace.nVal;
}
return FILTER_DDWORKSPACE_OPENONLY;
}
void fuSetDragDropWorkspace(TreeNode& trFilter, int iMode)
{
if( !IS_FILTER_DDWORKSPACE(iMode) )
iMode = FILTER_DDWORKSPACE_OPENONLY;
trFilter.Common.DragAndDrop.Workspace.nVal = iMode;
}
//--------------------------------------------------------------------------
int fuGetFilterFile(string &strFilter, LPCSTR lpcszDataFile)
{
string strFileExt = GetFileName(lpcszDataFile);
StringArray saFiltersInDataFolder;
string strDataPath = GetFilePath(lpcszDataFile);
if( !strDataPath.IsEmpty() )
fuGetFilterFiles(saFiltersInDataFolder, strDataPath, strFileExt);
int nCount = saFiltersInDataFolder.GetSize();
if( 1 == nCount ) // if only 1 applicable filter in data-folder then use it.
{
strFilter = saFiltersInDataFolder[0];
/// EJP 07-22-2003 v7.0631 QA70-4073 USE_DATAFOLDER_FILTER_WHEN_ONLY_1_APPLICABLE
return 1; // only 1 data-folder filter applicable, so we use it.
/// end USE_DATAFOLDER_FILTER_WHEN_ONLY_1_APPLICABLE
}
else if( 0 == nCount ) // if no applicable filters in data-folder then check ini and exe folders.
{
StringArray saFiltersInExeFolder;
string strExePath;
strExePath.Format("%s%s", GetAppPath(TRUE), FILTERS_FOLDER_NAME);
if( !strExePath.IsEmpty() && strExePath != strDataPath )
fuGetFilterFiles(saFiltersInExeFolder, strExePath, strFileExt);
nCount += saFiltersInExeFolder.GetSize();
if( nCount < 2 )
{
if( 1 == saFiltersInExeFolder.GetSize() )
strFilter = saFiltersInExeFolder[0];
StringArray saFiltersInUserFolder;
string strIniPath;
strIniPath.Format("%s%s", GetAppPath(), FILTERS_FOLDER_NAME);
if( !strIniPath.IsEmpty() && strIniPath != strDataPath && strIniPath != strExePath )
fuGetFilterFiles(saFiltersInUserFolder, strIniPath, strFileExt);
nCount += saFiltersInUserFolder.GetSize();
if( 1 == saFiltersInUserFolder.GetSize() )
strFilter = saFiltersInUserFolder[0];
}
}
if( nCount > 1 )
{
strFilter.Empty();
PFNSELECTFILTER pfn = GET_SELECTFILTER_FUNC;
if( pfn && pfn(strFilter, lpcszDataFile) )
nCount = 1;
}
return nCount;
}
int fuLoadFilterFile(TreeNode &trFilter, LPCSTR lpcszDataFile)
{
string strFilter;
int n = fuGetFilterFile(strFilter, lpcszDataFile);
if( n != 1 )
return n;
Tree tr;
if( tr.Load(strFilter) )
{
trFilter = tr;
return 1;
}
return 0;
}
//--------------------------------------------------------------------------
// fuGetImportFunctionPtr
//
//--------------------------------------------------------------------------
PFNIMPORTFUNC fuGetImportFunctionPtr(TreeNode &trFilter)
{
string strOCFunc = trFilter.Common.OCFunction.strVal;
string strOCFile = trFilter.Common.OCFile.strVal;
if( strOCFunc.IsEmpty() || strOCFile.IsEmpty() )
return NULL;
PFNIMPORTFUNC pfn = Project.FindFunction(strOCFunc, strOCFile, TRUE);
return pfn;
}
//--------------------------------------------------------------------------
BOOL fuRemoveHeaderParams(TreeNode &trFilter)
{
return trFilter.Common.HeaderParameters.Remove();
}
TreeNode fuGetHeaderParams(TreeNode &trFilter)
{
if( !trFilter.Common.HeaderParameters )
trFilter.Common.AddNode("HeaderParameters");
return trFilter.Common.HeaderParameters;
}
bool fuGetHeaderParamDefined(TreeNode &trFilter, int &nVal)
{
TreeNode trAllParams = fuGetHeaderParams(trFilter);
if( !trAllParams )
return false;
return trAllParams.GetAttribute(FILTER_HEADERPARAM_DEFINED, nVal);
}
void fuSetHeaderParamDefined(TreeNode &trFilter, int nVal)
{
TreeNode trAllParams = fuGetHeaderParams(trFilter);
if( !trAllParams )
return;
trAllParams.SetAttribute(FILTER_HEADERPARAM_DEFINED, nVal);
}
int fuGetHeaderParamCount(TreeNode &trFilter)
{
TreeNode trAllParams = fuGetHeaderParams(trFilter);
if( !trAllParams )
return 0;
return trAllParams.GetNodeCount();
}
TreeNode fuGetHeaderParam(TreeNode &trFilter, LPCSTR lpcszName)
{
TreeNode trParam;
TreeNode trAllParams = fuGetHeaderParams(trFilter);
if( !trAllParams )
return trParam;
string str(lpcszName);
foreach(trParam in trAllParams.Children)
{
if( trParam.Name && 0 == str.Compare(trParam.Name.strVal) )
return trParam;
}
return trParam;
}
bool fuGetHeaderParamNames(TreeNode &trFilter, StringArray &saNames)
{
TreeNode trAllParams = fuGetHeaderParams(trFilter);
if( !trAllParams )
return false;
TreeNode trParam;
foreach(trParam in trAllParams.Children)
{
if( trParam.Name )
saNames.Add(trParam.Name.strVal);
}
return true;
}
//--------------------------------------------------------------------------
// fuAddHeaderParam
//
// Do not call this function directly.
// Use fuAddASCHeaderParam or fuAddBinHeaderParam macros.
//--------------------------------------------------------------------------
bool fuAddHeaderParam(TreeNode &trFilter, LPCSTR lpcszName, int nType, int n1, int n2, int n3)
{
TreeNode trAllParams = fuGetHeaderParams(trFilter);
if( !trAllParams )
return false;
string str;
str.Format("P%d", trAllParams.GetNodeCount());
TreeNode trParam = trAllParams.AddNode(str);
if( !trParam )
return false;
trParam.Name.strVal = lpcszName;
trParam.Type.nVal = nType;
if( FILTER_TYPE_ASCII == trFilter.Type.nVal )
{
trParam.Line.nVal = n1;
trParam.Pos.nVal = n2;
trParam.End.nVal = n3;
}
else // FILTER_TYPE_BINARY
{
trParam.Offset.nVal = n1;
trParam.Size.nVal = n2;
}
return true;
}
bool fuAddASCHeaderParam(TreeNode &trFilter, LPCSTR lpcszName, int nType, int nLine, int nPos, int nEnd)
{
return fuAddHeaderParam(trFilter, lpcszName, nType, nLine, nPos, nEnd);
}
bool fuAddBinHeaderParam(TreeNode &trFilter, LPCSTR lpcszName, int nType, int nOffset, int nSize)
{
return fuAddHeaderParam(trFilter, lpcszName, nType, nOffset, nSize);
}
bool fuGetHeaderParam(TreeNode &trFilter, LPCSTR lpcszName, int &nType, int &n1, int &n2, int &n3)
{
TreeNode trParam = fuGetHeaderParam(trFilter, lpcszName);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -