개정판 4a4e7537
issue #563: 연결된 Component를 기준으로 라인 타입을 인식한다
Change-Id: I19c4fa94532ec8a7c39dec1174af1cb06567c13c
DTI_PID/DTI_PID/ConnectAttrDialog.py | ||
---|---|---|
171 | 171 |
import timeit |
172 | 172 |
|
173 | 173 |
try: |
174 |
# update line type |
|
175 |
#lines = [item for item in self.graphicsView.scene.items() if type(item) is QEngineeringLineItem] |
|
176 |
#for line in lines: |
|
177 |
# line.updateLineType() |
|
178 |
# up to here |
|
179 |
|
|
180 | 174 |
self.ui.progressBar.setValue(self.ui.progressBar.maximum()) |
181 | 175 |
self.ui.buttonBox.setEnabled(True) |
182 | 176 |
except Exception as ex: |
DTI_PID/DTI_PID/LineNoTracer.py | ||
---|---|---|
470 | 470 |
for valve in valves: |
471 | 471 |
valve.connectAttribute(labels, clear=False) |
472 | 472 |
|
473 |
""" update line type """ |
|
474 |
lines = [line for line in worker.graphicsView.scene.items() if type(line) is QEngineeringLineItem] |
|
475 |
for line in lines: line.update_line_type() |
|
476 |
|
|
473 | 477 |
"""make line end break""" |
474 | 478 |
end_breaks = [] |
475 | 479 |
for lineNo in lineNos: |
476 | 480 |
for end_break in lineNo.end_break(): |
477 | 481 |
end_breaks.append(end_break) |
478 |
|
|
479 |
if end_breaks: |
|
480 |
''' |
|
481 |
# check dulplication |
|
482 |
dupl = set() |
|
483 |
for i in range(len(end_breaks)): |
|
484 |
for j in range(len(end_breaks)): |
|
485 |
if i == j: |
|
486 |
continue |
|
487 |
else: |
|
488 |
setI = set(end_breaks[i].connected_lines) |
|
489 |
setJ = set(end_breaks[j].connected_lines) |
|
490 |
if not (setI - setJ): |
|
491 |
index = [i, j] |
|
492 |
index.sort() |
|
493 |
index = tuple(index) |
|
494 |
dupl.add(index) |
|
495 |
|
|
496 |
dupl = [indexSet[1] for indexSet in list(dupl)] |
|
497 |
dupl.sort(reverse=True) |
|
498 |
for index in dupl: |
|
499 |
end_breaks.pop(index) |
|
500 |
''' |
|
501 |
|
|
482 |
|
|
502 | 483 |
for end_break in end_breaks: |
503 | 484 |
end_break.addSvgItemToScene(worker.graphicsView.scene) |
504 | 485 |
|
DTI_PID/DTI_PID/LineTypeConditions.py | ||
---|---|---|
1 |
# coding: utf-8 |
|
2 |
""" This is line type conditions module """ |
|
3 |
|
|
4 |
import sys |
|
5 |
|
|
6 |
class LineTypeConditions: |
|
7 |
""" This is line type conditions class """ |
|
8 |
|
|
9 |
def __init__(self, line_type): |
|
10 |
self.line_type = line_type |
|
11 |
self._conditions = ([None,None],[None,None]) |
|
12 |
|
|
13 |
@property |
|
14 |
def conditions(self): |
|
15 |
return self._conditions |
|
16 |
|
|
17 |
@conditions.setter |
|
18 |
def conditions(self, value): |
|
19 |
self._conditions = value |
|
20 |
|
|
21 |
def eval(self, items): |
|
22 |
""" return the result of evaluate """ |
|
23 |
from EngineeringInstrumentItem import QEngineeringInstrumentItem |
|
24 |
from EngineeringLineItem import QEngineeringLineItem |
|
25 |
|
|
26 |
try: |
|
27 |
if len(items) == len([condition for condition in self.conditions if condition[0] is not None]): |
|
28 |
for condition in self.conditions: |
|
29 |
if not condition[0]: continue |
|
30 |
if condition[0] == 'Instrument': |
|
31 |
matches = [item for item in items if type(item) is QEngineeringInstrumentItem] |
|
32 |
if not matches: return False |
|
33 |
elif condition[0] == 'Line': |
|
34 |
matches = [item for item in items if type(item) is QEngineeringLineItem] |
|
35 |
if not matches: return False |
|
36 |
|
|
37 |
if condition[1]: |
|
38 |
res = False |
|
39 |
for item in matches: |
|
40 |
ret = eval(condition[1]) |
|
41 |
if ret == True: res = True |
|
42 |
|
|
43 |
if res == False: return False |
|
44 |
|
|
45 |
return True |
|
46 |
except Exception as ex: |
|
47 |
message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
|
48 |
print(message) |
|
49 |
|
|
50 |
return False |
DTI_PID/DTI_PID/Shapes/EngineeringLineItem.py | ||
---|---|---|
1 | 1 |
# coding: utf-8 |
2 |
""" |
|
3 |
This is engineering line item module |
|
4 |
""" |
|
2 |
""" This is engineering line item module """ |
|
5 | 3 |
import sys |
6 | 4 |
import cv2 |
7 | 5 |
import os |
... | ... | |
19 | 17 |
|
20 | 18 |
from EngineeringAbstractItem import QEngineeringAbstractItem |
21 | 19 |
import shapely |
20 |
from LineTypeConditions import LineTypeConditions |
|
22 | 21 |
|
23 | 22 |
class QEngineeringLineItem(QGraphicsLineItem, QEngineeringAbstractItem): |
24 | 23 |
""" This is engineering line item """ |
... | ... | |
27 | 26 |
ZVALUE = 100 |
28 | 27 |
HIGHLIGHT = '#BC4438' |
29 | 28 |
LINE_TYPE_COLORS = {} |
29 |
LINE_TYPE_CONDITIONS = [] |
|
30 | 30 |
|
31 | 31 |
''' |
32 | 32 |
@history 2018.05.11 Jeongwoo Make Comments self.setPen() |
... | ... | |
48 | 48 |
|
49 | 49 |
self._owner = None |
50 | 50 |
self._flowMark = None |
51 |
self._lineType = 'Primary' |
|
51 |
self._lineType = 'Primary' # defulat line type is 'Primary' |
|
52 |
""" setup line type conditions """ |
|
53 |
if not QEngineeringLineItem.LINE_TYPE_CONDITIONS: |
|
54 |
condition = LineTypeConditions('Connect To Process') |
|
55 |
condition.conditions[0][0] = 'Line' |
|
56 |
condition.conditions[1][0] = 'Instrument' |
|
57 |
condition.conditions[1][1] = "not item.attrib('Type') in ['RO']" |
|
58 |
QEngineeringLineItem.LINE_TYPE_CONDITIONS.append(condition) |
|
59 |
condition = LineTypeConditions('Electric') |
|
60 |
condition.conditions[0][0] = 'Instrument' |
|
61 |
condition.conditions[1][0] = 'Instrument' |
|
62 |
QEngineeringLineItem.LINE_TYPE_CONDITIONS.append(condition) |
|
52 | 63 |
|
53 | 64 |
self.setFlags(QGraphicsItem.ItemIsSelectable|QGraphicsItem.ItemIsFocusable) |
54 | 65 |
|
... | ... | |
925 | 936 |
@author humkyung |
926 | 937 |
@date 2018.07.05 |
927 | 938 |
''' |
928 |
def updateLineType(self): |
|
939 |
def update_line_type(self): |
|
940 |
import uuid |
|
929 | 941 |
from EngineeringInstrumentItem import QEngineeringInstrumentItem |
930 | 942 |
|
931 |
if len(self.connectors) == 2: |
|
932 |
lines = [item.connectedItem for item in self.connectors if item.connectedItem is not None and type(item.connectedItem) is QEngineeringLineItem] |
|
933 |
insts = [item.connectedItem for item in self.connectors if item.connectedItem is not None and type(item.connectedItem) is QEngineeringInstrumentItem] |
|
934 |
|
|
935 |
matches = [inst for inst in insts if (inst.measuredVariableCode + inst.typeModifier) not in ['FT', 'PT', 'TT', 'TI', 'TG', 'PG']] |
|
936 |
if matches: |
|
937 |
self.lineType = 'Electric' |
|
938 |
|
|
939 |
pool = [item.connectedItem for item in self.connectors if item.connectedItem is not None and type(item.connectedItem) is QEngineeringLineItem] |
|
940 |
visited = [] |
|
941 |
visited.extend(pool) |
|
942 |
while len(pool): |
|
943 |
line = pool.pop() |
|
944 |
line.lineType = 'Electric' |
|
943 |
try: |
|
944 |
for condition in QEngineeringLineItem.LINE_TYPE_CONDITIONS: |
|
945 |
items = [connector.connectedItem for connector in self.connectors if connector.connectedItem and not type(connector.connectedItem) is uuid.UUID] |
|
946 |
if condition.eval(items): |
|
947 |
self._lineType = condition.line_type |
|
948 |
break |
|
949 |
except Exception as ex: |
|
950 |
from App import App |
|
951 |
from AppDocData import MessageType |
|
945 | 952 |
|
946 |
matches = [item.connectedItem for item in line.connectors if item.connectedItem is not None and item.connectedItem not in visited and type(item.connectedItem) is QEngineeringLineItem] |
|
947 |
pool.extend(matches) |
|
948 |
visited.extend(matches) |
|
949 |
else: |
|
950 |
matches = [inst for inst in insts if (inst.measuredVariableCode + inst.typeModifier) in ['FT', 'PT', 'TT', 'TI', 'TG', 'PG']] |
|
951 |
if matches: |
|
952 |
self.lineType = 'Connect To Process' |
|
953 |
message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
|
954 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
|
953 | 955 |
|
954 | 956 |
def hoverEnterEvent(self, event): |
955 | 957 |
""" hilight item and it's children """ |
DTI_PID/DTI_PID/Shapes/SymbolSvgItem.py | ||
---|---|---|
139 | 139 |
matches = [prop for prop,_ in self._properties.items() if prop.Attribute == property] |
140 | 140 |
if matches: self._properties[matches[0]] = value |
141 | 141 |
|
142 |
def property(self, name): |
|
143 |
""" return the value of given property with name """ |
|
144 |
matches = [(prop,value) for prop,value in self.properties.items() if prop.Attribute == name] |
|
145 |
if matches: return matches[0][1] |
|
146 |
|
|
147 |
return None |
|
148 |
|
|
149 |
def attrib(self, name): |
|
150 |
""" return the value of given attribute with name """ |
|
151 |
matches = [(attr,value) for attr,value in self.getAttributes().items() if attr.Attribute == name] |
|
152 |
if matches: return matches[0][1] |
|
153 |
|
|
154 |
return None |
|
155 |
|
|
142 | 156 |
def validate(self): |
143 | 157 |
''' |
144 | 158 |
@brief validation check : flow |
... | ... | |
226 | 240 |
return res |
227 | 241 |
|
228 | 242 |
def texts(self): |
229 |
""" |
|
230 |
return text type of associations |
|
231 |
""" |
|
243 |
""" return text type of associations """ |
|
232 | 244 |
from EngineeringTextItem import QEngineeringTextItem |
233 | 245 |
|
234 | 246 |
return [x for x in self.associations() if issubclass(type(x), QEngineeringTextItem)] |
235 | 247 |
|
236 | 248 |
def symbols(self): |
237 |
""" |
|
238 |
return symbol type of associations |
|
239 |
""" |
|
249 |
""" return symbol type of associations """ |
|
240 | 250 |
return [x for x in self.associations() if issubclass(type(x), SymbolSvgItem)] |
241 | 251 |
|
242 | 252 |
def toSql(self): |
... | ... | |
810 | 820 |
properties_node = Element('PROPERTIES') |
811 | 821 |
for prop,value in self.properties.items(): |
812 | 822 |
prop_node = prop.toXml() |
813 |
prop_node.text = '' if not value else str(value.uid) if prop.is_selectable else str(value)
|
|
823 |
prop_node.text = str(value) if value else ''
|
|
814 | 824 |
properties_node.append(prop_node) |
815 | 825 |
node.append(properties_node) |
816 | 826 |
|
... | ... | |
820 | 830 |
if type(attr) is SymbolAttr: |
821 | 831 |
_node = attr.toXml() |
822 | 832 |
if attr.AttributeType != 'Spec': |
823 |
_node.text = _attrs[attr]
|
|
833 |
_node.text = str(_attrs[attr])
|
|
824 | 834 |
elif attr.AttributeType == 'Spec': |
825 | 835 |
_node.text = str(self.attrs[attr][0]) + ',' + str(self.attrs[attr][1]) |
826 | 836 |
attributesNode.append(_node) |
내보내기 Unified diff