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

Generated on Fri May 16 08:33:55 2008 for SecondLife by  doxygen 1.5.5