Exemplo n.º 1
0
SqlBool GetTextRange(const String& s1, const String& s2, const SqlVal& exp)
{
    if(IsNull(s1) && IsNull(s2))
        return SqlBool();
    if(IsNull(s1) || IsNull(s2)) // just one - use as template
        return LikeSmartWild(exp, s1 + s2);
//	return Between(GetCsAsciiVal(exp), GetCsAsciiVal(s1), GetCsAsciiVal(s2 + "ŽŽ"));
    return Between(UpperAscii(exp), Upper(s1), Upper(s2 + "ZZ"));
}
Exemplo n.º 2
0
bool NPC::returnToInitialPosition ()
{
	static const float gap = 0.1f;
	const float xPos = getPos().x;
	if (!Between(xPos, _initialPosition.x - gap, _initialPosition.x + gap)) {
		setMoving(_initialPosition);
		return false;
	}
	return true;
}
Exemplo n.º 3
0
char	ParallelInt( tPointi a, tPointi b, tPointi c, tPointi d, tPointd p )
{
   if ( !Collinear( a, b, c) )
      return '0';

   if ( Between( a, b, c ) ) {
      Assigndi( p, c );
      return 'e';
   }
   if ( Between( a, b, d ) ) {
      Assigndi( p, d );
      return 'e';
   }
   if ( Between( c, d, a ) ) {
      Assigndi( p, a );
      return 'e';
   }
   if ( Between( c, d, b ) ) {
      Assigndi( p, b );
      return 'e';
   }
   return '0';
}
Exemplo n.º 4
0
bool InvoiceList::prepare()
{
	String sqlStatement = "select r.invoice_id, r.inv_create_date, \
					(select sum(ri.item_price) from record_item ri where ri.record_id = r.id) \
					from record r \
					where r.invoice_id is not null and r.inv_create_date between '"
					 + AsString(from) + "' and '" + AsString(to) 
					 + "' order by r.inv_create_date, r.invoice_id";
	SQL.Execute(sqlStatement);
	
	bool found = false;
	while (SQL.Fetch()) {
		found = true;
		
		VectorMap<int, String> vmap;
		vmap.Add(iliInvNum, AsString(SQL[0]));
		vmap.Add(iliDate, AsString(SQL[1]));
		vmap.Add(iliTotal, fixFuckedLinuxFormating(ConvertMoney().Format(SQL[2])));
		inv_list_items.Add(vmap);
	}
	if (!found) return false;
	
	SQL & Select(SqlSum(ITEM_PRICE.Of(RECORD_ITEM))).From(RECORD_ITEM)
		.InnerJoin(RECORD).On(RECORD_ID.Of(RECORD_ITEM) == ID.Of(RECORD))
		.Where(NotNull(INVOICE_ID.Of(RECORD)) && (Between(INV_CREATE_DATE.Of(RECORD), from, to)));
	if (SQL.Fetch())
		summary_price = SQL[0];	
	
	invoiceList.Clear();
	invoiceList.Header(String("[A0> ") + String(t_("Page")) + String(" $$P"));
	
	StringBuffer buf;
	
	buf.Cat("{{1f4 ");
	formatHeader(buf);
	buf.Cat(":: ");
	formatCompanyData(buf);
	buf.Cat(":: ");
	formatItems(buf);
	buf.Cat("}}");
	
	LOG(~buf);
	invoiceList << ~buf;

	return true;
}
Exemplo n.º 5
0
SqlBool GetTimeRange(Time min, Time max, const SqlVal& exp, bool force_range)
{
    bool nl = IsNull(min), nh = IsNull(max);
    if(nl && nh)
        return SqlBool();
    if(nh) // 1st defined - equality
        return (force_range ? exp >= min : exp == min);
    if(nl)
        return exp <= max;

    // TODO (idea): here could be an ordering check, something like:
    // if(max < min)
    //     throw SqlExc("Koncové datum pøedchází poèáteèní datum.");
    // Is it a good idea?

    return Between(exp, min, max);
}
Exemplo n.º 6
0
int commom::randomList(const Json::Value &rateList)
{
	static int base = 1000000;
	int rate = random() % 1000 * 1000 + random() % 1000 + 1;
	//rate = (rate + base) % base;
	int low = 1;
	int high = 1;
	for (unsigned i = 0; i < rateList.size(); i++)
	{
		low = high;
		high = high + (int)(rateList[i].asDouble() * base);
		if (Between(rate, low, high))
		{
			return i;
		}
	}
	return 0;
}
Exemplo n.º 7
0
std::string	commom::tighten(const std::string &str)
{
	bool in_string = false;
	std::string tmp;
	for (std::string::const_iterator iter = str.begin(); iter != str.end(); iter++)
	{
		char ch = *iter;
		int a = (unsigned)(ch + 1);
		if (Between(a, 0, 256) && isspace(ch) && in_string == false)
		{
			continue;
		}

		tmp.insert(tmp.end(), ch);
		if (ch == '\"')
		{
			in_string = !in_string;
		}
	}
	return tmp;
}
Exemplo n.º 8
0
void Map::initWindows (CaveMapTile* caveTile, int start, int end)
{
	const int x = caveTile->getGridX();
	const int left = std::max(x - 2, start);
	const int right = std::max(x + 2, end);
	const int caveY = caveTile->getGridY();
	for (EntityListConstIter i = _entities.begin(); i != _entities.end(); ++i) {
		IEntity* e = *i;
		if (!e->isWindow())
			continue;
		WindowTile* window = static_cast<WindowTile*>(e);
		if (window->getGridY() != caveY)
			continue;
		for (int gridX = left; gridX < right; ++gridX) {
			const int windowX = window->getGridX();
			if (Between(windowX, left, right)) {
				caveTile->addWindow(window);
				break;
			}
		}
	}
}
Exemplo n.º 9
0
	void CMMI::Communication(void)
	{
		COMM_BUFFER mmiToSeq;

		if(FALSE == m_kamelas.Recv((PBYTE)&mmiToSeq))
			return;


		switch(mmiToSeq.nCmd)
		{
		case CMD_RD_PKG_DATA:
			{
				int nSize  = sizeof(double) * MAX_PKG_DATA;
				double* pOrigin = &g_nv.m_pNVdata->dbPkgData[0];
				double* pTarget = &mmiToSeq.buffer.pkgData.dData[0];
				memcpy(pTarget, pOrigin, nSize);
			}
			break;

		case CMD_WR_PKG_DATA:
			{
				int nStart = mmiToSeq.buffer.pkgData.nStart;
				int nEnd   = mmiToSeq.buffer.pkgData.nEnd;
				int nSize  = GetSize(nStart, nEnd, sizeof(double), MAX_PKG_DATA);

				if(nSize < 0)
				{
					DebugLog(L"CMD_WR_PKG_DATA fail : range err!!");
					break;
				}

				double* pOrigin = &mmiToSeq.buffer.pkgData.dData[nStart];
				double* pTarget = &g_nv.m_pNVdata->dbPkgData[nStart];
				memcpy(pTarget, pOrigin, nSize);

			}
			break;

		case CMD_RD_NDM:
			{
				int nSize  = sizeof(int) * MAX_NDM_DATA;
				int* pOrigin = &g_nv.m_pNVdata->nDmData[0];
				int* pTarget = &mmiToSeq.buffer.nDm.nData[0];
				memcpy(pTarget, pOrigin, nSize);
			}
			break;

		case CMD_WR_NDM:
			{
				int nStart = mmiToSeq.buffer.nDm.nStart;
				int nEnd   = mmiToSeq.buffer.nDm.nEnd;
				int nSize  = GetSize(nStart, nEnd, sizeof(int), MAX_NDM_DATA);

				if(nSize < 0)
				{
					DebugLog(L"CMD_WR_NDM fail : range err!!");
					break;
				}

				int* pOrigin = &mmiToSeq.buffer.nDm.nData[nStart];
				int* pTarget = &g_nv.m_pNVdata->nDmData[nStart];
				memcpy(pTarget, pOrigin, nSize);
			}
			break;

		case CMD_RD_DDM:
			{
				int nSize  = sizeof(double) * MAX_DDM_DATA;
				double* pOrigin = &g_nv.m_pNVdata->dbDmData[0];
				double* pTarget = &mmiToSeq.buffer.dDm.dData[0];
				memcpy(pTarget, pOrigin, nSize);
			}
			break;

		case CMD_WR_DDM:
			{
				int nStart = mmiToSeq.buffer.dDm.nStart;
				int nEnd   = mmiToSeq.buffer.dDm.nEnd;
				int nSize  = GetSize(nStart, nEnd, sizeof(double), MAX_DDM_DATA);

				if(nSize < 0)
				{
					DebugLog(L"CMD_WR_DDM fail : range err!!");
					break;
				}

				double* pOrigin = &mmiToSeq.buffer.dDm.dData[nStart];
				double* pTarget = &g_nv.m_pNVdata->dbDmData[nStart];
				memcpy(pTarget, pOrigin, nSize);
			}
			break;


		case CMD_RD_USESKIP:
			{
				int nSize  = sizeof(int) * MAX_USE_SKIP_DATA;
				int* pOrigin = &g_nv.m_pNVdata->bUseSkipData[0];
				int* pTarget = &mmiToSeq.buffer.useSkip.nData[0];
				memcpy(pTarget, pOrigin, nSize);
			}
			break;

		case CMD_WR_USESKIP:
			{
				int nStart = mmiToSeq.buffer.useSkip.nStart;
				int nEnd   = mmiToSeq.buffer.useSkip.nEnd;
				int nSize  = GetSize(nStart, nEnd, sizeof(int), MAX_USE_SKIP_DATA);

				if(nSize < 0)
				{
					DebugLog(L"CMD_WR_USESKIP fail : range err!!");
					break;
				}

				int* pOrigin = &mmiToSeq.buffer.useSkip.nData[nStart];
				int* pTarget = &g_nv.m_pNVdata->bUseSkipData[nStart];
				memcpy(pTarget, pOrigin, nSize);
			}
			break;


		case CMD_RD_IO:
			{
				PWORD pTarget, pOrigin;
				int nSize;

				nSize   = INPUTCH_CNT * sizeof(WORD);
				pTarget = &mmiToSeq.buffer.io.inCH[0];
				pOrigin = &g_input.m_ch[0];
				memcpy(pTarget, pOrigin, nSize);


				nSize   = OUTPUTCH_CNT * sizeof(WORD);
				pTarget = &mmiToSeq.buffer.io.outCH[0];
				pOrigin = &g_output.m_ch[0];
				memcpy(pTarget, pOrigin, nSize);	
			}
			break;

		case CMD_WR_IO:
			{
				if(!g_opr.bStop || g_opr.bPaused)
					break;

				int nStart = mmiToSeq.buffer.io.nStart;
				int nEnd   = mmiToSeq.buffer.io.nEnd;
				int nSize  = GetSize(nStart, nEnd, sizeof(WORD), OUTPUTCH_CNT);

				if(nSize < 0)
				{
					DebugLog(L"CMD_WR_IO fail : range err!!");
					break;
				}

				WORD* pOrigin = &mmiToSeq.buffer.io.outCH[nStart];
				WORD* pTarget = &g_output.m_ch[nStart];
				memcpy(pTarget, pOrigin, nSize);
			}
			break;

		case CMD_RD_ERROR:
			{
				UINT nSize = sizeof(UINT) * 10;
				UINT *pTarget = &mmiToSeq.buffer.nErr[0];
				UINT *pOrigin = g_err.GetAddr();
				memcpy(pTarget, pOrigin, nSize);
			}
			break;


		case CMD_RD_MT_STATUS:
			{
				int nMtNo = mmiToSeq.buffer.mtData.nMtNo; 
				if(!Between(nMtNo, 0, 19))
					break;

				mmiToSeq.buffer.mtData.state.bServoOn  = g_mt[nMtNo].m_state.bServoOn;   
				mmiToSeq.buffer.mtData.state.bCCw      = g_mt[nMtNo].m_state.bLimitCCw;
				mmiToSeq.buffer.mtData.state.bCw       = g_mt[nMtNo].m_state.bLimitCw;
				mmiToSeq.buffer.mtData.state.bOrg      = g_mt[nMtNo].m_state.bOrg;
				mmiToSeq.buffer.mtData.state.bHome     = g_mt[nMtNo].IsHome();
				mmiToSeq.buffer.mtData.state.bDriving  = g_mt[nMtNo].m_state.bDriving;
				mmiToSeq.buffer.mtData.state.bPaused   = g_mt[nMtNo].IsPaused();
				mmiToSeq.buffer.mtData.state.dRealCnt  = g_mt[nMtNo].m_state.nRealCnt;
				mmiToSeq.buffer.mtData.state.bAlarm    = g_mt[nMtNo].m_state.bAlarm;
				mmiToSeq.buffer.mtData.state.nCurIndex = g_mt[nMtNo].m_nCurIndex;
			}
			break;

		case CMD_WR_MT_CMD:
			{
				
				int nMtNo = mmiToSeq.buffer.mtData.nMtNo; 
				if(!Between(nMtNo, 0, 19))
					break;

				int nCmd   = mmiToSeq.buffer.mtData.control.nControlType;
				int nIndex = mmiToSeq.buffer.mtData.control.nCmdIndexNo;
				int nDir   = mmiToSeq.buffer.mtData.control.nDir;
				int nPulse = (int)(mmiToSeq.buffer.mtData.control.dPulse); 
				int nJogVel= g_nv.NDm(jogSpeed); //g_mt[nMtNo].m_config.nFastHomeSpeed;


				switch(nCmd)
				{
				case MTCMD_SERVO_ON:
					if(!g_opr.bStop)
						break;
					g_mt[nMtNo].ServoOn();
					break;

				case MTCMD_SERVO_OFF:
					if(!g_opr.bStop)
						break;
					g_mt[nMtNo].ServoOff();
					break;

				case MTCMD_INDEX_MOVE:
					if(g_nv.NDm(doorOpen))
					{
						g_err.ChkDoor();
						break;
					}

					if(!g_opr.bStop || g_opr.bEmg || g_opr.bPaused || g_allHome.m_bStartAll || AOn(iMarkProg))
						break;

// 					if(!g_MtSafety.CanMove(nMtNo, nIndex))
// 						break;

					if(!g_err.ChkMtSafety(nMtNo, nIndex))
						break;

					// Rear Stage 동기화 Move
					if (MT_REAR_STAGE == nMtNo)
					{
						int nBasePos = g_mt[MT_REAR_STAGE].m_table.nPos[nIndex];
						int nTargetPos = nBasePos - (int)(g_nv.Dm(rearStageSyncOffset) * 1000);

						g_mt[MT_REAR_STAGE].PMove(nIndex, nTargetPos);
						break;
					}

					g_mt[nMtNo].Move(nIndex);
					break;

				case MTCMD_JOG_MOVE:
					if(g_nv.NDm(doorOpen))
					{
						g_err.ChkDoor();
						break;
					}

					if(!g_opr.bStop || g_opr.bEmg || g_opr.bPaused || g_allHome.m_bStartAll || AOn(iMarkProg))
						break;

// 					if(!g_MtSafety.CanMove(nMtNo))
// 						break;

					if(g_mt[nMtNo].m_nCmdIndex < MTINDEX_WAIT)
					{
						g_mt[nMtNo].m_nNextIndex = g_mt[nMtNo].m_nCmdIndex;
						g_mt[nMtNo].m_nCmdIndex  = g_mt[nMtNo].m_nCurIndex = MTINDEX_WAIT;
					}

					if(nDir)
						g_mt[nMtNo].RMove(200000, nJogVel); //1회 최대 이동량은 200mm
					else
						g_mt[nMtNo].RMove(-200000, nJogVel);
					break;

				case MTCMD_JOG_STOP:
					g_mt[nMtNo].Stop(TRUE);
					break;

				case MTCMD_R_MOVE:
					if(g_nv.NDm(doorOpen))
					{
						g_err.ChkDoor();
						break;
					}

					if(!g_opr.bStop || g_opr.bEmg || g_opr.bPaused || g_allHome.m_bStartAll)
						break;

// 					if(!g_MtSafety.CanMove(nMtNo))
// 						break;

					if(g_mt[nMtNo].m_nCmdIndex < MTINDEX_WAIT)
					{
						g_mt[nMtNo].m_nNextIndex = g_mt[nMtNo].m_nCmdIndex;
						g_mt[nMtNo].m_nCmdIndex  = g_mt[nMtNo].m_nCurIndex = MTINDEX_WAIT;
					}

					if(nDir)
						g_mt[nMtNo].RMove(nPulse, nJogVel);
					else
						g_mt[nMtNo].RMove(nPulse * (-1), nJogVel);
					break;

				case MTCMD_A_MOVE:
					{
						if(g_nv.NDm(doorOpen))
						{
							g_err.ChkDoor();
							break;
						}

						if(!g_opr.bStop || g_opr.bEmg || g_opr.bPaused || g_allHome.m_bStartAll)
							break;

// 						if(!g_MtSafety.CanMove(nMtNo))
// 							break;

						if(g_mt[nMtNo].m_nCmdIndex < MTINDEX_WAIT)
						{
							g_mt[nMtNo].m_nNextIndex = g_mt[nMtNo].m_nCmdIndex;
							g_mt[nMtNo].m_nCmdIndex  = g_mt[nMtNo].m_nCurIndex = MTINDEX_WAIT;
						}

						int nAMovePos = nPulse - g_mt[nMtNo].m_state.nCmdCnt;
						g_mt[nMtNo].RMove(nAMovePos);
					}
					break;

				case MTCMD_ALL_HOME:
					break;

				case MTCMD_HOME:
					if(g_nv.NDm(doorOpen))
					{
						g_err.ChkDoor();
						break;
					}

					if(!g_opr.bStop || g_opr.bEmg || g_opr.bPaused || g_allHome.m_bStartAll)
						break;

// 					if(!g_MtSafety.CanMove(nMtNo))
// 						break;

					g_mt[nMtNo].CancelHomeSearch();
					g_mt[nMtNo].StartHomeSearch();
					break;

				case MTCMD_RESET:
					g_mt[nMtNo].AlarmClear();
					break;

				case MTCMD_STOP:
					g_mt[nMtNo].Stop(FALSE);
					break;
				}
			}
			break;

		case CMD_RD_MTTABLE:
			{
				int nMtNo = mmiToSeq.buffer.mtData.nMtNo; 
				if(!Between(nMtNo, 0, 19))
					break;

				for(int nIndex = 0; nIndex < MAX_MTARRAY; nIndex++)
				{
					mmiToSeq.buffer.mtData.table.dPos[nIndex]   = g_mt[nMtNo].m_table.nPos[nIndex];
					mmiToSeq.buffer.mtData.table.dSpeed[nIndex] = g_mt[nMtNo].m_table.nSpeed[nIndex];
				}
			}
			break;

		case CMD_WR_MTTABLE:
			{
				
				int nMtNo = mmiToSeq.buffer.mtData.nMtNo; 
				if(!Between(nMtNo, 0, 19))
					break;

				for(int nIndex = 0; nIndex < MAX_MTARRAY; nIndex ++)
				{
					g_mt[nMtNo].m_table.nPos[nIndex]   = (int)(mmiToSeq.buffer.mtData.table.dPos[nIndex]);
					g_mt[nMtNo].m_table.nSpeed[nIndex] = (int)(mmiToSeq.buffer.mtData.table.dSpeed[nIndex]);

					if(g_mt[nMtNo].m_config.nMaxSpeed < g_mt[nMtNo].m_table.nSpeed[nIndex])
					{
						g_mt[nMtNo].m_table.nSpeed[nIndex] = g_mt[nMtNo].m_config.nMaxSpeed;
					}
				}

				g_nv.WriteMtTable(nMtNo, g_mt[nMtNo].m_table);
			}
			break;

		case CMD_WR_PRSVI:
			//			
			break;

		case CMD_RD_MARK_COORD_F:
			//
			break;

		case CMD_RD_MARK_COORD_R:
			//
			break;

		case CMD_WR_ID_SEL_MAP_DATA:
			{
				// 초기화 Data(0) 검출..
				g_LdMz.m_bSelMapDataInitErr = TRUE;
				g_LdMz.m_bSelMapDataErr = FALSE;

				int nMaxCnt =  (int)(g_nv.PkgData(unitXcnt) * g_nv.PkgData(unitYcnt) * g_nv.PkgData(blockCount));

				for (int i = 0; i < 300; i++)
				{
					if(i < nMaxCnt)
					{
						g_LdMz.m_Info.nSelectMapData[i] = mmiToSeq.buffer.nIdSelMapData[i];

						// Data 오류 검출(1 이상의 값은 쓰레기 Data)
						if(1 < g_LdMz.m_Info.nSelectMapData[i])
							g_LdMz.m_bSelMapDataErr = TRUE;
						if(1 == g_LdMz.m_Info.nSelectMapData[i])
							g_LdMz.m_bSelMapDataInitErr = FALSE;
					}
					else
					{
						g_LdMz.m_Info.nSelectMapData[i] = 0;
					}
				}
			}
			break;

		case CMD_RD_MK_SEL_MAP_DATA:
			{
				int nMaxCnt = (int)(g_nv.PkgData(unitXcnt) * g_nv.PkgData(unitYcnt) * g_nv.PkgData(blockCount));

				BOOL bErr = FALSE;

				for(int nCnt = 0; nCnt < 300; nCnt++)
				{
					if(nCnt < nMaxCnt)
					{
						if(1 == g_nv.PkgData(useSkipSelectMap))
							mmiToSeq.buffer.nMkSelMapData[nCnt] = g_mkSelMap.nData[nCnt];
						else
							mmiToSeq.buffer.nMkSelMapData[nCnt] = _GOOD_;
						
						if(1 < mmiToSeq.buffer.nMkSelMapData[nCnt])
							bErr = TRUE;
					}
					else
					{
						mmiToSeq.buffer.nMkSelMapData[nCnt] = 0;
					}
				}

				if(bErr)
					g_err.Save(ER_LSR_WRONG_MAP_DATA);
			}
			break;

		case CMD_RD_QC_SEL_MAP_DATA:
			{
				int nMaxCnt = (int)(g_nv.PkgData(unitXcnt) * g_nv.PkgData(unitYcnt) * g_nv.PkgData(blockCount));

				BOOL bErr = FALSE;
				
				for(int nCnt = 0; nCnt < 300; nCnt++)
				{
					if(nCnt < nMaxCnt)
					{
						if(1 == g_nv.PkgData(useSkipSelectMap))
							mmiToSeq.buffer.nQcSelMapData[nCnt] = g_qcSelMap.nData[nCnt];
						else
							mmiToSeq.buffer.nQcSelMapData[nCnt] = _GOOD_;

						if(1 < mmiToSeq.buffer.nQcSelMapData[nCnt])
							bErr = TRUE;
					}
					else
					{
						mmiToSeq.buffer.nQcSelMapData[nCnt] = 0;
					}
				}

				if(bErr)
				{
					g_err.Save(ER_QC_WRONG_MAP_DATA);
				}
			}
			break;
		}

		if(FALSE == m_kamelas.Send((PBYTE)&mmiToSeq))
		{
			DebugLog(L"Kamelas Err : Failed to send data!!");
		}
	}
Exemplo n.º 10
0
bool IsInSection(Point const & p1, Point const & p2, Point const & p)
{
  return Between(p1.x, p2.x, p.x) && Between(p1.y, p2.y, p.y);
}
Exemplo n.º 11
0
void CTenkeyOpr::Jog(void)
{
	if(!Between(g_nv.NDm(jogSpeed), 1, 100))
		g_nv.NDm(jogSpeed) = 5;

	int nAxisNo   = g_nv.NDm(jogAxisNo);
	int nJogSpeed = (g_nv.NDm(jogSpeed) * 1000);

	BOOL bLpressed = (CLR_KEY == m_tenkey.GetKeyPadNo());
	BOOL bRpressed = (SET_KEY == m_tenkey.GetKeyPadNo());

	BOOL bJogStop   = (TRUE != g_nv.NDm(tenKeyJog));
	     bJogStop  |= (g_opr.bCycleProgress || !g_opr.bStop || g_allHome.m_bStartAll);

	BOOL bLdGantry  = (MT_2ND_RAIL_Y1 == nAxisNo || MT_2ND_RAIL_Y2 == nAxisNo);
	BOOL bUldGantry = (MT_3RD_RAIL_Y1 == nAxisNo || MT_3RD_RAIL_Y2 == nAxisNo);

	if(bJogStop)
	{
		if((C_JOGSTOP > m_fsmJog.GetStatus()) && (C_IDLE != m_fsmJog.GetStatus()))
			m_fsmJog.SetStatus(C_JOGSTOP);
	}


	switch(m_fsmJog.GetStatus())
	{
	case C_JOGWAIT:
		if(g_mt[nAxisNo].m_state.bDriving)
			break;

		if(bLpressed || bRpressed)
		{
			if(g_mt[nAxisNo].m_nCmdIndex < MTINDEX_WAIT)
			{
				g_mt[nAxisNo].m_nNextIndex = g_mt[nAxisNo].m_nCmdIndex;
				g_mt[nAxisNo].m_nCmdIndex  = g_mt[nAxisNo].m_nCurIndex = MTINDEX_WAIT;
			}
		}

		if(bRpressed)
		{
			if(bLdGantry)
				g_mt[MT_2ND_RAIL_Y1].RMove(-20000, nJogSpeed);
			else if(bUldGantry)
				g_mt[MT_3RD_RAIL_Y1].RMove(-20000, nJogSpeed);
			else
				g_mt[nAxisNo].RMove(-200000, nJogSpeed); 

			m_fsmJog.SetStatus(C_JOGMOVE_N);
		}
		else if(bLpressed)
		{
			if(bLdGantry)
				g_mt[MT_2ND_RAIL_Y1].RMove(20000, nJogSpeed);
			else if(bUldGantry)
				g_mt[MT_3RD_RAIL_Y1].RMove(20000, nJogSpeed);
			else
				g_mt[nAxisNo].RMove(200000, nJogSpeed); 

			m_fsmJog.SetStatus(C_JOGMOVE_P);
		}
		break;

	case C_JOGMOVE_N:
		if(!bRpressed)
		{
			m_fsmJog.SetStatus(C_JOGSTOP);
		}
		else
		{
			if(bLdGantry)
			{
				if(!g_mt[MT_2ND_RAIL_Y1].m_state.bDriving)
					m_fsmJog.SetStatus(C_IDLE);
			}
			else if(bUldGantry)
			{
				if(!g_mt[MT_3RD_RAIL_Y1].m_state.bDriving)
					m_fsmJog.SetStatus(C_IDLE);
			}
			else if(!g_mt[nAxisNo].m_state.bDriving)
			{
				m_fsmJog.SetStatus(C_IDLE);
			}
		}
		break;

	case C_JOGMOVE_P:
		if(!bLpressed)
		{
			m_fsmJog.SetStatus(C_JOGSTOP);
		}
		else
		{
			if(bLdGantry)
			{
				if(!g_mt[MT_2ND_RAIL_Y1].m_state.bDriving)
					m_fsmJog.SetStatus(C_IDLE);
			}
			else if(bUldGantry)
			{
				if(!g_mt[MT_3RD_RAIL_Y1].m_state.bDriving)
					m_fsmJog.SetStatus(C_IDLE);
			}
			else if(!g_mt[nAxisNo].m_state.bDriving)
			{
				m_fsmJog.SetStatus(C_IDLE);
			}
		}
		break;

	case C_JOGSTOP:
		if(bLdGantry)
		{
			if(g_mt[MT_2ND_RAIL_Y1].m_fsmHome.IsRun())
				break;
			g_mt[MT_2ND_RAIL_Y1].Stop(TRUE);
		}
		else if(bUldGantry)
		{
			if(g_mt[MT_3RD_RAIL_Y1].m_fsmHome.IsRun())
				break;
			g_mt[MT_3RD_RAIL_Y1].Stop(TRUE);
		}
		else
		{
			if(g_mt[nAxisNo].m_fsmHome.IsRun())
				break;

			g_mt[nAxisNo].Stop(TRUE);
		}
		m_fsmJog.SetStatus(C_IDLE);
		break;

	case C_IDLE:
		if(TRUE == bJogStop)
			break;
		if(FALSE == g_opr.bStop)
			break;

		if(NO_KEY == m_tenkey.GetKeyPadNo())
			m_fsmJog.SetStatus(C_JOGWAIT);
		break;

	default:
		m_fsmJog.SetStatus(C_IDLE);
		break;
	}
}
Exemplo n.º 12
0
bool
tBetween( LibTest & tester )
{
  {
    long    a( 1023 );
    long    b( a + 2732 );

    {
      for( short t = a; t <= b; ++ t )
	{
	  TEST( Between( a, b, t ) );
	  TEST( Between( b, a, t ) );
	}
    }
    TEST( ! Between( a, b, a * -1 ) );
    TEST( ! Between( b, a, a * -1 ) );
    
    TEST( ! Between( a, b, 0 ) );
    TEST( ! Between( b, a, 0 ) );
    
    TEST( ! Between( a, b, a - 1 ) );
    TEST( ! Between( b, a, a - 1 ) );
    
    TEST( ! Between( a, b, b + 1 ) );
    TEST( ! Between( b, a, b + 1 ) );
    
    TEST( ! Between( a, b, b + a ) );
    TEST( ! Between( b, a, b + a ) );
  }

  return( true );
}
Exemplo n.º 13
0
int SegSegIntersect(Vec *pEdge, Vec *qEdge, 
                    Vec *p0, Vec *p1, Vec *q0, Vec *q1, 
                    Vec *intersect1, Vec *intersect2)
{
   double pDot,  qDot;  /* Dot product [cos(length)] of the edge vertices */
   double p0Dot, p1Dot; /* Dot product from vertices to intersection      */
   double q0Dot, q1Dot; /* Dot pro}duct from vertices to intersection     */
   int    len;


   /* Get the edge lengths (actually cos(length)) */

   pDot = Dot(p0, p1);
   qDot = Dot(q0, q1);


   /* Find the point of intersection */

   len = Cross(pEdge, qEdge, intersect1);


   /* If the two edges are colinear, */ 
   /* check to see if they overlap   */

   if(len == 0)
   {
      if(Between(q0, p0, p1)
      && Between(q1, p0, p1))
      {
         intersect1 = q0;
         intersect2 = q1;
         return COLINEAR_SEGMENTS;
      }

      if(Between(p0, q0, q1)
      && Between(p1, q0, q1))
      {
         intersect1 = p0;
         intersect2 = p1;
         return COLINEAR_SEGMENTS;
      }

      if(Between(q0, p0, p1)
      && Between(p1, q0, q1))
      {
         intersect1 = q0;
         intersect2 = p1;
         return COLINEAR_SEGMENTS;
      }

      if(Between(p0, q0, q1)
      && Between(q1, p0, p1))
      {
         intersect1 = p0;
         intersect2 = q1;
         return COLINEAR_SEGMENTS;
      }

      if(Between(q1, p0, p1)
      && Between(p1, q0, q1))
      {
         intersect1 = p0;
         intersect2 = p1;
         return COLINEAR_SEGMENTS;
      }

      if(Between(q0, p0, p1)
      && Between(p0, q0, q1))
      {
         intersect1 = p0;
         intersect2 = q0;
         return COLINEAR_SEGMENTS;
      }

      return NO_INTERSECTION;
   }


   /* If this is the wrong one of the two */
   /* (other side of the sky) reverse it  */

   Normalize(intersect1);

   if(Dot(intersect1, p0) < 0.)
      Reverse(intersect1);


   /* Point has to be inside both sides to be an intersection */

   if((p0Dot = Dot(intersect1, p0)) <  pDot) return NO_INTERSECTION;
   if((p1Dot = Dot(intersect1, p1)) <  pDot) return NO_INTERSECTION;
   if((q0Dot = Dot(intersect1, q0)) <  qDot) return NO_INTERSECTION;
   if((q1Dot = Dot(intersect1, q1)) <  qDot) return NO_INTERSECTION;


   /* Otherwise, if the intersection is at an endpoint */

   if(p0Dot == pDot) return ENDPOINT_ONLY;
   if(p1Dot == pDot) return ENDPOINT_ONLY;
   if(q0Dot == qDot) return ENDPOINT_ONLY;
   if(q1Dot == qDot) return ENDPOINT_ONLY;


   /* Otherwise, it is a normal intersection */

   return NORMAL_INTERSECT;
}
Exemplo n.º 14
0
void Graphics::PlotFlatBottomTriangle(HDC hdc, ScreenPoint p1, ScreenPoint p2, ScreenPoint p3, const Texture& texture) {
	AssertEx(Approximately(p1.y, p2.y) && p1.y >= p3.y, "invalid flat bottom triangle");

	if (p1.x > p2.x) std::swap(p1, p2);
	float dy = -float(p3.y - p1.y);

	float dxdyl = float(p1.x - p3.x) / dy;
	float dxdyr = float(p2.x - p3.x) / dy;

	ColorDiff dcdyl = (p1.color - p3.color) / dy;
	ColorDiff dcdyr = (p2.color - p3.color) / dy;

	float dzdyl = float(1.f / p1.z - 1.f / p3.z) / dy;
	float dzdyr = float(1.f / p2.z - 1.f / p3.z) / dy;

	float dudyl = float(p1.u / p1.z - p3.u / p3.z) / dy;
	float dudyr = float(p2.u / p2.z - p3.u / p3.z) / dy;
	float dvdyl = float(p1.v / p1.z - p3.v / p3.z) / dy;
	float dvdyr = float(p2.v / p2.z - p3.v / p3.z) / dy;

	float xl = (float)p3.x, xr = (float)p3.x;
	float zl = 1.f / p3.z, zr = 1.f / p3.z;

	Color cl = p3.color;
	Color cr = p3.color;

	float ul = (float)p3.u / p3.z;
	float vl = (float)p3.v / p3.z;
	float ur = (float)p3.u / p3.z;
	float vr = (float)p3.v / p3.z;

	int iy1 = 0, iy3 = 0;

	if (p3.y < ymin) {
		UPDATE_VAR(ymin - p3.y);

		p3.y = ymin;
		iy3 = p3.y;
	}
	else {
		iy3 = (int)ceilf(p3.y);
		UPDATE_VAR(iy3 - p3.y);
	}

	if (p1.y > ymax) {
		p1.y = ymax;
		iy1 = p1.y - 1;
	}
	else {
		iy1 = ceilf(p1.y) - 1;
	}

	if (Between(p1.x, xmin, xmax) && Between(p2.x, xmin, xmax) && Between(p3.x, xmin, xmax)) {
		for (int y = iy3; y <= iy1; ++y) {
			PlotGradientLine(hdc, cl, cr, zl, zr, ul, ur, vl, vr, xl, xr, y, texture);
			UPDATE_VAR(1.f);
		}
	}
	else {
		for (int y = iy3; y <= iy1; ++y) {
			float left = xl, right = xr;
			Color tcl = cl;
			float tzl = zl, tul = ul, tvl = vl;
			if(right >= xmin && left <= xmax) {
				if (left < xmin) {
					SHIFT_RIGHT_SCALE((xmin - left) / (right - left));
					left = xmin;
				}
				right = Min(right, xmax);
				PlotGradientLine(hdc, tcl, cr, tzl, zr, tul, ur, tvl, vr, left, right, y, texture);
			}

			UPDATE_VAR(1.f);
		}
	}
}
Exemplo n.º 15
0
 template <class PointT> bool IsInSection(PointT const & p1, PointT const & p2, PointT const & p)
 {
   return Between(p1.x, p2.x, p.x) && Between(p1.y, p2.y, p.y);
 }
Exemplo n.º 16
0
char   ParallelInt( tPointi a, tPointi b, tPointi c, tPointi d, tPointd p, tPointd q )
{
/*   
   printf("ParallelInt: a,b,c,d: (%d,%d), (%d,%d), (%d,%d), (%d,%d)\n",
	a[X],a[Y], b[X],b[Y], c[X],c[Y], d[X],d[Y]);
*/

   if ( !Collinear( a, b, c) )
      return '0';

   if ( Between( a, b, c ) && Between( a, b, d ) ) {
      Assigndi( p, c );
      Assigndi( q, d );
      return 'e';
   }
   if ( Between( c, d, a ) && Between( c, d, b ) ) {
      Assigndi( p, a );
      Assigndi( q, b );
      return 'e';
   }
   if ( Between( a, b, c ) && Between( c, d, b ) ) {
      Assigndi( p, c );
      Assigndi( q, b );
      return 'e';
   }
   if ( Between( a, b, c ) && Between( c, d, a ) ) {
      Assigndi( p, c );
      Assigndi( q, a );
      return 'e';
   }
   if ( Between( a, b, d ) && Between( c, d, b ) ) {
      Assigndi( p, d );
      Assigndi( q, b );
      return 'e';
   }
   if ( Between( a, b, d ) && Between( c, d, a ) ) {
      Assigndi( p, d );
      Assigndi( q, a );
      return 'e';
   }
   return '0';
}