2 // File : SALOMEDS_Client.cxx
3 // Created : Wed Nov 28 16:20:25 2001
4 // Author : Yves FRICAUD
8 // Copyright : Open CASCADE 2001
11 #include <SALOMEconfig.h>
12 #include CORBA_SERVER_HEADER(SALOMEDS)
13 #include "SALOMEDS_StudyManager_i.hxx"
14 #include "utilities.h"
15 #include "SALOMEDS_AttributeName_i.hxx"
17 //============================================================================
21 //============================================================================
22 static void DumpComponent(SALOMEDS::Study_ptr Study,SALOMEDS::SObject_ptr SO,Standard_Integer offset) {
23 SALOMEDS::SObject_var RefSO;
24 SALOMEDS::ChildIterator_var it = Study->NewChildIterator(SO);
25 for (; it->More();it->Next()){
26 SALOMEDS::SObject_var CSO= it->Value();
27 SALOMEDS::GenericAttribute_var anAttr;
28 if (CSO->FindAttribute(anAttr,"AttributeName"))
30 SALOMEDS::AttributeName_var Name = SALOMEDS::AttributeName::_narrow(anAttr);
31 CORBA::String_var Val = Name->Value();
32 for (Standard_Integer i = 1; i <= offset ; i++)
34 MESSAGE(">"<<CSO->GetID()<<Val);
36 if (CSO->ReferencedObject(RefSO)) {
37 for (Standard_Integer i = 1; i <= offset ; i++)
39 MESSAGE("*Reference"<<RefSO->GetID());
41 DumpComponent(Study,CSO,offset+2);
45 //============================================================================
49 //============================================================================
50 static void DumpStudy (SALOMEDS::Study_ptr Study) {
51 MESSAGE("Explore Study and Write name of each object if it exists");
53 Standard_CString name;
54 SALOMEDS::SComponentIterator_var itcomp = Study->NewComponentIterator();
55 Standard_Integer offset = 1;
56 for (; itcomp->More(); itcomp->Next()) {
57 SALOMEDS::SComponent_var SC = itcomp->Value();
58 name = SC->ComponentDataType();
59 MESSAGE("-> ComponentDataType is "<<name);
60 DumpComponent(Study,SC,offset);
64 //============================================================================
68 //============================================================================
69 static void Test(SALOMEDS::StudyManager_ptr myStudyMgr )
72 Standard_CString name;
73 MESSAGE("Create New Study Study1");
74 SALOMEDS::Study_var myStudy = myStudyMgr->NewStudy("Study1");
76 MESSAGE("Create Builder ");
77 SALOMEDS::StudyBuilder_var StudyBuild = myStudy->NewBuilder();
80 // Create new components
81 SALOMEDS::GenericAttribute_var anAttr;
82 SALOMEDS::AttributeName_var Name;
83 SALOMEDS::AttributeComment_var Comment;
84 SALOMEDS::AttributePersistentRef_var PRef;
87 MESSAGE("Add Component GEOM");
88 SALOMEDS::SComponent_var Geom = StudyBuild->NewComponent("GEOM");
89 MESSAGE("Add attribute name GEOM to component Geom");
90 anAttr = StudyBuild->FindOrCreateAttribute(Geom, "AttributeName");
91 Name = SALOMEDS::AttributeName::_narrow(anAttr);
92 Name->SetValue("Geometry");
95 MESSAGE("Add Component MESH");
96 SALOMEDS::SComponent_var Mesh = StudyBuild->NewComponent("MESH");
97 anAttr = StudyBuild->FindOrCreateAttribute(Mesh, "AttributeName");
98 Name = SALOMEDS::AttributeName::_narrow(anAttr);
99 Name->SetValue("Mesh");
105 MESSAGE("Add Object box under GEOM");
106 SALOMEDS::SObject_var box = StudyBuild->NewObject(Geom);
108 MESSAGE("Add Attribute Name in object box");
109 anAttr = StudyBuild->FindOrCreateAttribute(box, "AttributeName");
110 Name = SALOMEDS::AttributeName::_narrow(anAttr);
111 Name->SetValue("box_0");
113 MESSAGE("Add Attribute Comment in object box");
114 anAttr = StudyBuild->FindOrCreateAttribute(box, "AttributeComment");
115 Comment = SALOMEDS::AttributeComment::_narrow(anAttr);
116 Comment->SetValue("this is a box");
119 MESSAGE("Add Object mesh_box under MESH");
120 SALOMEDS::SObject_var mesh_box = StudyBuild->NewObject(Mesh);
122 MESSAGE("Add Attribute Name in object mesh_box");
123 anAttr = StudyBuild->FindOrCreateAttribute(mesh_box, "AttributeName");
124 Name = SALOMEDS::AttributeName::_narrow(anAttr);
125 Name->SetValue("mesh_box_0");
127 // Test attribute delete
128 //MESSAGE("Delete Attribute Name in object mesh_box");
129 //StudyBuild->RemoveAttribute (mesh_box,SALOMEDS::Name);
132 MESSAGE("Add Object mesh_box_face under mesh_box");
133 SALOMEDS::SObject_var mesh_box_face = StudyBuild->NewObject(mesh_box);
135 MESSAGE("Add Attribute Name in object mesh_box_face");
136 anAttr = StudyBuild->FindOrCreateAttribute(mesh_box_face, "AttributeName");
137 Name = SALOMEDS::AttributeName::_narrow(anAttr);
138 Name->SetValue("mesh_box_face_0");
140 MESSAGE("Add Reference mesh_box_face to box");
141 StudyBuild->Addreference (mesh_box_face,box);
144 MESSAGE("Add Object cylinder under GEOM");
145 SALOMEDS::SObject_var cylinder = StudyBuild->NewObject(Geom);
147 MESSAGE("Add Attribute Name in object cylinder");
148 anAttr = StudyBuild->FindOrCreateAttribute(cylinder, "AttributeName");
149 Name = SALOMEDS::AttributeName::_narrow(anAttr);
150 Name->SetValue("cylinder_0");
152 MESSAGE("Add Attribute Persistent Reference in object cylinder");
153 anAttr = StudyBuild->FindOrCreateAttribute(cylinder, "AttributePersistentRef");
154 PRef = SALOMEDS::AttributePersistentRef::_narrow(anAttr);
155 PRef->SetValue("/HDFROOT/GEOM/cylinder");
158 MESSAGE("Test Undo");
160 StudyBuild->UndoLimit(3);
161 StudyBuild->NewCommand();
162 MESSAGE("Add Object mesh_cylinder under MESH");
163 SALOMEDS::SObject_var mesh_cylinder = StudyBuild->NewObject(Mesh);
164 MESSAGE("Add Attribute Name in object mesh_cylinder");
165 anAttr = StudyBuild->FindOrCreateAttribute(mesh_cylinder, "AttributeName");
166 Name = SALOMEDS::AttributeName::_narrow(anAttr);
167 Name->SetValue("mesh_cylinder_0");
168 StudyBuild->CommitCommand();
170 MESSAGE("Test GetStudy");
171 SALOMEDS::Study_var stu = mesh_cylinder->GetStudy();
172 MESSAGE ("-> Study Name is "<<stu->Name());
177 // Study should have no trace of object mesh_cylinder
181 //myStudyMgr->Open ((char*)name);
182 //MESSAGE("Name " << name);
185 MESSAGE("GetOpenStudies list");
186 SALOMEDS::ListOfOpenStudies_var _list_open_studies = myStudyMgr->GetOpenStudies();
188 for (unsigned int ind = 0; ind < _list_open_studies->length();ind++)
190 MESSAGE("Open studies list : " << _list_open_studies[ind]);
195 SALOMEDS::Study_var myStudy1 =myStudyMgr->GetStudyByName(_list_open_studies[0]);
196 MESSAGE("GetStudyByName done");
199 myStudyMgr->SaveAs("/home/edeville/Study1.hdf",myStudy1, false);
201 // Get Persistent Reference of the study test
202 name = myStudy1->GetPersistentReference();
203 MESSAGE("Persitent Reference of the study " << name);
205 // Get Transient Reference of the study test
206 name = myStudy1->GetTransientReference();
207 MESSAGE("Transient Reference of the study " << name);
209 // FindComponent Test
210 SALOMEDS::SComponent_var compo = myStudy1->FindComponent("GEOM");
211 // Get ComponentDataType test
212 MESSAGE("Find ComponentDataType of compo");
213 name = compo->ComponentDataType();
214 MESSAGE("-> ComponentDataType is "<<name);
217 // FindComponentID Test
218 SALOMEDS::SComponent_var compo1 = myStudy1->FindComponentID("0:1:2");
219 // Get ComponentDataType test
220 MESSAGE("Find ComponentDataType of compo1");
221 name = compo1->ComponentDataType();
222 MESSAGE("-> ComponentDataType is "<<name);
225 SALOMEDS::SObject_var objn = myStudy1->FindObject("cylinder_0");
226 // Test FindAttribute function : get AttributeName attribute
227 MESSAGE("Find Name in object objn");
228 if (objn->FindAttribute(anAttr, "AttributeName")) {
229 Name = SALOMEDS::AttributeName::_narrow(anAttr);
230 CORBA::String_var Val = Name->Value();
231 MESSAGE("-> Name is "<<Val);
234 MESSAGE("-> Name is not found");
238 SALOMEDS::SObject_var obj = myStudy1->FindObjectID("0:1:2:1:1");
239 // Test FindAttribute function : get AttributeName attribute
240 MESSAGE("Find Name in object obj");
241 if (obj->FindAttribute(anAttr, "AttributeName")) {
242 Name = SALOMEDS::AttributeName::_narrow(anAttr);
243 CORBA::String_var Val = Name->Value();
244 MESSAGE("-> Name is "<<Val);
247 MESSAGE("-> Name is not found");
249 //DumpStudy(myStudy1);
253 MESSAGE( "HDFexception ! " )
257 ///////////////////////////// MAIN ///////////////////////////////////////
258 //////////////////////////////////////////////////////////////////////////
259 int main(int argc, char** argv)
262 // Initialise the ORB.
263 CORBA::ORB_var orb = CORBA::ORB_init(argc, argv, "omniORB3");
267 // Obtain a reference to the root POA.
268 CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
269 PortableServer::POA_var poa = PortableServer::POA::_narrow(obj);
271 SALOME_NamingService * salomens = new SALOME_NamingService(orb);
273 MESSAGE("Find StudyManager ");
274 CORBA::Object_ptr obj2 = salomens->Resolve("myStudyManager");
275 SALOMEDS::StudyManager_var myStudyMgr = SALOMEDS::StudyManager::_narrow(obj2);
277 // Obtain a POAManager, and tell the POA to start accepting
278 // requests on its objects.
279 PortableServer::POAManager_var pman = poa->the_POAManager();
282 // Test basic services
288 catch(CORBA::SystemException&) {
289 MESSAGE("Caught CORBA::SystemException." )
291 catch(CORBA::Exception&) {
292 MESSAGE( "Caught CORBA::Exception." )
294 catch(omniORB::fatalException& fe) {
295 MESSAGE( "Caught omniORB::fatalException:" )
296 MESSAGE( " file: " << fe.file() )
297 MESSAGE( " line: " << fe.line() )
298 MESSAGE( " mesg: " << fe.errmsg() )
301 MESSAGE( "Caught unknown exception." )