Esempio n. 1
0
void GCDCGraphs::DrawBackground(wxGraphicsContext &dc) {
	int w, h;
	GetClientSize(&w, &h);

	PeriodType pt = m_draws_wdg->GetSelectedDraw()->GetPeriod();
	size_t pc = m_draws_wdg->GetSelectedDraw()->GetValuesTable().size();

	dc.SetBrush(wxBrush(back2_col, wxSOLID));
	dc.DrawRectangle(0, 0, w, h);

	size_t i = 0;
	int c = 1;
	double x = m_screen_margins.leftmargin + 1;

	while (i < pc) {
		double x1 = GetX(i);

		i += TimeIndex::PeriodMult[pt];
	
		double x2 = GetX(i);

		if (c > 0)
			dc.SetBrush(wxBrush(back1_col, wxSOLID));
		else
			dc.SetBrush(wxBrush(back2_col, wxSOLID));
	
		c *= -1; 

		dc.DrawRectangle(x, m_screen_margins.topmargin, x2 - x1, h - m_screen_margins.topmargin + 1);

		x = x + x2 - x1;
	}

}
Esempio n. 2
0
void GCDCGraphs::DrawXAxisVals(wxGraphicsContext& dc) {
	Draw* draw = m_draws_wdg->GetSelectedDraw();
	if (draw == NULL) 
		return;
	/* Draw ticks on axis. */
	int i = PeriodMarkShift[draw->GetPeriod()];
	int size = draw->GetValuesTable().size();

	int w, h;
	GetClientSize(&w, &h);
    
	wxDateTime prev_date;
	while (i < size) {
		int x = GetX(i);
		dc.StrokeLine(x, h - m_screen_margins.bottommargin + 1, x, h - m_screen_margins.bottommargin - 1);

		wxDateTime date = draw->GetTimeOfIndex(i);
	
		/* Print date */
		wxString datestring = get_date_string(draw->GetPeriod(), prev_date, date);

		double textw, texth, td, tel;

		dc.GetTextExtent(datestring, &textw, &texth, &td, &tel);
		dc.DrawText(datestring, x - textw / 2, h - m_screen_margins.bottommargin + 1);

		i += TimeIndex::PeriodMult[draw->GetPeriod()];
		prev_date = date;
	}
    
}
Esempio n. 3
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;
}
Esempio n. 4
0
void wxChartArc::Draw(wxGraphicsContext &gc)
{
	wxGraphicsPath path = gc.CreatePath();

	if (m_innerRadius > 0)
	{
		path.AddArc(m_x, m_y, m_innerRadius, m_startAngle, m_endAngle, true);
		path.AddArc(m_x, m_y, m_outerRadius, m_endAngle, m_startAngle, false);
	}
	else
	{
		path.AddArc(m_x, m_y, m_outerRadius, m_endAngle, m_startAngle, false);
		path.AddLineToPoint(m_x, m_y);
	}

	path.CloseSubpath();

	wxBrush brush(m_options.GetFillColor());
	gc.SetBrush(brush);
	gc.FillPath(path);

	wxPen pen(*wxWHITE, m_options.GetOutlineWidth());
	gc.SetPen(pen);
	gc.StrokePath(path);
}
Esempio n. 5
0
void GCDCGraphs::DrawYAxis(wxGraphicsContext& dc) {
	int w, h;
	GetClientSize(&w, &h);

	dc.StrokeLine(m_screen_margins.leftmargin, 0, m_screen_margins.leftmargin, h);
	dc.StrokeLine(m_screen_margins.leftmargin - 5, 7, m_screen_margins.leftmargin, 0);
	dc.StrokeLine(m_screen_margins.leftmargin, 0, m_screen_margins.leftmargin + 5, 7);
}
Esempio n. 6
0
void ElementCanvasWindow::DrawGrid(wxGraphicsContext &gc)
{
    wxPen pen(wxColor(0x7F, 0x7F, 0x7F), 1);
    gc.SetPen(pen);
    for (size_t i = 0; i < 20; i += 10)
    {
        gc.StrokeLine(i, 0, i, 20);
    }
}
Esempio n. 7
0
void GCDCGraphs::DrawUnit(wxGraphicsContext &dc) {
	Draw* draw = m_draws_wdg->GetSelectedDraw();
	if (draw == NULL) 
		return;

	double textw, texth, th, tsel;

	wxString unit = draw->GetDrawInfo()->GetUnit();
	dc.GetTextExtent(unit, &textw, &texth, &th, &tsel);
	dc.DrawText(unit, m_screen_margins.leftmargin - 6 - textw, m_screen_margins.topmargin - 2 - texth);
}
Esempio n. 8
0
void wxChartBackground::Draw(wxDouble x, 
                             wxDouble y, 
                             wxDouble width, 
                             wxDouble height,
                             wxGraphicsContext &gc)
{
    wxGraphicsPath path = gc.CreatePath();

    path.AddRoundedRectangle(x, y, width, height, m_options.GetCornerRadius());

    wxBrush brush(m_options.GetColor());
    gc.SetBrush(brush);
    gc.FillPath(path);
}
Esempio n. 9
0
void GCDCGraphs::DrawXAxis(wxGraphicsContext &dc) {
	int arrow_width = 8;
	int arrow_height = 4;

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

	//dc.StrokeLine(0, h - m_screen_margins.bottommargin, w - m_screen_margins.rightmargin, h - m_screen_margins.bottommargin);
	dc.StrokeLine(0, h - m_screen_margins.bottommargin, w, h - m_screen_margins.bottommargin);
	dc.StrokeLine(w - arrow_width, h - m_screen_margins.bottommargin - arrow_height,
		w, h - m_screen_margins.bottommargin);
	dc.StrokeLine(w - arrow_width, h - m_screen_margins.bottommargin + arrow_height,
		w, h - m_screen_margins.bottommargin);
    
}
Esempio n. 10
0
void GCDCGraphs::DrawCursor(wxGraphicsContext &dc, Draw* d) {
	int i = d->GetCurrentIndex();
	if (i < 0)
		return;

	if (d->GetValuesTable().at(i).IsData() == false)
		return;

	dc.SetBrush(wxBrush(wxColour(0,0,0), wxTRANSPARENT));
	dc.SetPen(wxPen(*wxWHITE, 1, wxSOLID));

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

	dc.DrawRectangle(x - 4, y - 4, 9, 9);
}
Esempio n. 11
0
void GCDCGraphs::DrawNoData(wxGraphicsContext &dc) {
	wxFont font = GetFont();
	font.SetPointSize(font.GetPointSize() + 8);
	dc.SetFont(font, *wxWHITE);

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

	w -= m_screen_margins.leftmargin - m_screen_margins.rightmargin;
	h -= m_screen_margins.topmargin - m_screen_margins.bottommargin;

	wxString sval = _("No data");
	double textw, texth, textd, textel;
	dc.GetTextExtent(sval, &textw, &texth, &textd, &textel);
	dc.DrawText(sval, m_screen_margins.leftmargin + w / 2 - textw / 2 - 1, m_screen_margins.topmargin + h / 2 - texth / 2);

}
Esempio n. 12
0
void GCDCGraphs::DrawParamName(wxGraphicsContext &dc) {
	DrawInfo *di = m_draws_wdg->GetCurrentDrawInfo();
	if (di == NULL)
		return;

	dc.SetBrush(*wxBLACK_BRUSH);
	dc.SetPen(*wxWHITE_PEN);

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

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

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

	double tw, th, _th, _ts;
	dc.GetTextExtent(text, &tw, &th, &_th, &_ts);

	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);
}
Esempio n. 13
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;
		}
	}

}
Esempio n. 14
0
void wxChartTooltip::Draw(wxGraphicsContext &gc)
{
    wxString text = m_provider->GetTooltipText();

    wxFont font(wxSize(0, m_options.GetFontSize()),
        m_options.GetFontFamily(), m_options.GetFontStyle(), wxFONTWEIGHT_NORMAL);
    wxDouble tooltipWidth;
    wxDouble tooltipHeight;
    wxChartUtilities::GetTextSize(gc, font, text, tooltipWidth, tooltipHeight);
    tooltipWidth += 2 * m_options.GetHorizontalPadding();
    tooltipHeight += 2 * m_options.GetVerticalPadding();


    wxDouble tooltipX = m_position.m_x - (tooltipWidth / 2);
    wxDouble tooltipY = m_position.m_y - tooltipHeight;


    wxChartBackground background(m_options.GetBackgroundOptions());
    background.Draw(tooltipX, tooltipY, tooltipWidth, tooltipHeight, gc);

    gc.SetFont(font, m_options.GetFontColor());
    gc.DrawText(text, tooltipX + m_options.GetHorizontalPadding(), tooltipY + m_options.GetVerticalPadding());
}
Esempio n. 15
0
void wxPDFViewPage::Draw(wxPDFViewPagesClient* client, wxDC& dc, wxGraphicsContext& gc, const wxRect& rect)
{
	// Calculate the required bitmap size
	wxSize bmpSize = rect.GetSize();
	double scaleX, scaleY;
	dc.GetUserScale(&scaleX, &scaleY);
	bmpSize.x *= scaleX;
	bmpSize.y *= scaleY;

	double screenScale = dc.GetContentScaleFactor();
	bmpSize.x *= screenScale;
	bmpSize.y *= screenScale;

	wxBitmap bmp = client->GetCachedBitmap(m_index, bmpSize);
	if (bmp.IsOk())
	{
		gc.DrawBitmap(bmp, rect.x, rect.y, rect.width, rect.height);
	} else {
		// Draw empty page
		gc.SetBrush(*wxWHITE_BRUSH);
		gc.SetPen(wxNullPen);
		gc.DrawRectangle(rect.x, rect.y, rect.width, rect.height);
	}
}
Esempio n. 16
0
void GCDCGraphs::DrawRemarksBitmaps(wxGraphicsContext &dc) {
	Draw* draw = m_draws_wdg->GetSelectedDraw();
	if (draw == NULL)
		return;

	const ValuesTable& vt = draw->GetValuesTable();
	for (size_t i = 0; i < draw->GetValuesTable().size(); i++)
		if (vt.at(i).m_remark) { 
			double x = GetX(i);
			dc.DrawBitmap(m_remark_flag_bitmap,
					x - m_remark_flag_bitmap.GetWidth() / 2,
					m_screen_margins.topmargin - 7,
					m_remark_flag_bitmap.GetWidth(),
					m_remark_flag_bitmap.GetHeight());
		}
}
Esempio n. 17
0
void GCDCGraphs::DrawGraphs(wxGraphicsContext &dc) {
	dc.SetPen(wxPen(wxColour(255, 255, 255), 1, wxSOLID));

	int sel = m_draws_wdg->GetSelectedDrawIndex();
	if (sel < 0)
		return;

	for (size_t i = 0; i <= m_draws.size(); i++) {
		 
		size_t j = i;
		if ((int) j == sel) 
			continue;
		if (j == m_draws.size())	
			j = sel;

		Draw* d = m_draws[j];

		DrawGraph(dc, d);

		if ((int) j == sel)
			DrawCursor(dc, d);
	}

}
Esempio n. 18
0
void GCDCGraphs::DrawYAxisVals(wxGraphicsContext& dc) {
	Draw* draw = m_draws_wdg->GetSelectedDraw();
	if (draw == NULL) 
		return;
	DrawInfo *di = draw->GetDrawInfo();

	if (!di->IsValid())
		return;

	double min = di->GetMin();
	double max = di->GetMax();
	if( max <= min  ) {
		// FIXME:  Draw3 should atomaticly detect axes in that case, but
		//         it currently doesnt :(
		wxLogWarning(_T("Parameter %s has invalid min/max values: min %f, max %f. Min is set to 0, and max to 100."), di->GetName().c_str(), min, max);
		min = 0;
		max = 100;
	}

	//procedure for calculating distance between marks stolen from SzarpDraw2
	double x = max - min;
	double step;
	int i = 0;

	if (x < 1)
		for (;x < 1; x *=10, --i);
	else
		for (;(int)x / 10; x /=10, ++i);

	if (x <= 1.5)
		step = .1;
	else if (x <= 3.)
		step = .2;
	else if (x <= 7.5)
		step = .5;
	else
		step = 1.;

	double acc = 1;

	int prec = di->GetPrec();
				
	for (int p = prec; p > 0; --p)
		acc /= 10;

	double factor  = (i > 0) ? 10 : .1;

	for (;i; i -= i / abs(i))
		step *= factor;

	if (step < acc)
		step = acc;

    	dc.SetPen(wxPen(*wxWHITE, 1, wxSOLID));

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

	h -= m_screen_margins.bottommargin + m_screen_margins.topmargin;

	for (double val = max; (min - val) < acc; val -= step) {

		int y = GetY(val, di);

		dc.StrokeLine(m_screen_margins.leftmargin - 8, y, m_screen_margins.leftmargin, y);

		wxString sval = di->GetValueStr(val, _T("- -"));
		double textw, texth, textd, textel;
		dc.GetTextExtent(sval, &textw, &texth, &textd, &textel);
		dc.DrawText(sval, m_screen_margins.leftmargin - textw - 1, y + 2);
	}

}
Esempio n. 19
0
void GCDCGraphs::DrawSeasonLimitInfo(wxGraphicsContext &dc, int i, int month, int day, bool summer) {

	const double stripe_width = 2; 

	double x1 = GetX(i);
	double x2 = GetX(i + 1);

	double x = (x1 + x2) / 2;

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

	wxColour color = summer ? *wxBLUE : *wxRED;

	dc.SetFont(GetFont(), color);

	dc.SetPen(wxPen(color, 1, wxSOLID));

	wxBrush brush(color);
	dc.SetBrush(brush);
	dc.DrawRectangle(x + 1, m_screen_margins.topmargin, stripe_width, w - m_screen_margins.topmargin - m_screen_margins.bottommargin);

	wxString str;
	if (summer)
		str = wxString(_("summer season"));
	else
		str = wxString(_("winter season"));

	str += wxString::Format(_T(" %d "), day);

	switch (month) {
		case 1:
			str += _("january");
			break;
		case 2:
			str += _("february");
			break;
		case 3:
			str += _("march");
			break;
		case 4:
			str += _("april");
			break;
		case 5:
			str += _("may");
			break;
		case 6:
			str += _("june");
			break;
		case 7:
			str += _("july");
			break;
		case 8:
			str += _("august");
			break;
		case 9:
			str += _("septermber");
			break;
		case 10:
			str += _("october");
			break;
		case 11:
			str += _("november");
			break;
		case 12:
			str += _("december");
			break;
		default:
			assert(false);
	}

	double tw, th, td, tsel;
	dc.GetTextExtent(_T("W"), &tw, &th, &td, &tsel);

	int ty = m_screen_margins.topmargin + 1;
	for (size_t i = 0; i < str.Len(); ++i) {
		double lw, lh, ld, lsel;
		wxString letter = str.Mid(i, 1);
		dc.GetTextExtent(letter, &lw, &lh, &ld, &lsel);
		dc.DrawText(letter, x + stripe_width + 2 + (tw - lw) / 2, ty);
		ty += th + 2;
	}

}
Esempio n. 20
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);
	}
}