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

📄 jointlist.cpp

📁 此程序实现了类似protel电路画图程序。
💻 CPP
📖 第 1 页 / 共 3 页
字号:
		delete pElement;
		count=pOtherJoint->pElementList.m_pListElement.GetCount();
		
	//		delete pOtherJoint;
		
	}
	pJoint->m_nEqualValueOrder=pOtherJoint->GetOrder();
	CAJoint* pInSave = GetJoint( pJoint->GetOrder(),m_pSaveList);
	pInSave->m_nEqualValueOrder = pOtherJoint->GetOrder();
}
void CJointList::RemoveAboutCapacity(JointList *pList,CList<CAElement*,CAElement*>*pCapaList)
{
	POSITION posCapa=pCapaList->GetHeadPosition();
	while(posCapa!=NULL)
	{
		CAElement *pCapa=pCapaList->GetNext(posCapa);
		CAJoint *p1=pCapa->GetJointStruct()->pJoint1;
		CAJoint *p2=pCapa->GetJointStruct()->pJoint2;
		CList<int,int>* OrderList1=pCapa->GetCapacityOrderList(p1);
		CList<int,int>* OrderList2=pCapa->GetCapacityOrderList(p2);
	}
}
void CJointList::AllElsToOthers(int type1,int type2,float value,JointList *pList)
{
	SetWorkedInList(false,pList);
	POSITION pos = pList->GetHeadPosition();
	while(pos != NULL)
	{
		CAJoint *pJoint = pList->GetNext(pos);
		POSITION posE = pJoint->pElementList.m_pListElement.GetHeadPosition();
		while(posE != NULL)
		{
			CAElement *pE = pJoint->pElementList.m_pListElement.GetNext(posE);
			if(pE->GetType() == type1)
			{
				OneElToOther(pE,type2,value);
				posE = pJoint->pElementList.m_pListElement.GetHeadPosition();
			}

		}
	//	pJoint->pElementList.AllElToOther(type1,type2,value);
	}
}
float CJointList::GetAverageOfResistance(JointList *pList)
{
	SetWorkedInList(false,pList);
	float fResistanceV=0;
	int nResistanceNum=0;
	POSITION posJ = pList->GetHeadPosition();
	while(posJ != NULL)
	{
		CAJoint *pJ = pList->GetNext(posJ);
		POSITION posE = pJ->pElementList.m_pListElement.GetHeadPosition();
		while(posE != NULL)
		{
			CAElement *pE = pJ->pElementList.m_pListElement.GetNext(posE);
			if(pE->GetType() == ID_RESISTANCE && !(pE->IsWorked()))
			{
				fResistanceV += pE->GetValue();
				nResistanceNum ++;
				pE->SetWorked(true);
			}
		}
	}
	if(nResistanceNum > 0)
	{
		return float(fResistanceV/nResistanceNum);
	}
	else
	{
		return 0;
	}
}

BOOL CJointList::IsExistSpecEl(int type, JointList *pList,ElementList *pElList)
{
	RemoveElList(pElList);
	SetWorkedInList(false,pList);
	POSITION posJ = pList->GetHeadPosition();
	while(posJ != NULL)
	{
		CAJoint *pJoint = pList->GetNext(posJ);
		POSITION posE = pJoint->pElementList.m_pListElement.GetHeadPosition();
		while(posE != NULL)
		{
			CAElement *pE = pJoint->pElementList.m_pListElement.GetNext(posE);
			if(pE->GetType() == type && !(pE->IsWorked()))
			{
				CAElement *pNewEl = NewElement(type,pE->GetValue());
				int index = pE->GetIndex();
				pNewEl->SetIndex( index );
				CAJoint* p1 = pE->GetJointStruct()->pJoint1;
				CAJoint* p2 = pE->GetJointStruct()->pJoint2;
				pNewEl->SetStructJoint(p1,p2);
				pNewEl->SetOrderStruct( p1->GetOrder(),p2->GetOrder() );
				pElList->AddTail(pNewEl);
				pE->SetWorked(true);
			}
		}
	}
	if(pElList->IsEmpty())
	{
		return false;
	}
	else
	{
		return true;
	}
}
void CJointList::RemoveElList(ElementList *pElList)
{
	POSITION pos = pElList->GetHeadPosition();
	while(pos != NULL)
	{
		CAElement *pE = pElList->GetAt(pos);
		pElList->RemoveAt(pos);
		delete pE;
		pos = pElList->GetHeadPosition();
	}
}


void CJointList::AdjustPloarityOfDiode(int nArrayPowerNum)
{
//	CreateCopyJointList(m_pCopyList,m_pOldList);
	POSITION posE = m_pDiodeList.GetHeadPosition();
	while(posE != NULL)
	{
		CAElement *pE = m_pDiodeList.GetAt(posE);
		int order1 = pE->GetJointStruct()->pJoint1->GetOrder();
		int order2 = pE->GetJointStruct()->pJoint2->GetOrder();
		CAJoint *p1InSave = GetJoint(order1,m_pSaveList);
		CAJoint *p2InSave = GetJoint(order2,m_pSaveList);
		CAJoint *p1InOld = GetJoint(order1,m_pOldList);
		CAJoint *p2InOld = GetJoint(order2,m_pOldList);
		CAElement *pEInOld = GetElement(pE,m_pOldList);
		if((p1InSave->m_fRealVoltage[nArrayPowerNum])< (p2InSave->m_fRealVoltage[nArrayPowerNum]))
		{
			m_pDiodeList.RemoveAt(posE);
			OneElToOther(pEInOld,ID_CAPACITANCE,1);
			CAElement* pEInSave = GetElement(pE,m_pSaveList);
			pEInSave->SetIsAsCapacity(true);
		}
		else
		{
			m_pDiodeList.RemoveAt(posE);
			OneElToOther(pEInOld,ID_INDUCTANCE,1);
			CAElement* pEInSave = GetElement(pE,m_pSaveList);
			pEInSave->SetIsAsInductor(true);
		}
		delete pE;
		posE = m_pDiodeList.GetHeadPosition();
	}
}



CAElement* CJointList::GetElement(CAElement* pE,JointList* pList)
{
	int index = pE->GetIndex();
	POSITION posJ = pList->GetHeadPosition();
	while( posJ != NULL )
	{
		CAJoint* pJ = pList->GetNext( posJ );
		POSITION posE = pJ->pElementList.m_pListElement.GetHeadPosition();
		while( posE != NULL )
		{
			CAElement* pEOther = pJ->pElementList.m_pListElement.GetNext( posE );
			if( index == pEOther->GetIndex() )
			{
				return pEOther;
			}
		}
	}
	return NULL;
/*	POSITION pos = p1->pElementList.m_pListElement.GetHeadPosition();
	while(pos != NULL)
	{
		CAElement *pE = p1->pElementList.m_pListElement.GetNext(pos);
		CAJoint *p11,*p22;
		p11 = pE->GetJointStruct()->pJoint1;
		p22 = pE->GetJointStruct()->pJoint2;
		int order1 = p1->GetOrder();
		int order2 = p2->GetOrder();
		int order11 = p11->GetOrder();
		int order22 = p22->GetOrder();
		if(order11 == order1 && order22 == order2)
		{
			return pE;
		}
		else if(order11 == order2 && order22 == order1)
		{
			return pE;
		}
	}
	return NULL;*/
}

void CJointList::SetZeroVoltage(int nArrayPowerNum, JointList *pList)
{
	POSITION pos = pList->GetHeadPosition();
	while(pos != NULL)
	{
		CAJoint *pJ = pList->GetNext(pos);
		pJ->m_fRealVoltage[nArrayPowerNum] = 0;
		pJ->m_fVoltage[nArrayPowerNum] = 0;
	}
}

void CJointList::OneElToOther(CAElement *pE, int type, float value)
{
	CAJoint *p1 = pE->GetJointStruct()->pJoint1;
	CAJoint *p2 = pE->GetJointStruct()->pJoint2;
	CAElement *pNewEl = NewElement(type,value);
	pNewEl->SetStructJoint(p1,p2);
	int index = pE->GetIndex();
	pNewEl->SetIndex( index );
	pNewEl->SetOrderStruct( p1->GetOrder(),p2->GetOrder() );
	POSITION posDel1 = p1->pElementList.m_pListElement.Find(pE);
	POSITION posDel2 = p2->pElementList.m_pListElement.Find(pE);
	p1->pElementList.m_pListElement.RemoveAt(posDel1);
	p2->pElementList.m_pListElement.RemoveAt(posDel2);
	p1->pElementList.m_pListElement.AddTail(pNewEl);
	p2->pElementList.m_pListElement.AddTail(pNewEl);
	delete pE;
	
}

void CJointList::DealWithSwitch(JointList *pList)
{
	POSITION posJ = pList->GetHeadPosition();
	while(posJ != NULL)
	{
		CAJoint* pJ = pList->GetNext(posJ);
		POSITION posE = pJ->pElementList.m_pListElement.GetHeadPosition();
		while(posE != NULL)
		{
			CAElement* pE = pJ->pElementList.m_pListElement.GetNext(posE);
			if(pE->GetType() == ID_SWITCH)
			{
				CAElement* pNewE;
				if(pE->IsClose())
				{
					pNewE = NewElement(ID_INDUCTANCE,1);
					CAElement* pEInSave = GetElement(pE,m_pSaveList);
					pEInSave->SetIsAsInductor(true);
				}
				else
				{
					pNewE = NewElement(ID_CAPACITANCE,1);
					CAElement* pEInSave = GetElement(pE,m_pSaveList);
					pEInSave->SetIsAsCapacity(true);
				}
				CAJoint* p1 = pE->GetJointStruct()->pJoint1;
				CAJoint* p2 = pE->GetJointStruct()->pJoint2;
				int index   = pE->GetIndex();
				pNewE->SetIndex( index );
				pNewE->SetOrderStruct( p1->GetOrder(),p2->GetOrder() );
				POSITION posDel1 = p1->pElementList.m_pListElement.Find(pE,NULL);
				POSITION posDel2 = p2->pElementList.m_pListElement.Find(pE,NULL);
				p1->pElementList.m_pListElement.RemoveAt(posDel1);
				p2->pElementList.m_pListElement.RemoveAt(posDel2);
				delete pE;
				pNewE->SetStructJoint(p1,p2);
				p1->pElementList.m_pListElement.AddTail(pNewE);
				p2->pElementList.m_pListElement.AddTail(pNewE);
				posE = pJ->pElementList.m_pListElement.GetHeadPosition();
			}
		}
	}
}

CAElement* CJointList::NewSwitch(BOOL bIsClose)
{
	return (new CASwitch(bIsClose));
}

void CJointList::DealWithAmpermeter(JointList *pList)
{
	POSITION posJ = pList->GetHeadPosition();
	while(posJ != NULL)
	{
		CAJoint* pJ = pList->GetNext(posJ);
		POSITION posE = pJ->pElementList.m_pListElement.GetHeadPosition();
		while(posE != NULL)
		{
			CAElement* pE = pJ->pElementList.m_pListElement.GetNext(posE);
			if(pE->GetType() == ID_CURRENT_METER)
			{
				CAElement* pNewE = NewElement(ID_INDUCTANCE,1);
				CAElement* pEInSave = GetElement(pE,m_pSaveList);
				pEInSave->SetIsAsInductor(true);
				CAJoint* p1 = pE->GetJointStruct()->pJoint1;
				CAJoint* p2 = pE->GetJointStruct()->pJoint2;
				int index   = pE->GetIndex();
				pNewE->SetIndex( index );
				pNewE->SetOrderStruct( p1->GetOrder(),p2->GetOrder() );
				POSITION posDel1 = p1->pElementList.m_pListElement.Find(pE,NULL);
				POSITION posDel2 = p2->pElementList.m_pListElement.Find(pE,NULL);
				p1->pElementList.m_pListElement.RemoveAt(posDel1);
				p2->pElementList.m_pListElement.RemoveAt(posDel2);
				delete pE;
				pNewE->SetStructJoint(p1,p2);
				p1->pElementList.m_pListElement.AddTail(pNewE);
				p2->pElementList.m_pListElement.AddTail(pNewE);
				posE = pJ->pElementList.m_pListElement.GetHeadPosition();
			}
		}
	}
}

void CJointList::DealWithVoltmeter(JointList *pList)
{
	POSITION posJ = pList->GetHeadPosition();
	while(posJ != NULL)
	{
		CAJoint* pJ = pList->GetNext(posJ);
		POSITION posE = pJ->pElementList.m_pListElement.GetHeadPosition();
		while(posE != NULL)
		{
			CAElement* pE = pJ->pElementList.m_pListElement.GetNext(posE);
			if(pE->GetType() == ID_VOLTAGE_METER)
			{
				CAElement *pNewE = NewElement(ID_CAPACITANCE,1);
				CAElement *pEInSave = GetElement(pE,m_pSaveList);
				pEInSave->SetIsAsCapacity(true);
				CAJoint* p1 = pE->GetJointStruct()->pJoint1;
				CAJoint* p2 = pE->GetJointStruct()->pJoint2;
				int index   = pE->GetIndex();
				pNewE->SetIndex( index );
				pNewE->SetOrderStruct( p1->GetOrder(),p2->GetOrder() );
				POSITION posDel1 = p1->pElementList.m_pListElement.Find(pE,NULL);
				POSITION posDel2 = p2->pElementList.m_pListElement.Find(pE,NULL);
				p1->pElementList.m_pListElement.RemoveAt(posDel1);
				p2->pElementList.m_pListElement.RemoveAt(posDel2);
				delete pE;
				pNewE->SetStructJoint(p1,p2);
				p1->pElementList.m_pListElement.AddTail(pNewE);
				p2->pElementList.m_pListElement.AddTail(pNewE);
				posE = pJ->pElementList.m_pListElement.GetHeadPosition();
			}
		}
	}
}

void CJointList::SetVoltmeterValue(JointList *pList)
{
	POSITION posJ = pList->GetHeadPosition();
	while(posJ != NULL)
	{
		CAJoint* pJ = pList->GetNext(posJ);
		POSITION posE = pJ->pElementList.m_pListElement.GetHeadPosition();
		while(posE != NULL)
		{
			CAElement* pE = pJ->pElementList.m_pListElement.GetNext(posE);
			if(pE->GetType() == ID_VOLTAGE_METER)
			{
				CAJoint* p1 = pE->GetJointStruct()->pJoint1;
				CAJoint* p2 = pE->GetJointStruct()->pJoint2;
				float v = p2->GetVoltage()-p1->GetVoltage();
				pE->SetVoltage(v);
			}
		}
	}
}
void CJointList::SetVoltmeterCurrent(CAElement* pVoltmeter,CAJoint* p)
{
	pVoltmeter->SetCurrent(0);
}
void CJointList::SetAmpermeterCurrent(CAElement* pAmper,CAJoint* p)
{
	float i = 0;
	CAJoint* p1 = pAmper->GetJointStruct()->pJoint1;
	CAJoint* p2 = pAmper->GetJointStruct()->pJoint2;
	CAJoint* pOther;
	if(p1 == p) pOther = p2;
	else		pOther = p1;
	POSITION posE = pOther->pElementList.m_pListElement.GetHeadPosition();
	while(posE != NULL)
	{
		CAElement* pE = pOther->pElementList.m_pListElement.GetNext(posE);
		if(!pE->IsWorked() && pE!=pAmper)
		{
			SetSpecialElCurrent(pE,pOther);
		}
		if( pE != pAmper )
		{
			if((pE->IsTheP1Joint( pOther ) && !pAmper->IsTheP1Joint( pOther ))
			|| (!pE->IsTheP1Joint( pOther ) && pAmper->IsTheP1Joint( pOther )))
			{
				i += pE->GetCurrent();
			}
			else if(( pE->IsTheP1Joint( pOther ) && pAmper->IsTheP1Joint( pOther ))
				 || ( !pE->IsTheP1Joint( pOther ) && !pAmper->IsTheP1Joint( pOther )))
			{
				i += -pE->GetCurrent();
			}
		}
	//	i += pE->GetCurrent();
	}
	pAmper->SetWorked(true);
	pAmper->SetCurrent(i);
}

void CJointList::SetAllElCurrent(JointList *pList)
{
	SetWorkedInList(false,pList);
	POSITION posJ = pList->GetHeadPosition();
	while(posJ != NULL)
	{
		CAJoint* pJ = pList->GetNext(posJ);
		POSITION posE = pJ->pElementList.m_pListElement.GetHeadPosition();
		while(posE != NULL)
		{
			CAElement* pE = pJ->pElementList.m_pListElement.GetNext(posE);
			if(!pE->IsWorked())
			{
				SetSpecialElCurrent(pE,pJ);
			}
		}
	}
}
void CJointList::SetSwitchCurrent(CAElement* pSwitch,CAJoint* p)
{
	float i = 0;
	BOOL IsClose = pSwitch->IsClose();
	if(IsClose)
	{
		CAJoint* p1 = pSwitch->GetJointStruct()->pJoint1;
		CAJoint* p2 = pSwitch->GetJointStruct()->pJoint2;
		CAJoint* pOther;
		if(p1 == p) pOther = p2;
		else		pOther = p1;

⌨️ 快捷键说明

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