Skip to content

Commit

Permalink
V2.1 修复bug,增加统一缩放功能
Browse files Browse the repository at this point in the history
  • Loading branch information
WenchenLie committed Oct 26, 2024
1 parent c5d14ca commit 55da58f
Show file tree
Hide file tree
Showing 8 changed files with 378 additions and 25 deletions.
90 changes: 70 additions & 20 deletions core/win.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,12 @@
from ui.win_export import Ui_win_export
from ui.win_about import Ui_win_about
from ui.win_terminal import Ui_win_terminal
from ui.win_scale import Ui_win_scale


SOFTWARE = '非线性多自由度时程分析软件'
VERSION = 'V2.0.2'
DATE = '2024.08.26'
VERSION = 'V2.1.0'
DATE = '2024.10.27'
TEMP_PATH = Path(os.getenv('TEMP')).as_posix()
ROOT = Path(__file__).parent.parent

Expand Down Expand Up @@ -84,6 +85,7 @@ def init_ui(self):
self.ui.setupUi(self)
self.setWindowTitle(f'{SOFTWARE} {VERSION}')
self.ui.pushButton.clicked.connect(self.open_win_select_gm)
self.ui.pushButton_23.clicked.connect(self.open_win_scale)
self.ui.pushButton_2.clicked.connect(self.open_win_select_gm1)
self.ui.pushButton_5.clicked.connect(self.delete_seleted)
self.ui.pushButton_4.clicked.connect(self.delete_all)
Expand Down Expand Up @@ -157,14 +159,14 @@ def init_ui(self):

def init_gm_var(self):
"""初始化地震动变量"""
self.gm = [] # 加速度序列
self.gm_name = []
self.gm_N = 0
self.gm_dt = []
self.gm_NPTS = []
self.gm_t = [] # 时间序列
self.gm_duration = [] # 持时
self.gm_unit = [] # 单位
self.gm: list[np.ndarray] = [] # 加速度序列
self.gm_name: list[str] = []
self.gm_N: int = 0
self.gm_dt: list[float] = []
self.gm_NPTS: list[int] = []
self.gm_t: list[np.ndarray] = [] # 时间序列
self.gm_duration: list[float] = [] # 持时
self.gm_unit: list[Literal['g', 'cm/s^2', 'm/s^2', 'mm/s^2']] = [] # 单位
self.gm_PGA = []

def init_var(self):
Expand Down Expand Up @@ -275,6 +277,11 @@ def open_win_select_gm(self):
win = Win_importGM(self)
win.exec_()

def open_win_scale(self):
win = Win_scale(self)
win.exec_()
self.plot_gm(None, self.current_gm_idx)

def gm_list_update(self):
"""更新地震动列表"""
self.ui.listWidget.clear()
Expand Down Expand Up @@ -358,16 +365,15 @@ def update_gm(self):
self.ui.lineEdit_4.setText('0.00001')
if float(self.ui.lineEdit.text()) == 0:
self.ui.lineEdit.setText('0.00001')
target_PGA = float(self.ui.lineEdit_4.text())
target_dt = float(self.ui.lineEdit.text())
idx = self.current_gm_idx
self.gm_PGA[idx] = float(self.ui.lineEdit_4.text())
self.gm_dt[idx] = float(self.ui.lineEdit.text())
self.gm_PGA[idx] = target_PGA
self.gm_t[idx] *= float(self.ui.lineEdit.text()) / self.gm_dt[idx]
self.gm_dt[idx] = target_dt
self.gm_unit[idx] = self.ui.comboBox.currentText()
self.gm_duration[idx] = self.gm_NPTS[idx] * float(self.ui.lineEdit.text())
th_old = self.gm[idx]
th = th_old / max(abs(th_old)) * float(self.ui.lineEdit_4.text())
t = np.linspace(0, self.gm_NPTS[idx] * float(self.ui.lineEdit.text()), self.gm_NPTS[idx] + 1)
self.gm[idx] = th
self.gm_t[idx] = t
self.gm_duration[idx] = self.gm_NPTS[idx] * target_dt
self.gm[idx] *= target_PGA / max(abs(self.gm[idx]))
self.ui.label_5.setText(f'{self.gm_name[idx]}已更新')
self.plot_gm(None, idx=idx)

Expand Down Expand Up @@ -572,8 +578,8 @@ def model_is_complete(self):
print('【MyWin, model_is_complete】质量数量与层数不等')
return False
print('【MyWin, model_is_complete】模型完备!')
print('【MyWin, model_is_complete】', self.mat_lib)
print('【MyWin, model_is_complete】', self.story_mat)
print('【MyWin, model_is_complete】材料定义:', self.mat_lib)
print('【MyWin, model_is_complete】楼层材料', self.story_mat)
return True

def mat_is_complete(self):
Expand Down Expand Up @@ -2785,3 +2791,47 @@ def __init__(self, parent=None):
self.ui.setupUi(self)
sys.stdout = core.EmittingStream(self.ui.textEdit)
sys.stderr = core.EmittingStream(self.ui.textEdit)


class Win_scale(QDialog):
"""统一缩放地震动"""
def __init__(self, main: MyWin, parent=None):
super().__init__(parent)
self.main = main
self.ui = Ui_win_scale()
self.ui.setupUi(self)
self.init_ui()

def init_ui(self):
validator = QDoubleValidator(0, 10000, 7)
validator.setNotation(QDoubleValidator.StandardNotation)
self.ui.lineEdit.setValidator(validator)
self.ui.lineEdit_4.setValidator(validator)
self.ui.pushButton.clicked.connect(self.confirmation)
self.ui.radioButton_5.toggled.connect(lambda: self.ui.lineEdit.setEnabled(self.ui.radioButton_5.isChecked()))
self.ui.radioButton_6.toggled.connect(lambda: self.ui.lineEdit_4.setEnabled(self.ui.radioButton_6.isChecked()))

def confirmation(self):
"""点击确认"""
print(f'【Win_scale, confirmation】进行地震动缩放')
if self.main.gm_N == 0:
self.accept()
return
if self.ui.radioButton_4.isChecked():
# 归一化
for idx in range(self.main.gm_N):
self.main.gm[idx] /= np.max(abs(self.main.gm[idx]))
elif self.ui.radioButton_5.isChecked():
# 指定PGA
PGA = float(self.ui.lineEdit.text())
for idx in range(self.main.gm_N):
self.main.gm[idx] *= PGA / np.max(abs(self.main.gm[idx]))
else:
# 指定缩放系数
SF = float(self.ui.lineEdit_4.text())
for idx in range(self.main.gm_N):
self.main.gm[idx] *= SF
self.main.ui.label_5.setText('已统一缩放')
self.accept()


8 changes: 7 additions & 1 deletion ui/main_win.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,17 @@ def setupUi(self, MainWindow):
self.pushButton_3.setMaximumSize(QtCore.QSize(16777215, 30))
self.pushButton_3.setObjectName("pushButton_3")
self.horizontalLayout_2.addWidget(self.pushButton_3)
self.pushButton_23 = QtWidgets.QPushButton(self.groupBox)
self.pushButton_23.setMinimumSize(QtCore.QSize(200, 30))
self.pushButton_23.setMaximumSize(QtCore.QSize(16777215, 30))
self.pushButton_23.setObjectName("pushButton_23")
self.horizontalLayout_2.addWidget(self.pushButton_23)
self.label_5 = QtWidgets.QLabel(self.groupBox)
self.label_5.setMaximumSize(QtCore.QSize(16777215, 40))
self.label_5.setText("")
self.label_5.setObjectName("label_5")
self.horizontalLayout_2.addWidget(self.label_5)
self.horizontalLayout_2.setStretch(1, 1)
self.horizontalLayout_2.setStretch(2, 1)
self.verticalLayout.addLayout(self.horizontalLayout_2)
self.verticalLayout.setStretch(0, 6)
self.verticalLayout.setStretch(1, 1)
Expand Down Expand Up @@ -621,6 +626,7 @@ def retranslateUi(self, MainWindow):
self.comboBox.setItemText(2, _translate("MainWindow", "cm/s^2"))
self.comboBox.setItemText(3, _translate("MainWindow", "m/s^2"))
self.pushButton_3.setText(_translate("MainWindow", "更新"))
self.pushButton_23.setText(_translate("MainWindow", "统一缩放"))
self.label_11.setText(_translate("MainWindow", "已导入地震动:(点击可绘制)"))
self.pushButton_5.setText(_translate("MainWindow", "删除选中"))
self.pushButton_4.setText(_translate("MainWindow", "删除全部"))
Expand Down
21 changes: 20 additions & 1 deletion ui/main_win.ui
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2" stretch="0,1">
<layout class="QHBoxLayout" name="horizontalLayout_2" stretch="0,0,1">
<item>
<widget class="QPushButton" name="pushButton_3">
<property name="minimumSize">
Expand All @@ -425,6 +425,25 @@
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_23">
<property name="minimumSize">
<size>
<width>200</width>
<height>30</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>30</height>
</size>
</property>
<property name="text">
<string>统一缩放</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_5">
<property name="maximumSize">
Expand Down
2 changes: 1 addition & 1 deletion ui/win_about.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def setupUi(self, win_about):
self.frame.setLineWidth(1)
self.frame.setObjectName("frame")
self.label = QtWidgets.QLabel(self.frame)
self.label.setGeometry(QtCore.QRect(40, 40, 171, 150))
self.label.setGeometry(QtCore.QRect(50, 40, 150, 150))
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(1)
sizePolicy.setVerticalStretch(1)
Expand Down
2 changes: 1 addition & 1 deletion ui/win_importGM.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def retranslateUi(self, win_importGM):
self.radioButton_6.setText(_translate("win_importGM", "指定缩放系数:"))
self.lineEdit_4.setText(_translate("win_importGM", "1"))
self.groupBox_3.setTitle(_translate("win_importGM", "通过.records文件导入"))
self.checkBox_2.setText(_translate("win_importGM", "缩放"))
self.checkBox_2.setText(_translate("win_importGM", "采用内置缩放"))
self.pushButton_2.setText(_translate("win_importGM", "选择.records"))
self.pushButton.setText(_translate("win_importGM", "选择文件"))
import resource_rc
Expand Down
2 changes: 1 addition & 1 deletion ui/win_importGM.ui
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@
<item>
<widget class="QCheckBox" name="checkBox_2">
<property name="text">
<string>缩放</string>
<string>采用内置缩放</string>
</property>
</widget>
</item>
Expand Down
104 changes: 104 additions & 0 deletions ui/win_scale.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'f:\Projects\NLMDOF\ui\win_scale.ui'
#
# Created by: PyQt5 UI code generator 5.15.9
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.


from PyQt5 import QtCore, QtGui, QtWidgets


class Ui_win_scale(object):
def setupUi(self, win_scale):
win_scale.setObjectName("win_scale")
win_scale.resize(300, 214)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(win_scale.sizePolicy().hasHeightForWidth())
win_scale.setSizePolicy(sizePolicy)
win_scale.setMinimumSize(QtCore.QSize(300, 200))
win_scale.setMaximumSize(QtCore.QSize(300, 214))
font = QtGui.QFont()
font.setFamily("宋体")
font.setPointSize(12)
win_scale.setFont(font)
icon = QtGui.QIcon()
icon.addPixmap(QtGui.QPixmap(":/插图/N.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
win_scale.setWindowIcon(icon)
self.verticalLayout_3 = QtWidgets.QVBoxLayout(win_scale)
self.verticalLayout_3.setObjectName("verticalLayout_3")
self.groupBox_2 = QtWidgets.QGroupBox(win_scale)
self.groupBox_2.setObjectName("groupBox_2")
self.verticalLayout_2 = QtWidgets.QVBoxLayout(self.groupBox_2)
self.verticalLayout_2.setObjectName("verticalLayout_2")
self.radioButton_4 = QtWidgets.QRadioButton(self.groupBox_2)
self.radioButton_4.setChecked(True)
self.radioButton_4.setObjectName("radioButton_4")
self.verticalLayout_2.addWidget(self.radioButton_4)
self.horizontalLayout_2 = QtWidgets.QHBoxLayout()
self.horizontalLayout_2.setObjectName("horizontalLayout_2")
self.radioButton_5 = QtWidgets.QRadioButton(self.groupBox_2)
self.radioButton_5.setObjectName("radioButton_5")
self.horizontalLayout_2.addWidget(self.radioButton_5)
self.lineEdit = QtWidgets.QLineEdit(self.groupBox_2)
self.lineEdit.setEnabled(False)
self.lineEdit.setMinimumSize(QtCore.QSize(0, 30))
self.lineEdit.setObjectName("lineEdit")
self.horizontalLayout_2.addWidget(self.lineEdit)
self.verticalLayout_2.addLayout(self.horizontalLayout_2)
self.horizontalLayout_4 = QtWidgets.QHBoxLayout()
self.horizontalLayout_4.setObjectName("horizontalLayout_4")
self.radioButton_6 = QtWidgets.QRadioButton(self.groupBox_2)
self.radioButton_6.setObjectName("radioButton_6")
self.horizontalLayout_4.addWidget(self.radioButton_6)
self.lineEdit_4 = QtWidgets.QLineEdit(self.groupBox_2)
self.lineEdit_4.setEnabled(False)
self.lineEdit_4.setMinimumSize(QtCore.QSize(0, 30))
self.lineEdit_4.setObjectName("lineEdit_4")
self.horizontalLayout_4.addWidget(self.lineEdit_4)
self.verticalLayout_2.addLayout(self.horizontalLayout_4)
self.horizontalLayout = QtWidgets.QHBoxLayout()
self.horizontalLayout.setObjectName("horizontalLayout")
self.pushButton = QtWidgets.QPushButton(self.groupBox_2)
self.pushButton.setMinimumSize(QtCore.QSize(0, 30))
self.pushButton.setCheckable(False)
self.pushButton.setObjectName("pushButton")
self.horizontalLayout.addWidget(self.pushButton)
self.pushButton_2 = QtWidgets.QPushButton(self.groupBox_2)
self.pushButton_2.setMinimumSize(QtCore.QSize(0, 30))
self.pushButton_2.setObjectName("pushButton_2")
self.horizontalLayout.addWidget(self.pushButton_2)
self.verticalLayout_2.addLayout(self.horizontalLayout)
self.verticalLayout_3.addWidget(self.groupBox_2)
self.verticalLayout_3.setStretch(0, 5)

self.retranslateUi(win_scale)
self.pushButton_2.clicked.connect(win_scale.accept) # type: ignore
QtCore.QMetaObject.connectSlotsByName(win_scale)

def retranslateUi(self, win_scale):
_translate = QtCore.QCoreApplication.translate
win_scale.setWindowTitle(_translate("win_scale", "缩放"))
self.groupBox_2.setTitle(_translate("win_scale", "缩放所有地震动"))
self.radioButton_4.setText(_translate("win_scale", "归一化"))
self.radioButton_5.setText(_translate("win_scale", "指定PGA(g):"))
self.lineEdit.setText(_translate("win_scale", "0.4"))
self.radioButton_6.setText(_translate("win_scale", "指定缩放系数:"))
self.lineEdit_4.setText(_translate("win_scale", "1"))
self.pushButton.setText(_translate("win_scale", "确认"))
self.pushButton_2.setText(_translate("win_scale", "返回"))
import resource_rc


if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
win_scale = QtWidgets.QDialog()
ui = Ui_win_scale()
ui.setupUi(win_scale)
win_scale.show()
sys.exit(app.exec_())
Loading

0 comments on commit 55da58f

Please sign in to comment.