//***************************************************************************** // Copyright (c) 2004, Antivari Software Design //***************************************************************************** // // Naziv projekta : // Podsistem : // Datoteka : // Prevodilac : // Kopirano iz : // Datoteku oformio : // //***************************************************************************** // Opis: // // // //***************************************************************************** // Izmene: // // // //***************************************************************************** //---------------------------------------------------------------------------- // OS, VCL i Sistemska zaglavlja //---------------------------------------------------------------------------- #include #pragma hdrstop #include //---------------------------------------------------------------------------- // Standardna zaglavlja //---------------------------------------------------------------------------- #include #include //---------------------------------------------------------------------------- // Zajednicka zaglavlja //---------------------------------------------------------------------------- #include "..\..\..\_Shared\Code\MsgDlg\MBox.h" #include "..\..\..\_Shared\Code\ReadRes\ReadRes.h" #include "..\..\..\_Shared\Resource\CmnStr.rc" #include "..\..\..\_Shared\SubSys\Config\Config.h" //---------------------------------------------------------------------------- // Projektna zaglavlja //---------------------------------------------------------------------------- #include "Extended\Main\MainExt.h" #include "Extended\Main\MainExt.rc" #include "..\Resource\Addition\AddCfg.rc" extern TAntivariExtended *Ext; #include "..\SubSys\Options\HndOptns.h" extern TAntivariOptions *Opt; //---------------------------------------------------------------------------- // Lokalna zaglavlja //---------------------------------------------------------------------------- //---------------------------------------------------------------------------- // Privatna zaglavlja //---------------------------------------------------------------------------- #include "Area.h" #include "Area.rc" //---------------------------------------------------------------------------- // Pragma //---------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" #define MIN(a,b) (a)<(b)?(a):(b) #define MAX(a,b) (a)>(b)?(a):(b) //---------------------------------------------------------------------------- // Externi podaci //---------------------------------------------------------------------------- extern TAntivariConfiguration *Cfg; //---------------------------------------------------------------------------- // Privatni globalni podaci //---------------------------------------------------------------------------- TPovrsinaForm *PovrsinaForm; __fastcall TPovrsinaForm::TPovrsinaForm(TComponent* Owner) : TForm(Owner) { DoubleBuffered = true; GetProperties(); GoSetSubsystemResources(); XPos = new TStringList(); XPos->Clear(); YPos = new TStringList(); YPos->Clear(); Finished = false; OkButton->Enabled = false; PiEdit->Visible = false; LastMethod = ComboBox->ItemIndex; } void __fastcall TPovrsinaForm::FormActivate(TObject *Sender) { Image->Width = Image->Picture->Bitmap->Width; Image->Height = Image->Picture->Bitmap->Height; Image->Left = ( ClientWidth - Image->Width ) / 2; Image->Top = Image->Left; PaintBox->Left = Image->Left; PaintBox->Top = Image->Top; PaintBox->Width = Image->Width; PaintBox->Height = Image->Height; } int TPovrsinaForm::Count() { return ( XPos->Count ); } /* 0 - Intersection dosn't exists 1 - Intersection exists 2 - Two line segments are parallel 3 - Two line segments are collinear, but not overlap 4 - Two line segments are collinear, and share one same end point 5 - Two line segments are collinear, and overlap */ int TPovrsinaForm::SegmentIntersection( double PointA[2], double PointB[2], double PointC[2], double PointD[2] ) { double u, v, delta; double t1, t2; double a, b, c, d; double xba, yba, xdc, ydc, xca, yca; xba = PointB[0] - PointA[0]; yba = PointB[1] - PointA[1]; xdc = PointD[0] - PointC[0]; ydc = PointD[1] - PointC[1]; xca = PointC[0] - PointA[0]; yca = PointC[1] - PointA[1]; delta = xba * ydc - yba * xdc; t1 = xca * ydc - yca * xdc; t2 = xca * yba - yca * xba; if ( delta!=0 ) { u = t1 / delta; v = t2 / delta; /*two segments intersect (including intersect at end points)*/ if ( u<=1 && u>=0 && v<=1 && v>=0 ) return 1; else return 0; } else { /* AB & CD are parallel. */ if ( ( t1 != 0 ) && ( t2 != 0 ) ) return 2; /* when AB & CD are collinear */ /* if AB isn't a vertical line segment, project to x-axis */ if ( PointA[0] != PointB[0] ) { a = MIN( PointA[0], PointB[0] ); b = MAX( PointA[0], PointB[0] ); c = MIN( PointC[0], PointD[0] ); d = MAX( PointC[0], PointD[0] ); if ( ( db ) ) return 3; else if( ( d==a ) || ( c==b ) ) return 4; else return 5; } else /* if AB is a vertical line segment, project to y-axis */ { a = MIN( PointA[1], PointB[1] ); b = MAX( PointA[1], PointB[1] ); c = MIN( PointC[1], PointD[1] ); d = MAX( PointC[1], PointD[1] ); if( ( db ) ) return 3; else if( ( d==a ) || ( c==b ) ) return 4; else return 5; } } } void __fastcall TPovrsinaForm::PaintBoxMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { if ( Button == mbLeft ) { if ( LastMethod == 1 ) { if ( Finished == false ) { if ( Shift.Contains ( ssCtrl ) ) { if ( Count() > 2 ) { X = GetX ( 0 ); Y = GetY ( 0 ); XPos->Delete ( 0 ); YPos->Delete ( 0 ); if ( CanAdd ( X, Y ) == true ) { XPos->Add( IntToStr( X ) ); YPos->Add( IntToStr( Y ) ); LastX = X; LastY = Y; Finished = true; OkButton->Enabled = true; PiEdit->Visible = true; } XPos->Insert( 0, IntToStr( X ) ); YPos->Insert( 0, IntToStr( Y ) ); PaintBox->Repaint(); if ( Finished == true ) { PiEdit->Text = FormatFloat( C(IDS_SER_MAINEXT_PANELS_TAB_MERENJA_FORMAT), CalculateArea() ); MBox( ::X(IDS_SER_CMNSTR_UNDER_CONSTRUCTION), ::X(IDS_SER_AREA_CALC_EXPERIMENTAL) ); } } } if ( CanAdd( X, Y ) == true ) { XPos->Add( IntToStr( X ) ); YPos->Add( IntToStr( Y ) ); PaintBox->Repaint(); } } } else if ( LastMethod == 0 ) { if ( Finished == false ) { if ( Shift.Contains ( ssCtrl ) ) { if ( Count() > 0 ) { if ( CanAddLine( X, Y ) == true ) { XPos->Add( IntToStr( X ) ); YPos->Add( IntToStr( Y ) ); Finished = true; OkButton->Enabled = true; PiEdit->Visible = true; PaintBox->Repaint(); PiEdit->Text = FormatFloat( C(IDS_SER_MAINEXT_PANELS_TAB_MERENJA_FORMAT), CalculateLine() ); } } } else { if ( CanAddLine( X, Y ) == true ) { XPos->Add( IntToStr( X ) ); YPos->Add( IntToStr( Y ) ); PaintBox->Repaint(); } } } } } else if ( Button == mbRight ) { if ( Count() > 0 ) { int c = Count() - 1; XPos->Delete( c ); YPos->Delete( c ); Finished = false; OkButton->Enabled = false; PiEdit->Visible = false; PaintBox->Repaint(); } } } //--------------------------------------------------------------------------- void __fastcall TPovrsinaForm::FormDestroy(TObject *Sender) { delete XPos; delete YPos; } //--------------------------------------------------------------------------- int TPovrsinaForm::GetX( int X ) { return ( StrToInt( XPos->Strings[ X ] ) ); } int TPovrsinaForm::GetY( int Y ) { return ( StrToInt( YPos->Strings[ Y ] ) ); } void __fastcall TPovrsinaForm::PaintBoxPaint(TObject *Sender) { GoPaint(); } //--------------------------------------------------------------------------- void __fastcall TPovrsinaForm::PaintBoxMouseMove(TObject *Sender, TShiftState Shift, int X, int Y) { if ( Finished == false ) { LastX = X; LastY = Y; PaintBox->Repaint(); } } //--------------------------------------------------------------------------- void TPovrsinaForm::GoPaint() { PaintBox->Canvas->Pen->Width = Precision; PaintBox->Canvas->Pen->Color = AreaLine; if ( Count() > 0 ) PaintBox->Canvas->MoveTo( GetX(0), GetY(0) ); for ( int i=0; iCanvas->LineTo( GetX(i), GetY(i) ); } if ( Count() > 0 && Finished == false ) { PaintBox->Canvas->Pen->Color = GuideLine; PaintBox->Canvas->LineTo( LastX, LastY ); PaintBox->Canvas->Pen->Color = AreaLine; } } bool TPovrsinaForm::CanAddLine( int X, int Y ) { if ( Count() < 1 ) return ( true ); //int firstxpos = GetX ( 0 ); //int firstypos = GetY ( 0 ); int lastxpos = GetX ( Count() - 1 ); //int lastypos = GetY ( Count() - 1 ); if ( lastxpos > X ) return ( false ); //if ( firstypos > Y ) // return ( false ); return ( true ); } bool TPovrsinaForm::CanAdd( int X, int Y ) { if ( Count() < 1 ) return ( true ); double pa[2], pb[2], pc[2], pd[2]; pa[0] = (double) X; pa[1] = (double) Y; pb[0] = (double) GetX ( Count() - 1 ); pb[1] = (double) GetY ( Count() - 1 ); for ( int i=0; i