void SaveEntityAsAction::Redo()
{
	if(!sc2Path.IsEmpty() && sc2Path.IsEqualToExtension(".sc2") &&
		NULL != entities && entities->Size() > 0)
	{
		DAVA::Scene *scene = new DAVA::Scene();
        Vector3 oldZero = entities->GetCommonZeroPos();
		for(size_t i = 0; i < entities->Size(); ++i)
		{
			DAVA::Entity *entity = entities->GetEntity(i);
			DAVA::Entity *clone = entity->Clone();

            Vector3 offset = clone->GetLocalTransform().GetTranslationVector() - oldZero;
            Matrix4 newLocalTransform = clone->GetLocalTransform();
            newLocalTransform.SetTranslationVector(offset);
            clone->SetLocalTransform(newLocalTransform);

            DAVA::KeyedArchive *props = GetCustomPropertiesArchieve(clone);
            if(props)
            {
                props->DeleteKey(ResourceEditor::EDITOR_REFERENCE_TO_OWNER);
            }
            
			scene->AddNode(clone);
		}

        scene->Save(sc2Path);

		scene->Release();
	}
}
void SettingsManager::Load()
{
	DAVA::KeyedArchive* toLoad = new DAVA::KeyedArchive();
	if(toLoad->Load(SETTINGS_CONFIG_FILE))
	{
        DAVA::FastNameMap<SettingsNode>::iterator i;
        DAVA::FastNameMap<SettingsNode>::iterator end = settingsMap.end();
        for(i = settingsMap.begin(); i != end; ++i)
        {
            SettingsNode *node = &i->second;
            DAVA::String name = i->first.c_str();

            if(toLoad->IsKeyExists(name))
            {
                DAVA::VariantType* sourceValue = toLoad->GetVariant(name);
                if(sourceValue->type == node->value.type)
                {
                    node->value.SetVariant(*sourceValue);
                }
            }
        }
	}

    SafeRelease(toLoad);
}
void ResourcesManageHelper::InitInternalResources()
{
	buttonBackgroundImagePath = QString::fromStdString(FilePath(BACKGROUND_IMAGE_PATH).GetAbsolutePathname());
	
	// Save project default title
    if(DAVA::Core::Instance())
    {
        DAVA::KeyedArchive *options = DAVA::Core::Instance()->GetOptions();
        if(options)
        {
			projectTitle = options->GetString("title", PROJECT_TITLE.toStdString()).c_str();
        }
    }
	// If project name wasn't set - create default name
	if (projectTitle.isNull() || projectTitle.isEmpty())
		projectTitle = PROJECT_TITLE;
}
void SettingsManager::Save()
{
	DAVA::KeyedArchive* toSave = new DAVA::KeyedArchive();

    DAVA::FastNameMap<SettingsNode>::iterator i;
    DAVA::FastNameMap<SettingsNode>::iterator end = settingsMap.end();
    for(i = settingsMap.begin(); i != end; ++i)
    {
        SettingsNode *node = &i->second;
        DAVA::String name = i->first.c_str();

        toSave->SetVariant(name, node->value);
    }

	toSave->Save(SETTINGS_CONFIG_FILE);
    toSave->Release();
}
void QtPropertyDataDavaVariant::MeSetFromChilds(const QString &lastChangedChildKey, QtPropertyData *lastChangedChildData)
{
	switch(curVariantValue.type)
	{
	case DAVA::VariantType::TYPE_KEYED_ARCHIVE:
		{
			QtPropertyDataDavaVariant *childVariantData = (QtPropertyDataDavaVariant *) lastChangedChildData;
			DAVA::KeyedArchive *archive = curVariantValue.AsKeyedArchive();

			if(NULL != archive && NULL != childVariantData)
			{
				archive->SetVariant(lastChangedChildKey.toStdString(), childVariantData->curVariantValue);
			}
		}
		break;
	case DAVA::VariantType::TYPE_MATRIX2:
		break;
	case DAVA::VariantType::TYPE_MATRIX3:
		break;
	case DAVA::VariantType::TYPE_MATRIX4:
		break;
	case DAVA::VariantType::TYPE_VECTOR2:
		{
			DAVA::Vector2 vec;
			vec.x = ChildGet("X")->GetValue().toFloat();
			vec.y = ChildGet("Y")->GetValue().toFloat();
			curVariantValue.SetVector2(vec);
		}
		break;
	case DAVA::VariantType::TYPE_VECTOR3:
		{
			DAVA::Vector3 vec;
			vec.x = ChildGet("X")->GetValue().toFloat();
			vec.y = ChildGet("Y")->GetValue().toFloat();
			vec.z = ChildGet("Z")->GetValue().toFloat();
			curVariantValue.SetVector3(vec);
		}
		break;
	case DAVA::VariantType::TYPE_VECTOR4:
		{
			DAVA::Vector4 vec;
			vec.x = ChildGet("X")->GetValue().toFloat();
			vec.y = ChildGet("Y")->GetValue().toFloat();
			vec.z = ChildGet("Z")->GetValue().toFloat();
			vec.w = ChildGet("W")->GetValue().toFloat();
			curVariantValue.SetVector4(vec);
		}
		break;
    case DAVA::VariantType::TYPE_COLOR:
		{
//			DAVA::Color color;
//			color.r = ChildGet("R")->GetValue().toFloat();
//			color.g = ChildGet("G")->GetValue().toFloat();
//			color.b = ChildGet("B")->GetValue().toFloat();
//			color.a = ChildGet("A")->GetValue().toFloat();
//			curVariantValue.SetColor(color);
		}
        break;
        case DAVA::VariantType::TYPE_AABBOX3:
        {
            DAVA::AABBox3 box;
            
            QtPropertyData* min = ChildGet("min");
            box.min.x = min->ChildGet("X")->GetValue().toFloat();
            box.min.y = min->ChildGet("Y")->GetValue().toFloat();
            box.min.z = min->ChildGet("Z")->GetValue().toFloat();
            
            QtPropertyData* max = ChildGet("max");
            box.max.x = max->ChildGet("X")->GetValue().toFloat();
            box.max.y = max->ChildGet("Y")->GetValue().toFloat();
            box.max.z = max->ChildGet("Z")->GetValue().toFloat();
            
            curVariantValue.SetAABBox3(box);
        }
            break;
	}
}
void QtPropertyDataDavaVariant::ChildsCreate()
{
	switch(curVariantValue.type)
	{
	case DAVA::VariantType::TYPE_KEYED_ARCHIVE:
		{
			DAVA::KeyedArchive *archive = curVariantValue.AsKeyedArchive();
			DAVA::Map<DAVA::String, DAVA::VariantType*> data = archive->GetArchieveData();
			DAVA::Map<DAVA::String, DAVA::VariantType*>::iterator i = data.begin();

			for(; i != data.end(); ++i)
			{
				ChildAdd(i->first.c_str(), new QtPropertyDataDavaVariant(*(i->second)));
			}
		}
		break;
	case DAVA::VariantType::TYPE_MATRIX2:
		break;
	case DAVA::VariantType::TYPE_MATRIX3:
		break;
	case DAVA::VariantType::TYPE_MATRIX4:
		break;
	case DAVA::VariantType::TYPE_VECTOR2:
		{
			DAVA::Vector2 vec = curVariantValue.AsVector2();
			ChildAdd("X", vec.x);
			ChildAdd("Y", vec.y);
		}
		break;
	case DAVA::VariantType::TYPE_VECTOR3:
		{
			DAVA::Vector3 vec = curVariantValue.AsVector3();
			ChildAdd("X", vec.x);
			ChildAdd("Y", vec.y);
			ChildAdd("Z", vec.z);
		}
		break;
	case DAVA::VariantType::TYPE_VECTOR4:
		{
			DAVA::Vector4 vec = curVariantValue.AsVector4();
			ChildAdd("X", vec.x);
			ChildAdd("Y", vec.y);
			ChildAdd("Z", vec.z);
			ChildAdd("W", vec.w);
		}
		break;
    case DAVA::VariantType::TYPE_COLOR:
        {
//            DAVA::Color color = curVariantValue.AsColor();
//            ChildAdd("R", color.r);
//            ChildAdd("G", color.g);
//            ChildAdd("B", color.b);
//            ChildAdd("A", color.a);
        }
        break;
	case DAVA::VariantType::TYPE_AABBOX3:
        {
            DAVA::AABBox3 box = curVariantValue.AsAABBox3();
            
            ChildAdd("min", FromVector3(box.min));
            ChildAdd("max", FromVector3(box.max));
            
            QtPropertyData* min = ChildGet("min");
            min->SetFlags(FLAG_IS_NOT_EDITABLE);
            min->ChildAdd("X", box.min.x);
            min->ChildAdd("Y", box.min.y);
            min->ChildAdd("Z", box.min.z);
            
            QtPropertyData* max = ChildGet("max");
            max->SetFlags(FLAG_IS_NOT_EDITABLE);
            max->ChildAdd("X", box.max.x);
            max->ChildAdd("Y", box.max.y);
            max->ChildAdd("Z", box.max.z);
        }
		break;
	}
}