« Back to AAU Project

relation-Class: Draw rectangle and dock to connected object

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Hello, 

I have a question regardarding the relation-Class. What I want to achive is the following: 


​I want to show the cardinalety and it's description as a seperate rectangle below the object (e.g book).  ​
​So far I tried the following: 


​The problem is that the rectangle box is not docked to the object and it doesn't adjust it self to the object position and width. The height of the box as well as the orientation should stay the same. If I start to move the e.g "book"-object these boxes the rectangles are always resizing and changing their orientation. ​My GraphRep for the relation-class: ​
GRAPHRE​​P​ ​​ ​sizing:asymmetrical
START
FILL color:whitesmoke
RECTANGLE x:1.5 y:-.5cm w:-3cm h:1cm
ATTR "attrSourceDescription" line-break: words w:c h:c x:-0.5cm

END
FILL color:black
POLYGON 3 x1:-3cm y1:.1cm x2:-2.7cm y2:0cm x3:-3cm y3:-0.1cm
FILL color:whitesmoke
RECTANGLE x:0 y:-0.5cm w:-2.7cm h:1cm
ATTR "attrTargetDescription" line-break: words w:c h:c x:-0.5cm

MIDDLE
ATTR "attrCardinalety" w:c h:c y:-0.2cm

​A​ttrRep ​for the relation-class: 
NOTEBOOK 
CHAPTER "Description"
ATTR "attrSourceDescription"
ATTR "attrTargetDescription"
ATTR "attrCardinalety"

​Whats the best solution to solve this and can you give me some hints. I don't think it is enough to just use the GRAPHREP to solve this problem. Maybe events and some ADOScript could help? 
​Thanks in advance, Christoph​

RE: relation-Class: Draw rectangle and dock to connected object
Answer
7/14/15 7:08 AM as a reply to christoph.
Dear Christoph,
Unfortunately, we cannot see your images in the post. Can you please attach the files by clicking on 'Attach Files' (see Screenshot)?
Attachment

Attachments: ScreenShot.png (103.9k)

RE: relation-Class: Draw rectangle and dock to connected object
Answer
7/14/15 7:37 AM as a reply to Mehmet Albayrak.
Thanks for the info Mehmet. That is strange, I can see them on different devices and browsers.
Anyways here they are attached and thanks for reporting back. 
Attachment

Attachment

Attachments: prototyp.png (21.0k), solution.png (7.4k)

RE: relation-Class: Draw rectangle and dock to connected object
Answer
7/24/15 11:56 AM as a reply to christoph.
Dear Christoph,

Sorry for only coming back to you now. Since the changing of the direction of the relation adjusts the values of the ‘x’ and ’y’ coordinates, there will always be the effect for the rectangles at the start- and endpoint of the relation. Therefore I would suggest you to create these information-rectangles as instances of an additional ‘help’ class.
These instances you can create automatically if you create a relation e.g. with the event ‘AfterCreateModelingNode’ for the source and target object. These ‘help’ objects are connected then with an InterRef with the source and target.
With a second event (‘AfterEditAttributevalue’) you can then coordinate the display of the attributes “attrSourceDescription” and “attrTargetDescription” (See below). The Implementation result of this approach would be as follows:
 
Please find below an example library, and the step by step documentation how the implement the scenario.

1) Create Classes and Attributes:   

    -)  Create Class "A"        
          ·
"RelalationCount"              type:EXPRESSION 
                   Standard Value:

1EXPR type:integer      
2     expr: (set (objName,aval(objid,"Name")),         
3            tokcnt(aql("({\""+objName+"\"}-->\"RelationDescription\") ")))

          · "RelationDescription"     type:INTERREF
             Instance Reference to "Description Class"

    -) Create Class "Description Class"

          · SourceDescription  type:STRING
          · TargetDescription    type:STRING

    -) Create Relation Class "relation"

2) Define the event handler "AfterCreateModellingConnector" for creating descriptive rectangles at the source and target object.


 1ON_EVENT "AfterCreateModelingConnector" {
 2 
 3  #Define Pregiven Parameters
 4  SETG nModelId: (modelid)
 5  SETG nObjId: (objid)
 6  SETG nClassId: (classid)
 7  SETG nFromObjId: (fromobjid)
 8  SETG nToObjId: (toobjid)
 9
10  CC "Core" GET_CLASS_ID objid: (nFromObjId)
11  SET nFromObjClassId: (classid)
12  CC "Core" GET_CLASS_ID objid: (nToObjId)
13  SET nToObjClassId: (classid)
14CC "Core" GET_CLASS_ID classname:"A"
15SET nAClassId: (classid)
16
17#Trigger Event if the source and target object are of class "A"
18IF (nFromObjClassId=nAClassId AND nToObjClassId=nAClassId) {
19 
20  ################################################################
21  #Ceate Object of class "Description" Class with an unique name.#
22  ################################################################
23  CC "Core" GET_ATTR_VAL objid: (nFromObjId) attrname:"RelationCount"
24  SET nCount: (val + 1)
25  CC "Core" GET_ATTR_VAL objid: (nFromObjId) attrname:"Name"
26  SET sSourceObjectName: (val)
27  CC "Core" GET_CLASS_ID classname:"Description Class"
28  SET nDCclassId: (classid)
29  SET sSourceName: (sSourceObjectName + STR nCount)
30  CC "Core" CREATE_OBJ modelid: (nModelId) classid: (nDCclassId) objname: (sSourceName)
31  SET nSourceObjId: (objid)
32
33  #Connect the instance of "A" with the new created object of "Description Class" with an InterRef
34  CC "Core" GET_ATTR_ID classid: (nAClassId) attrname:"RelationDescription"
35  SET nInterId: (attrid)
36  CC "Core" ADD_INTERREF  objid: (nFromObjId) attrid: (nInterId) tobjid: (nSourceObjId)
37
38  #Position the Objects and BendPoints
39  CC "Core" GET_ATTR_VAL objid: (nFromObjId) attrname:"Position"
40  SET sFromObjPosition: (val)
41  LEO parse: (sFromObjPosition) get-tmm-value:n_x_fromobj:"x" get-tmm-value:n_y_fromobj:"y"
42  SET n_x_fromobj: (n_x_fromobj )
43  SET n_y_fromobj: (n_y_fromobj+ (CM nCount + CM 0.5))
44  SET mFromEdgeX: (n_x_fromobj + CM 2)
45  SET mFromEdgeY: (n_y_fromobj)
46  CC "Modeling" SET_OBJ_POS objid: (nSourceObjId) x: (n_x_fromobj) y: (n_y_fromobj)
47
48  #################################
49  #Analogous for the target object#
50  #################################
51  CC "Core" GET_ATTR_VAL objid: (nToObjId) attrname:"RelationCount"
52  SET nToCount: (val + 1)
53  CC "Core" GET_ATTR_VAL objid: (nToObjId) attrname:"Name"
54  SET sTargetObjectName: (val)
55  SET sTargetName: (sTargetObjectName + STR nToCount)
56  CC "Core" CREATE_OBJ modelid: (nModelId) classid: (nDCclassId) objname: (sTargetName)
57  SET nTargetObjId: (objid)
58  CC "Core" ADD_INTERREF  objid: (nToObjId) attrid: (nInterId) tobjid: (nTargetObjId)
59  CC "Core" GET_ATTR_VAL objid: (nToObjId) attrname:"Position"
60  SET sToObjPosition: (val)
61  LEO parse: (sToObjPosition) get-tmm-value:n_x_toobj:"x" get-tmm-value:n_y_toobj:"y"
62  SET n_x_toobj: (n_x_toobj)
63  SET n_y_toobj: (n_y_toobj+ (CM nToCount)+ CM 0.5)
64  SET mToEdgeX: (n_x_toobj - CM 2)
65  SET mToEdgeY: (n_y_toobj)
66  CC "Modeling" SET_OBJ_POS objid: (nTargetObjId) x: (n_x_toobj) y: (n_y_toobj)
67  CC "Core" DELETE_CONNECTOR modelid: (nModelId) objid: (nObjId)
68  CC "Core" CREATE_CONNECTOR modelid: (nModelId) fromobjid: (nSourceObjId) toobjid: (nTargetObjId) classid: (nClassId)
69 
70  #Set bendpoints
71  CC "Core" SET_ATTR_VAL  objid: (objid) attrname:"Positions" val: ("EDGE 2 x1:" + (STR mFromEdgeX) + " y1:" + STR(mFromEdgeY) + " x2:" + (STR mToEdgeX) + " y2:" + STR (mToEdgeY)) }}

3)  Define the event handler "AfterEditAttributeValue" for displaying the source and target properties of the relation.


 1ON_EVENT "AfterEditAttributeValue" {
 2  #Define Pregiven Parameters  SETG nModelId: (modelid)
 3  SETG nObjId: (instid)
 4  SETG nAttrId: (attrid)
 5
 6  ################################
 7  #Display the source information#
 8  ################################
 9  CC "Core" GET_CLASS_ID relation classname:"relation" 
10  CC "Core" GET_ATTR_ID classid: (classid) attrname:"attrSourceDescription"
11  SET nSourceAttrId: (attrid)
12
13  IF (nAttrId=nSourceAttrId) {
14     CC "Core" GET_ATTR_VAL objid: (nObjId) attrname:"attrSourceDescription"
15     CC "Core" GET_CONNECTOR_ENDPOINTS objid: (nObjId)
16     CC "Core" SET_ATTR_VAL objid: (fromobjid) attrname:"SourceDescription" val: (val)
17  }
18
19  ################################  
20  #Display the source information#
21  ################################ 
22  CC "Core" GET_ATTR_ID classid: (classid) attrname:"attrTargetDescription"
23  SET nTargetAttrId: (attrid)
24
25  IF (nAttrId=nTargetAttrId) {
26     CC "Core" GET_ATTR_VAL objid: (nObjId) attrname:"attrTargetDescription"
27     CC "Core" GET_CONNECTOR_ENDPOINTS objid: (nObjId)
28     CC "Core" SET_ATTR_VAL objid: (toobjid) attrname:"TargetDescription" val: (val)
29  }
30}

.
Attachments: Relation Graph Library.abl (17.8k)

RE: relation-Class: Draw rectangle and dock to connected object
Answer
7/26/15 5:30 PM as a reply to Mehmet Albayrak.
Thank you so much Mehmet! This is an awesome solution for my problem - I just tried it and it works really well. 

The only thing I still want to add is the position of the rectangle with regard to the object position when I move it around - it should stay docked to the object. Can I use the "Position" attribute for that somehow because I couldn't find any "object-move" event or the like?

The calculation for the position of the rectangles would be pretty much the same as you have already shown in your code.    

Thanks again! 

RE: relation-Class: Draw rectangle and dock to connected object
Answer
7/27/15 6:46 AM as a reply to christoph.
Dear Christoph, 

You are absolutely right. The calculation for the position of the rectangles would be the same as above. 

Since the 'Position' is an attribute of each class (inherited from the super class '__D-construct__' ), you can here again use the event 'AfterEditAttributeValue'. Therefore you need only to trigger the event if the attribute 'Position' is changed, like we did above for the attributes 'attrSourceDescription' and 'attrTargetDescription'.  And then you can reposition the objects.