2019-09-21 08:19:55 -07:00
|
|
|
import { logger } from '../../logger';
|
|
|
|
|
|
|
|
let relations = [];
|
2019-09-25 21:01:21 +02:00
|
|
|
let states = {};
|
2019-09-21 08:19:55 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function called by parser when a node definition has been found.
|
|
|
|
* @param id
|
|
|
|
* @param text
|
|
|
|
* @param type
|
|
|
|
* @param style
|
|
|
|
*/
|
2019-09-25 21:01:21 +02:00
|
|
|
export const addState = function(id) {
|
|
|
|
if (typeof states[id] === 'undefined') {
|
|
|
|
states[id] = {
|
2019-09-21 08:19:55 -07:00
|
|
|
id: id,
|
2019-09-25 21:01:21 +02:00
|
|
|
descriptions: []
|
2019-09-21 08:19:55 -07:00
|
|
|
};
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
export const clear = function() {
|
|
|
|
relations = [];
|
2019-09-25 21:01:21 +02:00
|
|
|
states = {};
|
2019-09-21 08:19:55 -07:00
|
|
|
};
|
|
|
|
|
2019-09-25 21:01:21 +02:00
|
|
|
export const getState = function(id) {
|
|
|
|
return states[id];
|
2019-09-21 08:19:55 -07:00
|
|
|
};
|
2019-09-25 21:01:21 +02:00
|
|
|
export const getstates = function() {
|
|
|
|
return states;
|
2019-09-21 08:19:55 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
export const getRelations = function() {
|
|
|
|
return relations;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const addRelation = function(relation) {
|
|
|
|
logger.debug('Adding relation: ' + JSON.stringify(relation));
|
2019-09-25 21:01:21 +02:00
|
|
|
addState(relation.id1);
|
|
|
|
addState(relation.id2);
|
2019-09-21 08:19:55 -07:00
|
|
|
relations.push(relation);
|
|
|
|
};
|
|
|
|
|
|
|
|
export const addMember = function(className, member) {
|
2019-09-25 21:01:21 +02:00
|
|
|
const theState = states[className];
|
2019-09-21 08:19:55 -07:00
|
|
|
if (typeof member === 'string') {
|
|
|
|
if (member.substr(-1) === ')') {
|
2019-09-25 21:01:21 +02:00
|
|
|
theState.methods.push(member);
|
2019-09-21 08:19:55 -07:00
|
|
|
} else {
|
2019-09-25 21:01:21 +02:00
|
|
|
theState.members.push(member);
|
2019-09-21 08:19:55 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
export const addMembers = function(className, MembersArr) {
|
|
|
|
if (Array.isArray(MembersArr)) {
|
|
|
|
MembersArr.forEach(member => addMember(className, member));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
export const cleanupLabel = function(label) {
|
|
|
|
if (label.substring(0, 1) === ':') {
|
|
|
|
return label.substr(2).trim();
|
|
|
|
} else {
|
|
|
|
return label.trim();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
export const lineType = {
|
|
|
|
LINE: 0,
|
|
|
|
DOTTED_LINE: 1
|
|
|
|
};
|
|
|
|
|
|
|
|
export const relationType = {
|
|
|
|
AGGREGATION: 0,
|
|
|
|
EXTENSION: 1,
|
|
|
|
COMPOSITION: 2,
|
|
|
|
DEPENDENCY: 3
|
|
|
|
};
|
|
|
|
|
|
|
|
export default {
|
2019-09-25 21:01:21 +02:00
|
|
|
addState,
|
2019-09-21 08:19:55 -07:00
|
|
|
clear,
|
2019-09-25 21:01:21 +02:00
|
|
|
getState,
|
|
|
|
getstates,
|
2019-09-21 08:19:55 -07:00
|
|
|
getRelations,
|
|
|
|
addRelation,
|
|
|
|
addMember,
|
|
|
|
addMembers,
|
|
|
|
cleanupLabel,
|
|
|
|
lineType,
|
|
|
|
relationType
|
|
|
|
};
|