Скачиваний:
9
Добавлен:
01.05.2014
Размер:
3.58 Кб
Скачать
//File Cview.cpp
//Naznachenie: Opredelenie funkcij klassa "nabor cvetnyh mnogougolnikov na planshete"
//Author: Pavel Morozov
//Redakcija: 2.0 13.04.07


#ifndef cview_cpp
#define cview_cpp

#include<iostream.h>
#include<math.h>
#include<conio.h>
#include<stdio.h>
#include"cview.h"
#include"ctablet.cpp"
#include"cplist.h"
#include"cplist.cpp"

//--------------------Konstruktor--------------------------
	       CView::CView(CPolyList *ListPoly0):ID(HistNum+1)
           {
             ListPoly=ListPoly0;
             textcolor(9);
	     HistNum=HistNum+1;
	     Counter++;
	     cprintf("\nKonstruktor CView sozdaet ekzempliar klassa s ID = ");
	     cout<<endl;
	     cout<<GetID();
	     cprintf(", HistNum= ");
	     cout<<GetHistNum();
             cprintf(", Counter= ");
	     cout<<GetCounter()<<endl;
             textcolor(15);

          }
//-----------------Funkcii interfejsa----------------------
void CView::SetPtr( CPolyList *ListPoly0)
//Ustanovit ukazatel na element
	  { 
           ListPoly=ListPoly0;
          }



	  void CView::OutList()
                {

		 GetList()->OutListPoly();
		 CPlanshet::OutList();
                 float x_1,y_1,x_2,y_2,x_3,y_3,x_4,y_4;	
		 }


          void CView::Move_Set_Planshet_dx_dy(float dx,float dy)
		{
                 int t=0;
		 GetList()->MovePoly(dx,dy,t);
		 CPlanshet::MoveFigure(dx,dy);
                }

	

	  void CView::Move_Set(float dx, float dy,int t)
                {

float x_1,y_1,x_2,y_2,x_3,y_3,x_4,y_4,Ax0,Ay0,Bx0,By0,Cx0,Cy0,Dx0,Dy0;
GetList()->MovePoly(dx,dy,t);	
GetList()->GetXY(x_1,y_1,x_2,y_2,x_3,y_3,x_4,y_4,t);
CPlanshet::GetFigureXY(Ax0,Ay0,Bx0,By0,Cx0,Cy0,Dx0,Dy0);

if((Ax0>x_1)||(Bx0<x_1)||(Ax0>x_2)||(Bx0<x_2)||(Ax0>x_3)||(Bx0<x_3)||(Ax0>x_4)||(Bx0<x_4)||(Ay0<y_1)||(Cy0>y_1)||(Ay0<y_2)||(Cy0>y_2)||(Ay0<y_3)||(Cy0>y_3)||(Ay0<y_4)||(Cy0>y_4))
{cout<<"Figura ne lezit na planshete, povtorite popytku";GetList()->MovePoly(-dx,-dy,t);}

                 }

void CView::MoveFigure(float dx,float dy)
{
int i=1;
float x_1,y_1,x_2,y_2,x_3,y_3,x_4,y_4,Ax0,Ay0,Bx0,By0,Cx0,Cy0,Dx0,Dy0;



CPlanshet::MoveFigure(dx,dy);
CPlanshet::GetFigureXY(Ax0,Ay0,Bx0,By0,Cx0,Cy0,Dx0,Dy0);

while(i<GetList()->GetCounter())
{

GetList()->GetXY(x_1,y_1,x_2,y_2,x_3,y_3,x_4,y_4,i);
if((Ax0>x_1)||(Bx0<x_1)||(Ax0>x_2)||(Bx0<x_2)||(Ax0>x_3)||(Bx0<x_3)||(Ax0>x_4)||(Bx0<x_4)||(Ay0<y_1)||(Cy0>y_1)||(Ay0<y_2)||(Cy0>y_2)||(Ay0<y_3)||(Cy0>y_3)||(Ay0<y_4)||(Cy0>y_4))
{
cout<<"Figura ne lezit na planshete, povtorite popytku";
CPlanshet::MoveFigure(-dx,-dy);break;
}
i=i+1;
}
}


         CPolyList *CView::GetList()
          {return ListPoly;}

	unsigned int CView::GetID()
        //Poluchit ukazatel na predydushij element
		    { return ID;}

	unsigned int CView::GetHistNum()
        // Poluchit kolichestvo sozdannyh objektov
        { return HistNum;}


	unsigned int CView::GetCounter()
        // Poluchit kolichestvo sushestvujushih objektov
        {return Counter;}
                 
//-----------------------Destruktor------------------------
	       CView::~CView()
		{ 

                  	   cout<<endl;
           textcolor(10);

	   cprintf("~CView razrushaet objekt...s ID =");
           cout<<GetID()<<endl;
	   cout<<endl;
	   cprintf("Objekt unichtozen") ;
	   cout<<endl;
	   cprintf("Nazmite probel...");
	   cout<<endl;
	   getch();
	   textcolor(15);

           if(ListPoly){delete ListPoly;}
                 
                 }

#endif
Соседние файлы в папке LAB 3