]> SALOME platform Git repositories - modules/kernel.git/blob - src/SALOMEDSImpl/testDS.cxx
Salome HOME
PR: merge from branch BR_UnitTests tag mergeto_trunk_17oct05
[modules/kernel.git] / src / SALOMEDSImpl / testDS.cxx
1 //File:    testDS.cxx
2 //Author:  Sergey RUIN
3
4 #include <stdio.h>
5 #include <iostream> 
6
7 #include <TColStd_HSequenceOfTransient.hxx>
8 #include <TCollection_AsciiString.hxx>
9 #include <TDocStd_Document.hxx>
10 #include <TDF_Attribute.hxx>
11 #include <TDF_Label.hxx>
12 #include <TDF_Data.hxx>
13 #include <TDF_Tool.hxx>
14
15 #include "SALOMEDSImpl_Attributes.hxx"
16 #include "SALOMEDSImpl_StudyManager.hxx"
17 #include "SALOMEDSImpl_Study.hxx"
18 #include "SALOMEDSImpl_StudyBuilder.hxx"
19 #include "SALOMEDSImpl_SObject.hxx"
20 #include "SALOMEDSImpl_SComponent.hxx"
21 //#include "SALOMEDSImpl_.hxx"
22
23 int main (int argc, char * argv[])
24 {
25   cout << "Test started " << endl;
26
27   Handle(SALOMEDSImpl_StudyManager) aSM = new SALOMEDSImpl_StudyManager();
28   cout << "Manager is created " << endl;
29   Handle(SALOMEDSImpl_Study) aStudy = aSM->NewStudy("SRN");
30   cout << "Study with id = " << aStudy->StudyId() << " is created " << endl; 
31   Handle(SALOMEDSImpl_StudyBuilder) aBuilder = aStudy->NewBuilder();
32   cout << "StudyBuilder is created " << endl;
33   Handle(SALOMEDSImpl_SComponent) aSC = aBuilder->NewComponent("TEST");
34   cout << "New component with type " << aSC->ComponentDataType() << " is created " << endl;
35   Handle(SALOMEDSImpl_SObject) aSO = aBuilder->NewObject(aSC);
36   cout << "New SObject with  ID = " << aSO->GetID() << " is created"  << endl;
37   TCollection_AsciiString anEntry;
38   TDF_Tool::Entry(aSO->GetLabel(), anEntry);
39   cout << "An entry of newly created SO is "  << anEntry << endl;
40   Handle(SALOMEDSImpl_AttributeIOR) aIORA = SALOMEDSImpl_AttributeIOR::Set(aSO->GetLabel(), "ior1234");
41   cout << "New AttributeIOR is created, it contains " << aIORA->Value() << endl;
42   Handle(SALOMEDSImpl_GenericAttribute) ga = Handle(SALOMEDSImpl_GenericAttribute)::DownCast(aIORA);
43   cout << "Attribute has type: " << ga->Type() << " and value: " << ga->Save() << endl; 
44   cout << "Just another way to create an attribute: official one :) " << endl;
45   Handle(TDF_Attribute) aTDFAttr =  aBuilder->FindOrCreateAttribute(aSO, "AttributeName");  
46   Handle(SALOMEDSImpl_AttributeName) aRN = Handle(SALOMEDSImpl_AttributeName)::DownCast(aTDFAttr);
47   aRN->SetValue("name_attribute");
48   cout << " The type = " << aRN->Type() << endl;
49   ga = Handle(SALOMEDSImpl_GenericAttribute)::DownCast(aRN);
50   cout << "Attribute has type: " << ga->Type() << " and value: " << ga->Save() << endl;   
51   cout << "Check GetObjectPath: " << aStudy->GetObjectPath(aSO) << endl;
52   
53   Handle(SALOMEDSImpl_SObject) aSubSO = aBuilder->NewObject(aSO);
54   aTDFAttr =  aBuilder->FindOrCreateAttribute(aSubSO, "AttributeIOR");  
55   Handle(SALOMEDSImpl_AttributeIOR) aIOR2 = Handle(SALOMEDSImpl_AttributeIOR)::DownCast(aTDFAttr);
56   aIOR2->SetValue("some ior");
57   aBuilder->Addreference(aSubSO, aSO);
58   Handle(SALOMEDSImpl_SObject) aRefObject;
59   aSubSO->ReferencedObject(aRefObject);
60   cout << "Check reference : ReferencedObject is " << aRefObject->GetID() << endl;
61   cout << "Check : Remove object: " << endl;
62   aBuilder->RemoveObject(aSubSO);
63   cout << "Remove: done" << endl;
64
65   cout << "Check the attributes on SObject" << endl;
66   Handle(TColStd_HSequenceOfTransient) aSeq = aSO->GetAllAttributes();
67   for(int i = 1; i <= aSeq->Length(); i++) 
68     cout << "Found: " << Handle(SALOMEDSImpl_GenericAttribute)::DownCast(aSeq->Value(i))->Type() << endl;
69
70   cout << "Check AttributeTreeNode " << endl;
71   aTDFAttr =  aBuilder->FindOrCreateAttribute(aSO, "AttributeTreeNode");  
72   cout << Handle(SALOMEDSImpl_GenericAttribute)::DownCast(aTDFAttr)->Type() << endl;
73   cout << "Check AttributeTreeNode : done " << endl;
74
75   cout << "Test finished " << endl;    
76   return 0;
77 }
78