#include "stdafx.h"
#include "PGL/PGLMap.h"
#include "PGL/PGLMapPropPage.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
IMPLEMENT_SERIAL(CPGLMap, CPGLObject,1);
void CPGLMap::Serialize(CArchive &archive)
{
CPGLObject::Serialize( archive );
if( archive.IsStoring() )
{
archive << m_iNx
<< m_iNy
<< m_dDx
<< m_dDy
<< m_dX0
<< m_dY0;
}
else
{
archive << m_iNx
<< m_iNy
<< m_dDx
<< m_dDy
<< m_dX0
<< m_dY0;
}
}
#ifdef _DEBUG
void CPGLMap::Dump( CDumpContext& dc ) const
{
CPGLObject::Dump( dc );
dc << _T("CPGLMap ID ") << GetID() << endl;
dc << " nx : "<< m_iNx
<< " ny : "<< m_iNy
<< " dx : "<< m_dDx
<< " dy : "<< m_dDy
<< " x0 : "<< m_dX0
<< " y0 : "<< m_dY0<<"/n";
}
void CPGLMap::AssertValid() const
{
CPGLObject::AssertValid();
ASSERT(m_iNx>=0);
ASSERT(m_iNy>=0);
}
#endif
CPGLMap::CPGLMap()
: CPGLObject()
{
m_iNx=0;
m_iNy=0;
m_dDx=m_dDy=1;
m_dX0=0;
m_dY0=0;
}
CPGLMap::CPGLMap(const CPGLMap &l)
: CPGLObject(l)
{
m_iNx=l.m_iNx;
m_iNy=l.m_iNy;
m_dDx=l.m_dDx;
m_dDy=l.m_dDy;
m_dX0=l.m_dX0;
m_dY0=l.m_dY0;
}
CPGLMap& CPGLMap::operator = (const CPGLMap& l)
{
if (&l != this)
{
this->CPGLObject::operator =(l);
m_iNx=l.m_iNx;
m_iNy=l.m_iNy;
m_dDx=l.m_dDx;
m_dDy=l.m_dDy;
m_dX0=l.m_dX0;
m_dY0=l.m_dY0;
}
return *this;
}
void CPGLMap::SetDx(double _dDx)
{
if ( _dDx > PGL_EPS)
{
m_dDx = _dDx;
PostUpdateExtent();
}
}
void CPGLMap::SetDy(double _dDy)
{
if ( _dDy > PGL_EPS)
{
m_dDy = _dDy;
PostUpdateExtent();
}
}
void CPGLMap::AddContextMenuItems(CMenu* pMenu)
{
CPGLObject::AddContextMenuItems(pMenu);
}
void CPGLMap::AddPropertyPage(CPropertySheet *pPropSheet)
{
CPGLMapPropPage* propPage=new CPGLMapPropPage(this);
pPropSheet->AddPage(propPage);
CPGLObject::AddPropertyPage(pPropSheet);
}
void CPGLMap::PlotGfx(gfxinterface::CGfxInterface& gfx)
{
CPGLObject::PlotGfx(gfx);
gfx.AddComment("--- CPGLMap ID ---");
}
void CPGLMap::SetGrid(int iaxe, int iNPoints, double pos0, double step)
{
ASSERT(iNPoints>=0);
switch(iaxe)
{
case 0:
m_iNx=iNPoints;
m_dDx=step;
m_dX0=pos0;
break;
case 1:
m_iNy=iNPoints;
m_dDy=step;
m_dY0=pos0;
break;
}
PostUpdateExtent();
}
double* CPGLMap::GetExtent(CPGLView* pView)
{
if (NeedUpdateExtent())
UpdateExtent(pView);
return CPGLObject::GetExtent(pView);
}
void CPGLMap::UpdateExtent(CPGLView* pView)
{
CPGLObject::UpdateExtent(pView);
m_extent[0]=m_dX0;
m_extent[1]=m_dX0+(m_iNx-1)*m_dDx;
m_extent[2]=m_dY0;
m_extent[3]=m_dY0+(m_iNy-1)*m_dDy;
}