Marthee commited on
Commit
450cff3
·
verified ·
1 Parent(s): 7839d18

Upload proposed-GUI.html

Browse files
Files changed (1) hide show
  1. templates/proposed-GUI.html +132 -130
templates/proposed-GUI.html CHANGED
@@ -3314,7 +3314,7 @@ function getData(form) {
3314
  {
3315
  var Thickness= document.getElementById("text002extra").value
3316
  answers.push(tomeasureproj, 0,[], ratio1, ratio2,pdfpath,groupedValues,checkedItems,Thickness,shapeData,ratio3); //location of shape
3317
- formData.append('file',dxffile)
3318
  }
3319
  formData.append('answers',JSON.stringify(answers))
3320
  }
@@ -4603,146 +4603,147 @@ function drawCircle(x, y) {
4603
  /*Set canvas code to be visible on the new window with the pdftoimg as the background*/
4604
 
4605
  var levelsin = document.getElementById('levelcheckbox');
4606
- var canvaswindow= document.getElementById('canvaswindow');
4607
- var undoButtonId=document.getElementById('undoButtonId');
4608
- NewShapeButtonId=document.getElementById('NewShapeButtonId');
4609
- var savecanvas=document.getElementById('savecanvas');
4610
- var scaleX=1;
4611
- var scaleY=1;
4612
- var shapeData = [];
4613
- levelsin.addEventListener('click',function(){
4614
- if (sectionNumber.startsWith('1.0') || sectionNumber.startsWith('2.7') ||sectionNumber.startsWith('3.2') || sectionNumber.startsWith('3.3'))
4615
- {
4616
- document.getElementById("all").style.display = "block";
4617
- if (document.getElementById('levelcheckbox').checked) {
4618
- $.get('/canvaspdftoimgBackground/' + pdfname)
4619
- .success(function (data) {
4620
- document.getElementById("all").style.display = "none";
4621
- var popup = window.open('');
4622
- popup.document.write('<html><head><title>ADR Console:Draw on PDF tool</title><link rel="stylesheet" href="static/style.css"></head><body>');
4623
-
4624
- if (sectionNumber.startsWith('2.7') || sectionNumber.startsWith('3.2') || sectionNumber.startsWith('3.3')) {
4625
- document.getElementById('colorpickers').setAttribute('hidden', true);
4626
- document.getElementById('NewShapeButtonId').style.display='none';
4627
- }
4628
-
4629
- var element = popup.document.createElement('div');
4630
- element.setAttribute('id', 'mydiv');
4631
-
4632
- // Original PDF image size
4633
- const pdfWidth = data[2];
4634
- const pdfHeight = data[1];
 
 
 
 
4635
 
4636
- // Set actual canvas pixel dimensions (internal resolution)
4637
- canvaswindow.childNodes[1].width = pdfWidth;
4638
- canvaswindow.childNodes[1].height = pdfHeight;
 
4639
 
4640
- // Set displayed (on-screen) size
4641
- const displayWidthCSS = 0.5 * screen.width; // visual scale down
4642
- const displayHeightCSS = pdfHeight * (displayWidthCSS / pdfWidth);
4643
- canvaswindow.childNodes[1].style.width = displayWidthCSS + 'px';
4644
- canvaswindow.childNodes[1].style.height = displayHeightCSS + 'px';
4645
 
4646
- // Now get actual rendered size
4647
- const displayWidth = canvaswindow.childNodes[1].offsetWidth;
4648
- const displayHeight = canvaswindow.childNodes[1].offsetHeight;
4649
 
4650
- // Correct scale ratios (display → PDF)
4651
- const scaleX = pdfWidth / displayWidth;
4652
- const scaleY = pdfHeight / displayHeight;
 
4653
 
4654
- console.log("Display:", displayWidth, displayHeight);
4655
- console.log("PDF:", pdfWidth, pdfHeight);
4656
- console.log("ScaleX:", scaleX, "ScaleY:", scaleY);
4657
 
4658
- element.append(canvaswindow);
4659
- canvaswindow.removeAttribute('hidden');
4660
 
4661
- var imgDrawon = document.createElement("img");
4662
- imgDrawon.src = 'data:image/gif;base64,' + data[0];
4663
- imgDrawon.id = 'imgcanvas';
4664
- imgDrawon.alt = "Larry";
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4665
 
4666
- imgDrawon.onload = function () {
4667
- // ctx.setTransform(scaleX, 0, 0, scaleY, 0, 0);
4668
- var scale = data[2] / canvaswindow.childNodes[1].style.width.slice(0,-2) ; // get the scale that matches display size
4669
- ctx.setTransform(scale,0,0,scale,0,0);
4670
- ctx.drawImage(imgDrawon, 0, 0, displayWidth, displayHeight);
4671
- };
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4672
 
4673
- var win = popup.document.body;
4674
- win.appendChild(element);
 
 
 
 
4675
 
4676
- undoButtonId.addEventListener("click", e => {
4677
- if (ry[ry.length - 1].length > 0) {
4678
- ry[ry.length - 1].pop();
 
 
4679
  } else {
4680
- ry.pop();
4681
- ry[ry.length - 1].pop();
4682
- }
4683
- ctx.clearRect(0, 0, canvas.width, canvas.height);
4684
- ctx.drawImage(imgDrawon, 0, 0, displayWidth, displayHeight);
4685
- drawChart();
4686
- });
4687
-
4688
- savecanvas.addEventListener('click', function () {
4689
- var image = new Image();
4690
- image.src = canvas.toDataURL("image/png");
4691
- canvasimg = image.src;
4692
- console.log('saved');
4693
-
4694
- if (sectionNumber.startsWith('2.7') || sectionNumber.startsWith('3.2') || sectionNumber.startsWith('3.3')) {
4695
- for (let i = 0; i < ry.length; i++) {
4696
- let shape = ry[i];
4697
- if (!Array.isArray(shape) || shape.length === 0) continue;
4698
-
4699
- let coords = shape
4700
- .filter(p => p && typeof p.x === "number" && typeof p.y === "number")
4701
- .map(p => ({
4702
- x: p.x * scaleX, // now accurate
4703
- y: p.y * scaleY
4704
- }));
4705
-
4706
- shapeData.push({
4707
- shapeIndex: i + 1,
4708
- coordinates: coords
4709
- });
4710
-
4711
- ry.forEach(shape => {
4712
- if (shape.length > 1) {
4713
- const first = shape[0];
4714
- const last = shape[shape.length - 1];
4715
-
4716
- // Draw line between last and first point
4717
- ctx.beginPath();
4718
- ctx.moveTo(last.x, last.y);
4719
- ctx.lineTo(first.x, first.y);
4720
- ctx.strokeStyle = "red"; // you can change color
4721
- ctx.lineWidth = 2; // and thickness
4722
- ctx.stroke();
4723
- ctx.closePath();
4724
- }
4725
- });
4726
- }
4727
-
4728
- console.log("Final ScaleX:", scaleX, "ScaleY:", scaleY);
4729
- console.log("Scaled coordinates:", shapeData);
4730
  }
4731
- });
4732
- })
4733
- .error(function () {
4734
- PopupElement.textContent = 'Levels are not supported in this Section.';
4735
- ShowPopUp();
4736
- document.getElementById('levelcheckbox').checked = false;
4737
- });
4738
- }
4739
- }
4740
- else{
4741
- PopupElement.textContent='Levels are not supported in this Section. ';
4742
- ShowPopUp();
4743
- document.getElementById('levelcheckbox').checked=false;
4744
- }
4745
- })
4746
  //___________________________________________________________________________________________________________
4747
  function getSecondData(){
4748
  document.getElementById('all').style.display='block';
@@ -5609,7 +5610,7 @@ function callrefreshAPI(){
5609
 
5610
  //before all of this , u need to crrate a popup in html , give the div an id
5611
  let pdfname2_7 = document.querySelector('input[name="measureCheckbox"]').value;
5612
-
5613
  let LegendForm = new FormData();
5614
  LegendForm.append("nameofPDF", pdfname2_7);
5615
  LegendForm.append("groupedValues", JSON.stringify(groupedValues));
@@ -5624,6 +5625,7 @@ function callrefreshAPI(){
5624
  processData: false,
5625
  contentType: false,
5626
  success: function(response) {
 
5627
  console.log("Response:", response);
5628
  ColorsCheckPopup = document.getElementById("LegendPopUp");
5629
  LegendContent=document.getElementById("modalLegend");
 
3314
  {
3315
  var Thickness= document.getElementById("text002extra").value
3316
  answers.push(tomeasureproj, 0,[], ratio1, ratio2,pdfpath,groupedValues,checkedItems,Thickness,shapeData,ratio3); //location of shape
3317
+ formData.append('file',dxffile)
3318
  }
3319
  formData.append('answers',JSON.stringify(answers))
3320
  }
 
4603
  /*Set canvas code to be visible on the new window with the pdftoimg as the background*/
4604
 
4605
  var levelsin = document.getElementById('levelcheckbox');
4606
+ var canvaswindow = document.getElementById('canvaswindow');
4607
+ var undoButtonId = document.getElementById('undoButtonId');
4608
+ var NewShapeButtonId = document.getElementById('NewShapeButtonId');
4609
+ var savecanvas = document.getElementById('savecanvas');
4610
+ var scaleX = 1;
4611
+ var scaleY = 1;
4612
+ var shapeData = []; // Clear this on start
4613
+ var popup = null;
4614
+
4615
+ levelsin.addEventListener('click', function() {
4616
+ if (sectionNumber.startsWith('1.0') || sectionNumber.startsWith('2.7') || sectionNumber.startsWith('3.2') || sectionNumber.startsWith('3.3')) {
4617
+
4618
+ if (this.checked) {
4619
+ // ISSUE 2 FIX: Reset drawing data arrays so you start fresh
4620
+ shapeData = [];
4621
+ if (typeof ry !== 'undefined') ry = [[]]; // Reset your coordinate history array
4622
+
4623
+ document.getElementById("all").style.display = "block";
4624
+
4625
+ $.get('/canvaspdftoimgBackground/' + pdfname)
4626
+ .done(function(data) {
4627
+ document.getElementById("all").style.display = "none";
4628
+
4629
+ // 1. Setup Popup
4630
+ // popup = window.open('', '_blank', 'width=1100,height=900');
4631
+ var popup = window.open('');
4632
+ popup.document.write('<html><head><title>ADR Console</title><link rel="stylesheet" href="static/style.css"></head><body><div id="container"></div></body></html>');
4633
+ popup.document.close();
4634
+
4635
+ if (sectionNumber.startsWith('2.7') || sectionNumber.startsWith('3.2') || sectionNumber.startsWith('3.3')) {
4636
+ document.getElementById('colorpickers').setAttribute('hidden', true);
4637
+ document.getElementById('NewShapeButtonId').style.display = 'none';
4638
+ }
4639
 
4640
+ // 2. Move Canvas
4641
+ var container = popup.document.getElementById('container');
4642
+ canvaswindow.removeAttribute('hidden');
4643
+ container.appendChild(canvaswindow);
4644
 
4645
+ // 3. Scaling Logic
4646
+ const pdfWidth = data[2];
4647
+ const pdfHeight = data[1];
4648
+ var canvas = canvaswindow.querySelector('canvas') || canvaswindow.childNodes[1];
4649
+ var ctx = canvas.getContext('2d');
4650
 
4651
+ canvas.width = pdfWidth;
4652
+ canvas.height = pdfHeight;
 
4653
 
4654
+ const displayWidthCSS = 0.5 * screen.width;
4655
+ const displayHeightCSS = pdfHeight * (displayWidthCSS / pdfWidth);
4656
+ canvas.style.width = displayWidthCSS + 'px';
4657
+ canvas.style.height = displayHeightCSS + 'px';
4658
 
4659
+ scaleX = pdfWidth / displayWidthCSS;
4660
+ scaleY = pdfHeight / displayHeightCSS;
 
4661
 
4662
+ // Apply coordinate scaling
4663
+ ctx.setTransform(scaleX, 0, 0, scaleY, 0, 0);
4664
 
4665
+ var imgDrawon = new Image();
4666
+ imgDrawon.onload = function() {
4667
+ ctx.drawImage(imgDrawon, 0, 0, displayWidthCSS, displayHeightCSS);
4668
+ };
4669
+ imgDrawon.src = 'data:image/gif;base64,' + data[0];
4670
+
4671
+ // ISSUE 1 FIX: Re-incorporate Undo and Save Logic inside the context
4672
+ undoButtonId.onclick = function() {
4673
+ if (ry.length > 0) {
4674
+ if (ry[ry.length - 1].length > 0) {
4675
+ ry[ry.length - 1].pop();
4676
+ } else {
4677
+ ry.pop();
4678
+ if(ry.length > 0) ry[ry.length - 1].pop();
4679
+ }
4680
+ // Redraw background and shapes
4681
+ ctx.clearRect(0, 0, canvas.width, canvas.height);
4682
+ ctx.drawImage(imgDrawon, 0, 0, displayWidthCSS, displayHeightCSS);
4683
+ if (typeof drawChart === "function") drawChart();
4684
+ }
4685
+ };
4686
 
4687
+ savecanvas.onclick = function() {
4688
+ var image = canvas.toDataURL("image/png");
4689
+ canvasimg = image;
4690
+
4691
+ // Process coordinates with the current scale
4692
+ if (sectionNumber.startsWith('2.7') || sectionNumber.startsWith('3.2') || sectionNumber.startsWith('3.3')) {
4693
+ shapeData = []; // Clear before re-calculating
4694
+ for (let i = 0; i < ry.length; i++) {
4695
+ let shape = ry[i];
4696
+ if (!Array.isArray(shape) || shape.length === 0) continue;
4697
+
4698
+ let coords = shape
4699
+ .filter(p => p && typeof p.x === "number" && typeof p.y === "number")
4700
+ .map(p => ({
4701
+ x: p.x * scaleX,
4702
+ y: p.y * scaleY
4703
+ }));
4704
+
4705
+ shapeData.push({
4706
+ shapeIndex: i + 1,
4707
+ coordinates: coords
4708
+ });
4709
+
4710
+ // Draw the closing red lines
4711
+ if (shape.length > 1) {
4712
+ const first = shape[0];
4713
+ const last = shape[shape.length - 1];
4714
+ ctx.beginPath();
4715
+ ctx.moveTo(last.x, last.y);
4716
+ ctx.lineTo(first.x, first.y);
4717
+ ctx.strokeStyle = "red";
4718
+ ctx.lineWidth = 2;
4719
+ ctx.stroke();
4720
+ ctx.closePath();
4721
+ }
4722
+ }
4723
+ console.log("Scaled coordinates saved:", shapeData);
4724
+ }
4725
+ };
4726
 
4727
+ // 4. Cleanup on close
4728
+ popup.onbeforeunload = function() {
4729
+ canvaswindow.setAttribute('hidden', true);
4730
+ document.body.appendChild(canvaswindow);
4731
+ // levelsin.checked = false;
4732
+ };
4733
 
4734
+ })
4735
+ .fail(function() {
4736
+ document.getElementById("all").style.display = "none";
4737
+ levelsin.checked = false;
4738
+ });
4739
  } else {
4740
+ if (popup && !popup.closed) popup.close();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4741
  }
4742
+ } else {
4743
+ alert('Levels are not supported in this Section.');
4744
+ this.checked = false;
4745
+ }
4746
+ });
 
 
 
 
 
 
 
 
 
 
4747
  //___________________________________________________________________________________________________________
4748
  function getSecondData(){
4749
  document.getElementById('all').style.display='block';
 
5610
 
5611
  //before all of this , u need to crrate a popup in html , give the div an id
5612
  let pdfname2_7 = document.querySelector('input[name="measureCheckbox"]').value;
5613
+ document.getElementById("loading").hidden = false;
5614
  let LegendForm = new FormData();
5615
  LegendForm.append("nameofPDF", pdfname2_7);
5616
  LegendForm.append("groupedValues", JSON.stringify(groupedValues));
 
5625
  processData: false,
5626
  contentType: false,
5627
  success: function(response) {
5628
+ document.getElementById("loading").hidden = true;
5629
  console.log("Response:", response);
5630
  ColorsCheckPopup = document.getElementById("LegendPopUp");
5631
  LegendContent=document.getElementById("modalLegend");