Skip to content

Commit

Permalink
cleanup. add new grid, show double-clicked lines on canvas
Browse files Browse the repository at this point in the history
  • Loading branch information
Ron Lawrence committed Apr 14, 2024
1 parent 5e1ae78 commit 844f97b
Show file tree
Hide file tree
Showing 10 changed files with 201 additions and 158 deletions.
Binary file removed .DS_Store
Binary file not shown.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
node_modules
dist
src
index.html.gz
index.html.gz
.DS_Store
Empty file added prettier.config.js
Empty file.
7 changes: 2 additions & 5 deletions www/css/tablet.css
Original file line number Diff line number Diff line change
Expand Up @@ -758,11 +758,8 @@ textarea {

.caltable {
width: 100%;
font-size: 10pt;
}

.caltable table {
font-size: 10px;
font-size: x-small !important;
height: 600px;
}

.caltable textarea {
Expand Down
114 changes: 55 additions & 59 deletions www/index.html
Original file line number Diff line number Diff line change
@@ -1,63 +1,59 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="mobile-web-app-capable" content="yes">
<title>ESP3D WebUI</title>
<script>
var target_firmware = "";
</script>
<script>
var web_ui_version = "replaceVERSION";
</script>
<script>
var direct_sd = false;
</script>
<script>
var fw_version = "";
</script>
<script>
var primary_sd = "/ext/";
</script>
<script>
var secondary_sd = "/sd/";
</script>
<!--removeIf(cleanheader)-->
<link href="css/bootstrap.css" rel="stylesheet" />
<link href="css/menu.css" rel="stylesheet" />
<link href="css/tabs.css" rel="stylesheet" />
<link href="css/modaldlg.css" rel="stylesheet" />
<link href="css/wizard.css" rel="stylesheet" />
<link href="css/tablet.css" rel="stylesheet" />
<link href="css/tooltip.css" rel="stylesheet" />
<link href="css/loadingOverlay.css" rel="stylesheet" />

<!--endRemoveIf(cleanheader)-->
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="mobile-web-app-capable" content="yes">
<title>ESP3D WebUI</title>
<script>
var target_firmware = "";
</script>
<script>
var web_ui_version = "replaceVERSION";
</script>
<script>
var direct_sd = false;
</script>
<script>
var fw_version = "";
</script>
<script>
var primary_sd = "/ext/";
</script>
<script>
var secondary_sd = "/sd/";
</script>
<!--removeIf(cleanheader)-->
<link href="css/bootstrap.css" rel="stylesheet" />
<link href="css/menu.css" rel="stylesheet" />
<link href="css/tabs.css" rel="stylesheet" />
<link href="css/modaldlg.css" rel="stylesheet" />
<link href="css/wizard.css" rel="stylesheet" />
<link href="css/tablet.css" rel="stylesheet" />
<link href="css/tooltip.css" rel="stylesheet" />

<!-- smoosh -->
<link href="css/style.css" rel="stylesheet" />
<!-- endsmoosh -->
</head>
<body>
<file-include w3-include-html="'sub/calibrationtab.html'"></file-include>
<!--removeIf(cleanheader)-->
<script src="js/util.js"></script>
<script src="js/wizard.js"></script>
<script src="js/http.js"></script>
<script src="js/icons.js"></script>
<script src="js/camera.js"></script>
<script src="js/settings.js"></script>
<script src="js/config.js"></script>
<script src="js/controls.js"></script>
<script src="js/custom.js"></script>
<script src="js/calculatesCalibrationStuff.js"></script>
<script src="js/calibrationDraw.js"></script>
<!--endRemoveIf(cleanheader)-->
<!-- smoosh -->
<script src="js/app.js"></script>
<!-- endsmoosh -->
</body>
</html>
<!--endRemoveIf(cleanheader)-->

<!-- smoosh -->
<link href="css/style.css" rel="stylesheet" />
<!-- endsmoosh -->
<script src="https://cdn.jsdelivr.net/npm/ag-grid-community/dist/ag-grid-community.min.js"></script>

</head>

<body>
<file-include w3-include-html="'sub/calibrationtab.html'"></file-include>
<!--removeIf(cleanheader)-->
<script src="js/calculatesCalibrationStuff.js"></script>
<script src="js/calibrationDraw.js"></script>
<!--endRemoveIf(cleanheader)-->
<!-- smoosh -->
<script src="js/app.js"></script>
<!-- endsmoosh -->
<script src="js/grid.js"></script>
</body>

</html>
15 changes: 0 additions & 15 deletions www/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,21 +77,6 @@ function browser_is(bname) {
return false
}

window.onload = function () {
//to check if javascript is disabled like in anroid preview
displayNone('loadingmsg')
console.log('Connect to board')
connectdlg()
//ugly hack for IE
console.log(navigator.userAgent)
if (browser_is('IE')) {
id('control-body').className = 'panel-body'
id('command-body').className = 'panel-body'
id('file-body').className = 'panel-body panel-height panel-max-height panel-scroll'
}
tabletInit()
}

var wsmsg = ''

function startSocket() {
Expand Down
2 changes: 1 addition & 1 deletion www/js/calculatesCalibrationStuff.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ function magneticallyAttractedLinesFitness(measurement, individual) {
measurement.TLtension = TL
measurement.TRtension = TR

drawLines(tlLine, trLine, blLine, brLine, individual);
drawLines(tlLine, trLine, blLine, brLine, individual, measurement);

return { fitness: finalFitness, lines: { tlLine: tlLine, trLine: trLine, blLine: blLine, brLine: brLine } }
}
Expand Down
134 changes: 62 additions & 72 deletions www/js/calibrationDraw.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@ function measurementsChanged() {
}

function updateCalibrationSave(caldata) {
SavedMeasurements = caldata;
calibrationTableUpdate();
document.querySelector('button#compute-sim-button').disabled = false;
let id=0;
SavedMeasurements = caldata.map(m=>({...m, id: id++}));
calibrationTableUpdate();
document.querySelector('button#compute-sim-button').disabled = false;
// draw one...
computeLinesFitness(SavedMeasurements, initialGuess);
}

function computeSim() {
Expand Down Expand Up @@ -69,76 +72,63 @@ function changeStrokeStyle(inputValue) {
* @param {Object} line4 - An object containing the x and y coordinates of the beginning and end of the fourth line.
* @returns {void}
*/
function drawLines(line1, line2, line3, line4, guess) {

//Compute the tensions in the upper two belts
//const { TL, TR } = calculateTensions(line1.xEnd, line1.yEnd, guess); //This assumes the ends are in the same place which they aren't at first

var canvas = document.getElementById("CursorLayer");
var ctx = canvas.getContext("2d");

// Set the stroke color to a lighter grey
ctx.strokeStyle = "#999";

// Draw the four lines
ctx.setLineDash([5, 5]);

//Top left line
ctx.beginPath();
ctx.moveTo(line1.xBegin / 4, flipY(line1.yBegin / 4));
ctx.lineTo(line1.xEnd / 4, flipY(line1.yEnd / 4));
ctx.stroke();
ctx.beginPath();
ctx.arc(line1.xEnd / 4, flipY(line1.yEnd / 4), 2, 0, 2 * Math.PI);
ctx.fill();

//Top right line
ctx.beginPath();
ctx.moveTo(line2.xBegin / 4, flipY(line2.yBegin / 4));
ctx.lineTo(line2.xEnd / 4, flipY(line2.yEnd / 4));
ctx.stroke();
ctx.beginPath();
ctx.arc(line2.xEnd / 4, flipY(line2.yEnd / 4), 2, 0, 2 * Math.PI);
ctx.fill();

ctx.beginPath();
ctx.moveTo(line3.xBegin / 4, flipY(line3.yBegin / 4));
ctx.lineTo(line3.xEnd / 4, flipY(line3.yEnd / 4));
ctx.stroke();
ctx.beginPath();
ctx.arc(line3.xEnd / 4, flipY(line3.yEnd / 4), 2, 0, 2 * Math.PI);
ctx.fill();

ctx.beginPath();
ctx.moveTo(line4.xBegin / 4, flipY(line4.yBegin / 4));
ctx.lineTo(line4.xEnd / 4, flipY(line4.yEnd / 4));
ctx.stroke();
ctx.beginPath();
ctx.arc(line4.xEnd / 4, flipY(line4.yEnd / 4), 2, 0, 2 * Math.PI);
ctx.fill();
function drawLines(line1, line2, line3, line4, guess, measurement) {

//Compute the tensions in the upper two belts
//const { TL, TR } = calculateTensions(line1.xEnd, line1.yEnd, guess); //This assumes the ends are in the same place which they aren't at first

var canvas = document.getElementById("CursorLayer");
var ctx = canvas.getContext("2d");

// Set the stroke color to a lighter grey
ctx.strokeStyle = "#999";

// Draw the four lines
ctx.setLineDash([5, 5]);

//Top left line
ctx.beginPath();
ctx.moveTo(line1.xBegin / 4, flipY(line1.yBegin / 4));
ctx.lineTo(line1.xEnd / 4, flipY(line1.yEnd / 4));
ctx.stroke();
ctx.beginPath();
ctx.arc(line1.xEnd / 4, flipY(line1.yEnd / 4), 2, 0, 2 * Math.PI);
ctx.fill();

//Top right line
ctx.beginPath();
ctx.moveTo(line2.xBegin / 4, flipY(line2.yBegin / 4));
ctx.lineTo(line2.xEnd / 4, flipY(line2.yEnd / 4));
ctx.stroke();
ctx.beginPath();
ctx.arc(line2.xEnd / 4, flipY(line2.yEnd / 4), 2, 0, 2 * Math.PI);
ctx.fill();

ctx.beginPath();
ctx.moveTo(line3.xBegin / 4, flipY(line3.yBegin / 4));
ctx.lineTo(line3.xEnd / 4, flipY(line3.yEnd / 4));
ctx.stroke();
ctx.beginPath();
ctx.arc(line3.xEnd / 4, flipY(line3.yEnd / 4), 2, 0, 2 * Math.PI);
ctx.fill();

ctx.beginPath();
ctx.moveTo(line4.xBegin / 4, flipY(line4.yBegin / 4));
ctx.lineTo(line4.xEnd / 4, flipY(line4.yEnd / 4));
ctx.stroke();
ctx.beginPath();
ctx.arc(line4.xEnd / 4, flipY(line4.yEnd / 4), 2, 0, 2 * Math.PI);
ctx.fill();
if (measurement.id != undefined) {
// update grid
gridApi.applyTransaction({
update: [{ ...measurement, line1, line2, line3, line4 }],
});
} else{
console.log('no id', measurement);
}
}

function calibrationTableUpdate() {
const table = document.querySelector("#caltable");
if (table.rows.length) {
for (let i=table.rows.length; i>0;i--) {
table.deleteRow(0);
}
}
const headr = table.insertRow();
headr.insertCell(-1).innerText = "Action";
headr.insertCell(-1).innerText = "Top Left";
headr.insertCell(-1).innerText = "Top Right";
headr.insertCell(-1).innerText = "Bottom Right";
headr.insertCell(-1).innerText = "Bottom Left";
SavedMeasurements.forEach(
m => {
const row = table.insertRow();
row.insertCell(-1).innerText = "";
row.insertCell(-1).innerText = "" + m.tl;
row.insertCell(-1).innerText = "" + m.tr;
row.insertCell(-1).innerText = "" + m.br;
row.insertCell(-1).innerText = "" + m.bl;
}
)
gridApi?.setGridOption('rowData', SavedMeasurements);
}
74 changes: 74 additions & 0 deletions www/js/grid.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// Grid Options: Contains all of the grid configurations
const agGridOptions = {
rowData: [],
columnDefs: [
{
field: "id",
headerName: "ID",
width: 80,
},
{
field: "tl",
headerName: "Top Left",
width: 100,
},
{
field: "tr",
headerName: "Top Right",
width: 100,
},
{
field: "bl",
headerName: "Bottom Left",
width: 120,
},
{
field: "br",
headerName: "Bottom Right",
width: 120,
},
],
onRowDoubleClicked: (p) => {
console.log(p);
if (p.data.line1) {
var canvas = document.getElementById("CursorLayer");
var ctx = canvas.getContext("2d");
highlightLine(p.data.line1, ctx, 3000);
highlightLine(p.data.line2, ctx, 3000);
highlightLine(p.data.line3, ctx, 3000);
highlightLine(p.data.line4, ctx, 3000);
}
},
onGridReady: (params) => {
gridApi = params.api;
console.log("my grid is ready", params);
},
getRowId: (params) => params.data.id,
};

const myGridElement = document.querySelector("#caltable");
agGrid.createGrid(myGridElement, agGridOptions);
// Use this to update/ interact.
let gridApi = null;

function highlightLine(line, ctx, time) {
ctx.fillStyle = "red";
ctx.strokeStyle = "red";
doDrawLine(line, ctx);
ctx.fillStyle = "black";
ctx.strokeStyle = "#999";
setTimeout(() => {
doDrawLine(line, ctx);
}, time);
}

function doDrawLine(line, ctx) {
ctx.setLineDash([5, 5]);
ctx.beginPath();
ctx.moveTo(line.xBegin / 4, flipY(line.yBegin / 4));
ctx.lineTo(line.xEnd / 4, flipY(line.yEnd / 4));
ctx.stroke();
ctx.beginPath();
ctx.arc(line.xEnd / 4, flipY(line.yEnd / 4), 2, 0, 2 * Math.PI);
ctx.fill();
}
Loading

0 comments on commit 844f97b

Please sign in to comment.