void Button::OnClicked(const int& posx, const int& posy)	{
    if( IsIntersect(posx,posy) ) {
        if( m_CallBackFunction )
            m_CallBackFunction(this);
        m_ClickedState=1;
    }
}
void RoomGenerator::CreateRooms()
/*
 * @ todo:
 * Сделать адекватную генерацию ширины-высоты
 */
{
    for (int i = 0; i < m_roomsCount; i++)
    {
        Room room;
        do
        {
            room.x = Rand(0, m_width - 2);
            room.y = Rand(0, m_height - 2);
            int size = Rand(m_minRoomSize, m_maxRoomSize);
            room.w = Rand(2, size / 2);
            room.w = room.x + room.w >= m_width ? m_width - room.x : room.w;
            room.h = size / room.w;
            room.h = room.y + room.h >= m_height ? m_height - room.y : room.h;
            if (room.h * room.w < m_minRoomSize)
            {
                continue;
            }
            room.reachable = false;
        } while (IsIntersect(room));

        m_rooms.push_back(room);
        for (int x = room.x; x < room.x + room.w; x++)
        {
            for (int y = room.y; y < room.y + room.h; y++)
            {
                m_map[x][y] = 0;
            }
        }
    }
}
Exemplo n.º 3
0
static void ChangeSelectIntervalAndBreakpoint(ChewingData *pgdata, int from, int to, const char *str)
{
    int i;
    int user_alloc;

    IntervalType inte;

    inte.from = from;
    inte.to = to;
    for (i = 0; i < pgdata->nSelect; i++) {
        if (IsIntersect(inte, pgdata->selectInterval[i])) {
            RemoveSelectElement(i, pgdata);
            i--;
        }
    }

    pgdata->selectInterval[pgdata->nSelect].from = from;
    pgdata->selectInterval[pgdata->nSelect].to = to;

    /* No available selection */
    if ((user_alloc = (to - from)) == 0)
        return;

    ueStrNCpy(pgdata->selectStr[pgdata->nSelect], str, user_alloc, 1);
    pgdata->nSelect++;

    if (user_alloc > 1) {
        memset(&pgdata->bUserArrBrkpt[from + 1], 0, sizeof(int) * (user_alloc - 1));
        memset(&pgdata->bUserArrCnnct[from + 1], 0, sizeof(int) * (user_alloc - 1));
    }
}
void Button::OnHover(const int& posx, const int& posy)	{
    if( IsIntersect(posx,posy) ) {
        m_Anim->SetFinishFrame(m_FrameHover);
        m_HoverState=1;
    } else {
        m_Anim->SetFinishFrame(0);
        m_HoverState=0;
    }
}
Exemplo n.º 5
0
/*
 * phrase is said to satisfy a choose interval if 
 * their intersections are the same */
static int CheckChoose(
		ChewingData *pgdata,
		int ph_id, int from, int to, Phrase **pp_phr, 
		char selectStr[][ MAX_PHONE_SEQ_LEN * MAX_UTF8_SIZE + 1 ], 
		IntervalType selectInterval[], int nSelect )
{
	IntervalType inte, c;
	int chno, len;
	Phrase *phrase = ALC( Phrase, 1 );

	assert( phrase );
	inte.from = from;
	inte.to = to;
	*pp_phr = NULL;

	/* if there exist one phrase satisfied all selectStr then return 1, else return 0. */
	GetPhraseFirst( pgdata, phrase, ph_id );
	do {
		for ( chno = 0; chno < nSelect; chno++ ) {
			c = selectInterval[ chno ];

			if ( IsContain( inte, c ) ) {
				/* find a phrase of ph_id where the text contains 
				 * 'selectStr[chno]' test if not ok then return 0, if ok 
				 * then continue to test
				 */
				len = c.to - c.from;
				if ( memcmp(
					ueStrSeek( phrase->phrase, c.from - from ),
					selectStr[ chno ],
					ueStrNBytes( selectStr[ chno ], len ) ) )
					break;
			}
			else if ( IsIntersect( inte, selectInterval[ chno ] ) ) {
				free( phrase );
				return 0;
			} 
		}
		if ( chno == nSelect ) {
			*pp_phr = phrase;
			return 1;
		}
	} while ( GetPhraseNext( pgdata, phrase ) );
	free( phrase );
	return 0;
}
Exemplo n.º 6
0
static int CheckUserChoose( 
		ChewingData *pgdata,
		uint16_t *new_phoneSeq, int from , int to,
		Phrase **pp_phr, 
		char selectStr[][ MAX_PHONE_SEQ_LEN * MAX_UTF8_SIZE + 1 ], 
		IntervalType selectInterval[], int nSelect )
{
	IntervalType inte, c;
	int chno, len;
	int user_alloc;
	UserPhraseData *pUserPhraseData;
	Phrase *p_phr = ALC( Phrase, 1 );

	assert( p_phr );
	inte.from = from;
	inte.to = to;
	*pp_phr = NULL;

	/* pass 1
	 * if these exist one selected interval which is not contained by inte
	 * but has intersection with inte, then inte is an unacceptable interval
	 */
	for ( chno = 0; chno < nSelect; chno++ ) {
		c = selectInterval[ chno ];
		if ( IsIntersect( inte, c ) && ! IsContain( inte, c ) ) {
			free( p_phr );
			return 0;
		}
	}

	/* pass 2
	 * if there exist one phrase satisfied all selectStr then return 1, else return 0.
	 * also store the phrase with highest freq
	 */
	pUserPhraseData = UserGetPhraseFirst( pgdata, new_phoneSeq );
	p_phr->freq = -1;
	do {
		for ( chno = 0; chno < nSelect; chno++ ) {
			c = selectInterval[ chno ];

			if ( IsContain( inte, c ) ) {
				/* 
				 * find a phrase of ph_id where the text contains 
				 * 'selectStr[chno]' test if not ok then return 0, 
				 * if ok then continue to test. */
				len = c.to - c.from;
				if ( memcmp(
					ueStrSeek( pUserPhraseData->wordSeq, c.from - from ),
					selectStr[ chno ],
					ueStrNBytes( selectStr[ chno ], len ) ) )
					break;
			}

		}
		if ( chno == nSelect ) {
			/* save phrase data to "pp_phr" */
			if ( pUserPhraseData->userfreq > p_phr->freq ) {
				if ( ( user_alloc = ( to - from ) ) > 0 ) {
					ueStrNCpy( p_phr->phrase,
							pUserPhraseData->wordSeq,
							user_alloc, 1);
				}
				p_phr->freq = pUserPhraseData->userfreq;
				*pp_phr = p_phr;
			}
		}
	} while ( ( pUserPhraseData = UserGetPhraseNext( pgdata, new_phoneSeq ) ) != NULL );

	if ( p_phr->freq != -1 ) 
		return 1;
		
	free( p_phr );
	return 0;
}
Exemplo n.º 7
0
//////////////////////////////////////////////////////////////////////////
//	satisfy constraints
//////////////////////////////////////////////////////////////////////////
void RCharCloth::satisfyConstraints()
{
	sConstraint c;
	rvector x1, x2;
	rvector delta;
	float deltaLegth;
	float diff;
	int i, j, k;
	rvector intersection;

	c.refA = 0;
	c.refB = 0;
	c.restLength = 0.f;

	for( i = 0 ; i < m_nCntIter; ++i )
	{

		if(( mUpdateStatus & NOT_COLLISION ) == 0 )
		{

			for( j = 0 ; j < m_nCntP; ++j )							// particle index - j
			{
				for( k = 0 ; k < 6; ++k )													// sphere index - k
				{
					if( CLOTH_COLLISION & m_pHolds[j] )
					{
						rvector dir = m_pX[j] - m_pOldX[j];
						D3DXVec3Normalize(&dir, &dir);
						if(IsIntersect(m_pOldX[j], m_pX[j], dir ,mSphere[k].mCentre, mSphere[k].mRadius, m_pNormal[j], &intersection ))
						{
							m_pX[j] = intersection;
							break;
						}
					}
				}
			}
		}	

		float w1, w2;
		for( j = 0 ; j < m_nCntC; ++j )
		{
			c = m_pConst[j];
			if( c.refA <0 || c.refA>=m_nCntP )
			{
				mlog("RCharCloth_Error:: constraints reference Particle is Out of Range - ref : %d, n_particles : %d, mesh_node : %s, mesh : %s \n", c.refA, j, mpMeshNode->m_Name, mpMesh->GetFileName());
				continue;
			}
			if( c.refB < 0 || c.refB >= m_nCntP )
			{
				mlog("RCharCloth_Error:: constraints reference Particle is Out of Range - ref : %d, n_particles : %d, mesh_node : %s, mesh : %s \n", c.refA, j, mpMeshNode->m_Name, mpMesh->GetFileName());
				continue;
			}
			x1 = m_pX[c.refA];
			x2 = m_pX[c.refB];
			w1 = m_pWeights[c.refA];
			w2 = m_pWeights[c.refB];

			if( w1 == 0 && w2 == 0 )
				continue;
			delta = x2 - x1;

			deltaLegth = D3DXVec3Length( &delta );
			if( deltaLegth == 0 )
				diff = 0;
			else
				diff = (float)((deltaLegth - c.restLength)/(deltaLegth*(w1+w2)));

			m_pX[c.refA] += delta*w1*diff;
			m_pX[c.refB] -= delta*w2*diff;
		}


	}
}
Exemplo n.º 8
0
BOOL CGranitDlg::ProcessSave(void)
{
	for(int row = 1; row < m_GridData.GetRowCount(); row++)
	{
		for(int col = 0; col < m_GridData.GetColumnCount(); col++)
		{
			m_GridData.SetItemBkColour(row,col,RGB(255,255,255));
		}
	}
	// TODO: добавьте специализированный код или вызов базового класса
	CString str;
	
	CGridCellCombo *pCell = (CGridCellCombo*) m_Grid.GetCell(1, 1);
	m_Granit.TYPE = pCell->GetCurSel()+1;

	str = m_Grid.GetItemText(2,1);
	m_Granit.MEANDER_VALUE = atoi(str);

	pCell = (CGridCellCombo*) m_Grid.GetCell(3, 1);
	m_Granit.INVERT_REQUEST = pCell->GetCurSel();

	pCell = (CGridCellCombo*) m_Grid.GetCell(4, 1);
	m_Granit.INVERT_RESPONSE = pCell->GetCurSel();
	
	pCell = (CGridCellCombo*) m_Grid.GetCell(5, 1);
	m_Granit.SEND_CONFIRM = pCell->GetCurSel();

	pCell = (CGridCellCombo*) m_Grid.GetCell(6, 1);
	m_Granit.IC_ON_MEANDER = pCell->GetCurSel();

	pCell = (CGridCellCombo*) m_Grid.GetCell(7, 1);
	m_Granit.ADD_MEANDER_BEFORE_REQ = pCell->GetCurSel();

	pCell = (CGridCellCombo*) m_Grid.GetCell(8, 1);
	m_Granit.C_IC_TS_ENABLE = pCell->GetCurSel();

	pCell = (CGridCellCombo*) m_Grid.GetCell(9, 1);
	m_Granit.C_IC_TIT_ENABLE = pCell->GetCurSel();

	pCell = (CGridCellCombo*) m_Grid.GetCell(10, 1);
	m_Granit.C_IC_TII_ENABLE = pCell->GetCurSel();

	str = m_Grid.GetItemText(11,1);
	m_Granit.C_IC_NA_1_PERIOD = atoi(str);

	str = m_Grid.GetItemText(12,1);
	m_Granit.MEANDER_PERIOD = atoi(str);

	str = m_Grid.GetItemText(13,1);
	m_Granit.REQ_RESPONSE_PERIOD = atoi(str);

	str = m_Grid.GetItemText(14,1);
	m_Granit.TU_RESPONSE_PERIOD = atoi(str);

	str = m_Grid.GetItemText(15,1);
	m_Granit.NO_LINK_PERIOD = atoi(str);

	str = m_Grid.GetItemText(16,1);
	m_Granit.NUMBER_NO_ANSWER = atoi(str);

	pCell = (CGridCellCombo*) m_Grid.GetCell(17, 1);
	m_Granit.LOG_ENABLE = pCell->GetCurSel();

	pCell = (CGridCellCombo*) m_Grid.GetCell(18, 1);
	m_Granit.ALARM_ENABLE = pCell->GetCurSel();

	pCell = (CGridCellCombo*) m_Grid.GetCell(19, 1);
	m_Granit.SERVICE = pCell->GetCurSel();
	
	m_Granit.m_IndividualStructureGranitArray.RemoveAll();
	

	for(int i = 1; i < m_GridData.GetRowCount(); i++)
	{
		IndividualStructureGranit is101;	

		is101.strCOMMENT = m_GridData.GetItemText(i,0 );	

		str = m_GridData.GetItemText(i,1);
		is101.N_KP = atoi(str);
		if((is101.N_KP>256)||(is101.N_KP<0))
		{
			AfxMessageBox("№ КП: 0..256!");
			return FALSE;
		}	

		str = m_GridData.GetItemText(i,2);
		is101.AFB = atoi(str);
		if((is101.AFB>16)||(is101.AFB<0))
		{
			AfxMessageBox("АФБ: 0..16!");
			return FALSE;
		}	

		pCell = (CGridCellCombo*) m_GridData.GetCell(i,3);		
		
		if(pCell->GetCurSel() == 0)
			is101.INFO_TYPE = 2;
		else if(pCell->GetCurSel() == 1)
			is101.INFO_TYPE = 3;
		else if(pCell->GetCurSel() == 2)
			is101.INFO_TYPE = 6;
		else if(pCell->GetCurSel() == 3)
			is101.INFO_TYPE = 7;
		else if(pCell->GetCurSel() == 4)
			is101.INFO_TYPE = 4;
	
		str = m_GridData.GetItemText(i,4);
		is101.GROUP_NUMBER = atoi(str);
		if((is101.GROUP_NUMBER>16)||(is101.GROUP_NUMBER<0))
		{
			AfxMessageBox("АФБ: 0..16!");
			return FALSE;
		}

		str = m_GridData.GetItemText(i,5);
		is101.ADDRESS_PMZ = atoi(str);

		str = m_GridData.GetItemText(i,6);
		is101.NUMBER = atoi(str);

		if((is101.ADDRESS_PMZ < m_nStartPMZAddr)
			||(is101.ADDRESS_PMZ > m_nEndPMZAddr)
			||(is101.ADDRESS_PMZ + is101.NUMBER - 1 > m_nEndPMZAddr))
		{
			CString tmp;
			tmp.Format("Набор инф. объектов в строке %d выходит за пределы карты памяти ПРОЦЕССА: %d..%d!\r\n(строки подсвечены сиреневым цветом)",i,m_nStartPMZAddr,m_nEndPMZAddr);
			AfxMessageBox(tmp);
			for(int col = 0; col < m_GridData.GetColumnCount(); col++)
			{
				m_GridData.SetItemBkColour(i,col,RGB(255,128,255));
			}
			m_GridData.EnsureVisible(i,0);
			m_GridData.Refresh();
			//return FALSE;
		}		

		pCell = (CGridCellCombo*)m_GridData.GetCell(i, 7);
		is101.DATA_FORMAT = pCell->GetCurSel();

		m_Granit.m_IndividualStructureGranitArray.Add(is101);
	}
	
	for(int i = 0; i < m_Granit.m_IndividualStructureGranitArray.GetSize();i++)
	{
		for(int j = 0; j < m_Granit.m_IndividualStructureGranitArray.GetSize();j++)
		{
			if((IsIntersect(m_Granit.m_IndividualStructureGranitArray[i].ADDRESS_PMZ,
							m_Granit.m_IndividualStructureGranitArray[i].ADDRESS_PMZ+m_Granit.m_IndividualStructureGranitArray[i].NUMBER-1,
							m_Granit.m_IndividualStructureGranitArray[j].ADDRESS_PMZ,
							m_Granit.m_IndividualStructureGranitArray[j].ADDRESS_PMZ+m_Granit.m_IndividualStructureGranitArray[j].NUMBER-1))
							&&(i!=j))
			{
				str.Format("%d на %d !\r\n(строки подсвечены розовым цветом)",j+1,i+1);
				AfxMessageBox("Наложение наборов инф.объектов:"+str);
				for(int col = 0; col < m_GridData.GetColumnCount(); col++)
				{
					m_GridData.SetItemBkColour(j+1,col,RGB(255,128,128));
					m_GridData.SetItemBkColour(i+1,col,RGB(255,128,128));
				}
				m_GridData.EnsureVisible(i+1,0);
				m_GridData.Refresh();
				return FALSE;
			}
		}
	}
	return TRUE;
}
void Button::OnClickReleased(const int& posx, const int& posy)	{
    if( IsIntersect(posx,posy) ) {
        m_ClickedState=1;
    }
}
Exemplo n.º 10
0
//Show Main Window
//para:
// socket id
// pAttachData iAttachSize no used 
BOOL 
ShowMainWinServer(
	IpcHand hand, 
	void *pAttachData
)
{
	PlGUIAppStat pStat,pCurStat,pPrevStat,pThisStat,pActiveStat;
	PWindowsTree pControl;
	RECT rect;
	//_lGUI_pWindowsTree	
	if(IsActive((HWND)_lGUI_pWindowsTree)){//if desktop is active
		pActiveStat = NULL;
	}
	else{
		pStat=_lGUI_pAppStat;
		while(pStat){
			if(pStat->bVisible)
				break;
			pStat = pStat->pNext;
		}
		pActiveStat = pStat;
	}

	pStat = _lGUI_pAppStat;
	pPrevStat = _lGUI_pAppStat;
	while(pStat){
		if(pStat->hand==hand)
			break;
		pPrevStat = pStat;
		pStat=pStat->pNext;
	}
	if(!pStat)
		return false;
	//Move this main window node to top
	if(pStat!=_lGUI_pAppStat){
		pThisStat = pStat->pNext;

		pPrevStat->pNext = pStat->pNext;
		pStat->pNext = _lGUI_pAppStat;
		_lGUI_pAppStat = pStat;
	}
	else
		pThisStat = NULL;

	pStat->bVisible=true;
	
	//clipped by desktop rect
	GetWindowRect((HWND)_lGUI_pWindowsTree,&rect);
	IntersectRect(&(pStat->rc),&(pStat->rc),&rect);
	//Initial the clip region 
	SetInitRectClipRegion (pStat->pClipRgn, &(pStat->rc));
	//clipped by imewin and skbwin to generate initial clip region
	if(IsVisible((HWND)_lGUI_pImeWindow))
		SubtractClipRegion(pStat->pClipRgn,&_lGUI_pImeWindow->rect);
	if(IsVisible((HWND)_lGUI_pSkbWindow))
		SubtractClipRegion(pStat->pClipRgn,&_lGUI_pSkbWindow->rect);
	//clip region of all main window under this will change.
	pCurStat=_lGUI_pAppStat->pNext;
	while(pCurStat!= pThisStat){
		if(IsIntersect(&(pCurStat->pClipRgn->rcBound),&(pStat->rc))){
			SubtractClipRegion (pCurStat->pClipRgn, &(pStat->rc));
			//send clipregion change message to application
			if(pCurStat->bVisible)
				SendClipRgnChangeMsg(pCurStat);
		}
		pCurStat = pCurStat->pNext;
	}

	//send disactive message to the top application before.
	if(pActiveStat){
		SendMsgByServer(pActiveStat,LMSG_IPC_DISACTIVEAPP,NULL,0);
	}

	//calculate clipregion of desktop
	SubtractClipRegion(_lGUI_pWindowsTree->pClipRgn,&(pStat->rc));
	//calculate clip region of desktop control 
	pControl=_lGUI_pWindowsTree->pControlHead;
	while(pControl){
		SubtractClipRegion(pControl->pClipRgn,&(pStat->rc));
		pControl=pControl->pNext;
	}
	//send confirm message to the new generated application
//	SendMsgByServer(pStat,LMSG_IPC_SHOWMAINWIN_ANS,NULL,0);
	GetBoundClipRegion(pStat->pClipRgn);
	sem_post(&pStat->sem_cs);
	return true;
}
Exemplo n.º 11
0
BOOL CModbusMDlg::ProcessSave(void)
{
    for(int row = 1; row < m_GridData.GetRowCount(); row++)
    {
        for(int col = 0; col < m_GridData.GetColumnCount(); col++)
        {
            m_GridData.SetItemBkColour(row,col,RGB(255,255,255));
        }
    }
    // TODO: добавьте специализированный код или вызов базового класса
    CString str;

    str = m_Grid.GetItemText(1,1);
    if((atoi(str)<=0)||(atoi(str)>255))
    {
        AfxMessageBox("Неверно задан СОМ-порт!");
        return FALSE;
    }
    if(((CKPLConfigApp*)(AfxGetApp()))->m_KPLProject.IsPortDuplicated(atoi(str)-1,nProcNum))
    {
        AfxMessageBox("Данный СОМ-порт занят под другую задачу!");
        return FALSE;
    }

    m_ModbusM.PORT = atoi(str)-1;

    str = m_Grid.GetItemText(2,1);
    m_ModbusM.BAUDRATE = atoi(str);

    str = m_Grid.GetItemText(3,1);
    m_ModbusM.AMOUNTBYTE = atoi(str);
    if((m_ModbusM.AMOUNTBYTE > 8)||(m_ModbusM.AMOUNTBYTE < 5))
    {
        AfxMessageBox("Количество бит в байте 5..8!");
        return FALSE;
    }
    str = m_Grid.GetItemText(4,1);
    m_ModbusM.STOPBITS = atoi(str);

    str = m_Grid.GetItemText(5,1);
    if(str == "NONE")
        m_ModbusM.PARITY = 0;
    if(str == "EVEN")
        m_ModbusM.PARITY = 1;
    if(str == "ODD")
        m_ModbusM.PARITY = 2;

    str = m_Grid.GetItemText(6,1);
    if(str == "нет")
        m_ModbusM.CONTROLPOTOK = 0;
    if(str == "аппаратный")
        m_ModbusM.CONTROLPOTOK = 1;
    if(str == "программный")
        m_ModbusM.CONTROLPOTOK = 2;

    str = m_Grid.GetItemText(7,1);
    if((atoi(str)<=0)||(atoi(str)>3000))
    {
        AfxMessageBox("Таймаут ответа подчиненного в квантах 1..3000!");
        return FALSE;
    }
    m_ModbusM.WAITRESP = atoi(str);

    str = m_Grid.GetItemText(8,1);
    if((atoi(str)<=0)||(atoi(str)>3000))
    {
        AfxMessageBox("Пауза между байтами в квантах 1..3000!");
        return FALSE;
    }
    m_ModbusM.BYTETIME = atoi(str);

    str = m_Grid.GetItemText(9,1);
    if((atoi(str)<=0)||(atoi(str)>3000))
    {
        AfxMessageBox("Интервал между запросами в миллисекундах 1..3000!");
        return FALSE;
    }
    m_ModbusM.NEXTMESSAGE = atoi(str);

    str = m_Grid.GetItemText(10,1);
    if((atoi(str)<0)||(atoi(str)>50))
    {
        AfxMessageBox("Количество ошибок для генерации \"недостоверности\" 0..50!");
        return FALSE;
    }
    m_ModbusM.NUMBER_NO_ANSWER = atoi(str);

    str = m_Grid.GetItemText(11,1);
    if(str == "RTU")
        m_ModbusM.MODBUS_TYPE = 0;
    if(str == "ASCII")
        m_ModbusM.MODBUS_TYPE = 1;

    m_ModbusM.m_ModbusPriborArray.RemoveAll();
    int nTotalAmount=0;

    for(int i = 1; i < m_GridData.GetRowCount(); i++)
    {
        ModbusPribor is101;

        is101.strCOMMENT = m_GridData.GetItemText(i,0 );

        str = m_GridData.GetItemText(i,1 );
        if(str == "ТС-32")
            is101.PRIBOR = 4;
        else if(str == "ТУ-32")
            is101.PRIBOR = 5;
        else if(str == "ТИ-16")
            is101.PRIBOR = 6;
        else if(str == "Внешний")
            is101.PRIBOR = 0;
        else if(str == "SATEC")
            is101.PRIBOR = 1;
        else if(str == "SATEC TC")
            is101.PRIBOR = 8;
        else if(str == "МТЕ")
            is101.PRIBOR = 2;
        else if(str == "МТЕ(2-х байтный)")
            is101.PRIBOR = 7;
        else if(str == "SWAPPED FLOAT(4 байта)")
            is101.PRIBOR = 9;
        else if(str == "INTEL FLOAT(4 байта)")
            is101.PRIBOR = 10;
        else if(str == "INT32 TO FLOAT(4 байта)")
            is101.PRIBOR = 11;
        else
            is101.PRIBOR = atoi(str);

        str = m_GridData.GetItemText(i,2);
        is101.ADRESS = atoi(str);
        if((is101.ADRESS>255)||(is101.ADRESS<0))
        {
            AfxMessageBox("Адрес устройства: 1..255!");
            return FALSE;
        }

        str = m_GridData.GetItemText(i,3);
        is101.FUNCTION = atoi(str);
        if((is101.FUNCTION > 4)||(is101.FUNCTION<1))
        {
            AfxMessageBox("Номер функции: 1..4!");
            return FALSE;
        }

        str = m_GridData.GetItemText(i,4);
        is101.START_ADRESS = atoi(str);
        if(((is101.START_ADRESS>65535)||(is101.START_ADRESS<0)))
        {
            AfxMessageBox("Нач. адрес MODBUS: 0..65535!");
            return FALSE;
        }

        str = m_GridData.GetItemText(i,5);
        is101.NUMBER = atoi(str);

        int tmpNumber=0;
        if(is101.PRIBOR == 4)
            tmpNumber=50;
        else if(is101.PRIBOR == 5)
            tmpNumber=114;
        else if(is101.PRIBOR == 6)
            tmpNumber=20;
        else
            tmpNumber=is101.NUMBER;
        nTotalAmount+=tmpNumber;

        str = m_GridData.GetItemText(i,6);
        is101.ADRESS_PMZ = atoi(str);

        if((is101.ADRESS_PMZ < m_nStartPMZAddr)
                ||(is101.ADRESS_PMZ > m_nEndPMZAddr)
                ||(is101.ADRESS_PMZ + tmpNumber - 1 > m_nEndPMZAddr))
        {
            CString tmp;
            tmp.Format("Набор инф. объектов в строке %d выходит за пределы карты памяти ПРОЦЕССА: %d..%d!\r\n(строки подсвечены сиреневым цветом)",i,m_nStartPMZAddr,m_nEndPMZAddr);
            AfxMessageBox(tmp);
            for(int col = 0; col < m_GridData.GetColumnCount(); col++)
            {
                m_GridData.SetItemBkColour(i,col,RGB(255,128,255));
            }
            m_GridData.EnsureVisible(i,0);
            m_GridData.Refresh();
            //return FALSE;
        }

        str = m_GridData.GetItemText(i,7);
        is101.DOP_BYTE1 = atoi(str);

        str = m_GridData.GetItemText(i,8);
        is101.DOP_BYTE2 = atoi(str);

        str = m_GridData.GetItemText(i,9);
        is101.DOP_BYTE3 = atoi(str);

        str = m_GridData.GetItemText(i,10);
        is101.DOP_BYTE4 = atoi(str);

        str = m_GridData.GetItemText(i,11);
        is101.ADRES_4B = atoi(str);

        str = m_GridData.GetItemText(i,12 );
        if(str == "нет")
            is101.TYPE_STATUS = 0;
        else if(str == "в посылке")
            is101.TYPE_STATUS = 1;
        else if(str == "в карте памяти")
            is101.TYPE_STATUS = 2;

        str = m_GridData.GetItemText(i,13);
        is101.ADRES_STATUS = atoi(str);

        str = m_GridData.GetItemText(i,14);
        is101.MASKA_STATUS = atoi(str);

        m_ModbusM.m_ModbusPriborArray.Add(is101);
    }

    if(nTotalAmount > m_nEndPMZAddr+1)
    {
        str.Format("%d > %d !",nTotalAmount,m_nEndPMZAddr+1);
        AfxMessageBox("Суммарное кол-во инф. объектов больше выделенного количества для данного процесса:"+str);
        //return FALSE;
    }

    for(int i = 0; i < m_ModbusM.m_ModbusPriborArray.GetSize(); i++)
    {
        for(int j = 0; j < m_ModbusM.m_ModbusPriborArray.GetSize(); j++)
        {
            int tmpNumberI=0;
            int tmpNumberJ=0;
            if(m_ModbusM.m_ModbusPriborArray[i].PRIBOR == 4)
                tmpNumberI=50;
            else if(m_ModbusM.m_ModbusPriborArray[i].PRIBOR == 5)
                tmpNumberI=114;
            else if(m_ModbusM.m_ModbusPriborArray[i].PRIBOR == 6)
                tmpNumberI=20;
            else
                tmpNumberI=m_ModbusM.m_ModbusPriborArray[i].DOP_BYTE2 + m_ModbusM.m_ModbusPriborArray[i].DOP_BYTE4;

            if(m_ModbusM.m_ModbusPriborArray[j].PRIBOR == 4)
                tmpNumberJ=50;
            else if(m_ModbusM.m_ModbusPriborArray[j].PRIBOR == 5)
                tmpNumberJ=114;
            else if(m_ModbusM.m_ModbusPriborArray[j].PRIBOR == 6)
                tmpNumberJ=20;
            else
                tmpNumberJ=m_ModbusM.m_ModbusPriborArray[j].DOP_BYTE2 + m_ModbusM.m_ModbusPriborArray[j].DOP_BYTE4;
            //tmpNumberJ=m_ModbusM.m_ModbusPriborArray[j].NUMBER;


            if((IsIntersect(m_ModbusM.m_ModbusPriborArray[i].ADRESS_PMZ,
                            m_ModbusM.m_ModbusPriborArray[i].ADRESS_PMZ+tmpNumberI-1,
                            m_ModbusM.m_ModbusPriborArray[j].ADRESS_PMZ,
                            m_ModbusM.m_ModbusPriborArray[j].ADRESS_PMZ+tmpNumberJ-1))
                    &&(i!=j))
            {
                str.Format("%d на %d !\r\n(строки подсвечены розовым цветом)",j+1,i+1);
                AfxMessageBox("Наложение наборов инф.объектов:"+str);
                for(int col = 0; col < m_GridData.GetColumnCount(); col++)
                {
                    m_GridData.SetItemBkColour(j+1,col,RGB(255,128,128));
                    m_GridData.SetItemBkColour(i+1,col,RGB(255,128,128));
                }
                m_GridData.EnsureVisible(i+1,0);
                m_GridData.Refresh();
                return FALSE;
            }
        }
    }
    return TRUE;
}
Exemplo n.º 12
0
BOOL CKorundmDlg::ProcessSave(void)
{
	for(int row = 1; row < m_GridData.GetRowCount(); row++)
	{
		for(int col = 0; col < m_GridData.GetColumnCount(); col++)
		{
			m_GridData.SetItemBkColour(row,col,RGB(255,255,255));
		}
	}	
	m_GridData.Refresh();

	CString str;
		
	str = m_Grid.GetItemText(1,1);
	if((atoi(str)<=0)||(atoi(str)>255))
	{
		AfxMessageBox("Неверно задан СОМ-порт!");
		return FALSE;
	}
	//проверить порты
	if(((CKPLConfigApp*)(AfxGetApp()))->m_KPLProject.IsPortDuplicated(atoi(str)-1,nProcNum))
	{
		AfxMessageBox("Данный СОМ-порт занят под другую задачу!");
		return FALSE;
	}

	m_Korundm.PORT = atoi(str)-1;

	str = m_Grid.GetItemText(2,1);
	m_Korundm.BAUDRATE = atoi(str);

	str = m_Grid.GetItemText(3,1);
	m_Korundm.STOPBITS = atoi(str);

	str = m_Grid.GetItemText(4,1);
	if(str == "NONE")
		m_Korundm.PARITY = 0;
	if(str == "EVEN")
		m_Korundm.PARITY = 1;
	if(str == "ODD")
		m_Korundm.PARITY = 2;

	str = m_Grid.GetItemText(5,1);
	if(str == "нет")
		m_Korundm.FLOWCONTROLL = 0;
	if(str == "аппаратный")
		m_Korundm.FLOWCONTROLL = 1;
	if(str == "программный")
		m_Korundm.FLOWCONTROLL = 2;

	str = m_Grid.GetItemText(6,1);
	if((atoi(str)<=0)||(atoi(str)>3000))
	{
		AfxMessageBox("Таймаут ответа подчиненного в квантах 1..3000!");
		return FALSE;
	}
	m_Korundm.WAITRESP = atoi(str);

	str = m_Grid.GetItemText(7,1);
	if((atoi(str)<=0)||(atoi(str)>3000))
	{
		AfxMessageBox("Пауза между байтами в квантах 1..3000!");
		return FALSE;
	}
	m_Korundm.BYTETIME = atoi(str);

	str = m_Grid.GetItemText(8,1);
	if((atoi(str)<=0)||(atoi(str)>3000))
	{
		AfxMessageBox("Интервал между запросами в квантах 1..3000!");
		return FALSE;
	}
	m_Korundm.NEXTMESSAGE = atoi(str);

	/*str = m_Grid.GetItemText(9,1);
	m_Korundm.SIZE_LINK = atoi(str);

	str = m_Grid.GetItemText(10,1);
	m_Korundm.SIZE_COFT = atoi(str);

	str = m_Grid.GetItemText(11,1);
	m_Korundm.SIZE_ASDU = atoi(str);

	str = m_Grid.GetItemText(12,1);
	m_Korundm.SIZE_IOA = atoi(str);*/

	str = m_Grid.GetItemText(13,1);
	if((atoi(str)<0)||(atoi(str)>4320))
	{
		AfxMessageBox("Таймаут недостоверности: 0 - выкл., 1..4320 мин.!");
		return FALSE;
	}
	m_Korundm.PERIOD_C_IC_NA_1 = atoi(str);

	/*str = m_Grid.GetItemText(14,1);
	if((atoi(str)<0)||(atoi(str)>4320))
	{
		AfxMessageBox("Период для синхронизации времени: 0 - нет, 1..4320 мин.!");
		return FALSE;
	}
	m_Korundm.PERIOD_C_CS_NA_1 = atoi(str);
	
	str = m_Grid.GetItemText(15,1);
	if((atoi(str)<0)||(atoi(str)>50))
	{
		AfxMessageBox("Количество ошибок для генерации \"недостоверности\" 0..50!");
		return FALSE;
	}
	m_Korundm.NUMBER_NO_ANSWER = atoi(str);

	str = m_Grid.GetItemText(16,1);
	if((atoi(str)<m_nStartPMZAddr)||(atoi(str)>m_nEndPMZAddr))
	{
		CString tmp;
		tmp.Format("Запись статуса канала в карту памяти по адресу %d..%d!",m_nStartPMZAddr,m_nEndPMZAddr);
		AfxMessageBox(tmp);
		//return FALSE;
	}
	m_Korundm.ADRES_BADCHANEL = atoi(str);*/

	str = m_Grid.GetItemText(17,1);
	if((atoi(str)<=0)||(atoi(str)>50))
	{
		AfxMessageBox("Количество устройств, подключённых к данному каналу 1..50!");
		return FALSE;
	}
	m_Korundm.NUMBER_OF_DEVICES = atoi(str);
	
	m_Korundm.AMOUNTBYTE = 8;

	/*str = m_Grid.GetItemText(18,1);
	if((atoi(str)<=0)||(atoi(str)>120))
	{
		AfxMessageBox("Время на подтверждение команды ТУ 1..120 c!");
		return FALSE;
	}
	m_Korundm.TIME_TU_EXPIRE = atoi(str);
	
	str = m_Grid.GetItemText(19,1);	
	if((atoi(str)<=0)||(atoi(str)>255))
	{
		AfxMessageBox("Неверно задан Резервный СОМ-порт!");
		return FALSE;
	}	
	m_Korundm.RES_PORT = atoi(str)-1;*/

	
	m_Korundm.m_IndividualStructureKorundArray.RemoveAll();
	int nTotalAmount=0;

	for(int i = 1; i < m_GridData.GetRowCount(); i++)
	{
		IndividualStructureKorund is101;	
		int nCol=0;

		is101.strCOMMENT = m_GridData.GetItemText(i,nCol++);

		str = m_GridData.GetItemText(i,nCol++);										
		if(str == arrMain_Set_ObjectTypes[0])
		{
			is101.TYPE_ID = M_BO_TB_1;
			is101.TYPE_ID_C_IC_NA_1 = 0;
			is101.NUM_BYTE = 12;
			is101.NUM_BYTE_C_IC_NA_1 = 0;
			is101.POZITION_OF_QUALITY_FLAG = 0;
		}
		else if(str == arrMain_Set_ObjectTypes[1])
		{
			is101.TYPE_ID = M_ME_TD_1;
			is101.TYPE_ID_C_IC_NA_1 = 0;
			is101.NUM_BYTE = 10;
			is101.NUM_BYTE_C_IC_NA_1 = 0;
			is101.POZITION_OF_QUALITY_FLAG = 0;							
		}		
		else
		{
			AfxMessageBox("Неверный тип инф. объектов!");
			return FALSE;
		}		

		str = m_GridData.GetItemText(i,nCol++);
		is101.LINK_ADDRESS = atoi(str);
		if((m_Korundm.SIZE_LINK == 1)&&((is101.LINK_ADDRESS>255)||(is101.LINK_ADDRESS<=0)))
		{
			AfxMessageBox("Link Address: 1..255!");
			return FALSE;
		}
		if((m_Korundm.SIZE_LINK == 2)&&((is101.LINK_ADDRESS>65535)||(is101.LINK_ADDRESS<=0)))
		{
			AfxMessageBox("Link Address: 1..65535!");
			return FALSE;
		}


		str = m_GridData.GetItemText(i,nCol++);
		/*is101.ORIGINATOR_ADDRESS = atoi(str);
		if((m_Korundm.SIZE_COFT == 2)&&((is101.ORIGINATOR_ADDRESS>255)||(is101.ORIGINATOR_ADDRESS<0)))
		{
			AfxMessageBox("Originator Address: 0..255!");
			return FALSE;
		}*/		
		
		str = m_GridData.GetItemText(i,nCol++);
		int Hi = atoi(str);
		//is101.COMMON_ADDRESS_ASDU = atoi(str);
		if(((Hi>255)||(Hi<0)))
		{
			AfxMessageBox("№ блока: 0..255!");
			return FALSE;
		}	

		str = m_GridData.GetItemText(i,nCol++);
		int Lo = atoi(str);
		//is101.COMMON_ADDRESS_ASDU = atoi(str);
		if(((Lo>255)||(Lo<0)))
		{
			AfxMessageBox("№ в блоке: 0..255!");
			return FALSE;
		}	
		
		is101.START_IOA = MAKEWORD(Lo,Hi);
		
		str = m_GridData.GetItemText(i,nCol++);
		is101.AM_IOA = atoi(str);
		nTotalAmount+=is101.AM_IOA;

		str = m_GridData.GetItemText(i,nCol++);
		is101.ADDRESS_PMZ = atoi(str);

		if((is101.ADDRESS_PMZ < m_nStartPMZAddr)
			||(is101.ADDRESS_PMZ > m_nEndPMZAddr)
			||(is101.ADDRESS_PMZ + is101.AM_IOA - 1 > m_nEndPMZAddr))
		{
			CString tmp;
			tmp.Format("Набор инф. объектов в строке %d выходит за пределы карты памяти ПРОЦЕССА: %d..%d!",i,m_nStartPMZAddr,m_nEndPMZAddr);
			AfxMessageBox(tmp);
			for(int col = 0; col < m_GridData.GetColumnCount(); col++)
			{
				m_GridData.SetItemBkColour(i,col,RGB(255,128,255));
			}
			m_GridData.EnsureVisible(i,0);
			m_GridData.Refresh();
		}
		m_Korundm.m_IndividualStructureKorundArray.Add(is101);		
	}

	if(nTotalAmount > m_nEndPMZAddr+1)
	{
		str.Format("%d > %d !",nTotalAmount,m_nEndPMZAddr+1);
		AfxMessageBox("Суммарное кол-во инф. объектов больше выделенного количества для данного процесса:"+str);
		//return FALSE;
	}

	for(int i = 0; i < m_Korundm.m_IndividualStructureKorundArray.GetSize();i++)
	{
		for(int j = 0; j < m_Korundm.m_IndividualStructureKorundArray.GetSize();j++)
		{
			if((IsIntersect(m_Korundm.m_IndividualStructureKorundArray[i].ADDRESS_PMZ,
							m_Korundm.m_IndividualStructureKorundArray[i].ADDRESS_PMZ+m_Korundm.m_IndividualStructureKorundArray[i].AM_IOA-1,
							m_Korundm.m_IndividualStructureKorundArray[j].ADDRESS_PMZ,
							m_Korundm.m_IndividualStructureKorundArray[j].ADDRESS_PMZ+m_Korundm.m_IndividualStructureKorundArray[j].AM_IOA-1))
							&&(i!=j))
			{
				str.Format("%d на %d !\r\n(строки подсвечены розовым цветом)",j+1,i+1);
				AfxMessageBox("Наложение наборов инф.объектов:"+str);
				for(int col = 0; col < m_GridData.GetColumnCount(); col++)
				{
					m_GridData.SetItemBkColour(j+1,col,RGB(255,128,128));
					m_GridData.SetItemBkColour(i+1,col,RGB(255,128,128));
				}
				m_GridData.EnsureVisible(i+1,0);
				m_GridData.Refresh();
				return FALSE;
			}
		}
	}


/*/KP		
	CIndividualStructure101Array arr101;
	for(int j = 1; j < m_GridKP.GetRowCount(); j++)
	{
		IndividualStructure101	is101;
		is101.LINK_ADDRESS = atoi(m_GridKP.GetItemText(j,0));

		CGridCellCheck *pCell2 = (CGridCellCheck*) m_GridKP.GetCell(j, 1);
		if(pCell2->GetCheck())
			is101.C_CS_ENABLE = 1;
		else
			is101.C_CS_ENABLE = 0;

		str = m_GridKP.GetItemText(j,2);
		is101.GLOBAL_ASDU = atoi(str);
		if((m_Korundm.SIZE_ASDU == 1)&&((is101.GLOBAL_ASDU>255)||(is101.GLOBAL_ASDU<0)))
		{
			AfxMessageBox("Глобальный ASDU Address: 0..255!");
			return FALSE;
		}	
		if((m_Korundm.SIZE_ASDU == 2)&&((is101.GLOBAL_ASDU>65535)||(is101.GLOBAL_ASDU<0)))
		{
			AfxMessageBox("Глобальный ASDU Address: 0..65535!");
			return FALSE;
		}
		pCell2 = (CGridCellCheck*) m_GridKP.GetCell(j, 3);
		if(pCell2->GetCheck())
			is101.STATUS_TYPE = 1;
		else
			is101.STATUS_TYPE = 0;

		if(is101.STATUS_TYPE == 1)
		{
			str = m_GridKP.GetItemText(j,4);
			is101.STATUS_ADDRESS_PMZ = atoi(str);

			if((is101.STATUS_ADDRESS_PMZ < m_nStartPMZAddr)
				||(is101.STATUS_ADDRESS_PMZ > m_nEndPMZAddr))
			{
				CString tmp;
				tmp.Format("Адрес внутреннего статуса в строке %d выходит за пределы карты памяти ПРОЦЕССА: %d..%d!",j,m_nStartPMZAddr,m_nEndPMZAddr);
				AfxMessageBox(tmp);
				//return FALSE;
			}
			str = m_GridKP.GetItemText(j,5);
			is101.STATUS_MASKA = atoi(str);
		}
		else
		{
			str = m_GridKP.GetItemText(j,4);
			is101.STATUS_ADDRESS_PMZ = atoi(str);			
			str = m_GridKP.GetItemText(j,5);
			is101.STATUS_MASKA = atoi(str);
		}
		arr101.Add(is101);
	}

	for(int i = 0; i < m_Korundm.m_IndividualStructureKorundArray.GetSize();i++)
	{
		for(int j = 0; j < arr101.GetSize();j++)
		{
			if(m_Korundm.m_IndividualStructureKorundArray[i].LINK_ADDRESS == arr101[j].LINK_ADDRESS)
			{
				m_Korundm.m_IndividualStructureKorundArray[i].C_CS_ENABLE = arr101[j].C_CS_ENABLE;
				m_Korundm.m_IndividualStructureKorundArray[i].GLOBAL_ASDU = arr101[j].GLOBAL_ASDU;
				m_Korundm.m_IndividualStructureKorundArray[i].STATUS_ADDRESS_PMZ = arr101[j].STATUS_ADDRESS_PMZ;
				m_Korundm.m_IndividualStructureKorundArray[i].STATUS_MASKA = arr101[j].STATUS_MASKA;
				m_Korundm.m_IndividualStructureKorundArray[i].STATUS_TYPE = arr101[j].STATUS_TYPE;
				break;
			}			
		}
	}*/
	return TRUE;
}