https://taste.tuxfamily.org/wiki/index.php?title=Software_Design_MSC_Editor&feed=atom&action=historySoftware Design MSC Editor - Revision history2024-03-29T08:37:22ZRevision history for this page on the wikiMediaWiki 1.29.0https://taste.tuxfamily.org/wiki/index.php?title=Software_Design_MSC_Editor&diff=99&oldid=prevTtsiodras: 1 revision imported2017-08-04T21:01:56Z<p>1 revision imported</p>
<table class="diff diff-contentalign-left" data-mw="interface">
<tr style='vertical-align: top;' lang='en'>
<td colspan='1' style="background-color: white; color:black; text-align: center;">← Older revision</td>
<td colspan='1' style="background-color: white; color:black; text-align: center;">Revision as of 21:01, 4 August 2017</td>
</tr><tr><td colspan='2' style='text-align: center;' lang='en'><div class="mw-diff-empty">(No difference)</div>
</td></tr></table>Ttsiodrashttps://taste.tuxfamily.org/wiki/index.php?title=Software_Design_MSC_Editor&diff=98&oldid=prevMaxime-esa: /* Create new MSC Graphical Item */2013-10-16T09:26:49Z<p><span dir="auto"><span class="autocomment">Create new MSC Graphical Item</span></span></p>
<p><b>New page</b></p><div>= Overview =<br />
== Versions ==<br />
* 1- The authoritative are the grafical scene class, It is the model of data.<br />
* 2- In the future we have to achieve that the data will be out the scene, and the scene only be entrust to paint the element, but it have not the control of the data.<br />
<br />
= Parser =<br />
Must be parsed ITU T.120 Recomendation<br />
<br />
The parser is developed with PLY(Python Lex-Yacc). PLY is an implementation of lex and yacc parsing tools for Python. We can obtain PLY from [http://www.dabeaz.com/ply/ PLY Home Page]<br />
<br />
This part describes the whole development process. At the begining there is description of parsing process.<br />
<br />
== Parsing ==<br />
When the parser starts to read the input, it expect to read the document head and then descriptions of MSCs.<br />
* When parser read the head of document creates a Msc Document Data class. And It is the new scope and the root.<br />
* Then the parser expects MSC description, this starts with the name. Then, the parser creates a bMSC data class and put it like new scope.<br />
* When bMSc is created the parser expects starts of instances. When it has read the beginning of instance (I1 : instance) it creates an instance with the name, add the instance to bMSC in the scope.<br />
<br />
== Problems With Grammar Deffinition ITU T Z.120 (02/2011) ==<br />
I think that the latest version of ITU-T Z.120 recomendation for Message Sequence chart is not correctly define. I have problems to define the events inside instance declaration.<br />
The ITU-T define:<br />
<br />
<msc body> :== <msc statement> | <instance decl statement><br />
<msc statement> = <text definition> | <event definition><br />
<event definition> :== <instance name> : <instance event list><br />
<instance event list> :== <instance head statement> <instance event>* {<instance end statement> | ...}<br />
<instance decl statement> :== <instance head statement> <instance event>* {<instance end statement | ...}<br />
<instance head statement> :== 'instance' [<instance kind>] ... <end><br />
<instance end statement> :== 'endinstancd' <end><br />
<br />
where:<br />
*<instance kind> is name of class<br />
*<end> is a optional comment followed for ';'<br />
<br />
with this grammar is not allowed obtain "Event oriented textual syntax" examples showed in the same recommendation. This are one of the examples:<br />
...<br />
Initiator: instance process ISAP_Manager_Ini;<br />
Responder: instance;<br />
all: condition when Disconnected;<br />
Initiator: in ICONreq from env;<br />
out ICON to Responder;<br />
Responder: in ICON from Initiator;<br />
out ICONind to env;<br />
condition wait;<br />
endinstance;<br />
Initiator: action 'setting_counter';<br />
starttimer T (5);<br />
condition wait;<br />
timeout T;<br />
out IDISind to env;<br />
condition disconnected;<br />
endinstance;<br />
endmsc;<br />
<br />
And other mistake is describe events of no name instances. It is possible using the rule <instance decl statement>. Example:<br />
<br />
instance;<br />
out msg_1 to inst_2;<br />
in msg_2 from inst_3;<br />
endinstance<br />
<br />
For this reasons I decide to develop the parser using this grammar:<br />
<><br />
<br />
== Lexer ==<br />
=== Keywords admited ===<br />
* '''from'''<br />
* '''in'''<br />
* '''instance'''<br />
* '''msc'''<br />
* '''mscdocument'''<br />
* '''out'''<br />
* '''to'''<br />
<br />
== Parser ==<br />
The MscParser is a class that defined a [http://www.dabeaz.com/ply/ Python Lex-Yacc (PLY)] parser for MSC Grammar.To use this class is necessary to have installed PLY package.<br />
<br />
When the MscParser object is created, you can pass all the options that is allowed to yacc.yacc method in PLY. The one options that can't be passed are "tabmodule=".<br />
<br />
The parser generate a mscparsetab.py module the first time that instance of class is created, It is for efficiency. To prevent MscParser from generating any kind of parser table file, use: "write_tables=0" as parameter in the object constructor.<br />
<br />
To parser a file you must call "parse" method with the file path as argument. This function return a '''MscDocument''' object. It is a root node AST Tree of mscCore objects.<br />
<br />
=== Use the parser ===<br />
<br />
Example of use:<br />
import sys<br />
import mscParser<br />
if __name__ == '__main__':<br />
fileRead = open(sys.argv[1])<br />
parser = mscParser.MscParser()<br />
ast = parser.parse(fileRead.read())<br />
#Print the Msc Objects Tree<br />
ast.show()<br />
= Design =<br />
The Msc Data are stored in hierarchical tree of Msc Core Objects. <br />
<br />
== Msc Core Items ==<br />
Msc Core Items are the principal data objects. All the libraries (export to msc, import from textual file..) and almost widgets created for the application works using msc core data objects. <br />
<br />
mscCore is the principal package of classes. All elements of this package subclass MscElement, it is a subclass of QOBject and allow Signals. One of the most important signals are 'dataHasChanged' and 'deleted'. <br />
<br />
dataHasChanged signal must be emmited when data included into the subclassing class is changed. This allow other class, like MscGraphItems associated, knows that internal data from msc element has changed and it can be updated readind the new data.<br />
<br />
'deleted' signal is emmited before the object will be deleted, and allow to update the internal structures of other objects that contain references to this object, and remove these and disconnect the signal associated before the element will be destroyed.<br />
<br />
== MSC Graphical Items ==<br />
Are wrappers of Msc Core Items. Each Msc Graphical Item has asociation 1 to 1 of Msc Core Objects. The Msc Graphical Items are only a graphical wrapper of Msc Core Objects, in this way the Msc core Items can be showed. This class inherited from QGraphicsItem so it can be showed in standard QGraphicsView.<br />
<br />
=== MscGraphItem Class ===<br />
The class MscGraphItem is the base class for all of elements that can be drawed in the Taste Msc Editor. It is a subclass of <br />
QGraphicObject, but it can be showed in standard QGraphicsScene.<br />
<br />
The MscGraphItem are developed to have a 1 to 1 relation with MscCore objects, It provide a methods to set and get the MscCore data object associated with the graphical object. The objective of this design is make MscGraphItems like wrappers of MscCore Object Data.<br />
This methods are:<br />
* mscData()<br />
* setMscData()<br />
<br />
In this way when data (no graphical: name, kind, order) of MscGraphItem is changed inside the scene using keyboard and mouse the pourpuse is to make the change into MscCoreClass associated and when change is produced, the MscCore class emit DataChange signal and then graphical object receive the signal and read the data of associated object and update showed.<br />
<br />
MscGraphItem reimplement boundingRect(), contextMenu() functions.<br />
<br />
It has a flag "resizable" than can be set with setResizable(value) function. When the class is set as resizable and it is selected then four grabbers are drawed in the corners around the element. This grabbers allow change the size of the element.<br />
<br />
To know the correct position of corners and bounding rect of the MscGraphItem subclass variables x, y, width and height must be set correctly in all moment. This variables x,y represent the local coordinates of the paint start, and width and height represents the width and height of rect than contains all the elements paints.<br />
<br />
To have new MscGraphItem only need to reimplement the paint() function. If the object is resizable then resizeItem() must be override.<br />
<br />
=== Create new MSC Graphical Item ===<br />
This is a example of creation new graphical element based in MscGraphItem. In this case the new element is the timer graphics.<br />
<br />
The first is to create new class, we will named "MscTimer", in first this is not resizable but we do not implement resizeItem() function.<br />
<br />
With this code you have a graphical object for Timer, and is correct implementetion of MscGraphItem:<br />
<syntaxhighlight lang="python"> <br />
class MscGraphTimer(MscGraphItem):<br />
'''<br />
Class that draws a Timer simbol of MSC Standard<br />
'''<br />
TimerWidth = 15<br />
TimerLine = 40<br />
<br />
def __init__(self, data=None, parent=None):<br />
"""<br />
Initialize<br />
"""<br />
super(MscGraphTimer, self).__init__(parent)<br />
<br />
# Create Path<br />
self.createPath()<br />
self.setFlag(super(MscGraphTimer, self).ItemIsMovable, True)<br />
<br />
<br />
<br />
#**************************************************************************<br />
# Paint Functions<br />
#**************************************************************************<br />
def updateBounding(self):<br />
u"""<br />
Update internal drawing coordinates<br />
"""<br />
self.prepareGeometryChange()<br />
rect = self.path.boundingRect()<br />
self.drawOriginX = rect.x()<br />
self.drawOriginY = rect.y()<br />
self.width = rect.width()<br />
self.height = rect.height()<br />
<br />
def createPath(self):<br />
u"""<br />
Create the path of Timer<br />
"""<br />
# To rotate 180<br />
matrix = QMatrix()<br />
matrix.rotate(180)<br />
# Triangle of timer<br />
triangle = QPainterPath()<br />
triangle.lineTo(-self.TimerWidth / 2, -self.TimerWidth / 2)<br />
triangle.lineTo(self.TimerWidth / 2, -self.TimerWidth / 2)<br />
triangle.closeSubpath()<br />
<br />
# Second triangle, rotate 180 the first triangle<br />
triangle2 = QPainterPath(matrix.map(triangle))<br />
<br />
self.path = QPainterPath()<br />
self.path.lineTo(self.TimerLine, 0)<br />
triangle.translate(self.TimerLine, 0)<br />
triangle2.translate(self.TimerLine, 0)<br />
self.path.addPath(triangle)<br />
self.path.addPath(triangle2)<br />
<br />
# Set correct values of x, y, width and height<br />
self.updateBounding()<br />
<br />
def paint(self, painter, option, widget):<br />
painter.setPen(self.pen)<br />
painter.drawPath(self.path)<br />
</syntaxhighlight><br />
<br />
Now, we must add funcionality to the class. One important graphical funcionality is than it only can move in Y axis and it can't be positioning out of his parent. For this pourpose the parent must be a MscGraphical class that admit events, because of if offer UpperLimitInstance(), BottomLimitInstance() functions that return the limits betwen events can be.</div>Maxime-esa