Integrations (PTC products, 3rd party products and code) > Code integration (Ada, ARINC 653, C, C#, C++, IDL, Java, SQL and VB) > Transformation Development Kit (TDK) > Customizing an ACS Code Generator DLL > Customizing a TDK code generation transformation patterns model - current TDK models > How TDK code generation transformation patterns models define code generation > Definition of how code is generated - 4G generation classes (TDK)
  
Definition of how code is generated - 4G generation classes (TDK)
In the TDK Code Generation Transformation Patterns model, the definition of how code is generated is achieved through 4G Generation Classes - a 4G Generation Class is a Class that is stereotyped by the 4GGen stereotype. The supplied 4G Generation Classes reside in the Generator::Model2Text package and their names all start with Q, such as QClass. On Class Diagrams, these Classes appear yellow.
Mapping 4G generation classes to a 4G meta class
There can be many 4G Generation Classes that define code generation for a Modeler item type, but only one 4G Generation Class can be used each time code is generated for an item. The Mapping diagram in the Generator::Structure package shows which 4G Generation Classes apply to each Modeler item type, for example:
Evaluation order
To determine which 4G Generation Class is used to generate code for an item, all 4G Generation Classes that define code generation for the same Modeler item type must be linked to each other through Dependencies of type Dependency that are stereotyped by the GW EvalOrderstereotype. These links set up a chain of responsibility in which each 4G Generation Class candidate is assessed to see if it should be used to generate code. You can see the chain of responsibility for the provided 4G Generation Classes on the Class Diagrams contained in the Model2Text::Diagrams package.
Each 4G Generation Class can only be in one evaluation order, that is, a 4G Generation Class cannot have more than one incoming EvalOrder Dependency or more than one outgoing EvalOrder Dependency.
Attach point 4G generation classes
Typically the first 4G Generation Class in an evaluation order is an Attach Point 4G Generation Class - if you want to add your own 4G Generation Classes, you can add those 4G Generation Classes before the appropriate Attach Point 4G Generation Class in the evaluation order.
The Attach Point 4G Generation Classes do not define any code generation and they reside in the Generator::Model2Text::CustomizationAttachPoints package. There are Attach Point 4G Generation Classes for generating code from the Model, Packages, Classes, Attributes, Operations, Roles, Type Definitions and Parameters.
If you add new 4G Generation Classes before the provided Attach Point 4G Generation Classes in the chain of responsibility, after upgrading the provided TDK Code Generation Transformation Patterns model with future updates from PTC your customizations will continue to work.
When operations
Each 4G Generation Class has a When operation that determines whether that Class should be used to generate code:
If the When operation returns 1, that 4G Generation Class is used to generate code and other candidates in the chain of responsibility are not considered.
If the When operation returns 0, the 4G Generation Class is not used to generate code and the next candidate in the chain of responsibility is considered.
The When operation must be set up as follows:
The When operation must have an in Parameter named O. The Data Type of the O parameter must be set to the %object basic type and its Mechanism must be set to In.
The Data Usage of the When operation must be set to On Class.
The Return Type of the When operation must be set to the %numeric basic type.
The Body property of the When operation contains SDL script that determines whether that 4G Generation Class should be used to generate code. The Modeler item is passed to the When operation by means of its O:%object parameter.
The Data Usage of the When operation must be set to On Class.
* 
The final 4G Generation Class in a chain of responsibility must return 1, so its Body property should be set to %return 1.
Rules and operations
A 4G Generation Class typically has a number of Rules and Operations that define how code is generated. Rules are defined in the Rule Text property of a 4G Generation Class. The Rule Text property appears on the Text tab of the 4GGeneration Class Property Pages.
Each Rule has a name, followed by ->, followed by the rule text. The Rule text is written in Backus-Naur form (BNF) like notation and it specifies how code is generated for the item type.
Each Operation has SDL script that is specified in the Operation's Body property.
A 4G Generation Class can also use Rules and Operations that are defined on 4G Business Classes, that is, Classes that are stereotyped by the 4GBusiness stereotype. 4G Business Classes store Rules and Operations that can be reused by many 4G Generation Classes.
Rules can call Rules and Operation that are defined on the same Class, and they can also call Rules and Operation on 4G Business Classes and other 4G Generation Classes:
Rules and Operations on 4G Business Classes can be called only if they are linked to the 4G Generation Class through an abstraction Dependency. For more information about 4G Business Classes, see Reuse of rules and operations - 4G business classes (TDK).
Rules and Operations on other 4G Generation Classes can be called only if they are linked to the 4G Generation Class through a Generalization.
The following example shows how Rule text calls Rules and Operations on the same 4G Generation Class and on a linked 4G Business Class.
For more information about the grammar and syntax of Rule text, which is used only by TDK Code Generation Transformation Patterns models, see Working with rule text in TDK code generation transformation patterns models (TDK).
For more information about grammar and syntax of SDL script, which is used by all TDK models, see Overview of SDL script (TDK).