How to conditionally connect components

0 votes
asked Oct 22, 2018 in Question / help by mgrol (2,760 points)


I have the following problem:

I want to connect components in a system overview. I defined macros analog to service calls that need to be implemented to call a certain funcionality. this works pretty well. However, I'd like to have only 1 connection instead of two when I call a service and the connection already exists.

The first solution results in this:

My first idea was to wrap the line that links the CALLER and CALLEE into an if statement that checks whether or not a connection was created already. However, this doesn't work and the it results into the same image above.

Btw. Here is the new source code, if you want to try it:

Summarizing: The preprocessor works at load-time but I need a solution at runtime, otherwise pictures get crowded by lines, which defeats the purpose.



1 Answer

0 votes
answered Oct 24, 2018 by plantuml (201,280 points)

Maybe it's time to add some real variable management inside PlantUML:

$i = 0
Alice -> Bob : The value of "i" is ${i}
'It prints: The value of "i" is 0
$i = $i+1
Alice -> Bob : The value of "i" is now ${i}
'It prints: The value of "i" is now 1
$if ( i > 0)
Alice -> Bob : this is printed because i value is ${i}
$for (i=0; i<10; i++)
Alice -> Bob : in the for loop, "i" value is ${i}

This would not be preprocessed (like in the current preprocessor) but executed dynamically.
This is probably over-engineering but I am sure that people would be very creative with this feature :-)

In the meantime, with last beta , you can have:

!definelong connect(CALLER)
        component "CALLEE" as callee
        CALLER -[single]-> callee

component test1
component test2

[single] means that you can only have a single link between element.
Sounds good ?

commented Oct 25, 2018 by albert (3,230 points)
Regarding the variable management, some first thoughts  (probably needs a separate issue),
- when declaring a variable and initializing a variable you use $i
- in a "mathematical" operation you use $i = $i + 1
- in strings you reference the value as ${i}
- in if statement you use $if ( i > 0)
- in for statement you use $for (i=0; i<10; i++) .. $endfor
I think this is a bit inconsistent.
- The ${i} in the string I understand as it is to distinguish between the text $i and the value of the value of the variable i. I'm not sure but probably something could also be accomplished by means of an escape character like a backslash (but compatibility with older versions ...)
- regarding the use in if / for I think here $i should be used and not just i

Are there any thought behind this regarding when to use $i, ${i} and just i?
commented Oct 25, 2018 by mgrol (2,760 points)
[single] sounds good to me. I tried it in my umls and it looks way more tidy.
A side remark: Currently I have the feeling that the generation if the images takes longer than usual. I didn't analyze it yet.

As for the variable management, a separate ticket would be good. I think looking into existing solutions such as C or BASH could help to figure out a proper and consistent way. Better taking more time than to little with this. ...and yes I think the new variable management would be handy and I would like it as well. Just, think about whether or not you want to go this way.
commented Oct 25, 2018 by plantuml (201,280 points)
A new page is available to discuss about this.
This time, we are going to write specification of what we want before coding it :-)
We need indeed a proper and consistent way.
Thanks for your contributions!