개정판 46c46d21
issue #597: HMB 테이블 연계
Change-Id: I38268990765dccb91a53f2953d3082c32bfc54cd
DTI_PID/DTI_PID/AppDatabase.py | ||
---|---|---|
4 | 4 |
import sqlite3 |
5 | 5 |
import pymssql |
6 | 6 |
|
7 |
|
|
7 | 8 |
class AppDatabase: |
8 | 9 |
""" This is AppDatabase class """ |
9 | 10 |
def __init__(self, type, host, user, password, db_path): |
... | ... | |
74 | 75 |
if self._DBType == 'SQLite': |
75 | 76 |
conn = sqlite3.connect(self.file_path, isolation_level=None) |
76 | 77 |
conn.row_factory = sqlite3.Row |
77 |
#cursor = conn.cursor() |
|
78 | 78 |
elif self._DBType == 'MSSQL': |
79 |
conn = pymssql.connect(host=self._host, user=self._user, password=self._password, database=self.db_name, charset='utf8', autocommit=False)
|
|
80 |
#cursor = conn.cursor(as_dic=True)
|
|
79 |
conn = pymssql.connect(host=self._host, user=self._user, password=self._password, database=self.db_name, |
|
80 |
charset='utf8', autocommit=False, as_dict=True)
|
|
81 | 81 |
|
82 | 82 |
return conn |
83 | 83 |
|
DTI_PID/DTI_PID/AppDocData.py | ||
---|---|---|
200 | 200 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
201 | 201 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
202 | 202 |
|
203 |
def set_occupying_drawing(self, drawing): |
|
203 |
def set_occupying_drawing(self, drawing) -> str:
|
|
204 | 204 |
""" set drawing access return true if success""" |
205 |
conn = self.project.database.connect() |
|
206 |
with conn: |
|
205 |
with self.project.database.connect() as conn: |
|
207 | 206 |
try: |
208 | 207 |
# Get a cursor object |
209 | 208 |
cursor = conn.cursor() |
210 |
sql = "select OCCUPIED from Drawings where [UID]='{}'".format(drawing)
|
|
209 |
sql = f"select OCCUPIED from Drawings where [UID]='{drawing}'"
|
|
211 | 210 |
cursor.execute(sql) |
212 | 211 |
|
213 | 212 |
rows = cursor.fetchall() |
214 |
if not rows[0][0] or rows[0][0] == os.environ['COMPUTERNAME']:
|
|
215 |
sql = "UPDATE Drawings SET [OCCUPIED]='{}' WHERE UID='{}'".format(os.environ['COMPUTERNAME'], drawing)
|
|
213 |
if not rows[0]['OCCUPIED'] or rows[0]['OCCUPIED'] == os.environ['COMPUTERNAME']:
|
|
214 |
sql = f"UPDATE Drawings SET [OCCUPIED]='{os.environ['COMPUTERNAME']}' WHERE UID='{drawing}'"
|
|
216 | 215 |
cursor.execute(sql) |
217 | 216 |
conn.commit() |
218 |
return True
|
|
217 |
return None
|
|
219 | 218 |
else: |
220 |
return False
|
|
219 |
return rows[0]['OCCUPIED']
|
|
221 | 220 |
|
222 | 221 |
# Catch the exception |
223 | 222 |
except Exception as ex: |
... | ... | |
227 | 226 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
228 | 227 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
229 | 228 |
|
230 |
return False
|
|
229 |
return None
|
|
231 | 230 |
|
232 | 231 |
''' |
233 | 232 |
@brief Get drawing file list |
... | ... | |
970 | 969 |
rows = cursor.fetchall() |
971 | 970 |
for row in rows: |
972 | 971 |
attr = SymbolAttr() |
973 |
attr.UID = row[0]
|
|
974 |
attr.Attribute = row[1]
|
|
975 |
attr.DisplayAttribute = row[2]
|
|
976 |
attr.AttributeType = row[3]
|
|
977 |
attr.Length = row[4]
|
|
972 |
attr.UID = row['UID']
|
|
973 |
attr.Attribute = row['Name']
|
|
974 |
attr.DisplayAttribute = row['DisplayName']
|
|
975 |
attr.AttributeType = row['Type']
|
|
976 |
attr.Length = row['LimitNumber']
|
|
978 | 977 |
attr.IsProp = 5 |
979 | 978 |
self._lineNoProperties.append(attr) |
980 | 979 |
|
... | ... | |
1046 | 1045 |
rows = cursor.fetchall() |
1047 | 1046 |
for row in rows: |
1048 | 1047 |
attr = SymbolAttr() |
1049 |
attr.UID = row[0]
|
|
1050 |
attr.Attribute = row[1]
|
|
1051 |
attr.DisplayAttribute = row[2]
|
|
1052 |
attr.AttributeType = row[3]
|
|
1053 |
attr.Length = row[4]
|
|
1048 |
attr.UID = row['UID']
|
|
1049 |
attr.Attribute = row['Name']
|
|
1050 |
attr.DisplayAttribute = row['DisplayName']
|
|
1051 |
attr.AttributeType = row['Type']
|
|
1052 |
attr.Length = row['LimitNumber']
|
|
1054 | 1053 |
attr.IsProp = 5 |
1055 | 1054 |
res.append(attr) |
1056 | 1055 |
self._lineNoPropertiesUID[UID] = res |
... | ... | |
1284 | 1283 |
cursor.execute(sql) |
1285 | 1284 |
rows = cursor.fetchall() |
1286 | 1285 |
for row in rows: |
1287 |
name = row[1]
|
|
1286 |
name = row['Key']
|
|
1288 | 1287 |
area = Area(name) |
1289 |
area.parse(row[2])
|
|
1288 |
area.parse(row['Value'])
|
|
1290 | 1289 |
self._areas.append(area) |
1291 | 1290 |
# Catch the exception |
1292 | 1291 |
except Exception as ex: |
... | ... | |
1325 | 1324 |
cursor.execute(sql) |
1326 | 1325 |
rows = cursor.fetchall() |
1327 | 1326 |
for row in rows: |
1328 |
self._configs.append(Config(row[0], row[1], row[2]))
|
|
1327 |
self._configs.append(Config(row['Section'], row['Key'], row['Value']))
|
|
1329 | 1328 |
# Catch the exception |
1330 | 1329 |
except Exception as ex: |
1331 | 1330 |
print('error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
... | ... | |
1639 | 1638 |
|
1640 | 1639 |
with self.project.database.connect() as conn: |
1641 | 1640 |
cursor = conn.cursor() |
1642 |
sql = self.project.database.to_sql(f"SELECT a.UID,a.Name,b.Type,a.Threshold,a.MinMatchPoint," |
|
1641 |
sql = self.project.database.to_sql(f"SELECT a.UID as UID,a.Name,b.Type,a.Threshold,a.MinMatchPoint,"
|
|
1643 | 1642 |
f"a.IsDetectOrigin,a.RotationCount,a.OCROption,a.IsContainChild," |
1644 | 1643 |
f"a.OriginalPoint,a.ConnectionPoint,a.BaseSymbol,a.AdditionalSymbol," |
1645 |
f"a.IsExceptDetect,a.HasInstrumentLabel,a.flip,a.TextArea,b.UID FROM " |
|
1644 |
f"a.IsExceptDetect,a.HasInstrumentLabel,a.flip,a.TextArea,b.UID as DB_UID FROM "
|
|
1646 | 1645 |
f"Symbol a inner join SymbolType b on a.SymbolType_UID=b.UID WHERE " |
1647 | 1646 |
f"a.{fieldName}=?") |
1648 | 1647 |
try: |
... | ... | |
1650 | 1649 |
rows = cursor.fetchall() |
1651 | 1650 |
if rows is not None and len(rows) > 0: |
1652 | 1651 |
symbolTuple = rows[0] |
1653 |
ret = symbol.SymbolBase(symbolTuple[1], symbolTuple[2], symbolTuple[3] |
|
1654 |
, symbolTuple[4], symbolTuple[5], symbolTuple[6], symbolTuple[7], |
|
1655 |
symbolTuple[8] |
|
1656 |
, symbolTuple[9], symbolTuple[10], symbolTuple[11], symbolTuple[12], |
|
1657 |
symbolTuple[13], symbolTuple[14], symbolTuple[0], iType=symbolTuple[17], |
|
1658 |
detectFlip=symbolTuple[15], text_area=symbolTuple[16]) ## uid is last item |
|
1652 |
ret = symbol.SymbolBase(symbolTuple['Name'], symbolTuple['Type'], symbolTuple['Threshold'] |
|
1653 |
, symbolTuple['MinMatchPoint'], symbolTuple['IsDetectOrigin'], |
|
1654 |
symbolTuple['RotationCount'], symbolTuple['OCROption'], |
|
1655 |
symbolTuple['IsContainChild'], symbolTuple['OriginalPoint'], |
|
1656 |
symbolTuple['ConnectionPoint'], symbolTuple['BaseSymbol'], |
|
1657 |
symbolTuple['AdditionalSymbol'], symbolTuple['IsExceptDetect'], |
|
1658 |
symbolTuple['HasInstrumentLabel'], symbolTuple['UID'], |
|
1659 |
iType=symbolTuple['DB_UID'], detectFlip=symbolTuple['flip'], |
|
1660 |
text_area=symbolTuple['TextArea']) |
|
1659 | 1661 |
self._symbolBase[fieldName][param] = ret |
1660 | 1662 |
except Exception as ex: |
1661 | 1663 |
print('error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
... | ... | |
1676 | 1678 |
if field_name is not None and param is not None: |
1677 | 1679 |
sql = """SELECT a.UID,a.Name,b.Type,a.Threshold,a.MinMatchPoint,a.IsDetectOrigin,a.RotationCount, |
1678 | 1680 |
a.OCROption,a.IsContainChild,a.OriginalPoint,a.ConnectionPoint,a.BaseSymbol,a.AdditionalSymbol, |
1679 |
a.IsExceptDetect,a.HasInstrumentLabel,a.flip,a.TextArea,b.UID FROM Symbol a |
|
1681 |
a.IsExceptDetect,a.HasInstrumentLabel,a.flip,a.TextArea,b.UID as DB_UID FROM Symbol a
|
|
1680 | 1682 |
inner join SymbolType b on a.SymbolType_UID=b.UID WHERE |
1681 | 1683 |
SymbolType_UID = (select UID from SymbolType where {}={})""".format( |
1682 | 1684 |
field_name, self.project.database.place_holder) |
... | ... | |
1690 | 1692 |
rows = cursor.fetchall() |
1691 | 1693 |
if rows is not None and len(rows) > 0: |
1692 | 1694 |
for symbolTuple in rows: |
1693 |
sym = symbol.SymbolBase(symbolTuple[1], symbolTuple[2], symbolTuple[3], symbolTuple[4] |
|
1694 |
, symbolTuple[5], symbolTuple[6], symbolTuple[7], symbolTuple[8], |
|
1695 |
symbolTuple[9] |
|
1696 |
, symbolTuple[10], symbolTuple[11], symbolTuple[12], symbolTuple[13], |
|
1697 |
symbolTuple[14], symbolTuple[0], iType=symbolTuple[17], |
|
1698 |
detectFlip=symbolTuple[15], text_area=symbolTuple[16]) ## uid is last item |
|
1695 |
sym = symbol.SymbolBase(symbolTuple['Name'], symbolTuple['Type'], symbolTuple['Threshold'], |
|
1696 |
symbolTuple['MinMatchPoint'], symbolTuple['IsDetectOrigin'], |
|
1697 |
symbolTuple['RotationCount'], symbolTuple['OCROption'], |
|
1698 |
symbolTuple['IsContainChild'], symbolTuple['OriginalPoint'], |
|
1699 |
symbolTuple['ConnectionPoint'], symbolTuple['BaseSymbol'], |
|
1700 |
symbolTuple['AdditionalSymbol'], symbolTuple['IsExceptDetect'], |
|
1701 |
symbolTuple['HasInstrumentLabel'], symbolTuple['UID'], |
|
1702 |
iType=symbolTuple['DB_UID'], |
|
1703 |
detectFlip=symbolTuple['flip'], text_area=symbolTuple['TextArea']) |
|
1699 | 1704 |
ret.append(sym) |
1700 | 1705 |
except Exception as ex: |
1701 | 1706 |
print('error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
... | ... | |
1723 | 1728 |
# Get a cursor object |
1724 | 1729 |
cursor = conn.cursor() |
1725 | 1730 |
|
1726 |
sql = "select UID,Code,Metric,Inch,InchStr,AllowableInchStr,MetricStr,AllowableMetricStr from NominalDiameter ORDER BY {} DESC".format(
|
|
1727 |
orderStr)
|
|
1731 |
sql = f"select UID,Code,Metric,Inch,InchStr,AllowableInchStr,MetricStr,AllowableMetricStr from " \
|
|
1732 |
f"NominalDiameter ORDER BY {orderStr} DESC"
|
|
1728 | 1733 |
cursor.execute(sql) |
1729 | 1734 |
rows = cursor.fetchall() |
1730 | 1735 |
for row in rows: |
1731 |
pipeSize = NominalPipeSize(row[0], row[1], float(row[2]) if row[2] else None, |
|
1732 |
float(row[3]) if row[3] else None, row[4], row[5], row[6], row[7]) |
|
1736 |
pipeSize = NominalPipeSize(row['UID'], row['Code'], float(row['Metric']) if row['Metric'] else None, |
|
1737 |
float(row['Inch']) if row['Inch'] else None, row['InchStr'], |
|
1738 |
row['AllowableInchStr'], row['MetricStr'], row['AllowableMetricStr']) |
|
1733 | 1739 |
pipeSize.sizeUnit = sizeUnit |
1734 | 1740 |
if forCheckLineNumber: |
1735 | 1741 |
if sizeUnit == 'Inch' and pipeSize.inchStr: |
... | ... | |
2143 | 2149 |
cursor = conn.cursor() |
2144 | 2150 |
|
2145 | 2151 |
sql = self.project.database.to_sql( |
2146 |
'select a.UID, a.Attribute, a.DisplayAttribute, a.AttributeType, a.[AttrAt], a.[Expression], a.[index], a.[Target], a.[Property] from SymbolAttribute a inner join SymbolType t on a.SymbolType_UID = t.UID and t.type = ? order by a.[index]') |
|
2152 |
'select a.UID, a.Attribute, a.DisplayAttribute, a.AttributeType, a.[AttrAt], a.[Expression], ' |
|
2153 |
'a.[index], a.[Target], a.[Property] from SymbolAttribute a inner join SymbolType t ' |
|
2154 |
'on a.SymbolType_UID = t.UID and t.type = ? order by a.[index]') |
|
2147 | 2155 |
param = (_type,) |
2148 | 2156 |
cursor.execute(sql, param) |
2149 | 2157 |
rows = cursor.fetchall() |
2150 | 2158 |
for row in rows: |
2151 | 2159 |
attr = SymbolAttr() |
2152 |
attr.UID = uuid.UUID(row[0])
|
|
2153 |
attr.Attribute = row[1]
|
|
2154 |
attr.DisplayAttribute = row[2]
|
|
2155 |
attr.AttributeType = row[3]
|
|
2156 |
attr.AttrAt = row[4]
|
|
2157 |
attr.Expression = row[5]
|
|
2158 |
attr.Target = row[7]
|
|
2159 |
attr.IsProp = row[8]
|
|
2160 |
attr.Codes = CodeTable.instance('SymbolAttributeCodeTable', symbol_attribute_uid=row[0])
|
|
2160 |
attr.UID = uuid.UUID(row['UID'])
|
|
2161 |
attr.Attribute = row['Attribute']
|
|
2162 |
attr.DisplayAttribute = row['DisplayAttribute']
|
|
2163 |
attr.AttributeType = row['AttributeType']
|
|
2164 |
attr.AttrAt = row['AttrAt']
|
|
2165 |
attr.Expression = row['Expression']
|
|
2166 |
attr.Target = row['Target']
|
|
2167 |
attr.IsProp = row['Property']
|
|
2168 |
attr.Codes = CodeTable.instance('SymbolAttributeCodeTable', symbol_attribute_uid=row['UID'])
|
|
2161 | 2169 |
result.append(attr) |
2162 | 2170 |
# Catch the exception |
2163 | 2171 |
except Exception as ex: |
... | ... | |
2181 | 2189 |
|
2182 | 2190 |
res = None |
2183 | 2191 |
|
2184 |
conn = self.project.database.connect() |
|
2185 |
with conn: |
|
2192 |
with self.project.database.connect() as conn: |
|
2186 | 2193 |
try: |
2187 | 2194 |
# Get a cursor object |
2188 | 2195 |
cursor = conn.cursor() |
2189 | 2196 |
|
2190 |
sql = 'select Attribute, DisplayAttribute, AttributeType, AttrAt, Expression, Target, Property from SymbolAttribute where uid = "{}"'.format(
|
|
2191 |
UID)
|
|
2197 |
sql = f"select Attribute, DisplayAttribute, AttributeType, AttrAt, Expression, Target, Property from " \
|
|
2198 |
f"SymbolAttribute where uid = '{UID}'"
|
|
2192 | 2199 |
cursor.execute(sql) |
2193 | 2200 |
rows = cursor.fetchall() |
2194 | 2201 |
if len(rows): |
2195 | 2202 |
res = SymbolAttr() |
2196 | 2203 |
res.UID = UID |
2197 |
res.Attribute = rows[0][0]
|
|
2198 |
res.DisplayAttribute = rows[0][1]
|
|
2199 |
res.AttributeType = rows[0][2]
|
|
2200 |
res.AttrAt = rows[0][3]
|
|
2201 |
res.Expression = rows[0][4]
|
|
2202 |
res.Target = rows[0][5]
|
|
2203 |
res.IsProp = row[0][6]
|
|
2204 |
res.Attribute = rows[0]['Attribute']
|
|
2205 |
res.DisplayAttribute = rows[0]['DisplayAttribute']
|
|
2206 |
res.AttributeType = rows[0]['AttributeType']
|
|
2207 |
res.AttrAt = rows[0]['AttrAt']
|
|
2208 |
res.Expression = rows[0]['Expression']
|
|
2209 |
res.Target = rows[0]['Target']
|
|
2210 |
res.IsProp = rows[0]['Property']
|
|
2204 | 2211 |
# Catch the exception |
2205 | 2212 |
except Exception as ex: |
2206 | 2213 |
from App import App |
... | ... | |
2260 | 2267 |
if attr[-1]: |
2261 | 2268 |
for code in attr[-1]: |
2262 | 2269 |
sql = self.project.database.to_sql( \ |
2263 |
"insert into SymbolAttributeCodeTable(UID, Code, Description, Allowables, SymbolAttribute_UID) VALUES(?,?,?,?,?)") |
|
2270 |
"insert into SymbolAttributeCodeTable(UID, Code, Description, Allowables, " |
|
2271 |
"SymbolAttribute_UID) VALUES(?,?,?,?,?)") |
|
2264 | 2272 |
param = (code[0], code[1], code[2], ','.join(code[3]), attr[0]) |
2265 | 2273 |
cursor.execute(sql, param) |
2266 | 2274 |
# up to here |
... | ... | |
2351 | 2359 |
'AttrAt, Expression, Target, [index], [Property]) values(?, ' |
2352 | 2360 |
'(select uid from SymbolType where Type=\'HMB\'), ?, ?, ?, ?, ?, ?, ?, ?)') |
2353 | 2361 |
params = (str(attr.UID), attr.Attribute, attr.Attribute, 'String', attr.AttrAt, |
2354 |
attr.Expression, attr.Target, idx, attr.IsProp) |
|
2362 |
attr.Expression if attr.Expression else None, attr.Target, idx, attr.IsProp)
|
|
2355 | 2363 |
|
2356 | 2364 |
cursor.execute(sql, params) |
2357 | 2365 |
# up to here |
... | ... | |
2421 | 2429 |
@date 2018.08.14 |
2422 | 2430 |
''' |
2423 | 2431 |
def saveLineAttributes(self, attrs): |
2424 |
conn = self.project.database.connect() |
|
2425 |
with conn: |
|
2432 |
with self.project.database.connect() as conn: |
|
2426 | 2433 |
try: |
2427 | 2434 |
# Get a cursor object |
2428 | 2435 |
cursor = conn.cursor() |
... | ... | |
2458 | 2465 |
def getSymbolTypeId(self, symbolType): |
2459 | 2466 |
result = [] |
2460 | 2467 |
|
2461 |
conn = self.project.database.connect() |
|
2462 |
with conn: |
|
2468 |
with self.project.database.connect() as conn: |
|
2463 | 2469 |
try: |
2464 | 2470 |
# Get a cursor object |
2465 | 2471 |
cursor = conn.cursor() |
... | ... | |
2470 | 2476 |
rows = cursor.fetchall() |
2471 | 2477 |
|
2472 | 2478 |
if len(rows): |
2473 |
result = rows[0][0]
|
|
2479 |
result = rows[0]['UID']
|
|
2474 | 2480 |
else: |
2475 | 2481 |
result = -1 |
2476 | 2482 |
# Catch the exception |
... | ... | |
2488 | 2494 |
|
2489 | 2495 |
def getCodeTable(self, property, forCheckLineNumber=False, symbol_attribute_uid=None, custom_table_uid=None, custom=False): |
2490 | 2496 |
result = [] |
2491 |
conn = self.project.database.connect() |
|
2492 |
with conn: |
|
2497 |
with self.project.database.connect() as conn: |
|
2493 | 2498 |
try: |
2494 | 2499 |
# Get a cursor object |
2495 | 2500 |
cursor = conn.cursor() |
2496 | 2501 |
|
2497 | 2502 |
if property.upper().replace(' ', '') == "NOMINALDIAMETER" and forCheckLineNumber: |
2498 |
sql = 'select InchStr, MetricStr from [{}] order by Metric ASC'.format(property) |
|
2503 |
cols = ['InchStr', 'MetricStr'] |
|
2504 |
sql = f"select {cols[0]}, {cols[1]} from [{property}] order by Metric ASC" |
|
2499 | 2505 |
cursor.execute(sql) |
2500 | 2506 |
rows = cursor.fetchall() |
2501 | 2507 |
for index in range(2): |
2502 | 2508 |
for row in rows: |
2503 |
if row[index] != '' and result.count(row[index].replace("'", '"')) == 0:
|
|
2504 |
result.append(row[index].replace("'", '"'))
|
|
2509 |
if row[cols[index]] != '' and result.count(row[cols[index]].replace("'", '"')) == 0:
|
|
2510 |
result.append(row[cols[index]].replace("'", '"'))
|
|
2505 | 2511 |
else: |
2506 | 2512 |
""" |
2507 | 2513 |
sql = "select name from sqlite_master where type='table'"# AND name={}".format(property) |
... | ... | |
2512 | 2518 |
if not symbol_attribute_uid and not custom_table_uid and not custom: |
2513 | 2519 |
sql = 'select uid, code, description, Allowables from [{}] order by code DESC'.format(property) |
2514 | 2520 |
elif symbol_attribute_uid and not custom_table_uid: |
2515 |
sql = "select uid, code, description, Allowables from [{}] where SymbolAttribute_UID='{}' order by code DESC".format(property, symbol_attribute_uid) |
|
2521 |
sql = "select uid, code, description, Allowables from [{}] where SymbolAttribute_UID='{}' " \ |
|
2522 |
"order by code DESC".format(property, symbol_attribute_uid) |
|
2516 | 2523 |
elif not symbol_attribute_uid and custom_table_uid: |
2517 |
sql = "select uid, code, description, Allowables from [{}] where Table_UID='{}' order by code DESC".format(property, custom_table_uid) |
|
2524 |
sql = "select uid, code, description, Allowables from [{}] where Table_UID='{}' " \ |
|
2525 |
"order by code DESC".format(property, custom_table_uid) |
|
2518 | 2526 |
elif custom: |
2519 | 2527 |
sql = "select uid, code, description, Allowables from CustomCodes \ |
2520 | 2528 |
where table_uid = (select uid from CustomTables where upper(name) like upper('{}'))".format(property) |
... | ... | |
2522 | 2530 |
rows = cursor.fetchall() |
2523 | 2531 |
for row in rows: |
2524 | 2532 |
if forCheckLineNumber: |
2525 |
data = row[1]
|
|
2533 |
data = row['code']
|
|
2526 | 2534 |
else: |
2527 |
data = (row[0], row[1], row[2], row[3])
|
|
2535 |
data = (row['uid'], row['code'], row['description'], row['Allowables'])
|
|
2528 | 2536 |
result.append(data) |
2529 | 2537 |
# else: |
2530 | 2538 |
# result = None |
... | ... | |
2990 | 2998 |
""" get document name list """ |
2991 | 2999 |
result = [] |
2992 | 3000 |
|
2993 |
conn = self.project.database.connect() |
|
2994 |
with conn: |
|
3001 |
with self.project.database.connect() as conn: |
|
2995 | 3002 |
try: |
2996 | 3003 |
# Get a cursor object |
2997 | 3004 |
cursor = conn.cursor() |
2998 | 3005 |
|
2999 |
sql = "select distinct B.Name as 'Drawing_Name' from Components A join Drawings B on A.Drawings_UID=B.UID" |
|
3006 |
sql = "select distinct B.Name as 'Drawing_Name' from Components A join Drawings B on " \ |
|
3007 |
"A.Drawings_UID=B.UID" |
|
3000 | 3008 |
cursor.execute(sql) |
3001 | 3009 |
|
3002 | 3010 |
rows = cursor.fetchall() |
3003 | 3011 |
for row in rows: |
3004 |
result.append(row[0])
|
|
3012 |
result.append(row['Drawing_Name'])
|
|
3005 | 3013 |
|
3006 | 3014 |
result.sort() |
3007 | 3015 |
# Catch the exception |
... | ... | |
3288 | 3296 |
if not hasattr(self, '_valve_attributes'): |
3289 | 3297 |
self._valve_attributes = [] |
3290 | 3298 |
|
3291 |
conn = self.project.database.connect() |
|
3292 |
with conn: |
|
3299 |
with self.project.database.connect() as conn: |
|
3293 | 3300 |
try: |
3294 | 3301 |
# Get a cursor object |
3295 | 3302 |
cursor = conn.cursor() |
3296 | 3303 |
|
3297 |
sql = "select distinct A.Attribute from SymbolAttribute A join SymbolType B on A.SymbolType_UID=B.UID " \
|
|
3298 |
"where B.Category = 'Piping'" |
|
3304 |
sql = "select distinct A.Attribute from SymbolAttribute A join SymbolType B on " \ |
|
3305 |
"A.SymbolType_UID=B.UID where B.Category = 'Piping'"
|
|
3299 | 3306 |
cursor.execute(sql) |
3300 | 3307 |
rows = cursor.fetchall() |
3301 | 3308 |
for row in rows: |
3302 | 3309 |
attr = SymbolAttr() |
3303 |
attr.Attribute = row[0]
|
|
3310 |
attr.Attribute = row['Attribute']
|
|
3304 | 3311 |
self._valve_attributes.append(attr) |
3305 | 3312 |
|
3306 | 3313 |
res = self._valve_attributes |
... | ... | |
3368 | 3375 |
# Get a cursor object |
3369 | 3376 |
cursor = conn.cursor() |
3370 | 3377 |
|
3371 |
sql = "select distinct A.Attribute from SymbolAttribute A join SymbolType B on A.SymbolType_UID=B.UID " \
|
|
3372 |
"where B.Category = 'Instrumentation'" |
|
3378 |
sql = "select distinct A.Attribute from SymbolAttribute A join SymbolType B on " \ |
|
3379 |
"A.SymbolType_UID=B.UID where B.Category = 'Instrumentation'"
|
|
3373 | 3380 |
cursor.execute(sql) |
3374 | 3381 |
rows = cursor.fetchall() |
3375 | 3382 |
for row in rows: |
3376 | 3383 |
attr = SymbolAttr() |
3377 |
attr.Attribute = row[0]
|
|
3384 |
attr.Attribute = row['Attribute']
|
|
3378 | 3385 |
self._inst_attributes.append(attr) |
3379 | 3386 |
|
3380 | 3387 |
res = self._inst_attributes |
... | ... | |
3440 | 3447 |
if not hasattr(self, '_note_attributes'): |
3441 | 3448 |
self._note_attributes = [] |
3442 | 3449 |
|
3443 |
conn = self.project.database.connect() |
|
3444 |
with conn: |
|
3450 |
with self.project.database.connect() as conn: |
|
3445 | 3451 |
try: |
3446 | 3452 |
# Get a cursor object |
3447 | 3453 |
cursor = conn.cursor() |
3448 | 3454 |
|
3449 |
sql = "select distinct A.Attribute from SymbolAttribute A join SymbolType B on A.SymbolType_UID=B.UID " \
|
|
3450 |
"where B.Category='General' and B.Type='Notes'" |
|
3455 |
sql = "select distinct A.Attribute from SymbolAttribute A join SymbolType B on " \ |
|
3456 |
"A.SymbolType_UID=B.UID where B.Category='General' and B.Type='Notes'"
|
|
3451 | 3457 |
cursor.execute(sql) |
3452 | 3458 |
rows = cursor.fetchall() |
3453 | 3459 |
for row in rows: |
3454 | 3460 |
attr = SymbolAttr() |
3455 |
attr.Attribute = row[0]
|
|
3461 |
attr.Attribute = row['Attribute']
|
|
3456 | 3462 |
self._note_attributes.append(attr) |
3457 | 3463 |
|
3458 | 3464 |
res = self._note_attributes |
... | ... | |
3768 | 3774 |
cursor.execute(sql) |
3769 | 3775 |
rows = cursor.fetchall() |
3770 | 3776 |
for row in rows: |
3771 |
symbolTypeList.append((row[0], row[1], row[2])) # UID, category, type
|
|
3777 |
symbolTypeList.append((row['UID'], row['Category'], row['Type'])) # UID, category, type
|
|
3772 | 3778 |
except Exception as ex: |
3773 | 3779 |
from App import App |
3774 | 3780 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
... | ... | |
3795 | 3801 |
cursor.execute(sql, (type,)) |
3796 | 3802 |
rows = cursor.fetchall() |
3797 | 3803 |
if rows is not None and len(rows) > 0: |
3798 |
category = rows[0][0]
|
|
3804 |
category = rows[0]['Category']
|
|
3799 | 3805 |
self._symbolType[type] = category |
3800 | 3806 |
except Exception as ex: |
3801 | 3807 |
print('error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
DTI_PID/DTI_PID/Commands/PlaceLineCommand.py | ||
---|---|---|
72 | 72 |
self._line_type = selected.parentItem().lineType |
73 | 73 |
elif issubclass(type(selected.parentItem()), SymbolSvgItem): |
74 | 74 |
for idx, conn in enumerate(selected.parentItem().connectors): |
75 |
if selected is conn and selected.parentItem().conn_type:
|
|
75 |
if selected is conn and len(selected.parentItem().conn_type) > idx:
|
|
76 | 76 |
self._line_type = selected.parentItem().conn_type[idx] |
77 | 77 |
break |
78 | 78 |
# up to here |
DTI_PID/DTI_PID/HMBDialog.py | ||
---|---|---|
5 | 5 |
import os |
6 | 6 |
import sys |
7 | 7 |
|
8 |
sys.path.insert(0, os.path.dirname(os.path.realpath(__file__)) + '\\Commands')
|
|
8 |
sys.path.insert(0, os.path.join(os.path.dirname(os.path.realpath(__file__)), 'Commands'))
|
|
9 | 9 |
import FenceCommand |
10 | 10 |
|
11 | 11 |
from PyQt5.QtCore import * |
12 | 12 |
from PyQt5.QtGui import * |
13 | 13 |
from PyQt5.QtWidgets import * |
14 |
import sqlite3 |
|
14 |
import openpyxl |
|
15 |
from openpyxl.styles import * |
|
15 | 16 |
|
16 | 17 |
from AppDocData import AppDocData, Config |
17 | 18 |
|
18 |
sys.path.insert(0, os.path.dirname(os.path.realpath(__file__)) + '\\Shapes')
|
|
19 |
sys.path.insert(0, os.path.join(os.path.dirname(os.path.realpath(__file__)), 'Shapes'))
|
|
19 | 20 |
from GraphicsBoundingBoxItem import QGraphicsBoundingBoxItem |
20 | 21 |
|
21 | 22 |
|
... | ... | |
53 | 54 |
from TableWidgetEx import QTableWidgetEx |
54 | 55 |
|
55 | 56 |
QDialog.__init__(self, parent) |
56 |
self.ui = Ui_HMBDialog() |
|
57 |
self.ui.setupUi(self) |
|
58 |
self.ui.tableWidgetHMBRecord = QTableWidgetEx(self.ui.groupBoxHMBRecord) |
|
59 |
self.ui.horizontalLayoutHMBColTableWidget.addWidget(self.ui.tableWidgetHMBRecord) |
|
60 |
|
|
61 |
self.ui.tableWidgetHMBData = QTableWidget(self.ui.groupBoxHMBData) |
|
62 |
self.ui.horizontalLayoutHMBTableWidget.addWidget(self.ui.tableWidgetHMBData) |
|
63 |
|
|
64 |
self.ui.tableWidgetHMBRecord.setColumnCount(3) |
|
65 |
self.ui.tableWidgetHMBRecord.setHorizontalHeaderLabels(['UID', 'Name', 'Unit']) |
|
66 |
self.ui.tableWidgetHMBRecord.horizontalHeaderItem(0).setSizeHint(QSize(25, 25)) |
|
67 |
|
|
68 |
# add splitter widget |
|
69 |
splitter = QSplitter(Qt.Vertical) |
|
70 |
splitter.addWidget(self.ui.groupBoxHMBRecord) |
|
71 |
splitter.addWidget(self.ui.groupBoxHMBData) |
|
72 |
self.ui.verticalLayoutHMB.addWidget(splitter) |
|
73 |
|
|
74 |
self.ui.lineEditHMBArea.tag = None |
|
75 |
|
|
76 |
self.ui.pushButtonAddRecord.clicked.connect(self.onAddRecord) |
|
77 |
self.ui.pushButtonDelRecord.clicked.connect(self.onDelRecord) |
|
78 |
self.ui.pushButtonHMBArea.clicked.connect(self.onSelectHMBArea) |
|
79 |
self.ui.pushButtonRecognizeText.clicked.connect(self.onRecognizeText) |
|
80 |
self.ui.pushButtonAddHMBData.clicked.connect(self.on_add_hmb_data) |
|
81 |
self.ui.pushButtonDelHMBData.clicked.connect(self.onDelHMBData) |
|
82 |
|
|
83 |
self._cmd = FenceCommand.FenceCommand(self.parent().graphicsView) |
|
84 |
self._cmd.onSuccess.connect(self.onAreaSelected) |
|
85 |
|
|
86 |
app_doc_data = AppDocData.instance() |
|
87 |
attrs = app_doc_data.get_hmb_attributes() |
|
88 |
configs = app_doc_data.getConfigs('HMB Record', 'Count') |
|
89 |
rows = len(attrs) |
|
90 |
self.ui.tableWidgetHMBRecord.setRowCount(rows) |
|
91 |
for row in range(rows): |
|
92 |
self.ui.tableWidgetHMBRecord.setItem(row, 0, QTableWidgetItem(str(attrs[row].UID))) |
|
93 |
self.ui.tableWidgetHMBRecord.setItem(row, 1, QTableWidgetItem(attrs[row].Attribute)) |
|
94 |
self.ui.tableWidgetHMBRecord.setItem(row, 2, QTableWidgetItem(attrs[row].Expression)) |
|
95 |
self.ui.tableWidgetHMBRecord.hideColumn(0) # hide UID |
|
96 |
self.ui.tableWidgetHMBRecord.horizontalHeader().setSectionResizeMode(1, QHeaderView.ResizeToContents) |
|
97 |
|
|
98 |
configs = app_doc_data.getConfigs('HMB Data', 'Column Width') |
|
99 |
self.ui.lineEditColumnWidth.setText(configs[0].value if 1 == len(configs) else '0') |
|
100 |
configs = app_doc_data.getConfigs('HMB Data', 'Row Height') |
|
101 |
self.ui.lineEditRowHeight.setText(configs[0].value if 1 == len(configs) else '0') |
|
102 |
configs = app_doc_data.getConfigs('HMB Data', 'Record Direction') |
|
103 |
if 0 == len(configs) or 'Horizontal' == configs[0].value: |
|
104 |
self.ui.radioButtonHorizontal.setChecked(True) |
|
105 |
self.ui.radioButtonVertical.setChecked(False) |
|
106 |
else: |
|
107 |
self.ui.radioButtonHorizontal.setChecked(False) |
|
108 |
self.ui.radioButtonVertical.setChecked(True) |
|
109 |
|
|
110 |
self.ui.tableWidgetHMBData.setColumnCount(2) |
|
111 |
self.ui.tableWidgetHMBData.setRowCount(self.ui.tableWidgetHMBRecord.rowCount()) |
|
112 |
for row in range(self.ui.tableWidgetHMBData.rowCount()): |
|
113 |
uid = self.ui.tableWidgetHMBRecord.item(row, 0).text() |
|
114 |
name = self.ui.tableWidgetHMBRecord.item(row, 1).text() |
|
115 |
item = QTableWidgetItem(name) |
|
116 |
item.setData(Qt.UserRole, uid) |
|
117 |
item.setFlags(Qt.ItemIsEnabled) |
|
118 |
item.setBackground(QColor(220, 220, 220)) |
|
119 |
self.ui.tableWidgetHMBData.setItem(row, 0, item) |
|
120 |
unit = self.ui.tableWidgetHMBRecord.item(row, 2).text() |
|
121 |
item = QTableWidgetItem(unit) |
|
122 |
item.setFlags(Qt.ItemIsEnabled) |
|
123 |
item.setBackground(QColor(220, 220, 220)) |
|
124 |
self.ui.tableWidgetHMBData.setItem(row, 1, item) |
|
125 |
|
|
126 |
# display HMB Data |
|
127 |
fixedCols = self.ui.tableWidgetHMBRecord.columnCount() - 1 |
|
128 |
streamNos = sorted(list(app_doc_data.hmbTable.streamNos())) |
|
129 |
self.ui.tableWidgetHMBData.setColumnCount(fixedCols + len(streamNos)) |
|
130 |
for col in range(2, self.ui.tableWidgetHMBData.columnCount()): |
|
131 |
stream_no = streamNos[col - 2] |
|
132 |
datas = app_doc_data.hmbTable.dataOfStreamNo(stream_no) |
|
57 |
try: |
|
58 |
self.ui = Ui_HMBDialog() |
|
59 |
self.ui.setupUi(self) |
|
60 |
self.ui.tableWidgetHMBRecord = QTableWidgetEx(self.ui.groupBoxHMBRecord) |
|
61 |
self.ui.horizontalLayoutHMBColTableWidget.addWidget(self.ui.tableWidgetHMBRecord) |
|
62 |
|
|
63 |
self.ui.tableWidgetHMBData = QTableWidget(self.ui.groupBoxHMBData) |
|
64 |
self.ui.horizontalLayoutHMBTableWidget.addWidget(self.ui.tableWidgetHMBData) |
|
65 |
|
|
66 |
self.ui.tableWidgetHMBRecord.setColumnCount(3) |
|
67 |
self.ui.tableWidgetHMBRecord.setHorizontalHeaderLabels(['UID', 'Name', 'Unit']) |
|
68 |
self.ui.tableWidgetHMBRecord.horizontalHeaderItem(0).setSizeHint(QSize(25, 25)) |
|
69 |
|
|
70 |
# add splitter widget |
|
71 |
splitter = QSplitter(Qt.Vertical) |
|
72 |
splitter.addWidget(self.ui.groupBoxHMBRecord) |
|
73 |
splitter.addWidget(self.ui.groupBoxHMBData) |
|
74 |
self.ui.verticalLayoutHMB.addWidget(splitter) |
|
75 |
|
|
76 |
self.ui.lineEditHMBArea.tag = None |
|
77 |
|
|
78 |
self.ui.pushButtonAddRecord.clicked.connect(self.onAddRecord) |
|
79 |
self.ui.pushButtonDelRecord.clicked.connect(self.onDelRecord) |
|
80 |
self.ui.pushButtonHMBArea.clicked.connect(self.onSelectHMBArea) |
|
81 |
self.ui.pushButtonRecognizeText.clicked.connect(self.onRecognizeText) |
|
82 |
self.ui.pushButtonAddHMBData.clicked.connect(self.on_add_hmb_data) |
|
83 |
self.ui.pushButtonDelHMBData.clicked.connect(self.onDelHMBData) |
|
84 |
self.ui.pushButtonOpenXls.clicked.connect(self.on_open_excel) |
|
133 | 85 |
|
86 |
self._cmd = FenceCommand.FenceCommand(self.parent().graphicsView) |
|
87 |
self._cmd.onSuccess.connect(self.onAreaSelected) |
|
88 |
|
|
89 |
app_doc_data = AppDocData.instance() |
|
90 |
attrs = app_doc_data.get_hmb_attributes() |
|
91 |
configs = app_doc_data.getConfigs('HMB Record', 'Count') |
|
92 |
rows = len(attrs) |
|
93 |
self.ui.tableWidgetHMBRecord.setRowCount(rows) |
|
94 |
for row in range(rows): |
|
95 |
self.ui.tableWidgetHMBRecord.setItem(row, 0, QTableWidgetItem(str(attrs[row].UID))) |
|
96 |
self.ui.tableWidgetHMBRecord.setItem(row, 1, QTableWidgetItem(attrs[row].Attribute)) |
|
97 |
self.ui.tableWidgetHMBRecord.setItem(row, 2, QTableWidgetItem(attrs[row].Expression)) |
|
98 |
self.ui.tableWidgetHMBRecord.hideColumn(0) # hide UID |
|
99 |
self.ui.tableWidgetHMBRecord.horizontalHeader().setSectionResizeMode(1, QHeaderView.ResizeToContents) |
|
100 |
|
|
101 |
configs = app_doc_data.getConfigs('HMB Data', 'Column Width') |
|
102 |
self.ui.lineEditColumnWidth.setText(configs[0].value if 1 == len(configs) else '0') |
|
103 |
configs = app_doc_data.getConfigs('HMB Data', 'Row Height') |
|
104 |
self.ui.lineEditRowHeight.setText(configs[0].value if 1 == len(configs) else '0') |
|
105 |
configs = app_doc_data.getConfigs('HMB Data', 'Record Direction') |
|
106 |
if 0 == len(configs) or 'Horizontal' == configs[0].value: |
|
107 |
self.ui.radioButtonHorizontal.setChecked(True) |
|
108 |
self.ui.radioButtonVertical.setChecked(False) |
|
109 |
else: |
|
110 |
self.ui.radioButtonHorizontal.setChecked(False) |
|
111 |
self.ui.radioButtonVertical.setChecked(True) |
|
112 |
|
|
113 |
self.ui.tableWidgetHMBData.setColumnCount(2) |
|
114 |
self.ui.tableWidgetHMBData.setRowCount(self.ui.tableWidgetHMBRecord.rowCount()) |
|
134 | 115 |
for row in range(self.ui.tableWidgetHMBData.rowCount()): |
135 |
matches = [data for data in datas if data.name == self.ui.tableWidgetHMBData.item(row, 0).text()] |
|
136 |
if matches: |
|
137 |
item = QTableWidgetItem(matches[0].value) |
|
138 |
item.setData(Qt.UserRole, matches[0]) |
|
139 |
self.ui.tableWidgetHMBData.setItem(row, col, item) |
|
116 |
uid = self.ui.tableWidgetHMBRecord.item(row, 0).text() |
|
117 |
name = self.ui.tableWidgetHMBRecord.item(row, 1).text() |
|
118 |
item = QTableWidgetItem(name) |
|
119 |
item.setData(Qt.UserRole, uid) |
|
120 |
item.setFlags(Qt.ItemIsEnabled) |
|
121 |
item.setBackground(QColor(220, 220, 220)) |
|
122 |
self.ui.tableWidgetHMBData.setItem(row, 0, item) |
|
123 |
unit = self.ui.tableWidgetHMBRecord.item(row, 2).text() |
|
124 |
item = QTableWidgetItem(unit) |
|
125 |
item.setFlags(Qt.ItemIsEnabled) |
|
126 |
item.setBackground(QColor(220, 220, 220)) |
|
127 |
self.ui.tableWidgetHMBData.setItem(row, 1, item) |
|
128 |
|
|
129 |
# display HMB Data |
|
130 |
fixedCols = self.ui.tableWidgetHMBRecord.columnCount() - 1 |
|
131 |
streamNos = sorted(list(app_doc_data.hmbTable.streamNos())) |
|
132 |
|
|
133 |
stream_datas = {} |
|
134 |
for stream_no in streamNos: |
|
135 |
stream_datas[stream_no] = app_doc_data.hmbTable.dataOfStreamNo(stream_no) |
|
136 |
|
|
137 |
self.ui.tableWidgetHMBData.setColumnCount(fixedCols + len(streamNos)) |
|
138 |
self.ui.tableWidgetHMBData.setHorizontalHeaderLabels(['Name', 'Unit'] + streamNos) |
|
139 |
self.display_stream_data(stream_datas) |
|
140 |
self.ui.tableWidgetHMBData.horizontalHeader().setSectionResizeMode(0, QHeaderView.ResizeToContents) |
|
141 |
# up to here |
|
142 |
self.ui.tableWidgetHMBData.cellChanged.connect(self.cellValueChanged) # connect to slot after setting data |
|
143 |
except Exception as ex: |
|
144 |
from App import App |
|
145 |
from AppDocData import MessageType |
|
140 | 146 |
|
141 |
self.ui.tableWidgetHMBData.setHorizontalHeaderLabels(['Name', 'Unit'] + streamNos) |
|
142 |
self.ui.tableWidgetHMBData.horizontalHeader().setSectionResizeMode(0, QHeaderView.ResizeToContents) |
|
143 |
# up to here |
|
144 |
self.ui.tableWidgetHMBData.cellChanged.connect(self.cellValueChanged) # connect to slot after setting data |
|
147 |
message = f"error occurred({repr(ex)}) in {sys.exc_info()[-1].tb_frame.f_code.co_filename}:" \ |
|
148 |
f"{sys.exc_info()[-1].tb_lineno}" |
|
149 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
|
145 | 150 |
|
146 | 151 |
''' |
147 | 152 |
@brief cellValueChange event |
... | ... | |
184 | 189 |
continue |
185 | 190 |
item = self.ui.tableWidgetHMBData.item(_row, column) |
186 | 191 |
if item is not None: |
187 |
data = item.data(Qt.UserRole) |
|
188 |
data.stream_no = data.stream_no |
|
192 |
_data = item.data(Qt.UserRole)
|
|
193 |
data.stream_no = _data.stream_no
|
|
189 | 194 |
break |
190 | 195 |
except Exception as ex: |
191 | 196 |
print('error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
... | ... | |
291 | 296 |
print('error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
292 | 297 |
sys.exc_info()[-1].tb_lineno)) |
293 | 298 |
|
299 |
def display_stream_data(self, stream_datas): |
|
300 |
"""display stream data""" |
|
301 |
for col in range(2, self.ui.tableWidgetHMBData.columnCount()): |
|
302 |
stream_no = self.ui.tableWidgetHMBData.horizontalHeaderItem(col).text() |
|
303 |
for row in range(self.ui.tableWidgetHMBData.rowCount()): |
|
304 |
name = self.ui.tableWidgetHMBData.item(row, 0).text() |
|
305 |
matches = [data for data in stream_datas[stream_no] if data.name.upper() == name.upper()] |
|
306 |
if matches and matches[0].value: |
|
307 |
item = QTableWidgetItem(matches[0].value) |
|
308 |
item.setData(Qt.UserRole, matches[0]) |
|
309 |
self.ui.tableWidgetHMBData.setItem(row, col, item) |
|
310 |
|
|
311 |
def on_open_excel(self): |
|
312 |
"""read hmb data from selected excel file""" |
|
313 |
from HMBTable import HMBData |
|
314 |
|
|
315 |
try: |
|
316 |
project = AppDocData.instance().getCurrentProject() |
|
317 |
|
|
318 |
options = QFileDialog.Options() |
|
319 |
options |= QFileDialog.DontUseNativeDialog |
|
320 |
selected, _ = QFileDialog.getOpenFileNames(self, self.tr('Import', "Select HMB File"), |
|
321 |
project.getTempPath(), "excel files (*.xlsx)", options=options) |
|
322 |
if selected: |
|
323 |
book = openpyxl.load_workbook(selected[0]) |
|
324 |
sheet = book.active |
|
325 |
max_row = sheet.max_row |
|
326 |
max_column = sheet.max_column |
|
327 |
|
|
328 |
stream_datas = {} |
|
329 |
for col in range(3, max_column + 1): |
|
330 |
datas, stream_no = [], None |
|
331 |
for row in range(1, max_row + 1): |
|
332 |
name = sheet.cell(row=row, column=1).value |
|
333 |
value = sheet.cell(row=row, column=col).value |
|
334 |
if value: |
|
335 |
if name == 'STREAM NO': |
|
336 |
stream_no = str(value) |
|
337 |
|
|
338 |
data = HMBData() |
|
339 |
data.name, data.value = name, str(value) |
|
340 |
datas.append(data) |
|
341 |
|
|
342 |
if stream_no: |
|
343 |
for data in datas: |
|
344 |
data.stream_no = stream_no |
|
345 |
stream_datas[stream_no] = datas |
|
346 |
|
|
347 |
self.ui.tableWidgetHMBData.setColumnCount(2) |
|
348 |
self.ui.tableWidgetHMBData.setColumnCount(2 + len(stream_datas.keys())) |
|
349 |
self.ui.tableWidgetHMBData.setHorizontalHeaderLabels(['Name', 'Unit'] + list(stream_datas.keys())) |
|
350 |
self.display_stream_data(stream_datas) |
|
351 |
except Exception as ex: |
|
352 |
from App import App |
|
353 |
from AppDocData import MessageType |
|
354 |
|
|
355 |
message = f"error occurred({repr(ex)}) in {sys.exc_info()[-1].tb_frame.f_code.co_filename}:" \ |
|
356 |
f"{sys.exc_info()[-1].tb_lineno}" |
|
357 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
|
358 |
|
|
294 | 359 |
''' |
295 | 360 |
@brief recognize text in selected area |
296 | 361 |
@author humkyung |
DTI_PID/DTI_PID/HMBTable.py | ||
---|---|---|
101 | 101 |
def from_row(row): |
102 | 102 |
"""create hmb data from database record""" |
103 | 103 |
hmb = HMBData() |
104 |
hmb._uid = row[0]
|
|
105 |
hmb._stream_no = row[1]
|
|
106 |
hmb._name = row[2]
|
|
107 |
hmb._unit = row[3]
|
|
108 |
hmb._value = row[4]
|
|
104 |
hmb._uid = row['UID']
|
|
105 |
hmb._stream_no = row['STREAM_NO']
|
|
106 |
hmb._name = row['Name']
|
|
107 |
hmb._unit = row['UNIT']
|
|
108 |
hmb._value = row['VALUE']
|
|
109 | 109 |
|
110 | 110 |
return hmb |
111 | 111 |
|
... | ... | |
124 | 124 |
self._hmbs = [] |
125 | 125 |
|
126 | 126 |
app_doc_data = AppDocData.instance() |
127 |
db_path = os.path.join(app_doc_data.getCurrentProject().getDbFilePath(), 'ITI_PID.db') |
|
128 |
|
|
129 |
with sqlite3.connect(db_path) as conn: |
|
127 |
with app_doc_data.getCurrentProject().database.connect() as conn: |
|
130 | 128 |
cursor = conn.cursor() |
131 | 129 |
sql = 'SELECT A.UID,A.STREAM_NO,B.Attribute as Name,A.UNIT,A.VALUE FROM HMB A join ' \ |
132 | 130 |
'SymbolAttribute B on A.SymbolAttribute_UID=B.UID ORDER BY A.STREAM_NO' |
... | ... | |
137 | 135 |
self._hmbs.append(hmb) |
138 | 136 |
# Catch the exception |
139 | 137 |
except Exception as ex: |
140 |
# Roll back any change if something goes wrong |
|
141 |
conn.rollback() |
|
142 |
print('error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
|
138 |
from App import App |
|
139 |
from AppDocData import MessageType |
|
140 |
|
|
141 |
message = f"error occurred({repr(ex)}) in {sys.exc_info()[-1].tb_frame.f_code.co_filename}:" \ |
|
142 |
f"{sys.exc_info()[-1].tb_lineno}" |
|
143 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
|
143 | 144 |
|
144 | 145 |
return self._hmbs |
145 | 146 |
|
... | ... | |
161 | 162 |
f"values(?,?,?," \ |
162 | 163 |
f"(select A.UID from SymbolAttribute A join SymbolType B on " \ |
163 | 164 |
f"A.SymbolType_UID=B.UID " \ |
164 |
f"where B.Type='HMB' and A.Attribute='{data.name}'),?,?)"
|
|
165 |
f"where B.Type='HMB' and upper(A.Attribute)=upper('{data.name}')),?,?)"
|
|
165 | 166 |
param = (str(uuid.uuid4()), data.stream_no, data.name, data.unit, data.value) |
166 |
cursor.execute(sql, param)
|
|
167 |
cursor.execute(app_doc_data.getCurrentProject().database.to_sql(sql), param)
|
|
167 | 168 |
else: |
168 | 169 |
sql = f"update HMB set STREAM_NO=?,NAME=?," \ |
169 | 170 |
f"SymbolAttribute_UID=" \ |
170 | 171 |
f"(select A.UID from SymbolAttribute A join SymbolType B on A.SymbolType_UID=B.UID " \ |
171 |
f"where B.Type='HMB' and A.Attribute='{data.name}'),UNIT=?,VALUE=? where UID=?" |
|
172 |
f"where B.Type='HMB' and upper(A.Attribute)=upper('{data.name}')),UNIT=?," \ |
|
173 |
f"VALUE=? where UID=?" |
|
172 | 174 |
param = (data.stream_no, data.name, data.unit, data.value, data.uid) |
173 |
cursor.execute(sql, param)
|
|
175 |
cursor.execute(app_doc_data.getCurrentProject().database.to_sql(sql), param)
|
|
174 | 176 |
else: |
175 | 177 |
sql = "delete from HMB where UID=?" |
176 | 178 |
param = (data.uid,) |
177 | 179 |
cursor.execute(sql, param) |
178 | 180 |
|
179 |
conn.commit() |
|
181 |
conn.commit()
|
|
180 | 182 |
# Catch the exception |
181 | 183 |
except Exception as ex: |
182 |
# Roll back any change if something goes wrong |
|
183 |
conn.rollback() |
|
184 |
from App import App |
|
185 |
from AppDocData import MessageType |
|
186 |
|
|
184 | 187 |
message = f"error occurred({ex}) in {sys.exc_info()[-1].tb_frame.f_code.co_filename}:" \ |
185 | 188 |
f"{sys.exc_info()[-1].tb_lineno}" |
186 |
print(message)
|
|
189 |
App.mainWnd().addMessage.emit(MessageType.Error, message)
|
|
187 | 190 |
|
188 | 191 |
@property |
189 | 192 |
def names(self): |
... | ... | |
198 | 201 |
def streamNos(self): |
199 | 202 |
return set([hmb.stream_no for hmb in self._hmbs if not hmb.isDeleted]) if self._hmbs is not None else {} |
200 | 203 |
|
201 |
''' |
|
202 |
@brief return given index's data |
|
203 |
@author humkyung |
|
204 |
@date 2018.07.12 |
|
205 |
''' |
|
206 | 204 |
def dataOfStreamNo(self, streamNo): |
205 |
"""return stream data""" |
|
207 | 206 |
return [hmb for hmb in self._hmbs if hmb.stream_no == streamNo and not hmb.isDeleted] if self._hmbs is not None else None |
208 | 207 |
|
209 | 208 |
''' |
DTI_PID/DTI_PID/HMB_UI.py | ||
---|---|---|
100 | 100 |
self.gridLayout_8.addWidget(self.pushButtonRecognizeText, 3, 2, 1, 1) |
101 | 101 |
self.verticalLayout_2 = QtWidgets.QVBoxLayout() |
102 | 102 |
self.verticalLayout_2.setObjectName("verticalLayout_2") |
103 |
self.pushButtonOpenXls = QtWidgets.QPushButton(self.groupBoxHMBData) |
|
104 |
self.pushButtonOpenXls.setMinimumSize(QtCore.QSize(24, 24)) |
|
105 |
self.pushButtonOpenXls.setMaximumSize(QtCore.QSize(24, 24)) |
|
106 |
self.pushButtonOpenXls.setObjectName("pushButtonOpenXls") |
|
107 |
self.verticalLayout_2.addWidget(self.pushButtonOpenXls) |
|
103 | 108 |
self.pushButtonAddHMBData = QtWidgets.QPushButton(self.groupBoxHMBData) |
104 | 109 |
self.pushButtonAddHMBData.setMinimumSize(QtCore.QSize(24, 24)) |
105 | 110 |
self.pushButtonAddHMBData.setMaximumSize(QtCore.QSize(24, 24)) |
... | ... | |
148 | 153 |
self.label_2.setText(_translate("HMBDialog", "Row Height : ")) |
149 | 154 |
self.label_3.setText(_translate("HMBDialog", "Record Direction : ")) |
150 | 155 |
self.pushButtonRecognizeText.setText(_translate("HMBDialog", "Text Recog.")) |
156 |
self.pushButtonOpenXls.setText(_translate("HMBDialog", "...")) |
|
151 | 157 |
self.pushButtonAddHMBData.setText(_translate("HMBDialog", "+")) |
152 | 158 |
self.pushButtonDelHMBData.setText(_translate("HMBDialog", "x")) |
153 | 159 |
import MainWindow_rc |
DTI_PID/DTI_PID/ItemPropertyTableWidget.py | ||
---|---|---|
16 | 16 |
import sys |
17 | 17 |
import math |
18 | 18 |
import re |
19 |
from functools import partial |
|
19 | 20 |
import SelectAttributeCommand, SelectAttributeBatchCommand |
20 | 21 |
|
21 | 22 |
from EngineeringAbstractItem import QEngineeringAbstractItem |
... | ... | |
371 | 372 |
widgetItem = QTableWidgetItem(self.tr("Type")) |
372 | 373 |
widgetItem.setData(Qt.UserRole, item) |
373 | 374 |
self.setItem(2, 1, widgetItem) |
374 |
self._lineTypeComboBox = QComboBox(self)
|
|
375 |
self._lineTypeComboBox.tag = widgetItem
|
|
375 |
line_type_combo = QComboBox(self)
|
|
376 |
line_type_combo.tag = widgetItem
|
|
376 | 377 |
for lineType in LineTypeConditions.items(): |
377 |
self._lineTypeComboBox.addItem(lineType.name)
|
|
378 |
self.setCellWidget(2, 3, self._lineTypeComboBox)
|
|
379 |
self._lineTypeComboBox.setCurrentText(item.lineType)
|
|
380 |
self._lineTypeComboBox.currentIndexChanged.connect(self.onLineTypeChanged)
|
|
378 |
line_type_combo.addItem(lineType.name)
|
|
379 |
self.setCellWidget(2, 3, line_type_combo)
|
|
380 |
line_type_combo.setCurrentText(item.lineType)
|
|
381 |
line_type_combo.currentIndexChanged.connect(partial(self.on_line_type_changed, item, line_type_combo))
|
|
381 | 382 |
elif type(item) is QEngineeringVendorItem: |
382 | 383 |
self.setRowCount(1) |
383 | 384 |
self.setItem(0, 1, QTableWidgetItem(self.tr("UID"))) |
... | ... | |
421 | 422 |
sys.exc_info()[-1].tb_lineno) |
422 | 423 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
423 | 424 |
|
424 |
''' |
|
425 |
@brief change selected lines' type by selected line type |
|
426 |
@author humkyung |
|
427 |
@date 2018.08.15 |
|
428 |
''' |
|
429 |
|
|
430 |
def onLineTypeChanged(self, param): |
|
431 |
lineType = self._lineTypeComboBox.itemText(param) |
|
432 |
data = self._lineTypeComboBox.tag.data(Qt.UserRole) |
|
433 |
if type(data) is QEngineeringLineItem: |
|
434 |
self.changeConnectedLineType(data, lineType) |
|
425 |
def on_line_type_changed(self, item, combo_box, index): |
|
426 |
"""change connected lines' type by selected line type""" |
|
427 |
line_type = combo_box.itemText(index) |
|
428 |
if type(item) is QEngineeringLineItem: |
|
429 |
self.change_connected_line_type(item, line_type) |
|
435 | 430 |
|
436 | 431 |
def onAreaChanged(self, param): |
437 | 432 |
from Area import Area |
... | ... | |
449 | 444 |
if type(data) is QEngineeringTextItem: |
450 | 445 |
data.area = name[0] if name else 'None' |
451 | 446 |
|
452 |
def changeConnectedLineType(self, line, lineType): |
|
453 |
line.lineType = lineType |
|
454 |
if type(line.connectors[0].connectedItem) is QEngineeringLineItem and \ |
|
455 |
(line.connectors[0].connectedItem.connectors[0].connectedItem is line or |
|
456 |
line.connectors[0].connectedItem.connectors[1].connectedItem is line) and \ |
|
457 |
line.connectors[0].connectedItem.lineType is not lineType: |
|
458 |
self.changeConnectedLineType(line.connectors[0].connectedItem, lineType) |
|
459 |
if type(line.connectors[1].connectedItem) is QEngineeringLineItem and \ |
|
460 |
(line.connectors[1].connectedItem.connectors[0].connectedItem is line or |
|
461 |
line.connectors[1].connectedItem.connectors[1].connectedItem is line) and \ |
|
462 |
line.connectors[1].connectedItem.lineType is not lineType: |
|
463 |
self.changeConnectedLineType(line.connectors[1].connectedItem, lineType) |
|
447 |
def change_connected_line_type(self, line, line_type): |
|
448 |
"""change line type recursively""" |
|
449 |
pool, visited = [line], [] |
|
450 |
while pool: |
|
451 |
_item = pool.pop() |
|
452 |
visited.append(_item) |
|
453 |
_item.lineType = line_type |
|
454 |
|
|
455 |
if type(_item.connectors[0].connectedItem) is QEngineeringLineItem and \ |
|
456 |
_item.connectors[0].connectedItem.is_connected(_item) and \ |
|
457 |
_item.connectors[0].connectedItem not in visited: |
|
458 |
pool.append(_item.connectors[0].connectedItem) |
|
459 |
if type(_item.connectors[1].connectedItem) is QEngineeringLineItem and \ |
|
460 |
_item.connectors[1].connectedItem.is_connected(_item) and \ |
|
461 |
_item.connectors[1].connectedItem not in visited: |
|
462 |
pool.append(_item.connectors[1].connectedItem) |
|
463 |
"""up to here""" |
|
464 | 464 |
|
465 | 465 |
def show_icon_item(self, row, col, prop): |
466 | 466 |
""" show icon item on grid """ |
... | ... | |
583 | 583 |
stream_no_combo.tag = key |
584 | 584 |
|
585 | 585 |
app_doc_data = AppDocData.instance() |
586 |
streamNos = sorted(list(app_doc_data.hmbTable.streamNos()))
|
|
587 |
for streamNo in streamNos:
|
|
586 |
stream_nos = sorted(list(app_doc_data.hmbTable.streamNos()))
|
|
587 |
for streamNo in stream_nos:
|
|
588 | 588 |
stream_no_combo.addItem(streamNo) |
589 | 589 |
self.setCellWidget(row, 3, stream_no_combo) |
590 | 590 |
stream_no_combo.setCurrentText(value) |
... | ... | |
861 | 861 |
row = row + 1 |
862 | 862 |
|
863 | 863 |
def on_stream_no_changed(self, item, combobox, index): |
864 |
"""change selected lines' stream no by selected stream no""" |
|
865 |
stream_no = combobox.itemText(index) |
|
866 |
item.stream_no = stream_no |
|
864 |
"""change connected lines' stream no by selected stream no""" |
|
865 |
try: |
|
866 |
stream_no = combobox.itemText(index) |
|
867 |
item.stream_no = stream_no |
|
868 |
|
|
869 |
"""change connected line's stream no""" |
|
870 |
if type(item) is QEngineeringLineItem: |
|
871 |
pool, visited = [item], [] |
|
872 |
while pool: |
|
873 |
_item = pool.pop() |
|
874 |
visited.append(_item) |
|
875 |
_item.stream_no = stream_no |
|
876 |
|
|
877 |
if type(_item.connectors[0].connectedItem) is QEngineeringLineItem and \ |
|
878 |
_item.connectors[0].connectedItem.is_connected(_item) and \ |
|
879 |
_item.connectors[0].connectedItem not in visited: |
|
880 |
pool.append(_item.connectors[0].connectedItem) |
|
881 |
if type(_item.connectors[1].connectedItem) is QEngineeringLineItem and \ |
|
882 |
_item.connectors[1].connectedItem.is_connected(_item) and \ |
|
883 |
_item.connectors[1].connectedItem not in visited: |
|
884 |
pool.append(_item.connectors[1].connectedItem) |
|
885 |
"""up to here""" |
|
886 |
|
|
887 |
for row in range(self.rowCount()): |
|
888 |
data = self.item(row, 1).data(Qt.UserRole) |
|
889 |
if data and type(data) is SymbolAttr and data.AttributeType == 'HMB': |
|
890 |
value = item.attrib(data.Attribute) |
|
891 |
self.item(row, 1).setText(value) |
|
892 |
except Exception as ex: |
|
893 |
from App import App |
|
894 |
from AppDocData import MessageType |
|
895 |
|
|
896 |
message = f"error occurred({repr(ex)}) in {sys.exc_info()[-1].tb_frame.f_code.co_filename}:" \ |
|
897 |
f"{sys.exc_info()[-1].tb_lineno}" |
|
898 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
|
867 | 899 |
|
868 | 900 |
''' |
869 | 901 |
@brief Initialize Run Contents Cell |
... | ... | |
941 | 973 |
self.copy_cells_to_clipboard() |
942 | 974 |
event.accept() |
943 | 975 |
|
976 |
super(QItemPropertyTableWidget, self).keyPressEvent(event) |
|
977 |
|
|
944 | 978 |
def copy_cells_to_clipboard(self): |
945 | 979 |
""" copy selected text to clipboard """ |
946 | 980 |
|
DTI_PID/DTI_PID/MainWindow.py | ||
---|---|---|
1350 | 1350 |
def showItemDataList(self): |
1351 | 1351 |
from ItemDataExportDialog import QItemDataExportDialog |
1352 | 1352 |
|
1353 |
self.dlgLineDataList = QItemDataExportDialog(self)
|
|
1354 |
self.dlgLineDataList.exec_()
|
|
1353 |
dlg = QItemDataExportDialog(self)
|
|
1354 |
dlg.exec_()
|
|
1355 | 1355 |
|
1356 | 1356 |
def showTextDataList(self): |
1357 | 1357 |
''' |
... | ... | |
1417 | 1417 |
if self.save_drawing_if_necessary(): |
1418 | 1418 |
return |
1419 | 1419 |
|
1420 |
if not app_doc_data.set_occupying_drawing(drawing.UID): |
|
1420 |
occupied = app_doc_data.set_occupying_drawing(drawing.UID) |
|
1421 |
if occupied: |
|
1421 | 1422 |
QMessageBox.about(self.graphicsView, self.tr("Notice"), |
1422 |
self.tr("The drawing is locked for editing by another user"))
|
|
1423 |
self.tr(f"The drawing is locked for editing by another user({occupied})"))
|
|
1423 | 1424 |
return |
1424 | 1425 |
|
1425 | 1426 |
# save alarm |
DTI_PID/DTI_PID/QtImageViewerScene.py | ||
---|---|---|
41 | 41 |
self._guidePen.setStyle(Qt.DashLine) |
42 | 42 |
self._guidePen.setWidthF(0.3) |
43 | 43 |
|
44 |
self._pressed_position = None |
|
45 |
|
|
44 | 46 |
@property |
45 | 47 |
def undo_stack(self): |
46 | 48 |
return self._undo_stack |
DTI_PID/DTI_PID/Scripts/MSSQL/ID2.sql | ||
---|---|---|
12 | 12 |
Category VARCHAR(64), |
13 | 13 |
Type VARCHAR(64) NOT NULL |
14 | 14 |
); |
15 |
INSERT INTO SymbolType |
|
16 |
(UID, Category, "Type") |
|
17 |
VALUES(-1, '', 'General'); |
|
15 |
INSERT INTO SymbolType (UID, Category, "Type") VALUES(-2, 'HMB', 'HMB'); |
|
16 |
INSERT INTO SymbolType (UID, Category, "Type") VALUES(-1, '', 'General'); |
|
18 | 17 |
INSERT INTO SymbolType |
19 | 18 |
(UID, Category, "Type") |
20 | 19 |
VALUES(0, 'Line', 'Line'); |
... | ... | |
1888 | 1887 |
|
1889 | 1888 |
CREATE TABLE HMB ( |
1890 | 1889 |
UID VARCHAR (37) NOT NULL, |
1891 |
STREAM_NO TEXT NOT NULL,
|
|
1890 |
STREAM_NO VARCHAR (8) NOT NULL,
|
|
1892 | 1891 |
NAME TEXT NOT NULL, |
1893 | 1892 |
UNIT TEXT, |
1894 | 1893 |
VALUE TEXT, |
1894 |
SymbolAttribute_UID VARCHAR (37) REFERENCES SymbolAttribute (UID), |
|
1895 | 1895 |
PRIMARY KEY ( |
1896 | 1896 |
UID |
1897 | 1897 |
) |
DTI_PID/DTI_PID/Shapes/EngineeringLineItem.py | ||
---|---|---|
203 | 203 |
matches = [data for data in stream_data if data.name == attr.Attribute] |
204 | 204 |
if matches: |
205 | 205 |
self.attrs[attr] = matches[0].value |
206 |
else: |
|
207 |
self.attrs[attr] = '' |
|
208 |
|
|
206 | 209 |
|
207 | 210 |
''' |
208 | 211 |
@brief setter owner |
DTI_PID/DTI_PID/Shapes/EngineeringPolylineItem.py | ||
---|---|---|
173 | 173 |
from SymbolSvgItem import SymbolSvgItem |
174 | 174 |
from EngineeringConnectorItem import QEngineeringConnectorItem |
175 | 175 |
|
176 |
# get connection point near by mouse point |
|
177 |
pt = (scenePos.x(), scenePos.y()) |
|
178 |
item = self.scene().itemAt(scenePos, QTransform()) |
|
179 |
if (item is not None) and (type(item) is SymbolSvgItem): |
|
180 |
connPt = item.getConnectionPointCloseTo(pt, 5) |
|
181 |
if connPt is not None: pt = connPt |
|
182 |
elif (item is not None) and (type(item) is QEngineeringConnectorItem): |
|
183 |
pt = item.center() |
|
184 |
# up to here |
|
185 |
|
|
186 |
if self.drawing_mode == QEngineeringPolylineItem.AXIS_MODE and len(self._vertices) > 0: |
|
187 |
dx = abs(self._vertices[-1][0] - pt[0]) |
|
188 |
dy = abs(self._vertices[-1][1] - pt[1]) |
|
189 |
if dx < dy: |
|
190 |
self._pt = (self._vertices[-1][0], pt[1]) |
|
176 |
if self.scene(): |
|
177 |
# get connection point near by mouse point |
|
178 |
pt = (scenePos.x(), scenePos.y()) |
|
179 |
item = self.scene().itemAt(scenePos, QTransform()) |
|
180 |
if (item is not None) and (type(item) is SymbolSvgItem): |
|
181 |
connPt = item.getConnectionPointCloseTo(pt, 5) |
|
182 |
if connPt is not None: pt = connPt |
|
183 |
elif (item is not None) and (type(item) is QEngineeringConnectorItem): |
|
184 |
pt = item.center() |
|
185 |
# up to here |
|
186 |
|
|
187 |
if self.drawing_mode == QEngineeringPolylineItem.AXIS_MODE and len(self._vertices) > 0: |
|
188 |
dx = abs(self._vertices[-1][0] - pt[0]) |
|
189 |
dy = abs(self._vertices[-1][1] - pt[1]) |
|
190 |
if dx < dy: |
|
191 |
self._pt = (self._vertices[-1][0], pt[1]) |
|
192 |
else: |
|
193 |
self._pt = (pt[0], self._vertices[-1][1]) |
|
191 | 194 |
else: |
192 |
self._pt = (pt[0], self._vertices[-1][1]) |
|
193 |
else: |
|
194 |
self._pt = pt |
|
195 |
self._pt = pt |
|
195 | 196 |
|
196 |
self.buildItem() |
|
197 |
self.update() |
|
197 |
self.buildItem()
|
|
198 |
self.update()
|
|
198 | 199 |
|
199 | 200 |
''' |
200 | 201 |
@brief Return real item position |
DTI_PID/DTI_PID/Shapes/SymbolSvgItem.py | ||
---|---|---|
167 | 167 |
self._color = self.DEFAULT_COLOR |
168 | 168 |
self.setColor(self._color) |
169 | 169 |
|
170 |
''' |
|
171 | 170 |
@property |
172 |
def properties(self): |
|
173 |
""" getter of properties """ |
|
174 |
import uuid |
|
175 |
|
|
176 |
for prop, value in self._properties.items(): |
|
177 |
try: |
|
178 |
if prop.is_selectable and type(value) is uuid.UUID and self.scene(): |
|
179 |
matches = [x for x in self.scene().items() if hasattr(x, 'uid') and str(x.uid) == str(value)] |
|
180 |
if matches: self._properties[prop] = matches[0] |
|
181 |
|
|
182 |
if prop.Expression: |
|
183 |
item = self._properties[prop] # assign item |
|
184 |
self._properties[prop] = eval(prop.Expression) |
|
185 |
except Exception as ex: |
|
186 |
from App import App |
|
187 |
|
|
188 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
|
189 |
sys.exc_info()[-1].tb_lineno) |
|
190 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
|
171 |
def stream_no(self): |
|
172 |
matches = [attr for attr in self.attrs if attr.Attribute.upper() == 'STREAM NO'] |
|
173 |
if matches: |
|
174 |
return self.attrs[matches[0]] |
|
191 | 175 |
|
192 |
return self._properties
|
|
176 |
return None
|
|
193 | 177 |
|
194 |
def set_property(self, property, value): |
|
195 |
""" set property with given value """ |
|
196 |
if issubclass(type(value), QEngineeringAbstractItem): self.add_assoc_item(value, 0) |
|
197 |
matches = [prop for prop, _ in self._properties.items() if prop.Attribute == property] |
|
198 |
if matches: self._properties[matches[0]] = value |
|
178 |
@stream_no.setter |
|
179 |
def stream_no(self, value): |
|
180 |
from AppDocData import AppDocData |
|
199 | 181 |
|
200 |
def prop(self, name):
|
|
201 |
""" return the value of given property with name """
|
|
202 |
matches = [(prop, value) for prop, value in self.properties.items() if prop.Attribute == name]
|
|
203 |
if matches: return matches[0][1]
|
|
182 |
matches = [attr for attr in self.attrs if attr.Attribute.upper() == 'STREAM NO']
|
|
183 |
if matches:
|
|
184 |
self.attrs[matches[0]] = value
|
|
185 |
"""reset attributes for hmb with given stream no"""
|
|
204 | 186 |
|
205 |
return None |
|
206 |
''' |
|
187 |
app_doc_data = AppDocData.instance() |
|
188 |
stream_data = app_doc_data.hmbTable.dataOfStreamNo(value) |
|
189 |
for attr in self.attrs: |
|
190 |
if attr.AttributeType == 'HMB': |
|
191 |
matches = [data for data in stream_data if data.name == attr.Attribute] |
|
192 |
if matches: |
|
193 |
self.attrs[attr] = matches[0].value |
|
194 |
else: |
|
195 |
self.attrs[attr] = '' |
|
207 | 196 |
|
208 | 197 |
@property |
209 | 198 |
def Size(self): |
210 |
""" return valve's size """
|
|
199 |
""" return symbol's size """
|
|
211 | 200 |
from QEngineeringSizeTextItem import QEngineeringSizeTextItem |
212 | 201 |
|
213 | 202 |
matches = [assoc for assoc in self.associations() if type(assoc) is QEngineeringSizeTextItem] |
DTI_PID/DTI_PID/UI/HMB.ui | ||
---|---|---|
213 | 213 |
<item row="7" column="4"> |
214 | 214 |
<layout class="QVBoxLayout" name="verticalLayout_2"> |
215 | 215 |
<item> |
216 |
<widget class="QPushButton" name="pushButtonOpenXls"> |
|
217 |
<property name="minimumSize"> |
|
218 |
<size> |
|
219 |
<width>24</width> |
|
220 |
<height>24</height> |
|
221 |
</size> |
|
222 |
</property> |
|
223 |
<property name="maximumSize"> |
|
224 |
<size> |
|
225 |
<width>24</width> |
|
226 |
<height>24</height> |
|
227 |
</size> |
|
228 |
</property> |
|
229 |
<property name="text"> |
|
230 |
<string>...</string> |
|
231 |
</property> |
|
232 |
</widget> |
|
233 |
</item> |
|
234 |
<item> |
|
216 | 235 |
<widget class="QPushButton" name="pushButtonAddHMBData"> |
217 | 236 |
<property name="minimumSize"> |
218 | 237 |
<size> |
내보내기 Unified diff