1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/
26 #include <TColStd_HSequenceOfTransient.hxx>
27 #include <TCollection_AsciiString.hxx>
28 #include <TDocStd_Document.hxx>
29 #include <TDF_Attribute.hxx>
30 #include <TDF_Label.hxx>
31 #include <TDF_Data.hxx>
32 #include <TDF_Tool.hxx>
34 #include "SALOMEDSImpl_Attributes.hxx"
35 #include "SALOMEDSImpl_StudyManager.hxx"
36 #include "SALOMEDSImpl_Study.hxx"
37 #include "SALOMEDSImpl_StudyBuilder.hxx"
38 #include "SALOMEDSImpl_SObject.hxx"
39 #include "SALOMEDSImpl_SComponent.hxx"
40 //#include "SALOMEDSImpl_.hxx"
42 int main (int argc, char * argv[])
44 cout << "Test started " << endl;
46 Handle(SALOMEDSImpl_StudyManager) aSM = new SALOMEDSImpl_StudyManager();
47 cout << "Manager is created " << endl;
48 Handle(SALOMEDSImpl_Study) aStudy = aSM->NewStudy("SRN");
49 cout << "Study with id = " << aStudy->StudyId() << " is created " << endl;
50 Handle(SALOMEDSImpl_StudyBuilder) aBuilder = aStudy->NewBuilder();
51 cout << "StudyBuilder is created " << endl;
52 Handle(SALOMEDSImpl_SComponent) aSC = aBuilder->NewComponent("TEST");
53 cout << "New component with type " << aSC->ComponentDataType() << " is created " << endl;
54 Handle(SALOMEDSImpl_SObject) aSO = aBuilder->NewObject(aSC);
55 cout << "New SObject with ID = " << aSO->GetID() << " is created" << endl;
56 TCollection_AsciiString anEntry;
57 TDF_Tool::Entry(aSO->GetLabel(), anEntry);
58 cout << "An entry of newly created SO is " << anEntry << endl;
59 Handle(SALOMEDSImpl_AttributeIOR) aIORA = SALOMEDSImpl_AttributeIOR::Set(aSO->GetLabel(), "ior1234");
60 cout << "New AttributeIOR is created, it contains " << aIORA->Value() << endl;
61 Handle(SALOMEDSImpl_GenericAttribute) ga = Handle(SALOMEDSImpl_GenericAttribute)::DownCast(aIORA);
62 cout << "Attribute has type: " << ga->Type() << " and value: " << ga->Save() << endl;
63 cout << "Just another way to create an attribute: official one :) " << endl;
64 Handle(TDF_Attribute) aTDFAttr = aBuilder->FindOrCreateAttribute(aSO, "AttributeName");
65 Handle(SALOMEDSImpl_AttributeName) aRN = Handle(SALOMEDSImpl_AttributeName)::DownCast(aTDFAttr);
66 aRN->SetValue("name_attribute");
67 cout << " The type = " << aRN->Type() << endl;
68 ga = Handle(SALOMEDSImpl_GenericAttribute)::DownCast(aRN);
69 cout << "Attribute has type: " << ga->Type() << " and value: " << ga->Save() << endl;
70 cout << "Check GetObjectPath: " << aStudy->GetObjectPath(aSO) << endl;
72 Handle(SALOMEDSImpl_SObject) aSubSO = aBuilder->NewObject(aSO);
73 aTDFAttr = aBuilder->FindOrCreateAttribute(aSubSO, "AttributeIOR");
74 Handle(SALOMEDSImpl_AttributeIOR) aIOR2 = Handle(SALOMEDSImpl_AttributeIOR)::DownCast(aTDFAttr);
75 aIOR2->SetValue("some ior");
76 aBuilder->Addreference(aSubSO, aSO);
77 Handle(SALOMEDSImpl_SObject) aRefObject;
78 aSubSO->ReferencedObject(aRefObject);
79 cout << "Check reference : ReferencedObject is " << aRefObject->GetID() << endl;
80 cout << "Check : Remove object: " << endl;
81 aBuilder->RemoveObject(aSubSO);
82 cout << "Remove: done" << endl;
84 cout << "Check the attributes on SObject" << endl;
85 Handle(TColStd_HSequenceOfTransient) aSeq = aSO->GetAllAttributes();
86 for(int i = 1; i <= aSeq->Length(); i++)
87 cout << "Found: " << Handle(SALOMEDSImpl_GenericAttribute)::DownCast(aSeq->Value(i))->Type() << endl;
89 cout << "Check AttributeTreeNode " << endl;
90 aTDFAttr = aBuilder->FindOrCreateAttribute(aSO, "AttributeTreeNode");
91 cout << Handle(SALOMEDSImpl_GenericAttribute)::DownCast(aTDFAttr)->Type() << endl;
92 cout << "Check AttributeTreeNode : done " << endl;
94 cout << "Test finished " << endl;