2019-09-12 12:58:32 -07:00
|
|
|
import { logger } from '../../logger';
|
2015-10-26 08:03:30 +01:00
|
|
|
|
2019-09-12 12:58:32 -07:00
|
|
|
let relations = [];
|
|
|
|
let classes = {};
|
2015-11-15 15:06:24 +01:00
|
|
|
|
2015-10-26 08:03:30 +01:00
|
|
|
/**
|
2015-12-27 14:18:21 +01:00
|
|
|
* Function called by parser when a node definition has been found.
|
2015-10-26 08:03:30 +01:00
|
|
|
* @param id
|
|
|
|
* @param text
|
|
|
|
* @param type
|
|
|
|
* @param style
|
|
|
|
*/
|
2019-09-12 12:58:32 -07:00
|
|
|
export const addClass = function(id) {
|
2017-04-11 22:14:25 +08:00
|
|
|
if (typeof classes[id] === 'undefined') {
|
|
|
|
classes[id] = {
|
|
|
|
id: id,
|
|
|
|
methods: [],
|
2019-10-04 21:09:49 +02:00
|
|
|
members: [],
|
|
|
|
annotations: []
|
2019-09-12 12:58:32 -07:00
|
|
|
};
|
2017-04-11 22:14:25 +08:00
|
|
|
}
|
2019-09-12 12:58:32 -07:00
|
|
|
};
|
2015-10-26 08:03:30 +01:00
|
|
|
|
2019-09-12 12:58:32 -07:00
|
|
|
export const clear = function() {
|
|
|
|
relations = [];
|
|
|
|
classes = {};
|
|
|
|
};
|
2015-10-26 08:03:30 +01:00
|
|
|
|
2019-09-12 12:58:32 -07:00
|
|
|
export const getClass = function(id) {
|
|
|
|
return classes[id];
|
|
|
|
};
|
|
|
|
export const getClasses = function() {
|
|
|
|
return classes;
|
|
|
|
};
|
2015-10-29 07:49:08 +01:00
|
|
|
|
2019-09-12 12:58:32 -07:00
|
|
|
export const getRelations = function() {
|
|
|
|
return relations;
|
|
|
|
};
|
2015-10-26 08:03:30 +01:00
|
|
|
|
2019-09-12 12:58:32 -07:00
|
|
|
export const addRelation = function(relation) {
|
|
|
|
logger.debug('Adding relation: ' + JSON.stringify(relation));
|
|
|
|
addClass(relation.id1);
|
|
|
|
addClass(relation.id2);
|
|
|
|
relations.push(relation);
|
|
|
|
};
|
2015-10-28 08:12:47 +01:00
|
|
|
|
2019-09-12 12:58:32 -07:00
|
|
|
export const addMember = function(className, member) {
|
|
|
|
const theClass = classes[className];
|
2018-10-25 21:30:28 +02:00
|
|
|
if (typeof member === 'string') {
|
|
|
|
if (member.substr(-1) === ')') {
|
2019-09-12 12:58:32 -07:00
|
|
|
theClass.methods.push(member);
|
2017-04-11 22:14:25 +08:00
|
|
|
} else {
|
2019-09-12 12:58:32 -07:00
|
|
|
theClass.members.push(member);
|
2015-11-01 19:00:14 +01:00
|
|
|
}
|
2017-04-11 22:14:25 +08:00
|
|
|
}
|
2019-09-12 12:58:32 -07:00
|
|
|
};
|
2015-10-28 08:12:47 +01:00
|
|
|
|
2019-09-12 12:58:32 -07:00
|
|
|
export const addMembers = function(className, MembersArr) {
|
2018-10-25 21:30:28 +02:00
|
|
|
if (Array.isArray(MembersArr)) {
|
2019-09-12 12:58:32 -07:00
|
|
|
MembersArr.forEach(member => addMember(className, member));
|
2018-10-25 21:30:28 +02:00
|
|
|
}
|
2019-09-12 12:58:32 -07:00
|
|
|
};
|
2018-10-25 21:30:28 +02:00
|
|
|
|
2019-09-12 12:58:32 -07:00
|
|
|
export const cleanupLabel = function(label) {
|
2017-04-11 22:14:25 +08:00
|
|
|
if (label.substring(0, 1) === ':') {
|
2019-09-12 12:58:32 -07:00
|
|
|
return label.substr(2).trim();
|
2017-04-11 22:14:25 +08:00
|
|
|
} else {
|
2019-09-12 12:58:32 -07:00
|
|
|
return label.trim();
|
2017-04-11 22:14:25 +08:00
|
|
|
}
|
2019-09-12 12:58:32 -07:00
|
|
|
};
|
2015-11-11 13:16:38 +01:00
|
|
|
|
2017-09-10 21:23:04 +08:00
|
|
|
export const lineType = {
|
2017-04-11 22:14:25 +08:00
|
|
|
LINE: 0,
|
|
|
|
DOTTED_LINE: 1
|
2019-09-12 12:58:32 -07:00
|
|
|
};
|
2015-10-26 08:03:30 +01:00
|
|
|
|
2017-09-10 21:23:04 +08:00
|
|
|
export const relationType = {
|
2017-04-11 22:14:25 +08:00
|
|
|
AGGREGATION: 0,
|
|
|
|
EXTENSION: 1,
|
|
|
|
COMPOSITION: 2,
|
|
|
|
DEPENDENCY: 3
|
2019-09-12 12:58:32 -07:00
|
|
|
};
|
2017-09-10 21:51:48 +08:00
|
|
|
|
|
|
|
export default {
|
|
|
|
addClass,
|
|
|
|
clear,
|
|
|
|
getClass,
|
|
|
|
getClasses,
|
|
|
|
getRelations,
|
|
|
|
addRelation,
|
2018-10-25 21:30:28 +02:00
|
|
|
addMember,
|
2017-09-10 21:51:48 +08:00
|
|
|
addMembers,
|
|
|
|
cleanupLabel,
|
|
|
|
lineType,
|
|
|
|
relationType
|
2019-09-12 12:58:32 -07:00
|
|
|
};
|