#%AttributeTextColor interface (creations/saving/restoring)%
#%SALOMEDS methods : FindOrCreateAttribute, SaveAs, FindComponent, FindAttribute, Open%
#%Attribute methods : SetTextColor  TextColor%


#--------------------------------------------------------------------------
#              create    AttributeTextColor
#===========================================================
import SALOMEDS_Attributes_idl
color = SALOMEDS_Attributes_idl._0_SALOMEDS.Color(234,345,231)

A = batchmode_geompy.myBuilder.FindOrCreateAttribute(batchmode_geompy.father, "AttributeTextColor")

if A == None :
        raise  RuntimeError, "Can't create AttributeTextColor attribute"
A = A._narrow(SALOMEDS.AttributeTextColor)

if A == None :
        raise  RuntimeError, "Can't create AttributeTextColor attribute"

A.SetTextColor(color)

c = A.TextColor();

if c.R != 234 or c.G != 345 or c.B != 231:
        print "Error: wrong value of AttributeTextColor"

#      save / restore study      
#============================================================
str= os.getenv("TmpDir")
if str == None:
        str = "/tmp"
file = str+"/test.hdf"

batchmode_geompy.myStudyManager.SaveAs(file, batchmode_geompy.myStudy)
openedStudy = batchmode_geompy.myStudyManager.Open(file);

if openedStudy == None:
        raise  RuntimeError, "Can't open saved study!"

father = openedStudy.FindComponent("GEOM")
if father is None:
         raise  RuntimeError, "Geom component is not found!  Wrong study is opened." 


#       find   AttributeTextColor
#============================================================

res,A=father.FindAttribute("AttributeTextColor")
if res == 0 or A == None:
        raise  RuntimeError, "Error:  not found AttributeTextColor"

A = A._narrow(SALOMEDS.AttributeTextColor)

if A == None :
        raise  RuntimeError, "Can't create AttributeTextColor attribute"

c = A.TextColor();
if c.R != 234 or c.G != 345 or c.B != 231:
        print "Error: wrong value of AttributeTextColor"