/indra/newview/llfloaterobjectweights.cpp

https://bitbucket.org/lindenlab/viewer-beta/ · C++ · 266 lines · 186 code · 44 blank · 36 comment · 12 complexity · 69e2a95396973e37e7df47c29648615b MD5 · raw file

  1. /**
  2. * @file llfloaterobjectweights.cpp
  3. * @brief Object weights advanced view floater
  4. *
  5. * $LicenseInfo:firstyear=2011&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2011, Linden Research, Inc.
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation;
  12. * version 2.1 of the License only.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. *
  23. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  24. * $/LicenseInfo$
  25. */
  26. #include "llviewerprecompiledheaders.h"
  27. #include "llfloaterobjectweights.h"
  28. #include "llparcel.h"
  29. #include "llfloaterreg.h"
  30. #include "lltextbox.h"
  31. #include "llagent.h"
  32. #include "llviewerparcelmgr.h"
  33. #include "llviewerregion.h"
  34. // virtual
  35. bool LLCrossParcelFunctor::apply(LLViewerObject* obj)
  36. {
  37. // Add the root object box.
  38. mBoundingBox.addBBoxAgent(LLBBox(obj->getPositionRegion(), obj->getRotationRegion(), obj->getScale() * -0.5f, obj->getScale() * 0.5f).getAxisAligned());
  39. // Extend the bounding box across all the children.
  40. LLViewerObject::const_child_list_t children = obj->getChildren();
  41. for (LLViewerObject::const_child_list_t::const_iterator iter = children.begin();
  42. iter != children.end(); iter++)
  43. {
  44. LLViewerObject* child = *iter;
  45. mBoundingBox.addBBoxAgent(LLBBox(child->getPositionRegion(), child->getRotationRegion(), child->getScale() * -0.5f, child->getScale() * 0.5f).getAxisAligned());
  46. }
  47. bool result = false;
  48. LLViewerRegion* region = obj->getRegion();
  49. if (region)
  50. {
  51. std::vector<LLBBox> boxes;
  52. boxes.push_back(mBoundingBox);
  53. result = region->objectsCrossParcel(boxes);
  54. }
  55. return result;
  56. }
  57. LLFloaterObjectWeights::LLFloaterObjectWeights(const LLSD& key)
  58. : LLFloater(key),
  59. mSelectedObjects(NULL),
  60. mSelectedPrims(NULL),
  61. mSelectedDownloadWeight(NULL),
  62. mSelectedPhysicsWeight(NULL),
  63. mSelectedServerWeight(NULL),
  64. mSelectedDisplayWeight(NULL),
  65. mSelectedOnLand(NULL),
  66. mRezzedOnLand(NULL),
  67. mRemainingCapacity(NULL),
  68. mTotalCapacity(NULL)
  69. {
  70. }
  71. LLFloaterObjectWeights::~LLFloaterObjectWeights()
  72. {
  73. }
  74. // virtual
  75. BOOL LLFloaterObjectWeights::postBuild()
  76. {
  77. mSelectedObjects = getChild<LLTextBox>("objects");
  78. mSelectedPrims = getChild<LLTextBox>("prims");
  79. mSelectedDownloadWeight = getChild<LLTextBox>("download");
  80. mSelectedPhysicsWeight = getChild<LLTextBox>("physics");
  81. mSelectedServerWeight = getChild<LLTextBox>("server");
  82. mSelectedDisplayWeight = getChild<LLTextBox>("display");
  83. mSelectedOnLand = getChild<LLTextBox>("selected");
  84. mRezzedOnLand = getChild<LLTextBox>("rezzed_on_land");
  85. mRemainingCapacity = getChild<LLTextBox>("remaining_capacity");
  86. mTotalCapacity = getChild<LLTextBox>("total_capacity");
  87. return TRUE;
  88. }
  89. // virtual
  90. void LLFloaterObjectWeights::onOpen(const LLSD& key)
  91. {
  92. refresh();
  93. updateLandImpacts(LLViewerParcelMgr::getInstance()->getFloatingParcelSelection()->getParcel());
  94. }
  95. // virtual
  96. void LLFloaterObjectWeights::onWeightsUpdate(const SelectionCost& selection_cost)
  97. {
  98. mSelectedDownloadWeight->setText(llformat("%.1f", selection_cost.mNetworkCost));
  99. mSelectedPhysicsWeight->setText(llformat("%.1f", selection_cost.mPhysicsCost));
  100. mSelectedServerWeight->setText(llformat("%.1f", selection_cost.mSimulationCost));
  101. S32 render_cost = LLSelectMgr::getInstance()->getSelection()->getSelectedObjectRenderCost();
  102. mSelectedDisplayWeight->setText(llformat("%d", render_cost));
  103. toggleWeightsLoadingIndicators(false);
  104. }
  105. //virtual
  106. void LLFloaterObjectWeights::setErrorStatus(U32 status, const std::string& reason)
  107. {
  108. const std::string text = getString("nothing_selected");
  109. mSelectedDownloadWeight->setText(text);
  110. mSelectedPhysicsWeight->setText(text);
  111. mSelectedServerWeight->setText(text);
  112. mSelectedDisplayWeight->setText(text);
  113. toggleWeightsLoadingIndicators(false);
  114. }
  115. void LLFloaterObjectWeights::updateLandImpacts(const LLParcel* parcel)
  116. {
  117. if (!parcel || LLSelectMgr::getInstance()->getSelection()->isEmpty())
  118. {
  119. updateIfNothingSelected();
  120. }
  121. else
  122. {
  123. S32 rezzed_prims = parcel->getSimWidePrimCount();
  124. S32 total_capacity = parcel->getSimWideMaxPrimCapacity();
  125. mRezzedOnLand->setText(llformat("%d", rezzed_prims));
  126. mRemainingCapacity->setText(llformat("%d", total_capacity - rezzed_prims));
  127. mTotalCapacity->setText(llformat("%d", total_capacity));
  128. toggleLandImpactsLoadingIndicators(false);
  129. }
  130. }
  131. void LLFloaterObjectWeights::refresh()
  132. {
  133. LLSelectMgr* sel_mgr = LLSelectMgr::getInstance();
  134. if (sel_mgr->getSelection()->isEmpty())
  135. {
  136. updateIfNothingSelected();
  137. }
  138. else
  139. {
  140. S32 prim_count = sel_mgr->getSelection()->getObjectCount();
  141. S32 link_count = sel_mgr->getSelection()->getRootObjectCount();
  142. F32 prim_equiv = sel_mgr->getSelection()->getSelectedLinksetCost();
  143. mSelectedObjects->setText(llformat("%d", link_count));
  144. mSelectedPrims->setText(llformat("%d", prim_count));
  145. mSelectedOnLand->setText(llformat("%.1d", (S32)prim_equiv));
  146. LLCrossParcelFunctor func;
  147. if (sel_mgr->getSelection()->applyToRootObjects(&func, true))
  148. {
  149. // Some of the selected objects cross parcel bounds.
  150. // We don't display object weights and land impacts in this case.
  151. const std::string text = getString("nothing_selected");
  152. mRezzedOnLand->setText(text);
  153. mRemainingCapacity->setText(text);
  154. mTotalCapacity->setText(text);
  155. toggleLandImpactsLoadingIndicators(false);
  156. }
  157. LLViewerRegion* region = gAgent.getRegion();
  158. if (region && region->capabilitiesReceived())
  159. {
  160. for (LLObjectSelection::valid_root_iterator iter = sel_mgr->getSelection()->valid_root_begin();
  161. iter != sel_mgr->getSelection()->valid_root_end(); ++iter)
  162. {
  163. LLAccountingCostManager::getInstance()->addObject((*iter)->getObject()->getID());
  164. }
  165. std::string url = region->getCapability("ResourceCostSelected");
  166. if (!url.empty())
  167. {
  168. // Update the transaction id before the new fetch request
  169. generateTransactionID();
  170. LLAccountingCostManager::getInstance()->fetchCosts(Roots, url, getObserverHandle());
  171. toggleWeightsLoadingIndicators(true);
  172. }
  173. }
  174. else
  175. {
  176. llwarns << "Failed to get region capabilities" << llendl;
  177. }
  178. }
  179. }
  180. // virtual
  181. void LLFloaterObjectWeights::generateTransactionID()
  182. {
  183. mTransactionID.generate();
  184. }
  185. void LLFloaterObjectWeights::toggleWeightsLoadingIndicators(bool visible)
  186. {
  187. childSetVisible("download_loading_indicator", visible);
  188. childSetVisible("physics_loading_indicator", visible);
  189. childSetVisible("server_loading_indicator", visible);
  190. childSetVisible("display_loading_indicator", visible);
  191. mSelectedDownloadWeight->setVisible(!visible);
  192. mSelectedPhysicsWeight->setVisible(!visible);
  193. mSelectedServerWeight->setVisible(!visible);
  194. mSelectedDisplayWeight->setVisible(!visible);
  195. }
  196. void LLFloaterObjectWeights::toggleLandImpactsLoadingIndicators(bool visible)
  197. {
  198. childSetVisible("selected_loading_indicator", visible);
  199. childSetVisible("rezzed_on_land_loading_indicator", visible);
  200. childSetVisible("remaining_capacity_loading_indicator", visible);
  201. childSetVisible("total_capacity_loading_indicator", visible);
  202. mSelectedOnLand->setVisible(!visible);
  203. mRezzedOnLand->setVisible(!visible);
  204. mRemainingCapacity->setVisible(!visible);
  205. mTotalCapacity->setVisible(!visible);
  206. }
  207. void LLFloaterObjectWeights::updateIfNothingSelected()
  208. {
  209. const std::string text = getString("nothing_selected");
  210. mSelectedObjects->setText(text);
  211. mSelectedPrims->setText(text);
  212. mSelectedDownloadWeight->setText(text);
  213. mSelectedPhysicsWeight->setText(text);
  214. mSelectedServerWeight->setText(text);
  215. mSelectedDisplayWeight->setText(text);
  216. mSelectedOnLand->setText(text);
  217. mRezzedOnLand->setText(text);
  218. mRemainingCapacity->setText(text);
  219. mTotalCapacity->setText(text);
  220. toggleWeightsLoadingIndicators(false);
  221. toggleLandImpactsLoadingIndicators(false);
  222. }