leocad/common/group.cpp

82 lines
1.3 KiB
C++
Raw Normal View History

2011-09-07 23:06:51 +02:00
// Piece group
//
#include "lc_global.h"
2011-09-07 23:06:51 +02:00
#include <stdlib.h>
#include "group.h"
#include "lc_file.h"
2011-09-07 23:06:51 +02:00
/////////////////////////////////////////////////////////////////////////////
// Group construction/destruction
Group::Group()
{
m_pGroup = NULL;
m_pNext = NULL;
}
Group::~Group()
{
}
Group* Group::GetTopGroup()
{
return m_pGroup ? m_pGroup->GetTopGroup() : this;
}
void Group::SetGroup(Group* pGroup)
{
if (pGroup == this)
return;
if (m_pGroup != NULL && m_pGroup != (Group*)-1)
m_pGroup->SetGroup(pGroup);
else
m_pGroup = pGroup;
}
void Group::UnGroup(Group* pGroup)
{
if (m_pGroup == pGroup)
m_pGroup = NULL;
else
if (m_pGroup != NULL)
m_pGroup->UnGroup(pGroup);
}
2012-03-23 00:44:56 +01:00
void Group::FileLoad(lcFile* file)
2011-09-07 23:06:51 +02:00
{
2012-03-23 00:44:56 +01:00
lcuint8 version;
lcint32 i;
2011-09-07 23:06:51 +02:00
2012-03-23 00:44:56 +01:00
file->ReadU8(&version, 1);
file->ReadBuffer(m_strName, 65);
file->ReadFloats(m_fCenter, 3);
file->ReadS32(&i, 1);
2013-01-06 20:24:25 +01:00
m_pGroup = (Group*)(long)i;
2011-09-07 23:06:51 +02:00
}
2012-03-23 00:44:56 +01:00
void Group::FileSave(lcFile* file, Group* pGroups)
2011-09-07 23:06:51 +02:00
{
2012-03-23 00:44:56 +01:00
lcuint8 version = 1; // LeoCAD 0.60
lcint32 i = 0;
2011-09-07 23:06:51 +02:00
2012-03-23 00:44:56 +01:00
file->WriteU8(&version, 1);
file->WriteBuffer(m_strName, 65);
file->WriteFloats(m_fCenter, 3);
2011-09-07 23:06:51 +02:00
if (m_pGroup == NULL)
i = -1;
else
{
for (; pGroups; pGroups = pGroups->m_pNext)
if (pGroups == m_pGroup)
break;
else
i++;
}
2012-03-23 00:44:56 +01:00
file->WriteS32(&i, 1);
2011-09-07 23:06:51 +02:00
}