home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 February / Chip_2004-02_cd1.bin / program / delphi / navody / d56 / ec1vr2.exe / #setuppath# / CB6 / Prnplot / Main.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2003-12-09  |  3.1 KB  |  104 lines

  1. //---------------------------------------------------------------------------
  2. #include <vcl\vcl.h>
  3. #pragma hdrstop
  4.  
  5. #include "math.h"
  6. #include "Main.h"
  7. #include "about.h"
  8. #include "report.h"
  9. //---------------------------------------------------------------------------
  10. #pragma resource "*.dfm"
  11. TMainForm *MainForm;
  12. //---------------------------------------------------------------------------
  13. __fastcall TMainForm::TMainForm(TComponent* Owner)
  14.     : TForm(Owner)
  15. {
  16.   Db->Params->Values["PATH"] = Application->ExeName.SubString (0,Application->ExeName.LastDelimiter ("\\") - 1);
  17.   Table->Active = true;
  18. }
  19. //----------------------------------------------------------------------------
  20. void __fastcall TMainForm::GetFunction (double &AX,double &AY,double AFi,int AIndex)
  21. {
  22.   double a,b,l;
  23.  
  24.   switch (AIndex)
  25.   {
  26.     case 0:
  27.          a = 2;
  28.          b = 5;
  29.          AX = (a+b)*cos(AFi) - a*cos((a+b)*AFi/a);
  30.          AY = (a+b)*sin(AFi) - a*sin((a+b)*AFi/a);
  31.          break;
  32.     case 1:
  33.          a = 2;
  34.          b = 12;
  35.          AX = (b-a)*cos(AFi) + a*cos((b-a)*AFi/a);
  36.          AY = (b-a)*sin(AFi) - a*sin((b-a)*AFi/a);
  37.          break;
  38.     case 2:
  39.          a = 2;
  40.          b = 8;
  41.          l = 2;
  42.          AX = (b-a)*cos(AFi) + l*a*cos((b-a)*AFi/a);
  43.          AY = (b-a)*sin(AFi) - l*a*sin((b-a)*AFi/a);
  44.          break;
  45.   }
  46. }
  47.  
  48. void __fastcall TMainForm::Solve(void)
  49. {
  50.   double x,y,fi;
  51.   TCurvePoint *APoint;
  52.  
  53.   RepForm->Curve1->CurveData->Items[0]->CurvePoints->Clear ();
  54.   DSource->Enabled = false;
  55.   Table->EmptyTable ();
  56.  
  57.   for (fi=0; fi<=4*M_PI; fi+=M_PI/30)
  58.   {
  59.     GetFunction (x,y,fi,Group1->ItemIndex);
  60.     APoint = (TCurvePoint *)(RepForm->Curve1->CurveData->Items[0]->CurvePoints->Add ());
  61.     APoint->Argument->Value = x;
  62.     APoint->Function->Value = y;
  63.  
  64.     GetFunction (x,y,fi,Group2->ItemIndex);
  65.     Table->AppendRecord (ARRAYOFCONST(((double)x,(double)y)));
  66.   }
  67.  
  68.   DSource->Enabled = true;
  69.  
  70.   ((TLegendAbsString *)RepForm->Curve1->Legend->Data)->Value = Group1->Items->Strings[Group1->ItemIndex];
  71.   ((TLegendAbsString *)RepForm->Curve2->Legend->Data)->Value = Group2->Items->Strings[Group2->ItemIndex];
  72. }
  73. //----------------------------------------------------------------------------
  74. void __fastcall TMainForm::Print(TObject *Sender)
  75. {
  76.   Solve ();
  77.   if (RepForm->VividReport->PrintSetup ()) RepForm->VividReport->Print ();
  78. }
  79. //----------------------------------------------------------------------------
  80. void __fastcall TMainForm::PrintSetup(TObject *Sender)
  81. {
  82.   RepForm->VividReport->PrinterSetup ();
  83. }
  84. //----------------------------------------------------------------------------
  85. void __fastcall TMainForm::Exit(TObject *Sender)
  86. {
  87.   Close();
  88. }
  89. //----------------------------------------------------------------------------
  90. void __fastcall TMainForm::About(TObject *Sender)
  91. {
  92.   AboutBox->ShowModal ();
  93. }
  94. //----------------------------------------------------------------------------
  95. void __fastcall TMainForm::PrintPreview(TObject *Sender)
  96. {
  97.   Solve ();
  98.   RepForm->VividReport->PrintPreview (RepForm->VRPreview);
  99. }
  100. //---------------------------------------------------------------------------
  101.  
  102.  
  103.  
  104.