def slot_ok(self): while True: self.chuck_define = [] result = self.th.back_message(self.chuck_define, '$MEASURE\0') print '%s, %s' % (result, len(self.chuck_define)) if (result != 'error') & (len(self.chuck_define) == 2): if self.chuck_define != 0: self.img_b_list[0].setPixmap( QPixmap('Dusan-4/uiFile/red-check.png')) else: self.img_b_list[0].setPixmap( QPixmap('Dusan-4/uiFile/uncheck.png')) if self.chuck_define[1] != 0: self.img_b_list[1].setPixmap( QPixmap('Dusan-4/uiFile/red-check.png')) else: self.img_b_list[1].setPixmap( QPixmap('Dusan-4/uiFile/uncheck.png')) if (self.chuck_define[0] != 0) & (self.chuck_define[1] != 0): self.img_b_list[2].setText( '후면 레이저의 측정이 완료되었습니다.\n초기값을 변경하였습니다.') value.set_chuck(self.chuck_define) else: self.img_b_list[2].setText( '후면 레이저의 측정을 실패하였습니다.\n초기값이 변경되지 않았습니다.') self.chuck_define = value.get_chuck() self.ui.setting_com.setText('') self.ui.setting_info.setText( '척 기본값 : %s\n프레임 길이 : %d\n좌표계 보정값 : %s\n척 보정값 : %s\n레이저 사이 간격 : %s' % (value.get_chuck(), value.get_frame(), value.get_coor(), value.get_chuck_scale(), value.get_laser())) break
def __init__(self): QMainWindow.__init__(self) # define values file upload. value.set_value() self.measureData = [] self.tempMessage = [] self.xlist, self.ylist, self.rlist, self.xclist, self.yclist, self.laserlist = [], [], [], [], [], [] self.tempData = [self.measureData, self.xlist, self.ylist, self.rlist, self.xclist, self.yclist, self.laserlist] self.resultData = data_set.MeasureData(None) # start ui drawing. self.ui = Ui_MainWindow() self.ui.setupUi(self) # set window view size maximum. self.showMaximized() self.message_list = [self.ui.msg_1, self.ui.msg_2, self.ui.msg_3, self.ui.msg_4, self.ui.msg_5] # laser connect state ui values list. self.uiList = [self.ui.img_Rsock, self.ui.img_Lsock, self.ui.img_Bsock] self.uiBList = [self.ui.img_B1, self.ui.img_B2, self.ui.laser_state_B] # laser state ui values list. self.uiLaserList = [self.ui.img_R1, self.ui.img_R2, self.ui.img_R3, self.ui.img_R4, self.ui.img_L1, self.ui.img_L2, self.ui.img_L3, self.ui.img_L4] self.layerlist = [self.ui.layer_R1, self.ui.layer_R2, self.ui.layer_R3, self.ui.layer_R4, self.ui.layer_L1, self.ui.layer_L2, self.ui.layer_L3, self.ui.layer_L4] # set range. self.gScene = QGraphicsScene(0, 0, value.get_frame()/4, value.get_frame()/4, self.ui.graphicsView) self.ui.graphicsView.setScene(self.gScene) # socket connection start self.th = Socket(self, self.uiList) self.th.start() self.dialog = Connection(self.th) self.calculation = Calculation() # setting window set. Setting.setting = Setting(self.th, self.uiBList) Setting.setting.ui = Ui_SettingWindow() Setting.setting.ui.setupUi(Setting.setting) Setting.setting.btnList = [Setting.setting.ui.btn_laser, Setting.setting.ui.btn_chuck_default, Setting.setting.ui.btn_frame_set, Setting.setting.ui.btn_coor_set, Setting.setting.ui.btn_chuck_set, Setting.setting.ui.btn_laser_set] Setting.setting.ui.setting_info.setText('척 기본값 : %s\n프레임 길이 : %d\n좌표계 보정값 : %s\n척 보정값 : %s\n레이저 사이 간격 : %s' % (value.get_chuck(), value.get_frame(), value.get_coor(), value.get_chuck_scale(), value.get_laser())) # drawing basic view --------------------------------------------------------------------------- # ------------------------------------------------------------------------------------------------- # pen, brush setting inside_color = QBrush(Qt.white) pen = QPen(Qt.red) pen.setWidth(4) # make 8 laser lines self.laser = [] line = self.calculation.get_laser_location() for i in range(len(line)): line[i] = line[i] * 0.25 self.laser.append(QGraphicsLineItem(0, (self.gScene.height() / 2-line[i]), self.gScene.width(), (self.gScene.height() / 2-line[i]))) self.laser[i].setPen(pen) self.gScene.addItem(self.laser[i]) # make circle pen.setColor(Qt.blue) self.circle = self.gScene.addEllipse(self.gScene.width() / 2 - 50, self.gScene.height() / 2 - 50, 100, 100, pen, inside_color) self.circle_pot = self.gScene.addEllipse(self.gScene.width() / 2 - 2.25, self.gScene.height() / 2 - 2.25, 5, 5, pen, Qt.blue) # make chuck pot pen.setColor(Qt.red) self.chuck_pot = self.gScene.addEllipse(self.gScene.width() / 2 - 2.25, self.gScene.height() / 2 - 2.25, 5, 5, pen, Qt.red) # make x, y lines self.x_line = QGraphicsLineItem(0, self.gScene.height() / 2, self.gScene.width(), self.gScene.height() / 2) self.gScene.addItem(self.x_line) self.y_line = QGraphicsLineItem(self.gScene.width() / 2, 0, self.gScene.width() / 2, self.gScene.height()) self.gScene.addItem(self.y_line)
def slot_ok(self): self.chuck_define = Setting.setting.get_chuck() if len(self.chuck_define) != 2: # if system don't have chuck information, you can't start measure program. QMessageBox.question(self, 'Alert Box', '척 기본값을 먼저 셋팅해 주세요.', QMessageBox.Yes) else: # [ change ] image -> text. self.slot_ok_time = time.time() for_int = 0 del self.measureData[:] del self.tempMessage[:] for i in range(len(self.tempData)): del self.tempData[i][:] object_name = self.sender().objectName() if object_name == 'btn_one': for_int = 1 elif object_name == 'btn_all_ten': for_int = 10 else: for_int = 5 circle_scale = value.get_coor() chuck_scale = value.get_chuck_scale() self.resultData = data_set.MeasureData(None) for i in range(for_int): self.measureData.append(self.th.message('$MEASURE\0')) if self.measureData[i] == 'error': while True: self.measureData[i] = self.th.message('$MEASURE\0') if self.measureData[i] != 'error': break for i in range(for_int): laser_length = self.measureData[i] if len(laser_length) == 10: pipe = self.calculation.func_calculation(laser_length) # Scale pipeY, pipeZ, chuck_x, chuck_y. pipeY = pipe[0] - circle_scale[0] pipeZ = pipe[1] - circle_scale[1] chuck_x = (laser_length[-2] - self.chuck_define[0]) - chuck_scale[0] chuck_y = (laser_length[-1] - self.chuck_define[1]) - chuck_scale[1] #chuck_y = (self.chuck_define[1] - laser_length[-1]) - chuck_scale[1] self.tempData[1].append(pipeY) self.tempData[2].append(pipeZ) self.tempData[3].append(pipe[2]) self.tempData[4].append(chuck_x) self.tempData[5].append(chuck_y) self.tempData[6].append(pipe[3]) self.tempMessage.append('\t파이프 좌표 y, z (%d, %d) / 파이프 지름 : %d \n\t척 y, z (%d, %d)\n\t%02d:%02d:%02d' % (-pipeY, pipeZ, pipe[2] * 2, -chuck_x, chuck_y, time.localtime().tm_hour, time.localtime().tm_min, time.localtime().tm_sec)) else: self.tempData[1].append('error') self.tempData[2].append('error') self.tempData[3].append(0) self.tempData[4].append('error') self.tempData[5].append('error') self.tempData[6].append([0, 0, 0, 0, 0, 0]) self.tempMessage.append('\t측정이 잘못되었습니다. 측정을 다시 시도해주세요.\n\t%02d:%02d:%02d' %(time.localtime().tm_hour, time.localtime().tm_min, time.localtime().tm_sec)) result = [] half = int(for_int/2) for i in range(len(self.tempData)): if object_name == 'btn_one': if self.tempData[i][0] == 'error': self.resultData.errorFlag = True break else: result.append(self.tempData[i][0]) else: if i == 0: result.append(self.double_arr(i, 10)) elif i != len(self.tempData)-1: self.tempData[i].sort() if self.tempData[i][half+1] == 'error': self.resultData.errorFlag = True break else: result.append(self.tempData[i][half]) else: result.append(self.double_arr(i, 6)) if not self.resultData.errorFlag: self.resultData.setting(result) if len(self.measureData) > 0: message = self.resultData.message+'\n\t%02d:%02d:%02d' %(time.localtime().tm_hour, time.localtime().tm_min, time.localtime().tm_sec) self.message_setting(message) self.ui.msg_0.setText(('{0}회 측정 최종 값\n'.format(for_int))+message) self.draw() else: self.ui.msg_0.setText('\t측정이 잘못되었습니다. 다시 측정해주세요.\n\t%02d:%02d:%02d' %(time.localtime().tm_hour, time.localtime().tm_min, time.localtime().tm_sec)) self.message_setting('\t측정이 잘못되었습니다. 다시 측정해주세요.\n\t%02d:%02d:%02d' %(time.localtime().tm_hour, time.localtime().tm_min, time.localtime().tm_sec)) self.ui.img_LR.setPixmap(QPixmap('Dusan-4/uiFile/non-arrow.png')) self.ui.img_UD.setPixmap(QPixmap('Dusan-4/uiFile/non-arrow.png')) self.ui.information_LR.setText('ㅡ') self.ui.information_UD.setText('ㅡ')
def slot_action(self): command = self.sender().objectName() passNumber = None if self.toggle: self.toggle = not self.toggle self.ui.setting_com.setEnabled(True) if command == 'btn_frame_set': self.ui.setting_info.setText( '< ex >\n\t1670\n\t1674\n\t1660\n\n#현재 프레임 길이\n\t>> %d' % value.get_frame()) self.ui.setting_com.setPlaceholderText('프레임 길이를 입력해주세요.') self.ui.btn_frame_set.setText('프레임 길이설정 완료') passNumber = 2 elif command == 'btn_coor_set': self.ui.setting_info.setText( '< ex >\n\t6, -32\n\t0, 0\n\t50, 50\n\n#현재 좌표계 보정 값\n\t>> %s' % value.get_coor()) self.ui.setting_com.setPlaceholderText('보정할 y, x 좌표를 입력해주세요.') self.ui.btn_coor_set.setText('좌표계 보정 완료') passNumber = 3 elif command == 'btn_chuck_set': self.ui.setting_info.setText( '< ex >\n\t10, 10\n\t-10, 3\n\t0, 0\n\n#현재 척 보정 값\n\t>> %s' % value.get_chuck_scale()) self.ui.setting_com.setPlaceholderText('보정할 y, x 좌표를 입력해주세요.') self.ui.btn_chuck_set.setText('척 보정 완료') passNumber = 4 elif command == 'btn_laser_set': self.ui.setting_info.setText( '< ex > 중심을 기준으로 제일 위쪽 레이저모듈 부터\n\t제일 아래쪽 레이저모듈 순서로 적어주세요.' '\n\t60, 20, -20, -60\n\t83, 43, -3, -37\n\n#현재 레이저 모듈사이 간격\n\t>> %s' % value.get_laser()) self.ui.setting_com.setPlaceholderText( '레이저 모듈사이 간격( 순서 : R1, R2, R3, R4 )을 입력해주세요.') self.ui.btn_laser_set.setText('좌표계 보정 완료') passNumber = 5 for i in range(len(Setting.setting.btnList)): if i != passNumber: Setting.setting.btnList[i].setEnabled(False) else: temp = None result = False if command == 'btn_frame_set': try: temp = self.ui.setting_com.text() temp = int(temp) result = not result except Exception as e: QMessageBox.warning(Setting.setting, '경고메시지', '값을 잘못입력하였습니다.\n다시 입력하세요.', QMessageBox.Yes) print 'error > ', e # 프레임길이가 너무 큰 경우 막아야 하는데 최대값 뭐로 하지? if result: self.ui.btn_frame_set.setText('프레임 길이설정') value.set_frame(temp) passNumber = 2 elif command == 'btn_coor_set': try: temp = self.ui.setting_com.text() temp = temp.split(', ') if len(temp) == 2: temp[0] = int(temp[0]) temp[1] = int(temp[1]) else: raise Exception result = not result except Exception as e: QMessageBox.warning(Setting.setting, '경고메시지', '값을 잘못입력하였습니다.\n다시 입력하세요.', QMessageBox.Yes) print 'error > ', e if result: self.ui.btn_coor_set.setText('좌표계 보정값 설정') value.set_coordination(temp) passNumber = 3 elif command == 'btn_chuck_set': try: temp = self.ui.setting_com.text() temp = temp.split(', ') if len(temp) == 2: temp[0] = int(temp[0]) temp[1] = int(temp[1]) else: raise Exception result = not result except Exception as e: QMessageBox.warning(Setting.setting, '경고메시지', '값을 잘못입력하였습니다.\n다시 입력하세요.', QMessageBox.Yes) print 'error > ', e if result: self.ui.btn_chuck_set.setText('척 보정값 설정') value.set_chuck_scale(temp) passNumber = 4 elif command == 'btn_laser_set': try: temp = self.ui.setting_com.text() temp = temp.split(', ') if len(temp) == 4: temp[0] = int(temp[0]) temp[1] = int(temp[1]) temp[2] = int(temp[2]) temp[3] = int(temp[3]) else: raise Exception result = not result except Exception as e: QMessageBox.warning(Setting.setting, '경고메시지', '값을 잘못입력하였습니다.\n다시 입력하세요.', QMessageBox.Yes) print 'error > ', e if result: self.ui.btn_laser_set.setText('레이저 사이 간격 설정') value.set_laser(temp) passNumber = 5 if result: for i in range(len(Setting.setting.btnList)): if i != passNumber: Setting.setting.btnList[i].setEnabled(True) self.ui.setting_com.setPlaceholderText('') self.ui.setting_com.setEnabled(False) self.toggle = not self.toggle self.ui.setting_info.setText( '척 기본값 : %s\n프레임 길이 : %d\n좌표계 보정값 : %s\n척 보정값 : %s\n레이저 사이 간격 : %s' % (value.get_chuck(), value.get_frame(), value.get_coor(), value.get_chuck_scale(), value.get_laser())) self.ui.setting_com.setText('') print 'setting 으아아악 > ', value.get_value()