How to conditionally connect components

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

Hi,

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.

http://www.plantuml.com/plantuml/uml/NL3BJiD03BpxAoOzaKEHw0UWLYK7f9ugxYXA7B2wiL7N4Nm-RXuyufDdPpmpsdts-kf3dwXekHFbPFg6nbIvyRlZuNIgpYKXff1EGuBnhNezdgl3I_L4cAUn_iEKrR6P51lK6KsT4lEFQCvOUS2lmwGfM5lfndMAndRxk9ZSo3yTYNuZdRC_qD9wHEMAtlsZT-KQgZd354dqGi_uj26r0IuCDrWlJlxEo1ndxIY2T0ZxnKVYbhyaUxwdA8gR7-rZYx_z1W00

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: 

http://www.plantuml.com/plantuml/uml/VP3FJiCm3CRlVeflsuKUXiGU06qQFI3jL757LUg2jTH6YojuVB9suqyhy2Ln_DFtKxnDNf-yxo8j6cv5EPg-89Wg1x_Pxmw7iYe8kHRIQaOml9NF-whSFPKFX4i5wzvCMHtBaLYYJWXrZCnVqCKnoO2VUXuTh8sqSrsrMlsX7STOh-__Syq3PixpyMC3HDyVSav-HzUT35qn6Mz-ZJV5j5LpXYcYw94UyMvzR79pPBZ1Ed7oLqRYODeC4AJDF5zpn1Jy8SdJBN56pdcqpRU-Yvy0

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

BR,

Michael

1 Answer

0 votes
answered Oct 24, 2018 by plantuml (294,960 points)

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

@startuml
$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}
$endif
$for (i=0; i<10; i++)
Alice -> Bob : in the for loop, "i" value is ${i}
$endfor
@enduml

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 http://beta.plantuml.net/plantuml.jar , you can have:

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

component test1
connect(test1)
component test2
connect(test2)
connect(test2)
connect(test2)
@enduml

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

commented Oct 25, 2018 by albert (3,520 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 (3,150 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 (294,960 points)
A new page http://wiki.plantuml.net/site/plantumlshell 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!
...