#include "stdafx.h"
#include "PGL/PGL.h"
#include "PGL/PGLObjectManager.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
IMPLEMENT_SERIAL(CPGLObjectManager, CObject, 1);
void CPGLObjectManager::Serialize(CArchive &archive)
{
CObject::Serialize( archive );
m_lObjects.Serialize(archive);
}
#ifdef _DEBUG
void CPGLObjectManager::Dump( CDumpContext& dc ) const
{
CObject::Dump( dc );
dc << _T("--- CPGLObjectManager ---")<< endl;
dc<<m_lObjects;
}
void CPGLObjectManager::AssertValid() const
{
CObject::AssertValid();
m_lObjects.AssertValid();
}
#endif
CPGLObjectManager::CPGLObjectManager()
{
HINSTANCE hOldInst=AfxGetResourceHandle();
AfxSetResourceHandle(AfxGetInstanceHandle());
m_bmp.LoadBitmap(IDB_PGL_OBJMG_BITMAP);
AfxSetResourceHandle(hOldInst);
}
CPGLObjectManager::CPGLObjectManager(const CPGLObjectManager& om)
{
POSITION pos=om.m_lObjects.GetHeadPosition();
while (pos!=NULL)
{
AddHead(om.m_lObjects.GetNext(pos)->MakeCopy());
}
HINSTANCE hOldInst=AfxGetResourceHandle();
AfxSetResourceHandle(AfxGetInstanceHandle());
m_bmp.LoadBitmap(IDB_PGL_OBJMG_BITMAP);
AfxSetResourceHandle(hOldInst);
}
CPGLObjectManager& CPGLObjectManager::operator=(const CPGLObjectManager& om)
{
if (this!=&om)
{
DeleteAll();
POSITION pos=om.m_lObjects.GetHeadPosition();
while (pos!=NULL)
{
AddHead(om.m_lObjects.GetNext(pos)->MakeCopy());
}
}
return *this;
}
CPGLObjectManager::~CPGLObjectManager()
{
DeleteAll();
ASSERT(m_lObjects.IsEmpty());
}
CPGLObjectManager* CPGLObjectManager::CutSelection()
{
CPGLObjectManager* pSelList=GetSelection();
RemoveSelection();
return pSelList;
}
CPGLObjectManager* CPGLObjectManager::CopySelection()
{
CPGLObjectManager* pSelList=GetSelectionCopy();
return pSelList;
}
void CPGLObjectManager::PasteSelection(CPGLObjectManager* pClipboard)
{
if (pClipboard==NULL)
return;
ASSERT_VALID(pClipboard);
POSITION pos;
CPGLObject* pObject;
pos=pClipboard->GetHeadPosition();
while (pos!=NULL)
{
pObject=pClipboard->m_lObjects.GetNext(pos)->MakeCopy();
m_lObjects.AddHead(pObject);
}
}
CPGLObjectManager* CPGLObjectManager::GetSelection()
{
POSITION pos;
CPGLObject* pObject;
CPGLObjectManager* pSelection=new CPGLObjectManager();
pos=m_lObjects.GetHeadPosition();
while (pos!=NULL)
{
pObject=m_lObjects.GetNext(pos);
if (pObject->IsSelected())
{
pSelection->m_lObjects.AddHead(pObject);
}
}
return pSelection;
}
CPGLObjectManager* CPGLObjectManager::GetTextSelection()
{
POSITION pos;
CPGLObject* pObject;
CPGLObjectManager* pSelection=new CPGLObjectManager();
pos=m_lObjects.GetHeadPosition();
while (pos!=NULL)
{
pObject=m_lObjects.GetNext(pos);
if (pObject->IsSelected() && pObject->IsKindOf(RUNTIME_CLASS(CPGLText)))
{
pSelection->m_lObjects.AddHead(pObject);
}
}
return pSelection;
}
CPGLObjectManager* CPGLObjectManager::GetSelectionCopy()
{
POSITION pos;
CPGLObject* pObject;
CPGLObjectManager* pSelection=new CPGLObjectManager();
pos=m_lObjects.GetHeadPosition();
while (pos!=NULL)
{
pObject=m_lObjects.GetNext(pos);
if (pObject->IsSelected())
{
pSelection->m_lObjects.AddHead(pObject->MakeCopy());
}
}
return pSelection;
}
void CPGLObjectManager::RemoveObject(CPGLObject* pObject)
{
ASSERT_VALID(pObject);
POSITION pos;
pos=m_lObjects.Find(pObject);
if (pos!=NULL)
{
m_lObjects.RemoveAt(pos);
}
}
void CPGLObjectManager::RemoveObject(UINT ID)
{
POSITION pos;
CPGLObject* pObject;
pos=m_lObjects.GetHeadPosition();
while(pos!=NULL)
{
pObject=m_lObjects.GetNext(pos);
if (pObject->CheckID(ID))
{
m_lObjects.RemoveAt(pos);
return;
}
}
}
void CPGLObjectManager::DeleteObject(CPGLObject* pObject)
{
ASSERT_VALID(pObject);
POSITION pos;
pos=m_lObjects.Find(pObject);
if (pos!=NULL)
{
delete m_lObjects.GetAt(pos);
m_lObjects.RemoveAt(pos);
}
}
void CPGLObjectManager::DeleteObject(UINT ID)
{
POSITION pos;
CPGLObject* pObject;
pos=m_lObjects.GetHeadPosition();
while(pos!=NULL)
{
pObject=m_lObjects.GetNext(pos);
if (pObject->CheckID(ID))
{
delete m_lObjects.GetAt(pos);
m_lObjects.RemoveAt(pos);
return;
}
}
}
void CPGLObjectManager::DeleteAll()
{
POSITION pos;
pos=m_lObjects.GetHeadPosition();
while (pos!=NULL)
{
delete m_lObjects.GetNext(pos);
}
m_lObjects.RemoveAll();
}
void CPGLObjectManager::RemoveSelection()
{
POSITION pos,oldpos;
CPGLObject* pObject;
oldpos=pos=m_lObjects.GetHeadPosition();
while(pos!=NULL)
{
pObject=m_lObjects.GetNext(pos);
if (pObject->IsSelected())
{
m_lObjects.RemoveAt(oldpos);
}
oldpos=pos;
}
}
void CPGLObjectManager::DeleteSelection()
{
POSITION oldpos,pos;
CPGLObject* pObject;
oldpos=pos=m_lObjects.GetHeadPosition();
while(pos!=NULL)
{
pObject=m_lObjects.GetNext(pos);
if (pObject->IsSelected())
{
delete m_lObjects.GetAt(oldpos);
m_lObjects.RemoveAt(oldpos);
}
oldpos=pos;
}
}