#include "stdafx.h"
#include "PGL/PGLObject.h"
#include "PGL/PGLObjectPropPage.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
IMPLEMENT_SERIAL(CPGLObject, CObject, 1);
UINT CPGLObject::m_uNextID=1;
CPGLColor CPGLObject::m_selectionColor(1.0f,0.0f,0.0f,0.8f);
void CPGLObject::Serialize(CArchive &archive)
{
CObject::Serialize( archive );
m_color.Serialize(archive);
m_selectionColor.Serialize(archive);
int i;
if( archive.IsStoring() )
{
archive << m_bSelected << m_bVisible << m_uID << m_sName;
for (i=0;i<4;i++)
archive<<m_extent[i];
}
else
{
archive >> m_bSelected >> m_bVisible >> m_uID >> m_sName;
for (i=0;i<4;i++)
archive>>m_extent[i];
m_uNextID=__max(m_uID+1,m_uNextID);
PostUpdateExtent();
}
}
#ifdef _DEBUG
void CPGLObject::Dump( CDumpContext& dc ) const
{
CObject::Dump( dc );
dc << _T("CPGLOBject m_uID ") << GetID() << endl;
}
void CPGLObject::AssertValid() const
{
CObject::AssertValid();
m_color.AssertValid();
m_selectionColor.AssertValid();
ASSERT( !m_sName.IsEmpty());
ASSERT( m_extent[0]<=m_extent[1]);
ASSERT( m_extent[2]<=m_extent[3]);
}
#endif
CPGLObject::CPGLObject(const CPGLColor& _color)
{
m_hBitmap=NULL;
m_bSelected=FALSE;
m_bVisible=TRUE;
m_uID=m_uNextID++;
m_sName.Format("ID = %u",m_uID);
m_color=_color;
m_extent=new double[4];
for (int i=0;i<4;i++)
m_extent[i]=0;
PostUpdateExtent();
};
CPGLObject::CPGLObject(const CPGLObject& o)
{
m_bSelected=o.m_bSelected;
m_bVisible=o.m_bVisible;
m_uID=m_uNextID++;
m_sName=o.m_sName;
m_color=o.m_color;
m_extent=new double[4];
for (int i=0;i<4;i++)
m_extent[i]=o.m_extent[i];
};
CPGLObject& CPGLObject::operator = (const CPGLObject& o)
{
if (&o != this)
{
m_bSelected=o.m_bSelected;
m_bVisible=o.m_bVisible;
m_uID=m_uNextID++;
m_sName=o.m_sName;
m_color=o.m_color;
for (int i=0;i<4;i++)
m_extent[i]=o.m_extent[i];
}
return *this;
}
void CPGLObject::AddPropertyPage(CPropertySheet *pPropSheet)
{
CPGLObjectPropPage* propPage=new CPGLObjectPropPage(this);
pPropSheet->AddPage(propPage);
}
HTREEITEM CPGLObject::AddPropTree(CTreeCtrl* pTree, HTREEITEM hParent)
{
ASSERT_VALID(pTree);
CImageList* pImgList=pTree->GetImageList(TVSIL_NORMAL);
ASSERT_VALID(pImgList);
ASSERT(hParent);
COLORREF crMask=0;
pImgList->Add(CBitmap::FromHandle(GetBitmap()),crMask);
return pTree->InsertItem(TVIF_TEXT | TVIF_IMAGE | TVIF_PARAM ,
GetName() ,
pImgList->GetImageCount()-1 ,
0 ,
0 ,
0 ,
GetID() ,
hParent ,
TVI_LAST );
}
void CPGLObject::PlotGfx(gfxinterface::CGfxInterface& gfx)
{
gfx.AddComment("--- CPGLObject ---\n");
gfx.AddComment("set object color\n");
gfx.SetColor(m_color.GetRed(),m_color.GetGreen(),m_color.GetBlue(),m_color.GetAlpha());
};
void CPGLObject::LoadBitmap(DWORD ID_RESSOURCE)
{
HMODULE hInst=CPGLGlobal::GetInstance();
ASSERT(hInst);
if (m_hBitmap)
::DeleteObject(m_hBitmap);
m_hBitmap=::LoadBitmap(hInst, MAKEINTRESOURCE(ID_RESSOURCE));
}