Exemplo n.º 1
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;
}
//----------------------------------------------------------------------------------
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;
}