unit Setup;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ComCtrls, SharedData, MiscRoutines, ExtCtrls;

type
  TSurfaceScheme = (scSolid, scRandom, scGradient);
  
type
  TGeneralFlags = record
    // Состояние и положение главного окна
    WindowState : TWindowState;
    Left,
    Top,
    Width,
    Height      : dword;
    ToolBarVisible,
    StatusBarVisible,
    MenuBarVisible,
    FullScreen,
    CanHideAllControls : Boolean;
    // Предлагать сохранение отчета
    AskIfReportChanged : Boolean;
    // Выводить список окон при скрытии, показе и упорядочивании
    ShowHideList   : Boolean;
    ShowShowList   : Boolean;
    ShowArrangeList: Boolean;
    // Показывать советы
    ShowHints      : Boolean;
    // Флаги в формах отчета
    CohrenResultsShow    : Boolean;
    CohrenActivateReport : Boolean;
    StudentResultsShow   : Boolean;
    StudentActivateReport: Boolean;
    FisherResultsShow    : Boolean;
    FisherActivateReport : Boolean;
    // Нужно ли при экспорте данных для графиков сохранять все координаты
    ExportAllCoords      : Boolean;
    // Нужно ли при создании выдавать запрос на создание матрицы откликов
    AlsoCreateY          : Boolean;
    // Нужно ли при анализе выдавать запрос на создание матрицы откликов
    CPForSaturated       : Boolean;
  end;
  // Флаги, управляющие генерацией отчета
  PReportFlags  = ^TReportFlags;
  TReportFlags  = record
    UseDivider    : Boolean;
    DividerString : array[0..255] of char;
    TimeDate      : Boolean;
    Degree        : Boolean;
    pType         : Boolean;
    N             : Boolean;
    ModelType     : Boolean;
    MainMatrix    : Boolean;
    NaturalMatrix : Boolean;
    MLVector      : Boolean;
    DFVector      : Boolean;
    ExpandedMatrix: Boolean;
    MMatrix       : Boolean;
    CMatrix       : Boolean;
    R             : Boolean;
    YMatrix       : Boolean;
    AVector       : Boolean;
    DVector       : Boolean;
    SVector       : Boolean;
    DV            : Boolean;
    Dmax          : Boolean;
    ActualBSize   : Boolean;
    BVector       : Boolean;
    Dad           : Boolean;
    CohrenAnalysis: Boolean;
    FisherAnalysis: Boolean;
    MainPoint     : Boolean;
    MarkEndOfReport: Boolean;
    BackColor     : TColor;
    FontColor     : TColor;
    Font          : TLogFont;   
  end;
  // Флаги графика
  PTeeFlags = ^TTeeFlags;
  TTeeFlags = record
    // Параметры графика
    Legend      : array[0..255] of char;
    Color       : integer;
    CopyColor   : integer;
    // Параметры серии
    SeriesColor : integer;
    // 5.08.99 - экспериментальные точки
    Points      : Boolean;
    // Параметры осей
    AxisColor   : integer;
    NaturalX    : Boolean;
    // Параметры сетки
    GridVisible : Boolean;
    GridColor   : integer;
    GridStyle   : TPenStyle;
  end;
  // Флаги растрового генератора
  PGLFlags      = ^TGLFlags;
  TGLFlags      = record
    // Показывать окно состояния
    ShowLog     : Boolean;
    // Показывать описания форматов пикселей
    DescribePFDs: Boolean;
    // Рисовать линии
    DrawLines   : Boolean;
    // Прозрачная поверхность
    BlendSurface: Boolean;
    // Рисовать обрамляющую коробку
    DrawBBox    : Boolean;
    // Показывать частоту обновления
    ShowFPS     : Boolean;
    // Рисовать орты
    DrawBasis   : Boolean;
    // Масса камеры
    Mass        : integer;
    // Метки в натуральных координатах
    NaturalXY   : Boolean;
    // Управление камерой
    UseVR       : Boolean;
    BackColor   : integer;
    XWallColor,
    YWallColor,
    ZWallColor  : integer;
    BBoxColor   : integer;
    // 5.08.99 - экспериментальные точки
    Points      : Boolean;
    // Схема закраски поверхности
    SurfScheme  : TSurfaceScheme;
    SurfColor1,
    SurfColor2  : integer;
    LineColor   : integer;
  end;

  TSetupData = record
  // Основные параметры ==================================================
    GeneralFlags   : TGeneralFlags;
  // Параметры отчета ====================================================
    ReportFlags    : TReportFlags;
  // Параметры графика ===================================================
    TeeFlags       : TTeeFlags;
  // Параметры подсистемы трехмерной графики =============================
    GLFlags        : TGLFlags;
  end;

type
  TOptionsForm = class(TForm)
    PCOptions: TPageControl;
    ReportSheet: TTabSheet;
    OkButton: TButton;
    Button1: TButton;
    GeneralSheet: TTabSheet;
    GBReport: TGroupBox;
    CBUseDivider: TCheckBox;
    EDividerString: TEdit;
    CBTimeDate: TCheckBox;
    CBpType: TCheckBox;
    CBDegree: TCheckBox;
    CBN: TCheckBox;
    CBModelType: TCheckBox;
    CBMainMatrix: TCheckBox;
    CBNaturalMatrix: TCheckBox;
    CBMLVector: TCheckBox;
    CBDFVector: TCheckBox;
    CBYMatrix: TCheckBox;
    CBMMatrix: TCheckBox;
    CBCMatrix: TCheckBox;
    CBR: TCheckBox;
    CBAVector: TCheckBox;
    CBDVector: TCheckBox;
    CBSVector: TCheckBox;
    CBDV: TCheckBox;
    CBDad: TCheckBox;
    CBCohrenAnalysis: TCheckBox;
    CBFisherAnalysis: TCheckBox;
    CBMainPoint: TCheckBox;
    CBDmax: TCheckBox;
    CBMarkEndOfReport: TCheckBox;
    Bevel1: TBevel;
    Bevel2: TBevel;
    Bevel3: TBevel;
    CBExpandedMatrix: TCheckBox;
    Bevel4: TBevel;
    CBActualBSize: TCheckBox;
    CBBVector: TCheckBox;
    RFInverseButton: TButton;
    RFAllButton: TButton;
    Bevel5: TBevel;
    GBInterface: TGroupBox;
    GBOther: TGroupBox;
    CBShowHideList: TCheckBox;
    CBShowShowList: TCheckBox;
    CBShowArrangeList: TCheckBox;
    CBCohrenResultsShow: TCheckBox;
    CBCohrenActivateReport: TCheckBox;
    CBStudentResultsShow: TCheckBox;
    CBStudentActivateReport: TCheckBox;
    CBFisherResultsShow: TCheckBox;
    CBFisherActivateReport: TCheckBox;
    CBShowHints: TCheckBox;
    CBAskIfReportChanged: TCheckBox;
    CBExportAllCoords: TCheckBox;
    CBAlsoCreateY: TCheckBox;
    CBCPForSaturated: TCheckBox;
    TeeSheet: TTabSheet;
    GLSheet: TTabSheet;
    GBTeeOptions: TGroupBox;
    Label1: TLabel;
    ELegend: TEdit;
    CBGridVisible: TCheckBox;
    GBTeeColors: TGroupBox;
    Label2: TLabel;
    SColor: TShape;
    Label3: TLabel;
    SCopyColor: TShape;
    SSeriesColor: TShape;
    SAxisColor: TShape;
    SGridColor: TShape;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    ColorDialog: TColorDialog;
    GBGLOptions: TGroupBox;
    GBGLColors: TGroupBox;
    CBShowLog: TCheckBox;
    CBDescribePFDs: TCheckBox;
    CBShowFPS: TCheckBox;
    CBUseVR: TCheckBox;
    CBDrawBBox: TCheckBox;
    CBDrawBasis: TCheckBox;
    CBDrawLines: TCheckBox;
    CBBlendSurface: TCheckBox;
    LBSurfScheme: TListBox;
    SBackColor: TShape;
    SBBoxColor: TShape;
    SLineColor: TShape;
    SSurfColor1: TShape;
    SSurfColor2: TShape;
    SXWallColor: TShape;
    SYWallColor: TShape;
    SZWallColor: TShape;
    Label7: TLabel;
    Label8: TLabel;
    Label9: TLabel;
    Label10: TLabel;
    Label11: TLabel;
    Label12: TLabel;
    Label13: TLabel;
    Label14: TLabel;
    Label15: TLabel;
    Bevel6: TBevel;
    CBGridStyle: TComboBox;
    TBMass: TTrackBar;
    Label16: TLabel;
    CBNaturalX: TCheckBox;
    CBNaturalXY: TCheckBox;
    CBPoints2D: TCheckBox;
    CBPoints3D: TCheckBox;
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure CBUseDividerClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure OkButtonClick(Sender: TObject);
    procedure RFAllButtonClick(Sender: TObject);
    procedure RFInverseButtonClick(Sender: TObject);
    procedure SColorMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure CBCohrenResultsShowClick(Sender: TObject);
    procedure CBStudentResultsShowClick(Sender: TObject);
    procedure CBFisherResultsShowClick(Sender: TObject);
  end;

var
  AppSetup : TSetupData;

var
  OptionsForm: TOptionsForm;

implementation

uses MainUnit;

{$R *.DFM}

// =======================================================================
// UseDefaultReportFlags
// =======================================================================

procedure UseDefaultReportFlags(var AppSetup:TSetupData);
begin
  with AppSetup.ReportFlags do
  begin
    StrCopy(DividerString,PChar('* * * ================================'+
      '============================== * * *'));
    UseDivider:=True;
    TimeDate:=True;
    Degree:=True;
    pType:=True;
    N:=True;
    ModelType:=True;
    MainMatrix:=True;
    NaturalMatrix:=True;
    MLVector:=True;
    DFVector:=True;
    ExpandedMatrix:=False;
    MMatrix:=True;
    CMatrix:=True;
    R:=True;
    YMatrix:=True;
    AVector:=False;
    DVector:=False;
    SVector:=True;
    DV:=False;
    Dmax:=False;
    ActualBSize:=False;
    BVector:=True;
    Dad:=False;
    CohrenAnalysis:=True;
    FisherAnalysis:=True;
    MainPoint:=True;
    MarkEndOfReport:=False;
    BackColor:=clWindow;
    FontColor:=clWindowText;
    Font.lfHeight:=10;
    Font.lfWidth:=0;
    Font.lfEscapement:=0;
    Font.lfOrientation:=0;
    Font.lfWeight:=FW_NORMAL;
    Font.lfItalic:=0;
    Font.lfUnderline:=0;
    Font.lfStrikeOut:=0;
    Font.lfCharSet:=RUSSIAN_CHARSET;
    Font.lfOutPrecision:=OUT_DEFAULT_PRECIS;
    Font.lfClipPrecision:=CLIP_DEFAULT_PRECIS;
    Font.lfQuality:=DEFAULT_QUALITY;
    Font.lfPitchAndFamily:=DEFAULT_PITCH or FF_DONTCARE;
    StrCopy(Font.lfFaceName,PChar('Courier'));
  end;
end;

// =======================================================================
// UseDefaultGeneralFlags
// =======================================================================

procedure UseDefaultGeneralFlags(var AppSetup:TSetupData);
begin
  // Автоматически настраиваемые параметры
  AppSetup.GeneralFlags.WindowState:=wsNormal;
  AppSetup.GeneralFlags.Left:=30;
  AppSetup.GeneralFlags.Top:=20;
  AppSetup.GeneralFlags.Width:=640 - 60;
  AppSetup.GeneralFlags.Height:=480 - 40;
  AppSetup.GeneralFlags.ToolBarVisible:=True;
  AppSetup.GeneralFlags.StatusBarVisible:=True;
  AppSetup.GeneralFlags.MenuBarVisible:=True;
  AppSetup.GeneralFlags.FullScreen:=False;
  AppSetup.GeneralFlags.CanHideAllControls:=False;
  // Настраиваемые параметры
  AppSetup.GeneralFlags.ShowHints:=True;
  AppSetup.GeneralFlags.ShowHideList:=True;
  AppSetup.GeneralFlags.ShowShowList:=True;
  AppSetup.GeneralFlags.ShowArrangeList:=True;
  AppSetup.GeneralFlags.CohrenResultsShow:=True;
  AppSetup.GeneralFlags.CohrenActivateReport:=False;
  AppSetup.GeneralFlags.StudentResultsShow:=True;
  AppSetup.GeneralFlags.StudentActivateReport:=False;
  AppSetup.GeneralFlags.FisherResultsShow:=True;
  AppSetup.GeneralFlags.FisherActivateReport:=True;
  AppSetup.GeneralFlags.AskIfReportChanged:=True;
  AppSetup.GeneralFlags.ExportAllCoords:=False;
  AppSetup.GeneralFlags.AlsoCreateY:=True;
  AppSetup.GeneralFlags.CPForSaturated:=True;
end;

// =======================================================================
// UseDefaultTeeFlags
// =======================================================================
procedure UseDefaultTeeFlags(var AppSetup:TSetupData);
begin
  StrCopy(AppSetup.TeeFlags.Legend,PChar('Зависимость отклика от '+
    'одного из нормализованных факторов'));
  AppSetup.TeeFlags.Color:=clSilver;
  AppSetup.TeeFlags.CopyColor:=clWhite;
  AppSetup.TeeFlags.SeriesColor:=clBlack;
  AppSetup.TeeFlags.AxisColor:=clBlack;
  AppSetup.TeeFlags.GridVisible:=True;
  AppSetup.TeeFlags.GridColor:=clGray;
  AppSetup.TeeFlags.GridStyle:=psDot;
  AppSetup.TeeFlags.NaturalX:=True;
  AppSetup.TeeFlags.Points:=False;
end;

function RGB(r,g,b:integer):TColor;
begin
  Result:=(b shl 16) + (g shl 8) + r;
end;

// =======================================================================
// UseDefaultGLFlags
// =======================================================================
procedure UseDefaultGLFlags(var AppSetup:TSetupData);
begin
  AppSetup.GLFlags.ShowLog:=True;
  AppSetup.GLFlags.DescribePFDs:=False;
  AppSetup.GLFlags.DrawLines:=True;
  AppSetup.GLFlags.BlendSurface:=False;
  AppSetup.GLFlags.DrawBBox:=True;
  AppSetup.GLFlags.ShowFPS:=False;
  AppSetup.GLFlags.DrawBasis:=False;
  AppSetup.GLFlags.UseVR:=False;
  AppSetup.GLFlags.SurfScheme:=scGradient;
  AppSetup.GLFlags.Mass:=25;
  AppSetup.GLFlags.NaturalXY:=True;
  AppSetup.GLFlags.Points:=False;

  AppSetup.GLFlags.BackColor:=clBlack;
  AppSetup.GLFlags.XWallColor:=RGB(255,115,0);
  AppSetup.GLFlags.YWallColor:=RGB(0,192,16);
  AppSetup.GLFlags.ZWallColor:=RGB(181,0,206);
  AppSetup.GLFlags.BBoxColor:=clGray;
  AppSetup.GLFlags.SurfColor1:=RGB(0,0,255);
  AppSetup.GLFlags.SurfColor2:=RGB(32,255,0);
  AppSetup.GLFlags.LineColor:=clYellow;
end;

// =======================================================================
// UseDefault
// =======================================================================

procedure UseDefault(var AppSetup:TSetupData);
begin
  UseDefaultGeneralFlags(AppSetup);
  UseDefaultReportFlags(AppSetup);
  UseDefaultTeeFlags(AppSetup);
  UseDefaultGLFlags(AppSetup);
end;

// =======================================================================
// RetrieveAutoGeneralFlags
// =======================================================================

procedure RetrieveAutoGeneralFlags(var AppSetup:TSetupData);
begin
  AppSetup.GeneralFlags.WindowState:=MainForm.WindowState;
  if(AppSetup.GeneralFlags.WindowState=wsNormal) then
  begin
    AppSetup.GeneralFlags.Left:=MainForm.Left;
    AppSetup.GeneralFlags.Top:=MainForm.Top;
    AppSetup.GeneralFlags.Width:=MainForm.Width;
    AppSetup.GeneralFlags.Height:=MainForm.Height;
  end;
  AppSetup.GeneralFlags.ToolBarVisible:=MainForm.ToolPanel.Visible;
  AppSetup.GeneralFlags.StatusBarVisible:=MainForm.StatusBar.Visible;
  AppSetup.GeneralFlags.MenuBarVisible:=MainForm.Menu<>nil;
  AppSetup.GeneralFlags.FullScreen:=MainForm.BorderStyle=bsNone;
end;

// =======================================================================
// FormCreate
// =======================================================================

const
  MTST : dword = $5453544D;

procedure TOptionsForm.FormCreate(Sender: TObject);
var
  S : TFileStream;
  Id : dword;
begin
  // Загружаем настройки
  UseDefault(AppSetup);
  // ---------------------------------------------------------------------
  S:=nil;
  try
    S:=TFileStream.Create(StrAppHomePath+StrAppIniFile,fmOpenRead);
    S.ReadBuffer(Id,4);
    if((S.Size=(4+sizeof(AppSetup)))and(Id=MTST)) then
    begin
      S.ReadBuffer(AppSetup,sizeof(AppSetup));
      S.Destroy;
    end
    else
    begin
      S.Destroy;
      Warning('Конфигурационный файл поврежден.'+#13+
        'Будут использованы установки по умолчанию.');
      DeleteFile(StrAppHomePath+StrAppIniFile);
    end;
  except
    on EReadError do
    begin
      Error('Ошибка чтения конфигурационных данных.');
      S.Destroy;
    end;
    on EFOpenError do
    begin
      Warning('Конфигурационный файл не найден.'+#13+
        'Будут использованы установки по умолчанию.');
    end;
  end;
end;

// =======================================================================
// FormDestroy
// =======================================================================

procedure TOptionsForm.FormDestroy(Sender: TObject);
var
  S:TFileStream;
  Id:dword;
begin
  RetrieveAutoGeneralFlags(AppSetup);
  S:=nil;
  try
    DeleteFile(StrAppHomePath+StrAppIniFile);
    S:=TFileStream.Create(StrAppHomePath+StrAppIniFile,fmCreate);
    Id:=MTST;
    S.WriteBuffer(Id,4);
    S.WriteBuffer(AppSetup,sizeof(AppSetup));
    S.Destroy;
  except
    on EWriteError do
    begin
      Error('Ошибка записи конфигурационных данных.');
      S.Destroy;
    end;
    on EFCreateError do
    begin
      Error('Ошибка создания конфигурационного файла.');
    end;
  end;
end;

// =======================================================================
// Разные обработчики
// =======================================================================

procedure TOptionsForm.CBUseDividerClick(Sender: TObject);
begin
  EDividerString.ReadOnly:=not CBUseDivider.Checked;
  if(CBUseDivider.Checked) then
  begin
    EDividerString.Color:=clWindow;
    EDividerString.Text:=StrPas(AppSetup.ReportFlags.DividerString);
  end
  else
  begin
    EDividerString.Color:=clBtnFace;
    EDividerString.Text:='';
  end;
end;

procedure TOptionsForm.CBCohrenResultsShowClick(Sender: TObject);
begin
  CBCohrenActivateReport.Enabled:=CBCohrenResultsShow.Checked;
end;

procedure TOptionsForm.CBStudentResultsShowClick(Sender: TObject);
begin
  CBStudentActivateReport.Enabled:=CBStudentResultsShow.Checked;
end;

procedure TOptionsForm.CBFisherResultsShowClick(Sender: TObject);
begin
  CBFisherActivateReport.Enabled:=CBFisherResultsShow.Checked;
end;

procedure TOptionsForm.FormShow(Sender: TObject);
begin
  // Синхронизируем ключи
  // Общие
  CBShowHints.Checked:=AppSetup.GeneralFlags.ShowHints;
  CBShowHideList.Checked:=AppSetup.GeneralFlags.ShowHideList;
  CBShowShowList.Checked:=AppSetup.GeneralFlags.ShowShowList;
  CBShowArrangeList.Checked:=AppSetup.GeneralFlags.ShowArrangeList;
  CBCohrenResultsShow.Checked:=AppSetup.GeneralFlags.CohrenResultsShow;
  CBCohrenActivateReport.Checked:=AppSetup.GeneralFlags.CohrenActivateReport;
  CBStudentResultsShow.Checked:=AppSetup.GeneralFlags.StudentResultsShow;
  CBStudentActivateReport.Checked:=AppSetup.GeneralFlags.StudentActivateReport;
  CBFisherResultsShow.Checked:=AppSetup.GeneralFlags.FisherResultsShow;
  CBFisherActivateReport.Checked:=AppSetup.GeneralFlags.FisherActivateReport;
  CBAskIfReportChanged.Checked:=AppSetup.GeneralFlags.AskIfReportChanged;
  CBExportAllCoords.Checked:=AppSetup.GeneralFlags.ExportAllCoords;
  CBAlsoCreateY.Checked:=AppSetup.GeneralFlags.AlsoCreateY;
  CBCPForSaturated.Checked:=AppSetup.GeneralFlags.CPForSaturated;
  // Отчет
  EDividerString.Text:=StrPas(AppSetup.ReportFlags.DividerString);
  CBUseDivider.Checked:=AppSetup.ReportFlags.UseDivider;
  CBTimeDate.Checked:=AppSetup.ReportFlags.TimeDate;
  CBDegree.Checked:=AppSetup.ReportFlags.Degree;
  CBpType.Checked:=AppSetup.ReportFlags.pType;
  CBN.Checked:=AppSetup.ReportFlags.N;
  CBModelType.Checked:=AppSetup.ReportFlags.ModelType;
  CBMainMatrix.Checked:=AppSetup.ReportFlags.MainMatrix;
  CBNaturalMatrix.Checked:=AppSetup.ReportFlags.NaturalMatrix;
  CBMLVector.Checked:=AppSetup.ReportFlags.MLVector;
  CBDFVector.Checked:=AppSetup.ReportFlags.DFVector;
  CBExpandedMatrix.Checked:=AppSetup.ReportFlags.ExpandedMatrix;
  CBMMatrix.Checked:=AppSetup.ReportFlags.MMatrix;
  CBCMatrix.Checked:=AppSetup.ReportFlags.CMatrix;
  CBR.Checked:=AppSetup.ReportFlags.R;
  CBYMatrix.Checked:=AppSetup.ReportFlags.YMatrix;
  CBAVector.Checked:=AppSetup.ReportFlags.AVector;
  CBDVector.Checked:=AppSetup.ReportFlags.DVector;
  CBSVector.Checked:=AppSetup.ReportFlags.SVector;
  CBDV.Checked:=AppSetup.ReportFlags.DV;
  CBDmax.Checked:=AppSetup.ReportFlags.DMax;
  CBActualBSize.Checked:=AppSetup.ReportFlags.ActualBSize;
  CBBVector.Checked:=AppSetup.ReportFlags.BVector;
  CBDad.Checked:=AppSetup.ReportFlags.Dad;
  CBCohrenAnalysis.Checked:=AppSetup.ReportFlags.CohrenAnalysis;
  CBFisherAnalysis.Checked:=AppSetup.ReportFlags.FisherAnalysis;
  CBMainPoint.Checked:=AppSetup.ReportFlags.MainPoint;
  CBMarkEndOfReport.Checked:=AppSetup.ReportFlags.MarkEndOfReport;
  // График
  ELegend.Text:=StrPas(AppSetup.TeeFlags.Legend);
  SColor.Brush.Color:=AppSetup.TeeFlags.Color;
  SCopyColor.Brush.Color:=AppSetup.TeeFlags.CopyColor;
  SSeriesColor.Brush.Color:=AppSetup.TeeFlags.SeriesColor;
  SAxisColor.Brush.Color:=AppSetup.TeeFlags.AxisColor;
  SGridColor.Brush.Color:=AppSetup.TeeFlags.GridColor;
  CBGridVisible.Checked:=AppSetup.TeeFlags.GridVisible;
  CBNaturalX.Checked:=AppSetup.TeeFlags.NaturalX;
  CBPoints2D.Checked:=AppSetup.TeeFlags.Points;
  case AppSetup.TeeFlags.GridStyle of
    psSolid:        CBGridStyle.ItemIndex:=0;
    psDash:         CBGridStyle.ItemIndex:=1;
    psDot:          CBGridStyle.ItemIndex:=2;
    psDashDot:      CBGridStyle.ItemIndex:=3;
    psDashDotDot:   CBGridStyle.ItemIndex:=4;
  end;
  // Диаграмма
  CBShowLog.Checked:=AppSetup.GLFlags.ShowLog;
  CBDescribePFDs.Checked:=AppSetup.GLFlags.DescribePFDs;
  CBDrawLines.Checked:=AppSetup.GLFlags.DrawLines;
  CBBlendSurface.Checked:=AppSetup.GLFlags.BlendSurface;
  CBDrawBBox.Checked:=AppSetup.GLFlags.DrawBBox;
  CBShowFPS.Checked:=AppSetup.GLFlags.ShowFPS;
  CBDrawBasis.Checked:=AppSetup.GLFlags.DrawBasis;
  CBUseVR.Checked:=AppSetup.GLFlags.UseVR;
  CBPoints3D.Checked:=AppSetup.GLFlags.Points;
  case AppSetup.GLFlags.SurfScheme of
    scSolid:        LBSurfScheme.ItemIndex:=0;
    scGradient:     LBSurfScheme.ItemIndex:=1;
    scRandom:       LBSurfScheme.ItemIndex:=2;
  end;
  TBMass.Position:=AppSetup.GLFlags.Mass;
  CBNaturalXY.Checked:=AppSetup.GLFlags.NaturalXY;
  SBackColor.Brush.Color:=AppSetup.GLFlags.BackColor;
  SXWallColor.Brush.Color:=AppSetup.GLFlags.XWallColor;
  SYWallColor.Brush.Color:=AppSetup.GLFlags.YWallColor;
  SZWallColor.Brush.Color:=AppSetup.GLFlags.ZWallColor;
  SBBoxColor.Brush.Color:=AppSetup.GLFlags.BBoxColor;
  SSurfColor1.Brush.Color:=AppSetup.GLFlags.SurfColor1;
  SSurfColor2.Brush.Color:=AppSetup.GLFlags.SurfColor2;
  SLineColor.Brush.Color:=AppSetup.GLFlags.LineColor;
  // Обновляем состояния зависимых элементов
  CBCohrenActivateReport.Enabled:=CBCohrenResultsShow.Checked;
  CBStudentActivateReport.Enabled:=CBStudentResultsShow.Checked;
  CBFisherActivateReport.Enabled:=CBFisherResultsShow.Checked;
end;

procedure TOptionsForm.OkButtonClick(Sender: TObject);
begin
  // Синхронизируем ключи
  // Общие
  AppSetup.GeneralFlags.ShowHints:=CBShowHints.Checked;
  AppSetup.GeneralFlags.ShowHideList:=CBShowHideList.Checked;
  AppSetup.GeneralFlags.ShowShowList:=CBShowShowList.Checked;
  AppSetup.GeneralFlags.ShowArrangeList:=CBShowArrangeList.Checked;
  AppSetup.GeneralFlags.CohrenResultsShow:=CBCohrenResultsShow.Checked;
  AppSetup.GeneralFlags.CohrenActivateReport:=CBCohrenActivateReport.Checked;
  AppSetup.GeneralFlags.StudentResultsShow:=CBStudentResultsShow.Checked;
  AppSetup.GeneralFlags.StudentActivateReport:=CBStudentActivateReport.Checked;
  AppSetup.GeneralFlags.FisherResultsShow:=CBFisherResultsShow.Checked;
  AppSetup.GeneralFlags.FisherActivateReport:=CBFisherActivateReport.Checked;
  AppSetup.GeneralFlags.AskIfReportChanged:=CBAskIfReportChanged.Checked;
  AppSetup.GeneralFlags.ExportAllCoords:=CBExportAllCoords.Checked;
  AppSetup.GeneralFlags.AlsoCreateY:=CBAlsoCreateY.Checked;
  AppSetup.GeneralFlags.CPForSaturated:=CBCPForSaturated.Checked;
  // Отчет
  StrPLCopy(AppSetup.ReportFlags.DividerString,
    EDividerString.Text,255);
  AppSetup.ReportFlags.UseDivider:=CBUseDivider.Checked;
  AppSetup.ReportFlags.TimeDate:=CBTimeDate.Checked;
  AppSetup.ReportFlags.Degree:=CBDegree.Checked;
  AppSetup.ReportFlags.pType:=CBpType.Checked;
  AppSetup.ReportFlags.N:=CBN.Checked;
  AppSetup.ReportFlags.ModelType:=CBModelType.Checked;
  AppSetup.ReportFlags.MainMatrix:=CBMainMatrix.Checked;
  AppSetup.ReportFlags.NaturalMatrix:=CBNaturalMatrix.Checked;
  AppSetup.ReportFlags.MLVector:=CBMLVector.Checked;
  AppSetup.ReportFlags.DFVector:=CBDFVector.Checked;
  AppSetup.ReportFlags.ExpandedMatrix:=CBExpandedMatrix.Checked;
  AppSetup.ReportFlags.MMatrix:=CBMMatrix.Checked;
  AppSetup.ReportFlags.CMatrix:=CBCMatrix.Checked;
  AppSetup.ReportFlags.R:=CBR.Checked;
  AppSetup.ReportFlags.YMatrix:=CBYMatrix.Checked;
  AppSetup.ReportFlags.AVector:=CBAVector.Checked;
  AppSetup.ReportFlags.DVector:=CBDVector.Checked;
  AppSetup.ReportFlags.SVector:=CBSVector.Checked;
  AppSetup.ReportFlags.DV:=CBDV.Checked;
  AppSetup.ReportFlags.DMax:=CBDmax.Checked;
  AppSetup.ReportFlags.ActualBSize:=CBActualBSize.Checked;
  AppSetup.ReportFlags.BVector:=CBBVector.Checked;
  AppSetup.ReportFlags.Dad:=CBDad.Checked;
  AppSetup.ReportFlags.CohrenAnalysis:=CBCohrenAnalysis.Checked;
  AppSetup.ReportFlags.FisherAnalysis:=CBFisherAnalysis.Checked;
  AppSetup.ReportFlags.MainPoint:=CBMainPoint.Checked;
  AppSetup.ReportFlags.MarkEndOfReport:=CBMarkEndOfReport.Checked;
  // График
  StrPLCopy(AppSetup.TeeFlags.Legend,ELegend.Text,255);
  if((AppSetup.TeeFlags.NaturalX<>CBNaturalX.Checked) or
     (AppSetup.TeeFlags.Points<>CBPoints2D.Checked)) then
    Info('Изменения формата вступят в силу при следующем'+
      ' построении графика.');
  AppSetup.TeeFlags.NaturalX:=CBNaturalX.Checked;
  AppSetup.TeeFlags.Color:=SColor.Brush.Color;
  AppSetup.TeeFlags.CopyColor:=SCopyColor.Brush.Color;
  AppSetup.TeeFlags.SeriesColor:=SSeriesColor.Brush.Color;
  AppSetup.TeeFlags.AxisColor:=SAxisColor.Brush.Color;
  AppSetup.TeeFlags.GridColor:=SGridColor.Brush.Color;
  AppSetup.TeeFlags.GridVisible:=CBGridVisible.Checked;
  AppSetup.TeeFlags.Points:=CBPoints2D.Checked;
  case CBGridStyle.ItemIndex of
    0: AppSetup.TeeFlags.GridStyle:=psSolid;
    1: AppSetup.TeeFlags.GridStyle:=psDash;
    2: AppSetup.TeeFlags.GridStyle:=psDot;
    3: AppSetup.TeeFlags.GridStyle:=psDashDot;
    4: AppSetup.TeeFlags.GridStyle:=psDashDotDot;
  end;
  // Диаграмма
  AppSetup.GLFlags.ShowLog:=CBShowLog.Checked;
  AppSetup.GLFlags.DescribePFDs:=CBDescribePFDs.Checked;
  AppSetup.GLFlags.DrawLines:=CBDrawLines.Checked;
  AppSetup.GLFlags.BlendSurface:=CBBlendSurface.Checked;
  AppSetup.GLFlags.DrawBBox:=CBDrawBBox.Checked;
  AppSetup.GLFlags.ShowFPS:=CBShowFPS.Checked;
  AppSetup.GLFlags.DrawBasis:=CBDrawBasis.Checked;
  AppSetup.GLFlags.UseVR:=CBUseVR.Checked;
  AppSetup.GLFlags.Points:=CBPoints3D.Checked;
  case LBSurfScheme.ItemIndex of
    0: AppSetup.GLFlags.SurfScheme:=scSolid;
    1: AppSetup.GLFlags.SurfScheme:=scGradient;
    2: AppSetup.GLFlags.SurfScheme:=scRandom;
  end;
  AppSetup.GLFlags.Mass:=TBMass.Position;
  if(AppSetup.GLFlags.NaturalXY<>CBNaturalXY.Checked) then
    Info('Изменения формата меток вступят в силу при следующем'+
      ' построении поверхности.');
  AppSetup.GLFlags.NaturalXY:=CBNaturalXY.Checked;
  AppSetup.GLFlags.BackColor:=SBackColor.Brush.Color;
  AppSetup.GLFlags.XWallColor:=SXWallColor.Brush.Color;
  AppSetup.GLFlags.YWallColor:=SYWallColor.Brush.Color;
  AppSetup.GLFlags.ZWallColor:=SZWallColor.Brush.Color;
  AppSetup.GLFlags.BBoxColor:=SBBoxColor.Brush.Color;
  AppSetup.GLFlags.SurfColor1:=SSurfColor1.Brush.Color;
  AppSetup.GLFlags.SurfColor2:=SSurfColor2.Brush.Color;
  AppSetup.GLFlags.LineColor:=SLineColor.Brush.Color;
  MainForm.SetupChanged;
end;

procedure TOptionsForm.RFAllButtonClick(Sender: TObject);
begin
  CBUseDivider.Checked:=True;
  CBTimeDate.Checked:=True;
  CBDegree.Checked:=True;
  CBpType.Checked:=True;
  CBN.Checked:=True;
  CBModelType.Checked:=True;
  CBMainMatrix.Checked:=True;
  CBNaturalMatrix.Checked:=True;
  CBMLVector.Checked:=True;
  CBDFVector.Checked:=True;
  CBExpandedMatrix.Checked:=True;
  CBMMatrix.Checked:=True;
  CBCMatrix.Checked:=True;
  CBR.Checked:=True;
  CBYMatrix.Checked:=True;
  CBAVector.Checked:=True;
  CBDVector.Checked:=True;
  CBSVector.Checked:=True;
  CBDV.Checked:=True;
  CBDmax.Checked:=True;
  CBActualBSize.Checked:=True;
  CBBVector.Checked:=True;
  CBDad.Checked:=True;
  CBCohrenAnalysis.Checked:=True;
  CBFisherAnalysis.Checked:=True;
  CBMainPoint.Checked:=True;
  CBMarkEndOfReport.Checked:=True;
  CBUseDividerClick(Self);
end;

procedure TOptionsForm.RFInverseButtonClick(Sender: TObject);
begin
  CBUseDivider.Checked:=not CBUseDivider.Checked;
  CBTimeDate.Checked:=not CBTimeDate.Checked;
  CBDegree.Checked:=not CBDegree.Checked;
  CBpType.Checked:=not CBpType.Checked;
  CBN.Checked:=not CBN.Checked;
  CBModelType.Checked:=not CBModelType.Checked;
  CBMainMatrix.Checked:=not CBMainMatrix.Checked;
  CBNaturalMatrix.Checked:=not CBNaturalMatrix.Checked;
  CBMLVector.Checked:=not CBMLVector.Checked;
  CBDFVector.Checked:=not CBDFVector.Checked;
  CBExpandedMatrix.Checked:=not CBExpandedMatrix.Checked;
  CBMMatrix.Checked:=not CBMMatrix.Checked;
  CBCMatrix.Checked:=not CBCMatrix.Checked;
  CBR.Checked:=not CBR.Checked;
  CBYMatrix.Checked:=not CBYMatrix.Checked;
  CBAVector.Checked:=not CBAVector.Checked;
  CBDVector.Checked:=not CBDVector.Checked;
  CBSVector.Checked:=not CBSVector.Checked;
  CBDV.Checked:=not CBDV.Checked;
  CBDmax.Checked:=not CBDmax.Checked;
  CBActualBSize.Checked:=not CBActualBSize.Checked;
  CBBVector.Checked:=not CBBVector.Checked;
  CBDad.Checked:=not CBDad.Checked;
  CBCohrenAnalysis.Checked:=not CBCohrenAnalysis.Checked;
  CBFisherAnalysis.Checked:=not CBFisherAnalysis.Checked;
  CBMainPoint.Checked:=not CBMainPoint.Checked;
  CBMarkEndOfReport.Checked:=not CBMarkEndOfReport.Checked;
  CBUseDividerClick(Self);
end;


procedure TOptionsForm.SColorMouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  ColorDialog.Color:=TShape(Sender).Brush.Color;
  if(ColorDialog.Execute) then
    TShape(Sender).Brush.Color:=ColorDialog.Color;
end;

end.

