Skip to content

Commit

Permalink
Merge pull request #283 from RAIRLab/193-delete-mode-bad-highlights
Browse files Browse the repository at this point in the history
Better delete mode highlights
  • Loading branch information
RyanR712 authored Dec 9, 2023
2 parents 6b1a3e2 + dfa783f commit a7fda24
Show file tree
Hide file tree
Showing 8 changed files with 229 additions and 79 deletions.
8 changes: 2 additions & 6 deletions src/DrawModes/CopyFromDraw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {AtomNode} from "../AEG/AtomNode";
import {CutNode} from "../AEG/CutNode";
import {treeContext} from "../treeContext";
import {offset} from "../SharedToolUtils/DragTool";
import {drawAtom, cleanCanvas, redrawTree, highlightNode} from "../SharedToolUtils/DrawUtils";
import {cleanCanvas, redrawTree, highlightNode} from "../SharedToolUtils/DrawUtils";
import {legalColor} from "../Themes";
import {AEGTree} from "../AEG/AEGTree";

Expand Down Expand Up @@ -118,11 +118,7 @@ function isLegal() {
}

//Highlight the selected part by redrawing in legalColor
if (selectedNode instanceof AtomNode) {
drawAtom(selectedNode, legalColor(), true);
} else {
highlightNode(selectedNode, legalColor());
}
highlightNode(selectedNode, legalColor());

//If something was removed, add it back kin
if (removed) {
Expand Down
40 changes: 31 additions & 9 deletions src/DrawModes/DeleteMultiTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
import {Point} from "../AEG/Point";
import {AtomNode} from "../AEG/AtomNode";
import {CutNode} from "../AEG/CutNode";
import {redrawTree} from "../SharedToolUtils/DrawUtils";
import {treeContext} from "../treeContext";
import {illegalColor} from "../Themes";
import {highlightNode, redrawTree} from "../SharedToolUtils/DrawUtils";
import {offset} from "../SharedToolUtils/DragTool";
import {highlightChildren} from "../SharedToolUtils/EditModeUtils";
import {reInsertNode} from "../SharedToolUtils/EditModeUtils";

//The initial point the user pressed down.
let startingPoint: Point;
Expand All @@ -33,8 +33,16 @@ export function deleteMultiMouseDown(event: MouseEvent) {
currentNode = treeContext.tree.getLowestNode(startingPoint);

if (currentNode !== null) {
const currentParent = treeContext.tree.getLowestParent(startingPoint);
if (currentParent !== null) {
currentParent.remove(startingPoint);
} else {
currentNode = treeContext.tree.sheet.copy();
treeContext.tree.clear();
}
legalNode = true;
highlightChildren(currentNode, illegalColor());
redrawTree(treeContext.tree);
highlightNode(currentNode, illegalColor());
}
}

Expand All @@ -44,18 +52,29 @@ export function deleteMultiMouseDown(event: MouseEvent) {
* The removal will update accordingly.
*/
export function deleteMultiMouseMove(event: MouseEvent) {
if (legalNode && currentNode !== null) {
reInsertNode(treeContext.tree, currentNode);
}
const newPoint: Point = new Point(event.x - offset.x, event.y - offset.y);
const newNode: CutNode | AtomNode | null = treeContext.tree.getLowestNode(newPoint);
if (currentNode !== null && currentNode !== treeContext.tree.getLowestNode(newPoint)) {
const currentParent = treeContext.tree.getLowestParent(newPoint);
if (legalNode && currentNode !== null && currentParent !== null) {
legalNode = true;
redrawTree(treeContext.tree);
if (newNode === null) {
currentNode = null;
legalNode = false;
} else {
currentParent.remove(newPoint);
currentNode = newNode;
highlightChildren(currentNode, illegalColor());
legalNode = true;
redrawTree(treeContext.tree);
highlightNode(currentNode, illegalColor());
}
} else if (legalNode && currentParent === null) {
currentNode = treeContext.tree.sheet.copy();
treeContext.tree.clear();
redrawTree(treeContext.tree);
highlightNode(currentNode, illegalColor());
}
}

Expand All @@ -66,9 +85,9 @@ export function deleteMultiMouseMove(event: MouseEvent) {
export function deleteMultiMouseUp(event: MouseEvent) {
const newPoint: Point = new Point(event.x - offset.x, event.y - offset.y);
if (legalNode) {
const currentParent = treeContext.tree.getLowestParent(newPoint);
if (currentParent !== null) {
currentParent.remove(newPoint);
const currentNode = treeContext.tree.getLowestNode(newPoint);
if (currentNode !== null && currentNode instanceof CutNode) {
currentNode.remove(newPoint);
} else {
treeContext.tree.clear();
}
Expand All @@ -82,6 +101,9 @@ export function deleteMultiMouseUp(event: MouseEvent) {
* If the mouse is held down and the user leaves canvas, we reset fields back to default.
*/
export function deleteMultiMouseOut() {
if (legalNode && currentNode !== null) {
reInsertNode(treeContext.tree, currentNode);
}
currentNode = null;
legalNode = false;
redrawTree(treeContext.tree);
Expand Down
49 changes: 38 additions & 11 deletions src/DrawModes/DeleteSingleTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {offset} from "../SharedToolUtils/DragTool";
import {drawAtom, drawCut, redrawTree} from "../SharedToolUtils/DrawUtils";
import {treeContext} from "../treeContext";
import {illegalColor} from "../Themes";
import {readdChildren, reInsertNode} from "../SharedToolUtils/EditModeUtils";

//The initial point the user pressed down.
let startingPoint: Point;
Expand All @@ -31,14 +32,28 @@ let legalNode: boolean;
export function deleteSingleMouseDown(event: MouseEvent) {
startingPoint = new Point(event.x - offset.x, event.y - offset.y);
currentNode = treeContext.tree.getLowestNode(startingPoint);

if (currentNode !== null) {
legalNode = true;
const currentParent = treeContext.tree.getLowestParent(startingPoint);
if (currentParent !== null) {
currentParent.remove(startingPoint);
}

if (
currentNode instanceof CutNode &&
currentNode.children.length !== 0 &&
currentNode !== treeContext.tree.sheet
) {
readdChildren(treeContext.tree, currentNode);
}
redrawTree(treeContext.tree);
if (currentNode instanceof AtomNode) {
drawAtom(currentNode, illegalColor(), true);
} else {
drawCut(currentNode, illegalColor());
}
legalNode = true;
} else {
legalNode = false;
}
}

Expand All @@ -49,16 +64,26 @@ export function deleteSingleMouseDown(event: MouseEvent) {
* @param event The mouse move event
*/
export function deleteSingleMouseMove(event: MouseEvent) {
if (legalNode && currentNode !== null && (currentNode as CutNode).ellipse !== null) {
reInsertNode(treeContext.tree, currentNode);
}
const newPoint: Point = new Point(event.x - offset.x, event.y - offset.y);
const newNode: CutNode | AtomNode | null = treeContext.tree.getLowestNode(newPoint);
if (currentNode !== null && currentNode !== newNode) {
const currentParent = treeContext.tree.getLowestParent(newPoint);
if (legalNode && currentNode !== null && currentParent !== null) {
legalNode = true;
redrawTree(treeContext.tree);
if (newNode === null) {
currentNode = null;
legalNode = false;
} else {
currentParent.remove(newPoint);
currentNode = newNode;
if (currentNode instanceof CutNode && currentNode.children.length !== 0) {
readdChildren(treeContext.tree, currentNode);
currentNode.children = [];
}
redrawTree(treeContext.tree);
if (currentNode instanceof AtomNode) {
drawAtom(currentNode, illegalColor(), true);
} else {
Expand All @@ -75,22 +100,20 @@ export function deleteSingleMouseMove(event: MouseEvent) {
export function deleteSingleMouseUp(event: MouseEvent) {
const newPoint: Point = new Point(event.x - offset.x, event.y - offset.y);
if (legalNode) {
const currentParent = treeContext.tree.getLowestParent(newPoint);
if (currentParent !== null) {
currentParent.remove(newPoint);
const currentNode = treeContext.tree.getLowestNode(newPoint);
if (currentNode !== null && currentNode instanceof CutNode) {
currentNode.remove(newPoint);
}
if (
currentNode !== treeContext.tree.sheet &&
currentNode instanceof CutNode &&
currentNode.children.length !== 0
) {
//The cut node loses custody of its children so that those can still be redrawn.
for (let i = 0; i < currentNode.children.length; i++) {
treeContext.tree.insert(currentNode.children[i]);
}
readdChildren(treeContext.tree, currentNode);
}
redrawTree(treeContext.tree);
}
redrawTree(treeContext.tree);

currentNode = null;
legalNode = false;
}
Expand All @@ -99,6 +122,10 @@ export function deleteSingleMouseUp(event: MouseEvent) {
* If the mouse leaves the canvas, reset data back to defaults.
*/
export function deleteSingleMouseOut() {
if (legalNode && currentNode !== null) {
reInsertNode(treeContext.tree, currentNode);
}
currentNode = null;
legalNode = false;
redrawTree(treeContext.tree);
}
50 changes: 38 additions & 12 deletions src/ProofTools/DeiterationTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,26 @@
import {Point} from "../AEG/Point";
import {AtomNode} from "../AEG/AtomNode";
import {CutNode} from "../AEG/CutNode";
import {redrawProof} from "../SharedToolUtils/DrawUtils";
import {redrawProof, highlightNode, redrawTree} from "../SharedToolUtils/DrawUtils";
import {treeContext} from "../treeContext";
import {illegalColor} from "../Themes";
import {offset} from "../SharedToolUtils/DragTool";
import {ProofNode} from "../AEG/ProofNode";
import {AEGTree} from "../AEG/AEGTree";
import {highlightChildren} from "../SharedToolUtils/EditModeUtils";
import {getCurrentProofTree} from "./ProofToolsUtils";
import {reInsertNode} from "../SharedToolUtils/EditModeUtils";

//The node selected with the user mouse down.
let currentNode: CutNode | AtomNode | null = null;

//Whether or not the node is allowed to be moved (not the sheet).
let legalNode: boolean;

//A copy of the tree we are dealing with in this step
let tempTree: AEGTree;

//The point that the current mouse event is targeting
let currentPoint: Point;

//The current tree in the proof chain
let currentProofTree: AEGTree;

Expand All @@ -30,8 +35,12 @@ let currentProofTree: AEGTree;
* @param event A Mouse up event while using the deiteration tool
*/
export function deiterationMouseDown(event: MouseEvent) {
const currentPoint: Point = new Point(event.x - offset.x, event.y - offset.y);
currentProofTree = getCurrentProofTree();
currentPoint = new Point(event.x - offset.x, event.y - offset.y);
currentProofTree = new AEGTree();
if (treeContext.currentProofStep) {
currentProofTree.sheet = treeContext.currentProofStep.tree.sheet.copy();
}
tempTree = new AEGTree(currentProofTree.sheet);
currentNode = currentProofTree.getLowestNode(currentPoint);

setLegal();
Expand All @@ -43,11 +52,12 @@ export function deiterationMouseDown(event: MouseEvent) {
* @param event A mouse move event while using deiteration tool
*/
export function deiterationMouseMove(event: MouseEvent) {
const currentPoint: Point = new Point(event.x - offset.x, event.y - offset.y);
currentNode = currentProofTree.getLowestNode(currentPoint);
redrawProof();

setLegal();
currentPoint = new Point(event.x - offset.x, event.y - offset.y);
if (currentNode !== null) {
currentNode = currentProofTree.getLowestNode(currentPoint);
redrawProof();
setLegal();
}
}

/**
Expand All @@ -57,7 +67,7 @@ export function deiterationMouseMove(event: MouseEvent) {
*/
export function deiterationMouseUp(event: MouseEvent) {
if (legalNode) {
const currentPoint: Point = new Point(event.x - offset.x, event.y - offset.y);
currentPoint = new Point(event.x - offset.x, event.y - offset.y);
if (
currentNode !== null &&
canDeiterate(currentProofTree.sheet, currentProofTree.getLevel(currentNode))
Expand All @@ -83,8 +93,21 @@ function setLegal() {
!(currentNode instanceof CutNode && currentNode.ellipse === null) &&
canDeiterate(currentProofTree.sheet, currentProofTree.getLevel(currentNode))
) {
highlightChildren(currentNode, illegalColor());
legalNode = true;

//Find the parent at the point we are on
const tempParent = tempTree.getLowestParent(currentPoint);
if (tempParent !== null) {
//remove the node from the parent
tempParent.remove(currentPoint);
}

//Draw the temp tree, from which the node we want to erase has been removed
redrawTree(tempTree);
//Highlight the node selected for deiteration in illegal color
highlightNode(currentNode, illegalColor());
//Insert it back into the temporary tree
tempTree.insert(currentNode);
} else {
legalNode = false;
}
Expand All @@ -94,6 +117,9 @@ function setLegal() {
* Reset the current null and make this node illegal until it's selected again, redraws the screen.
*/
export function deiterationMouseOut() {
if (legalNode && currentNode !== null) {
reInsertNode(tempTree, currentNode);
}
legalNode = false;
currentNode = null;
redrawProof();
Expand Down
Loading

0 comments on commit a7fda24

Please sign in to comment.