00001 
00032 #include "llviewerprecompiledheaders.h"
00033 
00034 #include "llpreviewlandmark.h"
00035 
00036 #include "llassetstorage.h"
00037 #include "llfocusmgr.h"
00038 #include "llfontgl.h"
00039 #include "llgl.h"
00040 #include "llinventory.h"
00041 #include "message.h"
00042 
00043 #include "llagent.h"
00044 #include "llbutton.h"
00045 #include "lleconomy.h"
00046 #include "llfloaterworldmap.h"
00047 #include "llinventoryview.h"
00048 #include "lliconctrl.h"
00049 #include "lllandmarklist.h"
00050 #include "lllineeditor.h"
00051 #include "llpanelplace.h"
00052 #include "llresmgr.h"
00053 #include "llstatusbar.h"
00054 #include "lltextbox.h"
00055 #include "llui.h"
00056 #include "llviewercontrol.h"
00057 #include "llviewerregion.h"
00058 #include "llviewerstats.h"
00059 #include "viewer.h"
00060 #include "llvieweruictrlfactory.h"
00061 
00062 
00063 
00064 
00066 
00067 
00068 
00069 
00070 LLPreviewLandmarkList LLPreviewLandmark::sOrderedInstances;
00071 
00072 
00073 LLPreviewLandmark::LLPreviewLandmark(const std::string& name,
00074                                                                          const LLRect& rect,
00075                                                                          const std::string& title,
00076                                                                          const LLUUID& item_uuid,
00077                                                                          BOOL show_keep_discard,
00078                                                                          LLViewerInventoryItem* inv_item)
00079 :       LLPreview(name,
00080                           LLRect(rect.mLeft, 
00081                                         rect.mTop, 
00082                                         (show_keep_discard ? rect.mRight+70 : rect.mRight), 
00083                                         rect.mBottom), 
00084                           title, 
00085                           item_uuid, 
00086                           LLUUID::null, 
00087                           FALSE,  
00088                           0, 0, 
00089                           inv_item),
00090         mLandmark( NULL )
00091 {
00092         
00093         mFactoryMap["place_details_panel"] = LLCallbackMap(LLPreviewLandmark::createPlaceDetail, this);
00094         gUICtrlFactory->buildFloater(this, "floater_preview_existing_landmark.xml", &getFactoryMap());
00095 
00096         
00097 
00098 
00099 
00100 
00101 
00102 
00103 
00104 
00105 
00106 
00107 
00108 
00109 
00110         LLPreviewLandmark::sOrderedInstances.push_back( this );
00111 }
00112 
00113 
00114 LLPreviewLandmark::~LLPreviewLandmark()
00115 {
00116         LLPreviewLandmarkList::iterator this_itr;
00117         this_itr = std::find(LLPreviewLandmark::sOrderedInstances.begin(), 
00118                         LLPreviewLandmark::sOrderedInstances.end(), this);
00119         if (this_itr != LLPreviewLandmark::sOrderedInstances.end())
00120         {
00121                 LLPreviewLandmark::sOrderedInstances.erase(this_itr);
00122         }
00123 }
00124 
00125 
00126 
00127 
00128 void LLPreviewLandmark::getDegreesAndDist( F32* degrees, F64* horiz_dist, F64* vert_dist) const
00129 {
00130         if( mLandmark )
00131         {
00132                 LLVector3d pos;
00133                 if(mLandmark->getGlobalPos(pos))
00134                 {
00135                         LLVector3d to_vec = pos - gAgent.getPositionGlobal();
00136                         *horiz_dist = sqrt(to_vec.mdV[VX] * to_vec.mdV[VX] + to_vec.mdV[VY] * to_vec.mdV[VY]);
00137                         *vert_dist = to_vec.mdV[VZ];
00138                         *degrees = F32( RAD_TO_DEG * atan2( to_vec.mdV[VY], to_vec.mdV[VX] ) );
00139                 }
00140         }
00141 }
00142 
00143 const LLString& LLPreviewLandmark::getName() const
00144 {
00145         const LLInventoryItem *item = getItem();
00146         if (item)
00147         {
00148                 return item->getName();
00149         }
00150         return LLString::null;
00151 }
00152 
00153 LLVector3d LLPreviewLandmark::getPositionGlobal() const
00154 {
00155         LLVector3d pos;
00156         if( mLandmark )
00157         {
00158                 
00159                 (void)mLandmark->getGlobalPos(pos);
00160         }
00161         return pos;
00162 }
00163 
00164 
00165 const LLColor4& LLPreviewLandmark::getMarkerColor() const
00166 {
00167         return mMarkerColor;
00168 }
00169 
00170 void LLPreviewLandmark::draw()
00171 {
00172         if( getVisible() )
00173         {
00174                 const LLInventoryItem *item = getItem();
00175 
00176                 if( item && !mLandmark )
00177                 {
00178                         mLandmark = gLandmarkList.getAsset( item->getAssetUUID() );
00179                         if(mLandmark && mPlacePanel)
00180                         {
00181                                 LLVector3 pos_region = mLandmark->getRegionPos();       
00182                                 LLUUID landmark_asset_id = item->getAssetUUID();        
00183                                 LLUUID region_id;
00184                                 mLandmark->getRegionID(region_id);              
00185                                 LLVector3d pos_global = getPositionGlobal();    
00186                                 mPlacePanel->displayParcelInfo(pos_region, landmark_asset_id, region_id, pos_global);
00187                         }
00188                 }
00189 
00190                 LLFloater::draw();
00191         }
00192 }
00193 
00194 void LLPreviewLandmark::loadAsset()
00195 {
00196         const LLInventoryItem *item = getItem();
00197 
00198         if( item && !mLandmark )
00199         {
00200                 mLandmark = gLandmarkList.getAsset( item->getAssetUUID() );
00201         }
00202         mAssetStatus = PREVIEW_ASSET_LOADING;
00203 }
00204 
00205 LLPreview::EAssetStatus LLPreviewLandmark::getAssetStatus()
00206 {
00207         const LLInventoryItem *item = getItem();
00208         if (item && gLandmarkList.assetExists(item->getAssetUUID()))
00209         {
00210                 mAssetStatus = PREVIEW_ASSET_LOADED;
00211         }
00212         return mAssetStatus;
00213 }
00214 
00215 void* LLPreviewLandmark::createPlaceDetail(void* userdata)
00216 {
00217         LLPreviewLandmark *self = (LLPreviewLandmark*)userdata;
00218         self->mPlacePanel = new LLPanelPlace();
00219         gUICtrlFactory->buildPanel(self->mPlacePanel, "panel_place.xml");
00220         const LLInventoryItem* item = self->getItem();
00221         self->mPlacePanel->displayItemInfo(item);
00222 
00223         return self->mPlacePanel;
00224 }