|
@@ -4,7 +4,7 @@ import csv
|
|
import clustering_precomputed_dbscan
|
|
import clustering_precomputed_dbscan
|
|
|
|
|
|
def get_details(result): #search for all details in drawing and store it in list details, first need to append all text elements of one line and then check if regular expression is found in this text element
|
|
def get_details(result): #search for all details in drawing and store it in list details, first need to append all text elements of one line and then check if regular expression is found in this text element
|
|
- reg = r"([A-Z])-\1|([A-Z]\W?[A-Z]?\s?\W\s?\d\d?\s?\s?:\s?\d\d?\s?\W)|(Start drawing)|(All dimensions apply to the finished part including surface\/material treatment)"
|
|
|
|
|
|
+ reg = r"([A-Z])-\1|([A-Z]\W?[A-Z]?\s?\W\s?\d\d?\s?\s?:\s?\d\d?\s?\W)"
|
|
details = []
|
|
details = []
|
|
for element in result:
|
|
for element in result:
|
|
new = []
|
|
new = []
|
|
@@ -15,7 +15,10 @@ def get_details(result): #search for all details in drawing and store it in list
|
|
number = len(details)
|
|
number = len(details)
|
|
return details, number
|
|
return details, number
|
|
|
|
|
|
-def get_borders(details):
|
|
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+def get_borders(details, tables):
|
|
sections = []
|
|
sections = []
|
|
#print(coords)
|
|
#print(coords)
|
|
for first in details:
|
|
for first in details:
|
|
@@ -49,17 +52,19 @@ def get_borders(details):
|
|
#print(first, second)
|
|
#print(first, second)
|
|
distance_xmin = abs(secondx_min - firstx_max)/2
|
|
distance_xmin = abs(secondx_min - firstx_max)/2
|
|
x_max = firstx_max + distance_xmin
|
|
x_max = firstx_max + distance_xmin
|
|
- if firsty_min > secondy_max and abs(firstx_min-secondx_min) < 40 and first != second: ####check above
|
|
|
|
|
|
+ if firsty_min > secondy_max and abs(firstx_min-secondx_min) < 80 and first != second: ####check above
|
|
if abs(firsty_min - secondy_max)/2 < distance_ymin:
|
|
if abs(firsty_min - secondy_max)/2 < distance_ymin:
|
|
#print(first, second)
|
|
#print(first, second)
|
|
distance_ymin = abs(firsty_min - secondy_max)/2
|
|
distance_ymin = abs(firsty_min - secondy_max)/2
|
|
y_min = firsty_min
|
|
y_min = firsty_min
|
|
- if firsty_max < secondy_min and abs(firstx_min-secondx_min) < 40 and first != second: ####check below
|
|
|
|
|
|
+ if firsty_max < secondy_min and abs(firstx_min-secondx_min) < 80 and first != second: ####check below
|
|
if abs(firsty_max - secondy_min)/2 < distance_ymax:
|
|
if abs(firsty_max - secondy_min)/2 < distance_ymax:
|
|
#print(first, second)
|
|
#print(first, second)
|
|
distance_ymax = abs(firsty_max - secondy_min)/2
|
|
distance_ymax = abs(firsty_max - secondy_min)/2
|
|
y_max = secondy_min
|
|
y_max = secondy_min
|
|
|
|
|
|
|
|
+
|
|
|
|
+
|
|
if y_min == -1:
|
|
if y_min == -1:
|
|
y_min = firsty_min
|
|
y_min = firsty_min
|
|
if x_min == -1:
|
|
if x_min == -1:
|
|
@@ -68,20 +73,39 @@ def get_borders(details):
|
|
x_max = firstx_max + distance_xmax
|
|
x_max = firstx_max + distance_xmax
|
|
if y_max == -1:
|
|
if y_max == -1:
|
|
y_max = 1000000000
|
|
y_max = 1000000000
|
|
|
|
+
|
|
|
|
+ ##check if it intersects with tables
|
|
|
|
+ for table in tables:
|
|
|
|
+ #print(table)
|
|
|
|
+ table_xmin = table[0]
|
|
|
|
+ if "Start drawing" in table[4]:
|
|
|
|
+ table_xmax = 100000000
|
|
|
|
+ else:
|
|
|
|
+ table_xmax = table[2]
|
|
|
|
+ table_ymin = table[1]
|
|
|
|
+ #table_ymax = table[3]
|
|
|
|
+ if y_max > table_ymin:
|
|
|
|
+ if firstx_min > table_xmin and firstx_min < table_xmax:
|
|
|
|
+ #print("blub",first,table, table_xmax)
|
|
|
|
+ y_max = table_ymin
|
|
|
|
+ elif x_max > table_xmin and x_max < table_xmax:
|
|
|
|
+ #print(first,table)
|
|
|
|
+ y_max = table_ymin
|
|
|
|
+
|
|
sections.append((first,x_min, y_min,x_max,y_max))
|
|
sections.append((first,x_min, y_min,x_max,y_max))
|
|
|
|
|
|
- #for section in sections:
|
|
|
|
- # print(section)
|
|
|
|
|
|
+ """for section in sections:
|
|
|
|
+ print(section)"""
|
|
return sections
|
|
return sections
|
|
|
|
|
|
def intersects(detail, rectangle): #using the separating axis theorem
|
|
def intersects(detail, rectangle): #using the separating axis theorem
|
|
#print(detail)
|
|
#print(detail)
|
|
|
|
|
|
|
|
|
|
- rect1_bottom_left_x = detail[1][0]
|
|
|
|
- rect1_top_right_x = detail[1][2]
|
|
|
|
- rect1_bottom_left_y = detail[1][3]
|
|
|
|
- rect1_top_right_y = detail[1][1]
|
|
|
|
|
|
+ rect1_bottom_left_x = float(detail[1][0])
|
|
|
|
+ rect1_top_right_x = float(detail[1][2])
|
|
|
|
+ rect1_bottom_left_y = float(detail[1][3])
|
|
|
|
+ rect1_top_right_y = float(detail[1][1])
|
|
|
|
|
|
rect2_bottom_left_x = float(rectangle[0])
|
|
rect2_bottom_left_x = float(rectangle[0])
|
|
rect2_top_right_x = float(rectangle[2])
|
|
rect2_top_right_x = float(rectangle[2])
|
|
@@ -92,12 +116,16 @@ def intersects(detail, rectangle): #using the separating axis theorem
|
|
return not (rect1_top_right_x < rect2_bottom_left_x or rect1_bottom_left_x > rect2_top_right_x or rect1_top_right_y > rect2_bottom_left_y or rect1_bottom_left_y < rect2_top_right_y)
|
|
return not (rect1_top_right_x < rect2_bottom_left_x or rect1_bottom_left_x > rect2_top_right_x or rect1_top_right_y > rect2_bottom_left_y or rect1_bottom_left_y < rect2_top_right_y)
|
|
|
|
|
|
|
|
|
|
-def main_function(result):
|
|
|
|
|
|
+def main_function(result, tables):
|
|
reg = r"([A-Z])-\1|([A-Z]\W?[A-Z]?\s?\W\s?\d\d?\s?\s?:\s?\d\d?\s?\W)"
|
|
reg = r"([A-Z])-\1|([A-Z]\W?[A-Z]?\s?\W\s?\d\d?\s?\s?:\s?\d\d?\s?\W)"
|
|
- details, number= get_details(result)
|
|
|
|
- print(details)
|
|
|
|
|
|
+ details, number = get_details(result)
|
|
|
|
+ #details.extend(tables)
|
|
|
|
+ #print(tables)
|
|
|
|
+ #print(details)
|
|
details = sorted(details, key=lambda x: x[0]) #sort by distance from 0,0
|
|
details = sorted(details, key=lambda x: x[0]) #sort by distance from 0,0
|
|
- sections = get_borders(details)
|
|
|
|
|
|
+ sections = get_borders(details, tables)
|
|
|
|
+
|
|
|
|
+ #sections.append(tables)
|
|
section = []
|
|
section = []
|
|
details_dict = {}
|
|
details_dict = {}
|
|
|
|
|
|
@@ -109,19 +137,28 @@ def main_function(result):
|
|
details_dict[coord_name] = coord
|
|
details_dict[coord_name] = coord
|
|
section.append(list((coord_name,coord)))
|
|
section.append(list((coord_name,coord)))
|
|
#print(section)
|
|
#print(section)
|
|
|
|
+ for table in tables:
|
|
|
|
+ table[3] = 10000000
|
|
|
|
+ coord = []
|
|
|
|
+ name = "Table"
|
|
|
|
+ for tab in table[:4]:
|
|
|
|
+ coord.append(tab)
|
|
|
|
+ details_dict[name] = coord
|
|
|
|
+ section.append(list((name,coord)))
|
|
|
|
+ #print(section)
|
|
|
|
+
|
|
if number == 0 | len(section) == 0:
|
|
if number == 0 | len(section) == 0:
|
|
section.append(list(("No details",list((000.000,000.000,100000000.000,10000000.000)))))
|
|
section.append(list(("No details",list((000.000,000.000,100000000.000,10000000.000)))))
|
|
- # print(section)
|
|
|
|
-
|
|
|
|
|
|
|
|
|
|
|
|
dict = {}
|
|
dict = {}
|
|
|
|
|
|
-
|
|
|
|
for res in result:
|
|
for res in result:
|
|
|
|
+ #print(res)
|
|
for det in section:
|
|
for det in section:
|
|
help_array = []
|
|
help_array = []
|
|
help_dict = {}
|
|
help_dict = {}
|
|
|
|
+ #print(det)
|
|
if re.match(reg, res): ###damit nicht details zu details zugeordnet werden!!!
|
|
if re.match(reg, res): ###damit nicht details zu details zugeordnet werden!!!
|
|
break
|
|
break
|
|
if intersects(det,result[res]):
|
|
if intersects(det,result[res]):
|
|
@@ -136,10 +173,10 @@ def main_function(result):
|
|
dict[name] = help_dict
|
|
dict[name] = help_dict
|
|
break
|
|
break
|
|
|
|
|
|
- #for dic in dict:
|
|
|
|
- # print(dic)
|
|
|
|
- # for d in dict[dic]:
|
|
|
|
- # print(d)
|
|
|
|
|
|
+ """for dic in dict:
|
|
|
|
+ print(dic)
|
|
|
|
+ for d in dict[dic]:
|
|
|
|
+ print(d)"""
|
|
|
|
|
|
return dict, details_dict
|
|
return dict, details_dict
|
|
|
|
|