Skip to content

Commit

Permalink
code clean up and sourcery ai chagnes
Browse files Browse the repository at this point in the history
  • Loading branch information
M-Wicenec committed Jul 12, 2024
1 parent 6e64206 commit 4040c9e
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 45 deletions.
4 changes: 0 additions & 4 deletions src/Eagle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -653,10 +653,6 @@ export class Eagle {
Eagle.selectedLocation(selectedLocation);
GraphRenderer.clearPortPeek()

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

if (selection === null){
this.selectedObjects([]);
this.rightWindow().mode(rightWindowMode);
Expand Down
8 changes: 3 additions & 5 deletions src/GraphRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1580,11 +1580,9 @@ export class GraphRenderer {
// update the parent of the given node
// 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()
}
if (node.getParentKey() !== parentKey && allowGraphEditing){
node.setParentKey(parentKey);
Eagle.getInstance().checkGraph()
}
}

Expand Down
26 changes: 4 additions & 22 deletions src/Node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1980,7 +1980,6 @@ export class Node {
// check that node has modern (not legacy) category
if (node.getCategory() === Category.Component){
const issue: Errors.Issue = Errors.ShowFix("Node " + node.getKey() + " (" + node.getName() + ") has legacy category (" + node.getCategory() + ")", function(){Utils.showNode(eagle, node.getId());}, function(){Utils.fixNodeCategory(eagle, node, Category.PythonApp, Category.Type.Application)}, "");
// errorsWarnings.warnings.push(issue);
node.issues().push({issue:issue,validity:Errors.Validity.Warning})
}

Expand Down Expand Up @@ -2009,25 +2008,21 @@ export class Node {
const message: string = "Node " + node.getKey() + " (" + node.getName() + ") may have too few input ports. A " + node.getCategory() + " component would typically have at least " + cData.minInputs;
const issue: Errors.Issue = Errors.ShowFix(message, function(){Utils.showNode(eagle, node.getId())}, null, "");
node.issues().push({issue:issue,validity:Errors.Validity.Warning})
// errorsWarnings.warnings.push(issue);
}
if ((node.getInputPorts().length - node.getInputEventPorts().length) > cData.maxInputs){
const message: string = "Node " + node.getKey() + " (" + node.getName() + ") has too many input ports. Should have at most " + cData.maxInputs;
const issue: Errors.Issue = Errors.ShowFix(message, function(){Utils.showNode(eagle, node.getId())}, null, "");
node.issues().push({issue:issue,validity:Errors.Validity.Warning})
// errorsWarnings.warnings.push(issue);
}
if (node.getOutputPorts().length < cData.minOutputs){
const message: string = "Node " + node.getKey() + " (" + node.getName() + ") may have too few output ports. A " + node.getCategory() + " component would typically have at least " + cData.minOutputs;
const issue: Errors.Issue = Errors.ShowFix(message, function(){Utils.showNode(eagle, node.getId())}, null, "");
node.issues().push({issue:issue,validity:Errors.Validity.Warning})
// errorsWarnings.warnings.push(issue);
}
if ((node.getOutputPorts().length - node.getOutputEventPorts().length) > cData.maxOutputs){
const message: string = "Node " + node.getKey() + " (" + node.getName() + ") may have too many output ports. Should have at most " + cData.maxOutputs;
const issue: Errors.Issue = Errors.ShowFix(message, function(){Utils.showNode(eagle, node.getId())}, null, "");
node.issues().push({issue:issue,validity:Errors.Validity.Warning})
// errorsWarnings.warnings.push(issue);
}

// check that all nodes should have at least one connected edge, otherwise what purpose do they serve?
Expand All @@ -2044,25 +2039,21 @@ export class Node {
if (!isConnected && !(cData.maxInputs === 0 && cData.maxOutputs === 0) && selectedLocation === Eagle.FileType.Graph){
const issue: Errors.Issue = Errors.ShowFix("Node " + node.getKey() + " (" + node.getName() + ") has no connected edges. It should be connected to the graph in some way", function(){Utils.showNode(eagle, node.getId())}, null, "");
node.issues().push({issue:issue,validity:Errors.Validity.Warning})
// errorsWarnings.warnings.push(issue);
}

// check embedded application categories are not 'None'
if (node.hasInputApplication() && node.getInputApplication().getCategory() === Category.None){
const issue: Errors.Issue = Errors.Message("Node " + node.getKey() + " (" + node.getName() + ") has input application with category 'None'.")
// errorsWarnings.errors.push(Errors.Message("Node " + node.getKey() + " (" + node.getName() + ") has input application with category 'None'."));
node.issues().push({issue:issue,validity:Errors.Validity.Error});
}
if (node.hasOutputApplication() && node.getOutputApplication().getCategory() === Category.None){
const issue : Errors.Issue = Errors.Message("Node " + node.getKey() + " (" + node.getName() + ") has output application with category 'None'.")
// errorsWarnings.errors.push(Errors.Message("Node " + node.getKey() + " (" + node.getName() + ") has output application with category 'None'."));
node.issues().push({issue:issue,validity:Errors.Validity.Error});
}

// check that Service nodes have inputApplications with no output ports!
if (node.getCategory() === Category.Service && node.hasInputApplication() && node.getInputApplication().getOutputPorts().length > 0){
const issue : Errors.Issue = Errors.Message("Node " + node.getKey() + " (" + node.getName() + ") is a Service node, but has an input application with at least one output.")
// errorsWarnings.errors.push(Errors.Message("Node " + node.getKey() + " (" + node.getName() + ") is a Service node, but has an input application with at least one output."));
node.issues().push({issue:issue,validity:Errors.Validity.Error});
}

Expand All @@ -2083,10 +2074,6 @@ export class Node {
}
}
}

// node.errorsWarnings(errorsWarnings)

// return errorsWarnings
}

private static _checkForField(eagle: Eagle, node: Node, field: Field) : void {
Expand All @@ -2098,16 +2085,11 @@ export class Node {
if (existingField === null){
const message = "Node " + node.getKey() + " (" + node.getName() + ":" + node.category() + ":" + node.categoryType() + ") does not have the required '" + field.getDisplayText() + "' field";
const issue : Errors.Issue = Errors.ShowFix(message, function(){Utils.showNode(eagle, node.getId());}, function(){Utils.addMissingRequiredField(eagle, node, field);}, "Add missing " + field.getDisplayText() + " field.")
// errorsWarnings.errors.push(Errors.ShowFix(message, function(){Utils.showNode(eagle, node.getId());}, function(){Utils.addMissingRequiredField(eagle, node, field);}, "Add missing " + field.getDisplayText() + " field."));
node.issues().push({issue:issue,validity:Errors.Validity.Error});
} else {
if (existingField.getParameterType() !== field.getParameterType()){
const message = "Node " + node.getKey() + " (" + node.getName() + ") has a '" + field.getDisplayText() + "' field with the wrong parameter type (" + existingField.getParameterType() + "), should be a " + field.getParameterType();
const issue : Errors.Issue = Errors.ShowFix(message, function(){Utils.showField(eagle, node.getId(),existingField);}, function(){Utils.fixFieldParameterType(eagle, node, existingField, field.getParameterType())}, "Switch type of field to '" + field.getParameterType())
// existingField.addErrorsWarnings(Errors.ShowFix(message, function(){Utils.showField(eagle, node.getId(),existingField);}, function(){Utils.fixFieldParameterType(eagle, node, existingField, field.getParameterType())}, "Switch type of field to '" + field.getParameterType()),'error');
// node.issues.push({issue:issue,validity:Errors.Validity.Error});
existingField.addError(issue,Errors.Validity.Error)
}
} else if (existingField.getParameterType() !== field.getParameterType()){
const message = "Node " + node.getKey() + " (" + node.getName() + ") has a '" + field.getDisplayText() + "' field with the wrong parameter type (" + existingField.getParameterType() + "), should be a " + field.getParameterType();
const issue : Errors.Issue = Errors.ShowFix(message, function(){Utils.showField(eagle, node.getId(),existingField);}, function(){Utils.fixFieldParameterType(eagle, node, existingField, field.getParameterType())}, "Switch type of field to '" + field.getParameterType())
existingField.addError(issue,Errors.Validity.Error)
}
}
}
27 changes: 13 additions & 14 deletions src/Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,6 @@ export class Utils {
}

static showErrorsModal(title: string){
//maybe
const errors: Errors.Issue[] = Errors.getErrors();
const warnings: Errors.Issue[] = Errors.getWarnings();

Expand Down Expand Up @@ -1380,7 +1379,7 @@ export class Utils {

static checkPalette(palette: Palette): Errors.ErrorsWarnings {
const errorsWarnings: Errors.ErrorsWarnings = {warnings: [], errors: []};
const paletteErrors : {issue:Errors.Issue, validity:Errors.Validity}[]=[]
const paletteIssues : {issue:Errors.Issue, validity:Errors.Validity}[]=[]
// check for duplicate keys
const keys: number[] = [];

Expand All @@ -1396,12 +1395,12 @@ export class Utils {
// check all nodes are valid
for (const node of palette.getNodes()){
Node.isValid(node, Eagle.FileType.Palette);
paletteErrors.push(...node.getIssues())
paletteIssues.push(...node.getIssues())
// errorsWarnings.errors.push(...nodeErrorsWarnings.errors)
// errorsWarnings.warnings.push(...nodeErrorsWarnings.warnings)
}

for(const error of paletteErrors){
for(const error of paletteIssues){
if(error.validity === Errors.Validity.Error){
errorsWarnings.errors.push(error.issue)
}else{
Expand Down Expand Up @@ -1429,48 +1428,48 @@ export class Utils {
static gatherGraphErrors(): Errors.ErrorsWarnings {
const eagle = Eagle.getInstance()
const errorsWarnings: Errors.ErrorsWarnings = {warnings: [], errors: []};
const graphErrors : {issue:Errors.Issue, validity:Errors.Validity}[] = []
const graphIssues : {issue:Errors.Issue, validity:Errors.Validity}[] = []
const graph : LogicalGraph = eagle.logicalGraph()

//gather all the errors
//from nodes
for(const node of graph.getNodes()){
graphErrors.push(...node.getIssues())
graphIssues.push(...node.getIssues())

//from fields
for( const field of node.getFields()){
graphErrors.push(...field.getIssues())
graphIssues.push(...field.getIssues())
}

//embedded input applications and their fields
if(node.hasInputApplication()){
graphErrors.push(...node.getInputApplication().getIssues())
graphIssues.push(...node.getInputApplication().getIssues())

for( const field of node.getInputApplication().getFields()){
graphErrors.push(...field.getIssues())
graphIssues.push(...field.getIssues())
}
}

//embedded output applications and their fields
if(node.hasOutputApplication()){
graphErrors.push(...node.getOutputApplication().getIssues())
graphIssues.push(...node.getOutputApplication().getIssues())

for( const field of node.getOutputApplication().getFields()){
graphErrors.push(...field.getIssues())
graphIssues.push(...field.getIssues())
}
}
}

// from edges
for (const edge of graph.getEdges()){
graphErrors.push(...edge.getIssues())
graphIssues.push(...edge.getIssues())
}

//from logical graph
graphErrors.push(...graph.getIssues())
graphIssues.push(...graph.getIssues())

//sort all issues into warnings or errors
for(const error of graphErrors){
for(const error of graphIssues){
if(error.validity === Errors.Validity.Error || error.validity === Errors.Validity.Impossible || error.validity === Errors.Validity.Unknown){
errorsWarnings.errors.push(error.issue)
}else{
Expand Down

0 comments on commit 4040c9e

Please sign in to comment.