PageRenderTime 58ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 1ms

/indra/newview/llselectmgr.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 2415 lines | 1817 code | 300 blank | 298 comment | 264 complexity | ca67b7068cb2644ccd7bc23e3c748406 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llselectmgr.cpp
  3. * @brief A manager for selected objects and faces.
  4. *
  5. * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2010, 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. // file include
  28. #define LLSELECTMGR_CPP
  29. #include "llselectmgr.h"
  30. // library includes
  31. #include "llcachename.h"
  32. #include "lldbstrings.h"
  33. #include "lleconomy.h"
  34. #include "llgl.h"
  35. #include "llmediaentry.h"
  36. #include "llrender.h"
  37. #include "llnotifications.h"
  38. #include "llpermissions.h"
  39. #include "llpermissionsflags.h"
  40. #include "lltrans.h"
  41. #include "llundo.h"
  42. #include "lluuid.h"
  43. #include "llvolume.h"
  44. #include "message.h"
  45. #include "object_flags.h"
  46. #include "llquaternion.h"
  47. // viewer includes
  48. #include "llagent.h"
  49. #include "llagentcamera.h"
  50. #include "llviewerwindow.h"
  51. #include "lldrawable.h"
  52. #include "llfloaterinspect.h"
  53. #include "llfloaterproperties.h"
  54. #include "llfloaterreporter.h"
  55. #include "llfloaterreg.h"
  56. #include "llfloatertools.h"
  57. #include "llframetimer.h"
  58. #include "llfocusmgr.h"
  59. #include "llhudeffecttrail.h"
  60. #include "llhudmanager.h"
  61. #include "llinventorymodel.h"
  62. #include "llmenugl.h"
  63. #include "llmeshrepository.h"
  64. #include "llmutelist.h"
  65. #include "llnotificationsutil.h"
  66. #include "llsidepaneltaskinfo.h"
  67. #include "llslurl.h"
  68. #include "llstatusbar.h"
  69. #include "llsurface.h"
  70. #include "lltool.h"
  71. #include "lltooldraganddrop.h"
  72. #include "lltoolmgr.h"
  73. #include "lltoolpie.h"
  74. #include "llui.h"
  75. #include "llviewercamera.h"
  76. #include "llviewercontrol.h"
  77. #include "llviewertexturelist.h"
  78. #include "llviewermedia.h"
  79. #include "llviewermediafocus.h"
  80. #include "llviewermenu.h"
  81. #include "llviewerobject.h"
  82. #include "llviewerobjectlist.h"
  83. #include "llviewerregion.h"
  84. #include "llviewerstats.h"
  85. #include "llvoavatarself.h"
  86. #include "llvovolume.h"
  87. #include "pipeline.h"
  88. #include "llviewershadermgr.h"
  89. #include "llglheaders.h"
  90. LLViewerObject* getSelectedParentObject(LLViewerObject *object) ;
  91. //
  92. // Consts
  93. //
  94. const S32 NUM_SELECTION_UNDO_ENTRIES = 200;
  95. const F32 SILHOUETTE_UPDATE_THRESHOLD_SQUARED = 0.02f;
  96. const S32 MAX_ACTION_QUEUE_SIZE = 20;
  97. const S32 MAX_SILS_PER_FRAME = 50;
  98. const S32 MAX_OBJECTS_PER_PACKET = 254;
  99. const S32 TE_SELECT_MASK_ALL = 0xFFFFFFFF;
  100. //
  101. // Globals
  102. //
  103. //BOOL gDebugSelectMgr = FALSE;
  104. //BOOL gHideSelectedObjects = FALSE;
  105. //BOOL gAllowSelectAvatar = FALSE;
  106. BOOL LLSelectMgr::sRectSelectInclusive = TRUE;
  107. BOOL LLSelectMgr::sRenderHiddenSelections = TRUE;
  108. BOOL LLSelectMgr::sRenderLightRadius = FALSE;
  109. F32 LLSelectMgr::sHighlightThickness = 0.f;
  110. F32 LLSelectMgr::sHighlightUScale = 0.f;
  111. F32 LLSelectMgr::sHighlightVScale = 0.f;
  112. F32 LLSelectMgr::sHighlightAlpha = 0.f;
  113. F32 LLSelectMgr::sHighlightAlphaTest = 0.f;
  114. F32 LLSelectMgr::sHighlightUAnim = 0.f;
  115. F32 LLSelectMgr::sHighlightVAnim = 0.f;
  116. LLColor4 LLSelectMgr::sSilhouetteParentColor;
  117. LLColor4 LLSelectMgr::sSilhouetteChildColor;
  118. LLColor4 LLSelectMgr::sHighlightInspectColor;
  119. LLColor4 LLSelectMgr::sHighlightParentColor;
  120. LLColor4 LLSelectMgr::sHighlightChildColor;
  121. LLColor4 LLSelectMgr::sContextSilhouetteColor;
  122. static LLObjectSelection *get_null_object_selection();
  123. template<>
  124. const LLSafeHandle<LLObjectSelection>::NullFunc
  125. LLSafeHandle<LLObjectSelection>::sNullFunc = get_null_object_selection;
  126. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  127. // struct LLDeRezInfo
  128. //
  129. // Used to keep track of important derez info.
  130. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  131. struct LLDeRezInfo
  132. {
  133. EDeRezDestination mDestination;
  134. LLUUID mDestinationID;
  135. LLDeRezInfo(EDeRezDestination dest, const LLUUID& dest_id) :
  136. mDestination(dest), mDestinationID(dest_id) {}
  137. };
  138. //
  139. // Imports
  140. //
  141. static LLPointer<LLObjectSelection> sNullSelection;
  142. //
  143. // Functions
  144. //
  145. void LLSelectMgr::cleanupGlobals()
  146. {
  147. sNullSelection = NULL;
  148. LLSelectMgr::getInstance()->clearSelections();
  149. }
  150. LLObjectSelection *get_null_object_selection()
  151. {
  152. if (sNullSelection.isNull())
  153. {
  154. sNullSelection = new LLObjectSelection;
  155. }
  156. return sNullSelection;
  157. }
  158. // Build time optimization, generate this function once here
  159. template class LLSelectMgr* LLSingleton<class LLSelectMgr>::getInstance();
  160. //-----------------------------------------------------------------------------
  161. // LLSelectMgr()
  162. //-----------------------------------------------------------------------------
  163. LLSelectMgr::LLSelectMgr()
  164. : mHideSelectedObjects(LLCachedControl<bool>(gSavedSettings, "HideSelectedObjects", FALSE)),
  165. mRenderHighlightSelections(LLCachedControl<bool>(gSavedSettings, "RenderHighlightSelections", TRUE)),
  166. mAllowSelectAvatar( LLCachedControl<bool>(gSavedSettings, "AllowSelectAvatar", FALSE)),
  167. mDebugSelectMgr(LLCachedControl<bool>(gSavedSettings, "DebugSelectMgr", FALSE))
  168. {
  169. mTEMode = FALSE;
  170. mLastCameraPos.clearVec();
  171. sHighlightThickness = gSavedSettings.getF32("SelectionHighlightThickness");
  172. sHighlightUScale = gSavedSettings.getF32("SelectionHighlightUScale");
  173. sHighlightVScale = gSavedSettings.getF32("SelectionHighlightVScale");
  174. sHighlightAlpha = gSavedSettings.getF32("SelectionHighlightAlpha");
  175. sHighlightAlphaTest = gSavedSettings.getF32("SelectionHighlightAlphaTest");
  176. sHighlightUAnim = gSavedSettings.getF32("SelectionHighlightUAnim");
  177. sHighlightVAnim = gSavedSettings.getF32("SelectionHighlightVAnim");
  178. sSilhouetteParentColor =LLUIColorTable::instance().getColor("SilhouetteParentColor");
  179. sSilhouetteChildColor = LLUIColorTable::instance().getColor("SilhouetteChildColor");
  180. sHighlightParentColor = LLUIColorTable::instance().getColor("HighlightParentColor");
  181. sHighlightChildColor = LLUIColorTable::instance().getColor("HighlightChildColor");
  182. sHighlightInspectColor = LLUIColorTable::instance().getColor("HighlightInspectColor");
  183. sContextSilhouetteColor = LLUIColorTable::instance().getColor("ContextSilhouetteColor")*0.5f;
  184. sRenderLightRadius = gSavedSettings.getBOOL("RenderLightRadius");
  185. mRenderSilhouettes = TRUE;
  186. mGridMode = GRID_MODE_WORLD;
  187. gSavedSettings.setS32("GridMode", (S32)GRID_MODE_WORLD);
  188. mGridValid = FALSE;
  189. mSelectedObjects = new LLObjectSelection();
  190. mHoverObjects = new LLObjectSelection();
  191. mHighlightedObjects = new LLObjectSelection();
  192. mForceSelection = FALSE;
  193. mShowSelection = FALSE;
  194. }
  195. //-----------------------------------------------------------------------------
  196. // ~LLSelectMgr()
  197. //-----------------------------------------------------------------------------
  198. LLSelectMgr::~LLSelectMgr()
  199. {
  200. clearSelections();
  201. }
  202. void LLSelectMgr::clearSelections()
  203. {
  204. mHoverObjects->deleteAllNodes();
  205. mSelectedObjects->deleteAllNodes();
  206. mHighlightedObjects->deleteAllNodes();
  207. mRectSelectedObjects.clear();
  208. mGridObjects.deleteAllNodes();
  209. }
  210. void LLSelectMgr::update()
  211. {
  212. mSelectedObjects->cleanupNodes();
  213. }
  214. void LLSelectMgr::updateEffects()
  215. {
  216. //keep reference grid objects active
  217. struct f : public LLSelectedObjectFunctor
  218. {
  219. virtual bool apply(LLViewerObject* object)
  220. {
  221. LLDrawable* drawable = object->mDrawable;
  222. if (drawable)
  223. {
  224. gPipeline.markMoved(drawable);
  225. }
  226. return true;
  227. }
  228. } func;
  229. mGridObjects.applyToObjects(&func);
  230. if (mEffectsTimer.getElapsedTimeF32() > 1.f)
  231. {
  232. mSelectedObjects->updateEffects();
  233. mEffectsTimer.reset();
  234. }
  235. }
  236. void LLSelectMgr::overrideObjectUpdates()
  237. {
  238. //override any position updates from simulator on objects being edited
  239. struct f : public LLSelectedNodeFunctor
  240. {
  241. virtual bool apply(LLSelectNode* selectNode)
  242. {
  243. LLViewerObject* object = selectNode->getObject();
  244. if (object && object->permMove())
  245. {
  246. if (!selectNode->mLastPositionLocal.isExactlyZero())
  247. {
  248. object->setPosition(selectNode->mLastPositionLocal);
  249. }
  250. if (selectNode->mLastRotation != LLQuaternion())
  251. {
  252. object->setRotation(selectNode->mLastRotation);
  253. }
  254. if (!selectNode->mLastScale.isExactlyZero())
  255. {
  256. object->setScale(selectNode->mLastScale);
  257. }
  258. }
  259. return true;
  260. }
  261. } func;
  262. getSelection()->applyToNodes(&func);
  263. }
  264. //-----------------------------------------------------------------------------
  265. // Select just the object, not any other group members.
  266. //-----------------------------------------------------------------------------
  267. LLObjectSelectionHandle LLSelectMgr::selectObjectOnly(LLViewerObject* object, S32 face)
  268. {
  269. llassert( object );
  270. //remember primary object
  271. mSelectedObjects->mPrimaryObject = object;
  272. // Don't add an object that is already in the list
  273. if (object->isSelected() ) {
  274. // make sure point at position is updated
  275. updatePointAt();
  276. gEditMenuHandler = this;
  277. return NULL;
  278. }
  279. if (!canSelectObject(object))
  280. {
  281. //make_ui_sound("UISndInvalidOp");
  282. return NULL;
  283. }
  284. // llinfos << "Adding object to selected object list" << llendl;
  285. // Place it in the list and tag it.
  286. // This will refresh dialogs.
  287. addAsIndividual(object, face);
  288. // Stop the object from moving (this anticipates changes on the
  289. // simulator in LLTask::userSelect)
  290. // *FIX: shouldn't zero out these either
  291. object->setVelocity(LLVector3::zero);
  292. object->setAcceleration(LLVector3::zero);
  293. //object->setAngularVelocity(LLVector3::zero);
  294. object->resetRot();
  295. // Always send to simulator, so you get a copy of the
  296. // permissions structure back.
  297. gMessageSystem->newMessageFast(_PREHASH_ObjectSelect);
  298. gMessageSystem->nextBlockFast(_PREHASH_AgentData);
  299. gMessageSystem->addUUIDFast(_PREHASH_AgentID, gAgent.getID() );
  300. gMessageSystem->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
  301. gMessageSystem->nextBlockFast(_PREHASH_ObjectData);
  302. gMessageSystem->addU32Fast(_PREHASH_ObjectLocalID, object->getLocalID() );
  303. LLViewerRegion* regionp = object->getRegion();
  304. gMessageSystem->sendReliable( regionp->getHost());
  305. updatePointAt();
  306. updateSelectionCenter();
  307. saveSelectedObjectTransform(SELECT_ACTION_TYPE_PICK);
  308. // have selection manager handle edit menu immediately after
  309. // user selects an object
  310. if (mSelectedObjects->getObjectCount())
  311. {
  312. gEditMenuHandler = this;
  313. }
  314. return mSelectedObjects;
  315. }
  316. //-----------------------------------------------------------------------------
  317. // Select the object, parents and children.
  318. //-----------------------------------------------------------------------------
  319. LLObjectSelectionHandle LLSelectMgr::selectObjectAndFamily(LLViewerObject* obj, BOOL add_to_end)
  320. {
  321. llassert( obj );
  322. //remember primary object
  323. mSelectedObjects->mPrimaryObject = obj;
  324. // This may be incorrect if things weren't family selected before... - djs 07/08/02
  325. // Don't add an object that is already in the list
  326. if (obj->isSelected() )
  327. {
  328. // make sure pointat position is updated
  329. updatePointAt();
  330. gEditMenuHandler = this;
  331. return NULL;
  332. }
  333. if (!canSelectObject(obj))
  334. {
  335. //make_ui_sound("UISndInvalidOp");
  336. return NULL;
  337. }
  338. // Since we're selecting a family, start at the root, but
  339. // don't include an avatar.
  340. LLViewerObject* root = obj;
  341. while(!root->isAvatar() && root->getParent() && !root->isJointChild())
  342. {
  343. LLViewerObject* parent = (LLViewerObject*)root->getParent();
  344. if (parent->isAvatar())
  345. {
  346. break;
  347. }
  348. root = parent;
  349. }
  350. // Collect all of the objects
  351. std::vector<LLViewerObject*> objects;
  352. root->addThisAndNonJointChildren(objects);
  353. addAsFamily(objects, add_to_end);
  354. updateSelectionCenter();
  355. saveSelectedObjectTransform(SELECT_ACTION_TYPE_PICK);
  356. updatePointAt();
  357. dialog_refresh_all();
  358. // Always send to simulator, so you get a copy of the permissions
  359. // structure back.
  360. sendSelect();
  361. // Stop the object from moving (this anticipates changes on the
  362. // simulator in LLTask::userSelect)
  363. root->setVelocity(LLVector3::zero);
  364. root->setAcceleration(LLVector3::zero);
  365. //root->setAngularVelocity(LLVector3::zero);
  366. root->resetRot();
  367. // leave component mode
  368. if (gSavedSettings.getBOOL("EditLinkedParts"))
  369. {
  370. gSavedSettings.setBOOL("EditLinkedParts", FALSE);
  371. promoteSelectionToRoot();
  372. }
  373. // have selection manager handle edit menu immediately after
  374. // user selects an object
  375. if (mSelectedObjects->getObjectCount())
  376. {
  377. gEditMenuHandler = this;
  378. }
  379. return mSelectedObjects;
  380. }
  381. //-----------------------------------------------------------------------------
  382. // Select the object, parents and children.
  383. //-----------------------------------------------------------------------------
  384. LLObjectSelectionHandle LLSelectMgr::selectObjectAndFamily(const std::vector<LLViewerObject*>& object_list,
  385. BOOL send_to_sim)
  386. {
  387. // Collect all of the objects, children included
  388. std::vector<LLViewerObject*> objects;
  389. //clear primary object (no primary object)
  390. mSelectedObjects->mPrimaryObject = NULL;
  391. if (object_list.size() < 1)
  392. {
  393. return NULL;
  394. }
  395. // NOTE -- we add the objects in REVERSE ORDER
  396. // to preserve the order in the mSelectedObjects list
  397. for (std::vector<LLViewerObject*>::const_reverse_iterator riter = object_list.rbegin();
  398. riter != object_list.rend(); ++riter)
  399. {
  400. LLViewerObject *object = *riter;
  401. llassert( object );
  402. if (!canSelectObject(object)) continue;
  403. object->addThisAndNonJointChildren(objects);
  404. addAsFamily(objects);
  405. // Stop the object from moving (this anticipates changes on the
  406. // simulator in LLTask::userSelect)
  407. object->setVelocity(LLVector3::zero);
  408. object->setAcceleration(LLVector3::zero);
  409. //object->setAngularVelocity(LLVector3::zero);
  410. object->resetRot();
  411. }
  412. updateSelectionCenter();
  413. saveSelectedObjectTransform(SELECT_ACTION_TYPE_PICK);
  414. updatePointAt();
  415. dialog_refresh_all();
  416. // Almost always send to simulator, so you get a copy of the permissions
  417. // structure back.
  418. // JC: The one case where you don't want to do this is if you're selecting
  419. // all the objects on a sim.
  420. if (send_to_sim)
  421. {
  422. sendSelect();
  423. }
  424. // leave component mode
  425. if (gSavedSettings.getBOOL("EditLinkedParts"))
  426. {
  427. gSavedSettings.setBOOL("EditLinkedParts", FALSE);
  428. promoteSelectionToRoot();
  429. }
  430. // have selection manager handle edit menu immediately after
  431. // user selects an object
  432. if (mSelectedObjects->getObjectCount())
  433. {
  434. gEditMenuHandler = this;
  435. }
  436. return mSelectedObjects;
  437. }
  438. // Use for when the simulator kills an object. This version also
  439. // handles informing the current tool of the object's deletion.
  440. //
  441. // Caller needs to call dialog_refresh_all if necessary.
  442. BOOL LLSelectMgr::removeObjectFromSelections(const LLUUID &id)
  443. {
  444. BOOL object_found = FALSE;
  445. LLTool *tool = NULL;
  446. tool = LLToolMgr::getInstance()->getCurrentTool();
  447. // It's possible that the tool is editing an object that is not selected
  448. LLViewerObject* tool_editing_object = tool->getEditingObject();
  449. if( tool_editing_object && tool_editing_object->mID == id)
  450. {
  451. tool->stopEditing();
  452. object_found = TRUE;
  453. }
  454. // Iterate through selected objects list and kill the object
  455. if( !object_found )
  456. {
  457. for (LLObjectSelection::iterator iter = getSelection()->begin();
  458. iter != getSelection()->end(); )
  459. {
  460. LLObjectSelection::iterator curiter = iter++;
  461. LLViewerObject* object = (*curiter)->getObject();
  462. if (object->mID == id)
  463. {
  464. if (tool)
  465. {
  466. tool->stopEditing();
  467. }
  468. // lose the selection, don't tell simulator, it knows
  469. deselectObjectAndFamily(object, FALSE);
  470. object_found = TRUE;
  471. break; // must break here, may have removed multiple objects from list
  472. }
  473. else if (object->isAvatar() && object->getParent() && ((LLViewerObject*)object->getParent())->mID == id)
  474. {
  475. // It's possible the item being removed has an avatar sitting on it
  476. // So remove the avatar that is sitting on the object.
  477. deselectObjectAndFamily(object, FALSE);
  478. break; // must break here, may have removed multiple objects from list
  479. }
  480. }
  481. }
  482. return object_found;
  483. }
  484. bool LLSelectMgr::linkObjects()
  485. {
  486. if (!LLSelectMgr::getInstance()->selectGetAllRootsValid())
  487. {
  488. LLNotificationsUtil::add("UnableToLinkWhileDownloading");
  489. return true;
  490. }
  491. S32 object_count = LLSelectMgr::getInstance()->getSelection()->getObjectCount();
  492. if (object_count > MAX_CHILDREN_PER_TASK + 1)
  493. {
  494. LLSD args;
  495. args["COUNT"] = llformat("%d", object_count);
  496. int max = MAX_CHILDREN_PER_TASK+1;
  497. args["MAX"] = llformat("%d", max);
  498. LLNotificationsUtil::add("UnableToLinkObjects", args);
  499. return true;
  500. }
  501. if (LLSelectMgr::getInstance()->getSelection()->getRootObjectCount() < 2)
  502. {
  503. LLNotificationsUtil::add("CannotLinkIncompleteSet");
  504. return true;
  505. }
  506. if (!LLSelectMgr::getInstance()->selectGetRootsModify())
  507. {
  508. LLNotificationsUtil::add("CannotLinkModify");
  509. return true;
  510. }
  511. LLUUID owner_id;
  512. std::string owner_name;
  513. if (!LLSelectMgr::getInstance()->selectGetOwner(owner_id, owner_name))
  514. {
  515. // we don't actually care if you're the owner, but novices are
  516. // the most likely to be stumped by this one, so offer the
  517. // easiest and most likely solution.
  518. LLNotificationsUtil::add("CannotLinkDifferentOwners");
  519. return true;
  520. }
  521. LLSelectMgr::getInstance()->sendLink();
  522. return true;
  523. }
  524. bool LLSelectMgr::unlinkObjects()
  525. {
  526. LLSelectMgr::getInstance()->sendDelink();
  527. return true;
  528. }
  529. // in order to link, all objects must have the same owner, and the
  530. // agent must have the ability to modify all of the objects. However,
  531. // we're not answering that question with this method. The question
  532. // we're answering is: does the user have a reasonable expectation
  533. // that a link operation should work? If so, return true, false
  534. // otherwise. this allows the handle_link method to more finely check
  535. // the selection and give an error message when the uer has a
  536. // reasonable expectation for the link to work, but it will fail.
  537. bool LLSelectMgr::enableLinkObjects()
  538. {
  539. bool new_value = false;
  540. // check if there are at least 2 objects selected, and that the
  541. // user can modify at least one of the selected objects.
  542. // in component mode, can't link
  543. if (!gSavedSettings.getBOOL("EditLinkedParts"))
  544. {
  545. if(LLSelectMgr::getInstance()->selectGetAllRootsValid() && LLSelectMgr::getInstance()->getSelection()->getRootObjectCount() >= 2)
  546. {
  547. struct f : public LLSelectedObjectFunctor
  548. {
  549. virtual bool apply(LLViewerObject* object)
  550. {
  551. return object->permModify();
  552. }
  553. } func;
  554. const bool firstonly = true;
  555. new_value = LLSelectMgr::getInstance()->getSelection()->applyToRootObjects(&func, firstonly);
  556. }
  557. }
  558. return new_value;
  559. }
  560. bool LLSelectMgr::enableUnlinkObjects()
  561. {
  562. LLViewerObject* first_editable_object = LLSelectMgr::getInstance()->getSelection()->getFirstEditableObject();
  563. bool new_value = LLSelectMgr::getInstance()->selectGetAllRootsValid() &&
  564. first_editable_object &&
  565. !first_editable_object->isAttachment();
  566. return new_value;
  567. }
  568. void LLSelectMgr::deselectObjectAndFamily(LLViewerObject* object, BOOL send_to_sim, BOOL include_entire_object)
  569. {
  570. // bail if nothing selected or if object wasn't selected in the first place
  571. if(!object) return;
  572. if(!object->isSelected()) return;
  573. // Collect all of the objects, and remove them
  574. std::vector<LLViewerObject*> objects;
  575. if (include_entire_object)
  576. {
  577. // Since we're selecting a family, start at the root, but
  578. // don't include an avatar.
  579. LLViewerObject* root = object;
  580. while(!root->isAvatar() && root->getParent() && !root->isJointChild())
  581. {
  582. LLViewerObject* parent = (LLViewerObject*)root->getParent();
  583. if (parent->isAvatar())
  584. {
  585. break;
  586. }
  587. root = parent;
  588. }
  589. object = root;
  590. }
  591. else
  592. {
  593. object = (LLViewerObject*)object->getRoot();
  594. }
  595. object->addThisAndAllChildren(objects);
  596. remove(objects);
  597. if (!send_to_sim) return;
  598. //-----------------------------------------------------------
  599. // Inform simulator of deselection
  600. //-----------------------------------------------------------
  601. LLViewerRegion* regionp = object->getRegion();
  602. BOOL start_new_message = TRUE;
  603. S32 select_count = 0;
  604. LLMessageSystem* msg = gMessageSystem;
  605. for (U32 i = 0; i < objects.size(); i++)
  606. {
  607. if (start_new_message)
  608. {
  609. msg->newMessageFast(_PREHASH_ObjectDeselect);
  610. msg->nextBlockFast(_PREHASH_AgentData);
  611. msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID() );
  612. msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
  613. select_count++;
  614. start_new_message = FALSE;
  615. }
  616. msg->nextBlockFast(_PREHASH_ObjectData);
  617. msg->addU32Fast(_PREHASH_ObjectLocalID, (objects[i])->getLocalID());
  618. select_count++;
  619. // Zap the angular velocity, as the sim will set it to zero
  620. objects[i]->setAngularVelocity( 0,0,0 );
  621. objects[i]->setVelocity( 0,0,0 );
  622. if(msg->isSendFull(NULL) || select_count >= MAX_OBJECTS_PER_PACKET)
  623. {
  624. msg->sendReliable(regionp->getHost() );
  625. select_count = 0;
  626. start_new_message = TRUE;
  627. }
  628. }
  629. if (!start_new_message)
  630. {
  631. msg->sendReliable(regionp->getHost() );
  632. }
  633. updatePointAt();
  634. updateSelectionCenter();
  635. }
  636. void LLSelectMgr::deselectObjectOnly(LLViewerObject* object, BOOL send_to_sim)
  637. {
  638. // bail if nothing selected or if object wasn't selected in the first place
  639. if (!object) return;
  640. if (!object->isSelected() ) return;
  641. // Zap the angular velocity, as the sim will set it to zero
  642. object->setAngularVelocity( 0,0,0 );
  643. object->setVelocity( 0,0,0 );
  644. if (send_to_sim)
  645. {
  646. LLViewerRegion* region = object->getRegion();
  647. gMessageSystem->newMessageFast(_PREHASH_ObjectDeselect);
  648. gMessageSystem->nextBlockFast(_PREHASH_AgentData);
  649. gMessageSystem->addUUIDFast(_PREHASH_AgentID, gAgent.getID() );
  650. gMessageSystem->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
  651. gMessageSystem->nextBlockFast(_PREHASH_ObjectData);
  652. gMessageSystem->addU32Fast(_PREHASH_ObjectLocalID, object->getLocalID() );
  653. gMessageSystem->sendReliable(region->getHost());
  654. }
  655. // This will refresh dialogs.
  656. remove( object );
  657. updatePointAt();
  658. updateSelectionCenter();
  659. }
  660. //-----------------------------------------------------------------------------
  661. // addAsFamily
  662. //-----------------------------------------------------------------------------
  663. void LLSelectMgr::addAsFamily(std::vector<LLViewerObject*>& objects, BOOL add_to_end)
  664. {
  665. for (std::vector<LLViewerObject*>::iterator iter = objects.begin();
  666. iter != objects.end(); ++iter)
  667. {
  668. LLViewerObject* objectp = *iter;
  669. // Can't select yourself
  670. if (objectp->mID == gAgentID
  671. && !LLSelectMgr::getInstance()->mAllowSelectAvatar)
  672. {
  673. continue;
  674. }
  675. if (!objectp->isSelected())
  676. {
  677. LLSelectNode *nodep = new LLSelectNode(objectp, TRUE);
  678. if (add_to_end)
  679. {
  680. mSelectedObjects->addNodeAtEnd(nodep);
  681. }
  682. else
  683. {
  684. mSelectedObjects->addNode(nodep);
  685. }
  686. objectp->setSelected(TRUE);
  687. if (objectp->getNumTEs() > 0)
  688. {
  689. nodep->selectAllTEs(TRUE);
  690. }
  691. else
  692. {
  693. // object has no faces, so don't mess with faces
  694. }
  695. }
  696. else
  697. {
  698. // we want this object to be selected for real
  699. // so clear transient flag
  700. LLSelectNode* select_node = mSelectedObjects->findNode(objectp);
  701. if (select_node)
  702. {
  703. select_node->setTransient(FALSE);
  704. }
  705. }
  706. }
  707. saveSelectedObjectTransform(SELECT_ACTION_TYPE_PICK);
  708. }
  709. //-----------------------------------------------------------------------------
  710. // addAsIndividual() - a single object, face, etc
  711. //-----------------------------------------------------------------------------
  712. void LLSelectMgr::addAsIndividual(LLViewerObject *objectp, S32 face, BOOL undoable)
  713. {
  714. // check to see if object is already in list
  715. LLSelectNode *nodep = mSelectedObjects->findNode(objectp);
  716. // if not in list, add it
  717. if (!nodep)
  718. {
  719. nodep = new LLSelectNode(objectp, TRUE);
  720. mSelectedObjects->addNode(nodep);
  721. llassert_always(nodep->getObject());
  722. }
  723. else
  724. {
  725. // make this a full-fledged selection
  726. nodep->setTransient(FALSE);
  727. // Move it to the front of the list
  728. mSelectedObjects->moveNodeToFront(nodep);
  729. }
  730. // Make sure the object is tagged as selected
  731. objectp->setSelected( TRUE );
  732. // And make sure we don't consider it as part of a family
  733. nodep->mIndividualSelection = TRUE;
  734. // Handle face selection
  735. if (objectp->getNumTEs() <= 0)
  736. {
  737. // object has no faces, so don't do anything
  738. }
  739. else if (face == SELECT_ALL_TES)
  740. {
  741. nodep->selectAllTEs(TRUE);
  742. }
  743. else if (0 <= face && face < SELECT_MAX_TES)
  744. {
  745. nodep->selectTE(face, TRUE);
  746. }
  747. else
  748. {
  749. llerrs << "LLSelectMgr::add face " << face << " out-of-range" << llendl;
  750. return;
  751. }
  752. saveSelectedObjectTransform(SELECT_ACTION_TYPE_PICK);
  753. updateSelectionCenter();
  754. dialog_refresh_all();
  755. }
  756. LLObjectSelectionHandle LLSelectMgr::setHoverObject(LLViewerObject *objectp, S32 face)
  757. {
  758. if (!objectp)
  759. {
  760. mHoverObjects->deleteAllNodes();
  761. return NULL;
  762. }
  763. // Can't select yourself
  764. if (objectp->mID == gAgentID)
  765. {
  766. mHoverObjects->deleteAllNodes();
  767. return NULL;
  768. }
  769. // Can't select land
  770. if (objectp->getPCode() == LLViewerObject::LL_VO_SURFACE_PATCH)
  771. {
  772. mHoverObjects->deleteAllNodes();
  773. return NULL;
  774. }
  775. mHoverObjects->mPrimaryObject = objectp;
  776. objectp = objectp->getRootEdit();
  777. // is the requested object the same as the existing hover object root?
  778. // NOTE: there is only ever one linked set in mHoverObjects
  779. if (mHoverObjects->getFirstRootObject() != objectp)
  780. {
  781. // Collect all of the objects
  782. std::vector<LLViewerObject*> objects;
  783. objectp = objectp->getRootEdit();
  784. objectp->addThisAndNonJointChildren(objects);
  785. mHoverObjects->deleteAllNodes();
  786. for (std::vector<LLViewerObject*>::iterator iter = objects.begin();
  787. iter != objects.end(); ++iter)
  788. {
  789. LLViewerObject* cur_objectp = *iter;
  790. LLSelectNode* nodep = new LLSelectNode(cur_objectp, FALSE);
  791. nodep->selectTE(face, TRUE);
  792. mHoverObjects->addNodeAtEnd(nodep);
  793. }
  794. requestObjectPropertiesFamily(objectp);
  795. }
  796. return mHoverObjects;
  797. }
  798. LLSelectNode *LLSelectMgr::getHoverNode()
  799. {
  800. return mHoverObjects->getFirstRootNode();
  801. }
  802. LLSelectNode *LLSelectMgr::getPrimaryHoverNode()
  803. {
  804. return mHoverObjects->mSelectNodeMap[mHoverObjects->mPrimaryObject];
  805. }
  806. void LLSelectMgr::highlightObjectOnly(LLViewerObject* objectp)
  807. {
  808. if (!objectp)
  809. {
  810. return;
  811. }
  812. if (objectp->getPCode() != LL_PCODE_VOLUME)
  813. {
  814. return;
  815. }
  816. if ((gSavedSettings.getBOOL("SelectOwnedOnly") && !objectp->permYouOwner())
  817. || (gSavedSettings.getBOOL("SelectMovableOnly") && !objectp->permMove()))
  818. {
  819. // only select my own objects
  820. return;
  821. }
  822. mRectSelectedObjects.insert(objectp);
  823. }
  824. void LLSelectMgr::highlightObjectAndFamily(LLViewerObject* objectp)
  825. {
  826. if (!objectp)
  827. {
  828. return;
  829. }
  830. LLViewerObject* root_obj = (LLViewerObject*)objectp->getRoot();
  831. highlightObjectOnly(root_obj);
  832. LLViewerObject::const_child_list_t& child_list = root_obj->getChildren();
  833. for (LLViewerObject::child_list_t::const_iterator iter = child_list.begin();
  834. iter != child_list.end(); iter++)
  835. {
  836. LLViewerObject* child = *iter;
  837. highlightObjectOnly(child);
  838. }
  839. }
  840. // Note that this ignores the "select owned only" flag
  841. // It's also more efficient than calling the single-object version over and over.
  842. void LLSelectMgr::highlightObjectAndFamily(const std::vector<LLViewerObject*>& objects)
  843. {
  844. for (std::vector<LLViewerObject*>::const_iterator iter1 = objects.begin();
  845. iter1 != objects.end(); ++iter1)
  846. {
  847. LLViewerObject* object = *iter1;
  848. if (!object)
  849. {
  850. continue;
  851. }
  852. if (object->getPCode() != LL_PCODE_VOLUME)
  853. {
  854. continue;
  855. }
  856. LLViewerObject* root = (LLViewerObject*)object->getRoot();
  857. mRectSelectedObjects.insert(root);
  858. LLViewerObject::const_child_list_t& child_list = root->getChildren();
  859. for (LLViewerObject::child_list_t::const_iterator iter2 = child_list.begin();
  860. iter2 != child_list.end(); iter2++)
  861. {
  862. LLViewerObject* child = *iter2;
  863. mRectSelectedObjects.insert(child);
  864. }
  865. }
  866. }
  867. void LLSelectMgr::unhighlightObjectOnly(LLViewerObject* objectp)
  868. {
  869. if (!objectp || (objectp->getPCode() != LL_PCODE_VOLUME))
  870. {
  871. return;
  872. }
  873. mRectSelectedObjects.erase(objectp);
  874. }
  875. void LLSelectMgr::unhighlightObjectAndFamily(LLViewerObject* objectp)
  876. {
  877. if (!objectp)
  878. {
  879. return;
  880. }
  881. LLViewerObject* root_obj = (LLViewerObject*)objectp->getRoot();
  882. unhighlightObjectOnly(root_obj);
  883. LLViewerObject::const_child_list_t& child_list = root_obj->getChildren();
  884. for (LLViewerObject::child_list_t::const_iterator iter = child_list.begin();
  885. iter != child_list.end(); iter++)
  886. {
  887. LLViewerObject* child = *iter;
  888. unhighlightObjectOnly(child);
  889. }
  890. }
  891. void LLSelectMgr::unhighlightAll()
  892. {
  893. mRectSelectedObjects.clear();
  894. mHighlightedObjects->deleteAllNodes();
  895. }
  896. LLObjectSelectionHandle LLSelectMgr::selectHighlightedObjects()
  897. {
  898. if (!mHighlightedObjects->getNumNodes())
  899. {
  900. return NULL;
  901. }
  902. //clear primary object
  903. mSelectedObjects->mPrimaryObject = NULL;
  904. for (LLObjectSelection::iterator iter = getHighlightedObjects()->begin();
  905. iter != getHighlightedObjects()->end(); )
  906. {
  907. LLObjectSelection::iterator curiter = iter++;
  908. LLSelectNode *nodep = *curiter;
  909. LLViewerObject* objectp = nodep->getObject();
  910. if (!canSelectObject(objectp))
  911. {
  912. continue;
  913. }
  914. // already selected
  915. if (objectp->isSelected())
  916. {
  917. continue;
  918. }
  919. LLSelectNode* new_nodep = new LLSelectNode(*nodep);
  920. mSelectedObjects->addNode(new_nodep);
  921. // flag this object as selected
  922. objectp->setSelected(TRUE);
  923. mSelectedObjects->mSelectType = getSelectTypeForObject(objectp);
  924. // request properties on root objects
  925. if (objectp->isRootEdit())
  926. {
  927. requestObjectPropertiesFamily(objectp);
  928. }
  929. }
  930. // pack up messages to let sim know these objects are selected
  931. sendSelect();
  932. unhighlightAll();
  933. updateSelectionCenter();
  934. saveSelectedObjectTransform(SELECT_ACTION_TYPE_PICK);
  935. updatePointAt();
  936. if (mSelectedObjects->getObjectCount())
  937. {
  938. gEditMenuHandler = this;
  939. }
  940. return mSelectedObjects;
  941. }
  942. void LLSelectMgr::deselectHighlightedObjects()
  943. {
  944. BOOL select_linked_set = !gSavedSettings.getBOOL("EditLinkedParts");
  945. for (std::set<LLPointer<LLViewerObject> >::iterator iter = mRectSelectedObjects.begin();
  946. iter != mRectSelectedObjects.end(); iter++)
  947. {
  948. LLViewerObject *objectp = *iter;
  949. if (!select_linked_set)
  950. {
  951. deselectObjectOnly(objectp);
  952. }
  953. else
  954. {
  955. LLViewerObject* root_object = (LLViewerObject*)objectp->getRoot();
  956. if (root_object->isSelected())
  957. {
  958. deselectObjectAndFamily(root_object);
  959. }
  960. }
  961. }
  962. unhighlightAll();
  963. }
  964. void LLSelectMgr::addGridObject(LLViewerObject* objectp)
  965. {
  966. LLSelectNode* nodep = new LLSelectNode(objectp, FALSE);
  967. mGridObjects.addNodeAtEnd(nodep);
  968. LLViewerObject::const_child_list_t& child_list = objectp->getChildren();
  969. for (LLViewerObject::child_list_t::const_iterator iter = child_list.begin();
  970. iter != child_list.end(); iter++)
  971. {
  972. LLViewerObject* child = *iter;
  973. nodep = new LLSelectNode(child, FALSE);
  974. mGridObjects.addNodeAtEnd(nodep);
  975. }
  976. }
  977. void LLSelectMgr::clearGridObjects()
  978. {
  979. mGridObjects.deleteAllNodes();
  980. }
  981. void LLSelectMgr::setGridMode(EGridMode mode)
  982. {
  983. mGridMode = mode;
  984. gSavedSettings.setS32("GridMode", mode);
  985. updateSelectionCenter();
  986. mGridValid = FALSE;
  987. }
  988. void LLSelectMgr::getGrid(LLVector3& origin, LLQuaternion &rotation, LLVector3 &scale)
  989. {
  990. mGridObjects.cleanupNodes();
  991. LLViewerObject* first_grid_object = mGridObjects.getFirstObject();
  992. if (mGridMode == GRID_MODE_LOCAL && mSelectedObjects->getObjectCount())
  993. {
  994. //LLViewerObject* root = getSelectedParentObject(mSelectedObjects->getFirstObject());
  995. LLBBox bbox = mSavedSelectionBBox;
  996. mGridOrigin = mSavedSelectionBBox.getCenterAgent();
  997. mGridScale = mSavedSelectionBBox.getExtentLocal() * 0.5f;
  998. // DEV-12570 Just taking the saved selection box rotation prevents
  999. // wild rotations of linked sets while in local grid mode
  1000. //if(mSelectedObjects->getObjectCount() < 2 || !root || root->mDrawable.isNull())
  1001. {
  1002. mGridRotation = mSavedSelectionBBox.getRotation();
  1003. }
  1004. /*else //set to the root object
  1005. {
  1006. mGridRotation = root->getRenderRotation();
  1007. }*/
  1008. }
  1009. else if (mGridMode == GRID_MODE_REF_OBJECT && first_grid_object && first_grid_object->mDrawable.notNull())
  1010. {
  1011. mGridRotation = first_grid_object->getRenderRotation();
  1012. LLVector3 first_grid_obj_pos = first_grid_object->getRenderPosition();
  1013. LLVector4a min_extents(F32_MAX);
  1014. LLVector4a max_extents(-F32_MAX);
  1015. BOOL grid_changed = FALSE;
  1016. for (LLObjectSelection::iterator iter = mGridObjects.begin();
  1017. iter != mGridObjects.end(); ++iter)
  1018. {
  1019. LLViewerObject* object = (*iter)->getObject();
  1020. LLDrawable* drawable = object->mDrawable;
  1021. if (drawable)
  1022. {
  1023. const LLVector4a* ext = drawable->getSpatialExtents();
  1024. update_min_max(min_extents, max_extents, ext[0]);
  1025. update_min_max(min_extents, max_extents, ext[1]);
  1026. grid_changed = TRUE;
  1027. }
  1028. }
  1029. if (grid_changed)
  1030. {
  1031. LLVector4a center, size;
  1032. center.setAdd(min_extents, max_extents);
  1033. center.mul(0.5f);
  1034. size.setSub(max_extents, min_extents);
  1035. size.mul(0.5f);
  1036. mGridOrigin.set(center.getF32ptr());
  1037. LLDrawable* drawable = first_grid_object->mDrawable;
  1038. if (drawable && drawable->isActive())
  1039. {
  1040. mGridOrigin = mGridOrigin * first_grid_object->getRenderMatrix();
  1041. }
  1042. mGridScale.set(size.getF32ptr());
  1043. }
  1044. }
  1045. else // GRID_MODE_WORLD or just plain default
  1046. {
  1047. const BOOL non_root_ok = TRUE;
  1048. LLViewerObject* first_object = mSelectedObjects->getFirstRootObject(non_root_ok);
  1049. mGridOrigin.clearVec();
  1050. mGridRotation.loadIdentity();
  1051. mSelectedObjects->mSelectType = getSelectTypeForObject( first_object );
  1052. switch (mSelectedObjects->mSelectType)
  1053. {
  1054. case SELECT_TYPE_ATTACHMENT:
  1055. if (first_object && first_object->getRootEdit()->mDrawable.notNull())
  1056. {
  1057. // this means this object *has* to be an attachment
  1058. LLXform* attachment_point_xform = first_object->getRootEdit()->mDrawable->mXform.getParent();
  1059. mGridOrigin = attachment_point_xform->getWorldPosition();
  1060. mGridRotation = attachment_point_xform->getWorldRotation();
  1061. mGridScale = LLVector3(1.f, 1.f, 1.f) * gSavedSettings.getF32("GridResolution");
  1062. }
  1063. break;
  1064. case SELECT_TYPE_HUD:
  1065. // use HUD-scaled grid
  1066. mGridScale = LLVector3(0.25f, 0.25f, 0.25f);
  1067. break;
  1068. case SELECT_TYPE_WORLD:
  1069. mGridScale = LLVector3(1.f, 1.f, 1.f) * gSavedSettings.getF32("GridResolution");
  1070. break;
  1071. }
  1072. }
  1073. llassert(mGridOrigin.isFinite());
  1074. origin = mGridOrigin;
  1075. rotation = mGridRotation;
  1076. scale = mGridScale;
  1077. mGridValid = TRUE;
  1078. }
  1079. //-----------------------------------------------------------------------------
  1080. // remove() - an array of objects
  1081. //-----------------------------------------------------------------------------
  1082. void LLSelectMgr::remove(std::vector<LLViewerObject*>& objects)
  1083. {
  1084. for (std::vector<LLViewerObject*>::iterator iter = objects.begin();
  1085. iter != objects.end(); ++iter)
  1086. {
  1087. LLViewerObject* objectp = *iter;
  1088. LLSelectNode* nodep = mSelectedObjects->findNode(objectp);
  1089. if (nodep)
  1090. {
  1091. objectp->setSelected(FALSE);
  1092. mSelectedObjects->removeNode(nodep);
  1093. nodep = NULL;
  1094. }
  1095. }
  1096. updateSelectionCenter();
  1097. dialog_refresh_all();
  1098. }
  1099. //-----------------------------------------------------------------------------
  1100. // remove() - a single object
  1101. //-----------------------------------------------------------------------------
  1102. void LLSelectMgr::remove(LLViewerObject *objectp, S32 te, BOOL undoable)
  1103. {
  1104. // get object node (and verify it is in the selected list)
  1105. LLSelectNode *nodep = mSelectedObjects->findNode(objectp);
  1106. if (!nodep)
  1107. {
  1108. return;
  1109. }
  1110. // if face = all, remove object from list
  1111. if ((objectp->getNumTEs() <= 0) || (te == SELECT_ALL_TES))
  1112. {
  1113. // Remove all faces (or the object doesn't have faces) so remove the node
  1114. mSelectedObjects->removeNode(nodep);
  1115. nodep = NULL;
  1116. objectp->setSelected( FALSE );
  1117. }
  1118. else if (0 <= te && te < SELECT_MAX_TES)
  1119. {
  1120. // ...valid face, check to see if it was on
  1121. if (nodep->isTESelected(te))
  1122. {
  1123. nodep->selectTE(te, FALSE);
  1124. }
  1125. else
  1126. {
  1127. llerrs << "LLSelectMgr::remove - tried to remove TE " << te << " that wasn't selected" << llendl;
  1128. return;
  1129. }
  1130. // ...check to see if this operation turned off all faces
  1131. BOOL found = FALSE;
  1132. for (S32 i = 0; i < nodep->getObject()->getNumTEs(); i++)
  1133. {
  1134. found = found || nodep->isTESelected(i);
  1135. }
  1136. // ...all faces now turned off, so remove
  1137. if (!found)
  1138. {
  1139. mSelectedObjects->removeNode(nodep);
  1140. nodep = NULL;
  1141. objectp->setSelected( FALSE );
  1142. // *FIXME: Doesn't update simulator that object is no longer selected
  1143. }
  1144. }
  1145. else
  1146. {
  1147. // ...out of range face
  1148. llerrs << "LLSelectMgr::remove - TE " << te << " out of range" << llendl;
  1149. }
  1150. updateSelectionCenter();
  1151. dialog_refresh_all();
  1152. }
  1153. //-----------------------------------------------------------------------------
  1154. // removeAll()
  1155. //-----------------------------------------------------------------------------
  1156. void LLSelectMgr::removeAll()
  1157. {
  1158. for (LLObjectSelection::iterator iter = mSelectedObjects->begin();
  1159. iter != mSelectedObjects->end(); iter++ )
  1160. {
  1161. LLViewerObject *objectp = (*iter)->getObject();
  1162. objectp->setSelected( FALSE );
  1163. }
  1164. mSelectedObjects->deleteAllNodes();
  1165. updateSelectionCenter();
  1166. dialog_refresh_all();
  1167. }
  1168. //-----------------------------------------------------------------------------
  1169. // promoteSelectionToRoot()
  1170. //-----------------------------------------------------------------------------
  1171. void LLSelectMgr::promoteSelectionToRoot()
  1172. {
  1173. std::set<LLViewerObject*> selection_set;
  1174. BOOL selection_changed = FALSE;
  1175. for (LLObjectSelection::iterator iter = getSelection()->begin();
  1176. iter != getSelection()->end(); )
  1177. {
  1178. LLObjectSelection::iterator curiter = iter++;
  1179. LLSelectNode* nodep = *curiter;
  1180. LLViewerObject* object = nodep->getObject();
  1181. if (nodep->mIndividualSelection)
  1182. {
  1183. selection_changed = TRUE;
  1184. }
  1185. LLViewerObject* parentp = object;
  1186. while(parentp->getParent() && !(parentp->isRootEdit() || parentp->isJointChild()))
  1187. {
  1188. parentp = (LLViewerObject*)parentp->getParent();
  1189. }
  1190. selection_set.insert(parentp);
  1191. }
  1192. if (selection_changed)
  1193. {
  1194. deselectAll();
  1195. std::set<LLViewerObject*>::iterator set_iter;
  1196. for (set_iter = selection_set.begin(); set_iter != selection_set.end(); ++set_iter)
  1197. {
  1198. selectObjectAndFamily(*set_iter);
  1199. }
  1200. }
  1201. }
  1202. //-----------------------------------------------------------------------------
  1203. // demoteSelectionToIndividuals()
  1204. //-----------------------------------------------------------------------------
  1205. void LLSelectMgr::demoteSelectionToIndividuals()
  1206. {
  1207. std::vector<LLViewerObject*> objects;
  1208. for (LLObjectSelection::root_iterator iter = getSelection()->root_begin();
  1209. iter != getSelection()->root_end(); iter++)
  1210. {
  1211. LLViewerObject* object = (*iter)->getObject();
  1212. object->addThisAndNonJointChildren(objects);
  1213. }
  1214. if (!objects.empty())
  1215. {
  1216. deselectAll();
  1217. for (std::vector<LLViewerObject*>::iterator iter = objects.begin();
  1218. iter != objects.end(); ++iter)
  1219. {
  1220. LLViewerObject* objectp = *iter;
  1221. selectObjectOnly(objectp);
  1222. }
  1223. }
  1224. }
  1225. //-----------------------------------------------------------------------------
  1226. // dump()
  1227. //-----------------------------------------------------------------------------
  1228. void LLSelectMgr::dump()
  1229. {
  1230. llinfos << "Selection Manager: " << mSelectedObjects->getNumNodes() << " items" << llendl;
  1231. llinfos << "TE mode " << mTEMode << llendl;
  1232. S32 count = 0;
  1233. for (LLObjectSelection::iterator iter = getSelection()->begin();
  1234. iter != getSelection()->end(); iter++ )
  1235. {
  1236. LLViewerObject* objectp = (*iter)->getObject();
  1237. llinfos << "Object " << count << " type " << LLPrimitive::pCodeToString(objectp->getPCode()) << llendl;
  1238. llinfos << " hasLSL " << objectp->flagScripted() << llendl;
  1239. llinfos << " hasTouch " << objectp->flagHandleTouch() << llendl;
  1240. llinfos << " hasMoney " << objectp->flagTakesMoney() << llendl;
  1241. llinfos << " getposition " << objectp->getPosition() << llendl;
  1242. llinfos << " getpositionAgent " << objectp->getPositionAgent() << llendl;
  1243. llinfos << " getpositionRegion " << objectp->getPositionRegion() << llendl;
  1244. llinfos << " getpositionGlobal " << objectp->getPositionGlobal() << llendl;
  1245. LLDrawable* drawablep = objectp->mDrawable;
  1246. llinfos << " " << (drawablep&& drawablep->isVisible() ? "visible" : "invisible") << llendl;
  1247. llinfos << " " << (drawablep&& drawablep->isState(LLDrawable::FORCE_INVISIBLE) ? "force_invisible" : "") << llendl;
  1248. count++;
  1249. }
  1250. // Face iterator
  1251. for (LLObjectSelection::iterator iter = getSelection()->begin();
  1252. iter != getSelection()->end(); iter++ )
  1253. {
  1254. LLSelectNode* node = *iter;
  1255. LLViewerObject* objectp = node->getObject();
  1256. if (!objectp)
  1257. continue;
  1258. for (S32 te = 0; te < objectp->getNumTEs(); ++te )
  1259. {
  1260. if (node->isTESelected(te))
  1261. {
  1262. llinfos << "Object " << objectp << " te " << te << llendl;
  1263. }
  1264. }
  1265. }
  1266. llinfos << mHighlightedObjects->getNumNodes() << " objects currently highlighted." << llendl;
  1267. llinfos << "Center global " << mSelectionCenterGlobal << llendl;
  1268. }
  1269. //-----------------------------------------------------------------------------
  1270. // cleanup()
  1271. //-----------------------------------------------------------------------------
  1272. void LLSelectMgr::cleanup()
  1273. {
  1274. mSilhouetteImagep = NULL;
  1275. }
  1276. //---------------------------------------------------------------------------
  1277. // Manipulate properties of selected objects
  1278. //---------------------------------------------------------------------------
  1279. struct LLSelectMgrSendFunctor : public LLSelectedObjectFunctor
  1280. {
  1281. virtual bool apply(LLViewerObject* object)
  1282. {
  1283. if (object->permModify())
  1284. {
  1285. object->sendTEUpdate();
  1286. }
  1287. return true;
  1288. }
  1289. };
  1290. //-----------------------------------------------------------------------------
  1291. // selectionSetImage()
  1292. //-----------------------------------------------------------------------------
  1293. // *TODO: re-arch texture applying out of lltooldraganddrop
  1294. void LLSelectMgr::selectionSetImage(const LLUUID& imageid)
  1295. {
  1296. // First for (no copy) textures and multiple object selection
  1297. LLViewerInventoryItem* item = gInventory.getItem(imageid);
  1298. if(item
  1299. && !item->getPermissions().allowOperationBy(PERM_COPY, gAgent.getID())
  1300. && (mSelectedObjects->getNumNodes() > 1) )
  1301. {
  1302. llwarns << "Attempted to apply no-copy texture to multiple objects"
  1303. << llendl;
  1304. return;
  1305. }
  1306. struct f : public LLSelectedTEFunctor
  1307. {
  1308. LLViewerInventoryItem* mItem;
  1309. LLUUID mImageID;
  1310. f(LLViewerInventoryItem* item, const LLUUID& id) : mItem(item), mImageID(id) {}
  1311. bool apply(LLViewerObject* objectp, S32 te)
  1312. {
  1313. if (mItem)
  1314. {
  1315. if (te == -1) // all faces
  1316. {
  1317. LLToolDragAndDrop::dropTextureAllFaces(objectp,
  1318. mItem,
  1319. LLToolDragAndDrop::SOURCE_AGENT,
  1320. LLUUID::null);
  1321. }
  1322. else // one face
  1323. {
  1324. LLToolDragAndDrop::dropTextureOneFace(objectp,
  1325. te,
  1326. mItem,
  1327. LLToolDragAndDrop::SOURCE_AGENT,
  1328. LLUUID::null);
  1329. }
  1330. }
  1331. else // not an inventory item
  1332. {
  1333. // Texture picker defaults aren't inventory items
  1334. // * Don't need to worry about permissions for them
  1335. // * Can just apply the texture and be done with it.
  1336. objectp->setTEImage(te, LLViewerTextureManager::getFetchedTexture(mImageID, TRUE, LLViewerTexture::BOOST_NONE, LLViewerTexture::LOD_TEXTURE));
  1337. }
  1338. return true;
  1339. }
  1340. } setfunc(item, imageid);
  1341. getSelection()->applyToTEs(&setfunc);
  1342. struct g : public LLSelectedObjectFunctor
  1343. {
  1344. LLViewerInventoryItem* mItem;
  1345. g(LLViewerInventoryItem* item) : mItem(item) {}
  1346. virtual bool apply(LLViewerObject* object)
  1347. {
  1348. if (!mItem)
  1349. {
  1350. object->sendTEUpdate();
  1351. // 1 particle effect per object
  1352. LLHUDEffectSpiral *effectp = (LLHUDEffectSpiral *)LLHUDManager::getInstance()->createViewerEffect(LLHUDObject::LL_HUD_EFFECT_BEAM, TRUE);
  1353. effectp->setSourceObject(gAgentAvatarp);
  1354. effectp->setTargetObject(object);
  1355. effectp->setDuration(LL_HUD_DUR_SHORT);
  1356. effectp->setColor(LLColor4U(gAgent.getEffectColor()));
  1357. }
  1358. return true;
  1359. }
  1360. } sendfunc(item);
  1361. getSelection()->applyToObjects(&sendfunc);
  1362. }
  1363. //-----------------------------------------------------------------------------
  1364. // selectionSetColor()
  1365. //-----------------------------------------------------------------------------
  1366. void LLSelectMgr::selectionSetColor(const LLColor4 &color)
  1367. {
  1368. struct f : public LLSelectedTEFunctor
  1369. {
  1370. LLColor4 mColor;
  1371. f(const LLColor4& c) : mColor(c) {}
  1372. bool apply(LLViewerObject* object, S32 te)
  1373. {
  1374. if (object->permModify())
  1375. {
  1376. object->setTEColor(te, mColor);
  1377. }
  1378. return true;
  1379. }
  1380. } setfunc(color);
  1381. getSelection()->applyToTEs(&setfunc);
  1382. LLSelectMgrSendFunctor sendfunc;
  1383. getSelection()->applyToObjects(&sendfunc);
  1384. }
  1385. //-----------------------------------------------------------------------------
  1386. // selectionSetColorOnly()
  1387. //-----------------------------------------------------------------------------
  1388. void LLSelectMgr::selectionSetColorOnly(const LLColor4 &color)
  1389. {
  1390. struct f : public LLSelectedTEFunctor
  1391. {
  1392. LLColor4 mColor;
  1393. f(const LLColor4& c) : mColor(c) {}
  1394. bool apply(LLViewerObject* object, S32 te)
  1395. {
  1396. if (object->permModify())
  1397. {
  1398. LLColor4 prev_color = object->getTE(te)->getColor();
  1399. mColor.mV[VALPHA] = prev_color.mV[VALPHA];
  1400. // update viewer side color in anticipation of update from simulator
  1401. object->setTEColor(te, mColor);
  1402. }
  1403. return true;
  1404. }
  1405. } setfunc(color);
  1406. getSelection()->applyToTEs(&setfunc);
  1407. LLSelectMgrSendFunctor sendfunc;
  1408. getSelection()->applyToObjects(&sendfunc);
  1409. }
  1410. //-----------------------------------------------------------------------------
  1411. // selectionSetAlphaOnly()
  1412. //-----------------------------------------------------------------------------
  1413. void LLSelectMgr::selectionSetAlphaOnly(const F32 alpha)
  1414. {
  1415. struct f : public LLSelectedTEFunctor
  1416. {
  1417. F32 mAlpha;
  1418. f(const F32& a) : mAlpha(a) {}
  1419. bool apply(LLViewerObject* object, S32 te)
  1420. {
  1421. if (object->permModify())
  1422. {
  1423. LLColor4 prev_color = object->getTE(te)->getColor();
  1424. prev_color.mV[VALPHA] = mAlpha;
  1425. // update viewer side color in anticipation of update from simulator
  1426. object->setTEColor(te, prev_color);
  1427. }
  1428. return true;
  1429. }
  1430. } setfunc(alpha);
  1431. getSelection()->applyToTEs(&setfunc);
  1432. LLSelectMgrSendFunctor sendfunc;
  1433. getSelection()->applyToObjects(&sendfunc);
  1434. }
  1435. void LLSelectMgr::selectionRevertColors()
  1436. {
  1437. struct f : public LLSelectedTEFunctor
  1438. {
  1439. LLObjectSelectionHandle mSelectedObjects;
  1440. f(LLObjectSelectionHandle sel) : mSelectedObjects(sel) {}
  1441. bool apply(LLViewerObject* object, S32 te)
  1442. {
  1443. if (object->permModify())
  1444. {
  1445. LLSelectNode* nodep = mSelectedObjects->findNode(object);
  1446. if (nodep && te < (S32)nodep->mSavedColors.size())
  1447. {
  1448. LLColor4 color = nodep->mSavedColors[te];
  1449. // update viewer side color in anticipation of update from simulator
  1450. object->setTEColor(te, color);
  1451. }
  1452. }
  1453. return true;
  1454. }
  1455. } setfunc(mSelectedObjects);
  1456. getSelection()->applyToTEs(&setfunc);
  1457. LLSelectMgrSendFunctor sendfunc;
  1458. getSelection()->applyToObjects(&sendfunc);
  1459. }
  1460. BOOL LLSelectMgr::selectionRevertTextures()
  1461. {
  1462. struct f : public LLSelectedTEFunctor
  1463. {
  1464. LLObjectSelectionHandle mSelectedObjects;
  1465. f(LLObjectSelectionHandle sel) : mSelectedObjects(sel) {}
  1466. bool apply(LLViewerObject* object, S32 te)
  1467. {
  1468. if (object->permModify())
  1469. {
  1470. LLSelectNode* nodep = mSelectedObjects->findNode(object);
  1471. if (nodep && te < (S32)nodep->mSavedTextures.size())
  1472. {
  1473. LLUUID id = nodep->mSavedTextures[te];
  1474. // update textures on viewer side
  1475. if (id.isNull())
  1476. {
  1477. // this was probably a no-copy texture, leave image as-is
  1478. return FALSE;
  1479. }
  1480. else
  1481. {
  1482. object->setTEImage(te, LLViewerTextureManager::getFetchedTexture(id, TRUE, LLViewerTexture::BOOST_NONE, LLViewerTexture::LOD_TEXTURE));
  1483. }
  1484. }
  1485. }
  1486. return true;
  1487. }
  1488. } setfunc(mSelectedObjects);
  1489. BOOL revert_successful = getSelection()->applyToTEs(&setfunc);
  1490. LLSelectMgrSendFunctor sendfunc;
  1491. getSelection()->applyToObjects(&sendfunc);
  1492. return revert_successful;
  1493. }
  1494. void LLSelectMgr::selectionSetBumpmap(U8 bumpmap)
  1495. {
  1496. struct f : public LLSelectedTEFunctor
  1497. {
  1498. U8 mBump;
  1499. f(const U8& b) : mBump(b) {}
  1500. bool apply(LLViewerObject* object, S32 te)
  1501. {
  1502. if (object->permModify())
  1503. {
  1504. // update viewer side color in anticipation of update from simulator
  1505. object->setTEBumpmap(te, mBump);
  1506. }
  1507. return true;
  1508. }
  1509. } setfunc(bumpmap);
  1510. getSelection()->applyToTEs(&setfunc);
  1511. LLSelectMgrSendFunctor sendfunc;
  1512. getSelection()->applyToObjects(&sendfunc);
  1513. }
  1514. void LLSelectMgr::selectionSetTexGen(U8 texgen)
  1515. {
  1516. struct f : public LLSelectedTEFunctor
  1517. {
  1518. U8 mTexgen;
  1519. f(const U8& t) : mTexgen(t) {}
  1520. bool apply(LLViewerObject* object, S32 te)
  1521. {
  1522. if (object->permModify())
  1523. {
  1524. // update viewer side color in anticipation of update from simulator
  1525. object->setTETexGen(te, mTexgen);
  1526. }
  1527. return true;
  1528. }
  1529. } setfunc(texgen);
  1530. getSelection()->applyToTEs(&setfunc);
  1531. LLSelectMgrSendFunctor sendfunc;
  1532. getSelection()->applyToObjects(&sendfunc);
  1533. }
  1534. void LLSelectMgr::selectionSetShiny(U8 shiny)
  1535. {
  1536. struct f : public LLSelectedTEFunctor
  1537. {
  1538. U8 mShiny;
  1539. f(const U8& t) : mShiny(t) {}
  1540. bool apply(LLViewerObject* object, S32 te)
  1541. {
  1542. if (object->permModify())
  1543. {
  1544. // update viewer side color in anticipation of update from simulator
  1545. object->setTEShiny(te, mShiny);
  1546. }
  1547. return true;
  1548. }
  1549. } setfunc(shiny);
  1550. getSelection()->applyToTEs(&setfunc);
  1551. LLSelectMgrSendFunctor sendfunc;
  1552. getSelection()->applyToObjects(&sendfunc);
  1553. }
  1554. void LLSelectMgr::selectionSetFullbright(U8 fullbright)
  1555. {
  1556. struct f : public LLSelectedTEFunctor
  1557. {
  1558. U8 mFullbright;
  1559. f(const U8& t) : mFullbright(t) {}
  1560. bool apply(LLViewerObject* object, S32 te)
  1561. {
  1562. if (object->permModify())
  1563. {
  1564. // update viewer side color in anticipation of update from simulator
  1565. object->setTEFullbright(te, mFullbright);
  1566. }
  1567. return true;
  1568. }
  1569. } setfunc(fullbright);
  1570. getSelection()->applyToTEs(&setfunc);
  1571. struct g : public LLSelectedObjectFunctor
  1572. {
  1573. U8 mFullbright;
  1574. g(const U8& t) : mFullbright(t) {}
  1575. virtual bool apply(LLViewerObject* object)
  1576. {
  1577. if (object->permModify())
  1578. {
  1579. object->sendTEUpdate();
  1580. if (mFullbright)
  1581. {
  1582. U8 material = object->getMaterial();
  1583. U8 mcode = material & LL_MCODE_MASK;
  1584. if (mcode == LL_MCODE_LIGHT)
  1585. {
  1586. mcode = LL_MCODE_GLASS;
  1587. material = (material & ~LL_MCODE_MASK) | mcode;
  1588. object->setMaterial(material);
  1589. object->sendMaterialUpdate();
  1590. }
  1591. }
  1592. }
  1593. return true;
  1594. }
  1595. } sendfunc(fullbright);
  1596. getSelection()->applyToObjects(&sendfunc);
  1597. }
  1598. // This function expects media_data to be a map containing relevant
  1599. // media data name/value pairs (e.g. home_url, etc.)
  1600. void LLSelectMgr::selectionSetMedia(U8 media_type, const LLSD &media_data)
  1601. {
  1602. struct f : public LLSelectedTEFunctor
  1603. {
  1604. U8 mMediaFlags;
  1605. const LLSD &mMediaData;
  1606. f(const U8& t, const LLSD& d) : mMediaFlags(t), mMediaData(d) {}
  1607. bool apply(LLViewerObject* object, S32 te)
  1608. {
  1609. if (object->permModify())
  1610. {
  1611. // If we are adding media, then check the current state of the
  1612. // media data on this face.
  1613. // - If it does not have media, AND we are NOT setting the HOME URL, then do NOT add media to this
  1614. // face.
  1615. // - If it does not have media, and we ARE setting the HOME URL, add media to this face.
  1616. // - If it does already have media, add/update media to/on this face
  1617. // If we are removing media, just do it (ignore the passed-in LLSD).
  1618. if (mMediaFlags & LLTextureEntry::MF_HAS_MEDIA)
  1619. {
  1620. llassert(mMediaData.isMap());
  1621. const LLTextureEntry *texture_entry = object->getTE(te);
  1622. if (!mMediaData.isMap() ||
  1623. (NULL != texture_entry) && !texture_entry->hasMedia() && !mMediaData.has(LLMediaEntry::HOME_URL_KEY))
  1624. {
  1625. // skip adding/updating media
  1626. }
  1627. else {
  1628. // Add/update media
  1629. object->setTEMediaFlags(te, mMediaFlags);
  1630. LLVOVolume *vo = dynamic_cast<LLVOVolume*>(object);
  1631. llassert(NULL != vo);
  1632. if (NULL != vo)
  1633. {
  1634. vo->syncMediaData(te, mMediaData, true/*merge*/, true/*ignore_agent*/);
  1635. }
  1636. }
  1637. }
  1638. else
  1639. {
  1640. // delete media (or just set the flags)
  1641. object->setTEMediaFlags(te, mMediaFlags);
  1642. }
  1643. }
  1644. return true;
  1645. }
  1646. } setfunc(media_type, media_data);
  1647. getSelection()->applyToTEs(&setfunc);
  1648. struct f2 : public LLSelectedObjectFunctor
  1649. {
  1650. virtual bool apply(LLViewerObject* object)
  1651. {
  1652. if (object->permModify())
  1653. {
  1654. object->sendTEUpdate();
  1655. LLVOVolume *vo = dynamic_cast<LLVOVolume*>(object);
  1656. llassert(NULL != vo);
  1657. // It's okay to skip this object if hasMedia() is false...
  1658. // the sendTEUpdate() above would remove all media data if it were
  1659. // there.
  1660. if (NULL != vo && vo->hasMedia())
  1661. {
  1662. // Send updated media data FOR THE ENTIRE OBJECT
  1663. vo->sendMediaDataUpdate();
  1664. }
  1665. }
  1666. return true;
  1667. }
  1668. } func2;
  1669. mSelectedObjects->applyToObjects( &func2 );
  1670. }
  1671. void LLSelectMgr::selectionSetGlow(F32 glow)
  1672. {
  1673. struct f1 : public LLSelectedTEFunctor
  1674. {
  1675. F32 mGlow;
  1676. f1(F32 glow) : mGlow(glow) {};
  1677. bool apply(LLViewerObject* object, S32 face)
  1678. {
  1679. if (object->permModify())
  1680. {
  1681. // update viewer side color in anticipation of update from simulator
  1682. object->setTEGlow(face, mGlow);
  1683. }
  1684. return true;
  1685. }
  1686. } func1(glow);
  1687. mSelectedObjects->applyToTEs( &func1 );
  1688. struct f2 : public LLSelectedObjectFunctor
  1689. {
  1690. virtual bool apply(LLViewerObject* object)
  1691. {
  1692. if (object->permModify())
  1693. {
  1694. object->sendTEUpdate();
  1695. }
  1696. return true;
  1697. }
  1698. } func2;
  1699. mSelectedObjects->applyToObjects( &func2 );
  1700. }
  1701. //-----------------------------------------------------------------------------
  1702. // findObjectPermissions()
  1703. //-----------------------------------------------------------------------------
  1704. LLPermissions* LLSelectMgr::findObjectPermissions(const LLViewerObject* object)
  1705. {
  1706. for (LLObjectSelection::valid_iterator iter = getSelection()->valid_begin();
  1707. iter != getSelection()->valid_end(); iter++ )
  1708. {
  1709. LLSelectNode* nodep = *iter;
  1710. if (nodep->getObject() == object)
  1711. {
  1712. return nodep->mPermissions;
  1713. }
  1714. }
  1715. return NULL;
  1716. }
  1717. //-----------------------------------------------------------------------------
  1718. // selectionGetGlow()
  1719. //-----------------------------------------------------------------------------
  1720. BOOL LLSelectMgr::selectionGetGlow(F32 *glow)
  1721. {
  1722. BOOL identical;
  1723. F32 lglow = 0.f;
  1724. struct f1 : public LLSelectedTEGetFunctor<F32>
  1725. {
  1726. F32 get(LLViewerObject* object, S32 face)
  1727. {
  1728. return object->getTE(face)->getGlow();
  1729. }
  1730. } func;
  1731. identical = mSelectedObjects->getSelectedTEValue( &func, lglow );
  1732. *glow = lglow;
  1733. return identical;
  1734. }
  1735. void LLSelectMgr::selectionSetPhysicsType(U8 type)
  1736. {
  1737. struct f : public LLSelectedObjectFunctor
  1738. {
  1739. U8 mType;
  1740. f(const U8& t) : mType(t) {}
  1741. virtual bool apply(LLViewerObject* object)
  1742. {
  1743. if (object->permModify())
  1744. {
  1745. object->setPhysicsShapeType(mType);
  1746. object->updateFlags(TRUE);
  1747. }
  1748. return true;
  1749. }
  1750. } sendfunc(type);
  1751. getSelection()->applyToObjects(&sendfunc);
  1752. }
  1753. void LLSelectMgr::selectionSetFriction(F32 friction)
  1754. {
  1755. struct f : public LLSelectedObjectFunctor
  1756. {
  1757. F32 mFriction;
  1758. f(const F32& friction) : mFriction(friction) {}
  1759. virtual bool apply(LLViewerObject* object)
  1760. {
  1761. if (object->permModify())
  1762. {
  1763. object->setPhysicsFriction(mFriction);
  1764. object->updateFlags(TRUE);
  1765. }
  1766. return true;
  1767. }
  1768. } sendfunc(friction);
  1769. getSelection()->applyToObjects(&sendfunc);
  1770. }
  1771. void LLSelectMgr::selectionSetGravity(F32 gravity )
  1772. {
  1773. struct f : public LLSelectedObjectFunctor
  1774. {
  1775. F32 mGravity;
  1776. f(const F32& gravity) : mGravity(gravity) {}
  1777. virtual bool apply(LLViewerObject* object)
  1778. {
  1779. if (object->permModify())
  1780. {
  1781. object->setPhysicsGravity(mGravity);
  1782. object->updateFlags(TRUE);
  1783. }
  1784. return true;
  1785. }
  1786. } sendfunc(gravity);
  1787. getSelection()->applyToObjects(&sendfunc);
  1788. }
  1789. void LLSelectMgr::selectionSetDensity(F32 density )
  1790. {
  1791. struct f : public LLSelectedObjectFunctor
  1792. {
  1793. F32 mDensity;
  1794. f(const F32& density ) : mDensity(density) {}
  1795. virtual bool apply(LLViewerObject* object)
  1796. {
  1797. if (object->permModify())
  1798. {
  1799. object->setPhysicsDensity(mDensity);
  1800. object->updateFlags(TRUE);
  1801. }
  1802. return true;
  1803. }
  1804. } sendfunc(density);
  1805. getSelection()->applyToObjects(&sendfunc);
  1806. }
  1807. void LLSelectMgr::selectionSetRestitution(F32 restitution)
  1808. {
  1809. struct f : public LLSelectedObjectFunctor
  1810. {
  1811. F32 mRestitution;
  1812. f(const F32& restitution ) : mRestitution(restitution) {}
  1813. virtual bool apply(LLViewerObject* object)
  1814. {
  1815. if (object->permModify())
  1816. {
  1817. object->setPhysicsRestitution(mRestitution);
  1818. object->updateFlags(TRUE);
  1819. }
  1820. return true;
  1821. }
  1822. } sendfunc(restitution);
  1823. getSelection()->applyToObjects(&sendfunc);
  1824. }
  1825. //-----------------------------------------------------------------------------
  1826. // selectionSetMaterial()
  1827. //-----------------------------------------------------------------------------
  1828. void LLSelectMgr::selectionSetMaterial(U8 material)
  1829. {
  1830. struct f : public LLSelectedObjectFunctor
  1831. {
  1832. U8 mMaterial;
  1833. f(const U8& t) : mMaterial(t) {}
  1834. virtual bool apply(LLViewerObject* object)
  1835. {
  1836. if (object->permModify())
  1837. {
  1838. U8 cur_material = object->getMaterial();
  1839. U8 material = mMaterial | (cur_material & ~LL_MCODE_MASK);
  1840. object->setMaterial(material);
  1841. object->sendMaterialUpdate();
  1842. }
  1843. return true;
  1844. }
  1845. } sendfunc(material);
  1846. getSelection()->applyToObjects(&sendfunc);
  1847. }
  1848. // TRUE if all selected objects have this PCode
  1849. BOOL LLSelectMgr::selectionAllPCode(LLPCode code)
  1850. {
  1851. struct f : public LLSelectedObjectFunctor
  1852. {
  1853. LLPCode mCode;
  1854. f(const LLPCode& t) : mCode(t) {}
  1855. virtual bool apply(LLViewerObject* object)
  1856. {
  1857. if (object->getPCode() != mCode)
  1858. {
  1859. return FALSE;
  1860. }
  1861. return true;
  1862. }
  1863. } func(code);
  1864. BOOL res = getSelection()->applyToObjects(&func);
  1865. return res;
  1866. }
  1867. bool LLSelectMgr::selectionGetIncludeInSearch(bool* include_in_search_out)
  1868. {
  1869. LLViewerObject *object = mSelectedObjects->getFirstRootObject();
  1870. if (!object) return FALSE;
  1871. bool include_in_search = object->getIncludeInSearch();
  1872. bool identical = true;
  1873. for (LLObjectSelection::root_iterator iter = getSelection()->root_begin();
  1874. iter != getSelection()->root_end(); iter++)
  1875. {
  1876. LLViewerObject* object = (*iter)->getObject();
  1877. if ( include_in_search != object->getIncludeInSearch())
  1878. {
  1879. identical = false;
  1880. break;
  1881. }
  1882. }
  1883. *include_in_search_out = include_in_search;
  1884. return identical;
  1885. }
  1886. void LLSelectMgr::selectionSetIncludeInSearch(bool include_in_search)
  1887. {
  1888. LLViewerObject* object = NULL;
  1889. for (LLObjectSelection::root_iterator iter = getSelection()->root_begin();
  1890. iter != getSelection()->root_end(); iter++)
  1891. {
  1892. object = (*iter)->getObject();
  1893. object->setIncludeInSearch(include_in_search);
  1894. }
  1895. sendListToRegions(
  1896. "ObjectIncludeInSearch",
  1897. packAgentAndSessionID,
  1898. packObjectIncludeInSearch,
  1899. &include_in_search,
  1900. SEND_ONLY_ROOTS);
  1901. }
  1902. BOOL LLSelectMgr::selectionGetClickAction(U8 *out_action)
  1903. {
  1904. LLViewerObject *object = mSelectedObjects->getFirstObject();
  1905. if (!object)
  1906. {
  1907. return FALSE;
  1908. }
  1909. U8 action = object->getClickAction();
  1910. *out_action = action;
  1911. struct f : public LLSelectedObjectFunctor
  1912. {
  1913. U8 mAction;
  1914. f(const U8& t) : mAction(t) {}
  1915. virtual bool apply(LLViewerObject* object)
  1916. {
  1917. if ( mAction != object->getClickAction())
  1918. {
  1919. return false;
  1920. }
  1921. return true;
  1922. }
  1923. } func(action);
  1924. BOOL res = getSelection()->applyToObjects(&func);
  1925. return res;
  1926. }
  1927. void LLSelectMgr::selectionSetClickAction(U8 action)
  1928. {
  1929. struct f : public LLSelectedObjectFunctor
  1930. {
  1931. U8 mAction;
  1932. f(const U8& t) : mAction(t) {}
  1933. virtual bool apply(LLViewerObject* object)
  1934. {
  1935. object->setClickAction(mAction);
  1936. return true;
  1937. }
  1938. } func(action);
  1939. getSelection()->applyToObjects(&func);
  1940. sendListToRegions("ObjectClickAction",
  1941. packAgentAndSessionID,
  1942. packObjectClickAction,
  1943. &action,
  1944. SEND_INDIVIDUALS);
  1945. }
  1946. //-----------------------------------------------------------------------------
  1947. // godlike requests
  1948. //-----------------------------------------------------------------------------
  1949. typedef std::pair<const std::string, const std::string> godlike_request_t;
  1950. void LLSelectMgr::sendGodlikeRequest(const std::string& request, const std::string& param)
  1951. {
  1952. // If the agent is neither godlike nor an estate owner, the server
  1953. // will reject the request.
  1954. std::string message_type;
  1955. if (gAgent.isGodlike())
  1956. {
  1957. message_type = "GodlikeMessage";
  1958. }
  1959. else
  1960. {
  1961. message_type = "EstateOwnerMessage";
  1962. }
  1963. godlike_request_t data(request, param);
  1964. if(!mSelectedObjects->getRootObjectCount())
  1965. {
  1966. LLMessageSystem* msg = gMessageSystem;
  1967. msg->newMessage(message_type.c_str());
  1968. LLSelectMgr::packGodlikeHead(&data);
  1969. gAgent.sendReliableMessage();
  1970. }
  1971. else
  1972. {
  1973. sendListToRegions(message_type, packGodlikeHead, packObjectIDAsParam, &data, SEND_ONLY_ROOTS);
  1974. }
  1975. }
  1976. void LLSelectMgr::packGodlikeHead(void* user_data)
  1977. {
  1978. LLMessageSystem* msg = gMessageSystem;
  1979. msg->nextBlockFast(_PREHASH_AgentData);
  1980. msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
  1981. msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
  1982. msg->addUUID("TransactionID", LLUUID::null);
  1983. godlike_request_t* data = (godlike_request_t*)user_data;
  1984. msg->nextBlock("MethodData");
  1985. msg->addString("Method", data->first);
  1986. msg->addUUID("Invoice", LLUUID::null);
  1987. // The parameters used to be restricted to either string or
  1988. // integer. This mimics that behavior under the new 'string-only'
  1989. // parameter list by not packing a string if there wasn't one
  1990. // specified. The object ids will be packed in the
  1991. // packObjectIDAsParam() method.
  1992. if(data->second.size() > 0)
  1993. {
  1994. msg->nextBlock("ParamList");
  1995. msg->addString("Parameter", data->second);
  1996. }
  1997. }
  1998. // static
  1999. void LLSelectMgr::packObjectIDAsParam(LLSelectNode* node, void *)
  2000. {
  2001. std::string buf = llformat("%u", node->getObject()->getLocalID());
  2002. gMessageSystem->nextBlock("ParamList");
  2003. gMessageSystem->addString("Parameter", buf);
  2004. }
  2005. //-----------------------------------------------------------------------------
  2006. // Rotation options
  2007. //-----------------------------------------------------------------------------
  2008. void LLSelectMgr::selectionResetRotation()
  2009. {
  2010. struct f : public LLSelectedObjectFunctor
  2011. {
  2012. virtual bool apply(LLViewerObject* object)
  2013. {
  2014. LLQuaternion identity(0.f, 0.f, 0.f, 1.f);
  2015. object->setRotation(identity);
  2016. if (object->mDrawable.notNull())
  2017. {
  2018. gPipeline.markMoved(object->mDrawable, TRUE);
  2019. }
  2020. object->sendRotationUpdate();
  2021. return true;
  2022. }
  2023. } func;
  2024. getSelection()->applyToRootObjects(&func);
  2025. }
  2026. void LLSelectMgr::selectionRotateAroundZ(F32 degrees)
  2027. {
  2028. LLQuaternion rot( degrees * DEG_TO_RAD, LLVector3(0,0,1) );
  2029. struct f : public LLSelectedObjectFunctor
  2030. {
  2031. LLQuaternion mRot;
  2032. f(const LLQuaternion& rot) : mRot(rot) {}
  2033. virtual bool apply(LLViewerObject* object)
  2034. {
  2035. object->setRotation( object->getRotationEdit() * mRot );
  2036. if (object->mDrawable.notNull())
  2037. {
  2038. gPipeline.markMoved(object->mDrawable, TRUE);
  2039. }
  2040. object->sendRotationUpdate();
  2041. return true;
  2042. }
  2043. } func(rot);
  2044. getSelection()->applyToRootObjects(&func);
  2045. }
  2046. //-----------------------------------------------------------------------------
  2047. // selectionTexScaleAutofit()
  2048. //-----------------------------------------------------------------------------
  2049. void LLSelectMgr::selectionTexScaleAutofit(F32 repeats_per_meter)
  2050. {
  2051. struct f : public LLSelectedTEFunctor
  2052. {
  2053. F32 mRepeatsPerMeter;
  2054. f(const F32& t) : mRepeatsPerMeter(t) {}
  2055. bool apply(LLViewerObject* object, S32 te)
  2056. {
  2057. if (object->permModify())
  2058. {
  2059. // Compute S,T to axis mapping
  2060. U32 s_axis, t_axis;
  2061. if (!LLPrimitive::getTESTAxes(te, &s_axis, &t_axis))
  2062. {
  2063. return TRUE;
  2064. }
  2065. F32 new_s = object->getScale().mV[s_axis] * mRepeatsPerMeter;
  2066. F32 new_t = object->getScale().mV[t_axis] * mRepeatsPerMeter;
  2067. object->setTEScale(te, new_s, new_t);
  2068. }
  2069. return true;
  2070. }
  2071. } setfunc(repeats_per_meter);
  2072. getSelection()->applyToTEs(&setfunc);
  2073. LLSelectMgrSendFunctor sendfunc;
  2074. getSelection()->applyToObjects(&sendfunc);
  2075. }
  2076. // Called at the end of a scale operation, this adjusts the textures to attempt to
  2077. // maintain a constant repeats per meter.
  2078. // BUG: Only works for flex boxes.
  2079. //-----------------------------------------------------------------------------
  2080. // adjustTexturesByScale()
  2081. //-----------------------------------------------------------------------------
  2082. void LLSelectMgr::adjustTexturesByScale(BOOL send_to_sim, BOOL stretch)
  2083. {
  2084. for (LLObjectSelection::iterator iter = getSelection()->begin();
  2085. iter != getSelection()->end(); iter++)
  2086. {
  2087. LLSelectNode* selectNode = *iter;
  2088. LLViewerObject* object = selectNode->getObject();
  2089. if (!object)
  2090. {
  2091. continue;
  2092. }
  2093. if (!object->permModify())
  2094. {
  2095. continue;
  2096. }
  2097. if (object->getNumTEs() == 0)
  2098. {
  2099. continue;
  2100. }
  2101. BOOL send = FALSE;
  2102. for (U8 te_num = 0; te_num < object->getNumTEs(); te_num++)
  2103. {
  2104. const LLTextureEntry* tep = object->getTE(te_num);
  2105. BOOL planar = tep->getTexGen() == LLTextureEntry::TEX_GEN_PLANAR;
  2106. if (planar == stretch)
  2107. {
  2108. // Figure out how S,T changed with scale operation
  2109. U32 s_axis, t_axis;
  2110. if (!LLPrimitive::getTESTAxes(te_num, &s_axis, &t_axis))
  2111. {
  2112. continue;
  2113. }
  2114. LLVector3 scale_ratio = selectNode->mTextureScaleRatios[te_num];
  2115. LLVector3 object_sca