]> SALOME platform Git repositories - modules/geom.git/blob - src/GEOM_I/GEOM_Gen_i.cc
Salome HOME
For improvements 20019 and 20324.
[modules/geom.git] / src / GEOM_I / GEOM_Gen_i.cc
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21
22 #ifdef WNT
23 #pragma warning( disable:4786 )
24 #endif
25
26 #include <Standard_Stream.hxx>
27
28 #include "GEOM_Gen_i.hh"
29 #include "GEOM_Object_i.hh"
30
31 #include <strstream>
32 //#include <sstream>
33
34 #include "Utils_CorbaException.hxx"
35 #include "OpUtil.hxx"
36 #include "Utils_ExceptHandlers.hxx"
37 #include "utilities.h"
38
39 #include "GEOM_Object_i.hh"
40 #include "GEOM_Object.hxx"
41 #include "GEOM_Function.hxx"
42 #include "GEOM_ISubShape.hxx"
43 #include "GEOMImpl_Types.hxx"
44 #include "GEOMImpl_CopyDriver.hxx"
45
46 // Cascade headers
47 #include <BRep_Builder.hxx>
48 #include <BRepTools.hxx>
49 #include <TDF_Label.hxx>
50 #include <TDF_Tool.hxx>
51 #include <TDF_ChildIDIterator.hxx>
52 #include <TNaming_NamedShape.hxx>
53 #include <TDataStd_Name.hxx>
54 #include <TCollection_AsciiString.hxx>
55 #include <TColStd_HArray1OfInteger.hxx>
56 #include <TopAbs_ShapeEnum.hxx>
57 //#include <TopTools_IndexedMapOfShape.hxx>
58 #include <TopExp.hxx>
59 #include <OSD.hxx>
60
61 #include "SALOMEDS_Tool.hxx"
62
63 //============================================================================
64 // function : GEOM_Gen_i()
65 // purpose  : constructor to be called for servant creation.
66 //============================================================================
67 GEOM_Gen_i::GEOM_Gen_i(CORBA::ORB_ptr orb,
68                        PortableServer::POA_ptr poa,
69                        PortableServer::ObjectId * contId,
70                        const char *instanceName,
71                        const char *interfaceName) :
72   Engines_Component_i(orb, poa, contId, instanceName, interfaceName)
73 {
74   _thisObj = this;
75   _id = _poa->activate_object(_thisObj);
76   name_service = new SALOME_NamingService(_orb);
77
78   _impl = new ::GEOMImpl_Gen;
79
80   //PAL10867: disable signals catching with "noexcepthandler" option
81   char* envNoCatchSignals = getenv("NOT_INTERCEPT_SIGNALS");
82   if (!envNoCatchSignals || !atoi(envNoCatchSignals))
83   {
84     //work around PAL12004, PAL12628
85     //OSD::SetSignal( true );
86     bool raiseFPE;
87 #ifdef _DEBUG_
88     raiseFPE = true;
89     char* envDisableFPE = getenv("DISABLE_FPE");
90     if (envDisableFPE && atoi(envDisableFPE))
91       raiseFPE = false;
92 #else
93     raiseFPE = false;
94 #endif
95     OSD::SetSignal( raiseFPE );
96   }
97 }
98
99 //============================================================================
100 // function : ~GEOM_Gen_i()
101 // purpose  : destructor
102 //============================================================================
103 GEOM_Gen_i::~GEOM_Gen_i() {
104   delete name_service;
105   delete _impl;
106 }
107
108
109 //============================================================================
110 // function : IORToLocalPersistentID()
111 // purpose  :
112 //============================================================================
113 char* GEOM_Gen_i::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject,
114                                          const char* IORString,
115                                          CORBA::Boolean isMultiFile,
116                                          CORBA::Boolean isASCII)
117 {
118   GEOM::GEOM_Object_var anObject = GEOM::GEOM_Object::_narrow(_orb->string_to_object(IORString));
119   if (!CORBA::is_nil(anObject)) {
120     return CORBA::string_dup(anObject->GetEntry());
121   }
122   return 0;
123 }
124
125
126 //============================================================================
127 // function : LocalPersistentIDToIOR()
128 // purpose  : Create/Load CORBA object from a persistent ref (an entry)
129 //          : Used when a study is loaded
130 //          : The IOR (IORName) of object created is returned
131 //============================================================================
132 char* GEOM_Gen_i::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject,
133                                          const char* aLocalPersistentID,
134                                          CORBA::Boolean isMultiFile,
135                                          CORBA::Boolean isASCII)
136 {
137   SALOMEDS::Study_var aStudy = theSObject->GetStudy();
138
139   Handle(GEOM_Object) anObject = _impl->GetObject(aStudy->StudyId(), const_cast<char*>(aLocalPersistentID));
140   TCollection_AsciiString anEntry;
141   TDF_Tool::Entry(anObject->GetEntry(), anEntry);
142   GEOM::GEOM_Object_var obj = GetObject(anObject->GetDocID(), anEntry.ToCString());
143
144   CORBA::String_var aPersRefString = _orb->object_to_string(obj);
145   return CORBA::string_dup(aPersRefString);
146 }
147
148 //============================================================================
149 // function : CanPublishInStudy
150 // purpose  :
151 //============================================================================
152 bool GEOM_Gen_i::CanPublishInStudy(CORBA::Object_ptr theIOR)
153 {
154   GEOM::GEOM_Object_var anObject = GEOM::GEOM_Object::_narrow(theIOR);
155   return !(anObject->_is_nil());
156 }
157
158
159 //============================================================================
160 // function : PublishInStudy
161 // purpose  :
162 //============================================================================
163 SALOMEDS::SObject_ptr GEOM_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy,
164                                                  SALOMEDS::SObject_ptr theSObject,
165                                                  CORBA::Object_ptr theObject,
166                                                  const char* theName) throw (SALOME::SALOME_Exception)
167 {
168   Unexpect aCatch(SALOME_SalomeException);
169   SALOMEDS::SObject_var aResultSO;
170   if(CORBA::is_nil(theObject) || theStudy->_is_nil()) return aResultSO;
171   GEOM::GEOM_Object_var aShape = GEOM::GEOM_Object::_narrow(theObject);
172   if(aShape->_is_nil()) return aResultSO;
173
174   SALOMEDS::GenericAttribute_var anAttr;
175   SALOMEDS::StudyBuilder_var     aStudyBuilder = theStudy->NewBuilder();
176
177   SALOMEDS::SComponent_var       aFather = theStudy->FindComponent("GEOM");
178   if (aFather->_is_nil()) {
179     aFather = aStudyBuilder->NewComponent("GEOM");
180     anAttr = aStudyBuilder->FindOrCreateAttribute(aFather, "AttributeName");
181     SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
182     aName->SetValue("Geometry");
183     anAttr = aStudyBuilder->FindOrCreateAttribute(aFather, "AttributePixMap");
184     SALOMEDS::AttributePixMap::_narrow(anAttr)->SetPixMap("ICON_OBJBROWSER_Geometry");
185     aStudyBuilder->DefineComponentInstance(aFather, GEOM_Gen::_this());
186   }
187   if (aFather->_is_nil()) return aResultSO;
188
189   if (CORBA::is_nil(theSObject)) {
190     aResultSO = aStudyBuilder->NewObject(aFather);
191   } else {
192     if (!theSObject->ReferencedObject(aResultSO))
193       aResultSO = SALOMEDS::SObject::_duplicate(theSObject); //SRN: Added Aug 24,2004 : for  the method AddInStudy with theFather argumenet != NULL
194       //THROW_SALOME_CORBA_EXCEPTION("Publish in study supervision graph error",SALOME::BAD_PARAM);
195   }
196   anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeIOR");
197   SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
198   //char *aGeomObjIOR = _orb->object_to_string(theObject);
199    CORBA::String_var aGeomObjIOR = _orb->object_to_string(theObject);
200   //anIOR->SetValue(CORBA::string_dup(aGeomObjIOR));
201   anIOR->SetValue(aGeomObjIOR);
202
203   anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributePixMap");
204   SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
205   TCollection_AsciiString aShapeName("Shape_");
206
207   if ( aShape->GetType() == GEOM_GROUP ) {
208     GEOM::GEOM_IGroupOperations_var anOp = GetIGroupOperations( theStudy->StudyId() );
209     switch ( (TopAbs_ShapeEnum)anOp->GetType( aShape ) ) {
210     case TopAbs_VERTEX:
211       aPixmap->SetPixMap( "ICON_OBJBROWSER_GROUP_PNT" );
212       aShapeName = "Group_Of_Vertices_";
213       break;
214     case TopAbs_EDGE:
215       aPixmap->SetPixMap( "ICON_OBJBROWSER_GROUP_EDGE" );
216       aShapeName = "Group_Of_Edges_";
217       break;
218     case TopAbs_FACE:
219       aPixmap->SetPixMap( "ICON_OBJBROWSER_GROUP_FACE" );
220       aShapeName = "Group_Of_Faces_";
221       break;
222     case TopAbs_SOLID:
223       aPixmap->SetPixMap( "ICON_OBJBROWSER_GROUP_SOLID" );
224       aShapeName = "Group_Of_Solids_";
225       break;
226     }
227   } else if ( aShape->GetType() == GEOM_MARKER ) {
228     aPixmap->SetPixMap( "ICON_OBJBROWSER_LCS" );
229     aShapeName = "LocalCS_";
230   } else if ( aShape->GetShapeType() == GEOM::COMPOUND ) {
231     aPixmap->SetPixMap( "ICON_OBJBROWSER_COMPOUND" );
232     aShapeName = "Compound_";
233   } else if ( aShape->GetShapeType() == GEOM::COMPSOLID ) {
234     aPixmap->SetPixMap( "ICON_OBJBROWSER_COMPSOLID" );
235     aShapeName = "Compsolid_";
236   } else if ( aShape->GetShapeType() == GEOM::SOLID ) {
237     aPixmap->SetPixMap( "ICON_OBJBROWSER_SOLID" );
238     aShapeName = "Solid_";
239   } else if ( aShape->GetShapeType() == GEOM::SHELL ) {
240     aPixmap->SetPixMap( "ICON_OBJBROWSER_SHELL" );
241     aShapeName = "Shell_";
242   } else if ( aShape->GetShapeType() == GEOM::FACE ) {
243     aPixmap->SetPixMap( "ICON_OBJBROWSER_FACE" );
244     aShapeName = "Face_";
245   } else if ( aShape->GetShapeType() == GEOM::WIRE ) {
246     aPixmap->SetPixMap( "ICON_OBJBROWSER_WIRE" );
247     aShapeName = "Wire_";
248   } else if ( aShape->GetShapeType() == GEOM::EDGE ) {
249     aPixmap->SetPixMap( "ICON_OBJBROWSER_EDGE" );
250     aShapeName = "Edge_";
251   } else if ( aShape->GetShapeType() == GEOM::VERTEX ) {
252     aPixmap->SetPixMap( "ICON_OBJBROWSER_VERTEX" );
253     aShapeName = "Vertex_";
254   }
255   //if (strlen(theName) == 0) aShapeName += TCollection_AsciiString(aResultSO->Tag());
256   //else aShapeName = TCollection_AsciiString(CORBA::string_dup(theName));
257   
258   // try to find existed name for current shape
259   bool HasName = false;
260   // recieve current TopoDS shape
261   CORBA::String_var entry = aShape->GetEntry();
262   Handle(GEOM_Object) aGShape = _impl->GetObject(aShape->GetStudyID(), entry);
263   TopoDS_Shape TopoSh = aGShape->GetValue();
264   // find label of main shape
265   GEOM::GEOM_Object_var aMainShVar = aShape;
266   GEOM::GEOM_Object_ptr aMainSh = aMainShVar._retn();
267   while( !aMainSh->IsMainShape() ) {
268     aMainSh = aMainSh->GetMainShape();
269   }
270   entry = aMainSh->GetEntry();
271   Handle(GEOM_Object) anObj = _impl->GetObject(aMainSh->GetStudyID(), entry);
272   TDF_Label aMainLbl = anObj->GetEntry();
273   // check all named shapes using iterator
274   TDF_ChildIDIterator anIt(aMainLbl, TNaming_NamedShape::GetID(), Standard_True);
275   for(; anIt.More(); anIt.Next()) {
276     Handle(TNaming_NamedShape) anAttr =
277       Handle(TNaming_NamedShape)::DownCast(anIt.Value());
278     if(anAttr.IsNull()) continue;
279     TopoDS_Shape S = anAttr->Get();
280     if( !S.IsEqual(TopoSh) ) continue;
281     TDF_Label L = anAttr->Label();
282     Handle(TDataStd_Name) aName;
283     if(L.FindAttribute(TDataStd_Name::GetID(),aName)) {
284       aShapeName = aName->Get();
285       HasName = true;
286     }
287   }
288
289   if(!HasName) {
290     // asv : 11.11.04 Introducing a more sofisticated method of name creation, just as
291     //       it is done in GUI in GEOMBase::GetDefaultName() - not just add a Tag() == number
292     //       of objects in the study, but compute a number of objects with the same prefix
293     //       and build a new name as Prefix_N+1
294     if ( strlen( theName ) == 0 ) { // MOST PROBABLY CALLED FROM BATCHMODE OR SUPERVISOR
295       int i = 0;                    // (WITH EMPTY NEW NAME)
296       SALOMEDS::SObject_var obj;
297       TCollection_AsciiString aNewShapeName;
298       do {
299         aNewShapeName = aShapeName + TCollection_AsciiString(++i);
300         obj = theStudy->FindObject( aNewShapeName.ToCString() );
301       }
302       while ( !obj->_is_nil() );
303       aShapeName = aNewShapeName;
304     }
305     else // MOST PROBABLY CALLED FROM GEOM GUI (ALREADY WITH VALID NAME)
306       aShapeName = TCollection_AsciiString((char*)theName);
307   }
308
309   //Set the study entry as a name of  the published GEOM_Object
310   aShape->SetStudyEntry(aResultSO->GetID());
311
312   //Set a name of the added shape
313   anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeName");
314   SALOMEDS::AttributeName_var aNameAttrib = SALOMEDS::AttributeName::_narrow(anAttr);
315   aNameAttrib->SetValue(aShapeName.ToCString());
316
317   //Set NoteBook variables used in the object creation
318   TCollection_AsciiString aVars;
319   SALOMEDS::ListOfListOfStrings_var aSections = theStudy->ParseVariables(aShape->GetParameters());
320   for(int i = 0, n = aSections->length(); i < n; i++) {
321     SALOMEDS::ListOfStrings aListOfVars = aSections[i];
322     for(int j = 0, m = aListOfVars.length(); j < m; j++) {
323       if(theStudy->IsVariable(aListOfVars[j].in()))
324         aVars += TCollection_AsciiString(aListOfVars[j].in());
325       if(j != m-1)
326         aVars += ":";
327     }
328     if(i != n-1)
329       aVars += "|";
330   }
331   anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeString");
332   SALOMEDS::AttributeString_var aStringAttrib = SALOMEDS::AttributeString::_narrow(anAttr);
333   aStringAttrib->SetValue(aVars.ToCString());
334
335   //Set a name of the GEOM object
336   aShape->SetName(theName);
337
338   return aResultSO._retn();
339 }
340
341
342 //============================================================================
343 // function : CreateAndPublishGroup
344 // purpose  : auxilary for PublishNamedShapesInStudy
345 //============================================================================
346 void GEOM_Gen_i::CreateAndPublishGroup(SALOMEDS::Study_ptr theStudy,
347                                        GEOM::GEOM_Object_var theMainShape,
348                                        const TopTools_IndexedMapOfShape& anIndices,
349                                        const TopTools_SequenceOfShape& SeqS,
350                                        const TColStd_SequenceOfAsciiString& SeqN,
351                                        const Standard_CString& GrName,
352                                        GEOM::ListOfGO_var aResList)
353 {
354   CORBA::String_var entry = theMainShape->GetEntry();
355   Handle(GEOM_Object) aMainShape = _impl->GetObject(theMainShape->GetStudyID(), entry);
356   Handle(TColStd_HArray1OfInteger) anArray;
357   if(SeqS.Length()>0) {
358     // create a group
359     GEOM::GEOM_IGroupOperations_var GOp = GetIGroupOperations(theStudy->StudyId());
360     GEOM::GEOM_Object_ptr GrObj =
361       GOp->CreateGroup( theMainShape, SeqS.Value(1).ShapeType() );
362     AddInStudy(theStudy, GrObj, GrName, theMainShape._retn());
363     // add named objects
364     Handle(GEOM_Object) anObj;
365     for(int i=1; i<=SeqS.Length(); i++) {
366       TopoDS_Shape aValue = SeqS.Value(i);
367       anArray = new TColStd_HArray1OfInteger(1,1);
368       Standard_Integer anIndex = anIndices.FindIndex(aValue);
369       anArray->SetValue(1, anIndex);
370       anObj = GEOM_Engine::GetEngine()->AddObject(aMainShape->GetDocID(), GEOM_SUBSHAPE);
371       if (anObj.IsNull()) continue;
372       Handle(GEOM_Function) aFunction = anObj->AddFunction(GEOM_Object::GetSubShapeID(), 1);
373       if (aFunction.IsNull()) continue;
374       GEOM_ISubShape aSSI(aFunction);
375       aSSI.SetMainShape(aMainShape->GetLastFunction());
376       aSSI.SetIndices(anArray);
377       aFunction->SetValue(aValue);
378       GOp->UnionIDs(GrObj, anIndex);
379       SALOMEDS::SObject_var aResultSO;
380       TCollection_AsciiString anEntry;
381       TDF_Tool::Entry(anObj->GetEntry(),anEntry);
382       GEOM::GEOM_Object_var aGObj = GetObject(anObj->GetDocID(), anEntry.ToCString());
383       AddInStudy(theStudy, aGObj._retn(), SeqN.Value(i).ToCString(), GrObj);
384     }
385   }
386 }
387
388
389 //============================================================================
390 // function : PublishNamedShapesInStudy
391 // purpose  :
392 //============================================================================
393 GEOM::ListOfGO* GEOM_Gen_i::
394             PublishNamedShapesInStudy(SALOMEDS::Study_ptr theStudy,
395                                       //SALOMEDS::SObject_ptr theSObject,
396                                       CORBA::Object_ptr theObject)
397 {
398   //Unexpect aCatch(SALOME_SalomeException);
399   GEOM::ListOfGO_var aResList = new GEOM::ListOfGO;
400
401   //CORBA::Object_var theObject = theSObject->GetObject();
402   GEOM::GEOM_Object_var theMainShape = GEOM::GEOM_Object::_narrow(theObject);
403   if(theMainShape->_is_nil()) return aResList._retn();
404
405   CORBA::String_var entry = theMainShape->GetEntry();
406   Handle(GEOM_Object) aMainShape = _impl->GetObject(theMainShape->GetStudyID(), entry);
407   if (aMainShape.IsNull()) return aResList._retn();
408   TopoDS_Shape MainSh = aMainShape->GetValue();
409
410   TDF_Label aMainLbl = aMainShape->GetEntry();
411   TopTools_SequenceOfShape SolidSeqS, FaceSeqS, EdgeSeqS, VertSeqS;
412   TColStd_SequenceOfAsciiString SolidSeqN, FaceSeqN, EdgeSeqN, VertSeqN;
413   TDF_ChildIDIterator anIt(aMainLbl, TNaming_NamedShape::GetID(), Standard_True);
414   for(; anIt.More(); anIt.Next()) {
415     Handle(TNaming_NamedShape) anAttr =
416       Handle(TNaming_NamedShape)::DownCast(anIt.Value());
417     if(anAttr.IsNull()) continue;
418     TopoDS_Shape S = anAttr->Get();
419     TDF_Label L = anAttr->Label();
420     //if(S.IsEqual(MainSh)) continue;
421     Handle(TDataStd_Name) aName;
422     if(L.FindAttribute(TDataStd_Name::GetID(),aName)) {
423       TCollection_ExtendedString EName = aName->Get();
424       if(S.ShapeType()==TopAbs_SOLID) {
425         SolidSeqS.Append(S);
426         SolidSeqN.Append(aName->Get());
427       }
428       else if(S.ShapeType()==TopAbs_FACE) {
429         FaceSeqS.Append(S);
430         FaceSeqN.Append(aName->Get());
431       }
432       else if(S.ShapeType()==TopAbs_EDGE) {
433         EdgeSeqS.Append(S);
434         EdgeSeqN.Append(aName->Get());
435       }
436       else if(S.ShapeType()==TopAbs_VERTEX) {
437         VertSeqS.Append(S);
438         VertSeqN.Append(aName->Get());
439       }
440     }
441   }
442
443   TopTools_IndexedMapOfShape anIndices;
444   TopExp::MapShapes(MainSh, anIndices);
445
446   CreateAndPublishGroup(theStudy, theMainShape, anIndices, SolidSeqS, SolidSeqN,
447                         "Group_Of_Named_Solids", aResList);
448
449   CreateAndPublishGroup(theStudy, theMainShape, anIndices, FaceSeqS, FaceSeqN,
450                         "Group_Of_Named_Faces", aResList);
451
452   CreateAndPublishGroup(theStudy, theMainShape, anIndices, EdgeSeqS, EdgeSeqN,
453                         "Group_Of_Named_Edges", aResList);
454
455   CreateAndPublishGroup(theStudy, theMainShape, anIndices, VertSeqS, VertSeqN,
456                         "Group_Of_Named_Vertices", aResList);
457
458   return aResList._retn();
459 }
460
461
462 //============================================================================
463 // function : Save()
464 // purpose  : save OCAF/Geom document
465 //============================================================================
466 SALOMEDS::TMPFile* GEOM_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent,
467                                     const char* theURL,
468                                     bool isMultiFile) {
469   SALOMEDS::TMPFile_var aStreamFile;
470   // Get a temporary directory to store a file
471   std::string aTmpDir = (isMultiFile)?theURL:SALOMEDS_Tool::GetTmpDir();
472
473   // OCCT BUG: cannot save a document (in current folder)
474   // if directory name is empty
475   if (aTmpDir.size() == 0) {
476 #ifdef WNT
477     aTmpDir = ".\\";
478 #else
479     aTmpDir = "./";
480 #endif
481   }
482
483   // Create a list to store names of created files
484   SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames;
485   aSeq->length(1);
486   // Prepare a file name to open
487   TCollection_AsciiString aNameWithExt("");
488   if (isMultiFile)
489     aNameWithExt = TCollection_AsciiString((char*)(SALOMEDS_Tool::GetNameFromPath
490                                                    (theComponent->GetStudy()->URL())).c_str());
491   aNameWithExt += TCollection_AsciiString("_GEOM.sgd");
492   aSeq[0] = CORBA::string_dup(aNameWithExt.ToCString());
493   // Build a full file name of temporary file
494   TCollection_AsciiString aFullName = TCollection_AsciiString((char*)aTmpDir.c_str()) + aNameWithExt;
495   // Save GEOM component in this file
496   _impl->Save(theComponent->GetStudy()->StudyId(),(char*) aFullName.ToCString());
497   // Conver a file to the byte stream
498   aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir.c_str(), aSeq.in(), isMultiFile);
499   // Remove the created file and tmp directory
500   if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.c_str(), aSeq.in(), true);
501
502   // Return the created byte stream
503   return aStreamFile._retn();
504 }
505
506
507 //============================================================================
508 // function : SaveASCII()
509 // purpose  :
510 //============================================================================
511 SALOMEDS::TMPFile* GEOM_Gen_i::SaveASCII(SALOMEDS::SComponent_ptr theComponent,
512                                          const char* theURL,
513                                          bool isMultiFile) {
514   SALOMEDS::TMPFile_var aStreamFile = Save(theComponent, theURL, isMultiFile);
515   return aStreamFile._retn();
516 }
517
518
519 //============================================================================
520 // function : Load()
521 // purpose  :
522 //============================================================================
523 CORBA::Boolean GEOM_Gen_i::Load(SALOMEDS::SComponent_ptr theComponent,
524                                 const SALOMEDS::TMPFile& theStream,
525                                 const char* theURL,
526                                 bool isMultiFile) {
527
528   if (theStream.length() <= 9) {
529     MESSAGE("The TMPFile is too short : " << theStream.length() << " bytes ");
530     return false;
531   }
532
533   // Get a temporary directory for a file
534   std::string aTmpDir = isMultiFile?theURL:SALOMEDS_Tool::GetTmpDir();
535
536   // OCCT BUG: cannot load a document (from current folder)
537   // if directory name is empty
538   if (aTmpDir.size() == 0) {
539 #ifdef WNT
540     aTmpDir = ".\\";
541 #else
542     aTmpDir = "./";
543 #endif
544   }
545
546   // Conver the byte stream theStream to a file and place it in tmp directory
547   SALOMEDS::ListOfFileNames_var aSeq =
548     SALOMEDS_Tool::PutStreamToFiles(theStream, aTmpDir.c_str(), isMultiFile);
549
550   // Prepare a file name to open
551   TCollection_AsciiString aNameWithExt("");
552   if (isMultiFile)
553     aNameWithExt = TCollection_AsciiString((char*)(SALOMEDS_Tool::GetNameFromPath
554                                                    (theComponent->GetStudy()->URL())).c_str());
555   aNameWithExt += TCollection_AsciiString("_GEOM.sgd");
556   TCollection_AsciiString aFullName = (TCollection_AsciiString((char*)aTmpDir.c_str()) + aNameWithExt);
557
558   // Open document
559   if (!_impl->Load(theComponent->GetStudy()->StudyId(),(char*) aFullName.ToCString())) return false;
560
561   // Remove the created file and tmp directory
562   if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.c_str(), aSeq.in(), true);
563
564   SALOMEDS::Study_var Study = theComponent->GetStudy();
565   TCollection_AsciiString name (Study->Name());
566
567   return true;
568 }
569
570
571 //============================================================================
572 // function : LoadASCII()
573 // purpose  :
574 //============================================================================
575 CORBA::Boolean GEOM_Gen_i::LoadASCII(SALOMEDS::SComponent_ptr theComponent,
576                                      const SALOMEDS::TMPFile& theStream,
577                                      const char* theURL,
578                                      bool isMultiFile) {
579   return Load(theComponent, theStream, theURL, isMultiFile);
580 }
581
582
583 //============================================================================
584 // function : Close()
585 // purpose  :
586 //============================================================================
587 void GEOM_Gen_i::Close(SALOMEDS::SComponent_ptr theComponent)
588 {
589   _impl->Close(theComponent->GetStudy()->StudyId());
590 }
591
592 //============================================================================
593 // function : CanCopy()
594 // purpose  :
595 //============================================================================
596 CORBA::Boolean GEOM_Gen_i::CanCopy(SALOMEDS::SObject_ptr theObject) {
597   // Try to retrieve known by Geometry component GEOM_Object by given IOR
598   SALOMEDS::GenericAttribute_var anAttr;
599   if (!theObject->FindAttribute(anAttr, "AttributeIOR")) return false;
600
601   SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
602
603   GEOM::GEOM_Object_var anObject = GEOM::GEOM_Object::_narrow(_orb->string_to_object(anIOR->Value()));
604   // If the object is null one it can't be copied: return false
605   if (anObject->_is_nil()) return false;
606   return true;
607 }
608
609 //============================================================================
610 // function : CopyFrom()
611 // purpose  :
612 //============================================================================
613 SALOMEDS::TMPFile* GEOM_Gen_i::CopyFrom(SALOMEDS::SObject_ptr theObject, CORBA::Long& theObjectID)
614 {
615   // Declare a sequence of the byte to store the copied object
616   SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile;
617
618   // Try to get GEOM_Object object by given SObject
619   SALOMEDS::GenericAttribute_var anAttr;
620   if (!theObject->FindAttribute(anAttr, "AttributeIOR")) return aStreamFile._retn();
621   GEOM::GEOM_Object_var anObject = GEOM::GEOM_Object::_narrow
622     (_orb->string_to_object(SALOMEDS::AttributeIOR::_narrow(anAttr)->Value()));
623   if (anObject->_is_nil()) return aStreamFile._retn();
624
625   aStreamFile = anObject->GetShapeStream();
626
627   // Assign an ID  the type of  GEOM_Object
628   theObjectID = anObject->GetType();
629
630   // Return created TMPFile
631   return aStreamFile._retn();
632 }
633
634 //============================================================================
635 // function : CanPaste()
636 // purpose  :
637 //============================================================================
638 CORBA::Boolean GEOM_Gen_i::CanPaste(const char* theComponentName, CORBA::Long theObjectID) {
639   // The Geometry component can paste only objects copied by Geometry component
640   // and with the object type = 1
641   if (strcmp(theComponentName, ComponentDataType()) != 0) return false;
642   return true;
643 }
644
645 //============================================================================
646 // function : PasteInto()
647 // purpose  :
648 //============================================================================
649 SALOMEDS::SObject_ptr GEOM_Gen_i::PasteInto(const SALOMEDS::TMPFile& theStream,
650                                             CORBA::Long theObjectID,
651                                             SALOMEDS::SObject_ptr theObject) {
652   // Find the current Study and StudyBuilder
653   SALOMEDS::Study_var aStudy = theObject->GetStudy();
654   SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
655
656   // Retrieve a TopoDS_Shape from byte stream
657   TopoDS_Shape aTopology;
658   istrstream aStreamedBrep((char*) &theStream[0], theStream.length());
659   BRep_Builder aBuilder;
660   try {
661     BRepTools::Read(aTopology, aStreamedBrep, aBuilder);
662   } catch (Standard_Failure) {
663     return false;
664   }
665
666   // SObject of the created shape is theObject or new Child of Component if theObject == geom component
667   SALOMEDS::SObject_var aNewSO;
668   if (strcmp(theObject->GetFatherComponent()->GetID(),theObject->GetID()) == 0) {
669     aNewSO = aStudyBuilder->NewObject(theObject);
670   } else aNewSO = SALOMEDS::SObject::_duplicate(theObject);
671
672
673   //Create a new GEOM_Object
674   Handle(GEOM_Object) anObj = _impl->AddObject(aNewSO->GetStudy()->StudyId(), theObjectID);
675   Handle(GEOM_Function) aFunction = anObj->AddFunction(GEOMImpl_CopyDriver::GetID(), COPY_WITHOUT_REF);
676   aFunction->SetValue(aTopology);
677
678   TCollection_AsciiString anEntry;
679   TDF_Tool::Entry(anObj->GetEntry(), anEntry);
680   GEOM::GEOM_Object_var obj = GetObject(anObj->GetDocID(), anEntry.ToCString());
681
682   //Set the study entry of the published GEOM_Object
683   obj->SetStudyEntry(aNewSO->GetID());
684
685   // Add IORAttribute to the Study and set IOR of the created GEOM_Object to it
686   SALOMEDS::GenericAttribute_var anAttr = aStudyBuilder->FindOrCreateAttribute(aNewSO, "AttributeIOR");
687   SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
688   CORBA::String_var objStr = _orb->object_to_string(obj);
689   anIOR->SetValue(objStr.in());
690
691   // Return the created in the Study SObject
692   return aNewSO._retn();
693 }
694
695 //============================================================================
696 // function : ComponentDataType()
697 // purpose  :
698 //============================================================================
699 char* GEOM_Gen_i::ComponentDataType()
700 {
701   return CORBA::string_dup("GEOM");
702 }
703
704 //============================================================================
705 // function : AddInStudy
706 // purpose  :
707 //============================================================================
708 SALOMEDS::SObject_ptr GEOM_Gen_i::AddInStudy (SALOMEDS::Study_ptr theStudy,
709                                               GEOM::GEOM_Object_ptr theObject,
710                                               const char* theName,
711                                               GEOM::GEOM_Object_ptr theFather)
712 {
713   SALOMEDS::SObject_var aResultSO;
714   if(theObject->_is_nil() || theStudy->_is_nil()) return aResultSO;
715
716   SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
717   CORBA::String_var IOR;
718
719   if(!theFather->_is_nil()) {
720     IOR = _orb->object_to_string(theFather);
721     SALOMEDS::SObject_var aFatherSO = theStudy->FindObjectIOR(IOR.in());
722     if(aFatherSO->_is_nil()) return aResultSO._retn();
723     aResultSO = aStudyBuilder->NewObject(aFatherSO);
724     //aStudyBuilder->Addreference(aResultSO, aResultSO);
725   }
726
727   aResultSO = PublishInStudy(theStudy, aResultSO, theObject, theName);
728   if(aResultSO->_is_nil()) return aResultSO._retn();
729
730   GEOM::ListOfGO_var aList = theObject->GetDependency();
731   Standard_Integer aLength = aList->length();
732   if(aLength < 1) return aResultSO._retn();
733
734   //Publish the arguments
735   for(Standard_Integer i = 0; i< aLength; i++) {
736     GEOM::GEOM_Object_var anObject = aList[i];
737     if(anObject->_is_nil()) continue;
738     IOR = _orb->object_to_string(anObject);
739     SALOMEDS::SObject_var aSO =  theStudy->FindObjectIOR(IOR.in());
740     if(aSO->_is_nil()) continue;
741     SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(aResultSO);
742     aStudyBuilder->Addreference(aSubSO, aSO);
743   }
744
745   return aResultSO._retn();
746 }
747
748 //============================================================================
749 // function : RestoreSubShapesO
750 // purpose  : Publish sub-shapes, standing for arguments and sub-shapes of arguments.
751 //            To be used from python scripts out of geompy.addToStudy (non-default usage)
752 //============================================================================
753 CORBA::Boolean GEOM_Gen_i::RestoreSubShapesO (SALOMEDS::Study_ptr     theStudy,
754                                               GEOM::GEOM_Object_ptr   theObject,
755                                               const GEOM::ListOfGO&   theArgs,
756                                               GEOM::find_shape_method theFindMethod,
757                                               CORBA::Boolean          theInheritFirstArg)
758 {
759   if (CORBA::is_nil(theStudy) || CORBA::is_nil(theObject))
760     return false;
761
762   // find SObject in the study
763   CORBA::String_var anIORo = _orb->object_to_string(theObject);
764   SALOMEDS::SObject_var aSO = theStudy->FindObjectIOR(anIORo.in());
765   if (CORBA::is_nil(aSO))
766     return false;
767
768   return RestoreSubShapes(theStudy, theObject, aSO, theArgs, theFindMethod, theInheritFirstArg);
769 }
770
771 //============================================================================
772 // function : RestoreSubShapesSO
773 // purpose  : Publish sub-shapes, standing for arguments and sub-shapes of arguments.
774 //            To be used from GUI and from geompy.addToStudy
775 //============================================================================
776 CORBA::Boolean GEOM_Gen_i::RestoreSubShapesSO (SALOMEDS::Study_ptr     theStudy,
777                                                SALOMEDS::SObject_ptr   theSObject,
778                                                const GEOM::ListOfGO&   theArgs,
779                                                GEOM::find_shape_method theFindMethod,
780                                                CORBA::Boolean          theInheritFirstArg)
781 {
782   if (CORBA::is_nil(theStudy) || CORBA::is_nil(theSObject))
783     return false;
784
785   SALOMEDS::GenericAttribute_var anAttr;
786   if (!theSObject->FindAttribute(anAttr, "AttributeIOR"))
787     return false;
788
789   SALOMEDS::AttributeIOR_var anAttrIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
790   CORBA::String_var anIORso = anAttrIOR->Value();
791
792   // get Object from SObject
793   GEOM::GEOM_Object_var anO = GEOM::GEOM_Object::_narrow(_orb->string_to_object(anIORso));
794   if (CORBA::is_nil(anO))
795     return false;
796
797   return RestoreSubShapes(theStudy, anO, theSObject, theArgs, theFindMethod, theInheritFirstArg);
798 }
799
800 //============================================================================
801 // function : RestoreSubShapes
802 // purpose  : Private method. Works only if both theObject and theSObject
803 //            are defined, and does not check, if they correspond to each other.
804 //============================================================================
805 CORBA::Boolean GEOM_Gen_i::RestoreSubShapes (SALOMEDS::Study_ptr     theStudy,
806                                              GEOM::GEOM_Object_ptr   theObject,
807                                              SALOMEDS::SObject_ptr   theSObject,
808                                              const GEOM::ListOfGO&   theArgs,
809                                              GEOM::find_shape_method theFindMethod,
810                                              CORBA::Boolean          theInheritFirstArg)
811 {
812   if (CORBA::is_nil(theStudy) || CORBA::is_nil(theObject) || CORBA::is_nil(theSObject))
813     return false;
814
815   // Arguments to be published
816   GEOM::ListOfGO_var aList;
817
818   // If theArgs list is empty, we try to publish all arguments,
819   // otherwise publish only passed args
820   Standard_Integer nbArgsActual = -1; // -1 means unknown
821   Standard_Integer aLength = theArgs.length();
822   if (aLength > 0) {
823     aList = new GEOM::ListOfGO;
824     aList->length(aLength);
825     for (int i = 0; i < aLength; i++) {
826       aList[i] = theArgs[i];
827     }
828   }
829   else {
830     // Get all arguments
831     aList = theObject->GetDependency();
832     aLength = aList->length();
833     nbArgsActual = aLength;
834   }
835
836   if (aLength < 1)
837     return false;
838
839   if (theInheritFirstArg || (nbArgsActual == 1)) {
840     // Do not publish argument's reflection,
841     // but only reconstruct its published sub-shapes
842
843     GEOM::GEOM_Object_var anArgO = aList[0];
844     CORBA::String_var anIOR = _orb->object_to_string(anArgO);
845     SALOMEDS::SObject_var anArgSO = theStudy->FindObjectIOR(anIOR.in());
846
847     GEOM::ListOfGO_var aParts =
848       RestoreSubShapesOneLevel(theStudy, anArgSO, theSObject, theObject, theFindMethod);
849
850     // set the color of the transformed shape to the color of initial shape
851     theObject->SetColor(aList[0]->GetColor());
852
853     return (aParts->length() > 0);
854   }
855
856   // Get interface, containing method, which we will use to reconstruct sub-shapes
857   GEOM::GEOM_IShapesOperations_var aShapesOp = GetIShapesOperations(theStudy->StudyId());
858   GEOM::GEOM_IGroupOperations_var  aGroupOp  = GetIGroupOperations(theStudy->StudyId());
859
860   // Reconstruct arguments and tree of sub-shapes of the arguments
861   CORBA::String_var anIOR;
862   SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
863   for (Standard_Integer i = 0; i < aLength; i++)
864   {
865     GEOM::GEOM_Object_var anArgO = aList[i];
866     if (!CORBA::is_nil(anArgO)) {
867       anIOR = _orb->object_to_string(anArgO);
868       SALOMEDS::SObject_var anArgSO = theStudy->FindObjectIOR(anIOR.in());
869       TCollection_AsciiString anArgName;
870       if (CORBA::is_nil(anArgSO)) {
871         anArgName = "arg_";
872         anArgName += TCollection_AsciiString(i);
873       }
874       else {
875         anArgName = anArgSO->GetName();
876       }
877
878       // Find a sub-shape of theObject in place of the argument
879       GEOM::GEOM_Object_var aSubO;
880       switch (theFindMethod) {
881       case GEOM::FSM_GetInPlace:
882         {
883           // Use GetInPlace
884           aSubO = aShapesOp->GetInPlace(theObject, anArgO);
885         }
886         break;
887       case GEOM::FSM_Transformed:
888         {
889           // transformation, cannot use GetInPlace, operate with indices
890           GEOM::ListOfLong_var anIDs = anArgO->GetSubShapeIndices();
891           if (anIDs->length() > 1) {
892             // group
893             aSubO = aGroupOp->CreateGroup(theObject, aGroupOp->GetType(anArgO));
894             if (!CORBA::is_nil(aSubO))
895               aGroupOp->UnionIDs(aSubO, anIDs);
896           }
897           else {
898             // single sub-shape
899             aSubO = aShapesOp->GetSubShape(theObject, anIDs[0]);
900           }
901         }
902         break;
903       case GEOM::FSM_GetSame:
904         {
905           // Use GetSame
906           aSubO = aShapesOp->GetSame(theObject, anArgO);
907         }
908         break;
909       case GEOM::FSM_GetShapesOnShape:
910         {
911           // Use GetShapesOnShape. Can work only on solids, so it has sense to search only solids
912           aSubO = aShapesOp->GetShapesOnShapeAsCompound(anArgO, theObject,
913                                                         (short)GEOM::SOLID, GEOM::ST_ONIN);
914         }
915         break;
916       case GEOM::FSM_GetInPlaceByHistory:
917         {
918           // Use GetInPlaceByHistory
919           aSubO = aShapesOp->GetInPlaceByHistory(theObject, anArgO);
920         }
921         break;
922       default:
923         {}
924       }
925
926       if (!CORBA::is_nil(aSubO)) {
927         // Publish the sub-shape
928         TCollection_AsciiString aSubName ("from_");
929         aSubName += anArgName;
930         SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(theSObject);
931         aSubSO = PublishInStudy(theStudy, aSubSO, aSubO, aSubName.ToCString());
932         // Restore color
933         aSubO->SetColor(anArgO->GetColor());
934
935         if (!CORBA::is_nil(anArgSO)) {
936           // Restore published sub-shapes of the argument
937           if (theFindMethod == GEOM::FSM_GetInPlaceByHistory)
938             // pass theObject, because only it has the history
939             RestoreSubShapesOneLevel(theStudy, anArgSO, aSubSO, theObject, theFindMethod);
940           else
941             RestoreSubShapesOneLevel(theStudy, anArgSO, aSubSO, aSubO, theFindMethod);
942         }
943       }
944       else { // GetInPlace failed, try to build from published parts
945         if (!CORBA::is_nil(anArgSO)) {
946           SALOMEDS::SObject_var aSubSO = aStudyBuilder->NewObject(theSObject);
947
948           // Restore published sub-shapes of the argument
949           GEOM::ListOfGO_var aParts =
950             RestoreSubShapesOneLevel(theStudy, anArgSO, aSubSO, theObject, theFindMethod);
951
952           if (aParts->length() > 0) {
953             // try to build an argument from a set of its sub-shapes,
954             // that published and will be reconstructed
955             if (aParts->length() > 1) {
956               aSubO = aShapesOp->MakeCompound(aParts);
957             }
958             else {
959               aSubO = aParts[0];
960             }
961             if (!CORBA::is_nil(aSubO)) {
962               // Publish the sub-shape
963               TCollection_AsciiString aSubName ("from_parts_of_");
964               aSubName += anArgName;
965               aSubSO = PublishInStudy(theStudy, aSubSO, aSubO, aSubName.ToCString());
966               // Restore color
967               aSubO->SetColor(anArgO->GetColor());
968             }
969           }
970           else {
971             // remove created aSubSO, because no parts have been found
972             aStudyBuilder->RemoveObject(aSubSO);
973           }
974         }
975       } // try to build from published parts
976     }
977   } // process arguments
978
979   return true;
980 }
981
982 //============================================================================
983 // function : RestoreSubShapesOneLevel
984 // purpose  : Private method
985 //============================================================================
986 GEOM::ListOfGO* GEOM_Gen_i::RestoreSubShapesOneLevel (SALOMEDS::Study_ptr     theStudy,
987                                                       SALOMEDS::SObject_ptr   theOldSO,
988                                                       SALOMEDS::SObject_ptr   theNewSO,
989                                                       GEOM::GEOM_Object_ptr   theNewO,
990                                                       GEOM::find_shape_method theFindMethod)
991 {
992   int i = 0;
993   GEOM::ListOfGO_var aParts = new GEOM::ListOfGO;
994   if (CORBA::is_nil(theStudy) || CORBA::is_nil(theOldSO) ||
995       CORBA::is_nil(theNewO) || CORBA::is_nil(theNewSO))
996     return aParts._retn();
997
998   SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
999
1000   // Get interface, containing method, which we will use to reconstruct sub-shapes
1001   GEOM::GEOM_IShapesOperations_var aShapesOp = GetIShapesOperations(theStudy->StudyId());
1002   GEOM::GEOM_IGroupOperations_var  aGroupOp  = GetIGroupOperations(theStudy->StudyId());
1003
1004   // Reconstruct published sub-shapes
1005   SALOMEDS::ChildIterator_var it = theStudy->NewChildIterator(theOldSO);
1006
1007   int aLen = 0;
1008   for (it->Init(); it->More(); it->Next()) {
1009     aLen++;
1010   }
1011   aParts->length(aLen);
1012
1013   for (it->Init(); it->More(); it->Next()) {
1014     SALOMEDS::SObject_var anOldSubSO = it->Value();
1015
1016     TCollection_AsciiString anArgName = anOldSubSO->GetName();
1017
1018     SALOMEDS::GenericAttribute_var anAttr;
1019     if (anOldSubSO->FindAttribute(anAttr, "AttributeIOR")) {
1020       SALOMEDS::AttributeIOR_var anAttrIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1021       GEOM::GEOM_Object_var anOldSubO =
1022         GEOM::GEOM_Object::_narrow(_orb->string_to_object(anAttrIOR->Value()));
1023       if (!CORBA::is_nil(anOldSubO)) {
1024         // Find a sub-shape of theNewO in place of anOldSubO
1025         GEOM::GEOM_Object_var aNewSubO;
1026         switch (theFindMethod) {
1027         case GEOM::FSM_GetInPlace:
1028           {
1029             // Use GetInPlace
1030             aNewSubO = aShapesOp->GetInPlace(theNewO, anOldSubO);
1031           }
1032           break;
1033         case GEOM::FSM_Transformed:
1034           {
1035             // transformation, cannot use GetInPlace, operate with indices
1036             GEOM::ListOfLong_var anIDs = anOldSubO->GetSubShapeIndices();
1037             if (anIDs->length() > 1) {
1038               // group
1039               aNewSubO = aGroupOp->CreateGroup(theNewO, aGroupOp->GetType(anOldSubO));
1040               if (!CORBA::is_nil(aNewSubO))
1041                 aGroupOp->UnionIDs(aNewSubO, anIDs);
1042             }
1043             else {
1044               // single sub-shape
1045               aNewSubO = aShapesOp->GetSubShape(theNewO, anIDs[0]);
1046             }
1047           }
1048           break;
1049         case GEOM::FSM_GetSame:
1050           {
1051             // Use GetSame
1052             aNewSubO = aShapesOp->GetSame(theNewO, anOldSubO);
1053           }
1054           break;
1055         case GEOM::FSM_GetShapesOnShape:
1056           {
1057             // Use GetShapesOnShape. Can work only on solids, so it has sense to search only solids
1058             aNewSubO = aShapesOp->GetShapesOnShapeAsCompound(anOldSubO, theNewO,
1059                                                              (short)GEOM::SOLID, GEOM::ST_ONIN);
1060           }
1061           break;
1062         case GEOM::FSM_GetInPlaceByHistory:
1063           {
1064             // Use GetInPlaceByHistory
1065             aNewSubO = aShapesOp->GetInPlaceByHistory(theNewO, anOldSubO);
1066           }
1067           break;
1068         default:
1069           {}
1070         }
1071
1072         if (!CORBA::is_nil(aNewSubO)) {
1073           // add the part to the list
1074           aParts[i] = aNewSubO;
1075           i++;
1076
1077           // Publish the sub-shape
1078           TCollection_AsciiString aSubName ("from_");
1079           aSubName += anArgName;
1080           SALOMEDS::SObject_var aNewSubSO = aStudyBuilder->NewObject(theNewSO);
1081           aNewSubSO = PublishInStudy(theStudy, aNewSubSO, aNewSubO, aSubName.ToCString());
1082           // Restore color
1083           aNewSubO->SetColor(anOldSubO->GetColor());
1084
1085           // Restore published sub-shapes of the argument
1086           if (theFindMethod == GEOM::FSM_GetInPlaceByHistory)
1087             // pass the main shape as Object, because only it has the history
1088             RestoreSubShapesOneLevel(theStudy, anOldSubSO, aNewSubSO, theNewO, theFindMethod);
1089           else
1090             RestoreSubShapesOneLevel(theStudy, anOldSubSO, aNewSubSO, aNewSubO, theFindMethod);
1091         }
1092         else { // GetInPlace failed, try to build from published parts
1093           SALOMEDS::SObject_var aNewSubSO = aStudyBuilder->NewObject(theNewSO);
1094
1095           // Restore published sub-shapes of the argument
1096           GEOM::ListOfGO_var aParts =
1097             RestoreSubShapesOneLevel(theStudy, anOldSubSO, aNewSubSO, theNewO, theFindMethod);
1098
1099           if (aParts->length() > 0) {
1100             // try to build an object from a set of its sub-shapes,
1101             // that published and will be reconstructed
1102             if (aParts->length() > 1) {
1103               aNewSubO = aShapesOp->MakeCompound(aParts);
1104             }
1105             else {
1106               aNewSubO = aParts[0];
1107             }
1108
1109             if (!CORBA::is_nil(aNewSubO)) {
1110               // add the part to the list
1111               aParts[i] = aNewSubO;
1112               i++;
1113
1114               // Publish the sub-shape
1115               TCollection_AsciiString aSubName = "from_parts_of_";
1116               aSubName += anArgName;
1117               aNewSubSO = PublishInStudy(theStudy, aNewSubSO, aNewSubO, aSubName.ToCString());
1118               // Restore color
1119               aNewSubO->SetColor(anOldSubO->GetColor());
1120             }
1121           }
1122           else {
1123             // remove created aSubSO, because no parts have been found
1124             aStudyBuilder->RemoveObject(aNewSubSO);
1125           }
1126         } // try to build from published parts
1127       }
1128     }
1129   } // iterate on published sub-shapes
1130
1131   aParts->length(i);
1132   return aParts._retn();
1133 }
1134
1135 //============================================================================
1136 // function : register()
1137 // purpose  : register 'name' in 'name_service'
1138 //============================================================================
1139 void GEOM_Gen_i::register_name(char * name)
1140 {
1141   GEOM::GEOM_Gen_var g = _this();
1142   name_service->Register(g, name);
1143 }
1144
1145 //============================================================================
1146 // function : Undo
1147 // purpose  :
1148 //============================================================================
1149 void GEOM_Gen_i::Undo(CORBA::Long theStudyID)
1150 {
1151   _impl->Undo(theStudyID);
1152 }
1153
1154 //============================================================================
1155 // function : Redo
1156 // purpose  :
1157 //============================================================================
1158 void GEOM_Gen_i::Redo(CORBA::Long theStudyID)
1159 {
1160   _impl->Redo(theStudyID);
1161 }
1162
1163 //============================================================================
1164 // function : GetIBasicOperations
1165 // purpose  :
1166 //============================================================================
1167 GEOM::GEOM_IBasicOperations_ptr GEOM_Gen_i::GetIBasicOperations(CORBA::Long theStudyID)
1168      throw ( SALOME::SALOME_Exception )
1169 {
1170   Unexpect aCatch(SALOME_SalomeException);
1171   MESSAGE( "GEOM_Gen_i::GetIBasicOperations" );
1172
1173   GEOM::GEOM_Gen_ptr engine = _this();
1174
1175   //transfer reference on engine
1176   GEOM_IBasicOperations_i* aServant =
1177     new GEOM_IBasicOperations_i(_poa, engine, _impl->GetIBasicOperations(theStudyID));
1178
1179   // activate the CORBA servant
1180   GEOM::GEOM_IBasicOperations_var operations = aServant->_this();
1181   return operations._retn();
1182 }
1183
1184 //============================================================================
1185 // function : GetITransformOperations
1186 // purpose  :
1187 //============================================================================
1188 GEOM::GEOM_ITransformOperations_ptr GEOM_Gen_i::GetITransformOperations(CORBA::Long theStudyID)
1189      throw ( SALOME::SALOME_Exception )
1190 {
1191   Unexpect aCatch(SALOME_SalomeException);
1192   MESSAGE( "GEOM_Gen_i::GetITransformOperations" );
1193
1194   GEOM::GEOM_Gen_ptr engine = _this();
1195
1196   GEOM_ITransformOperations_i* aServant =
1197     new GEOM_ITransformOperations_i(_poa, engine, _impl->GetITransformOperations(theStudyID));
1198
1199   // activate the CORBA servant
1200   GEOM::GEOM_ITransformOperations_var operations = aServant->_this();
1201   return operations._retn();
1202 }
1203
1204 //============================================================================
1205 // function : GetI3DPrimOperations
1206 // purpose  :
1207 //============================================================================
1208 GEOM::GEOM_I3DPrimOperations_ptr GEOM_Gen_i::GetI3DPrimOperations(CORBA::Long theStudyID)
1209      throw ( SALOME::SALOME_Exception )
1210 {
1211   Unexpect aCatch(SALOME_SalomeException);
1212   MESSAGE( "GEOM_Gen_i::GetI3DPrimOperations" );
1213
1214   GEOM::GEOM_Gen_ptr engine = _this();
1215
1216   GEOM_I3DPrimOperations_i* aServant =
1217     new GEOM_I3DPrimOperations_i(_poa, engine, _impl->GetI3DPrimOperations(theStudyID));
1218
1219   // activate the CORBA servant
1220   GEOM::GEOM_I3DPrimOperations_var operations = aServant->_this();
1221   return operations._retn();
1222 }
1223
1224 //============================================================================
1225 // function : GetIShapesOperations
1226 // purpose  :
1227 //============================================================================
1228 GEOM::GEOM_IShapesOperations_ptr GEOM_Gen_i::GetIShapesOperations(CORBA::Long theStudyID)
1229      throw ( SALOME::SALOME_Exception )
1230 {
1231   Unexpect aCatch(SALOME_SalomeException);
1232   MESSAGE( "GEOM_Gen_i::GetIShapesOperations" );
1233
1234   GEOM::GEOM_Gen_ptr engine = _this();
1235
1236   GEOM_IShapesOperations_i* aServant =
1237     new GEOM_IShapesOperations_i(_poa, engine, _impl->GetIShapesOperations(theStudyID));
1238
1239   // activate the CORBA servant
1240   GEOM::GEOM_IShapesOperations_var operations = aServant->_this();
1241   return operations._retn();
1242 }
1243
1244 //============================================================================
1245 // function : GetIBlocksOperations
1246 // purpose  :
1247 //============================================================================
1248 GEOM::GEOM_IBlocksOperations_ptr GEOM_Gen_i::GetIBlocksOperations(CORBA::Long theStudyID)
1249      throw ( SALOME::SALOME_Exception )
1250 {
1251   Unexpect aCatch(SALOME_SalomeException);
1252   MESSAGE( "GEOM_Gen_i::GetIBlocksOperations" );
1253
1254   GEOM::GEOM_Gen_ptr engine = _this();
1255
1256   GEOM_IBlocksOperations_i* aServant =
1257     new GEOM_IBlocksOperations_i(_poa, engine, _impl->GetIBlocksOperations(theStudyID));
1258
1259   // activate the CORBA servant
1260   GEOM::GEOM_IBlocksOperations_var operations = aServant->_this();
1261   return operations._retn();
1262 }
1263
1264 //============================================================================
1265 // function : GetIBooleanOperations
1266 // purpose  :
1267 //============================================================================
1268 GEOM::GEOM_IBooleanOperations_ptr GEOM_Gen_i::GetIBooleanOperations(CORBA::Long theStudyID)
1269      throw ( SALOME::SALOME_Exception )
1270 {
1271   Unexpect aCatch(SALOME_SalomeException);
1272   MESSAGE( "GEOM_Gen_i::GetIBooleanOperations" );
1273
1274   GEOM::GEOM_Gen_ptr engine = _this();
1275
1276   GEOM_IBooleanOperations_i* aServant =
1277     new GEOM_IBooleanOperations_i(_poa, engine, _impl->GetIBooleanOperations(theStudyID));
1278
1279   // activate the CORBA servant
1280   GEOM::GEOM_IBooleanOperations_var operations = aServant->_this();
1281   return operations._retn();
1282 }
1283
1284 //============================================================================
1285 // function : GetICurvesOperations
1286 // purpose  :
1287 //============================================================================
1288 GEOM::GEOM_ICurvesOperations_ptr GEOM_Gen_i::GetICurvesOperations(CORBA::Long theStudyID)
1289      throw ( SALOME::SALOME_Exception )
1290 {
1291   Unexpect aCatch(SALOME_SalomeException);
1292   MESSAGE( "GEOM_Gen_i::GetICurvesOperations" );
1293
1294   GEOM::GEOM_Gen_ptr engine = _this();
1295
1296   GEOM_ICurvesOperations_i* aServant =
1297     new GEOM_ICurvesOperations_i(_poa, engine, _impl->GetICurvesOperations(theStudyID));
1298
1299   // activate the CORBA servant
1300   GEOM::GEOM_ICurvesOperations_var operations = aServant->_this();
1301   return operations._retn();
1302 }
1303
1304 //============================================================================
1305 // function : GetILocalOperations
1306 // purpose  :
1307 //============================================================================
1308 GEOM::GEOM_ILocalOperations_ptr GEOM_Gen_i::GetILocalOperations(CORBA::Long theStudyID)
1309      throw ( SALOME::SALOME_Exception )
1310 {
1311   Unexpect aCatch(SALOME_SalomeException);
1312   MESSAGE( "GEOM_Gen_i::GetILocalOperations" );
1313
1314   GEOM::GEOM_Gen_ptr engine = _this();
1315
1316   GEOM_ILocalOperations_i* aServant =
1317     new GEOM_ILocalOperations_i(_poa, engine, _impl->GetILocalOperations(theStudyID));
1318
1319   // activate the CORBA servant
1320   GEOM::GEOM_ILocalOperations_var operations = aServant->_this();
1321   return operations._retn();
1322 }
1323
1324 //============================================================================
1325 // function : GetIHealingOperations
1326 // purpose  :
1327 //============================================================================
1328 GEOM::GEOM_IHealingOperations_ptr GEOM_Gen_i::GetIHealingOperations(CORBA::Long theStudyID)
1329      throw ( SALOME::SALOME_Exception )
1330 {
1331   Unexpect aCatch(SALOME_SalomeException);
1332   MESSAGE( "GEOM_Gen_i::IHealingOperations" );
1333
1334   GEOM::GEOM_Gen_ptr engine = _this();
1335
1336   GEOM_IHealingOperations_i* aServant =
1337     new GEOM_IHealingOperations_i(_poa, engine, _impl->GetIHealingOperations(theStudyID));
1338
1339   // activate the CORBA servant
1340   GEOM::GEOM_IHealingOperations_var operations = aServant->_this();
1341   return operations._retn();
1342 }
1343
1344 //============================================================================
1345 // function : GetIInsertOperations
1346 // purpose  :
1347 //============================================================================
1348 GEOM::GEOM_IInsertOperations_ptr GEOM_Gen_i::GetIInsertOperations(CORBA::Long theStudyID)
1349      throw ( SALOME::SALOME_Exception )
1350 {
1351   Unexpect aCatch(SALOME_SalomeException);
1352   MESSAGE( "GEOM_Gen_i::GetIInsertOperations" );
1353
1354   GEOM::GEOM_Gen_ptr engine = _this();
1355
1356   GEOM_IInsertOperations_i* aServant =
1357     new GEOM_IInsertOperations_i(_poa, engine, _impl->GetIInsertOperations(theStudyID));
1358
1359   // activate the CORBA servant
1360   GEOM::GEOM_IInsertOperations_var operations = aServant->_this();
1361   return operations._retn();
1362 }
1363
1364 //============================================================================
1365 // function : GetIMeasureOperations
1366 // purpose  :
1367 //============================================================================
1368 GEOM::GEOM_IMeasureOperations_ptr GEOM_Gen_i::GetIMeasureOperations(CORBA::Long theStudyID)
1369      throw ( SALOME::SALOME_Exception )
1370 {
1371   Unexpect aCatch(SALOME_SalomeException);
1372   MESSAGE( "GEOM_Gen_i::GetIMeasureOperations" );
1373
1374   GEOM::GEOM_Gen_ptr engine = _this();
1375
1376   GEOM_IMeasureOperations_i* aServant =
1377     new GEOM_IMeasureOperations_i(_poa, engine, _impl->GetIMeasureOperations(theStudyID));
1378
1379   // activate the CORBA servant
1380   GEOM::GEOM_IMeasureOperations_var operations = aServant->_this();
1381   return operations._retn();
1382 }
1383
1384 //============================================================================
1385 // function : GetIGroupOperations
1386 // purpose  :
1387 //============================================================================
1388 GEOM::GEOM_IGroupOperations_ptr GEOM_Gen_i::GetIGroupOperations(CORBA::Long theStudyID)
1389      throw ( SALOME::SALOME_Exception )
1390 {
1391   Unexpect aCatch(SALOME_SalomeException);
1392   MESSAGE( "GEOM_Gen_i::GetIGroupOperations" );
1393
1394   GEOM::GEOM_Gen_ptr engine = _this();
1395
1396   GEOM_IGroupOperations_i* aServant =
1397     new GEOM_IGroupOperations_i(_poa, engine, _impl->GetIGroupOperations(theStudyID));
1398
1399   // activate the CORBA servant
1400   GEOM::GEOM_IGroupOperations_var operations = aServant->_this();
1401   return operations._retn();
1402 }
1403
1404 //=============================================================================
1405 /*!
1406  *  AddSubShape
1407  */
1408 //=============================================================================
1409 GEOM::GEOM_Object_ptr GEOM_Gen_i::AddSubShape (GEOM::GEOM_Object_ptr theMainShape,
1410                                                const GEOM::ListOfLong& theIndices)
1411 {
1412   if (CORBA::is_nil(theMainShape) || theIndices.length() < 1)
1413     return GEOM::GEOM_Object::_nil();
1414   CORBA::String_var entry = theMainShape->GetEntry();
1415   Handle(GEOM_Object) aMainsShape = _impl->GetObject(theMainShape->GetStudyID(), entry);
1416   if (aMainsShape.IsNull()) return GEOM::GEOM_Object::_nil();
1417
1418   Handle(TColStd_HArray1OfInteger) anArray = new TColStd_HArray1OfInteger(1, theIndices.length());
1419   for(Standard_Integer i = 0; i<theIndices.length(); i++) anArray->SetValue(i+1, theIndices[i]);
1420
1421   Handle(GEOM_Object) anObject = _impl->AddSubShape(aMainsShape, anArray, true);
1422   if(anObject.IsNull()) return GEOM::GEOM_Object::_nil();
1423
1424   TCollection_AsciiString anEntry;
1425   TDF_Tool::Entry(anObject->GetEntry(), anEntry);
1426   return GetObject(anObject->GetDocID(), anEntry.ToCString());
1427 }
1428
1429 //=============================================================================
1430 /*!
1431  *  RemoveObject
1432  */
1433 //=============================================================================
1434 void GEOM_Gen_i::RemoveObject(GEOM::GEOM_Object_ptr theObject)
1435 {
1436   CORBA::String_var anEntry = theObject->GetEntry();
1437   Handle(GEOM_Object) anObject = _impl->GetObject(theObject->GetStudyID(), anEntry);
1438   if (anObject.IsNull()) return;
1439   _impl->RemoveObject(anObject);
1440   return;
1441 }
1442
1443
1444 //=================================================================================
1445 // function : GetStringFromIOR()
1446 // purpose  : returns a string that represents  a 'GEOM::GEOM_Object_var'
1447 //=================================================================================
1448 char* GEOM_Gen_i::GetStringFromIOR(GEOM::GEOM_Object_ptr theObject) {
1449   return _orb->object_to_string(theObject);
1450 }
1451
1452
1453 //=================================================================================
1454 // function : GetIORFromString()
1455 // purpose  : returns a 'GEOM::GEOM_Object_var' from a string representing it
1456 //=================================================================================
1457 GEOM::GEOM_Object_ptr GEOM_Gen_i::GetIORFromString(const char* stringIOR) {
1458   GEOM::GEOM_Object_var aGeomObject;
1459   if(strcmp(stringIOR,"") != 0){
1460     CORBA::Object_var anObject = _orb->string_to_object(stringIOR);
1461     if(!CORBA::is_nil(anObject))
1462       aGeomObject =  GEOM::GEOM_Object::_narrow(anObject.in());
1463   }
1464   return aGeomObject._retn();
1465 }
1466
1467 //=================================================================================
1468 // function : GetObject()
1469 // purpose  :
1470 //=================================================================================
1471 GEOM::GEOM_Object_ptr GEOM_Gen_i::GetObject (CORBA::Long theStudyID, const char* theEntry)
1472 {
1473   GEOM::GEOM_Object_var obj;
1474   Handle(GEOM_Object) handle_object = _impl->GetObject(theStudyID, (char*)theEntry);
1475   if (handle_object.IsNull()) return obj._retn();
1476
1477   TCollection_AsciiString stringIOR = handle_object->GetIOR();
1478   if (stringIOR.Length() > 1) {
1479     CORBA::Object_var corba_object = _orb->string_to_object(stringIOR.ToCString());
1480     if (!CORBA::is_nil(corba_object)) obj = GEOM::GEOM_Object::_narrow(corba_object);
1481     return obj._retn();
1482   }
1483
1484   GEOM::GEOM_Gen_ptr engine = _this();
1485   GEOM_Object_i* servant = new GEOM_Object_i (_poa, engine, handle_object);
1486
1487   obj = servant->_this();
1488   CORBA::String_var objStr = _orb->object_to_string(obj);
1489   TCollection_AsciiString anAscii( (char *)objStr.in() );
1490   handle_object->SetIOR( anAscii );
1491   return obj._retn();
1492 }
1493
1494 //=================================================================================
1495 // function : hasObjectInfo()
1496 // purpose  : shows if module provides information for its objects
1497 //=================================================================================
1498 bool GEOM_Gen_i::hasObjectInfo()
1499 {
1500   return true;
1501 }
1502
1503 //=================================================================================
1504 // function : getObjectInfo()
1505 // purpose  : returns an information for a given object by its entry
1506 //=================================================================================
1507 char* GEOM_Gen_i::getObjectInfo(CORBA::Long studyId, const char* entry)
1508 {
1509   GEOM::GEOM_Object_var aGeomObject;
1510  
1511   CORBA::Object_var aSMObject = name_service->Resolve( "/myStudyManager" );
1512   SALOMEDS::StudyManager_var aStudyManager = SALOMEDS::StudyManager::_narrow( aSMObject );
1513   SALOMEDS::Study_var aStudy = aStudyManager->GetStudyByID( studyId );
1514   SALOMEDS::SObject_var aSObj = aStudy->FindObjectID( entry );
1515   SALOMEDS::SObject_var aResultSObj;
1516   if (aSObj->ReferencedObject(aResultSObj))
1517     aSObj = aResultSObj;
1518
1519   SALOMEDS::GenericAttribute_var anAttr;
1520   if (!aSObj->_is_nil() && aSObj->FindAttribute(anAttr, "AttributeIOR")) {
1521     SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1522     CORBA::String_var aVal = anIOR->Value();
1523     CORBA::Object_var anObject = aStudy->ConvertIORToObject(aVal);
1524     aGeomObject = GEOM::GEOM_Object::_narrow(anObject);
1525   }
1526   
1527   const char* aTypeInfo = "Object";
1528   if ( !aGeomObject->_is_nil() ) {
1529     GEOM::GEOM_IKindOfShape::shape_kind aKind;
1530     GEOM::ListOfLong_var anInts;
1531     GEOM::ListOfDouble_var aDbls;
1532
1533     GEOM::GEOM_IMeasureOperations_var anOp = GetIMeasureOperations( studyId );
1534     aKind = anOp->KindOfShape( aGeomObject, anInts, aDbls );
1535
1536     if ( anOp->IsDone() ) {
1537       switch ( aKind ) {
1538       case GEOM::GEOM_IKindOfShape::COMPOUND:
1539         aTypeInfo = "Compound";
1540         break;
1541       case GEOM::GEOM_IKindOfShape::COMPSOLID:
1542         aTypeInfo = "CompSolid";
1543         break;
1544       case GEOM::GEOM_IKindOfShape::SHELL:
1545         aTypeInfo = "Shell";
1546         break;
1547       case GEOM::GEOM_IKindOfShape::WIRE:
1548         if ( anInts[0] == 1 )
1549           aTypeInfo = "Closed Wire";
1550         else if ( anInts[0] == 2 )
1551           aTypeInfo = "Opened Wire";
1552         else
1553           aTypeInfo = "Wire";
1554         break;
1555         // SOLIDs
1556       case GEOM::GEOM_IKindOfShape::SPHERE:
1557         aTypeInfo = "Sphere";
1558         break;
1559       case GEOM::GEOM_IKindOfShape::CYLINDER:
1560         aTypeInfo = "Cylinder";
1561         break;
1562       case GEOM::GEOM_IKindOfShape::BOX:
1563       case GEOM::GEOM_IKindOfShape::ROTATED_BOX:
1564         aTypeInfo = "Box";
1565         break;
1566       case GEOM::GEOM_IKindOfShape::TORUS:
1567         aTypeInfo = "Torus";
1568         break;
1569       case GEOM::GEOM_IKindOfShape::CONE:
1570         aTypeInfo = "Cone";
1571         break;
1572       case GEOM::GEOM_IKindOfShape::POLYHEDRON:
1573         aTypeInfo = "Polyhedron";
1574         break;
1575       case GEOM::GEOM_IKindOfShape::SOLID:
1576         aTypeInfo = "Solid";
1577         break;
1578         // FACEs
1579       case GEOM::GEOM_IKindOfShape::SPHERE2D:
1580         aTypeInfo = "Spherical Face";
1581         break;
1582       case GEOM::GEOM_IKindOfShape::CYLINDER2D:
1583         aTypeInfo = "Cylindrical Face";
1584         break;
1585       case GEOM::GEOM_IKindOfShape::TORUS2D:
1586         aTypeInfo = "Toroidal Face";
1587         break;
1588       case GEOM::GEOM_IKindOfShape::CONE2D:
1589         aTypeInfo = "Conical Face";
1590         break;
1591       case GEOM::GEOM_IKindOfShape::DISK_CIRCLE:
1592         aTypeInfo = "Disk";
1593         break;
1594       case GEOM::GEOM_IKindOfShape::DISK_ELLIPSE:
1595         aTypeInfo = "Elliptical Face";
1596         break;
1597       case GEOM::GEOM_IKindOfShape::POLYGON:
1598         aTypeInfo = "Polygon";
1599         break;
1600       case GEOM::GEOM_IKindOfShape::PLANE:
1601         aTypeInfo = "Plane";
1602         break;
1603       case GEOM::GEOM_IKindOfShape::PLANAR:
1604         aTypeInfo = "Planar Face";
1605         break;
1606       case GEOM::GEOM_IKindOfShape::FACE:
1607         aTypeInfo = "Face";
1608         break;
1609         // EDGEs
1610       case GEOM::GEOM_IKindOfShape::CIRCLE:
1611         aTypeInfo = "Circle";
1612         break;
1613       case GEOM::GEOM_IKindOfShape::ARC_CIRCLE:
1614         aTypeInfo = "Ark";
1615         break;
1616       case GEOM::GEOM_IKindOfShape::ELLIPSE:
1617         aTypeInfo = "Ellipse";
1618         break;
1619       case GEOM::GEOM_IKindOfShape::ARC_ELLIPSE:
1620         aTypeInfo = "Arc Ellipse";
1621         break;
1622       case GEOM::GEOM_IKindOfShape::LINE:
1623         aTypeInfo = "Line";
1624         break;
1625       case GEOM::GEOM_IKindOfShape::SEGMENT:
1626         aTypeInfo = "Segment";
1627         break;
1628       case GEOM::GEOM_IKindOfShape::EDGE:
1629         aTypeInfo = "Edge";
1630         break;
1631       case GEOM::GEOM_IKindOfShape::VERTEX:
1632         aTypeInfo = "Vertex";
1633         break;
1634       default:
1635         break;
1636       }
1637     }
1638   }
1639     
1640   char* anInfo = new char[strlen("Module ") + strlen(ComponentDataType()) + strlen(", ") + strlen(aTypeInfo) + 3];
1641   sprintf(anInfo, "Module %s, %s", ComponentDataType(), aTypeInfo);
1642   
1643   char* ret = CORBA::string_dup(anInfo);
1644   delete [] anInfo;
1645   return ret;
1646 }
1647
1648 //=====================================================================================
1649 // EXPORTED METHODS
1650 //=====================================================================================
1651 extern "C"
1652 {
1653 GEOM_I_EXPORT
1654   PortableServer::ObjectId * GEOMEngine_factory(CORBA::ORB_ptr orb,
1655                                                 PortableServer::POA_ptr poa,
1656                                                 PortableServer::ObjectId * contId,
1657                                                 const char *instanceName,
1658                                                 const char * interfaceName)
1659   {
1660    GEOM_Gen_i * myGEOM_Gen_i = new GEOM_Gen_i(orb, poa, contId, instanceName, interfaceName);
1661    // Don't understand the reason of this register ????
1662 //   myGEOM_Gen_i->register_name("/myGEOM_Gen"); // NRI : 11/07/2002 : Add for Supervision example
1663    return myGEOM_Gen_i->getId();
1664   }
1665 }