llpreviewlandmark.cpp 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. /**
  2. * @file llpreviewlandmark.cpp
  3. * @brief LLPreviewLandmark class implementation
  4. *
  5. * $LicenseInfo:firstyear=2002&license=viewergpl$
  6. *
  7. * Copyright (c) 2002-2009, Linden Research, Inc.
  8. *
  9. * Second Life Viewer Source Code
  10. * The source code in this file ("Source Code") is provided by Linden Lab
  11. * to you under the terms of the GNU General Public License, version 2.0
  12. * ("GPL"), unless you have obtained a separate licensing agreement
  13. * ("Other License"), formally executed by you and Linden Lab. Terms of
  14. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16. *
  17. * There are special exceptions to the terms and conditions of the GPL as
  18. * it is applied to this Source Code. View the full text of the exception
  19. * in the file doc/FLOSS-exception.txt in this software distribution, or
  20. * online at
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. #include "llviewerprecompiledheaders.h"
  33. #include "llpreviewlandmark.h"
  34. #include "llassetstorage.h"
  35. #include "llinventory.h"
  36. #include "lluictrlfactory.h"
  37. #include "llagent.h"
  38. #include "lllandmarklist.h"
  39. #include "llpanelplace.h"
  40. #include "llviewerregion.h"
  41. ////////////////////////////////////////////////////////////////////////////
  42. // LLPreviewLandmark
  43. // static
  44. LLPreviewLandmarkList LLPreviewLandmark::sOrderedInstances;
  45. LLPreviewLandmark::LLPreviewLandmark(const std::string& name,
  46. const LLRect& rect,
  47. const std::string& title,
  48. const LLUUID& item_uuid,
  49. bool show_keep_discard,
  50. LLViewerInventoryItem* inv_item)
  51. : LLPreview(name, LLRect(rect.mLeft, rect.mTop, rect.mRight, rect.mBottom),
  52. title, item_uuid, LLUUID::null, false, 0, 0, inv_item),
  53. mLandmark(NULL)
  54. {
  55. mFactoryMap["place_details_panel"] = LLCallbackMap(createPlaceDetail,
  56. this);
  57. LLUICtrlFactory::getInstance()->buildFloater(this,
  58. "floater_preview_landmark.xml",
  59. &getFactoryMap());
  60. if (show_keep_discard)
  61. {
  62. childSetAction("Discard btn", onDiscardBtn, this);
  63. }
  64. else
  65. {
  66. childSetVisible("Discard btn", false);
  67. }
  68. #if 0
  69. childSetCommitCallback("desc_editor", LLPreview::onText, this);
  70. childSetText("desc_editor", item->getDescription());
  71. childSetText("name_editor", item->getName());
  72. childSetPrevalidate("desc_editor",
  73. &LLLineEditor::prevalidatePrintableNotPipe);
  74. if (!getHost())
  75. {
  76. LLRect curRect = getRect();
  77. translate(rect.mLeft - curRect.mLeft, rect.mTop - curRect.mTop);
  78. }
  79. #endif
  80. sOrderedInstances.push_back(this);
  81. }
  82. //virtual
  83. LLPreviewLandmark::~LLPreviewLandmark()
  84. {
  85. LLPreviewLandmarkList::iterator this_itr;
  86. this_itr = std::find(sOrderedInstances.begin(), sOrderedInstances.end(),
  87. this);
  88. if (this_itr != sOrderedInstances.end())
  89. {
  90. sOrderedInstances.erase(this_itr);
  91. }
  92. }
  93. // Distance and direction from avatar to landmark.
  94. // Distance is in meters; degrees is angle from east (north = 90)
  95. void LLPreviewLandmark::getDegreesAndDist(F32* degrees, F64* horiz_dist,
  96. F64* vert_dist) const
  97. {
  98. LLVector3d pos;
  99. if (mLandmark && mLandmark->getGlobalPos(pos))
  100. {
  101. LLVector3d to_vec = pos - gAgent.getPositionGlobal();
  102. *horiz_dist = sqrt(to_vec.mdV[VX] * to_vec.mdV[VX] +
  103. to_vec.mdV[VY] * to_vec.mdV[VY]);
  104. *vert_dist = to_vec.mdV[VZ];
  105. *degrees = RAD_TO_DEG * (F32)atan2(to_vec.mdV[VY], to_vec.mdV[VX]);
  106. }
  107. }
  108. std::string LLPreviewLandmark::getName() const
  109. {
  110. const LLInventoryItem* item = getItem();
  111. if (item)
  112. {
  113. return item->getName();
  114. }
  115. return LLStringUtil::null;
  116. }
  117. LLVector3d LLPreviewLandmark::getPositionGlobal() const
  118. {
  119. LLVector3d pos;
  120. if (mLandmark)
  121. {
  122. // we can safely ignore the return value here.
  123. (void)mLandmark->getGlobalPos(pos);
  124. }
  125. return pos;
  126. }
  127. // virtual
  128. void LLPreviewLandmark::draw()
  129. {
  130. const LLInventoryItem* item = getItem();
  131. if (item && !mLandmark)
  132. {
  133. mLandmark = gLandmarkList.getAsset(item->getAssetUUID());
  134. if (mLandmark && mPlacePanel)
  135. {
  136. // we always have these two:
  137. LLVector3 pos_region = mLandmark->getRegionPos();
  138. LLUUID landmark_asset_id = item->getAssetUUID();
  139. // Might be null UUID ?
  140. LLUUID region_id;
  141. mLandmark->getRegionID(region_id);
  142. // might be 0
  143. LLVector3d pos_global = getPositionGlobal();
  144. mPlacePanel->displayParcelInfo(pos_region, landmark_asset_id,
  145. getItem()->getUUID(), region_id,
  146. pos_global);
  147. }
  148. }
  149. LLPreview::draw();
  150. }
  151. // virtual
  152. void LLPreviewLandmark::loadAsset()
  153. {
  154. const LLInventoryItem* item = getItem();
  155. if (item && !mLandmark)
  156. {
  157. mLandmark = gLandmarkList.getAsset(item->getAssetUUID());
  158. }
  159. mAssetStatus = PREVIEW_ASSET_LOADING;
  160. }
  161. // virtual
  162. LLPreview::EAssetStatus LLPreviewLandmark::getAssetStatus()
  163. {
  164. const LLInventoryItem* item = getItem();
  165. if (item && gLandmarkList.assetExists(item->getAssetUUID()))
  166. {
  167. mAssetStatus = PREVIEW_ASSET_LOADED;
  168. }
  169. return mAssetStatus;
  170. }
  171. // static
  172. void* LLPreviewLandmark::createPlaceDetail(void* userdata)
  173. {
  174. LLPreviewLandmark* self = (LLPreviewLandmark*)userdata;
  175. self->mPlacePanel = new LLPanelPlace();
  176. LLUICtrlFactory::getInstance()->buildPanel(self->mPlacePanel,
  177. "panel_place.xml");
  178. const LLInventoryItem* item = self->getItem();
  179. self->mPlacePanel->displayItemInfo(item);
  180. return self->mPlacePanel;
  181. }