基于MoinMoin+ConTeXt实现包含数学内容的Wiki网站
使用ImageMagick将pdf矢量图形转换为png图片

使用ConTeXt绘制程序流程图

LiYanrui posted @ 2008年2月02日 08:16 in ConTeXt之旅 with tags ConTeXt 流程图 FlowChart , 11121 阅读

流程图这种东西貌似已经过时了,《人月神话》中直陈“流程图是被吹捧得过分的一种程序文档……很多程序甚至不需要流程图,很少有程序需要一页纸以上的流图”,因为早期引入流程图的时代是机器语言/汇编语言编程时代,那时是将程序流程图作为描述程序结构的一种逻辑语言使用的,但现在使用高级编程语言(伪代码)可以取而代之,所以在“现实中,流程图被鼓吹的程度远大于它们的实际作用”。

如果只是针对编写程序而言,我赞同《人月神话》的观点。不过,对于程序之外的事务流程描述,在不具备相应的逻辑语言时,流程图依然是一种直观的事务流程描述方式。

用于绘制流程图的工具通常是一些交互式绘图工具,譬如在 Windows 平台下,有 MS Office 软件内含的流程图绘制工具,比较专业一点的是 Viso;Linux 下比较有名的是 Dia(也可在 Windows 下运行)。这些软件没什么好说的,鼠标拖拖拽拽制造一些图框,然后在其中填上一些文本即可。

有一些矢量图形描述语言也可用于流程图绘制,譬如 MetaPost、PGF/TikZ、Asymptote 等,LaTeX 也有一些绘图宏包。ConTeXt 提供了一个 chart 模块,它封装了一些 MetaPost 绘图语句,为流程图绘制提供了友好的支持,这也是本文所讲述的主要内容。

一份 ConTeXt 绘制的流程图示例

下面的框图用于描述 CAPP 系统元素及工作流程,本文以此为例讲述 ConTeXt 的 chart 模块的用法。

所用完整代码如下:

\enableregime[utf]
\usemodule[chinese]
\usemodule[chart]
\setuppagenumbering[state=no]

\starttext

\setupFLOWcharts[
    % option=test, % 测试模式
    nx=5,
    ny=4,
    dx=1.2\bodyfontsize,
    dy=1.2\bodyfontsize,
    width=8\bodyfontsize,
    height=5\bodyfontsize,
    maxwidth=\textwidth]

\startFLOWchart [capp]
    \startFLOWcell
        \name{partFiles}
        \location{1,1}
        \shape{34}
        \text{零件族文件}
        \connection[bt]{partSearch}
    \stopFLOWcell
    \startFLOWcell
        \name{processFiles}
        \location{3,1}
        \shape{34}
        \text{标准工艺文件}
        \connection[bt]{processExtract}
    \stopFLOWcell
    \startFLOWcell
        \name{ruleFiles}
        \location{4,1}
        \shape{34}
        \text{操作规程文件}
        \connection[bt]{ruleExtract}
    \stopFLOWcell
    \startFLOWcell
        \name{applicationFiles}
        \location{5,1}
        \shape{34}
        \text{应用文件}
        \connection[bt]{workcellProcessor}
    \stopFLOWcell
    \startFLOWcell
        \name{partSearch}
        \location{1,2}
        \shape{action}
        \text{零件族检索}
        \connection[rl]{titleInput}
    \stopFLOWcell
    \startFLOWcell
        \name{titleInput}
        \location{2,2}
        \shape{action}
        \text{文件标题输入}
        \connection[rl]{processExtract}
    \stopFLOWcell
    \startFLOWcell
        \name{processExtract}
        \location{3,2}
        \shape{action}
        \text{标准文件工艺文件提取}
        \connection[rl]{ruleExtract}
    \stopFLOWcell
    \startFLOWcell
        \name{ruleExtract}
        \location{4,2}
        \shape{action}
        \text{操作规程提取、编辑}
        \connection[rl]{workcellProcessor}
        \connection[bt]{processStorage}
    \stopFLOWcell
    \startFLOWcell
        \name{workcellProcessor}
        \location{5,2}
        \shape{action}
        \text{工作单元处理器}
        \connection[br]{processStorage}
    \stopFLOWcell
    \startFLOWcell
        \name{partCategoryCode}
        \location{1,3}
        \shape{procedure}
        \text{零件分类编码}
        \connection[tb]{partSearch}
    \stopFLOWcell
    \startFLOWcell
        \name{processPlan}
        \location{2,4}
        \shape{multidocument}
        \text{工艺规划}
    \stopFLOWcell
    \startFLOWcell
        \name{processCreate}
        \location{3,4}
        \shape{action}
        \text{工艺规划生成}
        \connection[lr]{processPlan}
    \stopFLOWcell
    \startFLOWcell
        \name{processStorage}
        \location{4,4}
        \shape{34}
        \text{工艺规划存储}
        \connection[lr]{processCreate}
    \stopFLOWcell
\stopFLOWchart

\midaligned{\FLOWchart[capp]}

\stoptext

如何使用 ConTeXt 绘制流程图

结合上一小节提供的示例,阅读 CHARTS uncoverd 文档。在对 ConTeXt 流程图绘制过程有所了解后,可利用 http://www.im.ps.pl/context/?en 提供的在线创建流程图功能快速生成 ConTeXt 代码。


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter