BsGUISceneTreeView.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625
  1. #include "BsGUISceneTreeView.h"
  2. #include "BsSceneObject.h"
  3. #include "BsSceneManager.h"
  4. #include "BsGUISkin.h"
  5. #include "BsCmdRecordSO.h"
  6. #include "BsCmdReparentSO.h"
  7. #include "BsCmdDeleteSO.h"
  8. #include "BsCmdCloneSO.h"
  9. #include "BsCmdCreateSO.h"
  10. #include "BsCmdInstantiateSO.h"
  11. #include "BsDragAndDropManager.h"
  12. #include "BsSelection.h"
  13. #include "BsGUIResourceTreeView.h"
  14. #include "BsProjectLibrary.h"
  15. #include "BsProjectResourceMeta.h"
  16. #include "BsPrefab.h"
  17. #include "BsResources.h"
  18. #include "BsGUIContextMenu.h"
  19. namespace BansheeEngine
  20. {
  21. const MessageId GUISceneTreeView::SELECTION_CHANGED_MSG = MessageId("SceneTreeView_SelectionChanged");
  22. DraggedSceneObjects::DraggedSceneObjects(UINT32 numObjects)
  23. :numObjects(numObjects)
  24. {
  25. objects = bs_newN<HSceneObject>(numObjects);
  26. }
  27. DraggedSceneObjects::~DraggedSceneObjects()
  28. {
  29. bs_deleteN(objects, numObjects);
  30. objects = nullptr;
  31. }
  32. GUISceneTreeView::GUISceneTreeView(const String& backgroundStyle, const String& elementBtnStyle,
  33. const String& foldoutBtnStyle, const String& highlightBackgroundStyle, const String& selectionBackgroundStyle,
  34. const String& editBoxStyle, const String& dragHighlightStyle, const String& dragSepHighlightStyle, const GUIDimensions& dimensions)
  35. :GUITreeView(backgroundStyle, elementBtnStyle, foldoutBtnStyle, highlightBackgroundStyle, selectionBackgroundStyle, editBoxStyle, dragHighlightStyle,
  36. dragSepHighlightStyle, dimensions), mCutFlag(false)
  37. {
  38. SceneTreeViewLocator::_provide(this);
  39. GUIContextMenuPtr contextMenu = bs_shared_ptr_new<GUIContextMenu>();
  40. contextMenu->addMenuItem(L"New", std::bind(&GUISceneTreeView::createNewSO, this), 50);
  41. contextMenu->addMenuItem(L"Rename", std::bind(&GUISceneTreeView::renameSelected, this), 49, ShortcutKey(ButtonModifier::None, BC_F2));
  42. contextMenu->addMenuItem(L"Delete", std::bind(&GUISceneTreeView::deleteSelection, this), 48, ShortcutKey(ButtonModifier::None, BC_DELETE));
  43. contextMenu->addSeparator(L"", 40);
  44. contextMenu->addMenuItem(L"Duplicate", std::bind(&GUISceneTreeView::duplicateSelection, this), 39, ShortcutKey(ButtonModifier::Ctrl, BC_D));
  45. contextMenu->addMenuItem(L"Copy", std::bind(&GUISceneTreeView::copySelection, this), 38, ShortcutKey(ButtonModifier::Ctrl, BC_C));
  46. contextMenu->addMenuItem(L"Cut", std::bind(&GUISceneTreeView::cutSelection, this), 37, ShortcutKey(ButtonModifier::Ctrl, BC_X));
  47. contextMenu->addMenuItem(L"Paste", std::bind(&GUISceneTreeView::paste, this), 36, ShortcutKey(ButtonModifier::Ctrl, BC_V));
  48. setContextMenu(contextMenu);
  49. }
  50. GUISceneTreeView::~GUISceneTreeView()
  51. {
  52. SceneTreeViewLocator::_remove(this);
  53. }
  54. GUISceneTreeView* GUISceneTreeView::create(const String& backgroundStyle, const String& elementBtnStyle, const String& foldoutBtnStyle,
  55. const String& highlightBackgroundStyle, const String& selectionBackgroundStyle, const String& editBoxStyle, const String& dragHighlightStyle,
  56. const String& dragSepHighlightStyle)
  57. {
  58. return new (bs_alloc<GUISceneTreeView>()) GUISceneTreeView(backgroundStyle, elementBtnStyle, foldoutBtnStyle,
  59. highlightBackgroundStyle, selectionBackgroundStyle, editBoxStyle, dragHighlightStyle, dragSepHighlightStyle, GUIDimensions::create());
  60. }
  61. GUISceneTreeView* GUISceneTreeView::create(const GUIOptions& options, const String& backgroundStyle, const String& elementBtnStyle,
  62. const String& foldoutBtnStyle, const String& highlightBackgroundStyle, const String& selectionBackgroundStyle,
  63. const String& editBoxStyle, const String& dragHighlightStyle, const String& dragSepHighlightStyle)
  64. {
  65. return new (bs_alloc<GUISceneTreeView>()) GUISceneTreeView(backgroundStyle, elementBtnStyle,
  66. foldoutBtnStyle, highlightBackgroundStyle, selectionBackgroundStyle, editBoxStyle,
  67. dragHighlightStyle, dragSepHighlightStyle, GUIDimensions::create(options));
  68. }
  69. void GUISceneTreeView::updateTreeElement(SceneTreeElement* element)
  70. {
  71. HSceneObject currentSO = element->mSceneObject;
  72. // Check if SceneObject has changed in any way and update the tree element
  73. // Early exit case - Most commonly there will be no changes between active and cached data so
  74. // we first do a quick check in order to avoid expensive comparison later
  75. bool completeMatch = true;
  76. UINT32 visibleChildCount = 0;
  77. for (UINT32 i = 0; i < currentSO->getNumChildren(); i++)
  78. {
  79. if (i >= element->mChildren.size())
  80. {
  81. completeMatch = false;
  82. break;
  83. }
  84. HSceneObject currentSOChild = currentSO->getChild(i);
  85. #if BS_DEBUG_MODE == 0
  86. if (currentSOChild->hasFlag(SOF_Internal))
  87. continue;
  88. #endif
  89. SceneTreeElement* currentChild = static_cast<SceneTreeElement*>(element->mChildren[visibleChildCount]);
  90. visibleChildCount++;
  91. UINT64 curId = currentSOChild->getInstanceId();
  92. if (curId != currentChild->mId)
  93. {
  94. completeMatch = false;
  95. break;
  96. }
  97. }
  98. completeMatch &= visibleChildCount == element->mChildren.size();
  99. // Not a complete match, compare everything and insert/delete elements as needed
  100. bool needsUpdate = false;
  101. if(!completeMatch)
  102. {
  103. Vector<TreeElement*> newChildren;
  104. bool* tempToDelete = (bool*)bs_stack_alloc(sizeof(bool) * (UINT32)element->mChildren.size());
  105. for(UINT32 i = 0; i < (UINT32)element->mChildren.size(); i++)
  106. tempToDelete[i] = true;
  107. for(UINT32 i = 0; i < currentSO->getNumChildren(); i++)
  108. {
  109. HSceneObject currentSOChild = currentSO->getChild(i);
  110. bool isInternal = currentSOChild->hasFlag(SOF_Internal);
  111. #if BS_DEBUG_MODE == 0
  112. if (isInternal)
  113. continue;
  114. #endif
  115. UINT64 curId = currentSOChild->getInstanceId();
  116. bool found = false;
  117. for(UINT32 j = 0; j < element->mChildren.size(); j++)
  118. {
  119. SceneTreeElement* currentChild = static_cast<SceneTreeElement*>(element->mChildren[j]);
  120. if(curId == currentChild->mId)
  121. {
  122. tempToDelete[j] = false;
  123. currentChild->mSortedIdx = (UINT32)newChildren.size();
  124. newChildren.push_back(currentChild);
  125. found = true;
  126. break;
  127. }
  128. }
  129. if(!found)
  130. {
  131. SceneTreeElement* newChild = bs_new<SceneTreeElement>();
  132. newChild->mParent = element;
  133. newChild->mSceneObject = currentSOChild;
  134. newChild->mId = currentSOChild->getInstanceId();
  135. newChild->mName = currentSOChild->getName();
  136. newChild->mSortedIdx = (UINT32)newChildren.size();
  137. newChild->mIsVisible = element->mIsVisible && element->mIsExpanded;
  138. newChild->mTint = isInternal ? Color::Red : Color::White;
  139. newChildren.push_back(newChild);
  140. updateElementGUI(newChild);
  141. }
  142. }
  143. for(UINT32 i = 0; i < element->mChildren.size(); i++)
  144. {
  145. if(!tempToDelete[i])
  146. continue;
  147. deleteTreeElementInternal(element->mChildren[i]);
  148. }
  149. bs_stack_free(tempToDelete);
  150. element->mChildren = newChildren;
  151. needsUpdate = true;
  152. }
  153. // Check if name needs updating
  154. const String& name = element->mSceneObject->getName();
  155. if(element->mName != name)
  156. {
  157. element->mName = name;
  158. needsUpdate = true;
  159. }
  160. if(needsUpdate)
  161. updateElementGUI(element);
  162. for(UINT32 i = 0; i < (UINT32)element->mChildren.size(); i++)
  163. {
  164. SceneTreeElement* sceneElement = static_cast<SceneTreeElement*>(element->mChildren[i]);
  165. updateTreeElement(sceneElement);
  166. }
  167. // Calculate the sorted index of the elements based on their name
  168. bs_frame_mark();
  169. FrameVector<SceneTreeElement*> sortVector;
  170. for (auto& child : element->mChildren)
  171. sortVector.push_back(static_cast<SceneTreeElement*>(child));
  172. std::sort(sortVector.begin(), sortVector.end(),
  173. [&](const SceneTreeElement* lhs, const SceneTreeElement* rhs)
  174. {
  175. return StringUtil::compare(lhs->mName, rhs->mName, false) < 0;
  176. });
  177. UINT32 idx = 0;
  178. for (auto& child : sortVector)
  179. {
  180. child->mSortedIdx = idx;
  181. idx++;
  182. }
  183. bs_frame_clear();
  184. }
  185. void GUISceneTreeView::updateTreeElementHierarchy()
  186. {
  187. HSceneObject root = gCoreSceneManager().getRootNode();
  188. mRootElement.mSceneObject = root;
  189. mRootElement.mId = root->getInstanceId();
  190. mRootElement.mSortedIdx = 0;
  191. mRootElement.mIsExpanded = true;
  192. updateTreeElement(&mRootElement);
  193. }
  194. void GUISceneTreeView::renameTreeElement(GUITreeView::TreeElement* element, const WString& name)
  195. {
  196. SceneTreeElement* sceneTreeElement = static_cast<SceneTreeElement*>(element);
  197. HSceneObject so = sceneTreeElement->mSceneObject;
  198. CmdRecordSO::execute(so, false, L"Renamed \"" + toWString(so->getName()) + L"\"");
  199. so->setName(toString(name));
  200. onModified();
  201. }
  202. void GUISceneTreeView::deleteTreeElement(TreeElement* element)
  203. {
  204. SceneTreeElement* sceneTreeElement = static_cast<SceneTreeElement*>(element);
  205. HSceneObject so = sceneTreeElement->mSceneObject;
  206. CmdDeleteSO::execute(so, L"Deleted \"" + toWString(so->getName()) + L"\"");
  207. onModified();
  208. }
  209. void GUISceneTreeView::deleteTreeElementInternal(GUITreeView::TreeElement* element)
  210. {
  211. closeTemporarilyExpandedElements(); // In case this element is one of them
  212. if (element->mIsHighlighted)
  213. clearPing();
  214. if(element->mIsSelected)
  215. unselectElement(element);
  216. bs_delete(element);
  217. }
  218. bool GUISceneTreeView::acceptDragAndDrop() const
  219. {
  220. return DragAndDropManager::instance().isDragInProgress() &&
  221. (DragAndDropManager::instance().getDragTypeId() == (UINT32)DragAndDropType::SceneObject ||
  222. DragAndDropManager::instance().getDragTypeId() == (UINT32)DragAndDropType::Resources);
  223. }
  224. void GUISceneTreeView::dragAndDropStart()
  225. {
  226. DraggedSceneObjects* draggedSceneObjects = bs_new<DraggedSceneObjects>((UINT32)mSelectedElements.size());
  227. UINT32 cnt = 0;
  228. for(auto& selectedElement : mSelectedElements)
  229. {
  230. SceneTreeElement* sceneTreeElement = static_cast<SceneTreeElement*>(selectedElement.element);
  231. draggedSceneObjects->objects[cnt] = sceneTreeElement->mSceneObject;
  232. cnt++;
  233. }
  234. DragAndDropManager::instance().startDrag((UINT32)DragAndDropType::SceneObject, (void*)draggedSceneObjects,
  235. std::bind(&GUISceneTreeView::dragAndDropFinalize, this), false);
  236. }
  237. void GUISceneTreeView::dragAndDropEnded(TreeElement* overTreeElement)
  238. {
  239. UINT32 dragTypeId = DragAndDropManager::instance().getDragTypeId();
  240. if (dragTypeId == (UINT32)DragAndDropType::SceneObject)
  241. {
  242. if (overTreeElement != nullptr)
  243. {
  244. DraggedSceneObjects* draggedSceneObjects = reinterpret_cast<DraggedSceneObjects*>(DragAndDropManager::instance().getDragData());
  245. Vector<HSceneObject> sceneObjects;
  246. SceneTreeElement* sceneTreeElement = static_cast<SceneTreeElement*>(overTreeElement);
  247. HSceneObject newParent = sceneTreeElement->mSceneObject;
  248. for (UINT32 i = 0; i < draggedSceneObjects->numObjects; i++)
  249. {
  250. if (draggedSceneObjects->objects[i] != newParent)
  251. sceneObjects.push_back(draggedSceneObjects->objects[i]);
  252. }
  253. CmdReparentSO::execute(sceneObjects, newParent);
  254. onModified();
  255. }
  256. }
  257. else if (dragTypeId == (UINT32)DragAndDropType::Resources)
  258. {
  259. DraggedResources* draggedResources = reinterpret_cast<DraggedResources*>(DragAndDropManager::instance().getDragData());
  260. HSceneObject newParent;
  261. if (overTreeElement != nullptr)
  262. {
  263. SceneTreeElement* sceneTreeElement = static_cast<SceneTreeElement*>(overTreeElement);
  264. newParent = sceneTreeElement->mSceneObject;
  265. }
  266. onResourceDropped(newParent, draggedResources->resourcePaths);
  267. }
  268. }
  269. void GUISceneTreeView::dragAndDropFinalize()
  270. {
  271. mDragInProgress = false;
  272. _markLayoutAsDirty();
  273. if (DragAndDropManager::instance().getDragTypeId() == (UINT32)DragAndDropType::SceneObject)
  274. {
  275. DraggedSceneObjects* draggedSceneObjects = reinterpret_cast<DraggedSceneObjects*>(DragAndDropManager::instance().getDragData());
  276. bs_delete(draggedSceneObjects);
  277. }
  278. }
  279. bool GUISceneTreeView::_acceptDragAndDrop(const Vector2I position, UINT32 typeId) const
  280. {
  281. return (typeId == (UINT32)DragAndDropType::SceneObject || typeId == (UINT32)DragAndDropType::Resources) && !_isDisabled();
  282. }
  283. void GUISceneTreeView::selectionChanged()
  284. {
  285. onSelectionChanged();
  286. sendMessage(SELECTION_CHANGED_MSG);
  287. }
  288. Vector<HSceneObject> GUISceneTreeView::getSelection() const
  289. {
  290. Vector<HSceneObject> selectedSOs;
  291. for (auto& selectedElem : mSelectedElements)
  292. {
  293. SceneTreeElement* sceneTreeElement = static_cast<SceneTreeElement*>(selectedElem.element);
  294. selectedSOs.push_back(sceneTreeElement->mSceneObject);
  295. }
  296. return selectedSOs;
  297. }
  298. void GUISceneTreeView::setSelection(const Vector<HSceneObject>& objects)
  299. {
  300. unselectAll(false);
  301. // Note: I could queue the selection update until after the next frame in order to avoid the hierarchy update here
  302. // for better performance.
  303. updateTreeElementHierarchy();
  304. SceneTreeElement& root = mRootElement;
  305. Stack<SceneTreeElement*> todo;
  306. todo.push(&mRootElement);
  307. while (!todo.empty())
  308. {
  309. SceneTreeElement* currentElem = todo.top();
  310. todo.pop();
  311. auto iterFind = std::find(objects.begin(), objects.end(), currentElem->mSceneObject);
  312. if (iterFind != objects.end())
  313. {
  314. expandToElement(currentElem);
  315. selectElement(currentElem);
  316. }
  317. for (auto& child : currentElem->mChildren)
  318. {
  319. SceneTreeElement* sceneChild = static_cast<SceneTreeElement*>(child);
  320. todo.push(sceneChild);
  321. }
  322. }
  323. }
  324. void GUISceneTreeView::ping(const HSceneObject& object)
  325. {
  326. SceneTreeElement& root = mRootElement;
  327. Stack<SceneTreeElement*> todo;
  328. todo.push(&mRootElement);
  329. while (!todo.empty())
  330. {
  331. SceneTreeElement* currentElem = todo.top();
  332. todo.pop();
  333. if (currentElem->mSceneObject == object)
  334. {
  335. GUITreeView::ping(currentElem);
  336. break;
  337. }
  338. for (auto& child : currentElem->mChildren)
  339. {
  340. SceneTreeElement* sceneChild = static_cast<SceneTreeElement*>(child);
  341. todo.push(sceneChild);
  342. }
  343. }
  344. }
  345. GUISceneTreeView::SceneTreeElement* GUISceneTreeView::findTreeElement(const HSceneObject& so)
  346. {
  347. SceneTreeElement& root = mRootElement;
  348. Stack<SceneTreeElement*> todo;
  349. todo.push(&mRootElement);
  350. while (!todo.empty())
  351. {
  352. SceneTreeElement* currentElem = todo.top();
  353. todo.pop();
  354. if (so == currentElem->mSceneObject)
  355. return currentElem;
  356. for (auto& child : currentElem->mChildren)
  357. {
  358. SceneTreeElement* sceneChild = static_cast<SceneTreeElement*>(child);
  359. todo.push(sceneChild);
  360. }
  361. }
  362. return nullptr;
  363. }
  364. void GUISceneTreeView::duplicateSelection()
  365. {
  366. Vector<HSceneObject> duplicateList;
  367. for (auto& selectedElem : mSelectedElements)
  368. {
  369. SceneTreeElement* sceneElement = static_cast<SceneTreeElement*>(selectedElem.element);
  370. duplicateList.push_back(sceneElement->mSceneObject);
  371. }
  372. cleanDuplicates(duplicateList);
  373. if (duplicateList.size() == 0)
  374. return;
  375. WString message;
  376. if (duplicateList.size() == 1)
  377. message = L"Duplicated " + toWString(duplicateList[0]->getName());
  378. else
  379. message = L"Duplicated " + toWString(duplicateList.size()) + L" elements";
  380. CmdCloneSO::execute(duplicateList, message);
  381. onModified();
  382. }
  383. void GUISceneTreeView::copySelection()
  384. {
  385. clearCopyList();
  386. for (auto& selectedElem : mSelectedElements)
  387. {
  388. SceneTreeElement* sceneElement = static_cast<SceneTreeElement*>(selectedElem.element);
  389. mCopyList.push_back(sceneElement->mSceneObject);
  390. }
  391. mCutFlag = false;
  392. }
  393. void GUISceneTreeView::cutSelection()
  394. {
  395. clearCopyList();
  396. for (auto& selectedElem : mSelectedElements)
  397. {
  398. SceneTreeElement* sceneElement = static_cast<SceneTreeElement*>(selectedElem.element);
  399. mCopyList.push_back(sceneElement->mSceneObject);
  400. sceneElement->mIsGrayedOut = true;
  401. updateElementGUI(sceneElement);
  402. }
  403. mCutFlag = true;
  404. _markLayoutAsDirty();
  405. }
  406. void GUISceneTreeView::paste()
  407. {
  408. cleanDuplicates(mCopyList);
  409. if (mCopyList.size() == 0)
  410. return;
  411. HSceneObject parent = mRootElement.mSceneObject;
  412. if (mSelectedElements.size() > 0)
  413. {
  414. SceneTreeElement* sceneElement = static_cast<SceneTreeElement*>(mSelectedElements[0].element);
  415. parent = sceneElement->mSceneObject;
  416. }
  417. if (mCutFlag)
  418. {
  419. WString message;
  420. if (mCopyList.size() == 1)
  421. message = L"Moved " + toWString(mCopyList[0]->getName());
  422. else
  423. message = L"Moved " + toWString(mCopyList.size()) + L" elements";
  424. CmdReparentSO::execute(mCopyList, parent, message);
  425. clearCopyList();
  426. }
  427. else
  428. {
  429. WString message;
  430. if (mCopyList.size() == 1)
  431. message = L"Copied " + toWString(mCopyList[0]->getName());
  432. else
  433. message = L"Copied " + toWString(mCopyList.size()) + L" elements";
  434. Vector<HSceneObject> clones = CmdCloneSO::execute(mCopyList, message);
  435. for (auto& clone : clones)
  436. clone->setParent(parent);
  437. }
  438. onModified();
  439. }
  440. void GUISceneTreeView::clearCopyList()
  441. {
  442. for (auto& so : mCopyList)
  443. {
  444. if (so.isDestroyed())
  445. continue;
  446. TreeElement* treeElem = findTreeElement(so);
  447. if (treeElem != nullptr)
  448. {
  449. treeElem->mIsGrayedOut = false;
  450. updateElementGUI(treeElem);
  451. }
  452. }
  453. mCopyList.clear();
  454. _markLayoutAsDirty();
  455. }
  456. void GUISceneTreeView::createNewSO()
  457. {
  458. HSceneObject newSO = CmdCreateSO::execute("New", 0, L"Created a new SceneObject");
  459. if (mSelectedElements.size() > 0)
  460. {
  461. SceneTreeElement* sceneElement = static_cast<SceneTreeElement*>(mSelectedElements[0].element);
  462. newSO->setParent(sceneElement->mSceneObject);
  463. }
  464. updateTreeElementHierarchy();
  465. TreeElement* newTreeElement = findTreeElement(newSO);
  466. expandToElement(newTreeElement);
  467. setSelection({ newSO });
  468. renameSelected();
  469. onModified();
  470. }
  471. void GUISceneTreeView::cleanDuplicates(Vector<HSceneObject>& objects)
  472. {
  473. auto isChildOf = [&](const HSceneObject& parent, const HSceneObject& child)
  474. {
  475. HSceneObject elem = child;
  476. while (elem != nullptr && elem != parent)
  477. elem = elem->getParent();
  478. return elem == parent;
  479. };
  480. Vector<HSceneObject> cleanList;
  481. for (UINT32 i = 0; i < (UINT32)objects.size(); i++)
  482. {
  483. bool foundParent = false;
  484. for (UINT32 j = 0; j < (UINT32)objects.size(); j++)
  485. {
  486. if (i != j && isChildOf(objects[j], objects[i]))
  487. {
  488. foundParent = true;
  489. break;
  490. }
  491. }
  492. if (!foundParent)
  493. cleanList.push_back(objects[i]);
  494. }
  495. objects = cleanList;
  496. }
  497. const String& GUISceneTreeView::getGUITypeName()
  498. {
  499. static String typeName = "SceneTreeView";
  500. return typeName;
  501. }
  502. }