]> SALOME platform Git repositories - modules/geom.git/blob - src/GEOM_I/GEOM_Gen_i.cc
Salome HOME
Merge with OCC-V2_1_0_deb
[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   // asv : 11.11.04 Introducing a more sofisticated method of name creation, just as
207   //       it is done in GUI in GEOMBase::GetDefaultName() - not just add a Tag() == number
208   //       of objects in the study, but compute a number of objects with the same prefix
209   //       and build a new name as Prefix_N+1
210   if ( strlen( theName ) == 0 ) { // MOST PROBABLY CALLED FROM BATCHMODE OR SUPERVISOR
211     int i = 0;                    // (WITH EMPTY NEW NAME)
212     SALOMEDS::SObject_var obj;
213     TCollection_AsciiString aNewShapeName;
214     do {
215       aNewShapeName = aShapeName + TCollection_AsciiString(++i);
216       obj = theStudy->FindObject( aNewShapeName.ToCString() );
217     } 
218     while ( !obj->_is_nil() );
219     aShapeName = aNewShapeName;
220   }
221   else // MOST PROBABLY CALLED FROM GEOM GUI (ALREADY WITH VALID NAME)
222     aShapeName = TCollection_AsciiString(strdup(theName));
223
224   //Set the study entry as a name of  the published GEOM_Object
225   aShape->SetStudyEntry(aResultSO->GetID());
226
227   //Set a name of the added shape
228   anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeName");
229   SALOMEDS::AttributeName_var aNameAttrib = SALOMEDS::AttributeName::_narrow(anAttr);
230   aNameAttrib->SetValue(aShapeName.ToCString());
231
232   return aResultSO._retn();
233 }
234
235  
236 //============================================================================
237 // function : Save()
238 // purpose  : save OCAF/Geom document
239 //============================================================================
240 SALOMEDS::TMPFile* GEOM_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent,
241                                     const char* theURL,
242                                     bool isMultiFile) {
243   SALOMEDS::TMPFile_var aStreamFile;
244   // Get a temporary directory to store a file
245   std::string aTmpDir = (isMultiFile)?theURL:SALOMEDS_Tool::GetTmpDir();
246   // Create a list to store names of created files
247   SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames;
248   aSeq->length(1);
249   // Prepare a file name to open
250   TCollection_AsciiString aNameWithExt("");
251   if (isMultiFile)
252     aNameWithExt = TCollection_AsciiString((char*)(SALOMEDS_Tool::GetNameFromPath(theComponent->GetStudy()->URL())).c_str());
253   aNameWithExt += TCollection_AsciiString("_GEOM.sgd");
254   aSeq[0] = CORBA::string_dup(aNameWithExt.ToCString());
255   // Build a full file name of temporary file
256   TCollection_AsciiString aFullName = TCollection_AsciiString((char*)aTmpDir.c_str()) + aNameWithExt;
257   // Save GEOM component in this file
258   _impl->Save(theComponent->GetStudy()->StudyId(), aFullName.ToCString());
259   // Conver a file to the byte stream
260   aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir.c_str(), aSeq.in(), isMultiFile);
261   // Remove the created file and tmp directory
262   if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.c_str(), aSeq.in(), true);
263
264   // Return the created byte stream
265   return aStreamFile._retn();
266 }
267
268
269 //============================================================================
270 // function : SaveASCII()
271 // purpose  :
272 //============================================================================ 
273 SALOMEDS::TMPFile* GEOM_Gen_i::SaveASCII(SALOMEDS::SComponent_ptr theComponent,
274                                          const char* theURL,
275                                          bool isMultiFile) {
276   SALOMEDS::TMPFile_var aStreamFile = Save(theComponent, theURL, isMultiFile);
277   return aStreamFile._retn();
278 }
279
280
281 //============================================================================
282 // function : Load()
283 // purpose  :
284 //============================================================================ 
285 CORBA::Boolean GEOM_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent,
286                                 const SALOMEDS::TMPFile& theStream,
287                                 const char* theURL,
288                                 bool isMultiFile) {
289
290   if (theStream.length() <= 9) {
291     MESSAGE("The TMPFile is too short : " << theStream.length() << " bytes ");
292     return false;
293   }
294
295   // Get a temporary directory for a file
296   std::string aTmpDir = isMultiFile?theURL:SALOMEDS_Tool::GetTmpDir();
297   // Conver the byte stream theStream to a file and place it in tmp directory
298   SALOMEDS::ListOfFileNames_var aSeq = SALOMEDS_Tool::PutStreamToFiles(theStream, aTmpDir.c_str(), isMultiFile);
299
300   // Prepare a file name to open
301   TCollection_AsciiString aNameWithExt("");
302   if (isMultiFile)
303     aNameWithExt = TCollection_AsciiString((char*)(SALOMEDS_Tool::GetNameFromPath(theComponent->GetStudy()->URL())).c_str());
304   aNameWithExt += TCollection_AsciiString("_GEOM.sgd");
305   TCollection_AsciiString aFullName = (TCollection_AsciiString((char*)aTmpDir.c_str()) + aNameWithExt);
306
307   // Open document
308   if (!_impl->Load(theComponent->GetStudy()->StudyId(), aFullName.ToCString())) return false;
309
310   // Remove the created file and tmp directory
311   if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.c_str(), aSeq.in(), true);
312
313   SALOMEDS::Study_var Study = theComponent->GetStudy();
314   TCollection_AsciiString name( strdup(Study->Name()) );
315
316   return true;
317 }
318
319
320 //============================================================================
321 // function : LoadASCII()
322 // purpose  :
323 //============================================================================ 
324 CORBA::Boolean GEOM_Gen_i::LoadASCII(SALOMEDS::SComponent_ptr theComponent,
325                                      const SALOMEDS::TMPFile& theStream,
326                                      const char* theURL,
327                                      bool isMultiFile) {
328   return Load(theComponent, theStream, theURL, isMultiFile);
329 }
330
331
332 //============================================================================
333 // function : Close()
334 // purpose  :
335 //============================================================================
336 void GEOM_Gen_i::Close(SALOMEDS::SComponent_ptr theComponent)
337 {
338   _impl->Close(theComponent->GetStudy()->StudyId());
339 }
340
341 //============================================================================
342 // function : CanCopy()
343 // purpose  :
344 //============================================================================
345 CORBA::Boolean GEOM_Gen_i::CanCopy(SALOMEDS::SObject_ptr theObject) {
346   // Try to retrieve known by Geometry component GEOM_Object by given IOR
347   SALOMEDS::GenericAttribute_var anAttr;
348   if (!theObject->FindAttribute(anAttr, "AttributeIOR")) return false;
349
350   SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
351
352   GEOM::GEOM_Object_var anObject = GEOM::GEOM_Object::_narrow(_orb->string_to_object(anIOR->Value()));
353   // If the object is null one it can't be copied: return false
354   if (anObject->_is_nil()) return false;
355   return true;
356 }
357
358 //============================================================================
359 // function : CopyFrom()
360 // purpose  :
361 //============================================================================
362 SALOMEDS::TMPFile* GEOM_Gen_i::CopyFrom(SALOMEDS::SObject_ptr theObject, CORBA::Long& theObjectID) {
363   // Declare a sequence of the byte to store the copied object
364   SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile;
365
366   // Try to get GEOM_Object object by given SObject
367   SALOMEDS::GenericAttribute_var anAttr;
368   if (!theObject->FindAttribute(anAttr, "AttributeIOR")) return aStreamFile._retn();
369   GEOM::GEOM_Object_var anObject =  GEOM::GEOM_Object::_narrow(_orb->string_to_object(SALOMEDS::AttributeIOR::_narrow(anAttr)->Value()));
370   if (anObject->_is_nil()) return aStreamFile._retn();
371
372   aStreamFile = anObject->GetShapeStream();
373   
374   // Assign an ID  the type of  GEOM_Object
375   theObjectID = anObject->GetType();
376
377   // Return created TMPFile
378   return aStreamFile._retn();
379 }
380
381 //============================================================================
382 // function : CanPaste()
383 // purpose  :
384 //============================================================================
385 CORBA::Boolean GEOM_Gen_i::CanPaste(const char* theComponentName, CORBA::Long theObjectID) {
386   // The Geometry component can paste only objects copied by Geometry component
387   // and with the object type = 1
388   if (strcmp(theComponentName, ComponentDataType()) != 0) return false;
389   return true;
390 }
391
392 //============================================================================
393 // function : PasteInto()
394 // purpose  :
395 //============================================================================
396 SALOMEDS::SObject_ptr GEOM_Gen_i::PasteInto(const SALOMEDS::TMPFile& theStream,
397                                             CORBA::Long theObjectID,
398                                             SALOMEDS::SObject_ptr theObject) {
399   // Find the current Study and StudyBuilder
400   SALOMEDS::Study_var aStudy = theObject->GetStudy();
401   SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
402
403   // Retrieve a TopoDS_Shape from byte stream
404   TopoDS_Shape aTopology;
405   istrstream aStreamedBrep((char*) &theStream[0], theStream.length());
406   BRep_Builder aBuilder;
407   try {
408     BRepTools::Read(aTopology, aStreamedBrep, aBuilder);
409   } catch (Standard_Failure) {
410     return false;
411   }
412   
413   // SObject of the created shape is theObject or new Child of Component if theObject == geom component
414   SALOMEDS::SObject_var aNewSO;
415   if (strcmp(theObject->GetFatherComponent()->GetID(),theObject->GetID()) == 0) {
416     aNewSO = aStudyBuilder->NewObject(theObject);
417   } else aNewSO = SALOMEDS::SObject::_duplicate(theObject);
418
419   
420   //Create a new GEOM_Object 
421   Handle(GEOM_Object) anObj = _impl->AddObject(aNewSO->GetStudy()->StudyId(), theObjectID);  
422   Handle(GEOM_Function) aFunction = anObj->AddFunction(GEOMImpl_CopyDriver::GetID(), COPY_WITHOUT_REF);  
423   aFunction->SetValue(aTopology);
424
425   TCollection_AsciiString anEntry;  
426   TDF_Tool::Entry(anObj->GetEntry(), anEntry);  
427   GEOM::GEOM_Object_var obj = GetObject(anObj->GetDocID(), anEntry.ToCString());
428
429   // Add IORAttribute to the Study and set IOR of the created GEOM_Object to it
430   SALOMEDS::GenericAttribute_var anAttr = aStudyBuilder->FindOrCreateAttribute(aNewSO, "AttributeIOR");
431   SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
432   anIOR->SetValue(_orb->object_to_string(obj));
433
434   // Return the created in the Study SObject
435   return aNewSO._retn();
436 }
437
438 //============================================================================
439 // function : ComponentDataType()
440 // purpose  :
441 //============================================================================
442 char* GEOM_Gen_i::ComponentDataType()
443 {
444   return strdup("GEOM");
445 }
446
447 //============================================================================
448 // function : AddInStudy
449 // purpose  :
450 //============================================================================
451 SALOMEDS::SObject_ptr GEOM_Gen_i::AddInStudy(SALOMEDS::Study_ptr theStudy, GEOM::GEOM_Object_ptr theObject, const char* theName, GEOM::GEOM_Object_ptr theFather)
452 {
453   SALOMEDS::SObject_var aResultSO;
454   if(theObject->_is_nil() || theStudy->_is_nil()) return aResultSO;
455     
456   SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder(); 
457   char* IOR;
458
459   if(!theFather->_is_nil()) {
460     IOR = _orb->object_to_string(theFather); 
461     SALOMEDS::SObject_var aFatherSO = theStudy->FindObjectIOR(IOR);
462     if(aFatherSO->_is_nil()) return aResultSO._retn();
463     aResultSO = aStudyBuilder->NewObject(aFatherSO);
464     //aStudyBuilder->Addreference(aResultSO, aResultSO);
465   }   
466
467   aResultSO = PublishInStudy(theStudy, aResultSO, theObject, theName);
468   if(aResultSO->_is_nil()) return aResultSO._retn();
469
470   GEOM::ListOfGO_var aList = theObject->GetDependency();
471   Standard_Integer aLength = aList->length(); 
472   if(aLength < 1) return aResultSO._retn();
473
474   //Publish the arguments  
475   for(Standard_Integer i = 0; i< aLength; i++) {
476     GEOM::GEOM_Object_var anObject = aList[i];
477     if(anObject->_is_nil()) continue;
478     IOR = _orb->object_to_string(anObject);
479     SALOMEDS::SObject_var aSO =  theStudy->FindObjectIOR(IOR);
480     if(aSO->_is_nil()) continue;
481     SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aResultSO);
482     aStudyBuilder->Addreference(aSubSO, aSO);
483   }
484   
485   return aResultSO._retn();
486 }
487
488 //============================================================================
489 // function : register() 
490 // purpose  : register 'name' in 'name_service'
491 //============================================================================
492 void GEOM_Gen_i::register_name(char * name)
493 {
494   GEOM::GEOM_Gen_ptr g = GEOM::GEOM_Gen::_narrow(POA_GEOM::GEOM_Gen::_this());
495   name_service->Register(g, strdup(name)); 
496 }
497
498 //============================================================================
499 // function : Undo
500 // purpose  :
501 //============================================================================
502 void GEOM_Gen_i::Undo(CORBA::Long theStudyID)
503 {
504   _impl->Undo(theStudyID);
505 }
506
507 //============================================================================
508 // function : Redo
509 // purpose  :
510 //============================================================================
511 void GEOM_Gen_i::Redo(CORBA::Long theStudyID)
512 {
513   _impl->Redo(theStudyID);
514 }
515
516 //============================================================================
517 // function : GetIBasicOperations
518 // purpose  : 
519 //============================================================================
520 GEOM::GEOM_IBasicOperations_ptr GEOM_Gen_i::GetIBasicOperations(CORBA::Long theStudyID)
521      throw ( SALOME::SALOME_Exception )
522 {
523   Unexpect aCatch(SALOME_SalomeException);
524   MESSAGE( "GEOM_Gen_i::GetIBasicOperations" );
525
526   GEOM::GEOM_Gen_ptr engine = POA_GEOM::GEOM_Gen::_this(); 
527
528   GEOM_IBasicOperations_i* aServant =
529     new GEOM_IBasicOperations_i(_poa, engine, _impl->GetIBasicOperations(theStudyID));
530
531   // activate the CORBA servant 
532   GEOM::GEOM_IBasicOperations_var operations = aServant->_this();
533   return operations._retn();
534 }
535
536 //============================================================================
537 // function : GetITransformOperations
538 // purpose  : 
539 //============================================================================
540 GEOM::GEOM_ITransformOperations_ptr GEOM_Gen_i::GetITransformOperations(CORBA::Long theStudyID)
541      throw ( SALOME::SALOME_Exception )
542 {
543   Unexpect aCatch(SALOME_SalomeException);
544   MESSAGE( "GEOM_Gen_i::GetITransformOperations" );
545
546   GEOM::GEOM_Gen_ptr engine = POA_GEOM::GEOM_Gen::_this(); 
547
548   GEOM_ITransformOperations_i* aServant =
549     new GEOM_ITransformOperations_i(_poa, engine, _impl->GetITransformOperations(theStudyID));
550
551   // activate the CORBA servant 
552   GEOM::GEOM_ITransformOperations_var operations = aServant->_this();
553   return operations._retn();
554 }
555
556 //============================================================================
557 // function : GetI3DPrimOperations
558 // purpose  : 
559 //============================================================================
560 GEOM::GEOM_I3DPrimOperations_ptr GEOM_Gen_i::GetI3DPrimOperations(CORBA::Long theStudyID)
561      throw ( SALOME::SALOME_Exception )
562 {
563   Unexpect aCatch(SALOME_SalomeException);
564   MESSAGE( "GEOM_Gen_i::GetI3DPrimOperations" );
565
566   GEOM::GEOM_Gen_ptr engine = POA_GEOM::GEOM_Gen::_this(); 
567
568   GEOM_I3DPrimOperations_i* aServant =
569     new GEOM_I3DPrimOperations_i(_poa, engine, _impl->GetI3DPrimOperations(theStudyID));
570
571   // activate the CORBA servant 
572   GEOM::GEOM_I3DPrimOperations_var operations = aServant->_this();
573   return operations._retn();
574 }
575
576 //============================================================================
577 // function : GetIShapesOperations
578 // purpose  : 
579 //============================================================================
580 GEOM::GEOM_IShapesOperations_ptr GEOM_Gen_i::GetIShapesOperations(CORBA::Long theStudyID)
581      throw ( SALOME::SALOME_Exception )
582 {
583   Unexpect aCatch(SALOME_SalomeException);
584   MESSAGE( "GEOM_Gen_i::GetIShapesOperations" );
585
586   GEOM::GEOM_Gen_ptr engine = POA_GEOM::GEOM_Gen::_this(); 
587
588   GEOM_IShapesOperations_i* aServant =
589     new GEOM_IShapesOperations_i(_poa, engine, _impl->GetIShapesOperations(theStudyID));
590
591   // activate the CORBA servant 
592   GEOM::GEOM_IShapesOperations_var operations = aServant->_this();
593   return operations._retn();
594 }
595
596 //============================================================================
597 // function : GetIBlocksOperations
598 // purpose  : 
599 //============================================================================
600 GEOM::GEOM_IBlocksOperations_ptr GEOM_Gen_i::GetIBlocksOperations(CORBA::Long theStudyID)
601      throw ( SALOME::SALOME_Exception )
602 {
603   Unexpect aCatch(SALOME_SalomeException);
604   MESSAGE( "GEOM_Gen_i::GetIBlocksOperations" );
605
606   GEOM::GEOM_Gen_ptr engine = POA_GEOM::GEOM_Gen::_this(); 
607
608   GEOM_IBlocksOperations_i* aServant =
609     new GEOM_IBlocksOperations_i(_poa, engine, _impl->GetIBlocksOperations(theStudyID));
610
611   // activate the CORBA servant 
612   GEOM::GEOM_IBlocksOperations_var operations = aServant->_this();
613   return operations._retn();
614 }
615
616 //============================================================================
617 // function : GetIBooleanOperations
618 // purpose  : 
619 //============================================================================
620 GEOM::GEOM_IBooleanOperations_ptr GEOM_Gen_i::GetIBooleanOperations(CORBA::Long theStudyID)
621      throw ( SALOME::SALOME_Exception )
622 {
623   Unexpect aCatch(SALOME_SalomeException);
624   MESSAGE( "GEOM_Gen_i::GetIBooleanOperations" );
625
626   GEOM::GEOM_Gen_ptr engine = POA_GEOM::GEOM_Gen::_this(); 
627
628   GEOM_IBooleanOperations_i* aServant =
629     new GEOM_IBooleanOperations_i(_poa, engine, _impl->GetIBooleanOperations(theStudyID));
630
631   // activate the CORBA servant 
632   GEOM::GEOM_IBooleanOperations_var operations = aServant->_this();
633   return operations._retn();
634 }
635
636 //============================================================================
637 // function : GetICurvesOperations
638 // purpose  : 
639 //============================================================================
640 GEOM::GEOM_ICurvesOperations_ptr GEOM_Gen_i::GetICurvesOperations(CORBA::Long theStudyID)
641      throw ( SALOME::SALOME_Exception )
642 {
643   Unexpect aCatch(SALOME_SalomeException);
644   MESSAGE( "GEOM_Gen_i::GetICurvesOperations" );
645
646   GEOM::GEOM_Gen_ptr engine = POA_GEOM::GEOM_Gen::_this(); 
647
648   GEOM_ICurvesOperations_i* aServant =
649     new GEOM_ICurvesOperations_i(_poa, engine, _impl->GetICurvesOperations(theStudyID));
650
651   // activate the CORBA servant 
652   GEOM::GEOM_ICurvesOperations_var operations = aServant->_this();
653   return operations._retn();
654 }
655
656 //============================================================================
657 // function : GetILocalOperations
658 // purpose  : 
659 //============================================================================
660 GEOM::GEOM_ILocalOperations_ptr GEOM_Gen_i::GetILocalOperations(CORBA::Long theStudyID)
661      throw ( SALOME::SALOME_Exception )
662 {
663   Unexpect aCatch(SALOME_SalomeException);
664   MESSAGE( "GEOM_Gen_i::GetILocalOperations" );
665
666   GEOM::GEOM_Gen_ptr engine = POA_GEOM::GEOM_Gen::_this(); 
667
668   GEOM_ILocalOperations_i* aServant =
669     new GEOM_ILocalOperations_i(_poa, engine, _impl->GetILocalOperations(theStudyID));
670
671   // activate the CORBA servant 
672   GEOM::GEOM_ILocalOperations_var operations = aServant->_this();
673   return operations._retn();
674 }
675
676 //============================================================================
677 // function : GetIHealingOperations
678 // purpose  : 
679 //============================================================================
680 GEOM::GEOM_IHealingOperations_ptr GEOM_Gen_i::GetIHealingOperations(CORBA::Long theStudyID)
681      throw ( SALOME::SALOME_Exception )
682 {
683   Unexpect aCatch(SALOME_SalomeException);
684   MESSAGE( "GEOM_Gen_i::IHealingOperations" );
685
686   GEOM::GEOM_Gen_ptr engine = POA_GEOM::GEOM_Gen::_this(); 
687
688   GEOM_IHealingOperations_i* aServant =
689     new GEOM_IHealingOperations_i(_poa, engine, _impl->GetIHealingOperations(theStudyID));
690
691   // activate the CORBA servant 
692   GEOM::GEOM_IHealingOperations_var operations = aServant->_this();
693   return operations._retn();
694 }
695
696 //============================================================================
697 // function : GetIInsertOperations
698 // purpose  : 
699 //============================================================================
700 GEOM::GEOM_IInsertOperations_ptr GEOM_Gen_i::GetIInsertOperations(CORBA::Long theStudyID)
701      throw ( SALOME::SALOME_Exception )
702 {
703   Unexpect aCatch(SALOME_SalomeException);
704   MESSAGE( "GEOM_Gen_i::GetIInsertOperations" );
705
706   GEOM::GEOM_Gen_ptr engine = POA_GEOM::GEOM_Gen::_this(); 
707
708   GEOM_IInsertOperations_i* aServant =
709     new GEOM_IInsertOperations_i(_poa, engine, _impl->GetIInsertOperations(theStudyID));
710
711   // activate the CORBA servant 
712   GEOM::GEOM_IInsertOperations_var operations = aServant->_this();
713   return operations._retn();
714 }
715
716 //============================================================================
717 // function : GetIMeasureOperations
718 // purpose  : 
719 //============================================================================
720 GEOM::GEOM_IMeasureOperations_ptr GEOM_Gen_i::GetIMeasureOperations(CORBA::Long theStudyID)
721      throw ( SALOME::SALOME_Exception )
722 {
723   Unexpect aCatch(SALOME_SalomeException);
724   MESSAGE( "GEOM_Gen_i::GetIMeasureOperations" );
725
726   GEOM::GEOM_Gen_ptr engine = POA_GEOM::GEOM_Gen::_this(); 
727
728   GEOM_IMeasureOperations_i* aServant =
729     new GEOM_IMeasureOperations_i(_poa, engine, _impl->GetIMeasureOperations(theStudyID));
730
731   // activate the CORBA servant 
732   GEOM::GEOM_IMeasureOperations_var operations = aServant->_this();
733   return operations._retn();
734 }
735
736 //============================================================================
737 // function : GetIGroupOperations
738 // purpose  : 
739 //============================================================================
740 GEOM::GEOM_IGroupOperations_ptr GEOM_Gen_i::GetIGroupOperations(CORBA::Long theStudyID)
741      throw ( SALOME::SALOME_Exception )
742 {
743   Unexpect aCatch(SALOME_SalomeException);
744   MESSAGE( "GEOM_Gen_i::GetIGroupOperations" );
745
746   GEOM::GEOM_Gen_ptr engine = POA_GEOM::GEOM_Gen::_this(); 
747
748   GEOM_IGroupOperations_i* aServant =
749     new GEOM_IGroupOperations_i(_poa, engine, _impl->GetIGroupOperations(theStudyID));
750
751   // activate the CORBA servant 
752   GEOM::GEOM_IGroupOperations_var operations = aServant->_this();
753   return operations._retn();
754 }
755
756 //=============================================================================
757 /*!
758  *  AddSubShape
759  */
760 //=============================================================================
761 GEOM::GEOM_Object_ptr GEOM_Gen_i::AddSubShape(GEOM::GEOM_Object_ptr theMainShape, const GEOM::ListOfLong& theIndices)
762 {
763   if(theMainShape == NULL || theIndices.length() < 1) return GEOM::GEOM_Object::_nil();
764   Handle(GEOM_Object) aMainsShape = _impl->GetObject(theMainShape->GetStudyID(), theMainShape->GetEntry());
765   if (aMainsShape.IsNull()) return GEOM::GEOM_Object::_nil();
766   
767   Handle(TColStd_HArray1OfInteger) anArray = new TColStd_HArray1OfInteger(1, theIndices.length());
768   for(Standard_Integer i = 0; i<theIndices.length(); i++) anArray->SetValue(i+1, theIndices[i]);
769
770   Handle(GEOM_Object) anObject = _impl->AddSubShape(aMainsShape, anArray);
771   if(anObject.IsNull()) return GEOM::GEOM_Object::_nil();
772
773   TCollection_AsciiString anEntry;
774   TDF_Tool::Entry(anObject->GetEntry(), anEntry);
775   return GetObject(anObject->GetDocID(), anEntry.ToCString());
776 }
777
778 //=============================================================================
779 /*!
780  *  RemoveObject
781  */
782 //=============================================================================
783 void GEOM_Gen_i::RemoveObject(GEOM::GEOM_Object_ptr theObject)         
784 {
785   Handle(GEOM_Object) anObject = _impl->GetObject(theObject->GetStudyID(), theObject->GetEntry());
786   if (anObject.IsNull()) return;
787   _impl->RemoveObject(anObject);
788   return; 
789 }  
790
791
792 //=================================================================================
793 // function : GetStringFromIOR()
794 // purpose  : returns a string that represents  a 'GEOM::GEOM_Object_var'
795 //=================================================================================
796 char* GEOM_Gen_i::GetStringFromIOR(GEOM::GEOM_Object_ptr theObject) {
797   return _orb->object_to_string(theObject);
798 }
799
800
801 //=================================================================================
802 // function : GetIORFromString()
803 // purpose  : returns a 'GEOM::GEOM_Object_var' from a string representing it
804 //=================================================================================
805 GEOM::GEOM_Object_ptr GEOM_Gen_i::GetIORFromString(const char* stringIOR) {
806   GEOM::GEOM_Object_var aGeomObject;
807   if(strcmp(stringIOR,"") != 0){
808     CORBA::Object_var anObject = _orb->string_to_object(stringIOR);
809     if(!CORBA::is_nil(anObject))
810       aGeomObject =  GEOM::GEOM_Object::_narrow(anObject.in()) ;
811   }
812   return aGeomObject._retn() ;
813 }
814
815 //=================================================================================
816 // function : GetObject()
817 // purpose  : 
818 //=================================================================================
819 GEOM::GEOM_Object_ptr GEOM_Gen_i::GetObject(CORBA::Long theStudyID, const char* theEntry)
820 {
821   GEOM::GEOM_Object_var obj;
822   Handle(GEOM_Object) handle_object = _impl->GetObject(theStudyID, (char*)theEntry);
823   if(handle_object.IsNull()) return NULL;
824   TCollection_AsciiString stringIOR = handle_object->GetIOR();
825   if(stringIOR.Length() > 1) {
826     CORBA::Object_var corba_object = _orb->string_to_object(stringIOR.ToCString());
827     if(!CORBA::is_nil(corba_object)) obj = GEOM::GEOM_Object::_narrow(corba_object);
828     return obj._retn();  
829    }
830
831   GEOM::GEOM_Gen_ptr engine = POA_GEOM::GEOM_Gen::_this(); 
832   GEOM_Object_i* servant = new GEOM_Object_i(_poa, engine, handle_object);
833   
834   obj = servant->_this();
835   stringIOR =  _orb->object_to_string(obj);
836   handle_object->SetIOR(stringIOR);
837   return obj._retn(); 
838 }
839
840
841 //=====================================================================================
842 // EXPORTED METHODS
843 //=====================================================================================
844 extern "C"
845 {
846   PortableServer::ObjectId * GEOMEngine_factory(CORBA::ORB_ptr orb,
847                                                 PortableServer::POA_ptr poa, 
848                                                 PortableServer::ObjectId * contId,
849                                                 const char *instanceName, 
850                                                 const char * interfaceName)
851   {
852    GEOM_Gen_i * myGEOM_Gen_i = new GEOM_Gen_i(orb, poa, contId, instanceName, interfaceName);
853    myGEOM_Gen_i->register_name("/myGEOM_Gen"); // NRI : 11/07/2002 : Add for Supervision example 
854    return myGEOM_Gen_i->getId() ;
855   }
856 }
857