1 // Copyright (C) 2007-2024 CEA, EDF, 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 "ArgvKeeper.hxx"
34 #include "Basics_Utils.hxx"
36 #include "utilities.h"
39 //============================================================================
43 //============================================================================
44 static void DumpComponent(SALOMEDS::SObject_ptr SO, int offset) {
45 SALOMEDS::SObject_var RefSO;
46 SALOMEDS::ChildIterator_var it = KERNEL::getStudyServant()->NewChildIterator(SO);
47 for (; it->More();it->Next()){
48 SALOMEDS::SObject_var CSO= it->Value();
49 SALOMEDS::GenericAttribute_var anAttr;
50 if (CSO->FindAttribute(anAttr,"AttributeName"))
52 SALOMEDS::AttributeName_var Name = SALOMEDS::AttributeName::_narrow(anAttr);
53 CORBA::String_var Val = Name->Value();
54 for (int i = 1; i <= offset ; i++)
56 MESSAGE(">"<<CSO->GetID()<<Val);
58 if (CSO->ReferencedObject(RefSO)) {
59 for (int i = 1; i <= offset ; i++)
61 MESSAGE("*Reference"<<RefSO->GetID());
63 DumpComponent(CSO,offset+2);
67 //============================================================================
71 //============================================================================
72 static void DumpStudy() {
73 MESSAGE("Explore Study and Write name of each object if it exists");
76 SALOME_UNUSED(name); // unused in release mode
77 SALOMEDS::SComponentIterator_var itcomp = KERNEL::getStudyServant()->NewComponentIterator();
79 for (; itcomp->More(); itcomp->Next()) {
80 SALOMEDS::SComponent_var SC = itcomp->Value();
81 name = SC->ComponentDataType();
82 MESSAGE("-> ComponentDataType is "<<name);
83 DumpComponent(SC,offset);
87 //============================================================================
91 //============================================================================
96 SALOME_UNUSED(name); // unused in release mode
98 SALOMEDS::Study_var myStudy = KERNEL::getStudyServant();
100 MESSAGE("Create Builder ");
101 SALOMEDS::StudyBuilder_var StudyBuild = myStudy->NewBuilder();
103 // Create new components
104 SALOMEDS::GenericAttribute_var anAttr;
105 SALOMEDS::AttributeName_var Name;
106 SALOMEDS::AttributeComment_var Comment;
107 SALOMEDS::AttributePersistentRef_var PRef;
110 MESSAGE("Add Component GEOM");
111 SALOMEDS::SComponent_var Geom = StudyBuild->NewComponent("GEOM");
112 MESSAGE("Add attribute name GEOM to component Geom");
113 anAttr = StudyBuild->FindOrCreateAttribute(Geom, "AttributeName");
114 Name = SALOMEDS::AttributeName::_narrow(anAttr);
115 Name->SetValue("Geometry");
118 MESSAGE("Add Component MESH");
119 SALOMEDS::SComponent_var Mesh = StudyBuild->NewComponent("MESH");
120 anAttr = StudyBuild->FindOrCreateAttribute(Mesh, "AttributeName");
121 Name = SALOMEDS::AttributeName::_narrow(anAttr);
122 Name->SetValue("Mesh");
128 MESSAGE("Add Object box under GEOM");
129 SALOMEDS::SObject_var box = StudyBuild->NewObject(Geom);
131 MESSAGE("Add Attribute Name in object box");
132 anAttr = StudyBuild->FindOrCreateAttribute(box, "AttributeName");
133 Name = SALOMEDS::AttributeName::_narrow(anAttr);
134 Name->SetValue("box_0");
136 MESSAGE("Add Attribute Comment in object box");
137 anAttr = StudyBuild->FindOrCreateAttribute(box, "AttributeComment");
138 Comment = SALOMEDS::AttributeComment::_narrow(anAttr);
139 Comment->SetValue("this is a box");
142 MESSAGE("Add Object mesh_box under MESH");
143 SALOMEDS::SObject_var mesh_box = StudyBuild->NewObject(Mesh);
145 MESSAGE("Add Attribute Name in object mesh_box");
146 anAttr = StudyBuild->FindOrCreateAttribute(mesh_box, "AttributeName");
147 Name = SALOMEDS::AttributeName::_narrow(anAttr);
148 Name->SetValue("mesh_box_0");
150 // Test attribute delete
151 //MESSAGE("Delete Attribute Name in object mesh_box");
152 //StudyBuild->RemoveAttribute (mesh_box,SALOMEDS::Name);
155 MESSAGE("Add Object mesh_box_face under mesh_box");
156 SALOMEDS::SObject_var mesh_box_face = StudyBuild->NewObject(mesh_box);
158 MESSAGE("Add Attribute Name in object mesh_box_face");
159 anAttr = StudyBuild->FindOrCreateAttribute(mesh_box_face, "AttributeName");
160 Name = SALOMEDS::AttributeName::_narrow(anAttr);
161 Name->SetValue("mesh_box_face_0");
163 MESSAGE("Add Reference mesh_box_face to box");
164 StudyBuild->Addreference (mesh_box_face,box);
167 MESSAGE("Add Object cylinder under GEOM");
168 SALOMEDS::SObject_var cylinder = StudyBuild->NewObject(Geom);
170 MESSAGE("Add Attribute Name in object cylinder");
171 anAttr = StudyBuild->FindOrCreateAttribute(cylinder, "AttributeName");
172 Name = SALOMEDS::AttributeName::_narrow(anAttr);
173 Name->SetValue("cylinder_0");
175 MESSAGE("Add Attribute Persistent Reference in object cylinder");
176 anAttr = StudyBuild->FindOrCreateAttribute(cylinder, "AttributePersistentRef");
177 PRef = SALOMEDS::AttributePersistentRef::_narrow(anAttr);
178 PRef->SetValue("/HDFROOT/GEOM/cylinder");
181 MESSAGE("Test Undo");
183 StudyBuild->UndoLimit(3);
184 StudyBuild->NewCommand();
185 MESSAGE("Add Object mesh_cylinder under MESH");
186 SALOMEDS::SObject_var mesh_cylinder = StudyBuild->NewObject(Mesh);
187 MESSAGE("Add Attribute Name in object mesh_cylinder");
188 anAttr = StudyBuild->FindOrCreateAttribute(mesh_cylinder, "AttributeName");
189 Name = SALOMEDS::AttributeName::_narrow(anAttr);
190 Name->SetValue("mesh_cylinder_0");
191 StudyBuild->CommitCommand();
196 // Study should have no trace of object mesh_cylinder
200 myStudy->SaveAs(Kernel_Utils::decode("/home/edeville/Study1.hdf"), false, false);
202 // Get Persistent Reference of the study test
203 name = myStudy->GetPersistentReference();
204 MESSAGE("Persitent Reference of the study " << name);
206 // FindComponent Test
207 SALOMEDS::SComponent_var compo = myStudy->FindComponent("GEOM");
208 // Get ComponentDataType test
209 MESSAGE("Find ComponentDataType of compo");
210 name = compo->ComponentDataType();
211 MESSAGE("-> ComponentDataType is "<<name);
213 // FindComponentID Test
214 SALOMEDS::SComponent_var compo1 = myStudy->FindComponentID("0:1:2");
215 // Get ComponentDataType test
216 MESSAGE("Find ComponentDataType of compo1");
217 name = compo1->ComponentDataType();
218 MESSAGE("-> ComponentDataType is "<<name);
221 SALOMEDS::SObject_var objn = myStudy->FindObject("cylinder_0");
222 // Test FindAttribute function : get AttributeName attribute
223 MESSAGE("Find Name in object objn");
224 if (objn->FindAttribute(anAttr, "AttributeName")) {
225 Name = SALOMEDS::AttributeName::_narrow(anAttr);
226 CORBA::String_var Val = Name->Value();
227 MESSAGE("-> Name is "<<Val);
230 MESSAGE("-> Name is not found");
234 SALOMEDS::SObject_var obj = myStudy->FindObjectID("0:1:2:1:1");
235 // Test FindAttribute function : get AttributeName attribute
236 MESSAGE("Find Name in object obj");
237 if (obj->FindAttribute(anAttr, "AttributeName")) {
238 Name = SALOMEDS::AttributeName::_narrow(anAttr);
239 CORBA::String_var Val = Name->Value();
240 MESSAGE("-> Name is "<<Val);
243 MESSAGE("-> Name is not found");
249 MESSAGE("HDFexception ! ");
253 ///////////////////////////// MAIN ///////////////////////////////////////
254 //////////////////////////////////////////////////////////////////////////
255 int main(int argc, char** argv)
258 // Initialise the ORB.
259 SetArgcArgv(argc, argv);
260 CORBA::ORB_var orb = KERNEL::GetRefToORB() ;
262 // Obtain a reference to the root POA.
263 CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
264 PortableServer::POA_var poa = PortableServer::POA::_narrow(obj);
266 // Obtain a POAManager, and tell the POA to start accepting
267 // requests on its objects.
268 PortableServer::POAManager_var pman = poa->the_POAManager();
271 // Test basic services
277 catch(CORBA::SystemException&) {
278 MESSAGE("Caught CORBA::SystemException.");
280 catch(CORBA::Exception&) {
281 MESSAGE("Caught CORBA::Exception.");
283 catch(omniORB::fatalException& fe) { //!< TODO: unused variable
284 MESSAGE("Caught omniORB::fatalException:");
285 MESSAGE(" file: " << fe.file());
286 MESSAGE(" line: " << fe.line());
287 MESSAGE(" mesg: " << fe.errmsg());
290 MESSAGE("Caught unknown exception.");