lltoolplacer.cpp

Go to the documentation of this file.
00001 
00032 #include "llviewerprecompiledheaders.h"
00033 
00034 // self header
00035 #include "lltoolplacer.h"
00036 
00037 // linden library headers
00038 #include "llprimitive.h"
00039 
00040 // viewer headers
00041 #include "llbutton.h"
00042 #include "llviewercontrol.h"
00043 #include "llfirstuse.h"
00044 #include "llfloatertools.h"
00045 #include "llselectmgr.h"
00046 #include "llstatusbar.h"
00047 #include "lltoolcomp.h"
00048 #include "lltoolmgr.h"
00049 #include "llviewerobject.h"
00050 #include "llviewerregion.h"
00051 #include "llviewerwindow.h"
00052 #include "llworld.h"
00053 #include "viewer.h"
00054 #include "llui.h"
00055 
00056 //static 
00057 LLPCode LLToolPlacer::sObjectType = LL_PCODE_CUBE;
00058 
00059 LLToolPlacer::LLToolPlacer()
00060 :       LLTool( "Create" )
00061 {
00062 }
00063 
00064 // Used by the placer tool to add copies of the current selection.
00065 // Inspired by add_object().  JC
00066 BOOL add_duplicate(S32 x, S32 y)
00067 {
00068         LLVector3 ray_start_region;
00069         LLVector3 ray_end_region;
00070         LLViewerRegion* regionp = NULL;
00071         BOOL b_hit_land = FALSE;
00072         S32 hit_face = -1;
00073         LLViewerObject* hit_obj = NULL;
00074         BOOL success = raycast_for_new_obj_pos( x, y, &hit_obj, &hit_face, &b_hit_land, &ray_start_region, &ray_end_region, &regionp );
00075         if( !success )
00076         {
00077                 make_ui_sound("UISndInvalidOp");
00078                 return FALSE;
00079         }
00080         if( hit_obj && (hit_obj->isAvatar() || hit_obj->isAttachment()) )
00081         {
00082                 // Can't create objects on avatars or attachments
00083                 make_ui_sound("UISndInvalidOp");
00084                 return FALSE;
00085         }
00086 
00087 
00088         // Limit raycast to a single object.  
00089         // Speeds up server raycast + avoid problems with server ray hitting objects
00090         // that were clipped by the near plane or culled on the viewer.
00091         LLUUID ray_target_id;
00092         if( hit_obj )
00093         {
00094                 ray_target_id = hit_obj->getID();
00095         }
00096         else
00097         {
00098                 ray_target_id.setNull();
00099         }
00100 
00101         gSelectMgr->selectDuplicateOnRay(ray_start_region,
00102                                                                                 ray_end_region,
00103                                                                                 b_hit_land,                     // suppress raycast
00104                                                                                 FALSE,                          // intersection
00105                                                                                 ray_target_id,
00106                                                                                 gSavedSettings.getBOOL("CreateToolCopyCenters"),
00107                                                                                 gSavedSettings.getBOOL("CreateToolCopyRotates"),
00108                                                                                 FALSE);                         // select copy
00109 
00110         if (regionp
00111                 && (regionp->getRegionFlags() & REGION_FLAGS_SANDBOX))
00112         {
00113                 LLFirstUse::useSandbox();
00114         }
00115 
00116         return TRUE;
00117 }
00118 
00119 
00120 BOOL LLToolPlacer::placeObject(S32 x, S32 y, MASK mask)
00121 {
00122         BOOL added = TRUE;
00123         
00124         if (gSavedSettings.getBOOL("CreateToolCopySelection"))
00125         {
00126                 added = add_duplicate(x, y);
00127         }
00128         else
00129         {
00130                 added = add_object( sObjectType, x, y, NO_PHYSICS );
00131         }
00132 
00133         // ...and go back to the default tool
00134         if (added && !gSavedSettings.getBOOL("CreateToolKeepSelected"))
00135         {
00136                 gToolMgr->getCurrentToolset()->selectTool( gToolTranslate );
00137         }
00138 
00139         return added;
00140 }
00141 
00142 BOOL LLToolPlacer::handleHover(S32 x, S32 y, MASK mask)
00143 {
00144         lldebugst(LLERR_USER_INPUT) << "hover handled by LLToolPlacer" << llendl;               
00145         gViewerWindow->getWindow()->setCursor(UI_CURSOR_TOOLCREATE);
00146         return TRUE;
00147 }
00148 
00149 void LLToolPlacer::handleSelect()
00150 {
00151         gFloaterTools->setStatusText("place");
00152 }
00153 
00154 void LLToolPlacer::handleDeselect()
00155 {
00156 }
00157 
00159 // LLToolPlacerPanel
00160 
00161 // static
00162 LLPCode LLToolPlacerPanel::sCube                = LL_PCODE_CUBE;
00163 LLPCode LLToolPlacerPanel::sPrism               = LL_PCODE_PRISM;
00164 LLPCode LLToolPlacerPanel::sPyramid             = LL_PCODE_PYRAMID;
00165 LLPCode LLToolPlacerPanel::sTetrahedron = LL_PCODE_TETRAHEDRON;
00166 LLPCode LLToolPlacerPanel::sCylinder    = LL_PCODE_CYLINDER;
00167 LLPCode LLToolPlacerPanel::sCylinderHemi= LL_PCODE_CYLINDER_HEMI;
00168 LLPCode LLToolPlacerPanel::sCone                = LL_PCODE_CONE;
00169 LLPCode LLToolPlacerPanel::sConeHemi    = LL_PCODE_CONE_HEMI;
00170 LLPCode LLToolPlacerPanel::sTorus               = LL_PCODE_TORUS;
00171 LLPCode LLToolPlacerPanel::sSquareTorus = LLViewerObject::LL_VO_SQUARE_TORUS;
00172 LLPCode LLToolPlacerPanel::sTriangleTorus = LLViewerObject::LL_VO_TRIANGLE_TORUS;
00173 LLPCode LLToolPlacerPanel::sSphere              = LL_PCODE_SPHERE;
00174 LLPCode LLToolPlacerPanel::sSphereHemi  = LL_PCODE_SPHERE_HEMI;
00175 LLPCode LLToolPlacerPanel::sTree                = LL_PCODE_LEGACY_TREE;
00176 LLPCode LLToolPlacerPanel::sGrass               = LL_PCODE_LEGACY_GRASS;
00177 
00178 S32                     LLToolPlacerPanel::sButtonsAdded = 0;
00179 LLButton*       LLToolPlacerPanel::sButtons[ TOOL_PLACER_NUM_BUTTONS ];
00180 
00181 LLToolPlacerPanel::LLToolPlacerPanel(const std::string& name, const LLRect& rect)
00182         :
00183         LLPanel( name, rect )
00184 {
00185         /* DEPRECATED - JC
00186         addButton( "UIImgCubeUUID",                     "UIImgCubeSelectedUUID",                &LLToolPlacerPanel::sCube );
00187         addButton( "UIImgPrismUUID",            "UIImgPrismSelectedUUID",               &LLToolPlacerPanel::sPrism );
00188         addButton( "UIImgPyramidUUID",          "UIImgPyramidSelectedUUID",             &LLToolPlacerPanel::sPyramid );
00189         addButton( "UIImgTetrahedronUUID",      "UIImgTetrahedronSelectedUUID", &LLToolPlacerPanel::sTetrahedron );
00190         addButton( "UIImgCylinderUUID",         "UIImgCylinderSelectedUUID",    &LLToolPlacerPanel::sCylinder );
00191         addButton( "UIImgHalfCylinderUUID",     "UIImgHalfCylinderSelectedUUID",&LLToolPlacerPanel::sCylinderHemi );
00192         addButton( "UIImgConeUUID",                     "UIImgConeSelectedUUID",                &LLToolPlacerPanel::sCone );
00193         addButton( "UIImgHalfConeUUID",         "UIImgHalfConeSelectedUUID",    &LLToolPlacerPanel::sConeHemi );
00194         addButton( "UIImgSphereUUID",           "UIImgSphereSelectedUUID",              &LLToolPlacerPanel::sSphere );
00195         addButton( "UIImgHalfSphereUUID",       "UIImgHalfSphereSelectedUUID",  &LLToolPlacerPanel::sSphereHemi );
00196         addButton( "UIImgTreeUUID",                     "UIImgTreeSelectedUUID",                &LLToolPlacerPanel::sTree );
00197         addButton( "UIImgGrassUUID",            "UIImgGrassSelectedUUID",               &LLToolPlacerPanel::sGrass );
00198         addButton( "ObjectTorusImageID",        "ObjectTorusActiveImageID",             &LLToolPlacerPanel::sTorus );
00199         addButton( "ObjectTubeImageID",         "ObjectTubeActiveImageID",              &LLToolPlacerPanel::sSquareTorus );
00200         */
00201 }
00202 
00203 void LLToolPlacerPanel::addButton( const LLString& up_state, const LLString& down_state, LLPCode* pcode )
00204 {
00205         const S32 TOOL_SIZE = 32;
00206         const S32 HORIZ_SPACING = TOOL_SIZE + 5;
00207         const S32 VERT_SPACING = TOOL_SIZE + 5;
00208         const S32 VPAD = 10;
00209         const S32 HPAD = 7;
00210 
00211         S32 row = sButtonsAdded / 4;
00212         S32 column = sButtonsAdded % 4; 
00213 
00214         LLRect help_rect = gSavedSettings.getRect("ToolHelpRect");
00215 
00216         // Build the rectangle, recalling the origin is at lower left
00217         // and we want the icons to build down from the top.
00218         LLRect rect;
00219         rect.setLeftTopAndSize(
00220                 HPAD + (column * HORIZ_SPACING),
00221                 help_rect.mBottom - VPAD - (row * VERT_SPACING),
00222                 TOOL_SIZE,
00223                 TOOL_SIZE );
00224 
00225         LLButton* btn = new LLButton(
00226                 "ToolPlacerOptBtn",
00227                 rect,
00228                 up_state,
00229                 down_state,
00230                 "", &LLToolPlacerPanel::setObjectType,
00231                 pcode,
00232                 LLFontGL::sSansSerif);
00233         btn->setFollowsBottom();
00234         btn->setFollowsLeft();
00235         addChild(btn);
00236 
00237         sButtons[sButtonsAdded] = btn;
00238         sButtonsAdded++;
00239 }
00240 
00241 // static 
00242 void    LLToolPlacerPanel::setObjectType( void* data )
00243 {
00244         LLPCode pcode = *(LLPCode*) data;
00245         LLToolPlacer::setObjectType( pcode );
00246 }

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