//---------------------------------------------------------------------------

#include <vcl.h>
#include <Registry.hpp>

#pragma hdrstop

//С уклоном полок по ГОСТ 8239-89
//Нормальный(Б) по ГОСТ 26020-83
//Дополнительной серии(Д) по ГОСТ 26020-83
//Широкополочный по ГОСТ 26020-83
//Колонный(К) по ГОСТ 26020-83

#include "SelectProfilSect.h"
#include "Define_Material_ARSS.h"
#include "Advanced_gamma_c.h"
#include "Advanced_gamma_n.h"
#include "Data_Gen.h"
#include "StandartProfil.h"
#include "String_doubleUnit.h"
#include "CheckExecuteU.h""
#include "Steel_param_ARSS.h"
#include "TypeData.h"
#include "WRData_Check.h"
#include "message.h"
#include "SaveSelectProf.h"
#include "SortP.h"
#include "ProcExt.h"
#include "ListConst.h"
#include "HelpKoeffLength.h"
#include "HelpClass.h"
#include "ReportSelectSteel.h"
#include "Help_FlexComp.h"
#include "Help_FlexTens.h"
#include "EMBRAC.h"
#include "pCanvas_func.h"
#include "DefineQBal.h"
#include "DrawRSU.h"
#include "AboutProg.h"
#include "Point_dvutavr.h"
#include "Draw3D_beam.h"
#include "Help.h"
#include "Dvutavr_Choice_Alg.h"
#include "Dvutavr_Choice_Alg_0.h"
#include "ChoiceKolonna_Alg.h"
#include "Help_delta_Alg_1.h"
#include "Help_Algor.h"
#include "Get_param_sect_func.h"
//#include "MultiSupport.h"


//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "SectSelectCom_Param"
#pragma link "SHDocVw_OCX"
#pragma link "Sect_Param_Weld"
#pragma link "Draw_RSU_F"
#pragma link "Draw_RSU_F"
#pragma link "BalkaLoad"
#pragma link "RackLoad"
#pragma resource "*.dfm"

#define EMBRAC


TSelectProfilSectForm *SelectProfilSectForm;
// Объявление класса проверок
TCheckExecute CheckExecute;
const int MruCount = 5;
const char* RegKey = "Software\\BCBJournal\SelectProfilSectProgram";
TStringList* MruList;

MATER MaterProp[MAX_MATERIAL];
//int   n_material;
//int   index_modify_material;
int   Material_Number;
FILE * BD_file=NULL;


bool flag_sect_change; // флаг изменения параметров сечения
int  Type_sect;   // Тип сечения - Двутавр или труба
COMMON_SECT *common_sect;
SECT_DVUTAVR *sect;
SECT_DVUTAVR *sect_w;

bool flag_image = true;
TMetafile * GrapMeta = NULL;
TFont     * TheFont;
int Page_Width = 700;
int Page_Height = 450;
TMetafileCanvas *pCanvas;

static TStandartProfil StandartProfil;

static AnsiString String_Centr_Tension[N_CENTR_TENSION_U] ={List_Centr_TensionU};
static int NCentr_Tension = N_CENTR_TENSION_U;

static AnsiString String_Centr_Tension_Tube[N_CENTR_TENSION_TUBE_U] ={List_Centr_TensionU_Tube};
static int NCentr_Tension_Tube = N_CENTR_TENSION_TUBE_U;

static AnsiString String_Centr_Compression[N_CENTR_COMPRESSION_U] ={List_Centr_CompressionU};
static int NCentr_Compression = N_CENTR_COMPRESSION_U;

static AnsiString String_Centr_Compression_Tube[N_CENTR_COMPRESSION_TUBE_U] ={List_Centr_CompressionU_Tube};
static int NCentr_Compression_Tube = N_CENTR_COMPRESSION_TUBE_U;

static AnsiString String_Bending[N_BENDING_U] ={List_BendingU};
static int NBending = N_BENDING_U;

static AnsiString String_Bending_Tube[N_BENDING_TUBE_U] = {List_Bending_TubeU};
static int NBending_Tube = N_BENDING_TUBE_U;

static AnsiString String_Compression_Bending_Const[N_COMPRESSION_BENDING_U] ={List_Compression_Bending_ConstU};
static int NCompression_Bending_Const = N_COMPRESSION_BENDING_U;

static AnsiString String_Compression_Bending_Tube[N_COMPRESSION_BENDING_TUBE_U] ={List_Compression_Bending_TubeU};
static int NCompression_Bending_Tube = N_COMPRESSION_BENDING_TUBE_U;

static AnsiString String_Tension_Bending[N_TENSION_BENDING_U] ={List_Tension_Bending_U};
static int NTension_Bending = N_TENSION_BENDING_U;

static AnsiString String_Tension_Bending_Tube[N_TENSION_BENDING_TUBE_U] ={List_Tension_Bending_TubeU};
static int NTension_Bending_Tube = N_TENSION_BENDING_TUBE_U;

static AnsiString String_Weld_Dvut[NLIST_WELD_DVUT] ={List_Weld_Dvut};
static int NList_Weld_Dvut = NLIST_WELD_DVUT;

static AnsiString String_Weld_Tavr_Plit[NLIST_WELD_TAVR_PLIT] ={List_Weld_Tavr_Plit};
static int NList_Weld_Tavr_Plit = NLIST_WELD_TAVR_PLIT;

static AnsiString String_Weld_Dvut_Plit[NLIST_WELD_DVUT_PLIT] ={List_Weld_Dvut_Plit};
static int NList_Weld_Dvut_Plit = NLIST_WELD_DVUT_PLIT;

extern WELD_PARAM_UNIT  *Weld_unit;


extern char stroka_param[1024];

//---------------------------------------------------------------------------
__fastcall TSelectProfilSectForm::TSelectProfilSectForm(TComponent* Owner)
		: TForm(Owner)
{
	 sect_w = &(sect_weld);
	 SectSelectCom_ParamFrame2->TabSheet_Standart->Caption = "Двутавр + пластина";
	 SectSelectCom_ParamFrame2->TabSheet_TavrStandart->Caption = "Тавр + пластина";
}
//---------------------------------------------------------------------------
void __fastcall TSelectProfilSectForm::FormShow(TObject *Sender)
{
   N_profil = 0;
   BalkaLoadFrame1->Length_beam = 0;
   BalkaLoadFrame1->ConfigForm_profil(DVUTAVR_STAND, Sender);

   RackLoadFrame1->Length_rack = 0;
   RackLoadFrame1->ConfigForm_profil(DVUTAVR_STAND, Sender);

   ComboBox_Dvutavr->ItemIndex = 0;
   ComboBox_Dvutavr_TU->ItemIndex = 0;
   PageControl_Dvutavr->ActivePage = TabSheet_GOST;

   Data_select.index_GOST_or_TU = typeGOST_G57837_B;
   SectSelectCom_ParamFrame1->index_GOST_or_TU = Data_select.index_GOST_or_TU;
   SectSelectCom_ParamFrame2->index_GOST_or_TU = Data_select.index_GOST_or_TU;
   Data_select.index_TAVR_GOST_or_TU = typeTAVR_BT;
   SectSelectCom_ParamFrame1->index_TAVR_GOST_or_TU = Data_select.index_TAVR_GOST_or_TU;
   SectSelectCom_ParamFrame2->index_TAVR_GOST_or_TU = Data_select.index_TAVR_GOST_or_TU;

   SectSelectCom_ParamFrame1->index_composed = -1;
   SectSelectCom_ParamFrame2->index_composed = -1;


   ComboBox_TypeElemChange(Sender);
   PageControl_Data->ActivePage=TabSheet_Common;
   TabSheet_KI->TabVisible = false;
   TabSheet_Hole->TabVisible = false;
   TabSheet_Weld->TabVisible = false;
   Panel_mater->Caption = "";
   flag_change_elem = false;
   flag_change_rsu = false;
   Label_alfa->Caption = L"Угол  \u03B1, град";
   Label_mass_weld->Caption = "";

   SectSelectCom_ParamFrame1->Button_Apply->Visible = false;

   flag_message = true; // Выводить сообщение при смене типа профиля

   // Нарисовать профиль и оси координат при первом входе
   Draw_prof_ax(0);
   //InfMessage((AnsiString)stroka_param);
   if (stroka_param[0]!='\0') {
	 // открыть файл
	 OpenProject(Sender, 1);
	 //InfMessage("Файл:\""+(AnsiString)stroka_param+"\"");
   }
   else {
	   NNewClick(Sender);
   }
   Data_select.index_profil = ComboBox_Dvutavr->ItemIndex;
   Data_select.type_profil = Data_select.index_profil + Data_select.index_GOST_or_TU;

   N_profil = 0;

   Show_prof(0, Sender);
   index_mu = RadioGroup_mu->ItemIndex;

   sect_weld.h1 = sect_weld.h2 = 20;
   sect_weld.b1 = sect_weld.b2 = 300;
   sect_weld.h = 500;
   sect_weld.b = 8;
   sect_weld.flag_concl = true;
   sect_weld.n_group = -1;   // номер группы профилей
   sect_weld.n_profil = 0;  // номер профиля в группе
   sect_weld.index_orient = 0;   // ориентация = 0 (в плоскости XZ) или 1 (в плоскости YZ)
   sect_weld.type_profil = DVUTAVR;  // или двутавр (DVUTAVR) , или гнутик
   sect_weld.index_perfor = 0;  // 0 - не перфорированный двутавр, 1 - перфорированный

   Sect_Param_WeldFrame1->kf_dvut = 8.0;
   Sect_Param_WeldFrame1->Write_sect(Sender);  // Установка поля рисования сечения


   Label_mass->Caption =" ";
   Label_conditions->Caption =" ";
   Label_add_conditions->Caption =" ";
   Label_edge->Caption =" ";
   Label_edge_step->Caption =" ";
   Label_edge_param->Caption =" ";

   Label_mass_c->Caption =" ";
   Label_conditions_c->Caption =" ";
   Label_add_conditions_c->Caption =" ";
   Label_edge_c->Caption =" ";
   Label_edge_step_c->Caption =" ";
   Label_edge_param_c->Caption =" ";

   RadioGroup_Loads->ItemIndex = 0;
   RadioGroup_LoadsClick(Sender);
   PageControl_Data->ActivePage = TabSheet_Common;

}
//---------------------------------------------------------------------------
// Заполнение параметров составных сечений
void __fastcall TSelectProfilSectForm::Fill_param_comp()  {

	 GEOM_PARAM_SECT param_sect;

	 StringGrid_Comp->Cells[0][0] = "A, см2";
	 StringGrid_Comp->Cells[0][1] = "Iy, см4";
	 StringGrid_Comp->Cells[0][2] = "iy, мм";
	 StringGrid_Comp->Cells[0][3] = "z0, мм";

	 switch (Data_select.index_composed) {
	 case TAVR_PLATE_DOWN:
	 case TAVR_PLATE_UP:
	   Get_param_sect_composed(TAVR, &com_sect, Data_select.plate_width, Data_select.plate_thick, &param_sect, Data_select.index_composed);
	 break;
	 case DVUTAVR_PLATE_DOWN:
	   Get_param_sect_composed(DVUTAVR, &com_sect, Data_select.plate_width, Data_select.plate_thick, &param_sect, Data_select.index_composed);
	 break;
	 }
	 StringGrid_Comp->Cells[1][0] = Round(1e-2*param_sect.Ar, 1);
	 StringGrid_Comp->Cells[1][1] = Round(1e-4*param_sect.Izz, 0);
	 StringGrid_Comp->Cells[1][2] = Round(sqrt(param_sect.Izz/param_sect.Ar), 1);
	 StringGrid_Comp->Cells[1][3] = Round(param_sect.Zct, 1);

}

//-----------------------------------------------------------------
void __fastcall TSelectProfilSectForm::BitBtnExitClick(TObject *Sender)
{
	Close();
}
//
//---------------------------------------------------------------------------
// Выполнить проверку
void __fastcall TSelectProfilSectForm::BitBtnExecClick(TObject *Sender)
{
   int i, rc;
   if (!TabSheet_Part->TabVisible) {
		rc = Application->MessageBox(L"Подбор не выполняется, т.к. РСУ не получены.", L"",
								  MB_OK | MB_ICONERROR);
		return;
   }
   //if ( Material_Number < 1 || strcmp(MaterProp[Material_Number].title,"")==0) {
   if ( strcmp(Data_select.title_material, "")==0) {
			i = Application->MessageBox(L"Установите материал",	L"Материал не установлен",
				MB_OK | MB_ICONWARNING);
			BitBtnMaterialClick(Sender);
   }
   if (CheckBox_same_material->Checked) {
	  if ( strcmp(Data_select.title_material_plate, "")==0) {
			i = Application->MessageBox(L"Установите материал",	L"Материал стенки/пластины не установлен",
				MB_OK | MB_ICONWARNING);
			BitBtnMaterial_plateClick(Sender);
	  }
   }

   if (flag_change_rsu) {
	 #ifdef EMBRAC
	 rc=Application->MessageBox(L"Значения нагрузок были изменены, но в РСУ не включены. Продолжить выполнение c прежними РСУ?", L"",
								  MB_YESNO | MB_ICONQUESTION);
	 #else
	 rc=Application->MessageBox("Значения нагрузок были изменены, но в РСУ не включены. Продолжить выполнение c прежними РСУ?", "",
								  MB_YESNO | MB_ICONQUESTION);
	 #endif
	 if (rc==IDNO) return;
   }
   //InfMessage("Подбор сечения ");
   Label_mass->Caption = "";
   Label_mass_weld->Caption = "";
   Label_conditions->Caption = "";
   Label_edge->Caption = "";
   Label_edge_step->Caption =" ";
   Label_edge_param->Caption =" ";
   TabSheet_KI->TabVisible = false;
   //Sect_Param_WeldFrame1->Visible = false;

   PageControl_Data->ActivePage=TabSheet_Common;
   flag_checking = false;

   //--------------------------------------------------------------
   // Выполнить проверку сечений
   SectChecking(-1, -1, Sender);       //common_sect->dvutavr

   Draw_prof_ax(N_profil);

}
//--------------------------------------------------------------------------------
// Выполнить проверку сечений
void __fastcall TSelectProfilSectForm::SectChecking(int index, int n_thick, TObject *Sender)
{
	  int i, rc;
	  double ss;
	  double mass_prof;
	  int num_prof;
	  AnsiString StrFall;

	  // Чтение данных
	  rc = Read_data(Sender);
	  if (rc>0) {
		return;
	  }

	  // Проверка ограничений
	  if (Data_select.flag_add_limit) {
		 if (Data_select.max_width == 0 && Data_select.max_height == 0) {
		  #ifdef EMBRAC
			rc=Application->MessageBox(L"Необходимо задать ограничения на размеры профиля",
									   L" ", MB_OK | MB_ICONERROR);
		  #else
			rc=Application->MessageBox("Необходимо задать ограничения на размеры профиля",
									   " ", MB_OK | MB_ICONERROR);
		  #endif
		  return;
		 }
	  }
	  // Проверка соответствия РСУ заданному типу конструктивного элемента
	  //if (!CheckRSU())
	  //	return;
	  flag_conditions = false;

	  //------------------------------------------------------------------------------
	  //  Выполнить проверку профиля или группы профилей
	  rc = Executive(index, n_thick, &mass_prof, &num_prof, Sender);

	  Label_add_conditions->Caption = "";

	  AnsiString Msteel_orig = CheckExecute.Msteel_prof;
	  int ind = Msteel_orig.Pos("BG");
	  if (ind>0)
		Msteel_orig.Delete(ind, 2);
	  ind = Msteel_orig.Pos("G");
	  if (ind>0)
		Msteel_orig.Delete(ind, 1);
	  ind = Msteel_orig.Pos("R");
	  if (ind>0)
		Msteel_orig.Delete(ind, 1);


	  if (index>=0 && rc > 1) {   // Анализ одного профиля
		switch (rc) {
		case steel_T_UPPER:
		  if (Data_select.form_profil==DVUTAVR_STAND || Data_select.form_profil==TRUBA ||
			  Data_select.form_profil==PERFOR_BEAM) {
			  Label_add_conditions->Caption="Толщина профиля "+FloatToStrF(CheckExecute.thick_prof, ffFixed, 15, 1)+" мм меньше нижней границы "+
			  FloatToStrF(CheckExecute.thick_range_material[0], ffFixed, 15, 0)+" мм для стали "+ Msteel_orig;
			  PageControl_Data->ActivePage = TabSheet_sect_prof;
		  }
		  else {
			if (Data_select.form_profil==COMPOSED_BEAM) {
			  Label_mass_c->Caption="Толщина профиля "+FloatToStrF(CheckExecute.thick_prof, ffFixed, 15, 1)+" мм меньше нижней границы "+
			  FloatToStrF(CheckExecute.thick_range_material[0], ffFixed, 15, 0)+" мм для стали "+ Msteel_orig;
			  PageControl_Data->ActivePage = TabSheet_sect_comp;

			}
			else {
			  PageControl_Data->ActivePage = TabSheet_Weld;
			  Label_mass_weld->Caption="Толщина профиля "+FloatToStrF(CheckExecute.thick_prof, ffFixed, 15, 1)+" мм меньше нижней границы "+
			  FloatToStrF(CheckExecute.thick_range_material[0], ffFixed, 15, 0)+" мм для стали "+ Msteel_orig;
			}
		  }
		  Show_prof(num_prof, Sender);
		break;
		case steel_T_LESS:
		  if (Data_select.form_profil==DVUTAVR_STAND || Data_select.form_profil==TRUBA ||
			  Data_select.form_profil==PERFOR_BEAM) {
			  Label_add_conditions->Caption="Толщина профиля "+FloatToStrF(CheckExecute.thick_prof, ffFixed, 15, 1)+" мм превышает верхнюю границу "+
			  FloatToStrF(CheckExecute.thick_range_material[1], ffFixed, 15, 0)+" мм для стали "+ Msteel_orig;
			  PageControl_Data->ActivePage = TabSheet_sect_prof;    //common_sect->dvutavr
		  }
		  else {
			if (Data_select.form_profil==COMPOSED_BEAM) {
			  Label_mass_c->Caption="Толщина профиля "+FloatToStrF(CheckExecute.thick_prof, ffFixed, 15, 1)+" мм превышает верхнюю границу "+
			  FloatToStrF(CheckExecute.thick_range_material[1], ffFixed, 15, 0)+" мм для стали "+ Msteel_orig;
			  PageControl_Data->ActivePage = TabSheet_sect_comp;

			}
			else {
			  Label_mass_weld->Caption="Толщина профиля "+FloatToStrF(CheckExecute.thick_prof, ffFixed, 15, 1)+" мм превышает верхнюю границу "+
			  FloatToStrF(CheckExecute.thick_range_material[1], ffFixed, 15, 0)+" мм для стали "+ Msteel_orig;
			  PageControl_Data->ActivePage = TabSheet_Weld;
			}
		  }
		  Show_prof(num_prof, Sender);
		break;
		case steel_NO_STEEL:
		  if (strcmp(MaterProp[Material_Number].title,"")==0) {
			i=Application->MessageBox(L"Не задана марка стали", L"",
								  MB_OK | MB_ICONERROR);
		  }
		  else {
			i=Application->MessageBox((L"Задана некорректная марка стали " + (AnsiString)(MaterProp[Material_Number].title)).c_str(), L"",
								  MB_OK | MB_ICONERROR);
		  }
		break;
		}
	  }

	  else  {
		switch (rc) {
		case steel_T_UPPER:
		case steel_T_LESS:
		case 1:
		 rc=Application->MessageBox(L"При заданных условиях не все условия прочности и устойчивости удовлетворяются",
									L" ", MB_OK | MB_ICONERROR);
		case 0:
		  switch (Data_select.form_profil) {
		   case DVUTAVR_STAND:     // Прокатные сечения
		   case TRUBA:
		  // Показать сечение и вывести коэффициенты использования
			Show_prof(num_prof, Sender);
			TabSheet_sect_prof->TabVisible = true;
			PageControl_Data->ActivePage = TabSheet_sect_prof;    //common_sect->dvutavr
		   break;
		   case PERFOR_BEAM:
		  // Показать сечение и вывести коэффициенты использования
			Show_prof(num_prof, Sender);

			Show_prof_perfor(num_prof, Sender, Data_select.perfor_attit, Data_select.perfor_alfa, true);
			TabSheet_sect_prof->TabVisible = true;
			PageControl_Data->ActivePage = TabSheet_sect_prof;    //common_sect->dvutavr
		   break;
		   case DVUTAVR_WELD:   // Сварной двутавр
			Show_prof(num_prof, Sender);
		   break;
		   case COMPOSED_BEAM:     // Прокатные сечения
		  // Показать сечение и вывести коэффициенты использования

			Edit_thick_comp->Text = FloatToStr(Data_select.plate_thick);
			Edit_width_comp->Text = FloatToStr(Data_select.plate_width);
			Edit_kf_comp->Text = FloatToStr(Data_select.kf_comp);
			SectSelectCom_ParamFrame2Button_ApplyClick(Sender);

			Show_prof(num_prof, Sender);
			TabSheet_sect_comp->TabVisible = true;
			PageControl_Data->ActivePage = TabSheet_sect_comp;    //common_sect->dvutavr
		   break;
		  }
	  	  BitBtnCheck->Enabled = true;
		  TabSheet_KI->TabVisible = true;
		  Sect_Param_WeldFrame1->Visible = true;

		  Label_mass_c->Caption = "Масса профиля "+FloatToStr(Round(mass_prof, 1));
		  Label_mass->Caption = "Масса профиля "+FloatToStr(Round(mass_prof, 1));
		  Label_mass_weld->Caption = "Масса профиля "+FloatToStr(Round(mass_prof, 1));

		  if (Flag_fall_mater)
			StrFall = "Возможно, из-за ограничения на толщиу проката для выбранного материала.";
		  else
			StrFall ="";

		  Label_edge->Caption =" ";
		  Label_edge_step->Caption =" ";
          Label_edge_param->Caption =" ";


		  if (flag_conditions && rc == 0) {
			  if (Data_select.flag_add_limit) {
				Label_conditions->Caption = "При заданных ограничениях на размеры сечения условия прочности и устойчивости удовлетворяются";
				Label_conditions_c->Caption = "При заданных ограничениях на размеры сечения условия прочности и устойчивости удовлетворяются";
			  }
			  else {
				Label_conditions->Caption = "Условия прочности и устойчивости удовлетворяются";
				Label_conditions_c->Caption = "Условия прочности и устойчивости удовлетворяются";
			  }
			  //if (Data_select.index_edge==1 && CheckExecute.step_edge < 1e6) {
			  //	if (CheckExecute.step_edge > 10)
			  //	  Label_edge->Caption = "Шаг ребер не более " + FloatToStr(CheckExecute.step_edge) + " мм.";
			  //	else
			  //	  Label_edge->Caption = "Ребра не требуются";
			  //}
			  //	  Label_edge->Caption = "Ребра не требуются";
			  if (Data_select.index_1_or_2>=0) {
				  AnsiString Type_edge;
				  double step_max = MIN(CheckExecute.edge_param[0][0], CheckExecute.edge_param[1][0]);
				  step_max = MIN(step_max, CheckExecute.edge_param[2][0]);
				  double br = MAX(CheckExecute.edge_param[0][1], CheckExecute.edge_param[1][1]);
				  br = MAX(br, CheckExecute.edge_param[2][1]);
				  br = Round_row(br, 0);
				  double tr = MAX(CheckExecute.edge_param[0][2], CheckExecute.edge_param[1][2]);
				  tr = MAX(tr, CheckExecute.edge_param[2][2]);
				  tr = Round_row(tr, RadioGroup_sort->ItemIndex);
				  if (RadioGroup_1_or_2->ItemIndex==0)
					Type_edge = "Односторонние ребра с шагом ";
				  else
					Type_edge = "Парные симметричные ребра с шагом ";

				  if (step_max < 1e6) {
					Label_edge_step->Caption = Type_edge + FloatToStr(step_max) + " мм";
					Label_edge_param->Caption = "Ширина выступающей части "+FloatToStr(br)+" мм; " +
												"толщина "+FloatToStr(tr)+" мм."  ;
				  }
				  else {
					Label_edge_step->Caption = "Ребра не требуются";
				  }
			  }
		  }

			else {
			  if (index==-1) {
				if (Data_select.flag_add_limit) {
					Label_conditions->Caption = "При заданных ограничениях на размеры сечения условия прочности и устойчивости не удовлетворяются. " + StrFall;
					Label_conditions_c->Caption = "При заданных ограничениях на размеры сечения условия прочности и устойчивости не удовлетворяются. " + StrFall;
				}
				else  {
			// Показаны КИ для последего профиля в сортаменте";
				  Label_conditions->Caption = "Условия прочности и устойчивости не удовлетворяются. " + StrFall;
				  Label_conditions_c->Caption = "Условия прочности и устойчивости не удовлетворяются. " + StrFall;
				}


				Label_add_conditions->Caption = "Показаны КИ для последего проверенного профиля сортамента. ";
				Label_add_conditions_c->Caption = "Показаны КИ для последего проверенного профиля сортамента. ";

			  }
			 else {
			   Label_conditions->Caption = "Условия прочности и устойчивости не удовлетворяются";
			   Label_conditions_c->Caption = "Условия прочности и устойчивости не удовлетворяются";
			 }
			}
		 break;
		 case 101:
			#ifdef EMBRAC
			 rc=Application->MessageBox(L"Подбор профиля не выполняется. Не задан шаг раскрепления поясов", L" ", MB_OK | MB_ICONERROR);
		   #else
			 rc=Application->MessageBox("Подбор профиля не выполняется. Не задан шаг раскрепления поясов", " ", MB_OK | MB_ICONERROR);
		   #endif
			PageControl_Data->ActivePage = TabSheet_Part;
		break;
		defaults:
		 #ifdef EMBRAC
		 rc=Application->MessageBox(L"Executive:Программная ошибка", L" ", MB_OK | MB_ICONERROR);
		 #else
		 rc=Application->MessageBox("Executive:Программная ошибка", " ", MB_OK | MB_ICONERROR);
		 #endif
		}
	 }
	flag_checking = true;
	return;

}
//--------------------------------------------------------------------
// Проверка соответствия РСУ заданному типу конструктивного элемента
// Показать результаты подбора
void __fastcall TSelectProfilSectForm::Show_prof(int num_prof, TObject *Sender)
{
	  int k, rc;
	  int i, j;

	  N_profil = num_prof;

	  TabSheet_Weld->TabVisible = false;
	  TabSheet_sect_prof->TabVisible = false;
	  TabSheet_sect_comp->TabVisible = false;
	  SectSelectCom_ParamFrame1->TabSheet_StandTube->TabVisible = false;
	  SectSelectCom_ParamFrame1->TabSheet_Standart->TabVisible = false;
	  SectSelectCom_ParamFrame1->TabSheet_TavrStandart->TabVisible = false;
	  switch (Data_select.form_profil) {
	  case DVUTAVR_STAND:
	  case PERFOR_BEAM:
		TabSheet_sect_prof->TabVisible = true;
		PageControl_Data->ActivePage = TabSheet_sect_prof;
		Type_sect = DVUTAVR;
		// Заполнить структуру параметров сечения двутавра по его номеру
		rc = StandartProfil.SetParamProfil(&(com_sect.dvutavr), num_prof);
		if (rc>0) return;
		SectSelectCom_ParamFrame1->TabSheet_Standart->TabVisible = true;
		SectSelectCom_ParamFrame1->TabSheet_StandTube->TabVisible = false;

		common_sect = &(com_sect);
		SectSelectCom_ParamFrame1->Check_Original();  // Установка поля рисования сечения
		//-------------------------------------------------
		// Отображение стандартного сечения
		//-------------------------------------------------
		SectSelectCom_ParamFrame1->index_GOST_or_TU = Data_select.index_GOST_or_TU;
		SectSelectCom_ParamFrame1->Write_sect(Sender);
	  break;
	  case TRUBA:
		TabSheet_sect_prof->TabVisible = true;
		PageControl_Data->ActivePage = TabSheet_sect_prof;

		SectSelectCom_ParamFrame1->TabSheet_StandTube->TabVisible = false;
		SectSelectCom_ParamFrame1->TabSheet_CYL->TabVisible = false;
		SectSelectCom_ParamFrame1->TabSheet_Standart->TabVisible = false;
		switch (Data_select.type_profil) {
		case typeSQUARE:
		  SectSelectCom_ParamFrame1->TabSheet_StandTube->TabVisible = true;
		  Type_sect = SQUARE_TUBE;
		break;
		case typeRECT:
		  SectSelectCom_ParamFrame1->TabSheet_StandTube->TabVisible = true;
		  Type_sect = RECT_TUBE;
		break;
		case typeCIRC:
		  SectSelectCom_ParamFrame1->TabSheet_CYL->TabVisible = true;
		  Type_sect = CIRCULAR_TUBE;
		break;
		}
		rc = StandartProfil.SetParamProfil_Tube(&(com_sect), Data_select.type_profil, num_prof, 0);

		common_sect = &(com_sect);
		SectSelectCom_ParamFrame1->Check_Original();  // Установка поля рисования сечения
		SectSelectCom_ParamFrame1->Write_sect(Sender);
	  break;
	  case DVUTAVR_WELD:
		Type_sect = DVUTAVR;
		TabSheet_Weld->TabVisible = true;
		PageControl_Data->ActivePage = TabSheet_Weld;

		Sect_Param_WeldFrame1->kf_dvut = Data_select.kf_comp;

		Sect_Param_WeldFrame1->Write_sect(Sender);  // Установка поля рисования сечения
	  break;
	  case COMPOSED_BEAM:
		  TabSheet_sect_comp->TabVisible = true;
		  PageControl_Data->ActivePage = TabSheet_sect_comp;
		  SectSelectCom_ParamFrame2->index_composed = Data_select.index_composed;
		  switch (Data_select.index_composed) {
		  case TAVR_PLATE_DOWN:
		  case TAVR_PLATE_UP:
			 Type_sect = TAVR;
		// Заполнить структуру параметров сечения двутавра по его номеру
			rc = StandartProfil.SetParamProfil(&(com_sect.dvutavr), num_prof);
			if (rc>0) return;
			SectSelectCom_ParamFrame2->TabSheet_TavrStandart->TabVisible = true;

			common_sect = &(com_sect);
			SectSelectCom_ParamFrame2->Check_Original();  // Установка поля рисования сечения
		//-------------------------------------------------
		// Отображение стандартного сечения тавр
		//-------------------------------------------------
			SectSelectCom_ParamFrame2->index_TAVR_GOST_or_TU = Data_select.index_TAVR_GOST_or_TU;
			SectSelectCom_ParamFrame2->Write_sect(Sender);
		  break;
		  case DVUTAVR_PLATE_DOWN:
			Type_sect = DVUTAVR;
		// Заполнить структуру параметров сечения двутавра по его номеру
			rc = StandartProfil.SetParamProfil(&(com_sect.dvutavr), num_prof);
			if (rc>0) return;
			SectSelectCom_ParamFrame2->TabSheet_Standart->TabVisible = true;
			SectSelectCom_ParamFrame2->TabSheet_StandTube->TabVisible = false;

			common_sect = &(com_sect);
			SectSelectCom_ParamFrame2->Check_Original();  // Установка поля рисования сечения
		//-------------------------------------------------
		// Отображение стандартного сечения
		//-------------------------------------------------
			SectSelectCom_ParamFrame2->index_GOST_or_TU = Data_select.index_GOST_or_TU;
			SectSelectCom_ParamFrame2->Write_sect(Sender);
		  break;
		  }
		break;

	  }


	  TRichEdit *RichEdit_KI;
	  TabSheet_KI_CT->TabVisible = false;
	  TabSheet_KI_CC->TabVisible = false;
	  TabSheet_KI_CB->TabVisible = false;
	  TabSheet_KI_B->TabVisible = false;
	  TabSheet_KI_TB->TabVisible = false;

	  flag_conditions = true;
	  for (j=0; j<NUMBER_CHECK; j++) {
		if (!flag_check[j])  // означает, что данный тип проверки не выполнялся
		   continue;
		switch (j) {
		case CENTR_TENSION:
		  TabSheet_KI_CT->TabVisible = true;
		  RichEdit_KI = RichEdit_KI_CT;
		  PageControl_KI->ActivePage = TabSheet_KI_CT;
		break;
		case CENTR_COMPRESSION:
		  TabSheet_KI_CC->TabVisible = true;
		  RichEdit_KI = RichEdit_KI_CC;
		  PageControl_KI->ActivePage = TabSheet_KI_CC;
		break;
		case COMPRESSION_BENDING:
		  TabSheet_KI_CB->TabVisible = true;
		  RichEdit_KI = RichEdit_KI_CB;
		  PageControl_KI->ActivePage = TabSheet_KI_CB;
		break;
		case BENDING:
		  TabSheet_KI_B->TabVisible = true;
		  RichEdit_KI = RichEdit_KI_B;
		  PageControl_KI->ActivePage = TabSheet_KI_B;
		break;
		case TENSION_BENDING:
		  TabSheet_KI_TB->TabVisible = true;
		  RichEdit_KI = RichEdit_KI_TB;
		  PageControl_KI->ActivePage = TabSheet_KI_TB;
		break;
		}
		RichEdit_KI->Clear();
		for (i=0, k=0; i<Data_select.N_check[j]; i++) {
		  if (Round(Krit[j][i], 2) > 1.0) {
			RichEdit_KI->SelAttributes->Color=clRed;
			flag_conditions = false;
		  }
		  else
			RichEdit_KI->SelAttributes->Color=clBlack;
		  if (Num_prov[j][i]==1) {
			k++;
			if (Krit[j][i] >=0)
			  RichEdit_KI->Lines->Add(" "+FloatToStr(Round(Krit[j][i], 2)));
			else
			  RichEdit_KI->Lines->Add("  -");
		  }
		}
	  }


}
//--------------------------------------------------------------------
// Показать проекции перфорированного профиля
void __fastcall TSelectProfilSectForm::Show_prof_perfor(int num_prof, TObject *Sender, double perfor_attit, double perfor_alfa, bool flag_draw_size)
{
	  int k, rc;
	  int i, j;
	if (Data_select.form_profil!=PERFOR_BEAM)
	  return;

	N_profil = num_prof;

	// Заполнить структуру параметров сечения двутавра по его номеру
	rc = StandartProfil.SetParamProfil(&(com_sect.dvutavr), num_prof);
	if (rc>0) return;
	double h0 = com_sect.dvutavr.h + com_sect.dvutavr.h1 + com_sect.dvutavr.h2;
	double k_att = perfor_attit/3;
	double perfor_h = Round(k_att*h0, 0) - 1;
	double perfor_b = Round(k_att*h0/tan(perfor_alfa/RADIAN), 0);
	double perfor_a = Round(k_att*h0/sin(perfor_alfa/RADIAN), 0) + 2;
	double perfor_h1 = perfor_h;
	double perfor_h2 = Round(perfor_attit*h0 - 2*perfor_h, 0);
	double perfor_s = 2*(perfor_a + perfor_b);
	double perfor_c = MAX(250, perfor_a + perfor_b);
		// Диаметр отверстий: внешний пояс, внутренний пояс, стенка внешняя, стенка внутренняя
	float scale = draw_profil_perfor_scale(Image_perfor, Image_Balka, &(com_sect.dvutavr), perfor_h1, perfor_s, perfor_c);
	// Профиль двутавра в проекции XY
	draw_dvutavr_perfor(Image_perfor, &(com_sect.dvutavr), perfor_h1, scale, flag_draw_size);
	// Профиль двутавра в проекции YZ (отображаются перфорации)
	draw_profil_perfor(Image_Balka, &(com_sect.dvutavr), perfor_h1, perfor_a, perfor_b,
					   perfor_s, perfor_c, perfor_alfa, scale, flag_draw_size);
}
//---------------------------------------------------------------------------
//----------------------------------------------------------------------------
// Двутавр прокатной
void __fastcall TSelectProfilSectForm::RadioButton_DvutavrClick(TObject *Sender)
{
	if (RadioButton_Dvutavr->Checked) {
	  SaveTemp(Sender);

	  //CheckBoxAddLimit->Enabled = true;
	  Type_sect = DVUTAVR;

	  BitBtnExec->Enabled = true;
	  Label_step_comp->Visible = true;
	  Edit_step_comp->Visible = true;
	  Label_step_prim->Visible = true;
	  TabSheet_Weld->TabVisible = false;
	  TabSheetPerfor->TabVisible = false;
	  TabSheet_KI->TabVisible = false;
	  TabSheet_sect_comp->TabVisible = true;
	  TabSheet_sect_prof->TabVisible = true;
	  CheckBoxAddLimit->Visible = true;
	  CheckBoxAddLimit->Checked = false;
	  CheckBox_edge->Enabled = true;
	  CheckBox_edge_choose->Visible = true;
	  RadioGroup_1_or_2->Visible = false;
	  RadioGroup_Loads->Visible = true;
	  SpeedButton_WeldParam->Visible = false;

	  RadioButton_Tube->Checked = false;
	  RadioButton_Weld->Checked = false;
	  PageControl_Dvutavr->Visible = true;
	  ComboBox_Tube->Visible = false;
	  ComboBox_ComposedBeam->Visible = false;
	  RadioButton_ComposedBeam->Checked = false;
	  Data_select.form_profil = DVUTAVR_STAND;
	  Label_add_conditions->Caption = " ";
	  //Define_Material_ARSSForm->ComboBox_gost->ItemIndex = 1;
	  //Define_Material_ARSSForm->ComboBox_gostChange(Sender);
	  // Установить список материалов, соответствующих фасонному прокату,
	  Define_Material_ARSSForm->Set_Material_name(DVUTAVR_STAND, Data_select.index_GOST, Data_select.title_material);
	  Panel_mater->Caption = Define_Material_ARSSForm->ComboBox_steel->Text;

	  CheckBox_same_material->Visible = false;
	  Data_select.index_same_material = 0;
	  CheckBox_same_material->Checked = false;
	  CheckBox_same_materialClick(Sender);

	  ComboBox_TypeElemChange(Sender);
	  Config_RSU(DVUTAVR_STAND);
	  flag_change_rsu = false;

	  GroupBox_bend->Visible = true;

	  // Нарисовать профиль и оси координат прокатного двутавра
	  N_profil = SectSelectCom_ParamFrame1->ComboBox_profil->ItemIndex;

	  Show_prof(0, Sender);

	  Draw_prof_ax(N_profil);
	  modify_project = true;

	  RadioGroup_Loads_Fill(3);
	}
}
//--------------------------------------------------------------------------------
// Двутавр сварной
void __fastcall TSelectProfilSectForm::RadioButton_WeldClick(TObject *Sender)
{
	if (RadioButton_Weld->Checked) {
      SaveTemp(Sender);

	  Type_sect = DVUTAVR;

	  BitBtnExec->Enabled = true;
	  CheckBoxAddLimit->Enabled = true;
	  Label_step_comp->Visible = true;
	  Edit_step_comp->Visible = true;
	  Label_step_prim->Visible = true;
	  TabSheet_sect_comp->TabVisible = false;
	  TabSheet_sect_prof->TabVisible = false;
	  TabSheet_KI->TabVisible = false;
	  TabSheet_Weld->TabVisible = true;
	  TabSheetPerfor->TabVisible = false;
	  //GroupBox_AddLimit->Enabled = false;
	  Label_width->Enabled = false;
	  Edit_width->Enabled = false;
	  Label_height->Enabled = false;
	  Edit_height->Enabled = false;
	  flag_checking = false;
	  CheckBox_edge_choose->Visible = false;
	  RadioGroup_1_or_2->Visible = false;
	  RadioGroup_Loads->Visible =true;
	  RadioGroup_Loads->ItemIndex = 0;
      SpeedButton_WeldParam->Visible = true;

	  RadioButton_Tube->Checked = false;
	  RadioButton_Dvutavr->Checked = false;
	  PageControl_Dvutavr->Visible = false;
	  ComboBox_Tube->Visible = false;
	  ComboBox_ComposedBeam->Visible = false;
	  RadioButton_ComposedBeam->Checked = false;

	  Data_select.form_profil = DVUTAVR_WELD;

	  // Установить список материалов, соответствующих фасонному прокату,
	  Define_Material_ARSSForm->Set_Material_name(Data_select.form_profil, Data_select.index_GOST, Data_select.title_material);
	  Panel_mater->Caption = Define_Material_ARSSForm->ComboBox_steel->Text;
	  //CheckBox_same_material->Visible = true;
	  CheckBox_same_material->Visible = false;
	  //CheckBox_same_material->Caption = "Материал полок и стенки различный";
	  //CheckBox_same_material->Checked = Data_select.index_same_material;
	  CheckBox_same_material->Checked = 0;
	  CheckBox_same_material->Checked = false;
	  // Здесь устанавливается материал
	  CheckBox_same_materialClick(Sender);

	  ComboBox_TypeElemChange(Sender);
	  Config_RSU(DVUTAVR_WELD);
	  GroupBox_bend->Visible = true;
	  flag_change_rsu = false;

	  Type_sect = DVUTAVR;
	  // Нарисовать профиль и оси координат сварного двутавра
	  Draw_prof_ax(0);
	  modify_project = true;
	  RadioGroup_Loads_Fill(3);

	}

}
//---------------------------------------------------------------------------
// Трубы
void __fastcall TSelectProfilSectForm::RadioButton_TubeClick(TObject *Sender)
{
	if (RadioButton_Tube->Checked) {
	  SaveTemp(Sender);

	  BitBtnExec->Enabled = true;
	  CheckBoxAddLimit->Checked = false;
	  CheckBoxAddLimit->Enabled = false;
	  CheckBoxAddLimit->Visible = true;
	  Label_step_comp->Visible = false;
	  Edit_step_comp->Visible = false;
	  Label_step_prim->Visible = false;
	  TabSheet_sect_comp->TabVisible = false;
	  TabSheet_sect_prof->TabVisible = true;
	  TabSheet_Weld->TabVisible = false;
	  TabSheetPerfor->TabVisible = false;
	  CheckBox_edge->Enabled = true;
	  CheckBox_edge_choose->Visible = false;
	  RadioGroup_1_or_2->Visible = false;
	  RadioGroup_Loads->Visible = true;
	  ComboBox_ComposedBeam->Visible = false;
	  RadioButton_ComposedBeam->Checked = false;
	  SpeedButton_WeldParam->Visible = false;

	  modify_project = true;

	  if (flag_message) {
		if (Data_select.N_plane > 0) {
		  #ifdef EMBRAC
		  //int rc = Application->MessageBox(L"При выборе типа профиля Труба будут обнулены изгибающие моменты в РСУ. Продолжить? ",
		  //L" ", MB_YESNO | MB_ICONQUESTION);
		  #else
		  //int rc = Application->MessageBox("При выборе типа профиля Труба будут обнулены изгибающие моменты в РСУ. Продолжить? ",
		  //" ", MB_YESNO | MB_ICONQUESTION);
		  #endif
		  //if (rc==IDNO) {
		  //	RadioButton_Dvutavr->Checked = true;
		  //	return;
		  //}

		}
	  }
	  RadioButton_Dvutavr->Checked = false;
	  RadioButton_Weld->Checked = false;
	  PageControl_Dvutavr->Visible = false;
	  ComboBox_Tube->Visible = true;
	  Data_select.form_profil = TRUBA;
	  // Конфигурация РСУ - обнуление изгибающих моментов
	  Config_RSU(TRUBA);
	  flag_change_rsu = false;

	  switch (ComboBox_Tube->ItemIndex) {
			case 0:
			  Data_select.type_profil = typeSQUARE;
			  type_sect_tube = SQUARE_TUBE;
			  RadioButton_Tube->Caption = "Профили гнутые замкнутые ГОСТ 30245";
			break;
			case 1:
			  Data_select.type_profil = typeRECT;
			  type_sect_tube = RECT_TUBE;
			  RadioButton_Tube->Caption = "Профили гнутые замкнутые ГОСТ 30245";
			break;
			case 2:
			  Data_select.type_profil = typeCIRC;
			  type_sect_tube = CIRCULAR_TUBE;
			  RadioButton_Tube->Caption = "Трубы сварные ГОСТ Р 58064";
			break;
	  }
	  //Define_Material_ARSSForm->ComboBox_gost->ItemIndex = 0;
	  //Define_Material_ARSSForm->ComboBox_gostChange(Sender);

	  // Установить список материалов, соответствующих фасонному прокату,
	  Define_Material_ARSSForm->Set_Material_name(Data_select.form_profil, Data_select.index_GOST, Data_select.title_material);
	  Panel_mater->Caption = Define_Material_ARSSForm->ComboBox_steel->Text;
	  ComboBox_TypeElemChange(Sender);
	  CheckBox_same_material->Visible = false;
	  Data_select.index_same_material = 0;
	  CheckBox_same_material->Checked = false;
	  CheckBox_same_materialClick(Sender);

	  Data_select.form_profil = TRUBA;   // Трубы

	  Show_prof(0, Sender);
	  // Нарисовать профиль и оси координат трубы
	  Draw_prof_ax(0);
	  RadioGroup_Loads_Fill(3);

	}

}
//---------------------------------------------------------------------------
void __fastcall TSelectProfilSectForm::ComboBox_TypeElemChange(TObject *Sender)
{
	int i, k;
	// Центрально-растянутые
	int Num_prov_centr_tension[N_CENTR_TENSION_U] = NUM_PROV_CENTR_TENSION;
	int Num_prov_centr_tension_tube[N_CENTR_TENSION_TUBE_U] = NUM_PROV_CENTR_TENSION_TUBE;
	int Num_prov_centr_tension_circ[N_CENTR_TENSION_TUBE_U] = NUM_PROV_CENTR_TENSION_CIRC;
	// Растянуто-изгибвемые
	int Num_prov_tension_bending[N_TENSION_BENDING_U] = NUM_PROV_TENSION_BENDING;
	int Num_prov_tension_bending_Tube[N_TENSION_BENDING_TUBE_U] = NUM_PROV_TENSION_BENDING_TUBE;
	int Num_prov_tension_bending_Circ[N_TENSION_BENDING_TUBE_U] = NUM_PROV_TENSION_BENDING_CIRC;
	// Центрально-сжатые
	int Num_prov_centr_compress[N_CENTR_COMPRESSION_U] = NUM_PROV_CENTR_COMPRESS;
	int Num_prov_centr_compress_tube[N_CENTR_COMPRESSION_TUBE_U] = NUM_PROV_CENTR_COMPRESS_TUBE;
	int Num_prov_centr_compress_circ[N_CENTR_COMPRESSION_TUBE_U] = NUM_PROV_CENTR_COMPRESS_CIRC;
	// Сжато-изгибаемые
	int Num_prov_compress_bending[N_COMPRESSION_BENDING_U] = NUM_PROV_COMPRESS_BENDING;
	int Num_prov_compress_bending_tube[N_COMPRESSION_BENDING_TUBE_U] = NUM_PROV_COMPRESS_BENDING_TUBE;
	int Num_prov_compress_bending_circ[N_COMPRESSION_BENDING_TUBE_U] = NUM_PROV_COMPRESS_BENDING_CIRC;
	// Изгибаемые
	int Num_prov_bending[N_BENDING_U] = NUM_PROV_BENDING;
	int Num_prov_bending_weld[N_BENDING_U] = NUM_PROV_BENDING_WELD;
	int Num_prov_bending_perf[N_BENDING_U] = NUM_PROV_BENDING_PERF;
	int Num_prov_bending_Tube[N_BENDING_TUBE_U] = NUM_PROV_BENDING_TUBE;
	int Num_prov_bending_Circ[N_BENDING_TUBE_U] = NUM_PROV_BENDING_CIRC;
	// Проверки сварных швов
	int Num_prov_Weld_Dvut[NLIST_WELD_DVUT] = NUM_PROV_WELD_DVUT;
	int Num_prov_Weld_Tavr_Plit[NLIST_WELD_TAVR_PLIT] = NUM_PROV_WELD_TAVR_PLIT;
	int Num_prov_Weld_Dvut_Plit[NLIST_WELD_DVUT_PLIT] = NUM_PROV_WELD_DVUT_PLIT;

	//---------------------------------------------------------------------------
	// Формирование таблиц и видов проверок

	  ListBox_KI_CT->Clear();
	  ListBox_KI_TB->Clear();
	  ListBox_KI_CC->Clear();
	  ListBox_KI_CB->Clear();
	  ListBox_KI_B->Clear();
	  ListBox_KI_Weld->Clear();

	  switch (Data_select.form_profil) {
	  case DVUTAVR_STAND:
	  case PERFOR_BEAM:
	  case DVUTAVR_WELD:
	  case COMPOSED_BEAM:
		Data_select.N_check[0] = NCentr_Tension;
		for (i=0, k=0; i<NCentr_Tension; i++) {
		  Num_prov[0][i] = Num_prov_centr_tension[i];
		  if (Num_prov[0][i]==1) {
			k++;
			ListBox_KI_CT->Items->Add(IntToStr(k) + ". "+String_Centr_Tension[i]);
		  }
		}
		Data_select.N_check[1] = NCentr_Compression;
		for (i=0, k=0; i<NCentr_Compression; i++) {
		  Num_prov[1][i] = Num_prov_centr_compress[i];
		  if (Num_prov[1][i]==1) {
			k++;
			ListBox_KI_CC->Items->Add(IntToStr(k) + ". "+String_Centr_Compression[i]);
		  }
		}
		Data_select.N_check[2] = NCompression_Bending_Const;
		for (i=0, k=0; i<NCompression_Bending_Const; i++) {
		  Num_prov[2][i] = Num_prov_compress_bending[i];
		  if (Num_prov[2][i]==1) {
			k++;
			ListBox_KI_CB->Items->Add(IntToStr(k) + ". " + String_Compression_Bending_Const[i]);
		  }
		}
		Data_select.N_check[3] = NBending;
		for (i=0, k=0; i<NBending; i++) {
		  switch (Data_select.form_profil) {
		  case DVUTAVR_STAND:
			Num_prov[3][i] = Num_prov_bending[i];
		  break;
		  case PERFOR_BEAM:
			Num_prov[3][i] = Num_prov_bending_perf[i];
		  break;
		  case DVUTAVR_WELD:
			Num_prov[3][i] = Num_prov_bending_weld[i];
		  break;
		  }
		  if (Num_prov[3][i]==1) {
			k++;
			ListBox_KI_B->Items->Add(IntToStr(k) + ". " + String_Bending[i]);
		  }
		}
		Data_select.N_check[4] = NTension_Bending;
		for (i=0, k=0; i<NTension_Bending; i++) {
		  Num_prov[4][i] = Num_prov_tension_bending[i];
		  if (Num_prov[4][i]==1) {
			k++;
			ListBox_KI_TB->Items->Add(IntToStr(k) + ". " + String_Tension_Bending[i]);
		  }
		}
		StringGrid_Length->ColCount = 5;
	  break;
	  case TRUBA:  // Труба
		Data_select.N_check[0] = NCentr_Tension_Tube;
		for (i=0, k=0; i<NCentr_Tension_Tube; i++) {
		  if (Data_select.type_profil==typeCIRC)
			Num_prov[1][i] = Num_prov_centr_tension_circ[i];
		  else
			Num_prov[0][i] = Num_prov_centr_tension_tube[i];

		  if (Num_prov[0][i]==1) {
			k++;
			ListBox_KI_CT->Items->Add(IntToStr(k) + ". "+String_Centr_Tension_Tube[i]);      //ListBox_KI_CC->Visible
		  }
		}
		Data_select.N_check[1] = NCentr_Compression_Tube;
		for (i=0, k=0; i<NCentr_Compression_Tube; i++) {
		  if (Data_select.type_profil==typeCIRC)
			Num_prov[1][i] = Num_prov_centr_compress_circ[i];
		  else
			Num_prov[1][i] = Num_prov_centr_compress_tube[i];

		  if (Num_prov[1][i]==1) {
			k++;
			ListBox_KI_CC->Items->Add(IntToStr(k) + ". "+String_Centr_Compression_Tube[i]);
		  }
		}
		Data_select.N_check[2] = NCompression_Bending_Tube;
		for (i=0, k=0; i<NCompression_Bending_Tube; i++) {
		  if (Data_select.type_profil==typeCIRC)
			Num_prov[2][i] = Num_prov_compress_bending_circ[i];
		  else
			Num_prov[2][i] = Num_prov_compress_bending_tube[i];
		  if (Num_prov[2][i]==1) {
			k++;
			ListBox_KI_CB->Items->Add(IntToStr(k) + ". " + String_Compression_Bending_Tube[i]);
		  }
		}
		Data_select.N_check[3] = NBending_Tube;
		for (i=0, k=0; i<NBending_Tube; i++) {
		  if (Data_select.type_profil==typeCIRC)
			Num_prov[3][i] = Num_prov_bending_Circ[i];
		  else
			Num_prov[3][i] = Num_prov_bending_Tube[i];
		  if (Num_prov[3][i]==1) {
			k++;
			ListBox_KI_B->Items->Add(IntToStr(k) + ". " + String_Bending_Tube[i]);
		  }
		}
		Data_select.N_check[4] = NTension_Bending_Tube;
		for (i=0, k=0; i<NTension_Bending_Tube; i++) {
		  if (Data_select.type_profil==typeCIRC)
			Num_prov[4][i] = Num_prov_tension_bending_Circ[i];
		  else
			Num_prov[4][i] = Num_prov_tension_bending_Tube[i];
		  if (Num_prov[4][i]==1) {
			k++;
			ListBox_KI_TB->Items->Add(IntToStr(k) + ". " + String_Tension_Bending_Tube[i]);
		  }
		}
		StringGrid_Length->ColCount = 4;
	  break;
	  case 100:

		Data_select.N_check[0] = NCentr_Tension;
		for (i=0, k=0; i<NCentr_Tension; i++) {
		  Num_prov[0][i] = Num_prov_centr_tension[i];
		  if (Num_prov[0][i]==1) {
			k++;
			ListBox_KI_CT->Items->Add(IntToStr(k) + ". "+String_Centr_Tension[i]);
		  }
		}
		Data_select.N_check[1] = NCentr_Compression;
		for (i=0, k=0; i<NCentr_Compression; i++) {
		  Num_prov[1][i] = Num_prov_centr_compress[i];
		  if (Num_prov[1][i]==1) {
			k++;
			ListBox_KI_CC->Items->Add(IntToStr(k) + ". "+String_Centr_Compression[i]);
		  }
		}
		Data_select.N_check[2] = NCompression_Bending_Const;
		for (i=0, k=0; i<NCompression_Bending_Const; i++) {
		  Num_prov[2][i] = Num_prov_compress_bending[i];
		  if (Num_prov[2][i]==1) {
			k++;
			ListBox_KI_CB->Items->Add(IntToStr(k) + ". " + String_Compression_Bending_Const[i]);
		  }
		}
		Data_select.N_check[3] = NBending;
		for (i=0, k=0; i<NBending; i++) {
		  Num_prov[3][i] = Num_prov_bending[i];
		  if (Num_prov[3][i]==1) {
			k++;
			ListBox_KI_B->Items->Add(IntToStr(k) + ". " + String_Bending[i]);
		  }
		}
		Data_select.N_check[4] = NTension_Bending;
		for (i=0, k=0; i<NTension_Bending; i++) {
		  Num_prov[4][i] = Num_prov_tension_bending[i];
		  if (Num_prov[4][i]==1) {
			k++;
			ListBox_KI_TB->Items->Add(IntToStr(k) + ". " + String_Tension_Bending[i]);
		  }
		}
		StringGrid_Length->ColCount = 5;
	  break;
	  }
	  //-------------------------------------------------------------
	  // Проверки сварных  швов
	  switch (Data_select.form_profil) {
	  case DVUTAVR_STAND:
	  case PERFOR_BEAM:
		;
	  break;
	  case DVUTAVR_WELD:
		Data_select.N_check_weld = NList_Weld_Dvut;
		for (i=0, k=0; i<NList_Weld_Dvut; i++) {
		  Num_prov_weld[i] = Num_prov_Weld_Dvut[i];
		  if (Num_prov_weld[i]==1) {
			k++;
			ListBox_KI_Weld->Items->Add(IntToStr(k) + ". " + String_Weld_Dvut[i]);
		  }
		}
	  break;
	  case COMPOSED_BEAM:
	   switch (Data_select.index_composed) {
		  case TAVR_PLATE_DOWN:
		  case TAVR_PLATE_UP:
		Data_select.N_check_weld = NList_Weld_Tavr_Plit;
		for (i=0, k=0; i<NList_Weld_Tavr_Plit; i++) {
		  Num_prov_weld[i] = Num_prov_Weld_Tavr_Plit[i];
		  if (Num_prov_weld[i]==1) {
			k++;
			ListBox_KI_Weld->Items->Add(IntToStr(k) + ". " + String_Weld_Tavr_Plit[i]);
		  }
		}
	   break;
	   case DVUTAVR_PLATE_DOWN:
		Data_select.N_check_weld = NList_Weld_Dvut_Plit;
		for (i=0, k=0; i<NList_Weld_Dvut_Plit; i++) {
		  Num_prov_weld[i] = Num_prov_Weld_Dvut_Plit[i];
		  if (Num_prov_weld[i]==1) {
			k++;
			ListBox_KI_Weld->Items->Add(IntToStr(k) + ". " + String_Weld_Dvut_Plit[i]);
		  }
		}
	   break;
	   }
	  break;
	  case TRUBA:  // Труба
		;
	  break;
	  }


	RadioGroup_muClick(Sender);                 //Data_select.index_profil
	//
	NumRow_Len = -1;

	StringGrid_Length->RowCount = Data_select.N_plane + 1;
	 // Конфигурация таблиц длин и нагрузок
	StringGrid_Length->Cells[0][0] = "Элемент";
	StringGrid_Length->Cells[1][0] = "Длина L";
	StringGrid_Length->Cells[2][0] = "lef_XZ";
	StringGrid_Length->Cells[3][0] = "lef_XY";
	if (Data_select.form_profil == DVUTAVR_STAND || Data_select.form_profil == DVUTAVR_WELD || Data_select.form_profil == PERFOR_BEAM)
	  StringGrid_Length->Cells[4][0] = "l_с";
	if (Data_select.N_plane==0 || Data_select.index_loads==1) {
	  BitBtn_LenRep->Enabled = false;
	  BitBtn_LenDel->Enabled = false;
	}
	else {
	  BitBtn_LenRep->Enabled = true;
	  BitBtn_LenDel->Enabled = true;
	}
	// Заполнение заголовков таблицы РСУ
	StringGrid_RSU->ColCount = 7;
	NumRow_RSU = -1;

	StringGrid_RSU->RowCount = 1;
	 // Конфигурация таблиц длин и нагрузок
	StringGrid_RSU->Cells[0][0] = "№";
	StringGrid_RSU->Cells[1][0] = "N, кН";
	StringGrid_RSU->Cells[2][0] = "My, кН*м";
	StringGrid_RSU->Cells[3][0] = "Qz, кН";
	StringGrid_RSU->Cells[4][0] = "Mz, кН*м";
	StringGrid_RSU->Cells[5][0] = "Qy, кН";
	StringGrid_RSU->Cells[6][0] = "qz, кН/м";
	BitBtn_RSUAdd->Enabled = false;
	BitBtn_RSURep->Enabled = false;
	BitBtn_RSUDel->Enabled = false;
	// Выделить строку Lenth - здесь происходит рисование начальной модели
	StringGrid_LengthMySelect(1);
	// Выделить строку RSU
	if (Data_select.N_RSU[0]>0)
	  StringGrid_RSUMySelect(1);
}
//---------------------------------------------------------------------------


void __fastcall TSelectProfilSectForm::BitBtn_Advance_gamma_cClick(
	  TObject *Sender)
{
   Advanced_gamma_cForm->ShowModal();
   if (Advanced_gamma_cForm->Koeff_gamma_c > 0) {
	  ComboBox_gamma_c->Text = FloatToStr(Advanced_gamma_cForm->Koeff_gamma_c);
   }
   modify_project = true;


}
//---------------------------------------------------------------------------

void __fastcall TSelectProfilSectForm::BitBtnMaterialClick(TObject *Sender)
{
	 TabSheet_profil->TabVisible = true;
	 Define_Material_ARSSForm->Set_Material_name(Data_select.form_profil, Data_select.index_GOST, Data_select.title_material);
	 Define_Material_ARSSForm->Caption = "Выбор материала";
	 Define_Material_ARSSForm->ShowModal();
	 Panel_mater->Caption = Define_Material_ARSSForm->ComboBox_steel->Text;
	 modify_project = true;
	 strcpy(Data_select.title_material, MaterProp[Material_Number].title);
	 Data_select.index_GOST = MaterProp[Material_Number].index_GOST;
	 memcpy((char*)&(Data_select.MaterProp_prof), (char*)&(MaterProp[Material_Number]), sizeof(MATER));

	 // Установить метку Госта материала
	 Set_Label_steel();
}
//----------------------------------------------------------------------------
// Установить метку Госта материала
//----------------------------------------------------------------------------
void __fastcall TSelectProfilSectForm::Set_Label_steel() {

	 switch (Data_select.form_profil) {
	 case DVUTAVR_STAND:
	 case PERFOR_BEAM:
	 case COMPOSED_BEAM:
	   switch (Data_select.index_GOST) {
	   case 0: // материал по ГОСТ 27772
		 Label_steel->Caption = steel_STAND_GOST_27772;
		 Prefix ="BG";
	   break;
	   case 1: // материал по ГОСТ Р 57
		 Label_steel->Caption = steel_STAND_GOST_57837;
		 Prefix ="R";
	   break;
	   case 2: // материал по СП
		 Label_steel->Caption = steel_STAND_SP_16;
		 Prefix ="";
	   break;
	   }
	 break;
	 case TRUBA:
	   switch (Data_select.index_GOST) {
	   case 0: // материал по ГОСТ 27772
		 Label_steel->Caption = steel_TRUBA_GOST_27772;
		 Prefix ="G";
	   break;
	   case 1: // материал по СП 16
		 Label_steel->Caption = steel_TRUBA_SP_16;
		 Prefix ="";
	   break;
	   }
	 break;
	 case DVUTAVR_WELD:
	   switch (Data_select.index_GOST) {
	   case 0: // материал по ГОСТ 27772
		 Label_steel->Caption = steel_WELD_GOST_27772;
		 Prefix ="G";
	   break;
	   case 1: // материал по СП 16
		 Label_steel->Caption = steel_WELD_SP_16;
		 Prefix ="";
	   break;
	   }
	 break;

	 }
}
//---------------------------------------------------------------------------
// Установить метку Госта материала стенки или пластины
//----------------------------------------------------------------------------
void __fastcall TSelectProfilSectForm::Set_Label_steel_plate() {

	  switch (Data_select.index_GOST_plate) {
		 case 0: // материал по ГОСТ 27772
		   Label_steel_plate->Caption = steel_WELD_GOST_27772;
		   Prefix_plate ="G";
		 break;
		 case 1: // материал по СП 16
		   Label_steel_plate->Caption = steel_WELD_SP_16;
		   Prefix_plate ="";
		 break;
	  }
}
//-----------------------------------------------------------------------------
void __fastcall TSelectProfilSectForm::ComboBox_n_partChange(
	  TObject *Sender)
{
	 ComboBox_TypeElemChange(Sender);
}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
void __fastcall TSelectProfilSectForm::NOpenClick(TObject *Sender)
{
	  OpenProject(Sender, 0);
}
//---------------------------------------------------------------------------
// Открыть проект
void __fastcall TSelectProfilSectForm::OpenProject(TObject *Sender, int index_open)
{

   FILE * BD_file=NULL;
   bool rc_bool;
   int rc;

   flag_message = false;
   rc = NewProject(Sender);
   if (rc>0)
	  return;

   flag_temp_new = true;   // не записывать временный файл

   switch (index_open) {
   case 0:
	 if(OpenDialog_Model->Execute())
	 {
	   FileDir_Name = OpenDialog_Model->FileName;
	 }
   break;
   case 1:
	 stroka_param[strlen(stroka_param)-1]='\0';
	 FileDir_Name = (AnsiString)(stroka_param+1);
   break;
   case 2:
	 ;
   break;
   }

   if (FileDir_Name!="") {
	 //InfMessage("Открытие проекта " + FileDir_Name);

	  ModelFile = UNTITLED;
	// инициализация данных
	  BD_file = BD_Open(FileDir_Name.c_str(),"r");

	  if (BD_file==NULL) {
		  #ifdef EMBRAC
			rc = Application->MessageBox((L"Попытка открыть несуществующий файл: " + (String)FileDir_Name).c_str(),L" ", MB_OK | MB_ICONERROR);
		  #else
			rc=Application->MessageBox(("Попытка открыть несуществующий файл: " + FileDir_Name).c_str()," ", MB_OK | MB_ICONERROR);
		  #endif
		  InfMessage("Попытка открыть несуществующий файл: "+FileDir_Name);
		  return;
	  }
	  if (MruList->Strings[0] != FileDir_Name) {
		MruList->Insert(0, FileDir_Name);
		if (MruList->Count > MruCount)
		  MruList->Delete(MruCount);
	  }
	  InitTemp(Sender);

   }

   //--------------------------------------------
   // Чтение данных из архива
   if (!OpenSelectProf(BD_file)) {
		 InfMessage("Ошибка при чтении данных из архива");
		  return;
   }
	  ModelName(FileDir_Name.c_str());
	  InfMessage("Открыт проект \"" + ModelFile+"\"");
	  Caption = "Подбор стальных сечений, v4.1 - [" + ModelFile +".pwkS]";

	  //Sect_Param_WeldFrame1->Visible = false;
	  TabSheet_KI->TabVisible = false;
	  TabSheet_sect_comp->TabVisible = false;
	  TabSheet_sect_prof->TabVisible = false;
	  TabSheetPerfor->TabVisible = false;
	  TabSheet_Weld->TabVisible = false;
	  //---------------------------------------------

	  if (Data_beam.Length_beam > 0 ) {
		RadioGroup_Loads_Set(1, Sender);
		// Заполнить поля данных балки
		Fill_field_balka(&Data_beam, &Data_region_beam, Sender);
	  }

	  if (Data_rack.Length_rack > 0 ) {
		RadioGroup_Loads_Set(2, Sender);
		// Заполнить поля данных балки
		Fill_field_rack(&Data_rack, &Data_region_rack, Sender);
	  }

	  // Заполнить поля
	  Fill_field(Sender);              //Data_select.type_profil


	  // Выделить строку Lenth
	  StringGrid_LengthMySelect(1);
	  // Выделить строку RSU
	  if (Data_select.N_RSU[0]>0)
		StringGrid_RSUMySelect(1);


	  PageControl_Data->ActivePage=TabSheet_Common;

	  modify_project = false;
	  flag_change_rsu = false;
	  flag_change_elem = false;
	  flag_checking = false;

	  flag_message = true;
	  flag_temp_new = false;   // зависывать временный файл


   }
//---------------------------------------------------------------------------
// Заполнение полей
void __fastcall TSelectProfilSectForm::Fill_field(TObject *Sender)
{
	 int i, k, m, n;

	 double Gamma_c[5] = {0.9, 0.95, 1.0, 1.05, 1.1};
	 double Gamma_n[4] = {1.2, 1.1, 1.0, 0.8};
	 double Perfor_attit[7] = {1.2, 1.25, 1.3, 1.35, 1.4, 1.45, 1.5};


	 double *jdd = (double*)bsearch((char*)&(Data_select.gamma_n),(char*)Gamma_n, ComboBox_gamma_n->Items->Count, sizeof(double),(fptr)cmpd);
	 if (jdd!=NULL)
	   ComboBox_gamma_n->ItemIndex = (int)(jdd - Gamma_n);
	 else
	   ComboBox_gamma_n->Text = FloatToStr(Data_select.gamma_n);

	  RadioGroup_Schema_constr->ItemIndex = Data_select.index_constr;
	  RadioGroup_Schema_constrClick(Sender);

	  ComboBox_G1_Count->ItemIndex = Data_select.index_G1_count;
	  ComboBox_G1_CountChange(Sender);

	  ComboBox_G1_Load->ItemIndex = Data_select.index_G1_load;

	 jdd = (double*)bsearch((char*)&(Data_select.gamma_c),(char*)Gamma_c, ComboBox_gamma_c->Items->Count, sizeof(double),(fptr)cmpd);
	 if (jdd!=NULL)
	   ComboBox_gamma_c->ItemIndex = (int)(jdd - Gamma_c);
	 else
	   ComboBox_gamma_c->Text = FloatToStr(Data_select.gamma_c);

	 Edit_Krn->Text = FloatToStr(Data_select.Krn);

	 RadioGroup_gruppa->ItemIndex = Data_select.index_group - 1;
	 RadioGroup_class->ItemIndex = Data_select.index_class - 1;
	 for (i=0; i<Data_select.N_plane; i++) {
	   StringGrid_Length->Cells[0][i+1] = i+1;
	   StringGrid_Length->Cells[1][i+1] = FloatToStrFCut(Data_select.Length[i]/1000, 7, 3);
	   StringGrid_Length->Cells[2][i+1] = FloatToStrFCut(Data_select.length_YY[i]/1000, 7, 3);
	   StringGrid_Length->Cells[3][i+1] = FloatToStrFCut(Data_select.length_XX[i]/1000, 7, 3);
	   StringGrid_Length->Cells[4][i+1] = FloatToStrFCut(Data_select.step_comp[i]/1000, 7, 3);
	 }

	 // Установить список материалов, соответствующий прокату (фасон или труба) и материал в списке по имени
	 Define_Material_ARSSForm->Set_Material_name(Data_select.form_profil, Data_select.index_GOST, Data_select.title_material);
	 Panel_mater->Caption = Define_Material_ARSSForm->ComboBox_steel->Text;
	 // Установить метку Госта материала
	 Set_Label_steel();

 	 // Установить список материалов, соответствующий прокату (фасон или труба) и материал в списке по имени
	 Define_Material_ARSSForm->Set_Material_name(DVUTAVR_WELD, Data_select.index_GOST_plate, Data_select.title_material_plate);
	 Panel_mater_plate->Caption = Define_Material_ARSSForm->ComboBox_steel->Text;
	 // Установить метку Госта материала
	 Set_Label_steel_plate();

	 CheckBoxAddLimit->Checked = Data_select.flag_add_limit;
	 CheckBoxAddLimitClick(Sender);

	 Edit_width->Text = Data_select.max_width;
	 Edit_height->Text = Data_select.max_height;
	 LabeledEdit_a->Text = MAX(0, Data_select.Step_edge);

	 TabSheet_sect_comp->TabVisible = false;
	 TabSheet_sect_prof->TabVisible = false;
	 TabSheet_Weld->TabVisible = false;
	 TabSheetPerfor->TabVisible = false;

	 switch (Data_select.form_profil) {
	 case DVUTAVR_STAND:
	   RadioButton_Dvutavr->Checked = true;
	   // Панель на вкладке Общие данные
	   ComboBox_Dvutavr->ItemIndex = Data_select.index_profil;
	   TabSheet_sect_prof->TabVisible = true;
	   SectSelectCom_ParamFrame1->TabSheet_StandTube->TabVisible = false;
	   SectSelectCom_ParamFrame1->TabSheet_CYL->TabVisible = false;
	   SectSelectCom_ParamFrame1->TabSheet_Standart->TabVisible = true;

	 break;
	 case TRUBA:
	   flag_message = false;
	   flag_message = true;
	   TabSheet_sect_prof->TabVisible = true;
	   SectSelectCom_ParamFrame1->TabSheet_StandTube->TabVisible = false;
	   SectSelectCom_ParamFrame1->TabSheet_CYL->TabVisible = false;
	   SectSelectCom_ParamFrame1->TabSheet_Standart->TabVisible = false;
	   switch(Data_select.type_profil) {
	   case typeSQUARE:
		ComboBox_Tube->ItemIndex = 0;
		SectSelectCom_ParamFrame1->TabSheet_StandTube->TabVisible = true;
	   break;
	   case typeRECT:
		ComboBox_Tube->ItemIndex = 1;
		SectSelectCom_ParamFrame1->TabSheet_StandTube->TabVisible = true;
	   break;
	   case typeCIRC:
		ComboBox_Tube->ItemIndex = 2;
		SectSelectCom_ParamFrame1->TabSheet_CYL->TabVisible = true;
	   break;
	   }
	   RadioButton_Tube->Checked = true;
	 break;
	 case DVUTAVR_WELD:
	   flag_message = false;
	   RadioButton_Weld->Checked = true;
	   flag_message = true;
	   TabSheet_Weld->TabVisible = true;
	 break;
	 case PERFOR_BEAM:
	   RadioButtonPerfor->Checked = true;
	   // Панель на вкладке Общие данные
	   ComboBox_Dvutavr->ItemIndex = Data_select.index_profil;
	   Edit_alfa->Text = FloatToStr(Data_select.perfor_alfa);
	   jdd = (double*)bsearch((char*)&(Data_select.perfor_attit),(char*)Perfor_attit, ComboBox_attit->Items->Count, sizeof(double),(fptr)cmpd);
	   if (jdd!=NULL)
		 ComboBox_gamma_c->ItemIndex = (int)(jdd - Gamma_c);
	   else
		 ComboBox_gamma_c->Text = FloatToStr(Data_select.gamma_c);
	   TabSheet_sect_prof->TabVisible = true;
	   TabSheetPerfor->TabVisible = true;
	   SectSelectCom_ParamFrame1->TabSheet_StandTube->TabVisible = false;
	   SectSelectCom_ParamFrame1->TabSheet_CYL->TabVisible = false;
	   SectSelectCom_ParamFrame1->TabSheet_Standart->TabVisible = true;

	 break;
	 case COMPOSED_BEAM:
	   ComboBox_ComposedBeam->ItemIndex = Data_select.index_composed;
	   switch (Data_select.index_composed) {
	   case TAVR_PLATE_DOWN:
	   case TAVR_PLATE_UP:
		  // на невидимой панели
		  ComboBox_Tavr_comp->ItemIndex = Data_select.index_profil;
	   break;
	   case DVUTAVR_PLATE_DOWN:
		  // на невидимой панели
		  ComboBox_Dvutavr_comp->ItemIndex = Data_select.index_profil;
	   break;
	   }
	   Edit_thick_comp->Text = FloatToStr(Data_select.plate_thick);
	   Edit_width_comp->Text = FloatToStr(Data_select.plate_width);
	   Edit_kf_comp->Text = FloatToStr(Data_select.kf_comp);

	   TabSheet_sect_comp->TabVisible = true;
	   SectSelectCom_ParamFrame2->TabSheet_StandTube->TabVisible = false;
	   SectSelectCom_ParamFrame2->TabSheet_CYL->TabVisible = false;
	   //SectSelectCom_ParamFrame2->RadioGroupGOST57837->ItemIndex = Data_select.type_profil;
	   //SectSelectCom_ParamFrame2->ComboBox_profil->ItemIndex = Data_select.index_profil;

	   ComboBox_ComposedBeamChange(Sender);   // Здесь устанавливается панель либо двутавра, либо тавра
	   RadioButton_ComposedBeam->Checked = true;
	 break;
	 }
	 if (Data_select.N_plane==0)
	   Label_plane->Caption = "Длины элементов не заданы";
	 else
	   Label_plane->Caption = "Количество элементов "+IntToStr(Data_select.N_plane);
	 Edit1->Text = FloatToStr(Data_select.Limit_lambda1);
	 Edit2->Text = FloatToStr(Data_select.Limit_lambda2);
	 if (Data_select.Limit_lambda2 == 0) {
		Edit2->Visible = false;
		Label4->Visible = false;
		Label5->Visible = false;
	 }
	 else {
		Edit2->Visible = true;
		Label4->Visible = true;
		Label5->Visible = true;
	 }
	 Edit_Tens->Text = FloatToStr(Data_select.Limit_lambda_plus);
	 //-------------------------------------------------------------
	 // Ограничения на прогиб
	 Edit_strela->Text = FloatToStr(Data_select.Strela);
	 if (Data_select.Delta_lim ==0) {
	   ComboBox_Delta_lim->ItemIndex=0;
	 }
	 else {
	   String Astr = "l/"+FloatToStr(Data_select.Delta_lim);
	   for (i=0; i<ComboBox_Delta_lim->Items->Count; i++) {
		   if (ComboBox_Delta_lim->Items->Strings[i]==Astr) {
			 ComboBox_Delta_lim->ItemIndex=i;
			 break;
		   }
	   }
	 }

	 //Data_beam
	 if (Data_select.index_razrez == 1)
	   CheckBox_razrez->Checked = true;
	 else
	   CheckBox_razrez->Checked = false;

	 if (Data_select.index_edge == 1)
	   CheckBox_edge->Checked = true;
	 else
	   CheckBox_edge->Checked = false;

	 if (Data_select.index_1_or_2 == -1) {
	   CheckBox_edge_choose->Checked = false;
	 }
	 else  {
	   CheckBox_edge_choose->Checked = true;
	   RadioGroup_1_or_2->ItemIndex = Data_select.index_1_or_2;
	 }


	 ComboBox_TypeElemChange(Sender);

	 switch (Data_select.form_profil) {
	 case DVUTAVR_STAND:
	 case PERFOR_BEAM:
	 case DVUTAVR_WELD:
	   ComboBox_DvutavrChange(Sender);
	 break;
	 case TRUBA:
	   ComboBox_TubeChange(Sender);
	 break;
	 case COMPOSED_BEAM:
		ComboBox_ComposedBeamChange(Sender);
	 break;
	 }

	 Data_select.index_Qy = MAX(0, Data_select.index_Qy);   //com_sect
	 Data_select.index_Qy = MIN(2, Data_select.index_Qy);

	 ComboBox_index_Qy->ItemIndex = Data_select.index_Qy;

	 // Заполнение выбранного сечения
	 if (Last_type_sect!=0) {
	   switch (Data_select.form_profil) {
	   case DVUTAVR_STAND:
	   case TRUBA:
		 common_sect = &(Last_com_sect);
		 Type_sect = Last_type_sect;
		 SectSelectCom_ParamFrame1->Check_Original();  // Установка поля рисования сечения
		 //-------------------------------------------------
		 // Отображение стандартного сечения
		 //-------------------------------------------------
		 SectSelectCom_ParamFrame1->Write_sect(Sender);
		 TabSheet_sect_prof->TabVisible = true;
	   break;
	   case DVUTAVR_WELD:
		 //sect_w = &(Last_com_sect.dvutavr);
		 memcpy((char*)&sect_weld, (char*)&(Last_com_sect.dvutavr), sizeof(SECT_DVUTAVR));
		 Type_sect = Last_type_sect;
		 Sect_Param_WeldFrame1->Check_Original();  // Установка поля рисования сечения
		 //-------------------------------------------------
		 // Отображение сварногого сечения
		 //-------------------------------------------------
		 Sect_Param_WeldFrame1->kf_dvut = Data_select.kf_comp;
		 Sect_Param_WeldFrame1->Write_sect(Sender);
		 Sect_Param_WeldFrame1->Visible = true;

	   break;
	   case PERFOR_BEAM:
		 common_sect = &(Last_com_sect);
		 Type_sect = Last_type_sect;
		 SectSelectCom_ParamFrame1->Check_Original();  // Установка поля рисования сечения
		 //-------------------------------------------------
		 // Отображение стандартного сечения
		 //-------------------------------------------------
		 SectSelectCom_ParamFrame1->Write_sect(Sender);
		 TabSheet_sect_prof->TabVisible = true;
	   break;
	   case COMPOSED_BEAM:
		 common_sect = &(Last_com_sect);
		 Type_sect = Last_type_sect;
		 SectSelectCom_ParamFrame2->Check_Original();  // Установка поля рисования сечения
		 //-------------------------------------------------
		 // Отображение стандартного сечения
		 //-------------------------------------------------
		 SectSelectCom_ParamFrame2->Write_sect(Sender);
		 TabSheet_sect_comp->TabVisible = true;

		 SectSelectCom_ParamFrame2Button_ApplyClick(Sender);

	   break;
	   }
	   BitBtnCheck->Enabled = true;
	 }
	 //-----------------------------------------------------------------------
	 // Заполнение данных для подбора сечения сварного двутавра
	  if (Data_select.form_profil==DVUTAVR_WELD) {
		LabeledEdit_lambda0->Text = FloatToStr(Param_chosen_sect.lambda0);
		LabeledEdit_a->Text = FloatToStr(Param_chosen_sect.size_a);
		Edit_d_lambda->Text = FloatToStr(Param_chosen_sect.delta_lambda);
		Edit_d_w->Text = FloatToStr(Param_chosen_sect.delta_w);
		Edit_d_f->Text = FloatToStr(Param_chosen_sect.delta_f);
		Edit_round_h->Text = FloatToStr(Param_chosen_sect.round_h);
		Edit_round_width->Text = FloatToStr(Param_chosen_sect.round_width);
		RadioGroup_sort->ItemIndex = Param_chosen_sect.round_thick;
		Edit_min_tpol->Text = FloatToStr(Param_chosen_sect.min_tpol);
		Edit_max_tpol->Text = FloatToStr(Param_chosen_sect.max_tpol);
		Edit_min_tsten->Text = FloatToStr(Param_chosen_sect.min_tsten);
		Edit_max_tsten->Text = FloatToStr(Param_chosen_sect.max_tsten);
		Edit_min_bpol->Text = FloatToStr(Param_chosen_sect.min_bpol);
		Edit_max_bpol->Text = FloatToStr(Param_chosen_sect.max_bpol);
		Edit_min_hsten->Text = FloatToStr(Param_chosen_sect.min_hsten);
		Edit_max_hsten->Text = FloatToStr(Param_chosen_sect.max_hsten);
		CheckBox_ind_minimax->Checked = Param_chosen_sect.flag_minimax;
	 }


}
//---------------------------------------------------------------------------
// Выделение из имени файла в имени модели
void __fastcall TSelectProfilSectForm::ModelName(char * str0)
{
	  char *ptr1, *ptr2;
	  char i, str[240];

	  if (ModelFile == UNTITLED) {
	   i= 240<strlen(str0) ? 240 : strlen(str0);
	   strcpy(str,str0);
	   ptr1 = strrchr(str,'\\');
	   ptr2 = strrchr(ptr1,'.');
	   if (ptr2!=NULL)
		 *ptr2='\0';
	   if (ptr1==NULL)
		ModelFile = (AnsiString)str;
	   else
		ModelFile = (AnsiString)(ptr1+1);
	  }
}
//--------------------------------------------------------------------
void __fastcall TSelectProfilSectForm::InitTemp(TObject *Sender) {
   int i;
   for (i=num_file_temp_A; i<=num_file_temp_B; i++)
       DeleteTemp(Sender, i);
   num_file_temp_O = -1;
   num_file_temp_A = 0;
   num_file_temp_B = -1;

   NUndo->Enabled=false;
   NRedo->Enabled=false;
   ToolButtonUndo->Enabled=false;
   ToolButtonRedo->Enabled=false;

}
//---------------------------------------------------------------------------
// Уничтожение файла
void __fastcall TSelectProfilSectForm::DeleteTemp(TObject *Sender, int num_file) {

	  AnsiString File;

	  File = "Temp_file_ProfSel" + IntToStr(num_file)+".~wkS";
	  DeleteFile(File);
}
//---------------------------------------------------------------------------
// Сохранение модели во временном файле
//----------------------------------------
void __fastcall TSelectProfilSectForm::SaveTemp(TObject *Sender) {
  AnsiString File;
  int i, rc;
  bool rc_bool;

   return;

   if (flag_temp_new)
     return;
   // Уничтожение всех файлов, если модель была только что восстановлена
   if (num_file_temp_O >= 0) {
     for (i=num_file_temp_A; i<=num_file_temp_B; i++) {
        if (i!=num_file_temp_O) DeleteTemp(Sender, i);
     }
	 num_file_temp_B = num_file_temp_O+1;
   }
   else
     num_file_temp_B++;

   // Уничтожение верхних файлов
   if (num_file_temp_B - num_file_temp_A > MAX_TEMP_FILE) {
      DeleteTemp(Sender, num_file_temp_A);
      num_file_temp_A++;
   }

   File = "Temp_file_ProfSel" + IntToStr(num_file_temp_B)+".~wkS";

   rc = BD_Close(BD_file);
   if (rc ==0 ) BD_file = NULL;

   BD_file = BD_Open(File.c_str(),"w");
   if (BD_file==NULL) {
	   ErrorMessage("Ошибка при открытии временного файла "+ File +" на запись");
	   return;
   }
   //InfMessage("Запись проекта во временный файл "+ File);

   rc_bool = SaveSelectProf(BD_file);
   if (!rc_bool)
	  ErrorMessage("Ошибка при записи данных во временный файл");
   rc = BD_Close(BD_file);

   num_file_temp_O = -1;

   NUndo->Enabled=true;
   ToolButtonUndo->Enabled=true;
   NRedo->Enabled=false;
   ToolButtonRedo->Enabled=false;
   //Status(READY);
   //InfMessage("SaveTemp: temp_A="+IntToStr(num_file_temp_A)+", temp_B="+IntToStr(num_file_temp_B)+", temp_O="+IntToStr(num_file_temp_O));
}
//---------------------------------------------------------------------------
// Чтение модели из временного файла
//----------------------------------------
void __fastcall TSelectProfilSectForm::OpenTemp(TObject *Sender, int num_file) {

      AnsiString File;
      int rc;

	  File = "Temp_file_ProfSel" + IntToStr(num_file)+".~wkS";

      BD_file = BD_Open(File.c_str(),"r");
	  if (BD_file==NULL) {
          ErrorMessage("Ошибка при открытии временного файла" +File);
          return;
      }
	  bool rc_bool = OpenSelectProf(BD_file);

	  if (!rc_bool) {
         ErrorMessage("Ошибка при чтении данных из копии архива "+File);
         return;
      }
	  //InfMessage("Восстановление модели из файла "+File);

	  num_file_temp_O  = num_file;
      //InfMessage("OpenTemp: num_file="+IntToStr(num_file)+", temp_O="+IntToStr(num_file_temp_O));

      rc = BD_Close(BD_file);

}
//---------------------------------------------------------------------------
// Уничтожение всех временных файлов
void __fastcall TSelectProfilSectForm::RemoveTempFile() {
      int i, rc;
      AnsiString File;

	  rc = BD_Close(BD_file);
      for (i=0; i<MAX_TEMP_FILE; i++) {
		  File = "Temp_file_gen" + IntToStr(i)+".~wkS";
          rc = remove(File.c_str());
          if (rc==-1) {
             if (errno==EACCES) ErrorMessage(File +" - Permission denied");
             else  ErrorMessage(File +" - No such file or directory");
          }
      }
}
//--------------------------------------------------------------------
void __fastcall TSelectProfilSectForm::NSaveClick(TObject *Sender)
{
   int i, rc;
   char _error[240];
   char * path;
   AnsiString File;
   bool rc_bool;
   bool flag_demo, flag_demo2;

   //------------------------------------
   // Прочитать данные
   rc = Read_data(Sender);       //Data_select.type_profil
   if (rc>0) {
	 #ifdef EMBRAC
			rc=Application->MessageBox(L"Проект не сохраняется", L" ", MB_OK | MB_ICONINFORMATION);
	 #else
			rc=Application->MessageBox("Проект не сохраняется", " ", MB_OK | MB_ICONINFORMATION);
	 #endif
	 return;
   }
   // Получение имени директории, в которой находится исполняемый модуль
   //path = getcwd(Path_gen, PATHLEN);
   unsigned long dword = GetModuleFileName(NULL, Path_gen, PATHLEN );
   path = strrchr(Path_gen, '\\');
   path[0] = '\0';

   //-------------------------------------------------------------
   if  (ModelFile ==UNTITLED || ModelFile == NULL) {
	  if(SaveDialog_Model->Execute())
	  {
		  File = SaveDialog_Model->FileName;
          FileDir_Name = File;
          ModelName(File.c_str());
      }
	  else return;
   }
   else
	   File = FileDir_Name;
   rc = BD_Close(BD_file);

   BD_file = BD_Open(File.c_str(),"w");
   if (BD_file==NULL) {
	  InfMessage("Ошибка при открытии архива "+ File +" на запись");
	  return;
   }
   //InfMessage("Сохранение проекта в архиве ");
   rc_bool = SaveSelectProf(BD_file);
   if (!rc_bool) {
	  InfMessage("Ошибка при записи проекта в архив");
      return;
   }
   rc = BD_Close(BD_file);

   BD_file = BD_Open(File.c_str(),"r");
   if (BD_file==NULL) {
	  InfMessage("Ошибка при пробном открытии архива "+File+" на чтение");
      return;
   }

   InfMessage("Проект сохранен в архиве "+ File);
   ModelName(FileDir_Name.c_str());
   Caption = "Подбор стальных сечений, v4.1 - [" + ModelFile +".pwkS]";

   modify_project = false;
   InitTemp(Sender);


}
//---------------------------------------------------------------------------
void __fastcall TSelectProfilSectForm::NSaveAsClick(TObject *Sender)
{
       ModelFile = UNTITLED;
       NSaveClick(Sender);

}
//---------------------------------------------------------------------------
// Выбор типа прокатного двутавра ГОСТ
void __fastcall TSelectProfilSectForm::ComboBox_DvutavrChange(
	  TObject *Sender)
{
		Data_select.index_profil = ComboBox_Dvutavr->ItemIndex;
		// Нарисовать профиль и оси координат прокатного двутавра
		SectSelectCom_ParamFrame1->TabSheet_TU->TabVisible = false;
		SectSelectCom_ParamFrame1->TabSheet_GOST57837->TabVisible = true;
		//SectSelectCom_ParamFrame1->PageControl_StandDvut->ActivePage = TabSheet_GOST57837;
		N_profil = SectSelectCom_ParamFrame1->ComboBox_profil->ItemIndex;

		Draw_prof_ax(N_profil);

		Data_select.index_profil = ComboBox_Dvutavr->ItemIndex;
		Data_select.type_profil = Data_select.index_profil + Data_select.index_GOST_or_TU;
		Show_prof(0, Sender);

		modify_project = true;
		Edit_alfaEnter(Sender);
}
//---------------------------------------------------------------------------
// Выбор типа трубы
void __fastcall TSelectProfilSectForm::ComboBox_TubeChange(TObject *Sender)
{
		switch (ComboBox_Tube->ItemIndex) {
			case 0:
			  Data_select.type_profil = typeSQUARE;
			  RadioButton_Tube->Caption = "Профили гнутые замкнутые ГОСТ 30245";
			break;
			case 1:
			  Data_select.type_profil = typeRECT;
			  RadioButton_Tube->Caption = "Профили гнутые замкнутые ГОСТ 30245";
			break;
			case 2:
			  Data_select.type_profil = typeCIRC;
			  RadioButton_Tube->Caption = "Трубы сварные ГОСТ Р 58064";
			break;
		}
		Show_prof(0, Sender);
	  // Нарисовать профиль и оси координат трубы
		Draw_prof_ax(0);
		modify_project = true;

		ComboBox_TypeElemChange(Sender);
}
//---------------------------------------------------------------------------

void __fastcall TSelectProfilSectForm::RadioGroup_classClick(
      TObject *Sender)
{
          Data_select.index_class = RadioGroup_class->ItemIndex + 1;
}
//---------------------------------------------------------------------------

void __fastcall TSelectProfilSectForm::ComboBox_gamma_cChange(
	  TObject *Sender)
{
	  int rc = String_double_plus(Label_koeff_uslovij->Caption, ComboBox_gamma_c->Text, &(Data_select.gamma_c));
      if (rc>0) return;

}
//---------------------------------------------------------------------------
// Выполнить проверку для выбранного сечения
void __fastcall TSelectProfilSectForm::BitBtnCheckClick(TObject *Sender)
{
   int j = 1;
   int rc;
   int index, n_thick, n_prof;

   if (!TabSheet_Part->TabVisible) {
		rc = Application->MessageBox(L"Расчет не выполняется, т.к. РСУ не получены.", L"",
								  MB_OK | MB_ICONERROR);
		return;
   }
   // Чтение данных
   rc = Read_data(Sender);
   if (rc>0) {
		return;
   }

   if ( strcmp(Data_select.title_material, "")==0 || strcmp(Data_select.MaterProp_prof.title, "")==0) {
			rc = Application->MessageBox(L"Установите материал", L"Материал не установлен",
				MB_OK | MB_ICONWARNING);
		 BitBtnMaterialClick(Sender);
   }
   else {
	  memcpy((char*)&(Data_select.MaterProp_prof), (char*)&(MaterProp[Material_Number]), sizeof(MATER));
   }
   if (CheckBox_same_material->Checked) {
	  if ( strcmp(Data_select.title_material_plate, "")==0) {
			rc = Application->MessageBox(L"Установите материал стенки/пластины ",	L"Материал не установлен",
				MB_OK | MB_ICONWARNING);
			BitBtnMaterial_plateClick(Sender);
	  }
   }
   if (flag_change_rsu) {
	 rc=Application->MessageBox(L"Значения нагрузок были изменены, но в РСУ не включены. Продолжить выполнение c прежними РСУ?", L"",
								  MB_YESNO | MB_ICONQUESTION);
	 if (rc==IDNO) return;
   }
   Label_edge->Caption = "";
   // Выполнить проверку для типа профиля
   switch (Data_select.form_profil) {
   case DVUTAVR_STAND:    // Двутавр прокатной
   case PERFOR_BEAM:      // Двутавр прокатной, перфорированный
	 // Выполнить проверку для прокатного двутавра
	 SectChecking(SectSelectCom_ParamFrame1->ComboBox_profil->ItemIndex, j, Sender);
   break;
   case TRUBA:
	 switch (ComboBox_Tube->ItemIndex) {
     case 0:
	   index = SectSelectCom_ParamFrame1->ComboBox_h_b_square->ItemIndex;
	   n_thick = SectSelectCom_ParamFrame1->ComboBox_t_square->ItemIndex;
	 break;
     case 1:
       index = SectSelectCom_ParamFrame1->ComboBox_h_b_rect->ItemIndex;
       n_thick = SectSelectCom_ParamFrame1->ComboBox_t_rect->ItemIndex;
	 break;
	 case 2:
       index = SectSelectCom_ParamFrame1->ComboBox_Cyl_D->ItemIndex;
	   n_thick = SectSelectCom_ParamFrame1->ComboBox_Cyl_t->ItemIndex;
	 break;
	 }
	 //n_prof = StandartProfil.GetNumberProfil_Tube(index, n_thick);
	 // Выполнить проерку сечений для трубы
	 SectChecking(index, n_thick, Sender);
   break;
   case DVUTAVR_WELD:    // Двутавр прокатной
	 if (!CheckWeld())
	   return;
	 SectChecking(0, 0, Sender);
   break;
   case COMPOSED_BEAM:    // Составная балка
	 if (!CheckWeld())
	   return;
	   switch (Data_select.index_composed) {
	   case TAVR_PLATE_DOWN:
	   case TAVR_PLATE_UP:
		if (Data_select.index_TAVR_GOST_or_TU==typeTAVR_BT)
		  Data_select.index_profil = SectSelectCom_ParamFrame2->RadioGroup_Tavr_GOST->ItemIndex;
		else
		  Data_select.index_profil = SectSelectCom_ParamFrame2->RadioGroup_Tavr_TU->ItemIndex;
		Data_select.type_profil = Data_select.index_profil + Data_select.index_TAVR_GOST_or_TU;
	  break;
	  case DVUTAVR_PLATE_DOWN:
		if (Data_select.index_GOST_or_TU==typeTU_U)
		  Data_select.index_profil = SectSelectCom_ParamFrame2->RadioGroup_TU->ItemIndex;
		else
		  Data_select.index_profil = SectSelectCom_ParamFrame2->RadioGroupGOST57837->ItemIndex;
		Data_select.type_profil = Data_select.index_profil + Data_select.index_GOST_or_TU;
	  break;
	  }
	  // Выполнить проверку для составной балки
	  SectChecking(N_profil, 1, Sender);
   break;
   }
   Draw_prof_ax(N_profil);

}
//---------------------------------------------------------------------------
// Проверка задания параметров сварных швов
bool __fastcall TSelectProfilSectForm::CheckWeld()
{
   if (Data_select.kf_comp ==0)  {
		 int rc = Application->MessageBox(L"Не задан катет сврных швов",
									  L" ", MB_OK | MB_ICONERROR);
		 return false;
   }
   if (Data_select.index_weld_param ==0 || Data_select.Rwf <= 0)  {
		 int rc = Application->MessageBox(L"Не заданы параметры сварных швов",
									  L" ", MB_OK | MB_ICONWARNING);
		 Weld_unit = &Weld_balka_unit;
		 Weld_balka_unit.flag_weld = false;

		 //Weld_ParamForm->ShowModal();
         // Здесь открывается окно Weld_ParamForm
		 Weld_ParamForm->WeldParam(Data_select.index_vid_svarki);
		 if (!Weld_balka_unit.flag_weld)
			return false;
		 Data_select.index_vid_svarki = Weld_ParamForm->index_vid_svarki;
		 Data_select.index_weld_param = 1;
		 Data_select.Rwf = Weld_balka_unit.Rwf;
		 return true;
   }
   return true;
}
//-------------------------------------------------------------------------------
// Прочитать данные из полей формы
int __fastcall TSelectProfilSectForm::Read_data(TObject *Sender)
{
	  int i, k, m, rc;
	  double ss;

	  rc = 0;
	  // Проверка РСУ на элементах
	  for (i=0; i<Data_select.N_plane; i++) {
		if (Data_select.N_RSU[i] == 0) {
		 #ifdef EMBRAC
			rc += Application->MessageBox((L"Не заданы РСУ на элементе "+IntToStr(i+1)).c_str(),
										L"",
		 #else
			rc += Application->MessageBox(("Не заданы РСУ на элементе "+IntToStr(i+1)).c_str(),
										"",
		 #endif
				MB_OK | MB_ICONERROR);
		}
	  }
	  if (rc>0) {
			  PageControl_Data->ActivePage = TabSheet_Part;
			  return rc;
	  }
	  //----------------------------------------------------------------------
	  // Чтение ограничений на прогиб
	  char str[20];
	  AnsiString Lim;

	  if (ComboBox_Delta_lim->ItemIndex==0)
		Data_select.Delta_lim = 0;
	  else {
		Lim = ComboBox_Delta_lim->Text;
		strcpy(str, Lim.c_str());
		Data_select.Delta_lim = StrToFloat((AnsiString)(str+2));
	  }

	  rc = String_double(Label_strela->Caption, Edit_strela->Text, &(ss));
	  if (rc>0)
		return rc;
	  Data_select.Strela = ss;
	  //-------------------------------------------------

	  rc = String_double_plus(Label_gamma_n->Caption, ComboBox_gamma_n->Text, &ss);
	  if (rc>0) return rc;
	  Data_select.gamma_n = ss;

	  Data_select.index_otvetstv = MAX(0, ComboBox_gamma_n->ItemIndex - 1);

	  rc = String_double_plus(Label_koeff_uslovij->Caption, ComboBox_gamma_c->Text, &ss);
	  if (rc>0) return rc;
	  Data_select.gamma_c = ss;
	  Data_select.index_group = RadioGroup_gruppa->ItemIndex + 1;
	  Data_select.index_class = RadioGroup_class->ItemIndex + 1;

	  ComboBox_G1_Count->ItemIndex = MAX(0, ComboBox_G1_Count->ItemIndex);
	  Data_select.index_G1_count = ComboBox_G1_Count->ItemIndex;
	  Data_select.index_G1_load = ComboBox_G1_Load->ItemIndex;
	  Data_select.index_constr = RadioGroup_Schema_constr->ItemIndex;
	  if (CheckBox_edge_choose->Checked) {
		 Data_select.index_1_or_2 = RadioGroup_1_or_2->ItemIndex;
	  }
	  else {
		 Data_select.index_1_or_2 = -1;
	  }

	  if (Edit1->Text == "" || Edit2->Text == "" || Edit_Tens->Text=="") {
		 #ifdef EMBRAC
			rc = Application->MessageBox(L"Не заданы коэффициенты предельной гибкости",
										L"",
		 #else
			rc = Application->MessageBox("Не заданы коэффициенты предельной гибкости",
										"",
		 #endif
			  MB_OK | MB_ICONERROR);
			return rc;
	  }
	  rc = String_double_range(Label_Krn->Caption, Edit_Krn->Text, 0.7, 1.0, &(Data_select.Krn));
	  if (rc>0)
		return rc;
	  rc = String_double_range("Коэфф. 1 предельной гибкости при сжатии", Edit1->Text, 120, 220, &ss);
	  if (rc>0) return rc;
	  Data_select.Limit_lambda1 = ss;
	  rc = String_double_range("Коэфф. 2 предельной гибкости при сжатии", Edit2->Text, 0, 60, &ss);
	  if (rc>0) return rc;
	  Data_select.Limit_lambda2 = ss;
	  rc = String_double_range("Коэфф. предельной гибкости при растяжении", Edit_Tens->Text, 150, 400, &ss);
	  if (rc>0) return rc;
	  Data_select.Limit_lambda_plus = ss;
	  if (CheckBoxAddLimit->Checked) {
		rc=String_double_zero_plus(Label_width->Caption,Edit_width->Text, &ss);
		if (rc>0) return rc;
		Data_select.max_width = ss;

		rc=String_double_zero_plus(Label_height->Caption,Edit_height->Text, &ss);
		if (rc>0) return rc;
		Data_select.max_height = ss;
	  }
	  if (CheckBox_razrez->Checked)
		 Data_select.index_razrez = 1;
	  else
		 Data_select.index_razrez = 0;

	  if (CheckBox_edge->Checked)
		 Data_select.index_edge = 1;
	  else
		 Data_select.index_edge = 0;


	  switch (Data_select.form_profil) {
	  case TRUBA:  // Труба
			switch (ComboBox_Tube->ItemIndex) {
			case 0:
			  Data_select.type_profil = typeSQUARE;
			  type_sect_tube = SQUARE_TUBE;  // для труб: SQUARE_TUBE || RECT_TUBE || CIRCULAR_TUBE
			break;
			case 1:
			  Data_select.type_profil = typeRECT;
			  type_sect_tube = RECT_TUBE;
			break;
			case 2:
			  Data_select.type_profil = typeCIRC;
			  type_sect_tube = CIRCULAR_TUBE;
			break;
			}
	  break;
	  case DVUTAVR_STAND:
			Data_select.index_profil = ComboBox_Dvutavr->ItemIndex;
			Data_select.type_profil = Data_select.index_profil + Data_select.index_GOST_or_TU;
			ss = 0;
			if (CheckBox_edge->Checked) {
			  rc = String_double_plus(LabeledEdit_a->EditLabel->Caption, LabeledEdit_a->Text, &ss);
			  if (rc>0) return 1;
			}
			else {
			  rc = String_double_zero_plus(LabeledEdit_a->EditLabel->Caption, LabeledEdit_a->Text, &ss);
			  if (rc>0) return 1;
			}
			Data_select.Step_edge = ss;
	  break;
	  case PERFOR_BEAM:
			Data_select.index_profil = ComboBox_Dvutavr->ItemIndex;
			Data_select.type_profil = Data_select.index_profil + Data_select.index_GOST_or_TU;
			ss = 0;
			if (CheckBox_edge->Checked) {
			  rc = String_double_plus(LabeledEdit_a->EditLabel->Caption, LabeledEdit_a->Text, &ss);
			  if (rc>0) return 1;
			}
			else {
			  rc = String_double_zero_plus(LabeledEdit_a->EditLabel->Caption, LabeledEdit_a->Text, &ss);
			  if (rc>0) return 1;
			}

			Data_select.Step_edge = ss;
			rc = String_double_plus(Label_attit->Caption, ComboBox_attit->Text, &ss);
			if (rc>0) return 1;
			Data_select.perfor_attit = ss;
			rc = String_double_range(Label_alfa->Caption, Edit_alfa->Text, 40.0, 70.0, &ss);
			if (rc>0) return 1;
			Data_select.perfor_alfa = ss;
	  break;
	  case DVUTAVR_WELD:
			Data_select.index_profil = -1;
			Data_select.type_profil = -1;
			ss = 0;
			if (CheckBox_edge->Checked) {
			  rc = String_double_plus(LabeledEdit_a->EditLabel->Caption, LabeledEdit_a->Text, &ss);
			  if (rc>0) return 1;
			}
			else {
			  rc = String_double_zero_plus(LabeledEdit_a->EditLabel->Caption, LabeledEdit_a->Text, &ss);
			  if (rc>0) return 1;
			}

			Data_select.Step_edge = ss;
	  break;
	  case COMPOSED_BEAM:
			switch (Data_select.index_composed) {
			case TAVR_PLATE_DOWN:
			case TAVR_PLATE_UP:
			  if (Data_select.index_TAVR_GOST_or_TU==typeTAVR_BT)
				 Data_select.index_profil = SectSelectCom_ParamFrame2->RadioGroup_Tavr_GOST->ItemIndex;
			  else
				 Data_select.index_profil = SectSelectCom_ParamFrame2->RadioGroup_Tavr_TU->ItemIndex;
			  Data_select.type_profil = Data_select.index_profil + Data_select.index_TAVR_GOST_or_TU;
			break;
			case DVUTAVR_PLATE_DOWN:
			  if (Data_select.index_GOST_or_TU==typeTU_U)
				Data_select.index_profil = SectSelectCom_ParamFrame2->RadioGroup_TU->ItemIndex;
			  else
				Data_select.index_profil = SectSelectCom_ParamFrame2->RadioGroupGOST57837->ItemIndex;
			  Data_select.type_profil = Data_select.index_profil + Data_select.index_GOST_or_TU;
			break;
			}
			rc = String_double_plus(Label_thick_comp->Caption, Edit_thick_comp->Text, &ss);
			if (rc>0) return 1;
			Data_select.plate_thick = ss;
			rc = String_double_plus(Label_width_comp->Caption, Edit_width_comp->Text, &ss);
			if (rc>0) return 1;
			Data_select.plate_width = ss;
			rc = String_double_plus(Label_kf_comp->Caption, Edit_kf_comp->Text, &ss);
			if (rc>0) return 1;
			Data_select.kf_comp = ss;
			ss = 0;
			if (CheckBox_edge->Checked) {
			  rc = String_double_plus(LabeledEdit_a->EditLabel->Caption, LabeledEdit_a->Text, &ss);
			  if (rc>0) return 1;
			}
			else {
			  rc = String_double_zero_plus(LabeledEdit_a->EditLabel->Caption, LabeledEdit_a->Text, &ss);
			  if (rc>0) return 1;
			}
			Data_select.Step_edge = ss;
	  break;
	  }
	  // Заполнить данные по материалу
	  strcpy(Data_select.title_material, MaterProp[Material_Number].title);
	  Data_select.gamma_m = MaterProp[Material_Number].gamma_m;

	  //-----------------------------------------------------------------------
	  // Чтение данных для подбора сечения сварного двутавра
	  if (Data_select.form_profil==DVUTAVR_WELD) {
		Param_chosen_sect.gamma_c = Data_select.gamma_c;
		rc = String_double_plus(LabeledEdit_lambda0->EditLabel->Caption, LabeledEdit_lambda0->Text, &ss);
		if (rc>0) return 1;
		Param_chosen_sect.lambda0 = ss;
		ss = 0;
		if (CheckBox_edge->Checked) {
		  rc = String_double_plus(LabeledEdit_a->EditLabel->Caption, LabeledEdit_a->Text, &ss);
		  if (rc>0) return 1;
		}
		else {
			  rc = String_double_zero_plus(LabeledEdit_a->EditLabel->Caption, LabeledEdit_a->Text, &ss);
			  if (rc>0) return 1;
		}
		Param_chosen_sect.size_a = ss;
		rc = String_double_plus_low(Label_delta->Caption, Edit_d_lambda->Text, 2.5, &ss);
		if (rc>0) return 1;
		Param_chosen_sect.delta_lambda = ss;
		if (Edit_d_w->Text=="*") {
		   Param_chosen_sect.delta_w = 0.0;
		}
		else {
		   rc = String_double_plus_low(Label_delta->Caption, Edit_d_w->Text, 2.0, &ss);
		   if (rc>0) return 1;
		   Param_chosen_sect.delta_w = ss;
		}
		rc = String_double_plus_low(Label_delta->Caption, Edit_d_f->Text, 1.15, &ss);
		if (rc>0) return 1;
		Param_chosen_sect.delta_f = ss;
		rc = String_double_plus(Label_h->Caption, Edit_round_h->Text, &ss);
		if (rc>0) return 1;
		Param_chosen_sect.round_h = ss;
		rc = String_double_plus(Label_width->Caption, Edit_round_width->Text, &ss);
		if (rc>0) return 1;
		Param_chosen_sect.round_width = ss;
		Param_chosen_sect.round_thick = RadioGroup_sort->ItemIndex;

		rc = String_double_plus(Label_min_tpol->Caption, Edit_min_tpol->Text, &ss);
		if (rc>0) return 1;
		Param_chosen_sect.min_tpol = ss;
		rc = String_double_plus(Label_max_tpol->Caption, Edit_max_tpol->Text, &ss);
		if (rc>0) return 1;
		Param_chosen_sect.max_tpol = ss;
		rc = String_double_plus(Label_min_tsten->Caption, Edit_min_tsten->Text, &ss);
		if (rc>0) return 1;
		Param_chosen_sect.min_tsten = ss;
		rc = String_double_plus(Label_max_tsten->Caption, Edit_max_tsten->Text, &ss);
		if (rc>0) return 1;
		Param_chosen_sect.max_tsten = ss;
		rc = String_double_plus(Label_min_bpol->Caption, Edit_min_bpol->Text, &ss);
		if (rc>0) return 1;
		Param_chosen_sect.min_bpol = ss;
		rc = String_double_plus(Label_max_bpol->Caption, Edit_max_bpol->Text, &ss);
		if (rc>0) return 1;
		Param_chosen_sect.max_bpol = ss;
		rc = String_double_plus(Label_min_hsten->Caption, Edit_min_hsten->Text, &ss);
		if (rc>0) return 1;
		Param_chosen_sect.min_hsten = ss;
		rc = String_double_plus(Label_max_hsten->Caption, Edit_max_hsten->Text, &ss);
		if (rc>0) return 1;
		Param_chosen_sect.max_hsten = ss;
		Param_chosen_sect.flag_minimax = CheckBox_ind_minimax->Checked;

	 }

	 return 0;
}
//------------------------------------------------------------------------------------------
void __fastcall TSelectProfilSectForm::SectSelectCom_ParamFrame1ComboBox_t_squareChange(
	  TObject *Sender)
{
  SectSelectCom_ParamFrame1->ComboBox_t_squareChange(Sender);
  Label_mass->Caption = "";
  Label_mass_weld->Caption = "";
  Label_conditions->Caption = "";
  Label_add_conditions->Caption = "";
  TabSheet_KI->TabVisible = false;
  flag_checking = false;

  // Нарисовать профиль трубы
  int n_prof = StandartProfil.GetNumberProfil_Tube(SectSelectCom_ParamFrame1->ComboBox_h_b_square->ItemIndex,
											   SectSelectCom_ParamFrame1->ComboBox_t_square->ItemIndex);
  Draw_prof_ax(n_prof);

}
//---------------------------------------------------------------------------

void __fastcall TSelectProfilSectForm::SectSelectCom_ParamFrame1ComboBox_t_rectChange(
      TObject *Sender)
{
  SectSelectCom_ParamFrame1->ComboBox_t_rectChange(Sender);
  // Нарисовать профиль трубы
  int n_prof = StandartProfil.GetNumberProfil_Tube(SectSelectCom_ParamFrame1->ComboBox_h_b_rect->ItemIndex,
											   SectSelectCom_ParamFrame1->ComboBox_t_rect->ItemIndex);
  Draw_prof_ax(n_prof);

}
//---------------------------------------------------------------------------

void __fastcall TSelectProfilSectForm::SectSelectCom_ParamFrame1ComboBox_Cyl_tChange(
	  TObject *Sender)
{
  SectSelectCom_ParamFrame1->ComboBox_Cyl_tChange(Sender);
  Label_mass->Caption = "";
  Label_conditions->Caption = "";
  Label_add_conditions->Caption = "";
  TabSheet_KI->TabVisible = false;
  //Sect_Param_WeldFrame1->Visible = false;
  flag_checking = false;

  // Нарисовать профиль трубы
  int n_prof = StandartProfil.GetNumberProfil_Tube(SectSelectCom_ParamFrame1->ComboBox_Cyl_D->ItemIndex,
											   SectSelectCom_ParamFrame1->ComboBox_Cyl_t->ItemIndex);
  Draw_prof_ax(n_prof);

}
//---------------------------------------------------------------------------

void __fastcall TSelectProfilSectForm::SectSelectCom_ParamFrame1ComboBox_Cyl_DChange(
      TObject *Sender)
{
  SectSelectCom_ParamFrame1->ComboBox_Cyl_DChange(Sender);
  Label_mass->Caption = "";
  Label_conditions->Caption = "";
  Label_add_conditions->Caption = "";
  TabSheet_KI->TabVisible = false;
  flag_checking = false;

    // Нарисовать профиль трубы
  int n_prof = StandartProfil.GetNumberProfil_Tube(SectSelectCom_ParamFrame1->ComboBox_Cyl_D->ItemIndex,
											   SectSelectCom_ParamFrame1->ComboBox_Cyl_t->ItemIndex);
  Draw_prof_ax(n_prof);


}
//---------------------------------------------------------------------------

void __fastcall TSelectProfilSectForm::SectSelectCom_ParamFrame1ComboBox_h_b_rectChange(
      TObject *Sender)
{
  SectSelectCom_ParamFrame1->ComboBox_h_b_rectChange(Sender);
  // Нарисовать профиль трубы
  int n_prof = StandartProfil.GetNumberProfil_Tube(SectSelectCom_ParamFrame1->ComboBox_h_b_rect->ItemIndex,
											   SectSelectCom_ParamFrame1->ComboBox_t_rect->ItemIndex);
  Draw_prof_ax(n_prof);


}
//---------------------------------------------------------------------------

void __fastcall TSelectProfilSectForm::SectSelectCom_ParamFrame1ComboBox_h_b_squareChange(
	  TObject *Sender)
{
  SectSelectCom_ParamFrame1->ComboBox_h_b_squareChange(Sender);
  Label_mass->Caption = "";
  Label_conditions->Caption = "";
  Label_add_conditions->Caption = "";
  TabSheet_KI->TabVisible = false;
  flag_checking = false;

  // Нарисовать профиль трубы
  int n_prof = StandartProfil.GetNumberProfil_Tube(SectSelectCom_ParamFrame1->ComboBox_h_b_square->ItemIndex,
											   SectSelectCom_ParamFrame1->ComboBox_t_square->ItemIndex);
  Draw_prof_ax(n_prof);


}
//---------------------------------------------------------------------------

void __fastcall TSelectProfilSectForm::SectSelectCom_ParamFrame1RadioGroupGOST57837Click(
      TObject *Sender)
{

  SectSelectCom_ParamFrame1->RadioGroupGOST57837Click(Sender);
  ComboBox_Dvutavr->ItemIndex = SectSelectCom_ParamFrame1->RadioGroupGOST57837->ItemIndex;
  Label_mass->Caption = "";
  Label_conditions->Caption = "";
  TabSheet_KI->TabVisible = false;
  flag_checking = false;
  // Нарисовать профиль прокатного двутавра
  Data_select.index_profil = ComboBox_Dvutavr->ItemIndex;
  Data_select.type_profil = Data_select.index_profil + Data_select.index_GOST_or_TU;

  N_profil = SectSelectCom_ParamFrame1->ComboBox_profil->ItemIndex;
  Draw_prof_ax(N_profil);

  if (Data_select.form_profil==PERFOR_BEAM) {
	  AnsiString Astr = Edit_alfa->Text;
	  int rc;
	  double alfa = str_exp(Astr.c_str(), &rc);
	  if (rc>0 || alfa<40 || alfa>70)
		return;
	  double attid;
	  rc = String_double_plus(Label_attit->Caption, ComboBox_attit->Text, &attid);
	  if (rc>0) return;
	  // Нарисовать проекции перфорированного профиля
	  Show_prof_perfor(N_profil, Sender, attid, alfa, false);
  }



}
//---------------------------------------------------------------------------


void __fastcall TSelectProfilSectForm::ComboBox_RSUChange(TObject *Sender)
{
     ComboBox_TypeElemChange(Sender);
}
//---------------------------------------------------------------------------
void __fastcall TSelectProfilSectForm::SectSelectCom_ParamFrame1ComboBox_profilChange(
      TObject *Sender)
{
  Label_mass->Caption = "";
  Label_conditions->Caption = "";
  Label_add_conditions->Caption = "";
  TabSheet_KI->TabVisible = false;
  flag_checking = false;

  SectSelectCom_ParamFrame1->ComboBox_profilChange(Sender);
  // Нарисовать профиль прокатного двутавра
  Data_select.index_profil = ComboBox_Dvutavr->ItemIndex;
  Data_select.type_profil = Data_select.index_profil + Data_select.index_GOST_or_TU;

  N_profil = SectSelectCom_ParamFrame1->ComboBox_profil->ItemIndex;

  Draw_prof_ax(N_profil);
  if (Data_select.form_profil==PERFOR_BEAM) {
	  AnsiString Astr = Edit_alfa->Text;
	  int rc;
	  double alfa = str_exp(Astr.c_str(), &rc);
	  if (rc>0 || alfa<40 || alfa>70)
		return;
	  double attid;
	  rc = String_double_plus(Label_attit->Caption, ComboBox_attit->Text, &attid);
	  if (rc>0) return;
	  // Нарисовать проекции перфорированного профиля
	  Show_prof_perfor(N_profil, Sender, attid, alfa, false);
  }



}
//---------------------------------------------------------------------------
void __fastcall TSelectProfilSectForm::BitBtn3Click(TObject *Sender)
{
	 HelpKoeffLengthForm->ShowModal();
}
//---------------------------------------------------------------------------

void __fastcall TSelectProfilSectForm::CheckBoxAddLimitClick(TObject *Sender)
{
   if (CheckBoxAddLimit->Checked) {
	  //GroupBox_AddLimit->Enabled = true;
	  Label_width->Enabled = true;
	  Edit_width->Enabled = true;
	  Label_height->Enabled = true;
	  Edit_height->Enabled = true;

   }
   else {
	  //GroupBox_AddLimit->Enabled = false;
	  Label_width->Enabled = false;
	  Edit_width->Enabled = false;
	  Label_height->Enabled = false;
	  Edit_height->Enabled = false;
   }
   Data_select.flag_add_limit = CheckBoxAddLimit->Checked;

}
//---------------------------------------------------------------------------

void __fastcall TSelectProfilSectForm::BitBtnAddLimitClick(TObject *Sender)
{
   //AddLimitForm->ShowModal();
}
//---------------------------------------------------------------------------

void __fastcall TSelectProfilSectForm::BitBtn4Click(TObject *Sender)
{
	   HelpClassForm->ShowModal();
       modify_project = true;

	   if (HelpClassForm->Class >=0) {
		   RadioGroup_class->ItemIndex = HelpClassForm->Class;
	   }
}
//---------------------------------------------------------------------------

void __fastcall TSelectProfilSectForm::NPreferencesClick(TObject *Sender)
{
	   // Установить файлы XML
}
//---------------------------------------------------------------------------

void __fastcall TSelectProfilSectForm::NOutReportClick(TObject *Sender)
{
	int i;
	if (flag_checking) {
		int rc = Report_Checking(Sender);
		// Восстановить flag_image
		flag_image = true;  // рисовать на форме

	}
	else {
		 #ifdef EMBRAC
		 i = Application->MessageBox(L"Отчет не выводится. Необходимо выполнить подбор, либо проверку сечения",
									  L"",
									  MB_OK | MB_ICONWARNING);
		 #else
		 i = Application->MessageBox("Отчет не выводится. Необходимо выполнить подбор, либо проверку сечения",
									  "",
									  MB_OK | MB_ICONWARNING);
		 #endif
	}
}
//---------------------------------------------------------------------------


void __fastcall TSelectProfilSectForm::BitBtn_flex_tensClick(TObject *Sender)
{
	   Help_FlexCompForm->ShowModal();
	   if (Help_FlexCompForm->Koeff_FlexComp[0] != 0.0) {
		 Edit1->Text = FloatToStr(Help_FlexCompForm->Koeff_FlexComp[0]);
		 Edit2->Text = FloatToStr(Help_FlexCompForm->Koeff_FlexComp[1]);
		 if (Help_FlexCompForm->Koeff_FlexComp[1] == 0.0) {
		   Label4->Visible = false;
		   Label5->Visible = false;
		   Edit2->Visible = false;
		 }
		 else {
		   Label4->Visible = true;
		   Label5->Visible = true;
		   Edit2->Visible = true;
		 }
	   }
	   modify_project = true;

}
//---------------------------------------------------------------------------

void __fastcall TSelectProfilSectForm::BitBtn_flex_compClick(TObject *Sender)
{
	   Help_FlexTensForm->ShowModal();
	   if (Help_FlexTensForm->Koeff_FlexTens != 0.0) {
		 Edit_Tens->Text = FloatToStr(Help_FlexTensForm->Koeff_FlexTens);
	   }
	   modify_project = true;

}
//---------------------------------------------------------------------------
// Прочитать длины элемента и заполнить строку таблицы
void __fastcall TSelectProfilSectForm::FillRow_Len(TObject *Sender)
{
   int k, n_row;
   double Len;
   double muXZ, muYZ, step_comp;

   if (NumRow_Len >=0)
	 k = NumRow_Len - 1;
   else
	 k = Data_select.N_plane;

   int rc1 = String_double_plus(Label_Len->Caption, Edit_Len->Text, &(Len));
   int rc2 = String_double_plus(Label_muXZ->Caption, Edit_muXZ->Text, &(muXZ));
   int rc3 = String_double_plus(Label_muYZ->Caption, Edit_muYZ->Text, &(muYZ));
   int rc4 = String_double_zero_plus(Label_step_comp->Caption, Edit_step_comp->Text, &(step_comp));
   if (rc1>0 || rc2>0 || rc3>0 || rc4>0)
	 return;
   Data_select.Length[k] = Len*1000;
   Data_select.step_comp[k] = step_comp*1000;
   if (RadioGroup_mu->ItemIndex==0) {   // Задается расчетная длина
	 if (muYZ < 1.0) {
		 #ifdef EMBRAC
		 rc1 = Application->MessageBox(L"Значение расчетной длины в пл. YZ меньше 1.0 м",
									  L"",
									  MB_OK | MB_ICONWARNING);
		 #else
		rc1 = Application->MessageBox("Значение расчетной длины в пл. YZ меньше 1.0 м",
									  "",
									  MB_OK | MB_ICONWARNING);
		 #endif
	 }
	 if (muXZ < 1.0) {
		 #ifdef EMBRAC
		 rc1 = Application->MessageBox(L"Значение расчетной длины в пл. XZ меньше 1.0 м",
									  L"",
									  MB_OK | MB_ICONWARNING);
		 #else
		 rc1 = Application->MessageBox("Значение расчетной длины в пл. XZ меньше 1.0 м",
									  "",
									  MB_OK | MB_ICONWARNING);
		 #endif
	 }
	 Data_select.length_YY[k] = muYZ*1000;
	 Data_select.length_XX[k] = muXZ*1000;
	 Data_select.koeff_length_YY[k] = Data_select.length_YY[k]/Data_select.Length[k];
	 Data_select.koeff_length_XX[k] = Data_select.length_XX[k]/Data_select.Length[k];
   }
   else {    // Задается коэффициент расчетной длины
	 Data_select.koeff_length_YY[k] = muYZ;
	 Data_select.koeff_length_XX[k] = muXZ;
	 if (muYZ > 3.0) {
		 #ifdef EMBRAC
		 rc1 = Application->MessageBox(L"Значение коэффициента расчетной длины в пл. YZ больше 3.0",
									  L"",
									  MB_OK | MB_ICONERROR);
		 #else
		 rc1 = Application->MessageBox("Значение коэффициента расчетной длины в пл. YZ больше 3.0",
									  "",
									  MB_OK | MB_ICONERROR);
		 #endif
		 return;
	 }
	 if (muXZ > 3.0) {
		 #ifdef EMBRAC
		 rc1 = Application->MessageBox(L"Значение коэффициента расчетной длины в пл. XZ больше 3.0",
									  L"",
									  MB_OK | MB_ICONERROR);
		 #else
		 rc1 = Application->MessageBox("Значение коэффициента расчетной длины в пл. XZ больше 3.0",
									  "",
									  MB_OK | MB_ICONERROR);
		 #endif
		 return;
	 }
	 Data_select.length_YY[k] = muYZ*Data_select.Length[k];
	 Data_select.length_XX[k] = muXZ*Data_select.Length[k];
   }

   if (NumRow_Len < 0) {
	 Data_select.N_plane++;
	 StringGrid_Length->RowCount = Data_select.N_plane +1;
	 n_row = Data_select.N_plane;
   }
   else {
	 n_row = NumRow_Len;
   }
   StringGrid_Length->Cells[0][n_row] = n_row;
   StringGrid_Length->Cells[1][n_row] = FloatToStrFCut(Data_select.Length[k]/1000, 7, 3);
   StringGrid_Length->Cells[2][n_row] = FloatToStrFCut(Data_select.length_YY[k]/1000, 7, 3);
   StringGrid_Length->Cells[3][n_row] = FloatToStrFCut(Data_select.length_XX[k]/1000, 7, 3);
   StringGrid_Length->Cells[4][n_row] = FloatToStrFCut(Data_select.step_comp[k]/1000, 7, 3);
   n_plane = k;

   if (RadioGroup_Loads->ItemIndex==0) {
	 BitBtn_LenRep->Enabled = true;
	 BitBtn_LenDel->Enabled = true;
   }
}
//--------------------------------------------------------------------
// Добавить участок
void __fastcall TSelectProfilSectForm::BitBtn_LenAddClick(TObject *Sender)
{
	 int k = NumRow_Len;
	 NumRow_Len = -1;
	 // Прочитать длины элемента и заполнить строку таблицы
	 FillRow_Len(Sender);

	 // Выделить строку Lenth
	 StringGrid_LengthMySelect(Data_select.N_plane);

	 Label_plane->Caption = "Количество элементов "+IntToStr(Data_select.N_plane);
	 modify_project = true;

	 TabSheet_KI->TabVisible = false;
	 flag_checking = false;



}
//-----------------------------------------------
// Выделение строки элемента
void __fastcall TSelectProfilSectForm::StringGrid_LengthMySelect(int RowSelect)
{
	 // The following code selects the rectangle containing
	 // rows 1 through 4, and columns 2 and 3.
	 TGridRect myRect;
	 myRect.Left = 0;
	 myRect.Top = RowSelect;
	 myRect.Right = 4;
	 myRect.Bottom = RowSelect;
	 StringGrid_Length->Selection = myRect;
	 NumRow_Len = RowSelect;
	 OutRSU(RowSelect);       // Здесь выполняется рисование начальной модели
}

//----------------------------------------
// Выделение строки элемента
void __fastcall TSelectProfilSectForm::StringGrid_LengthSelectCell(TObject *Sender,
		  int ACol, int ARow, bool &CanSelect)
{
	 OutRSU(ARow);

}
//--------------------------------------------------------------
// Вывести РСУ
void __fastcall TSelectProfilSectForm::OutRSU(int ARow)
{
   int n;
   if (ARow > 0)  {
	 NumRow_Len = ARow;

	 if (RadioGroup_Loads->ItemIndex==0)
		BitBtn_RSUAdd->Enabled = true;
	 n_plane = NumRow_Len - 1;
	 RadioGroup_mu->ItemIndex = 0;

	 index_mu = 0;
	 RadioGroup_mu->ItemIndex = 0;

	 Edit_Len->Text = FloatToStrFCut(Data_select.Length[n_plane]/1000, 7, 3);
	 Edit_muYZ->Text = FloatToStrFCut(Data_select.length_YY[n_plane]/1000, 7, 3);
	 Edit_muXZ->Text = FloatToStrFCut(Data_select.length_XX[n_plane]/1000, 7, 3);
	 Edit_step_comp->Text = FloatToStrFCut(Data_select.step_comp[n_plane]/1000, 7, 3);


	 if (Data_select.N_RSU[NumRow_Len - 1] >0 && Data_select.index_loads==0) {
		BitBtn_RSURep->Enabled = true;
		BitBtn_RSUDel->Enabled = true;
	 }
	 else {
		BitBtn_RSURep->Enabled = false;
		BitBtn_RSUDel->Enabled = false;
	 }
	 // Заполнить таблицу РСУ
	 FillTab_RSU();             //Data_select.type_profil  Data_select.index_profil   BalkaLoadFrame1->n_beam
	 Draw_prof_ax(N_profil);     //Data_beam

   }
}
//---------------------------------------------------------------------------
// Корректировать РСУ, полученные из распред. давления
// Заменить длины элемента
void __fastcall TSelectProfilSectForm::BitBtn_LenRepClick(TObject *Sender)
{
   if (NumRow_Len > 0) {
	  // Прочитать длины элемента и заполнить строку таблицы
	  FillRow_Len(Sender);
	  // Проверка РСУ, полученных из распред. нагрузки
   	  modify_project = true;

   }
   else {
		  #ifdef EMBRAC
	  int rc = Application->MessageBox(L"Элемент не выбран", L" ", MB_OK | MB_ICONWARNING);
		  #else
	  int rc = Application->MessageBox("Элемент не выбран", " ", MB_OK | MB_ICONWARNING);
		  #endif

   }
   TabSheet_KI->TabVisible = false;
   TabSheet_sect_prof->TabVisible = false;
   flag_checking = false;

}
//---------------------------------------------------------------------------
// Удалить участок
void __fastcall TSelectProfilSectForm::BitBtn_LenDelClick(TObject *Sender)
{
   int i;
   if (NumRow_Len > 0) {
	  if (NumRow_Len > 1) {
		for (i = NumRow_Len; i < StringGrid_Length->RowCount - 1; i++) {
		  StringGrid_Length->Cells[1][i] = StringGrid_Length->Cells[1][i+1];
		  StringGrid_Length->Cells[2][i] = StringGrid_Length->Cells[2][i+1];
		  StringGrid_Length->Cells[3][i] = StringGrid_Length->Cells[3][i+1];
		  StringGrid_Length->Cells[4][i] = StringGrid_Length->Cells[4][i+1];
		  Data_select.Length[i-1] = Data_select.Length[i];
		  Data_select.length_YY[i-1] = Data_select.length_YY[i];
		  Data_select.length_XX[i-1] = Data_select.length_XX[i];
		  Data_select.step_comp[i-1] = Data_select.step_comp[i];
		}
	  }
	  StringGrid_Length->RowCount--;
	  if (Data_select.N_plane==0) {
		BitBtn_LenRep->Enabled = false;
		BitBtn_LenDel->Enabled = false;
	  }
	  Data_select.N_plane--;
	  modify_project = true;
	 // Выделить строку
	 //StringGrid_LengthMySelect(NumRow_Len);

   }
   else {
		  #ifdef EMBRAC
	  int rc = Application->MessageBox(L"Элемент не выбран", L" ", MB_OK | MB_ICONWARNING);
		  #else
	  int rc = Application->MessageBox("Элемент не выбран", " ", MB_OK | MB_ICONWARNING);
		  #endif

   }
	 TabSheet_KI->TabVisible = false;
	 flag_checking = false;


}
//---------------------------------------------------------------------------

void __fastcall TSelectProfilSectForm::RadioGroup_muClick(TObject *Sender)
{
   double Len, muXZ, muYZ;
   int rc1 = String_double_zero_plus(Label_muXZ->Caption, Edit_Len->Text, &(Len));
   int rc2 = String_double_zero_plus(Label_muXZ->Caption, Edit_muXZ->Text, &(muXZ));
   int rc3 = String_double_zero_plus(Label_muYZ->Caption, Edit_muYZ->Text, &(muYZ));
   if (rc2>0 || rc3>0)
	 return;

   if (index_mu==1) {
	  muXZ *= Len;
	  muYZ *= Len;
   }

   if (RadioGroup_mu->ItemIndex==0) {
	  Label_muXZ->Caption = "Расчетная длина lef в пл. XY, м";
	  Label_muYZ->Caption = "Расчетная длина lef в пл. XZ, м";
	  Edit_muXZ->Text = FloatToStr(muXZ);
	  Edit_muYZ->Text = FloatToStr(muYZ);
   }
   else {
	  Label_muXZ->Caption = L"Коэффициент расчетной длины \u03BC в пл. XY";
	  Label_muYZ->Caption = L"Коэффициент расчетной длины \u03BC в пл. XZ";
	  if (Len!=0)  {
		Edit_muXZ->Text = FloatToStr(muXZ/Len);
		Edit_muYZ->Text = FloatToStr(muYZ/Len);
	  }
   }
   index_mu = RadioGroup_mu->ItemIndex;
}
//---------------------------------------------------------------------------
// Добавить РСУ для элемента
void __fastcall TSelectProfilSectForm::BitBtn_RSUAddClick(TObject *Sender)
{
	 int k = NumRow_RSU;
	 NumRow_RSU = -1;
	 FillRow_RSU(Sender);
	 NumRow_RSU = k;
	 // Выделить строку RSU
	 StringGrid_RSUMySelect(Data_select.N_RSU[n_plane]);
	 flag_change_rsu = false;

	 if (DrawRSUForm->Visible) {
		BitBtn_DrawClick(Sender);
	 }

	 TabSheet_KI->TabVisible = false;
	 flag_checking = false;


}
//---------------------------------------------------------------------------
//-----------------------------------------------
// Выделение строки РСУ
void __fastcall TSelectProfilSectForm::StringGrid_RSUMySelect(int RowSelect)
{
	 // The following code selects the rectangle containing
	 // rows 1 through 4, and columns 2 and 3.
	 TGridRect myRect;
	 myRect.Left = 0;
	 myRect.Top = RowSelect;
	 myRect.Right = 6;
	 myRect.Bottom = RowSelect;
	 StringGrid_RSU->Selection = myRect;
	 NumRow_RSU = RowSelect;
	 if (NumRow_RSU > 0)  {
		 int n = NumRow_RSU - 1;
		 Edit_N->Text = Data_select.RSU[n_plane][n][0];
		 Edit_Mx->Text = Data_select.RSU[n_plane][n][1];
		 Edit_Qy->Text = Data_select.RSU[n_plane][n][2];
		 Edit_My->Text = Data_select.RSU[n_plane][n][3];
		 Edit_Qx->Text = Data_select.RSU[n_plane][n][4];
		 Edit_qy_->Text = Data_select.q_bal[n_plane][n];

		 Draw_prof_ax(N_profil);
	 }

}
//---------------------------------------------------------------------------
// Прочитать RSU и заполнить строку таблицы
void __fastcall TSelectProfilSectForm::FillRow_RSU(TObject *Sender)
{
   int k, n_row;
   double N_;
   double Mx_, Qy_, My_, Qx_, q_bal;

   if (NumRow_RSU >=0)
	 k = NumRow_RSU - 1;
   else
	 k = Data_select.N_RSU[n_plane];

   int rc1 = String_double(Label_N->Caption, Edit_N->Text, &(N_));
   int rc2 = String_double(Label_Mx->Caption, Edit_Mx->Text, &(Mx_));
   int rc3 = String_double(Label_Qy->Caption, Edit_Qy->Text, &(Qy_));
   int rc4 = String_double(Label_My->Caption, Edit_My->Text, &(My_));
   int rc5 = String_double(Label_Qx->Caption, Edit_Qx->Text, &(Qx_));
   int rc6 = String_double(Label_qy_->Caption, Edit_qy_->Text, &(q_bal));
   if (rc1>0 || rc2>0 || rc3>0 || rc4>0 || rc5>0|| rc6>0)
	 return;
   if (N_==0 && Mx_==0 & My_==0 && Qx_==0 && Qy_==0 && q_bal==0) {
	   rc1 = Application->MessageBox(L"Значения всех усилий заданы равными нулю",
									   L" ", MB_OK | MB_ICONERROR);
	   return;
   }
   if (N_==0 && Mx_==0 && Qy_ == 0 && q_bal == 0) {
	   //rc1 = Application->MessageBox(L"Одно или оба значения N и Mx должны быть заданы не равными нулю",
	   rc1 = Application->MessageBox(L"Одно из значений N, Mx или Qy должно быть задано не равным нулю",
									   L" ", MB_OK | MB_ICONERROR);
	   return;
   }
   Data_select.RSU[n_plane][k][0] = N_;
   Data_select.RSU[n_plane][k][1] = Mx_;
   Data_select.RSU[n_plane][k][2] = Qy_;
   Data_select.RSU[n_plane][k][3] = My_;
   Data_select.RSU[n_plane][k][4] = Qx_;
   Data_select.q_bal[n_plane][k] = q_bal;

   StringGrid_RSU->ColCount = 7;
   if (NumRow_RSU < 0) {
	 Data_select.N_RSU[n_plane]++;
	 StringGrid_RSU->RowCount = Data_select.N_RSU[n_plane] +1;
	 n_row = Data_select.N_RSU[n_plane];
   }
   else {
	 n_row = NumRow_RSU;
   }
   StringGrid_RSU->Cells[0][n_row] = n_row;
   StringGrid_RSU->Cells[1][n_row] = Data_select.RSU[n_plane][k][0];
   StringGrid_RSU->Cells[2][n_row] = Data_select.RSU[n_plane][k][1];
   StringGrid_RSU->Cells[3][n_row] = Data_select.RSU[n_plane][k][2];
   StringGrid_RSU->Cells[4][n_row] = Data_select.RSU[n_plane][k][3];
   StringGrid_RSU->Cells[5][n_row] = Data_select.RSU[n_plane][k][4];
   StringGrid_RSU->Cells[6][n_row] = Data_select.q_bal[n_plane][k];

   BitBtn_RSURep->Enabled = true;
   BitBtn_RSUDel->Enabled = true;
   modify_project = true;

}
//------------------------------------------------------------
// Заполнить таблицу РСУ
void __fastcall TSelectProfilSectForm::FillTab_RSU() {
  int k, n_row;

  GroupBox_RSU->Caption = " Расчетные сочетания усилий на элементе " + IntToStr(n_plane+1) + " ";
  StringGrid_RSU->RowCount = Data_select.N_RSU[n_plane] +1;
  for (k=0; k<Data_select.N_RSU[n_plane]; k++) {
	n_row = k+1;
	StringGrid_RSU->Cells[0][n_row] = n_row;
	StringGrid_RSU->Cells[1][n_row] = Data_select.RSU[n_plane][k][0];
	StringGrid_RSU->Cells[2][n_row] = Data_select.RSU[n_plane][k][1];
	StringGrid_RSU->Cells[3][n_row] = Data_select.RSU[n_plane][k][2];
	StringGrid_RSU->Cells[4][n_row] = Data_select.RSU[n_plane][k][3];
	StringGrid_RSU->Cells[5][n_row] = Data_select.RSU[n_plane][k][4];
	StringGrid_RSU->Cells[6][n_row] = Data_select.q_bal[n_plane][k];
	StringGrid_RSU->Cells[7][n_row] = Round(Data_select.X_sect[n_plane][k], 2);
  }
  Edit_N->Text = StringGrid_RSU->Cells[1][n_row];
  Edit_Mx->Text = StringGrid_RSU->Cells[2][n_row];
  Edit_My->Text = StringGrid_RSU->Cells[4][n_row];
  Edit_Qy->Text = StringGrid_RSU->Cells[3][n_row];
  Edit_Qx->Text = StringGrid_RSU->Cells[5][n_row];
  Edit_qy_->Text = StringGrid_RSU->Cells[6][n_row];

}
//------------------------------------------------------------
// Заменить РСУ
void __fastcall TSelectProfilSectForm::BitBtn_RSURepClick(TObject *Sender)
{
   if (NumRow_RSU > 0) {
	  FillRow_RSU(Sender);
	  flag_change_rsu = false;
   }
   else {
		  #ifdef EMBRAC
	  int rc = Application->MessageBox(L"Строка РСУ не выбрана", L" ", MB_OK | MB_ICONWARNING);
		  #else
	  int rc = Application->MessageBox("Строка РСУ не выбрана", " ", MB_OK | MB_ICONWARNING);
		  #endif

   }
   Draw_prof_ax(N_profil);

   if (DrawRSUForm->Visible) {
	 if (DrawRSUForm->index_draw==0)
		BitBtn_DrawClick(Sender);
	 else
		BitBtn_EpurClick(Sender);
   }
	 TabSheet_KI->TabVisible = false;
	 flag_checking = false;

}
//---------------------------------------------------------------------------
// Выделение строки РСУ
void __fastcall TSelectProfilSectForm::StringGrid_RSUSelectCell(TObject *Sender, int ACol,
		  int ARow, bool &CanSelect)
{
   int n;
   if (ARow > 0)  {
	 NumRow_RSU = ARow;
	 n = NumRow_RSU - 1;
	 Edit_N->Text = Data_select.RSU[n_plane][n][0];
	 Edit_Mx->Text = Data_select.RSU[n_plane][n][1];
	 Edit_Qy->Text = Data_select.RSU[n_plane][n][2];
	 Edit_My->Text = Data_select.RSU[n_plane][n][3];
	 Edit_Qx->Text = Data_select.RSU[n_plane][n][4];
	 Edit_qy_->Text = Data_select.q_bal[n_plane][n];
	 Draw_prof_ax(N_profil);
	 if (DrawRSUForm->Visible) {
	   if (DrawRSUForm->index_draw==0)
			BitBtn_DrawClick(Sender);
	   else
			BitBtn_EpurClick(Sender);
	 }

   }
}
//---------------------------------------------------------------------------

void __fastcall TSelectProfilSectForm::BitBtn_RSUDelClick(TObject *Sender)
{
   int i;
   if (NumRow_RSU > 0) {
	  if (Data_select.N_RSU[n_plane] > 1) {
		for (i = NumRow_RSU; i < StringGrid_RSU->RowCount - 1; i++) {
		  StringGrid_RSU->Cells[1][i] = StringGrid_RSU->Cells[1][i+1];
		  StringGrid_RSU->Cells[2][i] = StringGrid_RSU->Cells[2][i+1];
		  StringGrid_RSU->Cells[3][i] = StringGrid_RSU->Cells[3][i+1];
		  StringGrid_RSU->Cells[4][i] = StringGrid_RSU->Cells[4][i+1];
		  StringGrid_RSU->Cells[5][i] = StringGrid_RSU->Cells[5][i+1];
		  StringGrid_RSU->Cells[6][i] = StringGrid_RSU->Cells[6][i+1];
		  StringGrid_RSU->Cells[7][i] = StringGrid_RSU->Cells[7][i+1];
		  Data_select.RSU[n_plane][i-1][0] = Data_select.RSU[n_plane][i][0];
		  Data_select.RSU[n_plane][i-1][1] = Data_select.RSU[n_plane][i][1];
		  Data_select.RSU[n_plane][i-1][2] = Data_select.RSU[n_plane][i][2];
		  Data_select.RSU[n_plane][i-1][3] = Data_select.RSU[n_plane][i][3];
		  Data_select.RSU[n_plane][i-1][4] = Data_select.RSU[n_plane][i][4];
		  Data_select.q_bal[n_plane][i-1] = Data_select.q_bal[n_plane][i];
		}
		Data_select.N_RSU[n_plane]--;
	  }
	  else
		Data_select.N_RSU[n_plane]=0;
	  StringGrid_RSU->RowCount--;
	  if (Data_select.N_RSU[n_plane]==0) {
		BitBtn_RSURep->Enabled = false;
		BitBtn_RSUDel->Enabled = false;
	  }
	  modify_project = true;
      flag_change_rsu = false;


   }
   else {
		  #ifdef EMBRAC
	  int rc = Application->MessageBox(L"Строка РСУ не выбрана", L" ", MB_OK | MB_ICONWARNING);
		  #else
	  int rc = Application->MessageBox("Строка РСУ не выбрана", " ", MB_OK | MB_ICONWARNING);
		  #endif
   }

	 TabSheet_KI->TabVisible = false;
	 flag_checking = false;


}
//---------------------------------------------------------------------------
// Задание распределенной нагрузки на балке
// Конфигурация интерфейса задания РСУ
void __fastcall TSelectProfilSectForm::Config_RSU(int index)
{
	// Изгибающие моменты возможны для всех типов сечений
	int i, j, k, m;
	 if (index == PERFOR_BEAM) {
		Edit_N->Enabled = false;
		Edit_Mx->Enabled = false;
		Edit_Qy->Enabled = false;
		Edit_My->Enabled = false;
		Edit_Qx->Enabled = false;
		Edit_N->Text = "0";
		Edit_Mx->Text = "0";
		Edit_Qy->Text = "0";
		Edit_My->Text = "0";
		Edit_Qx->Text = "0";

		for (i=0; i<Data_select.N_plane; i++) {
		   for (j=0; j<Data_select.N_RSU[i]; j++) {
			  Data_select.RSU[i][j][0] = 0;
			  Data_select.RSU[i][j][1] = 0;
			  Data_select.RSU[i][j][2] = 0;
			  Data_select.RSU[i][j][3] = 0;
			  Data_select.RSU[i][j][4] = 0;
		   }

		   // Вычеркивание нулевых РСУ
		   for (j=0, m=0; j<Data_select.N_RSU[i]; j++) {
			 if (Data_select.q_bal[i][m] == 0) {
			   for (k=m; k < Data_select.N_RSU[i] - 1; k++) {
				 Data_select.RSU[i][k][0] = Data_select.RSU[i][k+1][0];
				 Data_select.RSU[i][k][1] = Data_select.RSU[i][k+1][1];
				 Data_select.RSU[i][k][2] = Data_select.RSU[i][k+1][2];
				 Data_select.RSU[i][k][3] = Data_select.RSU[i][k+1][3];
				 Data_select.RSU[i][k][4] = Data_select.RSU[i][k+1][4];
				 Data_select.q_bal[i][k] = Data_select.q_bal[i][k+1];
			   }
			 }
			 else
			   m++;
		   }
		   Data_select.N_RSU[i] = m;
		}
		for (i = 0; i < StringGrid_RSU->RowCount; i++) {
		  StringGrid_RSU->Cells[1][i] = 0;
		  StringGrid_RSU->Cells[2][i] = 0;
		  StringGrid_RSU->Cells[3][i] = 0;
		  StringGrid_RSU->Cells[4][i] = 0;
		  StringGrid_RSU->Cells[5][i] = 0;
		}
		Label_GridLen->Caption = "Длины и расчетные длины элементов, м";
	 }
	 else {
		Edit_N->Enabled = true;
		Edit_Mx->Enabled = true;
		Edit_Qy->Enabled = true;
		Edit_My->Enabled = true;
		Edit_Qx->Enabled = true;
		Edit_qy_->Enabled = true;
		Edit_N->Text = "0";
		Edit_Mx->Text = "0";
		Edit_Qy->Text = "0";
		Edit_My->Text = "0";
		Edit_Qx->Text = "0";
		Edit_qy_->Text = "0";
		Label_GridLen->Caption = "Длины и расчетные длины элементов, м";
	 }

}
//-----------------------------------------------------------------------
//
void __fastcall TSelectProfilSectForm::GetLoadFromRSU(double *load)
{
   //flag_image = true;  // Рисовать на форме

   //
   int n;
   n = NumRow_RSU - 1;
   Edit_N->Text = Data_select.RSU[n_plane][n][0];
   Edit_Mx->Text = Data_select.RSU[n_plane][n][1];
   Edit_Qy->Text = Data_select.RSU[n_plane][n][2];
   Edit_My->Text = Data_select.RSU[n_plane][n][3];
   Edit_Qx->Text = Data_select.RSU[n_plane][n][4];
   //

   int rc1 = String_double(Label_N->Caption, Edit_N->Text, &(load[0]));
   int rc2 = String_double(Label_Mx->Caption, Edit_Mx->Text, &(load[1]));
   int rc3 = String_double(Label_Qy->Caption, Edit_Qy->Text, &(load[2]));
   int rc4 = String_double(Label_My->Caption, Edit_My->Text, &(load[3]));
   int rc5 = String_double(Label_Qx->Caption, Edit_Qx->Text, &(load[4]));
   int rc6 = String_double(Label_qy_->Caption, Edit_qy_->Text, &(load[5]));
   if (rc1>0 || rc2>0 || rc3>0 || rc4>0 || rc5>0|| rc6>0)
	 return;
}
//---------------------------------------------------------------------------
void __fastcall TSelectProfilSectForm::BitBtn_DrawClick(TObject *Sender)
{
   double load[6];

   GetLoadFromRSU(load);

   for (int i=0; i<6; i++) {
	 DrawRSUForm->loads[i] = load[i];
   }
   DrawRSUForm->L_beam = Data_select.Length[n_plane];
   DrawRSUForm->form_profil = Data_select.form_profil;
   DrawRSUForm->index_profil = Data_select.index_profil;
   DrawRSUForm->type_profil = Data_select.type_profil;
   DrawRSUForm->attit = Data_select.perfor_attit;
   DrawRSUForm->alfa = Data_select.perfor_alfa;
   DrawRSUForm->plate_thick = Data_select.plate_thick;
   DrawRSUForm->plate_width = Data_select.plate_width;
   DrawRSUForm->index_GOST_or_TU = Data_select.index_GOST_or_TU;
   DrawRSUForm->index_TAVR_GOST_or_TU = Data_select.index_TAVR_GOST_or_TU;
   DrawRSUForm->index_composed = Data_select.index_composed;
   DrawRSUForm->n_profil = N_profil;

   DrawRSUForm->index_draw = 0;
   if (!DrawRSUForm->Visible) {
	  DrawRSUForm->Show();
   }
   DrawRSUForm->Draw_All(Sender);
}
//---------------------------------------------------------------------------

void __fastcall TSelectProfilSectForm::NNewClick(TObject *Sender)
{
	int rc = NewProject(Sender);
	if (rc==0) {
	   Caption = "Подбор стальных сечений, v4.1 - [Новый проект]";
	   InfMessage("Новый проект");
	}
}
//----------------------------------------------------------------
int __fastcall TSelectProfilSectForm::NewProject(TObject *Sender)
{
	int i;

	InitTemp(Sender);
	flag_temp_new = true;


	if (Data_select.N_plane!=0) {
	   i=Application->MessageBox(L"Закрыть текущий проект?", L" ",
				  MB_YESNO | MB_ICONQUESTION);
		if (i==IDNO)
		   return 1;
	   if (modify_project) {
		 i=Application->MessageBox(L"Текущий проект не сохранен, сохранить?", L" ",
				  MB_YESNO | MB_ICONQUESTION);
		 if (i==IDYES) NSaveClick(Sender);
	   }
	}
	ModelFile = UNTITLED;
	modify_project = false;
	flag_checking = false;
 	flag_change_rsu = false;



	CheckBoxAddLimit->Checked = false;
	//GroupBox_AddLimit->Enabled = false;
	Label_width->Enabled = false;
	Edit_width->Enabled = false;
	Label_height->Enabled = false;
	Edit_height->Enabled = false;
	GroupBox_bend->Visible = true;
	//BitBtnCheck->Enabled = false;
	Data_select.form_profil = 0;
	Data_select.N_plane = 0;
	Data_select.Strela = 0;
	Data_select.Delta_lim = 0;
	Data_select.index_GOST = 0;  // материал по ГОСТ 27772
	Label_steel->Caption = steel_STAND_GOST_27772;
	Data_select.index_weld_param = 0;
	Data_select.index_vid_svarki = 0;
	Data_select.index_loads = 0;
	Data_select.index_GOST_or_TU = 0;
	Data_select.index_same_material = 0;
	Data_select.index_TAVR_GOST_or_TU = 0;
	Data_select.index_composed = 0;
	Data_select.Rwf = 0.0;
	Data_select.kf_comp =0;

	Data_select.q_down_max = 0.0;
	Weld_balka_unit.flag_weld = false;

	SpeedButton_WeldParam->Visible = false;

	for (i=0; i<100; i++) {
	  Data_select.N_RSU[i] = 0;
	}

    RadioButton_DvutavrClick(Sender);
   //RadioButton_TubeClick(Sender);
	ComboBox_DvutavrChange(Sender);
   //ComboBox_TubeChange(Sender);

	Label_plane->Caption = "Длины элементов не заданы";
	CheckBox_razrez->Checked = true;

	Edit_N->Text = "0";
	Edit_Mx->Text = "0";
	Edit_Qy->Text = "0";
	Edit_My->Text = "0";
	Edit_Qx->Text = "0";
	Edit_qy_->Text = "0";
	Edit1->Text = "120";
	Edit2->Text = "0";
	Label4->Visible = false;
	Label5->Visible = false;
	Edit2->Visible = false;

	Edit_Tens->Text = "400";
	Edit_Len->Text = "0";
	Edit_muYZ->Text = "0";
	Edit_muXZ->Text = "0";

	TabSheet_KI->TabVisible = false;
	flag_checking = false;
	Last_type_sect = 0;
	ComboBox_index_Qy->ItemIndex = 0;
	//ComboBox_index_Qy->Visible = false;

	ComboBox_TypeElemChange(Sender);
	// Инициация балки
	BalkaLoadFrame1->InitBalka(Sender);

	// Инициация стойки
	RackLoadFrame1->InitRack(Sender);

	// Получение адресов регионов балки
	GetDataBeam(&Data_beam, &Data_region_beam);

	// Получение адресов регионов стойки
	GetDataRack(&Data_rack, &Data_region_rack);

	RadioGroup_Loads->ItemIndex = 0;

	Label_mass->Caption = "";
	Label_conditions->Caption = "";
	Label_add_conditions->Caption = "";
	Label_edge->Caption = "";
	Label_edge_step->Caption = "";
	Label_edge_param->Caption = "";
	Label_mass_weld->Caption = "";
	Label_edge_weld->Caption = "";
	Label_edge_param_weld->Caption = "";
	PageControl_Data->ActivePage = TabSheet_Common;
	PageControl_Dvutavr->ActivePage = TabSheet_GOST;
	PageControl_DvutavrChange(Sender);


	flag_temp_new = false;
	return 0;

}
//---------------------------------------------------------------------------

void __fastcall TSelectProfilSectForm::BitBtn_Advance_gamma_nClick(TObject *Sender)

{
   Advanced_gamma_nForm->ShowModal();
   if (Advanced_gamma_nForm->Koeff_gamma_n > 0) {
	  ComboBox_gamma_n->Text = FloatToStr(Advanced_gamma_nForm->Koeff_gamma_n);
   }
   modify_project = true;

}
//---------------------------------------------------------------------------



void __fastcall TSelectProfilSectForm::BitBtn_OutWordClick(TObject *Sender)
{
	NOutReportClick(Sender);
}
//---------------------------------------------------------------------------
	//WinExec(("hh "+Name_help).c_str(), SW_RESTORE);


void __fastcall TSelectProfilSectForm::NHelpCaptClick(TObject *Sender)
{

	//unsigned long dword = GetModuleFileName(NULL, Path_gen, PATHLEN );
	//char *path = strrchr(Path_gen, '\\');
	//path[0] = '\0';
	//String  Name_help=(AnsiString)Path_gen+"\\Руководство пользователя_стальные конструкции.pdf"; //  chm
	//HelpForm->CppWebBrowser1->Navigate(Name_help.c_str());

	WideString path = ExtractFilePath(Application->ExeName) + "Руководство пользователя_стальные конструкции_v4.1.pdf";
    InfMessage(path);
	HelpForm -> CppWebBrowser1 -> Navigate((BSTR)path);

	HelpForm->ShowModal();


}
//---------------------------------------------------------------------------

void __fastcall TSelectProfilSectForm::NRefProgClick(TObject *Sender)
{
   AboutProgForm->ShowModal();
}
//---------------------------------------------------------------------------

void __fastcall TSelectProfilSectForm::Edit_NChange(TObject *Sender)
{
   flag_change_rsu = true;
}
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------

void __fastcall TSelectProfilSectForm::CheckBox_gibClick(TObject *Sender)
{
	if (CheckBox_gib->Checked) {
	   Edit_d_lambda->Text="1.25";
	   Edit_d_w->Text="0.75";
	   Edit_d_f->Text="1.15";
    }
	else {
	   Edit_d_lambda->Text="1.0";
       Edit_d_w->Text="1.0";
	   Edit_d_f->Text="1.0";
    }
}
//---------------------------------------------------------------------------


void __fastcall TSelectProfilSectForm::Sect_Param_WeldFrame1BitBtn_ApplyClick(TObject *Sender)
{

   Sect_Param_WeldFrame1->BitBtn_ApplyClick(Sender);
   Data_select.kf_comp = Sect_Param_WeldFrame1->kf_dvut;

   Label_mass_weld->Caption = "";
   TabSheet_KI->TabVisible = false;

   Draw_prof_ax(-1);


}
//---------------------------------------------------------------------------
// Перфорированный двутавр
void __fastcall TSelectProfilSectForm::RadioButtonPerforClick(TObject *Sender)
{
	if (RadioButtonPerfor->Checked) {
	  SaveTemp(Sender);

	  BitBtnExec->Enabled = true;
	  CheckBoxAddLimit->Enabled = true;
	  Label_step_comp->Visible = true;
	  Edit_step_comp->Visible = true;
	  Label_step_prim->Visible = true;
	  TabSheet_Weld->TabVisible = false;
	  TabSheetPerfor->TabVisible = true;
	  TabSheet_sect_prof->TabVisible = true;
	  TabSheet_KI->TabVisible = false;
	  CheckBoxAddLimit->Visible = true;
	  CheckBoxAddLimit->Checked = false;
	  CheckBox_edge->Enabled = true;
	  CheckBox_edge_choose->Visible = false;
	  RadioGroup_1_or_2->Visible = false;
	  RadioGroup_Loads->Visible = true;
	  SpeedButton_WeldParam->Visible = false;

	  RadioButton_Tube->Checked = false;
	  RadioButton_Weld->Checked = false;
	  PageControl_Dvutavr->Visible = true;
	  ComboBox_Tube->Visible = false;
	  ComboBox_ComposedBeam->Visible = false;
	  RadioButton_ComposedBeam->Checked = false;

	  Data_select.form_profil = PERFOR_BEAM;
	  //Define_Material_ARSSForm->ComboBox_gost->ItemIndex = 1;
	  //Define_Material_ARSSForm->ComboBox_gostChange(Sender);
	  // Установить список материалов, соответствующих фасонному прокату,
	  Define_Material_ARSSForm->Set_Material_name(Data_select.form_profil, Data_select.index_GOST, Data_select.title_material);
	  Panel_mater->Caption = Define_Material_ARSSForm->ComboBox_steel->Text;
	  CheckBox_same_material->Visible = false;
	  Data_select.index_same_material = 0;
	  CheckBox_same_material->Checked = false;
	  CheckBox_same_materialClick(Sender);

	  ComboBox_TypeElemChange(Sender);

	  if (flag_message) {
		if (Data_select.N_plane != 0 ) {
		  #ifdef EMBRAC
		  int rc = Application->MessageBox(L"При выборе балки с перфорированной стенкой будут обнулены все РСУ. Продолжить? ",
		  L" ", MB_YESNO | MB_ICONQUESTION);
		  #else
		  int rc = Application->MessageBox("При выборе балки с перфорированной стенкой будут обнулены все РСУ. Продолжить? ",
		  " ", MB_YESNO | MB_ICONQUESTION);
		  #endif
		  if (rc==IDNO) {
			RadioButton_Dvutavr->Checked = true;
			return;
		  }

		}
	  }
	  // Конфигурация РСУ
	  Config_RSU(PERFOR_BEAM);

	  flag_change_rsu = false;

	  GroupBox_bend->Visible = true;

	  // Нарисовать профиль и оси координат прокатного двутавра
	  N_profil = SectSelectCom_ParamFrame1->ComboBox_profil->ItemIndex;

	  Show_prof(0, Sender);

	  Draw_prof_ax(N_profil);

	  AnsiString Astr = Edit_alfa->Text;
	  int rc;
	  double alfa = str_exp(Astr.c_str(), &rc);
	  if (rc>0 || alfa<40 || alfa>70)
		return;
	  double attid;
	  rc = String_double_plus(Label_attit->Caption, ComboBox_attit->Text, &attid);
	  if (rc>0) return;
	  // Нарисовать проекции перфорированного профиля
	  Show_prof_perfor(N_profil, Sender, attid, alfa, false);

	  modify_project = true;

	  RadioGroup_Loads_Fill(2);

	}

}
//---------------------------------------------------------------------------
void __fastcall TSelectProfilSectForm::NMRU1Click(TObject *Sender)
{
  // Load a file in the Memo component based on
  // the MRU item that was clicked.
  TMenuItem* itemClicked = dynamic_cast<TMenuItem*>(Sender);
  int index = itemClicked->MenuIndex - NMRU1->MenuIndex;
  FileDir_Name = MruList->Strings[index];
  OpenProject(Sender, 2);

}
//---------------------------------------------------------------------------
void __fastcall TSelectProfilSectForm::NFileClick(TObject *Sender)
{
// This is the OnClick handler for the top
// level File menu. Here we check each string
// in the MRU list and show the associated MRU
// menu item if the string is not empty.
  int index = NMRU1->MenuIndex;
  AnsiString Astr;
  for (int i=0; i<5; i++) {
	Astr = MruList->Strings[i];
	if (Astr != "") {
	  NMRUSeparator->Visible = true;
	  NFile->Items[index + i]->Visible = true;
	  char buff[MAX_PATH];
	  sprintf(buff, "&%d %s", i + 1, Astr.c_str());
	  NFile->Items[index + i]->Caption = buff;
	}
  }
}
//---------------------------------------------------------------------------

void __fastcall TSelectProfilSectForm::FormCreate(TObject *Sender)
{
  // Create the TStringList class.
  MruList = new TStringList;
  // Load the strings from the registry. First
  // try to open the key. If that fails, then we
  // know that the program is being run for the
  // first time and that we need to create the
  // key and set up the MRU items in the key.
  TRegistry* reg = new TRegistry;
  if (!reg->OpenKey(RegKey, false)) {
	reg->OpenKey(RegKey, true);
	reg->WriteString("MRU1", "");
	reg->WriteString("MRU2", "");
	reg->WriteString("MRU3", "");
	reg->WriteString("MRU4", "");
	reg->WriteString("MRU5", "");
  }
// Read each string from the registry. Some of
// the strings could be empty, but that’s OK.
  MruList->Add(reg->ReadString("MRU1"));
  MruList->Add(reg->ReadString("MRU2"));
  MruList->Add(reg->ReadString("MRU3"));
  MruList->Add(reg->ReadString("MRU4"));
  MruList->Add(reg->ReadString("MRU5"));
// Delete the TRegistry object.
  delete reg;

}
//---------------------------------------------------------------------------

void __fastcall TSelectProfilSectForm::FormDestroy(TObject *Sender)
{
  // Save the string list to the registry. If
  // the check box is checked, then delete the
  // key and don’t save the MRU list (duh).
  TRegistry* reg = new TRegistry;
  //if (CheckBox1->Checked)
  //  reg->DeleteKey(RegKey);
  //else {
	reg->OpenKey(RegKey, true);
   // Write the list to the registry.
	reg->WriteString("MRU1", MruList->Strings[0]);
	reg->WriteString("MRU2", MruList->Strings[1]);
	reg->WriteString("MRU3", MruList->Strings[2]);
	reg->WriteString("MRU4", MruList->Strings[3]);
	reg->WriteString("MRU5", MruList->Strings[4]);
  //}
  // Clean up.
  delete reg;
  delete MruList;

}
//---------------------------------------------------------------------------


void __fastcall TSelectProfilSectForm::RadioGroup_SimmSectClick(TObject *Sender)
{
	if (RadioGroup_SimmSect->ItemIndex==0) {
	   CheckBox_equWidth->Checked = true;
	   CheckBox_equWidth->Enabled = false;
	}
	else {
	   CheckBox_equWidth->Enabled = true;
	}
}
//---------------------------------------------------------------------------


void __fastcall TSelectProfilSectForm::ComboBox_AlgChange(TObject *Sender)
{
   if (ComboBox_Alg->ItemIndex==2) {
	   GroupBox_Set_1->Enabled = false;
       RadioGroup_SimmSect->ItemIndex = 0;
   }
   else {
	   GroupBox_Set_1->Enabled = true;
   }
}
//---------------------------------------------------------------------------

void __fastcall TSelectProfilSectForm::BitBtn1Click(TObject *Sender)
{
	Help_delta_Alg_1Form->ShowModal();
}
//---------------------------------------------------------------------------

void __fastcall TSelectProfilSectForm::BitBtn2Click(TObject *Sender)
{
	Help_Algor_Form->ShowModal();
}
//---------------------------------------------------------------------------
void __fastcall TSelectProfilSectForm::Edit_alfaEnter(TObject *Sender)
{
	  double alfa, attid;
	  int rc;
	  rc = String_double_range(Label_alfa->Caption, Edit_alfa->Text, 40.0, 70.0, &alfa);
	  if (rc>0) return;
	  //AnsiString Astr = Edit_alfa->Text;
	  //alfa = str_exp(Astr.c_str(), &rc);
	  //if (rc>0 || alfa<40 || alfa>70)
	  //	return;
	  rc = String_double_plus(Label_attit->Caption, ComboBox_attit->Text, &attid);
	  if (rc>0) return;
	  // Нарисовать профиль и оси координат прокатного двутавра
	  N_profil = SectSelectCom_ParamFrame1->ComboBox_profil->ItemIndex;

	  Show_prof_perfor(N_profil, Sender, attid, alfa, false);

	  // Нарисовать профиль прокатного двутавра
	  Data_select.index_profil = ComboBox_Dvutavr->ItemIndex;
	  Data_select.type_profil = Data_select.index_profil + Data_select.index_GOST_or_TU;

	  N_profil = SectSelectCom_ParamFrame1->ComboBox_profil->ItemIndex;
	  Draw_prof_ax(N_profil);

}
//---------------------------------------------------------------------------

void __fastcall TSelectProfilSectForm::Edit_alfaKeyDown(TObject *Sender, WORD &Key,
		  TShiftState Shift)
{
   if (Key == VK_RETURN) Edit_alfaEnter(Sender);

}
//---------------------------------------------------------------------------
void __fastcall TSelectProfilSectForm::ComboBox_index_QyChange(TObject *Sender)
{
   Data_select.index_Qy = ComboBox_index_Qy->ItemIndex;

   Draw_prof_ax(N_profil);

}
//---------------------------------------------------------------------------

void __fastcall TSelectProfilSectForm::Draw_RSU_Frame1CheckListBox_ShowClick(TObject *Sender)

{
	Draw_prof_ax(N_profil);

}
//---------------------------------------------------------------------------

void __fastcall TSelectProfilSectForm::Draw_RSU_Frame1CheckBox_CentrClick(TObject *Sender)

{
  Draw_RSU_Frame1->CheckBox_CentrClick(Sender);
  Draw_prof_ax(N_profil);


}
//---------------------------------------------------------------------------

void __fastcall TSelectProfilSectForm::Draw_RSU_Frame1CheckBox_SideClick(TObject *Sender)

{
  Draw_RSU_Frame1->CheckBox_SideClick(Sender);
  Draw_prof_ax(N_profil);


}
//---------------------------------------------------------------------------




void __fastcall TSelectProfilSectForm::NUndoClick(TObject *Sender)
{
   int rc;
   int num_file;

   if (num_file_temp_O<0) {
      num_file = num_file_temp_B;  // Запоминаем текущий номер

	  if (modify_project) {
        SaveTemp(Sender);
      }
   }
   else
      num_file = num_file_temp_O - 1;

   if (num_file>=num_file_temp_A)
       OpenTemp(Sender, num_file);

   if (num_file <= num_file_temp_A) {
      NUndo->Enabled=false;
	  ToolButtonUndo->Enabled=false;
   }
   NRedo->Enabled=true;
   ToolButtonRedo->Enabled=true;

   if (Data_beam.Length_beam > 0 ) {
		RadioGroup_Loads_Set(1, Sender);
		// Заполнить поля данных балки
		Fill_field_balka(&Data_beam, &Data_region_beam, Sender);
   }
   if (Data_rack.Length_rack > 0 ) {
		RadioGroup_Loads_Set(2, Sender);
		// Заполнить поля данных балки
		Fill_field_rack(&Data_rack, &Data_region_rack, Sender);
   }

   // Заполнить поля
   Fill_field(Sender);              //Data_select.type_profil
}
//---------------------------------------------------------------------------
// Установить кнопку на панели в зависимости от типа профиля
void __fastcall TSelectProfilSectForm::RadioGroup_Loads_Set(int index_loads, TObject *Sender)
{
	RadioGroup_Loads->ItemIndex = index_loads;
}
//-------------------------------------------------------------------------
void __fastcall TSelectProfilSectForm::NRedoClick(TObject *Sender)
{
   int rc, num_file;

   if (num_file_temp_O>=0)
	  num_file = num_file_temp_O + 1;

   if (num_file_temp_O > num_file_temp_B)
	  return;

   OpenTemp(Sender, num_file);

   if (num_file == num_file_temp_B) {
	  NRedo->Enabled=false;
	  ToolButtonRedo->Enabled=false;
   }

   if (num_file >= num_file_temp_A) {
	  NUndo->Enabled=true;
	  ToolButtonUndo->Enabled=true;
   }

   if (Data_beam.Length_beam > 0 ) {
		RadioGroup_Loads_Set(1, Sender);
		// Заполнить поля данных балки
		Fill_field_balka(&Data_beam, &Data_region_beam, Sender);
   }

   if (Data_rack.Length_rack > 0 ) {
		RadioGroup_Loads_Set(2, Sender);
		// Заполнить поля данных балки
		Fill_field_rack(&Data_rack, &Data_region_rack, Sender);
   }

   // Заполнить поля
   Fill_field(Sender);              //Data_select.type_profil
}
//---------------------------------------------------------------------------

void __fastcall TSelectProfilSectForm::SectSelectCom_ParamFrame1RadioGroup_orientClick(TObject *Sender)

{
  SectSelectCom_ParamFrame1->RadioGroup_orientClick(Sender);
  // Нарисовать профиль трубы
  int n_prof = StandartProfil.GetNumberProfil_Tube(SectSelectCom_ParamFrame1->ComboBox_h_b_rect->ItemIndex,
											   SectSelectCom_ParamFrame1->ComboBox_t_rect->ItemIndex);
  Draw_prof_ax(n_prof);

}
//---------------------------------------------------------------------------


void __fastcall TSelectProfilSectForm::RadioGroup_LoadsClick(TObject *Sender)
{
   int i;
   switch (RadioGroup_Loads->ItemIndex) {
   case 0:
	   Data_select.index_loads = 0;
	   TabSheet_Part->TabVisible = true;
	   TabSheet_BeamModel->TabVisible = false;
	   TabSheet_RackModel->TabVisible = false;
	   CheckBox_razrez->Enabled = true;
	   Edit_muYZ->Visible = true;
	   Label_muYZ->Visible = true;
	   Edit_muXZ->Visible = true;
	   Label_muXZ->Visible = true;
	   Edit_step_comp->Visible = true;
	   Label_step_comp->Visible = true;
	   Label_step_prim->Visible = true;
	   Label_message_length->Visible = false;
	   BitBtn_LenAdd->Enabled = true;
	   BitBtn_LenRep->Enabled = true;
	   BitBtn_LenDel->Enabled = true;
	   RadioGroup_mu->Enabled =  true;
	   Label_GridLen->Visible = true;
	   StringGrid_Length->Visible = true;

	   BitBtn_RSUAdd->Enabled = true;
	   BitBtn_RSURep->Enabled = true;
	   BitBtn_RSUDel->Enabled = true;

	   Draw_RSU_Frame1->CheckBox_RealScale->Visible = false;
	   Draw_RSU_Frame1->CheckListBox_Show->Items->Clear();
	   Draw_RSU_Frame1->CheckListBox_Show->Items->Add("РСУ");
	   Draw_RSU_Frame1->CheckListBox_Show->Items->Add("Значения нагрузок");
	   Draw_RSU_Frame1->CheckListBox_Show->Items->Add("Систему координат");
	   Draw_RSU_Frame1->CheckListBox_Show->Width = 250;
	   for (i=0; i<3; i++)
		  Draw_RSU_Frame1->CheckListBox_Show->Checked[i]=true;
   break;
   case 1:
	   Data_select.index_loads = 1;
	   TabSheet_Part->TabVisible = false;
	   //BalkaLoadFrame1->PageControl_BoundCondChange(Sender);
	   TabSheet_BeamModel->TabVisible = true;
	   TabSheet_RackModel->TabVisible = false;
	   Draw_RSU_Frame1->CheckBox_RealScale->Visible = true;
	   CheckBox_razrez->Enabled = false;
	   Edit_muYZ->Visible = false;
	   Label_muYZ->Visible = false;
	   Edit_muXZ->Visible = false;
	   Label_muXZ->Visible = false;
	   Edit_step_comp->Visible = false;
	   Label_step_comp->Visible = false;
	   BitBtn_LenAdd->Enabled = false;
	   BitBtn_LenRep->Enabled = false;
	   BitBtn_LenDel->Enabled = false;
	   RadioGroup_mu->Enabled =  false;
	   Label_GridLen->Visible = false;
	   StringGrid_Length->Visible = false;

	   BitBtn_RSUAdd->Enabled = false;
	   BitBtn_RSURep->Enabled = false;
	   BitBtn_RSUDel->Enabled = false;

	   Draw_RSU_Frame1->CheckListBox_Show->Items->Clear();
	   Draw_RSU_Frame1->CheckListBox_Show->Items->Add("Нагрузки");
	   Draw_RSU_Frame1->CheckListBox_Show->Items->Add("Значения нагрузок");
	   Draw_RSU_Frame1->CheckListBox_Show->Items->Add("Систему координат");
	   Draw_RSU_Frame1->CheckListBox_Show->Items->Add("Опоры");
	   Draw_RSU_Frame1->CheckListBox_Show->Items->Add("Раскрепления");
	   Draw_RSU_Frame1->CheckListBox_Show->Items->Add("Позиции нагрузок и опор");
	   Draw_RSU_Frame1->CheckListBox_Show->Width = 400;
	   for (i=0; i<4; i++)
		  Draw_RSU_Frame1->CheckListBox_Show->Checked[i]=true;
	   Draw_RSU_Frame1->CheckListBox_Show->Checked[4]=false;
	   PageControl_Data->ActivePage = TabSheet_BeamModel;
	   Label_step_prim->Visible = false;
	   Label_message_length->Visible = true;
	   Label_message_length->Caption = "Расчетные длины принимаются по условиям раскреплений, заданных в модели балки";
	   Label_message_length->Top = Label_muYZ->Top;
	   Label_message_length->Left = Label_muYZ->Left;
   break;
   case 2:
	   Data_select.index_loads = 2;
	   TabSheet_Part->TabVisible = false;
	   //BalkaLoadFrame1->PageControl_BoundCondChange(Sender);
	   TabSheet_BeamModel->TabVisible = false;
	   TabSheet_RackModel->TabVisible = true;
	   Draw_RSU_Frame1->CheckBox_RealScale->Visible = true;
	   CheckBox_razrez->Enabled = false;
	   Edit_muYZ->Visible = false;
	   Label_muYZ->Visible = false;
	   Edit_muXZ->Visible = false;
	   Label_muXZ->Visible = false;
	   Edit_step_comp->Visible = false;
	   Label_step_comp->Visible = false;
	   BitBtn_LenAdd->Enabled = false;
	   BitBtn_LenRep->Enabled = false;
	   BitBtn_LenDel->Enabled = false;
	   RadioGroup_mu->Enabled =  false;
	   Label_GridLen->Visible = false;
	   StringGrid_Length->Visible = true;

	   BitBtn_RSUAdd->Enabled = false;
	   BitBtn_RSURep->Enabled = false;
	   BitBtn_RSUDel->Enabled = false;

	   Draw_RSU_Frame1->CheckListBox_Show->Items->Clear();
	   Draw_RSU_Frame1->CheckListBox_Show->Items->Add("Нагрузки");
	   Draw_RSU_Frame1->CheckListBox_Show->Items->Add("Значения нагрузок");
	   Draw_RSU_Frame1->CheckListBox_Show->Items->Add("Систему координат");
	   Draw_RSU_Frame1->CheckListBox_Show->Items->Add("Опоры");
	   Draw_RSU_Frame1->CheckListBox_Show->Items->Add("Раскрепления");
	   Draw_RSU_Frame1->CheckListBox_Show->Items->Add("Позиции нагрузок и опор");
	   Draw_RSU_Frame1->CheckListBox_Show->Width = 400;
	   for (i=0; i<4; i++)
		  Draw_RSU_Frame1->CheckListBox_Show->Checked[i]=true;
	   Draw_RSU_Frame1->CheckListBox_Show->Checked[4]=false;
	   PageControl_Data->ActivePage = TabSheet_RackModel;
	   Label_step_prim->Visible = false;
	   Label_message_length->Visible = true;
	   Label_message_length->Visible = true;
	   Label_message_length->Caption = "Расчетные длины принимаются по условиям, заданных в модели стойки";
	   Label_message_length->Top = Label_muYZ->Top;
	   Label_message_length->Left = Label_muYZ->Left;
   break;
   }

}
//---------------------------------------------------------------------------



void __fastcall TSelectProfilSectForm::BalkaLoadFrame1BitBtn_AddClick(TObject *Sender)

{
  BalkaLoadFrame1->BitBtn_AddClick(Sender);
  Draw_prof_ax(N_profil);
}
//---------------------------------------------------------------------------


void __fastcall TSelectProfilSectForm::BalkaLoadFrame1BitBtnDeleteClick(TObject *Sender)

{
	 BalkaLoadFrame1->BitBtnDeleteClick(Sender);
	 Draw_prof_ax(N_profil);

}
//---------------------------------------------------------------------------

void __fastcall TSelectProfilSectForm::BalkaLoadFrame1BitBtn_ReplaceClick(TObject *Sender)

{
	BalkaLoadFrame1->BitBtn_ReplaceClick(Sender);
    Draw_prof_ax(N_profil);

}
//---------------------------------------------------------------------------


void __fastcall TSelectProfilSectForm::BalkaLoadFrame1Edit_p1Change(TObject *Sender)

{
	 BalkaLoadFrame1->Edit_p1Change(Sender);
}
//---------------------------------------------------------------------------

void __fastcall TSelectProfilSectForm::BalkaLoadFrame1Edit_n1Change(TObject *Sender)

{
     BalkaLoadFrame1->Edit_n1Change(Sender);
}
//---------------------------------------------------------------------------

void __fastcall TSelectProfilSectForm::BalkaLoadFrame1CheckBox_LinearClick(TObject *Sender)

{
     BalkaLoadFrame1->CheckBox_LinearClick(Sender);
}
//---------------------------------------------------------------------------

void __fastcall TSelectProfilSectForm::BalkaLoadFrame1CheckBox_Linear_nClick(TObject *Sender)

{
    BalkaLoadFrame1->CheckBox_Linear_nClick(Sender);
}
//---------------------------------------------------------------------------

void __fastcall TSelectProfilSectForm::BalkaLoadFrame1BitBtn_InsertClick(TObject *Sender)

{
    BalkaLoadFrame1->BitBtn_InsertClick(Sender);
}
//---------------------------------------------------------------------------

void __fastcall TSelectProfilSectForm::BalkaLoadFrame1ListBox1Click(TObject *Sender)

{
	BalkaLoadFrame1->ListBox1Click(Sender);
}
//---------------------------------------------------------------------------

void __fastcall TSelectProfilSectForm::BalkaLoadFrame1CSpinEditLineWidthChange(TObject *Sender)
{
	   BalkaLoadFrame1->CSpinEditLineWidthChange(Sender);
}
//---------------------------------------------------------------------------

void __fastcall TSelectProfilSectForm::BalkaLoadFrame1PageControl_BoundCondChange(TObject *Sender)

{
  BalkaLoadFrame1->PageControl_BoundCondChange(Sender);

}
//---------------------------------------------------------------------------

void __fastcall TSelectProfilSectForm::BalkaLoadFrame1SpeedButton_AddClick(TObject *Sender)

{
  BalkaLoadFrame1->SpeedButton_AddClick(Sender);
  Draw_prof_ax(N_profil);

}
//---------------------------------------------------------------------------

void __fastcall TSelectProfilSectForm::BalkaLoadFrame1SpeedButtonDeleteClick(TObject *Sender)

{
  BalkaLoadFrame1->SpeedButtonDeleteClick(Sender);
  Draw_prof_ax(N_profil);

}
//---------------------------------------------------------------------------

void __fastcall TSelectProfilSectForm::BalkaLoadFrame1ComboBox_num_zagrChange(TObject *Sender)

{
  BalkaLoadFrame1->ComboBox_num_zagrChange(Sender);
  Draw_prof_ax(N_profil);

}
//---------------------------------------------------------------------------


void __fastcall TSelectProfilSectForm::BalkaLoadFrame1SpeedButton_ApplyClick(TObject *Sender)

{
	BalkaLoadFrame1->SpeedButton_ApplyClick(Sender);

	Draw_prof_ax(N_profil);

}
//---------------------------------------------------------------------------
void __fastcall TSelectProfilSectForm::Draw_RSU_Frame1CheckBox_RealScaleClick(TObject *Sender)

{
	Draw_prof_ax(N_profil);
}
//---------------------------------------------------------------------------

void __fastcall TSelectProfilSectForm::BalkaLoadFrame1SpeedButtonTablClick(TObject *Sender)

{
  BalkaLoadFrame1->SpeedButtonTablClick(Sender);
  Draw_prof_ax(N_profil);


}
//---------------------------------------------------------------------------


void __fastcall TSelectProfilSectForm::BalkaLoadFrame1PageControl_LoadChange(TObject *Sender)

{
	BalkaLoadFrame1->PageControl_LoadChange(Sender);

}
//---------------------------------------------------------------------------

void __fastcall TSelectProfilSectForm::BalkaLoadFrame1ComboBox_type_zagrChange(TObject *Sender)

{
  BalkaLoadFrame1->ComboBox_type_zagrChange(Sender);
  Draw_prof_ax(N_profil);

}
//---------------------------------------------------------------------------



void __fastcall TSelectProfilSectForm::BalkaLoadFrame1BitBtn_AddZClick(TObject *Sender)

{
  BalkaLoadFrame1->BitBtn_AddClick(Sender);
  Draw_prof_ax(N_profil);

}
//---------------------------------------------------------------------------

void __fastcall TSelectProfilSectForm::BalkaLoadFrame1BitBtn_ReplaceZClick(TObject *Sender)

{
  BalkaLoadFrame1->BitBtn_ReplaceClick(Sender);
  Draw_prof_ax(N_profil);

}
//---------------------------------------------------------------------------

void __fastcall TSelectProfilSectForm::BalkaLoadFrame1BitBtn_DeleteZClick(TObject *Sender)

{
  BalkaLoadFrame1->BitBtnDeleteClick(Sender);
  Draw_prof_ax(N_profil);

}
//---------------------------------------------------------------------------


void __fastcall TSelectProfilSectForm::BalkaLoadFrame1RadioGroup_SupCountClick(TObject *Sender)

{
  BalkaLoadFrame1->RadioGroup_SupCountClick(Sender);
  Draw_prof_ax(N_profil);
}
//---------------------------------------------------------------------------

void __fastcall TSelectProfilSectForm::BalkaLoadFrame1SpeedButtonAppStepClick(TObject *Sender)
{
  BalkaLoadFrame1->SpeedButtonAppStepClick(Sender);
  Draw_prof_ax(N_profil);
}
//---------------------------------------------------------------------------

void __fastcall TSelectProfilSectForm::BalkaLoadFrame1BitBtn_CreateRSUClick(TObject *Sender)
{
  int i, j;
  int k = 0;
  bool flag_repeat;
  // Вычислить РСУ
  BalkaLoadFrame1->BitBtn_CreateRSUClick(Sender);

  Data_select.MaxV0 = BalkaLoadFrame1->MaxV;
  Data_select.MaxV = BalkaLoadFrame1->MaxV;
  Data_select.MaxV_W = BalkaLoadFrame1->MaxV_W;
  Data_select.Span = BalkaLoadFrame1->Span;

  Data_select.N_plane =  1;
  if (BalkaLoadFrame1->MaxN[0]>0) {
	 Data_select.RSU[0][k][0] = BalkaLoadFrame1->MaxN[0]/F1000;
	 Data_select.RSU[0][k][1] = BalkaLoadFrame1->MaxN[2]/F1000;
	 Data_select.RSU[0][k][2] = BalkaLoadFrame1->MaxN[1]/F1000;
	 Data_select.RSU[0][k][3] = BalkaLoadFrame1->MaxN[4]/F1000;
	 Data_select.RSU[0][k][4] = BalkaLoadFrame1->MaxN[3]/F1000;
	 Data_select.X_sect[0][k] = BalkaLoadFrame1->MaxN[5]/L1000;
	 Data_select.q_bal[0][k] = 0;
	 Data_select.RSU_W[k][0] = BalkaLoadFrame1->MaxN_W[0]/F1000;
	 Data_select.RSU_W[k][1] = BalkaLoadFrame1->MaxN_W[2]/F1000;
	 Data_select.RSU_W[k][2] = BalkaLoadFrame1->MaxN_W[1]/F1000;
	 Data_select.RSU_W[k][3] = BalkaLoadFrame1->MaxN_W[4]/F1000;
	 Data_select.RSU_W[k][4] = BalkaLoadFrame1->MaxN_W[3]/F1000;
	 k++;
  }
  if (BalkaLoadFrame1->MinN[0]<0) {
	 Data_select.RSU[0][k][0] = BalkaLoadFrame1->MinN[0]/F1000;
	 Data_select.RSU[0][k][1] = BalkaLoadFrame1->MinN[2]/F1000;
	 Data_select.RSU[0][k][2] = BalkaLoadFrame1->MinN[1]/F1000;
	 Data_select.RSU[0][k][3] = BalkaLoadFrame1->MinN[4]/F1000;
	 Data_select.RSU[0][k][4] = BalkaLoadFrame1->MinN[3]/F1000;
	 Data_select.X_sect[0][k] = BalkaLoadFrame1->MinN[5]/L1000;
	 Data_select.q_bal[0][k] = 0;
	 Data_select.RSU_W[k][0] = BalkaLoadFrame1->MinN_W[0]/F1000;
	 Data_select.RSU_W[k][1] = BalkaLoadFrame1->MinN_W[2]/F1000;
	 Data_select.RSU_W[k][2] = BalkaLoadFrame1->MinN_W[1]/F1000;
	 Data_select.RSU_W[k][3] = BalkaLoadFrame1->MinN_W[4]/F1000;
	 Data_select.RSU_W[k][4] = BalkaLoadFrame1->MinN_W[3]/F1000;
	 k++;
  }
  flag_repeat = false;
  for (i=0; i<k; i++) {
	if ((ABS(BalkaLoadFrame1->MaxQ[1]/F1000 - Data_select.RSU[0][i][2]))<1e-3)
	  flag_repeat = true;
  }
  if (BalkaLoadFrame1->MaxQ[1]>0 && !flag_repeat) {
	 Data_select.RSU[0][k][0] = BalkaLoadFrame1->MaxQ[0]/F1000;
	 Data_select.RSU[0][k][1] = BalkaLoadFrame1->MaxQ[2]/F1000;
	 Data_select.RSU[0][k][2] = BalkaLoadFrame1->MaxQ[1]/F1000;
	 Data_select.RSU[0][k][3] = BalkaLoadFrame1->MaxQ[4]/F1000;
	 Data_select.RSU[0][k][4] = BalkaLoadFrame1->MaxQ[3]/F1000;
	 Data_select.X_sect[0][k] = BalkaLoadFrame1->MaxQ[5]/L1000;
	 Data_select.q_bal[0][k] = 0;
	 Data_select.RSU_W[k][0] = BalkaLoadFrame1->MaxQ_W[0]/F1000;
	 Data_select.RSU_W[k][1] = BalkaLoadFrame1->MaxQ_W[2]/F1000;
	 Data_select.RSU_W[k][2] = BalkaLoadFrame1->MaxQ_W[1]/F1000;
	 Data_select.RSU_W[k][3] = BalkaLoadFrame1->MaxQ_W[4]/F1000;
	 Data_select.RSU_W[k][4] = BalkaLoadFrame1->MaxQ_W[3]/F1000;
	 k++;
  }
  flag_repeat = false;
  for (i=0; i<k; i++) {
	if ((ABS(BalkaLoadFrame1->MaxM[1]/F1000 - Data_select.RSU[0][i][1]))<1e-3)
	  flag_repeat = true;
  }
  if (BalkaLoadFrame1->MaxM[2]>0 && !flag_repeat) {
	 Data_select.RSU[0][k][0] = BalkaLoadFrame1->MaxM[0]/F1000;
	 Data_select.RSU[0][k][1] = BalkaLoadFrame1->MaxM[2]/F1000;
	 Data_select.RSU[0][k][2] = BalkaLoadFrame1->MaxM[1]/F1000;
	 Data_select.RSU[0][k][3] = BalkaLoadFrame1->MaxM[4]/F1000;
	 Data_select.RSU[0][k][4] = BalkaLoadFrame1->MaxM[3]/F1000;
	 Data_select.X_sect[0][k] = BalkaLoadFrame1->MaxM[5]/L1000;
	 Data_select.q_bal[0][k] = 0;
	 Data_select.RSU_W[k][0] = BalkaLoadFrame1->MaxM_W[0]/F1000;
	 Data_select.RSU_W[k][1] = BalkaLoadFrame1->MaxM_W[2]/F1000;
	 Data_select.RSU_W[k][2] = BalkaLoadFrame1->MaxM_W[1]/F1000;
	 Data_select.RSU_W[k][3] = BalkaLoadFrame1->MaxM_W[4]/F1000;
	 Data_select.RSU_W[k][4] = BalkaLoadFrame1->MaxM_W[3]/F1000;
	 k++;
  }
  flag_repeat = false;
  for (i=0; i<k; i++) {
	if ((ABS(BalkaLoadFrame1->MinM[2]/F1000 - Data_select.RSU[0][i][1]))<1e-3)
	  flag_repeat = true;
  }
  if (BalkaLoadFrame1->MinM[2]<0 && !flag_repeat) {
	 Data_select.RSU[0][k][0] = BalkaLoadFrame1->MinM[0]/F1000;
	 Data_select.RSU[0][k][1] = BalkaLoadFrame1->MinM[2]/F1000;
	 Data_select.RSU[0][k][2] = BalkaLoadFrame1->MinM[1]/F1000;
	 Data_select.RSU[0][k][3] = BalkaLoadFrame1->MinM[4]/F1000;
	 Data_select.RSU[0][k][4] = BalkaLoadFrame1->MinM[3]/F1000;
	 Data_select.X_sect[0][k] = BalkaLoadFrame1->MinM[5]/L1000;
	 Data_select.q_bal[0][k] = 0;
	 Data_select.RSU_W[k][0] = BalkaLoadFrame1->MinM_W[0]/F1000;
	 Data_select.RSU_W[k][1] = BalkaLoadFrame1->MinM_W[2]/F1000;
	 Data_select.RSU_W[k][2] = BalkaLoadFrame1->MinM_W[1]/F1000;
	 Data_select.RSU_W[k][3] = BalkaLoadFrame1->MinM_W[4]/F1000;
	 Data_select.RSU_W[k][4] = BalkaLoadFrame1->MinM_W[3]/F1000;
	 k++;
  }
  flag_repeat = false;
  for (i=0; i<k; i++) {
	if ((ABS(BalkaLoadFrame1->MaxSigma[2]/F1000 - Data_select.RSU[0][i][1]))<1e-3)
	  flag_repeat = true;
  }
  if (BalkaLoadFrame1->MaxSigma[2]>0 && !flag_repeat) {
	 Data_select.RSU[0][k][0] = BalkaLoadFrame1->MaxSigma[0]/F1000;
	 Data_select.RSU[0][k][1] = BalkaLoadFrame1->MaxSigma[2]/F1000;
	 Data_select.RSU[0][k][2] = BalkaLoadFrame1->MaxSigma[1]/F1000;
	 Data_select.RSU[0][k][3] = BalkaLoadFrame1->MaxSigma[4]/F1000;
	 Data_select.RSU[0][k][4] = BalkaLoadFrame1->MaxSigma[3]/F1000;
	 Data_select.X_sect[0][k] = BalkaLoadFrame1->MaxSigma[5]/L1000;
	 Data_select.q_bal[0][k] = 0;
	 Data_select.RSU_W[k][0] = BalkaLoadFrame1->MaxSigma_W[0]/F1000;
	 Data_select.RSU_W[k][1] = BalkaLoadFrame1->MaxSigma_W[2]/F1000;
	 Data_select.RSU_W[k][2] = BalkaLoadFrame1->MaxSigma_W[1]/F1000;
	 Data_select.RSU_W[k][3] = BalkaLoadFrame1->MaxSigma_W[4]/F1000;
	 Data_select.RSU_W[k][4] = BalkaLoadFrame1->MaxSigma_W[3]/F1000;
	 k++;
  }
  flag_repeat = false;
  for (i=0; i<k; i++) {
	if ((ABS(BalkaLoadFrame1->MinSigma[2]/F1000 - Data_select.RSU[0][i][1]))<1e-3)
	  flag_repeat = true;
  }
  if (BalkaLoadFrame1->MinSigma[2]<0 && !flag_repeat) {
	 Data_select.RSU[0][k][0] = BalkaLoadFrame1->MinSigma[0]/F1000;
	 Data_select.RSU[0][k][1] = BalkaLoadFrame1->MinSigma[2]/F1000;
	 Data_select.RSU[0][k][2] = BalkaLoadFrame1->MinSigma[1]/F1000;
	 Data_select.RSU[0][k][3] = BalkaLoadFrame1->MinSigma[4]/F1000;
	 Data_select.RSU[0][k][4] = BalkaLoadFrame1->MinSigma[3]/F1000;
	 Data_select.X_sect[0][k] = BalkaLoadFrame1->MinSigma[5]/L1000;
	 Data_select.q_bal[0][k] = 0;
	 Data_select.RSU_W[k][0] = BalkaLoadFrame1->MinSigma_W[0]/F1000;
	 Data_select.RSU_W[k][1] = BalkaLoadFrame1->MinSigma_W[2]/F1000;
	 Data_select.RSU_W[k][2] = BalkaLoadFrame1->MinSigma_W[1]/F1000;
	 Data_select.RSU_W[k][3] = BalkaLoadFrame1->MinSigma_W[4]/F1000;
	 Data_select.RSU_W[k][4] = BalkaLoadFrame1->MinSigma_W[3]/F1000;
	 k++;
  }
  Data_select.q_down_max = BalkaLoadFrame1->q_down_max;
  Data_select.q_down_LR_max = BalkaLoadFrame1->q_down_LR_max;
  Data_select.M_down_LR_max = BalkaLoadFrame1->M_down_LR_max;
  Data_select.FRo_RSU = BalkaLoadFrame1->FRo_RSU;
  Data_select.Izz_RSU = BalkaLoadFrame1->Izz_RSU;
  Data_select.N_RSU[0] = k;
  Data_select.Length[0] = BalkaLoadFrame1->Length_beam*L1000;
  Data_select.length_YY[0] = BalkaLoadFrame1->Length_beam*L1000;
  if (BalkaLoadFrame1->Len_XY > 0)
	Data_select.length_XX[0] = BalkaLoadFrame1->Len_XY*L1000;
  else
	Data_select.length_XX[0] = Data_select.Length[0];
  Data_select.koeff_length_YY[0] = 1;
  Data_select.koeff_length_XX[0] = BalkaLoadFrame1->Len_XY/BalkaLoadFrame1->Length_beam;
  Data_select.step_comp[0] = 0;
  if (BalkaLoadFrame1->Step_up > 0)
	Data_select.step_up = BalkaLoadFrame1->Step_up*L1000;
  else
	Data_select.step_up = Data_select.length_XX[0];
  if (BalkaLoadFrame1->Step_down > 0)
	Data_select.step_down = BalkaLoadFrame1->Step_down*L1000;
  else
	Data_select.step_down = Data_select.length_XX[0];
  // Заполнить таблицы РСУ
  StringGrid_Length->RowCount = 3;
  StringGrid_Length->Cells[0][1] = "1";
  StringGrid_Length->Cells[1][1] = FloatToStr(Data_select.Length[0]/L1000);
  StringGrid_Length->Cells[2][1] = FloatToStr(Data_select.length_YY[0]/L1000);
  StringGrid_Length->Cells[3][1] = FloatToStr(Data_select.length_XX[0]/L1000);
  StringGrid_Length->Cells[4][1] = FloatToStr(Data_select.step_comp[0]/L1000);
  //-------------------------------------------------------------------
  StringGrid_RSU->ColCount = 8;
  StringGrid_RSU->Cells[7][0] = "X сеч., м";
  StringGrid_RSU->RowCount = Data_select.N_RSU[0] + 1;
  for (i=0; i<Data_select.N_RSU[0]; i++) {
	StringGrid_RSU->Cells[0][i+1] = IntToStr(i+1);
	for (j=0; j<5; j++) {
	  StringGrid_RSU->Cells[j+1][i+1] =  FloatToStr(Data_select.RSU[0][i][j]);
	}
	StringGrid_RSU->Cells[j+1][i+1] = Data_select.q_bal[0][i];
	StringGrid_RSU->Cells[j+2][i+1] = Data_select.X_sect[0][i];
  }
  Edit_N->Text = Data_select.RSU[n_plane][0][0];
  Edit_Mx->Text = Data_select.RSU[n_plane][0][1];
  Edit_Qy->Text = Data_select.RSU[n_plane][0][2];
  Edit_My->Text = Data_select.RSU[n_plane][0][3];
  Edit_Qx->Text = Data_select.RSU[n_plane][0][4];
  Edit_qy_->Text = Data_select.q_bal[n_plane][0];
  TabSheet_Part->TabVisible = true;
  if (Data_select.Length[0]/Data_select.step_up < 2) {
	  ComboBox_G1_Count->ItemIndex = 0;
  }
  if (Data_select.Length[0]/Data_select.step_up>=2 && Data_select.Length[0]/Data_select.step_up< 3 ){
	  ComboBox_G1_Count->ItemIndex = 2;
  }
  if (Data_select.Length[0]/Data_select.step_up>=3) {
	  ComboBox_G1_Count->ItemIndex = 1;
  }
  // Анализ, является ли балка разрезной
  if (BalkaLoadFrame1->MaxMy_R >0.01)   // относительная величина
	CheckBox_razrez->Checked = false;
  else
	CheckBox_razrez->Checked = true;
  OutRSU(1);
}
//---------------------------------------------------------------------------


void __fastcall TSelectProfilSectForm::BalkaLoadFrame1SpeedButton_CallCombinClick(TObject *Sender)

{
  BalkaLoadFrame1->SpeedButton_CallCombinClick(Sender);
  Draw_prof_ax(N_profil);

}
//---------------------------------------------------------------------------
// Показать эпюру напряжений
void __fastcall TSelectProfilSectForm::BitBtn_EpurClick(TObject *Sender)
{
   GEOM_PARAM_SECT param_sect;
   PARAM_PERFOR param_perfor;
   double attit;
   double alfa;
   double load[5];
   int rc;


   switch (Data_select.form_profil) {
   case DVUTAVR_STAND:    // Двутавр прокатной
   // Установить тип стандартного сечения
	 Data_select.type_profil = Data_select.index_profil + Data_select.index_GOST_or_TU;
	 StandartProfil.SetProfil(Data_select.type_profil);
   // Получить вектор имен профилей и длину вектора
	 //NameProfil = StandartProfil.GetVectorNameProfil(&n_profil);
	 rc = StandartProfil.SetParamProfil(&(com_sect.dvutavr), N_profil);
	 if (rc>0) return;
	 //Draw_dvutavr(Image_prof, &com_sect.dvutavr, vDIMETR, 1.2, 20, true);
	 //Draw_dvutavr_oblic(Image_prof, &com_sect.dvutavr);
	 //Draw_dvutavr(Draw_RSU_Frame1->Image1, &com_sect.dvutavr, vISOMETR, 4.0, 60, flag_sysc, false, 0, 0, length_0);
	 H_beam = com_sect.dvutavr.h + 2*com_sect.dvutavr.h1;
	 B_beam = com_sect.dvutavr.b1;
	 Get_param_sect_comm(DVUTAVR, &com_sect, &param_sect);

   break;
   case PERFOR_BEAM:
   // Установить тип стандартного сечения
	 Data_select.type_profil = Data_select.index_profil + Data_select.index_GOST_or_TU;
	 StandartProfil.SetProfil(Data_select.type_profil);
   // Получить вектор имен профилей и длину вектора
	 //NameProfil = StandartProfil.GetVectorNameProfil(&n_profil);
	 rc = StandartProfil.SetParamProfil(&(com_sect.dvutavr), N_profil);
	 if (rc>0) return;

	 rc = String_double_plus(Label_attit->Caption, ComboBox_attit->Text, &attit);
	 if (rc>0) return;

	 rc = String_double_range(Label_alfa->Caption, Edit_alfa->Text, 40.0, 70.0, &alfa);
	 if (rc>0) return;

	 com_sect.dvutavr.h *= attit;
	 //Draw_dvutavr(Draw_RSU_Frame1->Image1, &com_sect.dvutavr, vISOMETR, 4.0, 60, flag_sysc, true, attit, alfa, length_0);

	 H_beam = com_sect.dvutavr.h + 2*com_sect.dvutavr.h1;
	 B_beam = com_sect.dvutavr.b1;

	 com_sect.dvutavr.h /= attit;
	 Get_param_sect_perfor(&com_sect.dvutavr, &param_sect, com_sect.dvutavr.h*attit, &param_perfor);

   break;
   case TRUBA:    // Труба
	 StandartProfil.SetProfil_Tube(Data_select.type_profil);
	 rc = StandartProfil.SetParamProfil_Tube(&(com_sect), Data_select.type_profil, N_profil, 0);
	 if (rc>0) return;
	 //Draw_tube(Image_prof, &com_sect, Data_select.type_profil, vDIMETR, 1.2, 20, true);
	 //Draw_tube(Draw_RSU_Frame1->Image1, &com_sect, Data_select.type_profil, vISOMETR, 4.0, 70, flag_sysc, length_0);

	 Get_param_sect_comm(type_sect_tube, &com_sect, &param_sect);
	 H_beam = param_sect.Hsect;
	 B_beam = param_sect.Wsect;

   break;
   case DVUTAVR_WELD:    // Двутавр сварной

	 //Draw_dvutavr_weld(Draw_RSU_Frame1->Image1, &sect_weld, vISOMETR, 4.0, 70, flag_sysc, length_0);
	 Get_param_sect(&sect_weld, &param_sect);
	 H_beam = param_sect.Hsect;
	 B_beam = param_sect.Wsect;
   break;
   case COMPOSED_BEAM:    // Составная балка
	   switch (Data_select.index_composed) {
	   case TAVR_PLATE_DOWN:
	   case TAVR_PLATE_UP:
		 Data_select.type_profil = Data_select.index_profil + Data_select.index_TAVR_GOST_or_TU;
		 StandartProfil.SetProfil(Data_select.type_profil);

		 rc = StandartProfil.SetParamProfil(&(com_sect.dvutavr), N_profil);
		 if (rc>0) return;
		 Get_param_sect_composed(TAVR, &com_sect, Data_select.plate_width, Data_select.plate_thick, &param_sect, Data_select.index_composed);
	   break;
	   case DVUTAVR_PLATE_DOWN:
		 Data_select.type_profil = Data_select.index_profil + Data_select.index_GOST_or_TU;
		 StandartProfil.SetProfil(Data_select.type_profil);
		 rc = StandartProfil.SetParamProfil(&(com_sect.dvutavr), N_profil);
		 if (rc>0) return;
		 Get_param_sect_composed(DVUTAVR, &com_sect, Data_select.plate_width, Data_select.plate_thick, &param_sect, Data_select.index_composed);
		 break;
	 }
	 H_beam = param_sect.Hsect;
	 B_beam = param_sect.Wsect;
   break;
   }

   GetLoadFromRSU(load);

   double sigma_ext = load[0]*1e3/param_sect.Ar - load[1]*1e6*param_sect.Zct/param_sect.Izz;
   double sigma_int = load[0]*1e3/param_sect.Ar + load[1]*1e6*(param_sect.Hsect - param_sect.Zct)/param_sect.Izz;

   DrawRSUForm->sigma_ext = sigma_ext;
   DrawRSUForm->sigma_int = sigma_int;
   DrawRSUForm->Hsect = param_sect.Hsect;
   DrawRSUForm->index_draw = 1;

   if (!DrawRSUForm->Visible) {
	  DrawRSUForm->Show();
   }
   DrawRSUForm->Draw_Epur(Sender);


}
//---------------------------------------------------------------------------

void __fastcall TSelectProfilSectForm::ComboBox_G1_CountChange(TObject *Sender)
{
	ComboBox_G1_Load->Items->Clear();
	switch (ComboBox_G1_Count->ItemIndex) {
	case G1_NULL:
	  ComboBox_G1_Load->Items->Add("Сосредоточенная");
	  ComboBox_G1_Load->Items->Add("Равномерно распределенная");
	  ComboBox_G1_Load->ItemIndex = 1;
	break;
	case G1_TWO_MORE:
	  ComboBox_G1_Load->Items->Add("Любая");
	  ComboBox_G1_Load->ItemIndex = 0;
	break;
	case G1_ONE:
	  ComboBox_G1_Load->Items->Add("Сосредоточенная в середине");
	  ComboBox_G1_Load->Items->Add("Сосредоточенная в четверти");
	  ComboBox_G1_Load->Items->Add("Равномерно распределенная");
	  ComboBox_G1_Load->ItemIndex = 2;
	break;
	}
}
//---------------------------------------------------------------------------
//
void __fastcall TSelectProfilSectForm::RadioGroup_Schema_constrClick(TObject *Sender)
{
  if (RadioGroup_Schema_constr->ItemIndex==0) {    // балка на опорах
	 Label_G1_Count->Visible = true;
	 ComboBox_G1_Count->Visible = true;

	 Label_G1_Load->Caption = "Вид нагрузки в пролете";
	 ComboBox_G1_CountChange(Sender);
  }
  else {                                          // жестко заделанная консоль
	 Label_G1_Count->Visible = false;
	 ComboBox_G1_Count->Visible = false;

	 Label_G1_Load->Caption = "Вид нагрузки";
	 ComboBox_G1_Load->Items->Clear();
	 ComboBox_G1_Load->Items->Add("Сосредоточенная на конце консоли");
	 ComboBox_G1_Load->Items->Add("Равномерно распределенная");
	 ComboBox_G1_Load->ItemIndex = 1;

  }
}
//---------------------------------------------------------------------------

void __fastcall TSelectProfilSectForm::Sect_Param_WeldFrame1Edit_b1Exit(TObject *Sender)

{
  Sect_Param_WeldFrame1->Edit_h2Exit(Sender);
  Draw_prof_ax(-1);

}
//---------------------------------------------------------------------------


void __fastcall TSelectProfilSectForm::Sect_Param_WeldFrame1Edit_h1Exit(TObject *Sender)

{
  Sect_Param_WeldFrame1->Edit_h2Exit(Sender);
  Draw_prof_ax(-1);
}
//---------------------------------------------------------------------------

void __fastcall TSelectProfilSectForm::Sect_Param_WeldFrame1Edit_h_1Exit(TObject *Sender)

{
  Sect_Param_WeldFrame1->Edit_h2Exit(Sender);
  Draw_prof_ax(-1);

}
//---------------------------------------------------------------------------


void __fastcall TSelectProfilSectForm::Sect_Param_WeldFrame1Edit_bExit(TObject *Sender)

{
  Sect_Param_WeldFrame1->Edit_h2Exit(Sender);
  Draw_prof_ax(-1);

}
//---------------------------------------------------------------------------

void __fastcall TSelectProfilSectForm::Sect_Param_WeldFrame1Edit_b2Exit(TObject *Sender)

{
  Sect_Param_WeldFrame1->Edit_h2Exit(Sender);
  Draw_prof_ax(-1);

}
//---------------------------------------------------------------------------

void __fastcall TSelectProfilSectForm::Sect_Param_WeldFrame1Edit_h2Exit(TObject *Sender)

{
  Sect_Param_WeldFrame1->Edit_h2Exit(Sender);
  Draw_prof_ax(-1);

}
//---------------------------------------------------------------------------


void __fastcall TSelectProfilSectForm::CheckBox_edge_chooseClick(TObject *Sender)

{
	if (CheckBox_edge_choose->Checked) {
		RadioGroup_1_or_2->Visible = true;
		CheckBox_edge->Checked = false;
	}
	else {
		RadioGroup_1_or_2->Visible = false;
	}
}
//---------------------------------------------------------------------------

void __fastcall TSelectProfilSectForm::CheckBox_edgeClick(TObject *Sender)
{
	if (CheckBox_edge->Checked)
		CheckBox_edge_choose->Checked = false;
}
//---------------------------------------------------------------------------
// Составная балка
void __fastcall TSelectProfilSectForm::RadioButton_ComposedBeamClick(TObject *Sender)

{
	if (RadioButton_ComposedBeam->Checked) {
	  //Сохранение копии происходит в
	  BitBtnExec->Enabled = true;
	  Label_step_comp->Visible = true;
	  Edit_step_comp->Visible = true;
	  Label_step_prim->Visible = true;
	  TabSheet_Weld->TabVisible = false;
	  TabSheetPerfor->TabVisible = false;
	  TabSheet_sect_prof->TabVisible = true;
	  TabSheet_KI->TabVisible = false;
	  CheckBoxAddLimit->Visible = true;
	  CheckBoxAddLimit->Checked = false;
	  CheckBox_edge->Enabled = true;
	  CheckBox_edge_choose->Visible = true;
	  RadioGroup_1_or_2->Visible = false;
	  RadioGroup_Loads->Visible = true;
	  SpeedButton_WeldParam->Visible = true;

	  RadioButton_Tube->Checked = false;
	  RadioButton_Weld->Checked = false;
	  PageControl_Dvutavr->Visible = false;
	  ComboBox_Tube->Visible = false;
	  ComboBox_ComposedBeam->Visible = true;
	  RadioButton_ComposedBeam->Checked = true;

	  Data_select.form_profil = COMPOSED_BEAM;

	  ComboBox_ComposedBeamChange(Sender);    // Здесь устанавливается панель либо двутавра, либо тавра

	  BalkaLoadFrame1->ConfigForm_profil(COMPOSED_BEAM, Sender);

	  Label_add_conditions->Caption = " ";
	  //Define_Material_ARSSForm->ComboBox_gost->ItemIndex = 1;
	  //Define_Material_ARSSForm->ComboBox_gostChange(Sender);
	  // Установить список материалов, соответствующих фасонному прокату,
	  Define_Material_ARSSForm->Set_Material_name(DVUTAVR_STAND, Data_select.index_GOST, Data_select.title_material);
	  Panel_mater->Caption = Define_Material_ARSSForm->ComboBox_steel->Text;
	  CheckBox_same_material->Visible = false;
	  CheckBox_same_material->Caption = "Материал профиля и пластины различный";
	  CheckBox_same_material->Checked = Data_select.index_same_material;
	  // Здесь устанавливается материал
	  CheckBox_same_materialClick(Sender);

	  ComboBox_TypeElemChange(Sender);
	  Config_RSU(DVUTAVR_STAND);
	  flag_change_rsu = false;

	  GroupBox_bend->Visible = true;
	  // Нарисовать профиль и оси координат прокатного двутавра
	  N_profil = SectSelectCom_ParamFrame1->ComboBox_profil->ItemIndex;

	  Show_prof(0, Sender);

	  Draw_prof_ax(N_profil);
	  modify_project = true;
      // Заполнение панели радио-кнопок РСУ-Балка-Стойка
	  RadioGroup_Loads_Fill(1);
	  // Вернуть активную вкладку, т.к она переключается в RadioGroup_Loads_Fill
      PageControl_Data->ActivePage = TabSheet_Common;
	}
}
//---------------------------------------------------------------------------
void __fastcall TSelectProfilSectForm::ComboBox_ComposedBeamChange(TObject *Sender)
{
       SaveTemp(Sender);

		//ComboBox_Dvutavr_compChange(Sender);

		switch (ComboBox_ComposedBeam->ItemIndex) {
		case TAVR_PLATE_DOWN:
		case TAVR_PLATE_UP:
		  Type_sect = TAVR;
		  Data_select.index_composed = ComboBox_ComposedBeam->ItemIndex;
		  SectSelectCom_ParamFrame2->TabSheet_TavrStandart->TabVisible = true;
		  SectSelectCom_ParamFrame2->TabSheet_Standart->TabVisible = false;

		  SectSelectCom_ParamFrame2PageControl_TavrChange(Sender);
		  /*
		  if (Data_select.index_TAVR_GOST_or_TU==typeTAVR_BT)
			 Data_select.index_profil = SectSelectCom_ParamFrame2->RadioGroup_Tavr_GOST->ItemIndex;
		  else
			 Data_select.index_profil = SectSelectCom_ParamFrame2->RadioGroup_Tavr_TU->ItemIndex;
		// Нарисовать профиль и оси координат прокатного тавра
		  N_profil = MAX(0, SectSelectCom_ParamFrame2->ComboBox_Tavr->ItemIndex);
		  Draw_prof_ax(N_profil);
		  */
		  Data_select.type_profil = Data_select.index_profil + Data_select.index_TAVR_GOST_or_TU;
		  Show_prof(0, Sender);

		  modify_project = true;
		break;
		case DVUTAVR_PLATE_DOWN:
		  Type_sect = DVUTAVR;
		  Data_select.index_composed = DVUTAVR_PLATE_DOWN;
		  //ComboBox_Dvutavr->ItemIndex = Data_select.index_profil;
		  SectSelectCom_ParamFrame2->TabSheet_TavrStandart->TabVisible = false;
		  SectSelectCom_ParamFrame2->TabSheet_Standart->TabVisible = true;

		  SectSelectCom_ParamFrame2PageControl_StandDvutChange(Sender);
		  /*
		  if (Data_select.index_GOST_or_TU==typeTU_U)
			Data_select.index_profil = SectSelectCom_ParamFrame2->RadioGroup_TU->ItemIndex;
		  else
			Data_select.index_profil = SectSelectCom_ParamFrame2->RadioGroupGOST57837->ItemIndex;

		// Нарисовать профиль и оси координат прокатного двутавра
		  N_profil = MAX(0, SectSelectCom_ParamFrame2->ComboBox_profil->ItemIndex);
		  Draw_prof_ax(N_profil);
		  */
		  Data_select.type_profil = Data_select.index_profil + Data_select.index_GOST_or_TU;
		  Show_prof(0, Sender);

		  modify_project = true;      //Data_select.type_profil
		  Edit_alfaEnter(Sender);
		break;

		}
}
//---------------------------------------------------------------------------
#include "SelectProfilSect%Executive.cpp"
#include "SelectProfilSect%SectSelect2.cpp"





void __fastcall TSelectProfilSectForm::ComboBox_Tavr_compChange(TObject *Sender)
{
		Data_select.index_profil = ComboBox_Tavr_comp->ItemIndex;
		// Нарисовать профиль и оси координат прокатного двутавра
		N_profil = SectSelectCom_ParamFrame2->ComboBox_Tavr->ItemIndex;
		Draw_prof_ax(N_profil);

		Data_select.index_profil = ComboBox_Tavr_comp->ItemIndex;
		Data_select.type_profil = Data_select.index_profil + typeTAVR_BT;
		Show_prof(0, Sender);

		modify_project = true;
		Edit_alfaEnter(Sender);
}
//---------------------------------------------------------------------------

void __fastcall TSelectProfilSectForm::FormCloseQuery(TObject *Sender, bool &CanClose)

{
	 bool rb = CheckModified(Sender);
     if (rb==false) CanClose = false;

	 //RemoveTempFile();

}
//---------------------------------------------------------------------------
//----------------------------------------------------------------------------
bool __fastcall TSelectProfilSectForm::CheckModified(TObject *Sender)
{
	// Диалог о сохранении модифицированной модели
     int i, k, rc;
     bool rc_bool;
	 String text;
	 String header;


	 if (modify_project) {
	   text="Изменения в проекте " + ModelFile + " не сохранены. Сохранить ?";
	   header="Сохранение проекта в архиве";
	   i=Application->MessageBox(text.c_str(),
				  header.c_str(),
				  MB_YESNOCANCEL | MB_ICONQUESTION);
	   switch (i) {
	   case IDYES:
		 NSaveClick(Sender);
		 goto Ret_true;
	   case IDNO:
		  k = Application->MessageBox(L"Текущий проект будет закрыт без сохранения! Закрыть проект?",
				  L" ",
				  MB_YESNO | MB_ICONQUESTION);
		  if (k==IDYES) {
			goto Ret_true;
		 }
		  else
			return false;
	   case IDCANCEL:
		  return false;
	   }
	 }
	 else {
		 k = Application->MessageBox(L"Закрыть текущий проект?",
				  L" ",
                  MB_YESNO | MB_ICONQUESTION);
          if (k==IDYES) {
           goto Ret_true;
          }
          else
            return false;
       }
Ret_true:
	 return true;
}
//---------------------------------------------------------------------------

void __fastcall TSelectProfilSectForm::SpeedButton_WeldParamClick(TObject *Sender)

{
		 Weld_unit = &Weld_balka_unit;
		 Weld_balka_unit.flag_weld = false;

		 Weld_ParamForm->ShowModal();

		 if (!Weld_balka_unit.flag_weld)
			return;
		 Data_select.index_vid_svarki = Weld_ParamForm->index_vid_svarki;
		 Data_select.index_weld_param = 1;
		 Data_select.Rwf = Weld_balka_unit.Rwf;

}
//---------------------------------------------------------------------------
void __fastcall TSelectProfilSectForm::SectSelectCom_ParamFrame2RadioGroupGOST57837Click(TObject *Sender)
{

  SectSelectCom_ParamFrame2->RadioGroupGOST57837Click(Sender);
  // На невидимой панели Общей вкладки
  ComboBox_Dvutavr_comp->ItemIndex = SectSelectCom_ParamFrame2->RadioGroupGOST57837->ItemIndex;
  Data_select.index_profil = ComboBox_Dvutavr->ItemIndex;
  // Здесь читаются все параметры составного сечения
  SectSelectCom_ParamFrame2ComboBox_profilChange(Sender);
}
//---------------------------------------------------------------------------
void __fastcall TSelectProfilSectForm::SectSelectCom_ParamFrame2RadioGroup_Tavr_GOSTClick(TObject *Sender)
{
  SectSelectCom_ParamFrame2->RadioGroup_Tavr_GOSTClick(Sender);
  // На невидимой панели Общей вкладки
  ComboBox_Tavr_comp->ItemIndex = SectSelectCom_ParamFrame2->RadioGroup_Tavr_GOST->ItemIndex;
  Data_select.index_profil = SectSelectCom_ParamFrame2->RadioGroup_Tavr_GOST->ItemIndex;
  // Здесь читаются все параметры составного таврового сечения
  SectSelectCom_ParamFrame2ComboBox_TavrChange(Sender);
}
//---------------------------------------------------------------------------
void __fastcall TSelectProfilSectForm::SectSelectCom_ParamFrame2Button_ApplyClick(TObject *Sender)
{
	if (SectSelectCom_ParamFrame2->TabSheet_Standart->TabVisible) {
	   if (Data_select.index_GOST_or_TU==typeTU_U)
		 SectSelectCom_ParamFrame2RadioGroup_TUClick(Sender);
	   else
		 SectSelectCom_ParamFrame2RadioGroupGOST57837Click(Sender);
	}
	else {
	   if (Data_select.index_TAVR_GOST_or_TU==typeTAVR_BT)
		 SectSelectCom_ParamFrame2RadioGroup_Tavr_GOSTClick(Sender);
	   else
		 SectSelectCom_ParamFrame2RadioGroup_Tavr_TUClick(Sender);
	}

}
//---------------------------------------------------------------------------
void __fastcall TSelectProfilSectForm::SectSelectCom_ParamFrame2ComboBox_TavrChange(TObject *Sender)

{
  double ss;
  Label_mass_c->Caption = "";
  Label_conditions_c->Caption = "";
  Label_add_conditions_c->Caption = "";
  TabSheet_KI->TabVisible = false;
  flag_checking = false;

  SectSelectCom_ParamFrame2->ComboBox_TavrChange(Sender);

  if (Data_select.index_TAVR_GOST_or_TU==typeTAVR_BT)
	Data_select.index_profil = SectSelectCom_ParamFrame2->RadioGroup_Tavr_GOST->ItemIndex;
  else
	Data_select.index_profil = SectSelectCom_ParamFrame2->RadioGroup_Tavr_TU->ItemIndex;
  Data_select.type_profil = Data_select.index_profil + Data_select.index_TAVR_GOST_or_TU;

  N_profil = SectSelectCom_ParamFrame2->ComboBox_Tavr->ItemIndex;

  int rc = String_double_plus(Label_width_comp->Caption, Edit_width_comp->Text, &ss);
  if (rc>0) return;

  Last_type_sect = TAVR;
  // ComboBox_TavrChange
  if (Data_select.index_composed==0 || Data_select.index_composed==2) {
	if ((ABS(ss - (common_sect->tavr.b1 + 2*100))) > 10.0) {
	  double ss_opt = Round_step_floor(common_sect->tavr.b1 + 2*100, 10);
	  rc = Application->MessageBox((L"Рекомендуемая ширина пластины "+
								  FloatToStr(ss_opt)+" мм. Изменить?").c_str(), L"",
								  MB_YESNO | MB_ICONQUESTION);
	  if (rc==IDYES)
		Edit_width_comp->Text = FloatToStr(ss_opt);
	}
	rc = String_double_plus(Label_width_comp->Caption, Edit_width_comp->Text, &ss);
	if (rc>0) return;
	if (ss < (common_sect->tavr.b1 + 2*80)) {
	  double ss_opt = Round_step(common_sect->tavr.b1 + 2*80, 10);
	  rc = Application->MessageBox((L"Ширина пластины должна быть больше"+
								  FloatToStr(ss_opt)+" мм. Принять?").c_str(), L"",
								  MB_YESNO | MB_ICONQUESTION);
	  if (rc==IDYES)
		Edit_width_comp->Text = FloatToStr(ss_opt);
	}
  }
  else {
	if ((ABS(ss - (common_sect->tavr.b1 - 2*102))) > 10.0) {
	  double ss_opt = Round_step(common_sect->tavr.b1 - 2*102, 10);
	  if (ss_opt < 50 ) { // common_sect->tavr.b
		rc = Application->MessageBox(L"Ширина полки тавра недостаточна для того, чтобы ширина верхней пластины была больше 50 мм", L"",
								  MB_OK | MB_ICONERROR);
        return;
	  }
	  else {
		rc = Application->MessageBox((L"Рекомендуемая ширина пластины "+
								  FloatToStr(ss_opt)+" мм. Изменить?").c_str(), L"",
								  MB_YESNO | MB_ICONQUESTION);
		if (rc==IDYES)
		  Edit_width_comp->Text = FloatToStr(ss_opt);
	  }
	}
	rc = String_double_plus(Label_width_comp->Caption, Edit_width_comp->Text, &ss);
	if (rc>0) return;
	if (ss > (common_sect->tavr.b1 - 2*80)) {
	  double ss_opt = Round_step(common_sect->tavr.b1 - 2*80, 10);
	  rc = Application->MessageBox((L"Ширина пластины должна быть меньше"+
								  FloatToStr(ss_opt)+" мм. Принять?").c_str(), L"",
								  MB_YESNO | MB_ICONQUESTION);
	  if (rc==IDYES)
		Edit_width_comp->Text = FloatToStr(ss_opt);
	}

  }


  Draw_prof_ax(N_profil);
  // Повторить после чтения ширины и толщины плястины
  // Нарисовать профиль прокатного тавра
  SectSelectCom_ParamFrame2->ComboBox_TavrChange(Sender);
  Fill_param_comp();


}
//---------------------------------------------------------------------------

void __fastcall TSelectProfilSectForm::SectSelectCom_ParamFrame2ComboBox_profilChange(TObject *Sender)

{
  double ss;
  Label_mass_c->Caption = "";
  Label_conditions_c->Caption = "";
  Label_add_conditions_c->Caption = "";
  TabSheet_KI->TabVisible = false;
  flag_checking = false;

  SectSelectCom_ParamFrame2->ComboBox_profilChange(Sender);
  // Нарисовать профиль прокатного двутавра
  if (Data_select.index_GOST_or_TU==typeTU_U)
	Data_select.index_profil = SectSelectCom_ParamFrame2->RadioGroup_TU->ItemIndex;
  else
	Data_select.index_profil = SectSelectCom_ParamFrame2->RadioGroupGOST57837->ItemIndex;
  Data_select.type_profil = Data_select.index_profil + Data_select.index_GOST_or_TU;

  N_profil = SectSelectCom_ParamFrame2->ComboBox_profil->ItemIndex;

  int rc = String_double_plus(Label_width_comp->Caption, Edit_width_comp->Text, &ss);
  if (rc>0) return;

  Last_type_sect = DVUTAVR;
  // ComboBox_profilChange

  if ((ABS(ss - (common_sect->tavr.b1 + 2*100))) > 10.0) {
	  double ss_opt = Round_step_floor(common_sect->tavr.b1 + 2*100, 10);
	  rc = Application->MessageBox((L"Рекомендуемая ширина пластины "+
								  FloatToStr(ss_opt)+" мм. Изменить?").c_str(), L"",
								  MB_YESNO | MB_ICONQUESTION);
	  if (rc==IDYES)
		Edit_width_comp->Text = FloatToStr(ss_opt);
  }
  rc = String_double_plus(Label_width_comp->Caption, Edit_width_comp->Text, &ss);
  if (rc>0) return;
  if (ss < (common_sect->tavr.b1 + 2*80)) {
	  double ss_opt = Round_step(common_sect->tavr.b1 + 2*80, 10);
	  rc = Application->MessageBox((L"Ширина пластины должна быть больше"+
								  FloatToStr(ss_opt)+" мм. Принять?").c_str(), L"",
								  MB_YESNO | MB_ICONQUESTION);
	  if (rc==IDYES)
		Edit_width_comp->Text = FloatToStr(ss_opt);
  }

  Draw_prof_ax(N_profil);
  // Повторить после чтения шинины и толщины пластины
  // Нарисовать профиль прокатного двутавра
  SectSelectCom_ParamFrame2->ComboBox_profilChange(Sender);
  Fill_param_comp();

}
// Выбор типа прокатного двутавра ТУ
void __fastcall TSelectProfilSectForm::ComboBox_Dvutavr_TUChange(TObject *Sender)

{
		Data_select.index_profil = ComboBox_Dvutavr_TU->ItemIndex;
		SectSelectCom_ParamFrame1->TabSheet_TU->TabVisible = true;
		SectSelectCom_ParamFrame1->PageControl_StandDvut->ActivePage = TabSheet_TU;
		SectSelectCom_ParamFrame1->TabSheet_GOST57837->TabVisible = false;
		// Нарисовать профиль и оси координат прокатного двутавра
		N_profil = SectSelectCom_ParamFrame1->ComboBox_profil->ItemIndex;
		Draw_prof_ax(N_profil);

		Data_select.index_profil = ComboBox_Dvutavr_TU->ItemIndex;
		Data_select.type_profil = Data_select.index_profil + typeTU_U;
		Show_prof(0, Sender);

		modify_project = true;
		Edit_alfaEnter(Sender);

}
//---------------------------------------------------------------------------

void __fastcall TSelectProfilSectForm::PageControl_DvutavrChange(TObject *Sender)

{
	if (PageControl_Dvutavr->ActivePage == TabSheet_GOST) {
	  Data_select.index_GOST_or_TU = typeGOST_G57837_B;
	  ComboBox_DvutavrChange(Sender);
	}
	if (PageControl_Dvutavr->ActivePage == TabSheet_TU)  {
	  Data_select.index_GOST_or_TU = typeTU_U;
	  ComboBox_Dvutavr_TUChange(Sender);
	}

}
//---------------------------------------------------------------------------

void __fastcall TSelectProfilSectForm::SectSelectCom_ParamFrame1RadioGroup_TUClick(TObject *Sender)

{
  SectSelectCom_ParamFrame1->RadioGroup_TUClick(Sender);
  ComboBox_Dvutavr->ItemIndex = SectSelectCom_ParamFrame1->RadioGroup_TU->ItemIndex;
  Label_mass->Caption = "";
  Label_conditions->Caption = "";
  TabSheet_KI->TabVisible = false;
  flag_checking = false;
  // Нарисовать профиль прокатного двутавра
  Data_select.index_profil = ComboBox_Dvutavr->ItemIndex;
  Data_select.type_profil = Data_select.index_profil + Data_select.index_GOST_or_TU;

  N_profil = SectSelectCom_ParamFrame1->ComboBox_profil->ItemIndex;
  Draw_prof_ax(N_profil);

  if (Data_select.form_profil==PERFOR_BEAM) {
	  AnsiString Astr = Edit_alfa->Text;
	  int rc;
	  double alfa = str_exp(Astr.c_str(), &rc);
	  if (rc>0 || alfa<40 || alfa>70)
		return;
	  double attid;
	  rc = String_double_plus(Label_attit->Caption, ComboBox_attit->Text, &attid);
	  if (rc>0) return;
	  // Нарисовать проекции перфорированного профиля
	  Show_prof_perfor(N_profil, Sender, attid, alfa, false);
  }




}
//---------------------------------------------------------------------------
void __fastcall TSelectProfilSectForm::SectSelectCom_ParamFrame2RadioGroup_TUClick(TObject *Sender)

{
  SectSelectCom_ParamFrame2->RadioGroup_TUClick(Sender);
  // На невидимой панели Общей вкладки
  ComboBox_Dvutavr_comp->ItemIndex = SectSelectCom_ParamFrame2->RadioGroup_TU->ItemIndex;
  Data_select.index_profil = ComboBox_Dvutavr_TU->ItemIndex;
  // Здесь читаются все параметры составного сечения
  SectSelectCom_ParamFrame2ComboBox_profilChange(Sender);

}
//---------------------------------------------------------------------------

void __fastcall TSelectProfilSectForm::SectSelectCom_ParamFrame2RadioGroup_Tavr_TUClick(TObject *Sender)
{
  SectSelectCom_ParamFrame2->RadioGroup_Tavr_TUClick(Sender);
  // На невидимой панели Общей вкладки
  ComboBox_Tavr_comp->ItemIndex = SectSelectCom_ParamFrame2->RadioGroup_Tavr_TU->ItemIndex;
  Data_select.index_profil = SectSelectCom_ParamFrame2->RadioGroup_Tavr_TU->ItemIndex;
  // Здесь читаются все параметры составного таврового сечения
  SectSelectCom_ParamFrame2ComboBox_TavrChange(Sender);

}
//---------------------------------------------------------------------------
void __fastcall TSelectProfilSectForm::SectSelectCom_ParamFrame2PageControl_StandDvutChange(TObject *Sender)
{
  SectSelectCom_ParamFrame2->PageControl_StandDvutChange(Sender);
  Data_select.index_GOST_or_TU = SectSelectCom_ParamFrame2->index_GOST_or_TU;
  if (Data_select.index_GOST_or_TU==typeTU_U)
	SectSelectCom_ParamFrame2RadioGroup_TUClick(Sender);
  else
	SectSelectCom_ParamFrame2RadioGroupGOST57837Click(Sender);

  N_profil = SectSelectCom_ParamFrame2->ComboBox_profil->ItemIndex;

  Draw_prof_ax(N_profil);

}
//---------------------------------------------------------------------------
void __fastcall TSelectProfilSectForm::SectSelectCom_ParamFrame2PageControl_TavrChange(TObject *Sender)

{
  SectSelectCom_ParamFrame2->PageControl_TavrChange(Sender);
  Data_select.index_TAVR_GOST_or_TU = SectSelectCom_ParamFrame2->index_TAVR_GOST_or_TU;
  if (Data_select.index_TAVR_GOST_or_TU==typeTAVR_BT)
	SectSelectCom_ParamFrame2RadioGroup_Tavr_GOSTClick(Sender);
  else
	SectSelectCom_ParamFrame2RadioGroup_Tavr_TUClick(Sender);

  N_profil = SectSelectCom_ParamFrame2->ComboBox_Tavr->ItemIndex;

  Draw_prof_ax(N_profil);

}
//---------------------------------------------------------------------------



void __fastcall TSelectProfilSectForm::RackLoadFrame1SpeedButton_ApplyClick(TObject *Sender)

{
  RackLoadFrame1->SpeedButton_ApplyClick(Sender);

  Draw_prof_ax(N_profil);

}
//---------------------------------------------------------------------------

void __fastcall TSelectProfilSectForm::RackLoadFrame1ComboBox_num_zagrChange(TObject *Sender)

{
  RackLoadFrame1->ComboBox_num_zagrChange(Sender);
  Draw_prof_ax(N_profil);

}
//---------------------------------------------------------------------------

void __fastcall TSelectProfilSectForm::RackLoadFrame1BitBtn_AddClick(TObject *Sender)

{
  RackLoadFrame1->BitBtn_AddClick(Sender);
  Draw_prof_ax(N_profil);
}
//---------------------------------------------------------------------------

void __fastcall TSelectProfilSectForm::RackLoadFrame1BitBtnDeleteClick(TObject *Sender)

{
	 RackLoadFrame1->BitBtnDeleteClick(Sender);
	 Draw_prof_ax(N_profil);

}
//---------------------------------------------------------------------------

void __fastcall TSelectProfilSectForm::RackLoadFrame1BitBtn_ReplaceClick(TObject *Sender)

{
  RackLoadFrame1->BitBtn_ReplaceClick(Sender);
  Draw_prof_ax(N_profil);

}
//---------------------------------------------------------------------------

void __fastcall TSelectProfilSectForm::RackLoadFrame1SpeedButton_AddClick(TObject *Sender)

{
  RackLoadFrame1->SpeedButton_AddClick(Sender);
  Draw_prof_ax(N_profil);

}
//---------------------------------------------------------------------------

void __fastcall TSelectProfilSectForm::RackLoadFrame1SpeedButtonDeleteClick(TObject *Sender)

{
  RackLoadFrame1->SpeedButtonDeleteClick(Sender);
  Draw_prof_ax(N_profil);

}
//---------------------------------------------------------------------------

void __fastcall TSelectProfilSectForm::RackLoadFrame1BitBtn_AddZClick(TObject *Sender)

{
  RackLoadFrame1->BitBtn_AddClick(Sender);
  Draw_prof_ax(N_profil);

}
//---------------------------------------------------------------------------

void __fastcall TSelectProfilSectForm::RackLoadFrame1BitBtn_ReplaceZClick(TObject *Sender)

{
  RackLoadFrame1->BitBtn_ReplaceClick(Sender);
  Draw_prof_ax(N_profil);

}
//---------------------------------------------------------------------------

void __fastcall TSelectProfilSectForm::RackLoadFrame1BitBtn_DeleteZClick(TObject *Sender)

{
  RackLoadFrame1->BitBtnDeleteClick(Sender);
  Draw_prof_ax(N_profil);

}
//---------------------------------------------------------------------------


void __fastcall TSelectProfilSectForm::RackLoadFrame1SpeedButtonAppStepClick(TObject *Sender)

{
  RackLoadFrame1->SpeedButtonAppStepClick(Sender);
  Draw_prof_ax(N_profil);

}
//---------------------------------------------------------------------------


void __fastcall TSelectProfilSectForm::RackLoadFrame1BitBtn_ApplyConstrClick(TObject *Sender)

{
  RackLoadFrame1->BitBtn_ApplyConstrClick(Sender);
  Draw_prof_ax(N_profil);


}
//---------------------------------------------------------------------------

void __fastcall TSelectProfilSectForm::RackLoadFrame1SpeedButtonFix_FreeClick(TObject *Sender)

{
  RackLoadFrame1->SpeedButtonFix_FreeClick(Sender);
  Draw_prof_ax(N_profil);


}
//---------------------------------------------------------------------------

void __fastcall TSelectProfilSectForm::RackLoadFrame1SpeedButtonFix_PinClick(TObject *Sender)

{
  RackLoadFrame1->SpeedButtonFix_PinClick(Sender);
  Draw_prof_ax(N_profil);

}
//---------------------------------------------------------------------------

void __fastcall TSelectProfilSectForm::RackLoadFrame1SpeedButtonFix_FixClick(TObject *Sender)

{
  RackLoadFrame1->SpeedButtonFix_FixClick(Sender);
  Draw_prof_ax(N_profil);

}
//---------------------------------------------------------------------------

void __fastcall TSelectProfilSectForm::RackLoadFrame1SpeedButtonPin_PinClick(TObject *Sender)

{
  RackLoadFrame1->SpeedButtonPin_PinClick(Sender);
  Draw_prof_ax(N_profil);

}
//---------------------------------------------------------------------------

void __fastcall TSelectProfilSectForm::RackLoadFrame1SpeedButtonPin_FixClick(TObject *Sender)

{
  RackLoadFrame1->SpeedButtonPin_FixClick(Sender);
  Draw_prof_ax(N_profil);

}
//---------------------------------------------------------------------------
// Создать РСУ для стойки
void __fastcall TSelectProfilSectForm::RackLoadFrame1BitBtn_CreateRSUClick(TObject *Sender)

{
  int i, j;
  int k;
  bool flag_repeat;
  // Вычислить РСУ
  RackLoadFrame1->BitBtn_CreateRSUClick(Sender);

  Data_select.MaxV0 = RackLoadFrame1->MaxV;
  Data_select.MaxV = RackLoadFrame1->MaxV;
  Data_select.MaxV_W = RackLoadFrame1->MaxV_W;
  Data_select.Span = RackLoadFrame1->Span;

  Data_select.N_plane =  RackLoadFrame1->N_part;
  for (i=0; i<Data_select.N_plane; i++) {
	k=0;
	if (RackLoadFrame1->MaxN[i][0]>0) {
	  Data_select.RSU[i][k][0] = RackLoadFrame1->MaxN[i][0]/F1000;
	  Data_select.RSU[i][k][1] = RackLoadFrame1->MaxN[i][2]/F1000;
	  Data_select.RSU[i][k][2] = RackLoadFrame1->MaxN[i][1]/F1000;
	  Data_select.RSU[i][k][3] = RackLoadFrame1->MaxN[i][4]/F1000;
	  Data_select.RSU[i][k][4] = RackLoadFrame1->MaxN[i][3]/F1000;
	  Data_select.X_sect[i][k] = RackLoadFrame1->MaxN[i][5]/L1000;
	  Data_select.q_bal[i][k] = 0;
	  Data_select.RSU_W[k][0] = RackLoadFrame1->MaxN_W[i][0]/F1000;
	  Data_select.RSU_W[k][1] = RackLoadFrame1->MaxN_W[i][2]/F1000;
	  Data_select.RSU_W[k][2] = RackLoadFrame1->MaxN_W[i][1]/F1000;
	  Data_select.RSU_W[k][3] = RackLoadFrame1->MaxN_W[i][4]/F1000;
	  Data_select.RSU_W[k][4] = RackLoadFrame1->MaxN_W[i][3]/F1000;
	  k++;
	}
	if (RackLoadFrame1->MinN[0]<0) {
	  Data_select.RSU[i][k][0] = RackLoadFrame1->MinN[i][0]/F1000;
	  Data_select.RSU[i][k][1] = RackLoadFrame1->MinN[i][2]/F1000;
	  Data_select.RSU[i][k][2] = RackLoadFrame1->MinN[i][1]/F1000;
	  Data_select.RSU[i][k][3] = RackLoadFrame1->MinN[i][4]/F1000;
	  Data_select.RSU[i][k][4] = RackLoadFrame1->MinN[i][3]/F1000;
	  Data_select.X_sect[i][k] = RackLoadFrame1->MinN[i][5]/L1000;
	  Data_select.q_bal[i][k] = 0;
	  Data_select.RSU_W[k][0] = RackLoadFrame1->MinN_W[i][0]/F1000;
	  Data_select.RSU_W[k][1] = RackLoadFrame1->MinN_W[i][2]/F1000;
	  Data_select.RSU_W[k][2] = RackLoadFrame1->MinN_W[i][1]/F1000;
	  Data_select.RSU_W[k][3] = RackLoadFrame1->MinN_W[i][4]/F1000;
	  Data_select.RSU_W[k][4] = RackLoadFrame1->MinN_W[i][3]/F1000;
	  k++;
	}
	flag_repeat = false;
	for (j=0; j<k; j++) {
	  if ((ABS(RackLoadFrame1->MaxQ[i][1]/F1000 - Data_select.RSU[i][j][2]))<1e-3)
		flag_repeat = true;
	}
	if (RackLoadFrame1->MaxQ[1]>0 && !flag_repeat) {
	  Data_select.RSU[i][k][0] = RackLoadFrame1->MaxQ[i][0]/F1000;
	  Data_select.RSU[i][k][1] = RackLoadFrame1->MaxQ[i][2]/F1000;
	  Data_select.RSU[i][k][2] = RackLoadFrame1->MaxQ[i][1]/F1000;
	  Data_select.RSU[i][k][3] = RackLoadFrame1->MaxQ[i][4]/F1000;
	  Data_select.RSU[i][k][4] = RackLoadFrame1->MaxQ[i][3]/F1000;
	  Data_select.X_sect[i][k] = RackLoadFrame1->MaxQ[i][5]/L1000;
	  Data_select.q_bal[i][k] = 0;
	  Data_select.RSU_W[k][0] = RackLoadFrame1->MaxQ_W[i][0]/F1000;
	  Data_select.RSU_W[k][1] = RackLoadFrame1->MaxQ_W[i][2]/F1000;
	  Data_select.RSU_W[k][2] = RackLoadFrame1->MaxQ_W[i][1]/F1000;
	  Data_select.RSU_W[k][3] = RackLoadFrame1->MaxQ_W[i][4]/F1000;
	  Data_select.RSU_W[k][4] = RackLoadFrame1->MaxQ_W[i][3]/F1000;
	  k++;
	}
	flag_repeat = false;
	for (j=0; j<k; j++) {
	  if ((ABS(RackLoadFrame1->MaxM[i][1]/F1000 - Data_select.RSU[i][j][1]))<1e-3)
		flag_repeat = true;
	}
	if (RackLoadFrame1->MaxM[i][2]>0 && !flag_repeat) {        //RackLoadFrame1->MaxM[1][5]
	  Data_select.RSU[i][k][0] = RackLoadFrame1->MaxM[i][0]/F1000;
	  Data_select.RSU[i][k][1] = RackLoadFrame1->MaxM[i][2]/F1000;
	  Data_select.RSU[i][k][2] = RackLoadFrame1->MaxM[i][1]/F1000;
	  Data_select.RSU[i][k][3] = RackLoadFrame1->MaxM[i][4]/F1000;
	  Data_select.RSU[i][k][4] = RackLoadFrame1->MaxM[i][3]/F1000;
	  Data_select.X_sect[i][k] = RackLoadFrame1->MaxM[i][5]/L1000;
	  Data_select.q_bal[i][k] = 0;
	  Data_select.RSU_W[k][0] = RackLoadFrame1->MaxM_W[i][0]/F1000;
	  Data_select.RSU_W[k][1] = RackLoadFrame1->MaxM_W[i][2]/F1000;
	  Data_select.RSU_W[k][2] = RackLoadFrame1->MaxM_W[i][1]/F1000;
	  Data_select.RSU_W[k][3] = RackLoadFrame1->MaxM_W[i][4]/F1000;
	  Data_select.RSU_W[k][4] = RackLoadFrame1->MaxM_W[i][3]/F1000;
	  k++;
	}
	flag_repeat = false;
	for (j=0; j<k; j++) {
	  if ((ABS(RackLoadFrame1->MinM[i][2]/F1000 - Data_select.RSU[i][j][1]))<1e-3)
		flag_repeat = true;
	}
	if (RackLoadFrame1->MinM[i][2]<0 && !flag_repeat) {
	  Data_select.RSU[i][k][0] = RackLoadFrame1->MinM[i][0]/F1000;
	  Data_select.RSU[i][k][1] = RackLoadFrame1->MinM[i][2]/F1000;
	  Data_select.RSU[i][k][2] = RackLoadFrame1->MinM[i][1]/F1000;
	  Data_select.RSU[i][k][3] = RackLoadFrame1->MinM[i][4]/F1000;
	  Data_select.RSU[i][k][4] = RackLoadFrame1->MinM[i][3]/F1000;
	  Data_select.X_sect[i][k] = RackLoadFrame1->MinM[i][5]/L1000;
	  Data_select.q_bal[i][k] = 0;
	  Data_select.RSU_W[k][0] = RackLoadFrame1->MinM_W[i][0]/F1000;
	  Data_select.RSU_W[k][1] = RackLoadFrame1->MinM_W[i][2]/F1000;
	  Data_select.RSU_W[k][2] = RackLoadFrame1->MinM_W[i][1]/F1000;
	  Data_select.RSU_W[k][3] = RackLoadFrame1->MinM_W[i][4]/F1000;
	  Data_select.RSU_W[k][4] = RackLoadFrame1->MinM_W[i][3]/F1000;
	  k++;
	}
	flag_repeat = false;
	for (j=0; j<k; j++) {
	  if ((ABS(RackLoadFrame1->MaxSigma[i][2]/F1000 - Data_select.RSU[i][j][1]))<1e-3)
		flag_repeat = true;
	}
	if (RackLoadFrame1->MaxSigma[2]>0 && !flag_repeat) {
	  Data_select.RSU[i][k][0] = RackLoadFrame1->MaxSigma[i][0]/F1000;
	  Data_select.RSU[i][k][1] = RackLoadFrame1->MaxSigma[i][2]/F1000;
	  Data_select.RSU[i][k][2] = RackLoadFrame1->MaxSigma[i][1]/F1000;
	  Data_select.RSU[i][k][3] = RackLoadFrame1->MaxSigma[i][4]/F1000;
	  Data_select.RSU[i][k][4] = RackLoadFrame1->MaxSigma[i][3]/F1000;
	  Data_select.X_sect[i][k] = RackLoadFrame1->MaxSigma[i][5]/L1000;
	  Data_select.q_bal[i][k] = 0;
	  Data_select.RSU_W[k][0] = RackLoadFrame1->MaxSigma_W[i][0]/F1000;
	  Data_select.RSU_W[k][1] = RackLoadFrame1->MaxSigma_W[i][2]/F1000;
	  Data_select.RSU_W[k][2] = RackLoadFrame1->MaxSigma_W[i][1]/F1000;
	  Data_select.RSU_W[k][3] = RackLoadFrame1->MaxSigma_W[i][4]/F1000;
	  Data_select.RSU_W[k][4] = RackLoadFrame1->MaxSigma_W[i][3]/F1000;
	  k++;
	}
	flag_repeat = false;
	for (j=0; j<k; j++) {
	  if ((ABS(RackLoadFrame1->MinSigma[i][2]/F1000 - Data_select.RSU[i][j][1]))<1e-3)
		flag_repeat = true;
	}
	if (RackLoadFrame1->MinSigma[i][2]<0 && !flag_repeat) {
	  Data_select.RSU[i][k][0] = RackLoadFrame1->MinSigma[i][0]/F1000;
	  Data_select.RSU[i][k][1] = RackLoadFrame1->MinSigma[i][2]/F1000;
	  Data_select.RSU[i][k][2] = RackLoadFrame1->MinSigma[i][1]/F1000;
	  Data_select.RSU[i][k][3] = RackLoadFrame1->MinSigma[i][4]/F1000;
	  Data_select.RSU[i][k][4] = RackLoadFrame1->MinSigma[i][3]/F1000;
	  Data_select.X_sect[i][k] = RackLoadFrame1->MinSigma[i][5]/L1000;
	  Data_select.q_bal[i][k] = 0;
	  Data_select.RSU_W[k][0] = RackLoadFrame1->MinSigma_W[i][0]/F1000;
	  Data_select.RSU_W[k][1] = RackLoadFrame1->MinSigma_W[i][2]/F1000;
	  Data_select.RSU_W[k][2] = RackLoadFrame1->MinSigma_W[i][1]/F1000;
	  Data_select.RSU_W[k][3] = RackLoadFrame1->MinSigma_W[i][4]/F1000;
	  Data_select.RSU_W[k][4] = RackLoadFrame1->MinSigma_W[i][3]/F1000;
	  k++;
	}
	Data_select.N_RSU[i] = k;
	Data_select.Length[i] = RackLoadFrame1->Length_part[i]*L1000;
	Data_select.length_YY[i] = RackLoadFrame1->Length_part[i]*RackLoadFrame1->Koeff_length_XZ[i]*L1000;
	Data_select.length_XX[i] = RackLoadFrame1->Length_part[i]*RackLoadFrame1->Koeff_length_XY[i]*L1000;
	Data_select.koeff_length_YY[i] = RackLoadFrame1->Koeff_length_XZ[i];
	Data_select.koeff_length_XX[i] = RackLoadFrame1->Koeff_length_XY[i];
	if (RackLoadFrame1->Step_comp_rack > 0)
	  Data_select.step_comp[i] = RackLoadFrame1->Step_comp_rack*L1000;
	else
	  Data_select.step_comp[i] = Data_select.length_XX[0];
  }
  Data_select.q_down_max = RackLoadFrame1->q_down_max;
  Data_select.q_down_LR_max = RackLoadFrame1->q_down_LR_max;
  Data_select.M_down_LR_max = RackLoadFrame1->M_down_LR_max;
  Data_select.FRo_RSU = RackLoadFrame1->FRo_RSU;
  Data_select.Izz_RSU = RackLoadFrame1->Izz_RSU;
  // Заполнить таблицы РСУ
  StringGrid_Length->RowCount = 1 + Data_select.N_plane;
  for (i=0; i<Data_select.N_plane; i++) {
	StringGrid_Length->Cells[0][i+1] = "1";
	StringGrid_Length->Cells[1][i+1] = FloatToStr(Data_select.Length[i]/L1000);
	StringGrid_Length->Cells[2][i+1] = FloatToStr(Data_select.length_YY[i]/L1000);
	StringGrid_Length->Cells[3][i+1] = FloatToStr(Data_select.length_XX[i]/L1000);
	StringGrid_Length->Cells[4][i+1] = FloatToStr(Data_select.step_comp[i]/L1000);
  }
  //-------------------------------------------------------------------
  n_plane = 0;
  StringGrid_RSU->ColCount = 8;
  StringGrid_RSU->Cells[7][0] = "X сеч., м";
  StringGrid_RSU->RowCount = Data_select.N_RSU[0] + 1;
  for (i=0; i<Data_select.N_RSU[0]; i++) {
	StringGrid_RSU->Cells[0][i+1] = IntToStr(i+1);
	for (j=0; j<5; j++) {
	  StringGrid_RSU->Cells[j+1][i+1] =  FloatToStr(Data_select.RSU[0][i][j]);
	}
	StringGrid_RSU->Cells[j+1][i+1] = Data_select.q_bal[0][i];
	StringGrid_RSU->Cells[j+2][i+1] = Data_select.X_sect[0][i];
  }
  Edit_N->Text = Data_select.RSU[n_plane][0][0];
  Edit_Mx->Text = Data_select.RSU[n_plane][0][1];
  Edit_Qy->Text = Data_select.RSU[n_plane][0][2];
  Edit_My->Text = Data_select.RSU[n_plane][0][3];
  Edit_Qx->Text = Data_select.RSU[n_plane][0][4];
  Edit_qy_->Text = Data_select.q_bal[n_plane][0];
  TabSheet_Part->TabVisible = true;
  ComboBox_G1_Count->ItemIndex = 0;

  CheckBox_razrez->Checked = false;

  OutRSU(1);                             //Data_select.X_sect[1][1]

}
//---------------------------------------------------------------------------

void __fastcall TSelectProfilSectForm::CheckBox_same_materialClick(TObject *Sender)

{
	if (CheckBox_same_material->Checked) {
	  Data_select.index_same_material = 1;
	  TabSheet_plate->TabVisible = true;
	  if (Data_select.form_profil==DVUTAVR_WELD) {
		 TabSheet_profil->Caption = "Материал полок";
		 TabSheet_plate->Caption = "Материал стенки";
	  }
	  else {
		 TabSheet_profil->Caption = "Материал профиля";
		 TabSheet_plate->Caption = "Материал пластины";
	  }
	  //--------------------------------
	  Define_Material_ARSSForm->Set_Material_name(DVUTAVR_WELD, Data_select.index_GOST_plate, Data_select.title_material_plate);
	  Panel_mater_plate->Caption = Define_Material_ARSSForm->ComboBox_steel->Text;

	  // Установить метку материала стенки или пластины
	  Set_Label_steel_plate();
	}
	else {
	  Data_select.index_same_material = 0;
	  TabSheet_profil->Caption = "Материал";
	  TabSheet_plate->TabVisible = false;

    }
}
//---------------------------------------------------------------------------

void __fastcall TSelectProfilSectForm::BitBtnMaterial_plateClick(TObject *Sender)

{
	 char mater_title_buf[10];
	 strcpy(mater_title_buf, MaterProp[Material_Number].title);
	 TabSheet_plate->TabVisible = true;

	 Define_Material_ARSSForm->Set_Material_name(DVUTAVR_WELD, Data_select.index_GOST_plate, Data_select.title_material_plate);

	 Define_Material_ARSSForm->Caption = "Выбор материала стенки/пластины";
	 Define_Material_ARSSForm->ShowModal();

	 Panel_mater_plate->Caption = Define_Material_ARSSForm->ComboBox_steel->Text;
	 modify_project = true;
	 strcpy(Data_select.title_material_plate, MaterProp[Material_Number].title);
	 Data_select.index_GOST_plate = MaterProp[Material_Number].index_GOST;
	 memcpy((char*)&(Data_select.MaterProp_plate), (char*)&(MaterProp[Material_Number]), sizeof(MATER));
	 // Установить метку Госта материала пластины
	 Set_Label_steel_plate();

	 strcpy(MaterProp[Material_Number].title, mater_title_buf);

}
//---------------------------------------------------------------------------

