Spaces:
Sleeping
Sleeping
Update deploying_3_3.py
Browse files- deploying_3_3.py +91 -28
deploying_3_3.py
CHANGED
|
@@ -545,6 +545,29 @@ def get_hatch_color(entity):
|
|
| 545 |
|
| 546 |
"""### Hatched areas"""
|
| 547 |
def get_hatched_areas(datadoc,filename,FinalRatio,rotationangle):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 548 |
doc = ezdxf.readfile(filename)
|
| 549 |
doc.header['$MEASUREMENT'] = 1
|
| 550 |
msp = doc.modelspace()
|
|
@@ -552,6 +575,35 @@ def get_hatched_areas(datadoc,filename,FinalRatio,rotationangle):
|
|
| 552 |
hatched_areas = []
|
| 553 |
threshold=0.01
|
| 554 |
unique_shapes = []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 555 |
for entity in msp:
|
| 556 |
if entity.dxftype() == 'HATCH':
|
| 557 |
# print(f"Processing HATCH entity: {entity}")
|
|
@@ -573,6 +625,17 @@ def get_hatched_areas(datadoc,filename,FinalRatio,rotationangle):
|
|
| 573 |
perimeter = round(poly.length, 3)
|
| 574 |
normalized_vertices = normalize_vertices(vertices)
|
| 575 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 576 |
duplicate_found = False
|
| 577 |
for existing_vertices, existing_area in unique_shapes:
|
| 578 |
if normalized_vertices == existing_vertices and areas_are_similar(area1, existing_area):
|
|
@@ -580,7 +643,7 @@ def get_hatched_areas(datadoc,filename,FinalRatio,rotationangle):
|
|
| 580 |
break
|
| 581 |
|
| 582 |
if not duplicate_found:
|
| 583 |
-
rgb_color = get_hatch_color(entity) # Assuming this function exists
|
| 584 |
unique_shapes.append((normalized_vertices, area1))
|
| 585 |
hatched_areas.append([vertices, area1, perimeter, rgb_color])
|
| 586 |
|
|
@@ -604,6 +667,16 @@ def get_hatched_areas(datadoc,filename,FinalRatio,rotationangle):
|
|
| 604 |
|
| 605 |
normalized_vertices = normalize_vertices(vert)
|
| 606 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 607 |
duplicate_found = False
|
| 608 |
for existing_vertices, existing_area in unique_shapes:
|
| 609 |
if normalized_vertices == existing_vertices and areas_are_similar(area1, existing_area):
|
|
@@ -611,7 +684,7 @@ def get_hatched_areas(datadoc,filename,FinalRatio,rotationangle):
|
|
| 611 |
break
|
| 612 |
|
| 613 |
if not duplicate_found:
|
| 614 |
-
rgb_color = get_hatch_color(entity) # Assuming this function exists
|
| 615 |
unique_shapes.append((normalized_vertices, area1))
|
| 616 |
hatched_areas.append([vert, area1, perimeter, rgb_color])
|
| 617 |
|
|
@@ -997,34 +1070,13 @@ def mainFunctionDrawImgPdf(datadoc,dxfpath, dxfratio,pdfpath=0,pdfname=0):
|
|
| 997 |
ColorCheck.append(NewColors)
|
| 998 |
|
| 999 |
|
| 1000 |
-
|
| 1001 |
-
|
| 1002 |
-
|
| 1003 |
-
|
| 1004 |
-
|
| 1005 |
-
if flagcolor == 1:
|
| 1006 |
-
SimilarAreaDictionary.at[existing_index, 'Total Area'] = SimilarAreaDictionary.at[existing_index, 'Total Area'] + SimilarAreaDictionary.at[index, 'Area']
|
| 1007 |
-
SimilarAreaDictionary.at[existing_index, 'Total Perimeter'] = SimilarAreaDictionary.at[existing_index, 'Total Perimeter'] + SimilarAreaDictionary.at[index, 'Perimeter']
|
| 1008 |
-
SimilarAreaDictionary.at[existing_index, 'Occurences'] = SimilarAreaDictionary.at[existing_index, 'Occurences'] + 1
|
| 1009 |
-
|
| 1010 |
-
|
| 1011 |
-
elif flagcolor == 2:
|
| 1012 |
-
SimilarAreaDictionary.at[existing_index, 'Total Area'] = SimilarAreaDictionary.at[existing_index, 'Total Area'] + SimilarAreaDictionary.at[i, 'Area']
|
| 1013 |
-
SimilarAreaDictionary.at[existing_index, 'Total Perimeter'] = SimilarAreaDictionary.at[existing_index, 'Total Perimeter'] + SimilarAreaDictionary.at[i, 'Perimeter']
|
| 1014 |
-
SimilarAreaDictionary.at[existing_index, 'Occurences'] = SimilarAreaDictionary.at[existing_index, 'Occurences'] + 1
|
| 1015 |
-
|
| 1016 |
-
|
| 1017 |
-
|
| 1018 |
-
else:
|
| 1019 |
-
if flagcolor == 1:
|
| 1020 |
-
SimilarAreaDictionary.at[index, 'Color'] = NewColors
|
| 1021 |
-
# print(f"Updated Color at index {index} with {NewColors}.")
|
| 1022 |
-
elif flagcolor == 2:
|
| 1023 |
SimilarAreaDictionary.at[i, 'Color'] = NewColors
|
| 1024 |
-
# print(f"Updated Color at index {i} with {NewColors}.")
|
| 1025 |
-
|
| 1026 |
|
| 1027 |
-
|
| 1028 |
cv2.drawContours(imgg, [np.array(cntPoints)], -1, ([NewColors[2],NewColors[1],NewColors[0]]), thickness=-1)
|
| 1029 |
|
| 1030 |
annot11 = page2.add_polygon_annot( points=shapee) # 'Polygon'
|
|
@@ -1061,6 +1113,17 @@ def mainFunctionDrawImgPdf(datadoc,dxfpath, dxfratio,pdfpath=0,pdfname=0):
|
|
| 1061 |
|
| 1062 |
# Reset the index to update row numbering
|
| 1063 |
SimilarAreaDictionary.reset_index(drop=True, inplace=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1064 |
|
| 1065 |
gc,spreadsheet_service,spreadsheetId, spreadsheet_url , namepathArr=google_sheet_Legend.legendGoogleSheets(SimilarAreaDictionary , pdfname,pdfpath)
|
| 1066 |
# dbxTeam=tsadropboxretrieval.ADR_Access_DropboxTeam('user')
|
|
|
|
| 545 |
|
| 546 |
"""### Hatched areas"""
|
| 547 |
def get_hatched_areas(datadoc,filename,FinalRatio,rotationangle):
|
| 548 |
+
|
| 549 |
+
text_with_positions = []
|
| 550 |
+
text_color_mapping = {}
|
| 551 |
+
color_palette = [
|
| 552 |
+
(255, 0, 0), (0, 0, 255), (0, 255, 255), (0, 64, 0), (255, 204, 0),
|
| 553 |
+
(255, 128, 64), (255, 0, 128), (255, 128, 192), (128, 128, 255),
|
| 554 |
+
(128, 64, 0), (0, 255, 0), (0, 200, 0), (255, 128, 255), (128, 0, 255),
|
| 555 |
+
(0, 128, 192), (128, 0, 128), (128, 0, 0), (0, 128, 255), (149, 1, 70),
|
| 556 |
+
(255, 182, 128), (222, 48, 71), (240, 0, 112), (255, 0, 255),
|
| 557 |
+
(192, 46, 65), (0, 0, 128), (0, 128, 64), (255, 255, 0), (128, 0, 80),
|
| 558 |
+
(255, 255, 128), (90, 255, 140), (255, 200, 20), (91, 16, 51),
|
| 559 |
+
(90, 105, 138), (114, 10, 138), (36, 82, 78), (225, 105, 190),
|
| 560 |
+
(108, 150, 170), (11, 35, 75), (42, 176, 170), (255, 176, 170),
|
| 561 |
+
(209, 151, 15), (81, 27, 85), (226, 106, 122), (67, 119, 149),
|
| 562 |
+
(159, 179, 140), (159, 179, 30), (255, 85, 198), (255, 27, 85),
|
| 563 |
+
(188, 158, 8), (140, 188, 120), (59, 61, 52), (65, 81, 21),
|
| 564 |
+
(212, 255, 174), (15, 164, 90), (41, 217, 245), (213, 23, 182),
|
| 565 |
+
(11, 85, 169), (78, 153, 239), (0, 66, 141), (64, 98, 232),
|
| 566 |
+
(140, 112, 255), (57, 33, 154), (194, 117, 252), (116, 92, 135),
|
| 567 |
+
(74, 43, 98), (188, 13, 123), (129, 58, 91), (255, 128, 100),
|
| 568 |
+
(171, 122, 145), (255, 98, 98), (222, 48, 77)
|
| 569 |
+
]
|
| 570 |
+
|
| 571 |
doc = ezdxf.readfile(filename)
|
| 572 |
doc.header['$MEASUREMENT'] = 1
|
| 573 |
msp = doc.modelspace()
|
|
|
|
| 575 |
hatched_areas = []
|
| 576 |
threshold=0.01
|
| 577 |
unique_shapes = []
|
| 578 |
+
|
| 579 |
+
for entity in doc.modelspace().query('TEXT MTEXT'):
|
| 580 |
+
if hasattr(entity, 'text'): # Ensure the entity has text content
|
| 581 |
+
text = entity.text
|
| 582 |
+
if text.startswith('C') and (len(text) > 1 and (text[1].isdigit() or text[1].upper() == 'T' or text[1].upper() == 'L')):
|
| 583 |
+
parts = text.split(' ') # Split into two parts: before and after the first newline
|
| 584 |
+
# print("Parts = ",parts[0])
|
| 585 |
+
main_text = parts[0] # Text before the first newline
|
| 586 |
+
|
| 587 |
+
# Check if the main text starts with 'C' followed by a number or 'T'
|
| 588 |
+
# if pattern.match(main_text):
|
| 589 |
+
position = entity.dxf.insert
|
| 590 |
+
|
| 591 |
+
|
| 592 |
+
# Check if the text already has a color assigned
|
| 593 |
+
if main_text not in text_color_mapping:
|
| 594 |
+
# Assign a new color from the palette
|
| 595 |
+
color_index = len(text_color_mapping) % len(color_palette)
|
| 596 |
+
text_color_mapping[main_text] = color_palette[color_index]
|
| 597 |
+
|
| 598 |
+
# Get the assigned color
|
| 599 |
+
color = text_color_mapping[main_text]
|
| 600 |
+
|
| 601 |
+
# Set the entity's true color
|
| 602 |
+
# entity.dxf.true_color = rgb_to_true_color(color)
|
| 603 |
+
|
| 604 |
+
# Append text, position, and color to the array
|
| 605 |
+
text_with_positions.append([main_text, position, color])
|
| 606 |
+
|
| 607 |
for entity in msp:
|
| 608 |
if entity.dxftype() == 'HATCH':
|
| 609 |
# print(f"Processing HATCH entity: {entity}")
|
|
|
|
| 625 |
perimeter = round(poly.length, 3)
|
| 626 |
normalized_vertices = normalize_vertices(vertices)
|
| 627 |
|
| 628 |
+
rgb_color = get_hatch_color(entity)
|
| 629 |
+
if(rgb_color == (255, 255, 255)):
|
| 630 |
+
if(len(text_with_positions)>0):
|
| 631 |
+
|
| 632 |
+
for text, position, color in text_with_positions:
|
| 633 |
+
text_position = Point(position[0], position[1])
|
| 634 |
+
|
| 635 |
+
if poly.contains(text_position):
|
| 636 |
+
rgb_color = color
|
| 637 |
+
break
|
| 638 |
+
|
| 639 |
duplicate_found = False
|
| 640 |
for existing_vertices, existing_area in unique_shapes:
|
| 641 |
if normalized_vertices == existing_vertices and areas_are_similar(area1, existing_area):
|
|
|
|
| 643 |
break
|
| 644 |
|
| 645 |
if not duplicate_found:
|
| 646 |
+
# rgb_color = get_hatch_color(entity) # Assuming this function exists
|
| 647 |
unique_shapes.append((normalized_vertices, area1))
|
| 648 |
hatched_areas.append([vertices, area1, perimeter, rgb_color])
|
| 649 |
|
|
|
|
| 667 |
|
| 668 |
normalized_vertices = normalize_vertices(vert)
|
| 669 |
|
| 670 |
+
rgb_color = get_hatch_color(entity)
|
| 671 |
+
if(rgb_color == (255, 255, 255)):
|
| 672 |
+
if(len(text_with_positions)>0):
|
| 673 |
+
for text, position, color in text_with_positions:
|
| 674 |
+
text_position = Point(position[0], position[1])
|
| 675 |
+
|
| 676 |
+
if poly.contains(text_position):
|
| 677 |
+
rgb_color = color
|
| 678 |
+
break
|
| 679 |
+
|
| 680 |
duplicate_found = False
|
| 681 |
for existing_vertices, existing_area in unique_shapes:
|
| 682 |
if normalized_vertices == existing_vertices and areas_are_similar(area1, existing_area):
|
|
|
|
| 684 |
break
|
| 685 |
|
| 686 |
if not duplicate_found:
|
| 687 |
+
# rgb_color = get_hatch_color(entity) # Assuming this function exists
|
| 688 |
unique_shapes.append((normalized_vertices, area1))
|
| 689 |
hatched_areas.append([vert, area1, perimeter, rgb_color])
|
| 690 |
|
|
|
|
| 1070 |
ColorCheck.append(NewColors)
|
| 1071 |
|
| 1072 |
|
| 1073 |
+
if flagcolor == 1:
|
| 1074 |
+
SimilarAreaDictionary.at[index, 'Color'] = NewColors
|
| 1075 |
+
# print(f"Updated Color at index {index} with {NewColors}.")
|
| 1076 |
+
elif flagcolor == 2:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1077 |
SimilarAreaDictionary.at[i, 'Color'] = NewColors
|
|
|
|
|
|
|
| 1078 |
|
| 1079 |
+
|
| 1080 |
cv2.drawContours(imgg, [np.array(cntPoints)], -1, ([NewColors[2],NewColors[1],NewColors[0]]), thickness=-1)
|
| 1081 |
|
| 1082 |
annot11 = page2.add_polygon_annot( points=shapee) # 'Polygon'
|
|
|
|
| 1113 |
|
| 1114 |
# Reset the index to update row numbering
|
| 1115 |
SimilarAreaDictionary.reset_index(drop=True, inplace=True)
|
| 1116 |
+
|
| 1117 |
+
grouped_df = SimilarAreaDictionary.groupby('Color').agg({
|
| 1118 |
+
'Occurences': 'sum', # Sum of occurrences for each color
|
| 1119 |
+
'Area':'first',
|
| 1120 |
+
'Total Area': 'sum', # Sum of areas for each color
|
| 1121 |
+
'Perimeter':'first',
|
| 1122 |
+
'Total Perimeter': 'sum', # Sum of perimeters for each color
|
| 1123 |
+
|
| 1124 |
+
}).reset_index()
|
| 1125 |
+
|
| 1126 |
+
SimilarAreaDictionary = grouped_df
|
| 1127 |
|
| 1128 |
gc,spreadsheet_service,spreadsheetId, spreadsheet_url , namepathArr=google_sheet_Legend.legendGoogleSheets(SimilarAreaDictionary , pdfname,pdfpath)
|
| 1129 |
# dbxTeam=tsadropboxretrieval.ADR_Access_DropboxTeam('user')
|