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