Commit 09e9c744 authored by aorlati's avatar aorlati
Browse files

Added the common module OMUpdate that allows to autoimatically update the pointing models

parent 01a32c02
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line

Lo script può essere seguito da riga di comando con i parametri illustrati sotto. Il parametro -g avvia l’interfaccia grafica

PMUpdate -e <errorfile> -p <pointingxmlfile> -r <receiver> -g

-e: file con i paramenti di puntamento ottento tramite il programma pdplt
-p: file xml con i modelli di puntamento di nuraghe
-r: nome del ricevitore per il quale si stanno aggiornando i dati di puntamento



Credits Andrea Saba (Andrea.Saba@inaf.it)
+237 −0
Original line number Diff line number Diff line

#*******************************************************************************
# PPPPPPPP
#
# "@(#) $Id$"
#
# Makefile of ........
#
# who       when      what
# --------  --------  ----------------------------------------------
# discos  22/08/18  created
#

# ALMA - Atacama Large Millimeter Array
# Copyright (c) ESO - European Southern Observatory, 2014
# (in the framework of the ALMA collaboration).
# All rights reserved.
# 
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
# 
# This library 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
# Lesser General Public License for more details.
# 
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
#*******************************************************************************

#*******************************************************************************
# This Makefile follows ALMA/ACS Standards (see Makefile(5) for more).
#*******************************************************************************
# REMARKS
#    None
#------------------------------------------------------------------------

#
# user definable C-compilation flags
#USER_CFLAGS = 

#
# additional include and library search paths
#USER_INC = 
#USER_LIB = 

#
# MODULE CODE DESCRIPTION:
# ------------------------
# As a general rule:  public file are "cleaned" and "installed"  
#                     local (_L) are not "installed".

#
# C programs (public and local)
# -----------------------------
EXECUTABLES     =
EXECUTABLES_L   = 

#
# <brief description of xxxxx program>
xxxxx_OBJECTS   =	
xxxxx_LDFLAGS   =
xxxxx_LIBS      =

#
# special compilation flags for single c sources
#yyyyy_CFLAGS   = 

#
# Includes (.h) files (public only)
# ---------------------------------
INCLUDES        =

#
# Libraries (public and local)
# ----------------------------
LIBRARIES       =
LIBRARIES_L     =

#
# <brief description of lllll library>
lllll_OBJECTS   =

#
# Scripts (public and local)
# ----------------------------
SCRIPTS         =
SCRIPTS_L       =

#
# TCL scripts (public and local)
# ------------------------------
TCL_SCRIPTS     =
TCL_SCRIPTS_L   =

#
# Python stuff (public and local)
# ----------------------------
PY_SCRIPTS         = PMUpdate
PY_SCRIPTS_L       =

PY_MODULES         = upgrade_module utility PMUpdate_gui PMUpdate_main
PY_MODULES_L       =

PY_PACKAGES        =
PY_PACKAGES_L      =
pppppp_MODULES	   =

#
# <brief description of tttttt tcl-script>
tttttt_OBJECTS  =
tttttt_TCLSH    = 
tttttt_LIBS     = 

#
# TCL libraries (public and local)
# ------------------------------
TCL_LIBRARIES   =
TCL_LIBRARIES_L =

#
# <brief description of tttlll library>
tttlll_OBJECTS  = 

#
# Configuration Database Files
# ----------------------------
CDB_SCHEMAS = 

# 
# IDL Files and flags
# 
IDL_FILES =
TAO_IDLFLAGS =
USER_IDL =
#
# Jarfiles and their directories
#
JARFILES= 
jjj_DIRS=
jjj_EXTRAS=
# For expressing dependencies between jarfiles (parallel builds)
jjj_JLIBS= 
#
# java sources in Jarfile on/off
DEBUG= 
#
# ACS XmlIdl generation on/off
#
XML_IDL= 
#
# Java Component Helper Classes generation on/off
#
COMPONENT_HELPERS=
#
# Java Entity Classes generation on/off
#
XSDBIND=
#
# Schema Config files for the above
#
XSDBIND_INCLUDE=
# man pages to be done
# --------------------
MANSECTIONS =
MAN1 =
MAN3 =
MAN5 =
MAN7 =
MAN8 =

#
# local man pages
# ---------------
MANl =

#
# ASCII file to be converted into Framemaker-MIF
# --------------------
ASCII_TO_MIF = 

#
# other files to be installed
#----------------------------
INSTALL_FILES =

#
# list of all possible C-sources (used to create automatic dependencies)
# ------------------------------
CSOURCENAMES = \
	$(foreach exe, $(EXECUTABLES) $(EXECUTABLES_L), $($(exe)_OBJECTS)) \
	$(foreach rtos, $(RTAI_MODULES) , $($(rtos)_OBJECTS)) \
	$(foreach lib, $(LIBRARIES) $(LIBRARIES_L), $($(lib)_OBJECTS))

#
#>>>>> END OF standard rules

#
# INCLUDE STANDARDS
# -----------------

MAKEDIRTMP := $(shell searchFile include/acsMakefile)
ifneq ($(MAKEDIRTMP),\#error\#)
   MAKEDIR := $(MAKEDIRTMP)/include
   include $(MAKEDIR)/acsMakefile
endif

.DEFAULT_GOAL := all

#
# TARGETS
# -------
all: gui do_all
	@echo " . . . 'all' done" 

clean : clean_all 
	@rm -f PMUpdate_gui.py*
	@echo " . . . clean done"

clean_dist : clean_all clean_dist_all 
	@echo " . . . clean_dist done"

man   : do_man 
	@echo " . . . man page(s) done"

install : install_all
	@echo " . . . installation done"
	@chmod 700 $(INTROOT)/bin/PMUpdate

gui :
	pyuic4 PMUpdate_gui.ui -o PMUpdate_gui.py


#___oOo___
+42 −0
Original line number Diff line number Diff line
#! /usr/bin/env python

from upgrade_module import load_error_file_on_xml
import sys, getopt

def main(argv):
    errorfile = ""
    pointingxmlfile = ""
    receiver = ""

    try:
        opts, args = getopt.getopt(argv,"hge:p:r:",["errorfile=", "pointingxmlfile=", "receiver="])
    except getopt.GetoptError:
        print 'PMUpdate -e <errorfile> -p <pointingxmlfile> -r <receiver> -g'
        sys.exit(2)
    for opt, arg in opts:
        if opt == '-h':
            print 'PMUpdate -e <errorfile> -p <pointingxmlfile> -r <receiver> -g '
            sys.exit()
        elif opt == "-g":
            from PMUpdate_main import main as main_gui
            main_gui()
            sys.exit()
        elif opt in ("-e", "--errorfile"):
            errorfile = arg
        elif opt in ("-p", "--pointingfile"):
            pointingxmlfile = arg
        elif opt in ("-r", "--receiver"):
            receiver = arg

    if errorfile == "" or pointingxmlfile == "" or receiver == "":
        print 'PMUpdate -e <errorfile> -p <pointingxmlfile> -r <receiver> -g'
        sys.exit("ERRORE: all parameters required")

    error_code , result = load_error_file_on_xml(errorfilename=errorfile, pointingxmlfilename=pointingxmlfile, receivername=receiver)
    if error_code:
        sys.exit("ERRORE: " + result)

if __name__ == "__main__":
   main(sys.argv[1:])

+132 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
 <author>Andrea Saba</author>
 <class>MainWindow</class>
 <widget class="QMainWindow" name="MainWindow">
  <property name="windowModality">
   <enum>Qt::NonModal</enum>
  </property>
  <property name="geometry">
   <rect>
    <x>0</x>
    <y>0</y>
    <width>939</width>
    <height>176</height>
   </rect>
  </property>
  <property name="windowTitle">
   <string>DISCOS - Update pointing file</string>
  </property>
  <widget class="QWidget" name="centralwidget">
   <layout class="QGridLayout" name="gridLayout_2">
    <item row="2" column="0" rowspan="3" colspan="2">
     <layout class="QGridLayout" name="gridLayout_3">
      <item row="0" column="0">
       <widget class="QLabel" name="label">
        <property name="text">
         <string>XML Pointing file</string>
        </property>
       </widget>
      </item>
      <item row="1" column="0">
       <widget class="QLabel" name="label_2">
        <property name="text">
         <string>pdplt error file</string>
        </property>
       </widget>
      </item>
      <item row="2" column="0">
       <widget class="QLabel" name="label_3">
        <property name="text">
         <string>Receiver</string>
        </property>
       </widget>
      </item>
      <item row="0" column="1">
       <widget class="QLineEdit" name="lineEdit_xml">
        <property name="enabled">
         <bool>false</bool>
        </property>
       </widget>
      </item>
      <item row="1" column="1">
       <widget class="QLineEdit" name="lineEdit_error">
        <property name="enabled">
         <bool>false</bool>
        </property>
       </widget>
      </item>
      <item row="0" column="2">
       <widget class="QPushButton" name="pushButton_browse_xml">
        <property name="text">
         <string>...</string>
        </property>
       </widget>
      </item>
      <item row="1" column="2">
       <widget class="QPushButton" name="pushButton_browse_error">
        <property name="text">
         <string>...</string>
        </property>
       </widget>
      </item>
      <item row="2" column="1" colspan="2">
       <widget class="QComboBox" name="comboBox_receivers">
        <property name="enabled">
         <bool>false</bool>
        </property>
       </widget>
      </item>
      <item row="3" column="0" colspan="3">
       <layout class="QHBoxLayout" name="horizontalLayout">
        <item>
         <widget class="QPushButton" name="pushButton_exit">
          <property name="text">
           <string>Exit</string>
          </property>
         </widget>
        </item>
        <item>
         <widget class="QPushButton" name="pushButton_update">
          <property name="enabled">
           <bool>false</bool>
          </property>
          <property name="text">
           <string>Update</string>
          </property>
         </widget>
        </item>
       </layout>
      </item>
     </layout>
    </item>
    <item row="5" column="0" colspan="2">
     <spacer name="verticalSpacer">
      <property name="orientation">
       <enum>Qt::Vertical</enum>
      </property>
      <property name="sizeHint" stdset="0">
       <size>
        <width>20</width>
        <height>40</height>
       </size>
      </property>
     </spacer>
    </item>
   </layout>
  </widget>
  <widget class="QMenuBar" name="menubar">
   <property name="geometry">
    <rect>
     <x>0</x>
     <y>0</y>
     <width>939</width>
     <height>21</height>
    </rect>
   </property>
  </widget>
  <widget class="QStatusBar" name="statusbar"/>
 </widget>
 <resources/>
 <connections/>
</ui>
+191 −0
Original line number Diff line number Diff line
#! /usr/bin/env python
# -*- coding: utf-8 -*-
#
# Here we provide the necessary imports.
# The basic GUI widgets are located in QtGui module.
import sys
from PyQt4 import QtGui
import xml.etree.ElementTree
from upgrade_module import load_error_file_on_xml
from PMUpdate_gui import Ui_MainWindow

VERSION = "0.3"

# list of filed required in schedeule data section file
fields_required = {"Date__(UT)__HR:MN:SS", "R.A._(ICRF/J2000.0)", "DEC_(ICRF/J2000.0)"}
# split_file_header is used to find the schedule data section file
split_file_header = "Date__"


class Editor(QtGui.QMainWindow):

    def __init__(self):
        super(Editor, self).__init__()
        self.xml_file_status = False
        self.pdplt_file_status = False
        self.receivers_status = False
        self.ui=Ui_MainWindow()
        self.ui.setupUi(self)
        self.home()

    def home(self):
        self.ui.pushButton_exit.clicked.connect(self.menu_exitcommand)
        self.ui.pushButton_browse_xml.clicked.connect(self.browsecommand_xml)
        self.ui.pushButton_browse_error.clicked.connect(self.browsecommand_error)
        self.ui.comboBox_receivers.currentIndexChanged.connect(self.combobox_select)
        self.ui.pushButton_update.clicked.connect(self.menu_updatecommand)
        self.show()

    def menu_updatecommand(self):
        error, error_messgae = load_error_file_on_xml(errorfilename=self.ui.lineEdit_error.text(),
                               pointingxmlfilename=self.ui.lineEdit_xml.text(),
                               receivername=str(self.ui.comboBox_receivers.currentText()))

        if error>0:
            qmsg = QtGui.QMessageBox()
            qmsg.setIcon(QtGui.QMessageBox.Critical)
            qmsg.setWindowTitle("Error")
            qmsg.setText(error_messgae)
            qmsg.show()
        else:
            qmsg = QtGui.QMessageBox()
            qmsg.setIcon(QtGui.QMessageBox.Information)
            qmsg.setWindowTitle("Error")
            qmsg.setText("Update completed.")
            qmsg.show()

    def browsecommand_xml(self):

        receivers = []

        fileName = QtGui.QFileDialog()
        WindowTitle = "Open XML Pointing file"
        Directory = "."
        Filter = "XML Files (*.xml)"

        self.ui.lineEdit_xml.setText(fileName.getOpenFileName(self, WindowTitle, Directory, Filter))

        try:
            xml.etree.ElementTree.register_namespace('', 'urn:schemas-cosylab-com:PointingModel:1.0')
            xml.etree.ElementTree.register_namespace('baci', 'urn:schemas-cosylab-com:BACI:1.0')
            xml.etree.ElementTree.register_namespace('cdb', 'urn:schemas-cosylab-com:CDB:1.0')
            xml.etree.ElementTree.register_namespace('xsi', 'http://www.w3.org/2001/XMLSchema-instance')
            et = xml.etree.ElementTree.parse(self.ui.lineEdit_xml.text())

            e = et.getroot()

            for child in e:
                receivers.append(child[0].text.strip())
            if len(receivers) == 0:
                self.xml_file_status = False
                qmsg = QtGui.QMessageBox()
                qmsg.setIcon(QtGui.QMessageBox.Critical)
                qmsg.setWindowTitle("Error")
                qmsg.setText("pointingxmlfilename: no receivers found")
                qmsg.show()
        except ValueError as e:
            self.xml_file_status = False
            qmsg = QtGui.QMessageBox()
            qmsg.setIcon(QtGui.QMessageBox.Critical)
            qmsg.setWindowTitle("Error")
            qmsg.setText("pointingxmlfilename: xml parsing error {error_value}".format(error_value=e))
            qmsg.show()

        # svuota il dropdown

        self.ui.comboBox_receivers.clear()

        # aggiungi la lista dei ricevitori al drop down

        for receiver in receivers:
            self.ui.comboBox_receivers.insertItem(0, receiver)

        self.xml_file_status = True

        self.ui.comboBox_receivers.setEnabled(self.xml_file_status and self.pdplt_file_status)
        self.ui.pushButton_update.setEnabled(self.xml_file_status and self.pdplt_file_status and self.receivers_status)

    def browsecommand_error(self):

        fileName = QtGui.QFileDialog()
        fileName.setWindowTitle("Open pdplt error file")
        fileName.setDirectory(".")
        fileName.setFilter("pdplt error file (*.*)")

        self.ui.lineEdit_error.setText(fileName.getOpenFileName())

        try:
            errorfilename_rows = []
            start_section = False
            with open(self.ui.lineEdit_error.text(), 'rb') as f:
                for line in f:
                    line_strip = line.strip()
                    if start_section:
                        if line_strip == "*":
                            pass
                        else:
                            errorfilename_rows.append(line_strip.split())
                    if line_strip == "$new_model":
                        start_section = True
                else:
                    # No more lines to be read from file
                    if not start_section:
                        self.pdplt_file_status = False
                        qmsg = QtGui.QMessageBox()
                        qmsg.setIcon(QtGui.QMessageBox.Critical)
                        qmsg.setWindowTitle("Error")
                        qmsg.setText("errorfilename: new model not found")
                        qmsg.show()
            if len(errorfilename_rows) < 8:
                self.pdplt_file_status = False
                qmsg = QtGui.QMessageBox()
                qmsg.setIcon(QtGui.QMessageBox.Critical)
                qmsg.setWindowTitle("Error")
                qmsg.setText("errorfilename: new model section too short")
                qmsg.show()

            if len(errorfilename_rows[0]) <> 7 or \
                    len(errorfilename_rows[1]) <> 31 or \
                    len(errorfilename_rows[2]) <> 5 or \
                    len(errorfilename_rows[3]) <> 5 or \
                    len(errorfilename_rows[4]) <> 5 or \
                    len(errorfilename_rows[5]) <> 5 or \
                    len(errorfilename_rows[6]) <> 5 or \
                    len(errorfilename_rows[7]) <> 5:
                self.pdplt_file_status = False
                qmsg = QtGui.QMessageBox()
                qmsg.setIcon(QtGui.QMessageBox.Critical)
                qmsg.setWindowTitle("Error")
                qmsg.setText("errorfilename: not enough parameters in new model section")
                qmsg.show()

        except:
            self.pdplt_file_status = False
            qmsg = QtGui.QMessageBox()
            qmsg.setIcon(QtGui.QMessageBox.Critical)
            qmsg.setWindowTitle("Error")
            qmsg.setText("errorfilename: generic error on parameters extraction")
            qmsg.show()

        self.pdplt_file_status = True
        self.ui.comboBox_receivers.setEnabled(self.xml_file_status and self.pdplt_file_status)
        self.ui.pushButton_update.setEnabled(self.xml_file_status and self.pdplt_file_status and self.receivers_status)

    def combobox_select(self, index):
        if index == -1:
            self.receivers_status = False
        else:
            self.receivers_status = True
        self.ui.pushButton_update.setEnabled(self.xml_file_status and self.pdplt_file_status and self.receivers_status)

    def menu_exitcommand(self):
        sys.exit()


def main():
    app = QtGui.QApplication(sys.argv)
    ex = Editor()
    sys.exit(app.exec_())

if __name__ == '__main__':
    main()
Loading