Commit 261c647c authored by Maxime Perrotin's avatar Maxime Perrotin

Add support for procedure call symbol

parent 44c5f6b9
#******************************************************************************
#
# 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 LGPL 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 LGPL for more details.
#
# You should have received a copy of the GNU LGPL
# along with TASTE Msc Diagram Editor. If not, see
# <http://www.gnu.org/licenses/>.
#
# Author: Angel Esquinas <aesquina@datsi.fi.upm.es>
# Author of this module: Maxime Perrotin maxime.perrotin@esa.int
#
# Copyright (c) 2015 UPM and European Space Agency
#
#******************************************************************************
u"""
The :class:`msccore.MscProcedure` class represents a Procedure call
within the MSC.
:class:`msccore.MscProcedure`
"""
from mscelement import MscElement
class MscProcedure(MscElement):
u"""
:param unicode name: Text of the procedure call
:param int orderPos: Absolute pos of symbol, when used as event.
:param parent:
:type parent: PySide.QtCore.QObject
"""
TYPE = u"Procedure"
def __init__(self, name, orderPos=0, parent=None):
'''
Constructor
'''
super(MscProcedure, self).__init__(name, parent, self.TYPE)
self.setAbsPos(orderPos)
def delete(self):
""" Delete is the destructor of MscProcedure
The signal 'deleted' is emitted before destroy himself.
"""
self.deleted.emit(self)
self.deleteLater()
#Order/Graphical Pos
def setAbsPos(self, pos):
self._absPos = pos
def absPos(self):
return self._absPos
def accept(self, visitor):
u""" Visitor Pattern"""
visitor.visitorMscProcedure(self)
def __str__(self):
return """<<{0}:{1}. Pos {3}>>\n
comment: {4}""".format(self.TYPE, self.getName(),
self.absPos(), self.comment())
......@@ -243,6 +243,26 @@ class MscGraphBasicMSCScene(QGraphicsScene):
condition.delete()
if condition.scene():
self.removeItem(condition)
#--------------- Local Procedure Call
def addProcedure(self, instance, y=None, label=''):
u"""
Add new "Procedure call " to the scene and position it in y pos if any
"""
procedure = MscGraphProcedure(label=label, y=y,
parent=self.bmsc(), instance=instance)
instance.addEvent(procedure)
if y is not None:
procedure.setY(instance.mapFromScene(0, y).y())
procedure.itemSelected.connect(self.itemSelected)
self.itemInserted.emit(procedure)
return condition
def removeProcedure(self, procedure):
procedure.delete()
if procedure.scene():
self.removeItem(procedure)
#**************************************************************************
# Actions
#**************************************************************************
......
#******************************************************************************
#
# 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 LGPL License as published
# by the Free Software Foundation, either version 3 of the License
#
# 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 LGPL License for more details.
#
# Author: Angel Esquinas <aesquina@datsi.fi.upm.es>
# Author of this module: Maxime Perrotin <maxime.perrotin@esa.int>
#
# Copyright (c) 2015 UPM and European Space Agency
#
#******************************************************************************
from PySide.QtGui import QPainterPath, QPen, QBrush, QColor, QPainter
from PySide.QtCore import Qt, Slot, QPointF
from msccore import MscProcedure
from mscgraphics import MscGraphItem
from mscgraphics import MscLabelable
class MscGraphProcedure(MscGraphItem):
'''
Class that draws a Procedure call symbol
'''
DefaultWidth = 15
DefaultHeight = 30
def __init__(self, data=None, y=0, label=None, parent=None, instance=None):
super(MscGraphProcedure, self).__init__(parent)
self.setFlag(super(MscGraphProcedure, self).ItemIsMovable, True)
self.instance = instance
if label is None:
label = "Call"
if data is None:
self.setMscData(MscProcedure(name=label))
else:
self.setMscData(data)
self.initilizeGraphics()
self.addLabel()
# Signal when selected
self.setSignalWhenSelected(True)
# Create Path
self.createPath()
self.setPos(self.pos().x(), y or 0)
#**************************************************************************
# Data Functions
#**************************************************************************
@Slot(str)
def setDataName(self, name):
self.mscData().setName(name)
@Slot()
def readMscData(self):
self.updateLabel()
def delete(self):
u"""
Delete the MscGraphProcedure.
Reimplemented from MscGraphItem.
"""
# Ask parentItem to delete the event
# NOTE: This could be implemented with signals
parent = self.parentItem()
if parent != None:
parent.deleteMscEvent(self)
#**************************************************************************
# Graphical Text
#**************************************************************************
def addLabel(self):
self.label = MscLabelable(self.mscData().getName(), self)
self.updateLabelPosition()
self.label.labelChanged.connect(self.setDataName)
def updateLabel(self):
self.label.setTextLabel(self.mscData().getName())
def updateLabelPosition(self):
self.label.setCenterPos(QPointF(0, 15))
#**************************************************************************
# Item Change
#**************************************************************************
def limitsOfItem(self, value):
u""" Check the limits of the event area of parent """
parent = self.instance
if parent == None:
return value
upperY = parent.upperLimit().y()
#bottomY = parent.bottomLimit().y()
valueY = value.y()
if valueY < upperY:
valueY = upperY
new_pos = QPointF(self.pos().x(), valueY)
return new_pos
def itemChange(self, change, value):
''' On position change, check that item stays in an allowed area '''
if (change == super(MscGraphProcedure, self).ItemPositionChange):
value = self.limitsOfItem(value)
elif (change == super(MscGraphProcedure, self).ItemPositionHasChanged):
self.mscData().setAbsPos(self.mapToScene(0, 0).y())
self.yHasChanged.emit(self)
return value #MscGraphItem.itemChange(self, change, value)
#**************************************************************************
# Paint Functions
#**************************************************************************
def initilizeGraphics(self):
self.color = Qt.black
self.pen = QPen(self.color, 1, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin)
self.brush = QBrush(QColor(255, 255, 202))
def updateBounding(self):
u"""
Update internal drawing coordinates
"""
self.prepareGeometryChange()
rect = self.path.boundingRect()
self.drawOriginX = rect.x()
self.drawOriginY = rect.y()
self.width = rect.width()
self.height = rect.height()
self.updateLabelPosition()
def createPath(self):
u"""
Create the path of the Procedure Call symbol
"""
self.path = QPainterPath()
self.path.moveTo(0, 0)
self.path.lineTo(self.DefaultWidth, 0)
self.path.lineTo(self.DefaultWidth, self.DefaultHeight)
self.path.lineTo(0, self.DefaultHeight)
self.path.moveTo(5, self.DefaultHeight - 5)
self.path.lineTo(0, self.DefaultHeight)
self.path.lineTo(5, self.DefaultHeight + 5)
self.updateBounding()
def paint(self, painter, option, widget):
painter.setPen(self.pen)
painter.setBrush(self.brush)
painter.setRenderHint(QPainter.Antialiasing, True)
painter.drawPath(self.path)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment