在 doxygen文档中嵌入 sequence diagram (PNG格式)

来源:互联网 发布:知乎穆勒名学 编辑:程序博客网 时间:2024/06/02 14:37

今天,公司的一位牛人说,在 doxygen 中借助于mscgen工具支持在生成的文档中嵌入 sequence diagram.

自己在网上搜了一下,大体上知道了怎么用这个工具了。

1. 下载 mscgen 工具

http://www.mcternan.me.uk/mscgen/yum/fedora/15/i386/mscgen-0.20-1.fc15.i686.rpm

 

yum localinstall /mscgen-0.20-1.fc15.i686.rpm

 

上面的网址(http://www.mcternan.me.uk/mscgen)还介绍了 mscgen的语法。如下所示:

 

 

Graphic Source Representation Meaning Rendered message arc-> or <-MessageRendered function call arc=> or <=Method or function callRendered return value arc>> or <<Method or function return valueRendered callback arc=>> or <<=CallbackRendered double message arc:> or <:Emphasised MessageRendered lost message arc-x or x-Lost MessageRendered discontinuinity...Indicates that some signals may be deliberately omitted from the msc, or that some large period of time may have passed.Rendered block divider---Used to add comment to a block of signals or indicate some action or state has occurred.Rendered spacer|||Used to add extra space between rows.Rendered broadcast arcx->* or *<-xBroadcast arcs, where the arc is extended to all but the source entity. Any arc label is centred across the whole chart.Rendered state boxboxBox arcs, where the arc is replaced with a box between the selected entities. Any arc label is centred in the box and word wrapped if needed.Rendered rounded boxrboxRounded box arcs, where the arc is replaced with a box between the selected entities. Any arc label is centred in the box and word wrapped if needed.Rendered angular boxaboxAngular box arcs, where the arc is replaced with a box between the selected entities. Any arc label is centred in the box and word wrapped if needed.Rendered note boxnoteNote box arcs, where the arc is replaced with a box between the selected entities. Any arc label is centred in the box and word wrapped if needed.

 

ource Attribute Meaning labelA label to place on the message arc, or label to use for an entity. This is reproduced literally above the message arc or in place of the entity name. When used as a message arc label this may also contain parameters or required text. If a /n is encountered, it will be interpreted as a newline, placing text below the arc as well as above it in the normal position, or expanding entity tiles onto more lines.URLWhen generating the image, colour the label in blue. If generating an image map, create an entry for the label to the specified URL. If the message sequence chart is to be embedded in Doxygen documentation, the URL maybe specified as /ref xxx where xxx is the name of some documented element; in this case a link to the element will automatically be made.IDAdds a superscript identifier to the label. Typically this maybe a number such that specific elements can be identified and referred to in surrounding descriptive text.IDURLSimilar to the URL attribute, but links from the ID text rather than the message label. This has the same semantics as the URL attribute, but is only of use if an arc also has an ID.arcskipThis offsets the vertical position at which an arc reaches its destination entity.linecolour, linecolorFor arcs or entities, set the line to the specified colour.textcolour, textcolorFor arcs or entities, set label text to the specified colour.textbgcolour, textbgcolorFor arcs or entities, set a colour for the text background block. Sets the fill colour for 'box', 'abox', 'rbox' and 'note' shapes.arclinecolour, arclinecolorOnly meaningful on a entity, this sets the default line colour for all arcs that originating from that entity. This can be overridden by linecolour attributes on specific arcs as desired.arctextcolour, arctextcolorOnly meaningful on a entity, this sets the default text colour for all arcs that originating from that entity. This can be overridden by textcolour attributes on specific arcs as desired.arctextbgcolour, arctextbgcolorOnly meaningful on a entity, this sets the default colour for the text background for all arc oriniationg from that entity. This can be overridden by textbgcolour attributes on specific arcs as desired.

2. 写一段测试代码如下:

 

/** Sender class. Can be used to send a command to the server.  The receiver will acknowlegde the command by calling Ack().  /msc    Sender,Receiver;    Sender->Receiver [label="Command()", URL="/ref Receiver::Command()"];    Sender<-Receiver [label="Ack()", URL="/ref Ack()", ID="1"];  /endmsc */class Sender{  public:    /** Acknowledgement from server */    void Ack(bool ok);};/** Receiver class. Can be used to receive and execute commands.  After execution of a command, the receiver will send an acknowledgement  /msc    Receiver,Sender;    Receiver<-Sender [label="Command()", URL="/ref Command()"];    Receiver->Sender [label="Ack()", URL="/ref Sender::Ack()", ID="1"];  /endmsc */class Receiver{  public:    /** Executable a command on the server */    void Command(int commandId);};

注意,sequence diagam 部分相应的注释要在 msc block内。

运行 doxgen 后,可以看到确实生成了 sequence diagam: