1 // Copyright (C) 2007-2016 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, or (at your option) any later version.
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
31 #include "DF_Document.hxx"
32 #include "DF_Attribute.hxx"
33 #include "DF_Label.hxx"
34 #include "DF_ChildIterator.hxx"
36 #include "SALOMEDSImpl_Attributes.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"
47 int main (int argc, char * argv[])
49 std::cout << "Test started " << std::endl;
51 SALOMEDSImpl_Study* aStudy = new SALOMEDSImpl_Study();
52 std::cout << "Study is created" << std::endl;
54 std::cout << "Check the study lock, locking" << std::endl;
55 aStudy->SetStudyLock("SRN");
56 std::cout << "Is study locked = " << aStudy->IsStudyLocked() << std::endl;
57 std::vector<std::string> ids = aStudy->GetLockerID();
58 for(int i = 0; i<ids.size(); i++)
59 std::cout << "Get study locker : " << ids[i] << std::endl;
60 aStudy->UnLockStudy("SRN");
61 std::cout << "Is study locked = " << aStudy->IsStudyLocked() << std::endl;
63 SALOMEDSImpl_StudyBuilder* aBuilder = aStudy->NewBuilder();
64 std::cout << "StudyBuilder is created " << std::endl;
65 SALOMEDSImpl_SComponent aSC = aBuilder->NewComponent("TEST");
66 std::cout << "New component with type " << aSC.ComponentDataType() << " is created " << std::endl;
67 SALOMEDSImpl_SObject aSO = aBuilder->NewObject(aSC);
68 std::cout << "New SObject with ID = " << aSO.GetID() << " is created" << std::endl;
69 std::cout << "An entry of newly created SO is " << aSO.GetLabel().Entry() << std::endl;
70 SALOMEDSImpl_AttributeIOR* aIORA = SALOMEDSImpl_AttributeIOR::Set(aSO.GetLabel(), "ior1234");
71 std::cout << "New AttributeIOR is created, it contains " << dynamic_cast<SALOMEDSImpl_AttributeIOR*>(aIORA)->Value() << std::endl;
72 std::cout << "Attribute has type: " << aIORA->Type() << " and value: " << aIORA->Save() << std::endl;
73 std::cout << "Just another way to create an attribute: official one :) " << std::endl;
74 std::cout << "Is SO null : " << aSO.IsNull()<< std::endl;
75 DF_Attribute* aTDFAttr = aBuilder->FindOrCreateAttribute(aSO, "AttributeName");
76 SALOMEDSImpl_AttributeName* aRN = dynamic_cast<SALOMEDSImpl_AttributeName*>(aTDFAttr);
77 aRN->SetValue("name_attribute");
78 std::cout << " The type = " << aRN->Type() << std::endl;
79 std::cout << "Attribute has type: " << aRN->Type() << " and value: " << aRN->Save() << std::endl;
80 std::cout << "Check GetObjectPath: " << aStudy->GetObjectPath(aSO) << std::endl;
82 SALOMEDSImpl_SObject aSubSO = aBuilder->NewObject(aSO);
83 aTDFAttr = aBuilder->FindOrCreateAttribute(aSubSO, "AttributeIOR");
84 SALOMEDSImpl_AttributeIOR* aIOR2 = dynamic_cast<SALOMEDSImpl_AttributeIOR*>(aTDFAttr);
85 aIOR2->SetValue("some ior");
86 aBuilder->Addreference(aSubSO, aSO);
87 SALOMEDSImpl_SObject aRefObject;
88 aSubSO.ReferencedObject(aRefObject);
89 std::cout << "Check reference : ReferencedObject is " << aRefObject.GetID() << std::endl;
90 std::cout << "Check : Remove object: " << std::endl;
91 aBuilder->RemoveObject(aSubSO);
92 std::cout << "Remove: done" << std::endl;
94 std::cout << "Try invalid attribute creation" << std::endl;
95 aTDFAttr = aBuilder->FindOrCreateAttribute(aSubSO, "invalid type");
96 std::cout << "Address of created attribute : " << aTDFAttr << std::endl;
98 std::cout << "Check AttributeUserID" << std::endl;
100 aTDFAttr = aBuilder->FindOrCreateAttribute(aSubSO, "AttributeUserID");
102 std::cout << "Attribute UserID was created succesfully : id = " << dynamic_cast<SALOMEDSImpl_AttributeUserID*>(aTDFAttr)->Value() << std::endl;
104 else std::cout << "Can't create AttributeUserID" << std::endl;
106 std::string id = "0e1c36e6-379b-4d90-ab3b-17a14310e648";
107 dynamic_cast<SALOMEDSImpl_AttributeUserID*>(aTDFAttr)->SetValue(id);
108 std::cout << "SetValue id = " << dynamic_cast<SALOMEDSImpl_AttributeUserID*>(aTDFAttr)->Value() << std::endl;
110 std::string id2 = "0e1c36e6-379b-4d90-ab3b-18a14310e648";
111 aTDFAttr = aBuilder->FindOrCreateAttribute(aSubSO, "AttributeUserID"+id2);
113 std::cout << "Attribute UserID was created succesfully : id = " << dynamic_cast<SALOMEDSImpl_AttributeUserID*>(aTDFAttr)->Value() << std::endl;
115 else std::cout << "Can't create AttributeUserID" << std::endl;
117 std::cout << "Check AttributeTreeNode " << std::endl;
118 aTDFAttr = aBuilder->FindOrCreateAttribute(aSO, "AttributeTreeNode");
119 std::cout << dynamic_cast<SALOMEDSImpl_GenericAttribute*>(aTDFAttr)->Type() << std::endl;
120 std::cout << "Check AttributeTreeNode : done " << std::endl;
122 aTDFAttr = aBuilder->FindOrCreateAttribute(aSO, "AttributeParameter");
123 std::cout << dynamic_cast<SALOMEDSImpl_GenericAttribute*>(aTDFAttr)->Type() << std::endl;
125 std::cout << "Check the attributes on SObject" << std::endl;
126 std::vector<DF_Attribute*> aSeq = aSO.GetAllAttributes();
127 for(int i = 0; i < aSeq.size(); i++)
128 std::cout << "Found: " << dynamic_cast<SALOMEDSImpl_GenericAttribute*>(aSeq[i])->Type() << std::endl;
131 std::cout << "Check UseCase" << std::endl;
132 SALOMEDSImpl_UseCaseBuilder* ucb = aStudy->GetUseCaseBuilder();
133 ucb->AddUseCase("use_case1");
134 ucb->AddUseCase("use_case2");
135 SALOMEDSImpl_UseCaseIterator ucitr = ucb->GetUseCaseIterator(SALOMEDSImpl_SObject());
137 std::cout << "More? : " << ucitr.More() << std::endl;
139 std::cout << "Check AttributeParameter " << std::endl;
141 SALOMEDSImpl_AttributeParameter* AP = dynamic_cast<SALOMEDSImpl_AttributeParameter*>(aTDFAttr);
143 std::cout << "AttributeParameter with type : " << AP->Type() << std::endl;
145 AP->SetInt("1", 123);
146 std::cout << "IsSet for int: " << AP->IsSet("1", PT_INTEGER) << " value : " << AP->GetInt("1") << std::endl;
147 //for(int i = 2; i < 5; i++) AP->SetInt(i, i*i);
149 AP->SetReal("1", 123.123);
150 std::cout << "IsSet for real: " << AP->IsSet("1", PT_REAL) << " value : " << AP->GetReal("1") << std::endl;
151 //for(int i = 2; i < 5; i++) AP->SetReal(i, 0.1);
153 AP->SetString("1", "value is 123.123!");
154 std::cout << "IsSet for string: " << AP->IsSet("1", PT_STRING) << " value : " << AP->GetString("1") << std::endl;
156 for(int i = 2; i < 5; i++) {
157 std::string s((double)(1.0/i));
158 std::cout << "Setting for " << i << " value : " << s << std::endl;
163 AP->SetBool("1", true);
164 std::cout << "IsSet for bool: " << AP->IsSet("1", PT_BOOLEAN) << " value : " << AP->GetBool("1") << std::endl;
165 //for(int i = 2; i < 5; i++) AP->SetBool(i, 0);
167 std::vector<double> v;
168 v.push_back(111.111);
169 v.push_back(222.22222);
170 v.push_back(333.3333333);
171 AP->SetRealArray("1", v);
172 std::cout << "IsSet for array: " << AP->IsSet("1", PT_REALARRAY);
173 std::vector<double> v2 = AP->GetRealArray("1");
174 std::cout.precision(10);
175 std::cout << " values : ";
176 for(int i = 0; i<v2.size(); i++) std::cout << v2[i] << " ";
177 std::cout << std::endl;
182 AP->SetRealArray("2", v);
187 AP->SetIntArray("2", vi);
189 std::vector<std::string> vs;
190 vs.push_back("hello, ");
191 vs.push_back("world!");
192 AP->SetStrArray("3", vs);
194 std::string as = AP->Save();
195 std::cout << "AS = " << as << std::endl;
198 std::cout << "Restored string with id = 1 is: " << AP->GetString("1") << std::endl;
199 std::cout << "Restored int with id = 2 is: " << AP->GetInt("1") << std::endl;
200 std::cout << "Restored real with id = 3 is: " << AP->GetReal("1") << std::endl;
201 std::cout << "Restored bool with id = 1 is: " << AP->GetBool("1") << std::endl;
203 v2 = AP->GetRealArray("2");
204 std::cout << "Restored real array with id = 2 is: ";
205 for(int i = 0; i<v2.size(); i++) std::cout << v2[i] << " ";
206 std::cout << std::endl;
208 vi = AP->GetIntArray("2");
209 std::cout << "Restored int array with id = 2 is: ";
210 for(int i = 0; i<vi.size(); i++) std::cout << vi[i] << " ";
211 std::cout << std::endl;
213 vs = AP->GetStrArray("3");
214 std::cout << "Restored string array with id = 2 is: ";
215 for(int i = 0; i<vs.size(); i++) std::cout << vs[i] << " ";
216 std::cout << std::endl;
218 std::cout << "Check RemoveID 1 with type PT_INTEGER" << std::endl;
219 AP->RemoveID("1", PT_INTEGER);
220 std::cout << "IsSet with id = 1, type = PT_INTEGER : " << AP->IsSet("1", PT_INTEGER) << std::endl;
221 std::cout << "Check RemoveID is done" << std::endl;
223 std::cout << "Check AttributeParameter : done" << std::endl;
226 SALOMEDSImpl_SComponent tst = aBuilder->NewComponent("TEST2");
227 aSO = aBuilder->NewObject(tst);
228 SALOMEDSImpl_SObject ss = aBuilder->NewObjectToTag(aSO, 3);
229 aBuilder->NewObjectToTag(ss, 1);
230 aBuilder->NewObjectToTag(ss, 3);
231 SALOMEDSImpl_SObject ss2 = aBuilder->NewObjectToTag(aSO, 2);
232 aBuilder->NewObjectToTag(ss, 2);
234 SALOMEDSImpl_ChildIterator ci=aStudy->NewChildIterator(tst);
235 for(ci.InitEx(true); ci.More(); ci.Next())
236 std::cout << "######## " << ci.Value().GetID() << std::endl;
238 DF_ChildIterator dci(tst.GetLabel(), true);
239 for(; dci.More(); dci.Next())
240 std::cout << "###### DF: " << dci.Value().Entry() << std::endl;
242 std::cout << "Test finished " << std::endl;