Скачиваний:
6
Добавлен:
01.05.2014
Размер:
2.92 Кб
Скачать

/********************************************************************************/
#include "stdafx.h"
#include "TrapeziumEntity.h"
#include <iostream>
/********************************************************************************/

CTrapeziumEntity::CTrapeziumEntity( const int  iC,
									const int  iB,  const int  iH,
									const int iX,	const int iY )
: CPointEntity(iX, iY),
  CTriangleEntity(iB, iH, iX, iY)
{
	setCutoff( iC );
}
	
/********************************************************************************/

CTrapeziumEntity::~CTrapeziumEntity()
{

}

/********************************************************************************/

int CTrapeziumEntity::getCutoff() const
{
	return mCutoff;
}

/********************************************************************************/

void CTrapeziumEntity::setCutoff( int iC )
{
	mCutoff = (iC > 0)? (iC < mHeight)? iC : mHeight : 0;
}

/********************************************************************************/
	
void CTrapeziumEntity::Printfig(std::ostream& os)
{
	os	<< "Trapezium:"<<std::endl;
	os	<< " X=" << mX<<std::endl;
	os	<< " Y=" << mY<<std::endl;
	os	<< " B=" << mBase<<std::endl;
	os	<< " C=" << mCutoff<<std::endl;
}

int CTrapeziumEntity::getNumType()
{ return 2; 
}
/********************************************************************************/
void CTrapeziumEntity::Draw(CDC* pDC, Shape* figure)
{  
CPen aPen; 
   COLORREF aColor=RGB(0,0,0);

   if(this == figure)                  
      aColor = RGB(255,0,0);

   if(!aPen.CreatePen(PS_SOLID, 1, aColor))
   {                                           
      AfxMessageBox("Pen creation failed drawing a rectangle", MB_OK);
      AfxAbort();
   }

   CPen* pOldPen = pDC->SelectObject(&aPen);  


   CPoint Start(getX(),getY()+getHeight());
   CPoint End(getX()+getCutoff(),getY());

	pDC->MoveTo(Start);
	pDC->LineTo(End);

  Start=End;
  End.x=getX()+getBase()-getCutoff();
  End.y=getY();
	pDC->MoveTo(Start);
	pDC->LineTo(End);

  Start=End;
  End.x=getX()+getBase();
  End.y=getY()+getHeight();
	pDC->MoveTo(Start);
	pDC->LineTo(End);

  Start=End;
  End.x=getX();
  End.y=getY()+getHeight();
	pDC->MoveTo(Start);
	pDC->LineTo(End);

   pDC->SelectObject(pOldPen);
}

CRect CTrapeziumEntity::GetBoundRect()
{
CRect BoundingRect(getX(),getY(),getX()+getBase(),getY()+getHeight()+2);

	return BoundingRect;
}

void CTrapeziumEntity::writeAr(CArchive& ar)
{ar<<getNumType();
 ar<<getX();
 ar<<getY();
 ar<<getBase();
 ar<<getHeight();
 ar<<getCutoff();
}

void CTrapeziumEntity::readAr(CArchive& ar)
{int _X,_Y;
 int _Base,_Height,_Cutoff;
 ar>>_X;
 ar>>_Y;
 ar>>_Base;
 ar>>_Height;
 ar>>_Cutoff;

 setX(_X);setY(_Y);
 setBase(_Base);
 setHeight(_Height);
 setCutoff(_Cutoff);
}

CString CTrapeziumEntity::getName()
{return "Trapezium";}
Соседние файлы в папке part32