개정판 a7d203dc
issue #563: opc attr auto binding
Change-Id: I2e5d535f683117c65faa30ed4c717b68b3e6b89d
DTI_PID/DTI_PID/MainWindow.py | ||
---|---|---|
676 | 676 |
from SaveWorkCommand import SaveWorkCommand |
677 | 677 |
|
678 | 678 |
try: |
679 |
if not self.actionSave.isEnabled(): |
|
680 |
return |
|
679 | 681 |
self.actionSave.setEnabled(False) |
680 | 682 |
app_doc_data = AppDocData.instance() |
681 | 683 |
if app_doc_data.imgName is None: |
DTI_PID/DTI_PID/Scripts/MSSQL/ID2.sql | ||
---|---|---|
46 | 46 |
('Fire & Safety','Piping',26), |
47 | 47 |
('Fittings','Piping',27), |
48 | 48 |
('Gaps','Piping',28), |
49 |
('Labels - Piping Components','Piping',29),
|
|
50 |
('Labels - Piping Segments','Piping',30),
|
|
49 |
('Labels - Piping Components','Instrumentation',29),
|
|
50 |
('Labels - Piping Segments','Instrumentation',30),
|
|
51 | 51 |
('Piping OPC''s','Piping',31), |
52 | 52 |
('Routing','Piping',32), |
53 | 53 |
('Segment Breaks','Piping',33), |
DTI_PID/DTI_PID/Shapes/EngineeringAbstractItem.py | ||
---|---|---|
345 | 345 |
return _type |
346 | 346 |
|
347 | 347 |
def clear_attr_and_assoc_item(self, force=False): |
348 |
""" clear attrs, return true if clear attrs """ |
|
348 | 349 |
if force: |
349 | 350 |
self.attrs.clear() |
350 | 351 |
self._associations.clear() |
352 |
return True |
|
351 | 353 |
else: |
352 | 354 |
freeze = False |
353 | 355 |
for key in self.attrs.keys(): |
... | ... | |
355 | 357 |
freeze = True |
356 | 358 |
break |
357 | 359 |
if freeze: |
358 |
pass |
|
359 |
#for assoc in self.associations(): |
|
360 |
# assoc.owner = self |
|
361 |
|
|
360 |
return False |
|
362 | 361 |
else: |
363 | 362 |
self.attrs.clear() |
364 | 363 |
self._associations.clear() |
364 |
return True |
|
365 | 365 |
|
366 | 366 |
def add_assoc_item(self, item, at=None, force=False): |
367 | 367 |
""" add given item to association """ |
DTI_PID/DTI_PID/Shapes/EngineeringInstrumentItem.py | ||
---|---|---|
173 | 173 |
|
174 | 174 |
try: |
175 | 175 |
if clear: |
176 |
self.clear_attr_and_assoc_item() |
|
176 |
if not self.clear_attr_and_assoc_item(): |
|
177 |
return |
|
177 | 178 |
|
178 | 179 |
rect = self.sceneBoundingRect() |
179 | 180 |
|
DTI_PID/DTI_PID/Shapes/EngineeringReducerItem.py | ||
---|---|---|
86 | 86 |
|
87 | 87 |
try: |
88 | 88 |
if clear: |
89 |
self.clear_attr_and_assoc_item() |
|
89 |
if not self.clear_attr_and_assoc_item(): |
|
90 |
return |
|
90 | 91 |
|
91 | 92 |
# configs = AppDocData.instance().getConfigs('Size', 'Delimiter') |
92 | 93 |
# delimiter = configs[0].value if configs else 'X' |
... | ... | |
107 | 108 |
if (length < dist) and (minDist is None or length < minDist): |
108 | 109 |
minDist = length |
109 | 110 |
selected = attr |
110 |
elif type(attr) is QEngineeringInstrumentItem: |
|
111 |
if not attr.is_connected: |
|
111 |
elif False:#type(attr) is QEngineeringInstrumentItem:
|
|
112 |
if not attr.is_connected():
|
|
112 | 113 |
dx = attr.center().x() - center.x() |
113 | 114 |
dy = attr.center().y() - center.y() |
114 | 115 |
if math.sqrt(dx * dx + dy * dy) < dist: |
DTI_PID/DTI_PID/Shapes/QEngineeringOPCItem.py | ||
---|---|---|
88 | 88 |
def connectAttribute(self, attributes, clear=True): |
89 | 89 |
from AppDocData import AppDocData, MessageType |
90 | 90 |
from EngineeringLineItem import QEngineeringLineItem |
91 |
from EngineeringTextItem import QEngineeringTextItem |
|
91 | 92 |
|
92 | 93 |
try: |
93 | 94 |
if clear: |
94 |
self.clear_attr_and_assoc_item() |
|
95 |
|
|
96 |
# return, opc attribute check manually |
|
97 |
''' |
|
95 |
if not self.clear_attr_and_assoc_item(): |
|
96 |
return |
|
98 | 97 |
|
99 | 98 |
app_doc_data = AppDocData.instance() |
100 | 99 |
|
100 |
''' |
|
101 | 101 |
matches = [connector.connectedItem for connector in self.connectors if connector is not None and type(connector.connectedItem) is QEngineeringLineItem] |
102 | 102 |
if matches: |
103 | 103 |
if matches[0].connectors[0].connectedItem is self: # FROM |
... | ... | |
106 | 106 |
configs = app_doc_data.getConfigs('OPC Tag Rule', 'To Prefix') |
107 | 107 |
|
108 | 108 |
self.set_property('Logical', 'Process' if (matches[0].lineType == 'Primary' or matches[0].lineType == 'Secondary') else 'Instrument') # set OPC type |
109 |
|
|
109 |
|
|
110 | 110 |
rect = self.sceneBoundingRect() |
111 | 111 |
for attr in attributes: |
112 | 112 |
if rect.contains(attr.center()): |
113 | 113 |
if self.add_assoc_item(attr): |
114 | 114 |
attr.owner = self |
115 |
''' |
|
116 |
|
|
117 |
configs = AppDocData.instance().getConfigs('Range', 'Detection Ratio') |
|
118 |
ratio = float(configs[0].value) if 1 == len(configs) else 1.5 |
|
115 | 119 |
|
116 |
self.associations() # to binding object from scene |
|
120 |
dist = max(self.sceneBoundingRect().height(), self.sceneBoundingRect().width()) * ratio / 5 |
|
121 |
center = self.sceneBoundingRect().center() |
|
122 |
|
|
123 |
minDists = [[sys.maxsize, None], [sys.maxsize, None], [sys.maxsize, None]] |
|
124 |
|
|
125 |
for attr in attributes: |
|
126 |
if type(attr) is QEngineeringTextItem and attr.owner is None: |
|
127 |
dx = attr.center().x() - center.x() |
|
128 |
dy = attr.center().y() - center.y() |
|
129 |
length = math.sqrt(dx * dx + dy * dy) |
|
130 |
if length < dist: |
|
131 |
minDists.pop(2) |
|
132 |
minDists.insert(2, [length, attr]) |
|
133 |
minDists = sorted(minDists, key=lambda minDist: minDist[0]) |
|
134 |
|
|
135 |
minDists.pop(2) |
|
136 |
for attr in minDists: |
|
137 |
if attr[1]: |
|
138 |
if self.add_assoc_item(attr[1]): |
|
139 |
attr[1].owner = self |
|
140 |
|
|
141 |
#self.associations() # to binding object from scene |
|
117 | 142 |
if 'Text Item' in self._associations and self._associations['Text Item']: |
118 | 143 |
if 0 == self.angle: |
119 | 144 |
sorted(self._associations['Text Item'], key=lambda attr: attr.loc[0]) # sort by x coordinate |
... | ... | |
123 | 148 |
sorted(self._associations['Text Item'], key=lambda attr: attr.loc[1], reverse=True) # sort by y coordinate |
124 | 149 |
elif 4.71 == self.angle: |
125 | 150 |
sorted(self._associations['Text Item'], key=lambda attr: attr.loc[1]) # sort by y coordinate |
126 |
''' |
|
151 |
|
|
127 | 152 |
except Exception as ex: |
128 | 153 |
from App import App |
129 | 154 |
from AppDocData import MessageType |
DTI_PID/DTI_PID/Shapes/SymbolSvgItem.py | ||
---|---|---|
1081 | 1081 |
|
1082 | 1082 |
try: |
1083 | 1083 |
if clear: |
1084 |
self.clear_attr_and_assoc_item() |
|
1084 |
if not self.clear_attr_and_assoc_item(): |
|
1085 |
return |
|
1085 | 1086 |
|
1086 | 1087 |
configs = AppDocData.instance().getConfigs('Range', 'Detection Ratio') |
1087 | 1088 |
ratio = float(configs[0].value) if 1 == len(configs) else 1.5 |
... | ... | |
1100 | 1101 |
if (length < dist) and (minDist is None or length < minDist): |
1101 | 1102 |
minDist = length |
1102 | 1103 |
selected = attr |
1103 |
elif type(attr) is QEngineeringInstrumentItem: |
|
1104 |
if not attr.is_connected: |
|
1104 |
elif False:#type(attr) is QEngineeringInstrumentItem:
|
|
1105 |
if not attr.is_connected():
|
|
1105 | 1106 |
dx = attr.center().x() - center.x() |
1106 | 1107 |
dy = attr.center().y() - center.y() |
1107 | 1108 |
if math.sqrt(dx * dx + dy * dy) < dist: |
DTI_PID/DTI_PID/SymbolTreeWidget.py | ||
---|---|---|
335 | 335 |
_, svg = app_doc_data.read_symbol_shape(symData.getName()) |
336 | 336 |
if svg: |
337 | 337 |
pixmap = QPixmap() |
338 |
pixmap.loadFromData(svg) |
|
338 |
pixmap.loadFromData(svg if isinstance(svg, bytes) else svg.encode())
|
|
339 | 339 |
|
340 | 340 |
mime = QMimeData() |
341 | 341 |
mime.setText(symData.getName()) |
내보내기 Unified diff