Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Expressions and GraphRep
interref graphrep adoscript expression
Answer
6/18/19 10:42 AM
I have a little bit of a difficulty understanding how expressions work.

I have an attribute of a class called "Arguments" of type INTERREF and the max refs are set to 5. On the GraphRep of the class I want to display different results depending on the number of refs (with the "AfterEditAttributeValue" event).
Can I achieve that directly into the GraphRep or do I need to define an expression attribute that takes a number from 1 to 5 depending on the refs? And how do I do that?

Thank you in advance!

RE: Expressions and GraphRep
Answer
6/11/19 1:21 PM as a reply to Nena Basina.
Hi Nena,
in case you want to visualize things from the INTERREFs, you can do that directly in the GRAPHREP. The ATTR attribute (also available in the documentation page here: https://www.adoxx.org/live/adoxx-notation-language-graphrep ) allows you to format things and perform required iterations. Expressions (as documented in here: https://www.adoxx.org/live/expressions) are supported in GRAPHREP directly. The examples can be used as an "inspiration" how things can be done.

Example A: Formatting INTERREFs in GRAPHREP
Let an ATTR element contain
1format:"%o (%c) @ %m (%t)"
For a reference to a modeling object "Zappa" of class "Host" in a model "1st floor" of model type "Local area" the resulting output would be
1Zappa (Host) @ 1st floor (Local area)

The following format syntax is supported:
%m ... the name (basename with version) of the referenced model,
%M ... the basename of the referenced model (if versioning is active),
%v ... the short version number of the referenced model (if versioning is active),
%V ... the long version number of the referenced model (if versioning is active),
%t ... the model type name of the referenced model,
%o ... the name of the referenced object (just for object references),
%c ... the class name of the referenced object (just for object references).

Example B: Multiple INTERREFs in GRAPHREP with separator
Let "Referenced models" be a multi-reference INTERREF attribute. The following displays all names of the referenced models separated by commas:
1ATTR "Referenced mdels" format:"%m" sep:", "

By default, multiple references are displayed using one line per reference (at least if there is no reference taking more than one line). That means the default for sep is "\r\n". (The \r character has no effect here and has just been retained for historical reasons.) By setting the sep string multiple references can, for example, be displayed in one line, keeping the hyperlink functionality working.

Example C: Alternative text for Single References
Let "Referenced document" be a single-reference INTERREF attribute. For that, we want just a fixed text "" being displayed as hyperlink:
1ATTR "Referenced document" text:"[refdoc]"

Specifying text at an ATTR element allows that instead of the attribute value any text can be displayed, while the text area is still working as click region for the referenced attribute. For a single-reference attribute, that means that any text can be displayed as hyperlink, being linked with the referenced model or object.

Example D: Using AVAL and ATTR/text for a single-reference INTERREF attribute

Let "Referenced document" be a single-reference INTERREF attribute. We want at most ten characters of the referenced object's name to be displayed. At first the name of the referenced object are read into a string variable using AVAL. Then the string value is truncated if it is too long. The result is used as replacement for the value which would normally be displayed by ATTR:
1AVAL set-format:"%o" ref:"Referenced document"
2SET ref: (cond(LEN ref <= 10, ref, copy(ref, 0, 10))
3ATTR "Referenced document" text: (ref)

If you want the displayed text being computed from the original attribute value, you need an AVAL ement. The AVAL element writes the value of a certain attribute into a runtime variable. The format for an INTERREF attribute can be specified with set-format. Note that it is important to write set-format before the assigned variable. The read attribute value can be used to compute the value being displayed by ATTR/text.

Example E: Using AVAL and ATTR/text for a multi-reference INTERREF attribute

Let "Referenced documents" be a multi-reference INTERREF attribute. We want at most ten characters of each referenced object's name to be displayed. The displayed references shall put in one line, separated by colons.
 1AVAL set-format:"%o" set-sep:":" ref:"Referenced documents"
 2SET ref: (
 3    set(r, ""),
 4    fortok(t, ref, ":", (
 5        set(r, cond(LEN r, r + ":", "") +
 6                 cond(LEN t <= 10, t, copy(t, 0, 10)))
 7    )),
 8    r)
 9ATTR "Referenced documents" text: (ref) format:"%o" sep:":"

At first, the names of the referenced objects are read into a string variable using AVAL. AVAL computes a string value for each reference and concatenates them using a specified string or newline as separator. Here, we specify set-sep:":".At next, each reference's text is truncated to a maximum length of 10 using a fortok expression.The computed text is displayed using ATTR with text. As explained above, it is important to specify format and sep here.

For multiple references it is not a priori determinable which part of the text value belongs to which reference. The specified text may contain anything. So the hyperlink mechanism does not work here without a little help of the customizer. Although the text is already given, the ATTR element needs a sep and a format specification here. The sep string must be the separator which is used in the text value. The format string must be in a way, that the produced order of references is the same as the order in the text value. Otherwise following a hyperlink could lead to a wrong destination. Probably the text value has been produced from a string which comes from an AVAL element. So the format value of the ATTR element has to be the same as the set-format value of the AVAL element