flowGraphDataConnection.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. import { RegisterClass } from "../Misc/typeStore.js";
  2. import { FlowGraphConnection, FlowGraphConnectionType } from "./flowGraphConnection.js";
  3. import { RichType } from "./flowGraphRichTypes.js";
  4. /**
  5. * @experimental
  6. * Represents a connection point for data.
  7. * An unconnected input point can have a default value.
  8. * An output point will only have a value if it is connected to an input point. Furthermore,
  9. * if the point belongs to a "function" node, the node will run its function to update the value.
  10. */
  11. export class FlowGraphDataConnection extends FlowGraphConnection {
  12. /**
  13. * Create a new data connection point.
  14. * @param name
  15. * @param connectionType
  16. * @param ownerBlock
  17. * @param richType
  18. */
  19. constructor(name, connectionType, ownerBlock,
  20. /**
  21. * the type of the data in this block
  22. */
  23. richType) {
  24. super(name, connectionType, ownerBlock);
  25. this.richType = richType;
  26. }
  27. /**
  28. * An output data block can connect to multiple input data blocks,
  29. * but an input data block can only connect to one output data block.
  30. * @returns true if the connection is singular
  31. */
  32. _isSingularConnection() {
  33. return this.connectionType === FlowGraphConnectionType.Input;
  34. }
  35. /**
  36. * Set the value of the connection in a specific context.
  37. * @param value the value to set
  38. * @param context the context to which the value is set
  39. */
  40. setValue(value, context) {
  41. context._setConnectionValue(this, value);
  42. }
  43. /**
  44. * Connect this point to another point.
  45. * @param point the point to connect to.
  46. */
  47. connectTo(point) {
  48. super.connectTo(point);
  49. }
  50. _getValueOrDefault(context) {
  51. if (context._hasConnectionValue(this)) {
  52. return context._getConnectionValue(this);
  53. }
  54. else {
  55. return this.richType.defaultValue;
  56. }
  57. }
  58. /**
  59. * Gets the value of the connection in a specific context.
  60. * @param context the context from which the value is retrieved
  61. * @returns the value of the connection
  62. */
  63. getValue(context) {
  64. if (this.connectionType === FlowGraphConnectionType.Output) {
  65. context._notifyExecuteNode(this._ownerBlock);
  66. this._ownerBlock._updateOutputs(context);
  67. return this._getValueOrDefault(context);
  68. }
  69. if (!this.isConnected()) {
  70. return this._getValueOrDefault(context);
  71. }
  72. else {
  73. return this._connectedPoint[0].getValue(context);
  74. }
  75. }
  76. /**
  77. * @returns class name of the object.
  78. */
  79. getClassName() {
  80. return "FGDataConnection";
  81. }
  82. /**
  83. * Serializes this object.
  84. * @param serializationObject the object to serialize to
  85. */
  86. serialize(serializationObject = {}) {
  87. super.serialize(serializationObject);
  88. serializationObject.richType = {};
  89. this.richType.serialize(serializationObject.richType);
  90. }
  91. /**
  92. * Parses a data connection from a serialized object.
  93. * @param serializationObject the object to parse from
  94. * @param ownerBlock the block that owns the connection
  95. * @returns the parsed connection
  96. */
  97. static Parse(serializationObject, ownerBlock) {
  98. const obj = FlowGraphConnection.Parse(serializationObject, ownerBlock);
  99. obj.richType = RichType.Parse(serializationObject.richType);
  100. return obj;
  101. }
  102. }
  103. RegisterClass("FGDataConnection", FlowGraphDataConnection);
  104. //# sourceMappingURL=flowGraphDataConnection.js.map