Calculation of the width of a relationCalculation of the width of a relationRE: Calculation of the width of a relationMehmet Albayrakhttps://www.adoxx.org/live/c/message_boards/find_message?p_l_id=&messageId=4323922016-01-07T15:44:23Z2016-01-07T15:29:26ZIn order to have this functionality also by changing the position of the instances, you can also work with the event "SetAttributeValue". Please have a look at the following code, which is also integrated in the attached library. <br />This AdoScript shows you how you can extend the above scenario also by changing the position of the source or target instance.<br /><br /><div class="code"><span class="code-lines"> 1</span>ON_EVENT "SetAttributeValue" {<br /><span class="code-lines"> 2</span><br /><span class="code-lines"> 3</span>#Save the pregiven values of the event<br /><span class="code-lines"> 4</span>SET nObjId: (instid)<br /><span class="code-lines"> 5</span>SET nAttrId: (attrid)<br /><span class="code-lines"> 6</span>SET nModelId: (modelid)<br /><span class="code-lines"> 7</span>SET sOldVal: (oldval)<br /><span class="code-lines"> 8</span><br /><span class="code-lines"> 9</span><br /><span class="code-lines">10</span>CC "Core" GET_CLASS_ID classname:"A"<br /><span class="code-lines">11</span>SET nAClassId: (classid)<br /><span class="code-lines">12</span>CC "Core" GET_ATTR_ID classid: (nAClassId) attrname:"Position"<br /><span class="code-lines">13</span>SET nPositionAAttrId: (attrid)<br /><span class="code-lines">14</span><br /><span class="code-lines">15</span>#Trigger the Functionality if the Position attribute is changed<br /><span class="code-lines">16</span>IF (nAttrId = nPositionAAttrId) { <br /><span class="code-lines">17</span> CC "Core" GET_ATTR_VAL objid: (nObjId) attrname:"Position" <br /><span class="code-lines">18</span> SET nFromObjPosition: (val) <br /><span class="code-lines">19</span> CC "Core" GET_OBJ_NAME objid: (nObjId) <br /><span class="code-lines">20</span> SET sObjName: (objname) <br /><span class="code-lines">21</span> CC "Core" GET_CLASS_ID objid: (nObjId) <br /><span class="code-lines">22</span> SET nInstClassId: (classid) <br /><span class="code-lines">23</span><br /><span class="code-lines">24</span>#Get Connectors and their Endpoints of the classes A and B<br /><span class="code-lines">25</span> IF (nInstClassId=nAClassId) { <br /><span class="code-lines">26</span> CC "AQL" EVAL_AQL_EXPRESSION expr: ("{\"" + sObjName + "\":\"A\"}->\"a2b\"") modelid: (nModelId) <br /><span class="code-lines">27</span> SET sConnectedObjIds: (objids) <br /><span class="code-lines">28</span> IF (sConnectedObjIds="") {<br /><span class="code-lines">29</span> EXIT<br /><span class="code-lines">30</span> } <br /><span class="code-lines">31</span> CC "AQL" EVAL_AQL_EXPRESSION expr: ("{\"" + sObjName + "\":\"A\"}-><\"a2b\">") modelid: (nModelId) <br /><span class="code-lines">32</span> SET sConnectorIds: (objids) <br /><span class="code-lines">33</span> } ELSE { <br /><span class="code-lines">34</span> CC "AQL" EVAL_AQL_EXPRESSION expr: ("{\"" + sObjName + "\":\"B\"}<-\"a2b\"") modelid: (nModelId) <br /><span class="code-lines">35</span> SET sConnectedObjIds: (objids) <br /><span class="code-lines">36</span> IF (sConnectedObjIds="") {<br /><span class="code-lines">37</span> EXIT<br /><span class="code-lines">38</span> } <br /><span class="code-lines">39</span> CC "AQL" EVAL_AQL_EXPRESSION expr: ("{\"" + sObjName + "\":\"B\"}<-<\"a2b\">") modelid: (nModelId) <br /><span class="code-lines">40</span> SET sConnectorIds: (objids) <br /><span class="code-lines">41</span> } <br /><span class="code-lines">42</span> <br /><span class="code-lines">43</span> CC "Core" GET_ATTR_VAL objid: (VAL sConnectedObjIds) attrname:"Position" <br /><span class="code-lines">44</span> SET nToObjPosition: (val)<br /><span class="code-lines">45</span><br /><span class="code-lines">46</span> LEO parse: (nFromObjPosition) get-tmm-value:n_x_fromobj:"x" get-tmm-value:n_y_fromobj:"y" <br /><span class="code-lines">47</span> get-tmm-value:n_w_fromobj:"w" get-tmm-value:n_h_fromobj:"h"<br /><span class="code-lines">48</span> LEO parse: (nToObjPosition) get-tmm-value:n_x_toobj:"x" get-tmm-value:n_y_toobj:"y" <br /><span class="code-lines">49</span> get-tmm-value:n_w_toobj:"w" get-tmm-value:n_h_toobj:"h"<br /><span class="code-lines">50</span><br /><span class="code-lines">51</span># If your source and target instance are resizebale then request also the height and the width of the instances. <br /><span class="code-lines">52</span># Otherwise take the values you defined in the GraphRep.<br /><span class="code-lines">53</span># Differenciate if the target and source instance are in the same line -vertically and horizontally<br /><span class="code-lines">54</span> IF (n_y_fromobj=(n_y_toobj)) {<br /><span class="code-lines">55</span> SET n_xDist: (abs(CMS(n_x_fromobj-n_x_toobj))-(CMS(n_w_fromobj/2)+CMS(n_w_toobj/2)))<br /><span class="code-lines">56</span> SET n_yDist: (abs(CMS(n_y_fromobj-n_y_toobj))<br /><span class="code-lines">57</span> } ELSIF (n_x_fromobj=n_x_toobj) {<br /><span class="code-lines">58</span> SET n_yDist: (abs(CMS(n_y_fromobj-n_y_toobj))-(CMS(n_h_fromobj/2)+CMS(n_h_toobj/2)))<br /><span class="code-lines">59</span> SET n_xDist: (abs(CMS(n_x_fromobj-n_x_toobj)))<br /><span class="code-lines">60</span> } ELSE {<br /><span class="code-lines">61</span> SET n_xDist: (abs(CMS(n_x_fromobj-n_x_toobj))-(CMS(n_w_fromobj/2)+CMS(n_w_toobj/2)))<br /><span class="code-lines">62</span> SET n_yDist: (abs(CMS(n_y_fromobj-n_y_toobj))-(CMS(n_h_fromobj/2)+CMS(n_h_toobj/2)))<br /><span class="code-lines">63</span> }<br /><span class="code-lines">64</span># Calculate the distance with the formula of Pythagoras<br /><span class="code-lines">65</span> SET nDistance: (sqrt(pow(n_xDist, 2)+pow(n_yDist, 2)))<br /><span class="code-lines">66</span># Set the value of the calculated distance into a hidden attribute so you can call it from the graphrep of the relation<br /><span class="code-lines">67</span> CC "Core" GET_CLASS_ID classname:"a2b"SET nRelationClassId: (classid)<br /><span class="code-lines">68</span> CC "Core" GET_ATTR_ID classid: (nRelationClassId) attrname:"Distance"<br /><span class="code-lines">69</span> SET nDistanceAttrId: (attrid)<br /><span class="code-lines">70</span> CC "Core" SET_ATTR_VAL objid: (VAL sConnectorIds) attrid: (nDistanceAttrId) val: (nDistance) <br /><span class="code-lines">71</span>}<br /></div><br /><br />.Mehmet Albayrak2016-01-07T15:29:26ZRE: Calculation of the width of a relationMehmet Albayrakhttps://www.adoxx.org/live/c/message_boards/find_message?p_l_id=&messageId=4313722016-01-08T07:05:10Z2016-01-05T15:19:39ZAs the position is an attribute you can work wih the event handler "SetAttributeValue". Note that you have to trigger this event in two cases: <br /><br />-) movement of an instance of the source class<br />-) movement of an instance of the target class<br /><br />The rest of the implementation is equivalent to the implementation above after you query the source/target instance position.Mehmet Albayrak2016-01-05T15:19:39ZRE: Calculation of the width of a relationPhilipp Küllerhttps://www.adoxx.org/live/c/message_boards/find_message?p_l_id=&messageId=4313332016-01-05T13:13:19Z2016-01-05T13:13:19ZThanks for your answer - works quite good!<br /><br />Do you have any idea how to deal with the situation that the distance might changes afterwards (e.g. an endpoint moves)? I tried different event handler but without sucess.<br /><br />Thanks and best regards,<br /><br />PhilippPhilipp Küller2016-01-05T13:13:19ZRE: Calculation of the width of a relationMehmet Albayrakhttps://www.adoxx.org/live/c/message_boards/find_message?p_l_id=&messageId=4281102015-12-21T10:57:01Z2015-12-21T10:35:18ZYou can trigger an AdoScript code that calculates the length of the relation and save the result into a hidden attribute, if the relation is created with the event handler "AfterCreateModelingConnector".<br />To calculate the length of the relation you neeed the position information of the source and target object. The AdoScript below shows yo how you can implement this scenario, which you also can find in the attached library as an example.<br /><br /><div class="code"><span class="code-lines"> 1</span>ON_EVENT "AfterCreateModelingConnector" {<br /><span class="code-lines"> 2</span><br /><span class="code-lines"> 3</span>#Save the pregiven values<br /><span class="code-lines"> 4</span> SET nModelId: (modelid)<br /><span class="code-lines"> 5</span> SET nObjId: (objid)<br /><span class="code-lines"> 6</span> SET nClassId: (classid)<br /><span class="code-lines"> 7</span> SET nFromObjId: (fromobjid)<br /><span class="code-lines"> 8</span> SET nToObjId: (toobjid)<br /><span class="code-lines"> 9</span><br /><span class="code-lines">10</span>#Get position of the source instance<br /><span class="code-lines">11</span> CC "Core" GET_ATTR_VAL objid: (nFromObjId) attrname:"Position"<br /><span class="code-lines">12</span> SET nFromObjPosition: (val)<br /><span class="code-lines">13</span><br /><span class="code-lines">14</span>#Get position of the target instance<br /><span class="code-lines">15</span> CC "Core" GET_ATTR_VAL objid: (nToObjId) attrname:"Position"<br /><span class="code-lines">16</span> SET nToObjPosition: (val)<br /><span class="code-lines">17</span><br /><span class="code-lines">18</span>#Parse the position attributes of the source and target instance and save the values you need in variables<br /><span class="code-lines">19</span> LEO parse: (nFromObjPosition) get-tmm-value:n_x_fromobj:"x" get-tmm-value:n_y_fromobj:"y"<br /><span class="code-lines">20</span> get-tmm-value:n_w_fromobj:"w" get-tmm-value:n_h_fromobj:"h"<br /><span class="code-lines">21</span> LEO parse: (nToObjPosition) get-tmm-value:n_x_toobj:"x" get-tmm-value:n_y_toobj:"y" <br /><span class="code-lines">22</span> get-tmm-value:n_w_toobj:"w" get-tmm-value:n_h_toobj:"h"<br /><span class="code-lines">23</span><br /><span class="code-lines">24</span># If your source and target instance are resizebale then request also the height and the width of the instances. <br /><span class="code-lines">25</span># Otherwise take the values you defined in the GraphRep.<br /><span class="code-lines">26</span><br /><span class="code-lines">27</span># Differenciate if the target and source instance are in the same line -vertically and horizontally.<br /><span class="code-lines">28</span># Note: These are simple conditions for demonstration<br /><span class="code-lines">29</span> IF (n_y_fromobj=(n_y_toobj)) {<br /><span class="code-lines">30</span> SET n_xDist: (abs(CMS(n_x_fromobj-n_x_toobj))-(CMS(n_w_fromobj/2)+CMS(n_w_toobj/2)))<br /><span class="code-lines">31</span> SET n_yDist: (abs(CMS(n_y_fromobj-n_y_toobj))<br /><span class="code-lines">32</span> } ELSIF (n_x_fromobj=n_x_toobj) {<br /><span class="code-lines">33</span> SET n_yDist: (abs(CMS(n_y_fromobj-n_y_toobj))-(CMS(n_h_fromobj/2)+CMS(n_h_toobj/2)))<br /><span class="code-lines">34</span> SET n_xDist: (abs(CMS(n_x_fromobj-n_x_toobj)))<br /><span class="code-lines">35</span> } ELSE {<br /><span class="code-lines">36</span> SET n_xDist: (abs(CMS(n_x_fromobj-n_x_toobj))-(CMS(n_w_fromobj/2)+CMS(n_w_toobj/2)))<br /><span class="code-lines">37</span> SET n_yDist: (abs(CMS(n_y_fromobj-n_y_toobj))-(CMS(n_h_fromobj/2)+CMS(n_h_toobj/2)))<br /><span class="code-lines">38</span> }<br /><span class="code-lines">39</span><br /><span class="code-lines">40</span># Calculate the distance with the formula of PythagorasSET nDistance: (sqrt(pow(n_xDist, 2)+pow(n_yDist, 2)))<br /><span class="code-lines">41</span># Set the value of the calculated distance into a hidden attribute so you can call it from the graphrep of the relation<br /><span class="code-lines">42</span> CC "Core" GET_ATTR_ID classid: (nClassId) attrname:"Distance"<br /><span class="code-lines">43</span> SET nDistanceAttrId: (attrid)<br /><span class="code-lines">44</span> CC "Core" SET_ATTR_VAL objid: (nObjId) attrid: (nDistanceAttrId) val: (nDistance)<br /><span class="code-lines">45</span>}<br /></div><br /><br />Now you can call the attribute value of the Distance attribute in the GraphRep and set the width of the text as follows:<br /><br /><br /><div class="code"><span class="code-lines">1</span>GRAPHREP<br /><span class="code-lines">2</span><br /><span class="code-lines">3</span>AVAL nDistance:"Distance"<br /><span class="code-lines">4</span>SET vDistance: (CM nDistance)<br /><span class="code-lines">5</span><br /><span class="code-lines">6</span>MIDDLE<br /><span class="code-lines">7</span>ATTR "Name" x:0.1cm w:c: (vDistance) h:b<br /></div><br /><br /><br />.Mehmet Albayrak2015-12-21T10:35:18ZCalculation of the width of a relationPhilipp Küllerhttps://www.adoxx.org/live/c/message_boards/find_message?p_l_id=&messageId=4211962015-12-20T13:33:15Z2015-12-06T16:53:07ZHello,<br />I like to connect to classes with a relation. This relation should have a variable showing the value of the relationship. This works as well as showing the variable top or left right. <br /><br />However, I currently use a fixed with of the text (3cm). This means, a long text looks quite ugly on a long relation and on a short realtion the text might run into another class. Is it possible to calculate the with of a relation to define the with of the text?<br /><br />Here is the graphrep extract:<br /><br /><div class="code"><span class="code-lines"> 1</span>GRAPHREP<br /><span class="code-lines"> 2</span>AVAL bColor:"Color"<br /><span class="code-lines"> 3</span>AVAL bLR:"Show Value Left / Right"<br /><span class="code-lines"> 4</span>AVAL bShowValue:"Schow Value"<br /><span class="code-lines"> 5</span><br /><span class="code-lines"> 6</span>PEN w:0.02cm color:bColor)<br /><span class="code-lines"> 7</span>SHADOW mode:off<br /><span class="code-lines"> 8</span><br /><span class="code-lines"> 9</span>EDGE<br /><span class="code-lines">10</span><br /><span class="code-lines">11</span>START<br /><span class="code-lines">12</span>FILL color:bColor)<br /><span class="code-lines">13</span>POLYGON 3 x1:0cm y1:.1cm x2:-0.3cm y2:0.0cm x3:0cm y3:-.1cm<br /><span class="code-lines">14</span><br /><span class="code-lines">15</span>MIDDLE<br /><span class="code-lines">16</span>FONT h:8pt bold color:bColor)<br /><span class="code-lines">17</span>IF (bLR="1") {<br /><span class="code-lines">18</span>ATTR "Value" line-break: words x:0.10cm y:0.00cm w:l:3cm h:b<br /><span class="code-lines">19</span>}<br /><span class="code-lines">20</span>IF (bLR="0") {<br /><span class="code-lines">21</span>ATTR "Value" line-break: words x:0.00cm y:0.00cm w:c:3cm h:b<br /><span class="code-lines">22</span>}<br /><span class="code-lines">23</span><br /><span class="code-lines">24</span>END<br /><span class="code-lines">25</span>FILL color:bColor)<br /><span class="code-lines">26</span>POLYGON 3 x1:-.3cm y1:.1cm x2:0cm y2:0cm x3:-.3cm y3:-.1cm<br /></div><br /><br />Thank you for any idea!<br /><br />Best regards,<br /><br />PhilippPhilipp Küller2015-12-06T16:53:07Z