PageRenderTime 27ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/newview/lltoolselect.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 263 lines | 181 code | 39 blank | 43 comment | 32 complexity | 264ca01111dacb2050d6a9f438149a4f MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file lltoolselect.cpp
  3. * @brief LLToolSelect class implementation
  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. #include "lltoolselect.h"
  28. #include "llagent.h"
  29. #include "llagentcamera.h"
  30. #include "llviewercontrol.h"
  31. #include "lldrawable.h"
  32. #include "llmanip.h"
  33. #include "llmenugl.h"
  34. #include "llselectmgr.h"
  35. #include "lltoolmgr.h"
  36. #include "llfloaterscriptdebug.h"
  37. #include "llviewercamera.h"
  38. #include "llviewermenu.h"
  39. #include "llviewerobject.h"
  40. #include "llviewerobjectlist.h"
  41. #include "llviewerregion.h"
  42. #include "llviewerwindow.h"
  43. #include "llvoavatarself.h"
  44. #include "llworld.h"
  45. // Globals
  46. //extern BOOL gAllowSelectAvatar;
  47. const F32 SELECTION_ROTATION_TRESHOLD = 0.1f;
  48. LLToolSelect::LLToolSelect( LLToolComposite* composite )
  49. : LLTool( std::string("Select"), composite ),
  50. mIgnoreGroup( FALSE )
  51. {
  52. }
  53. // True if you selected an object.
  54. BOOL LLToolSelect::handleMouseDown(S32 x, S32 y, MASK mask)
  55. {
  56. // do immediate pick query
  57. mPick = gViewerWindow->pickImmediate(x, y, TRUE);
  58. // Pass mousedown to agent
  59. LLTool::handleMouseDown(x, y, mask);
  60. return mPick.getObject().notNull();
  61. }
  62. // static
  63. LLObjectSelectionHandle LLToolSelect::handleObjectSelection(const LLPickInfo& pick, BOOL ignore_group, BOOL temp_select, BOOL select_root)
  64. {
  65. LLViewerObject* object = pick.getObject();
  66. if (select_root)
  67. {
  68. object = object->getRootEdit();
  69. }
  70. BOOL select_owned = gSavedSettings.getBOOL("SelectOwnedOnly");
  71. BOOL select_movable = gSavedSettings.getBOOL("SelectMovableOnly");
  72. // *NOTE: These settings must be cleaned up at bottom of function.
  73. if (temp_select || LLSelectMgr::getInstance()->mAllowSelectAvatar)
  74. {
  75. gSavedSettings.setBOOL("SelectOwnedOnly", FALSE);
  76. gSavedSettings.setBOOL("SelectMovableOnly", FALSE);
  77. LLSelectMgr::getInstance()->setForceSelection(TRUE);
  78. }
  79. BOOL extend_select = (pick.mKeyMask == MASK_SHIFT) || (pick.mKeyMask == MASK_CONTROL);
  80. // If no object, check for icon, then just deselect
  81. if (!object)
  82. {
  83. LLHUDIcon* last_hit_hud_icon = pick.mHUDIcon;
  84. if (last_hit_hud_icon && last_hit_hud_icon->getSourceObject())
  85. {
  86. LLFloaterScriptDebug::show(last_hit_hud_icon->getSourceObject()->getID());
  87. }
  88. else if (!extend_select)
  89. {
  90. LLSelectMgr::getInstance()->deselectAll();
  91. }
  92. }
  93. else
  94. {
  95. BOOL already_selected = object->isSelected();
  96. if ( extend_select )
  97. {
  98. if ( already_selected )
  99. {
  100. if ( ignore_group )
  101. {
  102. LLSelectMgr::getInstance()->deselectObjectOnly(object);
  103. }
  104. else
  105. {
  106. LLSelectMgr::getInstance()->deselectObjectAndFamily(object, TRUE, TRUE);
  107. }
  108. }
  109. else
  110. {
  111. if ( ignore_group )
  112. {
  113. LLSelectMgr::getInstance()->selectObjectOnly(object, SELECT_ALL_TES);
  114. }
  115. else
  116. {
  117. LLSelectMgr::getInstance()->selectObjectAndFamily(object);
  118. }
  119. }
  120. }
  121. else
  122. {
  123. // Save the current zoom values because deselect resets them.
  124. F32 target_zoom;
  125. F32 current_zoom;
  126. LLSelectMgr::getInstance()->getAgentHUDZoom(target_zoom, current_zoom);
  127. // JC - Change behavior to make it easier to select children
  128. // of linked sets. 9/3/2002
  129. if( !already_selected || ignore_group)
  130. {
  131. // ...lose current selection in favor of just this object
  132. LLSelectMgr::getInstance()->deselectAll();
  133. }
  134. if ( ignore_group )
  135. {
  136. LLSelectMgr::getInstance()->selectObjectOnly(object, SELECT_ALL_TES);
  137. }
  138. else
  139. {
  140. LLSelectMgr::getInstance()->selectObjectAndFamily(object);
  141. }
  142. // restore the zoom to the previously stored values.
  143. LLSelectMgr::getInstance()->setAgentHUDZoom(target_zoom, current_zoom);
  144. }
  145. if (!gAgentCamera.getFocusOnAvatar() && // if camera not glued to avatar
  146. LLVOAvatar::findAvatarFromAttachment(object) != gAgentAvatarp && // and it's not one of your attachments
  147. object != gAgentAvatarp) // and it's not you
  148. {
  149. // have avatar turn to face the selected object(s)
  150. LLVector3d selection_center = LLSelectMgr::getInstance()->getSelectionCenterGlobal();
  151. selection_center = selection_center - gAgent.getPositionGlobal();
  152. LLVector3 selection_dir;
  153. selection_dir.setVec(selection_center);
  154. selection_dir.mV[VZ] = 0.f;
  155. selection_dir.normVec();
  156. if (!object->isAvatar() && gAgent.getAtAxis() * selection_dir < 0.6f)
  157. {
  158. LLQuaternion target_rot;
  159. target_rot.shortestArc(LLVector3::x_axis, selection_dir);
  160. gAgent.startAutoPilotGlobal(gAgent.getPositionGlobal(), "", &target_rot, NULL, NULL, 1.f, SELECTION_ROTATION_TRESHOLD);
  161. }
  162. }
  163. if (temp_select)
  164. {
  165. if (!already_selected)
  166. {
  167. LLViewerObject* root_object = (LLViewerObject*)object->getRootEdit();
  168. LLObjectSelectionHandle selection = LLSelectMgr::getInstance()->getSelection();
  169. // this is just a temporary selection
  170. LLSelectNode* select_node = selection->findNode(root_object);
  171. if (select_node)
  172. {
  173. select_node->setTransient(TRUE);
  174. }
  175. LLViewerObject::const_child_list_t& child_list = root_object->getChildren();
  176. for (LLViewerObject::child_list_t::const_iterator iter = child_list.begin();
  177. iter != child_list.end(); iter++)
  178. {
  179. LLViewerObject* child = *iter;
  180. select_node = selection->findNode(child);
  181. if (select_node)
  182. {
  183. select_node->setTransient(TRUE);
  184. }
  185. }
  186. }
  187. } //if(temp_select)
  188. } //if(!object)
  189. // Cleanup temp select settings above.
  190. if (temp_select ||LLSelectMgr::getInstance()->mAllowSelectAvatar)
  191. {
  192. gSavedSettings.setBOOL("SelectOwnedOnly", select_owned);
  193. gSavedSettings.setBOOL("SelectMovableOnly", select_movable);
  194. LLSelectMgr::getInstance()->setForceSelection(FALSE);
  195. }
  196. return LLSelectMgr::getInstance()->getSelection();
  197. }
  198. BOOL LLToolSelect::handleMouseUp(S32 x, S32 y, MASK mask)
  199. {
  200. mIgnoreGroup = gSavedSettings.getBOOL("EditLinkedParts");
  201. handleObjectSelection(mPick, mIgnoreGroup, FALSE);
  202. return LLTool::handleMouseUp(x, y, mask);
  203. }
  204. void LLToolSelect::handleDeselect()
  205. {
  206. if( hasMouseCapture() )
  207. {
  208. setMouseCapture( FALSE ); // Calls onMouseCaptureLost() indirectly
  209. }
  210. }
  211. void LLToolSelect::stopEditing()
  212. {
  213. if( hasMouseCapture() )
  214. {
  215. setMouseCapture( FALSE ); // Calls onMouseCaptureLost() indirectly
  216. }
  217. }
  218. void LLToolSelect::onMouseCaptureLost()
  219. {
  220. // Finish drag
  221. LLSelectMgr::getInstance()->enableSilhouette(TRUE);
  222. // Clean up drag-specific variables
  223. mIgnoreGroup = FALSE;
  224. }