1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
30 #include "DF_Document.hxx"
31 #include "DF_Attribute.hxx"
32 #include "DF_Label.hxx"
33 #include "DF_ChildIterator.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"
42 #include "SALOMEDSImpl_UseCaseBuilder.hxx"
43 #include "SALOMEDSImpl_UseCaseIterator.hxx"
45 //#include "SALOMEDSImpl_.hxx"
49 int main (int argc, char * argv[])
51 cout << "Test started " << endl;
53 SALOMEDSImpl_StudyManager* aSM = new SALOMEDSImpl_StudyManager();
54 cout << "Manager is created " << endl;
55 SALOMEDSImpl_Study* aStudy = aSM->NewStudy("SRN");
56 cout << "Study with id = " << aStudy->StudyId() << " is created " << endl;
58 cout << "Check the study lock, locking" << endl;
59 aStudy->SetStudyLock("SRN");
60 cout << "Is study locked = " << aStudy->IsStudyLocked() << endl;
61 vector<string> ids = aStudy->GetLockerID();
62 for(int i = 0; i<ids.size(); i++)
63 cout << "Get study locker : " << ids[i] << endl;
64 aStudy->UnLockStudy("SRN");
65 cout << "Is study locked = " << aStudy->IsStudyLocked() << endl;
67 SALOMEDSImpl_StudyBuilder* aBuilder = aStudy->NewBuilder();
68 cout << "StudyBuilder is created " << endl;
69 SALOMEDSImpl_SComponent aSC = aBuilder->NewComponent("TEST");
70 cout << "New component with type " << aSC.ComponentDataType() << " is created " << endl;
71 SALOMEDSImpl_SObject aSO = aBuilder->NewObject(aSC);
72 cout << "New SObject with ID = " << aSO.GetID() << " is created" << endl;
73 cout << "An entry of newly created SO is " << aSO.GetLabel().Entry() << endl;
74 SALOMEDSImpl_AttributeIOR* aIORA = SALOMEDSImpl_AttributeIOR::Set(aSO.GetLabel(), "ior1234");
75 cout << "New AttributeIOR is created, it contains " << dynamic_cast<SALOMEDSImpl_AttributeIOR*>(aIORA)->Value() << endl;
76 cout << "Attribute has type: " << aIORA->Type() << " and value: " << aIORA->Save() << endl;
77 cout << "Just another way to create an attribute: official one :) " << endl;
78 cout << "Is SO null : " << aSO.IsNull()<< endl;
79 DF_Attribute* aTDFAttr = aBuilder->FindOrCreateAttribute(aSO, "AttributeName");
80 SALOMEDSImpl_AttributeName* aRN = dynamic_cast<SALOMEDSImpl_AttributeName*>(aTDFAttr);
81 aRN->SetValue("name_attribute");
82 cout << " The type = " << aRN->Type() << endl;
83 cout << "Attribute has type: " << aRN->Type() << " and value: " << aRN->Save() << endl;
84 cout << "Check GetObjectPath: " << aStudy->GetObjectPath(aSO) << endl;
86 SALOMEDSImpl_SObject aSubSO = aBuilder->NewObject(aSO);
87 aTDFAttr = aBuilder->FindOrCreateAttribute(aSubSO, "AttributeIOR");
88 SALOMEDSImpl_AttributeIOR* aIOR2 = dynamic_cast<SALOMEDSImpl_AttributeIOR*>(aTDFAttr);
89 aIOR2->SetValue("some ior");
90 aBuilder->Addreference(aSubSO, aSO);
91 SALOMEDSImpl_SObject aRefObject;
92 aSubSO.ReferencedObject(aRefObject);
93 cout << "Check reference : ReferencedObject is " << aRefObject.GetID() << endl;
94 cout << "Check : Remove object: " << endl;
95 aBuilder->RemoveObject(aSubSO);
96 cout << "Remove: done" << endl;
98 cout << "Try invalid attribute creation" << endl;
99 aTDFAttr = aBuilder->FindOrCreateAttribute(aSubSO, "invalid type");
100 cout << "Address of created attribute : " << aTDFAttr << endl;
102 cout << "Check AttributeUserID" << endl;
104 aTDFAttr = aBuilder->FindOrCreateAttribute(aSubSO, "AttributeUserID");
106 cout << "Attribute UserID was created succesfully : id = " << dynamic_cast<SALOMEDSImpl_AttributeUserID*>(aTDFAttr)->Value() << endl;
108 else cout << "Can't create AttributeUserID" << endl;
110 string id = "0e1c36e6-379b-4d90-ab3b-17a14310e648";
111 dynamic_cast<SALOMEDSImpl_AttributeUserID*>(aTDFAttr)->SetValue(id);
112 cout << "SetValue id = " << dynamic_cast<SALOMEDSImpl_AttributeUserID*>(aTDFAttr)->Value() << endl;
114 string id2 = "0e1c36e6-379b-4d90-ab3b-18a14310e648";
115 aTDFAttr = aBuilder->FindOrCreateAttribute(aSubSO, "AttributeUserID"+id2);
117 cout << "Attribute UserID was created succesfully : id = " << dynamic_cast<SALOMEDSImpl_AttributeUserID*>(aTDFAttr)->Value() << endl;
119 else cout << "Can't create AttributeUserID" << endl;
121 cout << "Check AttributeTreeNode " << endl;
122 aTDFAttr = aBuilder->FindOrCreateAttribute(aSO, "AttributeTreeNode");
123 cout << dynamic_cast<SALOMEDSImpl_GenericAttribute*>(aTDFAttr)->Type() << endl;
124 cout << "Check AttributeTreeNode : done " << endl;
126 aTDFAttr = aBuilder->FindOrCreateAttribute(aSO, "AttributeParameter");
127 cout << dynamic_cast<SALOMEDSImpl_GenericAttribute*>(aTDFAttr)->Type() << endl;
129 cout << "Check the attributes on SObject" << endl;
130 vector<DF_Attribute*> aSeq = aSO.GetAllAttributes();
131 for(int i = 0; i < aSeq.size(); i++)
132 cout << "Found: " << dynamic_cast<SALOMEDSImpl_GenericAttribute*>(aSeq[i])->Type() << endl;
135 cout << "Check UseCase" << endl;
136 SALOMEDSImpl_UseCaseBuilder* ucb = aStudy->GetUseCaseBuilder();
137 ucb->AddUseCase("use_case1");
138 ucb->AddUseCase("use_case2");
139 SALOMEDSImpl_UseCaseIterator ucitr = ucb->GetUseCaseIterator(SALOMEDSImpl_SObject());
141 cout << "More? : " << ucitr.More() << endl;
143 cout << "Check AttributeParameter " << endl;
145 SALOMEDSImpl_AttributeParameter* AP = dynamic_cast<SALOMEDSImpl_AttributeParameter*>(aTDFAttr);
147 cout << "AttributeParameter with type : " << AP->Type() << endl;
149 AP->SetInt("1", 123);
150 cout << "IsSet for int: " << AP->IsSet("1", PT_INTEGER) << " value : " << AP->GetInt("1") << endl;
151 //for(int i = 2; i < 5; i++) AP->SetInt(i, i*i);
153 AP->SetReal("1", 123.123);
154 cout << "IsSet for real: " << AP->IsSet("1", PT_REAL) << " value : " << AP->GetReal("1") << endl;
155 //for(int i = 2; i < 5; i++) AP->SetReal(i, 0.1);
157 AP->SetString("1", "value is 123.123!");
158 cout << "IsSet for string: " << AP->IsSet("1", PT_STRING) << " value : " << AP->GetString("1") << endl;
160 for(int i = 2; i < 5; i++) {
161 string s((double)(1.0/i));
162 cout << "Setting for " << i << " value : " << s << endl;
167 AP->SetBool("1", true);
168 cout << "IsSet for bool: " << AP->IsSet("1", PT_BOOLEAN) << " value : " << AP->GetBool("1") << endl;
169 //for(int i = 2; i < 5; i++) AP->SetBool(i, 0);
172 v.push_back(111.111);
173 v.push_back(222.22222);
174 v.push_back(333.3333333);
175 AP->SetRealArray("1", v);
176 cout << "IsSet for array: " << AP->IsSet("1", PT_REALARRAY);
177 vector<double> v2 = AP->GetRealArray("1");
179 cout << " values : ";
180 for(int i = 0; i<v2.size(); i++) cout << v2[i] << " ";
186 AP->SetRealArray("2", v);
191 AP->SetIntArray("2", vi);
194 vs.push_back("hello, ");
195 vs.push_back("world!");
196 AP->SetStrArray("3", vs);
198 string as = AP->Save();
199 cout << "AS = " << as << endl;
202 cout << "Restored string with id = 1 is: " << AP->GetString("1") << endl;
203 cout << "Restored int with id = 2 is: " << AP->GetInt("1") << endl;
204 cout << "Restored real with id = 3 is: " << AP->GetReal("1") << endl;
205 cout << "Restored bool with id = 1 is: " << AP->GetBool("1") << endl;
207 v2 = AP->GetRealArray("2");
208 cout << "Restored real array with id = 2 is: ";
209 for(int i = 0; i<v2.size(); i++) cout << v2[i] << " ";
212 vi = AP->GetIntArray("2");
213 cout << "Restored int array with id = 2 is: ";
214 for(int i = 0; i<vi.size(); i++) cout << vi[i] << " ";
217 vs = AP->GetStrArray("3");
218 cout << "Restored string array with id = 2 is: ";
219 for(int i = 0; i<vs.size(); i++) cout << vs[i] << " ";
222 cout << "Check RemoveID 1 with type PT_INTEGER" << endl;
223 AP->RemoveID("1", PT_INTEGER);
224 cout << "IsSet with id = 1, type = PT_INTEGER : " << AP->IsSet("1", PT_INTEGER) << endl;
225 cout << "Check RemoveID is done" << endl;
227 cout << "Check AttributeParameter : done" << endl;
230 SALOMEDSImpl_SComponent tst = aBuilder->NewComponent("TEST2");
231 aSO = aBuilder->NewObject(tst);
232 SALOMEDSImpl_SObject ss = aBuilder->NewObjectToTag(aSO, 3);
233 aBuilder->NewObjectToTag(ss, 1);
234 aBuilder->NewObjectToTag(ss, 3);
235 SALOMEDSImpl_SObject ss2 = aBuilder->NewObjectToTag(aSO, 2);
236 aBuilder->NewObjectToTag(ss, 2);
238 SALOMEDSImpl_ChildIterator ci=aStudy->NewChildIterator(tst);
239 for(ci.InitEx(true); ci.More(); ci.Next())
240 cout << "######## " << ci.Value().GetID() << endl;
242 DF_ChildIterator dci(tst.GetLabel(), true);
243 for(; dci.More(); dci.Next())
244 cout << "###### DF: " << dci.Value().Entry() << endl;
246 cout << "Test finished " << endl;