Example #1
0
    bool RetainedEntityInterface::SetParent(
        const Identifier& child, const Identifier& parent, int insertionPosition)
    {
        if (child.Document() != parent.Document())
            return false;

        auto childType = _scene->GetObjectType(child.ObjectType());
        if (!childType) return false;

        auto* childObj = _scene->GetEntityInt(child.Document(), child.Object());
        if (!childObj || childObj->_type != child.ObjectType())
            return false;

        if (childObj->_parent != 0) {
            auto* oldParent = _scene->GetEntityInt(child.Document(), childObj->_parent);
            if (oldParent) {
                auto i = std::find(oldParent->_children.begin(), oldParent->_children.end(), child.Object());
                oldParent->_children.erase(i);

                auto oldParentType = _scene->GetObjectType(parent.ObjectType());
                if (oldParentType)
                    _scene->InvokeOnChange(
                        *oldParentType, *oldParent, 
                        RetainedEntities::ChangeType::RemoveChild);
            }

            childObj->_parent = 0;
        }

///////////////////////////////////////////////////////////////////////////////////////////////////
            // if parent is set to 0, then this is a "remove from parent" operation
        if (!parent.Object()) {
            _scene->InvokeOnChange(*childType, *childObj, RetainedEntities::ChangeType::SetParent);
            return true;
        }

        auto* parentObj = _scene->GetEntityInt(parent.Document(), parent.Object());
        if (!parentObj || parentObj->_type != parent.ObjectType()) {
            _scene->InvokeOnChange(*childType, *childObj, RetainedEntities::ChangeType::SetParent);
            return false;
        }

        if (insertionPosition < 0 || insertionPosition >= (int)parentObj->_children.size()) {
            parentObj->_children.push_back(child.Object());
        } else {
            parentObj->_children.insert(
                parentObj->_children.begin() + insertionPosition,
                child.Object());
        }
        childObj->_parent = parentObj->_id;

        _scene->InvokeOnChange(*childType, *childObj, RetainedEntities::ChangeType::SetParent);

        auto parentType = _scene->GetObjectType(parent.ObjectType());
        if (parentType)
            _scene->InvokeOnChange(*parentType, *parentObj, RetainedEntities::ChangeType::AddChild);

        return true;
    }
Example #2
0
	bool RetainedEntityInterface::CreateObject(const Identifier& id, 
        const PropertyInitializer initializers[], size_t initializerCount)
    {
        auto type = _scene->GetObjectType(id.ObjectType());
        if (!type) return false;

        for (auto i=_scene->_objects.cbegin(); i!=_scene->_objects.cend(); ++i)
            if (i->_doc == id.Document() && i->_id == id.Object()) return false;

        RetainedEntity newObject;
        newObject._doc = id.Document();
        newObject._id = id.Object();
        newObject._type = id.ObjectType();
        newObject._parent = 0;

        for (size_t c=0; c<initializerCount; ++c)
            _scene->SetSingleProperties(newObject, *type, initializers[c]);

        _scene->_objects.push_back(std::move(newObject));

        _scene->InvokeOnChange(*type, _scene->_objects[_scene->_objects.size()-1], RetainedEntities::ChangeType::Create);
        return true;
    }
Example #3
0
	bool RetainedEntityInterface::DeleteObject(const Identifier& id)
    {
        for (auto i=_scene->_objects.begin(); i!=_scene->_objects.end(); ++i)
            if (i->_doc == id.Document() && i->_id == id.Object()) {
                assert(i->_type == id.ObjectType());
                RetainedEntity copy(std::move(*i));
                _scene->_objects.erase(i);

                auto type = _scene->GetObjectType(id.ObjectType());
                if (type)
                    _scene->InvokeOnChange(*type, copy, RetainedEntities::ChangeType::Delete);
                return true;
            }
        return false;
    }
Example #4
0
	bool RetainedEntityInterface::GetProperty(const Identifier& id, PropertyId prop, void* dest, unsigned* destSize) const
    {
        auto type = _scene->GetObjectType(id.ObjectType());
        if (!type) return false;
        if (prop == 0 || prop > type->_properties.size()) return false;

        const auto& propertyName = type->_properties[prop-1];

        for (auto i=_scene->_objects.begin(); i!=_scene->_objects.end(); ++i)
            if (i->_doc == id.Document() && i->_id == id.Object()) {
                auto res = i->_properties.GetParameter<unsigned>(propertyName.c_str());
                if (res.first) {
                    *(unsigned*)dest = res.second;
                }
                return true;
            }

        return false;
    }
Example #5
0
	bool RetainedEntityInterface::SetProperty(
        const Identifier& id, 
        const PropertyInitializer initializers[], size_t initializerCount)
    {
        auto type = _scene->GetObjectType(id.ObjectType());
        if (!type) return false;

        for (auto i=_scene->_objects.begin(); i!=_scene->_objects.end(); ++i)
            if (i->_doc == id.Document() && i->_id == id.Object()) {
                bool gotChange = false;
                for (size_t c=0; c<initializerCount; ++c) {
                    auto& prop = initializers[c];
                    gotChange |= _scene->SetSingleProperties(*i, *type, prop);
                }
                if (gotChange) _scene->InvokeOnChange(*type, *i, RetainedEntities::ChangeType::SetProperty);
                return true;
            }

        return false;
    }