msctimer.py 3.67 KB
Newer Older
Maxime Perrotin's avatar
Maxime Perrotin committed
1 2 3 4 5 6 7 8
#******************************************************************************
#
# 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
9
#  modify it under the terms of the GNU Lesser General Public License as published
Maxime Perrotin's avatar
Maxime Perrotin committed
10 11 12 13 14 15
#  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
16
#  GNU Lesser General Public License for more details.
Maxime Perrotin's avatar
Maxime Perrotin committed
17
#
18
#  You should have received a copy of the GNU Lesser General Public License
Maxime Perrotin's avatar
Maxime Perrotin committed
19 20 21 22 23
#  along with TASTE Msc Diagram Editor.  If not, see
#  <http://www.gnu.org/licenses/>.
#
#  Author: Angel Esquinas <aesquina@datsi.fi.upm.es>
#
24
#  Copyright (c) 2012 UPM and European Space Agency
Maxime Perrotin's avatar
Maxime Perrotin committed
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
#
#******************************************************************************
u"""
The :class:`msccore.MscTimer` class represents a timer event within MSC. 
Various :class:`msccore.MscTimer` can represent the same timer if its have
the same name. The behavior of :class:`~msccore.MscTimer` is different depends
in the type of timer event. This timer event are represented by
:attr:`Tipe Timers`.

:class:`msccore.MscTimer` 

:attr:`Type Timers`
^^^^^^^^^^^^^^^^^^^
+-------------------------------------+---------------------+
| Constant                            | Description         |
+=====================================+=====================+
| :const:`MscTimer.StartTimer`        | Start timer         |
+-------------------------------------+---------------------+
| :const:`MscTimer.StopTimer`         | Stop timer          |
+-------------------------------------+---------------------+
| :const:`MscTimer.TimeOut`           | Time out timer      |
+-------------------------------------+---------------------+

Timers are events. Timer can be `elem` within :class:`msccore.MscEvent`.

..
  .. tabularcolums::

:const:`MscCore.StartTimer`, :const:`MscCore.StopTimer`

"""
from mscelement import MscElement


class MscTimer(MscElement):
    u"""
    :param unicode name: Name of timer
    :param int orderPos: Absolute pos of timer, when used as event.
    :param int typeTimer: Type of timer.
    :param parent:
    :type parent: PySide.QtCore.QObject
    """
    TYPE = u"Timer"
    StartTimer, StopTimer, TimeOut = range(3)

    def __init__(self, name, orderPos=0, typeTimer=StartTimer, parent=None):
        '''
        Constructor
        '''
        super(MscTimer, self).__init__(name, parent, self.TYPE)
        self.setAbsPos(orderPos)
        self.setTimerType(typeTimer)

    def delete(self):
        """ Delete are the destroyer of MscTimer
        The signal 'deleted' is emitted before destroy himself.
        """
        self.deleted.emit(self)
        self.deleteLater()

    def timerType(self):
        u""" Return the type of the timer"""
        return self._timerType

    def setTimerType(self, typeTimer):
        u""" Set the type of the timer"""
        self._timerType = typeTimer
        self.dataChanged()

    #Order/Graphical Pos
    def setAbsPos(self, pos):
        self._absPos = pos

    def absPos(self):
        return self._absPos

    def accept(self, visitor):
        u""" Visitor Pattern"""
        visitor.visitorMscTimer(self)

    def __str__(self):
        return """<<{0}:{1}. Type {2}. Pos {3}>>\n
                comment: {4}""".format(self.TYPE, self.getName(),
                                       self.timerType(),
                                       self.absPos(), self.comment())