Скачиваний:
17
Добавлен:
01.05.2014
Размер:
24.14 Кб
Скачать
//---------------------------------------------------------------------
#include <vcl.h>
#include <math.h>
#include <Clipbrd.hpp>
#pragma hdrstop

#include "ChildWin.h"
#include "Unit1.h"
#include "Unit2.h"
#include "PointCoords.h"
#include "Main.h"

//---------------------------------------------------------------------
#pragma resource "*.dfm"
//---------------------------------------------------------------------

__fastcall TfrmMDIChild::TfrmMDIChild(TComponent *Owner)
	: TForm(Owner)
{
}
//---------------------------------------------------------------------

void __fastcall TfrmMDIChild::FormClose(TObject *Sender, TCloseAction &Action)
{
    DeleteObject(brushField);
    DeleteObject(brushPoint);
    DeleteObject(brushRect);
    DeleteObject(penField);
    DeleteObject(penLine);
    DeleteObject(penPoint);
    DeleteObject(penRect);

	ReleaseDC(Panel1->Handle, panelHDC);

	Action = caFree;
}
//---------------------------------------------------------------------

void __fastcall TfrmMDIChild::FormCreate(TObject *Sender)
{
    panelHDC = GetDC(Panel1->Handle);

    brushField = CreateSolidBrush(clWhite);
    brushPoint = CreateSolidBrush(clRed);
    brushRect  = CreateSolidBrush(RGB(197, 227, 245)); //GetStockObject(NULL_BRUSH);
    brushLocus = CreateSolidBrush(RGB(197, 245, 227)); //GetStockObject(NULL_BRUSH);

    penField = CreatePen(PS_SOLID, 1, clWhite);
    penLine  = CreatePen(PS_DOT,   1, clBlack);
    penPoint = CreatePen(PS_SOLID, 1, clBlack);
    penRect  = CreatePen(PS_DOT,   2, clBlack);
    penLocus = CreatePen(PS_SOLID, 1, clBlack);


    oldWindowProc = Panel1->WindowProc;
    Panel1->WindowProc = SubClassWndProc;

    isNewRect = 1;

    isDrawLines = 1;
    zoom = 1.0;
	pWidth = 1000;
	pHeight= 1000;

    Panel1->ClientWidth = getZoomCoord(pWidth, zoom);
    Panel1->ClientHeight= getZoomCoord(pHeight,zoom);

    randomize();
}
//---------------------------------------------------------------------------

void __fastcall TfrmMDIChild::Panel1DblClick(TObject *Sender)
{
	TControl *obj = ScrollBox1/*Panel1*/;
	TPoint pt = obj->ClientToScreen(TPoint(obj->Left, obj->Top));

    int x = getRealX(Mouse->CursorPos.x - pt.x + ScrollBox1->HorzScrollBar->Position, zoom);
    int y = getRealY(Mouse->CursorPos.y - pt.y + ScrollBox1->VertScrollBar->Position, zoom, Panel1->ClientHeight);

    addPoint(TPoint(x, y));
}
//---------------------------------------------------------------------------

void __fastcall TfrmMDIChild::paintLine(HDC hDC, const TPoint& point)
{
	int x = getZoomX(point.x, zoom);
	int y = getZoomY(point.y, zoom, pHeight);

  	MoveToEx(hDC, 0, y, NULL);
    LineTo(hDC, Panel1->ClientWidth, y);

    MoveToEx(hDC, x, 0, NULL);
   	LineTo(hDC, x, Panel1->ClientHeight);
}
//---------------------------------------------------------------------------

void __fastcall TfrmMDIChild::paintPoint(HDC hDC, const TPoint& point, int isActivePoint)
{
    int x = getZoomX(point.x, zoom);
    int y = getZoomY(point.y, zoom, pHeight);

   	Ellipse(hDC, x - POINT_R, y - POINT_R, x + POINT_R, y + POINT_R);

    if (isActivePoint) {
	    MoveToEx(hDC, x - POINT_A, y - POINT_A, NULL);
	      LineTo(hDC, x - POINT_A, y - POINT_A + POINT_R);
	    MoveToEx(hDC, x - POINT_A, y - POINT_A, NULL);
	      LineTo(hDC, x - POINT_A + POINT_R, y - POINT_A);
	    MoveToEx(hDC, x + POINT_A, y + POINT_A, NULL);
	      LineTo(hDC, x + POINT_A, y + POINT_A - POINT_R);
	    MoveToEx(hDC, x + POINT_A, y + POINT_A, NULL);
          LineTo(hDC, x + POINT_A - POINT_R, y + POINT_A);
	    MoveToEx(hDC, x + POINT_A, y - POINT_A, NULL);
	      LineTo(hDC, x + POINT_A, y - POINT_A + POINT_R);
	    MoveToEx(hDC, x + POINT_A, y - POINT_A, NULL);
          LineTo(hDC, x + POINT_A - POINT_R, y - POINT_A);

	    MoveToEx(hDC, x - POINT_A, y + POINT_A, NULL);
	      LineTo(hDC, x - POINT_A, y + POINT_A - POINT_R);
	    MoveToEx(hDC, x - POINT_A, y + POINT_A, NULL);
	      LineTo(hDC, x - POINT_A + POINT_R, y + POINT_A);
    }
}
//---------------------------------------------------------------------------

void __fastcall TfrmMDIChild::paintField(HDC hdc, int isDrawLines)
{
	HGDIOBJ hgdiPen;
	HGDIOBJ hgdiBrush;

	tempHDC = CreateCompatibleDC(hdc);
	HBITMAP hbm = CreateCompatibleBitmap(hdc, Panel1->ClientWidth, Panel1->ClientHeight);
	HBITMAP hbmOld = (HBITMAP)SelectObject(tempHDC, hbm);

  	hgdiBrush = SelectObject(tempHDC, brushField);
  	hgdiPen   = SelectObject(tempHDC, penField);

    Rectangle(tempHDC, 0, 0, Panel1->ClientWidth, Panel1->ClientHeight);

    if (pointList.getPointCount()) {
	SelectObject(tempHDC, penRect);
	SelectObject(tempHDC, brushRect);
    Rectangle(tempHDC,	activeRect.rect.left, activeRect.rect.top, activeRect.rect.right, activeRect.rect.bottom);

    if (isDrawLines) {
	    SelectObject(tempHDC, penLine);
		for (TPointListConstIterator ii = pointList.begin(); ii != pointList.end(); ++ii) {
			paintLine(tempHDC, (*ii)->point);
	    }
    }

	SelectObject(tempHDC, penLocus);
	SelectObject(tempHDC, brushLocus);

    int xc = getZoomX(currentLocus.rect.right, zoom);
    int x1 = getZoomX(locus1.rect.right, zoom);
    int x2 = getZoomX(locus2.rect.right, zoom);
    int x3 = getZoomX(locus3.rect.right, zoom);
    int x4 = getZoomX(locus4.rect.right, zoom);

    if (xc > Panel1->ClientWidth) xc = Panel1->ClientWidth-1;
    if (x1 > Panel1->ClientWidth) x1 = Panel1->ClientWidth-1;
    if (x2 > Panel1->ClientWidth) x2 = Panel1->ClientWidth-1;
    if (x3 > Panel1->ClientWidth) x3 = Panel1->ClientWidth-1;
    if (x4 > Panel1->ClientWidth) x4 = Panel1->ClientWidth-1;


    Rectangle(tempHDC,	getZoomX(currentLocus.rect.left, zoom),
    					getZoomY(currentLocus.rect.top,  zoom, pHeight)+1,
                        xc,
                        getZoomY(currentLocus.rect.bottom,zoom, pHeight)+1);
    Rectangle(tempHDC,	getZoomX(locus1.rect.left, zoom),
    					getZoomY(locus1.rect.top,  zoom, pHeight)+1,
                        x1,
                        getZoomY(locus1.rect.bottom,zoom, pHeight)+1);
    Rectangle(tempHDC,  getZoomX(locus2.rect.left, zoom),
    					getZoomY(locus2.rect.top,  zoom, pHeight)+1,
                        x2,
                        getZoomY(locus2.rect.bottom,zoom, pHeight)+1);
    Rectangle(tempHDC, 	getZoomX(locus3.rect.left, zoom),
    					getZoomY(locus3.rect.top,  zoom, pHeight)+1,
                        x3,
                        getZoomY(locus3.rect.bottom,zoom, pHeight)+1);
    Rectangle(tempHDC,  getZoomX(locus4.rect.left, zoom),
    					getZoomY(locus4.rect.top,  zoom, pHeight)+1,
                        x4,
                        getZoomY(locus4.rect.bottom,zoom, pHeight)+1);
    SetBkMode(tempHDC, TRANSPARENT);
    TextOut(tempHDC, getZoomX(currentLocus.rect.left,zoom),
    				 getZoomY(currentLocus.rect.bottom, zoom, pHeight),
                     AnsiString(currentLocus.domination).c_str(), AnsiString(currentLocus.domination).Length());
    TextOut(tempHDC, getZoomX(locus1.rect.left,zoom),
    				 getZoomY(locus1.rect.bottom, zoom, pHeight),
                     AnsiString(locus1.domination).c_str(), AnsiString(locus1.domination).Length());
    TextOut(tempHDC, getZoomX(locus2.rect.left,zoom),
    				 getZoomY(locus2.rect.bottom, zoom, pHeight),
                     AnsiString(locus2.domination).c_str(), AnsiString(locus2.domination).Length());
    TextOut(tempHDC, getZoomX(locus3.rect.left,zoom),
    				 getZoomY(locus3.rect.bottom, zoom, pHeight),
                     AnsiString(locus3.domination).c_str(), AnsiString(locus3.domination).Length());
    TextOut(tempHDC, getZoomX(locus4.rect.left,zoom),
    				 getZoomY(locus4.rect.bottom, zoom, pHeight),
                     AnsiString(locus4.domination).c_str(), AnsiString(locus4.domination).Length());

    SelectObject(tempHDC, penPoint);
    SelectObject(tempHDC, brushPoint);
	for (TPointListConstIterator ii = pointList.begin(); ii != pointList.end(); ++ii) {
	    paintPoint(tempHDC, (*ii)->point, ((*ii)->number == activePoint.number));
    }
    }

	SelectObject(tempHDC, hgdiPen);
	SelectObject(tempHDC, hgdiBrush);

	// copy to the destination DC resulting image
	BitBlt(hdc, 0, 0, Panel1->ClientWidth, Panel1->ClientHeight, tempHDC, 0, 0, SRCCOPY);
	SelectObject(tempHDC, hbmOld);
	DeleteDC(tempHDC);
	DeleteObject(hbm);
}
//---------------------------------------------------------------------------

void __fastcall TfrmMDIChild::SubClassWndProc(Messages::TMessage &Message)
{
	if (Message.Msg == WM_PAINT) {
	    PAINTSTRUCT pc;
    	BeginPaint(Panel1->Handle, &pc);
		paintField(panelHDC, isDrawLines);
    	EndPaint(Panel1->Handle, &pc);
	}
	else
		oldWindowProc(Message);
}
//---------------------------------------------------------------------------

MyPoint __fastcall TfrmMDIChild::addPoint(const TPoint& point)
{
	if (pointList.getPointInArea(point, POINT_A) != NULL_POINT) return NULL_MYPOINT;
	activePoint = pointList.addPoint(point);

    if (activePoint != NULL_MYPOINT) {
	    TListItem *ListItem = ListView1->Items->Add();
		ListItem->Caption = activePoint.number;
	    ListItem->SubItems->Add(activePoint.point.x);
	    ListItem->SubItems->Add(activePoint.point.y);
    }

    Panel1->Invalidate();

    FormActivate(this);

    return activePoint;
}
//---------------------------------------------------------------------------

void __fastcall TfrmMDIChild::movePoint(const TPoint& point)
{
	if (activePoint != NULL_MYPOINT && activePoint.point != point) {
      	activePoint = pointList.movePoint(activePoint, point);


        for (int i = 0; i < ListView1->Items->Count; i++)
           	if (ListView1->Items->Item[i]->Caption == activePoint.number) {
				ListView1->Items->Item[i]->SubItems->Strings[0] = activePoint.point.x;
                ListView1->Items->Item[i]->SubItems->Strings[1] = activePoint.point.y;
            }

	    Panel1->Invalidate();
    }

    FormActivate(this);
}
//---------------------------------------------------------------------------


void __fastcall TfrmMDIChild::Panel1MouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y)
{
    MyPoint temp = pointList.getPointInArea(TPoint(getRealX(X,zoom),getRealY(Y,zoom, Panel1->ClientHeight)), POINT_A);

    if (temp != activePoint) {
	    activePoint = temp;

        for (int i = 0; i < ListView1->Items->Count; i++)
          	if (ListView1->Items->Item[i]->Caption == activePoint.number) {
	            ListView1->Items->Item[i]->Selected = true;
	            ListView1->Items->Item[i]->MakeVisible(false);
                break;
            }

    	Panel1->Invalidate();
    }

    if (Shift.Contains(ssShift)) {
	 	activeRect.rect.top   = Y;
		activeRect.rect.right = X;
	 	activeRect.rect.left  = X;
		activeRect.rect.bottom= Y;
    }
    else {
	 	activeRect = NULL_MYRECT;
        currentLocus = NULL_LOCUS;
        locus1 = NULL_LOCUS;
        locus2 = NULL_LOCUS;
        locus3 = NULL_LOCUS;
        locus4 = NULL_LOCUS;
        MainForm->StatusBar->Panels->Items[3]->Text = "Число точек: 0";
        MainForm->StatusBar->Panels->Items[4]->Text = "";
        MainForm->StatusBar->Panels->Items[5]->Text = "";
        MainForm->StatusBar->Panels->Items[6]->Text = "";
        MainForm->StatusBar->Panels->Items[7]->Text = "";

    	Panel1->Invalidate();
    }

    TLocus locus = pointList.getLocus(TPoint(getRealX(X,zoom),getRealY(Y,zoom, Panel1->ClientHeight)));
	paintLocus(locus);

    actMovePoint->Update();
    actDeletePoint->Update();
}
//---------------------------------------------------------------------------

void __fastcall TfrmMDIChild::Panel1MouseMove(TObject *Sender, TShiftState Shift, int X, int Y)
{
	if (Shift.Contains(ssLeft)) {

       	if (Shift.Contains(ssShift)) {

	    	if (X < 2) X = 2;
    	    if (Y < 2) Y = 2;
            if (activeRect == NULL_MYRECT) {
	 			activeRect.rect.left = X;
				activeRect.rect.top  = Y;
            }
    	 	activeRect.rect.right = X;
 			activeRect.rect.bottom= Y;

            /*
            int x1, x2, y1, y2;
           	x1 = getRealX(activeRect.rect.left, zoom);
            x2 = getRealX(activeRect.rect.right, zoom);
			y1 = getRealY(activeRect.rect.top, zoom, Panel1->Height);
            y2 = getRealY(activeRect.rect.bottom, zoom, Panel1->Height);
            if (x1 > x2) swap(x1, x2);
            if (y1 > y2) swap(y1, y2);
            /*int rslt = pointList.getPointCountInRect(MyRect(x1, y1, x2, y2), locus1, locus2, locus3, locus4);

            MainForm->StatusBar->Panels->Items[3]->Text = "Число точек: " + (rslt != -1 ? IntToStr(rslt) : AnsiString("..."));
            MainForm->StatusBar->Panels->Items[4]->Text = LocusCoordsToStr(locus1);
            MainForm->StatusBar->Panels->Items[5]->Text = LocusCoordsToStr(locus2);
            MainForm->StatusBar->Panels->Items[6]->Text = LocusCoordsToStr(locus3);
            MainForm->StatusBar->Panels->Items[7]->Text = LocusCoordsToStr(locus3);
            */
	        currentLocus = NULL_LOCUS;
	        locus1 = NULL_LOCUS;
    	    locus2 = NULL_LOCUS;
        	locus3 = NULL_LOCUS;
	        locus4 = NULL_LOCUS;
        }
        else {
	   		int x = getRealX(X, zoom);
	    	int y = getRealY(Y, zoom, Panel1->ClientHeight);
           	if (x >= 1 && x <= pWidth && y >= 1 && y <= Panel1->ClientHeight)
	        	movePoint(TPoint(x, y));
        }

        Panel1->Invalidate();
    }
    MainForm->StatusBar->Panels->Items[1]->Text = "Координаты: " + IntToStr(getRealX(X,zoom)) + "," + IntToStr(getRealY(Y,zoom, Panel1->ClientHeight));
}
//---------------------------------------------------------------------------

void __fastcall TfrmMDIChild::actDeletePointExecute(TObject *Sender)
{
	pointList.deletePoint(activePoint);

    for (int i = 0; i < ListView1->Items->Count; i++)
       	if (ListView1->Items->Item[i]->Caption == activePoint.number) {
        	ListView1->Items->Item[i]->Delete();
            break;
    	}

    activePoint = NULL_MYPOINT;

   	Panel1->Invalidate();

    FormActivate(this);
}
//---------------------------------------------------------------------------

void __fastcall TfrmMDIChild::actDeletePointUpdate(TObject *Sender)
{
	actDeletePoint->Enabled = (activePoint != NULL_MYPOINT);
    MainForm->actDeletePoint->Enabled = actDeletePoint->Enabled;

	actMovePoint->Enabled = (activePoint != NULL_MYPOINT);
    MainForm->actMovePoint->Enabled = actMovePoint->Enabled;
}
//---------------------------------------------------------------------------

void __fastcall TfrmMDIChild::actMovePointExecute(TObject *Sender)
{
	frmPointCoords->x = activePoint.point.x;
	frmPointCoords->y = activePoint.point.y;
	frmPointCoords->ShowModal();
    if (frmPointCoords->ModalResult == mrOk) {
	    movePoint(TPoint(frmPointCoords->x, frmPointCoords->y));
    }

    Panel1->Invalidate();

    FormActivate(this);
}
//---------------------------------------------------------------------------

void __fastcall TfrmMDIChild::actInsertPointExecute(TObject *Sender)
{
	frmPointCoords->x = 1;
	frmPointCoords->y = 1;
	frmPointCoords->ShowModal();
    if (frmPointCoords->ModalResult == mrOk) {
	    addPoint(TPoint(frmPointCoords->x, frmPointCoords->y));
    }
}
//---------------------------------------------------------------------------

void __fastcall TfrmMDIChild::ListView1Click(TObject *Sender)
{
	try {
	    int x = StrToInt(ListView1->Selected->SubItems->Strings[0]);
        int y = StrToInt(ListView1->Selected->SubItems->Strings[1]);

	    activePoint = pointList.getPointInArea(TPoint(x, y), POINT_A);

	    Panel1->Invalidate();
    }
    catch(...) {}
}
//---------------------------------------------------------------------------

void __fastcall TfrmMDIChild::ListView1DblClick(TObject *Sender)
{
	try
    {
    	actMovePoint->Execute();
    }
    catch(...) {}
}
//---------------------------------------------------------------------------

void TfrmMDIChild::TraceFunc(const TLocus& locus)
{
}
//---------------------------------------------------------------------------

void __fastcall TfrmMDIChild::actAlgRunUpdate(TObject *Sender)
{
	dynamic_cast<TAction*>(Sender)->Enabled = (pointList.getPointCount());
}
//---------------------------------------------------------------------------

void __fastcall TfrmMDIChild::actAlgStepUpdate(TObject *Sender)
{
	dynamic_cast<TAction*>(Sender)->Enabled = (pointList.getPointCount());
}
//---------------------------------------------------------------------------

void __fastcall TfrmMDIChild::actAlgStopUpdate(TObject *Sender)
{
	dynamic_cast<TAction*>(Sender)->Enabled = (currentLocus != NULL_LOCUS);
}
//---------------------------------------------------------------------------

void __fastcall TfrmMDIChild::actAlgStopExecute(TObject *Sender)
{
	currentLocus = NULL_LOCUS;

    locus1 = NULL_LOCUS;
    locus2 = NULL_LOCUS;
    locus3 = NULL_LOCUS;
    locus4 = NULL_LOCUS;

    Panel1->Invalidate();

    actAlgStop->Enabled = false;
}
//---------------------------------------------------------------------------

void __fastcall TfrmMDIChild::actAlgRunExecute(TObject *Sender)
{
	actAlgStep->Execute();
    while (currentLocus != NULL_LOCUS || locus1 != NULL_LOCUS || locus2 != NULL_LOCUS ||
    								     locus3 != NULL_LOCUS || locus4 != NULL_LOCUS) actAlgStep->Execute();
    paintLocus(currentLocus);

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

void __fastcall TfrmMDIChild::actAlgStepExecute(TObject *Sender)
{
	if (pointList.IsModified()) currentLocus = pointList.preprocessingStep(currentLocus == NULL_LOCUS);

	if (currentLocus == NULL_LOCUS) {
    	if (activeRect != NULL_MYRECT) {
            int x1, x2, y1, y2;
           	x1 = getRealX(activeRect.rect.left, zoom);
            x2 = getRealX(activeRect.rect.right, zoom);
			y1 = getRealY(activeRect.rect.top, zoom, Panel1->ClientHeight);
            y2 = getRealY(activeRect.rect.bottom, zoom, Panel1->ClientHeight);
            if (x1 > x2) swap(x1, x2);
            if (y1 > y2) swap(y1, y2);

            if (locus1 == NULL_LOCUS) locus1= pointList.getLocus(TPoint(x2,y2)); else
            if (locus2 == NULL_LOCUS) locus2= pointList.getLocus(TPoint(x1,y2)); else
            if (locus3 == NULL_LOCUS) locus3= pointList.getLocus(TPoint(x1,y1)); else
            if (locus4 == NULL_LOCUS) {
	            locus4= pointList.getLocus(TPoint(x2,y1));

	           	Panel1->Repaint();

    	        int rslt = pointList.getPointCountInRect(MyRect(x1, y1, x2, y2), locus1, locus2, locus3, locus4);

	            ShowMessage("Число точек в области: " + IntToStr(rslt));

			    locus1 = NULL_LOCUS;
			    locus2 = NULL_LOCUS;
    			locus3 = NULL_LOCUS;
		    	locus4 = NULL_LOCUS;
            }
           	Panel1->Repaint();
        }

        actAlgStop->Enabled = false;
    }
    else {
	    paintLocus(currentLocus);
        actAlgStop->Enabled = true;
    }

   	Panel1->Invalidate();

    FormActivate(this);
}
//---------------------------------------------------------------------------

AnsiString __fastcall TfrmMDIChild::LocusCoordsToStr(TLocus &locus)
{
	if (locus == NULL_LOCUS) return "NULL";

    AnsiString
    	left = locus.rect.left  != INFINITY ? IntToStr(locus.rect.left)  : AnsiString("%"),
        top  = locus.rect.top   != INFINITY ? IntToStr(locus.rect.top)   : AnsiString("%"),
        right= locus.rect.right != INFINITY ? IntToStr(locus.rect.right) : AnsiString("%"),
       bottom= locus.rect.bottom!= INFINITY ? IntToStr(locus.rect.bottom): AnsiString("%");

	return "(" + left  + "," + top + "," + right + "," + bottom + ")";
}
//---------------------------------------------------------------------------

void __fastcall TfrmMDIChild::setField()
{
	for (int i = 0 ; i < ListView1->Items->Count; i++) {
    	addPoint(TPoint(StrToInt(ListView1->Items->Item[i]->SubItems->Strings[0]), StrToInt(ListView1->Items->Item[i]->SubItems->Strings[1])));
    }

   	Panel1->Invalidate();
}
//---------------------------------------------------------------------------

void __fastcall TfrmMDIChild::setOptions()
{
	Form2 = new TForm2(this);
	Form2->ShowModal();
    delete Form2;
}
//---------------------------------------------------------------------------

void TfrmMDIChild::setZoom(float zoom)
{
	if (zoom >= 0.25 || zoom <= 2.00) {
    	fzoom = zoom;
        Panel1->ClientWidth = getZoomCoord(pWidth, fzoom);
        Panel1->ClientHeight= getZoomCoord(pHeight,fzoom);
    }
}
//---------------------------------------------------------------------------

float TfrmMDIChild::getZoom()
{
	return fzoom;
}
//---------------------------------------------------------------------------

void __fastcall TfrmMDIChild::N14Click(TObject *Sender)
{
	if (SaveDialog1->Execute()) {
        Graphics::TBitmap* bitmap = new Graphics::TBitmap();
		bitmap->Width = Panel1->ClientWidth;
	    bitmap->Height = Panel1->ClientHeight;
    	bitmap->Canvas->Lock();
		paintField(bitmap->Canvas->Handle, isDrawLines);
        bitmap->Canvas->Unlock();

        bitmap->SaveToFile(SaveDialog1->FileName);

        delete bitmap;
    }
}
//---------------------------------------------------------------------------

void __fastcall TfrmMDIChild::N15Click(TObject *Sender)
{
        Graphics::TBitmap* bitmap = new Graphics::TBitmap();
		bitmap->Width = Panel1->ClientWidth;
	    bitmap->Height = Panel1->ClientHeight;
    	bitmap->Canvas->Lock();
		paintField(bitmap->Canvas->Handle, isDrawLines);
        bitmap->Canvas->Unlock();

		int DataHandle;
		HPALETTE APalette;
		unsigned short MyFormat;
    	bitmap->SaveToClipboardFormat(MyFormat, DataHandle, APalette);
	    Clipboard()->SetAsHandle(MyFormat,DataHandle);

        delete bitmap;
}
//---------------------------------------------------------------------------

void __fastcall TfrmMDIChild::FormActivate(TObject *Sender)
{
    MainForm->StatusBar->Panels->Items[2]->Text = pointList.IsModified() ? "Изменение" : "";
}
//---------------------------------------------------------------------------

void __fastcall TfrmMDIChild::paintLocus(const TLocus& locus)
{
	TListItem *li = ListView2->Items->Item[0];
    if (locus != NULL_LOCUS) {
	    li->Caption = locus.rect.left != INFINITY ? IntToStr(locus.rect.left) : AnsiString("%");
	    li->SubItems->Strings[0] = (locus.rect.bottom != INFINITY ? IntToStr(locus.rect.bottom) : AnsiString("%"));
    	li->SubItems->Strings[1] = (locus.rect.right != INFINITY ? IntToStr(locus.rect.right) : AnsiString("%"));
	    li->SubItems->Strings[2] = (locus.rect.top != INFINITY ? IntToStr(locus.rect.top) : AnsiString("%"));
    	li->SubItems->Strings[3] = (locus.domination);
    }
    else {
		TListItem *li = ListView2->Items->Item[0];
    	li->Caption = "NULL";
	    li->SubItems->Strings[0] = "NULL";
    	li->SubItems->Strings[1] = "NULL";
	    li->SubItems->Strings[2] = "NULL";
    	li->SubItems->Strings[3] = 0;
    }
}
//---------------------------------------------------------------------------

void __fastcall TfrmMDIChild::actAlgStepPreExecute(TObject *Sender)
{
	currentLocus = pointList.preprocessingStep(currentLocus == NULL_LOCUS);

    if (currentLocus == NULL_LOCUS) ShowMessage("Предоработка закончена.");

    actAlgStop->Enabled = currentLocus != NULL_LOCUS;

   	Panel1->Invalidate();

    FormActivate(this);
}
//---------------------------------------------------------------------------

void __fastcall TfrmMDIChild::actAlgStepPreUpdate(TObject *Sender)
{
	dynamic_cast<TAction*>(Sender)->Enabled = (pointList.getPointCount());
}
//---------------------------------------------------------------------------

Соседние файлы в папке Sources