개정판 3a7d7b10
issue #663: add noise filter for flange detection fix symbol connection
Change-Id: I166e471a03a32fcb2ab73a0b50e5ec507b16c048
DTI_PID/DTI_PID/RecognitionDialog.py | ||
---|---|---|
1228 | 1228 |
matches = [it for it in app_doc_data.symbols if |
1229 | 1229 |
it is not symbol and symbol.is_connectable(it, toler=toler)] |
1230 | 1230 |
for match in matches: |
1231 |
symbol.connect_if_possible(match) |
|
1231 |
symbol.connect_if_possible(match, toler=toler)
|
|
1232 | 1232 |
except Exception as ex: |
1233 | 1233 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
1234 | 1234 |
sys.exc_info()[-1].tb_lineno) |
... | ... | |
1286 | 1286 |
# up to here |
1287 | 1287 |
print('flag3.99') |
1288 | 1288 |
|
1289 |
# make short line that can not detected |
|
1290 |
try: |
|
1291 |
conns = [] |
|
1292 |
for sym in symbols: |
|
1293 |
if sym.conn_type: |
|
1294 |
for index in range(len(sym.conn_type)): |
|
1295 |
if sym.conn_type[index] == 'Secondary' or sym.conn_type[index] == 'Primary': |
|
1296 |
item = sym.connectors[index].connectedItem |
|
1297 |
if item is None: |
|
1298 |
conns.append(sym.connectors[index]) |
|
1299 |
|
|
1300 |
Worker.make_short_lines(app_doc_data.lines, conns, worker) |
|
1301 |
|
|
1302 |
except Exception as ex: |
|
1303 |
message = f"error occurred({repr(ex)}) in {sys.exc_info()[-1].tb_frame.f_code.co_filename}:" \ |
|
1304 |
f"{sys.exc_info()[-1].tb_lineno}" |
|
1305 |
worker.displayLog.emit(MessageType.Error, message) |
|
1306 |
|
|
1307 | 1289 |
# detect flange |
1308 | 1290 |
try: |
1291 |
not_conn = [] |
|
1309 | 1292 |
if instrument == 1: |
1293 |
flange = None |
|
1294 |
configs = app_doc_data.getConfigs('Default', 'Flange') |
|
1295 |
flange_name = configs[0].value if 1 == len(configs) else 'flange' |
|
1296 |
flange = QtImageViewer.createSymbolObject(flange_name) |
|
1297 |
|
|
1298 |
blind = None |
|
1299 |
configs = app_doc_data.getConfigs('Default', 'Blind') |
|
1300 |
flange_name = configs[0].value if 1 == len(configs) else 'blind flange' |
|
1301 |
blind = QtImageViewer.createSymbolObject(flange_name) |
|
1302 |
|
|
1310 | 1303 |
for sym in symbols: |
1311 | 1304 |
if sym.conn_type: |
1312 | 1305 |
for index in range(len(sym.conn_type)): |
1313 | 1306 |
item = sym.connectors[index].connectedItem |
1314 |
if item and type(item) is QEngineeringLineItem and (sym.conn_type[index] == 'Secondary' or sym.conn_type[index] == 'Primary') \ |
|
1307 |
if flange and item and type(item) is QEngineeringLineItem and (sym.conn_type[index] == 'Secondary' or sym.conn_type[index] == 'Primary') \
|
|
1315 | 1308 |
and item.is_piping(True): |
1316 | 1309 |
point = worker.detectFlangeOnPid(sym, sym.connectors[index], item, app_doc_data.activeDrawing.image_origin) |
1317 | 1310 |
if point is not None: |
1318 | 1311 |
flange_list.append(point) |
1319 | 1312 |
|
1320 |
elif not item and (sym.conn_type[index] == 'Secondary' or sym.conn_type[index] == 'Primary'): |
|
1313 |
elif blind and not item and (sym.conn_type[index] == 'Secondary' or sym.conn_type[index] == 'Primary'):
|
|
1321 | 1314 |
point = worker.detectFlangeOnPid(sym, sym.connectors[index], None, app_doc_data.activeDrawing.image_origin) |
1322 | 1315 |
if point is not None: |
1323 | 1316 |
blind_list.append(point) |
1317 |
not_conn.append(sym.connectors[index]) |
|
1324 | 1318 |
|
1325 | 1319 |
except Exception as ex: |
1326 | 1320 |
message = f"error occurred({repr(ex)}) in {sys.exc_info()[-1].tb_frame.f_code.co_filename}:" \ |
... | ... | |
1328 | 1322 |
worker.displayLog.emit(MessageType.Error, message) |
1329 | 1323 |
# up to here |
1330 | 1324 |
|
1325 |
# make short line that can not detected |
|
1326 |
try: |
|
1327 |
conns = [] |
|
1328 |
for sym in symbols: |
|
1329 |
if sym.conn_type: |
|
1330 |
for index in range(len(sym.conn_type)): |
|
1331 |
if sym.conn_type[index] == 'Secondary' or sym.conn_type[index] == 'Primary': |
|
1332 |
item = sym.connectors[index].connectedItem |
|
1333 |
if item is None and sym.connectors[index] not in not_conn: |
|
1334 |
conns.append(sym.connectors[index]) |
|
1335 |
|
|
1336 |
Worker.make_short_lines(app_doc_data.lines, conns, worker) |
|
1337 |
|
|
1338 |
except Exception as ex: |
|
1339 |
message = f"error occurred({repr(ex)}) in {sys.exc_info()[-1].tb_frame.f_code.co_filename}:" \ |
|
1340 |
f"{sys.exc_info()[-1].tb_lineno}" |
|
1341 |
worker.displayLog.emit(MessageType.Error, message) |
|
1342 |
|
|
1331 | 1343 |
# remove line has not connected item |
1332 | 1344 |
try: |
1333 | 1345 |
count = 1 |
... | ... | |
2461 | 2473 |
def detectFlangeBlindOnPid(start_x, start_y, arrow, image): |
2462 | 2474 |
loopRange = [] |
2463 | 2475 |
if arrow is Arrow.DOWN: |
2464 |
loopRange = range(start_y - 20, start_y + 40)
|
|
2476 |
loopRange = range(start_y - 10, start_y + 25)
|
|
2465 | 2477 |
elif arrow is Arrow.UP: |
2466 |
loopRange = range(start_y + 20, start_y - 40, -1)
|
|
2478 |
loopRange = range(start_y + 10, start_y - 25, -1)
|
|
2467 | 2479 |
elif arrow is Arrow.LEFT: |
2468 |
loopRange = range(start_x + 20, start_x - 40, -1)
|
|
2480 |
loopRange = range(start_x + 10, start_x - 25, -1)
|
|
2469 | 2481 |
elif arrow is Arrow.RIGHT: |
2470 |
loopRange = range(start_x - 20, start_x + 40)
|
|
2482 |
loopRange = range(start_x - 10, start_x + 25)
|
|
2471 | 2483 |
else: |
2472 | 2484 |
return None |
2473 | 2485 |
|
... | ... | |
2486 | 2498 |
flange_max = 50 |
2487 | 2499 |
# flange max width |
2488 | 2500 |
flange_count_max = 10 |
2501 |
# noise max count |
|
2502 |
noise_count_max = 5 |
|
2489 | 2503 |
|
2490 | 2504 |
# 임시 |
2491 | 2505 |
temp_count = 0 |
2506 |
noise_count = 0 |
|
2492 | 2507 |
find_list_x = [] |
2493 | 2508 |
find_list_y = [] |
2494 | 2509 |
for i in loopRange: |
... | ... | |
2530 | 2545 |
find_list_y.append(find_y) |
2531 | 2546 |
break |
2532 | 2547 |
elif width > 0: |
2548 |
if temp_count > 0: |
|
2549 |
noise_count += 1 |
|
2533 | 2550 |
break |
2534 | 2551 |
|
2535 | 2552 |
if loop_find: |
2536 | 2553 |
if temp_count > flange_count_max: |
2537 | 2554 |
break |
2538 | 2555 |
temp_count = temp_count + 1 |
2539 |
elif 0 < temp_count < flange_count_max and width > 0: |
|
2556 |
elif 0 < temp_count < flange_count_max and width > 0 and noise_count <= noise_count_max:
|
|
2540 | 2557 |
continue |
2541 |
elif 0 < temp_count < flange_count_max and width == 0: |
|
2558 |
elif noise_count > noise_count_max: |
|
2559 |
break |
|
2560 |
elif 0 < temp_count < flange_count_max and width == 0 and noise_count <= noise_count_max: |
|
2542 | 2561 |
find_forward = True |
2543 | 2562 |
break |
2544 | 2563 |
else: |
... | ... | |
2551 | 2570 |
|
2552 | 2571 |
# 임시 |
2553 | 2572 |
temp_count = 0 |
2573 |
noise_count = 0 |
|
2554 | 2574 |
find_list_x = [] |
2555 | 2575 |
find_list_y = [] |
2556 | 2576 |
for i in reversed(loopRange): |
... | ... | |
2591 | 2611 |
find_list_x.append(find_x) |
2592 | 2612 |
find_list_y.append(find_y) |
2593 | 2613 |
break |
2614 |
elif width > 0: |
|
2615 |
if temp_count > 0: |
|
2616 |
noise_count += 1 |
|
2617 |
break |
|
2594 | 2618 |
|
2595 | 2619 |
if loop_find: |
2596 | 2620 |
if temp_count > flange_count_max: |
2597 | 2621 |
break |
2598 | 2622 |
temp_count = temp_count + 1 |
2599 |
elif 0 < temp_count < flange_count_max and width > 0: |
|
2623 |
elif 0 < temp_count < flange_count_max and width > 0 and noise_count <= noise_count_max:
|
|
2600 | 2624 |
continue |
2601 |
elif 0 < temp_count < flange_count_max and width == 0: |
|
2625 |
elif noise_count > noise_count_max: |
|
2626 |
break |
|
2627 |
elif 0 < temp_count < flange_count_max and width == 0 and noise_count <= noise_count_max: |
|
2602 | 2628 |
find_backward = True |
2603 | 2629 |
break |
2604 | 2630 |
else: |
내보내기 Unified diff