프로젝트

일반

사용자정보

통계
| 개정판:

hytos / HYTOS / HYTOS / PressureVariation.py @ 4211450a

이력 | 보기 | 이력해설 | 다운로드 (7.34 KB)

1
# -*- coding: utf-8 -*-
2

    
3
# Form implementation generated from reading ui file 'ProjectDialog.ui'
4
#
5
# Created by: PyQt5 UI code generator 5.6
6
#
7
# WARNING! All changes made in this file will be lost!
8

    
9
from PyQt5 import QtCore, QtGui, QtWidgets
10
from PyQt5.QtWidgets import *
11
import os
12
from AppDocData import AppDocData, Qt
13
import PressureVariation_UI
14
import math
15

    
16

    
17
def is_float(s):
18
    try:
19
        if s:
20
            float(s)
21
            return True
22
        else:
23
            return False
24
    except ValueError:
25
        return False
26

    
27

    
28
def set_item_properties(name, alignment, color=None):
29
    if name is None:
30
        name = ''
31

    
32
    item = QTableWidgetItem(str(name))
33
    item.setTextAlignment(alignment)
34
    if color:
35
        item.setBackground(color)
36

    
37
    return item
38

    
39

    
40
def is_not_blank(s):
41
    return bool(s and s.strip())
42

    
43

    
44
class QPressureVariation(QDialog):
45
    def __init__(self):
46
        QDialog.__init__(self)
47

    
48
        self.ui = PressureVariation_UI.Ui_Dialog()
49
        self.ui.setupUi(self)
50
        self.units = None
51
        self.item = None
52
        self.init_units()
53
        self.initialize()
54

    
55
    def show_dialog(self, item):
56
        self.setWindowFlags(self.windowFlags() & ~QtCore.Qt.WindowContextHelpButtonHint)
57

    
58
        self.item = item
59
        self.load_data()
60

    
61
        return self.exec_()
62

    
63
    def init_units(self):
64
        app_doc_data = AppDocData.instance()
65
        active_drawing = app_doc_data.activeDrawing
66

    
67
        for attr in active_drawing.attrs:
68
            if attr[0] == 'Units':
69
                self.units = attr[1]
70

    
71
    def initialize(self):
72
        self.ui.tableWidget.setColumnCount(21)
73
        col_names = ['No.\n-', 'Element\n-', 'Diameter\n{}'.format(self.units['Pipe_Diameter']), 'Length\n{}'.format(self.units['Length']), 'Angle\n(deg)', 'K\n-',
74
                     'Pressure\n{}(g)'.format(self.units['Pressure']), 'Void\n-', 'Quality\n-', 'Density\n{}'.format(self.units['Density']), 'V.Den\n{}'.format(self.units['Density']),
75
                     'Mean Vel\n{}'.format(self.units['Velocity']), 'Max Vel\n{}'.format(self.units['Velocity']), 'Ero Vel\n{}'.format(self.units['Velocity']),
76
                     'Pattern\nX', 'Pattern\nY', 'Regime\n-', 'Friction\n{}/{}'.format(self.units['Pressure'], self.units['Length']), 'Gravity\n{}/{}'.format(self.units['Pressure'], self.units['Length']),
77
                     'Momentum\n{}/{}'.format(self.units['Pressure'], self.units['Length']), 'Total\n{}'.format(self.units['Pressure'])]
78
        self.ui.tableWidget.setHorizontalHeaderLabels(col_names)
79
        self.ui.tableWidget.verticalHeader().setVisible(False)
80
        self.ui.tableWidget.setSelectionMode(QAbstractItemView.SingleSelection)
81
        self.ui.tableWidget.setSelectionBehavior(QAbstractItemView.SelectRows)
82
        self.ui.tableWidget.setEditTriggers(QAbstractItemView.NoEditTriggers)
83
        self.ui.tableWidget.horizontalHeader().setStretchLastSection(True)
84

    
85
    def add_data(self, no, element, diameter, length, angle, k, pressure, void, quality, density, v_den, mean_vel, max_vel, ero_vel, x, y, regime, friction, gravity, momentum, total):
86
        row = self.ui.tableWidget.rowCount()
87
        self.ui.tableWidget.setRowCount(row + 1)
88

    
89
        self.ui.tableWidget.setItem(row, 0, set_item_properties(no, Qt.AlignHCenter | Qt.AlignVCenter))
90
        self.ui.tableWidget.setItem(row, 1, set_item_properties(element, Qt.AlignLeft | Qt.AlignVCenter))
91
        self.ui.tableWidget.setItem(row, 2, set_item_properties(diameter, Qt.AlignRight | Qt.AlignVCenter))
92
        self.ui.tableWidget.setItem(row, 3, set_item_properties(length, Qt.AlignRight | Qt.AlignVCenter))
93
        self.ui.tableWidget.setItem(row, 4, set_item_properties(angle, Qt.AlignRight | Qt.AlignVCenter))
94
        self.ui.tableWidget.setItem(row, 5, set_item_properties(k, Qt.AlignRight | Qt.AlignVCenter))
95
        self.ui.tableWidget.setItem(row, 6, set_item_properties(pressure, Qt.AlignRight | Qt.AlignVCenter))
96
        self.ui.tableWidget.setItem(row, 7, set_item_properties(void, Qt.AlignRight | Qt.AlignVCenter))
97
        self.ui.tableWidget.setItem(row, 8, set_item_properties(quality, Qt.AlignRight | Qt.AlignVCenter))
98
        self.ui.tableWidget.setItem(row, 9, set_item_properties(density, Qt.AlignRight | Qt.AlignVCenter))
99
        self.ui.tableWidget.setItem(row, 10, set_item_properties(v_den, Qt.AlignRight | Qt.AlignVCenter))
100
        self.ui.tableWidget.setItem(row, 11, set_item_properties(mean_vel, Qt.AlignRight | Qt.AlignVCenter))
101
        self.ui.tableWidget.setItem(row, 12, set_item_properties(max_vel, Qt.AlignRight | Qt.AlignVCenter))
102
        self.ui.tableWidget.setItem(row, 13, set_item_properties(ero_vel, Qt.AlignRight | Qt.AlignVCenter))
103
        self.ui.tableWidget.setItem(row, 14, set_item_properties(x, Qt.AlignRight | Qt.AlignVCenter))
104
        self.ui.tableWidget.setItem(row, 15, set_item_properties(y, Qt.AlignRight | Qt.AlignVCenter))
105
        self.ui.tableWidget.setItem(row, 16, set_item_properties(regime, Qt.AlignHCenter | Qt.AlignVCenter))
106
        self.ui.tableWidget.setItem(row, 17, set_item_properties(friction, Qt.AlignRight | Qt.AlignVCenter))
107
        self.ui.tableWidget.setItem(row, 18, set_item_properties(gravity, Qt.AlignRight | Qt.AlignVCenter))
108
        self.ui.tableWidget.setItem(row, 19, set_item_properties(momentum, Qt.AlignRight | Qt.AlignVCenter))
109
        self.ui.tableWidget.setItem(row, 20, set_item_properties(total, Qt.AlignRight | Qt.AlignVCenter))
110

    
111
        self.ui.tableWidget.resizeRowsToContents()
112
        self.ui.tableWidget.resizeColumnsToContents()
113

    
114
    def load_data(self):
115
        data = self.item.mixed_calculation_result
116
        for no in range(data.no):
117
            element = data.element[no] if no in data.element else None
118
            inside_diameter = round(data.inside_diameter[no], 3) if no in data.inside_diameter else None
119
            length = round(data.length[no], 3) if no in data.length else None
120
            angle = data.angle[no] if no in data.angle else None
121
            k = round(data.k[no], 3) if no in data.k else None
122
            pressure = round(data.pressure[no], 3) if no in data.pressure else None
123
            void = round(data.void[no], 3) if no in data.void else None
124
            quality = round(data.quality[no], 3) if no in data.quality else None
125
            mean_den = round(data.mean_den[no], 3) if no in data.mean_den else None
126
            v_density = round(data.v_density[no], 3) if no in data.v_density else None
127
            homo_vel = round(data.homo_vel[no], 3) if no in data.homo_vel else None
128
            max_vel = round(data.max_vel[no], 3) if no in data.max_vel else None
129
            ero_vel = round(data.ero_vel[no], 3) if no in data.ero_vel else None
130
            x = round(data.x[no], 3) if no in data.x else None
131
            y = round(data.y[no], 3) if no in data.y else None
132
            regime = data.regime[no] if no in data.regime else None
133
            dp_fric = round(data.dp_fric[no], 5) if no in data.dp_fric else None
134
            dp_stat = round(data.dp_stat[no], 5) if no in data.dp_stat else None
135
            dp_momen = round(data.dp_momen[no], 5) if no in data.dp_momen else None
136
            total_length = round(data.total_length[no], 5) if no in data.total_length else None
137

    
138
            self.add_data(no, element, inside_diameter, length, angle, k, pressure, void, quality, mean_den, v_density, homo_vel, max_vel, ero_vel, x, y, regime, dp_fric, dp_stat, dp_momen, total_length)
139

    
140

    
141

    
142
    def accept(self):
143
        QDialog.accept(self)
144

    
145
    def reject(self):
146
        QDialog.reject(self)
클립보드 이미지 추가 (최대 크기: 500 MB)