leocad/common/group.cpp

67 lines
1.3 KiB
C++
Raw Normal View History

#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
2014-05-25 03:45:19 +02:00
lcGroup::lcGroup()
2011-09-07 23:06:51 +02:00
{
2014-05-25 03:45:19 +02:00
mGroup = NULL;
2011-09-07 23:06:51 +02:00
}
2014-05-25 03:45:19 +02:00
lcGroup::~lcGroup()
2011-09-07 23:06:51 +02:00
{
}
2014-05-25 20:23:09 +02:00
void lcGroup::FileLoad(lcFile* File)
2011-09-07 23:06:51 +02:00
{
2014-05-25 20:23:09 +02:00
lcint32 GroupIndex;
File->ReadU8();
2014-05-25 20:23:09 +02:00
File->ReadBuffer(m_strName, 65);
File->ReadVector3();
File->ReadS32(&GroupIndex, 1);
mGroup = (lcGroup*)(long)GroupIndex;
2011-09-07 23:06:51 +02:00
}
2014-05-25 20:23:09 +02:00
void lcGroup::FileSave(lcFile* File, const lcArray<lcGroup*>& Groups)
2011-09-07 23:06:51 +02:00
{
2014-05-25 20:23:09 +02:00
lcuint8 Version = 1; // LeoCAD 0.60
2011-09-07 23:06:51 +02:00
2014-05-25 20:23:09 +02:00
File->WriteU8(Version);
File->WriteBuffer(m_strName, 65);
File->WriteVector3(lcVector3(0.0f, 0.0f, 0.0f));
2011-09-07 23:06:51 +02:00
2014-05-25 03:45:19 +02:00
lcint32 GroupIndex = Groups.FindIndex(mGroup);
2014-05-25 20:23:09 +02:00
File->WriteS32(&GroupIndex, 1);
2011-09-07 23:06:51 +02:00
}
2014-12-16 00:55:17 +01:00
void lcGroup::CreateName(const lcArray<lcGroup*>& Groups)
{
if (m_strName[0])
{
bool Found = false;
for (int GroupIdx = 0; GroupIdx < Groups.GetSize(); GroupIdx++)
{
if (!strcmp(Groups[GroupIdx]->m_strName, m_strName))
{
Found = true;
break;
}
}
if (!Found)
return;
}
int i, max = 0;
const char* Prefix = "Group ";
for (int GroupIdx = 0; GroupIdx < Groups.GetSize(); GroupIdx++)
if (strncmp(Groups[GroupIdx]->m_strName, Prefix, strlen(Prefix)) == 0)
if (sscanf(Groups[GroupIdx]->m_strName + strlen(Prefix), " %d", &i) == 1)
if (i > max)
max = i;
sprintf(m_strName, "%s %d", Prefix, max+1);
}