개정판 ad65e27f
issue #563: 비동기로 함수 호출
Change-Id: I5cc6dcc3c76ef176a7133992454cd839a32c4e76
DTI_PID/DTI_PID/ConnectAttrDialog.py | ||
---|---|---|
56 | 56 |
|
57 | 57 |
@pyqtSlot() |
58 | 58 |
def run(self): # A slot takes no params |
59 |
import asyncio |
|
60 |
|
|
59 | 61 |
try: |
60 |
self.fn(self.signals, *self.args, **self.kwargs) |
|
62 |
loop = asyncio.get_event_loop() |
|
63 |
loop.run_until_complete(self.fn(self.signals, *self.args, **self.kwargs)) |
|
64 |
# self.fn(self.signals, *self.args, **self.kwargs) |
|
61 | 65 |
except Exception as ex: |
62 | 66 |
message = 'error occurred({}) in {}:{}'.format(repr(ex), sys.exc_info()[-1].tb_frame.f_code.co_filename, |
63 | 67 |
sys.exc_info()[-1].tb_lineno) |
DTI_PID/DTI_PID/LineNoTracer.py | ||
---|---|---|
3 | 3 |
|
4 | 4 |
import sys |
5 | 5 |
import math |
6 |
import asyncio |
|
6 | 7 |
import shapely |
7 | 8 |
from AppDocData import AppDocData, MessageType |
8 | 9 |
from EngineeringLineItem import QEngineeringLineItem |
... | ... | |
345 | 346 |
# nextmatches list always has one item |
346 | 347 |
if type(obj) is QEngineeringLineItem: |
347 | 348 |
symbolMatches = [x for x in self._symbols if (x.owner is None or x.owner == start.owner) and ( |
348 |
x not in visited) and obj.is_connected(x)]
|
|
349 |
x not in visited) and obj.is_connected(x)] |
|
349 | 350 |
if include_signal: |
350 | 351 |
lineMatches = [x for x in self._lines if |
351 | 352 |
(x.owner is None or x.owner == start.owner) and (x is not obj) and ( |
352 |
x not in visited) and obj.is_connected(x)]
|
|
353 |
x not in visited) and obj.is_connected(x)] |
|
353 | 354 |
else: |
354 | 355 |
lineMatches = [x for x in self._lines if |
355 | 356 |
x.is_piping() and (x.owner is None or x.owner == start.owner) and ( |
356 |
x is not obj) and (x not in visited) and obj.is_connected(x)]
|
|
357 |
x is not obj) and (x not in visited) and obj.is_connected(x)] |
|
357 | 358 |
nextMatches = symbolMatches + lineMatches |
358 | 359 |
|
359 | 360 |
elif issubclass(type(obj), SymbolSvgItem): |
360 | 361 |
# symbol can be connected with line and another symbol at the same time |
361 | 362 |
if include_signal: |
362 | 363 |
lineMatches = [x for x in self._lines if (x.owner is None or x.owner == start.owner) and ( |
363 |
x not in visited) and obj.is_connected(x)]
|
|
364 |
x not in visited) and obj.is_connected(x)] |
|
364 | 365 |
else: |
365 | 366 |
lineMatches = [x for x in self._lines if |
366 | 367 |
x.is_piping() and (x.owner is None or x.owner == start.owner) and ( |
367 |
x not in visited) and obj.is_connected(x)]
|
|
368 |
x not in visited) and obj.is_connected(x)] |
|
368 | 369 |
symbolMatches = [x for x in self._symbols if |
369 | 370 |
(x.owner is None or x.owner == start.owner) and (x is not obj) and ( |
370 |
x not in visited) and obj.is_connected(x, None)]
|
|
371 |
x not in visited) and obj.is_connected(x, None)] |
|
371 | 372 |
nextMatches = symbolMatches + lineMatches |
372 | 373 |
|
373 | 374 |
if len(nextMatches) > 1: # choose one if connected items are more than 2 |
... | ... | |
445 | 446 |
kyouho 2018.09.14 clear Item's owner |
446 | 447 |
''' |
447 | 448 |
|
448 |
def connectAttrImpl(worker, update_line_type, update_flow_mark, update_spec): |
|
449 |
|
|
450 |
async def connectAttrImpl(worker, update_line_type, update_flow_mark, update_spec): |
|
449 | 451 |
from App import App |
450 | 452 |
import uuid |
451 | 453 |
from LineNoTracer import LineNoTracer |
... | ... | |
516 | 518 |
if type(item) is QEngineeringSpecBreakItem: |
517 | 519 |
spec_breaks.append(item) |
518 | 520 |
elif issubclass(type(item), SymbolSvgItem) and not (type(item) is QEngineeringErrorItem) and not ( |
519 |
type(item) is QEngineeringUnknownItem) and item.type != 'Notes' and not (type(item) is QEngineeringEndBreakItem): |
|
521 |
type(item) is QEngineeringUnknownItem) and item.type != 'Notes' and not ( |
|
522 |
type(item) is QEngineeringEndBreakItem): |
|
520 | 523 |
matches = [vendor_package for vendor_package in vendor_packages if vendor_package.includes(item)] |
521 | 524 |
if matches: |
522 | 525 |
item.set_property('Supplied By', vendorTag) |
... | ... | |
687 | 690 |
(type1, value, traceback) = sys.exc_info() |
688 | 691 |
sys.excepthook(type1, value, traceback) |
689 | 692 |
|
693 |
|
|
690 | 694 |
def make_end_break(worker, end_breaks, lineNos): |
691 | 695 |
''' make end break ''' |
692 | 696 |
|
... | ... | |
778 | 782 |
|
779 | 783 |
except Exception as ex: |
780 | 784 |
message = 'error occurred({}) in {}:{}'.format(repr(ex), sys.exc_info()[-1].tb_frame.f_code.co_filename, |
781 |
sys.exc_info()[-1].tb_lineno) |
|
785 |
sys.exc_info()[-1].tb_lineno)
|
|
782 | 786 |
worker.display_message.emit(message) |
783 | 787 |
|
788 |
|
|
784 | 789 |
def make_spec(worker, spec_breaks, lines, lineNos): |
785 | 790 |
''' update spec break ''' |
786 | 791 |
|
... | ... | |
809 | 814 |
svgFileName = spec_break_names[0].sName |
810 | 815 |
symbol = docdata.getSymbolByQuery('name', svgFileName) |
811 | 816 |
svgFilePath = os.path.join(docdata.getCurrentProject().getSvgFilePath(), symbol.getType(), |
812 |
svgFileName + '.svg')
|
|
817 |
svgFileName + '.svg') |
|
813 | 818 |
|
814 | 819 |
specBreakAttrsFull = [attr for attr in docdata.getSymbolAttribute('Segment Breaks') if |
815 |
attr.Target == 'ALL' and (
|
|
816 |
attr.AttributeType == 'Spec' or attr.AttributeType == 'String')]
|
|
820 |
attr.Target == 'ALL' and ( |
|
821 |
attr.AttributeType == 'Spec' or attr.AttributeType == 'String')] |
|
817 | 822 |
specBreakAttrs = [attr.Attribute for attr in specBreakAttrsFull] |
818 | 823 |
|
819 | 824 |
line_ends = [] |
... | ... | |
821 | 826 |
for lineNo in lineNos: |
822 | 827 |
for run in lineNo.runs: |
823 | 828 |
line_ends.append(run.items[0]) if issubclass(type(run.items[0]), SymbolSvgItem) or ( |
824 |
type(run.items[0]) is QEngineeringLineItem and (
|
|
825 |
run.items[0].lineType == 'Secondary' or run.items[
|
|
826 |
0].lineType == 'Primary')) else None
|
|
829 |
type(run.items[0]) is QEngineeringLineItem and ( |
|
830 |
run.items[0].lineType == 'Secondary' or run.items[ |
|
831 |
0].lineType == 'Primary')) else None |
|
827 | 832 |
for lineNo in lineNos: |
828 | 833 |
for run in lineNo.runs: |
829 | 834 |
if run.items[0] is not run.items[-1]: |
830 | 835 |
line_ends.append(run.items[-1]) if issubclass(type(run.items[-1]), SymbolSvgItem) or ( |
831 |
type(run.items[-1]) is QEngineeringLineItem and (
|
|
832 |
run.items[-1].lineType == 'Secondary' or run.items[
|
|
833 |
-1].lineType == 'Primary')) else None
|
|
836 |
type(run.items[-1]) is QEngineeringLineItem and ( |
|
837 |
run.items[-1].lineType == 'Secondary' or run.items[ |
|
838 |
-1].lineType == 'Primary')) else None |
|
834 | 839 |
|
835 | 840 |
spec_breaks = [] |
836 | 841 |
for line_end in line_ends: |
... | ... | |
842 | 847 |
for prop, value in [[prop, value] for prop, value in line_end.owner.getAttributes().items() |
843 | 848 |
if prop.Attribute in specBreakAttrs]: |
844 | 849 |
for prop2, value2 in [[prop2, value2] for prop2, value2 in |
845 |
connector.connectedItem.owner.getAttributes().items() if
|
|
846 |
prop2.Attribute in specBreakAttrs and prop2.UID == prop.UID]:
|
|
850 |
connector.connectedItem.owner.getAttributes().items() if |
|
851 |
prop2.Attribute in specBreakAttrs and prop2.UID == prop.UID]: |
|
847 | 852 |
if str(prop.UID) == str(prop2.UID) and value != value2: |
848 | 853 |
if not match: |
849 | 854 |
spec_break.extend([line_end, connector.connectedItem]) |
... | ... | |
892 | 897 |
if connector.connectedItem is spec[1]: |
893 | 898 |
spec_break = SymbolSvgItem.createItem(symbol.getType(), None, svgFilePath) |
894 | 899 |
pt = [60 + connector.center()[0] - float(symbol.getOriginalPoint().split(',')[0]), |
895 |
90 + connector.center()[1] - float(symbol.getOriginalPoint().split(',')[1])]
|
|
900 |
90 + connector.center()[1] - float(symbol.getOriginalPoint().split(',')[1])] |
|
896 | 901 |
origin = [0, 0] |
897 | 902 |
if 2 == len(symbol.getOriginalPoint().split(',')): |
898 | 903 |
tokens = symbol.getOriginalPoint().split(',') |
899 | 904 |
origin = [pt[0] + float(tokens[0]), pt[1] + float(tokens[1])] |
900 | 905 |
spec_break.buildItem(svgFileName, symbol.getType(), 0.0, pt, |
901 |
[spec_break.boundingRect().width(),
|
|
902 |
spec_break.boundingRect().height()], origin, [],
|
|
903 |
symbol.getBaseSymbol(), symbol.getAdditionalSymbol(),
|
|
904 |
symbol.getHasInstrumentLabel())
|
|
906 |
[spec_break.boundingRect().width(), |
|
907 |
spec_break.boundingRect().height()], origin, [], |
|
908 |
symbol.getBaseSymbol(), symbol.getAdditionalSymbol(), |
|
909 |
symbol.getHasInstrumentLabel()) |
|
905 | 910 |
|
906 | 911 |
attrs = spec_break.getAttributes() |
907 | 912 |
for key in attrs.keys(): |
... | ... | |
936 | 941 |
if connectorr.connectedItem and stream_track[ |
937 | 942 |
index] is not connectorr.connectedItem and stream_line[ |
938 | 943 |
index].next_connected(stream_track[index], |
939 |
connectorr.connectedItem):
|
|
944 |
connectorr.connectedItem): |
|
940 | 945 |
stream_track[index] = stream_line[index] |
941 | 946 |
stream_line[index] = connectorr.connectedItem |
942 | 947 |
find_next = True |
... | ... | |
959 | 964 |
|
960 | 965 |
if stream_res[0] and stream_res[1]: |
961 | 966 |
texts = [item for item in worker.scene.items() if |
962 |
type(item) is QEngineeringTextItem and item.owner is None]
|
|
967 |
type(item) is QEngineeringTextItem and item.owner is None] |
|
963 | 968 |
positioning = False |
964 | 969 |
|
965 | 970 |
for attr, value, value2 in spec[2:]: |
... | ... | |
975 | 980 |
dx = connector.center()[0] - up_down_text.center().x() |
976 | 981 |
dy = connector.center()[1] - up_down_text.center().y() |
977 | 982 |
dist = ( |
978 |
up_down_text.sceneBoundingRect().height() + up_down_text.sceneBoundingRect().width()) * ratio / 2
|
|
983 |
up_down_text.sceneBoundingRect().height() + up_down_text.sceneBoundingRect().width()) * ratio / 2 |
|
979 | 984 |
length = math.sqrt(dx * dx + dy * dy) |
980 | 985 |
if length < dist and length < minDist: |
981 | 986 |
up_down_find[index] = up_down_text |
... | ... | |
988 | 993 |
attrs[key] = up_down_find[index].text() |
989 | 994 |
key.AssocItem = up_down_find[index] |
990 | 995 |
stream_line[index].add_assoc_item(up_down_find[index], |
991 |
key.AttrAt, force=True)
|
|
996 |
key.AttrAt, force=True) |
|
992 | 997 |
up_down_find[index].owner = stream_line[index] |
993 | 998 |
break |
994 | 999 |
|
... | ... | |
1000 | 1005 |
new_y = round( |
1001 | 1006 |
(up_down_find[0].center().y() + up_down_find[1].center().y()) / 2) |
1002 | 1007 |
spec_break.loc = [new_x - spec_break.symbolOrigin[0], |
1003 |
new_y - spec_break.symbolOrigin[1]]
|
|
1008 |
new_y - spec_break.symbolOrigin[1]] |
|
1004 | 1009 |
spec_break.origin = [new_x, new_y] |
1005 | 1010 |
if abs(up_down_find[0].center().x() - up_down_find[ |
1006 | 1011 |
1].center().x()) < abs( |
1007 |
up_down_find[0].center().y() - up_down_find[1].center().y()):
|
|
1012 |
up_down_find[0].center().y() - up_down_find[1].center().y()): |
|
1008 | 1013 |
spec_break.angle = 1.57 |
1009 | 1014 |
else: |
1010 | 1015 |
spec_break.angle = 3.14 |
... | ... | |
1018 | 1023 |
spec_break_items.extend(freezed_spec_breaks) |
1019 | 1024 |
except Exception as ex: |
1020 | 1025 |
message = 'error occurred({}) in {}:{}'.format(repr(ex), sys.exc_info()[-1].tb_frame.f_code.co_filename, |
1021 |
sys.exc_info()[-1].tb_lineno) |
|
1026 |
sys.exc_info()[-1].tb_lineno)
|
|
1022 | 1027 |
worker.display_message.emit(message) |
1023 | 1028 |
|
1029 |
|
|
1024 | 1030 |
def make_flow_mark(worker, lines): |
1025 |
''' make flow mark '''
|
|
1031 |
''' make flow mark ''' |
|
1026 | 1032 |
|
1027 | 1033 |
try: |
1028 | 1034 |
docdata = AppDocData.instance() |
... | ... | |
1047 | 1053 |
sys.exc_info()[-1].tb_lineno) |
1048 | 1054 |
worker.display_message.emit(message) |
1049 | 1055 |
|
1056 |
|
|
1050 | 1057 |
def sort_run_flow(worker): |
1051 | 1058 |
''' sort runs ''' |
1052 | 1059 |
|
... | ... | |
1245 | 1252 |
fixed_run = fixed_run_info.run |
1246 | 1253 |
if len(waiting_run.items) > 1 and len(fixed_run.items) > 1 and type( |
1247 | 1254 |
waiting_run.items[0]) is QEngineeringLineItem and type( |
1248 |
waiting_run.items[-1]) is QEngineeringLineItem:
|
|
1255 |
waiting_run.items[-1]) is QEngineeringLineItem: |
|
1249 | 1256 |
if waiting_run.items[0].connectors[0].connectedItem in fixed_run.items and \ |
1250 | 1257 |
waiting_run.items[-1].connectors[1].connectedItem in fixed_run.items: |
1251 | 1258 |
if fixed_run.items.index( |
1252 | 1259 |
waiting_run.items[0].connectors[0].connectedItem) > fixed_run.items.index( |
1253 |
waiting_run.items[-1].connectors[1].connectedItem):
|
|
1260 |
waiting_run.items[-1].connectors[1].connectedItem): |
|
1254 | 1261 |
waiting_run.reverse() |
1255 | 1262 |
fixed_run_infos.append(waiting_run_info) |
1256 | 1263 |
waiting_run_infos.pop(run_index) |
... | ... | |
1457 | 1464 |
fixed_merged_run = fixed_merged_run_info[1].run |
1458 | 1465 |
if len(waiting_merged_run.items) > 1 and len(fixed_merged_run.items) > 1 and type( |
1459 | 1466 |
waiting_merged_run.items[0]) is QEngineeringLineItem and type( |
1460 |
waiting_merged_run.items[-1]) is QEngineeringLineItem:
|
|
1467 |
waiting_merged_run.items[-1]) is QEngineeringLineItem: |
|
1461 | 1468 |
if waiting_merged_run.items[0].connectors[0].connectedItem in fixed_merged_run.items and \ |
1462 | 1469 |
waiting_merged_run.items[-1].connectors[1].connectedItem in fixed_merged_run.items: |
1463 | 1470 |
if fixed_merged_run.items.index(waiting_merged_run.items[0].connectors[ |
1464 | 1471 |
0].connectedItem) > fixed_merged_run.items.index( |
1465 |
waiting_merged_run.items[-1].connectors[1].connectedItem):
|
|
1472 |
waiting_merged_run.items[-1].connectors[1].connectedItem): |
|
1466 | 1473 |
for waiting_run_info in waiting_merged_run_infos[run_index][0]: |
1467 | 1474 |
waiting_run_info.reverse() |
1468 | 1475 |
waiting_merged_run_infos[run_index][0].reverse() |
... | ... | |
1490 | 1497 |
except Exception as ex: |
1491 | 1498 |
message = 'error occurred({}) in {}:{}'.format(repr(ex), sys.exc_info()[-1].tb_frame.f_code.co_filename, |
1492 | 1499 |
sys.exc_info()[-1].tb_lineno) |
1493 |
worker.display_message.emit(message) |
|
1500 |
worker.display_message.emit(message) |
DTI_PID/DTI_PID/MainWindow.py | ||
---|---|---|
5 | 5 |
import os |
6 | 6 |
import subprocess |
7 | 7 |
from functools import partial |
8 |
import asyncio |
|
8 | 9 |
|
9 | 10 |
sys.path.insert(0, os.path.dirname(os.path.realpath(__file__))) |
10 | 11 |
sys.path.insert(0, os.path.join(os.path.dirname(os.path.realpath(__file__)), 'Commands')) |
... | ... | |
260 | 261 |
self.actionSymbol_Thickness_Reinforcement.triggered.connect(self.onSymbolThickness) |
261 | 262 |
self.actionHelp.triggered.connect(self.on_help) |
262 | 263 |
self.graphicsView.scene().selectionChanged.connect(self.onSelectionChanged) |
263 |
self.actionInitialize.triggered.connect(self.onInitializeScene)
|
|
264 |
self.actionInitialize.triggered.connect(self.on_initialize_scene)
|
|
264 | 265 |
self.actionSave.triggered.connect(self.actionSaveCliked) |
265 | 266 |
self.addMessage.connect(self.onAddMessage) |
266 | 267 |
self.actionFindReplaceText.triggered.connect(self.findReplaceTextClicked) |
... | ... | |
1039 | 1040 |
@history humkyung 2018.08.16 ask to delete recognized items before remove |
1040 | 1041 |
''' |
1041 | 1042 |
|
1042 |
def onInitializeScene(self, action):
|
|
1043 |
def on_initialize_scene(self, action):
|
|
1043 | 1044 |
if not self.graphicsView.hasImage(): |
1044 |
# self.actionEquipment.setChecked(False) |
|
1045 | 1045 |
self.showImageSelectionMessageBox() |
1046 | 1046 |
|
1047 | 1047 |
return |
... | ... | |
1053 | 1053 |
msg.setWindowTitle(self.tr("Initialize")) |
1054 | 1054 |
msg.setStandardButtons(QMessageBox.Ok | QMessageBox.Cancel) |
1055 | 1055 |
if QMessageBox.Ok == msg.exec_(): |
1056 |
app_doc_data = AppDocData.instance() |
|
1057 |
app_doc_data.clearItemList(True) |
|
1056 | 1058 |
|
1057 |
appDocData = AppDocData.instance() |
|
1058 |
appDocData.clearItemList(True) |
|
1059 |
|
|
1060 |
items = self.graphicsView.scene().items() |
|
1061 |
for item in items: |
|
1062 |
if type(item) is not QGraphicsPixmapItem and item.scene() is not None: |
|
1063 |
# if hasattr(item, 'tranfer'): |
|
1064 |
# item.tranfer.onRemoved.emit(item) |
|
1065 |
# else: |
|
1066 |
# self.graphicsView.scene().removeItem(item) |
|
1067 |
self.graphicsView.scene().removeItem(item) |
|
1068 |
|
|
1069 |
''' |
|
1070 |
if type(item) is QEngineeringLineNoTextItem: |
|
1071 |
self.removedItems['LINE'].append(str(item.uid)) |
|
1072 |
elif type(item) is QEngineeringInstrumentItem: |
|
1073 |
self.removedItems['INST'].append(str(item.uid)) |
|
1074 |
elif type(item) is QEngineeringEquipmentItem: |
|
1075 |
self.removedItems['EQUIP'].append(str(item.uid)) |
|
1076 |
elif type(item) is QEngineeringNoteItem: |
|
1077 |
self.removedItems['NOTE'].append(str(item.uid)) |
|
1078 |
''' |
|
1059 |
scene = self.graphicsView.scene() |
|
1060 |
pixmap = self.graphicsView.getPixmapHandle() |
|
1061 |
scene.removeItem(pixmap) # disconnect pixmap from scene |
|
1062 |
scene.clear() # remove all items from scene and then delete them |
|
1063 |
scene.addItem(pixmap) # add pixmap |
|
1079 | 1064 |
|
1080 | 1065 |
if self.path is not None: |
1081 | 1066 |
baseName = os.path.basename(self.path) |
... | ... | |
1404 | 1389 |
app_doc_data = AppDocData.instance() |
1405 | 1390 |
project = app_doc_data.getCurrentProject() |
1406 | 1391 |
|
1407 |
#self.graphicsView.setScene(None) |
|
1408 | 1392 |
self.path = self.graphicsView.loadImageFromFile(drawing) |
1409 | 1393 |
if os.path.isfile(self.path): |
1410 | 1394 |
self.onCommandRejected() |
... | ... | |
1441 | 1425 |
path = os.path.join(app_doc_data.getCurrentProject().getTempPath(), app_doc_data.imgName + '.xml') |
1442 | 1426 |
configs = app_doc_data.getConfigs('Data Load', 'Xml First') |
1443 | 1427 |
if configs and int(configs[0].value) is 1 and os.path.isfile(path): |
1444 |
self.loadRecognitionResultFromXml(path)
|
|
1428 |
self.load_recognition_result_from_xml(path)
|
|
1445 | 1429 |
else: |
1446 | 1430 |
self.load_drawing(app_doc_data.activeDrawing) |
1447 | 1431 |
|
1448 | 1432 |
self.display_number_of_items() |
1449 | 1433 |
# connect scene changed signal |
1450 | 1434 |
self.graphicsView.scene().contents_changed.connect(self.scene_changed) |
1451 |
#self.graphicsView.setScene(self.graphicsView.scene()) |
|
1452 | 1435 |
finally: |
1453 | 1436 |
if hasattr(self, 'progress'): |
1454 | 1437 |
self.progress.setValue(self.progress.maximum()) |
1455 |
# self.progress.hide() |
|
1456 | 1438 |
|
1457 | 1439 |
self.changeViewCheckedState(True) |
1458 | 1440 |
self.setWindowTitle(self.title) |
... | ... | |
3072 | 3054 |
2018.11.22 euisung fix note road |
3073 | 3055 |
''' |
3074 | 3056 |
|
3075 |
def loadRecognitionResultFromXml(self, xmlPath):
|
|
3057 |
def load_recognition_result_from_xml(self, xmlPath):
|
|
3076 | 3058 |
# Yield successive n-sized |
3077 | 3059 |
# chunks from l. |
3078 | 3060 |
def divide_chunks(l, n): |
내보내기 Unified diff