Dear Fadi,
for that purpose you would have to implement an event handler for the event
"CreateRelationInstance" in the library attribute
External Coupling of the
Dynamic Library.
In the event handler, you have to read the information about the relation name and the names of the
from and
to objects, respectively, and, if all these names are "compatible", you create a new pointer (
INTERREF) using the command call
ADD_INTERREF. Please observe the implementation below:
1ON_EVENT "CreateRelationInstance"
2{
3#Event triggered when a relation instance (connector) is created
4#componentid contains the ID of the affected component
5#relationinstanceid the ID of the affected relation
6#relationclassid the ID of the new relation's class
7#frominstanceid the ID of the from-instance of the relation
8#toinstanceid the ID of the to-instance of the new relation.
9
10SET id_relationinstanceid: (relationinstanceid)
11SET id_relationclassid: (relationclassid)
12SET id_frominstanceid: (frominstanceid)
13SET id_toinstanceid: (toinstanceid)
14SET id_componentid: (componentid)
15CC "Core" GET_CLASS_NAME classid: (id_relationclassid)
16 # --> RESULT ecode: intValue classname: strValue isrel: intValue
17SET str_classname: (classname)
18IF (str_classname = "has")
19{
20 # read class names of the two object connected with the newly created connector
21 CC "Core" GET_CLASS_ID objid: (id_frominstanceid)
22 #--> RESULT ecode: intValue classid: intValue isrel: intValue .
23 SET id_fromClassID: (classid)
24 CC "Core" GET_CLASS_NAME classid: (id_fromClassID)
25 #--> RESULT ecode: intValue classname: strValue isrel: intValue .
26 SET str_fromClassName: (classname)
27 CC "Core" GET_CLASS_ID objid: (id_toinstanceid)
28 #--> RESULT ecode: intValue classid: intValue isrel: intValue .
29 SET id_toClassID: (classid)
30 CC "Core" GET_CLASS_NAME classid: (id_toClassID)
31 #--> RESULT ecode: intValue classname: strValue isrel: intValue .
32 SET str_toClassName: (classname)
33
34 IF ((str_fromClassName = "vehicle") AND (str_toClassName = "part"))
35 {
36 #create interref
37 CC "Core" GET_ATTR_ID classid: (id_fromClassID) attrname: ("connected_to")
38 # --> RESULT ecode: intValue attrid: id .
39 SET id_interrefID: (attrid)
40 CC "Core" ADD_INTERREF objid: (id_frominstanceid) attrid: (id_interrefID) tobjid: (id_toinstanceid)
41 #--> RESULT ecode: intValue
42 }
43}
44}
45#=============================================
The names used in the example are fictive names, of course, and you have to adapt them to your own modelling language.