⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 topology.cpp

📁 一个通过矩阵运算得到图形连接关系的动态连接库
💻 CPP
📖 第 1 页 / 共 3 页
字号:
//提供二次开发人员进行拓扑信息的获取和分析接口功能
/*关于拓扑信息接口的说明:
1。数据采用磁盘文件共享;
2。系统不支持多模型并列工作;
*/
//2002.05.08---------------------------Start.
#include "stdafx.h"
#include "AVInfoAPI.h"
#include "AVInfoKernel.h"
#ifdef _ADOVER
	#include "Ado.h"
#endif
#include <afxtempl.h>

#ifdef __cplusplus
extern "C"{
#endif
//元件类的定义
class CElement
{
public:
	//拓扑属性
	AV_KEY_INFO keyInfo;				//元件检索键
										/*nID:元件自动编码 chKey元件系统编码*/
	ULONG TagIDState;					//元件状态变量索引
	ULONG TagIDFlash;					//元件闪烁变量索引
	ULONG TagIDPower;					//元件着色变量索引
	int nPortSum;						//元件端子数目
	AV_PORT_INFO* pPortInfo;			//端子信息(定义见AVInfoAPI.h)
	char BusType[16];					//母线类型(A为单母线,B为双母线,C为M/N母线);该属性已被扩充:U表电抗器开关,Z表中性点地刀
										//该字段对应数据库里的PortDesc,建模完成后自动填入该属性
										//若是刀闸,则填的是电源侧P,负荷侧L
										//对象不需弹出任务选项的X
	//物理属性
	int id;								//数组下标码

	int Type;							//元件类型
	int PhysicalType;					//元件物理类型
	int State;							//元件开关状态
	int ElectricState;					//元件电气状态
	int VoltageLevel;					//元件所在电压等级
	int Use;							//元件用途
	int Special;						//专用,非专用,未知(该属性在每次自动开票前针对一个具体对象自动填入)
	int CardInfo;						//挂牌信息0:不可挂牌;1:把手可挂牌;2本体可挂牌;3把手本体均可挂牌
	int CardOperate;					//挂牌操作0;无挂牌;1:把手挂牌;2:本体挂牌;3:把手本体均挂牌
	BOOL IsSpare;						//是否备用
	BOOL IsImpedance;					//是否有阻抗
	BOOL IsHandCart;					//是否手车式(断路器,隔离开关)
	BOOL IsTerminal;					//是否是终端元件
	BOOL IsOperate;						//是否可操作
	BOOL IsIsolationOperate;			//是否由刀闸控制停送电(用于有阻抗元件)
	//int IsolationAttribute;				//电源侧或负荷侧刀闸(电源侧1,负荷侧0)
	char SysCode[48];					
	char LineDescription[48];			//线路描述
	char ControlObj[128];				//如果是有工作备用电源的元件,则接级填为各工作、备用电源的控制开关(一般第一级为工作电源,以下顺次一级备用,二级备用……中间用分号隔开)	
	char AllElomorphObj[128];			//对偶对象编码
	char BelockRelation[256];			//填为闭锁元件信息 操作类型%闭锁元件编码*闭锁元件状态(如 0%221*1&223*0;1%220*0|224*0即表示该断路器闭合条件为221断位且223合位,断开条件为220合位或224合位)
	char twoLineDescription[64];		//设备间隔
	char testPoint[128];				//验电点
	char OperatePosition[128];          //操作地点
	CElement()
	{
		//拓扑属性初始化
		keyInfo.nID = -1;
		strcpy((char*)keyInfo.chKey,"");
		TagIDState = -1;
		TagIDFlash = -1;
		TagIDPower = -1;
		nPortSum = 0;
		pPortInfo = NULL;

		//物理属性初始化
		id = -1;
		strcpy(SysCode,"");
		strcpy(BusType,"");
		strcpy(LineDescription,"");
		strcpy(ControlObj,"");
		strcpy(AllElomorphObj,"");
		strcpy(BelockRelation,"");
		strcpy(twoLineDescription,"");
		strcpy(testPoint,"");
		strcpy(OperatePosition,"");
		Type = 0;
		PhysicalType = 0;
		State = -1;
		ElectricState = 5;
		VoltageLevel = 0;
		Use = 0;
		Special = 1;
		IsSpare = false;
		IsHandCart = false;
		IsImpedance = false;
		IsTerminal = false;
		IsOperate = false;
		IsIsolationOperate = false;
		CardInfo = 0;
		CardOperate = 0;
		//IsolationAttribute = -1;
	}
};
/////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////全局变量////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////
//外部全局变量
extern AV_NET_MODEL g_netModel;
typedef CMap<int,int,AV_COMPONENT_INFO*,AV_COMPONENT_INFO*>CMapComponentToID;
extern CMapComponentToID g_mapComponentID;
//外部函数声明
extern void RefreshCurrentNodeMatrixByState(AV_COMPONENT_INFO* pComponent,BOOL bUpdateNodeMatrix);
extern void RefreshCurrentNodeMatrixByPower(AV_COMPONENT_INFO* pComponent,BOOL bUpdateNodeMatrix);
/////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////内部使用函数/////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////
//由键值检索元件
AV_COMPONENT_INFO* GetComponentInfoByKey(AV_KEY_INFO* tagKey)
{
	if(!g_netModel.pComponentInfo) return NULL;

	AV_COMPONENT_INFO* pComponent = NULL;
	BOOL bFind = FALSE;
	for(int i=0; i<g_netModel.nComponentSum; i++)
	{
		if(_stricmp((g_netModel.pComponentInfo+i)->keyInfo.chKey,tagKey->chKey) == 0)
		{
			pComponent = g_netModel.pComponentInfo+i;
			bFind = TRUE;
			break;
		}
	}
	if(!bFind)
	{
		CString str(_T(""));
		str.Format(_T("网络模型中没有找到元件%s!"),tagKey->chKey);
		::MessageBox(AfxGetMainWnd()->GetSafeHwnd(),str,"提示::AVInfoKernel_GetComponentInfoByKey",MB_OK | MB_ICONEXCLAMATION | MB_ICONWARNING);
	}
	return pComponent;
}
//由内码检索元件
AV_COMPONENT_INFO* GetComponentInfoByID(AV_KEY_INFO* tagKey)
{
	AV_COMPONENT_INFO* pComponent = NULL;
	if(g_mapComponentID.Lookup(tagKey->nID,pComponent))
		return pComponent;
	else
	{
		CString str(_T(""));
		str.Format(_T("网络模型中没有找到元件%s!"),tagKey->chKey);
		::MessageBox(AfxGetMainWnd()->GetSafeHwnd(),str,"提示::AVInfoKernel_GetComponentInfoByID",MB_OK | MB_ICONEXCLAMATION | MB_ICONWARNING);
	}
	return NULL;
}
//由指定端子开始搜索
typedef CTypedPtrList<CPtrList, AV_RESULT_INFO*>CResultList;
static int g_nTagPortID = -1;
static CPtrArray g_arrayTagRecordset;
static CPtrArray g_arrayEndRecordset;
void SearchedComponentFromPort(AV_COMPONENT_INFO* pComponentLead,int nPortID,AV_SEARCH_INFO* pSearchInfo,CResultList* pResultList)
{
	if(!pComponentLead) return;
	AV_PORT_INFO* pPortInfo = pComponentLead->pPortInfo+nPortID;
	//连通性搜索忽略中性点端子(2003.11.24 for not proccess single port)
	if(pSearchInfo->nStateFlag == 1 && pPortInfo->nType == PORT_TYPE_SINGLE) return;
	for(int i=0; i<pPortInfo->nLinkSum; i++)
	{
		AV_COMPONENT_INFO* pComponentLinked = GetComponentInfoByID(pPortInfo->pKeyInfo+i);
		if(!pComponentLinked) continue;
		//已被搜索标志判断和置位
		if(pComponentLinked->bSearchedFlag) continue;
		pComponentLinked->bSearchedFlag = TRUE;
		//连通性搜索忽略中性点端子(2003.11.24 for not proccess single port)
		if(pSearchInfo->nStateFlag == 1)
		{
			//只对存在中性点的元件进行判断处理
			BOOL bFindSinglePort = FALSE;
			for(int j=0; j<pComponentLinked->nPortSum; j++)
			{
				if((pComponentLinked->pPortInfo+j)->nType == PORT_TYPE_SINGLE)
				{
					bFindSinglePort = TRUE;
					break;
				}
			}
			if(bFindSinglePort)
			{
				//如果所连元件仅仅只有中性点端子与该端子相连则忽略所连元件
				BOOL bFindNotSinglePortLink = FALSE;
				for(j=0; j<pComponentLinked->nPortSum; j++)
				{
					if((pComponentLinked->pPortInfo+j)->nType != PORT_TYPE_SINGLE)
					{
						for(int k=0; k<(pComponentLinked->pPortInfo+j)->nLinkSum; k++)
						{
							if(_stricmp(((pComponentLinked->pPortInfo+j)->pKeyInfo+k)->chKey,pComponentLead->keyInfo.chKey) == 0)
							{
								bFindNotSinglePortLink = TRUE;
								break;
							}
						}
					}
					if(bFindNotSinglePortLink) break;
				}
				if(!bFindNotSinglePortLink) continue;
			}
		}
		//先看是否是符合目标条件的元件,是则添加到结果列表中
		BOOL bTarget = TRUE;
		for(int j=0; j<pSearchInfo->nTagInfoCount; j++)
		{
			CString strSQL = " and " + CString((pSearchInfo->tagInfo+j)->chFieldKey) + " = " + "'" + CString(pComponentLinked->keyInfo.chKey) + "'";
			strSQL = "Select * from " + CString((pSearchInfo->tagInfo+j)->chTableName) + " where " + CString((pSearchInfo->tagInfo+j)->chFilter) + strSQL;
			if(!theApp.m_pDatabase) return;
			CRecordset* pTagSet = (CRecordset*)g_arrayTagRecordset.GetAt(j);
			if(!pTagSet) continue;
			TRY
			{
				pTagSet->Open(CRecordset::forwardOnly,strSQL);
			}
			CATCH(CDBException,e)
			{
				::MessageBox(AfxGetMainWnd()->GetSafeHwnd(),strSQL,"提示::AVInfoKernel_CheckYourSQL",MB_OK | MB_ICONEXCLAMATION | MB_ICONWARNING);
				bTarget = FALSE;
			}
			END_CATCH
			strSQL.Empty();
			if(pTagSet->IsEOF())
			{
				bTarget = FALSE;
				pTagSet->Close();
				break;
			}
			pTagSet->Close();
		}
		if(bTarget)
		{
			AV_RESULT_INFO* pNewResult = new AV_RESULT_INFO;
			memcpy(&pNewResult->keyInfo,&pComponentLinked->keyInfo,sizeof(AV_KEY_INFO));
			pNewResult->tagPortID = g_nTagPortID;
			pNewResult->pComoponent = NULL;
			pResultList->AddTail(pNewResult);
			if(pSearchInfo->nTargetFlag == 1) return;
		}
		//如果是连通性搜索并且元件拓扑状态为不连通则终止该支路搜索
		if(pSearchInfo->nStateFlag == 1 && pComponentLinked->nState != 1) continue;
		//再看是否是符合终止条件的元件,是则终止该支路的搜索,否则继续进行深度搜索
		BOOL bEnd = TRUE;
		for(int k=0; k<pSearchInfo->nEndInfoCount; k++)
		{
			CString strSQL = " and " + CString((pSearchInfo->endInfo+k)->chFieldKey) + " = " + "'" + CString(pComponentLinked->keyInfo.chKey) + "'";
			strSQL = "Select * from " + CString((pSearchInfo->endInfo+k)->chTableName) + " where " + CString((pSearchInfo->endInfo+k)->chFilter) + strSQL;
			if(!theApp.m_pDatabase) return;
			CRecordset* pEndSet = (CRecordset*)g_arrayEndRecordset.GetAt(k);
			if(!pEndSet) continue;
			TRY
			{
				pEndSet->Open(CRecordset::forwardOnly,strSQL);
			}
			CATCH(CDBException,e)
			{
				::MessageBox(AfxGetMainWnd()->GetSafeHwnd(),strSQL,"提示::AVInfoKernel_CheckYourSQL",MB_OK | MB_ICONEXCLAMATION | MB_ICONWARNING);
				bEnd = FALSE;
			}
			END_CATCH
			strSQL.Empty();
			if(pEndSet->IsEOF())
			{
				bEnd = FALSE;
				pEndSet->Close();
				break;
			}
			pEndSet->Close();
		}
		if(bEnd) continue;
		else
		{
			for(int m=0; m<pComponentLinked->nPortSum; m++)
				SearchedComponentFromPort(pComponentLinked,m,pSearchInfo,pResultList);
		}
	}
}
#ifdef _ADOVER
void SearchedComponentFromPortAdo(void* pDatabase,AV_COMPONENT_INFO* pComponentLead,int nPortID,AV_SEARCH_INFO* pSearchInfo,CResultList* pResultList)
{
	if(!pComponentLead) return;
	AV_PORT_INFO* pPortInfo = pComponentLead->pPortInfo+nPortID;
	//连通性搜索忽略中性点端子(2003.11.24 for not proccess single port)
	if(pSearchInfo->nStateFlag == 1 && pPortInfo->nType == PORT_TYPE_SINGLE) return;
	for(int i=0; i<pPortInfo->nLinkSum; i++)
	{
		AV_COMPONENT_INFO* pComponentLinked = GetComponentInfoByID(pPortInfo->pKeyInfo+i);
		if(!pComponentLinked) continue;
		//已被搜索标志判断和置位
		if(pComponentLinked->bSearchedFlag) continue;
		pComponentLinked->bSearchedFlag = TRUE;
		//连通性搜索忽略中性点端子(2003.11.24 for not proccess single port)
		if(pSearchInfo->nStateFlag == 1)
		{
			//只对存在中性点的元件进行判断处理
			BOOL bFindSinglePort = FALSE;
			for(int j=0; j<pComponentLinked->nPortSum; j++)
			{
				if((pComponentLinked->pPortInfo+j)->nType == PORT_TYPE_SINGLE)
				{
					bFindSinglePort = TRUE;
					break;
				}
			}
			if(bFindSinglePort)
			{
				//如果所连元件仅仅只有中性点端子与该端子相连则忽略所连元件
				BOOL bFindNotSinglePortLink = FALSE;
				for(j=0; j<pComponentLinked->nPortSum; j++)
				{
					if((pComponentLinked->pPortInfo+j)->nType != PORT_TYPE_SINGLE)
					{
						for(int k=0; k<(pComponentLinked->pPortInfo+j)->nLinkSum; k++)
						{
							if(_stricmp(((pComponentLinked->pPortInfo+j)->pKeyInfo+k)->chKey,pComponentLead->keyInfo.chKey) == 0)
							{
								bFindNotSinglePortLink = TRUE;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -