Duplicate groups when duplicating pieces. Fixes #158.

This commit is contained in:
Leonardo Zide 2018-02-19 19:12:32 -08:00
parent a1dfc7c26c
commit 10491629b7

View file

@ -1162,6 +1162,35 @@ void lcModel::DuplicateSelectedPieces()
{ {
lcArray<lcObject*> NewPieces; lcArray<lcObject*> NewPieces;
lcPiece* Focus = nullptr; lcPiece* Focus = nullptr;
std::map<lcGroup*, lcGroup*> GroupMap;
std::function<lcGroup*(lcGroup*)> GetNewGroup = [this, &GroupMap, &GetNewGroup](lcGroup* Group)
{
const auto GroupIt = GroupMap.find(Group);
if (GroupIt != GroupMap.end())
return GroupIt->second;
else
{
lcGroup* Parent = Group->mGroup ? GetNewGroup(Group->mGroup) : nullptr;
QString GroupName = Group->mName;
while (!GroupName.isEmpty())
{
QCharRef Last = GroupName[GroupName.size() - 1];
if (Last.isDigit())
GroupName.chop(1);
else
break;
}
if (GroupName.isEmpty())
GroupName = Group->mName;
lcGroup* NewGroup = AddGroup(GroupName, Parent);
GroupMap[Group] = NewGroup;
return NewGroup;
}
};
for (int PieceIdx = 0; PieceIdx < mPieces.GetSize(); PieceIdx++) for (int PieceIdx = 0; PieceIdx < mPieces.GetSize(); PieceIdx++)
{ {
@ -1179,6 +1208,10 @@ void lcModel::DuplicateSelectedPieces()
PieceIdx++; PieceIdx++;
InsertPiece(NewPiece, PieceIdx); InsertPiece(NewPiece, PieceIdx);
lcGroup* Group = Piece->GetGroup();
if (Group)
Piece->SetGroup(GetNewGroup(Group));
} }
if (NewPieces.IsEmpty()) if (NewPieces.IsEmpty())