mirror of
https://github.com/leozide/leocad
synced 2025-01-17 18:11:42 +01:00
Group cleanup.
This commit is contained in:
parent
e20907fbdd
commit
d4c3cf8ebe
5 changed files with 49 additions and 87 deletions
|
@ -10,48 +10,28 @@ lcGroup::lcGroup()
|
||||||
|
|
||||||
lcGroup::~lcGroup()
|
lcGroup::~lcGroup()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void lcGroup::SetGroup(lcGroup* Group)
|
void lcGroup::FileLoad(lcFile* File)
|
||||||
{
|
{
|
||||||
if (Group == this)
|
lcuint8 Version;
|
||||||
return;
|
lcint32 GroupIndex;
|
||||||
|
|
||||||
if (mGroup != NULL && mGroup != (lcGroup*)-1)
|
Version = File->ReadU8();
|
||||||
mGroup->SetGroup(Group);
|
File->ReadBuffer(m_strName, 65);
|
||||||
else
|
File->ReadVector3();
|
||||||
mGroup = Group;
|
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)
|
lcuint8 Version = 1; // LeoCAD 0.60
|
||||||
mGroup = NULL;
|
|
||||||
else if (mGroup != NULL)
|
|
||||||
mGroup->UnGroup(Group);
|
|
||||||
}
|
|
||||||
|
|
||||||
void lcGroup::FileLoad(lcFile* file)
|
File->WriteU8(Version);
|
||||||
{
|
File->WriteBuffer(m_strName, 65);
|
||||||
lcuint8 version;
|
File->WriteVector3(lcVector3(0.0f, 0.0f, 0.0f));
|
||||||
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);
|
|
||||||
|
|
||||||
lcint32 GroupIndex = Groups.FindIndex(mGroup);
|
lcint32 GroupIndex = Groups.FindIndex(mGroup);
|
||||||
file->WriteS32(&GroupIndex, 1);
|
File->WriteS32(&GroupIndex, 1);
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,16 +16,11 @@ public:
|
||||||
return mGroup ? mGroup->GetTopGroup() : this;
|
return mGroup ? mGroup->GetTopGroup() : this;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetGroup(lcGroup* Group);
|
void FileLoad(lcFile* File);
|
||||||
void UnGroup(lcGroup* Group);
|
void FileSave(lcFile* File, const lcArray<lcGroup*>& Groups);
|
||||||
|
|
||||||
lcGroup* mGroup;
|
lcGroup* mGroup;
|
||||||
|
|
||||||
void FileLoad(lcFile* file);
|
|
||||||
void FileSave(lcFile* file, const lcArray<lcGroup*>& Groups);
|
|
||||||
|
|
||||||
char m_strName[LC_MAX_GROUP_NAME + 1];
|
char m_strName[LC_MAX_GROUP_NAME + 1];
|
||||||
float m_fCenter[3];
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // _GROUP_H_
|
#endif // _GROUP_H_
|
||||||
|
|
|
@ -37,7 +37,7 @@ lcPiece::lcPiece(PieceInfo* pPieceInfo)
|
||||||
m_nStepShow = 1;
|
m_nStepShow = 1;
|
||||||
m_nStepHide = 255;
|
m_nStepHide = 255;
|
||||||
memset(m_strName, 0, sizeof(m_strName));
|
memset(m_strName, 0, sizeof(m_strName));
|
||||||
m_pGroup = NULL;
|
mGroup = NULL;
|
||||||
|
|
||||||
if (mPieceInfo != NULL)
|
if (mPieceInfo != NULL)
|
||||||
mPieceInfo->AddRef();
|
mPieceInfo->AddRef();
|
||||||
|
@ -226,15 +226,15 @@ bool lcPiece::FileLoad(lcFile& file)
|
||||||
lcint32 i = -1;
|
lcint32 i = -1;
|
||||||
if (version > 6)
|
if (version > 6)
|
||||||
file.ReadS32(&i, 1);
|
file.ReadS32(&i, 1);
|
||||||
m_pGroup = (Group*)(long)i;
|
mGroup = (Group*)(long)i;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
file.ReadU8(&ch, 1);
|
file.ReadU8(&ch, 1);
|
||||||
if (ch == 0)
|
if (ch == 0)
|
||||||
m_pGroup = (Group*)-1;
|
mGroup = (Group*)-1;
|
||||||
else
|
else
|
||||||
m_pGroup = (Group*)(long)ch;
|
mGroup = (Group*)(long)ch;
|
||||||
|
|
||||||
file.ReadU8(&ch, 1);
|
file.ReadU8(&ch, 1);
|
||||||
if (ch & 0x01)
|
if (ch & 0x01)
|
||||||
|
@ -265,7 +265,7 @@ void lcPiece::FileSave(lcFile& file) const
|
||||||
file.WriteBuffer(m_strName, Length);
|
file.WriteBuffer(m_strName, Length);
|
||||||
|
|
||||||
// version 7
|
// version 7
|
||||||
lcint32 GroupIndex = lcGetActiveProject()->GetGroupIndex(m_pGroup);
|
lcint32 GroupIndex = lcGetActiveProject()->GetGroupIndex(mGroup);
|
||||||
file.WriteS32(GroupIndex);
|
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)
|
void lcPiece::UpdatePosition(unsigned short nTime)
|
||||||
{
|
{
|
||||||
CalculateKeys(nTime);
|
CalculateKeys(nTime);
|
||||||
|
|
|
@ -130,13 +130,18 @@ public:
|
||||||
void UpdatePosition(unsigned short nTime);
|
void UpdatePosition(unsigned short nTime);
|
||||||
void Move(unsigned short nTime, bool bAddKey, float dx, float dy, float dz);
|
void Move(unsigned short nTime, bool bAddKey, float dx, float dy, float dz);
|
||||||
|
|
||||||
void DoGroup(Group* pGroup);
|
lcGroup* GetTopGroup();
|
||||||
void UnGroup(Group* pGroup);
|
|
||||||
Group* GetTopGroup();
|
void SetGroup(lcGroup* Group)
|
||||||
void SetGroup(Group* pGroup)
|
{
|
||||||
{ m_pGroup = pGroup; }
|
mGroup = Group;
|
||||||
Group* GetGroup()
|
}
|
||||||
{ return m_pGroup; }
|
|
||||||
|
lcGroup* GetGroup()
|
||||||
|
{
|
||||||
|
return mGroup;
|
||||||
|
}
|
||||||
|
|
||||||
void SetName(char* name)
|
void SetName(char* name)
|
||||||
{ strcpy(m_strName, name); }
|
{ strcpy(m_strName, name); }
|
||||||
const char* GetName()
|
const char* GetName()
|
||||||
|
@ -174,7 +179,7 @@ public:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// Atributes
|
// Atributes
|
||||||
Group* m_pGroup;
|
Group* mGroup;
|
||||||
|
|
||||||
lcuint8 m_nStepShow;
|
lcuint8 m_nStepShow;
|
||||||
lcuint8 m_nStepHide;
|
lcuint8 m_nStepHide;
|
||||||
|
|
|
@ -401,9 +401,6 @@ bool Project::FileLoad(lcFile* file, bool bUndo, bool bMerge)
|
||||||
{
|
{
|
||||||
file->ReadBuffer(Group->m_strName, 65);
|
file->ReadBuffer(Group->m_strName, 65);
|
||||||
file->ReadBuffer(&ch, 1);
|
file->ReadBuffer(&ch, 1);
|
||||||
Group->m_fCenter[0] = 0;
|
|
||||||
Group->m_fCenter[1] = 0;
|
|
||||||
Group->m_fCenter[2] = 0;
|
|
||||||
Group->mGroup = (lcGroup*)-1;
|
Group->mGroup = (lcGroup*)-1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -4232,7 +4229,7 @@ void Project::HandleCommand(LC_COMMANDS id)
|
||||||
if (GroupIndex != -1)
|
if (GroupIndex != -1)
|
||||||
Piece->SetGroup(Groups[GroupIndex]);
|
Piece->SetGroup(Groups[GroupIndex]);
|
||||||
else
|
else
|
||||||
Piece->UnGroup(NULL);
|
Piece->SetGroup(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int GroupIdx = 0; GroupIdx < Groups.GetSize(); GroupIdx++)
|
for (int GroupIdx = 0; GroupIdx < Groups.GetSize(); GroupIdx++)
|
||||||
|
@ -4817,7 +4814,6 @@ void Project::HandleCommand(LC_COMMANDS id)
|
||||||
|
|
||||||
case LC_PIECE_GROUP:
|
case LC_PIECE_GROUP:
|
||||||
{
|
{
|
||||||
Group* pGroup;
|
|
||||||
int i, Max = 0;
|
int i, Max = 0;
|
||||||
char name[65];
|
char name[65];
|
||||||
int Selected = 0;
|
int Selected = 0;
|
||||||
|
@ -4854,16 +4850,23 @@ void Project::HandleCommand(LC_COMMANDS id)
|
||||||
if (!gMainWindow->DoDialog(LC_DIALOG_PIECE_GROUP, name))
|
if (!gMainWindow->DoDialog(LC_DIALOG_PIECE_GROUP, name))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
pGroup = new Group();
|
lcGroup* NewGroup = new lcGroup();
|
||||||
strcpy(pGroup->m_strName, name);
|
strcpy(NewGroup->m_strName, name);
|
||||||
mGroups.Add(pGroup);
|
mGroups.Add(NewGroup);
|
||||||
|
|
||||||
for (int PieceIdx = 0; PieceIdx < mPieces.GetSize(); PieceIdx++)
|
for (int PieceIdx = 0; PieceIdx < mPieces.GetSize(); PieceIdx++)
|
||||||
{
|
{
|
||||||
Piece* Piece = mPieces[PieceIdx];
|
Piece* Piece = mPieces[PieceIdx];
|
||||||
|
|
||||||
if (Piece->IsSelected())
|
if (Piece->IsSelected())
|
||||||
Piece->DoGroup(pGroup);
|
{
|
||||||
|
lcGroup* Group = Piece->GetTopGroup();
|
||||||
|
|
||||||
|
if (!Group)
|
||||||
|
Piece->SetGroup(NewGroup);
|
||||||
|
else if (Group != NewGroup)
|
||||||
|
Group->mGroup = NewGroup;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
RemoveEmptyGroups();
|
RemoveEmptyGroups();
|
||||||
|
@ -4958,7 +4961,7 @@ void Project::HandleCommand(LC_COMMANDS id)
|
||||||
|
|
||||||
if (Piece->IsFocused())
|
if (Piece->IsFocused())
|
||||||
{
|
{
|
||||||
Piece->UnGroup(NULL);
|
Piece->SetGroup(NULL);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5742,9 +5745,6 @@ lcGroup* Project::AddGroup(lcGroup* Parent)
|
||||||
sprintf(NewGroup->m_strName, "Group #%.2d", Max + 1);
|
sprintf(NewGroup->m_strName, "Group #%.2d", Max + 1);
|
||||||
mGroups.Add(NewGroup);
|
mGroups.Add(NewGroup);
|
||||||
|
|
||||||
NewGroup->m_fCenter[0] = 0.0f;
|
|
||||||
NewGroup->m_fCenter[1] = 0.0f;
|
|
||||||
NewGroup->m_fCenter[2] = 0.0f;
|
|
||||||
NewGroup->mGroup = Parent;
|
NewGroup->mGroup = Parent;
|
||||||
|
|
||||||
return NewGroup;
|
return NewGroup;
|
||||||
|
|
Loading…
Reference in a new issue