//---------------------------------------------------------------------------
// Нарисовать профиль и оси координат
void __fastcall TSelectProfilSectForm::Draw_prof_ax(int n_profil)
{
   int rc;                  //Data_select.type_profil  Data_select.index_profil   BalkaLoadFrame1->n_beam
   double attit;
   double alfa;
   bool flag_sysc = Draw_RSU_Frame1->CheckListBox_Show->Checked[2];
   GEOM_PARAM_SECT param_sect;
   PARAM_PERFOR param_perfor;
   double  length_0;
   double ss;
   double Zct0, A_plate, I_comp;
   double Width_down;
   int index_view;

   if (Data_select.index_loads==0 || Data_select.index_loads==1)
	 index_view = vISOMETR;
   else
	 index_view = vISO_VERT;

   if (Draw_RSU_Frame1->CheckBox_RealScale->Checked) {
	 if (Data_select.index_loads==1)
	   length_0 = BalkaLoadFrame1->Length_beam;
	 else
	   length_0 = RackLoadFrame1->Length_rack;
   }
   else
	 length_0 = 0;
   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);

	 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, index_view, 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);
	 Width_down = com_sect.dvutavr.b2;
   break;
   case PERFOR_BEAM:
   // Установить тип стандартного сечения
	 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;

	 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, index_view, 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);
	 Width_down = com_sect.dvutavr.b2;

   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, index_view, 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;
	 Width_down = 0;

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

	 Draw_dvutavr_weld(Draw_RSU_Frame1->Image1, &sect_weld, index_view, 4.0, 70, flag_sysc, length_0);
	 Get_param_sect(&sect_weld, &param_sect);
	 H_beam = param_sect.Hsect;
	 B_beam = param_sect.Wsect;
	 Width_down = sect_weld.b2;
   break;
   case COMPOSED_BEAM:    // Составное сечение
   // толщина и ширина пластины
	 rc = String_double_plus(Label_thick_comp->Caption, Edit_thick_comp->Text, &ss);
	 if (rc>0) return;
	 Data_select.plate_thick = ss;
	 rc = String_double_plus(Label_width_comp->Caption, Edit_width_comp->Text, &ss);
	 if (rc>0) return;
	 Data_select.plate_width = ss;
	 rc = String_double_plus(Label_width_comp->Caption, Edit_kf_comp->Text, &ss);
	 if (rc>0) return;
	 Data_select.kf_comp = ss;
	 SectSelectCom_ParamFrame2->width = Data_select.plate_width;
	 SectSelectCom_ParamFrame2->thick = Data_select.plate_thick;
	 SectSelectCom_ParamFrame2->kf = Data_select.kf_comp;

   // Установить тип стандартного сечения и получит геометрические параметры сечения
	 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;
	 //Draw_dvutavr(Image_prof, &com_sect.dvutavr, vDIMETR, 1.2, 20, true);
	 //Draw_dvutavr_oblic(Image_prof, &com_sect.dvutavr);
	   Draw_tavr_plate(Draw_RSU_Frame1->Image1, &com_sect.tavr, index_view, 4.0, 60, flag_sysc, 0, 0, length_0,
					   Data_select.plate_thick, Data_select.plate_width, Data_select.index_composed);
	   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;
	 //Draw_dvutavr(Image_prof, &com_sect.dvutavr, vDIMETR, 1.2, 20, true);
	 //Draw_dvutavr_oblic(Image_prof, &com_sect.dvutavr);
	   Draw_dvutavr_plate(Draw_RSU_Frame1->Image1, &com_sect.dvutavr, index_view, 4.0, 60, flag_sysc, false, 0, 0, length_0,
						  Data_select.plate_thick, Data_select.plate_width);
	   Get_param_sect_composed(DVUTAVR, &com_sect, Data_select.plate_width, Data_select.plate_thick, &param_sect, Data_select.index_composed);
	 break;
	 }
	 Fill_param_comp();
	 H_beam = param_sect.Hsect;
	 B_beam = param_sect.Wsect;
	 Width_down = Data_select.plate_width;
   break;
   }
   I_beam = param_sect.Izz;
   F_beam = param_sect.Ar;

	 BalkaLoadFrame1->H_beam = H_beam;
	 BalkaLoadFrame1->Width_down = Width_down;
	 BalkaLoadFrame1->Zct_beam = param_sect.Zct;
	 BalkaLoadFrame1->IE_beam = I_beam*206000;
	 BalkaLoadFrame1->FE_beam = F_beam*206000;
	 BalkaLoadFrame1->FRo_beam = F_beam*7850*1e-6;  // кг/м
	 BalkaLoadFrame1->I_beam = I_beam;
	 BalkaLoadFrame1->F_beam = F_beam;
   // Пока отчасти дублирует, то что выше
	 BalkaLoadFrame1->PutParamSect(&param_sect);
	 Draw_RSU_Frame1->Length_beam = BalkaLoadFrame1->Length_beam;
	 Draw_RSU_Frame1->Len_XY = BalkaLoadFrame1->Len_XY;
	 Draw_RSU_Frame1->Step_up = BalkaLoadFrame1->Step_up;
	 Draw_RSU_Frame1->Step_down = BalkaLoadFrame1->Step_down;
	 RackLoadFrame1->H_beam = H_beam;
	 RackLoadFrame1->Width_down = Width_down;
	 RackLoadFrame1->Zct_beam = param_sect.Zct;
	 RackLoadFrame1->IE_beam = I_beam*206000;
	 RackLoadFrame1->FE_beam = F_beam*206000;
	 RackLoadFrame1->FRo_beam = F_beam*7850*1e-6;  // кг/м
	 RackLoadFrame1->I_beam = I_beam;
	 RackLoadFrame1->F_beam = F_beam;

   // Пока отчасти дублирует, то что выше
	 RackLoadFrame1->PutParamSect(&param_sect);
	 Draw_RSU_Frame1->Length_rack = RackLoadFrame1->Length_rack;
	 Draw_RSU_Frame1->N_part = RackLoadFrame1->N_part;
	 Draw_RSU_Frame1->index_TY_up = RackLoadFrame1->index_TY_up;
	 memcpy((char*)Draw_RSU_Frame1->Length_part, (char*)RackLoadFrame1->Length_part, sizeof(double)*RackLoadFrame1->N_part);
	 Draw_RSU_Frame1->Len_XY_rack = RackLoadFrame1->Len_XY;
	 Draw_RSU_Frame1->Step_up_rack = RackLoadFrame1->Step_up;
	 Draw_RSU_Frame1->Step_comp = RackLoadFrame1->Step_comp_rack;

   Draw_RSU_Frame1->L_beam = Data_select.Length[n_plane];
   Draw_RSU_Frame1->form_profil = Data_select.form_profil;
   Draw_RSU_Frame1->index_profil = Data_select.index_profil;
   Draw_RSU_Frame1->type_profil = Data_select.type_profil;
   Draw_RSU_Frame1->attit = Data_select.perfor_attit;
   Draw_RSU_Frame1->alfa = Data_select.perfor_alfa;
   Draw_RSU_Frame1->H_beam = H_beam;
   Draw_RSU_Frame1->B_beam = B_beam;
   Draw_RSU_Frame1->plate_thick = Data_select.plate_thick;
   Draw_RSU_Frame1->plate_width = Data_select.plate_width;
   Draw_RSU_Frame1->index_composed = Data_select.index_composed;
   Draw_RSU_Frame1->plate_kf = Data_select.kf_comp;

   Draw_RSU_Frame1->index_Qy = Data_select.index_Qy;
   memcpy((char*)&(Draw_RSU_Frame1->com_sect), (char*)&com_sect, sizeof(COMMON_SECT));
   //Draw_RSU_Frame1->beam_mod = &(BalkaLoadFrame1->beam_mod);

   double load[6] = {0, 0, 0, 0, 0, 0};
   int k_zagr;
   int length_q;
   BeamRegion *Aq;
   int length_N;
   BeamRegion *AN;
   int length_loads;
   Load *Aloads;
   int length_constr;
   Constraint *Aconstr;     //Data_beam
   int *index_place;
   double *b_;
   double *exc_L;
   double *exc_N;
   double b_ax[PORTION_REGION];
   int i;

   switch (Data_select.index_loads) {  // нагрузки задаются в форме РСУ
   case 0:    // РСУ

	 GetLoadFromRSU(load);

	 for (int i=0; i<5; i++) {
	   Draw_RSU_Frame1->loads[i] = load[i];
	 }
	 Draw_RSU_Frame1->q_bal = load[5];
	 if (load[5]==0) {
	   Draw_RSU_Frame1->GroupBox_q_bal->Visible = false;
	 }
	 else {
	  Draw_RSU_Frame1->GroupBox_q_bal->Visible = true;

	 }
	 Draw_RSU_Frame1->Draw_load() ;
   break;
   case 1:  // Отобразить нагрузки на балке

	 BalkaLoadFrame1->Correct_Weight();
	 // Взять балку (загружение) из депозитария
	 BalkaLoadFrame1->GetRegion(&k_zagr, &length_q, &Aq, &length_N, &AN,
								&length_loads, &Aloads, &length_constr, &Aconstr, &index_place, &b_);


	 Draw_RSU_Frame1->Draw_load_balka(k_zagr, length_q, Aq, length_N, AN,
								length_loads, Aloads, length_constr, Aconstr, index_place, b_) ;

	 // Заполнение данных о балке для записи в архив
	 GetDataBeam(&Data_beam, &Data_region_beam);           //Data_beam.loads_v[0]
   break;
   case 2:  // Отобразить нагрузки на стойке

	 RackLoadFrame1->Correct_Weight();
	 // Взять стойку (загружение) из депозитария
	 RackLoadFrame1->GetRegion(&k_zagr, &length_q, &Aq, &length_N, &AN,
								&length_loads, &Aloads, &length_constr, &Aconstr, &exc_N, &exc_L);


	 Draw_RSU_Frame1->Draw_load_rack(k_zagr, length_q, Aq, length_N, AN,
								length_loads, Aloads, length_constr, Aconstr, exc_N, exc_L) ;

	 // Заполнение данных о стойке для записи в архив
	 GetDataRack(&Data_rack, &Data_region_rack);
   break;
   }
}
//---------------------------------------------------------------------------
// Заполнение данных о балке для записи в архив
void __fastcall TSelectProfilSectForm::GetDataBeam(DATA_BEAM *Data_Beam, DATA_REGION *Data_Region_beam)  {
	//----------------------------------------------
	Data_Beam->n_zagr = BalkaLoadFrame1->n_beam;
	Data_Beam->Length_beam = BalkaLoadFrame1->Length_beam;
	Data_Beam->Len_v = BalkaLoadFrame1->Len_v;
	Data_Beam->n_comb = BalkaLoadFrame1->n_comb;
	Data_Beam->Len_XY = BalkaLoadFrame1->Len_XY;
	Data_Beam->Step_up = BalkaLoadFrame1->Step_up;
	Data_Beam->Step_down = BalkaLoadFrame1->Step_down;
	Data_Beam->constr_length = BalkaLoadFrame1->beam_mod.constr_length;

	Data_Region_beam->EI_v = BalkaLoadFrame1->EI_v;
	Data_Region_beam->q_v  = BalkaLoadFrame1->q_v;      //BalkaLoadFrame1->loads_v[0]
	Data_Region_beam->index_place_v  = BalkaLoadFrame1->index_place_v;
	Data_Region_beam->dist_LRv  = BalkaLoadFrame1->dist_LRv;
	Data_Region_beam->dist_eLv  = NULL;
	Data_Region_beam->dist_eNv  = NULL;
	Data_Region_beam->N_v  = BalkaLoadFrame1->N_v;
	Data_Region_beam->loads_v = BalkaLoadFrame1->loads_v;
	Data_Region_beam->constr = BalkaLoadFrame1->constr;
	Data_Region_beam->type_zagr = BalkaLoadFrame1->type_zagr;
	Data_Region_beam->flag_weight = BalkaLoadFrame1->flag_weight;
	Data_Region_beam->Koeff_gamma_f = BalkaLoadFrame1->Koeff_gamma_f;
	Data_Region_beam->Koeff_low = BalkaLoadFrame1->Koeff_low;
	Data_Region_beam->index_beam = &(BalkaLoadFrame1->index_beam[0][0]);
	Data_Region_beam->Combin_zagr = BalkaLoadFrame1->Combin_zagr;
}
//---------------------------------------------------------------------------
// Заполнение данных о стойке для записи в архив
void __fastcall TSelectProfilSectForm::GetDataRack(DATA_RACK *Data_Rack, DATA_REGION *Data_Region_rack)  {
	//----------------------------------------------
	int i;
	Data_Rack->n_zagr = RackLoadFrame1->n_beam;
	Data_Rack->Length_rack = RackLoadFrame1->Length_rack;
	Data_Rack->Len_v = RackLoadFrame1->Len_v;
	Data_Rack->n_comb = RackLoadFrame1->n_comb;
	Data_Rack->N_part = RackLoadFrame1->N_part;
	for (i=0; i<RackLoadFrame1->N_part; i++) {
	   Data_Rack->Length_part[i] = RackLoadFrame1->Length_part[i];
	   Data_Rack->Koeff_length_XZ[i] = RackLoadFrame1->Koeff_length_XZ[i];
	   Data_Rack->Koeff_length_XY[i] = RackLoadFrame1->Koeff_length_XY[i];
	}
	Data_Rack->index_raskr = RackLoadFrame1->index_raskr;
	Data_Rack->index_TY_up = RackLoadFrame1->index_TY_up;
	Data_Rack->Step_comp_rack = RackLoadFrame1->Step_comp_rack;
	Data_Rack->index_raskr = RackLoadFrame1->index_raskr;
	Data_Rack->constr_length = RackLoadFrame1->beam_mod.constr_length;

	Data_Region_rack->EI_v = RackLoadFrame1->EI_v;
	Data_Region_rack->q_v  = RackLoadFrame1->q_v;      //RackLoadFrame1->q_v[0]
	Data_Region_rack->index_place_v  = NULL;
	Data_Region_rack->dist_LRv  = NULL;
	Data_Region_rack->N_v  = RackLoadFrame1->N_v;
	Data_Region_rack->dist_eLv  = RackLoadFrame1->dist_eLv;
	Data_Region_rack->dist_eNv  = RackLoadFrame1->dist_eNv;
	Data_Region_rack->loads_v = RackLoadFrame1->loads_v;
	Data_Region_rack->constr = RackLoadFrame1->constr;
	Data_Region_rack->type_zagr = RackLoadFrame1->type_zagr;
	Data_Region_rack->flag_weight = RackLoadFrame1->flag_weight;
	Data_Region_rack->Koeff_gamma_f = RackLoadFrame1->Koeff_gamma_f;
	Data_Region_rack->Koeff_low = RackLoadFrame1->Koeff_low;
	Data_Region_rack->index_beam = &(RackLoadFrame1->index_beam[0][0]);
	Data_Region_rack->Combin_zagr = RackLoadFrame1->Combin_zagr;
}
//---------------------------------------------------------------------------
// Заполнение данных о балке после чтения из архива
void __fastcall TSelectProfilSectForm::Fill_field_balka(DATA_BEAM *Data_Beam, DATA_REGION *Data_Region, TObject *Sender)  {
	//----------------------------------------------
	BalkaLoadFrame1->n_beam = Data_Beam->n_zagr;
	BalkaLoadFrame1->Length_beam = Data_Beam->Length_beam;
	BalkaLoadFrame1->Len_v = Data_Beam->Len_v;
	BalkaLoadFrame1->n_comb = Data_Beam->n_comb;
	BalkaLoadFrame1->Len_XY = Data_Beam->Len_XY;
	BalkaLoadFrame1->Step_up = Data_Beam->Step_up;
	BalkaLoadFrame1->Step_down = Data_Beam->Step_down;
	BalkaLoadFrame1->beam_mod.constr_length = Data_Beam->constr_length;

	BalkaLoadFrame1->Combin_zagr = Data_Region->Combin_zagr;
	// Заполнить поля данных балки
	BalkaLoadFrame1->Fill_field(Sender);
}
//---------------------------------------------------------------------------
// Заполнение данных о стойке после чтения из архива
void __fastcall TSelectProfilSectForm::Fill_field_rack(DATA_RACK *Data_Rack, DATA_REGION *Data_Region_Rack, TObject *Sender)  {
	//----------------------------------------------
	int i;

	RackLoadFrame1->n_beam = Data_Rack->n_zagr;
	RackLoadFrame1->Length_rack = Data_Rack->Length_rack;
	RackLoadFrame1->Len_v = Data_Rack->Len_v;
	RackLoadFrame1->n_comb = Data_Rack->n_comb;
	RackLoadFrame1->N_part = MAX(1, Data_Rack->N_part);
	Data_select.N_plane = RackLoadFrame1->N_part;

	//RackLoadFrame1->N_part = Data_select.N_plane;
	for (i=0; i<RackLoadFrame1->N_part; i++) {
	   RackLoadFrame1->Length_part[i] = Data_Rack->Length_part[i];
	   RackLoadFrame1->Koeff_length_XZ[i] = Data_Rack->Koeff_length_XZ[i];
	   RackLoadFrame1->Koeff_length_XY[i] = Data_Rack->Koeff_length_XY[i];
	}
	RackLoadFrame1->Step_comp_rack = Data_Rack->Step_comp_rack;
	RackLoadFrame1->index_raskr = Data_Rack->index_raskr;
	RackLoadFrame1->index_TY_up = Data_Rack->index_TY_up;
	RackLoadFrame1->beam_mod.constr_length = Data_Rack->constr_length;

	RackLoadFrame1->Combin_zagr = Data_Region_Rack->Combin_zagr;
	// Заполнить поля данных балки
	RackLoadFrame1->Fill_field(Sender);
}
//---------------------------------------------------------------------------
void __fastcall TSelectProfilSectForm::ComboBox_Dvutavr_compChange(TObject *Sender)

{
		Data_select.index_profil = ComboBox_Dvutavr_comp->ItemIndex;
		// Нарисовать профиль и оси координат прокатного двутавра
		N_profil = SectSelectCom_ParamFrame2->ComboBox_profil->ItemIndex;
		Draw_prof_ax(N_profil);

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

		modify_project = true;
		Edit_alfaEnter(Sender);

}
//---------------------------------------------------------------------------
//--------------------------------------------------------------------------------
//
void __fastcall TSelectProfilSectForm::RadioGroup_Loads_Fill(int numb)
{
	  int index = RadioGroup_Loads->ItemIndex;

	  RadioGroup_Loads->Items->Clear();
	  switch (numb) {
	  case 1: // Для тавра с пластиной
		RadioGroup_Loads->Items->Add("Задаются пользователем");
		RadioGroup_Loads->Items->Add("Из расчета балки");
		RadioGroup_Loads->ItemIndex = 1;
		RadioGroup_Loads->Enabled = false;
	  break;
	  case 2:  // Для перворированной балки
		RadioGroup_Loads->Items->Add("Задаются пользователем");
		RadioGroup_Loads->Items->Add("Из расчета балки");
		RadioGroup_Loads->ItemIndex = 0;
		//RadioGroup_Loads->ItemIndex = MIN(1, index);
		RadioGroup_Loads->Enabled = true;
	  break;
	  case 3:  // Для всех остальных
		RadioGroup_Loads->Items->Add("Задаются пользователем");
		RadioGroup_Loads->Items->Add("Из расчета балки");
		RadioGroup_Loads->Items->Add("Из расчета стойки");
		RadioGroup_Loads->ItemIndex = 0;
		//RadioGroup_Loads->ItemIndex = MIN(2, index);
		RadioGroup_Loads->Enabled = true;
	  }
}

