347 lines
7.1 KiB
C++
347 lines
7.1 KiB
C++
// Medium3D.cpp: implementation of the CMedium3D class.
|
|
//
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
#include "geomative.h"
|
|
#include "Medium3D.h"
|
|
|
|
#ifdef _DEBUG
|
|
#undef THIS_FILE
|
|
static char THIS_FILE[]=__FILE__;
|
|
#define new DEBUG_NEW
|
|
#endif
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
// Construction/Destruction
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
CMedium3D::CMedium3D()
|
|
{
|
|
m_uiStackNumber = 1;
|
|
}
|
|
|
|
CMedium3D::CMedium3D(int iAR)
|
|
{
|
|
|
|
m_uiStackNumber = 1;
|
|
}
|
|
|
|
CMedium3D::~CMedium3D()
|
|
{
|
|
|
|
}
|
|
|
|
void CMedium3D::CalculateTdPtLoc(const CRect& vRect, const int& iEAmount, int& iMaxLevel, CRect& lRect, int& iSmWidth, int& iSmHeight, CPtrArray* pTdRecArray)
|
|
{
|
|
int iTop = 0;
|
|
int iBottom = 0;
|
|
int iLeft = 0;
|
|
int iRight = 0;
|
|
|
|
int iRectWidth = 0;
|
|
int iRectHeight = 0;
|
|
|
|
iSmWidth = 0;
|
|
iSmHeight = 0;
|
|
|
|
int iLevel = 0;
|
|
int iPos = 0;
|
|
int iIndex = 0;
|
|
|
|
int iEOffset = 0;
|
|
int iLOffset = 0;
|
|
|
|
iMaxLevel = this->GetMaxLevelByEAmount(iEAmount);
|
|
|
|
lRect = vRect;
|
|
lRect.DeflateRect(141, 30, 35, 30);
|
|
|
|
iSmWidth = (int)ceil(lRect.Width()*1.0/iEAmount);
|
|
iSmHeight = (int)ceil(lRect.Height()*1.0/iMaxLevel);
|
|
|
|
if (fmod((double)iSmWidth, 2.0) == 0.0)
|
|
{
|
|
iSmWidth++;
|
|
}
|
|
|
|
iRectWidth = iSmWidth+(iSmWidth-1)*(iEAmount-2);
|
|
|
|
if (fmod((double)iSmHeight, 2.0) == 0.0)
|
|
{
|
|
iSmHeight++;
|
|
}
|
|
|
|
iRectHeight = iSmHeight+(iSmHeight-1)*(iMaxLevel-1);
|
|
|
|
if (fmod(lRect.Width()-iRectWidth, 2.0) == 0.0)
|
|
{
|
|
iLeft = (lRect.Width()-iRectWidth)/2;
|
|
iRight = (lRect.Width()-iRectWidth)/2;
|
|
}
|
|
else
|
|
{
|
|
iLeft = (lRect.Width()-iRectWidth)/2+1;
|
|
iRight = (lRect.Width()-iRectWidth)/2;
|
|
}
|
|
|
|
if (fmod(lRect.Height()-iRectHeight, 2.0) == 0.0)
|
|
{
|
|
iTop = (lRect.Height()-iRectHeight)/2;
|
|
iBottom = (lRect.Height()-iRectHeight)/2;
|
|
}
|
|
else
|
|
{
|
|
iTop = (lRect.Height()-iRectHeight)/2+1;
|
|
iBottom = (lRect.Height()-iRectHeight)/2;
|
|
}
|
|
|
|
lRect.DeflateRect(iLeft, iTop, iRight, iBottom);
|
|
|
|
CRsp2DTdRecord* pRsp2DTdRecord = NULL;
|
|
iEOffset = (int)((iSmWidth-1)*m_fEOffsetR);
|
|
iLOffset = (int)((iSmWidth-1)*m_fLOffsetR);
|
|
|
|
while (iIndex < pTdRecArray->GetSize())
|
|
{
|
|
pRsp2DTdRecord = (CRsp2DTdRecord*)(pTdRecArray->GetAt(iIndex));
|
|
|
|
iLevel = pRsp2DTdRecord->m_iLevel-1;
|
|
iPos = pRsp2DTdRecord->m_iPosInLevel-1;
|
|
|
|
pRsp2DTdRecord->m_recPtArea.SetRectEmpty();
|
|
pRsp2DTdRecord->m_recPtArea.SetRect(lRect.left+iEOffset+iLOffset*iLevel+(iSmWidth-1)*iPos, lRect.top+(iSmHeight-1)*iLevel, lRect.left+iEOffset+iLOffset*iLevel+(iSmWidth-1)*iPos+iSmWidth, lRect.top+(iSmHeight-1)*iLevel+iSmHeight);
|
|
iIndex++;
|
|
}
|
|
}
|
|
|
|
float CMedium3D::CalculateDepth(float fA, float fFactor)
|
|
{
|
|
// return (float)(fabs(fB)+fabs(fA))*fFactor;
|
|
return 0.0;
|
|
}
|
|
|
|
void CMedium3D::Destroy()
|
|
{
|
|
if(m_scr)
|
|
scr_destroy(m_scr);
|
|
}
|
|
//将scr中的标记设置为ONLY_45DIAGONAL,并且将该标记对应的状态设置为使能状态
|
|
void CMedium3D::SetFlags(BOOL Flags)
|
|
{
|
|
if(m_scr)
|
|
{
|
|
if (Flags)
|
|
{
|
|
scr_set_flags(m_scr,ONLY_45DIAGONAL,TRUE);
|
|
}
|
|
else
|
|
{
|
|
scr_set_flags(m_scr,ONLY_45DIAGONAL,FALSE);
|
|
}
|
|
}
|
|
}
|
|
|
|
void CMedium3D::SetPoleStep(int f_step_x, int f_step_y)
|
|
{
|
|
scr_set_pole_step(m_scr, f_step_x, f_step_y);
|
|
}
|
|
|
|
bool CMedium3D::GenerateSptRecElecVal3D(int nSplittedNum, CScript3D *pScript, int* pPtAmount, CPtrArray* pSptRecArray)
|
|
{
|
|
//*pMaxLevel = 0;
|
|
_pos pos;
|
|
|
|
//m_PointNum的大小是128,可查看其定义
|
|
memset(pScript->m_PointNum, 0, sizeof(pScript->m_PointNum));
|
|
|
|
CSptRecord* pSptRecord = NULL;
|
|
|
|
struct _point *node, *head = NULL;
|
|
head = scr_get_points(m_scr);
|
|
|
|
// int iAmount = 0; //记录测点总数
|
|
int Id = 0;
|
|
|
|
for (node = head; node;)
|
|
{
|
|
//这个函数对脚本进行分割,nId返回值表示该节点应属于哪个子脚本
|
|
if( CheckPointVailed(node,nSplittedNum, &Id) == FALSE)
|
|
{
|
|
if (node->next == head)
|
|
break;
|
|
node = node->next;
|
|
continue;
|
|
}
|
|
|
|
pSptRecord = new CSptRecord();
|
|
|
|
pSptRecord->m_iC1 = node->A;
|
|
pSptRecord->m_iC2 = node->B;
|
|
pSptRecord->m_iP1 = node->M;
|
|
pSptRecord->m_iP2 = node->N;
|
|
pSptRecord->m_SubScriptIndex = Id;//记录这个测点属于哪个子脚本
|
|
|
|
pSptRecord->m_fK = node->KS;
|
|
// pSptRecord->m_bIsSel = TRUE;
|
|
pSptRecord->m_iN = (int)m_uiStackNumber;
|
|
|
|
pSptRecArray->Add(pSptRecord);
|
|
|
|
if (node->next == head)
|
|
{
|
|
(pScript->m_PointNum[Id])++;
|
|
break;
|
|
}
|
|
|
|
node = node->next;
|
|
(pScript->m_PointNum[Id])++;
|
|
|
|
// iAmount++;
|
|
}
|
|
|
|
// *pPtAmount = iAmount;
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
BOOL CMedium3D::CheckPointVailed(_point *point, int SplittedId, int *result)
|
|
{
|
|
int Aid = 0, Bid = 0, Cid = 0, Did = 0;
|
|
|
|
if (point->A == -1 && point->B == -1 && point->M == -1 && point->N == -1)
|
|
return FALSE;
|
|
|
|
//取得步长
|
|
int xStep = 0, yStep = 0;
|
|
scr_get_pole_step(m_scr, &xStep, &yStep);
|
|
|
|
//取得矩形大小
|
|
_rect *rect;
|
|
rect = scr_get_rect(m_scr);
|
|
|
|
//将ABMN电极转换为坐标
|
|
_pos *posA, *posB, *posM, *posN;
|
|
posA = new _pos();
|
|
posB = new _pos();
|
|
posM = new _pos();
|
|
posN = new _pos();
|
|
|
|
//将传进来的point(测点)转换成坐标
|
|
pole_to_pos(rect, 1, xStep, yStep, posA, point->A);
|
|
pole_to_pos(rect, 1, xStep, yStep, posB, point->B);
|
|
pole_to_pos(rect, 1, xStep, yStep, posM, point->M);
|
|
pole_to_pos(rect, 1, xStep, yStep, posN, point->N);
|
|
|
|
//计算ABMN的横坐标的位置
|
|
int locA = 0, locB = 0, locM = 0, locN = 0;
|
|
locA = posA->x - rect->x0;
|
|
locB = posB->x - rect->x0;
|
|
locM = posM->x - rect->x0;
|
|
locN = posN->x - rect->x0;
|
|
|
|
//-1代表无穷远,即该点无效,locA % SplitterId,A的横坐标取余脚本分割数,结果为该测点所属的子脚本序列
|
|
if (point->A != -1)
|
|
Aid = locA % SplittedId;
|
|
else
|
|
Aid = -1;
|
|
|
|
if (point->B != -1)
|
|
Bid = locB % SplittedId;
|
|
else
|
|
Bid = -1;
|
|
|
|
if (point->M != -1)
|
|
Cid = locM % SplittedId;
|
|
else
|
|
Cid = -1;
|
|
|
|
if (point->N != -1)
|
|
Did = locN % SplittedId;
|
|
else
|
|
Did = -1;
|
|
|
|
//将4个测点所属的子脚本序列放入数据,方便后面运算
|
|
int nArray[4] = {Aid, Bid, Cid, Did};
|
|
|
|
int i = 0;
|
|
|
|
BOOL bResult = FALSE;
|
|
|
|
//判断ABMN测点是否属于同一个子脚本序列(即Did,Aid,Bid,Cid是否相等,-1除外)
|
|
if (Aid != -1)
|
|
{
|
|
for (i = 1; i < 4; i++)
|
|
{
|
|
if (nArray[i] != -1)
|
|
{
|
|
if (Aid != nArray[i])
|
|
{
|
|
bResult = FALSE;
|
|
goto _exit;
|
|
}
|
|
}
|
|
}
|
|
*result = Aid;
|
|
}
|
|
else if (Bid != -1)
|
|
{
|
|
//进入该条件,则表明Aid==-1,故不需要再判断
|
|
for (i = 2; i < 4; i++)
|
|
{
|
|
if (nArray[i] != -1)
|
|
{
|
|
if (Bid != nArray[i])
|
|
{
|
|
bResult = FALSE;
|
|
goto _exit;
|
|
}
|
|
}
|
|
}
|
|
*result = Bid;
|
|
}
|
|
else if (Cid != -1)
|
|
{
|
|
//进入该条件,则表明Aid==-1且Bid == -1,故不需要再判断
|
|
if (Did != -1)
|
|
{
|
|
if (Cid != Did)
|
|
{
|
|
bResult = FALSE;
|
|
goto _exit;
|
|
}
|
|
else
|
|
*result = Cid;
|
|
}
|
|
else
|
|
*result = Cid;
|
|
}
|
|
|
|
bResult = TRUE;
|
|
|
|
//三维dipole_dipole装置去掉因子系数大于6的点
|
|
if (24 == scr_get_type(m_scr))
|
|
{
|
|
float fInterval = (1.0*abs(point->M - point->A)) / abs(point->N - point->M);
|
|
if ((fInterval > 6.0) || (point->B > point->N))
|
|
{
|
|
bResult = FALSE;
|
|
goto _exit;
|
|
}
|
|
}
|
|
|
|
_exit:
|
|
|
|
delete posA;
|
|
delete posB;
|
|
delete posM;
|
|
delete posN;
|
|
|
|
return bResult;
|
|
}
|
|
|
|
void CMedium3D::SetPoleDistance(DOUBLE f_dis_x, DOUBLE f_dis_y)
|
|
{
|
|
scr_set_spacing(m_scr, f_dis_x, f_dis_y);
|
|
}
|