lltoolselect.cpp

Go to the documentation of this file.
00001 
00032 #include "llviewerprecompiledheaders.h"
00033 
00034 #include "lltoolselect.h"
00035 
00036 #include "llagent.h"
00037 #include "llviewercontrol.h"
00038 #include "lldrawable.h"
00039 #include "llmanip.h"
00040 #include "llmenugl.h"
00041 #include "llselectmgr.h"
00042 #include "lltoolmgr.h"
00043 #include "llfloaterscriptdebug.h"
00044 #include "llviewercamera.h"
00045 #include "llviewermenu.h"
00046 #include "llviewerobject.h"
00047 #include "llviewerobjectlist.h" 
00048 #include "llviewerregion.h" 
00049 #include "llviewerwindow.h"
00050 #include "llvoavatar.h"
00051 #include "llworld.h"
00052 #include "viewer.h"                             // for gFPSClamped, pie menus
00053 
00054 // Globals
00055 LLToolSelect            *gToolSelect = NULL;
00056 extern BOOL gAllowSelectAvatar;
00057 
00058 const F32 SELECTION_ROTATION_TRESHOLD = 0.1f;
00059 
00060 LLToolSelect::LLToolSelect( LLToolComposite* composite )
00061 :       LLTool( "Select", composite ),
00062         mIgnoreGroup( FALSE )
00063 {
00064  }
00065 
00066 // True if you selected an object.
00067 BOOL LLToolSelect::handleMouseDown(S32 x, S32 y, MASK mask)
00068 {
00069         BOOL handled = FALSE;
00070 
00071         // didn't click in any UI object, so must have clicked in the world
00072         LLViewerObject* object = NULL;
00073 
00074         // You must hit the body for this tool to think you hit the object.
00075         object = gObjectList.findObject( gLastHitObjectID );
00076 
00077         if (object)
00078         {
00079                 mSelectObjectID = object->getID();
00080                 handled = TRUE;
00081         }
00082         else
00083         {
00084                 mSelectObjectID.setNull();
00085         }
00086 
00087         // Pass mousedown to agent
00088         LLTool::handleMouseDown(x, y, mask);
00089 
00090         return handled;
00091 }
00092 
00093 BOOL LLToolSelect::handleDoubleClick(S32 x, S32 y, MASK mask)
00094 {
00095         //RN: double click to toggle individual/linked picking???
00096         return LLTool::handleDoubleClick(x, y, mask);
00097 }
00098 
00099 // static
00100 LLHandle<LLObjectSelection> LLToolSelect::handleObjectSelection(LLViewerObject *object, MASK mask, BOOL ignore_group, BOOL temp_select)
00101 {
00102         BOOL select_owned = gSavedSettings.getBOOL("SelectOwnedOnly");
00103         BOOL select_movable = gSavedSettings.getBOOL("SelectMovableOnly");
00104         
00105         // *NOTE: These settings must be cleaned up at bottom of function.
00106         if (temp_select || gAllowSelectAvatar)
00107         {
00108                 gSavedSettings.setBOOL("SelectOwnedOnly", FALSE);
00109                 gSavedSettings.setBOOL("SelectMovableOnly", FALSE);
00110                 gSelectMgr->setForceSelection(TRUE);
00111         }
00112 
00113         BOOL extend_select = (mask == MASK_SHIFT) || (mask == MASK_CONTROL);
00114 
00115         // If no object, check for icon, then just deselect
00116         if (!object)
00117         {
00118                 if (gLastHitHUDIcon && gLastHitHUDIcon->getSourceObject())
00119                 {
00120                         LLFloaterScriptDebug::show(gLastHitHUDIcon->getSourceObject()->getID());
00121                 }
00122                 else if (!extend_select)
00123                 {
00124                         gSelectMgr->deselectAll();
00125                 }
00126         }
00127         else
00128         {
00129                 BOOL already_selected = object->isSelected();
00130 
00131                 if ( extend_select )
00132                 {
00133                         if ( already_selected )
00134                         {
00135                                 if ( ignore_group )
00136                                 {
00137                                         gSelectMgr->deselectObjectOnly(object);
00138                                 }
00139                                 else
00140                                 {
00141                                         gSelectMgr->deselectObjectAndFamily(object, TRUE, TRUE);
00142                                 }
00143                         }
00144                         else
00145                         {
00146                                 if ( ignore_group )
00147                                 {
00148                                         gSelectMgr->selectObjectOnly(object, SELECT_ALL_TES);
00149                                 }
00150                                 else
00151                                 {
00152                                         gSelectMgr->selectObjectAndFamily(object);
00153                                 }
00154                         }
00155                 }
00156                 else
00157                 {
00158                         // Save the current zoom values because deselect resets them.
00159                         F32 target_zoom;
00160                         F32 current_zoom;
00161                         gSelectMgr->getAgentHUDZoom(target_zoom, current_zoom);
00162 
00163                         // JC - Change behavior to make it easier to select children
00164                         // of linked sets. 9/3/2002
00165                         if( !already_selected || ignore_group)
00166                         {
00167                                 // ...lose current selection in favor of just this object
00168                                 gSelectMgr->deselectAll();
00169                         }
00170 
00171                         if ( ignore_group )
00172                         {
00173                                 gSelectMgr->selectObjectOnly(object, SELECT_ALL_TES);
00174                         }
00175                         else
00176                         {
00177                                 gSelectMgr->selectObjectAndFamily(object);
00178                         }
00179 
00180                         // restore the zoom to the previously stored values.
00181                         gSelectMgr->setAgentHUDZoom(target_zoom, current_zoom);
00182                 }
00183 
00184                 if (!gAgent.getFocusOnAvatar() &&                                                                               // if camera not glued to avatar
00185                         LLVOAvatar::findAvatarFromAttachment(object) != gAgent.getAvatarObject() &&     // and it's not one of your attachments
00186                         object != gAgent.getAvatarObject())                                                                     // and it's not you
00187                 {
00188                         // have avatar turn to face the selected object(s)
00189                         LLVector3d selection_center = gSelectMgr->getSelectionCenterGlobal();
00190                         selection_center = selection_center - gAgent.getPositionGlobal();
00191                         LLVector3 selection_dir;
00192                         selection_dir.setVec(selection_center);
00193                         selection_dir.mV[VZ] = 0.f;
00194                         selection_dir.normVec();
00195                         if (!object->isAvatar() && gAgent.getAtAxis() * selection_dir < 0.6f)
00196                         {
00197                                 LLQuaternion target_rot;
00198                                 target_rot.shortestArc(LLVector3::x_axis, selection_dir);
00199                                 gAgent.startAutoPilotGlobal(gAgent.getPositionGlobal(), "", &target_rot, NULL, NULL, 1.f, SELECTION_ROTATION_TRESHOLD);
00200                         }
00201                 }
00202 
00203                 if (temp_select)
00204                 {
00205                         if (!already_selected)
00206                         {
00207                                 LLViewerObject* root_object = (LLViewerObject*)object->getRootEdit();
00208                                 LLObjectSelectionHandle selection = gSelectMgr->getSelection();
00209 
00210                                 // this is just a temporary selection
00211                                 LLSelectNode* select_node = selection->findNode(root_object);
00212                                 if (select_node)
00213                                 {
00214                                         select_node->setTransient(TRUE);
00215                                 }
00216 
00217                                 for (S32 i = 0; i < (S32)root_object->mChildList.size(); i++)
00218                                 {
00219                                         select_node = selection->findNode(root_object->mChildList[i]);
00220                                         if (select_node)
00221                                         {
00222                                                 select_node->setTransient(TRUE);
00223                                         }
00224                                 }
00225 
00226                         }
00227                 } //if(temp_select)
00228         } //if(!object)
00229 
00230         // Cleanup temp select settings above.
00231         if (temp_select || gAllowSelectAvatar)
00232         {
00233                 gSavedSettings.setBOOL("SelectOwnedOnly", select_owned);
00234                 gSavedSettings.setBOOL("SelectMovableOnly", select_movable);
00235                 gSelectMgr->setForceSelection(FALSE);
00236         }
00237 
00238         return gSelectMgr->getSelection();
00239 }
00240 
00241 BOOL LLToolSelect::handleMouseUp(S32 x, S32 y, MASK mask)
00242 {
00243         mIgnoreGroup = gSavedSettings.getBOOL("EditLinkedParts");
00244 
00245         LLViewerObject* object = gObjectList.findObject(mSelectObjectID);
00246         LLToolSelect::handleObjectSelection(object, mask, mIgnoreGroup, FALSE);
00247 
00248         return LLTool::handleMouseUp(x, y, mask);
00249 }
00250 
00251 void LLToolSelect::handleDeselect()
00252 {
00253         if(     hasMouseCapture() )
00254         {
00255                 setMouseCapture( FALSE );  // Calls onMouseCaptureLost() indirectly
00256         }
00257 }
00258 
00259 
00260 void LLToolSelect::stopEditing()
00261 {
00262         if(     hasMouseCapture() )
00263         {
00264                 setMouseCapture( FALSE );  // Calls onMouseCaptureLost() indirectly
00265         }
00266 }
00267 
00268 void LLToolSelect::onMouseCaptureLost()
00269 {
00270         // Finish drag
00271 
00272         gSelectMgr->enableSilhouette(TRUE);
00273 
00274         // Clean up drag-specific variables
00275         mIgnoreGroup = FALSE;
00276 }
00277 
00278 

Generated on Thu Jul 1 06:09:22 2010 for Second Life Viewer by  doxygen 1.4.7