//-------------------------------------------------------------------------------- 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 PortalEditor::connectNearPortals(bool bAllowMove) { //compare this portal with others in the scene //NameObjectPairList portalList = OgitorsRoot::getSingletonPtr()->GetObjectsByType(this->getTypeID()); NameObjectPairList portalList = OgitorsRoot::getSingletonPtr()->GetObjectsByTypeName("MZ Portal"); NameObjectPairList::iterator itr; //check current connection if(mConnected) { Ogre::Real d = mConnected->getDerivedPosition().distance(this->getDerivedPosition()); if(d>=1.0f) { //break connection mConnected->connect(0); this->connect(0); } } for(itr=portalList.begin();itr!=portalList.end();++itr ) { PortalEditor* that = dynamic_cast<PortalEditor*>((*itr).second); //check its not in the same Zone unsigned int id1 = that->getParent()->getObjectID(); unsigned int id2 = (this->getParent()->getObjectID()); //if((*itr).second->getParent()->getObjectID()!=this->getParent()->getObjectID()) if(id1!=id2) { //check the portals match if(that->getHeight()==this->getHeight()&&that->getWidth()==this->getWidth()) { //check portal proximity Ogre::Real d = that->getDerivedPosition().distance(this->getDerivedPosition()); if(d<1.0f) { if(this->snapTpPortal(that,bAllowMove)) { //join the portals,set lock this->connect(that); that->connect(this); return true; } } } //TODO: else{/*check h vs w and rotate 90deg if matches*/} } } if(mPortalOutline) mPortalOutline->setPortalState(PortalOutlineRenderable::PS_FREE); return false; }
//-------------------------------------------------------------------------------- void CMultiSelEditor::add(const NameObjectPairList& newselection) { if(mDeletionInProgress) return; NameObjectPairList::const_iterator it = newselection.begin(); while(it != newselection.end()) { if(it->second && (it->second != this) && (mSelectedObjects.find(it->first) == mSelectedObjects.end())) { mSelectedObjects.insert(NameObjectPairList::value_type(it->first, it->second)); it->second->setSelected(true); } it++; } _createModifyList(); }
//-------------------------------------------------------------------------------- void CMultiSelEditor::remove(const NameObjectPairList& newselection) { if(mDeletionInProgress) return; NameObjectPairList::const_iterator it = newselection.begin(); NameObjectPairList::iterator dit; while(it != newselection.end()) { if(it->second && ((dit = mSelectedObjects.find(it->first)) != mSelectedObjects.end())) { mSelectedObjects.erase(dit); it->second->setSelected(false); } it++; } _createModifyList(); }
//---------------------------------------------------------------------------------------- int CDotSceneSerializer::Export(bool SaveAs, Ogre::String exportfile) { OgitorsRoot *ogRoot = OgitorsRoot::getSingletonPtr(); OgitorsSystem *mSystem = OgitorsSystem::getSingletonPtr(); PROJECTOPTIONS *pOpt = ogRoot->GetProjectOptions(); Ogre::String fileName = pOpt->ProjectName; UTFStringVector extlist; extlist.push_back(OTR("DotScene File")); extlist.push_back("*.scene"); extlist.push_back(OTR("DotScene File")); extlist.push_back("*.xml"); fileName = mSystem->DisplaySaveDialog(OTR("Export DotScene File"),extlist); if(fileName == "") return SCF_CANCEL; Ogre::String newDir = OgitorsUtils::ExtractFilePath(fileName); extractOFS(newDir); mSystem->DeleteFile(newDir + "/" + pOpt->ProjectName + ".ogscene"); TiXmlDocument *pXMLDoc = new TiXmlDocument(); pXMLDoc->InsertEndChild(TiXmlDeclaration("1.0", "UTF-8", "")); pXMLDoc->InsertEndChild(TiXmlElement("scene")); // export basic info TiXmlElement *pRoot = pXMLDoc->RootElement(); pRoot->SetAttribute("formatVersion", "1.0.0"); pRoot->SetAttribute("generator", Ogre::String(Ogre::String("Ogitor SceneBuilder ") + Ogre::String(OGITOR_VERSION)).c_str()); // export resource locations TiXmlElement *pResourceLocations = pRoot->InsertEndChild(TiXmlElement("resourceLocations"))->ToElement(); for(unsigned int r = 0; r < pOpt->ResourceDirectories.size(); r++) { TiXmlElement *pResourceLocation = pResourceLocations->InsertEndChild(TiXmlElement("resourceLocation"))->ToElement(); Ogre::String loc = pOpt->ResourceDirectories[r]; pResourceLocation->SetAttribute("type", "FileSystem"); std::replace(loc.begin(),loc.end(),'\\','/'); if(loc[0] != '.') loc = "./" + loc; pResourceLocation->SetAttribute("name", loc.c_str()); } //TODO: do we need all those object id's ? TiXmlElement *pEnvironment = pRoot->InsertEndChild(TiXmlElement("environment"))->ToElement(); // export octree scenemanagers NameObjectPairList smList = ogRoot->GetObjectsByTypeName("OctreeSceneManager"); NameObjectPairList::const_iterator smIt = smList.begin(); while(smIt != smList.end()) { TiXmlElement *result = smIt->second->exportDotScene(pEnvironment); saveUserData(smIt->second->getCustomProperties(), result); smIt++; } // export viewports NameObjectPairList vpList = ogRoot->GetObjectsByTypeName("Viewport Object"); NameObjectPairList::const_iterator vpIt = vpList.begin(); while(vpIt != vpList.end()) { TiXmlElement *result = vpIt->second->exportDotScene(pEnvironment); saveUserData(vpIt->second->getCustomProperties(), result); vpIt++; } // export terrains NameObjectPairList terrainList = ogRoot->GetObjectsByType(ETYPE_TERRAIN_MANAGER); NameObjectPairList::const_iterator tlIt = terrainList.begin(); while(tlIt != terrainList.end()) { TiXmlElement *result = tlIt->second->exportDotScene(pRoot); saveUserData(tlIt->second->getCustomProperties(), result); tlIt++; } NameObjectPairList items = ogRoot->GetSceneManagerEditor()->getChildren(); // export lights NameObjectPairList::const_iterator nodeIt = items.begin(); while(nodeIt != items.end()) { if(nodeIt->second->getEditorType() == ETYPE_LIGHT) { TiXmlElement *result = nodeIt->second->exportDotScene(pRoot); saveUserData(nodeIt->second->getCustomProperties(), result); } nodeIt++; } // export cameras nodeIt = items.begin(); while(nodeIt != items.end()) { if(nodeIt->second->getEditorType() == ETYPE_CAMERA) { TiXmlElement *result = nodeIt->second->exportDotScene(pRoot); saveUserData(nodeIt->second->getCustomProperties(), result); } nodeIt++; } // export nodes TiXmlElement *pNodes = pRoot->InsertEndChild(TiXmlElement("nodes"))->ToElement(); nodeIt = items.begin(); while(nodeIt != items.end()) { if( nodeIt->second->getEditorType() != ETYPE_TERRAIN_MANAGER && nodeIt->second->getEditorType() != ETYPE_LIGHT && nodeIt->second->getEditorType() != ETYPE_CAMERA ) { TiXmlElement *result = nodeIt->second->exportDotScene(pNodes); saveUserData(nodeIt->second->getCustomProperties(), result); } nodeIt++; } if (pXMLDoc->SaveFile(fileName.c_str())) { OgitorsSystem::getSingletonPtr()->DisplayMessageDialog(OTR("Scene has been exported succesfully"), DLGTYPE_OK); delete pXMLDoc; } else OgitorsSystem::getSingletonPtr()->DisplayMessageDialog(OTR("An error occured during export.. :("), DLGTYPE_OK); return SCF_OK; }
//---------------------------------------------------------------------------------- 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; }