Скачиваний:
25
Добавлен:
01.05.2014
Размер:
5.77 Кб
Скачать
/*  Project first

		Copyright © 1997 by US. All Rights Reserved.

		SUBSYSTEM:    first.exe Application
		FILE:         tstpscnd.cpp
		AUTHOR:       US


		OVERVIEW
		========
		Source file for implementation of TSetupSecond (TDialog).
*/

#include <owl\owlpch.h>
#pragma hdrstop

#include <stdio.h>

#include "tstpscnd.h"
#include "tools.h"

//
// Build a response table for all messages/commands handled
// by the application.
//
DEFINE_RESPONSE_TABLE1(TSetupSecond, TDialog)
//{{TSetupSecondRSP_TBL_BEGIN}}
		EV_BN_CLICKED(IDC_BACK-1000, BackBNClicked),
		EV_BN_CLICKED(IDC_NEXT-1000, NextBNClicked),
		EV_BN_CLICKED(IDC_STOP-1000, StopBNClicked),
		EV_CBN_SELCHANGE(IDC_SETUP2TITLE, CBNTitleSelchange),
    EV_EN_CHANGE(IDC_COV12EDIT, COV12ENChange),
//{{TSetupSecondRSP_TBL_END}}
END_RESPONSE_TABLE;


//{{TSetupSecond Implementation}}


TSetupSecond::TSetupSecond (TWindow* parent, FirstSetupList &results,
	TResId resId, TModule* module):
		TDialog(parent, resId, module),
		w_data(results)
{
	AllIsOk = TRUE;

	BackButton = new TOwnerButton(this, IDC_BACK-1000, 0);
	NextButton = new TOwnerButton(this, IDC_NEXT-1000, 0);
	StopButton = new TOwnerButton(this, IDC_STOP-1000, 0);

	TitleEdit = new TComboBox(this, IDC_SETUP2TITLE, SetupTitleLength, 0);

	YEdit = new TEdit(this, IDC_YEDIT, SetupNumbersLength, 0);
	DiffYEdit = new TEdit(this, IDC_DIFFYEDIT, SetupNumbersLength, 0);
	TrueYEdit = new TEdit(this, IDC_TRUEYEDIT, SetupNumbersLength, 0);
	TrueDiffYEdit = new TEdit(this, IDC_TRUEDIFFYEDIT, SetupNumbersLength, 0);

	COV11Edit = new TEdit(this, IDC_COV11EDIT, SetupNumbersLength, 0);
	COV12Edit = new TEdit(this, IDC_COV12EDIT, SetupNumbersLength, 0);
	COV21Edit = new TEdit(this, IDC_COV21EDIT, SetupNumbersLength, 0);
	COV22Edit = new TEdit(this, IDC_COV22EDIT, SetupNumbersLength, 0);
}


TSetupSecond::~TSetupSecond ()
{
		Destroy();
}


void TSetupSecond::BackBNClicked ()
{
		w_data.result = SetupBack;
		CloseWindow(IDCANCEL);
}


void TSetupSecond::NextBNClicked ()
{
		if (CheckFloatEditor(this, DiffYEdit, SetupNumbersLength, &w_data.Root->DiffY, "оценка производной Y должна") ||
				CheckFloatEditor(this, YEdit, SetupNumbersLength, &w_data.Root->Y, "оценка Y должна") ||
				CheckFloatEditor(this, TrueDiffYEdit, SetupNumbersLength, &w_data.Root->TrueDiffY, "значение производной Y должно") ||
				CheckFloatEditor(this, TrueYEdit, SetupNumbersLength, &w_data.Root->TrueY, "зачение Y должно") ||
				CheckFloatEditor(this, COV11Edit, SetupNumbersLength, &w_data.Root->COV11, "эл-т матрицы ковариации должен") ||
				CheckFloatEditor(this, COV12Edit, SetupNumbersLength, &w_data.Root->COV12, "эл-т матрицы ковариации должен") ||
				CheckFloatEditor(this, COV21Edit, SetupNumbersLength, &w_data.Root->COV21, "эл-т матрицы ковариации должен") ||
				CheckFloatEditor(this, COV22Edit, SetupNumbersLength, &w_data.Root->COV22, "эл-т матрицы ковариации должен"))
		{
			AllIsOk = FALSE;
			return;
		}

		w_data.result = SetupContinue;

		CloseWindow(IDOK);
}

void TSetupSecond::StopBNClicked ()
{
		w_data.result = SetupStopped;
		CloseWindow(IDCANCEL);
}

void TSetupSecond::CBNTitleSelchange ()
{
	char buffer[SetupMaxLength+1];
	FirstSetup *p;

	TitleEdit->GetString(buffer, TitleEdit->GetSelIndex());
	for (p = w_data.Root->Next; p; p = p->Next)
		if (!strcmp(buffer, p->Title))
		{
			sprintf(buffer, "%lf", p->Y);
			killZeros(buffer);
			YEdit->Clear();
			YEdit->Insert(buffer);
			sprintf(buffer, "%lf", p->DiffY);
			killZeros(buffer);
			DiffYEdit->Clear();
			DiffYEdit->Insert(buffer);
			sprintf(buffer, "%lf", p->TrueY);
			killZeros(buffer);
			TrueYEdit->Clear();
			TrueYEdit->Insert(buffer);
			sprintf(buffer, "%lf", p->TrueDiffY);
			killZeros(buffer);
			TrueDiffYEdit->Clear();
			TrueDiffYEdit->Insert(buffer);
			sprintf(buffer, "%lf", p->COV11);
			killZeros(buffer);
			COV11Edit->Clear();
			COV11Edit->Insert(buffer);
			sprintf(buffer, "%lf", p->COV12);
			killZeros(buffer);
			COV12Edit->Clear();
			COV12Edit->Insert(buffer);
			sprintf(buffer, "%lf", p->COV21);
			killZeros(buffer);
			COV21Edit->Clear();
			COV21Edit->Insert(buffer);
			sprintf(buffer, "%lf", p->COV22);
			killZeros(buffer);
			COV22Edit->Clear();
			COV22Edit->Insert(buffer);

			TitleEdit->SetText(w_data.Root->Title);

			break;
		}
}


void TSetupSecond::SetupWindow ()
{
		TDialog::SetupWindow();

		// Position window to the center of desktop
		TRect dialog_pos;
		RECT desktop_pos;
		unsigned dcx, dcy, sx, sy;
		GetWindowRect(dialog_pos);
		::GetWindowRect(GetDesktopWindow(), &desktop_pos);
		dcx = desktop_pos.left + desktop_pos.right;
		dcy = desktop_pos.top + desktop_pos.bottom;
		sx = dialog_pos.right - dialog_pos.left;
		sy = dialog_pos.bottom - dialog_pos.top;
		dialog_pos.left = (dcx - sx) >> 1;
		dialog_pos.right = (dcx + sx) >> 1;
		dialog_pos.top = (dcy - sy) >> 1;
		dialog_pos.bottom = (dcy + sy) >> 1;
		MoveWindow(dialog_pos, FALSE);
}


BOOL TSetupSecond::EvInitDialog (HWND hWndFocus)
{
		BOOL result;
		FirstSetup *fsp;
		unsigned index;

		result = TDialog::EvInitDialog(hWndFocus);

		for (fsp = w_data.Root, index = 0; fsp;
			fsp = fsp->Next, index++)
				TitleEdit->InsertString(fsp->Title, index);
		TitleEdit->SetText(w_data.Root->Title);

		SetDefaultId(IDC_NEXT-1000);

		return result;
}


BOOL TSetupSecond::CanClose ()
{
		BOOL result = TDialog::CanClose() && AllIsOk;
		AllIsOk = TRUE;
		return result;
}


void TSetupSecond::COV12ENChange ()
{
	char buffer[SetupMaxLength+1];

	COV12Edit->GetLine(buffer, SetupMaxLength, 1);
	COV21Edit->Clear();
	COV21Edit->Insert(buffer);
}

Соседние файлы в папке SOURCE