yaozhenx / mscgen

Automatically exported from code.google.com/p/mscgen
GNU General Public License v2.0
0 stars 0 forks source link

Enhancement: Allow entities to be created later in a sequence #40

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Often I would like to have a sequence diagram with entities that don't exist at 
the beginning of the sequence. For example, if a process spawns a worker thread 
at some point, it would be nice for the lifeline for that thread to only begin 
at that point.

Ideally to do this we would be able to introduce a new entity at any point in 
the sequence, and conversely destroy an entity. For example:

msc {
    M [label="Main"], P [label="Thread pool"];
    ...;
    M => P [label="requestThread"];
    t [label="worker"];
    P :> t [label="<<create>>"];
    M << P;
    M => t [label="doWork"];
    ...;
    M << t;
    M => P [label="releaseThread"];
    P :> t [label="<<destory>>"];
    ~t;
    M << P;
    ...;
}

Which would generate something like the attached image.

Original issue reported on code.google.com by kbriggs@gmail.com on 22 Jun 2010 at 11:59

Attachments:

GoogleCodeExporter commented 9 years ago
The attached patch takes an initial swing at the first part of this, by 
introducing a "delay" attribute that can be applied to an entity declaration 
which moves the start of the entity down by the specified number of rows. For 
example:

msc {
    M [label="Main"], P [label="Thread pool"], t [label="worker", delay="2"];
    ...;
    M => P [label="requestThread"];
    P :> t [label="<<create>>"];
    M << P;
    M => t [label="doWork"];
    ...;
}

Caveat: this patch just moves the label down by (delay * gOpts.arcSpacing), it 
doesn't take into account extra vertical space needed by multiline arc labels, 
or try to reconcile gOpts.entityHeadGap if the moved label was the limiting 
factor.

I'll keep playing with this as time allows.

Original comment by kbriggs@gmail.com on 23 Jun 2010 at 12:00

Attachments:

GoogleCodeExporter commented 9 years ago
Hi

Personally I like the idea of being able to add / remove entities like that (it 
would also work for "liveness" of an Object in OOP). However, I think the 
"delay" attribute would be a poor way of implementing it; particularly it is 
not auto-updated with changes in the msc code.
  As a user I would definitely prefer an "start here" and a "end here"-like approach like your original proposal. Unfortunately it is probably less trivial than the delay approach.

I wrote a patch that makes mscgen keep track of which entities are visible and 
hides the ones that are not visible. The patch lacks at least a way to 
toggle/change this visibility setting of entities in between the arcs.
  With the patch, the entity is not "targeted" on broadcast arcs if it is hidden, futhermore mscgen will refuse to create an arc from or to a hidden entity. I believe the same holds for boxes (but boxes may span across a hidden entity), but I did not test it.

Attached is a very short demonstration of this with source; again this is not 
very useful until there is way to toggle the visibility.
  My main problem is figuring out the syntax for this as well as creating a fake "arc" to do the toggling work.

~Niels

Original comment by NThykier@gmail.com on 24 Jun 2010 at 8:37

Attachments:

GoogleCodeExporter commented 9 years ago
Yeah, the delay attribute was always a stop-gap until I can work on a better 
solution. In my (quite limited) spare time I'm working on a solution that would 
be closer to the original proposal. It involves fairly extensive changes 
though; basically adding a new kind of arc that is an entity state transition, 
which can create or destroy (or hide or show etc) lifelines. The initial entity 
list line is then no longer special, it's just the first entity state 
transitions into existence...

Original comment by kbriggs@gmail.com on 1 Jul 2010 at 12:08

GoogleCodeExporter commented 9 years ago
I have created a second patch based on my first patch. It takes this concept a 
bit further but it could probably need a little more. It includes a small test 
example. It is now possible to show a hidden entity by doing "+ $entity" and 
hiding by using "- $entity" (see testinput17.msc).

Possible improvements: possibly make show/hide react to attributes (e.g. label) 
like other arcs. Personally I would also like the +t to be on the same line as 
the arc that "(visually) creates" the entity, but I did not have the insight 
and time to code it that way.

Attached is the patch, the new test case[1] and how it looks with the patched 
mscgen from revision 144.

[1] The test is also in the patch, but I attached it separately because it is 
easier to read then.

Original comment by NThykier@gmail.com on 25 Sep 2010 at 3:58

Attachments:

GoogleCodeExporter commented 9 years ago
Probably some improvement is needed in the syntax. It is good to specify who is 
creating/deleting the entity, instead of having an explicit arc to specify the 
same. This will help in improving the drawing as shown in the attached diagram. 
Currently msc can be drawn without the entity box as in the previous diagram 
testinput17.msc.png.

Syntax for this msc might be

msc {
    i, j [dummy];
    i (CREATE) j [label="Create"];
    i (DELETE) j [label="Delete"];
}

Note the brackets around CREATE, DELETE. This is just for the parser to treat 
it as command, instead of entity name. This is because, 'i' is optional in 'i 
(CREATE) j' and it could be simply specified as '(CREATE) j'.

Using '+' symbol to represent creation is fine, just that explicit text is more 
readable in doxygen comment. Also there will be definitely more such commands 
needed in the future and using lots of symbols might make the syntax unreadable.

Instead of brackets (), something else appropriate could be used.

Original comment by arunmozh...@gmail.com on 27 Sep 2010 at 8:29

Attachments: