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/ or email : webmaster.salome@opencascade.com
27 #include <TColStd_HSequenceOfTransient.hxx>
28 #include <TCollection_AsciiString.hxx>
29 #include <TDocStd_Document.hxx>
30 #include <TDF_Attribute.hxx>
31 #include <TDF_Label.hxx>
32 #include <TDF_Data.hxx>
33 #include <TDF_Tool.hxx>
35 #include "SALOMEDSImpl_Attributes.hxx"
36 #include "SALOMEDSImpl_StudyManager.hxx"
37 #include "SALOMEDSImpl_Study.hxx"
38 #include "SALOMEDSImpl_StudyBuilder.hxx"
39 #include "SALOMEDSImpl_SObject.hxx"
40 #include "SALOMEDSImpl_SComponent.hxx"
41 #include "SALOMEDSImpl_AttributeParameter.hxx"
43 //#include "SALOMEDSImpl_.hxx"
45 int main (int argc, char * argv[])
47 cout << "Test started " << endl;
49 Handle(SALOMEDSImpl_StudyManager) aSM = new SALOMEDSImpl_StudyManager();
50 cout << "Manager is created " << endl;
51 Handle(SALOMEDSImpl_Study) aStudy = aSM->NewStudy("SRN");
52 cout << "Study with id = " << aStudy->StudyId() << " is created " << endl;
53 Handle(SALOMEDSImpl_StudyBuilder) aBuilder = aStudy->NewBuilder();
54 cout << "StudyBuilder is created " << endl;
55 Handle(SALOMEDSImpl_SComponent) aSC = aBuilder->NewComponent("TEST");
56 cout << "New component with type " << aSC->ComponentDataType() << " is created " << endl;
57 Handle(SALOMEDSImpl_SObject) aSO = aBuilder->NewObject(aSC);
58 cout << "New SObject with ID = " << aSO->GetID() << " is created" << endl;
59 TCollection_AsciiString anEntry;
60 TDF_Tool::Entry(aSO->GetLabel(), anEntry);
61 cout << "An entry of newly created SO is " << anEntry << endl;
62 Handle(SALOMEDSImpl_AttributeIOR) aIORA = SALOMEDSImpl_AttributeIOR::Set(aSO->GetLabel(), "ior1234");
63 cout << "New AttributeIOR is created, it contains " << aIORA->Value() << endl;
64 Handle(SALOMEDSImpl_GenericAttribute) ga = Handle(SALOMEDSImpl_GenericAttribute)::DownCast(aIORA);
65 cout << "Attribute has type: " << ga->Type() << " and value: " << ga->Save() << endl;
66 cout << "Just another way to create an attribute: official one :) " << endl;
67 Handle(TDF_Attribute) aTDFAttr = aBuilder->FindOrCreateAttribute(aSO, "AttributeName");
68 Handle(SALOMEDSImpl_AttributeName) aRN = Handle(SALOMEDSImpl_AttributeName)::DownCast(aTDFAttr);
69 aRN->SetValue("name_attribute");
70 cout << " The type = " << aRN->Type() << endl;
71 ga = Handle(SALOMEDSImpl_GenericAttribute)::DownCast(aRN);
72 cout << "Attribute has type: " << ga->Type() << " and value: " << ga->Save() << endl;
73 cout << "Check GetObjectPath: " << aStudy->GetObjectPath(aSO) << endl;
75 Handle(SALOMEDSImpl_SObject) aSubSO = aBuilder->NewObject(aSO);
76 aTDFAttr = aBuilder->FindOrCreateAttribute(aSubSO, "AttributeIOR");
77 Handle(SALOMEDSImpl_AttributeIOR) aIOR2 = Handle(SALOMEDSImpl_AttributeIOR)::DownCast(aTDFAttr);
78 aIOR2->SetValue("some ior");
79 aBuilder->Addreference(aSubSO, aSO);
80 Handle(SALOMEDSImpl_SObject) aRefObject;
81 aSubSO->ReferencedObject(aRefObject);
82 cout << "Check reference : ReferencedObject is " << aRefObject->GetID() << endl;
83 cout << "Check : Remove object: " << endl;
84 aBuilder->RemoveObject(aSubSO);
85 cout << "Remove: done" << endl;
87 cout << "Check AttributeTreeNode " << endl;
88 aTDFAttr = aBuilder->FindOrCreateAttribute(aSO, "AttributeTreeNode");
89 cout << Handle(SALOMEDSImpl_GenericAttribute)::DownCast(aTDFAttr)->Type() << endl;
90 cout << "Check AttributeTreeNode : done " << endl;
92 aTDFAttr = aBuilder->FindOrCreateAttribute(aSO, "AttributeParameter");
93 cout << Handle(SALOMEDSImpl_GenericAttribute)::DownCast(aTDFAttr)->Type() << endl;
95 cout << "Check the attributes on SObject" << endl;
96 Handle(TColStd_HSequenceOfTransient) aSeq = aSO->GetAllAttributes();
97 for(int i = 1; i <= aSeq->Length(); i++)
98 cout << "Found: " << Handle(SALOMEDSImpl_GenericAttribute)::DownCast(aSeq->Value(i))->Type() << endl;
102 cout << "Check AttributeParameter " << endl;
104 Handle(SALOMEDSImpl_AttributeParameter) AP = Handle(SALOMEDSImpl_AttributeParameter)::DownCast(aTDFAttr);
106 cout << "AttributeParameter with type : " << AP->Type() << endl;
108 AP->SetInt("1", 123);
109 cout << "IsSet for int: " << AP->IsSet("1", PT_INTEGER) << " value : " << AP->GetInt("1") << endl;
110 //for(int i = 2; i < 5; i++) AP->SetInt(i, i*i);
112 AP->SetReal("1", 123.123);
113 cout << "IsSet for real: " << AP->IsSet("1", PT_REAL) << " value : " << AP->GetReal("1") << endl;
114 //for(int i = 2; i < 5; i++) AP->SetReal(i, 0.1);
116 AP->SetString("1", "value is 123.123!");
117 cout << "IsSet for string: " << AP->IsSet("1", PT_STRING) << " value : " << AP->GetString("1") << endl;
119 for(int i = 2; i < 5; i++) {
120 TCollection_AsciiString s((double)(1.0/i));
121 cout << "Setting for " << i << " value : " << s << endl;
126 AP->SetBool("1", true);
127 cout << "IsSet for bool: " << AP->IsSet("1", PT_BOOLEAN) << " value : " << AP->GetBool("1") << endl;
128 //for(int i = 2; i < 5; i++) AP->SetBool(i, 0);
131 v.push_back(111.111);
132 v.push_back(222.22222);
133 v.push_back(333.3333333);
134 AP->SetRealArray("1", v);
135 cout << "IsSet for array: " << AP->IsSet("1", PT_REALARRAY);
136 vector<double> v2 = AP->GetRealArray("1");
138 cout << " values : ";
139 for(int i = 0; i<v2.size(); i++) cout << v2[i] << " ";
145 AP->SetRealArray("2", v);
150 AP->SetIntArray("2", vi);
153 vs.push_back("hello, ");
154 vs.push_back("world!");
155 AP->SetStrArray("3", vs);
157 TCollection_AsciiString as = AP->Save();
158 cout << "AS = " << as << endl;
161 cout << "Restored string with id = 1 is: " << AP->GetString("1") << endl;
162 cout << "Restored int with id = 2 is: " << AP->GetInt("1") << endl;
163 cout << "Restored real with id = 3 is: " << AP->GetReal("1") << endl;
164 cout << "Restored bool with id = 1 is: " << AP->GetBool("1") << endl;
166 v2 = AP->GetRealArray("2");
167 cout << "Restored real array with id = 2 is: ";
168 for(int i = 0; i<v2.size(); i++) cout << v2[i] << " ";
171 vi = AP->GetIntArray("2");
172 cout << "Restored int array with id = 2 is: ";
173 for(int i = 0; i<vi.size(); i++) cout << vi[i] << " ";
176 vs = AP->GetStrArray("3");
177 cout << "Restored string array with id = 2 is: ";
178 for(int i = 0; i<vs.size(); i++) cout << vs[i] << " ";
181 cout << "Check RemoveID 1 with type PT_INTEGER" << endl;
182 AP->RemoveID("1", PT_INTEGER);
183 cout << "IsSet with id = 1, type = PT_INTEGER : " << AP->IsSet("1", PT_INTEGER) << endl;
184 cout << "Check RemoveID is done" << endl;
186 cout << "Check AttributeParameter : done" << endl;
188 cout << "Test finished " << endl;