控制网复测平面基准归算程序(包含控制网复测平面基准计算,平面控制网稳定性计算,水准测段高差稳定计算三个程序功能)
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466
  1. # ///////////////////////////////////////////////////////////////
  2. #
  3. # BY: WANDERSON M.PIMENTA
  4. # PROJECT MADE WITH: Qt Designer and PySide6
  5. # V: 1.0.0
  6. #
  7. # This project can be used freely for all uses, as long as they maintain the
  8. # respective credits only in the Python scripts, any information in the visual
  9. # interface (GUI) can be modified without any implication.
  10. #
  11. # There are limitations on Qt licenses if you want to use your products
  12. # commercially, I recommend reading them on the official website:
  13. # https://doc.qt.io/qtforpython/licenses.html
  14. #
  15. # ///////////////////////////////////////////////////////////////
  16. from PySide6.QtWidgets import QMessageBox
  17. # MAIN FILE
  18. # ///////////////////////////////////////////////////////////////
  19. from main import *
  20. import importlib
  21. import sqlite3
  22. from select import select
  23. from Back.GC import GC, GCExport
  24. from Back.GS import GS, GSExport
  25. from Back.WD import WD, WDExport
  26. from Back.GC import GCcompute
  27. from Back.GS import GScompute
  28. from Back.WD import WDcompute
  29. from Back.GC import GCshow
  30. from Back.GS import GSshow
  31. from Back.WD import WDshow
  32. import os
  33. # GLOBALS
  34. # ///////////////////////////////////////////////////////////////
  35. GLOBAL_STATE = False
  36. GLOBAL_TITLE_BAR = True
  37. class UIFunctions(MainWindow):
  38. # MAXIMIZE/RESTORE
  39. # ///////////////////////////////////////////////////////////////
  40. def maximize_restore(self):
  41. global GLOBAL_STATE
  42. status = GLOBAL_STATE
  43. if status == False:
  44. self.showMaximized()
  45. GLOBAL_STATE = True
  46. self.ui.appMargins.setContentsMargins(0, 0, 0, 0)
  47. self.ui.maximizeRestoreAppBtn.setToolTip("Restore")
  48. self.ui.maximizeRestoreAppBtn.setIcon(QIcon(u":/icons/images/icons/icon_restore.png"))
  49. self.ui.frame_size_grip.hide()
  50. self.left_grip.hide()
  51. self.right_grip.hide()
  52. self.top_grip.hide()
  53. self.bottom_grip.hide()
  54. else:
  55. GLOBAL_STATE = False
  56. self.showNormal()
  57. self.resize(self.width() + 1, self.height() + 1)
  58. self.ui.appMargins.setContentsMargins(10, 10, 10, 10)
  59. self.ui.maximizeRestoreAppBtn.setToolTip("Maximize")
  60. self.ui.maximizeRestoreAppBtn.setIcon(QIcon(u":/icons/images/icons/icon_maximize.png"))
  61. self.ui.frame_size_grip.show()
  62. self.left_grip.show()
  63. self.right_grip.show()
  64. self.top_grip.show()
  65. self.bottom_grip.show()
  66. # RETURN STATUS
  67. # ///////////////////////////////////////////////////////////////
  68. def returStatus(self):
  69. return GLOBAL_STATE
  70. # SET STATUS
  71. # ///////////////////////////////////////////////////////////////
  72. def setStatus(self, status):
  73. global GLOBAL_STATE
  74. GLOBAL_STATE = status
  75. # TOGGLE MENU
  76. # ///////////////////////////////////////////////////////////////
  77. def toggleMenu(self, enable):
  78. if enable:
  79. # GET WIDTH
  80. width = self.ui.leftMenuBg.width()
  81. maxExtend = Settings.MENU_WIDTH
  82. standard = 60
  83. # SET MAX WIDTH
  84. if width == 60:
  85. widthExtended = maxExtend
  86. else:
  87. widthExtended = standard
  88. # ANIMATION
  89. self.animation = QPropertyAnimation(self.ui.leftMenuBg, b"minimumWidth")
  90. self.animation.setDuration(Settings.TIME_ANIMATION)
  91. self.animation.setStartValue(width)
  92. self.animation.setEndValue(widthExtended)
  93. self.animation.setEasingCurve(QEasingCurve.InOutQuart)
  94. self.animation.start()
  95. # TOGGLE LEFT BOX
  96. # ///////////////////////////////////////////////////////////////
  97. def toggleLeftBox(self, enable):
  98. if enable:
  99. # GET WIDTH
  100. width = self.ui.extraLeftBox.width()
  101. widthRightBox = self.ui.extraRightBox.width()
  102. maxExtend = Settings.LEFT_BOX_WIDTH
  103. color = Settings.BTN_LEFT_BOX_COLOR
  104. standard = 0
  105. # GET BTN STYLE
  106. style = self.ui.toggleLeftBox.styleSheet()
  107. # SET MAX WIDTH
  108. if width == 0:
  109. widthExtended = maxExtend
  110. # SELECT BTN
  111. self.ui.toggleLeftBox.setStyleSheet(style + color)
  112. if widthRightBox != 0:
  113. style = self.ui.settingsTopBtn.styleSheet()
  114. self.ui.settingsTopBtn.setStyleSheet(style.replace(Settings.BTN_RIGHT_BOX_COLOR, ''))
  115. else:
  116. widthExtended = standard
  117. # RESET BTN
  118. self.ui.toggleLeftBox.setStyleSheet(style.replace(color, ''))
  119. UIFunctions.start_box_animation(self, width, widthRightBox, "left")
  120. # TOGGLE RIGHT BOX
  121. # ///////////////////////////////////////////////////////////////
  122. def toggleRightBox(self, enable):
  123. if enable:
  124. # GET WIDTH
  125. width = self.ui.extraRightBox.width()
  126. widthLeftBox = self.ui.extraLeftBox.width()
  127. maxExtend = Settings.RIGHT_BOX_WIDTH
  128. color = Settings.BTN_RIGHT_BOX_COLOR
  129. standard = 0
  130. # GET BTN STYLE
  131. style = self.ui.settingsTopBtn.styleSheet()
  132. # SET MAX WIDTH
  133. if width == 0:
  134. widthExtended = maxExtend
  135. # SELECT BTN
  136. self.ui.settingsTopBtn.setStyleSheet(style + color)
  137. if widthLeftBox != 0:
  138. style = self.ui.toggleLeftBox.styleSheet()
  139. self.ui.toggleLeftBox.setStyleSheet(style.replace(Settings.BTN_LEFT_BOX_COLOR, ''))
  140. else:
  141. widthExtended = standard
  142. # RESET BTN
  143. self.ui.settingsTopBtn.setStyleSheet(style.replace(color, ''))
  144. UIFunctions.start_box_animation(self, widthLeftBox, width, "right")
  145. def start_box_animation(self, left_box_width, right_box_width, direction):
  146. right_width = 0
  147. left_width = 0
  148. # Check values
  149. if left_box_width == 0 and direction == "left":
  150. left_width = 240
  151. else:
  152. left_width = 0
  153. # Check values
  154. if right_box_width == 0 and direction == "right":
  155. right_width = 240
  156. else:
  157. right_width = 0
  158. # ANIMATION LEFT BOX
  159. self.left_box = QPropertyAnimation(self.ui.extraLeftBox, b"minimumWidth")
  160. self.left_box.setDuration(Settings.TIME_ANIMATION)
  161. self.left_box.setStartValue(left_box_width)
  162. self.left_box.setEndValue(left_width)
  163. self.left_box.setEasingCurve(QEasingCurve.InOutQuart)
  164. # ANIMATION RIGHT BOX
  165. self.right_box = QPropertyAnimation(self.ui.extraRightBox, b"minimumWidth")
  166. self.right_box.setDuration(Settings.TIME_ANIMATION)
  167. self.right_box.setStartValue(right_box_width)
  168. self.right_box.setEndValue(right_width)
  169. self.right_box.setEasingCurve(QEasingCurve.InOutQuart)
  170. # GROUP ANIMATION
  171. self.group = QParallelAnimationGroup()
  172. self.group.addAnimation(self.left_box)
  173. self.group.addAnimation(self.right_box)
  174. self.group.start()
  175. # SELECT/DESELECT MENU
  176. # ///////////////////////////////////////////////////////////////
  177. # SELECT
  178. def selectMenu(getStyle):
  179. select = getStyle + Settings.MENU_SELECTED_STYLESHEET
  180. return select
  181. # DESELECT
  182. def deselectMenu(getStyle):
  183. deselect = getStyle.replace(Settings.MENU_SELECTED_STYLESHEET, "")
  184. return deselect
  185. # START SELECTION
  186. def selectStandardMenu(self, widget):
  187. for w in self.ui.topMenu.findChildren(QPushButton):
  188. if w.objectName() == widget:
  189. w.setStyleSheet(UIFunctions.selectMenu(w.styleSheet()))
  190. # RESET SELECTION
  191. def resetStyle(self, widget):
  192. for w in self.ui.topMenu.findChildren(QPushButton):
  193. if w.objectName() != widget:
  194. w.setStyleSheet(UIFunctions.deselectMenu(w.styleSheet()))
  195. # IMPORT THEMES FILES QSS/CSS
  196. # ///////////////////////////////////////////////////////////////
  197. def theme(self, file, useCustomTheme):
  198. if useCustomTheme:
  199. str = open(file, 'r').read()
  200. self.ui.styleSheet.setStyleSheet(str)
  201. # START - GUI DEFINITIONS
  202. # ///////////////////////////////////////////////////////////////
  203. def uiDefinitions(self):
  204. def dobleClickMaximizeRestore(event):
  205. # IF DOUBLE CLICK CHANGE STATUS
  206. if event.type() == QEvent.MouseButtonDblClick:
  207. QTimer.singleShot(250, lambda: UIFunctions.maximize_restore(self))
  208. self.ui.titleRightInfo.mouseDoubleClickEvent = dobleClickMaximizeRestore
  209. if Settings.ENABLE_CUSTOM_TITLE_BAR:
  210. # STANDARD TITLE BAR
  211. self.setWindowFlags(Qt.FramelessWindowHint)
  212. self.setAttribute(Qt.WA_TranslucentBackground)
  213. # MOVE WINDOW / MAXIMIZE / RESTORE
  214. def moveWindow(event):
  215. # IF MAXIMIZED CHANGE TO NORMAL
  216. if UIFunctions.returStatus(self):
  217. UIFunctions.maximize_restore(self)
  218. # MOVE WINDOW
  219. if event.buttons() == Qt.LeftButton:
  220. self.move(self.pos() + event.globalPos() - self.dragPos)
  221. self.dragPos = event.globalPos()
  222. event.accept()
  223. self.ui.titleRightInfo.mouseMoveEvent = moveWindow
  224. # CUSTOM GRIPS
  225. self.left_grip = CustomGrip(self, Qt.LeftEdge, True)
  226. self.right_grip = CustomGrip(self, Qt.RightEdge, True)
  227. self.top_grip = CustomGrip(self, Qt.TopEdge, True)
  228. self.bottom_grip = CustomGrip(self, Qt.BottomEdge, True)
  229. else:
  230. self.ui.appMargins.setContentsMargins(0, 0, 0, 0)
  231. self.ui.minimizeAppBtn.hide()
  232. self.ui.maximizeRestoreAppBtn.hide()
  233. self.ui.closeAppBtn.hide()
  234. self.ui.frame_size_grip.hide()
  235. # DROP SHADOW
  236. self.shadow = QGraphicsDropShadowEffect(self)
  237. self.shadow.setBlurRadius(17)
  238. self.shadow.setXOffset(0)
  239. self.shadow.setYOffset(0)
  240. self.shadow.setColor(QColor(0, 0, 0, 150))
  241. self.ui.bgApp.setGraphicsEffect(self.shadow)
  242. # RESIZE WINDOW
  243. self.sizegrip = QSizeGrip(self.ui.frame_size_grip)
  244. self.sizegrip.setStyleSheet("width: 20px; height: 20px; margin 0px; padding: 0px;")
  245. # MINIMIZE
  246. self.ui.minimizeAppBtn.clicked.connect(lambda: self.showMinimized())
  247. # MAXIMIZE/RESTORE
  248. self.ui.maximizeRestoreAppBtn.clicked.connect(lambda: UIFunctions.maximize_restore(self))
  249. # CLOSE APPLICATION
  250. self.ui.closeAppBtn.clicked.connect(lambda: self.close())
  251. def resize_grips(self):
  252. if Settings.ENABLE_CUSTOM_TITLE_BAR:
  253. self.left_grip.setGeometry(0, 10, 10, self.height())
  254. self.right_grip.setGeometry(self.width() - 10, 10, 10, self.height())
  255. self.top_grip.setGeometry(0, 0, self.width(), 10)
  256. self.bottom_grip.setGeometry(0, self.height() - 10, self.width(), 10)
  257. # 上传文件的方法
  258. def execute_script_based_on_selection(self, file_path):
  259. current_text = self.ui.comboBox_2.currentText()
  260. # db_path = r"D:/Code/ControlNetwork/UI/SQL/DataBase.db"
  261. # 获取当前脚本所在的目录
  262. current_dir = os.path.dirname(os.path.abspath(__file__))
  263. # 构建 SQL 文件夹的相对路径(上一级的上一级中的 SQL 文件夹)
  264. sql_folder = os.path.join(current_dir, '..', '..', 'SQL')
  265. # 将相对路径转换为绝对路径
  266. sql_folder = os.path.abspath(sql_folder)
  267. db_path = os.path.join(sql_folder, f"{self.ui.comboBox.currentText()}.db")
  268. file_path = file_path
  269. if current_text == "水准测段高差稳定计算":
  270. GC.main_function(file_path, db_path)
  271. # 添加水准执行代码
  272. elif current_text == "控制网复测平面基准计算":
  273. GS.main_function(file_path, db_path)
  274. # 添加控制网执行代码
  275. elif current_text == "平面控制网稳定性计算":
  276. WD.main_function(file_path, db_path)
  277. # 添加平面控制网执行代码
  278. # 计算与展示文件的方法
  279. def compute_show_process_excel_file(self, file_path):
  280. current_text = self.ui.comboBox_2.currentText()
  281. # 获取当前脚本所在的目录
  282. current_dir = os.path.dirname(os.path.abspath(__file__))
  283. # 构建 SQL 文件夹的相对路径(上一级的上一级中的 SQL 文件夹)
  284. sql_folder = os.path.join(current_dir, '..', '..', 'SQL')
  285. # 将相对路径转换为绝对路径
  286. sql_folder = os.path.abspath(sql_folder)
  287. db_path = os.path.join(sql_folder, f"{self.ui.comboBox.currentText()}.db")
  288. # 转换为utf-8
  289. excelname = os.path.basename(file_path) # 文件名
  290. utf_en = excelname.encode('utf-8') # 转换文件名为utf-8编码形式
  291. if current_text == "水准测段高差稳定计算":
  292. GCcompute.main_function(file_path, db_path)
  293. GCshow.main_function(self.ui, db_path, utf_en)
  294. elif current_text == "控制网复测平面基准计算":
  295. GScompute.main_function(excelname, db_path)
  296. GSshow.main_function(self.ui, db_path, utf_en)
  297. elif current_text == "平面控制网稳定性计算":
  298. WDcompute.main_function(excelname, db_path)
  299. WDshow.main_function(self.ui, db_path, utf_en)
  300. # 文件导出的方法
  301. def export_database_to_excel(self, file_path):
  302. current_text = self.ui.comboBox_2.currentText()
  303. # 获取当前脚本所在的目录
  304. current_dir = os.path.dirname(os.path.abspath(__file__))
  305. # 构建 SQL 文件夹的相对路径(上一级的上一级中的 SQL 文件夹)
  306. sql_folder = os.path.join(current_dir, '..', '..', 'SQL')
  307. # 将相对路径转换为绝对路径
  308. sql_folder = os.path.abspath(sql_folder)
  309. db_path = os.path.join(sql_folder, f"{self.ui.comboBox.currentText()}.db")
  310. # 转换为utf-8
  311. excelname = os.path.basename(file_path) # 文件名
  312. utf_en = excelname.encode('utf-8') # 转换文件名为utf-8编码形式
  313. if current_text == "水准测段高差稳定计算":
  314. GCExport.main_function_result(self, utf_en, db_path)
  315. elif current_text == "控制网复测平面基准计算":
  316. GSExport.main_function(self, db_path, excelname)
  317. elif current_text == "平面控制网稳定性计算":
  318. WDExport.main_function(self, db_path, excelname)
  319. else:
  320. QMessageBox.warning(self, '警告', '请选择有效的计算类型')
  321. # 数据一览,点击查询
  322. def search_data_to_show(self, file_path, current_text, tablename):
  323. utf_en = tablename.encode('utf-8') # 转换文件名为utf-8编码形式
  324. if current_text == "水准测段高差稳定计算":
  325. selectModel = GCshow.search_show_function(self.ui, file_path, utf_en)
  326. return selectModel
  327. elif current_text == "控制网复测平面基准计算":
  328. selectModel = GSshow.search_show_function(self.ui, file_path, utf_en)
  329. return selectModel
  330. elif current_text == "平面控制网稳定性计算":
  331. selectModel = WDshow.search_show_function(self.ui, file_path, utf_en)
  332. return selectModel
  333. # 删除行数据
  334. def del_row_from_db(self, row, methodName, tableName_utf8, dbPath):
  335. db1 = sqlite3.connect(dbPath)
  336. cursor1 = db1.cursor()
  337. # 通过行锁定对应的字段
  338. if methodName == '水准测段高差稳定计算':
  339. sqlstr1 = """SELECT * FROM GC_Input_Point WHERE TableName = ? LIMIT 1 OFFSET ?"""
  340. cursor1.execute(sqlstr1, (tableName_utf8, row,))
  341. result1 = cursor1.fetchall()
  342. list1 = result1[0]
  343. # 100%准确查询
  344. # sqlstr3 = """SELECT * FROM GC_Input_Point WHERE TableName = ? and New_SPName = ? and New_EPName = ? and New_HDiff = ? and New_RLen = ?"""
  345. # cursor1.execute(sqlstr3, (tableName_utf8, list1[7], list1[8], list1[11], list1[12],))
  346. # result3 = cursor1.fetchall()
  347. sqlstr2 = """DELETE FROM GC_Input_Point WHERE TableName = ? and New_SPName = ? and New_EPName = ? and New_HDiff = ? and New_RLen = ?"""
  348. cursor1.execute(sqlstr2, (tableName_utf8, list1[7], list1[8], list1[11], list1[12],))
  349. # # 获取删除的记录数量
  350. # deleted_count = cursor1.rowcount
  351. # 直接使用计算方式
  352. tableName = tableName_utf8.decode('utf-8')
  353. # 先把结果相关的点数据删一下
  354. sqlstr3 = """DELETE FROM GC_Output_Point WHERE TableName = ?"""
  355. cursor1.execute(sqlstr3, (tableName_utf8,))
  356. # 提交事务
  357. db1.commit()
  358. # 关闭db
  359. db1.close()
  360. GCcompute.main_function(tableName, dbPath)
  361. GCshow.main_function(self.ui, dbPath, tableName_utf8)
  362. elif methodName == '控制网复测平面基准计算':
  363. sqlstr1 = """SELECT * FROM GS_Input_Point WHERE TableName = ? LIMIT 1 OFFSET ?"""
  364. cursor1.execute(sqlstr1, (tableName_utf8, row,))
  365. result1 = cursor1.fetchall()
  366. list1 = result1[0]
  367. # 100%准确查询
  368. # sqlstr3 = """SELECT * FROM GC_Input_Point WHERE TableName = ? and New_SPName = ? and New_EPName = ? and New_HDiff = ? and New_RLen = ?"""
  369. # cursor1.execute(sqlstr3, (tableName_utf8, list1[7], list1[8], list1[11], list1[12],))
  370. # result3 = cursor1.fetchall()
  371. sqlstr2 = """DELETE FROM GS_Input_Point WHERE TableName = ? and PointName = ? and New_X = ? and New_Y = ?"""
  372. cursor1.execute(sqlstr2, (tableName_utf8, list1[7], list1[5], list1[6],))
  373. # # 获取删除的记录数量
  374. # deleted_count = cursor1.rowcount
  375. # 直接使用计算方式
  376. tableName = tableName_utf8.decode('utf-8')
  377. # 先把结果相关的点和参数删一下
  378. sqlstr3 = """DELETE FROM GS_Result_Point WHERE TableName = ?"""
  379. cursor1.execute(sqlstr3, (tableName_utf8,))
  380. sqlstr4 = """DELETE FROM GS_Trans_Point WHERE TableName = ?"""
  381. cursor1.execute(sqlstr4, (tableName_utf8,))
  382. sqlstr5 = """DELETE FROM GS_Trans_Param WHERE TableName = ?"""
  383. cursor1.execute(sqlstr5, (tableName_utf8,))
  384. # 提交事务
  385. db1.commit()
  386. # 关闭db
  387. db1.close()
  388. GScompute.main_function(tableName, dbPath)
  389. GSshow.main_function(self.ui, dbPath, tableName_utf8)
  390. else:
  391. # 平面控制网稳定性计算
  392. sqlstr1 = """SELECT * FROM WD_Input_Point WHERE TableName = ? LIMIT 1 OFFSET ?"""
  393. cursor1.execute(sqlstr1, (tableName_utf8, row,))
  394. result1 = cursor1.fetchall()
  395. list1 = result1[0]
  396. # 100%准确查询
  397. # sqlstr3 = """SELECT * FROM GC_Input_Point WHERE TableName = ? and New_SPName = ? and New_EPName = ? and New_HDiff = ? and New_RLen = ?"""
  398. # cursor1.execute(sqlstr3, (tableName_utf8, list1[7], list1[8], list1[11], list1[12],))
  399. # result3 = cursor1.fetchall()
  400. sqlstr2 = """DELETE FROM WD_Input_Point WHERE TableName = ? and PointName = ? and New_X = ? and New_Y = ?"""
  401. cursor1.execute(sqlstr2, (tableName_utf8, list1[11], list1[8], list1[9],))
  402. # # 获取删除的记录数量
  403. # deleted_count = cursor1.rowcount
  404. # 直接使用计算方式
  405. tableName = tableName_utf8.decode('utf-8')
  406. # 先把结果相关的点和参数删一下
  407. sqlstr3 = """DELETE FROM WD_Result_Point WHERE TableName = ?"""
  408. cursor1.execute(sqlstr3, (tableName_utf8,))
  409. sqlstr4 = """DELETE FROM WD_Result_Param WHERE TableName = ?"""
  410. cursor1.execute(sqlstr4, (tableName_utf8,))
  411. # 提交事务
  412. db1.commit()
  413. # 关闭db
  414. db1.close()
  415. WDcompute.main_function(tableName, dbPath)
  416. WDshow.main_function(self.ui, dbPath, tableName_utf8)
  417. # END - GUI DEFINITIONS