1 // Copyright (C) 2007-2016 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 "utilities.h"
36 //============================================================================
40 //============================================================================
41 static void DumpComponent(SALOMEDS::SObject_ptr SO, int offset) {
42 SALOMEDS::SObject_var RefSO;
43 SALOMEDS::ChildIterator_var it = KERNEL::getStudy()->NewChildIterator(SO);
44 for (; it->More();it->Next()){
45 SALOMEDS::SObject_var CSO= it->Value();
46 SALOMEDS::GenericAttribute_var anAttr;
47 if (CSO->FindAttribute(anAttr,"AttributeName"))
49 SALOMEDS::AttributeName_var Name = SALOMEDS::AttributeName::_narrow(anAttr);
50 CORBA::String_var Val = Name->Value();
51 for (int i = 1; i <= offset ; i++)
53 MESSAGE(">"<<CSO->GetID()<<Val);
55 if (CSO->ReferencedObject(RefSO)) {
56 for (int i = 1; i <= offset ; i++)
58 MESSAGE("*Reference"<<RefSO->GetID());
60 DumpComponent(CSO,offset+2);
64 //============================================================================
68 //============================================================================
69 static void DumpStudy() {
70 MESSAGE("Explore Study and Write name of each object if it exists");
73 SALOMEDS::SComponentIterator_var itcomp = KERNEL::getStudy()->NewComponentIterator();
75 for (; itcomp->More(); itcomp->Next()) {
76 SALOMEDS::SComponent_var SC = itcomp->Value();
77 name = SC->ComponentDataType();
78 MESSAGE("-> ComponentDataType is "<<name);
79 DumpComponent(SC,offset);
83 //============================================================================
87 //============================================================================
93 SALOMEDS::Study_var myStudy = KERNEL::getStudy();
95 MESSAGE("Create Builder ");
96 SALOMEDS::StudyBuilder_var StudyBuild = myStudy->NewBuilder();
98 // Create new components
99 SALOMEDS::GenericAttribute_var anAttr;
100 SALOMEDS::AttributeName_var Name;
101 SALOMEDS::AttributeComment_var Comment;
102 SALOMEDS::AttributePersistentRef_var PRef;
105 MESSAGE("Add Component GEOM");
106 SALOMEDS::SComponent_var Geom = StudyBuild->NewComponent("GEOM");
107 MESSAGE("Add attribute name GEOM to component Geom");
108 anAttr = StudyBuild->FindOrCreateAttribute(Geom, "AttributeName");
109 Name = SALOMEDS::AttributeName::_narrow(anAttr);
110 Name->SetValue("Geometry");
113 MESSAGE("Add Component MESH");
114 SALOMEDS::SComponent_var Mesh = StudyBuild->NewComponent("MESH");
115 anAttr = StudyBuild->FindOrCreateAttribute(Mesh, "AttributeName");
116 Name = SALOMEDS::AttributeName::_narrow(anAttr);
117 Name->SetValue("Mesh");
123 MESSAGE("Add Object box under GEOM");
124 SALOMEDS::SObject_var box = StudyBuild->NewObject(Geom);
126 MESSAGE("Add Attribute Name in object box");
127 anAttr = StudyBuild->FindOrCreateAttribute(box, "AttributeName");
128 Name = SALOMEDS::AttributeName::_narrow(anAttr);
129 Name->SetValue("box_0");
131 MESSAGE("Add Attribute Comment in object box");
132 anAttr = StudyBuild->FindOrCreateAttribute(box, "AttributeComment");
133 Comment = SALOMEDS::AttributeComment::_narrow(anAttr);
134 Comment->SetValue("this is a box");
137 MESSAGE("Add Object mesh_box under MESH");
138 SALOMEDS::SObject_var mesh_box = StudyBuild->NewObject(Mesh);
140 MESSAGE("Add Attribute Name in object mesh_box");
141 anAttr = StudyBuild->FindOrCreateAttribute(mesh_box, "AttributeName");
142 Name = SALOMEDS::AttributeName::_narrow(anAttr);
143 Name->SetValue("mesh_box_0");
145 // Test attribute delete
146 //MESSAGE("Delete Attribute Name in object mesh_box");
147 //StudyBuild->RemoveAttribute (mesh_box,SALOMEDS::Name);
150 MESSAGE("Add Object mesh_box_face under mesh_box");
151 SALOMEDS::SObject_var mesh_box_face = StudyBuild->NewObject(mesh_box);
153 MESSAGE("Add Attribute Name in object mesh_box_face");
154 anAttr = StudyBuild->FindOrCreateAttribute(mesh_box_face, "AttributeName");
155 Name = SALOMEDS::AttributeName::_narrow(anAttr);
156 Name->SetValue("mesh_box_face_0");
158 MESSAGE("Add Reference mesh_box_face to box");
159 StudyBuild->Addreference (mesh_box_face,box);
162 MESSAGE("Add Object cylinder under GEOM");
163 SALOMEDS::SObject_var cylinder = StudyBuild->NewObject(Geom);
165 MESSAGE("Add Attribute Name in object cylinder");
166 anAttr = StudyBuild->FindOrCreateAttribute(cylinder, "AttributeName");
167 Name = SALOMEDS::AttributeName::_narrow(anAttr);
168 Name->SetValue("cylinder_0");
170 MESSAGE("Add Attribute Persistent Reference in object cylinder");
171 anAttr = StudyBuild->FindOrCreateAttribute(cylinder, "AttributePersistentRef");
172 PRef = SALOMEDS::AttributePersistentRef::_narrow(anAttr);
173 PRef->SetValue("/HDFROOT/GEOM/cylinder");
176 MESSAGE("Test Undo");
178 StudyBuild->UndoLimit(3);
179 StudyBuild->NewCommand();
180 MESSAGE("Add Object mesh_cylinder under MESH");
181 SALOMEDS::SObject_var mesh_cylinder = StudyBuild->NewObject(Mesh);
182 MESSAGE("Add Attribute Name in object mesh_cylinder");
183 anAttr = StudyBuild->FindOrCreateAttribute(mesh_cylinder, "AttributeName");
184 Name = SALOMEDS::AttributeName::_narrow(anAttr);
185 Name->SetValue("mesh_cylinder_0");
186 StudyBuild->CommitCommand();
191 // Study should have no trace of object mesh_cylinder
195 myStudy->SaveAs("/home/edeville/Study1.hdf", false, false);
197 // Get Persistent Reference of the study test
198 name = myStudy->GetPersistentReference();
199 MESSAGE("Persitent Reference of the study " << name);
201 // FindComponent Test
202 SALOMEDS::SComponent_var compo = myStudy->FindComponent("GEOM");
203 // Get ComponentDataType test
204 MESSAGE("Find ComponentDataType of compo");
205 name = compo->ComponentDataType();
206 MESSAGE("-> ComponentDataType is "<<name);
208 // FindComponentID Test
209 SALOMEDS::SComponent_var compo1 = myStudy->FindComponentID("0:1:2");
210 // Get ComponentDataType test
211 MESSAGE("Find ComponentDataType of compo1");
212 name = compo1->ComponentDataType();
213 MESSAGE("-> ComponentDataType is "<<name);
216 SALOMEDS::SObject_var objn = myStudy->FindObject("cylinder_0");
217 // Test FindAttribute function : get AttributeName attribute
218 MESSAGE("Find Name in object objn");
219 if (objn->FindAttribute(anAttr, "AttributeName")) {
220 Name = SALOMEDS::AttributeName::_narrow(anAttr);
221 CORBA::String_var Val = Name->Value();
222 MESSAGE("-> Name is "<<Val);
225 MESSAGE("-> Name is not found");
229 SALOMEDS::SObject_var obj = myStudy->FindObjectID("0:1:2:1:1");
230 // Test FindAttribute function : get AttributeName attribute
231 MESSAGE("Find Name in object obj");
232 if (obj->FindAttribute(anAttr, "AttributeName")) {
233 Name = SALOMEDS::AttributeName::_narrow(anAttr);
234 CORBA::String_var Val = Name->Value();
235 MESSAGE("-> Name is "<<Val);
238 MESSAGE("-> Name is not found");
244 MESSAGE( "HDFexception ! " )
248 ///////////////////////////// MAIN ///////////////////////////////////////
249 //////////////////////////////////////////////////////////////////////////
250 int main(int argc, char** argv)
253 // Initialise the ORB.
254 #if OMNIORB_VERSION >= 4
255 CORBA::ORB_var orb = CORBA::ORB_init( argc, argv, "omniORB4" ) ;
257 CORBA::ORB_var orb = CORBA::ORB_init( argc, argv, "omniORB3" );
260 // Obtain a reference to the root POA.
261 CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
262 PortableServer::POA_var poa = PortableServer::POA::_narrow(obj);
264 // Obtain a POAManager, and tell the POA to start accepting
265 // requests on its objects.
266 PortableServer::POAManager_var pman = poa->the_POAManager();
269 // Test basic services
275 catch(CORBA::SystemException&) {
276 MESSAGE("Caught CORBA::SystemException." )
278 catch(CORBA::Exception&) {
279 MESSAGE( "Caught CORBA::Exception." )
281 catch(omniORB::fatalException& fe) {
282 MESSAGE( "Caught omniORB::fatalException:" )
283 MESSAGE( " file: " << fe.file() )
284 MESSAGE( " line: " << fe.line() )
285 MESSAGE( " mesg: " << fe.errmsg() )
288 MESSAGE( "Caught unknown exception." )