Added Orphan connection cleanup and logging.
This commit is contained in:
parent
6ec28efe78
commit
f26aa01211
@ -21,10 +21,12 @@ export function grabAndClone(diagramManager: DiagramManager, mesh: AbstractMesh,
|
|||||||
scale: vectoxys(mesh.scaling)
|
scale: vectoxys(mesh.scaling)
|
||||||
|
|
||||||
}
|
}
|
||||||
const obj = new DiagramObject(parent.getScene(), {
|
const obj = new DiagramObject(parent.getScene(),
|
||||||
diagramEntity: entity,
|
diagramManager.onDiagramEventObservable,
|
||||||
actionManager: diagramManager.actionManager
|
{
|
||||||
});
|
diagramEntity: entity,
|
||||||
|
actionManager: diagramManager.actionManager
|
||||||
|
});
|
||||||
obj.baseTransform.setParent(parent);
|
obj.baseTransform.setParent(parent);
|
||||||
diagramManager.addObject(obj);
|
diagramManager.addObject(obj);
|
||||||
return obj;
|
return obj;
|
||||||
|
|||||||
@ -37,7 +37,7 @@ export class DiagramManager {
|
|||||||
rotation: {x: 0, y: Math.PI, z: 0},
|
rotation: {x: 0, y: Math.PI, z: 0},
|
||||||
scale: {x: 1, y: 1, z: 1},
|
scale: {x: 1, y: 1, z: 1},
|
||||||
}
|
}
|
||||||
const object = new DiagramObject(this._scene, {diagramEntity: diagramEntity});
|
const object = new DiagramObject(this._scene, this.onDiagramEventObservable, {diagramEntity: diagramEntity});
|
||||||
this._diagramObjects.set(diagramEntity.id, object);
|
this._diagramObjects.set(diagramEntity.id, object);
|
||||||
|
|
||||||
//const newMesh = buildMeshFromDiagramEntity(diagramEntity, this._scene);
|
//const newMesh = buildMeshFromDiagramEntity(diagramEntity, this._scene);
|
||||||
@ -98,6 +98,7 @@ export class DiagramManager {
|
|||||||
diagramObject.fromDiagramEntity(event.entity);
|
diagramObject.fromDiagramEntity(event.entity);
|
||||||
} else {
|
} else {
|
||||||
diagramObject = new DiagramObject(this._scene,
|
diagramObject = new DiagramObject(this._scene,
|
||||||
|
this.onDiagramEventObservable,
|
||||||
{diagramEntity: event.entity, actionManager: this._diagramEntityActionManager});
|
{diagramEntity: event.entity, actionManager: this._diagramEntityActionManager});
|
||||||
}
|
}
|
||||||
if (diagramObject) {
|
if (diagramObject) {
|
||||||
|
|||||||
@ -1,9 +1,20 @@
|
|||||||
import {AbstractActionManager, AbstractMesh, Mesh, Observer, Scene, TransformNode, Vector3} from "@babylonjs/core";
|
import {
|
||||||
import {DiagramEntity} from "../diagram/types/diagramEntity";
|
AbstractActionManager,
|
||||||
|
AbstractMesh,
|
||||||
|
Mesh,
|
||||||
|
Observable,
|
||||||
|
Observer,
|
||||||
|
Scene,
|
||||||
|
TransformNode,
|
||||||
|
Vector3
|
||||||
|
} from "@babylonjs/core";
|
||||||
|
import {DiagramEntity, DiagramEvent, DiagramEventType} from "../diagram/types/diagramEntity";
|
||||||
import {buildMeshFromDiagramEntity} from "../diagram/functions/buildMeshFromDiagramEntity";
|
import {buildMeshFromDiagramEntity} from "../diagram/functions/buildMeshFromDiagramEntity";
|
||||||
import {toDiagramEntity} from "../diagram/functions/toDiagramEntity";
|
import {toDiagramEntity} from "../diagram/functions/toDiagramEntity";
|
||||||
import {v4 as uuidv4} from 'uuid';
|
import {v4 as uuidv4} from 'uuid';
|
||||||
import {createLabel} from "../diagram/functions/createLabel";
|
import {createLabel} from "../diagram/functions/createLabel";
|
||||||
|
import {DiagramEventObserverMask} from "../diagram/types/diagramEventObserverMask";
|
||||||
|
import log, {Logger} from "loglevel";
|
||||||
|
|
||||||
type DiagramObjectOptionsType = {
|
type DiagramObjectOptionsType = {
|
||||||
diagramEntity?: DiagramEntity,
|
diagramEntity?: DiagramEntity,
|
||||||
@ -12,12 +23,13 @@ type DiagramObjectOptionsType = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class DiagramObject {
|
export class DiagramObject {
|
||||||
|
private readonly _logger: Logger = log.getLogger('DiagramObject');
|
||||||
private _scene: Scene;
|
private _scene: Scene;
|
||||||
private _from: string;
|
private _from: string;
|
||||||
private _to: string;
|
private _to: string;
|
||||||
private _observingStart: number;
|
private _observingStart: number;
|
||||||
private _sceneObserver: Observer<Scene>;
|
private _sceneObserver: Observer<Scene>;
|
||||||
private _observer: Observer<AbstractMesh>;
|
private _eventObservable: Observable<DiagramEvent>;
|
||||||
|
|
||||||
private _mesh: AbstractMesh;
|
private _mesh: AbstractMesh;
|
||||||
private _label: AbstractMesh;
|
private _label: AbstractMesh;
|
||||||
@ -25,15 +37,19 @@ export class DiagramObject {
|
|||||||
return this._mesh;
|
return this._mesh;
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(scene: Scene, options?: DiagramObjectOptionsType) {
|
constructor(scene: Scene, eventObservable: Observable<DiagramEvent>, options?: DiagramObjectOptionsType) {
|
||||||
|
this._eventObservable = eventObservable;
|
||||||
this._scene = scene;
|
this._scene = scene;
|
||||||
if (options) {
|
if (options) {
|
||||||
|
this._logger.debug('DiagramObject constructor called with options', options);
|
||||||
if (options.diagramEntity) {
|
if (options.diagramEntity) {
|
||||||
|
this._logger.debug('DiagramObject constructor called with diagramEntity', options);
|
||||||
if (!options.diagramEntity.id) {
|
if (!options.diagramEntity.id) {
|
||||||
options.diagramEntity.id = 'id' + uuidv4();
|
options.diagramEntity.id = 'id' + uuidv4();
|
||||||
}
|
}
|
||||||
const myEntity = this.fromDiagramEntity(options.diagramEntity);
|
const myEntity = this.fromDiagramEntity(options.diagramEntity);
|
||||||
if (!myEntity) {
|
if (!myEntity) {
|
||||||
|
this._logger.warn('DiagramObject constructor called with invalid diagramEntity', options.diagramEntity);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -58,7 +74,6 @@ export class DiagramObject {
|
|||||||
public get diagramEntity(): DiagramEntity {
|
public get diagramEntity(): DiagramEntity {
|
||||||
if (this._mesh) {
|
if (this._mesh) {
|
||||||
this._diagramEntity = toDiagramEntity(this._mesh);
|
this._diagramEntity = toDiagramEntity(this._mesh);
|
||||||
|
|
||||||
}
|
}
|
||||||
return this._diagramEntity;
|
return this._diagramEntity;
|
||||||
}
|
}
|
||||||
@ -89,11 +104,11 @@ export class DiagramObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public clone(): DiagramObject {
|
public clone(): DiagramObject {
|
||||||
const clone = new DiagramObject(this._scene, {actionManager: this._mesh.actionManager});
|
const clone = new DiagramObject(this._scene, this._eventObservable, {actionManager: this._mesh.actionManager});
|
||||||
const newEntity = {...this._diagramEntity};
|
const newEntity = {...this._diagramEntity};
|
||||||
newEntity.id = 'id' + uuidv4();
|
newEntity.id = 'id' + uuidv4();
|
||||||
clone.fromDiagramEntity(this._diagramEntity);
|
clone.fromDiagramEntity(this._diagramEntity);
|
||||||
|
this._logger.debug('DiagramObject clone called', clone, this._diagramEntity, newEntity);
|
||||||
return clone;
|
return clone;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -125,6 +140,11 @@ export class DiagramObject {
|
|||||||
this.updateConnection(fromMesh, toMesh);
|
this.updateConnection(fromMesh, toMesh);
|
||||||
} else {
|
} else {
|
||||||
if (Date.now() - this._observingStart > 5000) {
|
if (Date.now() - this._observingStart > 5000) {
|
||||||
|
this._logger.warn('DiagramObject connection timeout for: ', this._from, this._to, ' removing');
|
||||||
|
this._eventObservable.notifyObservers({
|
||||||
|
type: DiagramEventType.REMOVE,
|
||||||
|
entity: this._diagramEntity
|
||||||
|
}, DiagramEventObserverMask.ALL);
|
||||||
this.dispose();
|
this.dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -146,14 +166,15 @@ export class DiagramObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public dispose() {
|
public dispose() {
|
||||||
this._scene.onAfterRenderObservable.remove(this._sceneObserver);
|
this._logger.debug('DiagramObject dispose called for ', this._diagramEntity?.id)
|
||||||
|
this._scene?.onAfterRenderObservable.remove(this._sceneObserver);
|
||||||
this._sceneObserver = null;
|
this._sceneObserver = null;
|
||||||
this._mesh.setParent(null);
|
this._mesh?.setParent(null);
|
||||||
this._mesh?.dispose(true, false);
|
this._mesh?.dispose(true, false);
|
||||||
this._mesh = null;
|
this._mesh = null;
|
||||||
this._label?.dispose();
|
this._label?.dispose();
|
||||||
this._label = null;
|
this._label = null;
|
||||||
this._baseTransform.dispose();
|
this._baseTransform?.dispose();
|
||||||
this._diagramEntity = null;
|
this._diagramEntity = null;
|
||||||
this._scene = null;
|
this._scene = null;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user