Exemple #1
0
class QMemAnalyzer(QWidget):
    def __init__(self, parent=None):
        super().__init__(parent)
        self.__ui = Ui_Widget()
        self.__ui.setupUi(self)
        self.file_path = ""
        self.__ui.lineEdit_E1ID.setText("11")
        self.__ui.lineEdit_E1Size.setText("32")
        self.__ui.lineEdit_E2ID.setText("12")
        self.__ui.lineEdit_E2Size.setText("32")
        self.__ui.lineEdit_FID.setText("13")
        self.__ui.lineEdit_FSize.setText("8")

    def on_Button_FileSelect_released(self):
        cur_dir = QDir.currentPath()
        dlgTitle = "请选择文件:"
        filt = "All(*.*)"
        file_list, filt_used = QFileDialog.getOpenFileName(
            self, dlgTitle, cur_dir, filt)
        if len(file_list) > 0:
            file_name = file_list.split("/")[-1]
            self.__ui.lineEdit.setText(file_name)
            self.file_path = file_list

    def on_pushButton_released(self):
        id_eeprom1 = int(self.__ui.lineEdit_E1ID.text())
        id_eeprom2 = int(self.__ui.lineEdit_E2ID.text())
        id_flash = int(self.__ui.lineEdit_FID.text())
        size_eeprom1 = int(self.__ui.lineEdit_E1Size.text())
        size_eeprom2 = int(self.__ui.lineEdit_E2Size.text())
        size_flash = int(self.__ui.lineEdit_FSize.text())
        print("plot")
Exemple #2
0
class QmyWidget(QWidget):
    def __init__(self, parent=None):
        super().__init__(parent=parent)
        self._ui = Ui_Widget()
        self._ui.setupUi(self)

        # 绑定信号
        self._ui.horizontalSlider.valueChanged.connect(self.my_valueChanged)
        self._ui.horizontalScrollBar.valueChanged.connect(self.my_valueChanged)

    @pyqtSlot(bool)
    def on_checkBox_Text_clicked(self, checked: bool):  # 设置TextVisible
        self._ui.progressBar.setTextVisible(checked)
    
    @pyqtSlot(bool)
    def on_checkBox_Inverted_clicked(self, checked: bool):  # 倒转
        self._ui.progressBar.setInvertedAppearance(checked)

    
    def on_radioButton_Percent_clicked(self):  # 设置显示格式
        self._ui.progressBar.setFormat('%p%')
    
    def on_radioButton_Value_clicked(self):  # 设置显示格式
        self._ui.progressBar.setFormat('%v')

    def my_valueChanged(self, value):  # 改变progressBar的值
        self._ui.progressBar.setValue(value)
Exemple #3
0
class QmyWideget(QWidget):
    def __init__(self, parent=None):
        super().__init__(parent=parent)
        self._ui = Ui_Widget()
        self._ui.setupUi(self)  # 创建UI

        self.human = Human(18, '小明')  # 绑定自定义信号
        self.human.nameChanged.connect(self.my_nameChanged)
        self.human.ageChanged[int].connect(self.my_ageChanged_int)
        self.human.ageChanged[str].connect(self.my_ageChanged_str)

    # ============自定义槽函数============
    def my_nameChanged(self, name):  # nameChanged(str)响应
        self._ui.lineEdit_nameStr.setText('Hello, %s!' % name)

    @pyqtSlot(int)
    def my_ageChanged_int(self, age):  # ageChanged(int)响应
        self._ui.lineEdit_ageInt.setText(str(age))

    @pyqtSlot(str)
    def my_ageChanged_str(self, info):  # ageChanged(str)响应
        self._ui.lineEdit_ageStr.setText(info)

    # ============自动关联槽函数============
    def on_slider_SetAge_valueChanged(self, value):  # 滑块改变年龄
        self.human.setAge(value)

    def on_pushButton_clicked(self):  # 设置姓名
        name = self._ui.lineEdit_inputName.text()
        self.human.setName(name)
Exemple #4
0
    def __init__(self, parent=None):
        super().__init__(parent=parent)
        self._ui = Ui_Widget()
        self._ui.setupUi(self)

        # 绑定信号
        self._ui.horizontalSlider.valueChanged.connect(self.my_valueChanged)
        self._ui.horizontalScrollBar.valueChanged.connect(self.my_valueChanged)
Exemple #5
0
    def __init__(self, parent=None):
        super().__init__(parent=parent)
        self._ui = Ui_Widget()
        self._ui.setupUi(self)  # 创建UI

        self.human = Human(18, '小明')  # 绑定自定义信号
        self.human.nameChanged.connect(self.my_nameChanged)
        self.human.ageChanged[int].connect(self.my_ageChanged_int)
        self.human.ageChanged[str].connect(self.my_ageChanged_str)
Exemple #6
0
    def __init__(self):
        super(MainWindow, self).__init__()
        self.ui = Ui_Widget()
        self.ui.setupUi(self)

        ####################################
        # Figure
        self.distance_fig = Figure()
        self.distance_canvas = FigureCanvas(self.distance_fig)
        self.ui.DistanceLayout.addWidget(self.distance_canvas)

        self.visual_fig = Figure()
        self.visual_canvas = FigureCanvas(self.visual_fig)
        self.ui.visualization_layout.addWidget(self.visual_canvas)

        self.visual_cnt = 0

        ####################################
        # Button Interactive
        self.ui.map_change_Down.clicked.connect(self.map_change_down_clicked)
        self.ui.map_change.clicked.connect(self.mpa_change_clicked)

        ####################################
        # Img Path
        self.map_100_path = "img/icon/map_100m.png"
        self.map_200_path = "img/icon/map_200m.png"
        self.map_400_path = "img/icon/map_400m.png"
        self.map_800_path = "img/icon/map_800m.png"
        self.map_1600_path = "img/icon/map_1600m.png"
        self.Scale_factor = scale_100m

        self.intruder_img_path = "img/icon/Intruder Symbol.png"
        self.ownship_img_path = "img/icon/Ownship Symbol.png"

        ####################################
        # Map Parameter
        self.map_size = 100
        self.map_img = read_img(self.map_100_path, map_row, map_col)
        self.Scale_factor = scale_100m

        ####################################
        # Check aircraft is in MAP
        self.check_Ownship_in_map = 0
        self.check_Intruder_in_map = 0

        ####################################
        # Update GUI
        self.timer = QTimer()
        self.connect(self.timer, SIGNAL("timeout()"), self.visual_UI)
        self.timer.start(33)
        self.prev_time = 0

        ####################################
        # Debug Part
        self.check_Hz = 0
        self.plot_visual = 10
Exemple #7
0
    def __init__(self, parent=None):
        super().__init__(parent=parent)
        self._ui = Ui_Widget()
        self._ui.setupUi(self)

        self._timer = QTimer()
        self._timer.stop()
        self._timer.setInterval(1000)
        self._timer.timeout.connect(self.my_timer_timeout)
        self._counter = QTime()
Exemple #8
0
 def __init__(self, parent=None):
     super().__init__(parent)
     self.__ui = Ui_Widget()
     self.__ui.setupUi(self)
     self.file_path = ""
     self.__ui.lineEdit_E1ID.setText("11")
     self.__ui.lineEdit_E1Size.setText("32")
     self.__ui.lineEdit_E2ID.setText("12")
     self.__ui.lineEdit_E2Size.setText("32")
     self.__ui.lineEdit_FID.setText("13")
     self.__ui.lineEdit_FSize.setText("8")
Exemple #9
0
class QmyWidget(QWidget):
    def __init__(self, parent=None, flags=Qt.WindowFlags()):
        super().__init__(parent=parent, flags=flags)
        self._ui = Ui_Widget()
        self._ui.setupUi(self)

    # ==== 自关联槽函数 ====
    def on_pushButton_Left_clicked(self):  # 居左
        self._ui.lineEdit.setAlignment(Qt.AlignLeft)

    def on_pushButton_Center_clicked(self):  # 居中
        self._ui.lineEdit.setAlignment(Qt.AlignCenter)

    def on_pushButton_Right_clicked(self):  # 居右
        self._ui.lineEdit.setAlignment(Qt.AlignRight)

    @pyqtSlot(bool)
    def on_pushButton_Bold_clicked(self, checked: bool):  # 加粗
        font = self._ui.lineEdit.font()
        font.setBold(checked)
        self._ui.lineEdit.setFont(font)

    @pyqtSlot(bool)
    def on_pushButton_Italic_clicked(self, checked: bool):  # 斜体
        font = self._ui.lineEdit.font()
        font.setItalic(checked)
        self._ui.lineEdit.setFont(font)

    @pyqtSlot(bool)
    def on_pushButton_Underline_clicked(self, checked: bool):  # 下划线
        font = self._ui.lineEdit.font()
        font.setUnderline(checked)
        self._ui.lineEdit.setFont(font)

    @pyqtSlot(bool)
    def on_checkBox_ReadOnly_clicked(self, checked: bool):  # ReadOnly
        self._ui.lineEdit.setReadOnly(checked)

    @pyqtSlot(bool)
    def on_checkBox_EnaBled_clicked(self, checked: bool):  # EnaBled
        self._ui.lineEdit.setEnabled(checked)

    @pyqtSlot(bool)
    def on_checkBox_ClearButtonEnabled_clicked(
            self, checked: bool):  # ClearButtonEnabled
        self._ui.lineEdit.setClearButtonEnabled(checked)
Exemple #10
0
class QmyWidget(QWidget):
    def __init__(self, parent=None):
        super().__init__(parent=parent)
        self._ui = Ui_Widget()
        self._ui.setupUi(self)

    def on_pushButton_GetNowTime_clicked(self):
        curDateTime = QDateTime.currentDateTime()
        self._ui.timeEdit.setTime(curDateTime.time())
        self._ui.lineEdit_Time.setText(curDateTime.toString('hh:mm:ss'))
        self._ui.dateEdit.setDate(curDateTime.date())
        self._ui.lineEdit_Date.setText(curDateTime.toString('yyyy/MM/dd'))
        self._ui.dateTimeEdit.setDateTime(curDateTime)
        self._ui.lineEdit_DateTime.setText(
            curDateTime.toString('yyyy/MM/dd hh:mm:ss'))

    def on_pushButton_SetTime_clicked(self):
        tmStr = self._ui.lineEdit_Time.text()
        tm = QTime.fromString(tmStr, 'hh:mm:ss')
        self._ui.timeEdit.setTime(tm)

    def on_pushButton_SetDate_clicked(self):
        dtStr = self._ui.lineEdit_Date.text()
        dt = QDate.fromString(dtStr, 'yyyy/MM/dd')
        self._ui.dateEdit.setDate(dt)

    def on_pushButton_SetDateTime_clicked(self):
        dttmStr = self._ui.lineEdit_DateTime.text()
        dttm = QDateTime.fromString(dttmStr, 'yyyy/MM/dd hh:mm:ss')
        self._ui.dateTimeEdit.setDateTime(dttm)

    def on_calendarWidget_selectionChanged(self):
        date = self._ui.calendarWidget.selectedDate()
        self._ui.lineEdit_Search.setText(date.toString('yyyy年MM月dd日'))

    def on_dateTimeEdit_dateChanged(self, dateTime):
        self._ui.lineEdit_DateTime.setText(
            dateTime.toString('yyyy/MM/dd hh:mm:ss'))

    def on_dateEdit_dateChanged(self, date):
        self._ui.lineEdit_Date.setText(date.toString('yyyy/MM/dd'))

    def on_timeEdit_timeChanged(self, time):
        self._ui.lineEdit_Time.setText(time.toString('hh:mm:ss'))
Exemple #11
0
class QmyWidget(QWidget):
    def __init__(self, parent=None):
        super().__init__(parent)
        self._ui = Ui_Widget()
        self._ui.setupUi(self)

    def on_pushButton_Total_clicked(self):  # 输出总价
        num = int(self._ui.lineEdit_Count.text())  # 获取数量
        price = float(self._ui.lineEdit_Price.text())  # 获取价格
        total = num * price
        self._ui.lineEdit_Total_Line.setText('%.2f' % total)  # 输出总价

    @pyqtSlot(int)
    def on_spinBox_valueChanged(self, weight: int):
        price = self._ui.doubleSpinBox.value()  # 获取价格
        self._ui.lineEdit_Total_Spin.setText(str(price * weight))  # 输出总价

    @pyqtSlot(float)
    def on_doubleSpinBox_valueChanged(self, price):
        widget = self._ui.spinBox.value()  # 获取重量
        self._ui.lineEdit_Total_Spin.setText(str(price * widget))  # 输出价格
Exemple #12
0
class QmyWidget(QWidget):
    def __init__(self, parent=None):
        super().__init__(parent=parent)
        self._ui = Ui_Widget()
        self._ui.setupUi(self)

        self._timer = QTimer()
        self._timer.stop()
        self._timer.setInterval(1000)
        self._timer.timeout.connect(self.my_timer_timeout)
        self._counter = QTime()

    def on_pushButton_Start_clicked(self):
        self._timer.start()
        self._counter.start()
        self._ui.pushButton_Start.setEnabled(False)
        self._ui.pushButton_Stop.setEnabled(True)
        self._ui.pushButton_SetTime.setEnabled(False)

    def on_pushButton_Stop_clicked(self):
        self._timer.stop()
        tms = self._counter.elapsed()
        ms = tms % 1000
        sec = tms / 1000
        timerstr = f'当前经过时间:{sec}s {ms}ms'
        self._ui.label_Reduce.setText(timerstr)
        self._ui.pushButton_Start.setEnabled(True)
        self._ui.pushButton_Stop.setEnabled(False)
        self._ui.pushButton_SetTime.setEnabled(True)

    def on_pushButton_SetTime_clicked(self):
        self._timer.setInterval(self._ui.timeEdit.value())

    def my_timer_timeout(self):
        curTime = QTime.currentTime()
        self._ui.lcdNumber_Hour.display(curTime.hour())
        self._ui.lcdNumber_Minute.display(curTime.minute())
        self._ui.lcdNumber_Second.display(curTime.second())
Exemple #13
0
	def __init__(self, parent=None):
		QtGui.QWidget.__init__(self, parent)
        
		self.center()
		self.ui = Ui_Widget()
		self.ui.setupUi(self)
		self.alpha = 0.0
		self.betta = 0.0
		self.sc = 1.0
		
		#создание тора
		self.Torus = makeTorus()
		self.amount = len(self.Torus)-1
		self.matr = qtMatrix()
Exemple #14
0
class QmyWidget(QWidget):
    def __init__(self, parent=None):
        super().__init__(parent=parent)
        self._ui = Ui_Widget()
        self._ui.setupUi(self)

    def on_pushButton_InitList_clicked(self):
        icon = QIcon(':/new/prefix1/images/unit.ico')
        self._ui.comboBox_City.clear()
        city = ['绵阳市', '成都市', '德阳市', '资阳市', '达州市']
        for name in city:
            self._ui.comboBox_City.addItem(icon, name)

    def on_pushButton_ClearList_clicked(self):
        self._ui.comboBox_City.clear()

    def on_pushButton_InitCity_clicked(self):
        icon = QIcon(':/new/prefix1/images/aim.ico')
        self._ui.comboBox_User.clear()
        cities = {'Beijing': 10, 'shanghai': 21, 'tianjin': 22}
        for k, v in cities.items():
            self._ui.comboBox_User.addItem(icon, k, v)

    @pyqtSlot(bool)
    def on_checkBox_clicked(self, checked):
        self._ui.comboBox_City.setEditable(checked)

    @pyqtSlot(str)
    def on_comboBox_City_currentIndexChanged(self, curText):
        self._ui.lineEdit.setText(curText)

    @pyqtSlot(str)
    def on_comboBox_User_currentIndexChanged(self, curText):
        self._ui.lineEdit.setText(curText)
        zone = self._ui.comboBox_User.currentData()
        if zone:
            self._ui.lineEdit.setText(f'城市:{curText}区号:{zone}')
Exemple #15
0
 def __init__(self, parent=None, flags=Qt.WindowFlags()):
     super().__init__(parent=parent, flags=flags)
     self._ui = Ui_Widget()
     self._ui.setupUi(self)
Exemple #16
0
class MainWindow(QMainWindow):
    def __init__(self):
        super(MainWindow, self).__init__()
        self.ui = Ui_Widget()
        self.ui.setupUi(self)

        ####################################
        # Figure
        self.distance_fig = Figure()
        self.distance_canvas = FigureCanvas(self.distance_fig)
        self.ui.DistanceLayout.addWidget(self.distance_canvas)

        self.visual_fig = Figure()
        self.visual_canvas = FigureCanvas(self.visual_fig)
        self.ui.visualization_layout.addWidget(self.visual_canvas)

        self.visual_cnt = 0

        ####################################
        # Button Interactive
        self.ui.map_change_Down.clicked.connect(self.map_change_down_clicked)
        self.ui.map_change.clicked.connect(self.mpa_change_clicked)

        ####################################
        # Img Path
        self.map_100_path = "img/icon/map_100m.png"
        self.map_200_path = "img/icon/map_200m.png"
        self.map_400_path = "img/icon/map_400m.png"
        self.map_800_path = "img/icon/map_800m.png"
        self.map_1600_path = "img/icon/map_1600m.png"
        self.Scale_factor = scale_100m

        self.intruder_img_path = "img/icon/Intruder Symbol.png"
        self.ownship_img_path = "img/icon/Ownship Symbol.png"

        ####################################
        # Map Parameter
        self.map_size = 100
        self.map_img = read_img(self.map_100_path, map_row, map_col)
        self.Scale_factor = scale_100m

        ####################################
        # Check aircraft is in MAP
        self.check_Ownship_in_map = 0
        self.check_Intruder_in_map = 0

        ####################################
        # Update GUI
        self.timer = QTimer()
        self.connect(self.timer, SIGNAL("timeout()"), self.visual_UI)
        self.timer.start(33)
        self.prev_time = 0

        ####################################
        # Debug Part
        self.check_Hz = 0
        self.plot_visual = 10

    def map_change_down_clicked(self):
        if (self.map_size == 200):
            self.map_size = 100
            self.Scale_factor = scale_100m
        elif (self.map_size == 400):
            self.map_size = 200
            self.Scale_factor = scale_200m
        elif (self.map_size == 800):
            self.map_size = 400
            self.Scale_factor = scale_400m
        elif (self.map_size == 1600):
            self.map_size = 800
            self.Scale_factor = scale_800m

        self.visual_map()

    def mpa_change_clicked(self):
        if (self.map_size == 100):
            self.map_size = 200
            self.Scale_factor = scale_200m
        elif (self.map_size == 200):
            self.map_size = 400
            self.Scale_factor = scale_400m
        elif (self.map_size == 400):
            self.map_size = 800
            self.Scale_factor = scale_800m
        elif (self.map_size == 800):
            self.map_size = 1600
            self.Scale_factor = scale_1600m

        self.visual_map()

    def visual_UI(self):
        if (self.check_Hz == 1):
            now = time.time()
            print("Hz : " + str(1 / (now - self.prev_time)))
            self.prev_time = now

        self.visual_img()
        self.visual_map()
        self.visual_txt()
        self.visual_Plot()
        if (self.visual_cnt % self.plot_visual == 0):
            self.visual_visual()
        self.visual_cnt += 1

    def visual_visual(self):
        self.visual_ax = self.visual_fig.add_subplot(111, projection='3d')
        self.visual_ax.cla()

        self.visual_ax.scatter([ros.Ownship_lat], [ros.Ownship_lon],
                               [ros.Ownship_alt],
                               color='b')
        self.visual_ax.scatter([ros.Intruder_lat], [ros.Intruder_lon],
                               [ros.Intruder_alt],
                               color='r')

        self.visual_ax.set_xlim(36.5, 36.68)
        self.visual_ax.set_ylim(126.2, 126.4)
        self.visual_ax.set_zlim(0, 2000)

        self.visual_ax.grid()
        self.visual_canvas.draw()

    def visual_Plot(self):
        self.distance_ax = self.distance_fig.add_subplot(111)
        self.distance_ax.cla()
        if (len(ros.distance_list) < ros.plot_cnt):
            temp_distance_list = [
                0 for i in range(ros.plot_cnt - len(ros.distance_list))
            ] + ros.distance_list
        else:
            temp_distance_list = ros.distance_list
        self.distance_ax.plot(ros.plot_time_table, temp_distance_list, 'r')
        self.distance_ax.set_ylim(0, 5000)
        self.distance_ax.axhspan(0, 2000, facecolor='0.5', alpha=0.5)
        self.distance_ax.grid()
        self.distance_canvas.draw()

    def visual_map(self):
        map_path_list = [
            self.map_100_path, self.map_200_path, self.map_400_path,
            self.map_800_path, self.map_1600_path
        ]
        self.map_img = read_img(
            map_path_list[int(math.log(self.map_size / 100, 2))], map_row,
            map_col)

        ownship_img = read_img(self.ownship_img_path, icon_row_col,
                               icon_row_col)
        intruder_img = read_img(self.intruder_img_path, icon_row_col,
                                icon_row_col)

        height, width, channel = ownship_img.shape
        matrix = cv2.getRotationMatrix2D((width / 2, height / 2),
                                         -ros.Ownship_heading, 1)
        rot_ownship_img = cv2.warpAffine(ownship_img, matrix, (width, height))

        matrix = cv2.getRotationMatrix2D((width / 2, height / 2),
                                         -ros.Intruder_heading, 1)
        rot_intruder_img = cv2.warpAffine(intruder_img, matrix,
                                          (width, height))

        ownship_row_in_map = map_row / 2 - int(
            ros.Ownship_local_x * self.Scale_factor)
        ownship_col_in_map = map_col / 2 + int(
            ros.Ownship_local_y * self.Scale_factor)

        Intruder_row_in_map = map_row / 2 - int(
            ros.Intruder_local_x * self.Scale_factor)
        Intruder_col_in_map = map_col / 2 + int(
            ros.Intruder_local_y * self.Scale_factor)

        height, width, channel = rot_intruder_img.shape
        check_image_size = int(height / 2)
        if (Intruder_row_in_map < map_row - check_image_size
                and Intruder_row_in_map > check_image_size
                and Intruder_col_in_map < map_col - check_image_size
                and Intruder_col_in_map > check_image_size):
            self.overwrite_map_img = image_add_function(
                self.map_img, rot_intruder_img, Intruder_row_in_map,
                Intruder_col_in_map)
            self.check_Intruder_in_map = 1
        else:
            self.check_Intruder_in_map = 0

        if (ownship_row_in_map < map_row - check_image_size
                and ownship_row_in_map > check_image_size
                and ownship_col_in_map < map_col - check_image_size
                and ownship_col_in_map > check_image_size):
            if (self.check_Intruder_in_map):
                self.overwrite_map_img = image_add_function(
                    self.overwrite_map_img, rot_ownship_img,
                    ownship_row_in_map, ownship_col_in_map)
            else:
                self.overwrite_map_img = image_add_function(
                    self.map_img, rot_ownship_img, ownship_row_in_map,
                    ownship_col_in_map)
            self.check_Ownship_in_map = 1
        else:
            self.check_Ownship_in_map = 0

        # Add indicator Text
        # map, text, location, font, fontsclae, color, thickness
        if (self.check_Intruder_in_map):
            cv2.putText(self.overwrite_map_img, "Intruder",
                        (Intruder_col_in_map - 30, Intruder_row_in_map - 20),
                        cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 0), 1)

        if (self.check_Ownship_in_map):
            cv2.putText(self.overwrite_map_img, "Ownship",
                        (ownship_col_in_map - 30, ownship_row_in_map - 20),
                        cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 0), 1)

        if (self.check_Intruder_in_map == 0
                and self.check_Ownship_in_map == 0):
            height, width, channel = self.map_img.shape
            bytesPerLine = 3 * width
            qImg = QImage(self.map_img.data, width, height, bytesPerLine,
                          QImage.Format_RGB888)
        else:
            height, width, channel = self.overwrite_map_img.shape
            bytesPerLine = 3 * width
            qImg = QImage(self.overwrite_map_img.data, width, height,
                          bytesPerLine, QImage.Format_RGB888)

        pixmap = QPixmap(qImg)
        pixmap = pixmap.scaled(map_col, map_row, QtCore.Qt.KeepAspectRatio)
        self.ui.MAP.setPixmap(pixmap)

    def visual_txt(self):
        self.ui.IN_Ownship_lat.setText(str(ros.Ownship_lat))
        self.ui.IN_Ownship_lon.setText(str(ros.Ownship_lon))
        self.ui.IN_Ownship_Alt.setText(str(ros.Ownship_alt))
        self.ui.IN_Ownship_Head.setText(str(ros.Ownship_heading))
        self.ui.IN_Ownship_Hor_vel.setText(str(ros.Ownship_hor_vel))
        self.ui.IN_Ownship_Ver_vel.setText(str(ros.Ownship_ver_vel))
        self.ui.IN_Ownship_x.setText(str(ros.Ownship_local_x))
        self.ui.IN_Ownship_y.setText(str(ros.Ownship_local_y))

        self.ui.IN_Intruder_lat.setText(str(ros.Intruder_lat))
        self.ui.IN_Intruder_lon.setText(str(ros.Intruder_lon))
        self.ui.IN_Intruder_Alt.setText(str(ros.Intruder_alt))
        self.ui.IN_Intruder_Head.setText(str(ros.Intruder_heading))
        self.ui.IN_Intruder_Hor_vel.setText(str(ros.Intruder_hor_vel))
        self.ui.IN_Intruder_Ver_vel.setText(str(ros.Intruder_ver_vel))
        self.ui.IN_Intruder_x.setText(str(ros.Intruder_local_x))
        self.ui.IN_Intruder_y.setText(str(ros.Intruder_local_y))

        self.ui.IN_distance.setText(str(ros.distance))

    def visual_img(self):
        self.ui.IN_ROS_TIME.setText(str(ros.ROS_TIME))

        year = datetime.datetime.fromtimestamp(ros.ROS_TIME).year
        month = datetime.datetime.fromtimestamp(ros.ROS_TIME).month
        if (len(str(month)) == 1):
            month = "0" + str(month)
        day = datetime.datetime.fromtimestamp(ros.ROS_TIME).day
        if (len(str(day)) == 1):
            day = "0" + str(day)
        hour = datetime.datetime.fromtimestamp(ros.ROS_TIME).hour
        if (len(str(hour)) == 1):
            hour = "0" + str(hour)
        minute = datetime.datetime.fromtimestamp(ros.ROS_TIME).minute
        if (len(str(minute)) == 1):
            minute = "0" + str(minute)
        second = datetime.datetime.fromtimestamp(ros.ROS_TIME).second
        if (len(str(second)) == 1):
            second = "0" + str(second)

        ROS_datetime = str(year) + '-' + str(month) + "-" + str(
            day) + " " + str(hour) + ":" + str(minute) + ":" + str(second)
        self.ui.CurrentTime.setText(str(ROS_datetime))

        for i in range(10):
            img_path1 = "/home/usrg-asus/Civil/bag_file/200926_06/video/frame0/" + str(
                ros.ROS_TIME) + str(i) + ".jpg"
            if (os.path.exists(img_path1)):
                pixmap = QPixmap(QImage(img_path1))
                pixmap = pixmap.scaled(480, 270, QtCore.Qt.KeepAspectRatio)
                self.ui.Img_view1.setPixmap(pixmap)

            img_path2 = "/home/usrg-asus/Civil/bag_file/200926_06/video/frame1/" + str(
                ros.ROS_TIME) + str(i) + ".jpg"
            if (os.path.exists(img_path2)):
                pixmap = QPixmap(QImage(img_path2))
                pixmap = pixmap.scaled(480, 270, QtCore.Qt.KeepAspectRatio)
                self.ui.Img_view3.setPixmap(pixmap)

            img_path3 = "/home/usrg-asus/Civil/bag_file/200926_06/video/frame2/" + str(
                ros.ROS_TIME) + str(i) + ".jpg"
            if (os.path.exists(img_path3)):
                pixmap = QPixmap(QImage(img_path3))
                pixmap = pixmap.scaled(480, 270, QtCore.Qt.KeepAspectRatio)
                self.ui.Img_view2.setPixmap(pixmap)
Exemple #17
0
 def __init__(self, parent=None):
     super().__init__(parent=parent)
     self._ui = Ui_Widget()
     self._ui.setupUi(self)
Exemple #18
0
class Widget(QtGui.QWidget):
	def __init__(self, parent=None):
		QtGui.QWidget.__init__(self, parent)
        
		self.center()
		self.ui = Ui_Widget()
		self.ui.setupUi(self)
		self.alpha = 0.0
		self.betta = 0.0
		self.sc = 1.0
		
		#создание тора
		self.Torus = makeTorus()
		self.amount = len(self.Torus)-1
		self.matr = qtMatrix()
		
	def center(self):
		screen = QtGui.QDesktopWidget().screenGeometry()
		size =  self.geometry()
		self.move((screen.width()-size.width())/2, (screen.height()-size.height())/2)	
		
	def mouseMoveEvent(self, event):
		x, y = event.pos().x(), event.pos().y()
		if 0<0.5*x<360 and 0<0.5*y<360:
			#~ print(x,y)
			self.alpha = 0.01*x
			self.betta = 0.01*y
		self.update()
	
	#~ масштабирование по "+", "-" 
	def keyPressEvent(self,event):
		st = 0.25
		if event.key() == QtCore.Qt.Key_Plus and self.sc+st > 0:
			self.sc += st
			#~ print(self.sc)
			self.update()
			
		elif event.key() == QtCore.Qt.Key_Minus and self.sc-st > 0:
			self.sc -= st
			#~ print(self.sc)
			self.update()
	
	
	def paintEvent(self, event):
		
		size = self.size()
		ox = size.width()/2
		oy = size.height()/2	
		
		matr = self.matr
		
		#~ объявление всех матриц для использования
		k=60
		matrScale = matr.scale(k*self.sc)
		matrRZ = matr.rotateZ(self.alpha)
		matrRX = matr.rotateX(self.betta)
		vectTrans = QtGui.QVector4D(ox,oy,0,0)	
		
		#~ получение "перспективных" вершин
		vect_Torus = self.Torus
		if self.ui.checkBox.isChecked():
			vect_Torus = [vect_perspective(matr,self.Torus[i]) for i in range(0, self.amount+1)]
		
		#~ общая матрица
		matrTotal = matrRZ*matrRX*matr.exchange*matrScale

		#~ камера применяется почти в конце
		if self.ui.checkBox_2.isChecked():
			matrTotal *= matr.lookAt()
		
		paint = QtGui.QPainter()
		
		paint.begin(self)
		paint.setPen(QtCore.Qt.blue)
		#~ каждый вектор умножается на общую матрицу и "немного" сдвигается
		for i in range(0, self.amount, 2):
			v1 = vect_Torus[i+0]*matrTotal
			v2 = vect_Torus[i+1]*matrTotal
			v1 += vectTrans
			v2 += vectTrans
			paint.drawLine(v1.x(),v1.y(),v2.x(),v2.y())
			
		paint.end()
		self.update()
class MainWindow(QMainWindow):
    def __init__(self):
        super(MainWindow, self).__init__()
        self.ui = Ui_Widget()
        self.ui.setupUi(self)

        ####################################
        # Check aircraft is in MAP
        self.check_Ownship_in_map = 0
        self.check_USV1_in_map = 0
        self.check_USV2_in_map = 0
        self.check_UAV1_in_map = 0
        self.check_UAV2_in_map = 0

        ####################################
        # Shared Pose
        self.shared_lat_pos = 0
        self.shared_lon_pos = 0

        self.shared_local_x = 0
        self.shared_local_y = 0

        self.pos_sharing = 0

        ####################################
        # Button Interactive
        self.ui.map_change_Down.clicked.connect(self.map_change_down_clicked)
        self.ui.map_change.clicked.connect(self.mpa_change_clicked)

        self.ui.OPV_pos_share.clicked.connect(self.OPV_pos_share_clicked)
        self.ui.OPV_shared_pos_clear.clicked.connect(
            self.OPV_shared_pos_clear_clicked)

        self.ui.OPV_stby_button.clicked.connect(self.OPV_stby_clicked)
        self.ui.OPV_done_button.clicked.connect(self.OPV_done_clicked)
        self.ui.OPV_mission_button.clicked.connect(self.OPV_mission_clicked)

        self.ui.USV1_stby_button.clicked.connect(self.USV1_stby_clicked)
        self.ui.USV1_done_button.clicked.connect(self.USV1_done_clicked)
        self.ui.USV1_mission_button.clicked.connect(self.USV1_mission_clicked)

        self.ui.USV2_stby_button.clicked.connect(self.USV2_stby_clicked)
        self.ui.USV2_done_button.clicked.connect(self.USV2_done_clicked)
        self.ui.USV2_mission_button.clicked.connect(self.USV2_mission_clicked)

        self.ui.UAV1_stby_button.clicked.connect(self.UAV1_stby_clicked)
        self.ui.UAV1_done_button.clicked.connect(self.UAV1_done_clicked)
        self.ui.UAV1_mission_button.clicked.connect(self.UAV1_mission_clicked)

        self.ui.UAV2_stby_button.clicked.connect(self.UAV2_stby_clicked)
        self.ui.UAV2_done_button.clicked.connect(self.UAV2_done_clicked)
        self.ui.UAV2_mission_button.clicked.connect(self.UAV2_mission_clicked)

        ####################################
        # Img Path
        self.map_20_path = "img/MAP_20.png"
        self.map_50_path = "img/MAP_50.png"
        self.map_100_path = "img/MAP_100.png"
        self.map_200_path = "img/MAP_200.png"
        self.map_500_path = "img/MAP_500.png"
        self.Scale_factor = scale_100m

        self.ownship_img_path = "img/icon/Ownship Symbol.png"
        self.USV1_img_path = "img/icon/Ship_logo.png"
        self.USV2_img_path = "img/icon/Ship_logo2.png"
        self.UAV1_img_path = "img/icon/drone1_logo.png"
        self.UAV2_img_path = "img/icon/drone2_logo.png"

        self.stby_img_path = "img/stby.png"
        self.mission_img_path = "img/mission.png"
        self.done_img_path = "img/done.png"
        self.error_img_path = "img/error.png"
        self.connect_img_path = "img/connect.png"
        self.disconnect_img_path = "img/disconnected.png"

        ####################################
        # Map Information
        self.map_size = 100  # 20, 50, 100
        self.map_img = read_img(self.map_100_path, map_row, map_col)

        # Status Initialize
        pixmap = QPixmap(QImage(self.disconnect_img_path))
        pixmap = pixmap.scaled(100, 20, QtCore.Qt.KeepAspectRatio)
        self.ui.OPV_Status.setPixmap(pixmap)

        pixmap = QPixmap(QImage(self.disconnect_img_path))
        pixmap = pixmap.scaled(100, 20, QtCore.Qt.KeepAspectRatio)
        self.ui.USV1_Status.setPixmap(pixmap)

        pixmap = QPixmap(QImage(self.disconnect_img_path))
        pixmap = pixmap.scaled(100, 20, QtCore.Qt.KeepAspectRatio)
        self.ui.USV2_Status.setPixmap(pixmap)

        pixmap = QPixmap(QImage(self.disconnect_img_path))
        pixmap = pixmap.scaled(100, 20, QtCore.Qt.KeepAspectRatio)
        self.ui.UAV1_Status.setPixmap(pixmap)

        pixmap = QPixmap(QImage(self.disconnect_img_path))
        pixmap = pixmap.scaled(100, 20, QtCore.Qt.KeepAspectRatio)
        self.ui.UAV2_Status.setPixmap(pixmap)

        ####################################
        # Update GUI
        self.timer = QTimer()
        self.connect(self.timer, SIGNAL("timeout()"), self.visual_UI)
        self.timer.start(50)

    # OPV find human, shared pos
    def OPV_pos_share_clicked(self):
        self.shared_lat_pos = ros.Ownship_lat
        self.shared_lon_pos = ros.Ownship_lon

        self.shared_local_x = ros.Ownship_local_x
        self.shared_local_y = ros.Ownship_local_y

        self.ui.OPV_share_lat.setText(str(self.shared_lat_pos))
        self.ui.OPV_share_lon.setText(str(self.shared_lon_pos))

        self.pos_sharing = 1

    def OPV_shared_pos_clear_clicked(self):
        self.pos_sharing = 0

        self.ui.OPV_share_lat.setText(str(0.0))
        self.ui.OPV_share_lon.setText(str(0.0))

        self.ui.OPV_acc_lat.setText(str(0.0))
        self.ui.OPV_acc_lon.setText(str(0.0))

        self.ui.USV1_acc_lat.setText(str(0.0))
        self.ui.USV1_acc_lon.setText(str(0.0))

        self.ui.USV2_acc_lat.setText(str(0.0))
        self.ui.USV2_acc_lon.setText(str(0.0))

        self.ui.UAV1_acc_lat.setText(str(0.0))
        self.ui.UAV1_acc_lon.setText(str(0.0))

        self.ui.UAV2_acc_lat.setText(str(0.0))
        self.ui.UAV2_acc_lon.setText(str(0.0))

    # OPV Status
    def OPV_stby_clicked(self):
        pixmap = QPixmap(QImage(self.stby_img_path))
        pixmap = pixmap.scaled(100, 20, QtCore.Qt.KeepAspectRatio)
        self.ui.OPV_Status.setPixmap(pixmap)

    def OPV_mission_clicked(self):
        pixmap = QPixmap(QImage(self.mission_img_path))
        pixmap = pixmap.scaled(100, 20, QtCore.Qt.KeepAspectRatio)
        self.ui.OPV_Status.setPixmap(pixmap)

    def OPV_done_clicked(self):
        pixmap = QPixmap(QImage(self.done_img_path))
        pixmap = pixmap.scaled(100, 20, QtCore.Qt.KeepAspectRatio)
        self.ui.OPV_Status.setPixmap(pixmap)

    # USV1 Status
    def USV1_stby_clicked(self):
        pixmap = QPixmap(QImage(self.stby_img_path))
        pixmap = pixmap.scaled(100, 20, QtCore.Qt.KeepAspectRatio)
        self.ui.USV1_Status.setPixmap(pixmap)

    def USV1_mission_clicked(self):
        pixmap = QPixmap(QImage(self.mission_img_path))
        pixmap = pixmap.scaled(100, 20, QtCore.Qt.KeepAspectRatio)
        self.ui.USV1_Status.setPixmap(pixmap)

    def USV1_done_clicked(self):
        pixmap = QPixmap(QImage(self.done_img_path))
        pixmap = pixmap.scaled(100, 20, QtCore.Qt.KeepAspectRatio)
        self.ui.USV1_Status.setPixmap(pixmap)

    # USV2 Status
    def USV2_stby_clicked(self):
        pixmap = QPixmap(QImage(self.stby_img_path))
        pixmap = pixmap.scaled(100, 20, QtCore.Qt.KeepAspectRatio)
        self.ui.USV2_Status.setPixmap(pixmap)

    def USV2_mission_clicked(self):
        pixmap = QPixmap(QImage(self.mission_img_path))
        pixmap = pixmap.scaled(100, 20, QtCore.Qt.KeepAspectRatio)
        self.ui.USV2_Status.setPixmap(pixmap)

    def USV2_done_clicked(self):
        pixmap = QPixmap(QImage(self.done_img_path))
        pixmap = pixmap.scaled(100, 20, QtCore.Qt.KeepAspectRatio)
        self.ui.USV2_Status.setPixmap(pixmap)

    # UAV1 Status
    def UAV1_stby_clicked(self):
        pixmap = QPixmap(QImage(self.stby_img_path))
        pixmap = pixmap.scaled(100, 20, QtCore.Qt.KeepAspectRatio)
        self.ui.UAV1_Status.setPixmap(pixmap)

    def UAV1_mission_clicked(self):
        pixmap = QPixmap(QImage(self.mission_img_path))
        pixmap = pixmap.scaled(100, 20, QtCore.Qt.KeepAspectRatio)
        self.ui.UAV1_Status.setPixmap(pixmap)

    def UAV1_done_clicked(self):
        pixmap = QPixmap(QImage(self.done_img_path))
        pixmap = pixmap.scaled(100, 20, QtCore.Qt.KeepAspectRatio)
        self.ui.UAV1_Status.setPixmap(pixmap)

    # UAV2 Status
    def UAV2_stby_clicked(self):
        pixmap = QPixmap(QImage(self.stby_img_path))
        pixmap = pixmap.scaled(100, 20, QtCore.Qt.KeepAspectRatio)
        self.ui.UAV2_Status.setPixmap(pixmap)

    def UAV2_mission_clicked(self):
        pixmap = QPixmap(QImage(self.mission_img_path))
        pixmap = pixmap.scaled(100, 20, QtCore.Qt.KeepAspectRatio)
        self.ui.UAV2_Status.setPixmap(pixmap)

    def UAV2_done_clicked(self):
        pixmap = QPixmap(QImage(self.done_img_path))
        pixmap = pixmap.scaled(100, 20, QtCore.Qt.KeepAspectRatio)
        self.ui.UAV2_Status.setPixmap(pixmap)

    def map_change_down_clicked(self):
        if (self.map_size == 50):
            self.map_size = 20
            self.Scale_factor = scale_20m
        elif (self.map_size == 100):
            self.map_size = 50
            self.Scale_factor = scale_50m
        elif (self.map_size == 200):
            self.map_size = 100
            self.Scale_factor = scale_100m
        elif (self.map_size == 500):
            self.map_size = 200
            self.Scale_factor = scale_200m
        self.visual_map()

    def mpa_change_clicked(self):
        if (self.map_size == 20):
            self.map_size = 50
            self.Scale_factor = scale_50m
        elif (self.map_size == 50):
            self.map_size = 100
            self.Scale_factor = scale_100m
        elif (self.map_size == 100):
            self.map_size = 200
            self.Scale_factor = scale_200m
        elif (self.map_size == 200):
            self.map_size = 500
            self.Scale_factor = scale_500m
        self.visual_map()

    def visual_UI(self):
        self.visual_map()
        self.visual_time()
        self.visual_txt()

    def visual_txt(self):
        # OPV
        self.ui.IN_Ownship_lat.setText(str(ros.Ownship_lat))
        self.ui.IN_Ownship_lon.setText(str(ros.Ownship_lon))
        self.ui.IN_Ownship_Alt.setText(str(ros.Ownship_alt))
        self.ui.IN_Ownship_Head.setText(str(ros.Ownship_heading))
        self.ui.IN_Ownship_Hor_vel.setText(str(ros.Ownship_hor_vel))
        self.ui.IN_Ownship_Ver_vel.setText(str(ros.Ownship_ver_vel))
        self.ui.IN_Ownship_x.setText(str(ros.Ownship_local_x))
        self.ui.IN_Ownship_y.setText(str(ros.Ownship_local_y))

        # USV1
        self.ui.USV1_lat.setText(str(ros.USV1_lat))
        self.ui.USV1_lon.setText(str(ros.USV1_lon))
        self.ui.USV1_alt.setText(str(ros.USV1_alt))
        self.ui.USV1_head.setText(str(ros.USV1_heading))
        self.ui.IN_USV1_Hor_vel.setText(str(ros.USV1_hor_vel))
        self.ui.IN_USV1_Ver_vel.setText(str(ros.USV1_ver_vel))
        self.ui.IN_USV1_x.setText(str(ros.USV1_local_x))
        self.ui.IN_USV1_y.setText(str(ros.USV1_local_y))

        # USV2
        self.ui.USV2_lat.setText(str(ros.USV2_lat))
        self.ui.USV2_lon.setText(str(ros.USV2_lon))
        self.ui.USV2_alt.setText(str(ros.USV2_alt))
        self.ui.USV2_head.setText(str(ros.USV2_heading))
        self.ui.IN_USV2_Hor_vel.setText(str(ros.USV2_hor_vel))
        self.ui.IN_USV2_Ver_vel.setText(str(ros.USV2_ver_vel))
        self.ui.IN_USV2_x.setText(str(ros.USV2_local_x))
        self.ui.IN_USV2_y.setText(str(ros.USV2_local_y))

        # UAV1
        self.ui.UAV1_lat.setText(str(ros.UAV1_lat))
        self.ui.UAV1_lon.setText(str(ros.UAV1_lon))
        self.ui.UAV1_alt.setText(str(ros.UAV1_alt))
        self.ui.UAV1_head.setText(str(ros.UAV1_heading))
        self.ui.IN_UAV1_Hor_vel.setText(str(ros.UAV1_hor_vel))
        self.ui.IN_UAV1_Ver_vel.setText(str(ros.UAV1_ver_vel))
        self.ui.IN_UAV1_x.setText(str(ros.UAV1_local_x))
        self.ui.IN_UAV1_y.setText(str(ros.UAV1_local_y))

        # UAV2
        self.ui.UAV2_lat.setText(str(ros.UAV2_lat))
        self.ui.UAV2_lon.setText(str(ros.UAV2_lon))
        self.ui.UAV2_alt.setText(str(ros.UAV2_alt))
        self.ui.UAV2_head.setText(str(ros.UAV2_heading))
        self.ui.IN_UAV2_Hor_vel.setText(str(ros.UAV2_hor_vel))
        self.ui.IN_UAV2_Ver_vel.setText(str(ros.UAV2_ver_vel))
        self.ui.IN_UAV2_x.setText(str(ros.UAV2_local_x))
        self.ui.IN_UAV2_y.setText(str(ros.UAV2_local_y))

        # Accident Distance
        if (self.pos_sharing):
            diff_x = round(ros.Ownship_local_x - self.shared_local_x, 3)
            diff_y = round(ros.Ownship_local_y - self.shared_local_y, 3)
            self.ui.OPV_acc_lat.setText(str(diff_x))
            self.ui.OPV_acc_lon.setText(str(diff_y))

            diff_x = round(ros.USV1_local_x - self.shared_local_x, 3)
            diff_y = round(ros.USV1_local_y - self.shared_local_y, 3)
            self.ui.USV1_acc_lat.setText(str(diff_x))
            self.ui.USV1_acc_lon.setText(str(diff_y))

            diff_x = round(ros.USV2_local_x - self.shared_local_x, 3)
            diff_y = round(ros.USV2_local_y - self.shared_local_y, 3)
            self.ui.USV2_acc_lat.setText(str(diff_x))
            self.ui.USV2_acc_lon.setText(str(diff_y))

            diff_x = round(ros.UAV1_local_x - self.shared_local_x, 3)
            diff_y = round(ros.UAV1_local_y - self.shared_local_y, 3)
            self.ui.UAV1_acc_lat.setText(str(diff_x))
            self.ui.UAV1_acc_lon.setText(str(diff_y))

            diff_x = round(ros.UAV2_local_x - self.shared_local_x, 3)
            diff_y = round(ros.UAV2_local_y - self.shared_local_y, 3)
            self.ui.UAV2_acc_lat.setText(str(diff_x))
            self.ui.UAV2_acc_lon.setText(str(diff_y))

    def visual_time(self):
        self.ui.IN_ROS_TIME.setText(str(ros.ROS_TIME))

        year = datetime.datetime.fromtimestamp(ros.ROS_TIME).year
        month = datetime.datetime.fromtimestamp(ros.ROS_TIME).month
        if (len(str(month)) == 1):
            month = "0" + str(month)
        day = datetime.datetime.fromtimestamp(ros.ROS_TIME).day
        if (len(str(day)) == 1):
            day = "0" + str(day)
        hour = datetime.datetime.fromtimestamp(ros.ROS_TIME).hour
        if (len(str(hour)) == 1):
            hour = "0" + str(hour)
        minute = datetime.datetime.fromtimestamp(ros.ROS_TIME).minute
        if (len(str(minute)) == 1):
            minute = "0" + str(minute)
        second = datetime.datetime.fromtimestamp(ros.ROS_TIME).second
        if (len(str(second)) == 1):
            second = "0" + str(second)

        ROS_datetime = str(year) + '-' + str(month) + "-" + str(
            day) + " " + str(hour) + ":" + str(minute) + ":" + str(second)
        self.ui.CurrentTime.setText(str(ROS_datetime))

    def visual_map(self):
        map_path_list = [self.map_20_path, self.map_50_path, self.map_100_path]
        if (self.map_size == 20):
            self.map_img = read_img(self.map_20_path, map_row, map_col)
        if (self.map_size == 50):
            self.map_img = read_img(self.map_50_path, map_row, map_col)
        if (self.map_size == 100):
            self.map_img = read_img(self.map_100_path, map_row, map_col)
        if (self.map_size == 200):
            self.map_img = read_img(self.map_200_path, map_row, map_col)
        if (self.map_size == 500):
            self.map_img = read_img(self.map_500_path, map_row, map_col)

        ownship_img = read_img(self.ownship_img_path, icon_row_col,
                               icon_row_col)
        USV1_img = read_img(self.USV1_img_path, icon_row_col, icon_row_col)
        USV2_img = read_img(self.USV2_img_path, icon_row_col, icon_row_col)
        UAV1_img = read_img(self.UAV1_img_path, icon_row_col, icon_row_col)
        UAV2_img = read_img(self.UAV2_img_path, icon_row_col, icon_row_col)

        height, width, channel = ownship_img.shape
        matrix = cv2.getRotationMatrix2D((width / 2, height / 2),
                                         -ros.Ownship_heading, 1)
        rot_ownship_img = cv2.warpAffine(ownship_img, matrix, (width, height))

        matrix = cv2.getRotationMatrix2D((width / 2, height / 2),
                                         -ros.USV1_heading, 1)
        rot_USV1_img = cv2.warpAffine(USV1_img, matrix, (width, height))

        matrix = cv2.getRotationMatrix2D((width / 2, height / 2),
                                         -ros.USV1_heading, 1)
        rot_USV2_img = cv2.warpAffine(USV2_img, matrix, (width, height))

        matrix = cv2.getRotationMatrix2D((width / 2, height / 2),
                                         -ros.USV1_heading, 1)
        rot_UAV1_img = cv2.warpAffine(UAV1_img, matrix, (width, height))

        matrix = cv2.getRotationMatrix2D((width / 2, height / 2),
                                         -ros.USV1_heading, 1)
        rot_UAV2_img = cv2.warpAffine(UAV2_img, matrix, (width, height))

        ownship_row_in_map = map_row / 2 - int(
            ros.Ownship_local_x * self.Scale_factor)
        ownship_col_in_map = map_col / 2 + int(
            ros.Ownship_local_y * self.Scale_factor)

        USV1_row_in_map = map_row / 2 - int(
            ros.USV1_local_x * self.Scale_factor)
        USV1_col_in_map = map_col / 2 + int(
            ros.USV1_local_y * self.Scale_factor)

        USV2_row_in_map = map_row / 2 - int(
            ros.USV2_local_x * self.Scale_factor)
        USV2_col_in_map = map_col / 2 + int(
            ros.USV2_local_y * self.Scale_factor)

        UAV1_row_in_map = map_row / 2 - int(
            ros.UAV1_local_x * self.Scale_factor)
        UAV1_col_in_map = map_col / 2 + int(
            ros.UAV1_local_y * self.Scale_factor)

        UAV2_row_in_map = map_row / 2 - int(
            ros.UAV2_local_x * self.Scale_factor)
        UAV2_col_in_map = map_col / 2 + int(
            ros.UAV2_local_y * self.Scale_factor)

        height, width, channel = rot_USV1_img.shape
        check_image_size = int(height / 2)

        # ADD USV1 image to MAP
        if (USV1_row_in_map < map_row - check_image_size
                and USV1_row_in_map > check_image_size
                and USV1_col_in_map < map_col - check_image_size
                and USV1_col_in_map > check_image_size):
            self.overwrite_map_img = image_add_function(
                self.map_img, rot_USV1_img, USV1_row_in_map, USV1_col_in_map)
            self.check_USV1_in_map = 1
        else:
            self.check_USV1_in_map = 0

        # ADD USV2 image to MAP
        if (USV2_row_in_map < map_row - check_image_size
                and USV2_row_in_map > check_image_size
                and USV2_col_in_map < map_col - check_image_size
                and USV2_col_in_map > check_image_size):
            if (self.check_USV1_in_map):
                self.overwrite_map_img = image_add_function(
                    self.overwrite_map_img, rot_USV2_img, USV2_row_in_map,
                    USV2_col_in_map)
            else:
                self.overwrite_map_img = image_add_function(
                    self.map_img, rot_USV2_img, USV2_row_in_map,
                    USV2_col_in_map)
            self.check_USV2_in_map = 1
        else:
            self.check_USV2_in_map = 0

        # ADD UAV1 image to MAP
        if (UAV1_row_in_map < map_row - check_image_size
                and UAV1_row_in_map > check_image_size
                and UAV1_col_in_map < map_col - check_image_size
                and UAV1_col_in_map > check_image_size):
            if (self.check_USV1_in_map or self.check_USV2_in_map):
                self.overwrite_map_img = image_add_function(
                    self.overwrite_map_img, rot_UAV1_img, UAV1_row_in_map,
                    UAV1_col_in_map)
            else:
                self.overwrite_map_img = image_add_function(
                    self.map_img, rot_UAV1_img, UAV1_row_in_map,
                    UAV1_col_in_map)
            self.check_UAV1_in_map = 1
        else:
            self.check_UAV1_in_map = 0

        # ADD UAV2 image to MAP
        if (UAV2_row_in_map < map_row - check_image_size
                and UAV2_row_in_map > check_image_size
                and UAV2_col_in_map < map_col - check_image_size
                and UAV2_col_in_map > check_image_size):
            if (self.check_USV1_in_map or self.check_USV2_in_map
                    or self.check_UAV1_in_map):
                self.overwrite_map_img = image_add_function(
                    self.overwrite_map_img, rot_UAV2_img, UAV2_row_in_map,
                    UAV2_col_in_map)
            else:
                self.overwrite_map_img = image_add_function(
                    self.map_img, rot_UAV2_img, UAV2_row_in_map,
                    UAV2_col_in_map)
            self.check_UAV2_in_map = 1
        else:
            self.check_UAV2_in_map = 0

        # ADD Ownship image to MAP
        if (ownship_row_in_map < map_row - check_image_size
                and ownship_row_in_map > check_image_size
                and ownship_col_in_map < map_col - check_image_size
                and ownship_col_in_map > check_image_size):
            if (self.check_UAV1_in_map or self.check_UAV2_in_map
                    or self.check_USV1_in_map or self.check_USV2_in_map):
                self.overwrite_map_img = image_add_function(
                    self.overwrite_map_img, rot_ownship_img,
                    ownship_row_in_map, ownship_col_in_map)
            else:
                self.overwrite_map_img = image_add_function(
                    self.map_img, rot_ownship_img, ownship_row_in_map,
                    ownship_col_in_map)
            self.check_Ownship_in_map = 1
        else:
            self.check_Ownship_in_map = 0

        # Add indicator Text
        # map, text, location, font, fontsclae, color, thickness
        if (self.check_USV1_in_map):
            cv2.putText(self.overwrite_map_img, "USV1",
                        (USV1_col_in_map - 20, USV1_row_in_map - 20),
                        cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 0), 1)

        if (self.check_USV2_in_map):
            cv2.putText(self.overwrite_map_img, "USV2",
                        (USV2_col_in_map - 20, USV2_row_in_map - 20),
                        cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 0), 1)

        if (self.check_UAV1_in_map):
            cv2.putText(self.overwrite_map_img, "UAV1",
                        (UAV1_col_in_map - 20, UAV1_row_in_map - 20),
                        cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 0), 1)

        if (self.check_UAV1_in_map):
            cv2.putText(self.overwrite_map_img, "UAV2",
                        (UAV2_col_in_map - 20, UAV2_row_in_map - 20),
                        cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 0), 1)

        if (self.check_USV1_in_map):
            cv2.putText(self.overwrite_map_img, "Ownship",
                        (ownship_col_in_map - 30, ownship_row_in_map - 20),
                        cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 0), 1)

        # Indicate Shared Pos in MAP
        if (self.pos_sharing):
            shared_pos_row_in_map = map_row / 2 - int(
                self.shared_local_x * self.Scale_factor)
            shared_pos_col_in_map = map_col / 2 + int(
                self.shared_local_y * self.Scale_factor)
            cv2.putText(self.overwrite_map_img, "X",
                        (shared_pos_col_in_map, shared_pos_row_in_map),
                        cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 0), 1)

        # Convert cv image to Q image
        if (self.check_Ownship_in_map == 0 and self.check_UAV1_in_map == 0
                and self.check_UAV2_in_map == 0 and self.check_USV1_in_map == 0
                and self.check_USV2_in_map == 0):
            height, width, channel = self.map_img.shape
            bytesPerLine = 3 * width
            qImg = QImage(self.map_img.data, width, height, bytesPerLine,
                          QImage.Format_RGB888)
        else:
            height, width, channel = self.overwrite_map_img.shape
            bytesPerLine = 3 * width
            qImg = QImage(self.overwrite_map_img.data, width, height,
                          bytesPerLine, QImage.Format_RGB888)

        # ADD Q image to Widget
        pixmap = QPixmap(qImg)
        pixmap = pixmap.scaled(map_col, map_row, QtCore.Qt.KeepAspectRatio)
        self.ui.MAP.setPixmap(pixmap)
    def __init__(self):
        super(MainWindow, self).__init__()
        self.ui = Ui_Widget()
        self.ui.setupUi(self)

        ####################################
        # Check aircraft is in MAP
        self.check_Ownship_in_map = 0
        self.check_USV1_in_map = 0
        self.check_USV2_in_map = 0
        self.check_UAV1_in_map = 0
        self.check_UAV2_in_map = 0

        ####################################
        # Shared Pose
        self.shared_lat_pos = 0
        self.shared_lon_pos = 0

        self.shared_local_x = 0
        self.shared_local_y = 0

        self.pos_sharing = 0

        ####################################
        # Button Interactive
        self.ui.map_change_Down.clicked.connect(self.map_change_down_clicked)
        self.ui.map_change.clicked.connect(self.mpa_change_clicked)

        self.ui.OPV_pos_share.clicked.connect(self.OPV_pos_share_clicked)
        self.ui.OPV_shared_pos_clear.clicked.connect(
            self.OPV_shared_pos_clear_clicked)

        self.ui.OPV_stby_button.clicked.connect(self.OPV_stby_clicked)
        self.ui.OPV_done_button.clicked.connect(self.OPV_done_clicked)
        self.ui.OPV_mission_button.clicked.connect(self.OPV_mission_clicked)

        self.ui.USV1_stby_button.clicked.connect(self.USV1_stby_clicked)
        self.ui.USV1_done_button.clicked.connect(self.USV1_done_clicked)
        self.ui.USV1_mission_button.clicked.connect(self.USV1_mission_clicked)

        self.ui.USV2_stby_button.clicked.connect(self.USV2_stby_clicked)
        self.ui.USV2_done_button.clicked.connect(self.USV2_done_clicked)
        self.ui.USV2_mission_button.clicked.connect(self.USV2_mission_clicked)

        self.ui.UAV1_stby_button.clicked.connect(self.UAV1_stby_clicked)
        self.ui.UAV1_done_button.clicked.connect(self.UAV1_done_clicked)
        self.ui.UAV1_mission_button.clicked.connect(self.UAV1_mission_clicked)

        self.ui.UAV2_stby_button.clicked.connect(self.UAV2_stby_clicked)
        self.ui.UAV2_done_button.clicked.connect(self.UAV2_done_clicked)
        self.ui.UAV2_mission_button.clicked.connect(self.UAV2_mission_clicked)

        ####################################
        # Img Path
        self.map_20_path = "img/MAP_20.png"
        self.map_50_path = "img/MAP_50.png"
        self.map_100_path = "img/MAP_100.png"
        self.map_200_path = "img/MAP_200.png"
        self.map_500_path = "img/MAP_500.png"
        self.Scale_factor = scale_100m

        self.ownship_img_path = "img/icon/Ownship Symbol.png"
        self.USV1_img_path = "img/icon/Ship_logo.png"
        self.USV2_img_path = "img/icon/Ship_logo2.png"
        self.UAV1_img_path = "img/icon/drone1_logo.png"
        self.UAV2_img_path = "img/icon/drone2_logo.png"

        self.stby_img_path = "img/stby.png"
        self.mission_img_path = "img/mission.png"
        self.done_img_path = "img/done.png"
        self.error_img_path = "img/error.png"
        self.connect_img_path = "img/connect.png"
        self.disconnect_img_path = "img/disconnected.png"

        ####################################
        # Map Information
        self.map_size = 100  # 20, 50, 100
        self.map_img = read_img(self.map_100_path, map_row, map_col)

        # Status Initialize
        pixmap = QPixmap(QImage(self.disconnect_img_path))
        pixmap = pixmap.scaled(100, 20, QtCore.Qt.KeepAspectRatio)
        self.ui.OPV_Status.setPixmap(pixmap)

        pixmap = QPixmap(QImage(self.disconnect_img_path))
        pixmap = pixmap.scaled(100, 20, QtCore.Qt.KeepAspectRatio)
        self.ui.USV1_Status.setPixmap(pixmap)

        pixmap = QPixmap(QImage(self.disconnect_img_path))
        pixmap = pixmap.scaled(100, 20, QtCore.Qt.KeepAspectRatio)
        self.ui.USV2_Status.setPixmap(pixmap)

        pixmap = QPixmap(QImage(self.disconnect_img_path))
        pixmap = pixmap.scaled(100, 20, QtCore.Qt.KeepAspectRatio)
        self.ui.UAV1_Status.setPixmap(pixmap)

        pixmap = QPixmap(QImage(self.disconnect_img_path))
        pixmap = pixmap.scaled(100, 20, QtCore.Qt.KeepAspectRatio)
        self.ui.UAV2_Status.setPixmap(pixmap)

        ####################################
        # Update GUI
        self.timer = QTimer()
        self.connect(self.timer, SIGNAL("timeout()"), self.visual_UI)
        self.timer.start(50)