Skip to content

Commit

Permalink
Improve terminal naming scheme
Browse files Browse the repository at this point in the history
Signed-off-by: Richard Marston <[email protected]>
  • Loading branch information
richardmarston committed Jan 13, 2023
1 parent a1c5d57 commit 7fe62e5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
24 changes: 16 additions & 8 deletions cimsvg/src/cimedit.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ class cimedit {
let componentPoints = [];
let terminalPoints = [];
let terminalIds = [];
let counter = common.getCimsvg().getNameCounter(type);
let name = type + counter.toString();
componentPoints[0] = point;

if (terminalConfig["terminalStyle"] === cimedit.linePoints) {
Expand All @@ -50,7 +52,7 @@ class cimedit {
terminalPoints.push(nextPoint);
componentPoints.push(nextPoint);
for (let i = 0; i<terminalConfig["minTerminals"]; i++) {
terminalIds.push(cimedit.makeTerminal(diagramId, graph, (i+1).toString(), id, terminalPoints[i]));
terminalIds.push(cimedit.makeTerminal(diagramId, graph, (i+1).toString(), id, terminalPoints[i], name + "-"));
}
}
if (terminalConfig["terminalStyle"] === cimedit.constellationPoints) {
Expand All @@ -61,17 +63,16 @@ class cimedit {
}

let diagramObject = cimedit.makeDiagramObjectWithPoints(graph, diagramId, id, componentPoints);
let counter = common.getCimsvg().getNameCounter(type);
let newAttributes = {
"cim:IdentifiedObject.name": type + counter.toString(),
"cim:IdentifiedObject.name": name,
"pintura:terminals": terminalIds,
"pintura:diagramObject": diagramObject,
};
let componentData = Object.assign({}, attributes, newAttributes);
cimedit.addCategorizedItem(graph, type, id, componentData);
if (terminalConfig["terminalStyle"] === cimedit.constellationPoints) {
for (let i = 0; i<terminalPoints.length; i++) {
cimedit.addTerminal(graph, type, id);
cimedit.addTerminal(graph, type, id, name + "-");
}
}
return id;
Expand Down Expand Up @@ -113,7 +114,7 @@ class cimedit {
}
}

static addTerminal(baseJson, type, rdfid) {
static addTerminal(baseJson, type, rdfid, ownerName) {
if (baseJson[type] && baseJson[type][rdfid]) {
let sequenceNumber;
if (baseJson[type][rdfid][common.pinturaTerminals()]) {
Expand All @@ -123,7 +124,7 @@ class cimedit {
baseJson[type][rdfid][common.pinturaTerminals()] = [];
sequenceNumber = 1;
}
let terminal = cimedit.makeTerminal(common.getCimsvg().getCurrentDiagramId(), baseJson, sequenceNumber, rdfid, { x: 100, y: 100 } );
let terminal = cimedit.makeTerminal(common.getCimsvg().getCurrentDiagramId(), baseJson, sequenceNumber, rdfid, { x: 100, y: 100 } , ownerName);
cimedit.moveTerminalIntoComponentOrbit(baseJson, terminal, type, rdfid);
baseJson[type][rdfid][common.pinturaTerminals()].push(terminal);
}
Expand Down Expand Up @@ -234,13 +235,20 @@ class cimedit {
}
}

static makeTerminal(diagramId, newStuff, sequenceNumber, conductingEquipmentId, point) {
static makeTerminal(diagramId, newStuff, sequenceNumber, conductingEquipmentId, point, ownerName) {
let id = common.generateUUID();
let counter = common.getCimsvg().getNameCounter("cim:Terminal");
let terminalName = "";
if (ownerName == "") {
terminalName = "terminal" + sequenceNumber.toString() + "-" + counter.toString();
}
else {
terminalName = ownerName + "terminal" + sequenceNumber.toString();
}
let diagramObjectId = cimedit.makeDiagramObjectWithPoints(newStuff, diagramId, id, [ point ]);
let terminal = {
"cim:ACDCTerminal.sequenceNumber": sequenceNumber.toString(),
"cim:IdentifiedObject.name": "terminal" + counter.toString(),
"cim:IdentifiedObject.name": terminalName,
"cim:Terminal.ConductingEquipment": { "rdf:resource": "#"+conductingEquipmentId },
"cim:Terminal.ConnectivityNode": { "rdf:resource":"#none" },
"cim:Terminal.phases": "",
Expand Down
5 changes: 0 additions & 5 deletions cimsvg/src/cimsvg.js
Original file line number Diff line number Diff line change
Expand Up @@ -526,11 +526,6 @@ class cimsvg {
this.applyTemplates();
}

addTerminal(type, rdfid) {
let baseJson = this.getBaseJson();
cimedit.addTerminal(baseJson, type, rdfid);
}

removeTerminal(type, rdfid, terminalId) {
let baseJson = this.getBaseJson();
if (baseJson[type] && baseJson[type][rdfid]) {
Expand Down

0 comments on commit 7fe62e5

Please sign in to comment.