Files
coco df489d5640 a
2026-07-03 16:05:30 +08:00

485 lines
11 KiB
C++

// MediumE.cpp: implementation of the CMediumE class.
//
//////////////////////////////////////////////////////////////////////
#include "geomative.h"
#include "MediumE.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
extern BOOL DoEvent(HWND hWnd);
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CMediumE::CMediumE(int iAR): CMedium(iAR)
{
m_fEOffsetR = 0.5;
m_fLOffsetR = 0.5;
m_iParamIma = -1;
m_iParamImn = -1;
}
CMediumE::~CMediumE()
{
}
void CMediumE::SetParamVal(const void* pVal)
{
int* iParam = (int*)pVal;
if (iParam != NULL)
{
m_iParamIma = *iParam;
m_iParamImn = *(iParam + 1);
}
}
bool CMediumE::GenerateSptRecElecVal(int iEAmount, //锟界极锟斤拷锟斤拷---in
int* pMaxLevel, //锟斤拷锟斤拷---out
int* pPtAmount, //锟斤拷锟斤拷锟斤拷锟?--out
CPtrArray* pSptRecArray //锟脚憋拷锟斤拷录锟斤拷---out
) //锟斤拷锟斤拷锟杰o拷锟斤拷山疟锟斤拷缂拷锟铰硷拷锟斤拷锟?
{
int iEqualValMove = (int)VAL_ZERO;
int iMaxSpace = (int)VAL_ZERO;
int iSpace = (int)VAL_ZERO;
int iTsn = (int)VAL_ZERO;
int iAVal = (int)VAL_ZERO;
int iBVal = (int)VAL_ZERO;
int iMVal = (int)VAL_ZERO;
int iNVal = (int)VAL_ZERO;
int iMAVal = (int)VAL_ZERO;
int iMMVal = (int)VAL_ZERO;
int iMNVal = (int)VAL_ZERO;
int iMBVal = (int)VAL_ZERO;
int iMMove = (int)VAL_ZERO;
int iAMove = (int)VAL_ZERO;
int iTotalMove = (int)VAL_ZERO;
int iMaxLevel = (int)VAL_ZERO;
CSptRecord* pSptRecord = NULL;
CString str = _T("");
while ((iEAmount - iEqualValMove - 1) % 2)
{
iEqualValMove++;
}
//锟斤拷锟斤拷啾讹拷锟絠mn,锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟?
iMaxSpace = m_iParamImn;
//iMaxSpace = (iEAmount - iEqualValMove -1) / 2;
iTotalMove = iEAmount - 2;
int a = 1;
int iMa = 0;
if (iTotalMove > m_iParamIma)
{
iMa = m_iParamIma;
}
else
{
iMa = iTotalMove;
}
//AMN装锟斤拷
CString strLog;
iMBVal = -1;
int iTempMNVal = -1;
int iTempImn = -1;
int iLevel = 0;
int iLastA = 0;
int iCurA = 0;
int iMinLevel = 0;
stLevel_BMN stlevel;
strLog.Format(_T("MNB装置测点: A M N B level a n\n"));
OutputDebugString(strLog);
for (iMAVal = 1; iMAVal <= iTotalMove; iMAVal++)
{
iTempMNVal = -1;
for (a = 1; a <= m_iParamIma; a++)
{
for (iMMVal = iMAVal + 1; iMMVal <= 1 + iTotalMove; iMMVal++)
{
if (iTempMNVal != -1)
{
iMMVal = iTempMNVal;
}
iMNVal = iMMVal + a;
iTempImn = abs(iMAVal - iMMVal) / abs(iMMVal - iMNVal);
if ((iTempImn > m_iParamImn) || (iMNVal > iEAmount))
{
break;
}
iAVal = iMBVal;
iMVal = iEAmount + 1 - iMMVal;
iNVal = iEAmount + 1 - iMNVal;
iBVal = iEAmount + 1 - iMAVal;
iTempMNVal = iMNVal;
pSptRecord = NULL;
pSptRecord = new CSptRecord;
if (NULL != pSptRecord)
{
pSptRecord->m_iC1 = iAVal;
pSptRecord->m_iC2 = iBVal;
pSptRecord->m_iP1 = iMVal;
pSptRecord->m_iP2 = iNVal;
pSptRecord->m_iTsn = ++iTsn;
pSptRecord->m_fK = CalculateSptKVal(iBVal - iMVal, iBVal - iNVal);
//计算层次
if (iBVal == iEAmount)
{
iMinLevel++;
iLevel++;
//层次
stlevel.level = iLevel;
//第几大层
stlevel.a = abs(iMVal - iNVal);
if (iLastA == 0)
{
iLastA = stlevel.a;
}
//第几小层
stlevel.n = iMinLevel;
if (stlevel.a != iLastA)
{
iMinLevel = 1;
stlevel.n = iMinLevel;
iLastA = stlevel.a;
}
stlevel.fNValue = 1.0*abs(iBVal - iNVal) / abs(iMVal - iNVal);
m_mapLevel[iLevel] = stlevel;
}
else
{
float n = 1.0*abs(iBVal - iNVal) / abs(iMVal - iNVal);
std::map<int, stLevel_BMN>::iterator iter = m_mapLevel.begin();
for (; iter != m_mapLevel.end(); iter++)
{
if (iter->second.fNValue == n && iter->second.a == abs(iMVal - iNVal))
{
stlevel.a = iter->second.a;
stlevel.n = iter->second.n;
stlevel.level = iter->second.level;
break;
}
}
}
pSptRecord->m_a = stlevel.a;
pSptRecord->m_n = stlevel.n;
pSptRecord->m_iLevel = stlevel.level;
pSptRecord->m_iPtNum = iMVal;
pSptRecord->m_colorREF = RGB(0, 255, 0);
pSptRecord->m_bIsSel = TRUE;
pSptRecord->m_iN = (int)VAL_ONE;
strLog.Format(_T("BMN装置测点: %d %d %d %d %d %d %d\n"), iAVal, iBVal, iMVal, iNVal, pSptRecord->m_iLevel, pSptRecord->m_a, pSptRecord->m_n);
OutputDebugString(strLog);
pSptRecArray->Add(pSptRecord);
if (pSptRecord->m_iLevel > iMaxLevel)
{
iMaxLevel = pSptRecord->m_iLevel;
}
}
}
}
}
*pMaxLevel = iMaxLevel;
*pPtAmount = pSptRecArray->GetSize();
/*for (iMNVal = 2; iMNVal <= 1+iTotalMove; iMNVal++)
{
iMMVal = iMNVal-1;
iMBVal = iMNVal+1;
iMAVal = -1;
iMVal = iMMVal;
iNVal = iMNVal;
iBVal = iMBVal;
iAVal = iMAVal;
pSptRecord = NULL;
pSptRecord = new CSptRecord;
if (NULL != pSptRecord)
{
pSptRecord->m_iP1 = iMVal;
pSptRecord->m_iC1 = iAVal;
pSptRecord->m_iP2 = iNVal;
pSptRecord->m_iC2 = iBVal;
pSptRecord->m_iTsn = ++iTsn;
pSptRecord->m_fK = CalculateSptKVal(iMVal, iNVal);
pSptRecord->m_iLevel = CalculateSptLevel(iMVal, iNVal);
pSptRecord->m_iPtNum = iMVal;
pSptRecord->m_colorREF = RGB(0, 255, 0);
pSptRecord->m_bIsSel = TRUE;
pSptRecord->m_iN = (int)VAL_ONE;
pSptRecArray->Add(pSptRecord);
if (pSptRecord->m_iLevel > iMaxLevel)
{
iMaxLevel = pSptRecord->m_iLevel;
}
}
if (iMNVal < (iMaxSpace+1))
{
iAMove = iMNVal-1;
}
else
{
iAMove = iEAmount-iMNVal;
}
while (iAMove > 1)
{
iAVal = -1;
iBVal++;
iMVal--;
pSptRecord = NULL;
pSptRecord = new CSptRecord;
if (NULL != pSptRecord)
{
pSptRecord->m_iC1 = iAVal;
pSptRecord->m_iC2 = iBVal;
pSptRecord->m_iP1 = iMVal;
pSptRecord->m_iP2 = iNVal;
pSptRecord->m_iTsn = ++iTsn;
pSptRecord->m_fK = CalculateSptKVal(iMVal, iNVal);
pSptRecord->m_iLevel = CalculateSptLevel(iMVal, iNVal);
pSptRecord->m_iPtNum = iMVal;
pSptRecord->m_colorREF = RGB(0, 255, 0);
pSptRecord->m_bIsSel = TRUE;
pSptRecord->m_iN = (int)VAL_ONE;
pSptRecArray->Add(pSptRecord);
if (pSptRecord->m_iLevel > iMaxLevel)
{
iMaxLevel = pSptRecord->m_iLevel;
}
}
if (iMVal == 1 || iBVal == iEAmount)
{
break;
}
iAMove--;
}
}
*pMaxLevel = iMaxLevel;
*pPtAmount = pSptRecArray->GetSize();*/
return true;
}
float CMediumE::CalculateSptKVal(int iBM, int iBN)
{
float fK = (float)VAL_ZERO;
fK = (float)(2*VAL_PI/(1.0/iBN-1.0/iBM));
return fK;
}
float CMediumE::CalculateCESptKVal(float fA, float fB, float fX, float fY)
{
return 0.0;
}
int CMediumE::CalculateSptLevel(int iM, int iN)
{
return iN-iM;
}
void CMediumE::CalculateSptPtLoc(int iMul, //倍数---in
CSptRecord* pSptRecord //脚本记录指针---out
) //函数功能:计算脚本测点位置
{
int iOffsetL = (int)VAL_ZERO;
int iOffsetR = (int)VAL_ZERO;
int iLevel = pSptRecord->m_iLevel;
int iPtNum = pSptRecord->m_iPtNum;
iOffsetL = (6 + 2)*iMul + 50 + 4 * iMul*(iLevel - 3) + (iMul - 2);
if (pSptRecord->m_a == 1)
{
if (iLevel > 1 )
{
iOffsetL = (6 + 2)*iMul + 50 + 4 * iMul*(pSptRecord->m_n - 3) + (iMul - 2) - (pSptRecord->m_n - 1) * 8;
}
}
else
{
if (pSptRecord->m_n == 1)
{
iOffsetL = (6 + 2)*iMul + 50 + 4 * iMul*(pSptRecord->m_n - 3) + (iMul - 2);
}
else
{
iOffsetL = (6 + 2)*iMul + 50 + 4 * iMul*(pSptRecord->m_n - 3) + (iMul - 2) + (pSptRecord->m_n - 1) * 8;
}
}
iOffsetR = iOffsetL+6*iMul;
pSptRecord->m_recPtArea.left = iOffsetL+(6+2)*iMul*(iPtNum-1);
pSptRecord->m_recPtArea.top = 50+(6+2)*iMul*(iLevel-1);
pSptRecord->m_recPtArea.right = iOffsetR+(6+2)*iMul*(iPtNum-1);
pSptRecord->m_recPtArea.bottom = (50+6*iMul)+(6+2)*iMul*(iLevel-1);
pSptRecord->m_fPtCenterX = (float)(iOffsetL+(6+2)*iMul*(iPtNum-1) + ((iOffsetR+(6+2)*iMul*(iPtNum-1)) - (iOffsetL+(6+2)*iMul*(iPtNum-1))) / 2);
pSptRecord->m_fPtCenterY = (float)(50+(6+2)*iMul*(iLevel-1) + (((50+6*iMul)+(6+2)*iMul*(iLevel-1)) - (50+(6+2)*iMul*(iLevel-1))) / 2);
pSptRecord->m_fPtRadius = (float)(abs((int)(pSptRecord->m_fPtCenterX) - pSptRecord->m_recPtArea.left));
iOffsetL = 46 + (6 + 2) * iMul * (pSptRecord->m_fSptXPos - 1) - 3 * iMul;
iOffsetR = iOffsetL + 6 * iMul;
pSptRecord->m_recPtArea.left = iOffsetL;
pSptRecord->m_recPtArea.right = iOffsetR;
pSptRecord->m_fPtCenterX = (float)(iOffsetL + iOffsetR) / 2;
}
int CMediumE::CalculateRecPosInlevel(int iM)
{
return iM;
}
int CMediumE::GenSptRecLevel(int iA, int iB, int iM, int iN)
{
return CalculateSptLevel(iM, iN);
}
int CMediumE::GenSptRecPosInLevel(int iA, int iB, int iM, int iN)
{
return CalculateRecPosInlevel(iM);
}
int CMediumE::GetMaxLevelByEAmount(int iEAmount)
{
// if (((iEAmount%12) == 0) && (0 != iEAmount))
// {
// return 5+(iEAmount/12-1)*6;
// }
// return 0;
//根据排列来推算,假设最大层数为x,那么此时收个1+2x = iEAmount时,x即为最大层数
//由于x为整数,所以对此表达式取整即为最大层数
if (iEAmount > 0)
return (int)((iEAmount-1)/2);
else
return 0;
}
void CMediumE::ReSortPoint(CPtrArray *f_ptr)
{
CSptRecord* pSptRecord = NULL;
int nMidPos = 0; //第一层中点的起始位置
int nWidth = 0; //用于统计第一层有多少个测点
int *nPos = new int[f_ptr->GetSize()];
for (int n = 0;n < f_ptr->GetSize(); n++)
{
pSptRecord = (CSptRecord *)f_ptr->GetAt(n);
if (pSptRecord->m_iLevel == 1)
{
nPos[nWidth] = pSptRecord->m_iTsn; //把对应的TSN保存在数组中方便取出
nWidth++;
}
}
nMidPos = ( nWidth / 2 ); //将测点分成2个部分进行测试,从上一个斜线方向开始测
int FirStart = 0;
int SecStart = 0;
int Sum = 1; //tsn从1开始
FirStart = 0; //第一部分的起点位置
SecStart = nPos[nMidPos]; //第二部分的起点位置
CSptRecord *pTmp;
while(Sum < f_ptr->GetSize())
{
for (FirStart; FirStart < nPos[nMidPos] - 1; )
{
pSptRecord = (CSptRecord *)f_ptr->GetAt(FirStart);
pTmp = (CSptRecord *)f_ptr->GetAt(FirStart + 1);
pSptRecord->m_iTsn = Sum;
Sum++;
FirStart++;
if (pSptRecord->m_iLevel >= pTmp->m_iLevel)
break;
}
for (SecStart; SecStart < f_ptr->GetSize(); )
{
pSptRecord = (CSptRecord *)f_ptr->GetAt(SecStart - 1); //索引要减1
pTmp = (CSptRecord *)f_ptr->GetAt(SecStart);
pSptRecord->m_iTsn = Sum;
Sum++;
SecStart++;
if (pSptRecord->m_iLevel >= pTmp->m_iLevel)
break;
}
}
//对数组中的元素全部重新进行排序
for (int k = 0; k < f_ptr->GetSize(); k++)
{
pSptRecord = (CSptRecord *)f_ptr->GetAt(k);
if (pSptRecord->m_iTsn != k + 1)
{
for (int n = k + 1; n < f_ptr->GetSize(); n++)
{
pSptRecord = (CSptRecord *)f_ptr->GetAt(n);
if (pSptRecord->m_iTsn == k + 1)
{
f_ptr->InsertAt(k, pSptRecord);
f_ptr->RemoveAt(n + 1); //上一行代码插入一个元素,故 + 1;
break;
}
}
}
}
}