Skip to content

Commit afa248d

Browse files
committed
Extending startuml with extra figure types
Not all diagrams can be created with the PlantUML `@startuml` command but need another PlantUML `@start...` command. This wil look like `@start<engine>` where currently supported are the following `<engine>`'s: `uml`, `bpm`, `wire`, `dot`, `ditaa`, `salt`, `math`, `latex`, `gantt`, `mindmap`, `wbs`, `yaml`, `creole`, `json` and `flow`. By default the `<engine>` is `uml`. The `<engine>` can be specified as an option. Explicitly the option variant has been chosen so we won't get an explosion of extra commands.
1 parent 97415f7 commit afa248d

11 files changed

+95
-18
lines changed

doc/commands.doc

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2907,19 +2907,31 @@ class Receiver
29072907
\sa section \ref cmdmscfile "\\mscfile".
29082908

29092909
<hr>
2910-
\section cmdstartuml \\startuml [{file}] ["caption"] [<sizeindication>=<size>]
2910+
\section cmdstartuml \\startuml ['{'option[,option]'}'] ["caption"] [<sizeindication>=<size>]
29112911

29122912
\addindex \\startuml
2913+
29132914
Starts a text fragment which should contain a valid description of a
29142915
PlantUML diagram. See https://plantuml.com/ for examples.
29152916
The text fragment ends with \ref cmdenduml "\\enduml".
29162917
\note You need to install Java and the PlantUML's jar file,
2917-
if you want to use this command. The location of the jar file should be specified
2918-
using \ref cfg_plantuml_jar_path "PLANTUML_JAR_PATH".
2918+
if you want to use this command. When using PlantUML in \LaTeX you have to download
2919+
some more `jar` files, for details see the PlantUML documentation.
2920+
The location of the jar file should be specified using
2921+
\ref cfg_plantuml_jar_path "PLANTUML_JAR_PATH".
2922+
2923+
Not all diagrams can be created with the PlantUML `@startuml` command but need another
2924+
PlantUML `@start...` command. This wil look like `@start<engine>` where currently supported are
2925+
the following `<engine>`'s: `uml`, `bpm`, `wire`, `dot`, `ditaa`, `salt`, `math`, `latex`,
2926+
`gantt`, `mindmap`, `wbs`, `yaml`, `creole`, `json` and `flow`. By default the `<engine>` is
2927+
`uml`. The `<engine>` can be specified as an option.
2928+
Also the file to write the resulting image to can be specified by means of an option, see the
2929+
description of the first (optional) argument for details.
2930+
Of course only one `<engine>` can be specified and also the filename can only be specified once.
29192931

29202932
The first argument is optional and is for compatibility with running PlantUML as a preprocessing
2921-
step before running doxygen, you can also add the name of the image file after \c \\startuml
2922-
and inside curly brackets, i.e.
2933+
step before running doxygen, you can also add the name of the image file after `\startuml`
2934+
and inside curly brackets as option, i.e.
29232935
\verbatim
29242936
@startuml{myimage.png} "Image Caption" width=5cm
29252937
Alice -> Bob : Hello

src/docbookvisitor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ DB_VIS_C
395395
case DocVerbatim::PlantUML:
396396
{
397397
static QCString docbookOutput = Config_getString(DOCBOOK_OUTPUT);
398-
QCString baseName = PlantumlManager::instance().writePlantUMLSource(docbookOutput,s->exampleFile(),s->text(),PlantumlManager::PUML_BITMAP);
398+
QCString baseName = PlantumlManager::instance().writePlantUMLSource(docbookOutput,s->exampleFile(),s->text(),PlantumlManager::PUML_BITMAP,s->engine());
399399
QCString shortName = baseName;
400400
int i;
401401
if ((i=shortName.findRev('/'))!=-1)

src/docparser.cpp

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ static const char *sectionLevelToName[] =
7979
"subparagraph"
8080
};
8181

82+
static const char *plantumlStart[] = {"uml", "bpm", "wire", "dot", "ditaa",
83+
"salt", "math", "latex", "gantt", "mindmap",
84+
"wbs", "yaml", "creole", "json", "flow" };
8285
//---------------------------------------------------------------------------
8386

8487
//---------------------------------------------------------------------------
@@ -5535,8 +5538,68 @@ int DocPara::handleCommand(const QCString &cmdName, const int tok)
55355538
static QCString jarPath = Config_getString(PLANTUML_JAR_PATH);
55365539
doctokenizerYYsetStatePlantUMLOpt();
55375540
retval = doctokenizerYYlex();
5538-
QCString plantFile(g_token->sectionId);
5541+
5542+
QCString fullMatch = g_token->sectionId;
5543+
QCString sectionId = "";
5544+
int idx = fullMatch.find('{');
5545+
int idxEnd = fullMatch.find("}",idx+1);
5546+
QCString cmdName;
5547+
StringVector optList;
5548+
QCString engine;
5549+
if (idx != -1) // options present
5550+
{
5551+
QCString optStr = fullMatch.mid(idx+1,idxEnd-idx-1).stripWhiteSpace();
5552+
optList = split(optStr.str(),",");
5553+
for (const auto &opt : optList)
5554+
{
5555+
if (opt.empty()) continue;
5556+
bool found = false;
5557+
QCString locOpt = opt;
5558+
locOpt = locOpt.lower();
5559+
for (int i = 0; i < sizeof(plantumlStart) / sizeof(*plantumlStart); i++)
5560+
{
5561+
if (locOpt == plantumlStart[i])
5562+
{
5563+
if (!engine.isEmpty())
5564+
{
5565+
warn(g_fileName,getDoctokinizerLineNr(), "Multiple definition of engine for '\\startuml'");
5566+
}
5567+
engine = plantumlStart[i];
5568+
found = true;
5569+
break;
5570+
}
5571+
}
5572+
if (!found)
5573+
{
5574+
if (sectionId.isEmpty())
5575+
{
5576+
sectionId = opt;
5577+
}
5578+
else
5579+
{
5580+
warn(g_fileName,getDoctokinizerLineNr(),"Multiple use of of filename for '\\startuml'");
5581+
}
5582+
}
5583+
}
5584+
}
5585+
else
5586+
{
5587+
sectionId = g_token->sectionId;
5588+
}
5589+
if (engine.isEmpty()) engine = "uml";
5590+
5591+
if (sectionId.isEmpty())
5592+
{
5593+
doctokenizerYYsetStatePlantUMLOpt();
5594+
retval = doctokenizerYYlex();
5595+
5596+
sectionId = g_token->sectionId;
5597+
sectionId = sectionId.stripWhiteSpace();
5598+
}
5599+
5600+
QCString plantFile(sectionId);
55395601
DocVerbatim *dv = new DocVerbatim(this,g_context,g_token->verb,DocVerbatim::PlantUML,FALSE,plantFile);
5602+
dv->setEngine(engine);
55405603
doctokenizerYYsetStatePara();
55415604
QCString width,height;
55425605
defaultHandleTitleAndSize(CMD_STARTUML,dv,dv->children(),width,height);

src/docparser.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,11 +507,13 @@ class DocVerbatim : public DocNode
507507
bool hasCaption() const { return !m_children.empty(); }
508508
QCString width() const { return m_width; }
509509
QCString height() const { return m_height; }
510+
QCString engine() const { return m_engine; }
510511
const DocNodeList &children() const { return m_children; }
511512
DocNodeList &children() { return m_children; }
512513
void setText(const QCString &t) { m_text=t; }
513514
void setWidth(const QCString &w) { m_width=w; }
514515
void setHeight(const QCString &h) { m_height=h; }
516+
void setEngine(const QCString &e) { m_engine=e; }
515517

516518
private:
517519
QCString m_context;
@@ -524,6 +526,7 @@ class DocVerbatim : public DocNode
524526
bool m_isBlock = false;
525527
QCString m_width;
526528
QCString m_height;
529+
QCString m_engine;
527530
DocNodeList m_children;
528531
};
529532

src/doctokenizer.l

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -964,10 +964,8 @@ RCSID "$"("Author"|"Date"|"Header"|"Id"|"Locker"|"Log"|"Name"|"RCSfile"|"Revisio
964964
lineCount(yytext,yyleng);
965965
g_token->verb+=yytext;
966966
}
967-
<St_PlantUMLOpt>{BLANK}*"{"[^}]*"}" { // case 1: file name is specified as {filename}
967+
<St_PlantUMLOpt>{BLANK}*"{"[a-zA-Z_,:0-9\. ]*"}" { // case 1: options present
968968
g_token->sectionId = QCString(yytext).stripWhiteSpace();
969-
// skip curly brackets around the optional image name
970-
g_token->sectionId = g_token->sectionId.mid(1,g_token->sectionId.length()-2).stripWhiteSpace();
971969
return RetVal_OK;
972970
}
973971
<St_PlantUMLOpt>{BLANK}*{FILEMASK}{BLANK}+/{ID}"=" { // case 2: plain file name specified followed by an attribute

src/htmldocvisitor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,7 @@ void HtmlDocVisitor::visit(DocVerbatim *s)
628628
{
629629
format = PlantumlManager::PUML_SVG;
630630
}
631-
QCString baseName = PlantumlManager::instance().writePlantUMLSource(htmlOutput,s->exampleFile(),s->text(),format);
631+
QCString baseName = PlantumlManager::instance().writePlantUMLSource(htmlOutput,s->exampleFile(),s->text(),format,s->engine());
632632
m_t << "<div class=\"plantumlgraph\">\n";
633633
writePlantUMLFile(baseName,s->relPath(),s->context());
634634
visitPreCaption(m_t, s);

src/latexdocvisitor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ void LatexDocVisitor::visit(DocVerbatim *s)
432432
case DocVerbatim::PlantUML:
433433
{
434434
QCString latexOutput = Config_getString(LATEX_OUTPUT);
435-
QCString baseName = PlantumlManager::instance().writePlantUMLSource(latexOutput,s->exampleFile(),s->text(),PlantumlManager::PUML_EPS);
435+
QCString baseName = PlantumlManager::instance().writePlantUMLSource(latexOutput,s->exampleFile(),s->text(),PlantumlManager::PUML_EPS,s->engine());
436436

437437
writePlantUMLFile(baseName, s);
438438
}

src/plantuml.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#include "debug.h"
2323
#include "fileinfo.h"
2424

25-
QCString PlantumlManager::writePlantUMLSource(const QCString &outDirArg,const QCString &fileName,const QCString &content,OutputFormat format)
25+
QCString PlantumlManager::writePlantUMLSource(const QCString &outDirArg,const QCString &fileName,const QCString &content,OutputFormat format, const QCString &engine)
2626
{
2727
QCString baseName;
2828
QCString puName;
@@ -71,9 +71,9 @@ QCString PlantumlManager::writePlantUMLSource(const QCString &outDirArg,const QC
7171
Debug::print(Debug::Plantuml,0,"*** %s puName: %s\n","writePlantUMLSource",qPrint(puName));
7272
Debug::print(Debug::Plantuml,0,"*** %s imgName: %s\n","writePlantUMLSource",qPrint(imgName));
7373

74-
QCString text = "@startuml "+imgName+"\n";
74+
QCString text = "@start"+engine+" "+imgName+"\n";
7575
text+=content;
76-
text+="\n@enduml\n";
76+
text+="\n@end"+engine+"\n";
7777

7878
QCString qcOutDir(outDir);
7979
uint pos = qcOutDir.findRev("/");

src/plantuml.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,13 @@ class PlantumlManager
5858
* @param[in] format the image format to generate.
5959
* @returns The name of the generated file.
6060
*/
61-
QCString writePlantUMLSource(const QCString &outDir,const QCString &fileName,const QCString &content, OutputFormat format);
61+
QCString writePlantUMLSource(const QCString &outDir,const QCString &fileName,const QCString &content, OutputFormat format, const QCString &engine);
6262

6363
/** Convert a PlantUML file to an image.
6464
* @param[in] baseName the name of the generated file (as returned by writePlantUMLSource())
6565
* @param[in] outDir the directory to write the resulting image into.
6666
* @param[in] format the image format to generate.
67+
* @param[in] engine the plantuml engine to be used so the start command will be `@start<engine>`
6768
*/
6869
void generatePlantUMLOutput(const char *baseName,const char *outDir,OutputFormat format);
6970

src/rtfdocvisitor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ void RTFDocVisitor::visit(DocVerbatim *s)
383383
case DocVerbatim::PlantUML:
384384
{
385385
static QCString rtfOutput = Config_getString(RTF_OUTPUT);
386-
QCString baseName = PlantumlManager::instance().writePlantUMLSource(rtfOutput,s->exampleFile(),s->text(),PlantumlManager::PUML_BITMAP);
386+
QCString baseName = PlantumlManager::instance().writePlantUMLSource(rtfOutput,s->exampleFile(),s->text(),PlantumlManager::PUML_BITMAP,s->engine());
387387

388388
writePlantUMLFile(baseName, s->hasCaption());
389389
visitCaption(this, s->children());

src/vhdldocgen.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3344,7 +3344,7 @@ void FlowChart::printUmlTree()
33443344
QCString htmlOutDir = Config_getString(HTML_OUTPUT);
33453345

33463346
QCString n=convertNameToFileName();
3347-
n=PlantumlManager::instance().writePlantUMLSource(htmlOutDir,n,qcs,PlantumlManager::PUML_SVG);
3347+
n=PlantumlManager::instance().writePlantUMLSource(htmlOutDir,n,qcs,PlantumlManager::PUML_SVG,"uml");
33483348
PlantumlManager::instance().generatePlantUMLOutput(n,htmlOutDir,PlantumlManager::PUML_SVG);
33493349
}
33503350

0 commit comments

Comments
 (0)