add region exporter to menu, fix a crash in region exporter

This commit is contained in:
Hazim Gazov
2010-06-09 02:12:12 -03:00
parent e9f32dcfbe
commit 29ee9f7a08
4 changed files with 314 additions and 302 deletions

View File

@@ -1,256 +1,258 @@
// <edit> // <edit>
#include "llviewerprecompiledheaders.h" #include "llviewerprecompiledheaders.h"
#include "llfloaterexportregion.h" #include "llfloaterexportregion.h"
#include "llfloaterexport.h" #include "llfloaterexport.h"
#include "lluictrlfactory.h" #include "lluictrlfactory.h"
#include "llsdutil.h" #include "llsdutil.h"
#include "llsdserialize.h" #include "llsdserialize.h"
#include "llselectmgr.h" #include "llselectmgr.h"
#include "llscrolllistctrl.h" #include "llscrolllistctrl.h"
#include "llchat.h" #include "llchat.h"
#include "llfloaterchat.h" #include "llfloaterchat.h"
#include "llfilepicker.h" #include "llfilepicker.h"
#include "llagent.h" #include "llagent.h"
#include "llvoavatar.h" #include "llvoavatar.h"
#include "llimportobject.h" #include "llimportobject.h"
#include "llviewerobjectlist.h" #include "llviewerobjectlist.h"
#include "llviewerregion.h" #include "llviewerregion.h"
LLFloaterExportRegion* LLFloaterExportRegion::sInstance = NULL; LLFloaterExportRegion* LLFloaterExportRegion::sInstance = NULL;
LLFloaterExportRegion::LLFloaterExportRegion() LLFloaterExportRegion::LLFloaterExportRegion(const LLSD& unused)
: LLFloater() {
{ sInstance = this;
sInstance = this; LLUICtrlFactory::getInstance()->buildFloater(this, "floater_export.xml");
LLUICtrlFactory::getInstance()->buildFloater(this, "floater_export.xml"); }
}
LLFloaterExportRegion::~LLFloaterExportRegion()
LLFloaterExportRegion::~LLFloaterExportRegion() {
{ sInstance = NULL;
sInstance = NULL; }
}
BOOL LLFloaterExportRegion::postBuild(void)
BOOL LLFloaterExportRegion::postBuild(void) {
{ updateNamesProgress();
updateNamesProgress();
childSetAction("select_all_btn", onClickSelectAll, this);
childSetAction("select_all_btn", onClickSelectAll, this); childSetEnabled("select_objects_btn", FALSE);
childSetEnabled("select_objects_btn", FALSE); childSetEnabled("select_wearables_btn", FALSE);
childSetEnabled("select_wearables_btn", FALSE);
childSetAction("save_as_btn", onClickSaveAs, this);
childSetAction("save_as_btn", onClickSaveAs, this); childSetEnabled("make_copy_btn", FALSE);
childSetEnabled("make_copy_btn", FALSE);
return TRUE;
return TRUE; }
}
//static
//static void LLFloaterExportRegion::onClickSelectAll(void* user_data)
void LLFloaterExportRegion::onClickSelectAll(void* user_data) {
{ LLFloaterExport* floater = (LLFloaterExport*)user_data;
LLFloaterExport* floater = (LLFloaterExport*)user_data; LLScrollListCtrl* list = floater->getChild<LLScrollListCtrl>("export_list");
LLScrollListCtrl* list = floater->getChild<LLScrollListCtrl>("export_list"); std::vector<LLScrollListItem*> items = list->getAllData();
std::vector<LLScrollListItem*> items = list->getAllData(); std::vector<LLScrollListItem*>::iterator item_iter = items.begin();
std::vector<LLScrollListItem*>::iterator item_iter = items.begin(); std::vector<LLScrollListItem*>::iterator items_end = items.end();
std::vector<LLScrollListItem*>::iterator items_end = items.end(); if(items.size())
bool new_value = !((*item_iter)->getColumn(LIST_CHECKED)->getValue()); {
for( ; item_iter != items_end; ++item_iter) bool new_value = !((*item_iter)->getColumn(LIST_CHECKED)->getValue());
{ for( ; item_iter != items_end; ++item_iter)
LLScrollListItem* item = (*item_iter); {
item->getColumn(LIST_CHECKED)->setValue(new_value); LLScrollListItem* item = (*item_iter);
} item->getColumn(LIST_CHECKED)->setValue(new_value);
} }
}
LLSD LLFloaterExportRegion::getLLSD() }
{
LLScrollListCtrl* list = getChild<LLScrollListCtrl>("export_list"); LLSD LLFloaterExportRegion::getLLSD()
std::vector<LLScrollListItem*> items = list->getAllData(); {
LLSD sd; LLScrollListCtrl* list = getChild<LLScrollListCtrl>("export_list");
std::vector<LLScrollListItem*>::iterator item_iter = items.begin(); std::vector<LLScrollListItem*> items = list->getAllData();
std::vector<LLScrollListItem*>::iterator items_end = items.end(); LLSD sd;
for( ; item_iter != items_end; ++item_iter) std::vector<LLScrollListItem*>::iterator item_iter = items.begin();
{ std::vector<LLScrollListItem*>::iterator items_end = items.end();
LLScrollListItem* item = (*item_iter); for( ; item_iter != items_end; ++item_iter)
if(item->getColumn(LIST_CHECKED)->getValue()) {
{ LLScrollListItem* item = (*item_iter);
LLSD item_sd = mExportables[item->getUUID()]; if(item->getColumn(LIST_CHECKED)->getValue())
LLSD::map_iterator map_iter = item_sd.beginMap(); {
LLSD::map_iterator map_end = item_sd.endMap(); LLSD item_sd = mExportables[item->getUUID()];
for( ; map_iter != map_end; ++map_iter) LLSD::map_iterator map_iter = item_sd.beginMap();
{ LLSD::map_iterator map_end = item_sd.endMap();
std::string key((*map_iter).first); for( ; map_iter != map_end; ++map_iter)
LLSD data = (*map_iter).second; {
// copy it... std::string key((*map_iter).first);
sd[key] = data; LLSD data = (*map_iter).second;
} // copy it...
} sd[key] = data;
} }
return sd; }
} }
return sd;
//static }
void LLFloaterExportRegion::onClickSaveAs(void* user_data)
{ //static
LLFloaterExport* floater = (LLFloaterExport*)user_data; void LLFloaterExportRegion::onClickSaveAs(void* user_data)
LLSD sd = floater->getLLSD(); {
LLFloaterExport* floater = (LLFloaterExport*)user_data;
if(sd.size()) LLSD sd = floater->getLLSD();
{
std::string default_filename = "untitled"; if(sd.size())
{
// set correct names within llsd std::string default_filename = "untitled";
LLSD::map_iterator map_iter = sd.beginMap();
LLSD::map_iterator map_end = sd.endMap(); // set correct names within llsd
for( ; map_iter != map_end; ++map_iter) LLSD::map_iterator map_iter = sd.beginMap();
{ LLSD::map_iterator map_end = sd.endMap();
std::istringstream keystr((*map_iter).first); for( ; map_iter != map_end; ++map_iter)
U32 key; {
keystr >> key; std::istringstream keystr((*map_iter).first);
LLSD item = (*map_iter).second; U32 key;
if(item["type"].asString() == "prim") keystr >> key;
{ LLSD item = (*map_iter).second;
std::string name = floater->mPrimNameMap[key]; if(item["type"].asString() == "prim")
item["name"] = name; {
// I don't understand C++ :( std::string name = floater->mPrimNameMap[key];
sd[(*map_iter).first] = item; item["name"] = name;
} // I don't understand C++ :(
} sd[(*map_iter).first] = item;
}
// count the number of selected items }
LLScrollListCtrl* list = floater->getChild<LLScrollListCtrl>("export_list");
std::vector<LLScrollListItem*> items = list->getAllData(); // count the number of selected items
int item_count = 0; LLScrollListCtrl* list = floater->getChild<LLScrollListCtrl>("export_list");
LLUUID avatarid = (*(items.begin()))->getColumn(LIST_AVATARID)->getValue().asUUID(); std::vector<LLScrollListItem*> items = list->getAllData();
bool all_same_avatarid = true; int item_count = 0;
std::vector<LLScrollListItem*>::iterator item_iter = items.begin(); LLUUID avatarid = (*(items.begin()))->getColumn(LIST_AVATARID)->getValue().asUUID();
std::vector<LLScrollListItem*>::iterator items_end = items.end(); bool all_same_avatarid = true;
for( ; item_iter != items_end; ++item_iter) std::vector<LLScrollListItem*>::iterator item_iter = items.begin();
{ std::vector<LLScrollListItem*>::iterator items_end = items.end();
LLScrollListItem* item = (*item_iter); for( ; item_iter != items_end; ++item_iter)
if(item->getColumn(LIST_CHECKED)->getValue()) {
{ LLScrollListItem* item = (*item_iter);
item_count++; if(item->getColumn(LIST_CHECKED)->getValue())
if(item->getColumn(LIST_AVATARID)->getValue().asUUID() != avatarid) {
{ item_count++;
all_same_avatarid = false; if(item->getColumn(LIST_AVATARID)->getValue().asUUID() != avatarid)
} {
} all_same_avatarid = false;
} }
}
if(item_count == 1) }
{
// Exporting one item? Use its name for the filename. if(item_count == 1)
// But make sure it's a root! {
LLSD target = (*(sd.beginMap())).second; // Exporting one item? Use its name for the filename.
if(target.has("parent")) // But make sure it's a root!
{ LLSD target = (*(sd.beginMap())).second;
std::string parentid = target["parent"].asString(); if(target.has("parent"))
target = sd[parentid]; {
} std::string parentid = target["parent"].asString();
if(target.has("name")) target = sd[parentid];
{ }
if(target["name"].asString().length() > 0) if(target.has("name"))
{ {
default_filename = target["name"].asString(); if(target["name"].asString().length() > 0)
} {
} default_filename = target["name"].asString();
} }
else }
{ }
// Multiple items? else
// If they're all part of the same avatar, use the avatar's name as filename. {
if(all_same_avatarid) // Multiple items?
{ // If they're all part of the same avatar, use the avatar's name as filename.
std::string fullname; if(all_same_avatarid)
if(gCacheName->getFullName(avatarid, fullname)) {
{ std::string fullname;
default_filename = fullname; if(gCacheName->getFullName(avatarid, fullname))
} {
} default_filename = fullname;
} }
}
LLFilePicker& file_picker = LLFilePicker::instance(); }
if(file_picker.getSaveFile( LLFilePicker::FFSAVE_XML, LLDir::getScrubbedFileName(default_filename + ".xml")))
{ LLFilePicker& file_picker = LLFilePicker::instance();
std::string file_name = file_picker.getFirstFile(); if(file_picker.getSaveFile( LLFilePicker::FFSAVE_XML, LLDir::getScrubbedFileName(default_filename + ".xml")))
llofstream export_file(file_name); {
LLSDSerialize::toPrettyXML(sd, export_file); std::string file_name = file_picker.getFirstFile();
export_file.close(); llofstream export_file(file_name);
LLSDSerialize::toPrettyXML(sd, export_file);
std::string msg = "Saved "; export_file.close();
msg.append(file_name);
LLChat chat(msg); std::string msg = "Saved ";
LLFloaterChat::addChat(chat); msg.append(file_name);
} LLChat chat(msg);
} LLFloaterChat::addChat(chat);
else }
{ }
std::string msg = "No exportable items selected"; else
LLChat chat(msg); {
LLFloaterChat::addChat(chat); std::string msg = "No exportable items selected";
return; LLChat chat(msg);
} LLFloaterChat::addChat(chat);
return;
floater->close(); }
}
floater->close();
void LLFloaterExportRegion::addToPrimList(LLViewerObject* object) }
{
mPrimList.push_back(object->getLocalID()); void LLFloaterExportRegion::addToPrimList(LLViewerObject* object)
LLViewerObject::child_list_t child_list = object->getChildren(); {
for (LLViewerObject::child_list_t::iterator i = child_list.begin(); i != child_list.end(); ++i) mPrimList.push_back(object->getLocalID());
{ LLViewerObject::child_list_t child_list = object->getChildren();
LLViewerObject* child = *i; for (LLViewerObject::child_list_t::iterator i = child_list.begin(); i != child_list.end(); ++i)
if(child->getPCode() < LL_PCODE_APP) {
{ LLViewerObject* child = *i;
mPrimList.push_back(child->getLocalID()); if(child->getPCode() < LL_PCODE_APP)
} {
} mPrimList.push_back(child->getLocalID());
} }
}
void LLFloaterExportRegion::updateNamesProgress() }
{
childSetText("names_progress_text", llformat("Names retrieved: %d of %d", mPrimNameMap.size(), mPrimList.size())); void LLFloaterExportRegion::updateNamesProgress()
} {
childSetText("names_progress_text", llformat("Names retrieved: %d of %d", mPrimNameMap.size(), mPrimList.size()));
void LLFloaterExportRegion::receivePrimName(LLViewerObject* object, std::string name) }
{
LLUUID fullid = object->getID(); void LLFloaterExportRegion::receivePrimName(LLViewerObject* object, std::string name)
U32 localid = object->getLocalID(); {
if(std::find(mPrimList.begin(), mPrimList.end(), localid) != mPrimList.end()) LLUUID fullid = object->getID();
{ U32 localid = object->getLocalID();
mPrimNameMap[localid] = name; if(std::find(mPrimList.begin(), mPrimList.end(), localid) != mPrimList.end())
LLScrollListCtrl* list = getChild<LLScrollListCtrl>("export_list"); {
S32 item_index = list->getItemIndex(fullid); mPrimNameMap[localid] = name;
if(item_index != -1) LLScrollListCtrl* list = getChild<LLScrollListCtrl>("export_list");
{ S32 item_index = list->getItemIndex(fullid);
std::vector<LLScrollListItem*> items = list->getAllData(); if(item_index != -1)
std::vector<LLScrollListItem*>::iterator iter = items.begin(); {
std::vector<LLScrollListItem*>::iterator end = items.end(); std::vector<LLScrollListItem*> items = list->getAllData();
for( ; iter != end; ++iter) std::vector<LLScrollListItem*>::iterator iter = items.begin();
{ std::vector<LLScrollListItem*>::iterator end = items.end();
if((*iter)->getUUID() == fullid) for( ; iter != end; ++iter)
{ {
(*iter)->getColumn(LIST_NAME)->setValue(name + " (worn on " + utf8str_tolower(object->getAttachmentPointName()) + ")"); if((*iter)->getUUID() == fullid)
break; {
} (*iter)->getColumn(LIST_NAME)->setValue(name + " (worn on " + utf8str_tolower(object->getAttachmentPointName()) + ")");
} break;
} }
updateNamesProgress(); }
} }
} updateNamesProgress();
}
// static }
void LLFloaterExportRegion::receiveObjectProperties(LLUUID fullid, std::string name, std::string desc)
{ // static
LLViewerObject* object = gObjectList.findObject(fullid); void LLFloaterExportRegion::receiveObjectProperties(LLUUID fullid, std::string name, std::string desc)
std::vector<LLFloaterExport*>::iterator iter = LLFloaterExport::instances.begin(); {
std::vector<LLFloaterExport*>::iterator end = LLFloaterExport::instances.end(); LLViewerObject* object = gObjectList.findObject(fullid);
for( ; iter != end; ++iter) std::vector<LLFloaterExport*>::iterator iter = LLFloaterExport::instances.begin();
{ std::vector<LLFloaterExport*>::iterator end = LLFloaterExport::instances.end();
(*iter)->receivePrimName(object, name); for( ; iter != end; ++iter)
} {
} (*iter)->receivePrimName(object, name);
}
// </edit> }
// </edit>

View File

@@ -1,46 +1,47 @@
// <edit> // <edit>
#ifndef LL_LLFLOATEREXPORTREGION_H #ifndef LL_LLFLOATEREXPORTREGION_H
#define LL_LLFLOATEREXPORTREGION_H #define LL_LLFLOATEREXPORTREGION_H
#include "llfloater.h" #include "llfloater.h"
#include "llselectmgr.h" #include "llselectmgr.h"
#include "llvoavatar.h" #include "llvoavatar.h"
class LLFloaterExportRegion class LLFloaterExportRegion
: public LLFloater : public LLFloater, public LLFloaterSingleton<LLFloaterExportRegion>
{ {
public: friend class LLUISingleton<LLFloaterExportRegion, VisibilityPolicy<LLFloater> >;
LLFloaterExportRegion(); public:
BOOL postBuild(void); LLFloaterExportRegion(const LLSD& unused);
void updateNamesProgress(); BOOL postBuild(void);
void receivePrimName(LLViewerObject* object, std::string name); void updateNamesProgress();
void receivePrimName(LLViewerObject* object, std::string name);
LLSD getLLSD();
LLSD getLLSD();
std::vector<U32> mPrimList;
std::map<U32, std::string> mPrimNameMap; std::vector<U32> mPrimList;
std::map<U32, std::string> mPrimNameMap;
static LLFloaterExportRegion* sInstance;
static LLFloaterExportRegion* sInstance;
static void receiveObjectProperties(LLUUID fullid, std::string name, std::string desc);
static void receiveObjectProperties(LLUUID fullid, std::string name, std::string desc);
static void onClickSelectAll(void* user_data);
static void onClickSaveAs(void* user_data); static void onClickSelectAll(void* user_data);
static void onClickSaveAs(void* user_data);
private:
virtual ~LLFloaterExportRegion(); private:
void addToPrimList(LLViewerObject* object); virtual ~LLFloaterExportRegion();
void addToPrimList(LLViewerObject* object);
enum LIST_COLUMN_ORDER
{ enum LIST_COLUMN_ORDER
LIST_CHECKED, {
LIST_TYPE, LIST_CHECKED,
LIST_NAME, LIST_TYPE,
LIST_AVATARID LIST_NAME,
}; LIST_AVATARID
};
std::map<LLUUID, LLSD> mExportables;
}; std::map<LLUUID, LLSD> mExportables;
};
#endif
// </edit> #endif
// </edit>

View File

@@ -233,6 +233,7 @@
#include "hgfloatertexteditor.h" #include "hgfloatertexteditor.h"
#include "llfloatermessagelog.h" #include "llfloatermessagelog.h"
#include "llfloatermessagebuilder.h" #include "llfloatermessagebuilder.h"
#include "llfloaterexportregion.h"
// </edit> // </edit>
using namespace LLVOAvatarDefines; using namespace LLVOAvatarDefines;
@@ -5631,6 +5632,10 @@ class LLShowFloater : public view_listener_t
{ {
JCFloaterAreaSearch::toggle(); JCFloaterAreaSearch::toggle();
} }
else if (floater_name == "export region")
{
LLFloaterExportRegion::toggleInstance(LLSD());
}
else if (floater_name == "grid options") else if (floater_name == "grid options")
{ {
LLFloaterBuildOptions::show(NULL); LLFloaterBuildOptions::show(NULL);

View File

@@ -539,6 +539,10 @@
mouse_opaque="true" name="Region/Estate..." width="185"> mouse_opaque="true" name="Region/Estate..." width="185">
<on_click function="ShowFloater" userdata="about region" /> <on_click function="ShowFloater" userdata="about region" />
</menu_item_call> </menu_item_call>
<menu_item_call bottom="-308" enabled="true" height="19" label="Export Region" left="0"
mouse_opaque="true" name="Export Region" width="185">
<on_click function="ShowFloater" userdata="export region" />
</menu_item_call>
<menu_item_separator bottom="-316" enabled="true" height="8" label="-----------" left="0" <menu_item_separator bottom="-316" enabled="true" height="8" label="-----------" left="0"
mouse_opaque="true" name="separator6" width="185" /> mouse_opaque="true" name="separator6" width="185" />
<menu bottom="-554" create_jump_keys="true" drop_shadow="true" enabled="true" <menu bottom="-554" create_jump_keys="true" drop_shadow="true" enabled="true"