// MediumV.cpp: implementation of the CMediumV class. // ////////////////////////////////////////////////////////////////////// #include "geomative.h" #include "MediumV.h" #ifdef _DEBUG #undef THIS_FILE static char THIS_FILE[]=__FILE__; #define new DEBUG_NEW #endif ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// CMediumV::CMediumV(int iAR) { m_iAR = iAR; } CMediumV::~CMediumV() { // scr_destroy(m_scr); } bool CMediumV::GenerateSptRecElecVal(int iEAmount, int *pMaxLevel, int *pPtAmount, CPtrArray *pSptRecArray) { *pMaxLevel = 0; CSptRecord* pSptRecord = NULL; struct _point *node, *head = NULL; head = scr_get_points(m_scr); int iAmount = 0; //记录测点总数 for (node = head; node;) { 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_iTsn = ++iTsn; pSptRecord->m_fK = node->KS; // pSptRecord->m_iLevel = CalculateSptLevel(iMVal, iNVal); // pSptRecord->m_iPtNum = iAVal; // pSptRecord->m_colorREF = RGB(150, 255, 255); pSptRecord->m_bIsSel = TRUE; pSptRecord->m_iN = (int)VAL_ONE; // CalculateSptPtLoc(2, pSptRecord); pSptRecArray->Add(pSptRecord); if (node->next == head) break; node = node->next; iAmount++; } *pPtAmount = iAmount; return true; } void CMediumV::CalculateSptPtLoc(int iMul, CSptRecord *pSptRecord) { } int CMediumV::GenSptRecLevel(int iA, int iB, int iM, int iN) { return FALSE; } int CMediumV::GenSptRecPosInLevel(int iA, int iB, int iM, int iN) { return FALSE; } int CMediumV::GetMaxLevelByEAmount(int iEAmount) { return FALSE; } float CMediumV::CalculateCESptKVal(float fA, float fB, float fX, float fY) { return FALSE; } void CMediumV::create() { m_rect.x0 = 1; m_rect.y0 = 1; m_rect.x1 = 12; m_rect.y1 = 12; m_scr = scr_create("Pole-Pole", NULL, &m_rect, 0, 0); } void CMediumV::SetRect(int x0, int y0, int x1, int y1) { rect_init(&m_rect, x0, y0, x1, y1); scr_set_rect(m_scr, &m_rect); } void CMediumV::setZone(bool enable, int zonec, int *zonev) { scr_set_zone(m_scr, enable, zonec, zonev); } BOOL CMediumV::setPoleStart(int startpole) { return scr_set_pole_start(m_scr, startpole); } BOOL CMediumV::generate() { return scr_generate(m_scr); } int CMediumV::getPoleStart() { return scr_get_pole_start(m_scr); } int CMediumV::getPoleCount() { return scr_get_pole_count(m_scr); } struct _rect * CMediumV::getRect() { return scr_get_rect(m_scr); } void CMediumV::SetPointCPosition(char *f_type, int f_x, int f_y) { return; } void CMediumV::SaveScr() { struct _rect rect = { 1, 1, 12, 12 }; struct _rect *r; struct _point *node, *head = NULL; int length; FILE *fd; char *buf = NULL; if (!m_scr) return; head = scr_get_points(m_scr); if (!head) goto __exit; buf = new char[512]; if (!buf) { printf("buffer alloc failed!\n"); goto __exit; } /* 只写 & 创建 打开 */ { r = scr_get_rect(m_scr); _snprintf(buf, 512, "D:\\%s(%d,%d,%d,%d).scr", scr_get_name(m_scr), r->x0, r->y0, r->x1, r->y1); fd = fopen(buf, "wb+"); } if (fd < 0) { printf("open \"%s\" for write failed!\n", scr_get_name(m_scr)); goto __exit; } { time_t now; struct tm *ptm; time(&now); ptm = localtime(&now); //取得当地时间 r = scr_get_rect(m_scr); length = _snprintf(buf, 512, "\r\n"); fwrite(buf, 1, length, fd); length = _snprintf(buf, 512, "\r\n"); fwrite(buf, 1, length, fd); __exit: if (fd >= 0) fclose(fd); if (buf) delete buf; return; } BOOL CMediumV::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_by_normal_axis(rect, 1, xStep, yStep, posA, point->A); pole_to_pos_by_normal_axis(rect, 1, xStep, yStep, posB, point->B); pole_to_pos_by_normal_axis(rect, 1, xStep, yStep, posM, point->M); pole_to_pos_by_normal_axis(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; _exit: delete posA; delete posB; delete posM; delete posN; return bResult; }