Hello,
I have a question regarding a small test model I created to check whether an element can be retrieved using a calculation.
The calculation logic appears to work in another tool, where it returns the expected model element(s). However, when I evaluate the same calculation using Syside Automator, no element is returned.
As a comparison, I also tested a simple dummy calculation that returns a literal value. That calculation produced the expected output in Syside Automator.
My Model:
package Test{
part def A;
connection def B {
end part [1] :A;
end part [1] : A;
connectedTo :SysML::PartUsage = ConTo(Metaobjects::Metaobject::self meta SysML::ConnectionUsage);
attribute conTest = ConTest(Metaobjects::Metaobject::self meta SysML::ConnectionUsage);
}
part d :A{
part a:A;
part b:A;
part c:A;
connection b1 : B connect a to b{
:>>connectedTo;
attribute :>>conTest;
}
connection b2 : B connect b to c{
:>>connectedTo;
}
connection b3: B connect c to a{
:>>connectedTo;
}
}
calc ConFrom {
in scope : SysML::ConnectionUsage;
scope.sourceFeature.featureTarget.? {
in x;
x hastype SysML::PartUsage
}
}
calc ConTo {
in scope : SysML::ConnectionUsage;
scope.targetFeature.featureTarget.? {in x;x hastype SysML::PartUsage}
//.targetFeature.featureTarget.featureTarget.? {in x;x hastype SysML::PartUsage}
}
calc ConTest {
in scope : SysML::ConnectionUsage;
42
}
}
My automator code:
#for getting the result of connectedTo
from pathlib import Path
import syside
model, diagnostics = syside.load_model(
paths=[Path("Test.sysml")]
)
# Print model diagnostics correctly
for diagnostic in diagnostics.all:
print(diagnostic)
# Find Test::d::b1
b1 = next(
element
for element in model.nodes(syside.ConnectionUsage)
if element.name == "b1"
)
print("Found:", b1.name)
# Find B::connectedTo
connected_to = None
for reference in model.nodes(syside.ReferenceUsage):
owner = reference.owner
if (
reference.name == "connectedTo"
and owner is not None
and owner.name == "B"
):
connected_to = reference
break
if connected_to is None:
raise RuntimeError(
"Could not find B::connectedTo"
)
# Get the expression ConTo(...)
expression = connected_to.feature_value_expression
print("Expression:", expression)
if expression is None:
print("No expression found on B::connectedTo")
else:
value, report = syside.Compiler().evaluate(
expression,
scope=b1,
)
if report.fatal:
print("Calculation evaluation failed:")
for diagnostic in report.diagnostics:
print(diagnostic)
else:
print("Calculation evaluation succeeded")
print("connectedTo for b1:", value)
#for getting the result of conTest
from pathlib import Path
import syside
model, diagnostics = syside.load_model(
paths=[Path("test.sysml")]
)
# Print model diagnostics correctly
for diagnostic in diagnostics.all:
print(diagnostic)
# Find Test::d::b1
b1 = next(
element
for element in model.nodes(syside.ConnectionUsage)
if element.name == "b1"
)
print("Found:", b1.name)
# Find B::conTest
connected_to = None
for attribute in model.nodes(syside.AttributeUsage):
owner = attribute.owner
if (
attribute.name == "conTest"
and owner is not None
and owner.name == "B"
):
connected_to = attribute
break
if connected_to is None:
raise RuntimeError(
"Could not find B::conTest"
)
# Get the expression ConTest(...)
expression = connected_to.feature_value_expression
print("Expression:", expression)
if expression is None:
print("No expression found on B::conTest")
else:
value, report = syside.Compiler().evaluate(
expression,
scope=b1,
)
if report.fatal:
print("Calculation evaluation failed:")
for diagnostic in report.diagnostics:
print(diagnostic)
else:
print("Calculation evaluation succeeded")
print("conTest for b1:", value)
The result I got when I ran the automator :
Found: b1
Expression: Test::b::connectedTo::(anonymous InvocationExpression)
Calculation evaluation failed:
:34:9: error (unsupported-type): SelectExpression compilation is not supported // When I tried to get the value inside the reference usage connectedTo
Found: b1
Expression: Test::b::conTest::(anonymous InvocationExpression)
Calculation evaluation succeeded
conTest for b1: 42 //When I tried to get the value of the attribute usage conTest
Could someone please clarify whether this could be a current limitation of Syside Automator’s calculation/expression evaluation, or whether there may be an issue with my modeling or evaluation approach?
Thank you very much for your help.
Best regards,
AK