0

无法从模型中获取需求。我试过 getAppliedStereotypes() 但它仍然不起作用。代码如下:

 [comment encoding = UTF-8 /]
[module maintest('http://www.eclipse.org/papyrus/sysml/1.4/SysML',
 'http://www.eclipse.org/papyrus/sysml/1.4/SysML/Activities',
'http://www.eclipse.org/papyrus/sysml/1.4/SysML/Requirements', 
'http://www.eclipse.org/uml2/5.0.0/UML')/]

[template public maintestClass(aPackage : Package)]
 [comment @main /]
[file ((aPackage.name+'.m'), false, 'UTF-8')]
0000
 [for (r : Requirements::Requirement| aPackage.packagedElement->filter(Requirements::Requirement))]
11111   
 [/for]
[/file]
[/template]

另外,从这个页面http://techqa.info/programming/question/35093700/cannot-access-sysml-stereotypes-and-their-properties-in-acceleo,我可以通过 generate(re : Requirements:: Requirement)但它不能满足需要,因为我必须将模型中的一些节点值放到文档中,但是这个模板无法获取模型信息。或者也许有任何关于在模型中获取节点信息的解决方案,这些信息只得到需求?

4

1 回答 1

0

我有一个非常相似的问题,为了解决这个问题,我在这里提出了这个问题,我现在相信已经找到了答案。我运行了我的 SysML 模型的类并确定它们是块还是需求。根据我调用不同的导入模板:

[comment encoding = UTF-8 /]
[module main('http://www.eclipse.org/papyrus/sysml/1.4/SysML', 'http://www.eclipse.org/uml2/5.0.0/UML')]

[import MULTIC_TOOLING_GenSystemC::files::modRequirement /]
[import MULTIC_TOOLING_GenSystemC::files::modBlock /]

[template public mainTemplate(aClass : Class)]

    [comment @main/]
    [if (aClass.getAppliedStereotype('SysML::Blocks::Block')->notEmpty())]
        [let aBlock : Block = aClass.getStereotypeApplication(aClass.getAppliedStereotype('SysML::Blocks::Block'))]
        [tempBlock(aBlock)/]
        [/let]
    [/if]
    [if (aClass.getAppliedStereotype('SysML::Requirements::Requirement')->notEmpty())]
        [let aRequirement : Requirement = aClass.getStereotypeApplication(aClass.getAppliedStereotype('SysML::Requirements::Requirement'))]
            [tempRequirement(aRequirement)/]
        [/let]
    [/if]

[/template]
于 2018-01-31T16:28:51.303 回答