ScriptCanvasVectorDataInterface.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. #pragma once
  9. #include <GraphCanvas/Components/NodePropertyDisplay/VectorDataInterface.h>
  10. #include "ScriptCanvasDataInterface.h"
  11. namespace ScriptCanvasEditor
  12. {
  13. template<class Type, int ElementCount>
  14. class ScriptCanvasVectorizedDataInterface
  15. : public ScriptCanvasDataInterface<GraphCanvas::VectorDataInterface>
  16. {
  17. public:
  18. AZ_CLASS_ALLOCATOR(ScriptCanvasVectorizedDataInterface, AZ::SystemAllocator);
  19. ScriptCanvasVectorizedDataInterface(const AZ::EntityId& nodeId, const ScriptCanvas::SlotId& slotId)
  20. : ScriptCanvasDataInterface(nodeId, slotId)
  21. {
  22. }
  23. ~ScriptCanvasVectorizedDataInterface() = default;
  24. int GetElementCount() const override
  25. {
  26. return ElementCount;
  27. }
  28. double GetValue(int index) const override
  29. {
  30. if (index < GetElementCount())
  31. {
  32. if (const ScriptCanvas::Datum* object = GetSlotObject())
  33. {
  34. if (const Type* retVal = object->GetAs<Type>())
  35. {
  36. return aznumeric_cast<double>(static_cast<float>(retVal->GetElement(index)));
  37. }
  38. }
  39. }
  40. return 0.0;
  41. }
  42. void SetValue(int index, double value) override
  43. {
  44. if (index < GetElementCount())
  45. {
  46. ScriptCanvas::ModifiableDatumView datumView;
  47. ModifySlotObject(datumView);
  48. if (datumView.IsValid())
  49. {
  50. Type currentValue = (*datumView.GetAs<Type>());
  51. currentValue.SetElement(index, aznumeric_cast<float>(value));
  52. datumView.SetAs<Type>(currentValue);
  53. PostUndoPoint();
  54. PropertyGridRequestBus::Broadcast(&PropertyGridRequests::RefreshPropertyGrid);
  55. }
  56. }
  57. }
  58. };
  59. template<class Type, int ElementCount>
  60. class ScriptCanvasVectorDataInterface
  61. : public ScriptCanvasVectorizedDataInterface<Type, ElementCount>
  62. {
  63. public:
  64. AZ_CLASS_ALLOCATOR(ScriptCanvasVectorDataInterface, AZ::SystemAllocator);
  65. ScriptCanvasVectorDataInterface(const AZ::EntityId& nodeId, const ScriptCanvas::SlotId& slotId)
  66. : ScriptCanvasVectorizedDataInterface<Type, ElementCount>(nodeId, slotId)
  67. {
  68. }
  69. ~ScriptCanvasVectorDataInterface() = default;
  70. const char* GetLabel(int index) const override
  71. {
  72. if (index == 0)
  73. {
  74. return "X";
  75. }
  76. else if (index == 1)
  77. {
  78. return "Y";
  79. }
  80. else if (index == 2)
  81. {
  82. return "Z";
  83. }
  84. else if (index == 3)
  85. {
  86. return "W";
  87. }
  88. return "???";
  89. }
  90. AZStd::string GetStyle() const override
  91. {
  92. return "vectorized";
  93. }
  94. AZStd::string GetElementStyle(int index) const override
  95. {
  96. return AZStd::string::format("vector_%i", index);
  97. }
  98. };
  99. }