Files
leocad/common/group.cpp
T
Leonardo Zide 851eecee50 Store only changed objects in edit undo history
Full before-and-after model snapshots accumulate large amounts of memory during editing, even when an operation changes only one object. Compact completed edits to retain only added, removed, or modified object states, with ordering metadata kept only for structural changes.

Restore objects by stable IDs, including group relationships, and detach views before removing cameras. Compose merged edits from their deltas and compare animation keys as well as current property values so keyframe-only edits remain undoable.
2026-10-21 10:48:24 -07:00

82 lines
1.6 KiB
C++

#include "lc_global.h"
#include <stdlib.h>
#include "group.h"
#include "lc_file.h"
lcGroupId lcGroup::mNextId;
lcGroup::lcGroup()
: mId(mNextId)
{
mNextId = static_cast<lcGroupId>(static_cast<uint32_t>(mNextId) + 1);
}
void lcGroup::FileLoad(lcFile* File)
{
qint32 GroupIndex;
char Name[LC_MAX_GROUP_NAME + 1];
File->ReadU8();
File->ReadBuffer(Name, sizeof(Name));
mName = QString::fromUtf8(Name);
File->ReadVector3();
File->ReadS32(&GroupIndex, 1);
mGroup = (lcGroup*)(quintptr)GroupIndex;
}
void lcGroup::CreateName(const std::vector<std::unique_ptr<lcGroup>>& Groups)
{
if (!mName.isEmpty())
{
bool Found = false;
for (const std::unique_ptr<lcGroup>& Group : Groups)
{
if (Group->mName == mName)
{
Found = true;
break;
}
}
if (!Found)
return;
}
int Max = 0;
QString Prefix = QApplication::tr("Group #");
const qsizetype Length = Prefix.length();
for (const std::unique_ptr<lcGroup>& Group : Groups)
{
const QString& Name = Group->mName;
if (Name.startsWith(Prefix))
{
bool Ok = false;
int GroupNumber = Name.mid(Length).toInt(&Ok);
if (Ok && GroupNumber > Max)
Max = GroupNumber;
}
}
mName = Prefix + QString::number(Max + 1);
}
lcGroupHistoryState lcGroup::GetHistoryState() const
{
lcGroupHistoryState State;
State.Id = mId;
State.ParentId = mGroup ? static_cast<uint32_t>(mGroup->GetId()) : LC_GROUP_ID_INVALID;
State.Name = mName;
return State;
}
void lcGroup::SetHistoryState(const lcGroupHistoryState& State, lcGroup* Parent)
{
mId = State.Id;
mName = State.Name;
mGroup = Parent;
}