Exemplo n.º 1
0
//--------------------------------------------------------------------------------
void CMultiSelEditor::remove(const Ogre::StringVector& newselection)
{
    if(mDeletionInProgress)
        return;

    Ogre::StringVector::const_iterator it = newselection.begin();
    NameObjectPairList::iterator dit;
    
    while(it != newselection.end())
    {
        CBaseEditor *object = mOgitorsRoot->FindObject(*it);
       
        if(object)
        {
            if((dit = mSelectedObjects.find(object->getName())) != mSelectedObjects.end())
            {
                mSelectedObjects.erase(dit);

                object->setSelected(false);
            }
        }

        it++;
    }

    _createModifyList();
}
Exemplo n.º 2
0
//--------------------------------------------------------------------------------
void CMultiSelEditor::deleteObjects()
{
    mDeletionInProgress = true;

    CBaseEditor *ed = 0;

    NameObjectPairList list = mSelectedObjects;
    NameObjectPairList::iterator it = list.begin();
    
    while(it != list.end())
    {
        //First trying to get the object by name, we could use it->second too but then
        //we can never be sure if the objects parent is deleted before the object
        //and that pointer became invalid, this way we make sure object exists...
        ed = mOgitorsRoot->FindObject(it->first);

        if(ed && ed->supports(CAN_DELETE))
            mOgitorsRoot->DestroyEditorObject(ed, true);

        it++;
    }

    mSelectedObjects.clear();
    mModifyList.clear();
    mDeletionInProgress = false;
}
Exemplo n.º 3
0
//--------------------------------------------------------------------------------
void CMultiSelEditor::add(const Ogre::StringVector& newselection)
{
    if(mDeletionInProgress)
        return;

    Ogre::StringVector::const_iterator it = newselection.begin();
    
    while(it != newselection.end())
    {
        CBaseEditor *object = mOgitorsRoot->FindObject(*it);
       
        if(object && object != this)
        {
            if(mSelectedObjects.find(object->getName()) == mSelectedObjects.end())
            {
                mSelectedObjects.insert(NameObjectPairList::value_type(object->getName(), object));

                object->setSelected(true);
            }
        }

        it++;
    }

    _createModifyList();
}
Exemplo n.º 4
0
//----------------------------------------------------------------------------------
bool PropertyUndo::apply()
{
    CBaseEditor *object = OgitorsRoot::getSingletonPtr()->FindObject(mObjectID);
    if(!object)
        return false;

    if(mValue.propType == PROP_UNSIGNED_LONG && mPropertyName == "parent")
    {
        CBaseEditor *parent = OgitorsRoot::getSingletonPtr()->FindObject(Ogre::any_cast<unsigned long>(mValue.val));
        if(!parent)
            return false;

        mValue.val = Ogre::Any((unsigned long)parent);
    }

    OgitorsPropertyValueMap map;
    map.insert(OgitorsPropertyValueMap::value_type(mPropertyName, mValue));
    if(mSetType == PROPSET_OBJECT)
    {
        object->getProperties()->setValueMap(map);
        return true;
    }
    else if(mSetType == PROPSET_CUSTOM)
    {
        object->getCustomProperties()->setValueMap(map);
        return true;
    }

    return false;
}
Exemplo n.º 5
0
//----------------------------------------------------------------------------------------
void ObjectsViewWidget::OnDragDropped(Ogre::Viewport *vp, Ogre::Vector2& position)
{
    mDragData.Parameters.clear();

    mDragData.Parameters["init"] = EMPTY_PROPERTY_VALUE;

    if(mDragData.Object)
    {
        OgitorsPropertyValueMap params;
        mDragData.Object->getPropertyMap(params);
        mDragData.Object->destroy();
        mDragData.Object = 0;
        
        mDragData.Parameters["position"] = params["position"];
    }

    CBaseEditor *object = OgitorsRoot::getSingletonPtr()->CreateEditorObject(0,mDragData.ObjectType, mDragData.Parameters, true, true);
    
    if(object && object->isTerrainType())
        mOgitorMainWindow->getTerrainToolsWidget()->updateTerrainOptions(object->getTerrainEditor());


    mDragData.Parameters.clear();
    mDragData.ObjectType = "";
    mDragData.Object = 0;
}
//----------------------------------------------------------------------------------  
CBaseEditor *OgitorsClipboardManager::paste(CBaseEditor *parent, int index)
{
    ObjectCopyData *data = 0;

    assert(index < (int)mBuffer.size());

    if(index == -1)
        data = mBuffer[mBuffer.size() - 1];
    else
        data = mBuffer[index];

    CBaseEditor* object = OgitorsRoot::getSingletonPtr()->FindObject(data->mObjectName);
    
    OgitorsPropertyValueMap properties = data->mProperties;
    if(object)
    {
        Ogre::String newname = data->mObjectName + "Copy";
        newname += OgitorsRoot::getSingletonPtr()->CreateUniqueID(newname, "", 0);
        properties["name"].val = Ogre::Any(newname);
    }

    object = OgitorsRoot::getSingletonPtr()->CreateEditorObject(parent, data->mObjectTypeName, properties, true, false);
    if(!object)
        return 0;

    object->getCustomProperties()->initFromSet(data->mCustomProperties);
    object->load();
    OgitorsRoot::getSingletonPtr()->GetSelection()->setSelection(object);

    return object;
}
Exemplo n.º 7
0
//----------------------------------------------------------------------------------
//----------------------------------------------------------------------------------
CustomSetRebuiltUndo::CustomSetRebuiltUndo(OgitorsCustomPropertySet *set)
{
    assert(set->getOwnerData().mOwnerType == PROPSETOWNER_EDITOR);
    CBaseEditor *object = static_cast<CBaseEditor*>(set->getOwnerData().mOwnerPtr);
    mObjectID = object->getObjectID();
    
    mCustomProperties = OGRE_NEW OgitorsCustomPropertySet();
    object->getCustomProperties()->cloneSet(*mCustomProperties);

    mDescription = object->getName() + " Custom Property Set Change";
}
Exemplo n.º 8
0
//----------------------------------------------------------------------------------
bool CustomSetRebuiltUndo::apply()
{
    CBaseEditor *object = OgitorsRoot::getSingletonPtr()->FindObject(mObjectID);

    if(object)
    {
        object->getCustomProperties()->initFromSet(*mCustomProperties);
        return true;
    }

    return false;
}
Exemplo n.º 9
0
//----------------------------------------------------------------------------------
bool ObjectDeletionUndo::apply()
{
    CBaseEditor *object;
    CBaseEditor *parent = OgitorsRoot::getSingletonPtr()->FindObject(mParentObjectID);

    object = OgitorsRoot::getSingletonPtr()->CreateEditorObject(parent, mTypeName, mObjectProperties, true, true);
    if(object)
    {
        object->getCustomProperties()->initFromSet(*mCustomProperties);
        return true;
    }

    return false;
}
void GeneralTreeBrowser::contextMenuEvent(QContextMenuEvent *evt)
{
    QtBrowserItem *citem = currentItem();
    if(citem == 0)
        return;

    CBaseEditor *e = OgitorsRoot::getSingletonPtr()->GetSelection()->getAsSingle();

    LastProperty = static_cast<GeneralPropertiesViewWidget*>(parent())->getOgitorProperty(citem->property());

    if(!LastProperty)
        LastPropertyName = citem->property()->propertyName();
    else
        LastPropertyName = LastProperty->getName().c_str();

    if(e != 0)
    {
        UTFStringVector menuList;
        e->getPropertyContextMenu(LastPropertyName.toStdString(), menuList);
        
        if(menuList.size() > 0)
        {
            UTFStringVector vList;
            int counter = 0;
            QMenu* contextMenu = new QMenu(this);
            QSignalMapper *signalMapper = new QSignalMapper(this);

            for(unsigned int i = 0;i < menuList.size();i++)
            {
                OgitorsUtils::ParseUTFStringVector(menuList[i], vList);
                if(vList.size() > 0 && vList[0] != "")
                {                 
                    QAction *item = contextMenu->addAction( ConvertToQString(vList[0]), signalMapper, SLOT(map()), 0);
                    if(vList.size() > 1)
                        item->setIcon(QIcon(ConvertToQString(vList[1])));
                    signalMapper->setMapping(item, i);
                    counter++;
                }
            }
            if(counter)
            {
                connect(signalMapper, SIGNAL(mapped( int )), this, SLOT(contextMenu( int )));
                contextMenu->exec(QCursor::pos());
            }
            delete contextMenu;
            delete signalMapper;
        }
//----------------------------------------------------------------------------
int CDotSceneSerializer::RecurseReadObjects(TiXmlElement *parentelement,CBaseEditor* parentobject)
{
    CBaseEditor *newobj;
    TiXmlElement* element = 0;
    Ogre::String eType;
    element = parentelement->FirstChildElement();
    if(!element) return SCF_OK;
    do
    {
        newobj = 0;
        eType = element->Value();
        if(eType == "node") 
        {
            ReadSceneNode(element, parentobject, &newobj);
            int ret = RecurseReadObjects(element, newobj);
            
            if(ret != SCF_OK) 
                return ret;

            NameObjectPairList& childlist = newobj->getChildren();
            if(childlist.size() == 1)
            {
                CBaseEditor *childobj = childlist.begin()->second;
                childobj->setParent(newobj->getParent());
                OgitorsPropertyValueMap vmapn = newobj->getProperties()->getValueMap();
                OgitorsPropertyValueMap vmapo;

                OgitorsPropertyValueMap::iterator vit;

                vit = vmapn.find("autotracktarget");
                vmapo.insert(OgitorsPropertyValueMap::value_type(vit->first, vit->second));
                vit = vmapn.find("position");
                vmapo.insert(OgitorsPropertyValueMap::value_type(vit->first, vit->second));
                vit = vmapn.find("scale");
                vmapo.insert(OgitorsPropertyValueMap::value_type(vit->first, vit->second));
                vit = vmapn.find("orientation");
                vmapo.insert(OgitorsPropertyValueMap::value_type(vit->first, vit->second));

                OgitorsRoot::getSingletonPtr()->DestroyEditorObject(newobj);
                newobj = childobj;
                childobj->getProperties()->setValueMap(vmapo);
            }
        }
        else if(eType == "entity") ReadEntity(element, parentobject, &newobj);
        else if(eType == "subentities") ReadSubEntity(element, parentobject, &newobj);
        else if(eType == "light") ReadLight(element, parentobject, &newobj);
        else if(eType == "camera") ReadCamera(element, parentobject, &newobj);
        else if(eType == "particle") ReadParticle(element, parentobject, &newobj);
        else if(eType == "plane") ReadPlane(element, parentobject, &newobj);
        else 
            continue;
    } while(element = element->NextSiblingElement());
    return SCF_OK;
}
Exemplo n.º 12
0
int COFSSceneSerializer::Import(Ogre::String importfile)
{
    OgitorsRoot *ogRoot = OgitorsRoot::getSingletonPtr();
    OgitorsSystem *mSystem = OgitorsSystem::getSingletonPtr();
    OFS::OfsPtr& mFile = OgitorsRoot::getSingletonPtr()->GetProjectFile();

    if(importfile == "")
    {
        UTFStringVector extlist;
        extlist.push_back(OTR("Ogitor File System File"));
        extlist.push_back("*.ofs");
        extlist.push_back(OTR("Ogitor Scene File"));
        extlist.push_back("*" + Globals::OGSCENE_FORMAT_EXTENSION);

        importfile = mSystem->GetSetting("system", "oldOpenPath", "");
        importfile = mSystem->DisplayOpenDialog(OTR("Open"), extlist, importfile);
        if(importfile == "") 
            return SCF_CANCEL;

        mSystem->SetSetting("system", "oldOpenPath", importfile);
    }

    importfile = OgitorsUtils::QualifyPath(importfile);

    Ogre::String filePath = OgitorsUtils::ExtractFilePath(importfile);
    Ogre::String fileName = OgitorsUtils::ExtractFileName(importfile);

    bool testpassed = false;
    try
    {
        std::ofstream test((filePath + "test.dat").c_str());
        if(test.is_open())
            testpassed = true;
        test.close();
        mSystem->DeleteFile(filePath + "test.dat");
    }
    catch(...)
    {
        testpassed = false;
    }

    if(!testpassed)
    {
        mSystem->DisplayMessageDialog("The path is read-only. Ogitor can not work with read-only project paths!", DLGTYPE_OK);
        return SCF_CANCEL;
    }

    Ogre::UTFString loadmsg = "";

    int typepos = importfile.find_last_of(".");
    if(typepos != -1 && (importfile.substr(typepos, 4) != ".ofs"))
        importfile = filePath;
    

    OFS::OfsResult oRet;
    if((oRet = mFile.mount(importfile.c_str(), OFS::OFS_MOUNT_OPEN | OFS::OFS_MOUNT_RECOVER)) != OFS::OFS_OK)
    {
        if(oRet == OFS::OFS_PREVIOUS_VERSION)
        {
            mSystem->DisplayMessageDialog("The OFS file is a previous version, please use qtOFS to upgrade it to new file version.", DLGTYPE_OK);
        }

        loadmsg = mSystem->Translate("Please load a Scene File...");
        mSystem->UpdateLoadProgress(-1, loadmsg);
        return SCF_ERRPARSE;
    }

    OFS::FileSystemStats fsStats;

    mFile->getFileSystemStats(fsStats);

    PROJECTOPTIONS *pOpt = ogRoot->GetProjectOptions();
    pOpt->CreatedIn = "";

    pOpt->ProjectDir = filePath;
    typepos = fileName.find_last_of(".");
    if(typepos != -1)
        fileName.erase(typepos, fileName.length() - typepos);
    pOpt->ProjectName = fileName;

    fileName += Globals::OGSCENE_FORMAT_EXTENSION;

    OFS::ofs64 file_size = 0;

    if(mFile->getFileSize(fileName.c_str(), file_size) != OFS::OFS_OK)
	{		
        // OGSCENE file name needs to match OFS container file name. If the later was renamed, we 
        // need to automatically adapt the OGSCENE file name now.
        OFS::FileList files = mFile->listFiles("/", OFS::OFS_FILE);
        unsigned int ogsceneFileExtensionLength = strlen(Globals::OGSCENE_FORMAT_EXTENSION.c_str());

		for(OFS::FileList::iterator iter = files.begin(); iter != files.end(); iter++)
		{
			// Filter out too short names
            if(iter->name.size() <= ogsceneFileExtensionLength) 
                continue;

			if(stricmp(iter->name.c_str() + (iter->name.size() - (ogsceneFileExtensionLength)), Globals::OGSCENE_FORMAT_EXTENSION.c_str()) == 0)
			{
				mFile->renameFile(iter->name.c_str(), fileName.c_str());
				break;
			}
		}

		if(mFile->getFileSize(fileName.c_str(), file_size) != OFS::OFS_OK)
			return SCF_ERRFILE;
	}

    char *file_data = new char[(unsigned int)file_size + 1];

    OFS::OFSHANDLE projHandle;

    if(mFile->openFile(projHandle, fileName.c_str(), OFS::OFS_READ) != OFS::OFS_OK)
    {
        delete [] file_data;
        return SCF_ERRFILE;
    }

    mFile->read(projHandle, file_data, file_size);
    mFile->closeFile(projHandle);

    TiXmlDocument docImport;

    if(!docImport.LoadFromMemory(file_data, file_size))
    {
        delete [] file_data;
        return SCF_ERRFILE;
    }

    delete [] file_data;

    loadmsg = mSystem->Translate("Parsing Scene File");
    mSystem->UpdateLoadProgress(1, loadmsg);

    TiXmlNode* ogitorSceneNode = 0;
    TiXmlNode* projectNode;
    TiXmlElement* element = 0;
    bool upgradeExecuted = false;
    ogitorSceneNode = docImport.FirstChild("OGITORSCENE");

    if(!ogitorSceneNode)
        return SCF_ERRPARSE;

    element = ogitorSceneNode->ToElement();

    // Old OGSCENE version check and attempt to fix/update
    int version = Ogre::StringConverter::parseInt(ValidAttr(element->Attribute("version"), "0"));    
    if(Ogre::StringConverter::toString(version) < Globals::OGSCENE_FORMAT_VERSION)
    {
        mSystem->DisplayMessageDialog(mSystem->Translate("Old OGSCENE file version detected. Ogitor will now attempt to upgrade the format and will also create a backup version of your OFS file."), DLGTYPE_OK);

        loadmsg = mSystem->Translate("Upgrading OGSCENE file.");
        mSystem->UpdateLoadProgress(10, loadmsg);

        if(version == 0)
        {
            mSystem->DisplayMessageDialog(mSystem->Translate("OGSCENE files contains no version number set and therefore cannot be loaded."), DLGTYPE_OK);
            return SCF_ERRPARSE;
        }
        else if(version == 1)
        {
            mSystem->DisplayMessageDialog(mSystem->Translate("OGSCENE files with version 1 cannot be upgraded automatically. Please contact the Ogitor team for further details."), DLGTYPE_OK);
            return SCF_ERRPARSE;
        }

        if(version > 1)
        {
            if((mFile->getFileSystemType() == OFS::OFS_PACKED) && (!mSystem->CopyFile(importfile, importfile + ".backup")))
                mSystem->DisplayMessageDialog(mSystem->Translate("Error while trying to create backup file."), DLGTYPE_OK);
        }
        switch(version)
        {
         case 2:
            _upgradeOgsceneFileFrom2To3(ogitorSceneNode);
            _upgradeOgsceneFileFrom3To4(ogitorSceneNode);
            break;
         case 3:
            _upgradeOgsceneFileFrom3To4(ogitorSceneNode);
            break;
        }

        upgradeExecuted = true;
    }  

    projectNode = ogitorSceneNode->FirstChild("PROJECT");

    if(projectNode)
    {
        loadmsg = mSystem->Translate("Parsing project options");
        mSystem->UpdateLoadProgress(5, loadmsg);
        ogRoot->LoadProjectOptions(projectNode->ToElement());
        ogRoot->PrepareProjectResources();
    }

    element = ogitorSceneNode->FirstChildElement();

    loadmsg = mSystem->Translate("Creating scene objects");
    mSystem->UpdateLoadProgress(10, loadmsg);

    unsigned int obj_count = 0;
    Ogre::String objecttype;
    OgitorsPropertyValueMap params;
    OgitorsPropertyValue tmpPropVal;
    Ogre::String objAttValue;
    Ogre::String elementName;
    TiXmlElement* properties = 0;
    Ogre::String attID;
    Ogre::String attValue;
    CBaseEditor* result = 0;
    TiXmlElement* customprop = 0;
    Ogre::StringVector invalidEditorTypes;

    do
    {
        // Make sure its NON-ZERO
        if(pOpt->ObjectCount)
        {
            ++obj_count;
            mSystem->UpdateLoadProgress(10 + ((obj_count * 70) / pOpt->ObjectCount), loadmsg);
        }

        params.clear();       

        objAttValue = ValidAttr(element->Attribute("object_id"), "");
        if(objAttValue != "")
        {
            tmpPropVal.propType = PROP_UNSIGNED_INT;
            tmpPropVal.val = Ogre::Any(Ogre::StringConverter::parseUnsignedInt(objAttValue));
            params.insert(OgitorsPropertyValueMap::value_type("object_id", tmpPropVal));
        }

        objAttValue = ValidAttr(element->Attribute("parentnode"), "");
        if(objAttValue != "")
        {
            tmpPropVal.propType = PROP_STRING;
            tmpPropVal.val = Ogre::Any(objAttValue);
            params.insert(OgitorsPropertyValueMap::value_type("parentnode", tmpPropVal));
        }

        objAttValue = ValidAttr(element->Attribute("name"), "");
        if(objAttValue != "")
        {
            tmpPropVal.propType = PROP_STRING;
            tmpPropVal.val = Ogre::Any(objAttValue);
            params.insert(OgitorsPropertyValueMap::value_type("name", tmpPropVal));
        }
        else
            continue;

        objAttValue = ValidAttr(element->Attribute("typename"), "");
        if(objAttValue != "")
        {
            tmpPropVal.propType = PROP_STRING;
            tmpPropVal.val = Ogre::Any(objAttValue);
            params.insert(OgitorsPropertyValueMap::value_type("typename", tmpPropVal));
        }
        else
            continue;

        properties = element->FirstChildElement();
        if(properties)
        {            
            do
            {
                elementName = properties->Value();
                if(elementName != "PROPERTY")
                    continue;

                attID = ValidAttr(properties->Attribute("id"), "");
                int attType = Ogre::StringConverter::parseInt(ValidAttr(properties->Attribute("type"), ""));
                attValue = ValidAttr(properties->Attribute("value"), "");

                params.insert(OgitorsPropertyValueMap::value_type(attID, OgitorsPropertyValue::createFromString((OgitorsPropertyType)attType, attValue)));
            } while(properties = properties->NextSiblingElement());
        }

        objecttype = Ogre::any_cast<Ogre::String>(params["typename"].val);
        result = ogRoot->CreateEditorObject(0, objecttype, params, false, false);
        if(result)
        {
            customprop = element->FirstChildElement("CUSTOMPROPERTIES");
            if(customprop) 
            {
                OgitorsUtils::ReadCustomPropertySet(customprop, result->getCustomProperties());
            }
        }
        else
            invalidEditorTypes.push_back(objecttype);

    } while(element = element->NextSiblingElement());

    // Print out invalid/unsupported editor types (= types where no factory could be found)
    if(invalidEditorTypes.size() > 0)
    {
        std::sort(invalidEditorTypes.begin(), invalidEditorTypes.end());
        invalidEditorTypes.erase(std::unique(invalidEditorTypes.begin(), invalidEditorTypes.end()), invalidEditorTypes.end());
        Ogre::String invalidTypesResultString;
        for(unsigned int i = 0; i < invalidEditorTypes.size(); i++)
        {
            invalidTypesResultString += invalidEditorTypes.at(i) + "\n";
        }
        mSystem->DisplayMessageDialog(mSystem->Translate("Could not create objects of types:\n" + invalidTypesResultString), DLGTYPE_OK);
    }

    //// Save directly after upgrade
    //if(upgradeExecuted)
    //    Export(false, importfile);

    ogRoot->AfterLoadScene();

    return SCF_OK;
}
Exemplo n.º 13
0
//--------------------------------------------------------------------------------
void CMultiSelEditor::_createModifyList()
{
    mWorldAABB = Ogre::AxisAlignedBox::BOX_NULL;
    mModifyList.clear();
    NameObjectPairList::const_iterator it = mSelectedObjects.begin();
    while(it != mSelectedObjects.end())
    {
        CBaseEditor *add = it->second;
        Ogre::AxisAlignedBox box = add->getWorldAABB();
        mWorldAABB.merge(box);

        Ogre::String name = add->getName();
        if(mModifyList.find(name) == mModifyList.end()) 
            mModifyList.insert(NameObjectPairList::value_type(add->getName(), add));

        it++;
    }
    
    Ogre::String remname;
    Ogre::StringVector removeList;
    removeList.clear();


    it = mModifyList.begin();
    while(it != mModifyList.end())
    {
        remname = it->second->getParent()->getName();

        if(mModifyList.find(remname) != mModifyList.end()) 
            removeList.push_back(it->first);

        it++;
    }

    for(unsigned int x = 0;x < removeList.size(); x++)
    {
        mModifyList.erase(mModifyList.find(removeList[x]));
    }

    Ogre::Vector3 xTot = Ogre::Vector3::ZERO;
    Ogre::Vector3 yTot = Ogre::Vector3::ZERO;
    Ogre::Vector3 zTot = Ogre::Vector3::ZERO;
    int count = 0;

    it = mModifyList.begin();
    while(it != mModifyList.end())
    {
        xTot += it->second->getDerivedOrientation() * Ogre::Vector3::UNIT_X;
        yTot += it->second->getDerivedOrientation() * Ogre::Vector3::UNIT_Y;
        zTot += it->second->getDerivedOrientation() * Ogre::Vector3::UNIT_Z;
        count++;
        it++;
    }

    if(count)
    {
        xTot /= ((float)count);
        yTot /= ((float)count);
        zTot /= ((float)count);
        Ogre::Vector3 normal = Ogre::Vector3::UNIT_Z;
        Ogre::Quaternion q;
        q.FromAxes(xTot,yTot,zTot);

        mNode->setPosition(mWorldAABB.getCenter());
        mNode->setOrientation(q);
    }
    else
    {
        mNode->setPosition(Ogre::Vector3::ZERO);
        mNode->setOrientation(Ogre::Quaternion::IDENTITY);
    }
    mNode->setScale(1,1,1);

    if(mSelectedObjects.size() == 0)
    {
        mSystem->SelectTreeItem(mOgitorsRoot->GetRootEditor());
        mSystem->PresentPropertiesView(0);
    }
    else if(mSelectedObjects.size() == 1)
    {
        mSystem->SelectTreeItem(mSelectedObjects.begin()->second);
        mSystem->PresentPropertiesView(mSelectedObjects.begin()->second);
    }
    else
    {
        mSystem->SelectTreeItem(this);
        mSystem->PresentPropertiesView(this);
    }

    SelectionChangeEvent evt(this);
    EventManager::getSingletonPtr()->sendEvent(this, 0, &evt);
}
//----------------------------------------------------------------------------------
CBaseEditor *OgitorsClipboardManager::instantiateTemplate(const Ogre::String& templatename)
{
    CBaseEditor *retObject = OgitorsRoot::getSingletonPtr()->GetSelection();

    CBaseEditor *item = 0;
    ObjectTemplateMap::const_iterator it;

    it = mGeneralTemplates.find(templatename);
    if(it == mGeneralTemplates.end())
    {
        it = mProjectTemplates.find(templatename);
        if(it == mProjectTemplates.end())
            return 0;
    }

    ObjectTemplate objTemplate = it->second;
    OgitorsPropertyValueMap::iterator pit;
    NameObjectPairList list;
    NameObjectPairList objlist;
    std::vector<CBaseEditor*> objlist2;
    NameObjectPairList::iterator nit;

    Ogre::String parentname;

    int numParentObjects = 0;

    for(unsigned int i = 0;i < objTemplate.size();i++)
    {
        OgitorsPropertyValueMap objMap = objTemplate[i].mObjectProperties;
        if((pit = objMap.find("parentnode")) != objMap.end())
        {
            parentname = Ogre::any_cast<Ogre::String>(pit->second.val);
            if((nit = list.find(parentname)) != list.end())
            {
                pit->second.val = Ogre::Any(nit->second->getName());
            }
            else
            {
                objMap.erase(pit);
                ++numParentObjects;
            }
        }
        else
            ++numParentObjects;

        parentname = Ogre::any_cast<Ogre::String>(objMap["name"].val);
        objMap["name"].val = Ogre::Any(parentname + OgitorsRoot::getSingletonPtr()->CreateUniqueID(parentname,"",0));

        item = OgitorsRoot::getSingletonPtr()->CreateEditorObject(0, objTemplate[i].mTypeName, objMap, true, false);

        if(item)
        {
            item->load();
            item->getCustomProperties()->initFromSet(*(objTemplate[i].mCustomProperties));
            list.insert(NameObjectPairList::value_type(parentname, item));
            objlist.insert(NameObjectPairList::value_type(item->getName(), item));
            objlist2.push_back(item);
        }
    }

    Ogre::Vector3 pos(999999, 999999, 999999);

    if(numParentObjects == 0)
        return 0;
    else if(numParentObjects == 1)
    {
        retObject = objlist2[0];
        OgitorsRoot::getSingletonPtr()->GetSelection()->setSelection(retObject);
    }
    else
        static_cast<CMultiSelEditor*>(retObject)->setSelection(objlist);


    if(retObject->getProperties()->hasProperty("position"))
        retObject->getProperties()->setValue("position", pos);

    return retObject;
}
//----------------------------------------------------------------------------------
bool OgitorsClipboardManager::copyToTemplateMulti(CMultiSelEditor *object, const Ogre::String& templatename, bool isGeneralScope)
{
    if(templatename.empty())
        return false;

    NameObjectPairList list = object->getSelection();
    NameObjectPairList::iterator oit = list.begin();

    if(oit == list.end())
        return false;

    Ogre::String filename;

    OFS::OfsPtr& mFile = OgitorsRoot::getSingletonPtr()->GetProjectFile();

    if(isGeneralScope)
    {
        filename = OgitorsSystem::getSingletonPtr()->getProjectsDirectory() + "/Templates";
        filename = OgitorsUtils::QualifyPath(filename) + "/";
        OgitorsSystem::getSingletonPtr()->MakeDirectory(filename);
    }
    else
    {
        filename = "/Templates";
        mFile->createDirectory(filename.c_str());
    }
    
    
    filename += "/" + templatename + ".otl";

    std::stringstream outfile;
    outfile << "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
    outfile << "<TEMPLATES>\n";
    outfile << "  <OBJECTTEMPLATE name=\"";
    outfile << templatename.c_str();
    outfile << "\">\n";

    ObjectTemplateMap::iterator rit;
    if(isGeneralScope)
        rit = mGeneralTemplates.insert(ObjectTemplateMap::value_type(templatename, ObjectTemplate())).first;
    else
        rit = mProjectTemplates.insert(ObjectTemplateMap::value_type(templatename, ObjectTemplate())).first;

    std::vector<CBaseEditor*> objList;

    while(oit != list.end())
    {
        CBaseEditor *item = oit->second;
        if(!item->supports(CAN_ACCEPTCOPY))
        {
            list.erase(oit);
            oit = list.begin();
        }
        else
        {
            CBaseEditor *itemParent = item->getParent();
            Ogre::String parentName = "";
            if(itemParent)
                parentName = itemParent->getName();

            if(list.find(parentName) == list.end())
            {
                list.erase(oit);
                oit = list.begin();
                objList.push_back(item);
            }
            else
                oit++;
        }
    }

    for(unsigned int objn = 0;objn < objList.size();objn++)
    {
        CBaseEditor *item = objList[objn];

        outfile << OgitorsUtils::GetObjectSaveStringV2(item, 2, false, true).c_str();

        rit->second.push_back(ObjectTemplateData());
        int itempos = rit->second.size() - 1;
        item->getPropertyMap(rit->second[itempos].mObjectProperties);
        rit->second[itempos].mObjectProperties.erase(rit->second[itempos].mObjectProperties.find("object_id"));
        OgitorsPropertyValue parentnodevalue;
        parentnodevalue.propType = PROP_STRING;
        parentnodevalue.val = Ogre::Any(item->getParent()->getName());
        rit->second[itempos].mObjectProperties.insert(OgitorsPropertyValueMap::value_type("parentnode", parentnodevalue));
        OgitorsCustomPropertySet *tmpset = OGRE_NEW OgitorsCustomPropertySet();
        item->getCustomProperties()->cloneSet(*tmpset);
        rit->second[itempos].mCustomProperties = tmpset;
        rit->second[itempos].mTypeName = item->getTypeName();
    }

    outfile << "  </OBJECTTEMPLATE>\n";
    outfile << "</TEMPLATES>\n";

    if(isGeneralScope)
    {
        std::ofstream out_general(filename.c_str());
        out_general << outfile.str();
        out_general.close();
    }
    else
    {
        OgitorsUtils::SaveStreamOfs(outfile, filename);
    }

    return true;
}
//----------------------------------------------------------------------------------
bool OgitorsClipboardManager::copyToTemplateWithChildren(CBaseEditor *object, const Ogre::String& templatename, bool isGeneralScope)
{
    if(templatename.empty())
        return false;

    Ogre::String filename;
    OFS::OfsPtr& mFile = OgitorsRoot::getSingletonPtr()->GetProjectFile();
    
    if(isGeneralScope)
    {
        filename = OgitorsSystem::getSingletonPtr()->getProjectsDirectory() + "/Templates";
        filename = OgitorsUtils::QualifyPath(filename);
        OgitorsSystem::getSingletonPtr()->MakeDirectory(filename);
    }
    else
    {
        filename = "/Templates";
        mFile->createDirectory(filename.c_str());
    }
    
    
    filename += "/" + templatename + ".otl";

    std::stringstream outfile;
    outfile << "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
    outfile << "<TEMPLATES>\n";
    outfile << "  <OBJECTTEMPLATE name=\"";
    outfile << templatename.c_str();
    outfile << "\">\n";
    Ogre::StringVector list;
    object->getNameList(list);
    outfile << OgitorsUtils::GetObjectSaveStringV2(object, 4, false, false).c_str();

    ObjectTemplateMap::iterator rit;
    if(isGeneralScope)
        rit = mGeneralTemplates.insert(ObjectTemplateMap::value_type(templatename, ObjectTemplate())).first;
    else
        rit = mProjectTemplates.insert(ObjectTemplateMap::value_type(templatename, ObjectTemplate())).first;

    rit->second.push_back(ObjectTemplateData());
    object->getPropertyMap(rit->second[0].mObjectProperties);
    rit->second[0].mObjectProperties.erase(rit->second[0].mObjectProperties.find("object_id"));
    OgitorsCustomPropertySet *tmpset = OGRE_NEW OgitorsCustomPropertySet();
    object->getCustomProperties()->cloneSet(*tmpset);
    rit->second[0].mCustomProperties = tmpset;
    rit->second[0].mTypeName = object->getTypeName();

    for(unsigned int i = 1;i < list.size();i++)
    {
        CBaseEditor *item = OgitorsRoot::getSingletonPtr()->FindObject(list[i]);
        if(item != 0)
        {
            outfile << OgitorsUtils::GetObjectSaveStringV2(item, 4, false, true).c_str();

            rit->second.push_back(ObjectTemplateData());
            int itempos = rit->second.size() - 1;
            item->getPropertyMap(rit->second[itempos].mObjectProperties);
            rit->second[itempos].mObjectProperties.erase(rit->second[itempos].mObjectProperties.find("object_id"));
            OgitorsPropertyValue parentnodevalue;
            parentnodevalue.propType = PROP_STRING;
            parentnodevalue.val = Ogre::Any(item->getParent()->getName());
            rit->second[itempos].mObjectProperties.insert(OgitorsPropertyValueMap::value_type("parentnode", parentnodevalue));
            OgitorsCustomPropertySet *tmpset = OGRE_NEW OgitorsCustomPropertySet();
            item->getCustomProperties()->cloneSet(*tmpset);
            rit->second[itempos].mCustomProperties = tmpset;
            rit->second[itempos].mTypeName = item->getTypeName();
        }
    }
    
    outfile << "  </OBJECTTEMPLATE>\n";
    outfile << "</TEMPLATES>\n";

    if(isGeneralScope)
    {
        std::ofstream out_general(filename.c_str());
        out_general << outfile.str();
        out_general.close();
    }
    else
    {
        OgitorsUtils::SaveStreamOfs(outfile, filename);
    }

    return true;
}