ADOxx support to implement functionality based on events triggered by the modeller, in the case as described in the question, a created relation of a specific class also results in the creation of an INTERREF to the class. This behaviour needs to be consistent for the creation and the deletion of relations. An important aspect to consider relates to the definition of the domain for INTERREF and the relation class, more precisely to align these two domains.
Case A) Creation of INTERREF:
1ON_EVENT "CreateRelationInstance" {
2 # pre-set values
3 SET id_relationinstanceid: (relationinstanceid)
4 SET id_relationclassid: (relationclassid)
5 SET id_frominstanceid: (frominstanceid)
6 SET id_toinstanceid: (toinstanceid)
7 SET id_componentid: (componentid)
8 # identify the relation class and perform different steps depending on the class being created
9 CC "Core" GET_CLASS_NAME classid: (id_relationclassid)
10 SET str_classname: (classname)
11
12 # read class names of the two object connected with the newly created connector
13 CC "Core" GET_CLASS_ID objid: (id_frominstanceid)
14 SET id_fromClassID: (classid)
15 CC "Core" GET_CLASS_NAME classid: (id_fromClassID)
16 SET str_fromClassName: (classname)
17 CC "Core" GET_CLASS_ID objid: (id_toinstanceid)
18 SET id_toClassID: (classid)
19 CC "Core" GET_CLASS_NAME classid: (id_toClassID)
20 SET str_toClassName: (classname)
21
22 # perform action for a specific relation class
23 IF (str_classname = "Is-A") {
24 # only if the connected instances are of a specific class
25 IF ((str_fromClassName = "Thing") AND (str_toClassName = "Thing")) {
26 # create interref
27 CC "Core" GET_ATTR_ID classid: (id_fromClassID) attrname: ("Is-A")
28 SETL id_interrefID: (attrid)
29 CC "Core" ADD_INTERREF objid: (id_frominstanceid) attrid: (id_interrefID) tobjid: (id_toinstanceid)
30 }
31 }
32}
Case A) Deletion of INTERREF:
1ON_EVENT "DeleteRelationInstance" {
2 # pre-set values
3 SET id_relationinstanceid: (relationinstanceid)
4 SET id_relationclassid: (relationclassid)
5 SET id_frominstanceid: (frominstanceid)
6 SET id_toinstanceid: (toinstanceid)
7 SET id_componentid: (componentid)
8
9 # identify the relation class and perform different steps depending on the class being created
10 CC "Core" GET_CLASS_NAME classid: (id_relationclassid)
11 SET str_classname: (classname)
12
13 # read class names of the two object connected with the newly created connector
14 CC "Core" GET_CLASS_ID objid: (id_frominstanceid)
15 SET id_fromClassID: (classid)
16 CC "Core" GET_CLASS_NAME classid: (id_fromClassID)
17 SET str_fromClassName: (classname)
18 CC "Core" GET_CLASS_ID objid: (id_toinstanceid)
19 SET id_toClassID: (classid)
20 CC "Core" GET_CLASS_NAME classid: (id_toClassID)
21 SET str_toClassName: (classname)}
22 # perform action for a specific relation class
23 IF (str_classname = "Is-A") {
24 # only if the connected instances are of a specific class
25 IF ((str_fromClassName = "Thing") AND (str_toClassName = "Thing")) {
26 # delete interref
27 CC "Core" GET_ATTR_ID classid: (id_fromClassID) attrname: ("Is-A")
28 SETL id_interrefID: (attrid)
29 # get the interref count and loop through to find the correct one to delete
30 CC "Core" GET_INTERREF_COUNT objid: (id_frominstanceid) attrid: (id_interrefID)
31 FOR i from:0 to: (count-1) {
32 CC "Core" GET_INTERREF objid: (id_frominstanceid) attrid: (id_interrefID) index: (i)
33 IF (tobjid == id_toinstanceid) {
34 CC "Core" REMOVE_INTERREF objid: (id_frominstanceid) attrid: (id_interrefID) index: (i)
35 EXIT
36 }
37 }
38 }
39 }