diff options
-rw-r--r-- | src/Authoring/Client/Code/Core/Doc/DocumentEditor.cpp | 70 |
1 files changed, 46 insertions, 24 deletions
diff --git a/src/Authoring/Client/Code/Core/Doc/DocumentEditor.cpp b/src/Authoring/Client/Code/Core/Doc/DocumentEditor.cpp index b81120d9..d134fcd3 100644 --- a/src/Authoring/Client/Code/Core/Doc/DocumentEditor.cpp +++ b/src/Authoring/Client/Code/Core/Doc/DocumentEditor.cpp @@ -2466,14 +2466,15 @@ public: } void RearrangeObjects(const qt3dsdm::TInstanceHandleList &inInstances, - TInstanceHandle inDest, - DocumentEditorInsertType::Enum inInsertType, - bool checkUniqueName, bool notifyRename = true) override + TInstanceHandle inDest, + DocumentEditorInsertType::Enum inInsertType, + bool checkUniqueName, bool notifyRename = true) override { - qt3dsdm::TInstanceHandleList sortableList(ToGraphOrdering(inInstances)); + TInstanceHandleList sortableList(ToGraphOrdering(inInstances)); + QSet<TInstanceHandle> updateList; TInstanceHandle theParent(inDest); if (inInsertType == DocumentEditorInsertType::PreviousSibling - || inInsertType == DocumentEditorInsertType::NextSibling) + || inInsertType == DocumentEditorInsertType::NextSibling) theParent = GetParent(inDest); if (m_Bridge.IsComponentInstance(theParent) @@ -2498,13 +2499,53 @@ public: SetName(theInstance, newName); } } + TInstanceHandle oldParentHandle = GetParent(theInstance); + if (inInsertType == DocumentEditorInsertType::PreviousSibling) m_AssetGraph.MoveBefore(theInstance, inDest); else if (inInsertType == DocumentEditorInsertType::NextSibling) m_AssetGraph.MoveAfter(theInstance, inDest); else if (inInsertType == DocumentEditorInsertType::LastChild) m_AssetGraph.MoveTo(theInstance, inDest, COpaquePosition::LAST); + + // If moving into a group, update the target group pivot point and position + TInstanceHandle newParentHandle = GetParent(theInstance); + if (m_Bridge.IsGroupInstance(newParentHandle)) + updateList.insert(newParentHandle); + // If moving from a group, update the source group pivot and position + if (m_Bridge.IsGroupInstance(oldParentHandle)) + updateList.insert(oldParentHandle); + } + + if (!updateList.empty()) { + for (auto it : qAsConst(updateList)) { + TInstanceHandleList childHandles; + GetChildren(GetActiveSlide(it), it, childHandles); + updatePivotAndPosition(it, childHandles); + } + } + } + + // Move the pivot point and position to the center of the objects in list + void updatePivotAndPosition(TInstanceHandle handle, TInstanceHandleList objectList) + { + // Calculate the center + SFloat3 pivotPoint; + for (auto it : objectList) { + SFloat3 position = GetPosition(it); + pivotPoint[0] += position[0]; + pivotPoint[1] += position[1]; + pivotPoint[2] += position[2]; } + size_t objectCount = objectList.size(); + pivotPoint[0] /= objectCount; + pivotPoint[1] /= objectCount; + pivotPoint[2] /= objectCount; + // Modify the pivot point of the target + SetInstancePropertyValue(handle, m_Bridge.GetObjectDefinitions().m_Node.m_Pivot, + pivotPoint, false); + // Modify the position of the target + SetPosition(handle, pivotPoint); } // Move all children out of a given parent instances and delete the instances. @@ -2557,25 +2598,6 @@ public: TInstanceHandle group = CreateSceneGraphInstance(ComposerObjectTypes::Group, sibling, slide, DocumentEditorInsertType::PreviousSibling, CPt(), PRIMITIVETYPE_UNKNOWN, -1); - // Move the pivot point of the group to the center of the grouped objects - // Calculate the center - SFloat3 pivotPoint; - for (auto it : sortedList) { - SFloat3 position = GetPosition(it); - pivotPoint[0] += position[0]; - pivotPoint[1] += position[1]; - pivotPoint[2] += position[2]; - } - size_t objectCount = sortedList.size(); - pivotPoint[0] /= objectCount; - pivotPoint[1] /= objectCount; - pivotPoint[2] /= objectCount; - // Modify the pivot point of the group - SetInstancePropertyValue(group, m_Bridge.GetObjectDefinitions().m_Node.m_Pivot, - pivotPoint, false); - // Modify the position of the group - SetPosition(group, pivotPoint); - // Move items into the group RearrangeObjects(sortedList, group, DocumentEditorInsertType::LastChild, true); } |