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
22 // SALOME SALOMEDS : data structure of SALOME and sources of Salome data server
23 // File : SALOMEDS_Client.cxx
24 // Author : Yves FRICAUD
28 #include <SALOMEconfig.h>
29 #include CORBA_SERVER_HEADER(SALOMEDS)
30 #include "SALOMEDS_StudyManager_i.hxx"
31 #include "SALOMEDS_AttributeName_i.hxx"
32 #include "utilities.h"
37 //============================================================================
41 //============================================================================
42 static void DumpComponent(SALOMEDS::Study_ptr Study,SALOMEDS::SObject_ptr SO, int offset) {
43 SALOMEDS::SObject_var RefSO;
44 SALOMEDS::ChildIterator_var it = Study->NewChildIterator(SO);
45 for (; it->More();it->Next()){
46 SALOMEDS::SObject_var CSO= it->Value();
47 SALOMEDS::GenericAttribute_var anAttr;
48 if (CSO->FindAttribute(anAttr,"AttributeName"))
50 SALOMEDS::AttributeName_var Name = SALOMEDS::AttributeName::_narrow(anAttr);
51 CORBA::String_var Val = Name->Value();
52 for (int i = 1; i <= offset ; i++)
54 MESSAGE(">"<<CSO->GetID()<<Val);
56 if (CSO->ReferencedObject(RefSO)) {
57 for (int i = 1; i <= offset ; i++)
59 MESSAGE("*Reference"<<RefSO->GetID());
61 DumpComponent(Study,CSO,offset+2);
65 //============================================================================
69 //============================================================================
70 static void DumpStudy (SALOMEDS::Study_ptr Study) {
71 MESSAGE("Explore Study and Write name of each object if it exists");
74 SALOMEDS::SComponentIterator_var itcomp = Study->NewComponentIterator();
76 for (; itcomp->More(); itcomp->Next()) {
77 SALOMEDS::SComponent_var SC = itcomp->Value();
78 name = SC->ComponentDataType();
79 MESSAGE("-> ComponentDataType is "<<name);
80 DumpComponent(Study,SC,offset);
84 //============================================================================
88 //============================================================================
89 static void Test(SALOMEDS::StudyManager_ptr myStudyMgr )
93 MESSAGE("Create New Study Study1");
94 SALOMEDS::Study_var myStudy = myStudyMgr->NewStudy("Study1");
96 MESSAGE("Create Builder ");
97 SALOMEDS::StudyBuilder_var StudyBuild = myStudy->NewBuilder();
100 // Create new components
101 SALOMEDS::GenericAttribute_var anAttr;
102 SALOMEDS::AttributeName_var Name;
103 SALOMEDS::AttributeComment_var Comment;
104 SALOMEDS::AttributePersistentRef_var PRef;
107 MESSAGE("Add Component GEOM");
108 SALOMEDS::SComponent_var Geom = StudyBuild->NewComponent("GEOM");
109 MESSAGE("Add attribute name GEOM to component Geom");
110 anAttr = StudyBuild->FindOrCreateAttribute(Geom, "AttributeName");
111 Name = SALOMEDS::AttributeName::_narrow(anAttr);
112 Name->SetValue("Geometry");
115 MESSAGE("Add Component MESH");
116 SALOMEDS::SComponent_var Mesh = StudyBuild->NewComponent("MESH");
117 anAttr = StudyBuild->FindOrCreateAttribute(Mesh, "AttributeName");
118 Name = SALOMEDS::AttributeName::_narrow(anAttr);
119 Name->SetValue("Mesh");
125 MESSAGE("Add Object box under GEOM");
126 SALOMEDS::SObject_var box = StudyBuild->NewObject(Geom);
128 MESSAGE("Add Attribute Name in object box");
129 anAttr = StudyBuild->FindOrCreateAttribute(box, "AttributeName");
130 Name = SALOMEDS::AttributeName::_narrow(anAttr);
131 Name->SetValue("box_0");
133 MESSAGE("Add Attribute Comment in object box");
134 anAttr = StudyBuild->FindOrCreateAttribute(box, "AttributeComment");
135 Comment = SALOMEDS::AttributeComment::_narrow(anAttr);
136 Comment->SetValue("this is a box");
139 MESSAGE("Add Object mesh_box under MESH");
140 SALOMEDS::SObject_var mesh_box = StudyBuild->NewObject(Mesh);
142 MESSAGE("Add Attribute Name in object mesh_box");
143 anAttr = StudyBuild->FindOrCreateAttribute(mesh_box, "AttributeName");
144 Name = SALOMEDS::AttributeName::_narrow(anAttr);
145 Name->SetValue("mesh_box_0");
147 // Test attribute delete
148 //MESSAGE("Delete Attribute Name in object mesh_box");
149 //StudyBuild->RemoveAttribute (mesh_box,SALOMEDS::Name);
152 MESSAGE("Add Object mesh_box_face under mesh_box");
153 SALOMEDS::SObject_var mesh_box_face = StudyBuild->NewObject(mesh_box);
155 MESSAGE("Add Attribute Name in object mesh_box_face");
156 anAttr = StudyBuild->FindOrCreateAttribute(mesh_box_face, "AttributeName");
157 Name = SALOMEDS::AttributeName::_narrow(anAttr);
158 Name->SetValue("mesh_box_face_0");
160 MESSAGE("Add Reference mesh_box_face to box");
161 StudyBuild->Addreference (mesh_box_face,box);
164 MESSAGE("Add Object cylinder under GEOM");
165 SALOMEDS::SObject_var cylinder = StudyBuild->NewObject(Geom);
167 MESSAGE("Add Attribute Name in object cylinder");
168 anAttr = StudyBuild->FindOrCreateAttribute(cylinder, "AttributeName");
169 Name = SALOMEDS::AttributeName::_narrow(anAttr);
170 Name->SetValue("cylinder_0");
172 MESSAGE("Add Attribute Persistent Reference in object cylinder");
173 anAttr = StudyBuild->FindOrCreateAttribute(cylinder, "AttributePersistentRef");
174 PRef = SALOMEDS::AttributePersistentRef::_narrow(anAttr);
175 PRef->SetValue("/HDFROOT/GEOM/cylinder");
178 MESSAGE("Test Undo");
180 StudyBuild->UndoLimit(3);
181 StudyBuild->NewCommand();
182 MESSAGE("Add Object mesh_cylinder under MESH");
183 SALOMEDS::SObject_var mesh_cylinder = StudyBuild->NewObject(Mesh);
184 MESSAGE("Add Attribute Name in object mesh_cylinder");
185 anAttr = StudyBuild->FindOrCreateAttribute(mesh_cylinder, "AttributeName");
186 Name = SALOMEDS::AttributeName::_narrow(anAttr);
187 Name->SetValue("mesh_cylinder_0");
188 StudyBuild->CommitCommand();
190 MESSAGE("Test GetStudy");
191 SALOMEDS::Study_var stu = mesh_cylinder->GetStudy();
192 MESSAGE ("-> Study Name is "<<stu->Name());
197 // Study should have no trace of object mesh_cylinder
201 //myStudyMgr->Open ((char*)name);
202 //MESSAGE("Name " << name);
205 MESSAGE("GetOpenStudies list");
206 SALOMEDS::ListOfOpenStudies_var _list_open_studies = myStudyMgr->GetOpenStudies();
208 for (unsigned int ind = 0; ind < _list_open_studies->length();ind++)
210 MESSAGE("Open studies list : " << _list_open_studies[ind]);
215 SALOMEDS::Study_var myStudy1 =myStudyMgr->GetStudyByName(_list_open_studies[0]);
216 MESSAGE("GetStudyByName done");
219 myStudyMgr->SaveAs("/home/edeville/Study1.hdf",myStudy1, false);
221 // Get Persistent Reference of the study test
222 name = myStudy1->GetPersistentReference();
223 MESSAGE("Persitent Reference of the study " << name);
225 // Get Transient Reference of the study test
226 name = myStudy1->GetTransientReference();
227 MESSAGE("Transient Reference of the study " << name);
229 // FindComponent Test
230 SALOMEDS::SComponent_var compo = myStudy1->FindComponent("GEOM");
231 // Get ComponentDataType test
232 MESSAGE("Find ComponentDataType of compo");
233 name = compo->ComponentDataType();
234 MESSAGE("-> ComponentDataType is "<<name);
237 // FindComponentID Test
238 SALOMEDS::SComponent_var compo1 = myStudy1->FindComponentID("0:1:2");
239 // Get ComponentDataType test
240 MESSAGE("Find ComponentDataType of compo1");
241 name = compo1->ComponentDataType();
242 MESSAGE("-> ComponentDataType is "<<name);
245 SALOMEDS::SObject_var objn = myStudy1->FindObject("cylinder_0");
246 // Test FindAttribute function : get AttributeName attribute
247 MESSAGE("Find Name in object objn");
248 if (objn->FindAttribute(anAttr, "AttributeName")) {
249 Name = SALOMEDS::AttributeName::_narrow(anAttr);
250 CORBA::String_var Val = Name->Value();
251 MESSAGE("-> Name is "<<Val);
254 MESSAGE("-> Name is not found");
258 SALOMEDS::SObject_var obj = myStudy1->FindObjectID("0:1:2:1:1");
259 // Test FindAttribute function : get AttributeName attribute
260 MESSAGE("Find Name in object obj");
261 if (obj->FindAttribute(anAttr, "AttributeName")) {
262 Name = SALOMEDS::AttributeName::_narrow(anAttr);
263 CORBA::String_var Val = Name->Value();
264 MESSAGE("-> Name is "<<Val);
267 MESSAGE("-> Name is not found");
269 //DumpStudy(myStudy1);
273 MESSAGE( "HDFexception ! " )
277 ///////////////////////////// MAIN ///////////////////////////////////////
278 //////////////////////////////////////////////////////////////////////////
279 int main(int argc, char** argv)
282 // Initialise the ORB.
283 #if OMNIORB_VERSION >= 4
284 CORBA::ORB_var orb = CORBA::ORB_init( argc, argv, "omniORB4" ) ;
286 CORBA::ORB_var orb = CORBA::ORB_init( argc, argv, "omniORB3" );
289 // Obtain a reference to the root POA.
290 CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
291 PortableServer::POA_var poa = PortableServer::POA::_narrow(obj);
293 SALOME_NamingService * salomens = new SALOME_NamingService(orb);
295 MESSAGE("Find StudyManager ");
296 CORBA::Object_ptr obj2 = salomens->Resolve("myStudyManager");
297 SALOMEDS::StudyManager_var myStudyMgr = SALOMEDS::StudyManager::_narrow(obj2);
299 // Obtain a POAManager, and tell the POA to start accepting
300 // requests on its objects.
301 PortableServer::POAManager_var pman = poa->the_POAManager();
304 // Test basic services
310 catch(CORBA::SystemException&) {
311 MESSAGE("Caught CORBA::SystemException." )
313 catch(CORBA::Exception&) {
314 MESSAGE( "Caught CORBA::Exception." )
316 catch(omniORB::fatalException& fe) {
317 MESSAGE( "Caught omniORB::fatalException:" )
318 MESSAGE( " file: " << fe.file() )
319 MESSAGE( " line: " << fe.line() )
320 MESSAGE( " mesg: " << fe.errmsg() )
323 MESSAGE( "Caught unknown exception." )