Skip to content

Commit

Permalink
Merge pull request #676 from ICRAR/eagle-1184
Browse files Browse the repository at this point in the history
Removed the dataType attribute from Edge
  • Loading branch information
james-strauss-uwa authored May 17, 2024
2 parents 8f9b872 + 8a00067 commit 1e3004b
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 137 deletions.
58 changes: 6 additions & 52 deletions src/Eagle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2750,7 +2750,7 @@ export class Eagle {
}

// if input edge is null, then we are creating a new edge here, so initialise it with some default values
const newEdge = new Edge(this.logicalGraph().getNodes()[0].getKey(), "", this.logicalGraph().getNodes()[0].getKey(), "", "", false, false, false);
const newEdge = new Edge(this.logicalGraph().getNodes()[0].getKey(), "", this.logicalGraph().getNodes()[0].getKey(), "", false, false, false);

// display edge editing modal UI
Utils.requestUserEditEdge(newEdge, this.logicalGraph(), (completed: boolean, edge: Edge) => {
Expand All @@ -2760,7 +2760,7 @@ export class Eagle {
}

// validate edge
const isValid: Eagle.LinkValid = Edge.isValid(this, edge.getId(), edge.getSrcNodeKey(), edge.getSrcPortId(), edge.getDestNodeKey(), edge.getDestPortId(), edge.getDataType(), edge.isLoopAware(), edge.isClosesLoop(), false, true, null);
const isValid: Eagle.LinkValid = Edge.isValid(this, edge.getId(), edge.getSrcNodeKey(), edge.getSrcPortId(), edge.getDestNodeKey(), edge.getDestPortId(), edge.isLoopAware(), edge.isClosesLoop(), false, true, null);
if (isValid === Eagle.LinkValid.Impossible || isValid === Eagle.LinkValid.Invalid || isValid === Eagle.LinkValid.Unknown){
Utils.showUserMessage("Error", "Invalid edge");
return;
Expand Down Expand Up @@ -2805,7 +2805,7 @@ export class Eagle {
}

// validate edge
const isValid: Eagle.LinkValid = Edge.isValid(this, edge.getId(), edge.getSrcNodeKey(), edge.getSrcPortId(), edge.getDestNodeKey(), edge.getDestPortId(), edge.getDataType(), edge.isLoopAware(), edge.isClosesLoop(), false, true, null);
const isValid: Eagle.LinkValid = Edge.isValid(this, edge.getId(), edge.getSrcNodeKey(), edge.getSrcPortId(), edge.getDestNodeKey(), edge.getDestPortId(), edge.isLoopAware(), edge.isClosesLoop(), false, true, null);
if (isValid === Eagle.LinkValid.Impossible || isValid === Eagle.LinkValid.Invalid || isValid === Eagle.LinkValid.Unknown){
Utils.showUserMessage("Error", "Invalid edge");
return;
Expand Down Expand Up @@ -4039,52 +4039,6 @@ export class Eagle {
});
}

changeEdgeDataType = (edge: Edge) : void => {
// get reference to selected Edge
const selectedEdge: Edge = this.selectedEdge();

if (selectedEdge === null){
console.error("Attempt to change edge data type when no edge selected");
return;
}

// set selectedIndex to the index of the current data type within the allTypes list
let selectedIndex = 0;
for (let i = 0 ; i < this.types().length ; i++){
if (this.types()[i] === selectedEdge.getDataType()){
selectedIndex = i;
break;
}
}

// launch modal
Utils.requestUserChoice("Change Edge Data Type", "NOTE: changing a edge's data type will also change the data type of the source and destination ports", this.types(), selectedIndex, false, "", (completed:boolean, userChoiceIndex: number, userCustomString: string) => {
if (!completed){
return;
}

// get user selection
const newType = this.types()[userChoiceIndex];

// get references to the source and destination ports of this edge
const sourceNode = this.logicalGraph().findNodeByKey(edge.getSrcNodeKey());
const sourcePort = sourceNode.findFieldById(edge.getSrcPortId());
const destinationNode = this.logicalGraph().findNodeByKey(edge.getDestNodeKey());
const destinationPort = destinationNode.findFieldById(edge.getDestPortId());

// update the edge and ports
edge.setDataType(newType);
sourcePort.setType(newType);
destinationPort.setType(newType);

// flag changes
this.checkGraph();
this.undo().pushSnapshot(this, "Change Edge Data Type");
this.selectedObjects.valueHasMutated();
this.logicalGraph.valueHasMutated();
});
}

removeFieldFromNodeById = (node : Node, id: string) : void => {
console.log("removeFieldFromNodeById(): node", node.getName(), "id", id);

Expand Down Expand Up @@ -4621,7 +4575,7 @@ export class Eagle {

// if edge DOES NOT connect two applications, process normally
if (!edgeConnectsTwoApplications || twoEventPorts){
const edge : Edge = new Edge(srcNode.getKey(), srcPort.getId(), destNode.getKey(), destPort.getId(), srcPort.getType(), loopAware, closesLoop, false);
const edge : Edge = new Edge(srcNode.getKey(), srcPort.getId(), destNode.getKey(), destPort.getId(), loopAware, closesLoop, false);
this.logicalGraph().addEdgeComplete(edge);
setTimeout(() => {
this.setSelection(Eagle.RightWindowMode.Hierarchy, edge,Eagle.FileType.Graph)
Expand Down Expand Up @@ -4691,8 +4645,8 @@ export class Eagle {
}

// create TWO edges, one from src to data component, one from data component to dest
const firstEdge : Edge = new Edge(srcNode.getKey(), srcPort.getId(), newNodeKey, newInputOutputPort.getId(), srcPort.getType(), loopAware, closesLoop, false);
const secondEdge : Edge = new Edge(newNodeKey, newInputOutputPort.getId(), destNode.getKey(), destPort.getId(), srcPort.getType(), loopAware, closesLoop, false);
const firstEdge : Edge = new Edge(srcNode.getKey(), srcPort.getId(), newNodeKey, newInputOutputPort.getId(), loopAware, closesLoop, false);
const secondEdge : Edge = new Edge(newNodeKey, newInputOutputPort.getId(), destNode.getKey(), destPort.getId(), loopAware, closesLoop, false);

this.logicalGraph().addEdgeComplete(firstEdge);
this.logicalGraph().addEdgeComplete(secondEdge);
Expand Down
46 changes: 8 additions & 38 deletions src/Edge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,19 @@ export class Edge {
private srcPortId : string;
private destNodeKey : number;
private destPortId : string;
private dataType : string;
private loopAware : boolean; // indicates the user is aware that the components at either end of the edge may differ in multiplicity
private closesLoop : boolean; // indicates that this is a special type of edge that can be drawn in eagle to specify the start/end of groups.
private selectionRelative : boolean // indicates if the edge is either selected or attached to a selected node
private isShortEdge : ko.Observable<boolean>;

constructor(srcNodeKey : number, srcPortId : string, destNodeKey : number, destPortId : string, dataType : string, loopAware: boolean, closesLoop: boolean, selectionRelative : boolean){
constructor(srcNodeKey : number, srcPortId : string, destNodeKey : number, destPortId : string, loopAware: boolean, closesLoop: boolean, selectionRelative : boolean){
this._id = Utils.uuidv4();

this.srcNodeKey = srcNodeKey;
this.srcPortId = srcPortId;
this.destNodeKey = destNodeKey;
this.destPortId = destPortId;

this.dataType = dataType;
this.loopAware = loopAware;
this.closesLoop = closesLoop;
this.selectionRelative = selectionRelative;
Expand Down Expand Up @@ -103,14 +101,6 @@ export class Edge {
this.destPortId = id;
}

getDataType = () : string => {
return this.dataType;
}

setDataType = (dataType: string) : void => {
this.dataType = dataType;
}

isLoopAware = () : boolean => {
return this.loopAware;
}
Expand Down Expand Up @@ -165,13 +155,12 @@ export class Edge {
this.srcPortId = "";
this.destNodeKey = 0;
this.destPortId = "";
this.dataType = "";
this.loopAware = false;
this.closesLoop = false;
}

clone = () : Edge => {
const result : Edge = new Edge(this.srcNodeKey, this.srcPortId, this.destNodeKey, this.destPortId, this.dataType, this.loopAware, this.closesLoop, this.selectionRelative);
const result : Edge = new Edge(this.srcNodeKey, this.srcPortId, this.destNodeKey, this.destPortId, this.loopAware, this.closesLoop, this.selectionRelative);

result._id = this._id;

Expand All @@ -181,7 +170,7 @@ export class Edge {
getErrorsWarnings = (eagle: Eagle): Errors.ErrorsWarnings => {
const result: {warnings: Errors.Issue[], errors: Errors.Issue[]} = {warnings: [], errors: []};

Edge.isValid(eagle, this._id, this.srcNodeKey, this.srcPortId, this.destNodeKey, this.destPortId, this.dataType, this.loopAware, this.closesLoop, false, false, result);
Edge.isValid(eagle, this._id, this.srcNodeKey, this.srcPortId, this.destNodeKey, this.destPortId, this.loopAware, this.closesLoop, false, false, result);

return result;
}
Expand All @@ -192,7 +181,6 @@ export class Edge {
fromPort: edge.srcPortId,
to: edge.destNodeKey,
toPort: edge.destPortId,
dataType: edge.dataType,
loop_aware: edge.loopAware ? "1" : "0",
closesLoop: edge.closesLoop
};
Expand Down Expand Up @@ -226,12 +214,6 @@ export class Edge {
destPortId = linkData.toPort;
}

// try to read the dataType attribute
let dataType: string = Daliuge.DataType.Unknown;
if (typeof linkData.dataType !== 'undefined'){
dataType = linkData.dataType;
}

// try to read loop_aware attribute
let loopAware: boolean = false;
if (typeof linkData.loop_aware !== 'undefined'){
Expand All @@ -247,7 +229,7 @@ export class Edge {
closesLoop = linkData.closesLoop;
}

return new Edge(srcNodeKey, srcPortId, destNodeKey, destPortId, dataType, loopAware, closesLoop, false);
return new Edge(srcNodeKey, srcPortId, destNodeKey, destPortId, loopAware, closesLoop, false);
}

static toV3Json(edge : Edge) : object {
Expand All @@ -262,7 +244,7 @@ export class Edge {
}

static fromV3Json(edgeData: any, errorsWarnings: Errors.ErrorsWarnings): Edge {
return new Edge(edgeData.srcNode, edgeData.srcPort, edgeData.destNode, edgeData.destPort, "", edgeData.loop_aware === "1", edgeData.closesLoop, false);
return new Edge(edgeData.srcNode, edgeData.srcPort, edgeData.destNode, edgeData.destPort, edgeData.loop_aware === "1", edgeData.closesLoop, false);
}

static toAppRefJson(edge : Edge, lg: LogicalGraph) : object {
Expand All @@ -272,8 +254,7 @@ export class Edge {
to: edge.destNodeKey,
toPort: edge.destPortId,
loopAware: edge.loopAware,
closesLoop: edge.closesLoop,
dataType: edge.dataType
closesLoop: edge.closesLoop
};

// if srcNode is an embedded application, add a 'fromRef' attribute to the edge
Expand All @@ -292,10 +273,10 @@ export class Edge {
}

static fromAppRefJson(edgeData: any, errorsWarnings: Errors.ErrorsWarnings): Edge {
return new Edge(edgeData.from, edgeData.fromPort, edgeData.to, edgeData.toPort, edgeData.dataType, edgeData.loopAware, edgeData.closesLoop, false);
return new Edge(edgeData.from, edgeData.fromPort, edgeData.to, edgeData.toPort, edgeData.loopAware, edgeData.closesLoop, false);
}

static isValid(eagle: Eagle, edgeId: string, sourceNodeKey : number, sourcePortId : string, destinationNodeKey : number, destinationPortId : string, dataType: string, loopAware: boolean, closesLoop: boolean, showNotification : boolean, showConsole : boolean, errorsWarnings: Errors.ErrorsWarnings) : Eagle.LinkValid {
static isValid(eagle: Eagle, edgeId: string, sourceNodeKey : number, sourcePortId : string, destinationNodeKey : number, destinationPortId : string, loopAware: boolean, closesLoop: boolean, showNotification : boolean, showConsole : boolean, errorsWarnings: Errors.ErrorsWarnings) : Eagle.LinkValid {
// check for problems
if (isNaN(sourceNodeKey)){
return Eagle.LinkValid.Unknown;
Expand Down Expand Up @@ -468,17 +449,6 @@ export class Edge {
}
}

// check that all edges have same data type as their source and destination ports
if (sourcePort !== null && !Utils.typesMatch(dataType, sourcePort.getType())){
const x = Errors.ShowFix("Edge data type (" + dataType + ") does not match start port (" + sourcePort.getDisplayText() + ") data type (" + sourcePort.getType() + ").", function(){Utils.showEdge(eagle, edgeId)}, function(){Utils.fixEdgeType(eagle, edgeId, sourcePort.getType());}, "Change edge data type to match source port type");
Edge.isValidLog(edgeId, Eagle.LinkValid.Invalid, x, showNotification, showConsole, errorsWarnings);
}

if (destinationPort !== null && !Utils.typesMatch(dataType, destinationPort.getType())){
const x = Errors.ShowFix("Edge data type (" + dataType + ") does not match end port (" + destinationPort.getDisplayText() + ") data type (" + destinationPort.getType() + ").", function(){Utils.showEdge(eagle, edgeId)}, function(){Utils.fixEdgeType(eagle, edgeId, destinationPort.getType());}, "Change edge data type to match destination port type");
Edge.isValidLog(edgeId, Eagle.LinkValid.Invalid, x, showNotification, showConsole, errorsWarnings);
}

// check that all "closes loop" edges:
// - begin from a Data component
// - end with a App component
Expand Down
8 changes: 4 additions & 4 deletions src/GraphRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1335,7 +1335,7 @@ export class GraphRenderer {
if (srcHasConnectedInput){
// build a new edge
const newSrc = GraphRenderer.findInputToDataNode(graph.getEdges(), edge.getSrcNodeKey());
edges.push(new Edge(newSrc.nodeKey, newSrc.portId, edge.getDestNodeKey(), edge.getDestPortId(), edge.getDataType(), edge.isLoopAware(), edge.isClosesLoop(), false));
edges.push(new Edge(newSrc.nodeKey, newSrc.portId, edge.getDestNodeKey(), edge.getDestPortId(), edge.isLoopAware(), edge.isClosesLoop(), false));
} else {
// draw edge as normal
edges.push(edge);
Expand Down Expand Up @@ -1701,7 +1701,7 @@ export class GraphRenderer {
}

// check if link is valid
const linkValid : Eagle.LinkValid = Edge.isValid(eagle, null, realSourceNode.getKey(), realSourcePort.getId(), realDestinationNode.getKey(), realDestinationPort.getId(), realSourcePort.getType(), false, false, true, true, {errors:[], warnings:[]});
const linkValid : Eagle.LinkValid = Edge.isValid(eagle, null, realSourceNode.getKey(), realSourcePort.getId(), realDestinationNode.getKey(), realDestinationPort.getId(), false, false, true, true, {errors:[], warnings:[]});

// abort if edge is invalid
if ((Setting.findValue(Setting.ALLOW_INVALID_EDGES) && linkValid === Eagle.LinkValid.Invalid) || linkValid === Eagle.LinkValid.Valid || linkValid === Eagle.LinkValid.Warning){
Expand Down Expand Up @@ -2104,7 +2104,7 @@ export class GraphRenderer {
GraphRenderer.destinationPort = port;
GraphRenderer.destinationNode = eagle.logicalGraph().findNodeByKey(port.getNodeKey());

const isValid = Edge.isValid(eagle, null, GraphRenderer.portDragSourceNode().getKey(), GraphRenderer.portDragSourcePort().getId(), GraphRenderer.destinationNode.getKey(), GraphRenderer.destinationPort.getId(), GraphRenderer.portDragSourcePort().getType(), false, false, false, false, {errors:[], warnings:[]});
const isValid = Edge.isValid(eagle, null, GraphRenderer.portDragSourceNode().getKey(), GraphRenderer.portDragSourcePort().getId(), GraphRenderer.destinationNode.getKey(), GraphRenderer.destinationPort.getId(), false, false, false, false, {errors:[], warnings:[]});
GraphRenderer.isDraggingPortValid(isValid);
}

Expand Down Expand Up @@ -2230,7 +2230,7 @@ export class GraphRenderer {
}

// check if link has a warning or is invalid
const linkValid : Eagle.LinkValid = Edge.isValid(eagle, edge.getId(), edge.getSrcNodeKey(), edge.getSrcPortId(), edge.getDestNodeKey(), edge.getDestPortId(), edge.getDataType(), edge.isLoopAware(), edge.isClosesLoop(), false, false, {errors:[], warnings:[]});
const linkValid : Eagle.LinkValid = Edge.isValid(eagle, edge.getId(), edge.getSrcNodeKey(), edge.getSrcPortId(), edge.getDestNodeKey(), edge.getDestPortId(), edge.isLoopAware(), edge.isClosesLoop(), false, false, {errors:[], warnings:[]});

if (linkValid === Eagle.LinkValid.Invalid || linkValid === Eagle.LinkValid.Impossible){
normalColor = GraphConfig.getColor('edgeInvalid');
Expand Down
3 changes: 1 addition & 2 deletions src/Modals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,11 +288,10 @@ export class Modals {
const srcPortId : string = $('#editEdgeModalSrcPortIdSelect').val().toString();
const destNodeKey : number = parseInt($('#editEdgeModalDestNodeKeySelect').val().toString(), 10);
const destPortId: string = $('#editEdgeModalDestPortIdSelect').val().toString();
const dataType: string = $('#editEdgeModalDataTypeInput').val().toString();
const loopAware: boolean = $('#editEdgeModalLoopAwareCheckbox').prop('checked');
const closesLoop: boolean = $('#editEdgeModalClosesLoopCheckbox').prop('checked');

const newEdge = new Edge(srcNodeKey, srcPortId, destNodeKey, destPortId, dataType, loopAware, closesLoop, false);
const newEdge = new Edge(srcNodeKey, srcPortId, destNodeKey, destPortId, loopAware, closesLoop, false);

callback(true, newEdge);
});
Expand Down
17 changes: 1 addition & 16 deletions src/Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -936,8 +936,6 @@ export class Utils {
}));
}
}

$('#editEdgeModalDataTypeInput').val(edge.getDataType());
}

/**
Expand Down Expand Up @@ -1433,7 +1431,7 @@ export class Utils {

// check all edges are valid
for (const edge of graph.getEdges()){
Edge.isValid(eagle, edge.getId(), edge.getSrcNodeKey(), edge.getSrcPortId(), edge.getDestNodeKey(), edge.getDestPortId(), edge.getDataType(), edge.isLoopAware(), edge.isClosesLoop(), false, false, errorsWarnings);
Edge.isValid(eagle, edge.getId(), edge.getSrcNodeKey(), edge.getSrcPortId(), edge.getDestNodeKey(), edge.getDestPortId(), edge.isLoopAware(), edge.isClosesLoop(), false, false, errorsWarnings);
}

// check that all node, edge, field ids are unique
Expand Down Expand Up @@ -1735,16 +1733,6 @@ export class Utils {
return value.toLowerCase() === "true";
}

static fixEdgeType(eagle: Eagle, edgeId: string, newType: string) : void {
const edge = eagle.logicalGraph().findEdgeById(edgeId);

if (edge === null){
return;
}

edge.setDataType(newType);
}

static fixDeleteEdge(eagle: Eagle, edgeId: string): void {
eagle.logicalGraph().removeEdgeById(edgeId);
}
Expand Down Expand Up @@ -2103,8 +2091,6 @@ export class Utils {
"peek":node.isPeek(),
"x":node.getPosition().x,
"y":node.getPosition().y,
// "realX":node.getRealPosition().x,
// "realY":node.getRealPosition().y,
"radius":node.getRadius(),
"inputAppKey":node.getInputApplication() === null ? null : node.getInputApplication().getKey(),
"inputAppCategory":node.getInputApplication() === null ? null : node.getInputApplication().getCategory(),
Expand All @@ -2130,7 +2116,6 @@ export class Utils {
"sourcePortId":edge.getSrcPortId(),
"destNodeKey":edge.getDestNodeKey(),
"destPortId":edge.getDestPortId(),
"dataType":edge.getDataType(),
"loopAware":edge.isLoopAware(),
"isSelectionRelative":edge.getSelectionRelative()
});
Expand Down
Loading

0 comments on commit 1e3004b

Please sign in to comment.