Skip to content

Commit

Permalink
fixed a major issue with a looping function chekc graph function more…
Browse files Browse the repository at this point in the history
… reliable
  • Loading branch information
M-Wicenec committed Jul 11, 2024
1 parent 29d95c7 commit 2a9a80f
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 58 deletions.
5 changes: 5 additions & 0 deletions src/Eagle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,11 @@ export class Eagle {
setSelection = (rightWindowMode : Eagle.RightWindowMode, selection : Node | Edge, selectedLocation: Eagle.FileType) : void => {
Eagle.selectedLocation(selectedLocation);
GraphRenderer.clearPortPeek()

// if(selection === null && this.selectedObjects().length === 0){
// return
// }

if (selection === null){
this.selectedObjects([]);
this.rightWindow().mode(rightWindowMode);
Expand Down
28 changes: 17 additions & 11 deletions src/Edge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class Edge {
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>;
private issues : {issue:Errors.Issue, validity:Errors.Validity}[]
private issues : ko.ObservableArray<{issue:Errors.Issue, validity:Errors.Validity}> //keeps track of edge errors

constructor(srcNodeKey : number, srcPortId : string, destNodeKey : number, destPortId : string, loopAware: boolean, closesLoop: boolean, selectionRelative : boolean){
this._id = Utils.uuidv4();
Expand All @@ -56,7 +56,7 @@ export class Edge {
this.closesLoop = closesLoop;
this.selectionRelative = selectionRelative;
this.isShortEdge = ko.observable(false)
this.issues = [];
this.issues = ko.observableArray([]);
}

getId = () : string => {
Expand Down Expand Up @@ -169,16 +169,23 @@ export class Edge {
return result;
}

getErrorsWarnings = (eagle: Eagle): Errors.ErrorsWarnings => {
const result: {warnings: Errors.Issue[], errors: Errors.Issue[]} = {warnings: [], errors: []};
getErrorsWarnings = (): Errors.ErrorsWarnings => {
const errorsWarnings : Errors.ErrorsWarnings = {warnings: [], errors: []};

this.getIssues().forEach(function(error){
if(error.validity === Errors.Validity.Error || error.validity === Errors.Validity.Unknown){
errorsWarnings.errors.push(error.issue)
}else{
errorsWarnings.warnings.push(error.issue)
}
})

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

return result;
}

getissues = () : {issue:Errors.Issue, validity:Errors.Validity}[] => {
return this.issues;
getIssues = () : {issue:Errors.Issue, validity:Errors.Validity}[] => {
return this.issues();
}

static toOJSJson(edge : Edge) : object {
Expand Down Expand Up @@ -283,11 +290,10 @@ export class Edge {
}

static isValid(eagle: Eagle,autoSuggestMode:boolean, edgeId: string, sourceNodeKey : number, sourcePortId : string, destinationNodeKey : number, destinationPortId : string, loopAware: boolean, closesLoop: boolean, showNotification : boolean, showConsole : boolean, errorsWarnings: Errors.ErrorsWarnings) : Errors.Validity {

let impossibleEdge : boolean = false;
const edge = eagle.logicalGraph().findEdgeById(edgeId)
if(edge){
edge.issues = [] //clear old issues
edge.issues([]) //clear old issues
}

// check for problems
Expand Down Expand Up @@ -532,6 +538,6 @@ export class Edge {
if (type === "warning" && errorsWarnings !== null){
errorsWarnings.warnings.push(issue);
}
Eagle.getInstance().logicalGraph().findEdgeById(edgeId)?.issues.push({issue:issue, validity:linkValid})
Eagle.getInstance().logicalGraph().findEdgeById(edgeId)?.issues().push({issue:issue, validity:linkValid})
}
}
30 changes: 14 additions & 16 deletions src/Field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ export class Field {
private inputAngle : number;
private outputAngle : number;

private issues : {issue:Errors.Issue, validity:Errors.Validity}[]
// private errorsWarnings : ko.Observable<Errors.ErrorsWarnings>;
private issues : ko.ObservableArray<{issue:Errors.Issue, validity:Errors.Validity}>//keeps track of issues on the field

constructor(id: string, displayText: string, value: string, defaultValue: string, description: string, readonly: boolean, type: string, precious: boolean, options: string[], positional: boolean, parameterType: Daliuge.FieldType, usage: Daliuge.FieldUsage, keyAttribute: boolean){
this.displayText = ko.observable(displayText);
Expand Down Expand Up @@ -74,8 +73,7 @@ export class Field {
this.inputAngle = 0;
this.outputAngle = 0;

this.issues = [];
// this.errorsWarnings = ko.observable({warnings: [], errors: []});
this.issues = ko.observableArray([])
}

getId = () : string => {
Expand Down Expand Up @@ -361,11 +359,11 @@ export class Field {
}, this);

getIssues = (): {issue:Errors.Issue, validity:Errors.Validity}[] => {
return this.issues;
return this.issues();
}

addError(issue:Errors.Issue, validity:Errors.Validity){
this.issues.push({issue:issue,validity:validity})
this.issues().push({issue:issue,validity:validity})
}

getBackgroundColor : ko.PureComputed<string> = ko.pureComputed(() => {
Expand Down Expand Up @@ -819,7 +817,7 @@ export class Field {

static isValid(node:Node, field:Field, selectedLocation:Eagle.FileType, fieldIndex:number){
const eagle = Eagle.getInstance()
field.issues = [] //clear old issues
field.issues([]) //clear old issues

//checks for input ports
if(field.isInputPort()){
Expand All @@ -844,7 +842,7 @@ export class Field {
}
}

field.issues.push({issue:issue,validity:Errors.Validity.Warning})
field.issues().push({issue:issue,validity:Errors.Validity.Warning})
// errorsWarnings.warnings.push(issue);
}

Expand Down Expand Up @@ -873,7 +871,7 @@ export class Field {
issue = Errors.ShowFix("Node " + node.getKey() + " (" + parentNode.getName() + ") has output application (" + node.getName() + ") with output port (" + field.getDisplayText() + ") whose type is not specified", function(){Utils.showField(eagle, node.getId(),field);}, function(){Utils.fixFieldType(eagle, field)}, "");
}
}
field.issues.push({issue:issue,validity:Errors.Validity.Warning})
field.issues().push({issue:issue,validity:Errors.Validity.Warning})
// errorsWarnings.warnings.push(issue);
}

Expand All @@ -883,28 +881,28 @@ export class Field {
//check that the field has an id
if (field.getId() === "" || field.getId() === null){
const issue = Errors.ShowFix("Node " + node.getKey() + " (" + node.getName() + ") has field (" + field.getDisplayText() + ") with no id", function(){Utils.showField(eagle, node.getId(),field);}, function(){Utils.fixFieldId(eagle, field)}, "Generate id for field");
field.issues.push({issue:issue,validity:Errors.Validity.Error})
field.issues().push({issue:issue,validity:Errors.Validity.Error})
// errorsWarnings.errors.push(issue);
}

// check that the field has a default value
if (field.getDefaultValue() === "" && !field.isType(Daliuge.DataType.String) && !field.isType(Daliuge.DataType.Password) && !field.isType(Daliuge.DataType.Object) && !field.isType(Daliuge.DataType.Unknown)) {
const issue: Errors.Issue = Errors.ShowFix("Node " + node.getKey() + " (" + node.getName() + ") has a component parameter (" + field.getDisplayText() + ") whose default value is not specified", function(){Utils.showField(eagle, node.getId(),field)}, function(){Utils.fixFieldDefaultValue(eagle, field)}, "Generate default value for parameter");
field.issues.push({issue:issue,validity:Errors.Validity.Warning})
field.issues().push({issue:issue,validity:Errors.Validity.Warning})
// errorsWarnings.warnings.push(issue);
}

//chack that the field has a known type
if (!Utils.validateType(field.getType())) {
const issue: Errors.Issue = Errors.ShowFix("Node " + node.getKey() + " (" + node.getName() + ") has a component parameter (" + field.getDisplayText() + ") whose type (" + field.getType() + ") is unknown", function(){Utils.showField(eagle, node.getId(),field)}, function(){Utils.fixFieldType(eagle, field)}, "Prepend existing type (" + field.getType() + ") with 'Object.'");
field.issues.push({issue:issue,validity:Errors.Validity.Warning})
field.issues().push({issue:issue,validity:Errors.Validity.Warning})
// errorsWarnings.warnings.push(issue);
}

// check that the fields "key" is the same as the key of the node it belongs to
if (field.getNodeKey() !== node.getKey()) {
const issue: Errors.Issue = Errors.ShowFix("Node " + node.getKey() + " (" + node.getName() + ") has a field (" + field.getDisplayText() + ") whose key (" + field.getNodeKey() + ") doesn't match the node (" + node.getKey() + ")", function(){Utils.showField(eagle, node.getId(),field)}, function(){Utils.fixFieldKey(eagle, node, field)}, "Set field node key correctly");
field.issues.push({issue:issue,validity:Errors.Validity.Error})
field.issues().push({issue:issue,validity:Errors.Validity.Error})
// errorsWarnings.errors.push(issue);
}

Expand All @@ -918,11 +916,11 @@ export class Field {
if (field.getDisplayText() === field1.getDisplayText() && field.getParameterType() === field1.getParameterType()){
if (field.getId() === field1.getId()){
const issue: Errors.Issue = Errors.ShowFix("Node " + node.getKey() + " (" + node.getName() + ") has multiple attributes with the same display text and id (" + field.getDisplayText() + ").", function(){Utils.showField(eagle, node.getId(),field);}, function(){Utils.fixNodeMergeFieldsByIndex(eagle, node, fieldIndex, j)}, "Merge fields");
field.issues.push({issue:issue,validity:Errors.Validity.Warning})
field.issues().push({issue:issue,validity:Errors.Validity.Warning})
// errorsWarnings.warnings.push(issue);
} else {
const issue: Errors.Issue = Errors.ShowFix("Node " + node.getKey() + " (" + node.getName() + ") has multiple attributes with the same display text (" + field.getDisplayText() + ").", function(){Utils.showField(eagle, node.getId(),field);}, function(){Utils.fixNodeMergeFields(eagle, node, field, field1)}, "Merge fields");
field.issues.push({issue:issue,validity:Errors.Validity.Warning})
field.issues().push({issue:issue,validity:Errors.Validity.Warning})
// errorsWarnings.warnings.push(issue);
}
}
Expand Down Expand Up @@ -954,7 +952,7 @@ export class Field {

const message = "Node " + node.getKey() + " (" + node.getName() + ") with category " + node.getCategory() + " contains field (" + field.getDisplayText() + ") with unsuitable type (" + field.getParameterType() + ").";
const issue: Errors.Issue = Errors.ShowFix(message, function(){Utils.showField(eagle, node.getId(),field);}, function(){Utils.fixFieldParameterType(eagle, node, field, suitableType)}, "Switch to suitable type, or remove if no suitable type");
field.issues.push({issue:issue,validity:Errors.Validity.Warning})
field.issues().push({issue:issue,validity:Errors.Validity.Warning})
// errorsWarnings.warnings.push(issue);
}
}
Expand Down
15 changes: 7 additions & 8 deletions src/GraphRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1122,7 +1122,6 @@ export class GraphRenderer {
const oldParent: Node = eagle.logicalGraph().findNodeByKeyQuiet(outerMostNode.getParentKey());

// keep track of whether we would update any node parents
const updated = {parent: false};
const allowGraphEditing = Setting.findValue(Setting.ALLOW_GRAPH_EDITING);
//construct resizing
if(outerMostNode.getParentKey() != null){
Expand All @@ -1140,13 +1139,13 @@ export class GraphRenderer {

// if a parent was found, update
if (parent !== null && outerMostNode.getParentKey() !== parent.getKey() && outerMostNode.getKey() !== parent.getKey() && !ancestorOfParent && !outerMostNode.isEmbedded()){
GraphRenderer._updateNodeParent(outerMostNode, parent.getKey(), updated, allowGraphEditing);
GraphRenderer.updateNodeParent(outerMostNode, parent.getKey(), allowGraphEditing);
GraphRenderer.NodeParentRadiusPreDrag = eagle.logicalGraph().findNodeByKeyQuiet(parent.getKey()).getRadius()
}

// if no parent found, update
if (parent === null && outerMostNode.getParentKey() !== null && !outerMostNode.isEmbedded()){
GraphRenderer._updateNodeParent(outerMostNode, null, updated, allowGraphEditing);
GraphRenderer.updateNodeParent(outerMostNode, null, allowGraphEditing);
}

if (oldParent !== null){
Expand Down Expand Up @@ -1594,14 +1593,13 @@ export class GraphRenderer {
}

// update the parent of the given node
// however, if allGraphEditing is false, then don't update
// always keep track of whether an update would have happened, sp we can warn user
static _updateNodeParent(node: Node, parentKey: number, updated: {parent: boolean}, allowGraphEditing: boolean): void {
// however, if allowGraphEditing is false, then don't update
static updateNodeParent(node: Node, parentKey: number, allowGraphEditing: boolean): void {
if (node.getParentKey() !== parentKey){
if (allowGraphEditing){
node.setParentKey(parentKey);
Eagle.getInstance().checkGraph()
}
updated.parent = true;
}
}

Expand Down Expand Up @@ -2248,7 +2246,8 @@ export class GraphRenderer {
}

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

if (linkValid === Errors.Validity.Error || linkValid === Errors.Validity.Impossible){
normalColor = GraphConfig.getColor('edgeInvalid');
Expand Down
6 changes: 3 additions & 3 deletions src/LogicalGraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ export class LogicalGraph {
fileInfo : ko.Observable<FileInfo>;
private nodes : ko.ObservableArray<Node>;
private edges : ko.ObservableArray<Edge>;
private issues : {issue:Errors.Issue, validity:Errors.Validity}[]
private issues : ko.ObservableArray<{issue:Errors.Issue, validity:Errors.Validity}> //keeps track of higher level errors on the graph

constructor(){
this.fileInfo = ko.observable(new FileInfo());
this.fileInfo().type = Eagle.FileType.Graph;
this.nodes = ko.observableArray([]);
this.edges = ko.observableArray([]);
this.issues = []
this.issues = ko.observableArray([])
}

static toOJSJson(graph : LogicalGraph, forTranslation : boolean) : object {
Expand Down Expand Up @@ -316,7 +316,7 @@ export class LogicalGraph {
}

getIssues = (): {issue:Errors.Issue, validity:Errors.Validity}[] => {
return this.issues;
return this.issues();
}

/**
Expand Down
Loading

0 comments on commit 2a9a80f

Please sign in to comment.