Exemple #1
0
double CChartAxis::GetNextTickValue(double Previous)
{
	double NewTick = 0;
	switch (m_AxisType)
	{
	case atStandard:
		NewTick = Previous + m_TickIncrement;
		break;

	case atLogarithmic:
		NewTick = Previous * m_TickIncrement;
		break;

	case atDateTime:
		{
			COleDateTime dtTick((DATE)Previous);
			COleDateTimeSpan dtSpan;
			switch (m_BaseInterval)
			{
			case tiSecond:
				dtSpan.SetDateTimeSpan(0,0,0,m_iDTTickIntervalMult);
				dtTick += dtSpan;
				break;
			case tiMinute:
				dtSpan.SetDateTimeSpan(0,0,m_iDTTickIntervalMult,0);
				dtTick += dtSpan;
				break;
			case tiHour:
				dtSpan.SetDateTimeSpan(0,m_iDTTickIntervalMult,0,0);
				dtTick += dtSpan;
				break;
			case tiDay:
				dtSpan.SetDateTimeSpan(m_iDTTickIntervalMult,0,0,0);
				dtTick += dtSpan;
				break;
			case tiMonth:
				{
					dtTick = AddMonthToDate(dtTick,m_iDTTickIntervalMult);
				}
				break;
			case tiYear:
				break;
			}

			NewTick = (DATE)dtTick;
		}
		break;
	}

	return NewTick;
}
Exemple #2
0
static void __stdcall ActivityCallback(ConversionActivity* activity, void* userData)
{
	COleDateTimeSpan ts;

	ts.SetDateTimeSpan(0, 0, 0, activity->ElapsedTimeSpanInSeconds);

	char spinner[] = {'-', '\\', '|', '/'};

	if (_spinnerIndex++ >= 3) _spinnerIndex = 0;

	TCHAR output1[128];
	TCHAR output2[128];
	TCHAR output3[128];

	_stprintf_s(output1, _T(" %c %s converted: %sK d/l'ed:"),
		spinner[_spinnerIndex],
		ts.Format(_T("%H:%M:%S")),
		CommaSeparate((ULONGLONG)activity->CurrentFileSize / 1024));

	_stprintf_s(output2, _T("%sK"),
		CommaSeparate((ULONGLONG)activity->DownloadCurrent / 1024));

	_stprintf_s(output3, _T("/ %sK"),
		CommaSeparate((ULONGLONG)activity->DownloadTotal / 1024));

	_tprintf_s(_T("%s %s %s\r"), output1, output2, output3);
}
bool CChartDateTimeAxis::GetNextTickValue(double dCurrentTick, double& dNextTick) const
{
	if (m_MinValue == m_MaxValue)
		return false;

	COleDateTime dtTick((DATE)dCurrentTick);
	COleDateTimeSpan dtSpan;
	switch (m_BaseInterval)
	{
	case tiSecond:
		dtSpan.SetDateTimeSpan(0,0,0,m_iDTTickIntervalMult);
		dtTick += dtSpan;
		break;
	case tiMinute:
		dtSpan.SetDateTimeSpan(0,0,m_iDTTickIntervalMult,0);
		dtTick += dtSpan;
		break;
	case tiHour:
		dtSpan.SetDateTimeSpan(0,m_iDTTickIntervalMult,0,0);
		dtTick += dtSpan;
		break;
	case tiDay:
		dtSpan.SetDateTimeSpan(m_iDTTickIntervalMult,0,0,0);
		dtTick += dtSpan;
		break;
	case tiMonth:
		dtTick = AddMonthToDate(dtTick,m_iDTTickIntervalMult);
		break;
	case tiYear:
		dtTick = AddMonthToDate(dtTick,12*m_iDTTickIntervalMult);
		break;
	}

	dNextTick = (DATE)dtTick;
	if (dNextTick <= m_MaxValue)
		return true;
	else
		return false;
}
double CChartDateTimeAxis::GetFirstTickValue() const
{
	double dRetVal = m_dFirstTickValue;
	if (m_bDiscrete)
	{
		COleDateTime dtTick((DATE)m_dFirstTickValue);
		COleDateTimeSpan dtSpan;
		switch (m_BaseInterval)
		{
		case tiSecond:
			dtSpan.SetDateTimeSpan(0,0,0,m_iDTTickIntervalMult);
			dtTick -= dtSpan;
			break;
		case tiMinute:
			dtSpan.SetDateTimeSpan(0,0,m_iDTTickIntervalMult,0);
			dtTick -= dtSpan;
			break;
		case tiHour:
			dtSpan.SetDateTimeSpan(0,m_iDTTickIntervalMult,0,0);
			dtTick -= dtSpan;
			break;
		case tiDay:
			dtSpan.SetDateTimeSpan(m_iDTTickIntervalMult,0,0,0);
			dtTick -= dtSpan;
			break;
		case tiMonth:
			dtTick = AddMonthToDate(dtTick,-m_iDTTickIntervalMult);
			break;
		case tiYear:
			dtTick = AddMonthToDate(dtTick,-12*m_iDTTickIntervalMult);
			break;
		}
	}
	return dRetVal;

}
Exemple #5
0
void  VirtualMeasurement::UpdateDischargeDate()
{
	//if (_iMPMeasurementType == AssemblyVerification)
	{
		if (_fMPCoolingTime < 0.0f)
			_fMPCoolingTime = 0.0;

		// change discharge date to conform to the cooling time
		// cooling time is in years
		COleDateTimeSpan coolings;
		int secs = int(24.0*60.0*60.0 * 365.0 * _fMPCoolingTime);
		coolings.SetDateTimeSpan(0, 0, 0, secs);

		COleDateTime dd = _iMPMeasurementDateTime - coolings;
		_iMPDischargeDateYear = dd.GetYear();
		_iMPDischargeDateMonth = dd.GetMonth();
		_iMPDischargeDateDay = dd.GetDay();

	}
}
COleDateTime CXTPCalendarTLV_TimeScaleParams::CalcScaleIntervalBegin(
														COleDateTime dtStart)
{
	if (!m_scaleInterval.m_nValue)
	{
		ASSERT(FALSE);
		return dtStart;
	}

	COleDateTime dtBegin = dtStart;

	int nFirstDayOfWeekIndex = 0;
	COleDateTimeSpan spAdd;

	LONGLONG nVal = 0;
	LONGLONG nDiv = 0;
	//int nMod = 0;
	LONGLONG nNewVal = 0;

	LONGLONG nllDays_total = (int)(DATE)dtStart;

	switch (m_scaleInterval.m_eType)
	{
	case xtpDTScale_Sec:
		nVal = dtStart.GetSecond() + nllDays_total * 24 * 60 * 60;
		nDiv = nVal / m_scaleInterval.m_nValue;
		nNewVal = nDiv * m_scaleInterval.m_nValue;

		dtBegin = (DATE)(nNewVal / (24 * 60 * 60));
		dtBegin = CXTPCalendarUtils::UpdateTime(dtBegin, (int)(nNewVal % (24 * 60 * 60)),
										(int)(nNewVal % (60 * 60)), (int)(nNewVal % 60));

		/*nVal = dtStart.GetSecond();
		nDiv = nVal / m_scaleInterval.m_nValue;
		//nMod = nVal % m_scaleInterval.m_nValue;
		nNewVal = (nDiv + (nMod ? 1 : 0)) * m_scaleInterval.m_nValue;

		spAdd.SetDateTimeSpan(0, 0, 0, nNewVal);
		dtBegin = CXTPCalendarUtils::UpdateTime(dtBegin, dtStart.GetHour(), dtStart.GetMinute(), 0);
		dtBegin += spAdd;*/

		break;
	case xtpDTScale_Min:
		nVal = dtStart.GetMinute() /*+ (dtStart.GetSecond() ? 1 : 0)*/;
		nDiv = nVal / m_scaleInterval.m_nValue;
		//nMod = nVal % m_scaleInterval.m_nValue;
		//nNewVal = (nDiv +(nMod?1:0)) * m_scaleInterval.m_nValue;
		nNewVal = nDiv * m_scaleInterval.m_nValue;

		spAdd.SetDateTimeSpan(0, 0, (int)nNewVal, 0);
		dtBegin = CXTPCalendarUtils::UpdateTime(dtStart, dtStart.GetHour(), 0, 0);
		dtBegin += spAdd;

		break;

	case xtpDTScale_Hour:
		nVal = dtStart.GetHour();
		nDiv = nVal / m_scaleInterval.m_nValue;
		nNewVal = (nDiv) * m_scaleInterval.m_nValue;

		spAdd.SetDateTimeSpan(0, (int)nNewVal, 0, 0);
		dtBegin = CXTPCalendarUtils::ResetTime(dtBegin);
		dtBegin += spAdd;

		break;

	case xtpDTScale_Day:
		nVal = dtStart.GetDay();
		nDiv = nVal / m_scaleInterval.m_nValue;
		nNewVal = (nDiv) * m_scaleInterval.m_nValue;

		//spAdd.SetDateTimeSpan((int)max(0, nNewVal - 1), 0, 0, 0);
		//dtBegin = CXTPCalendarUtils::ResetTime(dtBegin);
		//CXTPCalendarUtils::UpdateMonthDay(dtBegin, 1);
		//dtBegin += spAdd;

		dtBegin = CXTPCalendarUtils::ResetTime(dtBegin);
		CXTPCalendarUtils::UpdateMonthDay(dtBegin, (int)nNewVal);

		break;
	case xtpDTScale_Week:
		// update first day of week
		nFirstDayOfWeekIndex = XTP_SAFE_GET3(m_pTimeScale, GetView(), GetCalendarControl(), GetFirstDayOfWeek(), 2);
		dtBegin = CXTPCalendarUtils::ShiftDateToWeekBegin(dtStart, nFirstDayOfWeekIndex);

		nVal = (int)(DATE)dtStart;
		nDiv = nVal / m_scaleInterval.m_nValue;
		nNewVal = (nDiv) * m_scaleInterval.m_nValue;

		dtBegin = (DATE)nNewVal;

		break;

	case xtpDTScale_WorkWeek:
		// update first day of week
		nFirstDayOfWeekIndex = XTP_SAFE_GET3(m_pTimeScale, GetView(), GetCalendarControl(), GetFirstDayOfWeek(), 2);
		dtBegin = CXTPCalendarUtils::ShiftDateToWeekBegin(dtStart, nFirstDayOfWeekIndex);

		nVal = (int)(DATE)dtStart;
		nDiv = nVal / m_scaleInterval.m_nValue;
		nNewVal = (nDiv) * m_scaleInterval.m_nValue;

		dtBegin = (DATE)nNewVal;

		break;
	case xtpDTScale_Month:
		dtBegin = CXTPCalendarUtils::ResetTime(dtStart);

		nVal = dtStart.GetMonth() + (dtStart.GetYear() - 1900) * 12;
		nDiv = nVal / m_scaleInterval.m_nValue;
		nNewVal = (nDiv) * m_scaleInterval.m_nValue;
		{
			int nNewYear = (int)(nNewVal / 12 + 1900);
			int nNewMonth = (int)(nNewVal % 12);

			dtBegin.SetDate(nNewYear, nNewMonth, 1);
		}

		break;
	case xtpDTScale_Year:
		dtBegin = CXTPCalendarUtils::ResetTime(dtStart);

		nVal = dtStart.GetYear();
		nDiv = nVal / m_scaleInterval.m_nValue;
		nNewVal = (nDiv) * m_scaleInterval.m_nValue;

		dtBegin.SetDate((int)nNewVal, 1, 1);

		break;
	default:
		ASSERT(FALSE);
	}

	return dtBegin;
}
double CChartDateTimeAxis::GetTickBeforeVal(double dValue) const
{
	double precision = 0.0000000001;
	if (dValue < 0)
		precision = -0.0000000001;

	COleDateTime tickBefore;
	COleDateTime valueTime = COleDateTime(DATE(dValue+precision));
	COleDateTimeSpan dtSpan = valueTime - m_ReferenceTick;
	switch (m_BaseInterval)
	{
	case tiSecond:
		{
			int totalSecs = (int)dtSpan.GetTotalSeconds();
			totalSecs = (totalSecs/m_iDTTickIntervalMult) * m_iDTTickIntervalMult;
			int Days = totalSecs/86400;					// 86400 seconds in one day
			int Hours = (totalSecs%86400)/3600;			// 3600 seconds in one hour
			int Minutes = ((totalSecs%86400)%3600)/60;	// 60 seconds in one minute
			int Seconds = ((totalSecs%86400)%3600)%60;
			dtSpan.SetDateTimeSpan(Days, Hours, Minutes, Seconds);
			tickBefore = m_ReferenceTick + dtSpan;
		}
		break;
	case tiMinute:
		{
			int totalMinutes = (int)dtSpan.GetTotalMinutes();
			totalMinutes = (totalMinutes/m_iDTTickIntervalMult) * m_iDTTickIntervalMult;
			int Days = totalMinutes/1440;			// 1440 minutes in one day
			int Hours = (totalMinutes%1440)/60;		// 60 minutes in one hour
			int Minutes = (totalMinutes%1440)%60;
			dtSpan.SetDateTimeSpan(Days, Hours, Minutes, 0);
			tickBefore = m_ReferenceTick + dtSpan;
		}
		break;
	case tiHour:
		{
			int totalHours = (int)dtSpan.GetTotalHours();
			totalHours = (totalHours/m_iDTTickIntervalMult) * m_iDTTickIntervalMult;
			int Days = totalHours/24;			// 24 hours in one day
			int Hours = totalHours%24;
			dtSpan.SetDateTimeSpan(Days, Hours, 0, 0);
			tickBefore = m_ReferenceTick + dtSpan;
		}
		break;
	case tiDay:
		{
			int totalDays = (int)dtSpan.GetTotalDays();
			totalDays = (totalDays/m_iDTTickIntervalMult) * m_iDTTickIntervalMult;
			dtSpan.SetDateTimeSpan(totalDays, 0, 0, 0);
			tickBefore = m_ReferenceTick + dtSpan;
		}
		break;
	case tiMonth:
		{
			int yearDiff = valueTime.GetYear() - m_ReferenceTick.GetYear();
			int monthDiff = valueTime.GetMonth() - m_ReferenceTick.GetMonth();
			int totalMonths = ((yearDiff*12+monthDiff)/m_iDTTickIntervalMult) * m_iDTTickIntervalMult;
			tickBefore = AddMonthToDate(m_ReferenceTick,totalMonths);
		}
		break;
	case tiYear:
		{
			int yearDiff = valueTime.GetYear() - m_ReferenceTick.GetYear();
			int year = ((yearDiff)/m_iDTTickIntervalMult) * m_iDTTickIntervalMult;
			tickBefore = AddMonthToDate(m_ReferenceTick,year*12);
		}
		break;
	}

	return (DATE)tickBefore;
}
void CXTPCalendarDayViewTimeScale::Draw(CDC* pDC)
{
	ASSERT(pDC && m_pDayView);

	if (!pDC || !m_pDayView)
	{
		return;
	}

	pDC->FillSolidRect(m_Layout.m_rcHeader, GetSysColor(COLOR_3DFACE));
	pDC->SetBkMode(TRANSPARENT);

	int nRowHeight = XTP_SAFE_GET1(m_pDayView, GetRowHeight(), 0);

	if (nRowHeight <= 0)
		return;

	const int nRowCount = m_pDayView->GetVisibleRowCount();
	const int nTopRow = m_pDayView->GetTopRow();
	COleDateTimeSpan spScaleInterval = GetScaleInterval();

	if (CXTPCalendarUtils::GetTotalMinutes(spScaleInterval) < 1)
	{
		ASSERT(FALSE);
		spScaleInterval.SetDateTimeSpan(0, 0, 5, 0);
	}

	//=== Calculate 'now' line. Draw it's BK ================================
	int nNowLineY = 0;
	if (m_bDrawNowLineDyn)
	{
		int nBottomRow = nTopRow + m_pDayView->GetVisibleRowCount();
		COleDateTime dtTopTime = m_pDayView->GetCellTime(nTopRow);
		COleDateTime dtBottomTime = m_pDayView->GetCellTime(nBottomRow);
		COleDateTimeSpan spView = dtBottomTime - dtTopTime;

		COleDateTime dtNow = CXTPCalendarUtils::GetCurrentTime();
		dtNow = CXTPCalendarUtils::ResetDate(dtNow);

		COleDateTimeSpan spNow = dtNow - dtTopTime;

		double dPixelPerSecond = m_Layout.m_rcTimeZone.Height() / (double)CXTPCalendarUtils::GetTotalSeconds(spView);

		int nDlta = int(CXTPCalendarUtils::GetTotalSeconds(spNow) * dPixelPerSecond);
		nNowLineY = m_Layout.m_rcTimeZone.top + nDlta;

		XTP_SAFE_CALL3(m_pDayView, GetPaintManager(), GetDayViewTimeScaleHeaderPart(),
			DrawNowLine(pDC, m_pDayView, m_Layout.m_rcTimeZone, nNowLineY, TRUE) );
	}

	//================================================================
	int nTimeShiftCorrectorY = 0;
	COleDateTimeSpan spShiftCorrector(0);
	int nScaleInterval_min = max(1, (int)CXTPCalendarUtils::GetTotalMinutes(spScaleInterval));
	double dPixelPerMin = (double)nRowHeight / (double)nScaleInterval_min;

	if (CXTPCalendarUtils::GetTotalHours(spScaleInterval) < 1)
	{
		int nMul = m_nTimeshift_min / 60;
		int nMod = m_nTimeshift_min % 60;
		int nShiftCorrector_min = (nMul + (nMod ? 1 :0))*60 - m_nTimeshift_min;

		//-------------------------------------------------------------------
		int nMul2 = nShiftCorrector_min / nScaleInterval_min;
		int nMod2 = nShiftCorrector_min % nScaleInterval_min;
		int nShiftCorrector2_min = (nMul2 + (nMod2 ? 1 :0)) * nScaleInterval_min;

		nTimeShiftCorrectorY = (int)(dPixelPerMin * nShiftCorrector2_min);

		spShiftCorrector = CXTPCalendarUtils::Minutes2Span(nShiftCorrector_min);
	}

	// draw time scale header
	COleDateTimeSpan spShift = CXTPCalendarUtils::Minutes2Span(m_nTimeshift_min);

	// draw time scale rows
	if (CXTPCalendarUtils::GetTotalHours(spScaleInterval) >= 1)
	{
		// draw time scale cells one by one
		for (int i = 0; i < nRowCount; i++)
		{
			CRect rcCell(m_Layout.m_rcTimeZone.left,
						m_Layout.m_rcTimeZone.top + nRowHeight * i,
						m_Layout.m_rcTimeZone.right,
						m_Layout.m_rcTimeZone.top + nRowHeight * (i + 1));

			COleDateTime dtTime = m_pDayView->GetCellTime(nTopRow + i);

			dtTime += spShift;
			CString str = Format(dtTime, FALSE);

			XTP_SAFE_CALL3(m_pDayView, GetPaintManager(), GetDayViewTimeScaleCellPart(),
							DrawHourCell(pDC, rcCell, str, FALSE));
		}
	}
	else
	{
		COleDateTimeSpan spHour(0, 1, 0, 0);

		spShift += spShiftCorrector;

		int nRowPerHour = (int)((double)spHour / (double)spScaleInterval + XTP_HALF_SECOND);
		ASSERT(nRowPerHour > 0);
		nRowPerHour = max(1, nRowPerHour);
		const int nHourCellHeight = nRowHeight*nRowPerHour;

		// Adjust time font size
		CRect rcStartCell(m_Layout.m_rcTimeZone);

		rcStartCell.top += nTimeShiftCorrectorY;

		rcStartCell.bottom = rcStartCell.top + nHourCellHeight;

		//XTP_SAFE_CALL3(m_pDayView, GetPaintManager(), GetDayViewTimeScaleCellPart(),
		//              AdjustTimeFont(pDC, rcStartCell));

		//-------------------------------------------------------------------
		int nHrCellDiv = m_Layout.m_rcTimeZone.Height() / rcStartCell.Height();
		int nHrCellMod = m_Layout.m_rcTimeZone.Height() / rcStartCell.Height();

		int nDrawCellCount = nHrCellDiv + (nHrCellMod ? 1 :0);

		COleDateTime dtStartCell = m_pDayView->GetCellTime(nTopRow);
		dtStartCell += spShift;
		int nSCMinute = dtStartCell.GetMinute();
		if (nSCMinute != 0)
		{
			int nMinutesShiftY = (int)(dPixelPerMin * nSCMinute);
			rcStartCell.top -= nMinutesShiftY;
			rcStartCell.bottom -= nMinutesShiftY;

			dtStartCell.SetTime(dtStartCell.GetHour(), 0, 0);

			nDrawCellCount++;
		}

		//while (rcStartCell.top > m_rcTimeZone.top)
		for (int n = 0; rcStartCell.top > m_Layout.m_rcTimeZone.top && n < 100; n++)
		{
			dtStartCell -= spHour;

			rcStartCell.top -= nHourCellHeight;
			rcStartCell.bottom -= nHourCellHeight;

			nDrawCellCount++;
		}

		// draw time scale cells with only one big hour number
		BOOL bTopCell = TRUE;
		CRect rcCell = rcStartCell;
		for (int i = 0; i < nDrawCellCount; i++)
		{
			COleDateTime dtCell = dtStartCell + COleDateTimeSpan(i * (double)spHour);
			ASSERT(dtCell.GetMinute() == 0);

			CString strHour, strMin;
			Format(dtCell, bTopCell, &strHour, &strMin);

			if (rcCell.top >= m_Layout.m_rcTimeZone.top)
			{
				bTopCell = FALSE;
			}

			// draw text
			XTP_SAFE_CALL3(m_pDayView, GetPaintManager(), GetDayViewTimeScaleCellPart(),
							DrawBigHourCell(pDC, rcCell, strHour, strMin, nRowPerHour, FALSE));

			rcCell.top += nHourCellHeight;
			rcCell.bottom += nHourCellHeight;
		}
	}

	//*** draw 'now' line
	if (m_bDrawNowLineDyn)
	{
		XTP_SAFE_CALL3(m_pDayView, GetPaintManager(), GetDayViewTimeScaleHeaderPart(),
			DrawNowLine(pDC, m_pDayView, m_Layout.m_rcTimeZone, nNowLineY, FALSE) );
	}

	//*** Draw Expand Signs
	XTP_SAFE_CALL3(m_pDayView, GetPaintManager(), GetDayViewTimeScaleHeaderPart(),
			DrawExpandSigns(pDC, m_pDayView, m_Layout.m_rcTimeZone) );

	//*** Draw header
	CRect rcHeader(m_Layout.m_rcHeader.left, m_Layout.m_rcHeader.top, m_Layout.m_rcHeader.right, m_Layout.m_rcTimeZone.top);

	XTP_SAFE_CALL3(m_pDayView, GetPaintManager(), GetDayViewTimeScaleHeaderPart(),
					OnDraw(pDC, m_pDayView, rcHeader, m_strCaption));
}