1 // Copyright (C) 2007-2021 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
23 // SALOME SALOMEDS : data structure of SALOME and sources of Salome data server
24 // File : SALOMEDS_Client.cxx
25 // Author : Yves FRICAUD
29 #include <SALOMEconfig.h>
30 #include CORBA_SERVER_HEADER(SALOMEDS)
31 #include "SALOMEDS_AttributeName_i.hxx"
32 #include "SALOME_KernelServices.hxx"
33 #include "Basics_Utils.hxx"
34 #include "utilities.h"
37 //============================================================================
41 //============================================================================
42 static void DumpComponent(SALOMEDS::SObject_ptr SO, int offset) {
43 SALOMEDS::SObject_var RefSO;
44 SALOMEDS::ChildIterator_var it = KERNEL::getStudyServant()->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(CSO,offset+2);
65 //============================================================================
69 //============================================================================
70 static void DumpStudy() {
71 MESSAGE("Explore Study and Write name of each object if it exists");
74 SALOME_UNUSED(name); // unused in release mode
75 SALOMEDS::SComponentIterator_var itcomp = KERNEL::getStudyServant()->NewComponentIterator();
77 for (; itcomp->More(); itcomp->Next()) {
78 SALOMEDS::SComponent_var SC = itcomp->Value();
79 name = SC->ComponentDataType();
80 MESSAGE("-> ComponentDataType is "<<name);
81 DumpComponent(SC,offset);
85 //============================================================================
89 //============================================================================
94 SALOME_UNUSED(name); // unused in release mode
96 SALOMEDS::Study_var myStudy = KERNEL::getStudyServant();
98 MESSAGE("Create Builder ");
99 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();
194 // Study should have no trace of object mesh_cylinder
198 myStudy->SaveAs(Kernel_Utils::decode("/home/edeville/Study1.hdf"), false, false);
200 // Get Persistent Reference of the study test
201 name = myStudy->GetPersistentReference();
202 MESSAGE("Persitent Reference of the study " << name);
204 // FindComponent Test
205 SALOMEDS::SComponent_var compo = myStudy->FindComponent("GEOM");
206 // Get ComponentDataType test
207 MESSAGE("Find ComponentDataType of compo");
208 name = compo->ComponentDataType();
209 MESSAGE("-> ComponentDataType is "<<name);
211 // FindComponentID Test
212 SALOMEDS::SComponent_var compo1 = myStudy->FindComponentID("0:1:2");
213 // Get ComponentDataType test
214 MESSAGE("Find ComponentDataType of compo1");
215 name = compo1->ComponentDataType();
216 MESSAGE("-> ComponentDataType is "<<name);
219 SALOMEDS::SObject_var objn = myStudy->FindObject("cylinder_0");
220 // Test FindAttribute function : get AttributeName attribute
221 MESSAGE("Find Name in object objn");
222 if (objn->FindAttribute(anAttr, "AttributeName")) {
223 Name = SALOMEDS::AttributeName::_narrow(anAttr);
224 CORBA::String_var Val = Name->Value();
225 MESSAGE("-> Name is "<<Val);
228 MESSAGE("-> Name is not found");
232 SALOMEDS::SObject_var obj = myStudy->FindObjectID("0:1:2:1:1");
233 // Test FindAttribute function : get AttributeName attribute
234 MESSAGE("Find Name in object obj");
235 if (obj->FindAttribute(anAttr, "AttributeName")) {
236 Name = SALOMEDS::AttributeName::_narrow(anAttr);
237 CORBA::String_var Val = Name->Value();
238 MESSAGE("-> Name is "<<Val);
241 MESSAGE("-> Name is not found");
247 MESSAGE( "HDFexception ! " )
251 ///////////////////////////// MAIN ///////////////////////////////////////
252 //////////////////////////////////////////////////////////////////////////
253 int main(int argc, char** argv)
256 // Initialise the ORB.
257 #if OMNIORB_VERSION >= 4
258 CORBA::ORB_var orb = CORBA::ORB_init( argc, argv, "omniORB4" ) ;
260 CORBA::ORB_var orb = CORBA::ORB_init( argc, argv, "omniORB3" );
263 // Obtain a reference to the root POA.
264 CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
265 PortableServer::POA_var poa = PortableServer::POA::_narrow(obj);
267 // Obtain a POAManager, and tell the POA to start accepting
268 // requests on its objects.
269 PortableServer::POAManager_var pman = poa->the_POAManager();
272 // Test basic services
278 catch(CORBA::SystemException&) {
279 MESSAGE("Caught CORBA::SystemException." )
281 catch(CORBA::Exception&) {
282 MESSAGE( "Caught CORBA::Exception." )
284 catch(omniORB::fatalException& fe) { //!< TODO: unused variable
285 MESSAGE( "Caught omniORB::fatalException:" )
286 MESSAGE( " file: " << fe.file() )
287 MESSAGE( " line: " << fe.line() )
288 MESSAGE( " mesg: " << fe.errmsg() )
291 MESSAGE( "Caught unknown exception." )