BooleanDataInterface.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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 <GraphModel/GraphModelBus.h>
  9. #include <GraphModel/Integration/BooleanDataInterface.h>
  10. #include <GraphModel/Integration/IntegrationBus.h>
  11. namespace GraphModelIntegration
  12. {
  13. BooleanDataInterface::BooleanDataInterface(GraphModel::SlotPtr slot)
  14. : m_slot(slot)
  15. {
  16. }
  17. bool BooleanDataInterface::GetBool() const
  18. {
  19. if (GraphModel::SlotPtr slot = m_slot.lock())
  20. {
  21. return slot->GetValue<bool>();
  22. }
  23. else
  24. {
  25. return false;
  26. }
  27. }
  28. void BooleanDataInterface::SetBool(bool enabled)
  29. {
  30. if (GraphModel::SlotPtr slot = m_slot.lock())
  31. {
  32. if (enabled != slot->GetValue<bool>())
  33. {
  34. const GraphCanvas::GraphId graphCanvasSceneId = GetDisplay()->GetSceneId();
  35. GraphCanvas::ScopedGraphUndoBatch undoBatch(graphCanvasSceneId);
  36. slot->SetValue(enabled);
  37. GraphControllerNotificationBus::Event(
  38. graphCanvasSceneId, &GraphControllerNotifications::OnGraphModelSlotModified, slot);
  39. GraphControllerNotificationBus::Event(
  40. graphCanvasSceneId, &GraphControllerNotifications::OnGraphModelGraphModified, slot->GetParentNode());
  41. }
  42. }
  43. }
  44. }