Skip to content

Commit

Permalink
Merge pull request #718 from ICRAR/eagle-1259
Browse files Browse the repository at this point in the history
EAGLE-1259: Error creating gather from selection after undo
  • Loading branch information
james-strauss-uwa authored Jul 4, 2024
2 parents 183d434 + 3039f20 commit 070e82b
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 17 deletions.
2 changes: 0 additions & 2 deletions src/Eagle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -993,8 +993,6 @@ export class Eagle {
}

createSubgraphFromSelection = () : void => {
console.log("createSubgraphFromSelection()");

const eagle = Eagle.getInstance()
if(eagle.selectedObjects().length === 0){
Utils.showNotification('Error','At least one node must be selected!', 'warning')
Expand Down
26 changes: 12 additions & 14 deletions src/LogicalGraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ export class LogicalGraph {

result.modelData = FileInfo.toOJSJson(graph.fileInfo());
result.modelData.schemaVersion = Daliuge.SchemaVersion.OJS;
result.modelData.numLGNodes = graph.getNodes().length;
result.modelData.numLGNodes = graph.nodes().length;

// add nodes
result.nodeDataArray = [];
for (const node of graph.getNodes()){
for (const node of graph.nodes()){
const nodeData : any = Node.toOJSGraphJson(node);
result.nodeDataArray.push(nodeData);
}
Expand Down Expand Up @@ -267,7 +267,7 @@ export class LogicalGraph {
getCommentNodes = () : Node[] => {
const commentNodes: Node[] = [];

for (const node of this.getNodes()){
for (const node of this.nodes()){
if (node.isComment()){
commentNodes.push(node);
}
Expand Down Expand Up @@ -419,14 +419,13 @@ export class LogicalGraph {
}

findNodeGraphIdByNodeName = (name:string) :string =>{
const eagle: Eagle = Eagle.getInstance();
let graphNodeId:string
eagle.logicalGraph().getNodes().forEach(function(node){
if(node.getName() === name){
graphNodeId = node.getId()
for (const node of this.nodes()){
if (node.getName() === name){
return node.getId();
}
})
return graphNodeId
}

return null;
}

removeNode = (node: Node) : void => {
Expand Down Expand Up @@ -552,15 +551,14 @@ export class LogicalGraph {
return;
}

const nodes : Node[] = this.getNodes();
let minX : number = Number.MAX_SAFE_INTEGER;
let minY : number = Number.MAX_SAFE_INTEGER;
let maxX : number = Number.MIN_SAFE_INTEGER;
let maxY : number = Number.MIN_SAFE_INTEGER;
let numChildren : number = 0;

// loop through all nodes, finding all children and determining minimum bounding box to contain all children
for (const n of nodes){
for (const n of this.nodes()){
if (n.getParentKey() === node.getKey()){
numChildren += 1;

Expand Down Expand Up @@ -729,7 +727,7 @@ export class LogicalGraph {

// populate index plus depths
for (let i = 0 ; i < this.nodes().length ; i++){
const node = this.getNodes()[i];
const node = this.nodes()[i];

const depth = this.findDepthByKey(node.getKey());

Expand All @@ -743,7 +741,7 @@ export class LogicalGraph {

// write nodes to result in sorted order
for (const indexPlusDepth of indexPlusDepths){
result.push(this.getNodes()[indexPlusDepth.index]);
result.push(this.nodes()[indexPlusDepth.index]);
}

return result;
Expand Down
37 changes: 36 additions & 1 deletion src/Undo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ export class Undo {
}

eagle.checkGraph();

this._updateSelection();
}

nextSnapshot = (eagle: Eagle) : void => {
Expand All @@ -141,6 +143,8 @@ export class Undo {
}

eagle.checkGraph();

this._updateSelection();
}

toString = () : string => {
Expand Down Expand Up @@ -174,8 +178,37 @@ export class Undo {
}

const dataObject: LogicalGraph = snapshot.data();
eagle.logicalGraph(dataObject.clone());
}

// if we undo, or redo, then the objects in selectedObject are from the graph prior to the new snapshot
// so the references will be to non-existent objects
// in this function, we use the ids of the old selectedObjects, and attempt to add the matching objects in the new snapshot to the selectedObjects list
_updateSelection = () : void => {
const eagle: Eagle = Eagle.getInstance();
const objectIds: string[] = [];

// build a list of the ids of the selected objects
for (const object of eagle.selectedObjects()){
objectIds.push(object.getId());
}

eagle.logicalGraph(dataObject);
// clear selection
eagle.setSelection(Eagle.RightWindowMode.Hierarchy, null, Eagle.FileType.Graph);

// find the objects in the ids list, and add them to the selection
for (const id of objectIds){
const node = eagle.logicalGraph().findNodeById(id);
const edge = eagle.logicalGraph().findEdgeById(id);
const object = node || edge;

// abort if no edge or node exists fot that id
if (node === null && edge === null){
continue;
}

eagle.editSelection(<Eagle.RightWindowMode>eagle.rightWindow().mode(), object, Eagle.selectedLocation());
}
}

static printTable() : void {
Expand All @@ -194,6 +227,8 @@ export class Undo {
"current": realCurrent === i ? "->" : "",
"description": snapshot.description(),
"buffer position": i,
"nodes": snapshot.data().getNodes().length,
"edges": snapshot.data().getEdges().length
});
}

Expand Down

0 comments on commit 070e82b

Please sign in to comment.