Exemplo n.º 1
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.º 2
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.º 3
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.º 4
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;
}