mscmessagedecl.py 3.58 KB
Newer Older
Maxime Perrotin's avatar
Maxime Perrotin committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
#******************************************************************************
#
# TASTE Msc Diagram Editor
# http://taste.tuxfamily.org/
#
#  This file is part of TASTE Msc Editor.
#
#  TASTE Msc Diagram Editor 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.
#
#  TASTE Msc Diagram Editor 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 TASTE Msc Diagram Editor.  If not, see
#  <http://www.gnu.org/licenses/>.
#
#  Author: Angel Esquinas <aesquina@datsi.fi.upm.es>
#
#  Copyright (c) 2012 European Space Agency
#
#******************************************************************************
from mscelement import MscElement


class MscMessageDecl(MscElement):
    u"""
    The MscMessageDecl represents information about declaration of
    messages with parameters.
    """
    # Signal that must be emitted when data of the element has changed.

    def __init__(self, msgName, parameters=[], parent=None):
        super(MscMessageDecl, self).__init__(parent)

        self._name = msgName
        self._parametersType = []

        for i in parameters:
            self.addParameterType(i)

        #self.dataHasChanged.connect(self.contentsChanged)

    def delete(self):
        self.deleted.emit(self)
        self.deleteLater()

#    def name(self):
#        u""" Return the name of message"""
#        return self._name
#
#    def setName(self, name):
#        u""" Set 'name' as new name of message """
#        self._name = name
#        # Emit data changed signals
#        self.nameChanged.emit(self._name)
#        self.dataHasChanged.emit()

    def numberOfParameters(self):
        u""" Return the number of parameters declared """
        return len(self._parametersType)

    def parametersType(self):
        u""" Return the list of parameters """
        return self._parametersType

    def changeParameterTye(self, index, parameterType):
        u"""
        Change the value of parameter in position 'index' to 'parameter'
        """
        if 0 <= index < self.numberOfParameters():
            self._parametersType[index] = parameterType
            self.dataChanged()
            return True
        return False

    def addParameterType(self, parameter):
        u"""
        Add 'parameter' to the list of parameters.
        The parameters are save in the last position
        """
        self._parametersType.append(parameter)
        self.dataChanged()
        return True

    def delParameter(self, index):
        u"""
        Delete the parameter in position 'index' and return it.
        """
        par = self._parametersType.pop(index)
        self.dataChanged()
        #self.dataChanged()
        return par

    def textual(self):
        u"""
        Return the standard textual form of message declaration.
        (02/2011) ITU-T Z.120 5.4
        """
        if self.numberOfParameters() == 0:
            return u"{name}".format(name=self.name())
        else:
            return u"{name} : ({types})".format(name=self.name(),
                types=u', '.join(self.parametersType()))

    def __str__(self):
        return u"{name} : ({types})".format(name=self.name(),
                                            types=u', '.join(self.parametersType()))