Hello community, |
Re: Default Attribues Value
I don't think you can do it with the GUI, but you can find such obj-attr values using:
Module mod = current
string NameAttr = "MyDefaultedAttr"
AttrDef ad = find(mod, NameAttr)
if (! ad.defval)
{ infoBox(NameAttr " has no default value")
halt
}
string ValueDefault = ad.defval "",
ValueCurr
Object obj
for obj in entire (current Module) do
{ ValueCurr = obj.NameAttr
if (ValueCurr == ValueDefault and
hasSpecificValue(obj, ad))
print (identifier(obj)) "\tHas explicit value '" ValueCurr "'\n"
}
|
Re: Default Attribues Value
I tried to print the value and the default value of a module attribute "XYZ" (of type text) in all the formal modules of the current project.
Module m
AttrDef ad
string attrName = "XYZ"
for m in current Project do
{
if( (!null m) && (type(m) == "Formal") )
{
print("\n" m."Name" "\n")
for ad in m do
{
if (ad.module)
{
if(ad.name "" == attrName)
{
if(hasSpecificValue(m, ad))
print "\t" (ad.name) ": " m.(ad.name) "\n"
else
print "\t" (ad.name) ": " "Has No Specific Value!\n"
if(ad.defval)
print "\tDefault Value: " ad.defval "\n"
else
print "\tDefault Value: Does Not Exist!\n"
}
}
}
}
}
|
Re: Default Attribues Value bullbala - Thu Jul 21 10:39:35 EDT 2011
I tried to print the value and the default value of a module attribute "XYZ" (of type text) in all the formal modules of the current project.
Module m
AttrDef ad
string attrName = "XYZ"
for m in current Project do
{
if( (!null m) && (type(m) == "Formal") )
{
print("\n" m."Name" "\n")
for ad in m do
{
if (ad.module)
{
if(ad.name "" == attrName)
{
if(hasSpecificValue(m, ad))
print "\t" (ad.name) ": " m.(ad.name) "\n"
else
print "\t" (ad.name) ": " "Has No Specific Value!\n"
if(ad.defval)
print "\tDefault Value: " ad.defval "\n"
else
print "\tDefault Value: Does Not Exist!\n"
}
}
}
}
}
The ambiguity daemon hit you! You need to be very careful using those x.y syntax. It is better not to embed them since most of the times the statements are ambiguous and the DXL interpreter gets the type wrong most of the time. Therefore you should do:
if(ad.defval) print "\tDefault Value: " ((ad.defval) string) "\n"
// OR:
if (ad.defval) { string s = ad.defval; print "\tDefault Value: " s "\n"
Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS
|
Re: Default Attribues Value bullbala - Thu Jul 21 10:39:35 EDT 2011
I tried to print the value and the default value of a module attribute "XYZ" (of type text) in all the formal modules of the current project.
Module m
AttrDef ad
string attrName = "XYZ"
for m in current Project do
{
if( (!null m) && (type(m) == "Formal") )
{
print("\n" m."Name" "\n")
for ad in m do
{
if (ad.module)
{
if(ad.name "" == attrName)
{
if(hasSpecificValue(m, ad))
print "\t" (ad.name) ": " m.(ad.name) "\n"
else
print "\t" (ad.name) ": " "Has No Specific Value!\n"
if(ad.defval)
print "\tDefault Value: " ad.defval "\n"
else
print "\tDefault Value: Does Not Exist!\n"
}
}
}
}
}
So many years ago reading the DXL manual for first time I was flabergasted that they used "defval" as two different valid AttrDef properties. Gads.
//********************
string fDefVal(AttrDef ad)
{ // Retrieve the default value, if any, for the attribute.
// Return null if it has no default value.
// Returns 'True' or 'False' for Booleans that have a Default.
// Programs can determine IF an attr has a default value like this:
// if (ad.defval){}
if (null ad) return("") // Bad Input
if (!ad.defval) return("") // This attr has no default value
string Results = ad.defval
return(Results)
// Note: Consider a Boolean attribute that true has a default value of False.
// Since 'ad.defval' can mean either [1] does it have a default value,
// and [2] what that default value is, testing shows DXL should do this:
// [1] >> Use [print (bool ad.defval)] or [bool IsDef = ad.defval] or [if (ad.defval)]
// [2] >> Use [print (string ad.defval)] or [string Value = ad.defval]
// This also works, but not recommended:
// AttrDef ad = find(current Module, "aBool")
// string DefVal = ad.(ADADefault_ defval)
// bool DefHas = ad.(ADABool_ defval)
// print DefVal "\t" DefHas "\n"
} // end fDefVal()
bool HasDef = ad.defval
string DefVal = ""
if (HasDef) DefVal = ad.defval
string Value = probeAttr_(m, attrName)
if (null Value)
print "\t" attrName ": " Value "\tIs Null\n"
elseif(hasSpecificValue(m, ad))
print "\t" attrName ": " Value "\tIs Specific\n"
elseif(Value == DefVal)
print "\t" attrName ": " Value "\tIs Defaulted\n"
else print "\t" attrName ": " Value "\tIs Inherited\n"
|
Re: Default Attribues Value llandale - Thu Jul 21 15:41:53 EDT 2011
So many years ago reading the DXL manual for first time I was flabergasted that they used "defval" as two different valid AttrDef properties. Gads.
//********************
string fDefVal(AttrDef ad)
{ // Retrieve the default value, if any, for the attribute.
// Return null if it has no default value.
// Returns 'True' or 'False' for Booleans that have a Default.
// Programs can determine IF an attr has a default value like this:
// if (ad.defval){}
if (null ad) return("") // Bad Input
if (!ad.defval) return("") // This attr has no default value
string Results = ad.defval
return(Results)
// Note: Consider a Boolean attribute that true has a default value of False.
// Since 'ad.defval' can mean either [1] does it have a default value,
// and [2] what that default value is, testing shows DXL should do this:
// [1] >> Use [print (bool ad.defval)] or [bool IsDef = ad.defval] or [if (ad.defval)]
// [2] >> Use [print (string ad.defval)] or [string Value = ad.defval]
// This also works, but not recommended:
// AttrDef ad = find(current Module, "aBool")
// string DefVal = ad.(ADADefault_ defval)
// bool DefHas = ad.(ADABool_ defval)
// print DefVal "\t" DefHas "\n"
} // end fDefVal()
bool HasDef = ad.defval
string DefVal = ""
if (HasDef) DefVal = ad.defval
string Value = probeAttr_(m, attrName)
if (null Value)
print "\t" attrName ": " Value "\tIs Null\n"
elseif(hasSpecificValue(m, ad))
print "\t" attrName ": " Value "\tIs Specific\n"
elseif(Value == DefVal)
print "\t" attrName ": " Value "\tIs Defaulted\n"
else print "\t" attrName ": " Value "\tIs Inherited\n"
Thanks so much for the great inputs. It works now :-) Louie, I used you logic above and found that for one of the modules in the current project, the module attribute "XYZ" has a value which "Is Inherited". I checked that the "Inherit" option was not enabled in that module for the attribute "XYZ". Do you know what can cause this ? |
Re: Default Attribues Value bullbala - Fri Jul 22 04:16:01 EDT 2011 Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS |
Re: Default Attribues Value Mathias Mamsch - Fri Jul 22 05:46:38 EDT 2011 Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS My module attribute's default value is of rich text. I had to strip the rich text tags away before printing ! How can Louie's code be improved to work for both rich text and non-rich text default values ? |
Re: Default Attribues Value bullbala - Fri Jul 22 05:51:14 EDT 2011 Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS |
Re: Default Attribues Value Mathias Mamsch - Fri Jul 22 06:39:46 EDT 2011 Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS But for module attributes I'd be tempted to replace the "Is Inherited" line with one that says "Impossible Error" or something like that, prompting folks to fix the DXL. |