• No results found

Relationship Diagram

In document IntegrationToolkitProgrammerGuide_V10 (Page 121-130)

Figure 6-1 shows the Teamcenter object model. It demonstrates the relationships among objects, classes, and types. The figure also shows the relationships between properties and attributes.

Figure 6-1. Teamcenter Object Model Types

A type is a specialization of an Teamcenter class based on properties and behavior.

Teamcenter uses types to represent real-world objects (for example, part, tool, employee). You can the Type application to create, modify, and delete types.

Properties

Type data (for example, ID, Name, Description, and so on) is defined by a set of properties. The messages used to control these properties can be customized and extended using property methods.

Methods

Type behavior (for example, save, delete, create, and so on) is defined by a set of messages that are passed to the type at runtime. These messages are implemented using methods. Methods are C/C++ functions. Programmers can define new methods for types or customize and extend existing methods by adding pre- and postconditions to these existing methods.

Chapter 6 Core Functions

Properties

Properties perform only a simple set of functions, namely asking and setting the value of the attribute or relationship they represent. They can return a List of Values (LOV) that is applicable for that property.

Properties are represented by two classes: ImanProperty and

PropertyDescriptor. The PropertyDescriptor class defines the property for the type, while the ImanProperty class holds the value for a property instance.

In base Teamcenter, each type is specified by a set of properties that directly maps to the attributes defined for a class. You can customize and extend these types by adding new properties to new or existing types. These properties can represent anything you wish to define for a type.

All properties belong to one of five classifications:

• Attribute-based

• Reference-based

• Relation-based

• Runtime

• Compound properties

Properties can also be customized using methods.

Attribute-Based Properties

Attribute-based properties ask or set a simple value (for example, integer, string, and date). The value is stored in the database as an attribute and mapped to the property.

Reference-Based Properties

Reference-based properties ask or set a reference to another object. The reference is stored in the database as a Reference attribute and mapped to the property.

Relation-Based Properties

Relation-based properties ask or set a reference to secondary objects of an

ImanRelation type. The reference is stored in the database as a Relation type and is derived from that ImanRelation type.

Runtime (Derived) Properties

Runtime properties are properties that can be defined at runtime and attached to types. Runtime properties do not map directly to persistent attributes, references or relations. Instead, runtime properties derive data from one or more pieces of system

Core Functions

Compound Properties

A compound property is a property that can be displayed from one type, as if it were the property of that type, though it actually resides on another type. Though runtime properties can be used to display such a property, they require custom coding to do so. Compound properties allow you to create such properties, without custom coding, through the Business Modeler application.

Customizing Properties Using Methods

Property methods can be used to customize the ask_value, set_value and

initialize_value property messages. Although default behavior of these messages is defined in base Teamcenter, you can modify this behavior by adding pre- and postconditions to these messages.

Methods

Methods are user-definable functions that are associated with types and properties.

ITK methods allow Teamcenter sites to customize and extend the behavior of Teamcenter objects and to incorporate enterprise business rules.

Methods are most often used to create subtypes in order to customize parent type behavior. For example, instances of Class Item directly correspond to Type Item.

Methods can be used to define a subtype of item for a Teamcenter site to customize the behavior of items at that site.

Inheritance

Methods incorporate limited single-level inheritance. For example, if no method has been registered for a subtype, the equivalent primary type method is displayed instead. This allows the creation of subtypes that implement an extension of a limited subset of the primary type behavior.

Actions

A method can be divided into four functions that are executed in the following sequence:

1. Precondition 2. Preaction 3. Base action 4. Postaction

Chapter 6 Core Functions

All methods must have a base action, the other actions are optional. Each registered action function must return ITK_ok for processing to continue to the next action.

Otherwise an error is posted and an integer error code is returned.

Precondition is only intended to verify that no conditions exist that could prevent the method from executing properly. Actual execution of the method should only commence in the pre-action.

Careful planning of pre- and post-actions allows extension of base action behavior without having to re-implement the base action.

Message Identification

Each message is uniquely identified by a text string. These strings are used to register methods as type/message combinations. To maximize runtime performance when executing methods, minimize repeated lookups of message IDs. Teamcenter assigns runtime unique integers to each message (message ID) and passes them to the METHOD_SETUP_MESSAGE macro. It caches the message IDs in a static int where they are retrieved the next time the method is executed. This can be useful when implementing custom message execution code.

Method Registration

Methods are registered during initialization of Teamcenter. Registrations apply for the duration of that Teamcenter session. User-defined methods must be registered by code in the USER_init_module user exit function. This code must be called after base Teamcenter initialization (including primary type method registration) is complete.

The following sample program listing shows the code required to:

• Register a method.

Execute the save message for an object of MyType type.

Core Functions

• Implement a precondition handler.

• Implement a base action.

#include <iman_msg.h> /* Defines basic messages like save. */

#include <my_type.h> /* Prototypes for the actions I want to register. */

int USER_init_module() {

int ifail;

METHOD_id_t my_method;

/* Create the method by registering the base action.

*/

if ((ifail = METHOD_register_method("MyType", IMAN_save_msg,

&MYTPE_save, NULL, &my_method)) != ITK_ok) {

return ifail;

}

/* Now add the pre-condition to the method.

*/

if ((ifail = METHOD_add_pre_condition(my_method, MYTYPE_save_precheck, NULL)) != ITK_ok)

{

return ifail;

}

/* The action functions registered here will now be executed instead of

** the default save code every time AOM_save is called for an object

** of type MyType.

*/

return ITK_ok;

}

Chapter 6 Core Functions

The following sample program listing shows the registered actions implemented in the my_type.c file.

#include <my_type.h>

int MYTYPE_save_precheck(METHOD_message_t *, va_list args) {

/* IMAN_save_msg is defined to pass the tag of the object as its only

** vararg.

*/

tag_t object_tag = va_arg(args, tag_t);

. . .

if (... everything ok to save...) {

return ITK_ok;

} else {

return failure code;

} }

int MYTYPE_save(METHOD_message_t *, va_list args) {

/* IMAN_save_msg is defined to pass the tag of the object as its only

** vararg.

*/

tag_t object_tag = va_arg(args, tag_t);

/*... code to implement save action... */

return ITK_ok; /*... or failure code */

}

Core Functions

Property Methods

Property methods are special methods that are attached to a property instead of a type. Property method actions are identical to those described in the Actions section above. However, there are slight differences in the way the following functionality is implemented:

Inheritance

Property methods inheritance is similar to Inheritance discussed earlier in this topic, except that property methods can be inherited through multiple levels of type hierarchy.

The primary type hierarchy directly corresponds to the class hierarchy. When a new user-defined type is created, it becomes a new subtype of the primary type.

Consider the class and type hierarchy as shown in figure 6-2.

Figure 6-2. Property Method Inheritance

Item is a default Teamcenter WorkspaceObject class with a corresponding Item primary type.

The user-defined NewItem subclass is created and also has a corresponding NewItem primary type.

The user-defined Part subtype is created for the NewItem primary type . If a method is registered against any WorkspaceObject property, that same method also applies to the same property of Part.

Message ID

Property message ID is implemented as discussed earlier in this section, except that property methods use a the METHOD_SETUP_PROP_MESSAGE macro instead of METHOD_SETUP_MESSAGE.

Registration

Property methods registration is subject to the same rule and limitations discussed above. Because property methods are registered against a single property, they have a separate registration call and function. Also, property methods are not registered until the property is used for the first time.

Chapter 6 Core Functions

Registering a Property init_module Function

When registering properties and property methods, a special init_module function is required for each type. You determine the names of these init_module functions.

To name the property init_module function, declare the function prototype and insert the type name and the function name into the user_types_methods array definition inside the USER_register_properties function in the user_init.c file.

A sample user_init.c file is provided in the

IMAN_ROOT/sample/properties/smp_props.c directory in

UNIX or Linux or IMAN_ROOT\sample\properties\smp_props.c on Windows.

This sample contains some useful properties. After you modify the user_init.c file, relink the shared library.

The following example registers properties and property methods on the MyType customer type. It uses a function called MYTYPE_prop_init_module to accomplish this. You insert the new function into the user_init.c file.

Property Method Registration in user_init.c:

#include <iman_msg.h> /* Defines basic messages */

int USER_register_properties() {

int ifail = ITK_ok;

/*

* You can declare your function prototypes here or in another file

* #included by this one.

*/

extern int MYTYPE_prop_init_module();

/*

* This array is used to register methods which initialize properties

* on types. The message name is IMANTYPE_init_user_props_msg. No coding

* is necessary in this function. Just add an entry in this array to

* indicate the object type, the function which implements the property

* additions/modifications and the list of arguments.

*

* The array should be terminated with a NULL entry.

*/

USER_prop_init_entry_t user_types_methods[] = {

{ "MyType" , MYTYPE_prop_init_module , NULL }, { "" , 0 , NULL }

};

int n_types = size of(user_types_methods)/size of(USER_prop_init_entry_t);

/*

* Do not edit this call. This call is not to be used elsewhere.

*/

ifail = IMANTYPE_register_properties(user_types_methods, n_types);

return ITK_ok;

}

Core Functions

Registering Properties and Property Methods

To add or remove properties and/or customize the behavior of properties, insert code into the property init module function for the associated type (in other words, the type characterized by the property).

The sample program below shows how to add the MyNewProperty runtime property to the MyType type. The program does three main things:

1. Gets the tag and name of the type to register the property against.

2. Adds the property to the type.

3. Registers a property method against the ask_value message of the property.

The program does not hard code the type name. This is very important to support the inheritance of the property onto subtypes. Always use the IMANTYPE_ask_name function to get the type name from the type tag.

Registered actions implemented in my_type.c:

#include <prop.h>

extern int MYTYPE_ask_newprop_value_function(METHOD_message_t *message,/

va_list args);

int MYTYPE_prop_init_module(METHOD_message_t *message, va_list args) {

/* Extract type_tag */

int ifail = ITK_ok;

tag_t type_tag = va_arg(args, tag_t);

tag_t pd_tag = NULLTAG;

/* Add a new run-time property called MyNewProperty */

ifail = IMANTYPE_add_runtime_property(type_tag,

/* Add an askValue method for our property */

if(ifail == ITK_ok)

/* More property method registrations */

return ifail;

}

Chapter 6 Core Functions

The PROP_ask_value_string function is replaced by the AOM_ask_value_string function after version 10.0.

Writing Property Methods

After registering a property method to ask or set the value of a property, you must write the actual property method function.

The sample program below shows how to write a property method to ask the value of a runtime property. In this sample, the value is retrieved from storage, associated with the property, and returned as-is. However, the value could have been retrieved by calling any ITK function or by manipulating the value retrieved by the ITK function using a suitable algorithm.

int MYTYPE_ask_newprop_value_function(METHOD_message_t *message, va_list args) {

/* Extract property tag

*/

tag_t prop_tag = va_arg(args, tag_t);

char **value = va_arg(args, char**);

char* tmp_value_string = NULL;

int ifail = ITK_ok;

/* Compute or Find actual tmp_value_string then copy it into value with

* persistent memory allocation. The field value is automatically set

*/

if ((ifail = PROP_get_value(prop_tag, &tmp_value_string)) == ITK_ok) {

Custom canned methods are included with the Teamcenter system and can be configured using the Business Modeler application. Canned methods allow you, as system administrator, to change the behavior of items, item revisions, and dataset types without having to write custom code. The user interface for using canned methods is within the Business Modeler application in theAction Rules tab. Once the types are configured with canned methods, the configuration information is stored and can then be easily distributed to your other sites, without having to redo the configuration from Business Modeler.

You have to make changes to both the server side and client side.

In document IntegrationToolkitProgrammerGuide_V10 (Page 121-130)