Добавил:
Studfiles2
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:Программы для выполнения лаб 1 и 2 / KALMAN / SOURCE / TSTPFRST
.CPP/* Project first
Copyright © 1997 by US. All Rights Reserved.
SUBSYSTEM: first.exe Application
FILE: tstpfrst.cpp
AUTHOR: US
OVERVIEW
========
Source file for implementation of TSetupFirst (TDialog).
*/
#include <owl\owlpch.h>
#pragma hdrstop
#include <stdio.h>
#include "tstpfrst.h"
#include "tools.h"
#include "txsetupb.h"
#include "txsetupc.h"
//
// Build a response table for all messages/commands handled
// by the application.
//
DEFINE_RESPONSE_TABLE1(TSetupFirst, TDialog)
//{{TSetupFirstRSP_TBL_BEGIN}}
EV_BN_CLICKED(IDC_STOP-1000, StopBNClicked),
EV_BN_CLICKED(IDC_NEXT-1000, NextBNClicked),
EV_BN_CLICKED(IDC_BACK-1000, BackBNClicked),
EV_CBN_SELCHANGE(IDC_SETUPTITLE, CBNSelchange),
EV_BN_CLICKED(IDC_WPARAMS, WPBNClicked),
EV_BN_CLICKED(IDC_XINPUT, XIBNClicked),
//{{TSetupFirstRSP_TBL_END}}
END_RESPONSE_TABLE;
//{{TSetupFirst Implementation}}
TSetupFirst::TSetupFirst (TWindow* parent, FirstSetupList &results, TResId resId,
TModule* module):
TDialog(parent, resId, module),
w_data(results), result(SetupStopped)
{
TitleEdit = new TComboBox(this, IDC_SETUPTITLE, SetupTitleLength, 0);
MethodList = new TComboBox(this, IDC_METHODLIST, MethodNameLength, 0);
VKNoiseList = new TComboBox(this, IDC_VNOISELIST, NoiseGeneratorNameLength, 0);
MEdit = new TEdit(this, IDC_MEDIT, SetupNumbersLength, 0);
FEdit = new TEdit(this, IDC_FEDIT, SetupNumbersLength, 0);
KFEdit = new TEdit(this, IDC_KFEDIT, SetupNumbersLength, 0);
QFEdit = new TEdit(this, IDC_QFEDIT, SetupNumbersLength, 0);
SigmaEdit = new TEdit(this, IDC_SIGMAEDIT, SetupNumbersLength, 0);
LengthEdit = new TEdit(this, IDC_LENGTHEDIT, SetupNumbersLength, 0);
BackButton = new TOwnerButton(this, IDC_BACK-1000, 0);
NextButton = new TOwnerButton(this, IDC_NEXT-1000, 0);
StopButton = new TOwnerButton(this, IDC_STOP-1000, 0);
w_data.result = SetupStopped;
}
TSetupFirst::~TSetupFirst ()
{
Destroy();
}
/* HWND button = GetDlgItem(IDC_BACK-1000-1000);
HDC buttonDc = ::GetDC(button);
TDC dc(buttonDc);
dc.SelectStockObject(WHITE_PEN);
dc.Rectangle(TPoint(0, 0), TPoint(dc.GetViewportExt()));
dc.RestoreObjects();
::ReleaseDC(button, buttonDc); */
void TSetupFirst::StopBNClicked ()
{
result = SetupStopped;
CloseWindow(IDCANCEL);
}
void TSetupFirst::NextBNClicked ()
{
result = SetupContinue;
CloseWindow(IDOK);
}
void TSetupFirst::BackBNClicked ()
{
result = SetupBack;
CloseWindow(IDCANCEL);
}
BOOL TSetupFirst::CanClose ()
{
if (!TDialog::CanClose())
return FALSE;
if (result == SetupContinue)
{
if (CheckFloatEditor(this, MEdit, SetupNumbersLength, &w_data.Root->m, "m должно") ||
CheckFloatEditor(this, FEdit, SetupNumbersLength, &w_data.Root->f, "f должно") ||
CheckFloatEditor(this, KFEdit, SetupNumbersLength, &w_data.Root->kf, "kf должно") ||
CheckFloatEditor(this, QFEdit, SetupNumbersLength, &w_data.Root->Qf, "Qf должно") ||
CheckFloatEditor(this, SigmaEdit, SetupNumbersLength, &w_data.Root->sigma, "Сигма должна") ||
CheckDwordEditor(this, LengthEdit, SetupNumbersLength, &w_data.Root->length, "Длина должна"))
return FALSE;
if (w_data.Root->length > 65528lu / sizeof(double))
{
MessageBox("Размер выборки превышает возможости large модели памяти",
"Проблема", MB_OK|MB_ICONSTOP);
LengthEdit->SetFocus();
return FALSE;
}
TitleEdit->GetText(w_data.Root->Title, SetupTitleLength);
if (!*w_data.Root->Title)
{
MessageBox("Идентификатор должен быть не пустым", "Ошибка", MB_ICONHAND|MB_OK);
TitleEdit->SetFocus();
return FALSE;
}
if (TitleEdit->FindString(w_data.Root->Title, 0) >= 0)
{
MessageBox("Идентификатор не должен повторяться", "Ошибка", MB_ICONHAND|MB_OK);
TitleEdit->SetFocus();
return FALSE;
}
w_data.Root->VNoise = (NoiseType)VKNoiseList->GetSelIndex();
w_data.Root->Method = (FilterMethod)MethodList->GetSelIndex();
}
w_data.result = result;
return TRUE;
}
BOOL TSetupFirst::EvInitDialog (HWND hWndFocus)
{
BOOL result;
FirstSetup *fsp;
unsigned index;
result = TDialog::EvInitDialog(hWndFocus);
TitleEdit->SetText(w_data.Root->Title);
for (fsp = w_data.Root->Next, index = 0; fsp;
fsp = fsp->Next, index++)
TitleEdit->InsertString(fsp->Title, index);
/* MEdit->Insert("1");
FEdit->Insert("1");
KFEdit->Insert("1");
QFEdit->Insert("1");
SigmaEdit->Insert("1"); */
VKNoiseList->AddString("Гауссовская");
VKNoiseList->AddString("Показательная");
VKNoiseList->AddString("Равномерная");
VKNoiseList->SetText("Равномерная");
MethodList->AddString("Фильтр Калмана");
MethodList->AddString("Фильтр Калмана со старением данных");
MethodList->AddString("Расширеный фильтр Калмана");
MethodList->AddString("Адаптивный фильтр");
MethodList->SetSelIndex(0);/*Text("Фильтр Калмана");*/
SetDefaultId(IDC_NEXT-1000);
return result;
}
void TSetupFirst::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);
}
void TSetupFirst::CBNSelchange ()
{
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->m);
killZeros(buffer);
MEdit->Clear();
MEdit->Insert(buffer);
sprintf(buffer, "%lf", p->f);
killZeros(buffer);
FEdit->Clear();
FEdit->Insert(buffer);
sprintf(buffer, "%lf", p->kf);
killZeros(buffer);
KFEdit->Clear();
KFEdit->Insert(buffer);
sprintf(buffer, "%lf", p->Qf);
killZeros(buffer);
QFEdit->Clear();
QFEdit->Insert(buffer);
sprintf(buffer, "%lf", p->sigma);
killZeros(buffer);
SigmaEdit->Clear();
SigmaEdit->Insert(buffer);
sprintf(buffer, "%lu", p->length);
killZeros(buffer);
LengthEdit->Clear();
LengthEdit->Insert(buffer);
w_data.Root->sm = p->m;
w_data.Root->sf = p->f;
w_data.Root->skf = p->kf;
w_data.Root->XI_IntervalRule = p->XI_IntervalRule;
w_data.Root->XI_Interval_E = p->XI_Interval_E;
w_data.Root->XI_Interval_D = p->XI_Interval_D;
w_data.Root->XI_DurationRule = p->XI_DurationRule;
w_data.Root->XI_Duration_E = p->XI_Duration_E;
w_data.Root->XI_Duration_D = p->XI_Duration_D;
w_data.Root->XI_TypeRule = p->XI_TypeRule;
w_data.Root->XI_Type_E = p->XI_Type_E;
w_data.Root->XI_Type_D = p->XI_Type_D;
/* UINT selStart, selEnd;
TitleEdit->GetEditSel(selStart, selEnd); DOES NOT WORK - WHY?
TitleEdit->SetEditSel(selEnd, selEnd); */
break;
}
}
void TSetupFirst::XIBNClicked ()
{
TXSetupC(this, w_data).Execute();
}
void TSetupFirst::WPBNClicked ()
{
if (CheckFloatEditor(this, MEdit, SetupNumbersLength, &w_data.Root->sm, "m должно") ||
CheckFloatEditor(this, FEdit, SetupNumbersLength, &w_data.Root->sf, "f должно") ||
CheckFloatEditor(this, KFEdit, SetupNumbersLength, &w_data.Root->skf, "kf должно"))
return;
TXSetupB(this, w_data).Execute();
}
Соседние файлы в папке SOURCE