mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 14:47:41 +02:00
Merge pull request #9057 from druiz17/childParent
fixed children of parent object not being added back when performing an undo
This commit is contained in:
commit
d2b32c3084
3 changed files with 89 additions and 14 deletions
|
@ -1318,6 +1318,26 @@ QVector<QUuid> EntityScriptingInterface::getChildrenIDs(const QUuid& parentID) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool EntityScriptingInterface::isChildOfParent(QUuid childID, QUuid parentID) {
|
||||||
|
bool isChild = false;
|
||||||
|
|
||||||
|
if (!_entityTree) {
|
||||||
|
return isChild;
|
||||||
|
}
|
||||||
|
|
||||||
|
_entityTree->withReadLock([&] {
|
||||||
|
EntityItemPointer parent = _entityTree->findEntityByEntityItemID(parentID);
|
||||||
|
parent->forEachDescendant([&](SpatiallyNestablePointer descendant) {
|
||||||
|
if(descendant->getID() == childID) {
|
||||||
|
isChild = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
return isChild;
|
||||||
|
}
|
||||||
|
|
||||||
QVector<QUuid> EntityScriptingInterface::getChildrenIDsOfJoint(const QUuid& parentID, int jointIndex) {
|
QVector<QUuid> EntityScriptingInterface::getChildrenIDsOfJoint(const QUuid& parentID, int jointIndex) {
|
||||||
QVector<QUuid> result;
|
QVector<QUuid> result;
|
||||||
if (!_entityTree) {
|
if (!_entityTree) {
|
||||||
|
|
|
@ -255,6 +255,7 @@ public slots:
|
||||||
Q_INVOKABLE QStringList getJointNames(const QUuid& entityID);
|
Q_INVOKABLE QStringList getJointNames(const QUuid& entityID);
|
||||||
Q_INVOKABLE QVector<QUuid> getChildrenIDs(const QUuid& parentID);
|
Q_INVOKABLE QVector<QUuid> getChildrenIDs(const QUuid& parentID);
|
||||||
Q_INVOKABLE QVector<QUuid> getChildrenIDsOfJoint(const QUuid& parentID, int jointIndex);
|
Q_INVOKABLE QVector<QUuid> getChildrenIDsOfJoint(const QUuid& parentID, int jointIndex);
|
||||||
|
Q_INVOKABLE bool isChildOfParent(QUuid childID, QUuid parentID);
|
||||||
|
|
||||||
Q_INVOKABLE QUuid getKeyboardFocusEntity() const;
|
Q_INVOKABLE QUuid getKeyboardFocusEntity() const;
|
||||||
Q_INVOKABLE void setKeyboardFocusEntity(QUuid id);
|
Q_INVOKABLE void setKeyboardFocusEntity(QUuid id);
|
||||||
|
|
|
@ -1027,19 +1027,70 @@ function selectAllEtitiesInCurrentSelectionBox(keepIfTouching) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function sortSelectedEntities(selected) {
|
||||||
|
var sortedEntities = selected.slice();
|
||||||
|
var begin = 0;
|
||||||
|
while (begin < sortedEntities.length) {
|
||||||
|
var elementRemoved = false;
|
||||||
|
var next = begin + 1;
|
||||||
|
while (next < sortedEntities.length) {
|
||||||
|
var beginID = sortedEntities[begin];
|
||||||
|
var nextID = sortedEntities[next];
|
||||||
|
|
||||||
|
if (Entities.isChildOfParent(beginID, nextID)) {
|
||||||
|
sortedEntities[begin] = nextID;
|
||||||
|
sortedEntities[next] = beginID;
|
||||||
|
sortedEntities.splice(next, 1);
|
||||||
|
elementRemoved = true;
|
||||||
|
break;
|
||||||
|
} else if (Entities.isChildOfParent(nextID, beginID)) {
|
||||||
|
sortedEntities.splice(next, 1);
|
||||||
|
elementRemoved = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
next++;
|
||||||
|
}
|
||||||
|
if (!elementRemoved) {
|
||||||
|
begin++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return sortedEntities;
|
||||||
|
}
|
||||||
|
|
||||||
|
function recursiveDelete(entities, childrenList) {
|
||||||
|
var entitiesLength = entities.length;
|
||||||
|
for (var i = 0; i < entitiesLength; i++) {
|
||||||
|
var entityID = entities[i];
|
||||||
|
var children = Entities.getChildrenIDs(entityID);
|
||||||
|
var grandchildrenList = [];
|
||||||
|
recursiveDelete(children, grandchildrenList);
|
||||||
|
var initialProperties = Entities.getEntityProperties(entityID);
|
||||||
|
childrenList.push({
|
||||||
|
entityID: entityID,
|
||||||
|
properties: initialProperties,
|
||||||
|
children: grandchildrenList
|
||||||
|
});
|
||||||
|
Entities.deleteEntity(entityID);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function deleteSelectedEntities() {
|
function deleteSelectedEntities() {
|
||||||
if (SelectionManager.hasSelection()) {
|
if (SelectionManager.hasSelection()) {
|
||||||
selectedParticleEntity = 0;
|
selectedParticleEntity = 0;
|
||||||
particleExplorerTool.destroyWebView();
|
particleExplorerTool.destroyWebView();
|
||||||
SelectionManager.saveProperties();
|
SelectionManager.saveProperties();
|
||||||
var savedProperties = [];
|
var savedProperties = [];
|
||||||
for (var i = 0; i < selectionManager.selections.length; i++) {
|
var newSortedSelection = sortSelectedEntities(selectionManager.selections);
|
||||||
var entityID = SelectionManager.selections[i];
|
for (var i = 0; i < newSortedSelection.length; i++) {
|
||||||
|
var entityID = newSortedSelection[i];
|
||||||
var initialProperties = SelectionManager.savedProperties[entityID];
|
var initialProperties = SelectionManager.savedProperties[entityID];
|
||||||
SelectionManager.savedProperties[entityID];
|
var children = Entities.getChildrenIDs(entityID);
|
||||||
|
var childList = [];
|
||||||
|
recursiveDelete(children, childList);
|
||||||
savedProperties.push({
|
savedProperties.push({
|
||||||
entityID: entityID,
|
entityID: entityID,
|
||||||
properties: initialProperties
|
properties: initialProperties,
|
||||||
|
children: childList
|
||||||
});
|
});
|
||||||
Entities.deleteEntity(entityID);
|
Entities.deleteEntity(entityID);
|
||||||
}
|
}
|
||||||
|
@ -1253,6 +1304,16 @@ Controller.keyReleaseEvent.connect(function (event) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function recursiveAdd(newParentID, parentData) {
|
||||||
|
var children = parentData.children;
|
||||||
|
for (var i = 0; i < children.length; i++) {
|
||||||
|
var childProperties = children[i].properties;
|
||||||
|
childProperties.parentID = newParentID;
|
||||||
|
var newChildID = Entities.addEntity(childProperties);
|
||||||
|
recursiveAdd(newChildID, children[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// When an entity has been deleted we need a way to "undo" this deletion. Because it's not currently
|
// When an entity has been deleted we need a way to "undo" this deletion. Because it's not currently
|
||||||
// possible to create an entity with a specific id, earlier undo commands to the deleted entity
|
// possible to create an entity with a specific id, earlier undo commands to the deleted entity
|
||||||
// will fail if there isn't a way to find the new entity id.
|
// will fail if there isn't a way to find the new entity id.
|
||||||
|
@ -1274,6 +1335,7 @@ function applyEntityProperties(data) {
|
||||||
entityID = data.createEntities[i].entityID;
|
entityID = data.createEntities[i].entityID;
|
||||||
var entityProperties = data.createEntities[i].properties;
|
var entityProperties = data.createEntities[i].properties;
|
||||||
var newEntityID = Entities.addEntity(entityProperties);
|
var newEntityID = Entities.addEntity(entityProperties);
|
||||||
|
recursiveAdd(newEntityID, data.createEntities[i]);
|
||||||
DELETED_ENTITY_MAP[entityID] = newEntityID;
|
DELETED_ENTITY_MAP[entityID] = newEntityID;
|
||||||
if (data.selectCreated) {
|
if (data.selectCreated) {
|
||||||
selectedEntityIDs.push(newEntityID);
|
selectedEntityIDs.push(newEntityID);
|
||||||
|
@ -1314,19 +1376,11 @@ function pushCommandForSelections(createdEntityData, deletedEntityData) {
|
||||||
}
|
}
|
||||||
undoData.setProperties.push({
|
undoData.setProperties.push({
|
||||||
entityID: entityID,
|
entityID: entityID,
|
||||||
properties: {
|
properties: initialProperties
|
||||||
position: initialProperties.position,
|
|
||||||
rotation: initialProperties.rotation,
|
|
||||||
dimensions: initialProperties.dimensions
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
redoData.setProperties.push({
|
redoData.setProperties.push({
|
||||||
entityID: entityID,
|
entityID: entityID,
|
||||||
properties: {
|
properties: currentProperties
|
||||||
position: currentProperties.position,
|
|
||||||
rotation: currentProperties.rotation,
|
|
||||||
dimensions: currentProperties.dimensions
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
UndoStack.pushCommand(applyEntityProperties, undoData, applyEntityProperties, redoData);
|
UndoStack.pushCommand(applyEntityProperties, undoData, applyEntityProperties, redoData);
|
||||||
|
|
Loading…
Reference in a new issue