Topic
10 replies Latest Post - ‏2013-07-08T20:01:55Z by spcraft
spcraft
spcraft
9 Posts
ACCEPTED ANSWER

Pinned topic Simple inter-module boolean attribute

‏2013-07-01T19:35:40Z |

Hello,

I'm a DXL-ubernoob. Even still, I suspect the answer to this question is easy -- I just don't know enough yet about DXL syntax to work it out on my own (though I'm trying to learn!).

Module B contains objects B1, B2, B3, all of which have a boolean attribute B1.X B2.X B3.X. Module A contains an object A1 that has a boolean attribute A1.Y that should be determined by the state of B1.X, B2.X, and B3.X. (There already exist links between A1 and B1, B2, and B3.) That is, if B1.X, B2.X, and B3.X are all True, then A1.Y should also be True; otherwise, A1.Y should be False.

If these were Java objects I could do this in ten seconds, but in DXL I'm floundering. If anyone can give me any tips, I'd appreciate it.

Thank you! 

Edit: I should add that I need to iterate over all the objects in module A, but that the only objects in B I'll evaluate for a given object A.N are the ones for which links B --> A.N exist, though there may be an arbitrary number of those objects in B to evaluate.

Updated on 2013-07-01T19:50:45Z at 2013-07-01T19:50:45Z by spcraft
  • GregM_dxler
    GregM_dxler
    162 Posts
    ACCEPTED ANSWER

    Re: Simple inter-module boolean attribute

    ‏2013-07-02T16:12:09Z  in response to spcraft

    It's pretty easy using links.  In the following code snippet, it assumes you have your A module open in editable mode and the B module open (in any mode).  Hopefully I can figure out the blockquote.

    Object o, othero
    Module A = current
    bool otherX, Obj_Accepted
    string attr = "_Req?"
    Link l


    for o in A do {
       Obj_Accepted = true
       for l in all(o<-"*") do { //loop through all incoming links
          othero = source l
          otherX = othero.attr
          if (!otherX){
             Obj_Accepted = false
          } 
       }
       if (Obj_Accepted) {
          o.attr = true //if all true, then set object attribute true
       }
       else {
          o.attr = false
       }
    }

    Greg

    • adevicq
      adevicq
      154 Posts
      ACCEPTED ANSWER

      Re: Simple inter-module boolean attribute

      ‏2013-07-02T16:28:09Z  in response to GregM_dxler

      And to open a module from a Link you can use the following:

      Module openModuleFromLink(Link l) {
          ModuleVersion otherVersion = null
          ModName_ otherMod = null
          Module m


          otherVersion = targetVersion l
          otherMod = module(otherVersion)
          if (null otherMod || isDeleted otherMod)
             return null
          m = load(otherVersion, true)
          return m
      }

       

    • spcraft
      spcraft
      9 Posts
      ACCEPTED ANSWER

      Re: Simple inter-module boolean attribute

      ‏2013-07-05T17:16:51Z  in response to GregM_dxler

      Thank you both -- this is very helpful. It occurred to me after I posted that what I asked for was a way to iterate over the entire module, when what I actually needed was attribute DXL -- that way, if I'm not mistaken, the boolean is kept up to date without having to run the DXL every time. So I modified your script a little bit, mostly to help me keep track of what I was doing, but also to remove the outermost for loop. Your code worked as a DXL script, but when I removed the for loop and applied the remainder as attribute DXL, only the first object in a module shows any boolean value -- the rest are left blank.

      Here are the changes I made (I'm linking to test cases, hence all the "satisfied" and "met" nonsense):

      Object linkedObject, localObject

      bool linkMet, Obj_Accepted
      string localAttr, linkAttr
      Link lnk
      int inCount
       
      localAttr = "Satisfied"
      linkAttr = "Met"
      Obj_Accepted = true
      inCount = 0
      localObject = current Object
       
      for lnk in localObject <- "*" do {
         inCount++
      }
       
      if (inCount == 0) {
         Obj_Accepted = false
      }
       
      else {
         for lnk in all (localObject <- "*") do {
            linkedObject = source lnk
            linkMet = linkedObject.linkAttr
            if (!linkMet) {
               Obj_Accepted = false
               break
            }
         }
      }
       
      if (Obj_Accepted) {
         localObject.localAttr = true
      }
      else {
         localObject.localAttr = false
      }
       

      The attribute is applied for every object in the module, so I don't know why it's not running. Any ideas?

       

      Edit: Just found out that the boolean updates for any requirement I have selected when I hit F5 (though it blanks out the value for any previously selected requirement). So I'm thinking it's not a DXL problem but some piece of DOORS functionality of which I am unaware. A layout DXL column might solve this, I suppose, but those sure sound like a bad idea...

      Updated on 2013-07-05T19:37:54Z at 2013-07-05T19:37:54Z by spcraft
      • GregM_dxler
        GregM_dxler
        162 Posts
        ACCEPTED ANSWER

        Re: Simple inter-module boolean attribute

        ‏2013-07-08T13:24:02Z  in response to spcraft

        A DXL attribute will not automatically update. That is the main difference between a layout dxl and a dxl attribute.  A layout dxl will continue to update.  On one hand, this is a benefit, on the other hand, it slows the tool down because it is always running.

        An easy way to change your program to make it a layout dxl instead is to add the following command at the end:

        display localObject.localAttr

        To use this, insert a new column that is a layout dxl with the updated program.

        Now, when the linked object is changed, the local object will get updated (it won't appear updated if it is on the screen, you have to page away and page back).  Since this program is continually running, it will also update your localAttr variable.

        Hope this helps,

        Greg

        • spcraft
          spcraft
          9 Posts
          ACCEPTED ANSWER

          Re: Simple inter-module boolean attribute

          ‏2013-07-08T16:09:09Z  in response to GregM_dxler

          I'm glad this came up, because I've been confused about this for a while. What does "automatically update" mean? Does it mean the column will update in real time, as changes come up in the linked module (i.e., without having to manually refresh)?

          Conversely, does this mean that attribute DXL never updates, or that it can only be updated manually? Can it be updated simply by opening the module? I don't need real-time updates -- having the correct values populated when the module is opened suits my purposes just fine.

          (I'm sure I could answer all these questions myself if I could get this working! :) )

          In any case, I don't think I explained myself properly. It's not that the attributes aren't updating, it's that they're not populated at all. I can select a single requirement and hit F5, and its attribute will appear, but the previously selected one will disappear -- not switch values from True to False or vice versa, but blank out completely. In other words, I only get one populated attribute at a time; all the rest in the module are blank. This says to me something is wrong in my code, but I've been fiddling and I can't for the life of me figure out what it is.

           

          EDIT: I suppose I'm just confused because the attributes aren't behaving like I expect them to. This, from the support site, is what I expect, but not how things are working:

          The values of an object's DXL attributes are automatically calculated only when the object is first displayed on your screen. Attribute DXL executes only once for every object when the module is first opened. Saving, closing and reopening the module will refresh the DXL attribute. In the DOORS GUI there is also an option to "Refresh DXL Attributes" under the TOOLS menu choice. You can also use the F5 key on your keyboard to refresh the attribute.

          Updated on 2013-07-08T17:24:08Z at 2013-07-08T17:24:08Z by spcraft
          • GregM_dxler
            GregM_dxler
            162 Posts
            ACCEPTED ANSWER

            Re: Simple inter-module boolean attribute

            ‏2013-07-08T18:23:44Z  in response to spcraft

            To get your program to work, delete the localObject = current Object line and change all remaining instances of localObject with obj.

            obj is pre-declared so it does not need to be declared.  I'm not sure why this works instead of using localObject = current.

            Greg

          • GregM_dxler
            GregM_dxler
            162 Posts
            ACCEPTED ANSWER

            Re: Simple inter-module boolean attribute

            ‏2013-07-08T18:28:22Z  in response to spcraft

            According to dxl help, dxl attribute will be calculated only the first time it is accessed.  Accessed is a little vague.  When it is displayed, it is accessed and so essentially, why you first open the module, it will be calculated.  It is not recalculated with the module open, unless you use the F5.

            Since it is not recalculated, any changes to the other module will also not be reflected.

            Hope this helps,

            Greg

            • spcraft
              spcraft
              9 Posts
              ACCEPTED ANSWER

              Re: Simple inter-module boolean attribute

              ‏2013-07-08T19:09:21Z  in response to GregM_dxler

              That works! Thank you so much, Greg -- I really appreciate you taking the time to help me out. There's a bunch more work I have to do on this project, but this really points me in the right direction.

              I do have one more question that will almost certainly come up this week. Is there a simple way to deal with only the links from a specific module, as opposed to all links? I'm guessing it's some variation in:

              for lnk in all (obj <- "*") do {

                 ...

              }

              But I'm not yet sure what to vary.

              This has been both helpful and educational. Thanks again.

              • GregM_dxler
                GregM_dxler
                162 Posts
                ACCEPTED ANSWER

                Re: Simple inter-module boolean attribute

                ‏2013-07-08T19:52:16Z  in response to spcraft

                Well, there is a couple of ways to handle this.

                1) If you only want inlinks from certain modules, only open those modules.  All other incoming links to the object from modules that are not open will not be detected.

                2) If the links are divided by different link modules (for example, you want to only look at inlinks from test modules that use test links link module and not code inlinkes from code link module), you can change the loop to <-"test links" instead of <-"*" where "test links" is the name of the link module used for the test links.

                3) Inside the link loop, get the source module name and skip it if it is not the applicable source module.  The code for this would be something like this:

                otherModName = fullName(source l)

                if (otherModName != "Wanted Module") continue //not right module so skip this link and go to the next link

                Greg

                • spcraft
                  spcraft
                  9 Posts
                  ACCEPTED ANSWER

                  Re: Simple inter-module boolean attribute

                  ‏2013-07-08T20:01:55Z  in response to GregM_dxler

                  I never thought to try something as simple as don't open the module. Ah, learning.

                  Thanks again!