FloatDataInterface.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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/FloatDataInterface.h>
  10. #include <GraphModel/Integration/IntegrationBus.h>
  11. namespace GraphModelIntegration
  12. {
  13. FloatDataInterface::FloatDataInterface(GraphModel::SlotPtr slot)
  14. : m_slot(slot)
  15. {
  16. }
  17. double FloatDataInterface::GetNumber() const
  18. {
  19. if (GraphModel::SlotPtr slot = m_slot.lock())
  20. {
  21. return slot->GetValue<float>();
  22. }
  23. else
  24. {
  25. return 0.0;
  26. }
  27. }
  28. void FloatDataInterface::SetNumber(double value)
  29. {
  30. if (GraphModel::SlotPtr slot = m_slot.lock())
  31. {
  32. if (static_cast<float>(value) != slot->GetValue<float>())
  33. {
  34. const GraphCanvas::GraphId graphCanvasSceneId = GetDisplay()->GetSceneId();
  35. GraphCanvas::ScopedGraphUndoBatch undoBatch(graphCanvasSceneId);
  36. slot->SetValue(static_cast<float>(value));
  37. GraphControllerNotificationBus::Event(
  38. graphCanvasSceneId, &GraphControllerNotifications::OnGraphModelSlotModified, slot);
  39. GraphControllerNotificationBus::Event(
  40. graphCanvasSceneId, &GraphControllerNotifications::OnGraphModelGraphModified, slot->GetParentNode());
  41. }
  42. }
  43. }
  44. int FloatDataInterface::GetDecimalPlaces() const
  45. {
  46. return 7;
  47. }
  48. int FloatDataInterface::GetDisplayDecimalPlaces() const
  49. {
  50. return 4;
  51. }
  52. double FloatDataInterface::GetMin() const
  53. {
  54. return std::numeric_limits<float>::lowest();
  55. }
  56. double FloatDataInterface::GetMax() const
  57. {
  58. return std::numeric_limits<float>::max();
  59. }
  60. }