wisemapping-frontend/packages/mindplot/src/components/model/RelationshipModel.ts

142 lines
3.5 KiB
TypeScript
Raw Normal View History

2021-07-16 16:41:58 +02:00
/*
2021-12-25 23:39:34 +01:00
* Copyright [2021] [wisemapping]
2021-07-16 16:41:58 +02:00
*
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
* It is basically the Apache License, Version 2.0 (the "License") plus the
* "powered by wisemapping" text requirement on every single page;
* you may not use this file except in compliance with the License.
* You may obtain a copy of the license at
*
* http://www.wisemapping.org/license
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
2021-12-19 17:06:42 +01:00
import { $assert, $defined } from '@wisemapping/core-js';
2022-01-03 06:04:37 +01:00
import Point from '@wisemapping/web2d';
import ConnectionLine from '../ConnectionLine';
2021-07-16 16:41:58 +02:00
2021-12-03 19:58:25 +01:00
class RelationshipModel {
static _next_uuid = 0;
2022-01-03 06:04:37 +01:00
private _id: number;
2022-01-03 06:04:37 +01:00
private _sourceTargetId: number;
2022-01-03 06:04:37 +01:00
private _targetTopicId: number;
2022-01-03 06:04:37 +01:00
private _lineType: number;
2022-01-03 06:04:37 +01:00
private _srcCtrlPoint: Point;
2022-01-03 06:04:37 +01:00
private _destCtrlPoint: Point;
2022-01-03 06:04:37 +01:00
private _endArrow: boolean;
2022-01-03 06:04:37 +01:00
private _startArrow: boolean;
2022-01-02 23:01:50 +01:00
constructor(sourceTopicId: number, targetTopicId: number) {
2021-12-03 19:58:25 +01:00
$assert($defined(sourceTopicId), 'from node type can not be null');
$assert($defined(targetTopicId), 'to node type can not be null');
2021-12-16 02:59:51 +01:00
$assert(Number.isFinite(sourceTopicId), 'sourceTopicId is not a number');
$assert(Number.isFinite(targetTopicId), 'targetTopicId is not a number');
2021-12-03 19:58:25 +01:00
this._id = RelationshipModel._nextUUID();
this._sourceTargetId = sourceTopicId;
this._targetTopicId = targetTopicId;
this._lineType = ConnectionLine.SIMPLE_CURVED;
this._srcCtrlPoint = null;
this._destCtrlPoint = null;
this._endArrow = true;
this._startArrow = false;
}
2022-01-03 17:27:00 +01:00
getFromNode(): number {
2021-12-03 19:58:25 +01:00
return this._sourceTargetId;
}
2022-01-03 17:27:00 +01:00
getToNode(): number {
2021-12-03 19:58:25 +01:00
return this._targetTopicId;
}
2022-01-03 17:27:00 +01:00
getId(): number {
2021-12-03 19:58:25 +01:00
$assert(this._id, 'id is null');
return this._id;
}
getLineType() {
return this._lineType;
}
2022-01-03 06:09:35 +01:00
setLineType(lineType: number) {
2021-12-03 19:58:25 +01:00
this._lineType = lineType;
}
2022-01-03 06:04:37 +01:00
getSrcCtrlPoint(): Point {
2021-12-03 19:58:25 +01:00
return this._srcCtrlPoint;
}
2022-01-03 06:04:37 +01:00
setSrcCtrlPoint(srcCtrlPoint: Point) {
2021-12-03 19:58:25 +01:00
this._srcCtrlPoint = srcCtrlPoint;
}
2022-01-03 06:04:37 +01:00
getDestCtrlPoint(): Point {
2021-12-03 19:58:25 +01:00
return this._destCtrlPoint;
}
2022-01-03 17:27:00 +01:00
setDestCtrlPoint(destCtrlPoint: Point): void {
2021-12-03 19:58:25 +01:00
this._destCtrlPoint = destCtrlPoint;
}
2022-01-03 17:27:00 +01:00
getEndArrow(): boolean {
2021-12-03 19:58:25 +01:00
return this._endArrow;
}
2022-01-03 06:09:35 +01:00
setEndArrow(endArrow: boolean) {
2021-12-03 19:58:25 +01:00
this._endArrow = endArrow;
}
2022-01-03 17:27:00 +01:00
getStartArrow(): boolean {
2021-12-03 19:58:25 +01:00
return this._startArrow;
}
2022-01-03 17:27:00 +01:00
setStartArrow(startArrow: boolean): void {
2021-12-03 19:58:25 +01:00
this._startArrow = startArrow;
}
/**
* @return a clone of the relationship model
*/
clone() {
const result = new RelationshipModel(this._sourceTargetId, this._targetTopicId);
result._id = this._id;
result._lineType = this._lineType;
result._srcCtrlPoint = this._srcCtrlPoint;
result._destCtrlPoint = this._destCtrlPoint;
result._endArrow = this._endArrow;
result._startArrow = this._startArrow;
return result;
}
/**
* @return {String} textual information about the relationship's source and target node
*/
2022-01-02 23:01:50 +01:00
inspect(): string {
2021-12-03 19:58:25 +01:00
return (
2022-01-02 23:01:50 +01:00
`(fromNode:${this.getFromNode()
} , toNode: ${this.getToNode()
2021-12-03 19:58:25 +01:00
})`
);
}
2022-01-02 23:01:50 +01:00
static _nextUUID() {
RelationshipModel._next_uuid += 1;
return RelationshipModel._next_uuid;
}
2021-12-03 19:58:25 +01:00
}
2021-07-16 16:41:58 +02:00
export default RelationshipModel;