Drawing table information

All topics on the Atoms in any Enterprise Dynamics Library.
Post Reply
menno
Posts: 45
Joined: Tuesday 29 March, 2011 - 16:01

Drawing table information

Post by menno »

Say you have the settings/parameters for your simulation model placed in a central place in the model: a table. For instance, this table contains all the different process times, MTBF's, MTTR's, etc. for all the atoms in your model. This is a nice way to keep your settings centralized.

If you want to view your the settings during a simulation run (with ED Developer, ED Builder or ED Runtime), you can 'open' the table atom. However, if your using the ED Viewer to run the model, you are not able to modify atoms or to 'open a table'. Also, the speed of your simulation model can decrease when the table is open and frequently used by the model.

There is another option to view your model settings without having to open the table atom (for this option, you must use ED developer. Your model with the table view functionality can be opened in ED Developer, ED Builder, ED Runtime and ED Viewer):

- Drawing the table with help of 2dDraw!


Say your settings table is named 'Settings'. It's atom reference (alias) is then refSettings. In the Atom Editor, you then create a new atom in your model tree named, for example, ShowSettings (tip: put this atom in a seperate layer, in this way, you can easily turn on/off the table information). In the 2D tab of the atom ShowSettings, make sure to set the setting '2D Draw' to 'Yes'.

Now you must place some code on the 2dDraw event handler:

Code: Select all

 Do(   
 {first, declare some help variables}
  var([atmTable], vbAtom, refSettings),  
  var([valStartX], vbvalue,0),
  var([valStartY], vbvalue,0),  
  var([valColWidth], vbvalue,30),
  var([valRowHeight], vbvalue,1.6),   
  var([valNrRows], vbvalue, nrows(atmTable)),
  var([valNrCols], vbvalue, ncols(atmTable)),  
  var([valColCount], vbvalue, 1),
  var([valRowCount], vbvalue, 1), 

  {if you want a show a title for your table, the do the following:}
  {* Title *}
  diText(valStartX, valStartY - 3*valRowHeight, name(atmTable), colorblack, ColorTransparent, 2, [arial]), 
 
 {then draw the headers of the table:} 
  {* Header *}
  repeat(
   valNrCols,
   do(
    {* draw text *}
    dishape(valStartX + ((count-1)*valColWidth), valStartY - valRowHeight, valColWidth, valRowHeight,0, ColorBlack, ColorRed),   
    {* draw lines *}
    diText(valStartX+valTextSpace + ((count-1)*valColWidth), valStartY - valRowHeight, string(cell(0,count,atmTable)), Colorblack, ColorRed, 1, [arial])
 
   )
  ),
  
 {now draw the body, or the actual information, of the table:} 
  {* Body *}
  Repeat(
   valNrRows,
   do(
    valColCount := 1,
    repeat(
     valNrCols,
     do(
      {* draw lines *}
      dishape(valStartX + ((valColCount-1)*valColWidth), valStartY+ ((valRowCount-1)*valRowHeight), valColWidth, valRowHeight,0, ColorBlack, ColorTransparent),
 
      {* draw text *}
      diText(valStartX+ valTextSpace + ((valColCount-1)*valColWidth), valStartY+ ((valRowCount-1)*valRowHeight), 
      do(
       {is this example, certain '0' values in the table (places in the table with no entry) are not displayed as '0'!}
       if(
        And(
         CompareText(String(cell(valRowCount,valColCount,atmTable)), [0]),
         Or(
          valColCount = 1,        
          valColCount = 2,
          And(
           valColCount = 3,
           CompareText(String(cell(valRowCount,valColCount-1,atmTable)), [0])
          )
         )
        ),
        [],
        String(cell(valRowCount,valColCount,atmTable))
       )
      ),
      colorblack, ColorTransparent, 1, [arial]),
                 
      inc(valColCount)      
     )
    ),
    inc(valRowCount)
   )  
  )
  
 )

This code gives a simple table viewer for your 2dDraw. Good luck!
Last edited by menno on Thursday 07 July, 2011 - 11:18, edited 2 times in total.
menno
Posts: 45
Joined: Tuesday 29 March, 2011 - 16:01

Re: Drawing table information

Post by menno »

There is also an option to 'build' this functionality with ED Builder!

You have to use the following atoms:
- the Initialize atom (under 'Tools' in the library tree)
- the Textbox atom (under 'Visualization' in the library tree)

Connect the input channel of the Initialize atom the central channel of the Textbox atom. Put the code from the post above between brackets in the 'Initialize code' of the GUI of the Initialize atom:

Code: Select all

On2DDraw(in(1,c)) := [{2dDraw Code!!!}]
Also, tick the box 'On reset' in the GUI of the Initialize atom.

What is happens, is that the 2dDraw Event handler of the Textbox atom is updated on reset with the entered code, without having to use the atom editor.

Good luck!
Post Reply