#!/usr/bin/env python #-*- coding:utf-8 -* """ The pyscan software V1 G{importgraph} """ # pyscan # Copyright (C) 2013 GALODE A. # # This file is part of Expymaker. # # pyscan is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # pyscan is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with pyscan. If not, see import shutil import os import path_mkr import bdd_pyscan import arduino_pyscan import img_pyscan import fileout_pyscan import ihm_pyscan import serial_pyscan import webcam_pyscan import thread import time #=======================================================================# # Classe gérant le logiciel # #=======================================================================# class Pyscan3d(): """ Class which manage the pyscan software G{classtree} """ #===================================================# # Init # #===================================================# def __init__(self): self.serial_state = False self.arduino_state = False self.webcam_state = False self.path_base = self.f_init_path() self.bdd = self.f_init_bdd() self.f_bdd_read_all() self.img = self.f_init_img() self.serialcom = self.f_init_serialcom() self.list_port = self.serialcom.f_get_ports() self.list_lang = self.f_bdd_read_lang_dispo() self.interface = self.f_init_ihm() self.p_start_software() #===================================================# # Init de path_mkr # #===================================================# def f_init_path(self): """ Allow to know the execution path PARAMETERS ========== None RETURNS ======= The execution path """ path_base = path_mkr.cxf_get_path() return path_base #===================================================# # Init de l'IHM # #===================================================# def f_init_ihm(self): """ Allow to init the IhmScanon class PARAMETERS ========== None RETURNS ======= An IhmScanon object """ ihm = ihm_pyscan.IhmPyscan(self.path_base,self.dict_about, self.dict_config, self.dict_ihm, self.list_port, \ self.list_lang, self.dict_error, self.dict_info, self.dict_warning, self.p_bdd_upd_config, \ self.p_scan, self.p_serial_open, self.p_serial_close) return ihm #===================================================# # Init des objets BddScanon # #===================================================# def f_init_img(self): """ Allow to create a BddScanon object PARAMETERS ========== None RETURNS ======= A BddScanon object """ img = img_pyscan.ImgPyscan() return img #===================================================# # Init des objets BddScanon # #===================================================# def f_init_fileout_obj(self): """ Allow to create a BddScanon object PARAMETERS ========== None RETURNS ======= A BddScanon object """ obj = fileout_pyscan.FileOBJ() return obj #===================================================# # Init des objets BddScanon # #===================================================# def f_init_fileout_xyz(self): """ Allow to create a BddScanon object PARAMETERS ========== None RETURNS ======= A BddScanon object """ xyz = fileout_pyscan.FileXYZ() return xyz #===================================================# # Init des objets BddScanon # #===================================================# def f_init_serialcom(self): """ Allow to create a BddScanon object PARAMETERS ========== None RETURNS ======= A BddScanon object """ serial = serial_pyscan.SerialPyscan() return serial #===================================================# # Init des objets BddScanon # #===================================================# def f_init_webcam(self): """ Allow to create a BddScanon object PARAMETERS ========== None RETURNS ======= A BddScanon object """ webcam = webcam_pyscan.WebcamPyscan() return webcam #===================================================# # Init des objets BddScanon # #===================================================# def f_init_bdd(self): """ Allow to create a BddScanon object PARAMETERS ========== None RETURNS ======= A BddScanon object """ bdd = bdd_pyscan.BddPyscan(self.path_base) return bdd #===================================================# # Lecture d'une partie de la base # #===================================================# def f_bdd_read_all(self): """ Allow to read several table of database and configure variable PARAMETERS ========== None RETURNS ======= None """ dict_param = self.bdd.f_read_base() self.dict_about = dict_param["ABOUT"] self.dict_config = dict_param["CONFIG"] self.dict_ihm = dict_param["IHM"] self.dict_arduino = dict_param["ARDUINO"] self.dict_error = dict_param["ERROR"] self.dict_info = dict_param["INFO"] self.dict_warning = dict_param["WARNING"] self.lang = self.dict_config["LANG"] #===================================================# # Lecture des langues disponibles # #===================================================# def f_bdd_read_lang_dispo(self): """ Allow to read the available language PARAMETERS ========== None RETURNS ======= A list with available languages """ list_lang_dispo = self.bdd.f_read_lang() return list_lang_dispo #===================================================# # MAJ de la langue choisie # #===================================================# def p_bdd_upd_config(self, param, value): """ Allow to update the selected language PARAMETERS ========== lang ---- The selected language RETURNS ======= None """ self.bdd.p_upd_config(param, value) #===================================================# # MAJ de la langue choisie # #===================================================# def p_serial_open(self): """ Allow to update the selected language PARAMETERS ========== lang ---- The selected language RETURNS ======= None """ port = self.interface.p_serial_get_port() self.serialcom.p_port_open(port) self.serial_state = True try: door = self.serialcom.f_emet_text(self.dict_arduino["DOOR_STATE"]) self.arduino_state = True except: self.arduino_state = False self.interface.p_gtk_win_error(None, self.dict_error["ERR002"]) self.p_ihm_upd(0) #===================================================# # MAJ de la langue choisie # #===================================================# def p_serial_close(self): """ Allow to update the selected language PARAMETERS ========== lang ---- The selected language RETURNS ======= None """ self.serialcom.p_port_close() self.serial_state = False self.arduino_state = False #===================================================# # MAJ de la langue choisie # #===================================================# def p_ihm_upd(self, mpap_step): """ Allow to update the selected language PARAMETERS ========== lang ---- The selected language RETURNS ======= None """ try: door = self.serialcom.f_emet_text(self.dict_arduino["DOOR_STATE"]) light = self.serialcom.f_emet_text(self.dict_arduino["LIGHT_STATE"]) laser1 = self.serialcom.f_emet_text(self.dict_arduino["LASER1_STATE"]) laser2 = self.serialcom.f_emet_text(self.dict_arduino["LASER2_STATE"]) pow12v = self.serialcom.f_emet_text(self.dict_arduino["POW12V"]) pow05v = self.serialcom.f_emet_text(self.dict_arduino["POW05V"]) except: self.interface.p_gtk_win_error(None, self.dict_error["ERR002"]) self.interface.p_status_upd(self.serial_state, self.arduino_state, \ self.webcam_state, door, light, laser1, laser2, \ mpap_step, pow12v, pow05v) return door #===================================================# # Init de path_mkr # #===================================================# def p_scan(self, config_dict, event): """ Allow to know the execution path PARAMETERS ========== None RETURNS ======= The execution path """ #Init of variables pourcentage = 0 pas = 0 self.config_dict = config_dict #Init of path path_file_ouput = os.path.join(self.path_base, self.config_dict["FILE_DST_DIR"]) path_file_ouput = os.path.join(path_file_ouput, self.interface.p_choice_file_name()) path_snapshot1 = os.path.join(self.path_base, self.config_dict["FILE_TMP_DIR"]) path_snapshot1 = os.path.join(path_snapshot1, "Capture1.png") path_webcam1 = path2 = os.path.join(self.path_base, self.config_dict["FILE_TMP_DIR"]) path_webcam1 = os.path.join(path_webcam1, "Webcam1.png") path_snapshot2 = os.path.join(self.path_base, self.config_dict["FILE_TMP_DIR"]) path_snapshot2 = os.path.join(path_snapshot2, "Capture2.png") path_webcam2 = path2 = os.path.join(self.path_base, self.config_dict["FILE_TMP_DIR"]) path_webcam2 = os.path.join(path_webcam2, "Webcam2.png") path_mire = path2 = os.path.join(self.path_base, "02-IMG/Mire.png") cur_vh, cur_vl, cur_hh, cur_hl = self.interface.f_cursor_get_position() self.webcam = self.f_init_webcam() self.webcam.p_open_flux(int(self.config_dict["WEBCAM_NUMBER"])) if self.interface.p_choice_ext() == "xyz": self.fileoutput = self.f_init_fileout_xyz() elif self.interface.p_choice_ext() == "obj": self.fileoutput = self.f_init_fileout_obj() else: self.interface.p_gtk_win_error(None, self.dict_error["ERR006"]) self.fileoutput.p_file_open(path_file_ouput) self.fileoutput.f_file_write_entete(self.interface.p_choice_file_name()) motor_angle = 0.0 #nb pas * angle pas * mode start = time.time() while(( motor_angle) < 15 and not (event.isSet())): print "event:", event.isSet() try: rtr0 = self.serialcom.f_emet_text(self.dict_arduino["LIGHT_OFF"]) rtr1 = self.serialcom.f_emet_text(self.dict_arduino["LASER_OFF"]) rtr2 = self.serialcom.f_emet_text(self.dict_arduino["LASER1_ON"]) except: self.interface.p_gtk_win_error(None, self.dict_error["ERR002"]) door = self.p_ihm_upd(pas) if door == "false": self.interface.p_gtk_win_error(None, self.dict_error["ERR002"]) break #self.webcam.p_capture_frame1(path_snapshot1, float(self.config_dict["WEBCAM_SENSIBILITY"])) self.img.p_webcam_capture1(path_snapshot1, path_webcam1, cur_vh, cur_vl, cur_hh, cur_hl) door = self.p_ihm_upd(pas) if door == "false": self.interface.p_gtk_win_error(None, self.dict_error["ERR002"]) break self.interface.p_webcam_upd_img(path_webcam1) try: rtr1 = self.serialcom.f_emet_text(self.dict_arduino["LASER_OFF"]) rtr2 = self.serialcom.f_emet_text(self.dict_arduino["LASER2_ON"]) except: self.interface.p_gtk_win_error(None, self.dict_error["ERR002"]) door = self.p_ihm_upd(pas) if door == "false": self.interface.p_gtk_win_error(None, self.dict_error["ERR002"]) break #self.webcam.p_capture_frame2(path_snapshot2, float(self.config_dict["WEBCAM_SENSIBILITY"])) self.img.p_webcam_capture1(path_snapshot2, path_webcam2, cur_vh, cur_vl, cur_hh, cur_hl) door = self.p_ihm_upd(pas) if door == "false": elf.interface.p_gtk_win_error(None, self.dict_error["ERR002"]) break self.interface.p_webcam_upd_img(path_webcam2) #Compute img 1 & 2 angle = motor_angle angle2 = motor_angle + (180 - (2 * int(self.config_dict["LASER_ANGLE"]))) #tab_xyz = self.img.f_compute_img_left(path_snapshot1, cur_hh, cur_hl, cur_vh, cur_vl, angle) #self.fileoutput.f_file_write_body(tab_xyz) tab_xyz = self.img.f_compute_img_right(path_snapshot2, cur_hh, cur_hl, cur_vh, cur_vl, angle2) self.fileoutput.f_file_write_body(tab_xyz) try: rtr0 = self.serialcom.f_emet_text(self.dict_arduino["MPAP+1"]) except: self.interface.p_gtk_win_error(None, self.dict_error["ERR002"]) motor_angle = motor_angle + ((360./int(self.config_dict["MPAP_NB_STEP"])) * int(self.config_dict["MPAP_MODE"])) pas += 1 door = self.p_ihm_upd(pas) if door == "false": self.interface.p_gtk_win_error(None, self.dict_error["ERR002"]) break pourcentage = (pas * 100) / int(self.config_dict["MPAP_NB_STEP"]) self.interface.p_pbar_upd_pourcentage(pourcentage) print "event:", event.isSet() print "event: effacement" event.clear() print "event:", event.isSet() self.fileoutput.f_file_write_end() self.fileoutput.p_file_close() del self.webcam del self.fileoutput self.p_ihm_upd(pas) stop = time.time() self.interface.p_scan_end() self.interface.p_webcam_upd_img(path_mire) elapsed_time = stop-start minute = int(elapsed_time/ 60) seconde = int(elapsed_time - (minute * 60)) text = self.dict_info["INF002"] + "%s mn %s s"%(minute,seconde) self.interface.p_gtk_win_info_thread(None,text) #===================================================# # Demarrage du logiciel # #===================================================# def p_start_software(self): """ Allow to start the software PARAMETERS ========== None RETURNS ======= None """ self.interface.start_ihm() #=======================================================================# # Main # #=======================================================================# if __name__ == "__main__": software = Pyscan3d()