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