Exemple #1
0
void GCDCGraphs::RecalculateMargins(wxGraphicsContext &dc) {
	if (!m_recalulate_margins)
		return;

	double leftmargin = 36;
	double bottommargin = 12;
	double topmargin = 24;

	for (size_t i = 0; i < m_draws.size(); i++) {
		double tw, th, td, tel;
		DrawInfo *di = m_draws[i]->GetDrawInfo();
		wxString sval = di->GetValueStr(di->GetMax(), _T(""));

		dc.GetTextExtent(sval, &tw, &th, &td, &tel);
		if (leftmargin < tw + 1)
			leftmargin = tw + 1;
		if (bottommargin < th + 1)
			bottommargin = th + 1;

		if (topmargin < th + m_screen_margins.infotopmargin)
			topmargin = th + m_screen_margins.infotopmargin;

		dc.GetTextExtent(di->GetUnit(), &tw, &th, &td, &tel);
		if (leftmargin < tw + 6)
			leftmargin = tw + 6;
	}

	m_screen_margins.leftmargin = leftmargin;
	m_screen_margins.bottommargin = bottommargin;
	m_screen_margins.topmargin = topmargin;

	m_recalulate_margins = false;
}
Exemple #2
0
void InfoWidget::SetDrawInfo(Draw *draw) {
	DrawInfo *info = draw->GetDrawInfo();
	if (info == NULL)
		return;
	SetUnit(info->GetUnit());
	SetColor(info->GetDrawColor());
	SetPrec(info->GetPrec());
	SetPeriod(draw->GetPeriod());
}
Exemple #3
0
void SummaryWindow::OnIdle(wxIdleEvent &event) {

	if (!m_active)
		return;

	bool resize = false;

#define SHOW(wdg, show) \
	wdg->Show(show); \
	m_values_sizer->Show(wdg, show, true);


	if (m_update) {
		if (m_summary_draws_count == 0) {
			SHOW(m_no_draws_label, true)
			SHOW(m_no_draws_line, true)
			resize = true;
		} else { 
			for (size_t i = 0; i < m_draws.Count(); ++i) {
	
				ObservedDraw* od = m_draws[i];
				if (od == NULL)
					continue;
	
				TTLabel *l = m_labels[i];
				wxStaticLine *li = m_lines[i];
	
				double val = od->draw->GetValuesTable().m_hsum;
				double data_percentage = od->draw->GetValuesTable().m_data_probes_ratio;
	
				if (std::isnan(val) && l->IsShown()) {
					SHOW(l, false);
					SHOW(li, false);

					resize = true;
					continue;
				}
		
				if (od->draw->GetEnable() == false) {
					SHOW(l, false);
					SHOW(li, false);

					resize = true;
					continue;
				}
		
				if (!std::isnan(val) && !l->IsShown()) {
					SHOW(l, true);
					SHOW(li, true);

					resize = true;
		
					od->tooltip = true;
					m_tooltip = true;
				}
		
				od->update = false;
		
				if (l->IsShown() == false)
					continue;
		
				Draw* draw = od->draw;
				assert(draw);
				DrawInfo* info = draw->GetDrawInfo();
				assert(info);

				//convert unit, idea taken from draw2 :)
				wxString sunit = info->GetSumUnit();
				wxString unit = info->GetUnit();
				wxString text;
				if (!sunit.IsEmpty()) {
					text = wxString(info->GetValueStr(val, _T(""))) + _T(" ") + sunit;
				} else if (unit == _T("kW")) {
					text = wxString(info->GetValueStr(val, _T(""))) + _T(" ") + _T("kWh") + 
						_T(" (") + wxString(info->GetValueStr(val * 3.6 / 1000, _T(""))) + _T(" GJ)");
				} else if (unit == _T("MW")) {
					text = wxString(info->GetValueStr(val, _T(""))) + _T(" ") + _T("MWh") + 
						_T(" (") + wxString(info->GetValueStr(val * 3.6, _T(""))) + _T(" GJ)");
				} else if (unit.Replace(_T("/h"), _T("")) == 0) {
					unit += _T("*h");
					text = wxString(info->GetValueStr(val, _T(""))) + _T(" ") + unit;
				} else {
					text = wxString(info->GetValueStr(val, _T(""))) + _T(" ") + unit;
				}
		
				if (!std::isnan(data_percentage) && !(data_percentage > 0.9999))
					text += wxString::Format(_T(" (%.2f%%)"), data_percentage * 100);
		
				l->SetValueText(text);
		
				resize = true;

			}
			if (m_no_draws_label->IsShown()) {
				SHOW(m_no_draws_label, false);
				SHOW(m_no_draws_line, false);
			}
		}
	}

	if (m_tooltip) for (size_t i = 0; i < m_draws.Count(); ++i) {
		ObservedDraw* od = m_draws[i];
		if (od == NULL)
			continue;

		if (od->tooltip == false)
			continue;

		Draw* draw = od->draw;
		DrawInfo* info = draw->GetDrawInfo();

		wxString tooltip = _T("");
		tooltip += info->GetName();
		tooltip += _T("\n");

		PeriodType period = draw->GetPeriod();

		const Draw::VT& vt = draw->GetValuesTable();

		wxDateTime s = draw->GetTimeOfIndex(vt.m_stats.Start() - vt.m_view.Start());
		wxDateTime e = draw->GetTimeOfIndex(vt.m_stats.End() - vt.m_view.Start());

		tooltip += _("From:"); 
		tooltip += _T("\n") + FormatTime(s, period) + _T("\n") + _("To:") + _T("\n") + FormatTime(e, period);

		double data_percentage = od->draw->GetValuesTable().m_data_probes_ratio;
		if (std::isnan(data_percentage))
			data_percentage = 0;
		tooltip += _T("\n\n") + wxString::Format(_("Data contains %.2f%% probes from current period"), data_percentage * 100);

		m_labels[i]->SetToolTip(tooltip);

		od->tooltip = false;
	}

	if (resize) 
		Resize();

	m_update = m_tooltip = false;

}
Exemple #4
0
void DrawsPrintout::PrintDrawsInfo(wxDC *dc, int leftmargin, int topmargin, int rightmargin, int bottommargin) {
	int w, h;
	int tw, th;
	int maxy = 5;
	int info_print_start;
	dc->GetSize(&w, &h);
	//GetPageSizePixels(&w, &h);
	w -= leftmargin + rightmargin;
	int hw = w / 2;

	info_print_start = h * 2 / 3 + topmargin;
	dc->SetDeviceOrigin(leftmargin, info_print_start);

	Draw* fd = m_draws[0];
	DrawInfo* fdi = m_draws[0]->GetDrawInfo();

	wxFont font = dc->GetFont();
	wxFont f = font;
	//wxFont f(10, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL, false, _T("Helvetica"), wxFONTENCODING_ISO8859_2);
#ifdef __WXMSW__
	f.SetPointSize(100);
#else
	f.SetPointSize(16);
#endif
	dc->SetTextForeground(*wxBLACK);
	dc->SetFont(f);

	wxString cn = GetPrintoutConfigTitle();
	dc->GetTextExtent(cn, &tw, &th);
	dc->DrawText(cn, hw - tw / 2, maxy);
	maxy += int(1.4 * th);

#ifdef __WXMSW__
	f.SetPointSize(65);
#else
	f.SetPointSize(8);
#endif
	dc->SetFont(f);

	wxString wt = fdi->GetSetName();
	dc->GetTextExtent(wt, &tw, &th);
	dc->DrawText(wt, hw - tw / 2, maxy);
	maxy += int(1.4 * th);

	PeriodType pt = fd->GetPeriod();
	wxString period = _("For period: ");
	switch (pt) {
		case PERIOD_T_DECADE:
			period += _("DECADE ");
			break;
		case PERIOD_T_YEAR:
			period += _("YEAR ");
			break;
		case PERIOD_T_MONTH:
			period += _("MONTH ");
			break;
		case PERIOD_T_WEEK:
			period += _("WEEK ");
			break;
		case PERIOD_T_DAY:
			period += _("DAY ");
			break;
		case PERIOD_T_30MINUTE:
			period += _("HOUR ");
			break;
		case PERIOD_T_5MINUTE:
			period += _("5MINUTE ");
			break;
		case PERIOD_T_MINUTE:
			period += _("MINUTE ");
			break;
		case PERIOD_T_30SEC:
			period += _("30SEC ");
			break;
		case PERIOD_T_SEASON:
			period += _("SEASON ");
			break;
		default:
			assert(false);
	}

	dc->GetTextExtent(period, &tw, &th);
	dc->DrawText(period, hw - tw / 2, maxy);
	maxy += int(1.4 * th);

	int point_size = f.GetPointSize();
	bool painted = false;
	do {
		wxString time;
		time += _("From: ");
		time += FormatTime(fd->GetTimeOfIndex(0), pt);
		time += _(" to: ");
		time += FormatTime(fd->GetTimeOfIndex(fd->GetValuesTable().size() - 1), pt);

		dc->GetTextExtent(time, &tw, &th);
		if (tw > w && f.GetPointSize() >= 2) {
			f.SetPointSize(f.GetPointSize() - 1);
			dc->SetFont(f);	
		} else {
			dc->DrawText(time, hw - tw / 2, maxy);
			maxy += int(1.4 * th);
			painted = true;
		}
	} while (!painted);

	f.SetPointSize(point_size) ;
	dc->SetFont(f);
	painted = false;
	bool painting = false;
	int pmaxy = maxy;
	do {
		for (int i = 0; i < m_draws_count; ++i) {
			Draw *d = m_draws[i];
			if (!d->GetEnable())
				continue;
	
			DrawInfo* di = d->GetDrawInfo();
	
			int cx = 0.02 * w;
	
			wxString str = wxString::Format(_T("%s = %s "), 
						di->GetShortName().c_str(),
						di->GetName().c_str());
	
			dc->SetTextForeground(di->GetDrawColor());
			dc->GetTextExtent(str, &tw, &th);
			if (painting)
				dc->DrawText(str, cx, maxy);
	
			cx += tw;
	
			const Draw::VT& vt = d->GetValuesTable();
			if (vt.m_count) {
				dc->SetTextForeground(*wxBLACK);
	
				wxString unit = di->GetUnit();
	
				str = wxString(_T(": ")) 
					+ _("min.=") + d->GetDrawInfo()->GetValueStr(vt.m_min, _T("- -")) + 
					+ _T(" ; ") + _("avg.=") + wxString(d->GetDrawInfo()->GetValueStr(vt.m_sum / vt.m_count, _T("- -"))) + 
					+ _T(" ; ") + _("max.=") + wxString(d->GetDrawInfo()->GetValueStr(vt.m_max, _T("- -"))) +
					+ _T(" ") + unit;
	
				if (painting) {
					dc->GetTextExtent(str, &tw, &th);
					dc->DrawText(str, cx, maxy);
				}
				cx += tw;
	
				if (di->GetSpecial() == TDraw::HOURSUM) {
					wxString u = unit;
					if (u.Replace(_T("/h"), _T("")) == 0)
						u += _T("*h");
					wxString vals;
					double val = vt.m_hsum;
					wxString sunit = d->GetDrawInfo()->GetSumUnit();
					if (!sunit.IsEmpty()) {
						vals = wxString(di->GetValueStr(val, _T(""))) + _T(" ") + sunit;
					} else if (unit == _T("kW")) {
						vals = wxString(di->GetValueStr(val, _T(""))) + _T(" ") + _T("kWh") + 
							_T(" (") + wxString(di->GetValueStr(val * 3.6 / 1000, _T(""))) + _T(" GJ)");
					} else if (unit == _T("MW")) {
						vals = wxString(di->GetValueStr(val, _T(""))) + _T(" ") + _T("MWh") + 
							_T(" (") + wxString(di->GetValueStr(val * 3.6, _T(""))) + _T(" GJ)");
					} else if (unit.Replace(_T("/h"), _T("")) == 0) {
						u += _T("*h");
						vals = wxString(di->GetValueStr(val, _T(""))) + _T(" ") + u;
					} else {
						vals = wxString(di->GetValueStr(val, _T(""))) + _T(" ") + u;
					}
					str = wxString::Format(_T(" sum.: %s"), vals.c_str());
	
					if (painting)
						dc->DrawText(str, cx, maxy);
				}
			}
			maxy += int(1.4 * th);
		}

		if (painting)
			painted = true;
		else  {
			if (maxy + info_print_start + topmargin < dc->GetSize().GetHeight() - bottommargin)
				painting = true;
			else {
				f.SetPointSize(f.GetPointSize() - 1);
				if (f.GetPointSize() <= 2)
					painting = true;
				dc->SetFont(f);
			}
			maxy = pmaxy;
		}
		
	} while (!painted);

}