📄 topology.cpp
字号:
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(!pDatabase) return;
CAdoRecordSet* pTagSet = (CAdoRecordSet*)g_arrayTagRecordset.GetAt(j);
if(!pTagSet) continue;
if(pTagSet->Open(strSQL,adCmdText,adOpenForwardOnly,adLockReadOnly) == -1)
{
::MessageBox(AfxGetMainWnd()->GetSafeHwnd(),strSQL,"提示::AVInfoKernel_CheckYourSQL",MB_OK | MB_ICONEXCLAMATION | MB_ICONWARNING);
bTarget = FALSE;
}
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(!pDatabase) return;
CAdoRecordSet* pEndSet = (CAdoRecordSet*)g_arrayEndRecordset.GetAt(k);
if(!pEndSet) continue;
if(pEndSet->Open(strSQL,adCmdText,adOpenForwardOnly,adLockReadOnly) == -1)
{
::MessageBox(AfxGetMainWnd()->GetSafeHwnd(),strSQL,"提示::AVInfoKernel_CheckYourSQL",MB_OK | MB_ICONEXCLAMATION | MB_ICONWARNING);
bEnd = FALSE;
}
strSQL.Empty();
if(pEndSet->IsEOF())
{
bEnd = FALSE;
pEndSet->Close();
break;
}
pEndSet->Close();
}
if(bEnd) continue;
else
{
for(int m=0; m<pComponentLinked->nPortSum; m++)
SearchedComponentFromPortAdo(pDatabase,pComponentLinked,m,pSearchInfo,pResultList);
}
}
}
CStringList g_listTagKey;
CStringList g_listEndKey;
void SearchedComponentFromPortInSingleTable(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;//wxg20070129 非连通搜时也应该忽略
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;
}
}
//先看是否是符合目标条件的元件,是则添加到结果列表中
if(g_listTagKey.Find(pComponentLinked->keyInfo.chKey))
{
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;
//再看是否是符合终止条件的元件,是则终止该支路的搜索,否则继续进行深度搜索
if(g_listEndKey.Find(pComponentLinked->keyInfo.chKey))
continue;
else
{
for(int m=0; m<pComponentLinked->nPortSum; m++)
SearchedComponentFromPortInSingleTable(pDatabase,pComponentLinked,m,pSearchInfo,pResultList);
}
}
}
#endif
/////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////接口函数///////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////
/*****************************************************************************
【函数名称】 AVGetComponentPortInfo(AV_KEY_INFO* tagKey,AV_PORT_INFO** pPortInfo,int* nSum)
【函数功能】 获取指定键值元件的端子信息
【输入参数】 [in]tagKey指定元件键值
[in]bInit是否系统初始化
【输出参数】 [out]pPortInfo返回的端子信息(二次开发者不能释放)
[out]nSum端子数目
*****************************************************************************/
AV_EXPORT USHORT AVGetComponentPortInfo(AV_KEY_INFO* tagKey,AV_PORT_INFO** pPortInfo,int* nSum)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
*pPortInfo = NULL;
*nSum = 0;
if(!g_netModel.pComponentInfo) return AVERR_NOT_FOUND;
AV_COMPONENT_INFO* pComponent = NULL;
pComponent = GetComponentInfoByID(tagKey);
if(!pComponent) return AVERR_NOT_FOUND;
*pPortInfo = pComponent->pPortInfo;
*nSum = pComponent->nPortSum;
return AV_NO_ERR;
}
/*****************************************************************************
【函数名称】 AVGetNetNodeInfo(int nNodeID,AV_NODE_INFO** pNodeInfo,BOOL bInit)
【函数功能】 获取指定节点的节点信息
【输入参数】 [in]nNodeID指定节点编号
[in]bInit是否系统初始化
【输出参数】 [out]pNodeInfo节点信息结构(二次开发者不能释放)
*****************************************************************************/
AV_EXPORT USHORT AVGetNetNodeInfo(int nNodeID,AV_NODE_INFO** pNodeInfo)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
if(g_netModel.nNodeSum <= 0) return AVERR_OVER;
if(nNodeID < 0 || nNodeID >= g_netModel.nNodeSum) return AVERR_OVER;
*pNodeInfo = (g_netModel.pNodeInfo+nNodeID);
return AV_NO_ERR;
}
/*****************************************************************************
【函数名称】 AVSetComponentTagVal(AV_KEY_INFO* tagKey,char* prefix,char* suffix,AV_TAG_VALUE* pValue)
【函数功能】 设置元件相关标记值(更新图形动态属性显示)
【输入参数】 [in]tagKey元件检索键,value元件相关标记值,prefix,suffix分别为元件相关标记命名前缀和后缀
【输出参数】 无
*****************************************************************************/
AV_EXPORT USHORT AVSetComponentTagVal(AV_KEY_INFO* tagKey,char* prefix,char* suffix,AV_TAG_VALUE* pValue)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
CString str(tagKey->chKey);
if(prefix && strlen(prefix) > 0) str = CString(prefix) + str;
if(suffix && strlen(suffix) > 0) str = str + _T("_") + CString(suffix);
if(str.GetLength() >= TAGNAME_LENGTH+8) return AVERR_BAD_PARAM;//wxg+8 [_State]
AV_TAG_NAME tagName;
strcpy((char*)tagName,str.GetBuffer(str.GetLength()));
str.ReleaseBuffer();
::AVSetTagValByName(tagName,pValue);
return AV_NO_ERR;
}
/*****************************************************************************
【函数名称】 AV_EXPORT USHORT AVSetComponentState(AV_KEY_INFO* tagKey,int nState,BOOL bUpdateNodeMatrix)
【函数功能】 设置元件状态(更新网络分析模型中的元件状态)
【输入参数】 [in]tagKey元件检索键,nState状态值,bUpdateNodeMatrix是否要刷新节点矩阵
【输出参数】 无
*****************************************************************************/
AV_EXPORT USHORT AVSetComponentState(AV_KEY_INFO* tagKey,int nState,BOOL bUpdateNodeMatrix)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
AV_COMPONENT_INFO* pComponent = GetComponentInfoByID(tagKey);
if(!pComponent) return AVERR_NOT_FOUND;
if(pComponent->nState != nState)
{
pComponent->nState = nState;
RefreshCurrentNodeMatrixByState(pComponent,bUpdateNodeMatrix);
}
return AV_NO_ERR;
}
/*****************************************************************************
【函数名称】 AVSetComponentPower(AV_KEY_INFO* tagKey,int nPower,BOOL bUpdateNodeMatrix)
【函数功能】 设置元件入口状态(如是否电源,水源,气源等)
【输入参数】 [in]tagKey元件检索键,nPower是否入口元件标志,bUpdateNodeMatrix是否要刷新节点矩阵
【输出参数】 无
*****************************************************************************/
AV_EXPORT USHORT AVSetComponentPower(AV_KEY_INFO* tagKey,int nPower,BOOL bUpdateNodeMatrix)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
AV_COMPONENT_INFO* pComponent = GetComponentInfoByID(tagKey);
if(!pComponent) return AVERR_NOT_FOUND;
if(pComponent->nPower != nPower)
{
pComponent->nPower = nPower;
RefreshCurrentNodeMatrixByPower(pComponent,bUpdateNodeMatrix);
}
return AV_NO_ERR;
}
/*****************************************************************************
【函数名称】 AVSearchComponent(AV_SEARCH_INFO* infoSearch,AV_RESULT_INFO** resultInfo,int* nSum)
【函数功能】 从调用者指定的起始元件开始,搜索符合若干指定检索条件的元件,搜索过程也在若干指定的条件下结束
【输入参数】 终止条件或目标条件infoSearch
【输出参数】 搜索到的目标对象结果resultInfo以及目标对象数目nSum(resultInfo由二次开发者释放)
*****************************************************************************/
AV_EXPORT USHORT AVSearchComponent(AV_SEARCH_INFO* infoSearch,AV_RESULT_INFO** resultInfo,int* nSum)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
//初始化结果数据
*resultInfo = NULL;
*nSum = 0;
//搜索标志复位
for(int i=0; i<g_netModel.nComponentSum; i++)
(g_netModel.pComponentInfo+i)->bSearchedFlag = FALSE;
//首先定位元件信息体
AV_COMPONENT_INFO* pComponentStart = NULL;
pComponentStart = GetComponentInfoByID(&infoSearch->keyInfo);
if(pComponentStart == NULL) return AVERR_NOT_FOUND;
pComponentStart->bSearchedFlag = TRUE;
//性能优化
g_arrayTagRecordset.RemoveAll();
g_arrayEndRecordset.RemoveAll();
if(theApp.m_pDatabase)
{
for(i=0; i<infoSearch->nTagInfoCount; i++)
{
CRecordset* pTagRecordset = new CRecordset(theApp.m_pDatabase);
g_arrayTagRecordset.Add(pTagRecordset);
}
for(i=0; i<infoSearch->nEndInfoCount; i++)
{
CRecordset* pEndRecordset = new CRecordset(theApp.m_pDatabase);
g_arrayEndRecordset.Add(pEndRecordset);
}
}
//开始进行搜索
CResultList resultList;
if(infoSearch->refPortID == -1)
{
for(int i=0; i<pComponentStart->nPortSum; i++)
{
g_nTagPortID = i;
SearchedComponentFromPort(pComponentStart,i,infoSearch,&resultList);
if(infoSearch->nTargetFlag == 1 && resultList.GetCount() > 0) break;
}
}
else
{
if(infoSearch->refPortID < 0 || infoSearch->refPortID >= pComponentStart->nPortSum)
return AVERR_OVER;
g_nTagPortID = infoSearch->refPortID;
SearchedComponentFromPort(pComponentStart,infoSearch->refPortID,infoSearch,&resultList);
}
//输出结果
*nSum = resultList.GetCount();
if(*nSum <= 0) return AVERR_NOT_FOUND;
*resultInfo = new AV_RESULT_INFO[*nSum];
i = 0;
POSITION pos = resultList.GetHeadPosition();
while(pos)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -