Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

284 clear proofs #287

Merged
merged 35 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
9184621
Ugly little buttons with text next to them
DawnTheWitch Nov 26, 2023
ff147be
Only shows up when in proof mode
DawnTheWitch Nov 26, 2023
1670123
Merge branch 'master' into 230-proof-history-bar-keep-track-of-previo…
DawnTheWitch Nov 26, 2023
5090a38
working
AnushaTiwari5 Nov 27, 2023
565499a
Merge branch 'master' into 230-proof-history-bar-keep-track-of-previo…
RyanR712 Nov 28, 2023
b1802c5
master merge
AnushaTiwari5 Nov 29, 2023
a25bbfb
changed all references of proofHistory to proof
AnushaTiwari5 Nov 29, 2023
06a9766
fixed all conflicts
AnushaTiwari5 Nov 29, 2023
ff24657
left in comments oop theyre gone now
AnushaTiwari5 Nov 29, 2023
33a1096
Idk what I'm doing
DawnTheWitch Nov 29, 2023
eaa667f
Merge remote-tracking branch 'origin/select-proof-tree-to-work-on' in…
DawnTheWitch Nov 29, 2023
b07c67b
Merge branch '230-proof-history-bar-keep-track-of-previous-aegs-and-l…
DawnTheWitch Nov 29, 2023
d4c333b
New button for each step, no clicky though
DawnTheWitch Nov 29, 2023
b27096f
Basic commenting, as well as the deletion of buttons
DawnTheWitch Nov 29, 2023
52016f5
Merge branch 'master' into 230-proof-history-bar-keep-track-of-previo…
AnushaTiwari5 Dec 2, 2023
f6adfef
proof history maintained when toggling modes
AnushaTiwari5 Dec 2, 2023
c793ee1
Merge branch 'master' into 230-proof-history-bar-keep-track-of-previo…
DawnTheWitch Dec 3, 2023
29632f5
Working I believe, needs cleaning and some additional things
DawnTheWitch Dec 3, 2023
d2173e0
Merge branch 'master' into 230-proof-history-bar-keep-track-of-previo…
DawnTheWitch Dec 3, 2023
b3b4a52
Merge branch '230-proof-history-bar-keep-track-of-previous-aegs-and-l…
AnushaTiwari5 Dec 5, 2023
97e8828
clear proof done
AnushaTiwari5 Dec 5, 2023
dd419b2
Merge branch 'modeState-magic-numbers-fix' of github.com:James-Oswald…
AnushaTiwari5 Dec 5, 2023
0d26448
proof clear and drag done
AnushaTiwari5 Dec 5, 2023
209c624
Become Egg.
DawnTheWitch Dec 5, 2023
08e2e11
Merge branch 'master' into 284-clear-proofs
AnushaTiwari5 Dec 5, 2023
b47f394
Removed aspect ration, other circle buttons have same issue.
DawnTheWitch Dec 5, 2023
2daeaad
Merge branch 'master' into 284-clear-proofs
AnushaTiwari5 Dec 5, 2023
158b61d
4 Spaces gang
DawnTheWitch Dec 6, 2023
b1c5657
Inline dictionary
DawnTheWitch Dec 6, 2023
05b1923
Guess who missed an indent on 1 line.
DawnTheWitch Dec 6, 2023
e720f85
Merge branch 'master' into 284-clear-proofs
AnushaTiwari5 Dec 6, 2023
3e6ca2b
fix for insertion messing up after a drag - added extra offset in cal…
AnushaTiwari5 Dec 6, 2023
90be43e
Mouse out bug I was seeing
DawnTheWitch Dec 6, 2023
21fadc2
Merge branch '284-clear-proofs' of https://github.com/RAIRLab/Peirce-…
DawnTheWitch Dec 6, 2023
4107afe
Merge branch 'master' into 284-clear-proofs
AnushaTiwari5 Dec 7, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/AEG/ProofNode.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {treeContext} from "../treeContext";
import {AEGTree} from "./AEGTree";

/**
Expand All @@ -10,8 +11,16 @@ export class ProofNode {
*/
public tree: AEGTree;

/**
* The proof node's action that changed the proof
*/
public appliedRule: string;

/**
* The current location of this proof node in our proof array
*/
public index: number;

/**
* Construct a proof node by providing the AEG Tree at the current state of the proof
* @param tree The AEG at the current state of the proof.
Expand All @@ -21,5 +30,6 @@ export class ProofNode {
public constructor(tree?: AEGTree, rule?: string) {
this.appliedRule = rule ?? "";
this.tree = new AEGTree(tree?.sheet);
this.index = treeContext.proof.length;
}
}
15 changes: 12 additions & 3 deletions src/DrawModes/DragTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import {Point} from "../AEG/Point";
import {treeContext} from "../treeContext";
import {redrawTree} from "./DrawUtils";
import {redrawProof, redrawTree} from "./DrawUtils";

//Original point later points will be compared to.
let originPoint: Point;
Expand All @@ -32,7 +32,12 @@ export function dragMouseDown(event: MouseEvent) {
export function dragMouseMove(event: MouseEvent) {
if (!wasOut) {
offset = new Point(event.x - originPoint.x, event.y - originPoint.y);
redrawTree(treeContext.tree);

if (treeContext.modeState === "Proof") {
redrawProof();
} else {
redrawTree(treeContext.tree);
}
}
}

Expand All @@ -41,5 +46,9 @@ export function dragMouseMove(event: MouseEvent) {
*/
export function dragMosueOut() {
wasOut = true;
redrawTree(treeContext.tree);
if (treeContext.modeState === "Proof") {
redrawProof();
} else {
redrawTree(treeContext.tree);
}
}
4 changes: 2 additions & 2 deletions src/DrawModes/DrawUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,10 @@ export function redrawProof() {
//If this is the first step taken in the proof,
//set the current tree as the head of the proof history
let tree: AEGTree;
if (treeContext.proofHistory.length === 0) {
if (treeContext.proof.length === 0 || treeContext.currentProofStep === undefined) {
tree = new AEGTree();
} else {
tree = treeContext.proofHistory[treeContext.proofHistory.length - 1].tree;
tree = treeContext.currentProofStep.tree;
}

cleanCanvas();
Expand Down
70 changes: 70 additions & 0 deletions src/ProofHistory.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/**
* Creates the history bar on the left side of the screen and handles returning to a previous state.
* @author Dawn Moore
*/

import {treeContext} from "./treeContext";
import {redrawProof} from "./DrawModes/DrawUtils";
import {ProofNode} from "./AEG/ProofNode";

/**
* Creates a button representing the proof step allowing a user to return to that step.
* Creates a new row, a piece of text, and a button for it.
* @param newStep The newest step of our proof
*/
export function appendStep(newStep: ProofNode) {
const newDiv = document.createElement("div");
newDiv.className = "row";
newDiv.id = "Row: " + treeContext.proof.length;

//Create the new button with the function stepBack calling the step it represents
const button = document.createElement("button");
button.type = "button";
button.id = "Step: " + treeContext.proof.length;
button.className = "proofNodeButton";
button.title = newStep.tree.toString();
button.onclick = function () {
stepBack(newStep);
};

//Determine which action was just taken to give the button the corresponding icon.
const icon = document.createElement("Text");
icon.className =
"fa fa-" +
{
"Single Move": "mouse-pointer",
"Multi Move": "arrows",
Resize: "arrows-alt",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm suspicious that this may not work without quotations, though its possible it will, add them anyway for quality.

"DC Insert": "dot-circle-o",
"DC Delete": "times-circle",
Insertion: "plus",
Erasure: "trash",
Iteration: "expand",
Deiteration: "compress",
Pasted: "files-o",
}[newStep.appliedRule];

button.appendChild(icon);
newDiv.appendChild(button);
document.getElementById("proofHistoryBar")?.appendChild(newDiv);
}

/**
* Sets the selected step to be the current step and redraws the canvas to represent this.
* This will be called when a button representing a proof step is pushed.
* @param selectedStep The selected proof Node that will become the current step
*/
export function stepBack(selectedStep: ProofNode) {
treeContext.currentProofStep = selectedStep;
redrawProof();
}

/**
* Removes buttons related to proof steps that are no longer a part of the proof.
* @param stopIndex The index to stop removing buttons.
*/
export function deleteButtons(stopIndex: number) {
for (let i = treeContext.proof.length; i > stopIndex + 1; i--) {
document.getElementById("Row: " + i)?.remove();
}
}
55 changes: 55 additions & 0 deletions src/ProofTools/ClearProofTool.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/**
* File containing clear proof tool event handlers
* @author Anusha Tiwari
*/

import {treeContext} from "../treeContext";
import {cleanCanvas, highlightNode, redrawProof} from "../DrawModes/DrawUtils";
import {AEGTree} from "../AEG/AEGTree";
import {illegalColor} from "../Themes";
import {deleteButtons} from "../ProofHistory";

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

//Whether or not the node can be cleared
let legalNode: boolean;

/**
* Handles the mouseDown event for clearProofTool
* Gets the tree of the current step and highlights it in the illegal color
*/
export function clearProofMouseDown() {
//Get the tree of the current step
currentProofTree = new AEGTree();
if (treeContext.currentProofStep) {
currentProofTree.sheet = treeContext.currentProofStep.tree.sheet.copy();
}

//As long as we are within the canvas, we can legally perform clear
legalNode = true;
//Clear the canvas and redraw the tree in illegal color to show that it will be deleted
cleanCanvas();
highlightNode(currentProofTree.sheet, illegalColor());
}

/**
* Handles the mouseOut event for clearProofTool
* If we are within the canvas, delete the proof history buttons and clear the proof
*/
export function clearProofMouseUp() {
if (legalNode) {
deleteButtons(-1);
treeContext.clearProof();
redrawProof();
}
}

/**
* Handles the mouseOut event for clearProofTool
* If we move out of the canvas, the proof cannot be cleared
*/
export function clearProofMouseOut() {
legalNode = false;
redrawProof();
}
7 changes: 5 additions & 2 deletions src/ProofTools/DeiterationTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ let currentProofTree: AEGTree;
*/
export function deiterationMouseDown(event: MouseEvent) {
const currentPoint: Point = new Point(event.x - offset.x, event.y - offset.y);
currentProofTree = new AEGTree(treeContext.getLastProofStep().tree.sheet);
currentProofTree = new AEGTree();
if (treeContext.currentProofStep) {
currentProofTree.sheet = treeContext.currentProofStep.tree.sheet.copy();
}
Comment on lines +33 to +36
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we need this exact block of code in every single proof mode tool it should be turned into a helper function.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still holds

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has been added to the master clean up issue.

currentNode = currentProofTree.getLowestNode(currentPoint);

setLegal();
Expand Down Expand Up @@ -65,7 +68,7 @@ export function deiterationMouseUp(event: MouseEvent) {
if (currentParent instanceof CutNode) {
currentParent.remove(currentPoint);
}
treeContext.proofHistory.push(new ProofNode(currentProofTree, "Deiteration"));
treeContext.pushToProof(new ProofNode(currentProofTree, "Deiteration"));
}
}

Expand Down
9 changes: 6 additions & 3 deletions src/ProofTools/DoubleCutDeletionTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ let currentProofTree: AEGTree;
*/
export function doubleCutDeletionMouseDown(event: MouseEvent) {
const currentPoint: Point = new Point(event.x - offset.x, event.y - offset.y);
currentProofTree = new AEGTree(treeContext.getLastProofStep().tree.sheet);
currentProofTree = new AEGTree();
if (treeContext.currentProofStep) {
currentProofTree.sheet = treeContext.currentProofStep.tree.sheet.copy();
}
currentNode = currentProofTree.getLowestNode(currentPoint);

isLegal();
Expand All @@ -55,7 +58,7 @@ export function doubleCutDeletionMouseMove(event: MouseEvent) {
export function doubleCutDeletionMouseUp(event: MouseEvent) {
//Stores the tree of the previous proof so that we can perform double cut actions without
//altering that tree
const nextProof = new ProofNode(currentProofTree, "Double Cut Deletion");
const nextProof = new ProofNode(currentProofTree, "DC Delete");
const currentPoint: Point = new Point(event.x - offset.x, event.y - offset.y);

if (legalNode && currentNode instanceof CutNode) {
Expand All @@ -67,8 +70,8 @@ export function doubleCutDeletionMouseUp(event: MouseEvent) {
for (let i = 0; i < lowerCut.children.length; i++) {
nextProof.tree.insert(lowerCut.children[i]);
}
treeContext.pushToProof(nextProof);
}
treeContext.proofHistory.push(nextProof);
}

redrawProof();
Expand Down
9 changes: 6 additions & 3 deletions src/ProofTools/DoubleCutInsertionTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ let currentProofTree: AEGTree;
*/
export function doubleCutInsertionMouseDown(event: MouseEvent) {
startingPoint = new Point(event.clientX - offset.x, event.clientY - offset.y);
currentProofTree = new AEGTree(treeContext.getLastProofStep().tree.sheet);
currentProofTree = new AEGTree();
if (treeContext.currentProofStep) {
currentProofTree.sheet = treeContext.currentProofStep.tree.sheet.copy();
}
wasOut = false;
}

Expand Down Expand Up @@ -80,7 +83,7 @@ export function doubleCutInsertionMouseUp(event: MouseEvent) {

//Stores the tree of the previous proof so that we can perform double cut actions without
//altering that tree
const nextProof = new ProofNode(currentProofTree, "Double Cut Insertion");
const nextProof = new ProofNode(currentProofTree, "DC Insert");

if (!wasOut && largeCut.ellipse !== null && smallCut.ellipse !== null) {
//If either ellipse is in an invalid position or too small it cannot be inserted
Expand All @@ -93,7 +96,7 @@ export function doubleCutInsertionMouseUp(event: MouseEvent) {
if (legal) {
nextProof.tree.insert(largeCut);
nextProof.tree.insert(smallCut);
treeContext.proofHistory.push(nextProof);
treeContext.pushToProof(nextProof);
}
}
redrawProof();
Expand Down
7 changes: 5 additions & 2 deletions src/ProofTools/ErasureTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ let currentProofTree: AEGTree;
*/
export function erasureMouseDown(event: MouseEvent) {
const currentPoint: Point = new Point(event.x - offset.x, event.y - offset.y);
currentProofTree = new AEGTree(treeContext.getLastProofStep().tree.sheet);
currentProofTree = new AEGTree();
if (treeContext.currentProofStep) {
currentProofTree.sheet = treeContext.currentProofStep.tree.sheet.copy();
}
currentNode = currentProofTree.getLowestNode(currentPoint);

isLegal();
Expand Down Expand Up @@ -65,7 +68,7 @@ export function erasureMouseUp(event: MouseEvent) {
currentParent.remove(currentPoint);
}

treeContext.proofHistory.push(nextProof);
treeContext.pushToProof(nextProof);
redrawProof();
}

Expand Down
16 changes: 8 additions & 8 deletions src/ProofTools/InsertionTools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,15 @@ let legalNode: boolean;
export function insertionMouseDown(event: MouseEvent) {
//Create a deep copy of the tree we are trying to insert the incoming node into so that we can
//modify it as needed without affecting the actual structure
currentTree = new AEGTree(treeContext.getLastProofStep().tree.sheet);
currentTree = new AEGTree();
if (treeContext.currentProofStep) {
currentTree.sheet = treeContext.currentProofStep.tree.sheet.copy();
}
const selectedNodes = treeContext.selectForProof.sheet.children;
const startingPoint = new Point(event.x - offset.x, event.y - offset.y);

//we can insert only a single subgraph at a time
if (treeContext.proofHistory.length > 0 && selectedNodes.length === 1) {
if (treeContext.proof.length > 0 && selectedNodes.length === 1) {
//As long as there are graphs to be placed, they are legal nodes
legalNode = true;
currentNode = selectedNodes[0];
Expand Down Expand Up @@ -225,7 +228,7 @@ export function insertionMouseUp(event: MouseEvent) {
currentTree.insert(tempAtom);
}
//Insertion is a new step -> push a new node in the proof, signifying it as such
treeContext.proofHistory.push(new ProofNode(currentTree, "Insertion"));
treeContext.pushToProof(new ProofNode(currentTree, "Insertion"));
}
}
redrawProof();
Expand All @@ -246,12 +249,9 @@ export function insertionMouseOut() {
*/
function calculatePoint(event: MouseEvent, node: CutNode | AtomNode): Point | undefined {
if (node instanceof CutNode && node.ellipse !== null) {
return new Point(
event.x - node.ellipse.center.x - offset.x,
event.y - node.ellipse.center.y - offset.y
);
return new Point(event.x - node.ellipse.center.x, event.y - node.ellipse.center.y);
} else if (node instanceof AtomNode) {
return new Point(event.x - node.origin.x - offset.x, event.y - node.origin.y - offset.y);
return new Point(event.x - node.origin.x, event.y - node.origin.y);
}

return undefined;
Expand Down
7 changes: 5 additions & 2 deletions src/ProofTools/IterationTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ export function iterationMouseDown(event: MouseEvent) {
//Make a deep copy of the tree of our latest proof step. Our iteration actions will be performed
//on this structure, but they should all be on a new step - we do not want to make any changes
//on the existing step
currentProofTree = new AEGTree(treeContext.getLastProofStep().tree.sheet);
currentProofTree = new AEGTree();
if (treeContext.currentProofStep) {
currentProofTree.sheet = treeContext.currentProofStep.tree.sheet.copy();
}
startingPoint = new Point(event.x - offset.x, event.y - offset.y);
currentNode = currentProofTree.getLowestNode(startingPoint);
currentParent = currentProofTree.getLowestParent(startingPoint);
Expand Down Expand Up @@ -99,7 +102,7 @@ export function iterationMouseUp(event: MouseEvent) {
currentProofTree.insert(tempAtom);
}
//Iteration is a new step -> push a new node in the proof, signifying it as such
treeContext.proofHistory.push(new ProofNode(currentProofTree, "Iteration"));
treeContext.pushToProof(new ProofNode(currentProofTree, "Iteration"));
}
}
redrawProof();
Expand Down
Loading