Main Page   Alphabetical List   Compound List   File List   Compound Members   Related Pages  

MDITransfer.cpp

00001 //---------------------------------------------------------------------------
00002 
00003 #include <vcl.h>
00004 #pragma hdrstop
00005 
00006 #include "MDITransfer.h"
00007 #include "mdiframe.h"
00008 #include "MDIEdit.h"
00009 #include <XMLDoc.hpp>
00010 
00011 //---------------------------------------------------------------------------
00012 #pragma package(smart_init)
00013 #pragma resource "*.dfm"
00014 TTransferForm *TransferForm;
00015 //---------------------------------------------------------------------------
00016 __fastcall TTransferForm::TTransferForm(TComponent* Owner, TTransfer *transe)
00017         : TForm(Owner),
00018           _created(false),
00019           _selLine(-1),
00020           _selPoint(-1),
00021           _lineNr(-1),
00022           _endpoint(-1),
00023           _beginSelect(false),
00024           _beginSelectEndpoint(false),
00025           _beginCut(false),
00026           _beginMove(false)
00027 {
00028 }
00029 //---------------------------------------------------------------------------
00030 
00031 void __fastcall TTransferForm::_setHistoArea()
00032 {
00033         // HA->Width:
00034         HistoArea->Width = (int)((float)PHistoAreaBack->ClientWidth *
00035                                  histo->histoZoom);
00036         // HA->Height:
00037         HistoArea->Height = (int)((float)PHistoAreaBack->ClientHeight *
00038                                   histo->valZoom);
00039         // HA->Left:
00040         if (HistoArea->Width > PHistoAreaBack->Width)
00041                 HistoArea->Left = (int)((float)HistoArea->Width *
00042                                         histo->histoPos);
00043         else
00044                 HistoArea->Left = PHistoAreaBack->Width - HistoArea->Width;
00045         // HA->Top:
00046         if (HistoArea->Height > PHistoAreaBack->Height)
00047                 HistoArea->Top = (int)((float)HistoArea->Height *
00048                                        histo->valPos);
00049         else
00050                 HistoArea->Top = PHistoAreaBack->Height - HistoArea->Height;
00051 }
00052 //---------------------------------------------------------------------------
00053 
00054 void __fastcall TTransferForm::_setHistoZoom()
00055 {
00056         // HistoZoom->Max:
00057         TBHorizontal->Max = (int)(histo->getHMaxZoom(PHistoAreaBack)*100.0);
00058 }
00059 //---------------------------------------------------------------------------
00060 
00061 void __fastcall TTransferForm::_setValZoom()
00062 {
00063         // ValZoom->Pos:
00064         TBVertical->Position = (int)(histo->valZoom * 100.0);
00065 }
00066 //---------------------------------------------------------------------------
00067 
00068 void __fastcall TTransferForm::_setHistoPos()
00069 {
00070         if (SBHorizontal->PageSize > HistoArea->Width) {
00071                 // HistoPos->Page:
00072                 if (HistoArea->Width > PHistoAreaBack->Width) {
00073                         SBHorizontal->PageSize = PHistoAreaBack->Width;
00074                         SBHorizontal->LargeChange = SBHorizontal->PageSize;
00075                 } else {
00076                         SBHorizontal->PageSize = HistoArea->Width;
00077                         SBHorizontal->LargeChange = SBHorizontal->PageSize;
00078                 }
00079                 // HistoPos->Max
00080                 SBHorizontal->Max = HistoArea->Width;
00081         } else {
00082                 // HistoPos->Max
00083                 SBHorizontal->Max = HistoArea->Width;
00084                 // HistoPos->Page:
00085                 if (HistoArea->Width > PHistoAreaBack->Width) {
00086                         SBHorizontal->PageSize = PHistoAreaBack->Width;
00087                         SBHorizontal->LargeChange = SBHorizontal->PageSize;
00088                 } else {
00089                         SBHorizontal->PageSize = HistoArea->Width;
00090                         SBHorizontal->LargeChange = SBHorizontal->PageSize;
00091                 }
00092         }
00093         SBHorizontal->Position = SBHorizontal->Max * histo->histoPos;
00094 }
00095 //---------------------------------------------------------------------------
00096 
00097 void __fastcall TTransferForm::_setValPos()
00098 {
00099         if (SBVertical->PageSize > HistoArea->Height) {
00100                 // ValPos->Page
00101                 if (HistoArea->Height > PHistoAreaBack->Height) {
00102                         SBVertical->PageSize = PHistoAreaBack->Height;
00103                         SBVertical->LargeChange = SBVertical->PageSize;
00104                 } else {
00105                         SBVertical->PageSize = HistoArea->Height;
00106                         SBVertical->LargeChange = SBVertical->PageSize;
00107                 }
00108                 // ValPos->Max
00109                 SBVertical->Max = HistoArea->Height;
00110         } else {
00111                 // ValPos->Max
00112                 SBVertical->Max = HistoArea->Height;
00113                 // ValPos->Page
00114                 if (HistoArea->Height > PHistoAreaBack->Height) {
00115                         SBVertical->PageSize = PHistoAreaBack->Height;
00116                         SBVertical->LargeChange = SBVertical->PageSize;
00117                 } else {
00118                         SBVertical->PageSize = HistoArea->Height;
00119                         SBVertical->LargeChange = SBVertical->PageSize;
00120                 }
00121         }
00122         SBVertical->Position = SBVertical->Max * -histo->valPos;
00123 }
00124 //---------------------------------------------------------------------------
00125 
00126 void __fastcall TTransferForm::_movePointTo(int x, int y, bool start)
00127 {
00128         const int n = transe->numLines-1;
00129         const int idx = transe->getSelIdx();
00130         TLine *l = transe->getSelected();
00131         // the real values:
00132         int rx = (int)((float)x*histo->getHPP(HistoArea));
00133         int ry = (int)((float)(HistoArea->Height-y)/
00134                        (float)HistoArea->Height*
00135                        (float)0xff);
00136         if (start) {    // manipulate start point
00137                 TLine *l2 = transe->getLine(idx-1);
00138 
00139                 // make a few tests:
00140                 if (idx == 0) {
00141                         rx=0;
00142                 } else {
00143                         if (rx>l->End.X) rx=l->End.X;
00144                         if (l2) if (rx<l2->Start.X) rx=l2->Start.X;
00145                         if (rx>histo->size) rx=histo->size;
00146                         if (rx<0) rx=0;
00147                 }
00148                 if (ry>0xff) ry=0xff;
00149                 if (ry<0) ry=0;
00150 
00151                 // set line:
00152                 l->Start.X = rx;
00153                 l->Start.Y = ry;
00154                 if (l2) {
00155                         l2->End.X = rx;
00156                         l2->End.Y = ry;
00157                 }
00158         } else {        // manipulate end point
00159                 TLine *l2 = transe->getLine(idx+1);
00160 
00161                 // make a few tests:
00162                 if (idx == n) {
00163                         rx=4096;
00164                 } else {
00165                         if (rx<l->Start.X) rx=l->Start.X;
00166                         if (rx>l2->End.X) rx=l2->End.X;
00167                         if (rx>histo->size) rx=histo->size;
00168                         if (rx<0) rx=0;
00169                 }
00170                 if (ry>0xff) ry=0xff;
00171                 if (ry<0) ry=0;
00172 
00173                 // set line:
00174                 l->End.X = rx;
00175                 l->End.Y = ry;
00176                 if (l2) {
00177                         l2->Start.X = rx;
00178                         l2->Start.Y = ry;
00179                 }
00180         }
00181         transe->Dirty = true;
00182 }
00183 //---------------------------------------------------------------------------
00184 
00185 void __fastcall TTransferForm::_updateColor()
00186 {
00187         for (int i=0; i<size; ++i) color[i] = transe->getColor(data[i]);
00188 }
00189 //---------------------------------------------------------------------------
00190 
00191 void __fastcall TTransferForm::FormCreate(TObject *Sender)
00192 {
00193         histo->horizontal = true;
00194 
00195         _setHistoArea();
00196         _setHistoZoom();
00197         _setHistoPos();
00198         _setValZoom();
00199         _setValPos();
00200 
00201         LZoomX->Caption = AnsiString::FormatFloat("#0.00000", histo->histoZoom);
00202         LZoomY->Caption = AnsiString::FormatFloat("#0.00000", histo->valZoom);
00203         LHistoX->Caption = "0.000";
00204         LHistoY->Caption = "0.000";
00205         LbName->Items->Assign(transe->areaNames);
00206 
00207         _created = true;
00208 }
00209 //---------------------------------------------------------------------------
00210 
00211 void __fastcall TTransferForm::FormClose(TObject *Sender,
00212       TCloseAction &Action)
00213 {
00214         Action=caFree;
00215         FrameForm->METransferfunktion->Checked = false;
00216 }
00217 //---------------------------------------------------------------------------
00218 
00219 void __fastcall TTransferForm::HistoAreaPaint(TObject *Sender)
00220 {
00221         histo->drawTo(HistoArea);
00222         transe->drawTo(HistoArea);
00223 }
00224 //---------------------------------------------------------------------------
00225 
00226 void __fastcall TTransferForm::PHistoAreaBackResize(TObject *Sender)
00227 {
00228         // Set Histo Zoom:
00229         if (histo->histoZoom > histo->getHMaxZoom(PHistoAreaBack))
00230                 histo->histoZoom = histo->getHMaxZoom(PHistoAreaBack);
00231         _setHistoZoom();
00232         _setHistoArea();
00233         _setHistoPos();
00234         _setValPos();
00235 }
00236 //---------------------------------------------------------------------------
00237 
00238 void __fastcall TTransferForm::TBVerticalChange(TObject *Sender)
00239 {
00240         if (!_created) return;
00241         if (histo->horizontal) {
00242                 histo->valZoom = (float)TBVertical->Position/100.0;
00243         } else {
00244                 histo->histoZoom = (float)TBVertical->Position/100.0;
00245         }
00246         _setHistoArea();
00247         _setValPos();
00248         LZoomY->Caption = AnsiString::FormatFloat("#0.00000", histo->valZoom);
00249 }
00250 //---------------------------------------------------------------------------
00251 
00252 void __fastcall TTransferForm::TBHorizontalChange(TObject *Sender)
00253 {
00254         if (!_created) return;
00255         if (histo->horizontal) {
00256                 histo->histoZoom = (float)TBHorizontal->Position/100.0;
00257         } else {
00258                 histo->valZoom = (float)TBHorizontal->Position/100.0;
00259         }
00260         _setHistoArea();
00261         _setHistoPos();
00262         LZoomX->Caption = AnsiString::FormatFloat("#0.00000", histo->histoZoom);
00263 }
00264 //---------------------------------------------------------------------------
00265 
00266 void __fastcall TTransferForm::SBVerticalChange(TObject *Sender)
00267 {
00268         histo->valPos = -(float)SBVertical->Position/(float)HistoArea->Height;
00269         _setHistoArea();
00270 }
00271 //---------------------------------------------------------------------------
00272 
00273 void __fastcall TTransferForm::SBHorizontalChange(TObject *Sender)
00274 {
00275         histo->histoPos = -(float)SBHorizontal->Position/
00276                            (float)HistoArea->Width;
00277         _setHistoArea();
00278 }
00279 //---------------------------------------------------------------------------
00280 
00281 void __fastcall TTransferForm::SFGColorMouseUp(TObject *Sender,
00282       TMouseButton Button, TShiftState Shift, int X, int Y)
00283 {
00284         if (_selLine != -1) {
00285                 if (ColorDialog1->Execute()) {
00286                         SFGColor->Brush->Color = ColorDialog1->Color;
00287                         transe->Dirty = true;
00288                         TLine *l = transe->getSelected();
00289                         if (l->Start.Selected)
00290                                 l->Start.TC = SFGColor->Brush->Color;
00291                         else if (l->End.Selected)
00292                                 l->End.TC = SFGColor->Brush->Color;
00293                         HistoAreaPaint(this);
00294                         _updateColor();
00295                 }
00296         }
00297 }
00298 //---------------------------------------------------------------------------
00299 
00300 void __fastcall TTransferForm::SBGColorMouseUp(TObject *Sender,
00301       TMouseButton Button, TShiftState Shift, int X, int Y)
00302 {
00303         ColorDialog1->Execute();
00304         SBGColor->Brush->Color = ColorDialog1->Color;
00305         histo->background = SBGColor->Brush->Color;
00306         HistoAreaPaint(this);
00307 }
00308 //---------------------------------------------------------------------------
00309 
00310 void __fastcall TTransferForm::HistoAreaMouseMove(TObject *Sender,
00311       TShiftState Shift, int X, int Y)
00312 {
00313         LHistoX->Caption = AnsiString((int)((float)X*histo->getHPP(HistoArea)));
00314         LHistoY->Caption = AnsiString((int)((float)(HistoArea->Height-Y)/
00315                                             (float)HistoArea->Height*
00316                                             (float)0xff));
00317 
00318         _lineNr = transe->lineNear(HistoArea, X, Y);
00319         _endpoint = transe->nearStart(_selLine, HistoArea, X, Y) ? 1 : -1;
00320         _endpoint = transe->nearEnd(_selLine, HistoArea, X, Y) ? 2 : _endpoint;
00321 
00322         if (_beginMove) {
00323                 _movePointTo(X,Y,(_selPoint == 1));
00324                 HistoAreaPaint(this);
00325         } else if (_lineNr != -1 || _endpoint != -1) {
00326                 if (SBCursor->Down)
00327                         HistoArea->Cursor = crHandPoint;
00328                 else if (SBCut->Down)
00329                         HistoArea->Cursor = crCross;
00330                 else if (SBMove->Down) {
00331                         HistoArea->Cursor = crHandPoint;
00332                         if (_endpoint != -1)
00333                                 HistoArea->Cursor = crSizeAll;
00334                 }
00335         } else {
00336                 HistoArea->Cursor = crDefault;
00337         }
00338 }
00339 //---------------------------------------------------------------------------
00340 
00341 void __fastcall TTransferForm::HistoAreaMouseDown(TObject *Sender,
00342       TMouseButton Button, TShiftState Shift, int X, int Y)
00343 {
00344         _beginSelect = (SBCursor->Down || SBMove->Down) && _lineNr != -1;
00345         _beginSelectEndpoint = SBCursor->Down && (_endpoint != -1);
00346         _beginCut = SBCut->Down && _lineNr != -1;
00347         _beginMove = SBMove->Down && ((_selLine != -1) && (_endpoint != -1));
00348         if (_beginMove)
00349                 _selPoint = _endpoint;
00350         else
00351                 _selPoint = -1;
00352 }
00353 //---------------------------------------------------------------------------
00354 
00355 void __fastcall TTransferForm::HistoAreaMouseUp(TObject *Sender,
00356       TMouseButton Button, TShiftState Shift, int X, int Y)
00357 {
00358         if (_beginCut) {
00359                  _selLine = transe->split(HistoArea, X, Y);
00360                 _updateColor();
00361         } else if (_beginMove) {
00362                 _updateColor();
00363         } else if (_beginSelectEndpoint) {
00364                 if (_endpoint == 1) {
00365                         transe->selectStart(_selLine);
00366                         SFGColor->Brush->Color =
00367                                 transe->getSelected()->Start.TC;
00368                 } else if (_endpoint == 2) {
00369                         transe->selectEnd(_selLine);
00370                         SFGColor->Brush->Color =
00371                                 transe->getSelected()->End.TC;
00372                 }
00373         } else if (_beginSelect) {      // A line is selected:
00374                 _selLine = _lineNr;
00375                 if (!_beginMove) transe->select(_selLine);
00376                 TLine *l = transe->getSelected();
00377 
00378                 if (l) {
00379                         // Setup properties:
00380                         LStart->Caption = "(" + AnsiString(l->Start.X) + ", "
00381                                           + AnsiString(l->Start.Y) + ")";
00382                         LEnd->Caption = "(" + AnsiString(l->End.X) + ", "
00383                                         + AnsiString(l->End.Y) + ")";
00384                         //EName->Enabled = true;
00385                         EName->Text = "";
00386                         //SbNameOkay->Enabled = true;
00387                         //SbNameDel->Enabled = true;
00388                         //LbName->Enabled = true;
00389                         if (l->Name <= LbName->Items->Count)
00390                                 LbName->ItemIndex = l->Name;
00391                         else
00392                                 LbName->ItemIndex = -1;
00393                         SStart->Brush->Color = l->Start.TC;
00394                         SEnd->Brush->Color = l->End.TC;
00395                 }
00396         } else if (SBCursor->Down) {
00397                 transe->unselect();
00398 
00399                 // Reset properties:
00400                 LStart->Caption = "(0, 0)";
00401                 LEnd->Caption = "(0, 0)";
00402                 SStart->Brush->Color = clBtnFace;
00403                 SEnd->Brush->Color = clBtnFace;
00404                 //LbName->Enabled = false;
00405                 LbName->ItemIndex = -1;
00406                 //EName->Enabled = false;
00407                 EName->Text = "";
00408                 //SbNameOkay->Enabled = false;
00409                 //SbNameDel->Enabled = false;
00410         }
00411         HistoAreaPaint(this);
00412         _beginSelect = false;
00413         _beginSelectEndpoint = false;
00414         _beginCut = false;
00415         _beginMove = false;
00416 }
00417 //---------------------------------------------------------------------------
00418 
00419 void __fastcall TTransferForm::SpeedButton1Click(TObject *Sender)
00420 {
00421         _updateColor();
00422 }
00423 //---------------------------------------------------------------------------
00424 
00425 void __fastcall TTransferForm::ENameKeyPress(TObject *Sender, char &Key)
00426 {
00427         if (Key == 13) {
00428                 SbNameOkayClick(this);
00429         } else {
00430                 int idx = LbName->Items->IndexOf(EName->Text);
00431                 if (idx != -1) LbName->ItemIndex = idx;
00432         }
00433 }
00434 //---------------------------------------------------------------------------
00435 
00436 void __fastcall TTransferForm::SbNameOkayClick(TObject *Sender)
00437 {
00438         int idx = LbName->Items->IndexOf(EName->Text);
00439         if (idx != -1) {
00440                 LbName->ItemIndex = idx;
00441         } else {
00442                 transe->areaNames->Add(EName->Text);
00443                 LbName->Items->Assign(transe->areaNames);
00444                 EName->Text = "";
00445         }
00446 }
00447 //---------------------------------------------------------------------------
00448 
00449 void __fastcall TTransferForm::LbNameClick(TObject *Sender)
00450 {
00451         if (LbName->ItemIndex != -1) {
00452                 EName->Text = (*LbName->Items)[LbName->ItemIndex];
00453                 TLine *l = transe->getSelected();
00454                 if (l) l->Name = LbName->ItemIndex;
00455         }
00456 }
00457 //---------------------------------------------------------------------------
00458 
00459 void __fastcall TTransferForm::SbNameDelClick(TObject *Sender)
00460 {
00461         if (LbName->ItemIndex != -1) {
00462                 transe->areaNames->Delete(LbName->ItemIndex);
00463                 LbName->Items->Assign(transe->areaNames);
00464                 EName->Text = "";
00465                 TLine *l = transe->getSelected();
00466                 if (l) l->Name = -1;
00467         }
00468 }
00469 //---------------------------------------------------------------------------
00470 
00471 void __fastcall TTransferForm::LbNameDblClick(TObject *Sender)
00472 {
00473         if (LbName->ItemIndex != -1) {
00474                 LbName->ItemIndex = -1;
00475                 EName->Text = "";
00476                 TLine *l = transe->getSelected();
00477                 if (l) l->Name = -1;
00478         }
00479 }
00480 //---------------------------------------------------------------------------
00481 
00482 void __fastcall TTransferForm::SbLoadClick(TObject *Sender)
00483 {
00484         if (OpenDialog1->Execute()) {
00485                 _di_IXMLDocument obj = LoadXMLDocument(OpenDialog1->FileName);
00486                 _di_IXMLNode doc = obj->DocumentElement;
00487                 if (transe->loadFromXLM(doc))
00488                         LbName->Items->Assign(transe->areaNames);
00489         }
00490 }
00491 //---------------------------------------------------------------------------
00492 
00493 void __fastcall TTransferForm::SbSaveClick(TObject *Sender)
00494 {
00495         if (SaveDialog1->Execute()) {
00496                 _di_IXMLDocument obj = NewXMLDocument("1.0");
00497                 _di_IXMLNode doc = obj->AddChild("Transferfunction");
00498                 if (transe->saveToXML(doc))
00499                         obj->SaveToFile(SaveDialog1->FileName);
00500         }
00501 }
00502 //---------------------------------------------------------------------------
00503 

Generated on Thu Jan 23 06:17:38 2003 for Vol by doxygen1.2.18