Book a Demo

Author Topic: Inheritance in a custom Code Template  (Read 3785 times)

Rogier van Stapele

  • EA Novice
  • *
  • Posts: 11
  • Karma: +0/-0
    • View Profile
Inheritance in a custom Code Template
« on: October 29, 2006, 06:00:45 am »
I am working on a custom code template to create class definitions in IEC61131-3 (PLC code).
This language does not offer inheritance so I have to define all inherited attributes and operations in the class definition.

How can I do this? How can I get the template to process all inherited Attributes and Operations? ???
« Last Edit: October 29, 2006, 06:20:02 am by R_van_Stapele »

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: Inheritance in a custom Code Template
« Reply #1 on: October 29, 2006, 01:26:06 pm »
Code Generation Templates don't directly support getting the the attributes and operations defined by parent classes.  However if you want them you can access them using the EXEC_ADD_IN call from the templates.

C# method
Code: [Select]
// sample EXEC_ADD_IN call
public object MyAddInFunction(EA.Repository repository, object argsObject)
{
string[] args = (string[])argsObject;
return "";
}

Template
Code: [Select]
%EXEC_ADD_IN ("MyAddin", "MyAddInFunction", classGUID)%

You'll want to look at the Element.AttributesEx and Element.MethodsEx properties.

Hope that gets you going.

Rogier van Stapele

  • EA Novice
  • *
  • Posts: 11
  • Karma: +0/-0
    • View Profile
Re: Inheritance in a custom Code Template
« Reply #2 on: October 29, 2006, 01:59:40 pm »
I see what you mean.  

Does the attributesEx collection also contain the linked attributes? If not, where can I find those?

Maybe the easiest way for me is to do the whole code generation in a special add-in? With the classGuid i can obtain all the information I need to build and return the class definition as one long string.

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: Inheritance in a custom Code Template
« Reply #3 on: October 29, 2006, 02:08:03 pm »
No it doesn't.  To get to them you'll need to look at the Element.Connectors property for all associations or aggregations and look at the relevant ConnectorEnd.

If your target language is too different from what EA expects to be generating then the advantage of use the code templates will be much less and it may be worth not using them.  It's a bit hard for me to say.

Rogier van Stapele

  • EA Novice
  • *
  • Posts: 11
  • Karma: +0/-0
    • View Profile
Re: Inheritance in a custom Code Template
« Reply #4 on: October 29, 2006, 02:17:20 pm »
The syntax of PLC programs is indeed very different from the OO languages that are defined with EA. But with some tricks a method of code generation can be defined.

I think I see light at the end of the tunnel.  ;D

Thankx for helping me out.