Commits

Andrew Fenn  committed e80c450

Added recursive pasting for Nodes

  • Participants
  • Parent commits d15dca2
  • Branches general_ui

Comments (0)

Files changed (2)

File Ogitor/include/OgitorsClipboardManager.h

         * Index specifies which object from the clipboardbuffer will be pasted
         */
         CBaseEditor *paste(CBaseEditor *parent, int index = -1);
-        
         /**
         * Fetch the names of objects in the clipboard buffer
         * @return stringvector of available objects in clipboard buffer
         ClipboardBuffer     mBuffer;                    /** Clipboard's internal buffer to hold multiple copy operations */
         ObjectTemplateMap   mGeneralTemplates;          /** General Scope Templates */
         ObjectTemplateMap   mProjectTemplates;          /** Project Scope Templates */
+    private:
+        /** Private function for recursively pasting an object */
+        CBaseEditor *pasteRecursive(CBaseEditor* copyParent, CBaseEditor* newParent);
     };
 };

File Ogitor/src/OgitorsClipboardManager.cpp

 void OgitorsClipboardManager::copy(CBaseEditor* object)
 {
     assert(object != 0 && "The object to copy must not be null");
-    
+
     if((mBuffer.size() + 1) > mClipboardMaxSize)
     {
         int count = (mBuffer.size() + 1) - mClipboardMaxSize;
     else
         data = mBuffer[index];
 
-    CBaseEditor* object = OgitorsRoot::getSingletonPtr()->FindObject(data->mObjectName);
-    
+    CBaseEditor* copyObject = OgitorsRoot::getSingletonPtr()->FindObject(data->mObjectName);
+
     OgitorsPropertyValueMap properties = data->mProperties;
-    if(object)
+    if(copyObject)
     {
         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);
+    CBaseEditor* object = OgitorsRoot::getSingletonPtr()->CreateEditorObject(parent, data->mObjectTypeName, properties, true, false);
     if(!object)
         return 0;
 
+    if (copyObject->getEditorType() == ETYPE_NODE)
+    {
+        pasteRecursive(copyObject, object);
+    }
+
     object->getCustomProperties()->initFromSet(data->mCustomProperties);
     object->load();
     OgitorsRoot::getSingletonPtr()->GetSelection()->setSelection(object);
     return object;
 }
 //----------------------------------------------------------------------------------
+CBaseEditor *OgitorsClipboardManager::pasteRecursive(CBaseEditor* copyParent, CBaseEditor* newParent)
+{
+    Ogre::StringVector list;
+    copyParent->getNameList(list);
+
+    ObjectTemplateMap::iterator rit;
+    for(unsigned int i = 1;i < list.size();i++)
+    {
+        CBaseEditor *item = OgitorsRoot::getSingletonPtr()->FindObject(list[i]);
+        if(item == 0)
+            continue;
+
+        OgitorsPropertyValueMap properties;
+        item->getPropertyMap(properties);
+        properties.erase(properties.find("object_id"));
+
+        Ogre::String newname = item->getName() + "Copy";
+        newname += OgitorsRoot::getSingletonPtr()->CreateUniqueID(newname, "", 0);
+        properties["name"].val = Ogre::Any(newname);
+
+        CBaseEditor* object = OgitorsRoot::getSingletonPtr()->CreateEditorObject(newParent, item->getTypeName(), properties, true, false);
+        if(!object)
+            continue;
+
+        object->load();
+
+        if (item->getEditorType() == ETYPE_NODE)
+            pasteRecursive(item, object);
+    }
+
+    return newParent;
+}
+//----------------------------------------------------------------------------------
 bool OgitorsClipboardManager::copyToTemplate(CBaseEditor *object, const Ogre::String& templatename, bool isGeneralScope)
 {
     if(templatename.empty())