Salome HOME
Join modifications from branch OCC_development_for_3_2_0a2
[modules/geom.git] / src / GEOM_I / GEOM_Gen_i.cc
1 // Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
3 // 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either 
7 // version 2.1 of the License.
8 // 
9 // This library is distributed in the hope that it will be useful 
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
12 // Lesser General Public License for more details.
13 //
14 // You should have received a copy of the GNU Lesser General Public  
15 // License along with this library; if not, write to the Free Software 
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 //
18 // See http://www.salome-platform.org/
19 //
20 #ifdef WNT
21 #pragma warning( disable:4786 )
22 #endif
23
24 #include <Standard_Stream.hxx>
25
26 #include "GEOM_Gen_i.hh"
27 #include "GEOM_Object_i.hh"
28
29 #include <strstream>
30
31 #include "Utils_CorbaException.hxx"
32 #include "OpUtil.hxx"
33 #include "Utils_ExceptHandlers.hxx"
34 #include "utilities.h"
35
36 #include "GEOM_Object_i.hh"
37 #include "GEOM_Object.hxx"
38 #include "GEOM_Function.hxx"
39 #include "GEOMImpl_Types.hxx"
40 #include "GEOMImpl_CopyDriver.hxx"
41
42 // Cascade headers
43 #include <BRep_Builder.hxx>
44 #include <BRepTools.hxx>
45 #include <TDF_Label.hxx>
46 #include <TDF_Tool.hxx>
47 #include <TCollection_AsciiString.hxx>
48 #include <TColStd_HArray1OfInteger.hxx>
49 #include <TopAbs_ShapeEnum.hxx>
50 #include <OSD.hxx>
51
52 #include "SALOMEDS_Tool.hxx"
53
54 //============================================================================
55 // function : GEOM_Gen_i()
56 // purpose  : constructor to be called for servant creation.
57 //============================================================================
58 GEOM_Gen_i::GEOM_Gen_i(CORBA::ORB_ptr orb,
59                        PortableServer::POA_ptr poa,
60                        PortableServer::ObjectId * contId,
61                        const char *instanceName,
62                        const char *interfaceName) :
63   Engines_Component_i(orb, poa, contId, instanceName, interfaceName)
64 {
65   _thisObj = this;
66   _id = _poa->activate_object(_thisObj);
67   name_service = new SALOME_NamingService(_orb);
68
69   _impl = new ::GEOMImpl_Gen;
70
71   OSD::SetSignal( true );
72 }
73
74
75
76 //============================================================================
77 // function : ~GEOM_Gen_i()
78 // purpose  : destructor
79 //============================================================================
80 GEOM_Gen_i::~GEOM_Gen_i() {
81   delete name_service;
82   delete _impl;
83 }
84
85
86 //============================================================================
87 // function : IORToLocalPersistentID()
88 // purpose  :
89 //============================================================================
90 char* GEOM_Gen_i::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject,
91                                          const char* IORString,
92                                          CORBA::Boolean isMultiFile,
93                                          CORBA::Boolean isASCII)
94 {
95   GEOM::GEOM_Object_var anObject = GEOM::GEOM_Object::_narrow(_orb->string_to_object(IORString));
96   if (!CORBA::is_nil(anObject)) {
97     return strdup(anObject->GetEntry());
98   }
99   return 0;
100 }
101
102
103 //============================================================================
104 // function : LocalPersistentIDToIOR()
105 // purpose  : Create/Load CORBA object from a persistent ref (an entry)
106 //          : Used when a study is loaded
107 //          : The IOR (IORName) of object created is returned
108 //============================================================================
109 char* GEOM_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject,
110                                          const char* aLocalPersistentID,
111                                          CORBA::Boolean isMultiFile,
112                                          CORBA::Boolean isASCII)
113 {
114   SALOMEDS::Study_var aStudy = theSObject->GetStudy();
115
116   Handle(GEOM_Object) anObject = _impl->GetObject(aStudy->StudyId(), const_cast<char*>(aLocalPersistentID));
117   TCollection_AsciiString anEntry;
118   TDF_Tool::Entry(anObject->GetEntry(), anEntry);
119   GEOM::GEOM_Object_var obj = GetObject(anObject->GetDocID(), anEntry.ToCString());
120
121   CORBA::String_var aPersRefString = _orb->object_to_string(obj);
122   return strdup(aPersRefString);
123 }
124
125 //============================================================================
126 // function : CanPublishInStudy
127 // purpose  :
128 //============================================================================
129 bool GEOM_Gen_i::CanPublishInStudy(CORBA::Object_ptr theIOR)
130 {
131   GEOM::GEOM_Object_var anObject = GEOM::GEOM_Object::_narrow(theIOR);
132   return !(anObject->_is_nil());
133 }
134
135
136 //============================================================================
137 // function : PublishInStudy
138 // purpose  :
139 //============================================================================
140 SALOMEDS::SObject_ptr GEOM_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy,
141                                                  SALOMEDS::SObject_ptr theSObject,
142                                                  CORBA::Object_ptr theObject,
143                                                  const char* theName) throw (SALOME::SALOME_Exception)
144 {
145   Unexpect aCatch(SALOME_SalomeException);
146   SALOMEDS::SObject_var aResultSO;
147   if(CORBA::is_nil(theObject) || theStudy->_is_nil()) return aResultSO;
148
149   GEOM::GEOM_Object_var aShape = GEOM::GEOM_Object::_narrow(theObject);
150   if(aShape->_is_nil()) return aResultSO;
151
152   SALOMEDS::GenericAttribute_var anAttr;
153   SALOMEDS::StudyBuilder_var     aStudyBuilder = theStudy->NewBuilder();
154
155   SALOMEDS::SComponent_var       aFather = theStudy->FindComponent("GEOM");
156   if (aFather->_is_nil()) {
157     aFather = aStudyBuilder->NewComponent("GEOM");
158     anAttr = aStudyBuilder->FindOrCreateAttribute(aFather, "AttributeName");
159     SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
160     aName->SetValue("Geometry");
161     anAttr = aStudyBuilder->FindOrCreateAttribute(aFather, "AttributePixMap");
162     SALOMEDS::AttributePixMap::_narrow(anAttr)->SetPixMap("ICON_OBJBROWSER_Geometry");
163     aStudyBuilder->DefineComponentInstance(aFather, GEOM_Gen::_this());
164   }
165   if (aFather->_is_nil()) return aResultSO;
166
167   if (CORBA::is_nil(theSObject)) {
168     aResultSO = aStudyBuilder->NewObject(aFather);
169   } else {
170     if (!theSObject->ReferencedObject(aResultSO))
171       aResultSO = SALOMEDS::SObject::_duplicate(theSObject); //SRN: Added Aug 24,2004 : for  the method AddInStudy with theFather argumenet != NULL
172       //THROW_SALOME_CORBA_EXCEPTION("Publish in study supervision graph error",SALOME::BAD_PARAM);
173   }
174   anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeIOR");
175   SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
176   char *aGeomObjIOR = _orb->object_to_string(theObject);
177   anIOR->SetValue(strdup(aGeomObjIOR));
178
179   anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributePixMap");
180   SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
181   TCollection_AsciiString aShapeName("Shape_");
182
183   if ( aShape->GetType() == GEOM_GROUP ) {
184     GEOM::GEOM_IGroupOperations_var anOp = GetIGroupOperations( theStudy->StudyId() );
185     switch ( (TopAbs_ShapeEnum)anOp->GetType( aShape ) ) {
186     case TopAbs_VERTEX:
187       aPixmap->SetPixMap( "ICON_OBJBROWSER_GROUP_PNT" );
188       aShapeName = "Group_Of_Vertices_";
189       break;
190     case TopAbs_EDGE:
191       aPixmap->SetPixMap( "ICON_OBJBROWSER_GROUP_EDGE" );
192       aShapeName = "Group_Of_Edges_";
193       break;
194     case TopAbs_FACE:
195       aPixmap->SetPixMap( "ICON_OBJBROWSER_GROUP_FACE" );
196       aShapeName = "Group_Of_Faces_";
197       break;
198     case TopAbs_SOLID:
199       aPixmap->SetPixMap( "ICON_OBJBROWSER_GROUP_SOLID" );
200       aShapeName = "Group_Of_Solids_";
201       break;
202     }
203   } else if ( aShape->GetType() == GEOM_MARKER ) {
204     aPixmap->SetPixMap( "ICON_OBJBROWSER_LCS" );
205     aShapeName = "LocalCS_";
206   } else if ( aShape->GetShapeType() == GEOM::COMPOUND ) {
207     aPixmap->SetPixMap( "ICON_OBJBROWSER_COMPOUND" );
208     aShapeName = "Compound_";
209   } else if ( aShape->GetShapeType() == GEOM::COMPSOLID ) {
210     aPixmap->SetPixMap( "ICON_OBJBROWSER_COMPSOLID" );
211     aShapeName = "Compsolid_";
212   } else if ( aShape->GetShapeType() == GEOM::SOLID ) {
213     aPixmap->SetPixMap( "ICON_OBJBROWSER_SOLID" );
214     aShapeName = "Solid_";
215   } else if ( aShape->GetShapeType() == GEOM::SHELL ) {
216     aPixmap->SetPixMap( "ICON_OBJBROWSER_SHELL" );
217     aShapeName = "Shell_";
218   } else if ( aShape->GetShapeType() == GEOM::FACE ) {
219     aPixmap->SetPixMap( "ICON_OBJBROWSER_FACE" );
220     aShapeName = "Face_";
221   } else if ( aShape->GetShapeType() == GEOM::WIRE ) {
222     aPixmap->SetPixMap( "ICON_OBJBROWSER_WIRE" );
223     aShapeName = "Wire_";
224   } else if ( aShape->GetShapeType() == GEOM::EDGE ) {
225     aPixmap->SetPixMap( "ICON_OBJBROWSER_EDGE" );
226     aShapeName = "Edge_";
227   } else if ( aShape->GetShapeType() == GEOM::VERTEX ) {
228     aPixmap->SetPixMap( "ICON_OBJBROWSER_VERTEX" );
229     aShapeName = "Vertex_";
230   }
231   //if (strlen(theName) == 0) aShapeName += TCollection_AsciiString(aResultSO->Tag());
232   //else aShapeName = TCollection_AsciiString(strdup(theName));
233
234   // asv : 11.11.04 Introducing a more sofisticated method of name creation, just as
235   //       it is done in GUI in GEOMBase::GetDefaultName() - not just add a Tag() == number
236   //       of objects in the study, but compute a number of objects with the same prefix
237   //       and build a new name as Prefix_N+1
238   if ( strlen( theName ) == 0 ) { // MOST PROBABLY CALLED FROM BATCHMODE OR SUPERVISOR
239     int i = 0;                    // (WITH EMPTY NEW NAME)
240     SALOMEDS::SObject_var obj;
241     TCollection_AsciiString aNewShapeName;
242     do {
243       aNewShapeName = aShapeName + TCollection_AsciiString(++i);
244       obj = theStudy->FindObject( aNewShapeName.ToCString() );
245     }
246     while ( !obj->_is_nil() );
247     aShapeName = aNewShapeName;
248   }
249   else // MOST PROBABLY CALLED FROM GEOM GUI (ALREADY WITH VALID NAME)
250     aShapeName = TCollection_AsciiString(strdup(theName));
251
252   //Set the study entry as a name of  the published GEOM_Object
253   aShape->SetStudyEntry(aResultSO->GetID());
254
255   //Set a name of the added shape
256   anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeName");
257   SALOMEDS::AttributeName_var aNameAttrib = SALOMEDS::AttributeName::_narrow(anAttr);
258   aNameAttrib->SetValue(aShapeName.ToCString());
259
260   return aResultSO._retn();
261 }
262
263
264 //============================================================================
265 // function : Save()
266 // purpose  : save OCAF/Geom document
267 //============================================================================
268 SALOMEDS::TMPFile* GEOM_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent,
269                                     const char* theURL,
270                                     bool isMultiFile) {
271   SALOMEDS::TMPFile_var aStreamFile;
272   // Get a temporary directory to store a file
273   std::string aTmpDir = (isMultiFile)?theURL:SALOMEDS_Tool::GetTmpDir();
274   // Create a list to store names of created files
275   SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames;
276   aSeq->length(1);
277   // Prepare a file name to open
278   TCollection_AsciiString aNameWithExt("");
279   if (isMultiFile)
280     aNameWithExt = TCollection_AsciiString((char*)(SALOMEDS_Tool::GetNameFromPath(theComponent->GetStudy()->URL())).c_str());
281   aNameWithExt += TCollection_AsciiString("_GEOM.sgd");
282   aSeq[0] = CORBA::string_dup(aNameWithExt.ToCString());
283   // Build a full file name of temporary file
284   TCollection_AsciiString aFullName = TCollection_AsciiString((char*)aTmpDir.c_str()) + aNameWithExt;
285   // Save GEOM component in this file
286   _impl->Save(theComponent->GetStudy()->StudyId(), aFullName.ToCString());
287   // Conver a file to the byte stream
288   aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir.c_str(), aSeq.in(), isMultiFile);
289   // Remove the created file and tmp directory
290   if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.c_str(), aSeq.in(), true);
291
292   // Return the created byte stream
293   return aStreamFile._retn();
294 }
295
296
297 //============================================================================
298 // function : SaveASCII()
299 // purpose  :
300 //============================================================================
301 SALOMEDS::TMPFile* GEOM_Gen_i::SaveASCII(SALOMEDS::SComponent_ptr theComponent,
302                                          const char* theURL,
303                                          bool isMultiFile) {
304   SALOMEDS::TMPFile_var aStreamFile = Save(theComponent, theURL, isMultiFile);
305   return aStreamFile._retn();
306 }
307
308
309 //============================================================================
310 // function : Load()
311 // purpose  :
312 //============================================================================
313 CORBA::Boolean GEOM_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent,
314                                 const SALOMEDS::TMPFile& theStream,
315                                 const char* theURL,
316                                 bool isMultiFile) {
317
318   if (theStream.length() <= 9) {
319     MESSAGE("The TMPFile is too short : " << theStream.length() << " bytes ");
320     return false;
321   }
322
323   // Get a temporary directory for a file
324   std::string aTmpDir = isMultiFile?theURL:SALOMEDS_Tool::GetTmpDir();
325   // Conver the byte stream theStream to a file and place it in tmp directory
326   SALOMEDS::ListOfFileNames_var aSeq = SALOMEDS_Tool::PutStreamToFiles(theStream, aTmpDir.c_str(), isMultiFile);
327
328   // Prepare a file name to open
329   TCollection_AsciiString aNameWithExt("");
330   if (isMultiFile)
331     aNameWithExt = TCollection_AsciiString((char*)(SALOMEDS_Tool::GetNameFromPath(theComponent->GetStudy()->URL())).c_str());
332   aNameWithExt += TCollection_AsciiString("_GEOM.sgd");
333   TCollection_AsciiString aFullName = (TCollection_AsciiString((char*)aTmpDir.c_str()) + aNameWithExt);
334
335   // Open document
336   if (!_impl->Load(theComponent->GetStudy()->StudyId(), aFullName.ToCString())) return false;
337
338   // Remove the created file and tmp directory
339   if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.c_str(), aSeq.in(), true);
340
341   SALOMEDS::Study_var Study = theComponent->GetStudy();
342   TCollection_AsciiString name( strdup(Study->Name()) );
343
344   return true;
345 }
346
347
348 //============================================================================
349 // function : LoadASCII()
350 // purpose  :
351 //============================================================================
352 CORBA::Boolean GEOM_Gen_i::LoadASCII(SALOMEDS::SComponent_ptr theComponent,
353                                      const SALOMEDS::TMPFile& theStream,
354                                      const char* theURL,
355                                      bool isMultiFile) {
356   return Load(theComponent, theStream, theURL, isMultiFile);
357 }
358
359
360 //============================================================================
361 // function : Close()
362 // purpose  :
363 //============================================================================
364 void GEOM_Gen_i::Close(SALOMEDS::SComponent_ptr theComponent)
365 {
366   _impl->Close(theComponent->GetStudy()->StudyId());
367 }
368
369 //============================================================================
370 // function : CanCopy()
371 // purpose  :
372 //============================================================================
373 CORBA::Boolean GEOM_Gen_i::CanCopy(SALOMEDS::SObject_ptr theObject) {
374   // Try to retrieve known by Geometry component GEOM_Object by given IOR
375   SALOMEDS::GenericAttribute_var anAttr;
376   if (!theObject->FindAttribute(anAttr, "AttributeIOR")) return false;
377
378   SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
379
380   GEOM::GEOM_Object_var anObject = GEOM::GEOM_Object::_narrow(_orb->string_to_object(anIOR->Value()));
381   // If the object is null one it can't be copied: return false
382   if (anObject->_is_nil()) return false;
383   return true;
384 }
385
386 //============================================================================
387 // function : CopyFrom()
388 // purpose  :
389 //============================================================================
390 SALOMEDS::TMPFile* GEOM_Gen_i::CopyFrom(SALOMEDS::SObject_ptr theObject, CORBA::Long& theObjectID) {
391   // Declare a sequence of the byte to store the copied object
392   SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile;
393
394   // Try to get GEOM_Object object by given SObject
395   SALOMEDS::GenericAttribute_var anAttr;
396   if (!theObject->FindAttribute(anAttr, "AttributeIOR")) return aStreamFile._retn();
397   GEOM::GEOM_Object_var anObject =  GEOM::GEOM_Object::_narrow(_orb->string_to_object(SALOMEDS::AttributeIOR::_narrow(anAttr)->Value()));
398   if (anObject->_is_nil()) return aStreamFile._retn();
399
400   aStreamFile = anObject->GetShapeStream();
401
402   // Assign an ID  the type of  GEOM_Object
403   theObjectID = anObject->GetType();
404
405   // Return created TMPFile
406   return aStreamFile._retn();
407 }
408
409 //============================================================================
410 // function : CanPaste()
411 // purpose  :
412 //============================================================================
413 CORBA::Boolean GEOM_Gen_i::CanPaste(const char* theComponentName, CORBA::Long theObjectID) {
414   // The Geometry component can paste only objects copied by Geometry component
415   // and with the object type = 1
416   if (strcmp(theComponentName, ComponentDataType()) != 0) return false;
417   return true;
418 }
419
420 //============================================================================
421 // function : PasteInto()
422 // purpose  :
423 //============================================================================
424 SALOMEDS::SObject_ptr GEOM_Gen_i::PasteInto(const SALOMEDS::TMPFile& theStream,
425                                             CORBA::Long theObjectID,
426                                             SALOMEDS::SObject_ptr theObject) {
427   // Find the current Study and StudyBuilder
428   SALOMEDS::Study_var aStudy = theObject->GetStudy();
429   SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
430
431   // Retrieve a TopoDS_Shape from byte stream
432   TopoDS_Shape aTopology;
433   istrstream aStreamedBrep((char*) &theStream[0], theStream.length());
434   BRep_Builder aBuilder;
435   try {
436     BRepTools::Read(aTopology, aStreamedBrep, aBuilder);
437   } catch (Standard_Failure) {
438     return false;
439   }
440
441   // SObject of the created shape is theObject or new Child of Component if theObject == geom component
442   SALOMEDS::SObject_var aNewSO;
443   if (strcmp(theObject->GetFatherComponent()->GetID(),theObject->GetID()) == 0) {
444     aNewSO = aStudyBuilder->NewObject(theObject);
445   } else aNewSO = SALOMEDS::SObject::_duplicate(theObject);
446
447
448   //Create a new GEOM_Object
449   Handle(GEOM_Object) anObj = _impl->AddObject(aNewSO->GetStudy()->StudyId(), theObjectID);
450   Handle(GEOM_Function) aFunction = anObj->AddFunction(GEOMImpl_CopyDriver::GetID(), COPY_WITHOUT_REF);
451   aFunction->SetValue(aTopology);
452
453   TCollection_AsciiString anEntry;
454   TDF_Tool::Entry(anObj->GetEntry(), anEntry);
455   GEOM::GEOM_Object_var obj = GetObject(anObj->GetDocID(), anEntry.ToCString());
456
457   // Add IORAttribute to the Study and set IOR of the created GEOM_Object to it
458   SALOMEDS::GenericAttribute_var anAttr = aStudyBuilder->FindOrCreateAttribute(aNewSO, "AttributeIOR");
459   SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
460   anIOR->SetValue(_orb->object_to_string(obj));
461
462   // Return the created in the Study SObject
463   return aNewSO._retn();
464 }
465
466 //============================================================================
467 // function : ComponentDataType()
468 // purpose  :
469 //============================================================================
470 char* GEOM_Gen_i::ComponentDataType()
471 {
472   return strdup("GEOM");
473 }
474
475 //============================================================================
476 // function : AddInStudy
477 // purpose  :
478 //============================================================================
479 SALOMEDS::SObject_ptr GEOM_Gen_i::AddInStudy(SALOMEDS::Study_ptr theStudy, GEOM::GEOM_Object_ptr theObject, const char* theName, GEOM::GEOM_Object_ptr theFather)
480 {
481   SALOMEDS::SObject_var aResultSO;
482   if(theObject->_is_nil() || theStudy->_is_nil()) return aResultSO;
483
484   SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
485   char* IOR;
486
487   if(!theFather->_is_nil()) {
488     IOR = _orb->object_to_string(theFather);
489     SALOMEDS::SObject_var aFatherSO = theStudy->FindObjectIOR(IOR);
490     if(aFatherSO->_is_nil()) return aResultSO._retn();
491     aResultSO = aStudyBuilder->NewObject(aFatherSO);
492     //aStudyBuilder->Addreference(aResultSO, aResultSO);
493   }
494
495   aResultSO = PublishInStudy(theStudy, aResultSO, theObject, theName);
496   if(aResultSO->_is_nil()) return aResultSO._retn();
497
498   GEOM::ListOfGO_var aList = theObject->GetDependency();
499   Standard_Integer aLength = aList->length();
500   if(aLength < 1) return aResultSO._retn();
501
502   //Publish the arguments
503   for(Standard_Integer i = 0; i< aLength; i++) {
504     GEOM::GEOM_Object_var anObject = aList[i];
505     if(anObject->_is_nil()) continue;
506     IOR = _orb->object_to_string(anObject);
507     SALOMEDS::SObject_var aSO =  theStudy->FindObjectIOR(IOR);
508     if(aSO->_is_nil()) continue;
509     SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aResultSO);
510     aStudyBuilder->Addreference(aSubSO, aSO);
511   }
512
513   return aResultSO._retn();
514 }
515
516 //============================================================================
517 // function : register()
518 // purpose  : register 'name' in 'name_service'
519 //============================================================================
520 void GEOM_Gen_i::register_name(char * name)
521 {
522   GEOM::GEOM_Gen_ptr g = GEOM::GEOM_Gen::_narrow(_this());
523   name_service->Register(g, strdup(name));
524 }
525
526 //============================================================================
527 // function : Undo
528 // purpose  :
529 //============================================================================
530 void GEOM_Gen_i::Undo(CORBA::Long theStudyID)
531 {
532   _impl->Undo(theStudyID);
533 }
534
535 //============================================================================
536 // function : Redo
537 // purpose  :
538 //============================================================================
539 void GEOM_Gen_i::Redo(CORBA::Long theStudyID)
540 {
541   _impl->Redo(theStudyID);
542 }
543
544 //============================================================================
545 // function : GetIBasicOperations
546 // purpose  :
547 //============================================================================
548 GEOM::GEOM_IBasicOperations_ptr GEOM_Gen_i::GetIBasicOperations(CORBA::Long theStudyID)
549      throw ( SALOME::SALOME_Exception )
550 {
551   Unexpect aCatch(SALOME_SalomeException);
552   MESSAGE( "GEOM_Gen_i::GetIBasicOperations" );
553
554   GEOM::GEOM_Gen_ptr engine = _this();
555
556   GEOM_IBasicOperations_i* aServant =
557     new GEOM_IBasicOperations_i(_poa, engine, _impl->GetIBasicOperations(theStudyID));
558
559   // activate the CORBA servant
560   GEOM::GEOM_IBasicOperations_var operations = aServant->_this();
561   return operations._retn();
562 }
563
564 //============================================================================
565 // function : GetITransformOperations
566 // purpose  :
567 //============================================================================
568 GEOM::GEOM_ITransformOperations_ptr GEOM_Gen_i::GetITransformOperations(CORBA::Long theStudyID)
569      throw ( SALOME::SALOME_Exception )
570 {
571   Unexpect aCatch(SALOME_SalomeException);
572   MESSAGE( "GEOM_Gen_i::GetITransformOperations" );
573
574   GEOM::GEOM_Gen_ptr engine = _this();
575
576   GEOM_ITransformOperations_i* aServant =
577     new GEOM_ITransformOperations_i(_poa, engine, _impl->GetITransformOperations(theStudyID));
578
579   // activate the CORBA servant
580   GEOM::GEOM_ITransformOperations_var operations = aServant->_this();
581   return operations._retn();
582 }
583
584 //============================================================================
585 // function : GetI3DPrimOperations
586 // purpose  :
587 //============================================================================
588 GEOM::GEOM_I3DPrimOperations_ptr GEOM_Gen_i::GetI3DPrimOperations(CORBA::Long theStudyID)
589      throw ( SALOME::SALOME_Exception )
590 {
591   Unexpect aCatch(SALOME_SalomeException);
592   MESSAGE( "GEOM_Gen_i::GetI3DPrimOperations" );
593
594   GEOM::GEOM_Gen_ptr engine = _this();
595
596   GEOM_I3DPrimOperations_i* aServant =
597     new GEOM_I3DPrimOperations_i(_poa, engine, _impl->GetI3DPrimOperations(theStudyID));
598
599   // activate the CORBA servant
600   GEOM::GEOM_I3DPrimOperations_var operations = aServant->_this();
601   return operations._retn();
602 }
603
604 //============================================================================
605 // function : GetIShapesOperations
606 // purpose  :
607 //============================================================================
608 GEOM::GEOM_IShapesOperations_ptr GEOM_Gen_i::GetIShapesOperations(CORBA::Long theStudyID)
609      throw ( SALOME::SALOME_Exception )
610 {
611   Unexpect aCatch(SALOME_SalomeException);
612   MESSAGE( "GEOM_Gen_i::GetIShapesOperations" );
613
614   GEOM::GEOM_Gen_ptr engine = _this();
615
616   GEOM_IShapesOperations_i* aServant =
617     new GEOM_IShapesOperations_i(_poa, engine, _impl->GetIShapesOperations(theStudyID));
618
619   // activate the CORBA servant
620   GEOM::GEOM_IShapesOperations_var operations = aServant->_this();
621   return operations._retn();
622 }
623
624 //============================================================================
625 // function : GetIBlocksOperations
626 // purpose  :
627 //============================================================================
628 GEOM::GEOM_IBlocksOperations_ptr GEOM_Gen_i::GetIBlocksOperations(CORBA::Long theStudyID)
629      throw ( SALOME::SALOME_Exception )
630 {
631   Unexpect aCatch(SALOME_SalomeException);
632   MESSAGE( "GEOM_Gen_i::GetIBlocksOperations" );
633
634   GEOM::GEOM_Gen_ptr engine = _this();
635
636   GEOM_IBlocksOperations_i* aServant =
637     new GEOM_IBlocksOperations_i(_poa, engine, _impl->GetIBlocksOperations(theStudyID));
638
639   // activate the CORBA servant
640   GEOM::GEOM_IBlocksOperations_var operations = aServant->_this();
641   return operations._retn();
642 }
643
644 //============================================================================
645 // function : GetIBooleanOperations
646 // purpose  :
647 //============================================================================
648 GEOM::GEOM_IBooleanOperations_ptr GEOM_Gen_i::GetIBooleanOperations(CORBA::Long theStudyID)
649      throw ( SALOME::SALOME_Exception )
650 {
651   Unexpect aCatch(SALOME_SalomeException);
652   MESSAGE( "GEOM_Gen_i::GetIBooleanOperations" );
653
654   GEOM::GEOM_Gen_ptr engine = _this();
655
656   GEOM_IBooleanOperations_i* aServant =
657     new GEOM_IBooleanOperations_i(_poa, engine, _impl->GetIBooleanOperations(theStudyID));
658
659   // activate the CORBA servant
660   GEOM::GEOM_IBooleanOperations_var operations = aServant->_this();
661   return operations._retn();
662 }
663
664 //============================================================================
665 // function : GetICurvesOperations
666 // purpose  :
667 //============================================================================
668 GEOM::GEOM_ICurvesOperations_ptr GEOM_Gen_i::GetICurvesOperations(CORBA::Long theStudyID)
669      throw ( SALOME::SALOME_Exception )
670 {
671   Unexpect aCatch(SALOME_SalomeException);
672   MESSAGE( "GEOM_Gen_i::GetICurvesOperations" );
673
674   GEOM::GEOM_Gen_ptr engine = _this();
675
676   GEOM_ICurvesOperations_i* aServant =
677     new GEOM_ICurvesOperations_i(_poa, engine, _impl->GetICurvesOperations(theStudyID));
678
679   // activate the CORBA servant
680   GEOM::GEOM_ICurvesOperations_var operations = aServant->_this();
681   return operations._retn();
682 }
683
684 //============================================================================
685 // function : GetILocalOperations
686 // purpose  :
687 //============================================================================
688 GEOM::GEOM_ILocalOperations_ptr GEOM_Gen_i::GetILocalOperations(CORBA::Long theStudyID)
689      throw ( SALOME::SALOME_Exception )
690 {
691   Unexpect aCatch(SALOME_SalomeException);
692   MESSAGE( "GEOM_Gen_i::GetILocalOperations" );
693
694   GEOM::GEOM_Gen_ptr engine = _this();
695
696   GEOM_ILocalOperations_i* aServant =
697     new GEOM_ILocalOperations_i(_poa, engine, _impl->GetILocalOperations(theStudyID));
698
699   // activate the CORBA servant
700   GEOM::GEOM_ILocalOperations_var operations = aServant->_this();
701   return operations._retn();
702 }
703
704 //============================================================================
705 // function : GetIHealingOperations
706 // purpose  :
707 //============================================================================
708 GEOM::GEOM_IHealingOperations_ptr GEOM_Gen_i::GetIHealingOperations(CORBA::Long theStudyID)
709      throw ( SALOME::SALOME_Exception )
710 {
711   Unexpect aCatch(SALOME_SalomeException);
712   MESSAGE( "GEOM_Gen_i::IHealingOperations" );
713
714   GEOM::GEOM_Gen_ptr engine = _this();
715
716   GEOM_IHealingOperations_i* aServant =
717     new GEOM_IHealingOperations_i(_poa, engine, _impl->GetIHealingOperations(theStudyID));
718
719   // activate the CORBA servant
720   GEOM::GEOM_IHealingOperations_var operations = aServant->_this();
721   return operations._retn();
722 }
723
724 //============================================================================
725 // function : GetIInsertOperations
726 // purpose  :
727 //============================================================================
728 GEOM::GEOM_IInsertOperations_ptr GEOM_Gen_i::GetIInsertOperations(CORBA::Long theStudyID)
729      throw ( SALOME::SALOME_Exception )
730 {
731   Unexpect aCatch(SALOME_SalomeException);
732   MESSAGE( "GEOM_Gen_i::GetIInsertOperations" );
733
734   GEOM::GEOM_Gen_ptr engine = _this();
735
736   GEOM_IInsertOperations_i* aServant =
737     new GEOM_IInsertOperations_i(_poa, engine, _impl->GetIInsertOperations(theStudyID));
738
739   // activate the CORBA servant
740   GEOM::GEOM_IInsertOperations_var operations = aServant->_this();
741   return operations._retn();
742 }
743
744 //============================================================================
745 // function : GetIMeasureOperations
746 // purpose  :
747 //============================================================================
748 GEOM::GEOM_IMeasureOperations_ptr GEOM_Gen_i::GetIMeasureOperations(CORBA::Long theStudyID)
749      throw ( SALOME::SALOME_Exception )
750 {
751   Unexpect aCatch(SALOME_SalomeException);
752   MESSAGE( "GEOM_Gen_i::GetIMeasureOperations" );
753
754   GEOM::GEOM_Gen_ptr engine = _this();
755
756   GEOM_IMeasureOperations_i* aServant =
757     new GEOM_IMeasureOperations_i(_poa, engine, _impl->GetIMeasureOperations(theStudyID));
758
759   // activate the CORBA servant
760   GEOM::GEOM_IMeasureOperations_var operations = aServant->_this();
761   return operations._retn();
762 }
763
764 //============================================================================
765 // function : GetIGroupOperations
766 // purpose  :
767 //============================================================================
768 GEOM::GEOM_IGroupOperations_ptr GEOM_Gen_i::GetIGroupOperations(CORBA::Long theStudyID)
769      throw ( SALOME::SALOME_Exception )
770 {
771   Unexpect aCatch(SALOME_SalomeException);
772   MESSAGE( "GEOM_Gen_i::GetIGroupOperations" );
773
774   GEOM::GEOM_Gen_ptr engine = _this();
775
776   GEOM_IGroupOperations_i* aServant =
777     new GEOM_IGroupOperations_i(_poa, engine, _impl->GetIGroupOperations(theStudyID));
778
779   // activate the CORBA servant
780   GEOM::GEOM_IGroupOperations_var operations = aServant->_this();
781   return operations._retn();
782 }
783
784 //=============================================================================
785 /*!
786  *  AddSubShape
787  */
788 //=============================================================================
789 GEOM::GEOM_Object_ptr GEOM_Gen_i::AddSubShape (GEOM::GEOM_Object_ptr theMainShape,
790                                                const GEOM::ListOfLong& theIndices)
791 {
792   if(theMainShape == NULL || theIndices.length() < 1) return GEOM::GEOM_Object::_nil();
793   Handle(GEOM_Object) aMainsShape = _impl->GetObject(theMainShape->GetStudyID(), theMainShape->GetEntry());
794   if (aMainsShape.IsNull()) return GEOM::GEOM_Object::_nil();
795
796   Handle(TColStd_HArray1OfInteger) anArray = new TColStd_HArray1OfInteger(1, theIndices.length());
797   for(Standard_Integer i = 0; i<theIndices.length(); i++) anArray->SetValue(i+1, theIndices[i]);
798
799   Handle(GEOM_Object) anObject = _impl->AddSubShape(aMainsShape, anArray, true);
800   if(anObject.IsNull()) return GEOM::GEOM_Object::_nil();
801
802   TCollection_AsciiString anEntry;
803   TDF_Tool::Entry(anObject->GetEntry(), anEntry);
804   return GetObject(anObject->GetDocID(), anEntry.ToCString());
805 }
806
807 //=============================================================================
808 /*!
809  *  RemoveObject
810  */
811 //=============================================================================
812 void GEOM_Gen_i::RemoveObject(GEOM::GEOM_Object_ptr theObject)
813 {
814   Handle(GEOM_Object) anObject = _impl->GetObject(theObject->GetStudyID(), theObject->GetEntry());
815   if (anObject.IsNull()) return;
816   _impl->RemoveObject(anObject);
817   return;
818 }
819
820
821 //=================================================================================
822 // function : GetStringFromIOR()
823 // purpose  : returns a string that represents  a 'GEOM::GEOM_Object_var'
824 //=================================================================================
825 char* GEOM_Gen_i::GetStringFromIOR(GEOM::GEOM_Object_ptr theObject) {
826   return _orb->object_to_string(theObject);
827 }
828
829
830 //=================================================================================
831 // function : GetIORFromString()
832 // purpose  : returns a 'GEOM::GEOM_Object_var' from a string representing it
833 //=================================================================================
834 GEOM::GEOM_Object_ptr GEOM_Gen_i::GetIORFromString(const char* stringIOR) {
835   GEOM::GEOM_Object_var aGeomObject;
836   if(strcmp(stringIOR,"") != 0){
837     CORBA::Object_var anObject = _orb->string_to_object(stringIOR);
838     if(!CORBA::is_nil(anObject))
839       aGeomObject =  GEOM::GEOM_Object::_narrow(anObject.in());
840   }
841   return aGeomObject._retn();
842 }
843
844 //=================================================================================
845 // function : GetObject()
846 // purpose  :
847 //=================================================================================
848 GEOM::GEOM_Object_ptr GEOM_Gen_i::GetObject (CORBA::Long theStudyID, const char* theEntry)
849 {
850   GEOM::GEOM_Object_var obj;
851   Handle(GEOM_Object) handle_object = _impl->GetObject(theStudyID, (char*)theEntry);
852   if (handle_object.IsNull()) return NULL;
853
854   TCollection_AsciiString stringIOR = handle_object->GetIOR();
855   if (stringIOR.Length() > 1) {
856     CORBA::Object_var corba_object = _orb->string_to_object(stringIOR.ToCString());
857     if (!CORBA::is_nil(corba_object)) obj = GEOM::GEOM_Object::_narrow(corba_object);
858     return obj._retn();
859   }
860
861   GEOM::GEOM_Gen_ptr engine = _this();
862   GEOM_Object_i* servant = new GEOM_Object_i (_poa, engine, handle_object);
863
864   obj = servant->_this();
865   stringIOR = _orb->object_to_string(obj);
866   handle_object->SetIOR(stringIOR);
867   return obj._retn();
868 }
869
870
871 //=====================================================================================
872 // EXPORTED METHODS
873 //=====================================================================================
874 extern "C"
875 {
876 #ifdef WNT
877         __declspec( dllexport )
878 #endif
879   PortableServer::ObjectId * GEOMEngine_factory(CORBA::ORB_ptr orb,
880                                                 PortableServer::POA_ptr poa,
881                                                 PortableServer::ObjectId * contId,
882                                                 const char *instanceName,
883                                                 const char * interfaceName)
884   {
885    GEOM_Gen_i * myGEOM_Gen_i = new GEOM_Gen_i(orb, poa, contId, instanceName, interfaceName);
886    myGEOM_Gen_i->register_name("/myGEOM_Gen"); // NRI : 11/07/2002 : Add for Supervision example
887    return myGEOM_Gen_i->getId();
888   }
889 }