Howto programmatically create Constraint object and add them in melodymodeller model

Hello,

I have to create programmatically a list of Constraint to place in ModelRoot element but I can’t figure out how to create an instance of Constraint object. Is there a factory object to use ?

Thanks,

Gilles

Found,

I’m missing the org.polarsys.capella.common.data.core.gen plugin in dependencies providing CapellacoreFactory

then create constraint instance by using :
CapellacoreFactory capellaCoreFactory = CapellacoreFactoryImpl.init();
Constraint aConstraint = capellaCoreFactory.createConstraint();

1 Like

It depends on how you use the Factory,
but you can probably use CapellacoreFactory.eInstance.createConstraint(); rather than creating a new one.

Once you attached it to an element,
((CapellaElement) parent).getOwnedConstraints().add(aConstraint);

you can also call CapellaElementExt.creationService(aConstraint); from ( org.polarsys.capella.core.model.helpers.CapellaElementExt ) to create automatically the OpaqueExpression that is created when you create a constraint using the tools.

You can add dependency to org.polarsys.capella.core.model.helpers and org.polarsys.capella.core.model.handler to have some helpers.

1 Like