llpanelvolume.cpp

Go to the documentation of this file.
00001 
00032 #include "llviewerprecompiledheaders.h"
00033 
00034 // file include
00035 #include "llpanelvolume.h"
00036 
00037 // linden library includes
00038 #include "llclickaction.h"
00039 #include "lleconomy.h"
00040 #include "llerror.h"
00041 #include "llfontgl.h"
00042 #include "llflexibleobject.h"
00043 #include "llmaterialtable.h"
00044 #include "llpermissionsflags.h"
00045 #include "llstring.h"
00046 #include "llvolume.h"
00047 #include "m3math.h"
00048 #include "material_codes.h"
00049 
00050 // project includes
00051 #include "llagent.h"
00052 #include "llbutton.h"
00053 #include "llcheckboxctrl.h"
00054 #include "llcolorswatch.h"
00055 #include "llcombobox.h"
00056 #include "llfirstuse.h"
00057 #include "llfocusmgr.h"
00058 #include "llmanipscale.h"
00059 #include "llpanelinventory.h"
00060 #include "llpreviewscript.h"
00061 #include "llresmgr.h"
00062 #include "llselectmgr.h"
00063 #include "llspinctrl.h"
00064 #include "lltextbox.h"
00065 #include "lltool.h"
00066 #include "lltoolcomp.h"
00067 #include "lltoolmgr.h"
00068 #include "llui.h"
00069 #include "llviewerobject.h"
00070 #include "llviewerregion.h"
00071 #include "llviewerwindow.h"
00072 #include "llvovolume.h"
00073 #include "llworld.h"
00074 #include "pipeline.h"
00075 #include "viewer.h"
00076 
00077 #include "lldrawpool.h"
00078 #include "llvieweruictrlfactory.h"
00079 
00080 // "Features" Tab
00081 
00082 BOOL    LLPanelVolume::postBuild()
00083 {
00084         // Flexible Objects Parameters
00085         {
00086                 childSetCommitCallback("Flexible1D Checkbox Ctrl",onCommitIsFlexible,this);
00087                 childSetCommitCallback("FlexNumSections",onCommitFlexible,this);
00088                 childSetValidate("FlexNumSections",precommitValidate);
00089                 childSetCommitCallback("FlexGravity",onCommitFlexible,this);
00090                 childSetValidate("FlexGravity",precommitValidate);
00091                 childSetCommitCallback("FlexFriction",onCommitFlexible,this);
00092                 childSetValidate("FlexFriction",precommitValidate);
00093                 childSetCommitCallback("FlexWind",onCommitFlexible,this);
00094                 childSetValidate("FlexWind",precommitValidate);
00095                 childSetCommitCallback("FlexTension",onCommitFlexible,this);
00096                 childSetValidate("FlexTension",precommitValidate);
00097                 childSetCommitCallback("FlexForceX",onCommitFlexible,this);
00098                 childSetValidate("FlexForceX",precommitValidate);
00099                 childSetCommitCallback("FlexForceY",onCommitFlexible,this);
00100                 childSetValidate("FlexForceY",precommitValidate);
00101                 childSetCommitCallback("FlexForceZ",onCommitFlexible,this);
00102                 childSetValidate("FlexForceZ",precommitValidate);
00103         }
00104 
00105         // LIGHT Parameters
00106         {
00107                 childSetCommitCallback("Light Checkbox Ctrl",onCommitIsLight,this);
00108                 LLColorSwatchCtrl*      LightColorSwatch = gUICtrlFactory->getColorSwatchByName(this,"colorswatch");
00109                 if(LightColorSwatch){
00110                         LightColorSwatch->setOnCancelCallback(onLightCancelColor);
00111                         LightColorSwatch->setOnSelectCallback(onLightSelectColor);
00112                         childSetCommitCallback("colorswatch",onCommitLight,this);
00113                 }
00114                 childSetCommitCallback("Light Intensity",onCommitLight,this);
00115                 childSetValidate("Light Intensity",precommitValidate);
00116                 childSetCommitCallback("Light Radius",onCommitLight,this);
00117                 childSetValidate("Light Radius",precommitValidate);
00118                 childSetCommitCallback("Light Falloff",onCommitLight,this);
00119                 childSetValidate("Light Falloff",precommitValidate);
00120         }
00121         
00122         // Start with everyone disabled
00123         clearCtrls();
00124 
00125         return TRUE;
00126 }
00127 
00128 LLPanelVolume::LLPanelVolume(const std::string& name)
00129         :       LLPanel(name)
00130 {
00131         setMouseOpaque(FALSE);
00132 
00133 }
00134 
00135 
00136 LLPanelVolume::~LLPanelVolume()
00137 {
00138         // Children all cleaned up by default view destructor.
00139 }
00140 
00141 void LLPanelVolume::getState( )
00142 {
00143         LLViewerObject* objectp = gSelectMgr->getSelection()->getFirstRootObject();
00144         LLViewerObject* root_objectp = objectp;
00145         if(!objectp)
00146         {
00147                 objectp = gSelectMgr->getSelection()->getFirstObject();
00148                 // *FIX: shouldn't we just keep the child?
00149                 if (objectp)
00150                 {
00151                         LLViewerObject* parentp = objectp->getSubParent();
00152 
00153                         if (parentp)
00154                         {
00155                                 root_objectp = parentp;
00156                         }
00157                         else
00158                         {
00159                                 root_objectp = objectp;
00160                         }
00161                 }
00162         }
00163 
00164         LLVOVolume *volobjp = NULL;
00165         if ( objectp && (objectp->getPCode() == LL_PCODE_VOLUME))
00166         {
00167                 volobjp = (LLVOVolume *)objectp;
00168         }
00169         
00170         if( !objectp )
00171         {
00172                 //forfeit focus
00173                 if (gFocusMgr.childHasKeyboardFocus(this))
00174                 {
00175                         gFocusMgr.setKeyboardFocus(NULL, NULL);
00176                 }
00177 
00178                 // Disable all text input fields
00179                 clearCtrls();
00180 
00181                 return;
00182         }
00183 
00184         BOOL owners_identical;
00185         LLUUID owner_id;
00186         LLString owner_name;
00187         owners_identical = gSelectMgr->selectGetOwner(owner_id, owner_name);
00188 
00189         // BUG? Check for all objects being editable?
00190         BOOL editable = root_objectp->permModify();
00191         BOOL single_volume = gSelectMgr->selectionAllPCode( LL_PCODE_VOLUME )
00192                 && gSelectMgr->getSelection()->getObjectCount() == 1;
00193 
00194         // Select Single Message
00195         if (single_volume)
00196         {
00197                 childSetVisible("edit_object",true);
00198                 childSetEnabled("edit_object",true);
00199                 childSetVisible("select_single",false);
00200         }
00201         else
00202         {       
00203                 childSetVisible("edit_object",false);
00204                 childSetVisible("select_single",true);
00205                 childSetEnabled("select_single",true);
00206         }
00207         
00208         // Light properties
00209         BOOL is_light = volobjp && volobjp->getIsLight();
00210         childSetValue("Light Checkbox Ctrl",is_light);
00211         childSetEnabled("Light Checkbox Ctrl",editable && single_volume && volobjp);
00212         
00213         if (is_light && editable && single_volume)
00214         {
00215                 childSetEnabled("label color",true);
00216                 //mLabelColor            ->setEnabled( TRUE );
00217                 LLColorSwatchCtrl* LightColorSwatch = gUICtrlFactory->getColorSwatchByName(this,"colorswatch");
00218                 if(LightColorSwatch)
00219                 {
00220                         LightColorSwatch->setEnabled( TRUE );
00221                         LightColorSwatch->setValid( TRUE );
00222                         LightColorSwatch->set(volobjp->getLightBaseColor());
00223                 }
00224                 childSetEnabled("Light Intensity",true);
00225                 childSetEnabled("Light Radius",true);
00226                 childSetEnabled("Light Falloff",true);
00227 
00228                 childSetValue("Light Intensity",volobjp->getLightIntensity());
00229                 childSetValue("Light Radius",volobjp->getLightRadius());
00230                 childSetValue("Light Falloff",volobjp->getLightFalloff());
00231 
00232                 mLightSavedColor = volobjp->getLightColor();
00233         }
00234         else
00235         {
00236                 childSetEnabled("label color",false);   
00237                 LLColorSwatchCtrl* LightColorSwatch = gUICtrlFactory->getColorSwatchByName(this,"colorswatch");
00238                 if(LightColorSwatch)
00239                 {
00240                         LightColorSwatch->setEnabled( FALSE );
00241                         LightColorSwatch->setValid( FALSE );
00242                 }
00243                 childSetEnabled("Light Intensity",false);
00244                 childSetEnabled("Light Radius",false);
00245                 childSetEnabled("Light Falloff",false);
00246         }
00247         
00248         // Flexible properties
00249         BOOL is_flexible = volobjp && volobjp->isFlexible();
00250         childSetValue("Flexible1D Checkbox Ctrl",is_flexible);
00251         if (is_flexible || (volobjp && volobjp->canBeFlexible()))
00252         {
00253                 childSetEnabled("Flexible1D Checkbox Ctrl", editable && single_volume && volobjp);
00254         }
00255         else
00256         {
00257                 childSetEnabled("Flexible1D Checkbox Ctrl", false);
00258         }
00259         if (is_flexible && editable && single_volume)
00260         {
00261                 childSetVisible("FlexNumSections",true);
00262                 childSetVisible("FlexGravity",true);
00263                 childSetVisible("FlexTension",true);
00264                 childSetVisible("FlexFriction",true);
00265                 childSetVisible("FlexWind",true);
00266                 childSetVisible("FlexForceX",true);
00267                 childSetVisible("FlexForceY",true);
00268                 childSetVisible("FlexForceZ",true);
00269 
00270                 childSetEnabled("FlexNumSections",true);
00271                 childSetEnabled("FlexGravity",true);
00272                 childSetEnabled("FlexTension",true);
00273                 childSetEnabled("FlexFriction",true);
00274                 childSetEnabled("FlexWind",true);
00275                 childSetEnabled("FlexForceX",true);
00276                 childSetEnabled("FlexForceY",true);
00277                 childSetEnabled("FlexForceZ",true);
00278 
00279                 LLFlexibleObjectData *attributes = (LLFlexibleObjectData *)objectp->getParameterEntry(LLNetworkData::PARAMS_FLEXIBLE);
00280                 
00281                 childSetValue("FlexNumSections",(F32)attributes->getSimulateLOD());
00282                 childSetValue("FlexGravity",attributes->getGravity());
00283                 childSetValue("FlexTension",attributes->getTension());
00284                 childSetValue("FlexFriction",attributes->getAirFriction());
00285                 childSetValue("FlexWind",attributes->getWindSensitivity());
00286                 childSetValue("FlexForceX",attributes->getUserForce().mV[VX]);
00287                 childSetValue("FlexForceY",attributes->getUserForce().mV[VY]);
00288                 childSetValue("FlexForceZ",attributes->getUserForce().mV[VZ]);
00289         }
00290         else
00291         {
00292                 childSetEnabled("FlexNumSections",false);
00293                 childSetEnabled("FlexGravity",false);
00294                 childSetEnabled("FlexTension",false);
00295                 childSetEnabled("FlexFriction",false);
00296                 childSetEnabled("FlexWind",false);
00297                 childSetEnabled("FlexForceX",false);
00298                 childSetEnabled("FlexForceY",false);
00299                 childSetEnabled("FlexForceZ",false);
00300         }
00301         
00302         mObject = objectp;
00303         mRootObject = root_objectp;
00304 }
00305 
00306 // static
00307 BOOL LLPanelVolume::precommitValidate( LLUICtrl* ctrl, void* userdata )
00308 {
00309         // TODO: Richard will fill this in later.  
00310         return TRUE; // FALSE means that validation failed and new value should not be commited.
00311 }
00312 
00313 
00314 void LLPanelVolume::refresh()
00315 {
00316         getState();
00317         if (mObject.notNull() && mObject->isDead())
00318         {
00319                 mObject = NULL;
00320         }
00321 
00322         if (mRootObject.notNull() && mRootObject->isDead())
00323         {
00324                 mRootObject = NULL;
00325         }
00326 }
00327 
00328 
00329 void LLPanelVolume::draw()
00330 {
00331         LLPanel::draw();
00332 }
00333 
00334 // virtual
00335 void LLPanelVolume::clearCtrls()
00336 {
00337         LLPanel::clearCtrls();
00338 
00339         childSetEnabled("select_single",false);
00340         childSetVisible("select_single",true);
00341         childSetEnabled("edit_object",false);
00342         childSetVisible("edit_object",false);
00343         childSetEnabled("Light Checkbox Ctrl",false);
00344         childSetEnabled("label color",false);
00345         childSetEnabled("label color",false);
00346         LLColorSwatchCtrl* LightColorSwatch = gUICtrlFactory->getColorSwatchByName(this,"colorswatch");
00347         if(LightColorSwatch)
00348         {
00349                 LightColorSwatch->setEnabled( FALSE );
00350                 LightColorSwatch->setValid( FALSE );
00351         }
00352         childSetEnabled("Light Intensity",false);
00353         childSetEnabled("Light Radius",false);
00354         childSetEnabled("Light Falloff",false);
00355 
00356         childSetEnabled("Flexible1D Checkbox Ctrl",false);
00357         childSetEnabled("FlexNumSections",false);
00358         childSetEnabled("FlexGravity",false);
00359         childSetEnabled("FlexTension",false);
00360         childSetEnabled("FlexFriction",false);
00361         childSetEnabled("FlexWind",false);
00362         childSetEnabled("FlexForceX",false);
00363         childSetEnabled("FlexForceY",false);
00364         childSetEnabled("FlexForceZ",false);
00365 }
00366 
00367 //
00368 // Static functions
00369 //
00370 
00371 void LLPanelVolume::sendIsLight()
00372 {
00373         LLViewerObject* objectp = mObject;
00374         if (!objectp || (objectp->getPCode() != LL_PCODE_VOLUME))
00375         {
00376                 return;
00377         }       
00378         LLVOVolume *volobjp = (LLVOVolume *)objectp;
00379         
00380         BOOL value = childGetValue("Light Checkbox Ctrl");
00381         volobjp->setIsLight(value);
00382         llinfos << "update light sent" << llendl;
00383 }
00384 
00385 void LLPanelVolume::sendIsFlexible()
00386 {
00387         LLViewerObject* objectp = mObject;
00388         if (!objectp || (objectp->getPCode() != LL_PCODE_VOLUME))
00389         {
00390                 return;
00391         }       
00392         LLVOVolume *volobjp = (LLVOVolume *)objectp;
00393         
00394         BOOL is_flexible = childGetValue("Flexible1D Checkbox Ctrl");
00395         //BOOL is_flexible = mCheckFlexible1D->get();
00396 
00397         if (is_flexible)
00398         {
00399                 LLFirstUse::useFlexible();
00400 
00401                 if (objectp->getClickAction() == CLICK_ACTION_SIT)
00402                 {
00403                         gSelectMgr->selectionSetClickAction(CLICK_ACTION_NONE);
00404                 }
00405 
00406         }
00407 
00408         if (volobjp->setIsFlexible(is_flexible))
00409         {
00410                 mObject->sendShapeUpdate();
00411                 gSelectMgr->selectionUpdatePhantom(volobjp->flagPhantom());
00412         }
00413 
00414         llinfos << "update flexible sent" << llendl;
00415 }
00416 
00417 void LLPanelVolume::onLightCancelColor(LLUICtrl* ctrl, void* userdata)
00418 {
00419         LLPanelVolume* self = (LLPanelVolume*) userdata;
00420         LLColorSwatchCtrl*      LightColorSwatch = gUICtrlFactory->getColorSwatchByName(self,"colorswatch");
00421         if(LightColorSwatch)
00422         {
00423                 LightColorSwatch->setColor(self->mLightSavedColor);
00424         }
00425         onLightSelectColor(NULL, userdata);
00426 }
00427 
00428 void LLPanelVolume::onLightSelectColor(LLUICtrl* ctrl, void* userdata)
00429 {
00430         LLPanelVolume* self = (LLPanelVolume*) userdata;
00431         LLViewerObject* objectp = self->mObject;
00432         if (!objectp || (objectp->getPCode() != LL_PCODE_VOLUME))
00433         {
00434                 return;
00435         }       
00436         LLVOVolume *volobjp = (LLVOVolume *)objectp;
00437 
00438 
00439         LLColorSwatchCtrl*      LightColorSwatch = gUICtrlFactory->getColorSwatchByName(self,"colorswatch");
00440         if(LightColorSwatch)
00441         {
00442                 LLColor4        clr = LightColorSwatch->get();
00443                 LLColor3        clr3( clr );
00444                 volobjp->setLightColor(clr3);
00445                 self->mLightSavedColor = clr;
00446         }
00447 }
00448 
00449 // static
00450 void LLPanelVolume::onCommitLight( LLUICtrl* ctrl, void* userdata )
00451 {
00452         LLPanelVolume* self = (LLPanelVolume*) userdata;
00453         LLViewerObject* objectp = self->mObject;
00454         if (!objectp || (objectp->getPCode() != LL_PCODE_VOLUME))
00455         {
00456                 return;
00457         }       
00458         LLVOVolume *volobjp = (LLVOVolume *)objectp;
00459         
00460         
00461         volobjp->setLightIntensity((F32)self->childGetValue("Light Intensity").asReal());
00462         volobjp->setLightRadius((F32)self->childGetValue("Light Radius").asReal());
00463         volobjp->setLightFalloff((F32)self->childGetValue("Light Falloff").asReal());
00464         LLColorSwatchCtrl*      LightColorSwatch = gUICtrlFactory->getColorSwatchByName(self,"colorswatch");
00465         if(LightColorSwatch)
00466         {
00467                 LLColor4        clr = LightColorSwatch->get();
00468                 volobjp->setLightColor(LLColor3(clr));
00469         }
00470 }
00471 
00472 // static
00473 void LLPanelVolume::onCommitIsLight( LLUICtrl* ctrl, void* userdata )
00474 {
00475         LLPanelVolume* self = (LLPanelVolume*) userdata;
00476         self->sendIsLight();
00477 }
00478 
00479 //----------------------------------------------------------------------------
00480 
00481 // static
00482 void LLPanelVolume::onCommitFlexible( LLUICtrl* ctrl, void* userdata )
00483 {
00484         LLPanelVolume* self = (LLPanelVolume*) userdata;
00485         LLViewerObject* objectp = self->mObject;
00486         if (!objectp || (objectp->getPCode() != LL_PCODE_VOLUME))
00487         {
00488                 return;
00489         }
00490         
00491         LLFlexibleObjectData *attributes = (LLFlexibleObjectData *)objectp->getParameterEntry(LLNetworkData::PARAMS_FLEXIBLE);
00492         if (attributes)
00493         {
00494                 LLFlexibleObjectData new_attributes;
00495                 new_attributes = *attributes;
00496 
00497 
00498                 new_attributes.setSimulateLOD(self->childGetValue("FlexNumSections").asInteger());//(S32)self->mSpinSections->get());
00499                 new_attributes.setGravity((F32)self->childGetValue("FlexGravity").asReal());
00500                 new_attributes.setTension((F32)self->childGetValue("FlexTension").asReal());
00501                 new_attributes.setAirFriction((F32)self->childGetValue("FlexFriction").asReal());
00502                 new_attributes.setWindSensitivity((F32)self->childGetValue("FlexWind").asReal());
00503                 F32 fx = (F32)self->childGetValue("FlexForceX").asReal();
00504                 F32 fy = (F32)self->childGetValue("FlexForceY").asReal();
00505                 F32 fz = (F32)self->childGetValue("FlexForceZ").asReal();
00506                 LLVector3 force(fx,fy,fz);
00507 
00508                 new_attributes.setUserForce(force);
00509                 objectp->setParameterEntry(LLNetworkData::PARAMS_FLEXIBLE, new_attributes, true);
00510         }
00511 
00512         // Values may fail validation
00513         self->refresh();
00514 }
00515 
00516 // static
00517 void LLPanelVolume::onCommitIsFlexible( LLUICtrl* ctrl, void* userdata )
00518 {
00519         LLPanelVolume* self = (LLPanelVolume*) userdata;
00520         self->sendIsFlexible();
00521 }
00522 

Generated on Thu Jul 1 06:08:59 2010 for Second Life Viewer by  doxygen 1.4.7