135 lines
4.0 KiB
C++
135 lines
4.0 KiB
C++
// MediumAM.cpp: implementation of the CMediumAM class.
|
|
//
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
#include "geomative.h"
|
|
#include "MediumAM.h"
|
|
|
|
#ifdef _DEBUG
|
|
#undef THIS_FILE
|
|
static char THIS_FILE[]=__FILE__;
|
|
#define new DEBUG_NEW
|
|
#endif
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
// Construction/Destruction
|
|
//////////////////////////////////////////////////////////////////////
|
|
extern int g_iUILanguage;
|
|
CMediumAM::CMediumAM(int iAR): CMedium(iAR)
|
|
{
|
|
m_fEOffsetR = 0.5;
|
|
m_fLOffsetR = 0.5;
|
|
}
|
|
|
|
CMediumAM::~CMediumAM()
|
|
{
|
|
|
|
}
|
|
|
|
bool CMediumAM::GenerateSptRecElecVal(int iEAmount, int* pMaxLevel, int* pPtAmount, CPtrArray* pSptRecArray)
|
|
{
|
|
if (iEAmount < 1)
|
|
{
|
|
if (LANG_ZHCN == g_iUILanguage)
|
|
AfxMessageBox(_T("AM-Array中的EA_MOUNT数目为错误!"));
|
|
else
|
|
MessageBoxEx(NULL, _T("The number of EA_MOUNT in AM-Array is error!"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
|
return false;
|
|
}
|
|
if (NULL == pSptRecArray)
|
|
{
|
|
if (LANG_ZHCN == g_iUILanguage)
|
|
AfxMessageBox(_T("pSptRecArray不能为空!"));
|
|
else
|
|
MessageBoxEx(NULL, _T("pSptRecArray can't be NULL!"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
|
|
return false;
|
|
}
|
|
pSptRecArray->RemoveAll();
|
|
int iC1Pos,iC2Pos,iP1Pos,iP2Pos;
|
|
int iTsn = 0;
|
|
CSptRecord *pSptRec = NULL;
|
|
int iLayer = 0;
|
|
iC2Pos = -1;
|
|
iP2Pos = -1;
|
|
while(TRUE)
|
|
{
|
|
iLayer++;
|
|
iC1Pos = 1;
|
|
iP1Pos = iC1Pos + iLayer;
|
|
//变化的规律就是B,N都在无穷远,而AM在同一层中依次右移,可以认为AM的值就是层数
|
|
//同时,当每层的其实位置时,A都是从1开始的
|
|
|
|
if (iP1Pos > iEAmount)
|
|
{
|
|
break;
|
|
}
|
|
|
|
//确定好每一层的电极初始位置之后,开始横向往右测量,此时每测一次,电极向右平移1
|
|
while(iP1Pos <= iEAmount)
|
|
{
|
|
pSptRec = new CSptRecord();
|
|
pSptRec->m_iC1 = iC1Pos;
|
|
pSptRec->m_iC2 = iC2Pos;
|
|
pSptRec->m_iP1 = iP1Pos;
|
|
pSptRec->m_iP2 = iP2Pos;
|
|
pSptRec->m_fK = CalculateCESptKVal(iC1Pos, iC2Pos, iP1Pos, iP2Pos);
|
|
pSptRec->m_iPtNum = iC1Pos;
|
|
pSptRec->m_iLevel = GenSptRecLevel(iC1Pos, iC2Pos, iP1Pos, iP2Pos);
|
|
pSptRec->m_colorREF = RGB(0, 255, 0);
|
|
pSptRec->m_iN = 1;
|
|
pSptRec->m_bIsSel = TRUE;
|
|
pSptRec->m_iTsn = ++iTsn;
|
|
pSptRecArray->Add(pSptRec);
|
|
|
|
iC1Pos++;
|
|
iP1Pos++;
|
|
}
|
|
}
|
|
|
|
*pPtAmount = pSptRecArray->GetSize();
|
|
*pMaxLevel = iLayer-1;
|
|
return true;
|
|
}
|
|
|
|
float CMediumAM::CalculateCESptKVal(float fA, float fB, float fX, float fY)
|
|
{
|
|
//这里K值的计算公式为: k = 2*pai*AM
|
|
//n:指的是AM之间的间隔系数(即AM=n*a)
|
|
//x:指的是MN之间的间隔系数(即MN=x*a)
|
|
return (2*VAL_PI*(fX - fA));
|
|
|
|
}
|
|
|
|
void CMediumAM::CalculateSptPtLoc(int iMul,CSptRecord* pSptRecord)
|
|
{
|
|
int iOffsetL = (int)VAL_ZERO;
|
|
int iOffsetR = (int)VAL_ZERO;
|
|
|
|
int iLevel = pSptRecord->m_iLevel;
|
|
int iPtNum = pSptRecord->m_iPtNum;
|
|
|
|
//此时的中点为AM的中点
|
|
iOffsetL = 46 + iMul*((6+2)*iLevel/2 -3);
|
|
iOffsetR = iOffsetL+6*iMul;
|
|
|
|
//矩形的X轴的位置有OFFSETL 再加上向右的偏移距离组成,向右的偏移距离即是全部电极每测一次向右偏移的距离
|
|
//举例来说,此时OFFSETL相当于此时的中心点的起始位置,iPtNum-1则相当于此时向右偏移的次数
|
|
//其中圆点的半径为3
|
|
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));
|
|
}
|
|
|
|
int CMediumAM::GetMaxLevelByEAmount(int iEAmount)
|
|
{
|
|
if (iEAmount < 2)
|
|
{
|
|
return 0;
|
|
}
|
|
return iEAmount-1;
|
|
} |