View Switch - dynamic GraphRep
View Switch - dynamic GraphRep
View Switch - dynamic GraphRep
Sabin Popescu
https://www.adoxx.org/live/c/message_boards/find_message?p_l_id=&messageId=87212
2014-04-03T12:35:31Z
2014-03-17T13:43:56Z
<strong></strong>This package provides an example for dynamic GraphReps. <br /><br />The graphical representation of objects depends on the value of two attributes (in our case "People-like view" and "Action type"):<br /><br /><img src="http://www.adoxx.org/live/documents/10157/86220/View_switch_preview_1.png/4d0bcf4b-70ee-40f8-b529-81d25f11a6ae?t=1395145618000" /><br /><br /><img src="http://www.adoxx.org/live/documents/10157/86220/View_switch_preview_2.png/cfc3bfe3-b1f5-4709-9850-12e3660fabbe?t=1395145618383" /><br /><br /><br /><span style="font-size: 18px"><strong>Downloads</strong></span><br /><br />The files below contain an example library (View Switch Library.abl) and anexample model (Sample_View Switch.adl). A step-by-step configuration guide is presented in the Hands-On section below. It completely describes how to build this example library.<br /><br /><a href="http://www.adoxx.org/live/documents/10157/86220/View+Switch+Library.abl/4a9af41d-1130-482b-bde7-ec42f18313b4">View Switch Library.abl </a><br /><a href="http://www.adoxx.org/live/documents/10157/86220/Sample_View+Switch.adl/cc10f624-a8f6-4593-ba6d-04bf28226646">Sample_View Switch.adl </a><br /><br /><strong><span style="font-size: 18px">Hands-On<br /><br /><span style="font-size: 12px"><strong>1) Create new classes __ModelTypeMetaData__ and Task<br /><br /></strong></span><img src="http://www.adoxx.org/live/documents/10157/86220/01_new_classes.png/097aec31-dea1-4292-b6f2-56e0e51546b1?t=1396532899847" /><br /><span style="font-size: 12px"><br />Steps to create classes __ModelTypeMetaData__, Task </span></span></strong><strong></strong><strong><span style="font-size: 18px"><strong><span style="font-size: 12px"></span></strong></span></strong><ul style="list-style: disc inside;"><li>Go to the Library management, select a dynamic library and click <em>Class hierarchy</em>.</li><li>Click <em>View</em> and select <em>Metamodel</em>.</li><li>Select <em>__D-construct__ (Metamodel)</em></li><li>Click <em>New</em> --> <em>New class</em>; name it <em>__ModelTypeMetaData__</em> (two underscore signs!).</li><li>Click <em>New</em> --> <em>New class</em>; name it <em>Task</em>.<em></em></li></ul style="list-style: disc inside;"><strong>2) Add attributes</strong><br /><br /><img src="http://www.adoxx.org/live/documents/10157/86220/02_new_attributes.png/4b3d8106-8654-4a0a-8115-be82d4bd538b?t=1396533276556" /><br /><ul style="list-style: disc inside;"><li>Select class <em>Task </em>and click <em>New attribute</em>.</li><li>name: <em>Action type</em>, type: <em>Enumeration</em></li><li>Set EnumerationDomain:</li></ul style="list-style: disc inside;"><div class="code"><span class="code-lines">1</span>Register@Observe@Plan@Do@Check@Adjust</div><ul style="list-style: disc inside;"><li>Select class <em>Task </em>and click <em>New attribute</em>.</li><li>name: <em>People-like view</em>, type: <em>Enumeration</em></li><li>Set EnumerationDomain:</li></ul style="list-style: disc inside;"><div class="code"><span class="code-lines">1</span>No@Yes</div><ul style="list-style: disc inside;"><li>Select class <em>__ModelTypeMetaData__</em> and click <em>New attribute</em>.</li><li>name: <em>BoolPLV</em>, type: <em>Enumeration</em></li><li>Set EnumerationDomain:</li></ul style="list-style: disc inside;"><div class="code"><span class="code-lines">1</span>No@Yes</div><strong>3) Define Model Type “Task Pool”</strong><br /><br /><img src="http://www.adoxx.org/live/documents/10157/86220/03_new_mt.png/a3c80512-779c-4f30-8eba-6d953cec78d7?t=1396533957575" /><br /><ul style="list-style: disc inside;"><li>Go to your dynamic library</li><li>click <em>Library attributes</em> --> <em>Add-ons</em></li><li>add the model type <em>Task Pool</em> to the <em>Modi</em> attribute and include class <em>Task</em>:</li></ul style="list-style: disc inside;"><div class="code"><span class="code-lines">1</span>MODELTYPE "Task Pool"<br /><span class="code-lines">2</span>INCL "Task"<br /></div><br /><strong>4) Configure GraphRep of class Task</strong><br /><ul style="list-style: disc inside;"><li>go to class <em>Task</em></li><li>double-click <em>GraphRep (Metamodel)</em> attribute</li><li>enter the following code to the <em>Standard value</em> attribute:</li></ul style="list-style: disc inside;"><div class="code"><span class="code-lines"> 1</span>GRAPHREP<br /><span class="code-lines"> 2</span>AVAL plv:"People-like view"<br /><span class="code-lines"> 3</span>FILL r:102 g:153 b:255<br /><span class="code-lines"> 4</span>AVAL actionType:"Action type"<br /><span class="code-lines"> 5</span>IF (plv = "No")<br /><span class="code-lines"> 6</span>RECTANGLE x:-1.4cm y:-.7cm w:2.8cm h:1.4cm<br /><span class="code-lines"> 7</span>ATTR "Name" y:1.2cm w:c:2.8cm h:t<br /><span class="code-lines"> 8</span>ELSE<br /><span class="code-lines"> 9</span>SET filename: ("db:\\plan.jpg") <br /><span class="code-lines">10</span> IF (actionType = "Register")<br /><span class="code-lines">11</span> {<br /><span class="code-lines">12</span> SET filename:"db:\\register.jpg"<br /><span class="code-lines">13</span> }<br /><span class="code-lines">14</span> IF (actionType = "Observe")<br /><span class="code-lines">15</span> {<br /><span class="code-lines">16</span> SET filename:"db:\\observe.jpg"<br /><span class="code-lines">17</span> }<br /><span class="code-lines">18</span> IF (actionType = "Plan")<br /><span class="code-lines">19</span> {<br /><span class="code-lines">20</span> SET filename:"db:\\plan.jpg"<br /><span class="code-lines">21</span> }<br /><span class="code-lines">22</span> IF (actionType = "Do")<br /><span class="code-lines">23</span> {<br /><span class="code-lines">24</span> SET filename:"db:\\do.jpg"<br /><span class="code-lines">25</span> }<br /><span class="code-lines">26</span> IF (actionType = "Check")<br /><span class="code-lines">27</span> {<br /><span class="code-lines">28</span> SET filename:"db:\\check.jpg"<br /><span class="code-lines">29</span> }<br /><span class="code-lines">30</span> IF (actionType = "Adjust")<br /><span class="code-lines">31</span> {<br /><span class="code-lines">32</span> SET filename:"db:\\adjust.jpg"<br /><span class="code-lines">33</span> }<br /><span class="code-lines">34</span>SET we:5.6cm<br /><span class="code-lines">35</span> SET he:2.8cm<br /><span class="code-lines">36</span> PEN w:0.07cm color:black<br /><span class="code-lines">37</span> FILL style:null<br /><span class="code-lines">38</span> SET bigRectangle: (CM (5.6))<br /><span class="code-lines">39</span> RECTANGLE x: ((-1)*(we/2)) y: ((-1)*(he/2)) w: (bigRectangle) h: (CM 3) # a border marking the object's size<br /><span class="code-lines">40</span> TABLE w: (we/2) h: (he/2) rows:1 cols:1 w1:100% h1:100% # get the current size of the object<br /><span class="code-lines">41</span> BITMAPINFO (filename) # get the bitmap size<br /><span class="code-lines">42</span> STRETCH off<br /><span class="code-lines">43</span> IF (bmpwidth / CMS tabw1 < bmpheight / CMS tabh1) {<br /><span class="code-lines">44</span> # use maximum height, space left and right<br /><span class="code-lines">45</span> SET w: (tabh1 * 2 * (bmpwidth / bmpheight))<br /><span class="code-lines">46</span> BITMAP (filename) x: ((-1)*(w)) y: (((-1)*(tabh1)) + (CM 0.05)) w: (w) h: (he)<br /><span class="code-lines">47</span> } ELSE {<br /><span class="code-lines">48</span> # use maximum width, space at top and bottom<br /><span class="code-lines">49</span> SET h: (tabw1 * 2 * (bmpheight / bmpwidth))<br /><span class="code-lines">50</span> BITMAP (filename) x: ((-1)*(tabw1 * 2)) y: ((-1)*(h)) w: (tabw1 * 2) h: (h)<br /><span class="code-lines">51</span> }<br /><span class="code-lines">52</span> FONT bold<br /><span class="code-lines">53</span> ATTR "Name" x:0.5cm y: ((((-1)*(he/2))+0.5cm)) w:l:2.0cm h:b:1.5cm line-break:rigorous<br /><span class="code-lines">54</span> FONT<br /><span class="code-lines">55</span> ATTR "Description" x:0.5cm y: (((-1)*(he/2)+1.5cm)) w:l:2.0cm h:c:2cm line-break:rigorous<br /><span class="code-lines">56</span>ENDIF<br /></div><br /><strong>5) Add Images and AdoScript file to the data base</strong><br /><ul style="list-style: disc inside;"><li>click <em>Extras </em>--> <em>File management...</em></li><li>select the data base of your library</li><li>import files (adjust.jpg, check.jpg, do.jpg, observe.jpg, plan.jpg, register.jpg, showHidePeopleLikeView.asc)</li></ul style="list-style: disc inside;"><strong>6) Code contained in showHidePeopleLikeView.asc:</strong><br /><div class="code"><span class="code-lines"> 1</span>CC "Modeling" GET_ACT_MODEL<br /><span class="code-lines"> 2</span> #--> RESULT modelid:intValue<br /><span class="code-lines"> 3</span>SETL id_ActModel: (modelid)<br /><span class="code-lines"> 4</span><br /><span class="code-lines"> 5</span>CC "Core" GET_ATTR_VAL objid: (id_ActModel) attrname: ("BoolPLV")<br /><span class="code-lines"> 6</span>SET s_peoplelikeview_attrval: (val)<br /><span class="code-lines"> 7</span><br /><span class="code-lines"> 8</span>IF (s_peoplelikeview_attrval = "No")<br /><span class="code-lines"> 9</span>{<br /><span class="code-lines">10</span> SET plvOption: ("Yes")<br /><span class="code-lines">11</span> CC "Core" SET_ATTR_VAL objid: (id_ActModel) attrname: ("BoolPLV") val: ("Yes")<br /><span class="code-lines">12</span>}<br /><span class="code-lines">13</span>ELSE<br /><span class="code-lines">14</span>{<br /><span class="code-lines">15</span> SET plvOption: ("No")<br /><span class="code-lines">16</span> CC "Core" SET_ATTR_VAL objid: (id_ActModel) attrname: ("BoolPLV") val: ("No")<br /><span class="code-lines">17</span>}<br /><span class="code-lines">18</span><br /><span class="code-lines">19</span>CC "AQL" EVAL_AQL_EXPRESSION modelid: (id_ActModel) expr: ("<\"" + c_CLASS_NAME_1 + "\">")<br /><span class="code-lines">20</span>SET ocount: (tokcnt (objids, " ")) j:0<br /><span class="code-lines">21</span>WHILE(j < ocount)<br /><span class="code-lines">22</span>{<br /><span class="code-lines">23</span> SET objid: (VAL token (objids, j, " "))<br /><span class="code-lines">24</span> CC "Core" SET_ATTR_VAL objid: (objid) attrname: (c_ATTR_NAME_SHOW_PEOPLE_LIKE_VIEW) val: (plvOption)<br /><span class="code-lines">25</span> SET j: (j + 1)<br /><span class="code-lines">26</span>}<br /><span class="code-lines">27</span><br /><span class="code-lines">28</span>IF (plvOption = "No")<br /><span class="code-lines">29</span>{<br /><span class="code-lines">30</span> CC "AdoScript" INFOBOX (c_str_SHOW_PEOPLE_LIKE_TEXT_SHOW)<br /><span class="code-lines">31</span>}<br /><span class="code-lines">32</span><br /><span class="code-lines">33</span>IF (plvOption = "Yes")<br /><span class="code-lines">34</span>{<br /><span class="code-lines">35</span> CC "AdoScript" INFOBOX (c_str_SHOW_PEOPLE_LIKE_TEXT_HIDE)<br /><span class="code-lines">36</span>}<br /></div><br /><strong>7) Add new menu item to the Modelling Toolkit</strong><br /><ul style="list-style: disc inside;"><li>Select your dynamic library</li><li>click <em>Library attributes</em> --> <em>Add-ons</em></li><li>add the following lines to the <em>External coupling</em> attribute:</li></ul style="list-style: disc inside;"><div class="code"><span class="code-lines">1</span>ITEM "Show/Hide People-like view"<br /><span class="code-lines">2</span> modeling:"Extras"<br /><span class="code-lines">3</span>EXECUTE file: ("db:\\showHidePeopleLikeView.asc")<br /></div><strong><br /></strong>
Sabin Popescu
2014-03-17T13:43:56Z