Spaces:
Sleeping
Sleeping
Update dxf__omar3_2.py
Browse files- dxf__omar3_2.py +75 -8
dxf__omar3_2.py
CHANGED
|
@@ -420,7 +420,7 @@ def Create_DF(dxfpath,datadoc):
|
|
| 420 |
SimilarAreaDictionary= pd.DataFrame(columns=['Guess','Color','Occurences','Area','Total Area','Perimeter','Total Perimeter','Length','Total Length','Texts','Comments'])
|
| 421 |
|
| 422 |
colorRanges2=generate_color_array(300)
|
| 423 |
-
colorRanges=[[255,0,0],[0,0,255],[0,255,255],[0,64,0],[255,204,0],[255,128,64],[255,0,128],[255,128,192],[128,128,255],[128,64,0],[0,255,0],[255,128,255],[128,0,255],[0,128,192],[128,0,128],[128,0,0],[0,128,255],[149,1,70],[255,182,128],[222,48,71],[240,0,112],[255,0,255],[192,46,65],[0,0,128],[0,128,64],[255,255,0],[
|
| 424 |
colorUsed=[]
|
| 425 |
TotalArea=0
|
| 426 |
TotalPerimeter=0
|
|
@@ -443,8 +443,8 @@ def Create_DF(dxfpath,datadoc):
|
|
| 443 |
if any(combined_condition):
|
| 444 |
index = np.where(combined_condition)[0][0]
|
| 445 |
SimilarAreaDictionary.at[index, 'Occurences'] += 1
|
| 446 |
-
SimilarAreaDictionary.at[index, 'Total Area'] = SimilarAreaDictionary.at[index, 'Area']
|
| 447 |
-
SimilarAreaDictionary.at[index, 'Total Perimeter'] = SimilarAreaDictionary.at[index, 'Perimeter']
|
| 448 |
else:
|
| 449 |
TotalArea=area
|
| 450 |
TotalPerimeter=perimeter
|
|
@@ -529,7 +529,7 @@ def mainFunctionDrawImgPdf(datadoc,dxfpath, dxfratio,pdfpath,pdfname):
|
|
| 529 |
annot11.set_border(width=0.2)
|
| 530 |
annot11.set_colors(stroke=(int(NewColors[0])/255,int(NewColors[1])/255,int(NewColors[2])/255), fill= (int(NewColors[0])/255,int(NewColors[1])/255,int(NewColors[2])/255) )
|
| 531 |
annot11.set_info(content='Area='+str(polygon[1])+' m^2',subject='ADR Team')
|
| 532 |
-
annot11.set_opacity(0.
|
| 533 |
# annot.set_line_ends(fitz.PDF_ANNOT_LE_DIAMOND, fitz.PDF_ANNOT_LE_CIRCLE)
|
| 534 |
annot11.update()
|
| 535 |
|
|
@@ -556,9 +556,76 @@ def mainFunctionDrawImgPdf(datadoc,dxfpath, dxfratio,pdfpath,pdfname):
|
|
| 556 |
# data = res.content
|
| 557 |
# doc=fitz.open("pdf", data)
|
| 558 |
# list1=pd.DataFrame(columns=['content', 'creationDate', 'id', 'modDate', 'name', 'subject', 'title'])
|
| 559 |
-
list1=pd.DataFrame(columns=['content', 'id', 'subject'])
|
| 560 |
-
|
| 561 |
-
|
| 562 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 563 |
return doc,image_new1, SimilarAreaDictionary ,spreadsheetId, spreadsheet_url , namepathArr , list1,hatched_areas
|
| 564 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 420 |
SimilarAreaDictionary= pd.DataFrame(columns=['Guess','Color','Occurences','Area','Total Area','Perimeter','Total Perimeter','Length','Total Length','Texts','Comments'])
|
| 421 |
|
| 422 |
colorRanges2=generate_color_array(300)
|
| 423 |
+
colorRanges = [[255, 0, 0], [0, 0, 255], [0, 255, 255], [0, 64, 0], [255, 204, 0], [255, 128, 64], [255, 0, 128], [255, 128, 192], [128, 128, 255], [128, 64, 0],[0, 255, 0],[0, 200, 0],[255, 128, 255], [128, 0, 255], [0, 128, 192], [128, 0, 128],[128, 0, 0], [0, 128, 255], [149, 1, 70], [255, 182, 128], [222, 48, 71], [240, 0, 112], [255, 0, 255], [192, 46, 65], [0, 0, 128],[0, 128, 64],[255, 255, 0], [128, 0, 80], [255, 255, 128], [90, 255, 140],[255, 200, 20],[91, 16, 51], [90, 105, 138], [114, 10, 138], [36, 82, 78], [225, 105, 190], [108, 150, 170], [11, 35, 75], [42, 176, 170], [255, 176, 170], [209, 151, 15],[81, 27, 85], [226, 106, 122], [67, 119, 149], [159, 179, 140], [159, 179, 30],[255, 85, 198], [255, 27, 85], [188, 158, 8],[140, 188, 120], [59, 61, 52], [65, 81, 21], [212, 255, 174], [15, 164, 90],[41, 217, 245], [213, 23, 182], [11, 85, 169], [78, 153, 239], [0, 66, 141],[64, 98, 232], [140, 112, 255], [57, 33, 154], [194, 117, 252], [116, 92, 135], [74, 43, 98], [188, 13, 123], [129, 58, 91], [255, 128, 100], [171, 122, 145], [255, 98, 98], [222, 48, 77]]
|
| 424 |
colorUsed=[]
|
| 425 |
TotalArea=0
|
| 426 |
TotalPerimeter=0
|
|
|
|
| 443 |
if any(combined_condition):
|
| 444 |
index = np.where(combined_condition)[0][0]
|
| 445 |
SimilarAreaDictionary.at[index, 'Occurences'] += 1
|
| 446 |
+
SimilarAreaDictionary.at[index, 'Total Area'] = SimilarAreaDictionary.at[index, 'Total Area'] + area
|
| 447 |
+
SimilarAreaDictionary.at[index, 'Total Perimeter'] = SimilarAreaDictionary.at[index, 'Total Perimeter'] + perimeter
|
| 448 |
else:
|
| 449 |
TotalArea=area
|
| 450 |
TotalPerimeter=perimeter
|
|
|
|
| 529 |
annot11.set_border(width=0.2)
|
| 530 |
annot11.set_colors(stroke=(int(NewColors[0])/255,int(NewColors[1])/255,int(NewColors[2])/255), fill= (int(NewColors[0])/255,int(NewColors[1])/255,int(NewColors[2])/255) )
|
| 531 |
annot11.set_info(content='Area='+str(polygon[1])+' m^2',subject='ADR Team')
|
| 532 |
+
annot11.set_opacity(0.9)
|
| 533 |
# annot.set_line_ends(fitz.PDF_ANNOT_LE_DIAMOND, fitz.PDF_ANNOT_LE_CIRCLE)
|
| 534 |
annot11.update()
|
| 535 |
|
|
|
|
| 556 |
# data = res.content
|
| 557 |
# doc=fitz.open("pdf", data)
|
| 558 |
# list1=pd.DataFrame(columns=['content', 'creationDate', 'id', 'modDate', 'name', 'subject', 'title'])
|
| 559 |
+
list1=pd.DataFrame(columns=['content', 'id', 'subject','color'])
|
| 560 |
+
|
| 561 |
+
for page in doc:
|
| 562 |
+
# Iterate through annotations on the page
|
| 563 |
+
for annot in page.annots():
|
| 564 |
+
# Get the color of the annotation
|
| 565 |
+
annot_color = annot.colors
|
| 566 |
+
if annot_color is not None:
|
| 567 |
+
# annot_color is a dictionary with 'stroke' and 'fill' keys
|
| 568 |
+
stroke_color = annot_color.get('stroke') # Border color
|
| 569 |
+
fill_color = annot_color.get('fill') # Fill color
|
| 570 |
+
if fill_color:
|
| 571 |
+
v='fill'
|
| 572 |
+
print('fill')
|
| 573 |
+
if stroke_color:
|
| 574 |
+
v='stroke'
|
| 575 |
+
x,y,z=int(annot_color.get(v)[0]*255),int(annot_color.get(v)[1]*255),int(annot_color.get(v)[2]*255)
|
| 576 |
+
list1.loc[len(list1)] =[annot.info['content'],annot.info['id'],annot.info['subject'],[x,y,z]]
|
| 577 |
return doc,image_new1, SimilarAreaDictionary ,spreadsheetId, spreadsheet_url , namepathArr , list1,hatched_areas
|
| 578 |
|
| 579 |
+
|
| 580 |
+
def deletemarkupsDXF(list1, dbPath, path):
|
| 581 |
+
'''list1 : original markup pdf
|
| 582 |
+
list2 : deleted markup pdf
|
| 583 |
+
deletedrows : deleted markups - difference between both dfs
|
| 584 |
+
'''
|
| 585 |
+
|
| 586 |
+
myDict1 = eval(list1)
|
| 587 |
+
list1 = pd.DataFrame(myDict1)
|
| 588 |
+
|
| 589 |
+
dbxTeam = tsadropboxretrieval.ADR_Access_DropboxTeam('user')
|
| 590 |
+
md, res = dbxTeam.files_download(path=dbPath + path)
|
| 591 |
+
data = res.content
|
| 592 |
+
doc = fitz.open("pdf", data)
|
| 593 |
+
|
| 594 |
+
# Prepare a DataFrame for the annotations in the new PDF
|
| 595 |
+
list2 = pd.DataFrame(columns=['content', 'id', 'subject', 'color'])
|
| 596 |
+
|
| 597 |
+
for page in doc:
|
| 598 |
+
# Iterate through annotations on the page
|
| 599 |
+
for annot in page.annots():
|
| 600 |
+
# Get the color of the annotation
|
| 601 |
+
annot_color = annot.colors
|
| 602 |
+
if annot_color is not None:
|
| 603 |
+
# Check for fill or stroke color
|
| 604 |
+
stroke_color = annot_color.get('stroke')
|
| 605 |
+
fill_color = annot_color.get('fill')
|
| 606 |
+
|
| 607 |
+
v = 'stroke' if stroke_color else 'fill'
|
| 608 |
+
color = annot_color.get(v)
|
| 609 |
+
if color:
|
| 610 |
+
# Convert color to tuple and multiply by 255 to get RGB values
|
| 611 |
+
color_tuple = (int(color[0] * 255), int(color[1] * 255), int(color[2] * 255))
|
| 612 |
+
# Append annotation data to list2
|
| 613 |
+
list2.loc[len(list2)] = [annot.info['content'], annot.info['id'], annot.info['subject'], color_tuple]
|
| 614 |
+
|
| 615 |
+
# Ensure that colors are stored as tuples (which are hashable)
|
| 616 |
+
list1['color'] = list1['color'].apply(lambda x: tuple(x) if isinstance(x, list) else x)
|
| 617 |
+
|
| 618 |
+
# Find the deleted rows by checking the difference between original and current annotations
|
| 619 |
+
deletedrows = pd.concat([list1, list2]).drop_duplicates(keep=False)
|
| 620 |
+
|
| 621 |
+
print(deletedrows, len(deletedrows))
|
| 622 |
+
flag = 0
|
| 623 |
+
if len(deletedrows) != 0:
|
| 624 |
+
flag = 1
|
| 625 |
+
deletedrows = deletedrows[['content', 'id', 'subject', 'color']]
|
| 626 |
+
# Drop rows where 'content' starts with 'Scale'
|
| 627 |
+
deletedrows = deletedrows.drop(deletedrows.index[deletedrows['content'].str.startswith('Scale')])
|
| 628 |
+
else:
|
| 629 |
+
flag = 0
|
| 630 |
+
|
| 631 |
+
return deletedrows
|