Update app.py
Browse files
app.py
CHANGED
|
@@ -1044,9 +1044,9 @@ def measureproject(result,dataDoc=0,img=0,dxffile=0,pdf_content=0):
|
|
| 1044 |
print("SearchArray = ",SearchArray)
|
| 1045 |
global hatched_areas2_7
|
| 1046 |
if pdf_content:
|
| 1047 |
-
doc,outputimg, SimilarAreaDictionary ,spreadsheetId, spreadsheet_url , namepathArr , list1,hatched_areas,bax_pretty_xml,column_xml=Code_2_7.mainFunctionDrawImgPdf(dataDoc,temp_filename,result[4],SearchArray,CorrectionRatio,
|
| 1048 |
else:
|
| 1049 |
-
doc,outputimg, SimilarAreaDictionary ,spreadsheetId, spreadsheet_url , namepathArr , list1,hatched_areas,bax_pretty_xml,column_xml=Code_2_7.mainFunctionDrawImgPdf(dataDoc,temp_filename,result[4],SearchArray,CorrectionRatio,
|
| 1050 |
# global colorsused
|
| 1051 |
hatched_areas2_7=hatched_areas
|
| 1052 |
colorsused=list(SimilarAreaDictionary['Color'])
|
|
@@ -1182,15 +1182,23 @@ def measureproject(result,dataDoc=0,img=0,dxffile=0,pdf_content=0):
|
|
| 1182 |
#_________________________________________________________________________________________________________________________
|
| 1183 |
#_________________________________________________________________________________________________________________________
|
| 1184 |
######################################################### HELPER FUNCTIONS: MARTHE/OMAR #################################################################################################################################
|
| 1185 |
-
|
|
|
|
|
|
|
| 1186 |
try:
|
| 1187 |
-
|
| 1188 |
-
|
| 1189 |
-
|
|
|
|
| 1190 |
data = res.content
|
| 1191 |
-
doc = fitz.open("pdf",data)
|
| 1192 |
-
page=doc[0]
|
| 1193 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1194 |
if not isinstance(shape, dict):
|
| 1195 |
continue
|
| 1196 |
|
|
@@ -1203,19 +1211,38 @@ def drawonpdf(nameofpdf,coords):
|
|
| 1203 |
|
| 1204 |
# Convert to fitz.Point objects and apply derotation
|
| 1205 |
points = [fitz.Point(x, y) * page.derotation_matrix for x, y in vertices]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1206 |
|
| 1207 |
# --- 🟢 Use polygon annotation ---
|
| 1208 |
if len(points) > 2:
|
| 1209 |
annot = page.add_polygon_annot(points)
|
| 1210 |
else:
|
| 1211 |
annot = page.add_polyline_annot(points)
|
| 1212 |
-
|
| 1213 |
# Style annotation
|
| 1214 |
annot.set_colors(stroke=(1, 0, 0)) # red border
|
| 1215 |
annot.set_border(width=1)
|
| 1216 |
annot.update()
|
|
|
|
| 1217 |
# doc.save("output.pdf")
|
| 1218 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1219 |
except (ConnectionError, TimeoutError) as e:
|
| 1220 |
# Use app context when logging
|
| 1221 |
from flask import current_app
|
|
@@ -1229,8 +1256,8 @@ def drawonpdf(nameofpdf,coords):
|
|
| 1229 |
error_details = traceback.format_exc()
|
| 1230 |
error_msg = log_error(error_details, issue_type="backend")
|
| 1231 |
return jsonify({"error": error_msg}), 500
|
| 1232 |
-
|
| 1233 |
|
|
|
|
| 1234 |
######################################################### GUI: CANVAS #################################################################################################################################
|
| 1235 |
@app.route("/canvaspdftoimgBackground/<jsdata>",methods=["GET", "POST"])
|
| 1236 |
def pdftoimgCanvas(jsdata):
|
|
|
|
| 1044 |
print("SearchArray = ",SearchArray)
|
| 1045 |
global hatched_areas2_7
|
| 1046 |
if pdf_content:
|
| 1047 |
+
doc,outputimg, SimilarAreaDictionary ,spreadsheetId, spreadsheet_url , namepathArr , list1,hatched_areas,bax_pretty_xml,column_xml=Code_2_7.mainFunctionDrawImgPdf(dataDoc,temp_filename,result[4],SearchArray,CorrectionRatio,points_Of_drawing_Canvas,Thickness, pdfpath,result[0],pdf_content)
|
| 1048 |
else:
|
| 1049 |
+
doc,outputimg, SimilarAreaDictionary ,spreadsheetId, spreadsheet_url , namepathArr , list1,hatched_areas,bax_pretty_xml,column_xml=Code_2_7.mainFunctionDrawImgPdf(dataDoc,temp_filename,result[4],SearchArray,CorrectionRatio,points_Of_drawing_Canvas,Thickness, pdfpath,result[0])
|
| 1050 |
# global colorsused
|
| 1051 |
hatched_areas2_7=hatched_areas
|
| 1052 |
colorsused=list(SimilarAreaDictionary['Color'])
|
|
|
|
| 1182 |
#_________________________________________________________________________________________________________________________
|
| 1183 |
#_________________________________________________________________________________________________________________________
|
| 1184 |
######################################################### HELPER FUNCTIONS: MARTHE/OMAR #################################################################################################################################
|
| 1185 |
+
|
| 1186 |
+
|
| 1187 |
+
def drawonpdf(nameofpdf, coords):
|
| 1188 |
try:
|
| 1189 |
+
print()
|
| 1190 |
+
pdfpath, pdflink = tsadropboxretrieval.getPathtoPDF_File(nameofPDF=nameofpdf)
|
| 1191 |
+
dbxTeam = tsadropboxretrieval.ADR_Access_DropboxTeam('user')
|
| 1192 |
+
md, res = dbxTeam.files_download(path=pdfpath)
|
| 1193 |
data = res.content
|
| 1194 |
+
doc = fitz.open("pdf", data)
|
| 1195 |
+
page = doc[0]
|
| 1196 |
+
|
| 1197 |
+
# 1. Initialize a list to hold all your shape dictionaries
|
| 1198 |
+
canvas_points_list = []
|
| 1199 |
+
|
| 1200 |
+
# Use enumerate to get a 1-based shape index
|
| 1201 |
+
for index, shape in enumerate(coords, start=1):
|
| 1202 |
if not isinstance(shape, dict):
|
| 1203 |
continue
|
| 1204 |
|
|
|
|
| 1211 |
|
| 1212 |
# Convert to fitz.Point objects and apply derotation
|
| 1213 |
points = [fitz.Point(x, y) * page.derotation_matrix for x, y in vertices]
|
| 1214 |
+
|
| 1215 |
+
# --- Convert to your desired format ---
|
| 1216 |
+
# 1. Create the list of {'x': ..., 'y': ...} dictionaries
|
| 1217 |
+
coordinates_list = [{"x": p.x, "y": p.y} for p in points]
|
| 1218 |
+
|
| 1219 |
+
# 2. Create the final dictionary for this shape
|
| 1220 |
+
shape_data = {
|
| 1221 |
+
'shapeIndex': index,
|
| 1222 |
+
'coordinates': coordinates_list
|
| 1223 |
+
}
|
| 1224 |
+
|
| 1225 |
+
# 3. Append this shape's dictionary to the main list
|
| 1226 |
+
canvas_points_list.append(shape_data)
|
| 1227 |
+
# --- End of conversion ---
|
| 1228 |
|
| 1229 |
# --- 🟢 Use polygon annotation ---
|
| 1230 |
if len(points) > 2:
|
| 1231 |
annot = page.add_polygon_annot(points)
|
| 1232 |
else:
|
| 1233 |
annot = page.add_polyline_annot(points)
|
| 1234 |
+
|
| 1235 |
# Style annotation
|
| 1236 |
annot.set_colors(stroke=(1, 0, 0)) # red border
|
| 1237 |
annot.set_border(width=1)
|
| 1238 |
annot.update()
|
| 1239 |
+
|
| 1240 |
# doc.save("output.pdf")
|
| 1241 |
+
|
| 1242 |
+
# # 4. Return the list of dictionaries
|
| 1243 |
+
# print('pointsomar,',canvas_points_list)
|
| 1244 |
+
return canvas_points_list
|
| 1245 |
+
|
| 1246 |
except (ConnectionError, TimeoutError) as e:
|
| 1247 |
# Use app context when logging
|
| 1248 |
from flask import current_app
|
|
|
|
| 1256 |
error_details = traceback.format_exc()
|
| 1257 |
error_msg = log_error(error_details, issue_type="backend")
|
| 1258 |
return jsonify({"error": error_msg}), 500
|
|
|
|
| 1259 |
|
| 1260 |
+
|
| 1261 |
######################################################### GUI: CANVAS #################################################################################################################################
|
| 1262 |
@app.route("/canvaspdftoimgBackground/<jsdata>",methods=["GET", "POST"])
|
| 1263 |
def pdftoimgCanvas(jsdata):
|