📄 jointlist.cpp
字号:
// JointList.cpp: implementation of the CJointList class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "pointtest.h"
#include "JointList.h"
#include "Component.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CJointList::CJointList()
{
m_pOldList=&m_pListJoint;
m_pCopyList=&m_copyListJoint;
m_pSaveList=&m_saveListJoint;
m_pSaveRealList = & m_saveRealList;
}
CJointList::~CJointList()
{
RemoveElList(&(m_pDiodeList));
RemoveAll(m_pOldList);
RemoveAll(m_pSaveList);
RemoveAll(m_pSaveRealList);
RemoveAll(m_pCopyList);
RemoveElList(&(m_VoltList));
RemoveElList(&(m_AmperList));
}
void CJointList::ClearUpAllList()
{
RemoveElList(&(m_pDiodeList));
RemoveAll(m_pOldList);
RemoveAll(m_pSaveList);
RemoveAll(m_pSaveRealList);
RemoveAll(m_pCopyList);
RemoveElList(&(m_VoltList));
RemoveElList(&(m_AmperList));
}
void CJointList::AddJoint(JointList *p,int order)
{
BOOL b;
POSITION pos;
if(p->IsEmpty())
{
b=false;
}
else
{
pos=p->GetHeadPosition();
while(pos!=NULL)
{
if((p->GetNext(pos))->GetOrder()==order)
{
b=true;
break;
}
else
{
b=false;
}
}
}
if(!b)
{
CAJoint *pJoint=new CAJoint(order);
pJoint->SetVoltage(0);
p->AddTail(pJoint);
}
}
void CJointList::RemoveJoint(CAJoint *pJoint,JointList *pList)
{
POSITION pos=pList->Find(pJoint,NULL);
pJoint=pList->GetAt(pos);
pList->RemoveAt(pos);
if(pJoint)
{
delete pJoint;
}
}
CAJoint* CJointList::GetJoint(int order,JointList *pList)
{
POSITION pos=pList->GetHeadPosition();
CAJoint *p;
while(pos!=NULL)
{
p=pList->GetNext(pos);
if(p->GetOrder()==order)
{
return p;
}
}
return NULL;
}
void CJointList::AdjustJoint(JointList *pList)
{
if(pList->IsEmpty())
{
return;
}
else
{
CAJoint *pJoint;
int i=1;
POSITION pos,sourcePos[10];
pos=pList->GetHeadPosition();
while(pos!=NULL)
{
pJoint=pList->GetAt(pos);
int b=pJoint->GetOrder();
// pJoint->SearchElecSource();
if(pJoint->IsHoldElecSource())
{
sourcePos[i]=pos;
i++;
}
pList->GetNext(pos);
}
for(int j=1;j<i;j++)
{
pList->RemoveAt(sourcePos[j]);//Is delete the power joint
}
}
}
void CJointList::CreateCopyJointList(JointList *pSourceList,JointList *pCopyList)
{
RegulateListAsOrder(pSourceList);
SetWorkedInList(false,pSourceList);
RemoveAll(pCopyList);
CAJoint *pJoint;
CAElement *pElement,*pNewElement;
int type;
float value;
BOOL bIsClose;
POSITION pos=pSourceList->GetHeadPosition();
while(pos!=NULL)
{
pJoint=pSourceList->GetNext(pos);
POSITION pos1=pJoint->pElementList.m_pListElement.GetHeadPosition();
while(pos1!=NULL)
{
pElement=pJoint->pElementList.m_pListElement.GetNext(pos1);
if(!(pElement->IsWorked()))
{
type=pElement->GetType();
if(type != ID_SWITCH)
{
value=pElement->GetValue();
pNewElement=NewElement(type,value);
}
else
{
bIsClose = pElement->IsClose();
pNewElement = NewSwitch(bIsClose);
}
CAJoint *p1,*p2;
p1=pElement->GetJointStruct()->pJoint1;
p2=pElement->GetJointStruct()->pJoint2;
int index = pElement->GetIndex();
pNewElement->SetIndex( index );
pNewElement->SetOrderStruct( p1->GetOrder(),p2->GetOrder() );
// p1->pElementList.AddElement(pNewElement);
int order1,order2;
order1=p1->GetOrder();
order2=p2->GetOrder();
AddJoint(pCopyList,order1);
AddJoint(pCopyList,order2);
pNewElement->SetStructJoint(GetJoint(order1,pCopyList),GetJoint(order2,pCopyList));
GetJoint(order1,pCopyList)->pElementList.AddElement(pNewElement);
GetJoint(order2,pCopyList)->pElementList.AddElement(pNewElement);
pElement->SetWorked(true);
}
}
}
RegulateListAsOrder(pCopyList);
}
POSITION CJointList::TwoLoop(POSITION pos,JointList *pList)
{
while(pos!=NULL)
{
CAJoint *pJoint=pList->GetAt(pos);
POSITION pos1=pos;
while(pos1!=NULL)
{
CAJoint *pJointNext=pList->GetAt(pos1);
if(pJoint->GetOrder()>pJointNext->GetOrder())
{
pList->RemoveAt(pos);
pos1=pList->Find(pJointNext,NULL);
pList->InsertAfter(pos1,pJoint);
return pos;
}
pList->GetNext(pos1);
}
pList->GetNext(pos);
}
return pos;
}
void CJointList::RegulateListAsOrder(JointList *pList)
{
POSITION pos;
pos=pList->GetHeadPosition();
while(pos!=NULL)
{
pos=TwoLoop(pos,pList);
if(pos!=NULL)
{
pos=pList->GetHeadPosition();
}
else
{
break;
}
}
}
void CJointList::RemoveAll(JointList *pList)
{
POSITION pos=pList->GetHeadPosition();
while(pos!=NULL)
{
CAJoint *pJoint=pList->GetNext(pos);
POSITION pos1=pJoint->pElementList.m_pListElement.GetHeadPosition();
while(pos1!=NULL)
{
CAElement *pElement=pJoint->pElementList.m_pListElement.GetNext(pos1);
CAJoint *p1,*p2,*pOther;
p1=pElement->GetJointStruct()->pJoint1;
p2=pElement->GetJointStruct()->pJoint2;
if(p1==pJoint)
{
pOther=p2;
}
else
{
pOther=p1;
}
POSITION pos3=pOther->pElementList.m_pListElement.GetHeadPosition();
while(pos3!=NULL)
{
CAElement *pElement1=pOther->pElementList.m_pListElement.GetAt(pos3);
if(pElement1==pElement)
{
pOther->pElementList.m_pListElement.RemoveAt(pos3);
break;
}
pOther->pElementList.m_pListElement.GetNext(pos3);
}
if(pElement)
{
delete pElement;
}
}
pJoint->pElementList.m_pListElement.RemoveAll();
if(pJoint)
{
delete pJoint;
}
}
pList->RemoveAll();
}
CAElement* CJointList::NewElement(int type, float value)
{
switch(type)
{
case ID_POWER:
return (new CAPower(value));
break;
case ID_RESISTANCE:
return (new CAResistance(value));
break;
case ID_CAPACITANCE:
return (new CACapacity(value));
break;
case ID_INDUCTANCE:
return (new CAInductor(value));
break;
// case ID_SWITCH:
// return (new CASwitch(BOOL(value)));
// break;
case ID_DIODE:
return (new CADiode());
break;
case ID_CURRENT_METER:
return (new CAAmpermeter());
break;
case ID_VOLTAGE_METER:
return (new CAVoltmeter());
break;
default:
return NULL;
break;
}
}
void CJointList::SetWorkedInList(BOOL b, JointList *pList)
{
CAJoint *pJoint;
POSITION pos=pList->GetHeadPosition();
while(pos!=NULL)
{
pJoint=pList->GetNext(pos);
CAElement *pElement;
POSITION pos1=pJoint->pElementList.m_pListElement.GetHeadPosition();
while(pos1!=NULL)
{
pElement=pJoint->pElementList.m_pListElement.GetNext(pos1);
pElement->SetWorked(b);
}
}
}
void CJointList::SetAllIsAllPowerInList(BOOL b,JointList *pList)
{
POSITION pos1=pList->GetHeadPosition();
while(pos1!=NULL)
{
CAJoint *pJoint=pList->GetNext(pos1);
CAElement *pElement;
POSITION pos2=pJoint->pElementList.m_pListElement.GetHeadPosition();
while(pos2!=NULL)
{
pElement=pJoint->pElementList.m_pListElement.GetNext(pos2);
pElement->SetIsAsPower(b);
}
}
}
void CJointList::SaveCapacityInList(JointList *pList,CList<CAElement*,CAElement*>*pCapaList)
{
POSITION posCapa=pCapaList->GetHeadPosition();
while(posCapa!=NULL)
{
CAElement *pCapa=pCapaList->GetNext(posCapa);
delete pCapa;
}
pCapaList->RemoveAll();
POSITION pos=pList->GetHeadPosition();
while(pos!=NULL)
{
CAJoint *pJoint=pList->GetNext(pos);
CAElement *pElement;
POSITION pos1=pJoint->pElementList.m_pListElement.GetHeadPosition();
while(pos1!=NULL)
{
pElement=pJoint->pElementList.m_pListElement.GetNext(pos1);
if(pElement->GetType()==ID_CAPACITANCE)
{
BOOL bIsAdd=false;
if(pCapaList->IsEmpty())
{
bIsAdd=false;
}
else
{
POSITION posIs=pCapaList->GetHeadPosition();
while(posIs!=NULL)
{
CAElement *pIs=pCapaList->GetNext(posIs);
if(pElement!=pIs)
{
bIsAdd=false;
}
else
{
bIsAdd=true;
break;
}
}
}
if(!bIsAdd)
{
pCapaList->AddTail(pElement);
}
}
}
}
}
void CJointList::AdjustCapacityInList(JointList *pList,CList<CAElement*,CAElement*>*pCapaList)
{
POSITION capaPos=pCapaList->GetHeadPosition();
while(capaPos!=NULL)
{
CAElement *pElement=pCapaList->GetNext(capaPos);
CAJoint *p1=pElement->GetJointStruct()->pJoint1;
CAJoint *p2=pElement->GetJointStruct()->pJoint2;
POSITION posCapa1=p1->pElementList.m_pListElement.Find(pElement,NULL);
POSITION posCapa2=p2->pElementList.m_pListElement.Find(pElement,NULL);
p1->pElementList.m_pListElement.RemoveAt(posCapa1);
p2->pElementList.m_pListElement.RemoveAt(posCapa2);
pElement->GetCapacityOrderList(p1)->RemoveAll();
pElement->GetCapacityOrderList(p2)->RemoveAll();
SearchEqualVoltageJoint(p1,pElement,pList);
SearchEqualVoltageJoint(p2,pElement,pList);
// delete pElement;
}
}
void CJointList::SearchEqualVoltageJoint(CAJoint *pJoint,CAElement *pCapa,JointList *pList)//search pJoint's equal voltage joint
{
int count=pJoint->pElementList.m_pListElement.GetCount();
CAJoint *pOtherJoint=pJoint;
while( count==1 && !pOtherJoint->IsHoldElecSource() )
{
POSITION pos1=pList->Find(pOtherJoint,NULL);
pList->RemoveAt(pos1);
pCapa->GetCapacityOrderList(pJoint)->AddTail(pOtherJoint->GetOrder());
CAElement *pElement=pOtherJoint->pElementList.m_pListElement.GetHead();
CAJoint *p11=pElement->GetJointStruct()->pJoint1;
CAJoint *p22=pElement->GetJointStruct()->pJoint2;
if(p11==pJoint)
{
pOtherJoint=p22;
}
else
{
pOtherJoint=p11;
}
POSITION pos=pOtherJoint->pElementList.m_pListElement.Find(pElement,NULL);
pOtherJoint->pElementList.m_pListElement.RemoveAt(pos);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -