📄 datamanager.cpp
字号:
#include "stdafx.h"
#include "AVInfoAPI.h"
#include "AVInfoKernel.h"
#include "../AVPublic/AVGraphics.h"
#include <afxtempl.h>
#ifdef __cplusplus
extern "C"{
#endif
/////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////全局变量////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////
//本模块全局变量
AV_NET_MODEL g_netModel;
typedef CMap<int,int,AV_COMPONENT_INFO*,AV_COMPONENT_INFO*>CMapComponentToID;
CMapComponentToID g_mapComponentID;
//外部全局变量引用
extern int **g_pMatrixNodeOrigin; //连通性分析原始节点矩阵
extern int **g_pMatrixNodePrev; //连通性分析结果节点矩阵(前一状态)
extern int **g_pMatrixNodeCurrent; //连通性分析结果节点矩阵(当前状态)
extern int **pMatrixLocal;
//外部函数声明
extern AV_COMPONENT_INFO* GetComponentInfoByKey(AV_KEY_INFO* tagKey);
/////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////接口函数////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////
/*****************************************************************************
【功能说明】:设置当前网络模型(FirstCall,Must)
【输入参数】:网络模型描述结构pNetModel
【输出参数】:无
【返回说明】:本图形系统定义的调用返回码
*****************************************************************************/
AV_EXPORT USHORT AVOpenNetModel(BOOL bEdit)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
AVCloseNetModel();
char modelName[255];
::AVGetModelName((char*)modelName,bEdit);
char pszPath[MAX_PATH];
if(bEdit)
{
char* szGPath = NULL;
::GetGDataPath(&szGPath);
strcpy(pszPath,szGPath);
strcat(pszPath,"\\");
}
else ::GetTempPath(MAX_PATH,pszPath);
CFile file;
CString strPath = CString(pszPath) + CString(modelName) + _T(".nnm");
if (!file.Open((LPCTSTR)strPath,CFile::modeRead|CFile::shareExclusive))
{
CString str = _T("无效的节点模型存储:") + strPath;
if(!bEdit) ::MessageBox(AfxGetMainWnd()->GetSafeHwnd(),str,"提示::AVInfoKernel_AVOpenNetModel",MB_OK | MB_ICONEXCLAMATION | MB_ICONWARNING);
return AVERR_FILE_NOT_FOUND;
}
int nVersion1 = 1;
int nVersion2 = 0;
char szBuffer[LENGTH_VERSION_STRING];
strcpy( szBuffer, "" );
file.Read( szBuffer, sizeof(char)*LENGTH_VERSION_STRING );
char szTemp[LENGTH_VERSION_STRING];
strcpy( szTemp, szBuffer );
szTemp[7] = '\0';
if( stricmp(szTemp, "VERSION") == 0 )
{
nVersion1 = atoi( &szBuffer[10] );
nVersion2 = atoi( &szBuffer[12] );
}
else //未存储版本串版本
{
nVersion1 = 1;
nVersion2 = 0;
file.Seek( -sizeof(char)*LENGTH_VERSION_STRING, CFile::current );
}
file.Read(&g_netModel.nNodeSum,sizeof(int));
if(g_netModel.nNodeSum <= 0)
{
CString str(_T(""));
str.Format(_T("网络模型[%s]中节点数目为零!"),modelName);
if(!bEdit) ::MessageBox(AfxGetMainWnd()->GetSafeHwnd(),str,"提示::AVInfoKernel_AVOpenNetModel",MB_OK | MB_ICONEXCLAMATION | MB_ICONWARNING);
return AV_NO_ERR;
}
g_netModel.pNodeInfo = new AV_NODE_INFO[g_netModel.nNodeSum];
for(int i=0; i<g_netModel.nNodeSum; i++)
{
file.Read(&(g_netModel.pNodeInfo+i)->nID,sizeof(int));
file.Read(&(g_netModel.pNodeInfo+i)->nComponentSum,sizeof(int));
(g_netModel.pNodeInfo+i)->pKeyInfo = NULL;
(g_netModel.pNodeInfo+i)->nPower = 0;
if((g_netModel.pNodeInfo+i)->nComponentSum <= 0) continue;
(g_netModel.pNodeInfo+i)->pKeyInfo = new AV_KEY_INFO[(g_netModel.pNodeInfo+i)->nComponentSum];
if( nVersion1 == 1 && nVersion2 == 0 ) //原始版本键值长度为48,原始版本后为96
file.Read((g_netModel.pNodeInfo+i)->pKeyInfo,(sizeof(AV_KEY_INFO)-48)*(g_netModel.pNodeInfo+i)->nComponentSum);
else
file.Read((g_netModel.pNodeInfo+i)->pKeyInfo,sizeof(AV_KEY_INFO)*(g_netModel.pNodeInfo+i)->nComponentSum);
for(int j=0; j<(g_netModel.pNodeInfo+i)->nComponentSum; j++)
((g_netModel.pNodeInfo+i)->pKeyInfo+j)->nID = -1;
}
file.Close();
strPath = CString(pszPath) + CString(modelName) + _T(".ctm");
if (!file.Open((LPCTSTR)strPath,CFile::modeRead|CFile::shareExclusive))
{
CString str = _T("无效的元件模型存储:") + strPath;
if(!bEdit) ::MessageBox(AfxGetMainWnd()->GetSafeHwnd(),str,"提示::AVInfoKernel_AVOpenNetModel",MB_OK | MB_ICONEXCLAMATION | MB_ICONWARNING);
return AVERR_FILE_NOT_FOUND;
}
nVersion1 = 1;
nVersion2 = 0;
strcpy( szBuffer, "" );
file.Read( szBuffer, sizeof(char)*LENGTH_VERSION_STRING );
strcpy( szTemp, szBuffer );
szTemp[7] = '\0';
if( stricmp(szTemp, "VERSION") == 0 )
{
nVersion1 = atoi( &szBuffer[10] );
nVersion2 = atoi( &szBuffer[12] );
}
else //未存储版本串版本
{
nVersion1 = 1;
nVersion2 = 0;
file.Seek( -sizeof(char)*LENGTH_VERSION_STRING, CFile::current );
}
file.Read(&g_netModel.nComponentSum,sizeof(int));
if(g_netModel.nComponentSum <= 0)
{
CString str(_T(""));
str.Format(_T("网络模型[%s]中元件数目为零!"),modelName);
if(!bEdit) ::MessageBox(AfxGetMainWnd()->GetSafeHwnd(),str,"提示::AVInfoKernel_AVOpenNetModel",MB_OK | MB_ICONEXCLAMATION | MB_ICONWARNING);
return AV_NO_ERR;
}
g_netModel.pComponentInfo = new AV_COMPONENT_INFO[g_netModel.nComponentSum];
//wxg20070115所有遥测量不需参与拓朴计算
/*for(i=0; i<g_netModel.nComponentSum; i++)
{
file.Read(&(g_netModel.pComponentInfo+i)->keyInfo,sizeof(AV_KEY_INFO));
file.Read(&(g_netModel.pComponentInfo+i)->nType,sizeof(int));
file.Read(&(g_netModel.pComponentInfo+i)->nPortSum,sizeof(int));
(g_netModel.pComponentInfo+i)->pPortInfo = NULL;
(g_netModel.pComponentInfo+i)->pComponent = NULL;
(g_netModel.pComponentInfo+i)->pVisualObj = NULL;
(g_netModel.pComponentInfo+i)->nState = 0;
(g_netModel.pComponentInfo+i)->nPower = 0;
(g_netModel.pComponentInfo+i)->nTopoColorTagID = -1;
(g_netModel.pComponentInfo+i)->keyInfo.nID = -1;
if((g_netModel.pComponentInfo+i)->nPortSum <= 0) continue;
(g_netModel.pComponentInfo+i)->pPortInfo = new AV_PORT_INFO[(g_netModel.pComponentInfo+i)->nPortSum];
for(int j=0; j < (g_netModel.pComponentInfo+i)->nPortSum; j++)
{
file.Read(&((g_netModel.pComponentInfo+i)->pPortInfo+j)->nID,sizeof(int));
file.Read(&((g_netModel.pComponentInfo+i)->pPortInfo+j)->nNode,sizeof(int));
file.Read(&((g_netModel.pComponentInfo+i)->pPortInfo+j)->nType,sizeof(int));
file.Read(&((g_netModel.pComponentInfo+i)->pPortInfo+j)->nLinkSum,sizeof(int));
((g_netModel.pComponentInfo+i)->pPortInfo+j)->pKeyInfo = NULL;
if(((g_netModel.pComponentInfo+i)->pPortInfo+j)->nLinkSum <= 0) continue;
((g_netModel.pComponentInfo+i)->pPortInfo+j)->pKeyInfo = new AV_KEY_INFO[((g_netModel.pComponentInfo+i)->pPortInfo+j)->nLinkSum];
file.Read(((g_netModel.pComponentInfo+i)->pPortInfo+j)->pKeyInfo,sizeof(AV_KEY_INFO)*((g_netModel.pComponentInfo+i)->pPortInfo+j)->nLinkSum);
for(int k=0; k<((g_netModel.pComponentInfo+i)->pPortInfo+j)->nLinkSum; k++)
(((g_netModel.pComponentInfo+i)->pPortInfo+j)->pKeyInfo+k)->nID = -1;
}
}*/
int nIndex=0;///////////////////////////////////////////////////////////
for(i=0; i<g_netModel.nComponentSum; i++)
{
if( nVersion1 == 1 && nVersion2 == 0 ) //原始版本键值长度为48,原始版本后为96
file.Read(&(g_netModel.pComponentInfo+nIndex)->keyInfo,sizeof(AV_KEY_INFO)-48);
else
file.Read(&(g_netModel.pComponentInfo+nIndex)->keyInfo,sizeof(AV_KEY_INFO));
file.Read(&(g_netModel.pComponentInfo+nIndex)->nType,sizeof(int));
file.Read(&(g_netModel.pComponentInfo+nIndex)->nPortSum,sizeof(int));
(g_netModel.pComponentInfo+nIndex)->pPortInfo = NULL;
(g_netModel.pComponentInfo+nIndex)->pComponent = NULL;
(g_netModel.pComponentInfo+nIndex)->pVisualObj = NULL;
(g_netModel.pComponentInfo+nIndex)->nState = 0;
(g_netModel.pComponentInfo+nIndex)->nPower = 0;
(g_netModel.pComponentInfo+nIndex)->nTopoColorTagID = -1;
(g_netModel.pComponentInfo+nIndex)->keyInfo.nID = -1;
if((g_netModel.pComponentInfo+nIndex)->nPortSum <= 0)
{
if((g_netModel.pComponentInfo+nIndex)->nType != 28)//28遥测量
nIndex++;
continue;
}
(g_netModel.pComponentInfo+nIndex)->pPortInfo = new AV_PORT_INFO[(g_netModel.pComponentInfo+nIndex)->nPortSum];
for(int j=0; j < (g_netModel.pComponentInfo+nIndex)->nPortSum; j++)
{
file.Read(&((g_netModel.pComponentInfo+nIndex)->pPortInfo+j)->nID,sizeof(int));
file.Read(&((g_netModel.pComponentInfo+nIndex)->pPortInfo+j)->nNode,sizeof(int));
file.Read(&((g_netModel.pComponentInfo+nIndex)->pPortInfo+j)->nType,sizeof(int));
file.Read(&((g_netModel.pComponentInfo+nIndex)->pPortInfo+j)->nLinkSum,sizeof(int));
((g_netModel.pComponentInfo+nIndex)->pPortInfo+j)->pKeyInfo = NULL;
if(((g_netModel.pComponentInfo+nIndex)->pPortInfo+j)->nLinkSum <= 0) continue;
((g_netModel.pComponentInfo+nIndex)->pPortInfo+j)->pKeyInfo = new AV_KEY_INFO[((g_netModel.pComponentInfo+nIndex)->pPortInfo+j)->nLinkSum];
if( nVersion1 == 1 && nVersion2 == 0 ) //原始版本键值长度为48,原始版本后为96
file.Read(((g_netModel.pComponentInfo+nIndex)->pPortInfo+j)->pKeyInfo,(sizeof(AV_KEY_INFO)-48)*((g_netModel.pComponentInfo+nIndex)->pPortInfo+j)->nLinkSum);
else
file.Read(((g_netModel.pComponentInfo+nIndex)->pPortInfo+j)->pKeyInfo,sizeof(AV_KEY_INFO)*((g_netModel.pComponentInfo+nIndex)->pPortInfo+j)->nLinkSum);
for(int k=0; k<((g_netModel.pComponentInfo+nIndex)->pPortInfo+j)->nLinkSum; k++)
(((g_netModel.pComponentInfo+nIndex)->pPortInfo+j)->pKeyInfo+k)->nID = -1;
}
if((g_netModel.pComponentInfo+nIndex)->nType != 28)//28遥测量
nIndex++;
}
g_netModel.nComponentSum = nIndex;////////////////////////////////////
file.Close();
return AV_NO_ERR;
}
/*****************************************************************************
【功能说明】:获取当前网络模型完整信息(FirstCall,Must)
【输入参数】:网络模型描述结构pNetModel
【输出参数】:无
【返回说明】:本图形系统定义的调用返回码
*****************************************************************************/
AV_EXPORT USHORT AVGetNetModel(AV_NET_MODEL** pNetModel)
{
*pNetModel = &g_netModel;
return AV_NO_ERR;
}
/*****************************************************************************
【功能说明】:初始化元件二次系统索引ID(InitFirstA,Option)
【输入参数】:元件检索键tagKey,二次系统对象指针object,是否显示错误信息bShowMsg
【输出参数】:无
【返回说明】:本图形系统定义的调用返回码
*****************************************************************************/
AV_EXPORT USHORT AVInitComponentID(AV_KEY_INFO* tagKey,void* object,BOOL bShowMsg)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
if(!g_netModel.pComponentInfo) return AVERR_NOT_FOUND;
BOOL bFind = FALSE;
for(int i=0; i<g_netModel.nComponentSum; i++)
{
if(_stricmp((g_netModel.pComponentInfo+i)->keyInfo.chKey,tagKey->chKey) == 0)
{
if((g_netModel.pComponentInfo+i)->keyInfo.nID != -1)
{
CString str(_T(""));
str.Format(_T("系统检索键%s存在冲突!"),tagKey->chKey);
if(bShowMsg) ::MessageBox(AfxGetMainWnd()->GetSafeHwnd(),str,"提示::AVInfoKernel_AVInitComponentID",MB_OK | MB_ICONEXCLAMATION | MB_ICONWARNING);
bFind = TRUE;
return AVERR_ALREADY_EXIST;
}
(g_netModel.pComponentInfo+i)->keyInfo.nID = tagKey->nID;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -