Layout DXL column by script

Hello everyone,

 

I adapted a script to make the baseline comparison with layout DXL (the same script in here, versionCompare). I'd like to make the task automatic, in that I want to make a script that inserts a layout DXL column, selects the baselines through a dialog box (simply with the find command) and then performs the task of the layout DXL versionCompare in the link. I can do it manually of course, but as I am new to DXL and DOORS I would like to force myself into a more "stylish" solution, to improve my knowledge and my skills with the tool. 

Do you have any tips to help me with the task above?

Thanks in advance for your suggestion

Cheers,

 

Gianluca


GianlucaPisano - Mon Apr 01 08:36:01 EDT 2019

Re: Layout DXL column by script
PekkaMakinen - Tue Apr 02 02:21:39 EDT 2019

You have such a script supplied with DOORS in your installation.  Check the DOORS DXL Library - in a DOORS module open menu item Tools / DXL Library and open "Some example programs which ....". There you find a script "Example to create a Layout DXL that shows changes to Object Text".

The DXL script itself can be viewed in your DOORS installation directory lib\dxl\example as "histcol.dxl".

Re: Layout DXL column by script
llandale - Tue Apr 02 17:02:32 EDT 2019

I've been in this situation several times, and I found it easier to just edit the DXL as you ..err.. I deployed it.  Only admins would do this and do it rarely.  One problem is coding up the code that goes into the attr-DXL; it needs to be hard coded in the dialog script file, escaping all the double-quotes and slashes, or in a separate file that your dialog script dxl reads.

The "Adjustable" or "Calibratable" attributes are at the top.  That would look like:

// MyScript.dxl compares baselines

// Change the following two variables for the specified Baseline compare
string a_NameBase_From = ""  // "Most Recent" means the latest baseline

string a_NameBase_To = ""    // "Current" means use the current Module

Having said that, I've got a fair amount of Attr-DXL that is also Layout, and it gets the "Title" of the DXL (Name of the deployed attribute or name of the column), and uses information to determine exactly what to do.  That would not work well here as the baseline names are long.
-Louie

Re: Layout DXL column by script
GianlucaPisano - Wed Apr 03 06:03:40 EDT 2019

Thanks to you both. I attach the code I did so far to better explain

/*Compare Baseline of System Requirements*/
//Script to compare two SYS.2 Baselines
DB exBox = create "System Requirements Baselines comparison"
DBE b1 = field(exBox, "SYS.2 older baseline:","",20) //put the older baseline number you want to compare
DBE b2 = field(exBox, "SYS.2 newer baseline:","",20) //put the newer baseline number you want to compare
Module m = current
void get_numbers(DB exBox) {
string s1 = get b2
string s2 = get b1
Regexp r = regexp2 "([0-9]+)\\.([0-9]+)"
if (r(s1)){
major1 = intOf s1[match 1]
minor1 = intOf s1[match 2]
}
if (r(s2)){
major2 = intOf s2[match 1]
minor2 = intOf s2[match 2]
}
print(major1"""."minor1"""\n")
print(major2"""."minor2"""\n")
string code = "#include <C:/Program Files/IBM/Rational/DOORS/9.6/lib/dxl/addins/user/versionCompare.inc>\n"//-
"int major1 = \""major1"\"\n/ //- //This part to declare variableswith baseline numbers inside the DXL layout
"int major2 = \""major2"\"\n" //-
"int minor1 = \""minor1"\"\n" //-
"int minor2 = \""minor2"\"\n" //-
"modifications(true,false,major1,minor1,"",major2,minor2,"")\n"
Column c = insert (column 2)
title(c, "System requirements baselines " major1"""."minor1"" " and " major2"""."minor2""" comparison")
width(c, 300)
justify(c, full)
dxl(c, code)
}
apply(exBox, "Get", get_numbers)
show exBox
hide exBox

The problem I have is in the declaration of the variables for the DXL code, I think. If I don't pass them in the string code, I will have a declaration error, so I have to find a way to make the function modifications able to use the major and minor numbers in input to make the comparison and put the results in the dxl column.

Sorry if the script isn't well-ordered, I wrote it in a hurry to show the issue. Sorry for mistakes as well, I have just a couple of weeks of experience withdxl.

 

Gianluca

Re: Layout DXL column by script
llandale - Wed Apr 03 22:08:09 EDT 2019

GianlucaPisano - Wed Apr 03 06:03:40 EDT 2019

Thanks to you both. I attach the code I did so far to better explain

/*Compare Baseline of System Requirements*/
//Script to compare two SYS.2 Baselines
DB exBox = create "System Requirements Baselines comparison"
DBE b1 = field(exBox, "SYS.2 older baseline:","",20) //put the older baseline number you want to compare
DBE b2 = field(exBox, "SYS.2 newer baseline:","",20) //put the newer baseline number you want to compare
Module m = current
void get_numbers(DB exBox) {
string s1 = get b2
string s2 = get b1
Regexp r = regexp2 "([0-9]+)\\.([0-9]+)"
if (r(s1)){
major1 = intOf s1[match 1]
minor1 = intOf s1[match 2]
}
if (r(s2)){
major2 = intOf s2[match 1]
minor2 = intOf s2[match 2]
}
print(major1"""."minor1"""\n")
print(major2"""."minor2"""\n")
string code = "#include <C:/Program Files/IBM/Rational/DOORS/9.6/lib/dxl/addins/user/versionCompare.inc>\n"//-
"int major1 = \""major1"\"\n/ //- //This part to declare variableswith baseline numbers inside the DXL layout
"int major2 = \""major2"\"\n" //-
"int minor1 = \""minor1"\"\n" //-
"int minor2 = \""minor2"\"\n" //-
"modifications(true,false,major1,minor1,"",major2,minor2,"")\n"
Column c = insert (column 2)
title(c, "System requirements baselines " major1"""."minor1"" " and " major2"""."minor2""" comparison")
width(c, 300)
justify(c, full)
dxl(c, code)
}
apply(exBox, "Get", get_numbers)
show exBox
hide exBox

The problem I have is in the declaration of the variables for the DXL code, I think. If I don't pass them in the string code, I will have a declaration error, so I have to find a way to make the function modifications able to use the major and minor numbers in input to make the comparison and put the results in the dxl column.

Sorry if the script isn't well-ordered, I wrote it in a hurry to show the issue. Sorry for mistakes as well, I have just a couple of weeks of experience withdxl.

 

Gianluca

Updated code in the attached.

Landale Comments
in DXL, a space character is a concatenate function.
 wrong: major1"."minor1"."
 right major1 "." minor1 "."
You forgot to declare the major/minor in the main function.
 You really should turn "autodeclare" off, its a terrible feature; and if you turn it on then
  you are forcing everybody who uses your code to turn it on also
  With DXL's overload feature, its easy to get the wrong type
  and some errors are very hard to find, like the error following:
   Examplel = "Something"
   print Example1 "\n"
    You get "Example1 not defined" error.
    1st line, Example ends with the  letter "l", comes before "m"
    2nd line, Example ends in the digit "1", comes before "2"
  or this common error:
   m = current
   for o in m do
    "o" is indeed implicitely defined, but not as an "Object".  Expect subsequent errors.
  And once in a while code that runs in one DOORS version doesn't run in another.
Baselines can have annotations.  In this example I assumed they DO, but a real program will
 need to see if that's true, probably having two regexp, one without Annotion and one with.
If you print your "code" after making it, you should see the error.
 You needed to escape the two empty strings
I'm surprised your "modifications" function doesn't accept an Object.
 Does it compare just the "obj", and end with displayRichWithColor(result)?
since "major1" et tal are integers, you don't surround their values with quotes
 wrong: "int major1 = \"" major1 "\"\n" //-
 right: "int major1 = " major1 "\n" //-
I see your matched "s1" with "b2" and "s2" with "b1".
 That was probably a mistake, but if intentional then it is plane confusing to whoever reads your code next.

You need to get your "modifications" function and insert it directly into your "code".
 As it is now, EVERYBODY who uses the view with this column will need to have
 that include file on their computer.  Yuuck.
I always stage the string part of a reqexp in a string variable and print it while debugging.
 I think it makes debugging it a lot easier, at least for me.
Ditto, print DXL code that I generate.
Use checkDXL to find interpret errors in the code, before trying to deploy it.
I think the main code should insure s1 and s2 represent actual baselines before proceeding
 You will need to cycle through the baselines of m to do that.
 That might also need "current = m" at the top of getNumbers().
I think "modifications" should just accept the baseline string (s1, s2),
 instead of breaking it apart outside and rebuilding it inside the function.
 That would do away with the awkward regexp.
DXL code thread ends with the "show(DB)" command.  Therefore your "hide exBox" line would never execute.
 If you want some dialog close function, you need to write it yourself
  void closeBox(DB dbXX)
  { hide exBox
  }
  ...
  close(exBox, true, closeBox)
 the native close function indeed hides the dialog, and I think destroy's it,
  so simple dialogs like this one don't need a special close function.
  You don't notice it running with you "close" the dialog, or "X" the window.
` Note that "realize" and "block" do NOT end the DXL thread.


Attachments

Temp.dxl

Re: Layout DXL column by script
GianlucaPisano - Thu Apr 04 06:23:09 EDT 2019

llandale - Wed Apr 03 22:08:09 EDT 2019

Updated code in the attached.

Landale Comments
in DXL, a space character is a concatenate function.
 wrong: major1"."minor1"."
 right major1 "." minor1 "."
You forgot to declare the major/minor in the main function.
 You really should turn "autodeclare" off, its a terrible feature; and if you turn it on then
  you are forcing everybody who uses your code to turn it on also
  With DXL's overload feature, its easy to get the wrong type
  and some errors are very hard to find, like the error following:
   Examplel = "Something"
   print Example1 "\n"
    You get "Example1 not defined" error.
    1st line, Example ends with the  letter "l", comes before "m"
    2nd line, Example ends in the digit "1", comes before "2"
  or this common error:
   m = current
   for o in m do
    "o" is indeed implicitely defined, but not as an "Object".  Expect subsequent errors.
  And once in a while code that runs in one DOORS version doesn't run in another.
Baselines can have annotations.  In this example I assumed they DO, but a real program will
 need to see if that's true, probably having two regexp, one without Annotion and one with.
If you print your "code" after making it, you should see the error.
 You needed to escape the two empty strings
I'm surprised your "modifications" function doesn't accept an Object.
 Does it compare just the "obj", and end with displayRichWithColor(result)?
since "major1" et tal are integers, you don't surround their values with quotes
 wrong: "int major1 = \"" major1 "\"\n" //-
 right: "int major1 = " major1 "\n" //-
I see your matched "s1" with "b2" and "s2" with "b1".
 That was probably a mistake, but if intentional then it is plane confusing to whoever reads your code next.

You need to get your "modifications" function and insert it directly into your "code".
 As it is now, EVERYBODY who uses the view with this column will need to have
 that include file on their computer.  Yuuck.
I always stage the string part of a reqexp in a string variable and print it while debugging.
 I think it makes debugging it a lot easier, at least for me.
Ditto, print DXL code that I generate.
Use checkDXL to find interpret errors in the code, before trying to deploy it.
I think the main code should insure s1 and s2 represent actual baselines before proceeding
 You will need to cycle through the baselines of m to do that.
 That might also need "current = m" at the top of getNumbers().
I think "modifications" should just accept the baseline string (s1, s2),
 instead of breaking it apart outside and rebuilding it inside the function.
 That would do away with the awkward regexp.
DXL code thread ends with the "show(DB)" command.  Therefore your "hide exBox" line would never execute.
 If you want some dialog close function, you need to write it yourself
  void closeBox(DB dbXX)
  { hide exBox
  }
  ...
  close(exBox, true, closeBox)
 the native close function indeed hides the dialog, and I think destroy's it,
  so simple dialogs like this one don't need a special close function.
  You don't notice it running with you "close" the dialog, or "X" the window.
` Note that "realize" and "block" do NOT end the DXL thread.

Thank you for your suggestions. I managed to get the script working with your suggestions.

You are right with all your observations, I wanted  a first "draft" version to  work quickly, as I have deadlines already scheduled in the near future, but I'm indeed going to improve the "code", adding also new features

Thank you very much!

 

Gianluca