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 <SALOMEconfig.h>
30 #include CORBA_SERVER_HEADER(SALOMEDS)
31 #include "SALOMEDS_StudyManager_i.hxx"
32 #include "SALOMEDS_AttributeName_i.hxx"
33 #include "utilities.h"
38 //============================================================================
42 //============================================================================
43 static void DumpComponent(SALOMEDS::Study_ptr Study,SALOMEDS::SObject_ptr SO,Standard_Integer offset) {
44 SALOMEDS::SObject_var RefSO;
45 SALOMEDS::ChildIterator_var it = Study->NewChildIterator(SO);
46 for (; it->More();it->Next()){
47 SALOMEDS::SObject_var CSO= it->Value();
48 SALOMEDS::GenericAttribute_var anAttr;
49 if (CSO->FindAttribute(anAttr,"AttributeName"))
51 SALOMEDS::AttributeName_var Name = SALOMEDS::AttributeName::_narrow(anAttr);
52 CORBA::String_var Val = Name->Value();
53 for (Standard_Integer i = 1; i <= offset ; i++)
55 MESSAGE(">"<<CSO->GetID()<<Val);
57 if (CSO->ReferencedObject(RefSO)) {
58 for (Standard_Integer i = 1; i <= offset ; i++)
60 MESSAGE("*Reference"<<RefSO->GetID());
62 DumpComponent(Study,CSO,offset+2);
66 //============================================================================
70 //============================================================================
71 static void DumpStudy (SALOMEDS::Study_ptr Study) {
72 MESSAGE("Explore Study and Write name of each object if it exists");
74 Standard_CString name;
75 SALOMEDS::SComponentIterator_var itcomp = Study->NewComponentIterator();
76 Standard_Integer offset = 1;
77 for (; itcomp->More(); itcomp->Next()) {
78 SALOMEDS::SComponent_var SC = itcomp->Value();
79 name = SC->ComponentDataType();
80 MESSAGE("-> ComponentDataType is "<<name);
81 DumpComponent(Study,SC,offset);
85 //============================================================================
89 //============================================================================
90 static void Test(SALOMEDS::StudyManager_ptr myStudyMgr )
93 Standard_CString name;
94 MESSAGE("Create New Study Study1");
95 SALOMEDS::Study_var myStudy = myStudyMgr->NewStudy("Study1");
97 MESSAGE("Create Builder ");
98 SALOMEDS::StudyBuilder_var StudyBuild = myStudy->NewBuilder();
101 // Create new components
102 SALOMEDS::GenericAttribute_var anAttr;
103 SALOMEDS::AttributeName_var Name;
104 SALOMEDS::AttributeComment_var Comment;
105 SALOMEDS::AttributePersistentRef_var PRef;
108 MESSAGE("Add Component GEOM");
109 SALOMEDS::SComponent_var Geom = StudyBuild->NewComponent("GEOM");
110 MESSAGE("Add attribute name GEOM to component Geom");
111 anAttr = StudyBuild->FindOrCreateAttribute(Geom, "AttributeName");
112 Name = SALOMEDS::AttributeName::_narrow(anAttr);
113 Name->SetValue("Geometry");
116 MESSAGE("Add Component MESH");
117 SALOMEDS::SComponent_var Mesh = StudyBuild->NewComponent("MESH");
118 anAttr = StudyBuild->FindOrCreateAttribute(Mesh, "AttributeName");
119 Name = SALOMEDS::AttributeName::_narrow(anAttr);
120 Name->SetValue("Mesh");
126 MESSAGE("Add Object box under GEOM");
127 SALOMEDS::SObject_var box = StudyBuild->NewObject(Geom);
129 MESSAGE("Add Attribute Name in object box");
130 anAttr = StudyBuild->FindOrCreateAttribute(box, "AttributeName");
131 Name = SALOMEDS::AttributeName::_narrow(anAttr);
132 Name->SetValue("box_0");
134 MESSAGE("Add Attribute Comment in object box");
135 anAttr = StudyBuild->FindOrCreateAttribute(box, "AttributeComment");
136 Comment = SALOMEDS::AttributeComment::_narrow(anAttr);
137 Comment->SetValue("this is a box");
140 MESSAGE("Add Object mesh_box under MESH");
141 SALOMEDS::SObject_var mesh_box = StudyBuild->NewObject(Mesh);
143 MESSAGE("Add Attribute Name in object mesh_box");
144 anAttr = StudyBuild->FindOrCreateAttribute(mesh_box, "AttributeName");
145 Name = SALOMEDS::AttributeName::_narrow(anAttr);
146 Name->SetValue("mesh_box_0");
148 // Test attribute delete
149 //MESSAGE("Delete Attribute Name in object mesh_box");
150 //StudyBuild->RemoveAttribute (mesh_box,SALOMEDS::Name);
153 MESSAGE("Add Object mesh_box_face under mesh_box");
154 SALOMEDS::SObject_var mesh_box_face = StudyBuild->NewObject(mesh_box);
156 MESSAGE("Add Attribute Name in object mesh_box_face");
157 anAttr = StudyBuild->FindOrCreateAttribute(mesh_box_face, "AttributeName");
158 Name = SALOMEDS::AttributeName::_narrow(anAttr);
159 Name->SetValue("mesh_box_face_0");
161 MESSAGE("Add Reference mesh_box_face to box");
162 StudyBuild->Addreference (mesh_box_face,box);
165 MESSAGE("Add Object cylinder under GEOM");
166 SALOMEDS::SObject_var cylinder = StudyBuild->NewObject(Geom);
168 MESSAGE("Add Attribute Name in object cylinder");
169 anAttr = StudyBuild->FindOrCreateAttribute(cylinder, "AttributeName");
170 Name = SALOMEDS::AttributeName::_narrow(anAttr);
171 Name->SetValue("cylinder_0");
173 MESSAGE("Add Attribute Persistent Reference in object cylinder");
174 anAttr = StudyBuild->FindOrCreateAttribute(cylinder, "AttributePersistentRef");
175 PRef = SALOMEDS::AttributePersistentRef::_narrow(anAttr);
176 PRef->SetValue("/HDFROOT/GEOM/cylinder");
179 MESSAGE("Test Undo");
181 StudyBuild->UndoLimit(3);
182 StudyBuild->NewCommand();
183 MESSAGE("Add Object mesh_cylinder under MESH");
184 SALOMEDS::SObject_var mesh_cylinder = StudyBuild->NewObject(Mesh);
185 MESSAGE("Add Attribute Name in object mesh_cylinder");
186 anAttr = StudyBuild->FindOrCreateAttribute(mesh_cylinder, "AttributeName");
187 Name = SALOMEDS::AttributeName::_narrow(anAttr);
188 Name->SetValue("mesh_cylinder_0");
189 StudyBuild->CommitCommand();
191 MESSAGE("Test GetStudy");
192 SALOMEDS::Study_var stu = mesh_cylinder->GetStudy();
193 MESSAGE ("-> Study Name is "<<stu->Name());
198 // Study should have no trace of object mesh_cylinder
202 //myStudyMgr->Open ((char*)name);
203 //MESSAGE("Name " << name);
206 MESSAGE("GetOpenStudies list");
207 SALOMEDS::ListOfOpenStudies_var _list_open_studies = myStudyMgr->GetOpenStudies();
209 for (unsigned int ind = 0; ind < _list_open_studies->length();ind++)
211 MESSAGE("Open studies list : " << _list_open_studies[ind]);
216 SALOMEDS::Study_var myStudy1 =myStudyMgr->GetStudyByName(_list_open_studies[0]);
217 MESSAGE("GetStudyByName done");
220 myStudyMgr->SaveAs("/home/edeville/Study1.hdf",myStudy1, false);
222 // Get Persistent Reference of the study test
223 name = myStudy1->GetPersistentReference();
224 MESSAGE("Persitent Reference of the study " << name);
226 // Get Transient Reference of the study test
227 name = myStudy1->GetTransientReference();
228 MESSAGE("Transient Reference of the study " << name);
230 // FindComponent Test
231 SALOMEDS::SComponent_var compo = myStudy1->FindComponent("GEOM");
232 // Get ComponentDataType test
233 MESSAGE("Find ComponentDataType of compo");
234 name = compo->ComponentDataType();
235 MESSAGE("-> ComponentDataType is "<<name);
238 // FindComponentID Test
239 SALOMEDS::SComponent_var compo1 = myStudy1->FindComponentID("0:1:2");
240 // Get ComponentDataType test
241 MESSAGE("Find ComponentDataType of compo1");
242 name = compo1->ComponentDataType();
243 MESSAGE("-> ComponentDataType is "<<name);
246 SALOMEDS::SObject_var objn = myStudy1->FindObject("cylinder_0");
247 // Test FindAttribute function : get AttributeName attribute
248 MESSAGE("Find Name in object objn");
249 if (objn->FindAttribute(anAttr, "AttributeName")) {
250 Name = SALOMEDS::AttributeName::_narrow(anAttr);
251 CORBA::String_var Val = Name->Value();
252 MESSAGE("-> Name is "<<Val);
255 MESSAGE("-> Name is not found");
259 SALOMEDS::SObject_var obj = myStudy1->FindObjectID("0:1:2:1:1");
260 // Test FindAttribute function : get AttributeName attribute
261 MESSAGE("Find Name in object obj");
262 if (obj->FindAttribute(anAttr, "AttributeName")) {
263 Name = SALOMEDS::AttributeName::_narrow(anAttr);
264 CORBA::String_var Val = Name->Value();
265 MESSAGE("-> Name is "<<Val);
268 MESSAGE("-> Name is not found");
270 //DumpStudy(myStudy1);
274 MESSAGE( "HDFexception ! " )
278 ///////////////////////////// MAIN ///////////////////////////////////////
279 //////////////////////////////////////////////////////////////////////////
280 int main(int argc, char** argv)
283 // Initialise the ORB.
284 #if OMNIORB_VERSION >= 4
285 CORBA::ORB_var orb = CORBA::ORB_init( argc, argv, "omniORB4" ) ;
287 CORBA::ORB_var orb = CORBA::ORB_init( argc, argv, "omniORB3" );
290 // Obtain a reference to the root POA.
291 CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
292 PortableServer::POA_var poa = PortableServer::POA::_narrow(obj);
294 SALOME_NamingService * salomens = new SALOME_NamingService(orb);
296 MESSAGE("Find StudyManager ");
297 CORBA::Object_ptr obj2 = salomens->Resolve("myStudyManager");
298 SALOMEDS::StudyManager_var myStudyMgr = SALOMEDS::StudyManager::_narrow(obj2);
300 // Obtain a POAManager, and tell the POA to start accepting
301 // requests on its objects.
302 PortableServer::POAManager_var pman = poa->the_POAManager();
305 // Test basic services
311 catch(CORBA::SystemException&) {
312 MESSAGE("Caught CORBA::SystemException." )
314 catch(CORBA::Exception&) {
315 MESSAGE( "Caught CORBA::Exception." )
317 catch(omniORB::fatalException& fe) {
318 MESSAGE( "Caught omniORB::fatalException:" )
319 MESSAGE( " file: " << fe.file() )
320 MESSAGE( " line: " << fe.line() )
321 MESSAGE( " mesg: " << fe.errmsg() )
324 MESSAGE( "Caught unknown exception." )