1 // SALOME SALOMEDS : data structure of SALOME and sources of Salome data server
3 // Copyright (C) 2003 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
24 // File : SALOMEDS_Client.cxx
25 // Author : Yves FRICAUD
29 #include "utilities.h"
32 #include "SALOMEDS_StudyManager_i.hxx"
33 #include "SALOMEDS_AttributeName_i.hxx"
35 #include <SALOMEconfig.h>
36 #include CORBA_SERVER_HEADER(SALOMEDS)
40 //============================================================================
44 //============================================================================
45 static void DumpComponent(SALOMEDS::Study_ptr Study,SALOMEDS::SObject_ptr SO,Standard_Integer offset) {
46 SALOMEDS::SObject_var RefSO;
47 SALOMEDS::ChildIterator_var it = Study->NewChildIterator(SO);
48 for (; it->More();it->Next()){
49 SALOMEDS::SObject_var CSO= it->Value();
50 SALOMEDS::GenericAttribute_var anAttr;
51 if (CSO->FindAttribute(anAttr,"AttributeName"))
53 SALOMEDS::AttributeName_var Name = SALOMEDS::AttributeName::_narrow(anAttr);
54 CORBA::String_var Val = Name->Value();
55 for (Standard_Integer i = 1; i <= offset ; i++)
57 MESSAGE(">"<<CSO->GetID()<<Val);
59 if (CSO->ReferencedObject(RefSO)) {
60 for (Standard_Integer i = 1; i <= offset ; i++)
62 MESSAGE("*Reference"<<RefSO->GetID());
64 DumpComponent(Study,CSO,offset+2);
68 //============================================================================
72 //============================================================================
73 static void DumpStudy (SALOMEDS::Study_ptr Study) {
74 MESSAGE("Explore Study and Write name of each object if it exists");
76 Standard_CString name;
77 SALOMEDS::SComponentIterator_var itcomp = Study->NewComponentIterator();
78 Standard_Integer offset = 1;
79 for (; itcomp->More(); itcomp->Next()) {
80 SALOMEDS::SComponent_var SC = itcomp->Value();
81 name = SC->ComponentDataType();
82 MESSAGE("-> ComponentDataType is "<<name);
83 DumpComponent(Study,SC,offset);
87 //============================================================================
91 //============================================================================
92 static void Test(SALOMEDS::StudyManager_ptr myStudyMgr )
95 Standard_CString name;
96 MESSAGE("Create New Study Study1");
97 SALOMEDS::Study_var myStudy = myStudyMgr->NewStudy("Study1");
99 MESSAGE("Create Builder ");
100 SALOMEDS::StudyBuilder_var StudyBuild = myStudy->NewBuilder();
103 // Create new components
104 SALOMEDS::GenericAttribute_var anAttr;
105 SALOMEDS::AttributeName_var Name;
106 SALOMEDS::AttributeComment_var Comment;
107 SALOMEDS::AttributePersistentRef_var PRef;
110 MESSAGE("Add Component GEOM");
111 SALOMEDS::SComponent_var Geom = StudyBuild->NewComponent("GEOM");
112 MESSAGE("Add attribute name GEOM to component Geom");
113 anAttr = StudyBuild->FindOrCreateAttribute(Geom, "AttributeName");
114 Name = SALOMEDS::AttributeName::_narrow(anAttr);
115 Name->SetValue("Geometry");
118 MESSAGE("Add Component MESH");
119 SALOMEDS::SComponent_var Mesh = StudyBuild->NewComponent("MESH");
120 anAttr = StudyBuild->FindOrCreateAttribute(Mesh, "AttributeName");
121 Name = SALOMEDS::AttributeName::_narrow(anAttr);
122 Name->SetValue("Mesh");
128 MESSAGE("Add Object box under GEOM");
129 SALOMEDS::SObject_var box = StudyBuild->NewObject(Geom);
131 MESSAGE("Add Attribute Name in object box");
132 anAttr = StudyBuild->FindOrCreateAttribute(box, "AttributeName");
133 Name = SALOMEDS::AttributeName::_narrow(anAttr);
134 Name->SetValue("box_0");
136 MESSAGE("Add Attribute Comment in object box");
137 anAttr = StudyBuild->FindOrCreateAttribute(box, "AttributeComment");
138 Comment = SALOMEDS::AttributeComment::_narrow(anAttr);
139 Comment->SetValue("this is a box");
142 MESSAGE("Add Object mesh_box under MESH");
143 SALOMEDS::SObject_var mesh_box = StudyBuild->NewObject(Mesh);
145 MESSAGE("Add Attribute Name in object mesh_box");
146 anAttr = StudyBuild->FindOrCreateAttribute(mesh_box, "AttributeName");
147 Name = SALOMEDS::AttributeName::_narrow(anAttr);
148 Name->SetValue("mesh_box_0");
150 // Test attribute delete
151 //MESSAGE("Delete Attribute Name in object mesh_box");
152 //StudyBuild->RemoveAttribute (mesh_box,SALOMEDS::Name);
155 MESSAGE("Add Object mesh_box_face under mesh_box");
156 SALOMEDS::SObject_var mesh_box_face = StudyBuild->NewObject(mesh_box);
158 MESSAGE("Add Attribute Name in object mesh_box_face");
159 anAttr = StudyBuild->FindOrCreateAttribute(mesh_box_face, "AttributeName");
160 Name = SALOMEDS::AttributeName::_narrow(anAttr);
161 Name->SetValue("mesh_box_face_0");
163 MESSAGE("Add Reference mesh_box_face to box");
164 StudyBuild->Addreference (mesh_box_face,box);
167 MESSAGE("Add Object cylinder under GEOM");
168 SALOMEDS::SObject_var cylinder = StudyBuild->NewObject(Geom);
170 MESSAGE("Add Attribute Name in object cylinder");
171 anAttr = StudyBuild->FindOrCreateAttribute(cylinder, "AttributeName");
172 Name = SALOMEDS::AttributeName::_narrow(anAttr);
173 Name->SetValue("cylinder_0");
175 MESSAGE("Add Attribute Persistent Reference in object cylinder");
176 anAttr = StudyBuild->FindOrCreateAttribute(cylinder, "AttributePersistentRef");
177 PRef = SALOMEDS::AttributePersistentRef::_narrow(anAttr);
178 PRef->SetValue("/HDFROOT/GEOM/cylinder");
181 MESSAGE("Test Undo");
183 StudyBuild->UndoLimit(3);
184 StudyBuild->NewCommand();
185 MESSAGE("Add Object mesh_cylinder under MESH");
186 SALOMEDS::SObject_var mesh_cylinder = StudyBuild->NewObject(Mesh);
187 MESSAGE("Add Attribute Name in object mesh_cylinder");
188 anAttr = StudyBuild->FindOrCreateAttribute(mesh_cylinder, "AttributeName");
189 Name = SALOMEDS::AttributeName::_narrow(anAttr);
190 Name->SetValue("mesh_cylinder_0");
191 StudyBuild->CommitCommand();
193 MESSAGE("Test GetStudy");
194 SALOMEDS::Study_var stu = mesh_cylinder->GetStudy();
195 MESSAGE ("-> Study Name is "<<stu->Name());
200 // Study should have no trace of object mesh_cylinder
204 //myStudyMgr->Open ((char*)name);
205 //MESSAGE("Name " << name);
208 MESSAGE("GetOpenStudies list");
209 SALOMEDS::ListOfOpenStudies_var _list_open_studies = myStudyMgr->GetOpenStudies();
211 for (unsigned int ind = 0; ind < _list_open_studies->length();ind++)
213 MESSAGE("Open studies list : " << _list_open_studies[ind]);
218 SALOMEDS::Study_var myStudy1 =myStudyMgr->GetStudyByName(_list_open_studies[0]);
219 MESSAGE("GetStudyByName done");
222 myStudyMgr->SaveAs("/home/edeville/Study1.hdf",myStudy1, false);
224 // Get Persistent Reference of the study test
225 name = myStudy1->GetPersistentReference();
226 MESSAGE("Persitent Reference of the study " << name);
228 // Get Transient Reference of the study test
229 name = myStudy1->GetTransientReference();
230 MESSAGE("Transient Reference of the study " << name);
232 // FindComponent Test
233 SALOMEDS::SComponent_var compo = myStudy1->FindComponent("GEOM");
234 // Get ComponentDataType test
235 MESSAGE("Find ComponentDataType of compo");
236 name = compo->ComponentDataType();
237 MESSAGE("-> ComponentDataType is "<<name);
240 // FindComponentID Test
241 SALOMEDS::SComponent_var compo1 = myStudy1->FindComponentID("0:1:2");
242 // Get ComponentDataType test
243 MESSAGE("Find ComponentDataType of compo1");
244 name = compo1->ComponentDataType();
245 MESSAGE("-> ComponentDataType is "<<name);
248 SALOMEDS::SObject_var objn = myStudy1->FindObject("cylinder_0");
249 // Test FindAttribute function : get AttributeName attribute
250 MESSAGE("Find Name in object objn");
251 if (objn->FindAttribute(anAttr, "AttributeName")) {
252 Name = SALOMEDS::AttributeName::_narrow(anAttr);
253 CORBA::String_var Val = Name->Value();
254 MESSAGE("-> Name is "<<Val);
257 MESSAGE("-> Name is not found");
261 SALOMEDS::SObject_var obj = myStudy1->FindObjectID("0:1:2:1:1");
262 // Test FindAttribute function : get AttributeName attribute
263 MESSAGE("Find Name in object obj");
264 if (obj->FindAttribute(anAttr, "AttributeName")) {
265 Name = SALOMEDS::AttributeName::_narrow(anAttr);
266 CORBA::String_var Val = Name->Value();
267 MESSAGE("-> Name is "<<Val);
270 MESSAGE("-> Name is not found");
272 //DumpStudy(myStudy1);
276 MESSAGE( "HDFexception ! " )
280 ///////////////////////////// MAIN ///////////////////////////////////////
281 //////////////////////////////////////////////////////////////////////////
282 int main(int argc, char** argv)
285 // Initialise the ORB.
286 #if OMNIORB_VERSION >= 4
287 const char* options[][2] = { { "giopMaxMsgSize", "104857600" }, { 0, 0 } };
288 CORBA::ORB_var orb = CORBA::ORB_init( argc , argv , "omniORB4", options) ;
290 CORBA::ORB_var orb = CORBA::ORB_init(argc, argv, "omniORB3");
291 omniORB::MaxMessageSize(100 * 1024 * 1024);
294 // Obtain a reference to the root POA.
295 CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
296 PortableServer::POA_var poa = PortableServer::POA::_narrow(obj);
298 SALOME_NamingService * salomens = new SALOME_NamingService(orb);
300 MESSAGE("Find StudyManager ");
301 CORBA::Object_ptr obj2 = salomens->Resolve("myStudyManager");
302 SALOMEDS::StudyManager_var myStudyMgr = SALOMEDS::StudyManager::_narrow(obj2);
304 // Obtain a POAManager, and tell the POA to start accepting
305 // requests on its objects.
306 PortableServer::POAManager_var pman = poa->the_POAManager();
309 // Test basic services
315 catch(CORBA::SystemException&) {
316 MESSAGE("Caught CORBA::SystemException." )
318 catch(CORBA::Exception&) {
319 MESSAGE( "Caught CORBA::Exception." )
321 catch(omniORB::fatalException& fe) {
322 MESSAGE( "Caught omniORB::fatalException:" )
323 MESSAGE( " file: " << fe.file() )
324 MESSAGE( " line: " << fe.line() )
325 MESSAGE( " mesg: " << fe.errmsg() )
328 MESSAGE( "Caught unknown exception." )