test.py 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. # ===============================================================================
  4. #
  5. # test.py
  6. #
  7. # Test program for the simple GL Viewer.
  8. #
  9. # Copyright (c) 2011, Arne Schmitz <arne.schmitz@gmx.net>
  10. # All rights reserved.
  11. #
  12. # Redistribution and use in source and binary forms, with or without
  13. # modification, are permitted provided that the following conditions are met:
  14. # * Redistributions of source code must retain the above copyright
  15. # notice, this list of conditions and the following disclaimer.
  16. # * Redistributions in binary form must reproduce the above copyright
  17. # notice, this list of conditions and the following disclaimer in the
  18. # documentation and/or other materials provided with the distribution.
  19. # * Neither the name of the <organization> nor the
  20. # names of its contributors may be used to endorse or promote products
  21. # derived from this software without specific prior written permission.
  22. #
  23. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  24. # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  25. # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  26. # DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
  27. # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  28. # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  29. # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  30. # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  31. # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  32. # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  33. #
  34. # ===============================================================================
  35. import math
  36. import threading
  37. import time
  38. import sys
  39. from PyQt5.QtGui import *
  40. from PyQt5.QtWidgets import *
  41. from PyQt5.QtCore import *
  42. from MapGLWidget import MapGLWidget
  43. import json
  44. import dijkstra.Map as mp
  45. import ControllWidget
  46. import JointContrallerWidget
  47. import ManualOperationWidget
  48. import RobotData as RD
  49. import message_pb2 as message
  50. import google.protobuf.json_format as jtf
  51. import google.protobuf.text_format as tf
  52. from concurrent.futures import ThreadPoolExecutor
  53. import uuid
  54. from mytool.txt_helper.txt_operation import TXTOperation
  55. from custom_define import RobotName
  56. from mytool.RabbitMq_helper import async_communication as rabitmq
  57. # ===============================================================================
  58. class MainWindow(QMainWindow):
  59. """docstring for Mainwindow"""
  60. djks_map_ = mp.MapManager()
  61. ui_nodes = {}
  62. ui_nodes["street_nodes"] = []
  63. ui_nodes["space_nodes"] = []
  64. def __init__(self, parent=None):
  65. super(MainWindow, self).__init__(parent)
  66. self.basic()
  67. self.count_frame_ = ControllWidget.CountFrame()
  68. self.LoadMap()
  69. self.isLocalTest = False
  70. self.isAutoDispatchOnline = True
  71. rpc_1 = "192.168.0.70:9090"
  72. mqtt_1 = ["pyui1", "192.168.0.70", 1883, "admin", "zx123456"]
  73. rpc_2 = "192.168.0.71:9090"
  74. mqtt_2 = ["pyui2", "192.168.0.71", 1883, "admin", "zx123456"]
  75. if self.isLocalTest:
  76. rpc_1 = "127.0.0.1:9090"
  77. mqtt_1 = ["pyui-main", "127.0.0.1", 1883, "admin", "zx123456"]
  78. rpc_2 = "127.0.0.1:9091"
  79. mqtt_2 = ["pyui-child", "127.0.0.1", 1883, "admin", "zx123456"]
  80. config1 = {"label": RobotName.strAGVMain,
  81. "rpc": rpc_1,
  82. "street_nodes": self.ui_nodes["street_nodes"],
  83. "space_nodes": self.ui_nodes["space_nodes"],
  84. "mqtt": mqtt_1,
  85. "subTopics": {"agv_main/agv_statu": message.RobotStatu.__name__,
  86. "agv_main/nav_statu": message.NavStatu.__name__},
  87. "cmdTopic": "agv_main/nav_cmd",
  88. "robotColor": [0.7, 0.2, 0.3]}
  89. config2 = {"label": RobotName.strAGV2,
  90. "rpc": rpc_2,
  91. # "rpc": "127.0.0.1:9091",
  92. "street_nodes": self.ui_nodes["street_nodes"],
  93. "space_nodes": self.ui_nodes["space_nodes"],
  94. "mqtt": mqtt_2,
  95. "subTopics": {"agv_child/agv_statu": message.RobotStatu.__name__,
  96. "agv_child/nav_statu": message.NavStatu.__name__},
  97. "cmdTopic": "agv_child/nav_cmd",
  98. "robotColor": [0.4, 0.2, 0.8]}
  99. self.Controller1 = ControllWidget.ControlFrame(config1)
  100. self.Controller2 = ControllWidget.ControlFrame(config2)
  101. robot_dict = {self.Controller1.robot_.name_: self.Controller1.robot_,
  102. self.Controller2.robot_.name_: self.Controller2.robot_}
  103. self.ManualOperationWidget = ManualOperationWidget.ManualOperationWidget(robot_dict)
  104. splitter_main = self.split_()
  105. self.setCentralWidget(splitter_main)
  106. self.gl.SetRobot1Instance(self.Controller1.robot_)
  107. self.gl.SetRobot2Instance(self.Controller2.robot_)
  108. self.timer_ = QTimer()
  109. self.timer_.timeout.connect(self.Update)
  110. self.timer_.start(100)
  111. # 启动RabbitMQ
  112. self.g_rabbitmq = None
  113. if self.isAutoDispatchOnline:
  114. self.g_rabbitmq = rabitmq.RabbitAsyncCommunicator("192.168.0.201", 5672, "zx", "123456")
  115. calbbacks = [["agv_park_command_request_queue", self.recv_park_request],
  116. ["agv_pick_command_request_queue", self.recv_pick_request]]
  117. self.g_rabbitmq.Init(calbbacks, None)
  118. self.g_rabbitmq.setDaemon(True) # 守护线程随主线程结束
  119. self.g_rabbitmq.start()
  120. def recv_park_request(self, msg):
  121. print("Recv_park_request------------------\n", msg)
  122. park_table = message.park_table()
  123. try:
  124. tf.Parse(msg, park_table)
  125. except Exception as e:
  126. print("Parse error\n")
  127. # split_msg = msg.split(' ')
  128. # result = [float(split_msg[0]), float(split_msg[1]), float(split_msg[2])]
  129. if self.isAutoDispatchOnline:
  130. self.AutoParkTask(park_table)
  131. # self.g_rabbitmq.publish()
  132. def recv_pick_request(self, msg):
  133. print("Recv_pick_request------------------\n", msg)
  134. pick_table = message.pick_table()
  135. try:
  136. tf.Parse(msg, pick_table)
  137. except Exception as e:
  138. print("Parse error\n")
  139. # split_msg = msg.split(' ')
  140. # result = [float(split_msg[0]), float(split_msg[1]), float(split_msg[2])]
  141. if self.isAutoDispatchOnline:
  142. self.AutoPickTask(pick_table)
  143. def updateMap_park(self, entrance_id, pose, type): # 0:前车轨迹,1:后车轨迹,2:添加整车轨迹
  144. self.djks_map_.Reset() # 重置地图
  145. trans_x, trans_y, trans_a = pose
  146. self.djks_map_.AddVertex_t(mp.SpaceNode(entrance_id, trans_x, trans_y, trans_a)) # 更新库位点
  147. entrance_street_nodes = self.ComputeStreetNode(entrance_id, trans_x, trans_y, trans_a)
  148. print("entrance_space pose: ", self.djks_map_.map_t.graph_.points[entrance_id])
  149. if type == 0:
  150. self.djks_map_.AddVertex_t(mp.StreetNode("FInput_R1101", entrance_street_nodes[0][0],
  151. entrance_street_nodes[0][1])) # 更新库位点对应马路点
  152. self.djks_map_.AddEdge_t(entrance_id, "FInput_R1101")
  153. # 加临时边
  154. for node_id, value in self.djks_map_.VertexDict().items():
  155. if node_id.find("FInput") >= 0:
  156. self.djks_map_.AddEdge_t("FInput_R1101", node_id)
  157. print("F entrance_street pose ", self.djks_map_.map_t.graph_.points["FInput_R1101"])
  158. elif type == 1:
  159. self.djks_map_.AddVertex_t(mp.StreetNode("BInput_R1101", entrance_street_nodes[2][0],
  160. entrance_street_nodes[2][1])) # 更新库位点对应马路点
  161. self.djks_map_.AddEdge_t(entrance_id, "BInput_R1101")
  162. # 加临时边
  163. for node_id, value in self.djks_map_.VertexDict().items():
  164. if node_id.find("BInput") >= 0:
  165. self.djks_map_.AddEdge_t("BInput_R1101", node_id)
  166. else:
  167. self.djks_map_.AddVertex_t(mp.StreetNode("CInput_R1101", entrance_street_nodes[1][0],
  168. entrance_street_nodes[1][1])) # 更新库位点对应马路点
  169. self.djks_map_.AddEdge_t(entrance_id, "CInput_R1101")
  170. for node_id, value in self.djks_map_.VertexDict().items():
  171. if node_id.find("CInput") >= 0:
  172. self.djks_map_.AddEdge_t("CInput_R1101", node_id)
  173. print("C entrance_street pose ", self.djks_map_.map_t.graph_.points["CInput_R1101"])
  174. def GetMainFrontBackAGV(self):
  175. controlMain = self.Controller1
  176. nagtive = False
  177. if controlMain.robot_.timedRobotStatu_.statu.theta < 0:
  178. nagtive = True
  179. control1 = None
  180. control2 = None
  181. if nagtive == False:
  182. control1 = self.Controller1
  183. control2 = self.Controller2
  184. else:
  185. control2 = self.Controller1
  186. control1 = self.Controller2
  187. return [controlMain,control1,control2]
  188. def AutoParkTask(self, park_table: message.park_table = None):
  189. print("AutoParkTask:---------------------\n")
  190. [controlMain,control1,control2]=self.GetMainFrontBackAGV()
  191. entrance_id = "S" + str(park_table.terminal_id) # "S1101"
  192. entrance_x, entrance_y, entrance_theta = [park_table.entrance_measure_info.measure_info_to_plc_forward.cx,
  193. park_table.entrance_measure_info.measure_info_to_plc_forward.cy,
  194. (
  195. 90 + park_table.entrance_measure_info.measure_info_to_plc_forward.theta) / 180 * math.pi]
  196. # 变换到地图坐标系
  197. # [dx, dy, da] = [-0.223411843181, -0.643030941486, 178.9478 / 180 * math.pi]
  198. # trans_x = -0.99983137 * entrance_x - 0.01836309 * entrance_y + dx
  199. # trans_y = 0.01836309 * entrance_x - 0.99983137 * entrance_y + dy
  200. [dx, dy, da] = [-0.234040126204, -0.647539079189, 178.9302736990612 / 180 * math.pi]
  201. trans_x = -0.999825716019 * entrance_x - 0.018668506294 * entrance_y + dx
  202. trans_y = 0.018668506294 * entrance_x - 0.999825716019 * entrance_y + dy
  203. trans_a = entrance_theta + da - math.pi
  204. while trans_a < 0:
  205. trans_a += math.pi
  206. print("entrance:", entrance_id, trans_x, trans_y, trans_a / math.pi * 180)
  207. target_id = "S" + str(park_table.allocated_space_info.table_id) # "S147"
  208. print("target:", target_id)
  209. # 轴距
  210. wheel_base = park_table.entrance_measure_info.measure_info_to_plc_forward.wheelbase
  211. control1.WheelBaseEdit.setText(str(wheel_base))
  212. control2.WheelBaseEdit.setText(str(wheel_base))
  213. trans_x += wheel_base / 2 * math.cos(trans_a)
  214. trans_y += wheel_base / 2 * math.sin(trans_a)
  215. # # 双单车入库-----------------------------------------------------
  216. threadPool = ThreadPoolExecutor(2)
  217. threadPool.submit(control1.robot_.SwitchMoveMode, 0, wheel_base)
  218. threadPool.submit(control2.robot_.SwitchMoveMode, 0, wheel_base)
  219. threadPool.shutdown(wait=True)
  220. self.updateMap_park(entrance_id, [trans_x, trans_y, trans_a], 0)
  221. cur_pose1 = control1.robot_.timedRobotStatu_.statu
  222. [label, pt] = mp.MapManager().findNeastNode([cur_pose1.x, cur_pose1.y])
  223. control1.robot_.GeneratePath(label, entrance_id)
  224. print("Main: begin:%s target:%s wheelBase:%f" % (label, entrance_id, wheel_base))
  225. # 后车 ------------------------------------------------------
  226. self.updateMap_park(entrance_id, [trans_x, trans_y, trans_a], 1)
  227. cur_pose2 = control2.robot_.timedRobotStatu_.statu
  228. [label, pt] = mp.MapManager().findNeastNode([cur_pose2.x, cur_pose2.y])
  229. control2.robot_.GeneratePath(label, entrance_id)
  230. print("Child: begin:%s target:%s wheelBase:%f" % (label, entrance_id, wheel_base))
  231. autoDirect = True
  232. threadPool = ThreadPoolExecutor(2)
  233. threadPool.submit(control1.robot_.Navigatting,
  234. label, entrance_id, autoDirect, wheel_base)
  235. threadPool.submit(control2.robot_.Navigatting,
  236. label, entrance_id, autoDirect, wheel_base)
  237. threadPool.shutdown(wait=True)
  238. print(" input entrance completed!!!!")
  239. threadPool = ThreadPoolExecutor(1)
  240. threadPool.submit(controlMain.robot_.SwitchMoveMode, 1, wheel_base)
  241. threadPool.shutdown(wait=True)
  242. threadPool = ThreadPoolExecutor(1)
  243. threadPool.submit(controlMain.robot_.ClampClose)
  244. threadPool.shutdown(wait=True)
  245. # 整车入库---------------------------------
  246. self.updateMap_park(entrance_id, [trans_x, trans_y, trans_a], 2)
  247. controlMain.robot_.GeneratePath(entrance_id, target_id)
  248. print("begin:%s target:%s wheelBase:%f" % (entrance_id, target_id, wheel_base))
  249. threadPool = ThreadPoolExecutor(1)
  250. threadPool.submit(controlMain.robot_.Navigatting,
  251. entrance_id, target_id, autoDirect, wheel_base)
  252. threadPool.shutdown(wait=True)
  253. # 整车松夹池------------------------------------
  254. threadPool = ThreadPoolExecutor(1)
  255. threadPool.submit(controlMain.robot_.ClampOpen)
  256. threadPool.shutdown(wait=True)
  257. threadPool = ThreadPoolExecutor(1)
  258. threadPool.submit(controlMain.robot_.SwitchMoveMode, 0, wheel_base)
  259. threadPool.shutdown(wait=True)
  260. # 双单车出库
  261. controlMain, control1, control2 = self.GetMainFrontBackAGV()
  262. self.djks_map_.Reset() # 重置地图
  263. control1.robot_.GeneratePath(target_id, "FInput_R147")
  264. control2.robot_.GeneratePath(target_id, "BInput_R147")
  265. threadPool = ThreadPoolExecutor(2)
  266. threadPool.submit(control1.robot_.Navigatting,
  267. target_id, "FInput_R147", autoDirect, wheel_base)
  268. threadPool.submit(control2.robot_.Navigatting,
  269. target_id, "BInput_R147", autoDirect, wheel_base)
  270. threadPool.shutdown(wait=True)
  271. def updateMap_pick(self, export_id, type): # 0:前车轨迹,1:后车轨迹,2:添加整车轨迹
  272. self.djks_map_.Reset() # 重置地图
  273. # export_id = "S1103"
  274. # 添加出口车位点
  275. self.djks_map_.AddVertex_t(mp.SpaceNode(export_id, self.djks_map_.map_t.graph_.points["S1100"][0],
  276. self.djks_map_.map_t.graph_.points["S1100"][1], 90)) # 更新库位点对应马路点
  277. if type == 0:
  278. self.djks_map_.AddEdge_t(export_id, "FInput_R1100")
  279. elif type == 1:
  280. self.djks_map_.AddEdge_t(export_id, "BInput_R1100")
  281. elif type == 2:
  282. export_street_node_x = self.djks_map_.map_t.graph_.points["CInput_R1100"][0]
  283. export_street_node_y = self.djks_map_.map_t.graph_.points["CInput_R1100"][1]
  284. self.djks_map_.AddVertex_t(mp.StreetNode("CInput_R1103", export_street_node_x,
  285. export_street_node_y)) # 更新库位点对应马路点
  286. self.djks_map_.AddEdge_t(export_id, "CInput_R1103")
  287. for node_id, value in self.djks_map_.VertexDict().items():
  288. if node_id.find("CInput") >= 0:
  289. self.djks_map_.AddEdge_t("CInput_R1103", node_id)
  290. print("C entrance_street pose ", self.djks_map_.map_t.graph_.points["CInput_R1103"])
  291. def AutoPickTask(self, pick_table: message.pick_table = None):
  292. print("AutoPickTask:---------------------\n")
  293. controlMain, control1, control2 = self.GetMainFrontBackAGV()
  294. self.djks_map_.Reset() # 重置地图
  295. space_id = "S" + str(pick_table.actually_space_info.table_id) # "S147"
  296. export_id = "S" + str(pick_table.terminal_id) # "S1103"
  297. print(space_id, export_id)
  298. # 轴距
  299. wheel_base = pick_table.actually_measure_info.measure_info_to_plc_forward.wheelbase
  300. control1.WheelBaseEdit.setText(str(wheel_base))
  301. control2.WheelBaseEdit.setText(str(wheel_base))
  302. # 双单车入库
  303. threadPool = ThreadPoolExecutor(2)
  304. threadPool.submit(control1.robot_.SwitchMoveMode, 0, wheel_base)
  305. threadPool.submit(control2.robot_.SwitchMoveMode, 0, wheel_base)
  306. threadPool.shutdown(wait=True)
  307. cur_pose1 = control1.robot_.timedRobotStatu_.statu
  308. [label, pt] = mp.MapManager().findNeastNode([cur_pose1.x, cur_pose1.y])
  309. control1.robot_.GeneratePath(label, space_id)
  310. print("Main: begin:%s target:%s wheelBase:%f" % (label, space_id, wheel_base))
  311. cur_pose2 = control2.robot_.timedRobotStatu_.statu
  312. [label, pt] = mp.MapManager().findNeastNode([cur_pose2.x, cur_pose2.y])
  313. control2.robot_.GeneratePath(label, space_id)
  314. print("Child: begin:%s target:%s wheelBase:%f" % (label, space_id, wheel_base))
  315. autoDirect = True
  316. threadPool = ThreadPoolExecutor(2)
  317. threadPool.submit(control1.robot_.Navigatting,
  318. label, space_id, autoDirect, wheel_base)
  319. threadPool.submit(control2.robot_.Navigatting,
  320. label, space_id, autoDirect, wheel_base)
  321. threadPool.shutdown(wait=True)
  322. # 整车夹持------------------------------------
  323. print(" input space completed!!!!")
  324. threadPool = ThreadPoolExecutor(1)
  325. threadPool.submit(controlMain.robot_.SwitchMoveMode, 1, wheel_base)
  326. threadPool.shutdown(wait=True)
  327. threadPool = ThreadPoolExecutor(1)
  328. threadPool.submit(controlMain.robot_.ClampClose)
  329. threadPool.shutdown(wait=True)
  330. # 整车到出口---------------------------------
  331. self.updateMap_pick(export_id, 2)
  332. controlMain.robot_.GeneratePath(space_id, export_id)
  333. print("Total: begin:%s target:%s wheelBase:%f" % (space_id, export_id, wheel_base))
  334. threadPool = ThreadPoolExecutor(1)
  335. threadPool.submit(controlMain.robot_.Navigatting,
  336. space_id, export_id, True, wheel_base)
  337. threadPool.shutdown(wait=True)
  338. # 整车松夹池------------------------------------
  339. threadPool = ThreadPoolExecutor(1)
  340. threadPool.submit(controlMain.robot_.ClampOpen)
  341. threadPool.shutdown(wait=True)
  342. threadPool = ThreadPoolExecutor(1)
  343. threadPool.submit(controlMain.robot_.SwitchMoveMode, 0, wheel_base)
  344. threadPool.shutdown(wait=True)
  345. # 双单车出库
  346. controlMain, control1, control2 = self.GetMainFrontBackAGV()
  347. self.updateMap_pick(export_id, 0)
  348. control1.robot_.GeneratePath(export_id, "FInput_R1100")
  349. self.updateMap_pick(export_id, 1)
  350. control2.robot_.GeneratePath(export_id, "BInput_R1100")
  351. threadPool = ThreadPoolExecutor(2)
  352. threadPool.submit(control1.robot_.Navigatting,
  353. export_id, "FInput_R1100", True, wheel_base)
  354. threadPool.submit(control2.robot_.Navigatting,
  355. export_id, "BInput_R1100", True, wheel_base)
  356. threadPool.shutdown(wait=True)
  357. def ComputeStreetNode(self, s_id, s_x, s_y, s_theta):
  358. """
  359. """
  360. n_x, n_y = 0, 0
  361. if s_id == "S1101":
  362. n_y = self.djks_map_.map_t.graph_.points["CInput_R1100"][1]
  363. k = math.tan(s_theta)
  364. n_x = (n_y - s_y) / k + s_x # 弧度
  365. n_yF = self.djks_map_.map_t.graph_.points["FInput_R1100"][1]
  366. n_xF = (n_yF - s_y) / k + s_x # 弧度
  367. n_yB = self.djks_map_.map_t.graph_.points["BInput_R1100"][1]
  368. n_xB = (n_yB - s_y) / k + s_x # 弧度
  369. # print(n_x, n_y)
  370. return [[n_xF, n_yF], [n_x, n_y], [n_xB, n_yB]]
  371. def LoadMap(self):
  372. self.gl = MapGLWidget() # 将opengl例子嵌入GUI
  373. map = self.load_map("./map.json")
  374. for node in map['street_nodes'].items():
  375. [id, point] = node
  376. street_node = mp.StreetNode(id, point[0], point[1])
  377. self.djks_map_.AddVertex(street_node)
  378. self.gl.AddNode([id, "street_node", point])
  379. self.ui_nodes["street_nodes"].append(id)
  380. for node in map['space_nodes'].items():
  381. [id, point] = node
  382. [x, y, yaw] = point
  383. space_node = mp.SpaceNode(id, point[0], point[1], yaw)
  384. self.djks_map_.AddVertex(space_node)
  385. glNode = [id, "space_node", [x, y]]
  386. self.gl.AddNode(glNode)
  387. self.ui_nodes["space_nodes"].append(id)
  388. for road in map['roads'].items():
  389. self.gl.AddRoad(road)
  390. [_, points] = road
  391. for pt1 in points:
  392. for pt2 in points:
  393. if not pt1 == pt2:
  394. self.djks_map_.AddEdge(pt1, pt2)
  395. def load_map(self, file):
  396. with open(file, 'r', encoding='utf-8') as fp:
  397. map = json.load(fp)
  398. return map
  399. def Update(self):
  400. self.gl.update()
  401. if self.isAutoDispatchOnline:
  402. # self.Controller1.setEnabled(False)
  403. # self.Controller2.setEnabled(False)
  404. pass
  405. else:
  406. self.Controller1.setVisible(True)
  407. self.Controller2.setVisible(True)
  408. # 窗口基础属性
  409. def basic(self):
  410. # 设置标题,大小,图标
  411. self.setWindowTitle("GT")
  412. self.resize(1100, 650)
  413. self.setWindowIcon(QIcon("./image/Gt.png"))
  414. # 居中显示
  415. screen = QDesktopWidget().geometry()
  416. self_size = self.geometry()
  417. self.move(int((screen.width() - self_size.width()) / 2), int((screen.height() - self_size.height()) / 2))
  418. def closeEvent(self, QCloseEvent):
  419. self.gl.close()
  420. print("close...")
  421. # 分割窗口
  422. def split_(self):
  423. splitter_main = QSplitter(Qt.Horizontal)
  424. splitter = QSplitter(Qt.Vertical)
  425. splitter.addWidget(self.count_frame_)
  426. splitter.addWidget(self.Controller1)
  427. splitter.addWidget(self.Controller2)
  428. splitter.addWidget(self.ManualOperationWidget)
  429. splitter.setStretchFactor(0, 1)
  430. splitter.setStretchFactor(1, 3)
  431. splitter.setStretchFactor(2, 3)
  432. splitter.setStretchFactor(3, 1)
  433. splitter_main.addWidget(splitter)
  434. splitter_main.addWidget(self.gl)
  435. splitter_main.setStretchFactor(0, 1)
  436. splitter_main.setStretchFactor(2, 4)
  437. return splitter_main
  438. if __name__ == "__main__":
  439. app = QApplication(sys.argv)
  440. win = MainWindow()
  441. win.show()
  442. sys.exit(app.exec_())
  443. # ===============================================================================
  444. # Main
  445. # ===============================================================================
  446. '''app = QApplication(sys.argv)
  447. mainWindow = MapGLWidget()
  448. mainWindow.show()
  449. mainWindow.raise_() # Need this at least on OS X, otherwise the window ends up in background
  450. sys.exit(app.exec_())'''
  451. # ===============================================================================
  452. #
  453. # Local Variables:
  454. # mode: Python
  455. # indent-tabs-mode: nil
  456. # End:
  457. #
  458. # ===============================================================================