362 lines
8.4 KiB
C++
362 lines
8.4 KiB
C++
// MediumD.cpp: implementation of the CMediumD class.
|
|
//
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
#include "geomative.h"
|
|
#include "MediumD.h"
|
|
|
|
#ifdef _DEBUG
|
|
#undef THIS_FILE
|
|
static char THIS_FILE[]=__FILE__;
|
|
#define new DEBUG_NEW
|
|
#endif
|
|
|
|
extern BOOL DoEvent(HWND hWnd);
|
|
//////////////////////////////////////////////////////////////////////
|
|
// Construction/Destruction
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
CMediumD::CMediumD(int iAR): CMedium(iAR)
|
|
{
|
|
m_fEOffsetR = 0.5;
|
|
m_fLOffsetR = 0.5;
|
|
m_iParamIma = -1;
|
|
m_iParamImn = -1;
|
|
}
|
|
|
|
CMediumD::~CMediumD()
|
|
{
|
|
|
|
}
|
|
|
|
void CMediumD::SetParamVal(const void* pVal)
|
|
{
|
|
int* iParam = (int*)pVal;
|
|
if (iParam != NULL)
|
|
{
|
|
m_iParamIma = *iParam;
|
|
m_iParamImn = *(iParam + 1);
|
|
}
|
|
}
|
|
|
|
bool CMediumD::GenerateSptRecElecVal(int iEAmount, //电极总数---in
|
|
int* pMaxLevel, //最大层---out
|
|
int* pPtAmount, //测点总数---out
|
|
CPtrArray* pSptRecArray //脚本记录集---out
|
|
) //函数功能:生成脚本电极记录集合
|
|
{
|
|
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 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 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++;
|
|
}
|
|
|
|
//最大间距倍数imn,界面输入参数
|
|
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;
|
|
int iTempMNVal = -1;
|
|
int iTempImn = -1;
|
|
int iLevel = 0;
|
|
strLog.Format(_T("AMN装置测点: A B M N level\n"));
|
|
OutputDebugString(strLog);
|
|
stLevel stlevel;
|
|
|
|
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 = iMAVal;
|
|
iMVal = iMMVal;
|
|
iNVal = iMNVal;
|
|
iTempMNVal = iMNVal;
|
|
|
|
pSptRecord = NULL;
|
|
pSptRecord = new CSptRecord;
|
|
if (NULL != pSptRecord)
|
|
{
|
|
pSptRecord->m_iC1 = iAVal;
|
|
pSptRecord->m_iC2 = -1;
|
|
pSptRecord->m_iP1 = iMVal;
|
|
pSptRecord->m_iP2 = iNVal;
|
|
pSptRecord->m_iTsn = ++iTsn;
|
|
pSptRecord->m_fK = CalculateSptKVal(iMVal - iAVal, iNVal - iAVal);
|
|
|
|
//计算层次
|
|
if (iAVal == 1)
|
|
{
|
|
iLevel++;
|
|
//层次
|
|
stlevel.level = iLevel;
|
|
//第几大层
|
|
stlevel.a = abs(iMVal - iNVal);
|
|
//第几小层
|
|
stlevel.n = 1.0*abs(iAVal - iMVal) / abs(iMVal - iNVal);
|
|
m_mapLevel[iLevel] = stlevel;
|
|
}
|
|
else
|
|
{
|
|
float n = 1.0*abs(iAVal - iMVal) / abs(iMVal - iNVal);
|
|
std::map<int, stLevel>::iterator iter = m_mapLevel.begin();
|
|
for (; iter != m_mapLevel.end(); iter++)
|
|
{
|
|
if (iter->second.n == n && iter->second.a == abs(iMVal - iNVal))
|
|
{
|
|
iLevel = iter->second.level;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
pSptRecord->m_iLevel = iLevel;//CalculateSptLevel(iMVal, iNVal);
|
|
pSptRecord->m_iPtNum = iAVal;
|
|
pSptRecord->m_colorREF = RGB(0, 255, 0);
|
|
pSptRecord->m_bIsSel = TRUE;
|
|
|
|
pSptRecord->m_iN = (int)VAL_ONE;
|
|
strLog.Format(_T("AMN装置测点: %d %d %d %d %d\n"), iAVal, -1, iMVal, iNVal, pSptRecord->m_iLevel);
|
|
OutputDebugString(strLog);
|
|
pSptRecArray->Add(pSptRecord);
|
|
|
|
if (pSptRecord->m_iLevel > iMaxLevel)
|
|
{
|
|
iMaxLevel = pSptRecord->m_iLevel;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
*pMaxLevel = iMaxLevel;
|
|
|
|
*pPtAmount = pSptRecArray->GetSize();
|
|
/*for (iMMVal = 2; iMMVal <= 1+iTotalMove; iMMVal++)
|
|
{
|
|
if (iMMVal <= (iMaxSpace + 1))
|
|
{
|
|
iMAVal = 1;
|
|
iSpace++;
|
|
}
|
|
else if ((iMMVal > (iMaxSpace + 1)) && (iMMVal <= ((iMaxSpace + 1)+iEqualValMove)))
|
|
{
|
|
iSpace = iMaxSpace;
|
|
iMAVal = iMMVal-iSpace;
|
|
}
|
|
else if (iMMVal > ((iMaxSpace + 1)+iEqualValMove))
|
|
{
|
|
if (iMNVal == iEAmount)
|
|
{
|
|
iSpace--;
|
|
}
|
|
iMAVal = iMMVal-iSpace;
|
|
}
|
|
iMNVal = iMMVal+iSpace;
|
|
iMBVal = -1;
|
|
|
|
iAVal = iMAVal;
|
|
iMVal = iMMVal;
|
|
iNVal = iMNVal;
|
|
iBVal = iMBVal;
|
|
|
|
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(iAVal, iMVal);
|
|
|
|
pSptRecord->m_iLevel = CalculateSptLevel(iMVal, iNVal);
|
|
pSptRecord->m_iPtNum = iAVal;
|
|
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;
|
|
}
|
|
|
|
}
|
|
|
|
iAMove = iMVal - iAVal;
|
|
while (iAMove > 1)
|
|
{
|
|
iAVal++;
|
|
iNVal--;
|
|
iBVal = -1;
|
|
iAMove--;
|
|
|
|
pSptRecord = NULL;
|
|
pSptRecord = new CSptRecord;
|
|
|
|
if (NULL != pSptRecord)
|
|
{
|
|
pSptRecord->m_iC1 = iAVal;
|
|
pSptRecord->m_iC2 = -1;
|
|
pSptRecord->m_iP1 = iMVal;
|
|
pSptRecord->m_iP2 = iNVal;
|
|
pSptRecord->m_iTsn = ++iTsn;
|
|
pSptRecord->m_fK = CalculateSptKVal(iAVal, iMVal);
|
|
|
|
pSptRecord->m_iLevel = CalculateSptLevel(iMVal, iNVal);
|
|
pSptRecord->m_iPtNum = iAVal;
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
*pMaxLevel = iMaxLevel;
|
|
|
|
*pPtAmount = pSptRecArray->GetSize();*/
|
|
|
|
return true;
|
|
}
|
|
|
|
float CMediumD::CalculateSptKVal(int iAM, int iAN)
|
|
{
|
|
float fK = (float)VAL_ZERO;
|
|
fK = (float)(2*VAL_PI/(1.0/iAM-1.0/iAN));
|
|
|
|
return fK;
|
|
}
|
|
|
|
float CMediumD::CalculateCESptKVal(float fA, float fB, float fX, float fY)
|
|
{
|
|
return 0.0;
|
|
}
|
|
|
|
int CMediumD::CalculateSptLevel(int iM, int iN)
|
|
{
|
|
return iN-iM;
|
|
}
|
|
|
|
void CMediumD::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-1)*3+(iMul-2);
|
|
if (iLevel > 1)
|
|
{
|
|
iOffsetL = (6 + 2)*iMul + 50 + 4 * iMul*(iLevel - 1) * 3 + (iMul - 2)-(iLevel-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 CMediumD::CalculateRecPosInlevel(int iA)
|
|
{
|
|
return iA;
|
|
}
|
|
|
|
int CMediumD::GenSptRecLevel(int iA, int iB, int iM, int iN)
|
|
{
|
|
return CalculateSptLevel(iM, iN);
|
|
}
|
|
|
|
int CMediumD::GenSptRecPosInLevel(int iA, int iB, int iM, int iN)
|
|
{
|
|
//AMN的点的位置选取的是MN的中点
|
|
return CalculateRecPosInlevel(iM);
|
|
}
|
|
|
|
int CMediumD::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;
|
|
} |