/indra/newview/llfloaterobjectweights.cpp
C++ | 266 lines | 186 code | 44 blank | 36 comment | 12 complexity | 69e2a95396973e37e7df47c29648615b MD5 | raw file
Possible License(s): LGPL-2.1
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 28#include "llfloaterobjectweights.h" 29 30#include "llparcel.h" 31 32#include "llfloaterreg.h" 33#include "lltextbox.h" 34 35#include "llagent.h" 36#include "llviewerparcelmgr.h" 37#include "llviewerregion.h" 38 39// virtual 40bool LLCrossParcelFunctor::apply(LLViewerObject* obj) 41{ 42 // Add the root object box. 43 mBoundingBox.addBBoxAgent(LLBBox(obj->getPositionRegion(), obj->getRotationRegion(), obj->getScale() * -0.5f, obj->getScale() * 0.5f).getAxisAligned()); 44 45 // Extend the bounding box across all the children. 46 LLViewerObject::const_child_list_t children = obj->getChildren(); 47 for (LLViewerObject::const_child_list_t::const_iterator iter = children.begin(); 48 iter != children.end(); iter++) 49 { 50 LLViewerObject* child = *iter; 51 mBoundingBox.addBBoxAgent(LLBBox(child->getPositionRegion(), child->getRotationRegion(), child->getScale() * -0.5f, child->getScale() * 0.5f).getAxisAligned()); 52 } 53 54 bool result = false; 55 56 LLViewerRegion* region = obj->getRegion(); 57 if (region) 58 { 59 std::vector<LLBBox> boxes; 60 boxes.push_back(mBoundingBox); 61 result = region->objectsCrossParcel(boxes); 62 } 63 64 return result; 65} 66 67LLFloaterObjectWeights::LLFloaterObjectWeights(const LLSD& key) 68: LLFloater(key), 69 mSelectedObjects(NULL), 70 mSelectedPrims(NULL), 71 mSelectedDownloadWeight(NULL), 72 mSelectedPhysicsWeight(NULL), 73 mSelectedServerWeight(NULL), 74 mSelectedDisplayWeight(NULL), 75 mSelectedOnLand(NULL), 76 mRezzedOnLand(NULL), 77 mRemainingCapacity(NULL), 78 mTotalCapacity(NULL) 79{ 80} 81 82LLFloaterObjectWeights::~LLFloaterObjectWeights() 83{ 84} 85 86// virtual 87BOOL LLFloaterObjectWeights::postBuild() 88{ 89 mSelectedObjects = getChild<LLTextBox>("objects"); 90 mSelectedPrims = getChild<LLTextBox>("prims"); 91 92 mSelectedDownloadWeight = getChild<LLTextBox>("download"); 93 mSelectedPhysicsWeight = getChild<LLTextBox>("physics"); 94 mSelectedServerWeight = getChild<LLTextBox>("server"); 95 mSelectedDisplayWeight = getChild<LLTextBox>("display"); 96 97 mSelectedOnLand = getChild<LLTextBox>("selected"); 98 mRezzedOnLand = getChild<LLTextBox>("rezzed_on_land"); 99 mRemainingCapacity = getChild<LLTextBox>("remaining_capacity"); 100 mTotalCapacity = getChild<LLTextBox>("total_capacity"); 101 102 return TRUE; 103} 104 105// virtual 106void LLFloaterObjectWeights::onOpen(const LLSD& key) 107{ 108 refresh(); 109 updateLandImpacts(LLViewerParcelMgr::getInstance()->getFloatingParcelSelection()->getParcel()); 110} 111 112// virtual 113void LLFloaterObjectWeights::onWeightsUpdate(const SelectionCost& selection_cost) 114{ 115 mSelectedDownloadWeight->setText(llformat("%.1f", selection_cost.mNetworkCost)); 116 mSelectedPhysicsWeight->setText(llformat("%.1f", selection_cost.mPhysicsCost)); 117 mSelectedServerWeight->setText(llformat("%.1f", selection_cost.mSimulationCost)); 118 119 S32 render_cost = LLSelectMgr::getInstance()->getSelection()->getSelectedObjectRenderCost(); 120 mSelectedDisplayWeight->setText(llformat("%d", render_cost)); 121 122 toggleWeightsLoadingIndicators(false); 123} 124 125//virtual 126void LLFloaterObjectWeights::setErrorStatus(U32 status, const std::string& reason) 127{ 128 const std::string text = getString("nothing_selected"); 129 130 mSelectedDownloadWeight->setText(text); 131 mSelectedPhysicsWeight->setText(text); 132 mSelectedServerWeight->setText(text); 133 mSelectedDisplayWeight->setText(text); 134 135 toggleWeightsLoadingIndicators(false); 136} 137 138void LLFloaterObjectWeights::updateLandImpacts(const LLParcel* parcel) 139{ 140 if (!parcel || LLSelectMgr::getInstance()->getSelection()->isEmpty()) 141 { 142 updateIfNothingSelected(); 143 } 144 else 145 { 146 S32 rezzed_prims = parcel->getSimWidePrimCount(); 147 S32 total_capacity = parcel->getSimWideMaxPrimCapacity(); 148 149 mRezzedOnLand->setText(llformat("%d", rezzed_prims)); 150 mRemainingCapacity->setText(llformat("%d", total_capacity - rezzed_prims)); 151 mTotalCapacity->setText(llformat("%d", total_capacity)); 152 153 toggleLandImpactsLoadingIndicators(false); 154 } 155} 156 157void LLFloaterObjectWeights::refresh() 158{ 159 LLSelectMgr* sel_mgr = LLSelectMgr::getInstance(); 160 161 if (sel_mgr->getSelection()->isEmpty()) 162 { 163 updateIfNothingSelected(); 164 } 165 else 166 { 167 S32 prim_count = sel_mgr->getSelection()->getObjectCount(); 168 S32 link_count = sel_mgr->getSelection()->getRootObjectCount(); 169 F32 prim_equiv = sel_mgr->getSelection()->getSelectedLinksetCost(); 170 171 mSelectedObjects->setText(llformat("%d", link_count)); 172 mSelectedPrims->setText(llformat("%d", prim_count)); 173 mSelectedOnLand->setText(llformat("%.1d", (S32)prim_equiv)); 174 175 LLCrossParcelFunctor func; 176 if (sel_mgr->getSelection()->applyToRootObjects(&func, true)) 177 { 178 // Some of the selected objects cross parcel bounds. 179 // We don't display object weights and land impacts in this case. 180 const std::string text = getString("nothing_selected"); 181 182 mRezzedOnLand->setText(text); 183 mRemainingCapacity->setText(text); 184 mTotalCapacity->setText(text); 185 186 toggleLandImpactsLoadingIndicators(false); 187 } 188 189 LLViewerRegion* region = gAgent.getRegion(); 190 if (region && region->capabilitiesReceived()) 191 { 192 for (LLObjectSelection::valid_root_iterator iter = sel_mgr->getSelection()->valid_root_begin(); 193 iter != sel_mgr->getSelection()->valid_root_end(); ++iter) 194 { 195 LLAccountingCostManager::getInstance()->addObject((*iter)->getObject()->getID()); 196 } 197 198 std::string url = region->getCapability("ResourceCostSelected"); 199 if (!url.empty()) 200 { 201 // Update the transaction id before the new fetch request 202 generateTransactionID(); 203 204 LLAccountingCostManager::getInstance()->fetchCosts(Roots, url, getObserverHandle()); 205 toggleWeightsLoadingIndicators(true); 206 } 207 } 208 else 209 { 210 llwarns << "Failed to get region capabilities" << llendl; 211 } 212 } 213} 214 215// virtual 216void LLFloaterObjectWeights::generateTransactionID() 217{ 218 mTransactionID.generate(); 219} 220 221void LLFloaterObjectWeights::toggleWeightsLoadingIndicators(bool visible) 222{ 223 childSetVisible("download_loading_indicator", visible); 224 childSetVisible("physics_loading_indicator", visible); 225 childSetVisible("server_loading_indicator", visible); 226 childSetVisible("display_loading_indicator", visible); 227 228 mSelectedDownloadWeight->setVisible(!visible); 229 mSelectedPhysicsWeight->setVisible(!visible); 230 mSelectedServerWeight->setVisible(!visible); 231 mSelectedDisplayWeight->setVisible(!visible); 232} 233 234void LLFloaterObjectWeights::toggleLandImpactsLoadingIndicators(bool visible) 235{ 236 childSetVisible("selected_loading_indicator", visible); 237 childSetVisible("rezzed_on_land_loading_indicator", visible); 238 childSetVisible("remaining_capacity_loading_indicator", visible); 239 childSetVisible("total_capacity_loading_indicator", visible); 240 241 mSelectedOnLand->setVisible(!visible); 242 mRezzedOnLand->setVisible(!visible); 243 mRemainingCapacity->setVisible(!visible); 244 mTotalCapacity->setVisible(!visible); 245} 246 247void LLFloaterObjectWeights::updateIfNothingSelected() 248{ 249 const std::string text = getString("nothing_selected"); 250 251 mSelectedObjects->setText(text); 252 mSelectedPrims->setText(text); 253 254 mSelectedDownloadWeight->setText(text); 255 mSelectedPhysicsWeight->setText(text); 256 mSelectedServerWeight->setText(text); 257 mSelectedDisplayWeight->setText(text); 258 259 mSelectedOnLand->setText(text); 260 mRezzedOnLand->setText(text); 261 mRemainingCapacity->setText(text); 262 mTotalCapacity->setText(text); 263 264 toggleWeightsLoadingIndicators(false); 265 toggleLandImpactsLoadingIndicators(false); 266}