ScriptableImGui.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include <Automation/ScriptableImGui.h>
  9. #include <Automation/ScriptRepeaterBus.h>
  10. #include <AzFramework/StringFunc/StringFunc.h>
  11. #include <Utils/Utils.h>
  12. namespace AtomSampleViewer
  13. {
  14. ScriptableImGui* ScriptableImGui::s_instance = nullptr;
  15. void ScriptableImGui::Create()
  16. {
  17. AZ_Assert(s_instance == nullptr, "instance already called");
  18. s_instance = aznew ScriptableImGui();
  19. }
  20. void ScriptableImGui::Destory()
  21. {
  22. AZ_Assert(s_instance != nullptr, "instance is null");
  23. delete s_instance;
  24. s_instance = nullptr;
  25. }
  26. void ScriptableImGui::CheckAllActionsConsumed()
  27. {
  28. AZ_DEBUG_STATIC_MEMEBER(instance, s_instance);
  29. AZ_Error("Automation", s_instance->m_scriptedActions.empty(), "Not all scripted ImGui actions were consumed");
  30. for (auto iter : s_instance->m_scriptedActions)
  31. {
  32. AZ_Error("Automation", false, "Scripted action for '%s' not consumed", iter.first.c_str());
  33. }
  34. AZ_Error("Automation", s_instance->m_nameContextStack.empty(), "PushNameContext and PopNameContext calls didn't match");
  35. }
  36. void ScriptableImGui::ClearActions()
  37. {
  38. AZ_DEBUG_STATIC_MEMEBER(instance, s_instance);
  39. s_instance->m_scriptedActions.clear();
  40. s_instance->m_nameContextStack.clear();
  41. }
  42. void ScriptableImGui::PushNameContext(const AZStd::string& nameContext)
  43. {
  44. AZ_DEBUG_STATIC_MEMEBER(instance, s_instance);
  45. s_instance->m_nameContextStack.push_back(nameContext);
  46. }
  47. void ScriptableImGui::PopNameContext()
  48. {
  49. AZ_DEBUG_STATIC_MEMEBER(instance, s_instance);
  50. AZ_Assert(!s_instance->m_nameContextStack.empty(), "Called PopNameContext too many times");
  51. s_instance->m_nameContextStack.pop_back();
  52. }
  53. ScriptableImGui::ActionItem ScriptableImGui::FindAndRemoveAction(const AZStd::string& pathToImGuiItem)
  54. {
  55. AZ_DEBUG_STATIC_MEMEBER(instance, s_instance);
  56. auto iter = s_instance->m_scriptedActions.find(pathToImGuiItem);
  57. if (iter != s_instance->m_scriptedActions.end())
  58. {
  59. ScriptableImGui::ActionItem item = AZStd::move(iter->second);
  60. s_instance->m_scriptedActions.erase(iter);
  61. return AZStd::move(item);
  62. }
  63. return ScriptableImGui::ActionItem{};
  64. }
  65. AZStd::string ScriptableImGui::MakeFullPath(const AZStd::string& forLabel)
  66. {
  67. static constexpr char Delimiter[] = "/";
  68. AZStd::string fullPath;
  69. if (!s_instance->m_nameContextStack.empty())
  70. {
  71. AzFramework::StringFunc::Join(fullPath, s_instance->m_nameContextStack.begin(), s_instance->m_nameContextStack.end(), Delimiter);
  72. fullPath += Delimiter;
  73. }
  74. fullPath += forLabel;
  75. return fullPath;
  76. }
  77. void ScriptableImGui::ReportScriptError([[maybe_unused]] const char* message)
  78. {
  79. AZ_Error("Automation", false, "Script: %s", message);
  80. }
  81. void ScriptableImGui::SetBool(const AZStd::string& pathToImGuiItem, bool value)
  82. {
  83. AZ_DEBUG_STATIC_MEMEBER(instance, s_instance);
  84. s_instance->m_scriptedActions[pathToImGuiItem] = value;
  85. }
  86. void ScriptableImGui::SetNumber(const AZStd::string& pathToImGuiItem, float value)
  87. {
  88. AZ_DEBUG_STATIC_MEMEBER(instance, s_instance);
  89. s_instance->m_scriptedActions[pathToImGuiItem] = value;
  90. }
  91. void ScriptableImGui::SetVector(const AZStd::string& pathToImGuiItem, const AZ::Vector2& value)
  92. {
  93. AZ_DEBUG_STATIC_MEMEBER(instance, s_instance);
  94. s_instance->m_scriptedActions[pathToImGuiItem] = value;
  95. }
  96. void ScriptableImGui::SetVector(const AZStd::string& pathToImGuiItem, const AZ::Vector3& value)
  97. {
  98. AZ_DEBUG_STATIC_MEMEBER(instance, s_instance);
  99. s_instance->m_scriptedActions[pathToImGuiItem] = value;
  100. }
  101. void ScriptableImGui::SetString(const AZStd::string& pathToImGuiItem, const AZStd::string& value)
  102. {
  103. AZ_DEBUG_STATIC_MEMEBER(instance, s_instance);
  104. s_instance->m_scriptedActions[pathToImGuiItem] = value;
  105. }
  106. template<typename ActionDataT>
  107. bool ScriptableImGui::ActionHelper(
  108. const char* label,
  109. AZStd::function<bool()> imguiAction,
  110. AZStd::function<void(const AZStd::string& /*pathToImGuiItem*/)> reportScriptableAction,
  111. AZStd::function<bool(ActionDataT /*scriptArg*/)> handleScriptedAction,
  112. bool shouldReportScriptableActionAfterAnyChange)
  113. {
  114. bool imResult = imguiAction();
  115. const AZStd::string pathToImGuiItem = MakeFullPath(label);
  116. if (ImGui::IsItemDeactivatedAfterEdit() || (shouldReportScriptableActionAfterAnyChange && imResult))
  117. {
  118. reportScriptableAction(pathToImGuiItem);
  119. }
  120. bool scriptResult = false;
  121. ActionItem actionItem = FindAndRemoveAction(pathToImGuiItem);
  122. bool foundAction = !AZStd::holds_alternative<InvalidActionItem>(actionItem);
  123. if (foundAction)
  124. {
  125. if (AZStd::holds_alternative<ActionDataT>(actionItem))
  126. {
  127. scriptResult = handleScriptedAction(AZStd::get<ActionDataT>(actionItem));
  128. }
  129. else
  130. {
  131. ReportScriptError(AZStd::string::format("Wrong data type used to set '%s'", pathToImGuiItem.c_str()).c_str());
  132. }
  133. }
  134. return imResult || scriptResult;
  135. }
  136. bool ScriptableImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
  137. {
  138. PushNameContext(name);
  139. return ImGui::Begin(name, p_open, flags);
  140. }
  141. void ScriptableImGui::End()
  142. {
  143. ImGui::End();
  144. PopNameContext();
  145. }
  146. bool ScriptableImGui::Checkbox(const char* label, bool* v)
  147. {
  148. auto imguiAction = [&]()
  149. {
  150. return ImGui::Checkbox(label, v);
  151. };
  152. auto reportScriptableAction = [&](const AZStd::string& pathToImGuiItem)
  153. {
  154. Utils::ReportScriptableAction("SetImguiValue('%s', %s)", pathToImGuiItem.c_str(), (*v ? "true" : "false"));
  155. };
  156. auto handleScriptedAction = [&](bool scriptArg)
  157. {
  158. if (*v != scriptArg)
  159. {
  160. *v = scriptArg;
  161. return true;
  162. }
  163. return false;
  164. };
  165. return ActionHelper<bool>(label, imguiAction, reportScriptableAction, handleScriptedAction);
  166. }
  167. bool ScriptableImGui::Button(const char* label, const ImVec2& size_arg)
  168. {
  169. auto imguiAction = [&]()
  170. {
  171. return ImGui::Button(label, size_arg);
  172. };
  173. auto reportScriptableAction = [&](const AZStd::string& pathToImGuiItem)
  174. {
  175. Utils::ReportScriptableAction("SetImguiValue('%s', true)", pathToImGuiItem.c_str());
  176. };
  177. auto handleScriptedAction = [](bool scriptArg)
  178. {
  179. return scriptArg;
  180. };
  181. return ActionHelper<bool>(label, imguiAction, reportScriptableAction, handleScriptedAction);
  182. }
  183. bool ScriptableImGui::ListBox(const char* label, int* current_item, bool(*items_getter)(void* data, int idx, const char** out_text), void* data, int items_count, int height_in_items)
  184. {
  185. auto imguiAction = [&]()
  186. {
  187. return ImGui::ListBox(label, current_item, items_getter, data, items_count, height_in_items);
  188. };
  189. auto reportScriptableAction = [&](const AZStd::string& pathToImGuiItem)
  190. {
  191. const char* itemText = nullptr;
  192. if (items_getter(data, *current_item, &itemText) && itemText)
  193. {
  194. Utils::ReportScriptableAction("SetImguiValue('%s', '%s')", pathToImGuiItem.c_str(), itemText);
  195. }
  196. };
  197. auto handleScriptedAction = [&](AZStd::string scriptArg)
  198. {
  199. for (int i = 0; i < items_count; ++i)
  200. {
  201. const char* itemText = nullptr;
  202. if (items_getter(data, i, &itemText) && itemText && scriptArg == itemText)
  203. {
  204. *current_item = i;
  205. return true;
  206. }
  207. }
  208. ReportScriptError(AZStd::string::format("List '%s' does not contain item '%s'", label, scriptArg.c_str()).c_str());
  209. return false;
  210. };
  211. return ActionHelper<AZStd::string>(label, imguiAction, reportScriptableAction, handleScriptedAction);
  212. }
  213. bool ScriptableImGui::Combo(const char* label, int* current_item, const char* const items[], int items_count, int height_in_items)
  214. {
  215. auto imguiAction = [&]()
  216. {
  217. return ImGui::Combo(label, current_item, items, items_count, height_in_items);
  218. };
  219. auto reportScriptableAction = [&](const AZStd::string& pathToImGuiItem)
  220. {
  221. Utils::ReportScriptableAction("SetImguiValue('%s', '%s')", pathToImGuiItem.c_str(), items[*current_item]);
  222. };
  223. auto handleScriptedAction = [&](AZStd::string scriptArg)
  224. {
  225. for (int i = 0; i < items_count; ++i)
  226. {
  227. if (items[i] == scriptArg)
  228. {
  229. *current_item = i;
  230. return true;
  231. }
  232. }
  233. ReportScriptError(AZStd::string::format("Combo box '%s' does not contain item '%s'", label, scriptArg.c_str()).c_str());
  234. return false;
  235. };
  236. return ActionHelper<AZStd::string>(label, imguiAction, reportScriptableAction, handleScriptedAction,
  237. true /* It seems ImGui::Combo doesn't work with IsItemDeactivatedAfterChange() */);
  238. }
  239. bool ScriptableImGui::RadioButton(const char* label, int* v, int v_button)
  240. {
  241. auto imguiAction = [&]()
  242. {
  243. return ImGui::RadioButton(label, v, v_button);
  244. };
  245. auto reportScriptableAction = [&](const AZStd::string& pathToImGuiItem)
  246. {
  247. Utils::ReportScriptableAction("SetImguiValue('%s', true)", pathToImGuiItem.c_str());
  248. };
  249. auto handleScriptedAction = [&](bool scriptArg)
  250. {
  251. if (scriptArg)
  252. {
  253. *v = v_button;
  254. return true;
  255. }
  256. return false;
  257. };
  258. return ActionHelper<bool>(label, imguiAction, reportScriptableAction, handleScriptedAction);
  259. }
  260. bool ScriptableImGui::SliderInt(const char* label, int* v, int v_min, int v_max, const char* format)
  261. {
  262. auto imguiAction = [&]()
  263. {
  264. return ImGui::SliderInt(label, v, v_min, v_max, format);
  265. };
  266. auto reportScriptableAction = [&](const AZStd::string& pathToImGuiItem)
  267. {
  268. Utils::ReportScriptableAction("SetImguiValue('%s', %d)", pathToImGuiItem.c_str(), *v);
  269. };
  270. auto handleScriptedAction = [&](float scriptArg)
  271. {
  272. *v = aznumeric_cast<int>(scriptArg);
  273. return true;
  274. };
  275. return ActionHelper<float>(label, imguiAction, reportScriptableAction, handleScriptedAction);
  276. }
  277. bool ScriptableImGui::SliderFloat(const char* label, float* v, float v_min, float v_max, const char* format, ImGuiSliderFlags flags)
  278. {
  279. auto imguiAction = [&]()
  280. {
  281. return ImGui::SliderFloat(label, v, v_min, v_max, format, flags);
  282. };
  283. auto reportScriptableAction = [&](const AZStd::string& pathToImGuiItem)
  284. {
  285. Utils::ReportScriptableAction("SetImguiValue('%s', %f)", pathToImGuiItem.c_str(), *v);
  286. };
  287. auto handleScriptedAction = [&](float scriptArg)
  288. {
  289. *v = scriptArg;
  290. return true;
  291. };
  292. return ActionHelper<float>(label, imguiAction, reportScriptableAction, handleScriptedAction);
  293. }
  294. bool ScriptableImGui::SliderFloat2(const char* label, float v[2], float v_min, float v_max, const char* format, ImGuiSliderFlags flags)
  295. {
  296. auto imguiAction = [&]()
  297. {
  298. return ImGui::SliderFloat2(label, v, v_min, v_max, format, flags);
  299. };
  300. auto reportScriptableAction = [&](const AZStd::string& pathToImGuiItem)
  301. {
  302. Utils::ReportScriptableAction("SetImguiValue('%s', Vector2(%f, %f))", pathToImGuiItem.c_str(), v[0], v[1]);
  303. };
  304. auto handleScriptedAction = [&](AZ::Vector2 scriptArg)
  305. {
  306. v[0] = scriptArg.GetX();
  307. v[1] = scriptArg.GetY();
  308. return true;
  309. };
  310. return ActionHelper<AZ::Vector2>(label, imguiAction, reportScriptableAction, handleScriptedAction);
  311. }
  312. template <typename ImGuiActionType>
  313. bool ScriptableImGui::ThreeComponentHelper(const char* label, float v[3], ImGuiActionType& imguiAction)
  314. {
  315. auto reportScriptableAction = [&](const AZStd::string& pathToImGuiItem)
  316. {
  317. Utils::ReportScriptableAction("SetImguiValue('%s', Vector3(%f, %f, %f))", pathToImGuiItem.c_str(), v[0], v[1], v[2]);
  318. };
  319. auto handleScriptedAction = [&](AZ::Vector3 scriptArg)
  320. {
  321. v[0] = scriptArg.GetX();
  322. v[1] = scriptArg.GetY();
  323. v[2] = scriptArg.GetZ();
  324. return true;
  325. };
  326. return ActionHelper<AZ::Vector3>(label, imguiAction, reportScriptableAction, handleScriptedAction);
  327. }
  328. bool ScriptableImGui::SliderFloat3(const char* label, float v[3], float v_min, float v_max, const char* format, ImGuiSliderFlags flags)
  329. {
  330. auto imguiAction = [&]()
  331. {
  332. return ImGui::SliderFloat3(label, v, v_min, v_max, format, flags);
  333. };
  334. return ThreeComponentHelper(label, v, imguiAction);
  335. }
  336. bool ScriptableImGui::ColorEdit3(const char* label, float v[3], ImGuiColorEditFlags flags)
  337. {
  338. auto imguiAction = [&]()
  339. {
  340. return ImGui::ColorEdit3(label, v, flags);
  341. };
  342. return ThreeComponentHelper(label, v, imguiAction);
  343. }
  344. bool ScriptableImGui::ColorPicker3(const char* label, float v[3], ImGuiColorEditFlags flags)
  345. {
  346. auto imguiAction = [&]()
  347. {
  348. return ImGui::ColorPicker3(label, v, flags);
  349. };
  350. return ThreeComponentHelper(label, v, imguiAction);
  351. }
  352. bool ScriptableImGui::SliderAngle(const char* label, float* v, float v_min, float v_max, const char* format)
  353. {
  354. auto imguiAction = [&]()
  355. {
  356. return ImGui::SliderAngle(label, v, v_min, v_max, format);
  357. };
  358. auto reportScriptableAction = [&](const AZStd::string& pathToImGuiItem)
  359. {
  360. Utils::ReportScriptableAction("SetImguiValue('%s', %f)", pathToImGuiItem.c_str(), *v);
  361. };
  362. auto handleScriptedAction = [&](float scriptArg)
  363. {
  364. *v = scriptArg;
  365. return true;
  366. };
  367. return ActionHelper<float>(label, imguiAction, reportScriptableAction, handleScriptedAction);
  368. }
  369. bool ScriptableImGui::Selectable(const char* label, bool selected, ImGuiSelectableFlags flags, const ImVec2& size)
  370. {
  371. auto imguiAction = [&]()
  372. {
  373. return ImGui::Selectable(label, selected, flags, size);
  374. };
  375. auto reportScriptableAction = [&](const AZStd::string& pathToImGuiItem)
  376. {
  377. // The "selected" value that's passed determines if the selectable is *currently* selected, and clicking the selectable toggles its state.
  378. // So when someone clicks the selectable to change its state, we need to report the opposite of what the original state was.
  379. Utils::ReportScriptableAction("SetImguiValue('%s', %s)", pathToImGuiItem.c_str(), (selected ? "false" : "true"));
  380. };
  381. auto handleScriptedAction = [&](bool scriptArg)
  382. {
  383. return scriptArg != selected;
  384. };
  385. return ActionHelper<bool>(label, imguiAction, reportScriptableAction, handleScriptedAction);
  386. }
  387. bool ScriptableImGui::Selectable(const char* label, bool* p_selected, ImGuiSelectableFlags flags, const ImVec2& size)
  388. {
  389. auto imguiAction = [&]()
  390. {
  391. return ImGui::Selectable(label, p_selected, flags, size);
  392. };
  393. auto reportScriptableAction = [&](const AZStd::string& pathToImGuiItem)
  394. {
  395. // The "selected" value that's passed determines if the selectable is *currently* selected, and clicking the selectable toggles its state.
  396. // So when someone clicks the selectable to change its state, we need to report the opposite of what the original state was.
  397. Utils::ReportScriptableAction("SetImguiValue('%s', %s)", pathToImGuiItem.c_str(), (*p_selected ? "false" : "true"));
  398. };
  399. auto handleScriptedAction = [&](bool scriptArg)
  400. {
  401. if (scriptArg != *p_selected)
  402. {
  403. *p_selected = scriptArg;
  404. return true;
  405. }
  406. return false;
  407. };
  408. return ActionHelper<bool>(label, imguiAction, reportScriptableAction, handleScriptedAction);
  409. }
  410. bool ScriptableImGui::TreeNodeEx(const char* label, ImGuiSelectableFlags flags)
  411. {
  412. AZ_DEBUG_STATIC_MEMEBER(instance, s_instance);
  413. if (ImGui::TreeNodeEx(label, flags))
  414. {
  415. PushNameContext(label);
  416. return true;
  417. }
  418. return false;
  419. }
  420. void ScriptableImGui::TreePop()
  421. {
  422. ImGui::TreePop();
  423. PopNameContext();
  424. }
  425. bool ScriptableImGui::BeginCombo(const char* label, const char* preview_value, ImGuiComboFlags flags)
  426. {
  427. AZ_DEBUG_STATIC_MEMEBER(instance, s_instance);
  428. const AZStd::string pathToImGuiItem = MakeFullPath(label);
  429. if (ImGui::BeginCombo(label, preview_value, flags))
  430. {
  431. PushNameContext(label);
  432. return true;
  433. }
  434. else if (!s_instance->m_scriptedActions.empty())
  435. {
  436. // If a script is running, we return true so that imgui controls inside the combo box are checked.
  437. // We also have to set a flag to prevent ScriptableImGui::EndCombo() from calling ImGui::EndCombo()
  438. // because that is only allowed when ImGui::BeginCombo() returns true.
  439. s_instance->m_isInScriptedComboPopup = true;
  440. PushNameContext(label);
  441. return true;
  442. }
  443. return false;
  444. }
  445. void ScriptableImGui::EndCombo()
  446. {
  447. if (s_instance->m_isInScriptedComboPopup)
  448. {
  449. s_instance->m_isInScriptedComboPopup = false;
  450. // ScriptableImGui::BeginCombo() returned true even though ImGui::BeginCombo() didn't, so we aren't allowed
  451. // to call ImGui::EndCombo() here.
  452. }
  453. else
  454. {
  455. ImGui::EndCombo();
  456. }
  457. PopNameContext();
  458. }
  459. bool ScriptableImGui::BeginMenu(const char* label, bool enabled)
  460. {
  461. // We don't use ActionHelper here because BeginMenu has to do things a bit different since there is a persistent popup.
  462. // It has to run the script code before the ImGui code, and if there is a scripted action then force the menu to open.
  463. // Also, we don't include a "scriptResult", just the "imResult", because we need to ensure that ImGui is in the actual
  464. // state we are reporting back to the caller. Otherwise the internal state of ImGui could become invalid and crash.
  465. const AZStd::string pathToImGuiItem = MakeFullPath(label);
  466. ActionItem actionItem = FindAndRemoveAction(pathToImGuiItem);
  467. bool foundAction = !AZStd::holds_alternative<InvalidActionItem>(actionItem);
  468. if (foundAction)
  469. {
  470. if (AZStd::holds_alternative<bool>(actionItem))
  471. {
  472. if (AZStd::get<bool>(actionItem))
  473. {
  474. // Here we force the menu to open before arriving at ImGui::BeginMenu
  475. ImGui::OpenPopup(label);
  476. }
  477. }
  478. else
  479. {
  480. ReportScriptError(AZStd::string::format("Wrong data type used to set '%s'", label).c_str());
  481. }
  482. }
  483. bool wasPopupOpen = ImGui::IsPopupOpen(label);
  484. bool isPopupOpen = ImGui::BeginMenu(label, enabled);
  485. if (isPopupOpen)
  486. {
  487. PushNameContext(label);
  488. if (!wasPopupOpen && isPopupOpen)
  489. {
  490. Utils::ReportScriptableAction("SetImguiValue('%s', true)", pathToImGuiItem.c_str());
  491. }
  492. }
  493. return isPopupOpen;
  494. }
  495. void ScriptableImGui::EndMenu()
  496. {
  497. ImGui::EndMenu();
  498. PopNameContext();
  499. }
  500. bool ScriptableImGui::MenuItem(const char* label, const char* shortcut, bool selected, bool enabled)
  501. {
  502. auto imguiAction = [&]()
  503. {
  504. return ImGui::MenuItem(label, shortcut, selected, enabled);
  505. };
  506. auto reportScriptableAction = [&](const AZStd::string& pathToImGuiItem)
  507. {
  508. Utils::ReportScriptableAction("SetImguiValue('%s', true)", pathToImGuiItem.c_str());
  509. };
  510. auto handleScriptedAction = [](bool scriptArg)
  511. {
  512. return scriptArg;
  513. };
  514. return ActionHelper<bool>(label, imguiAction, reportScriptableAction, handleScriptedAction);
  515. }
  516. } // namespace AtomSampleViewer