6 |
6 |
import subprocess
|
7 |
7 |
from functools import partial
|
8 |
8 |
|
|
9 |
from openpyxl.drawing import colors
|
|
10 |
|
9 |
11 |
sys.path.insert(0, os.path.dirname(os.path.realpath(__file__)))
|
10 |
12 |
sys.path.insert(0, os.path.dirname(os.path.realpath(__file__)) + '\\Commands')
|
11 |
13 |
import CreateCommand
|
... | ... | |
40 |
42 |
def is_blank(s):
|
41 |
43 |
return not (s and s.strip())
|
42 |
44 |
|
|
45 |
|
43 |
46 |
def is_float(s):
|
44 |
47 |
try:
|
45 |
48 |
if s:
|
... | ... | |
50 |
53 |
except ValueError:
|
51 |
54 |
return False
|
52 |
55 |
|
53 |
|
def set_item_properties(name, alignment, color=None):
|
|
56 |
|
|
57 |
def set_item_properties(name, alignment, backgroundcolor=None, foregroundcolor=None):
|
54 |
58 |
if name is None:
|
55 |
59 |
name = ''
|
56 |
60 |
|
57 |
61 |
item = QTableWidgetItem(str(name))
|
58 |
62 |
item.setTextAlignment(alignment)
|
59 |
|
if color:
|
60 |
|
item.setBackground(color)
|
61 |
|
|
|
63 |
if backgroundcolor:
|
|
64 |
item.setBackground(backgroundcolor)
|
|
65 |
if foregroundcolor:
|
|
66 |
item.setForeground(foregroundcolor) # QBrush(QColor(255, 0, 0)))
|
62 |
67 |
return item
|
63 |
68 |
|
64 |
69 |
|
... | ... | |
810 |
815 |
sys.exc_info()[-1].tb_lineno)
|
811 |
816 |
self.addMessage.emit(MessageType.Error, message)
|
812 |
817 |
|
813 |
|
|
814 |
818 |
def on_about(self):
|
815 |
819 |
"""show about dialog"""
|
816 |
820 |
from AboutDialog import QAboutDialog
|
... | ... | |
907 |
911 |
options = QFileDialog.Options()
|
908 |
912 |
options |= QFileDialog.DontUseNativeDialog
|
909 |
913 |
file_name, _ = QFileDialog.getSaveFileName(self, self.tr('Report'), file_name, 'Excel(*.xlsx)',
|
910 |
|
options=options)
|
|
914 |
options=options)
|
911 |
915 |
|
912 |
916 |
template = os.path.join(os.getenv('ALLUSERSPROFILE'), App.NAME, 'Report_Template.xlsx')
|
913 |
917 |
if file_name and os.path.exists(template):
|
... | ... | |
915 |
919 |
|
916 |
920 |
wb = openpyxl.load_workbook(template)
|
917 |
921 |
|
918 |
|
page_no = 1
|
|
922 |
page_no = 1
|
919 |
923 |
pages = math.ceil(len(list(app_doc_data.activeDrawing.hmbTable.streamNos())) / 20)
|
920 |
924 |
for page in range(pages):
|
921 |
925 |
ws = wb.copy_worksheet(wb.get_sheet_by_name('Page'))
|
... | ... | |
943 |
947 |
elif config.key == 'ApprovedBy' and config.value:
|
944 |
948 |
ws['Z79'].value = config.value
|
945 |
949 |
|
946 |
|
configs = app_doc_data.getAppConfigs('app', 'UserName')
|
|
950 |
configs = app_doc_data.getAppConfigs('app', 'SingleID')
|
947 |
951 |
if configs and configs[0].value:
|
948 |
952 |
ws['Z77'].value = configs[0].value
|
949 |
953 |
ws['Z68'].value = str(datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
|
... | ... | |
952 |
956 |
# Output [Pump, Compressor, Control Valve]
|
953 |
957 |
ws['X1'].value = 'Loop_Deviation'
|
954 |
958 |
ws['X1'].font = Font(bold=True, underline='single', size=11)
|
955 |
|
ws['X2'].value = 'To Do ...'
|
956 |
959 |
|
957 |
960 |
loops = app_doc_data.activeDrawing.loops
|
|
961 |
strmsg = None
|
|
962 |
row_no = 2
|
|
963 |
for loop in loops:
|
|
964 |
deviation = loop.deviation
|
|
965 |
if round(deviation, 9) == 0:
|
|
966 |
continue
|
|
967 |
|
|
968 |
for i in range(1, len(loop.items) - 1, 3):
|
|
969 |
if i == 1:
|
|
970 |
loop_no = loop.name.replace('Loop', '')
|
|
971 |
if len(loop_no) > 1:
|
|
972 |
strmsg = '({}) {}'.format(loop_no, loop.items[i].stream_no)
|
|
973 |
else:
|
|
974 |
strmsg = '(0{}) {}'.format(loop_no, loop.items[i].stream_no)
|
|
975 |
else:
|
|
976 |
if len(str(loop.items[i - 1])) > 13 and str(loop.items[i - 1])[
|
|
977 |
:13] == 'Line_Splitter':
|
|
978 |
pre_stream_num = loop.items[i - 3].stream_no
|
|
979 |
cur_stream_num = loop.items[i].stream_no
|
|
980 |
if pre_stream_num == cur_stream_num:
|
|
981 |
strmsg = '{}-{}'.format(strmsg, cur_stream_num)
|
|
982 |
else:
|
|
983 |
strmsg = '{}-{}-{}'.format(strmsg, pre_stream_num, cur_stream_num)
|
|
984 |
|
|
985 |
last_stream_num = loop.items[len(loop.items) - 2].stream_no
|
|
986 |
strmsg = '{}-{}'.format(strmsg, last_stream_num)
|
|
987 |
|
|
988 |
value = '{} = {} {}'.format(strmsg, round(deviation, 3), units['Pressure'])
|
|
989 |
if round(deviation, 3) < 0:
|
|
990 |
ws.cell(row_no, 24, value).font = Font(underline='single',
|
|
991 |
size=10,
|
|
992 |
color='FF0000')
|
|
993 |
|
|
994 |
elif round(deviation, 3) > 0:
|
|
995 |
ws.cell(row_no, 24, value).font = Font(size=10)
|
|
996 |
else:
|
|
997 |
ws.cell(row_no, 24, value).font = Font(underline='single',
|
|
998 |
size=10)
|
|
999 |
row_no += 1
|
958 |
1000 |
|
959 |
|
start_row_no = 4
|
|
1001 |
start_row_no = row_no + 1
|
960 |
1002 |
start_col_no = 24
|
961 |
1003 |
# Pump
|
962 |
1004 |
pumps = []
|
... | ... | |
1433 |
1475 |
page_no = math.ceil(count / 20)
|
1434 |
1476 |
return work_book.get_sheet_by_name('Page ({})'.format(page_no))
|
1435 |
1477 |
|
1436 |
|
def loop_streams_hy(self):
|
1437 |
|
try:
|
1438 |
|
pass
|
1439 |
|
# self.add_data('Loop_Deviation', None, None)
|
1440 |
|
|
1441 |
|
except Exception as ex:
|
1442 |
|
message = 'error occurred({}) in {}:{}'.format(repr(ex), sys.exc_info()[-1].tb_frame.f_code.co_filename,
|
1443 |
|
sys.exc_info()[-1].tb_lineno)
|
1444 |
|
self.addMessage.emit(MessageType.Error, message)
|
1445 |
|
|
1446 |
1478 |
def has_duplicate_tag_no(self, tag_no):
|
1447 |
1479 |
row_count = self.tableWidgetOutput.rowCount()
|
1448 |
1480 |
for row in range(row_count):
|
... | ... | |
1471 |
1503 |
units = [attr[1] for attr in drawing.attrs if attr[0] == 'Units'][0]
|
1472 |
1504 |
|
1473 |
1505 |
loops = drawing.loops
|
|
1506 |
# Deviation
|
|
1507 |
self.add_data('Loop_Deviation', None, None, True, True)
|
|
1508 |
strmsg = None
|
|
1509 |
for loop in loops:
|
|
1510 |
deviation = loop.deviation
|
|
1511 |
if round(deviation, 9) == 0:
|
|
1512 |
continue
|
|
1513 |
|
|
1514 |
for i in range(1, len(loop.items) - 1, 3):
|
|
1515 |
if i == 1:
|
|
1516 |
loop_no = loop.name.replace('Loop', '')
|
|
1517 |
if len(loop_no) > 1:
|
|
1518 |
strmsg = '({}) {}'.format(loop_no, loop.items[i].stream_no)
|
|
1519 |
else:
|
|
1520 |
strmsg = '(0{}) {}'.format(loop_no, loop.items[i].stream_no)
|
|
1521 |
else:
|
|
1522 |
if len(str(loop.items[i - 1])) > 13 and str(loop.items[i - 1])[:13] == 'Line_Splitter':
|
|
1523 |
pre_stream_num = loop.items[i - 3].stream_no
|
|
1524 |
cur_stream_num = loop.items[i].stream_no
|
|
1525 |
if pre_stream_num == cur_stream_num:
|
|
1526 |
strmsg = '{}-{}'.format(strmsg, cur_stream_num)
|
|
1527 |
else:
|
|
1528 |
strmsg = '{}-{}-{}'.format(strmsg, pre_stream_num, cur_stream_num)
|
|
1529 |
|
|
1530 |
last_stream_num = loop.items[len(loop.items) - 2].stream_no
|
|
1531 |
strmsg = '{}-{}'.format(strmsg, last_stream_num)
|
|
1532 |
|
|
1533 |
if round(deviation, 3) < 0:
|
|
1534 |
self.add_data('{} = {} {}'.format(strmsg, round(deviation, 3), units['Pressure']), None, None, None,
|
|
1535 |
True, QBrush(QColor(255, 0, 0)))
|
|
1536 |
else:
|
|
1537 |
self.add_data('{} = {} {}'.format(strmsg, round(deviation, 3), units['Pressure']), None, None, None,
|
|
1538 |
True)
|
|
1539 |
|
1474 |
1540 |
names = []
|
1475 |
1541 |
# Pump
|
1476 |
1542 |
for loop in loops:
|
... | ... | |
1484 |
1550 |
names.append(name)
|
1485 |
1551 |
attr = item.parent.attribute
|
1486 |
1552 |
|
1487 |
|
self.add_data(attr['Tag_No'], None, None, True)
|
|
1553 |
self.add_data(attr['Tag_No'], None, None, True, True)
|
1488 |
1554 |
self.add_data('Suct.P :', round(attr['Suct.P'], 3),
|
1489 |
1555 |
'{}.g'.format(units['Pressure']))
|
1490 |
1556 |
self.add_data('Disc.P :', round(attr['Disc.P'], 3),
|
... | ... | |
1507 |
1573 |
names.append(name)
|
1508 |
1574 |
|
1509 |
1575 |
attr = item.parent.attribute
|
1510 |
|
self.add_data(attr['Tag_No'], None, None, True)
|
|
1576 |
self.add_data(attr['Tag_No'], None, None, True, True)
|
1511 |
1577 |
self.add_data('Suct.P :', round(attr['Suct.P'], 3),
|
1512 |
1578 |
'{}.g'.format(units['Pressure']))
|
1513 |
1579 |
self.add_data('Disc.P :', round(attr['Disc.P'], 3),
|
... | ... | |
1527 |
1593 |
names.append(name)
|
1528 |
1594 |
|
1529 |
1595 |
attr = item.parent.attribute
|
1530 |
|
self.add_data(attr['Tag_No'], None, None, True)
|
|
1596 |
self.add_data(attr['Tag_No'], None, None, True, True)
|
1531 |
1597 |
self.add_data('Inlet P :', round(attr['Suct.P'], 3),
|
1532 |
1598 |
'{}.g'.format(units['Pressure']))
|
1533 |
1599 |
self.add_data('Outlet P :', round(attr['Disc.P'], 3),
|
... | ... | |
1548 |
1614 |
loops = drawing.loops
|
1549 |
1615 |
if loops:
|
1550 |
1616 |
self.tableWidgetLoop.clear()
|
1551 |
|
self.tableWidgetLoop.setColumnCount(len(loops) * 4)
|
|
1617 |
self.tableWidgetLoop.setColumnCount(len(loops) * 5)
|
1552 |
1618 |
|
1553 |
|
_col_names = [[loop.name, 'pressure', 'Static\nLine\ndP_Eq', 'El.\nDensity\nEl.'] for loop in loops]
|
|
1619 |
_col_names = [[loop.name, 'pressure', 'Static\nLine\ndP_Eq', 'El.\nDensity\nEl.', 'Extra'] for loop in
|
|
1620 |
loops]
|
1554 |
1621 |
col_names = []
|
1555 |
1622 |
for col_name in _col_names: col_names.extend(col_name)
|
1556 |
1623 |
self.tableWidgetLoop.setHorizontalHeaderLabels(col_names)
|
... | ... | |
1565 |
1632 |
for row in range(len(loops[col].items)):
|
1566 |
1633 |
item = QTableWidgetItem(str(loops[col].items[row]))
|
1567 |
1634 |
item.setTextAlignment(Qt.AlignHCenter | Qt.AlignVCenter)
|
1568 |
|
self.tableWidgetLoop.setItem(row, col * 4, item)
|
|
1635 |
self.tableWidgetLoop.setItem(row, col * 5, item)
|
1569 |
1636 |
|
1570 |
1637 |
# display calcuation values
|
1571 |
1638 |
for row in range(len(loops[col].items)):
|
... | ... | |
1573 |
1640 |
item = QTableWidgetItem(str(round(loops[col].pressures[loops[col].items[row]], 8)))
|
1574 |
1641 |
item.setTextAlignment(Qt.AlignRight | Qt.AlignVCenter)
|
1575 |
1642 |
# if not loops[col].pressures[loops[col].items[row]]: item.setBackground(Qt.red)
|
1576 |
|
self.tableWidgetLoop.setItem(row, col * 4 + 1, item)
|
|
1643 |
self.tableWidgetLoop.setItem(row, col * 5 + 1, item)
|
1577 |
1644 |
|
1578 |
1645 |
if loops[col].items[row] in loops[col].pressure_drops:
|
1579 |
1646 |
item = QTableWidgetItem(str(round(loops[col].pressure_drops[loops[col].items[row]], 9)))
|
1580 |
1647 |
item.setTextAlignment(Qt.AlignRight | Qt.AlignVCenter)
|
1581 |
1648 |
# if not loops[col].pressure_drops[loops[col].items[row]]: item.setBackground(Qt.red)
|
1582 |
|
self.tableWidgetLoop.setItem(row, col * 4 + 2, item)
|
|
1649 |
self.tableWidgetLoop.setItem(row, col * 5 + 2, item)
|
1583 |
1650 |
|
1584 |
1651 |
if loops[col].items[row] in loops[col].density_elevations:
|
1585 |
1652 |
item = QTableWidgetItem(str(round(loops[col].density_elevations[loops[col].items[row]], 8)))
|
1586 |
1653 |
item.setTextAlignment(Qt.AlignRight | Qt.AlignVCenter)
|
1587 |
1654 |
# if not loops[col].density_elevations[loops[col].items[row]]: item.setBackground(Qt.red)
|
1588 |
|
self.tableWidgetLoop.setItem(row, col * 4 + 3, item)
|
|
1655 |
self.tableWidgetLoop.setItem(row, col * 5 + 3, item)
|
|
1656 |
|
|
1657 |
if loops[col].items[row] in loops[col].extras:
|
|
1658 |
item = QTableWidgetItem(str(loops[col].extras[loops[col].items[row]]))
|
|
1659 |
item.setTextAlignment(Qt.AlignRight | Qt.AlignVCenter)
|
|
1660 |
# if not loops[col].density_elevations[loops[col].items[row]]: item.setBackground(Qt.red)
|
|
1661 |
self.tableWidgetLoop.setItem(row, col * 5 + 4, item)
|
1589 |
1662 |
|
1590 |
1663 |
self.tableWidgetLoop.resizeColumnsToContents()
|
1591 |
1664 |
self.tableWidgetLoop.resizeRowsToContents()
|
... | ... | |
1740 |
1813 |
# Set appDocData
|
1741 |
1814 |
app_doc_data.clear()
|
1742 |
1815 |
self.onCommandRejected()
|
1743 |
|
|
1744 |
1816 |
app_doc_data.activeDrawing = drawing
|
1745 |
1817 |
|
1746 |
1818 |
self.setAttributes(drawing)
|
... | ... | |
1753 |
1825 |
|
1754 |
1826 |
self.symbolTreeWidget.initSymbolTreeWidget()
|
1755 |
1827 |
|
1756 |
|
components = app_doc_data.getComponentListByDrawingUID(drawing)
|
|
1828 |
components = app_doc_data.getComponentListByDrawingUID()
|
1757 |
1829 |
count = len(components)
|
1758 |
1830 |
|
1759 |
1831 |
if count > 0:
|
... | ... | |
2315 |
2387 |
|
2316 |
2388 |
return itemList
|
2317 |
2389 |
|
2318 |
|
def add_data(self, name, value, unit, separation=None):
|
|
2390 |
def add_data(self, name, value, unit, separation=None, is_cell_merge=None, foregroundcolor=None):
|
2319 |
2391 |
row = self.tableWidgetOutput.rowCount()
|
2320 |
2392 |
self.tableWidgetOutput.setRowCount(row + 1)
|
2321 |
2393 |
|
2322 |
2394 |
if separation:
|
2323 |
|
self.tableWidgetOutput.setItem(row, 0, set_item_properties(name,
|
2324 |
|
Qt.AlignLeft | Qt.AlignVCenter,
|
2325 |
|
QColor(153, 204, 255)))
|
2326 |
|
self.tableWidgetOutput.setItem(row, 1, set_item_properties(value,
|
2327 |
|
Qt.AlignHCenter | Qt.AlignVCenter,
|
2328 |
|
QColor(153, 204, 255)))
|
2329 |
|
self.tableWidgetOutput.setItem(row, 2, set_item_properties(unit,
|
2330 |
|
Qt.AlignHCenter | Qt.AlignVCenter,
|
2331 |
|
QColor(153, 204, 255)))
|
|
2395 |
if is_cell_merge:
|
|
2396 |
self.tableWidgetOutput.setSpan(row, 0, 1, 3)
|
|
2397 |
self.tableWidgetOutput.setItem(row, 0, set_item_properties(name,
|
|
2398 |
Qt.AlignLeft | Qt.AlignVCenter,
|
|
2399 |
QColor(153, 204, 255), foregroundcolor))
|
|
2400 |
else:
|
|
2401 |
self.tableWidgetOutput.setItem(row, 0, set_item_properties(name,
|
|
2402 |
Qt.AlignLeft | Qt.AlignVCenter,
|
|
2403 |
QColor(153, 204, 255), foregroundcolor))
|
|
2404 |
self.tableWidgetOutput.setItem(row, 1, set_item_properties(value,
|
|
2405 |
Qt.AlignHCenter | Qt.AlignVCenter,
|
|
2406 |
QColor(153, 204, 255), foregroundcolor))
|
|
2407 |
self.tableWidgetOutput.setItem(row, 2, set_item_properties(unit,
|
|
2408 |
Qt.AlignHCenter | Qt.AlignVCenter,
|
|
2409 |
QColor(153, 204, 255), foregroundcolor))
|
2332 |
2410 |
else:
|
2333 |
|
self.tableWidgetOutput.setItem(row, 0, set_item_properties(name,
|
2334 |
|
Qt.AlignLeft | Qt.AlignVCenter))
|
2335 |
|
self.tableWidgetOutput.setItem(row, 1, set_item_properties(value,
|
2336 |
|
Qt.AlignRight | Qt.AlignVCenter))
|
2337 |
|
self.tableWidgetOutput.setItem(row, 2, set_item_properties(unit,
|
2338 |
|
Qt.AlignLeft | Qt.AlignVCenter))
|
|
2411 |
if is_cell_merge:
|
|
2412 |
self.tableWidgetOutput.setSpan(row, 0, 1, 3)
|
|
2413 |
self.tableWidgetOutput.setItem(row, 0, set_item_properties(name,
|
|
2414 |
Qt.AlignLeft | Qt.AlignVCenter, None,
|
|
2415 |
foregroundcolor))
|
|
2416 |
else:
|
|
2417 |
self.tableWidgetOutput.setItem(row, 0, set_item_properties(name,
|
|
2418 |
Qt.AlignLeft | Qt.AlignVCenter, None,
|
|
2419 |
foregroundcolor))
|
|
2420 |
self.tableWidgetOutput.setItem(row, 1, set_item_properties(value,
|
|
2421 |
Qt.AlignRight | Qt.AlignVCenter, None,
|
|
2422 |
foregroundcolor))
|
|
2423 |
self.tableWidgetOutput.setItem(row, 2, set_item_properties(unit,
|
|
2424 |
Qt.AlignLeft | Qt.AlignVCenter, None,
|
|
2425 |
foregroundcolor))
|
2339 |
2426 |
|
2340 |
2427 |
self.tableWidgetOutput.resizeRowsToContents()
|
2341 |
2428 |
self.tableWidgetOutput.resizeColumnsToContents()
|