Ejemplo n.º 1
0
void WxGraphs::DrawCurrentParamName(wxDC *dc) {
	DrawInfo *di = m_draws_wdg->GetCurrentDrawInfo();
	if (di == NULL)
		return;

	wxFont f = GetFont();

	int ps = f.GetPointSize();
	int fw = f.GetWeight();
	f.SetWeight(wxFONTWEIGHT_BOLD);
	f.SetPointSize(ps * 1.25);
	dc->SetFont(f);

	wxString text = m_cfg_mgr->GetConfigTitles()[di->GetBasePrefix()] + _T(":") + di->GetParamName();

	int tw, th;
	dc->GetTextExtent(text, &tw, &th);

	int w, h;
	GetSize(&w, &h);
	dc->SetTextForeground(di->GetDrawColor());
	dc->SetBrush(*wxBLACK_BRUSH);
	dc->SetPen(*wxWHITE_PEN);
	dc->DrawRectangle(w / 2 - tw / 2 - 1, h / 2 - th / 2 - 1, tw + 2, th + 2);
	dc->DrawText(text, w / 2 - tw / 2, h / 2 - th / 2);

	f.SetPointSize(ps);
	f.SetWeight(fw);
	dc->SetFont(f);

}
Ejemplo n.º 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());
}
Ejemplo n.º 3
0
void WxGraphs::DrawWindowInfo(wxDC * dc, const wxRegion & repainted_region)
{

	if (repainted_region.IsEmpty())
		return;

	int info_left_marg = m_screen_margins.leftmargin + 8;
	int param_name_shift = 5;

	if (m_draws.size() < 1)
		return;

	int w, h;
	dc->GetSize(&w, &h);

	DrawInfo *info = m_draws[0]->GetDrawInfo();
	wxString name = info->GetSetName().c_str();

	int namew, nameh;
	dc->GetTextExtent(name, &namew, &nameh);

	if (repainted_region.Contains(info_left_marg, m_screen_margins.infotopmargin, w - m_screen_margins.infotopmargin, nameh) == wxOutRegion)
		return;

	dc->SetTextForeground(*wxWHITE);

	dc->DrawText(name, info_left_marg, m_screen_margins.infotopmargin);

	wxColor color = dc->GetTextForeground();

	int xpos = info_left_marg + namew + param_name_shift;

	for (int i = 0; i < (int)m_draws.size(); ++i) {

		if (!m_draws[i]->GetEnable())
			continue;

		DrawInfo *info = m_draws[i]->GetDrawInfo();

		dc->SetTextForeground(info->GetDrawColor());

		name = info->GetShortName().c_str();
		dc->GetTextExtent(name, &namew, &nameh);

		dc->DrawText(name, xpos, m_screen_margins.infotopmargin);
		xpos += namew + param_name_shift;
	}

	dc->SetTextForeground(color);

}
Ejemplo n.º 4
0
void GCDCGraphs::DrawWindowInfo(wxGraphicsContext &dc) {
	double info_left_marg = m_screen_margins.leftmargin + 8;
	double param_name_shift = 5;

	if (m_draws.size() < 1)
		return;

	int w, h;
	GetClientSize(&w, &h);

	DrawInfo *info = m_draws[0]->GetDrawInfo();
	wxString name = info->GetSetName().c_str();

	double namew, nameh, th, tsel;
	dc.GetTextExtent(name, &namew, &nameh, &th, &tsel);

	dc.DrawText(name, info_left_marg, m_screen_margins.infotopmargin);

	int xpos = info_left_marg + namew + param_name_shift;

	for (int i = 0; i < (int)m_draws.size(); ++i) {

		if (!m_draws[i]->GetEnable())
			continue;

		DrawInfo *info = m_draws[i]->GetDrawInfo();

		dc.SetFont(GetFont(), info->GetDrawColor());

		name = info->GetShortName().c_str();
		if (!name.IsEmpty()) {
			dc.GetTextExtent(name, &namew, &nameh, &th, &tsel);
			dc.DrawText(name, xpos, m_screen_margins.infotopmargin);
			xpos += namew + param_name_shift;
		} else {
			xpos += param_name_shift;
		}
	}

}
Ejemplo n.º 5
0
void GCDCGraphs::DrawGraph(wxGraphicsContext &dc, Draw* d) {
	static const int ellipse_size = 5;

	if (d->GetEnable() == false)
		return;

	DrawInfo *di = d->GetDrawInfo();

	bool double_cursor = d->GetSelected() && d->GetDoubleCursor();

	wxGraphicsPath path1 = dc.CreatePath();
	wxGraphicsPath path2 = dc.CreatePath();

	wxGraphicsPath *path = &path1;

	const wxColour &wc = di->GetDrawColor();
	dc.SetPen(wxPen(wc, double_cursor ? 4 : 2, wxSOLID));

	int pc = d->GetValuesTable().size();

	bool prev_data = false;
	bool switched_to_alternate = false;
	bool switched_back = false;

	int dcs = -1, dce = -1;
	if (double_cursor) {
		dcs = d->GetValuesTable().m_stats.Start() - d->GetValuesTable().m_view.Start();
		dce = d->GetValuesTable().m_stats.End() - d->GetValuesTable().m_view.Start();
	}

	std::vector<std::pair<double,double> > p1circles;
	std::vector<std::pair<double,double> > p2circles;
	std::vector<std::pair<double,double> >* pcircles = &p1circles;

	bool draw_circle =
		d->GetPeriod() != PERIOD_T_DAY
		&& d->GetPeriod() != PERIOD_T_30MINUTE
		&& d->GetPeriod() != PERIOD_T_5MINUTE
		&& d->GetPeriod() != PERIOD_T_MINUTE
		&& d->GetPeriod() != PERIOD_T_30SEC;

	for (int i = 0; i < pc; i++) {
		if (!d->GetValuesTable().at(i).IsData()) {
			prev_data = false;
			continue;
		}

		double x = GetX(i);
		double y = GetY(d->GetValuesTable().at(i).val, di);

		bool drawn = false;

		if (i >= dcs && i <= dce && !switched_to_alternate) {
			if (prev_data)
				path->AddLineToPoint(x, y);

			path = &path2;
			pcircles = &p2circles;

			if (draw_circle || (!prev_data && ((i + 1) < pc) && !d->GetValuesTable().at(i + 1).IsData())) 
				pcircles->push_back(std::make_pair(x, y));

			path->MoveToPoint(x, y);
			switched_to_alternate = true;
			drawn = true;
		}

		if (i >= dce && switched_to_alternate && !switched_back) {
			if (prev_data)
				path->AddLineToPoint(x, y);

			std::vector<std::pair<double, double> > *p;
			if (i == dce)
				p = &p2circles;
			else
				p = &p1circles;

			if (draw_circle || (!prev_data && ((i + 1) < pc) && !d->GetValuesTable().at(i + 1).IsData())) 
				p->push_back(std::make_pair(x, y));

			path = &path1;
			pcircles = &p1circles;
			path->MoveToPoint(x, y);

			switched_back = true;

			drawn = true;
		}

		if (!drawn) {
			if (prev_data)
				path->AddLineToPoint(x, y);
			else
				path->MoveToPoint(x, y);

			if (draw_circle || (!prev_data && ((i + 1) < pc) && !d->GetValuesTable().at(i + 1).IsData())) 
				pcircles->push_back(std::make_pair(x, y));
		}
		
		prev_data = true;
	}

	for (std::vector<std::pair<double, double> >::iterator i = p1circles.begin();
			i != p1circles.end();
			i++)
		if (draw_circle)
			path1.AddEllipse(i->first - ellipse_size / 2, i->second - ellipse_size / 2, ellipse_size, ellipse_size);
		else
			path1.AddCircle(i->first, i->second, 1);

	dc.StrokePath(path1);

	if (double_cursor) {
		dc.SetPen(wxPen(*wxWHITE, 4, wxSOLID));
		for (std::vector<std::pair<double, double> >::iterator i = p2circles.begin();
				i != p2circles.end();
				i++)
			if (draw_circle)
				path2.AddEllipse(i->first - ellipse_size / 2, i->second - ellipse_size / 2, ellipse_size, ellipse_size);
			else
				path2.AddCircle(i->first, i->second, 1);
		dc.StrokePath(path2);
	}
}
Ejemplo n.º 6
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);

}
Ejemplo n.º 7
0
int BackgroundPrinter::PrintBackground(wxDC *dc, std::vector<Draw*> draws, const SS& sd) {

	dc->SetTextForeground(GetTimeAxisCol());
	dc->SetBrush(wxBrush(GetTimeAxisCol(), wxSOLID));

	int ax_dist = FindVerticalAxesDistance(dc, draws, sd);

	SS::iterator ssi = sd.begin();
	do {
		set<int>::iterator si = (*ssi).begin();
		if ((*ssi).end() == si) 
			assert(false);
		int di = *si;

		m_draw = draws[di];

		m_leftmargin += ax_dist;

		SS::iterator next = ssi;
		next++;
		if (next == sd.end()) {
			int w,h;
			GetSize(&w, &h);
			w = w - m_leftmargin + ax_dist;
			SetSize(w, h);

			DrawBackground(dc);
#ifdef __WXMSW__
			DrawTimeAxis(dc, 48, 24, 15, 7);
#else
			DrawTimeAxis(dc, 8, 4, 6);
#endif
		}

		DrawYAxisVals(dc, tick_len, line_width);
		DrawYAxis(dc, arrow_height, arrow_width, line_width);

		int x = (int)(arrow_width * 1.2) , y = line_width;

		int textw, texth;
		DrawUnit(dc, x, y);
		dc->GetTextExtent(draws[*si]->GetDrawInfo()->GetUnit(), &textw, &texth);

		wxColour pc = dc->GetTextForeground();
		y = m_topmargin;
		for (set<int>::reverse_iterator i = (*ssi).rbegin(); i != (*ssi).rend(); i++) {
			DrawInfo* di = draws[*i]->GetDrawInfo();
			dc->GetTextExtent(di->GetShortName(), &textw, &texth);

			dc->SetTextForeground(di->GetDrawColor());
			dc->DrawText(di->GetShortName(), m_leftmargin - 2 * line_width - textw, y - texth - line_width);
			y -= texth + line_width;

		}
		dc->SetTextForeground(pc);

		++ssi;
		
	} while (ssi != sd.end());

	return m_leftmargin;

}