Beispiel #1
0
DTime DTime::operator+(const wxTimeSpan& span) const {

	if (!m_time.IsValid() || m_period == PERIOD_T_OTHER)
		return DTime(m_period, wxInvalidDateTime);
		
	switch (m_period) {
		//in following periods we are not interested in time resolution
		case PERIOD_T_DECADE:
		case PERIOD_T_YEAR:
		case PERIOD_T_MONTH: 
			return DTime(m_period, m_time);
			break;
		//in this case will just follow UTC
		case PERIOD_T_30SEC:
		case PERIOD_T_MINUTE:
		case PERIOD_T_5MINUTE:
		case PERIOD_T_30MINUTE: 
		case PERIOD_T_DAY: 
			return DTime(m_period, m_time + span);
			break;
		case PERIOD_T_WEEK:
		case PERIOD_T_SEASON: {
			wxDateTime t = m_time + span;					   
			if (t.IsDST() != m_time.IsDST())
				t += ( m_time.IsDST() ? 1 : -1 ) * wxTimeSpan::Hour();
			return DTime(m_period, t);
			break;
		}
		default:
			assert(false);
			break;
	}

}
Beispiel #2
0
DTime DTime::operator+(const wxDateSpan& span) const {
	//note - this if is neccessary because result of addition of empty
	//wxDateSpan to 02:00 CET at the daylight saving time boundary 
	//magically becomes 02:00 CEST...
	if (span.GetYears() || span.GetMonths() || span.GetWeeks() || span.GetDays())
		return DTime(m_period, m_time + span);
	else
		return DTime(m_period, m_time);
}
Beispiel #3
0
__interrupt void AC_DET(void) 
{
  if (!DTime()) //Прогамный антидребезг
  {
    unsigned char State = PC_ODR >> 6;
    if (State != 0)
    {
      PC_ODR = ((((State >> 1) ^ (State & 1)) << 2) | State) << 5; // (10) -> (11) -> (10) cycle
    } else 
Beispiel #4
0
void StatDialog::OnDateChange(wxCommandEvent &event) {
    wxButton *button;
    wxDateTime time;

    bool start_time = false;

    if (event.GetId() == STAT_START_TIME) {
        button = wxDynamicCast(FindWindow(STAT_START_TIME), wxButton);
        start_time = true;
        time = m_start_time.GetTime();
    } else  {
        button = wxDynamicCast(FindWindow(STAT_END_TIME), wxButton);
        time = m_end_time.GetTime();
    }

    DateChooserWidget *dcw =
        new DateChooserWidget(
        this,
        _("Select date"),
        1,
        -1,
        -1,
        10
    );

    bool ret = dcw->GetDate(time);
    dcw->Destroy();

    if (ret == false)
        return;

    if (start_time) {
        m_start_time = DTime(m_period, time);
        m_start_time.AdjustToPeriod();
        button->SetLabel(FormatTime(time, m_period));
    } else {
        m_end_time = DTime(m_period, time);
        m_end_time.AdjustToPeriod();
        button->SetLabel(FormatTime(time, m_period));
    }


}
Beispiel #5
0
void DataMangler::DatabaseResponse(DatabaseQuery *q) {

	for (std::vector<DatabaseQuery::ValueData::V>::iterator i = q->value_data.vv->begin();
			i != q->value_data.vv->end();
			i++) {
		DTime time = DTime(m_period, i->time);

		int index = m_start_time.GetDistance(time);

		m_draw_vals.at(index).second = time;

		ValueInfo *vi;
		vi = &m_draw_vals.at(index).first.at(q->draw_no);
		vi->state = ValueInfo::PRESENT;
		vi->val = i->response;
	}

	m_pending -= q->value_data.vv->size();
	m_fetched += q->value_data.vv->size();

	delete q;

	m_progress->SetProgress(m_fetched * 100 / m_tofetch);

	if (m_fetched == m_tofetch) {
		assert(m_pending == 0);

		XYGraph* graph = new XYGraph;

		graph->m_start = m_start_time.GetTime();
		graph->m_end = m_end_time.GetTime();
		graph->m_period = m_period;
		graph->m_di = m_di;
		graph->m_min.resize(m_di.size());
		graph->m_max.resize(m_di.size());
		graph->m_dmin.resize(m_di.size());
		graph->m_dmax.resize(m_di.size());
		graph->m_avg.resize(m_di.size());
		graph->m_standard_deviation.resize(m_di.size());
		graph->m_averaged = m_average;

		AssociateValues(graph);
		FindMaxMinRange(graph);

		if (m_average)
			AverageValues(graph);

		m_progress->Destroy();
		m_dialog->DataFromMangler(graph);
	} if (m_pending <= 100 && m_pending + m_fetched != m_tofetch) {
		ProgressFetch();
	}

}
Beispiel #6
0
DTime TimeIndex::AdjustToPeriodSpan(const DTime &time) const {
	wxDateTime dt = time.GetTime();

	if (m_number_of_values == default_units_count[time.GetPeriod()] * PeriodMult[time.GetPeriod()]) {
		switch (time.GetPeriod()) {
			case PERIOD_T_DECADE :
			case PERIOD_T_YEAR :
				dt.SetMonth(wxDateTime::Jan);
			case PERIOD_T_MONTH :
				dt.SetDay(1);
				dt.SetHour(0);
				break;
			case PERIOD_T_WEEK:
			case PERIOD_T_SEASON :
				dt.SetToWeekDayInSameWeek(wxDateTime::Mon);
			case PERIOD_T_DAY :
				dt.SetHour(0);
				dt.SetMinute(0);
				break;
			case PERIOD_T_30MINUTE :
				dt.SetMinute(dt.GetMinute() / 30 * 30);
				dt.SetSecond(0);
				break;
			case PERIOD_T_5MINUTE :
				dt.SetMinute(dt.GetMinute() / 3 * 3);
				dt.SetSecond(0);
				break;
			case PERIOD_T_MINUTE :
			case PERIOD_T_30SEC :
				dt.SetSecond(dt.GetSecond() / 30 * 30);
				break;
			case PERIOD_T_OTHER:
			case PERIOD_T_LAST:
				assert(false);
		}
		return DTime(time.GetPeriod(), dt);
	} else {
		DTime ret(time);
		return ret.AdjustToPeriodStart();
	}
}
Beispiel #7
0
void XYDialog::OnDateChange(wxCommandEvent &event) {
	wxButton *button;
	DTime *time;

	if (event.GetId() == XY_START_TIME) {
		button = wxDynamicCast(FindWindow(XY_START_TIME), wxButton);
		time = &m_start_time;
	} else {
		button = wxDynamicCast(FindWindow(XY_END_TIME), wxButton);
		time = &m_end_time;
	}

	DateChooserWidget *dcw = 
		new DateChooserWidget(
				this,
				_("Select date"),
				1,
				-1,
				-1,
				1
		);

	wxDateTime wxtime = time->GetTime();
	
	bool ret = dcw->GetDate(wxtime);
	dcw->Destroy();

	if (ret == false)
		return;

	*time = DTime(m_period, wxtime);
	time->AdjustToPeriod();

	button->SetLabel(FormatTime(time->GetTime(), m_period));

}
Beispiel #8
0
DTime DTime::operator-(const wxDateSpan& span) const {
	if (span.GetYears() || span.GetMonths() || span.GetWeeks() || span.GetDays())
		return DTime(m_period, m_time - span);
	else
		return DTime(m_period, m_time);
}
Beispiel #9
0
XYDialog::XYDialog(wxWindow *parent, wxString prefix, ConfigManager *cfg, DatabaseManager *db, RemarksHandler *rh, TimeInfo time, DrawInfoList user_draws,  XFrame *frame) :
		wxDialog(parent,
			wxID_ANY,
			_("X/Y graph parameters"),
			wxDefaultPosition,
			wxDefaultSize,
			wxDEFAULT_DIALOG_STYLE | wxTAB_TRAVERSAL | wxRESIZE_BORDER ),
		m_period(time.period),
		m_start_time(time.begin_time),
		m_end_time(time.end_time)
		{

	if (user_draws.GetDoubleCursor()) {
		m_start_time = DTime(m_period, wxDateTime(user_draws.GetStatsInterval().first));
		m_end_time = DTime(m_period, wxDateTime(user_draws.GetStatsInterval().second));
	}

	if (frame->GetDimCount() == 3)
		SetHelpText(_T("draw3-ext-chartxyz"));
	else
		SetHelpText(_T("draw3-ext-chartxy"));

	SetIcon(szFrame::default_icon);

	wxString period_choices[PERIOD_T_SEASON] = { _("DECADE"), _("YEAR"), _("MONTH"), _("WEEK"), _("DAY"), _("30 MINUTES") };

	m_start_time.AdjustToPeriod();
	m_end_time.AdjustToPeriod();

	wxStaticText *label; 
	wxStaticLine *line;
	wxButton *button;

	m_config_manager = cfg;
	
	m_database_manager = db;

	m_remarks_handler = rh;

	m_mangler = NULL;

	m_frame = frame;

	m_draw_search = new IncSearch(m_config_manager, m_remarks_handler, prefix, this, incsearch_DIALOG, _("Choose draw"), false, true, true, m_database_manager);

	wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL);
	label = new wxStaticText(this, wxID_ANY, _("Choose graph parameters:"));
	line  = new wxStaticLine(this);

	sizer->Add(label, 0, wxALIGN_CENTER | wxALL, 5);
	sizer->Add(line, 0, wxEXPAND | wxALL, 5);

#define __BUTTON_NAME(N) user_draws.size() >= N ? user_draws[N-1]->GetName() :wxString( _("Choose draw"))

	wxBoxSizer* sizer_1 = new wxBoxSizer(wxHORIZONTAL);
	label = new wxStaticText(this, wxID_ANY, _("Axis X:"));
	sizer_1->Add(label, 0, wxALIGN_CENTER | wxALL, 5);
	button = new wxButton(this, XY_XAXIS_BUTTON, __BUTTON_NAME(1));
	sizer_1->Add(button, 1, wxEXPAND);
	sizer->Add(sizer_1, 0, wxEXPAND | wxALL, 5);

	wxBoxSizer* sizer_2 = new wxBoxSizer(wxHORIZONTAL);
	label = new wxStaticText(this, wxID_ANY, _("Axis Y:"));
	sizer_2->Add(label, 0, wxALIGN_CENTER | wxALL, 5);
	button = new wxButton(this, XY_YAXIS_BUTTON, __BUTTON_NAME(2));
	sizer_2->Add(button, 1, wxEXPAND);
	sizer->Add(sizer_2, 0, wxEXPAND | wxALL, 5);

	if (m_frame->GetDimCount() == 3) {
		wxBoxSizer* sizer_3 = new wxBoxSizer(wxHORIZONTAL);
		label = new wxStaticText(this, wxID_ANY, _("Axis Z:"));
		sizer_3->Add(label, 0, wxALIGN_CENTER | wxALL, 5);
		button = new wxButton(this, XY_ZAXIS_BUTTON, __BUTTON_NAME(3));
		sizer_3->Add(button, 1, wxEXPAND);
		sizer->Add(sizer_3, 0, wxEXPAND | wxALL, 5);
	} 

#undef __BUTTON_NAME

	line = new wxStaticLine(this);

	sizer->Add(line, 0, wxEXPAND | wxALL, 5);
	wxBoxSizer* sizer_4 = new wxBoxSizer(wxHORIZONTAL);
	label = new wxStaticText(this, wxID_ANY, _("Choose period:"));
	sizer_4->Add(label, 0, wxALIGN_CENTER | wxALL, 5);
	line = new wxStaticLine(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLI_VERTICAL);
	m_period_choice = new wxChoice(this, XY_CHOICE_PERIOD, wxDefaultPosition, wxDefaultSize, PERIOD_T_SEASON, period_choices);
	sizer_4->Add(m_period_choice, 0, wxALIGN_CENTER, 5);
	sizer->Add(sizer_4, 0, wxALIGN_CENTER | wxALL, 5);

	line = new wxStaticLine(this);
	sizer->Add(line, 0, wxEXPAND | wxALL, 5);

	wxFlexGridSizer* sizer_3 = new wxFlexGridSizer(2, 5, 5);

	sizer_3->AddGrowableCol(1);
	label = new wxStaticText(this, wxID_ANY, _("Start time:"));
	sizer_3->Add(label, 0, wxALIGN_CENTER | wxALL, 5);
	button = new wxButton(this, XY_START_TIME, FormatTime(m_start_time.GetTime(), m_period));
	sizer_3->Add(button, 1, wxEXPAND);
	sizer->Add(sizer_3, 0, wxEXPAND | wxALL, 5);

	label = new wxStaticText(this, wxID_ANY, _("End time:"));
	sizer_3->Add(label, 0, wxALIGN_CENTER | wxALL, 5);
	button = new wxButton(this, XY_END_TIME, FormatTime(m_end_time.GetTime(), m_period));
	sizer_3->Add(button, 1, wxEXPAND);

	wxBoxSizer *button_sizer1 = new wxBoxSizer(wxHORIZONTAL);
	button = new wxButton(this, XY_SAVE_TIME, _("Save time"));
	button_sizer1->Add(button, 0, wxALL, 3);
	button = new wxButton(this, XY_LOAD_TIME, _("Load time"));
	button_sizer1->Add(button, 0, wxALL, 3);
	if (m_loaded_time == 0) {
		button->Disable();
		button->Update();
	}
	sizer->Add(button_sizer1, 0, wxALIGN_RIGHT | wxALL, 5);

	line = new wxStaticLine(this);
	sizer->Add(line, 0, wxEXPAND | wxALL, 5);

	m_avg_check = NULL;
	if (m_frame->GetDimCount() == 2) {
		m_avg_check = new wxCheckBox(this, wxID_ANY, _("Average values"));
		sizer->Add(m_avg_check, 0, wxALIGN_CENTER | wxALL, 5);

		line = new wxStaticLine(this);
		sizer->Add(line, 0, wxEXPAND | wxALL, 5);
	}

	wxBoxSizer *button_sizer = new wxBoxSizer(wxHORIZONTAL);
	button = new wxButton(this, wxID_OK, _("OK"));
	button_sizer->Add(button, 0, wxALL, 10);
	button = new wxButton(this, wxID_CANCEL, _("Cancel"));
	button_sizer->Add(button, 0, wxALL, 10);
	button = new wxButton(this, wxID_HELP, _("Help"));
	button_sizer->Add(button, 0, wxALL, 10);

	sizer->Add(button_sizer, 1, wxALIGN_CENTER | wxALL, 10);

	m_period_choice->SetSelection(m_period);
	m_period_choice->SetFocus();

	// init draws information
	for (int i = 0; i < m_frame->GetDimCount(); i++) {
		if ((int) (user_draws.size() -1)  >= i)
			m_di.push_back(user_draws[i]);
		else
			m_di.push_back(NULL);
	}

	if (m_frame->GetDimCount() == 3)
		SetTitle(_("XYZ Graph"));

	SetSizer(sizer);
	sizer->SetSizeHints(this);

}
Beispiel #10
0
#include "drawdnd.h"
#include "timeformat.h"
#include "drawtime.h"
#include "database.h"
#include "draw.h"
#include "dbinquirer.h"
#include "datechooser.h"
#include "progfrm.h"
#include "xydiag.h"
#include "cfgmgr.h"
#include "xygraph.h"
#include "incsearch.h"

/* initialize static members from XYDialog class */
int XYDialog::m_loaded_time = 0;
DTime XYDialog::m_saved_start_time = DTime();
DTime XYDialog::m_saved_end_time = DTime();

XYDialog::XYDialog(wxWindow *parent, wxString prefix, ConfigManager *cfg, DatabaseManager *db, RemarksHandler *rh, TimeInfo time, DrawInfoList user_draws,  XFrame *frame) :
		wxDialog(parent,
			wxID_ANY,
			_("X/Y graph parameters"),
			wxDefaultPosition,
			wxDefaultSize,
			wxDEFAULT_DIALOG_STYLE | wxTAB_TRAVERSAL | wxRESIZE_BORDER ),
		m_period(time.period),
		m_start_time(time.begin_time),
		m_end_time(time.end_time)
		{

	if (user_draws.GetDoubleCursor()) {
Beispiel #11
0
DTime TaskLog::totalTime() const {
    return DTime(*end - *start);
}
Beispiel #12
0
void LogScene::getTaskItem(const QModelIndex &index) {
    Task* task = _model->task(index);

    Calendar* calendar = task->project()->projectDefaultCalendar();
    int hoursInDay = calendar->endHour().hour() - calendar->startHour().hour();
    std::vector<TaskLog*>* logs =task->logs();
    double startHour = 0;//calendar->startHour().hour();
    double endHour = 24;//calendar->endHour().hour() + 1;
    double minuteSize = (double)24*BLOCKSIZE / (double)((endHour - startHour) * 60);
    int red = 0;
    for (std::vector<TaskLog*>::iterator iter = logs->begin(); iter != logs->end(); iter++) {
        TaskLog* log = *iter;

        QSize size = sizeHint(index);

        int bordermargin = (size.height() * .4) / 2;

        int daysToStart = _startDate.daysTo(*log->start);
        double x1 = (double)daysToStart * (double)_dayWidth;
        DTime logStartTime = log->start->time();
        double y1 = (double)(logStartTime.totalMinutes() - (startHour*60)) * minuteSize;

        double x2 = (daysToStart + 1) * (double)_dayWidth;
        DTime logEndTime = log->end->time();
        if (log->end->getDay() != log->start->getDay()) {
            logEndTime = DTime(23, 59, 59);
        }
        double y2 = (double)(logEndTime.totalMinutes() - (startHour*60)) * minuteSize;

        QBrush b(task->taskColor());//QImage(":/img/task_bar.png"));//(QPixmap(":/img/task_bar.png"));
        red += 20;
        QColor penColor((task->taskColor().red() < 100) ? 0: (task->taskColor().red() - 100),
                        (task->taskColor().green() < 100) ? 0: (task->taskColor().green() - 100),
                        (task->taskColor().blue() < 100) ? 0: (task->taskColor().blue() - 100));
        QPen pen(penColor);
        if (log->activeLog) {
            pen.setWidth(3);
        }

        QGraphicsItem* item = this->addRect(x1, y1, (x2 - x1), (y2 - y1), pen, b);
        item->setZValue(1);
        if ((y2 - y1) > 20) {
            QFont f("Arial", 8);
            f.setWeight(QFont::Light);
            QBrush brush(penColor);

            std::string description = *task->shortDescription();
            int textY = y1 + 5;
            while (description.length() > 0) {
                std::string label;
                if (description.length() > 15) {
                    label = description.substr(0, 15);
                    description = description.substr(15);
                    if ((label.at(label.length() - 1) != ' ') &&
                        (description.at(0) != ' ')) {
                        int pos;
                        if ((pos = label.rfind(' ')) != std::string::npos) {
                            description = label.substr(pos) + description;
                            label = label.substr(0, pos);
                        }
                    }
                } else {
                    label = description;
                    description = "";
                }
                label = label.erase(label.find_last_not_of(" \n\r\t")+1);
                description = description.erase(description.find_last_not_of(" \n\r\t")+1);
                if ((textY + 20) < y2) {
                    QGraphicsSimpleTextItem* text = this->addSimpleText(tr(label.c_str()));
                    text->setPos(x1 + 10, textY);
                    //text->rotate(90);
                    text->setVisible(true);
                    text->setBrush(brush);
                    text->setFont(f);
                    text->setZValue(2);
                    textY += 15;
                } else {
                    break;
                }
            }
        }
        _currentY += sizeHint(index).height();
    }
    delete(logs);
}