Group cleanup.

This commit is contained in:
leo 2014-05-25 18:23:09 +00:00
parent e20907fbdd
commit d4c3cf8ebe
5 changed files with 49 additions and 87 deletions

View file

@ -10,48 +10,28 @@ lcGroup::lcGroup()
lcGroup::~lcGroup()
{
}
void lcGroup::SetGroup(lcGroup* Group)
void lcGroup::FileLoad(lcFile* File)
{
if (Group == this)
return;
lcuint8 Version;
lcint32 GroupIndex;
if (mGroup != NULL && mGroup != (lcGroup*)-1)
mGroup->SetGroup(Group);
else
mGroup = Group;
Version = File->ReadU8();
File->ReadBuffer(m_strName, 65);
File->ReadVector3();
File->ReadS32(&GroupIndex, 1);
mGroup = (lcGroup*)(long)GroupIndex;
}
void lcGroup::UnGroup(lcGroup* Group)
void lcGroup::FileSave(lcFile* File, const lcArray<lcGroup*>& Groups)
{
if (mGroup == Group)
mGroup = NULL;
else if (mGroup != NULL)
mGroup->UnGroup(Group);
}
lcuint8 Version = 1; // LeoCAD 0.60
void lcGroup::FileLoad(lcFile* file)
{
lcuint8 version;
lcint32 i;
file->ReadU8(&version, 1);
file->ReadBuffer(m_strName, 65);
file->ReadFloats(m_fCenter, 3);
file->ReadS32(&i, 1);
mGroup = (lcGroup*)(long)i;
}
void lcGroup::FileSave(lcFile* file, const lcArray<lcGroup*>& Groups)
{
lcuint8 version = 1; // LeoCAD 0.60
file->WriteU8(&version, 1);
file->WriteBuffer(m_strName, 65);
file->WriteFloats(m_fCenter, 3);
File->WriteU8(Version);
File->WriteBuffer(m_strName, 65);
File->WriteVector3(lcVector3(0.0f, 0.0f, 0.0f));
lcint32 GroupIndex = Groups.FindIndex(mGroup);
file->WriteS32(&GroupIndex, 1);
File->WriteS32(&GroupIndex, 1);
}

View file

@ -16,16 +16,11 @@ public:
return mGroup ? mGroup->GetTopGroup() : this;
}
void SetGroup(lcGroup* Group);
void UnGroup(lcGroup* Group);
void FileLoad(lcFile* File);
void FileSave(lcFile* File, const lcArray<lcGroup*>& Groups);
lcGroup* mGroup;
void FileLoad(lcFile* file);
void FileSave(lcFile* file, const lcArray<lcGroup*>& Groups);
char m_strName[LC_MAX_GROUP_NAME + 1];
float m_fCenter[3];
};
#endif // _GROUP_H_

View file

@ -37,7 +37,7 @@ lcPiece::lcPiece(PieceInfo* pPieceInfo)
m_nStepShow = 1;
m_nStepHide = 255;
memset(m_strName, 0, sizeof(m_strName));
m_pGroup = NULL;
mGroup = NULL;
if (mPieceInfo != NULL)
mPieceInfo->AddRef();
@ -226,15 +226,15 @@ bool lcPiece::FileLoad(lcFile& file)
lcint32 i = -1;
if (version > 6)
file.ReadS32(&i, 1);
m_pGroup = (Group*)(long)i;
mGroup = (Group*)(long)i;
}
else
{
file.ReadU8(&ch, 1);
if (ch == 0)
m_pGroup = (Group*)-1;
mGroup = (Group*)-1;
else
m_pGroup = (Group*)(long)ch;
mGroup = (Group*)(long)ch;
file.ReadU8(&ch, 1);
if (ch & 0x01)
@ -265,7 +265,7 @@ void lcPiece::FileSave(lcFile& file) const
file.WriteBuffer(m_strName, Length);
// version 7
lcint32 GroupIndex = lcGetActiveProject()->GetGroupIndex(m_pGroup);
lcint32 GroupIndex = lcGetActiveProject()->GetGroupIndex(mGroup);
file.WriteS32(GroupIndex);
}
@ -454,29 +454,11 @@ void lcPiece::CompareBoundingBox(float box[6])
}
}
Group* lcPiece::GetTopGroup()
lcGroup* lcPiece::GetTopGroup()
{
return m_pGroup ? m_pGroup->GetTopGroup() : NULL;
return mGroup ? mGroup->GetTopGroup() : NULL;
}
void lcPiece::DoGroup(Group* pGroup)
{
if (m_pGroup != NULL && m_pGroup != (Group*)-1 && m_pGroup > (Group*)0xFFFF)
m_pGroup->SetGroup(pGroup);
else
m_pGroup = pGroup;
}
void lcPiece::UnGroup(Group* pGroup)
{
if ((m_pGroup == pGroup) || (pGroup == NULL))
m_pGroup = NULL;
else
if (m_pGroup != NULL)
m_pGroup->UnGroup(pGroup);
}
// Recalculates current position and connections
void lcPiece::UpdatePosition(unsigned short nTime)
{
CalculateKeys(nTime);

View file

@ -130,13 +130,18 @@ public:
void UpdatePosition(unsigned short nTime);
void Move(unsigned short nTime, bool bAddKey, float dx, float dy, float dz);
void DoGroup(Group* pGroup);
void UnGroup(Group* pGroup);
Group* GetTopGroup();
void SetGroup(Group* pGroup)
{ m_pGroup = pGroup; }
Group* GetGroup()
{ return m_pGroup; }
lcGroup* GetTopGroup();
void SetGroup(lcGroup* Group)
{
mGroup = Group;
}
lcGroup* GetGroup()
{
return mGroup;
}
void SetName(char* name)
{ strcpy(m_strName, name); }
const char* GetName()
@ -174,7 +179,7 @@ public:
protected:
// Atributes
Group* m_pGroup;
Group* mGroup;
lcuint8 m_nStepShow;
lcuint8 m_nStepHide;

View file

@ -401,9 +401,6 @@ bool Project::FileLoad(lcFile* file, bool bUndo, bool bMerge)
{
file->ReadBuffer(Group->m_strName, 65);
file->ReadBuffer(&ch, 1);
Group->m_fCenter[0] = 0;
Group->m_fCenter[1] = 0;
Group->m_fCenter[2] = 0;
Group->mGroup = (lcGroup*)-1;
}
else
@ -4232,7 +4229,7 @@ void Project::HandleCommand(LC_COMMANDS id)
if (GroupIndex != -1)
Piece->SetGroup(Groups[GroupIndex]);
else
Piece->UnGroup(NULL);
Piece->SetGroup(NULL);
}
for (int GroupIdx = 0; GroupIdx < Groups.GetSize(); GroupIdx++)
@ -4817,7 +4814,6 @@ void Project::HandleCommand(LC_COMMANDS id)
case LC_PIECE_GROUP:
{
Group* pGroup;
int i, Max = 0;
char name[65];
int Selected = 0;
@ -4854,16 +4850,23 @@ void Project::HandleCommand(LC_COMMANDS id)
if (!gMainWindow->DoDialog(LC_DIALOG_PIECE_GROUP, name))
break;
pGroup = new Group();
strcpy(pGroup->m_strName, name);
mGroups.Add(pGroup);
lcGroup* NewGroup = new lcGroup();
strcpy(NewGroup->m_strName, name);
mGroups.Add(NewGroup);
for (int PieceIdx = 0; PieceIdx < mPieces.GetSize(); PieceIdx++)
{
Piece* Piece = mPieces[PieceIdx];
if (Piece->IsSelected())
Piece->DoGroup(pGroup);
{
lcGroup* Group = Piece->GetTopGroup();
if (!Group)
Piece->SetGroup(NewGroup);
else if (Group != NewGroup)
Group->mGroup = NewGroup;
}
}
RemoveEmptyGroups();
@ -4958,7 +4961,7 @@ void Project::HandleCommand(LC_COMMANDS id)
if (Piece->IsFocused())
{
Piece->UnGroup(NULL);
Piece->SetGroup(NULL);
break;
}
}
@ -5742,9 +5745,6 @@ lcGroup* Project::AddGroup(lcGroup* Parent)
sprintf(NewGroup->m_strName, "Group #%.2d", Max + 1);
mGroups.Add(NewGroup);
NewGroup->m_fCenter[0] = 0.0f;
NewGroup->m_fCenter[1] = 0.0f;
NewGroup->m_fCenter[2] = 0.0f;
NewGroup->mGroup = Parent;
return NewGroup;