frameNodePort.ts 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import { NodePort } from "./nodePort";
  2. import { GraphNode } from './graphNode';
  3. import { FramePortPosition } from './graphFrame';
  4. import { GlobalState } from '../globalState';
  5. import { IDisplayManager } from './display/displayManager';
  6. import { Observable } from 'babylonjs/Misc/observable';
  7. import { Nullable } from 'babylonjs/types';
  8. import { NodeMaterialConnectionPoint } from 'babylonjs/Materials/Node/nodeMaterialBlockConnectionPoint';
  9. import { FramePortData, isFramePortData } from './graphCanvas';
  10. export class FrameNodePort extends NodePort {
  11. private _parentFrameId: number;
  12. private _isInput: boolean;
  13. private _framePortPosition: FramePortPosition
  14. private _framePortId: number;
  15. private _onFramePortPositionChangedObservable = new Observable<FrameNodePort>();
  16. public get parentFrameId () {
  17. return this._parentFrameId;
  18. }
  19. public get onFramePortPositionChangedObservable() {
  20. return this._onFramePortPositionChangedObservable;
  21. }
  22. public get isInput() {
  23. return this._isInput;
  24. }
  25. public get framePortId() {
  26. return this._framePortId;
  27. }
  28. public get framePortPosition() {
  29. return this._framePortPosition;
  30. }
  31. public set framePortPosition(position: FramePortPosition) {
  32. this._framePortPosition = position;
  33. this.onFramePortPositionChangedObservable.notifyObservers(this);
  34. }
  35. public constructor(portContainer: HTMLElement, public connectionPoint: NodeMaterialConnectionPoint, public node: GraphNode, globalState: GlobalState, isInput: boolean, framePortId: number, parentFrameId: number) {
  36. super(portContainer, connectionPoint,node, globalState);
  37. this._parentFrameId = parentFrameId;
  38. this._isInput = isInput;
  39. this._framePortId = framePortId;
  40. this._onSelectionChangedObserver = this._globalState.onSelectionChangedObservable.add((selection) => {
  41. if (isFramePortData(selection) && (selection as FramePortData).port === this) {
  42. this._img.classList.add("selected");
  43. } else {
  44. this._img.classList.remove("selected");
  45. }
  46. });
  47. this.refresh();
  48. }
  49. public static CreateFrameNodePortElement(connectionPoint: NodeMaterialConnectionPoint, node: GraphNode, root: HTMLElement,
  50. displayManager: Nullable<IDisplayManager>, globalState: GlobalState, isInput: boolean, framePortId: number, parentFrameId: number) {
  51. let portContainer = root.ownerDocument!.createElement("div");
  52. let block = connectionPoint.ownerBlock;
  53. portContainer.classList.add("portLine");
  54. if(framePortId !== null) {
  55. portContainer.dataset.framePortId = `${framePortId}`;
  56. }
  57. root.appendChild(portContainer);
  58. if (!displayManager || displayManager.shouldDisplayPortLabels(block)) {
  59. let portLabel = root.ownerDocument!.createElement("div");
  60. portLabel.classList.add("port-label");
  61. portLabel.innerHTML = connectionPoint.displayName || connectionPoint.name;
  62. portContainer.appendChild(portLabel);
  63. }
  64. return new FrameNodePort(portContainer, connectionPoint, node, globalState, isInput, framePortId, parentFrameId);
  65. }
  66. }