Salome HOME
fix leaks of SALOMEDS_UseCaseBuilder_i
[modules/smesh.git] / src / SMESH_I / SMESH_Gen_i_1.cxx
1 // Copyright (C) 2007-2013  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 //  File      : SMESH_Gen_i_1.cxx
23 //  Created   : Thu Oct 21 17:24:06 2004
24 //  Author    : Edward AGAPOV (eap)
25 //  Module    : SMESH
26
27 #include "SMESH_Gen_i.hxx"
28
29 #include "SMESH_Algo_i.hxx"
30 #include "SMESH_Comment.hxx"
31 #include "SMESH_Group_i.hxx"
32 #include "SMESH_Hypothesis_i.hxx"
33 #include "SMESH_Mesh_i.hxx"
34 #include "SMESH_subMesh_i.hxx"
35
36 #include CORBA_CLIENT_HEADER(SALOME_ModuleCatalog)
37
38 #include <utilities.h>
39 #include <Utils_ExceptHandlers.hxx>
40 #include <SALOMEDS_wrap.hxx>
41 #include <SALOMEDS_Attributes_wrap.hxx>
42
43 #include <TCollection_AsciiString.hxx>
44 #include <TopoDS_Solid.hxx>
45
46 #ifdef _DEBUG_
47 static int MYDEBUG = 0;
48 //static int VARIABLE_DEBUG = 0;
49 #else
50 static int MYDEBUG = 0;
51 //static int VARIABLE_DEBUG = 0;
52 #endif
53
54 //=============================================================================
55 /*!
56  *  Get...Tag [ static ]
57  *
58  *  Methods which determine SMESH data model structure
59  */
60 //=============================================================================
61
62 long SMESH_Gen_i::GetHypothesisRootTag()
63 {
64   return SMESH::Tag_HypothesisRoot;
65 }
66
67 long SMESH_Gen_i::GetAlgorithmsRootTag()
68 {
69   return SMESH::Tag_AlgorithmsRoot;
70 }
71
72 long SMESH_Gen_i::GetRefOnShapeTag()
73 {
74   return SMESH::Tag_RefOnShape;
75 }
76
77 long SMESH_Gen_i::GetRefOnAppliedHypothesisTag()
78 {
79   return SMESH::Tag_RefOnAppliedHypothesis;
80 }
81
82 long SMESH_Gen_i::GetRefOnAppliedAlgorithmsTag()
83 {
84   return SMESH::Tag_RefOnAppliedAlgorithms;
85 }
86
87 long SMESH_Gen_i::GetSubMeshOnVertexTag()
88 {
89   return SMESH::Tag_SubMeshOnVertex;
90 }
91
92 long SMESH_Gen_i::GetSubMeshOnEdgeTag()
93 {
94   return SMESH::Tag_SubMeshOnEdge;
95 }
96
97 long SMESH_Gen_i::GetSubMeshOnFaceTag()
98 {
99   return SMESH::Tag_SubMeshOnFace;
100 }
101
102 long SMESH_Gen_i::GetSubMeshOnSolidTag()
103 {
104   return SMESH::Tag_SubMeshOnSolid;
105 }
106
107 long SMESH_Gen_i::GetSubMeshOnCompoundTag()
108 {
109   return SMESH::Tag_SubMeshOnCompound;
110 }
111
112 long SMESH_Gen_i::GetSubMeshOnWireTag()
113 {
114   return SMESH::Tag_SubMeshOnWire;
115 }
116
117 long SMESH_Gen_i::GetSubMeshOnShellTag()
118 {
119   return SMESH::Tag_SubMeshOnShell;
120 }
121
122 long SMESH_Gen_i::GetNodeGroupsTag()
123 {
124   return SMESH::Tag_NodeGroups;
125 }
126
127 long SMESH_Gen_i::GetEdgeGroupsTag()
128 {
129   return SMESH::Tag_EdgeGroups;
130 }
131
132 long SMESH_Gen_i::GetFaceGroupsTag()
133 {
134   return SMESH::Tag_FaceGroups;
135 }
136
137 long SMESH_Gen_i::GetVolumeGroupsTag()
138 {
139   return SMESH::Tag_VolumeGroups;
140 }
141
142 long SMESH_Gen_i::Get0DElementsGroupsTag()
143 {
144   return SMESH::Tag_0DElementsGroups;
145 }
146
147 long SMESH_Gen_i::GetBallElementsGroupsTag()
148 {
149   return SMESH::Tag_BallElementsGroups;
150 }
151
152 //=============================================================================
153 /*!
154  *  SMESH_Gen_i::CanPublishInStudy
155  *
156  *  Returns true if object can be published in the study
157  */
158 //=============================================================================
159
160 bool SMESH_Gen_i::CanPublishInStudy(CORBA::Object_ptr theIOR)
161 {
162   if(MYDEBUG) MESSAGE("CanPublishInStudy - "<<!CORBA::is_nil(myCurrentStudy));
163   if(CORBA::is_nil(myCurrentStudy))
164     return false;
165   
166   SMESH::SMESH_Mesh_var aMesh       = SMESH::SMESH_Mesh::_narrow(theIOR);
167   if( !aMesh->_is_nil() )
168     return true;
169
170   SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow(theIOR);
171   if( !aSubMesh->_is_nil() )
172     return true;
173
174   SMESH::SMESH_Hypothesis_var aHyp  = SMESH::SMESH_Hypothesis::_narrow(theIOR);
175   if( !aHyp->_is_nil() )
176     return true;
177
178   SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow(theIOR);
179   if( !aGroup->_is_nil() )
180     return true;
181
182   if(MYDEBUG) MESSAGE("CanPublishInStudy--CANT");
183   return false;
184 }
185
186 //=======================================================================
187 //function : ObjectToSObject
188 //purpose  : Put a result into a SALOMEDS::SObject_wrap or call UnRegister()!
189 //=======================================================================
190
191 SALOMEDS::SObject_ptr SMESH_Gen_i::ObjectToSObject(SALOMEDS::Study_ptr theStudy,
192                                                    CORBA::Object_ptr   theObject)
193 {
194   SALOMEDS::SObject_wrap aSO;
195   if ( !CORBA::is_nil( theStudy ) && !CORBA::is_nil( theObject ))
196   {
197     CORBA::String_var objStr = SMESH_Gen_i::GetORB()->object_to_string( theObject );
198     aSO = theStudy->FindObjectIOR( objStr.in() );
199   }
200   return aSO._retn();
201 }
202
203 //=======================================================================
204 //function : objectToServant
205 //purpose  : 
206 //=======================================================================
207
208 template<typename T> static inline T* objectToServant( CORBA::Object_ptr theIOR )
209 {
210   return dynamic_cast<T*>( SMESH_Gen_i::GetServant( theIOR ).in() );
211 }
212
213 //=======================================================================
214 //function : ShapeToGeomObject
215 //purpose  : 
216 //=======================================================================
217
218 GEOM::GEOM_Object_ptr SMESH_Gen_i::ShapeToGeomObject (const TopoDS_Shape& theShape )
219 {
220   GEOM::GEOM_Object_var aShapeObj;
221   if ( !theShape.IsNull() ) {
222     GEOM_Client* aClient = GetShapeReader();
223     TCollection_AsciiString IOR;
224     if ( aClient && aClient->Find( theShape, IOR ))
225     {
226       CORBA::Object_var obj = GetORB()->string_to_object( IOR.ToCString() );
227       aShapeObj = GEOM::GEOM_Object::_narrow ( obj );
228     }
229   }
230   return aShapeObj._retn();
231 }
232
233 //=======================================================================
234 //function : GeomObjectToShape
235 //purpose  : 
236 //=======================================================================
237
238 TopoDS_Shape SMESH_Gen_i::GeomObjectToShape(GEOM::GEOM_Object_ptr theGeomObject)
239 {
240   TopoDS_Shape S;
241   if ( !theGeomObject->_is_nil() ) {
242     GEOM_Client* aClient = GetShapeReader();
243     GEOM::GEOM_Gen_ptr aGeomEngine = GetGeomEngine();
244     if ( aClient && !aGeomEngine->_is_nil () )
245       S = aClient->GetShape( aGeomEngine, theGeomObject );
246   }
247   return S;
248 }
249
250 //=======================================================================
251 //function : publish
252 //purpose  : 
253 //=======================================================================
254
255 static SALOMEDS::SObject_ptr publish(SALOMEDS::Study_ptr   theStudy,
256                                      CORBA::Object_ptr     theIOR,
257                                      SALOMEDS::SObject_ptr theFatherObject,
258                                      const int             theTag = 0,
259                                      const char*           thePixMap = 0,
260                                      const bool            theSelectable = true)
261 {
262   SALOMEDS::SObject_wrap SO = SMESH_Gen_i::ObjectToSObject( theStudy, theIOR );
263   SALOMEDS::StudyBuilder_var     aStudyBuilder = theStudy->NewBuilder();
264   SALOMEDS::UseCaseBuilder_wrap useCaseBuilder = theStudy->GetUseCaseBuilder();
265   SALOMEDS::SObject_wrap objAfter;
266   if ( SO->_is_nil() )
267   {
268     if ( theTag == 0 ) {
269       SO = aStudyBuilder->NewObject( theFatherObject );
270     }
271     else if ( !theFatherObject->FindSubObject( theTag, SO.inout() ))
272     {
273       SO = aStudyBuilder->NewObjectToTag( theFatherObject, theTag );
274
275       // define the next tag after given one in the data tree to insert SObject
276       std::string anEntry;
277       int last2Pnt_pos = -1;
278       int tagAfter = -1;
279       CORBA::String_var entry;
280       SALOMEDS::SObject_wrap curObj;
281       SALOMEDS::UseCaseIterator_wrap anUseCaseIter = useCaseBuilder->GetUseCaseIterator(theFatherObject);
282       for ( ; anUseCaseIter->More(); anUseCaseIter->Next() ) {
283         curObj = anUseCaseIter->Value();
284         entry = curObj->GetID();
285         anEntry = entry.in();
286         last2Pnt_pos = anEntry.rfind( ":" );
287         tagAfter = atoi( anEntry.substr( last2Pnt_pos+1 ).c_str() );
288         if ( tagAfter > theTag  ) {
289           objAfter = curObj;
290           break;
291         }
292       }
293     }
294   }
295
296   SALOMEDS::GenericAttribute_wrap anAttr;
297   if ( !CORBA::is_nil( theIOR )) {
298     anAttr = aStudyBuilder->FindOrCreateAttribute( SO, "AttributeIOR" );
299     CORBA::String_var objStr = SMESH_Gen_i::GetORB()->object_to_string( theIOR );
300     SALOMEDS::AttributeIOR_wrap iorAttr = anAttr;
301     iorAttr->SetValue( objStr.in() );
302     // UnRegister() !!!
303     SALOME::GenericObj_var genObj = SALOME::GenericObj::_narrow( theIOR );
304     if ( !genObj->_is_nil() )
305       genObj->UnRegister();
306   }
307   if ( thePixMap ) {
308     anAttr  = aStudyBuilder->FindOrCreateAttribute( SO, "AttributePixMap" );
309     SALOMEDS::AttributePixMap_wrap pm = anAttr;
310     pm->SetPixMap( thePixMap );
311   }
312   if ( !theSelectable ) {
313     anAttr = aStudyBuilder->FindOrCreateAttribute( SO, "AttributeSelectable" );
314     SALOMEDS::AttributeSelectable_wrap selAttr = anAttr;
315     selAttr->SetSelectable( false );
316   }
317
318   // add object to the use case tree
319   // (to support tree representation customization and drag-n-drop)
320   if ( !CORBA::is_nil( objAfter ) ) {
321     useCaseBuilder->InsertBefore( SO, objAfter );    // insert at given tag
322   } else if ( !useCaseBuilder->IsUseCaseNode( SO ) ) {
323     useCaseBuilder->AppendTo( theFatherObject, SO ); // append to the end of list
324   }
325
326   return SO._retn();
327 }
328
329 //=======================================================================
330 //function : setName
331 //purpose  : 
332 //=======================================================================
333
334 void SMESH_Gen_i::SetName(SALOMEDS::SObject_ptr theSObject,
335                           const char*           theName,
336                           const char*           theDefaultName)
337 {
338   if ( !theSObject->_is_nil() ) {
339     SALOMEDS::Study_var               aStudy = theSObject->GetStudy();
340     SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
341     SALOMEDS::GenericAttribute_wrap   anAttr =
342       aStudyBuilder->FindOrCreateAttribute( theSObject, "AttributeName" );
343     SALOMEDS::AttributeName_wrap aNameAttr = anAttr;
344     if ( theName && strlen( theName ) != 0 )
345       aNameAttr->SetValue( theName );
346     else {
347       CORBA::String_var curName = aNameAttr->Value();
348       if ( strlen( curName.in() ) == 0 ) {
349         SMESH_Comment aName(theDefaultName);
350         aNameAttr->SetValue( ( aName<< "_" << theSObject->Tag()).c_str() );
351       }
352     }
353   }
354 }
355
356 //=======================================================================
357 //function : SetPixMap
358 //purpose  : 
359 //=======================================================================
360
361 void SMESH_Gen_i::SetPixMap(SALOMEDS::SObject_ptr theSObject,
362                             const char*           thePixMap)
363 {
364   if ( !theSObject->_is_nil() && thePixMap && strlen( thePixMap ))
365   {
366     SALOMEDS::Study_var               aStudy = theSObject->GetStudy();
367     SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
368     SALOMEDS::GenericAttribute_wrap anAttr =
369       aStudyBuilder->FindOrCreateAttribute( theSObject, "AttributePixMap" );
370     SALOMEDS::AttributePixMap_wrap aPMAttr = anAttr;
371     aPMAttr->SetPixMap( thePixMap );
372   }
373 }
374
375 //=======================================================================
376 //function : addReference
377 //purpose  : 
378 //=======================================================================
379
380 static void addReference (SALOMEDS::Study_ptr   theStudy,
381                           SALOMEDS::SObject_ptr theSObject,
382                           CORBA::Object_ptr     theToObject,
383                           int                   theTag = 0)
384 {
385   SALOMEDS::SObject_wrap aToObjSO = SMESH_Gen_i::ObjectToSObject( theStudy, theToObject );
386   if ( !aToObjSO->_is_nil() && !theSObject->_is_nil() ) {
387     SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder();
388     SALOMEDS::SObject_wrap aReferenceSO;
389     if ( !theTag ) {
390       // check if the reference to theToObject already exists
391       // and find a free label for the reference object
392       bool isReferred = false;
393       int tag = 1;
394       SALOMEDS::ChildIterator_wrap anIter = theStudy->NewChildIterator( theSObject );
395       for ( ; !isReferred && anIter->More(); anIter->Next(), ++tag ) {
396         SALOMEDS::SObject_wrap curSO = anIter->Value();
397         if ( curSO->ReferencedObject( aReferenceSO.inout() )) {
398           CORBA::String_var refEntry = aReferenceSO->GetID();
399           CORBA::String_var  toEntry = aToObjSO->GetID();
400           if ( strcmp( refEntry, toEntry ) == 0 )
401             isReferred = true;
402         }
403         else if ( !theTag ) {
404           SALOMEDS::GenericAttribute_wrap anAttr;
405           if ( !curSO->FindAttribute( anAttr.inout(), "AttributeIOR" ))
406             theTag = tag;
407         }
408       }
409       if ( isReferred )
410         return;
411       if ( !theTag )
412         theTag = tag;
413     }
414     if ( !theSObject->FindSubObject( theTag, aReferenceSO.inout() ))
415       aReferenceSO = aStudyBuilder->NewObjectToTag( theSObject, theTag );
416     aStudyBuilder->Addreference( aReferenceSO, aToObjSO );
417     // add reference to the use case tree
418     // (to support tree representation customization and drag-n-drop)
419     SALOMEDS::UseCaseBuilder_wrap useCaseBuilder = theStudy->GetUseCaseBuilder();
420     useCaseBuilder->AppendTo( aReferenceSO->GetFather(), aReferenceSO );
421   }
422 }
423
424 //=============================================================================
425 /*!
426  *  SMESH_Gen_i::PublishInStudy
427  *
428  *  Publish object in the study
429  */
430 //=============================================================================
431
432 SALOMEDS::SObject_ptr SMESH_Gen_i::PublishInStudy(SALOMEDS::Study_ptr   theStudy,
433                                                   SALOMEDS::SObject_ptr theSObject,
434                                                   CORBA::Object_ptr     theIOR,
435                                                   const char*           theName)
436      throw (SALOME::SALOME_Exception)
437 {
438   Unexpect aCatch(SALOME_SalomeException);
439   SALOMEDS::SObject_wrap aSO;
440   if ( CORBA::is_nil( theStudy ) || CORBA::is_nil( theIOR ))
441     return aSO._retn();
442   if(MYDEBUG) MESSAGE("PublishInStudy");
443
444   // Publishing a mesh
445   SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow( theIOR );
446   if( !aMesh->_is_nil() )
447     aSO = PublishMesh( theStudy, aMesh, theName );
448
449   // Publishing a sub-mesh
450   SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow( theIOR );
451   if( aSO->_is_nil() && !aSubMesh->_is_nil() ) {
452     GEOM::GEOM_Object_var aShapeObject = aSubMesh->GetSubShape();
453     aMesh = aSubMesh->GetFather();
454     aSO = PublishSubMesh( theStudy, aMesh, aSubMesh, aShapeObject, theName );
455   }
456
457   // Publishing a hypothesis or algorithm
458   SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow( theIOR );
459   if ( aSO->_is_nil() && !aHyp->_is_nil() )
460     aSO = PublishHypothesis( theStudy, aHyp );
461
462   // Publishing a group
463   SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow(theIOR);
464   if ( aSO->_is_nil() && !aGroup->_is_nil() ) {
465     GEOM::GEOM_Object_var aShapeObject;
466     aMesh = aGroup->GetMesh();
467     aSO = PublishGroup( theStudy, aMesh, aGroup, aShapeObject, theName );
468   }
469   if(MYDEBUG) MESSAGE("PublishInStudy_END");
470
471   return aSO._retn();
472 }
473
474 //=======================================================================
475 //function : PublishComponent
476 //purpose  : 
477 //=======================================================================
478
479 SALOMEDS::SComponent_ptr SMESH_Gen_i::PublishComponent(SALOMEDS::Study_ptr theStudy)
480 {
481   if ( CORBA::is_nil( theStudy ))
482     return SALOMEDS::SComponent::_nil();
483   if(MYDEBUG) MESSAGE("PublishComponent");
484
485   SALOMEDS::StudyBuilder_var    aStudyBuilder  = theStudy->NewBuilder(); 
486   SALOMEDS::UseCaseBuilder_wrap useCaseBuilder = theStudy->GetUseCaseBuilder();
487
488   CORBA::String_var   compDataType = ComponentDataType();
489   SALOMEDS::SComponent_wrap father = theStudy->FindComponent( compDataType.in() );
490   if ( !CORBA::is_nil( father ) ) {
491     // check that the component is added to the use case browser
492     if ( !useCaseBuilder->IsUseCaseNode( father ) ) {
493       useCaseBuilder->SetRootCurrent();
494       useCaseBuilder->Append( father ); // component object is added as the top level item
495     }
496     return father._retn();
497   }
498
499   SALOME_ModuleCatalog::ModuleCatalog_var aCat =
500     SALOME_ModuleCatalog::ModuleCatalog::_narrow( GetNS()->Resolve("/Kernel/ModulCatalog") );
501   if ( CORBA::is_nil( aCat ) )
502     return father._retn();
503
504   SALOME_ModuleCatalog::Acomponent_var aComp = aCat->GetComponent( compDataType.in() );
505   if ( CORBA::is_nil( aComp ) )
506     return father._retn();
507
508   SALOMEDS::GenericAttribute_wrap anAttr;
509   SALOMEDS::AttributePixMap_wrap  aPixmap;
510
511   father  = aStudyBuilder->NewComponent( compDataType.in() );
512   aStudyBuilder->DefineComponentInstance( father, SMESH_Gen::_this() );
513   anAttr  = aStudyBuilder->FindOrCreateAttribute( father, "AttributePixMap" );
514   aPixmap = anAttr;
515   aPixmap->SetPixMap( "ICON_OBJBROWSER_SMESH" );
516   CORBA::String_var userName = aComp->componentusername();
517   SetName( father, userName.in(), "MESH" );
518   // add component to the use case tree
519   // (to support tree representation customization and drag-n-drop)
520   useCaseBuilder->SetRootCurrent();
521   useCaseBuilder->Append( father ); // component object is added as the top level item
522   if(MYDEBUG) MESSAGE("PublishComponent--END");
523
524   return father._retn();
525 }
526
527 //=============================================================================
528 /*!
529  *  findMaxChildTag [ static internal ]
530  *
531  *  Finds maximum child tag for the given object
532  */
533 //=============================================================================
534
535 static long findMaxChildTag( SALOMEDS::SObject_ptr theSObject )
536 {
537   long aTag = 0;
538   if ( !theSObject->_is_nil() ) {
539     SALOMEDS::Study_var aStudy = theSObject->GetStudy();
540     if ( !aStudy->_is_nil() ) {
541       SALOMEDS::ChildIterator_wrap anIter = aStudy->NewChildIterator( theSObject );
542       for ( ; anIter->More(); anIter->Next() ) {
543         SALOMEDS::SObject_wrap anSO = anIter->Value();
544         long nTag = anSO->Tag();
545         if ( nTag > aTag )
546           aTag = nTag;
547       }
548     }
549   }
550   return aTag;
551 }
552
553 //=======================================================================
554 //function : PublishMesh
555 //purpose  : 
556 //=======================================================================
557
558 SALOMEDS::SObject_ptr SMESH_Gen_i::PublishMesh (SALOMEDS::Study_ptr   theStudy,
559                                                 SMESH::SMESH_Mesh_ptr theMesh,
560                                                 const char*           theName)
561 {
562   if ( CORBA::is_nil( theStudy ) ||
563        CORBA::is_nil( theMesh ))
564     return SALOMEDS::SComponent::_nil();
565   if(MYDEBUG) MESSAGE("PublishMesh--IN");
566
567   // find or publish a mesh
568
569   SALOMEDS::SObject_wrap aMeshSO = ObjectToSObject( theStudy, theMesh );
570   if ( aMeshSO->_is_nil() )
571   {
572     SALOMEDS::SComponent_wrap father = PublishComponent( theStudy );
573     if ( father->_is_nil() )
574       return aMeshSO._retn();
575
576     // Find correct free tag
577     long aTag = findMaxChildTag( father.in() );
578     if ( aTag <= GetAlgorithmsRootTag() )
579       aTag = GetAlgorithmsRootTag() + 1;
580     else
581       aTag++;
582
583     aMeshSO = publish (theStudy, theMesh, father, aTag, "ICON_SMESH_TREE_MESH_WARN" );
584     if ( aMeshSO->_is_nil() )
585       return aMeshSO._retn();
586   }
587   SetName( aMeshSO, theName, "Mesh" );
588
589   // Add shape reference
590
591   GEOM::GEOM_Object_var aShapeObject = theMesh->GetShapeToMesh();
592   if ( !CORBA::is_nil( aShapeObject )) {
593     addReference( theStudy, aMeshSO, aShapeObject, GetRefOnShapeTag() );
594
595     // Publish global hypotheses
596
597     SMESH::ListOfHypothesis_var hypList = theMesh->GetHypothesisList( aShapeObject );
598     for ( int i = 0; i < hypList->length(); i++ )
599     {
600       SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow( hypList[ i ]);
601       SALOMEDS::SObject_wrap so = PublishHypothesis( theStudy, aHyp );
602       AddHypothesisToShape( theStudy, theMesh, aShapeObject, aHyp );
603     }
604   }
605
606   // Publish submeshes
607
608   SMESH_Mesh_i* mesh_i = objectToServant<SMESH_Mesh_i>( theMesh );
609   if ( !mesh_i )
610     return aMeshSO._retn();
611   map<int, SMESH_subMesh_i*>& subMap = mesh_i->_mapSubMesh_i;
612   map<int, SMESH_subMesh_i*>::iterator subIt = subMap.begin();
613   for ( ; subIt != subMap.end(); subIt++ ) {
614     SMESH::SMESH_subMesh_ptr aSubMesh = (*subIt).second->_this();
615     if ( !CORBA::is_nil( aSubMesh )) {
616       aShapeObject = aSubMesh->GetSubShape();
617       SALOMEDS::SObject_wrap( PublishSubMesh( theStudy, theMesh, aSubMesh, aShapeObject ));
618     }
619   }
620
621   // Publish groups
622   const map<int, SMESH::SMESH_GroupBase_ptr>& grMap = mesh_i->getGroups();
623   map<int, SMESH::SMESH_GroupBase_ptr>::const_iterator it = grMap.begin();
624   for ( ; it != grMap.end(); it++ )
625   {
626     SMESH::SMESH_GroupBase_ptr aGroup = (*it).second;
627     if ( !aGroup->_is_nil() ) {
628       GEOM::GEOM_Object_var aShapeObj;
629       SMESH::SMESH_GroupOnGeom_var aGeomGroup = SMESH::SMESH_GroupOnGeom::_narrow( aGroup );
630       if ( !aGeomGroup->_is_nil() )
631         aShapeObj = aGeomGroup->GetShape();
632       SALOMEDS::SObject_wrap( PublishGroup( theStudy, theMesh, aGroup, aShapeObj ));
633     }
634   }
635
636   if(MYDEBUG) MESSAGE("PublishMesh_END");
637   return aMeshSO._retn();
638 }
639
640 //=======================================================================
641 //function : PublishSubMesh
642 //purpose  : 
643 //=======================================================================
644
645 SALOMEDS::SObject_ptr SMESH_Gen_i::PublishSubMesh (SALOMEDS::Study_ptr      theStudy,
646                                                    SMESH::SMESH_Mesh_ptr    theMesh,
647                                                    SMESH::SMESH_subMesh_ptr theSubMesh,
648                                                    GEOM::GEOM_Object_ptr    theShapeObject,
649                                                    const char*              theName)
650 {
651   if (theStudy->_is_nil() || theMesh->_is_nil() ||
652       theSubMesh->_is_nil() || theShapeObject->_is_nil() )
653     return SALOMEDS::SObject::_nil();
654
655   SALOMEDS::SObject_wrap aSubMeshSO = ObjectToSObject( theStudy, theSubMesh );
656   if ( aSubMeshSO->_is_nil() )
657   {
658     SALOMEDS::SObject_wrap aMeshSO = ObjectToSObject( theStudy, theMesh );
659     if ( aMeshSO->_is_nil() ) {
660       aMeshSO = PublishMesh( theStudy, theMesh );
661       if ( aMeshSO->_is_nil())
662         return SALOMEDS::SObject::_nil();
663     }
664     // Find submesh sub-tree tag
665     long aRootTag;
666     const char* aRootName = "";
667     switch ( theShapeObject->GetShapeType() ) {
668     case GEOM::VERTEX:
669       aRootTag  = GetSubMeshOnVertexTag();
670       aRootName = "SubMeshes on Vertex";
671       break;
672     case GEOM::EDGE:
673       aRootTag  = GetSubMeshOnEdgeTag();
674       aRootName = "SubMeshes on Edge";
675       break;
676     case GEOM::WIRE:
677       aRootTag  = GetSubMeshOnWireTag();
678       aRootName = "SubMeshes on Wire";
679       break;
680     case GEOM::FACE:
681       aRootTag  = GetSubMeshOnFaceTag();
682       aRootName = "SubMeshes on Face";    
683       break;
684     case GEOM::SHELL:
685       aRootTag  = GetSubMeshOnShellTag();
686       aRootName = "SubMeshes on Shell";   
687       break;
688     case GEOM::SOLID:
689       aRootTag  = GetSubMeshOnSolidTag();
690       aRootName = "SubMeshes on Solid";
691       break;
692     default:
693       aRootTag  = GetSubMeshOnCompoundTag();
694       aRootName = "SubMeshes on Compound";
695       break;
696     }
697
698     // Find or create submesh root
699     SALOMEDS::SObject_wrap aRootSO = publish (theStudy, CORBA::Object::_nil(),
700                                              aMeshSO, aRootTag, 0, false );
701     if ( aRootSO->_is_nil() )
702       return aSubMeshSO._retn();
703
704     SetName( aRootSO, aRootName );
705
706     // Add new submesh to corresponding sub-tree
707     SMESH::array_of_ElementType_var elemTypes = theSubMesh->GetTypes();
708     const int isEmpty = ( elemTypes->length() == 0 );
709     const char* pm[2] = { "ICON_SMESH_TREE_MESH", "ICON_SMESH_TREE_MESH_WARN" };
710     aSubMeshSO = publish (theStudy, theSubMesh, aRootSO, 0, pm[isEmpty] );
711     if ( aSubMeshSO->_is_nil() )
712       return aSubMeshSO._retn();
713   }
714   SetName( aSubMeshSO, theName, "SubMesh" );
715
716   // Add reference to theShapeObject
717
718   addReference( theStudy, aSubMeshSO, theShapeObject, 1 );
719
720   // Publish hypothesis
721
722   SMESH::ListOfHypothesis_var hypList = theMesh->GetHypothesisList( theShapeObject );
723   for ( int i = 0; i < hypList->length(); i++ ) {
724     SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow( hypList[ i ]);
725     SALOMEDS::SObject_wrap so = PublishHypothesis( theStudy, aHyp );
726     AddHypothesisToShape( theStudy, theMesh, theShapeObject, aHyp );
727   }
728
729   return aSubMeshSO._retn();
730 }
731
732 //=======================================================================
733 //function : PublishGroup
734 //purpose  : 
735 //=======================================================================
736
737 SALOMEDS::SObject_ptr SMESH_Gen_i::PublishGroup (SALOMEDS::Study_ptr    theStudy,
738                                                  SMESH::SMESH_Mesh_ptr  theMesh,
739                                                  SMESH::SMESH_GroupBase_ptr theGroup,
740                                                  GEOM::GEOM_Object_ptr  theShapeObject,
741                                                  const char*            theName)
742 {
743   if (theStudy->_is_nil() || theMesh->_is_nil() || theGroup->_is_nil() )
744     return SALOMEDS::SObject::_nil();
745
746   SALOMEDS::SObject_wrap aGroupSO = ObjectToSObject( theStudy, theGroup );
747   if ( aGroupSO->_is_nil() )
748   {
749     SALOMEDS::SObject_wrap aMeshSO = ObjectToSObject( theStudy, theMesh );
750     if ( aMeshSO->_is_nil() ) {
751       aMeshSO = PublishInStudy( theStudy, SALOMEDS::SObject::_nil(), theMesh, "");
752       if ( aMeshSO->_is_nil())
753         return SALOMEDS::SObject::_nil();
754     }
755     int aType = (int)theGroup->GetType();
756     const char* aRootNames[] = {
757       "Compound Groups", "Groups of Nodes", "Groups of Edges",
758       "Groups of Faces", "Groups of Volumes", "Groups of 0D Elements",
759       "Groups of Balls" };
760
761     // Currently, groups with heterogenous content are not supported
762     if ( aType != SMESH::ALL )
763     {
764       long aRootTag = GetNodeGroupsTag() + aType - 1;
765
766       // Find or create groups root
767       SALOMEDS::SObject_wrap aRootSO = publish (theStudy, CORBA::Object::_nil(),
768                                                aMeshSO, aRootTag, 0, false );
769       if ( aRootSO->_is_nil() ) return SALOMEDS::SObject::_nil();
770
771       if ( aType < sizeof(aRootNames)/sizeof(char*) )
772         SetName( aRootSO, aRootNames[aType] );
773
774       // Add new group to corresponding sub-tree
775       SMESH::array_of_ElementType_var elemTypes = theGroup->GetTypes();
776       int isEmpty = ( elemTypes->length() == 0 );
777       std::string pm[2] = { "ICON_SMESH_TREE_GROUP", "ICON_SMESH_TREE_MESH_WARN" };
778       if ( SMESH::DownCast< SMESH_GroupOnFilter_i* > ( theGroup ))
779       {
780         pm[0] = "ICON_SMESH_TREE_GROUP_ON_FILTER";
781       }
782       else if ( SMESH::DownCast< SMESH_Group_i* > ( theGroup ))
783       {
784         SMESH::array_of_ElementType_var allElemTypes = theMesh->GetTypes();
785         for ( size_t i =0; i < allElemTypes->length() && isEmpty; ++i )
786           isEmpty = ( allElemTypes[i] != theGroup->GetType() );
787       }
788       aGroupSO = publish (theStudy, theGroup, aRootSO, 0, pm[isEmpty].c_str() );
789     }
790     if ( aGroupSO->_is_nil() )
791       return aGroupSO._retn();
792   }
793
794   SetName( aGroupSO, theName, "Group" );
795
796   //Add reference to geometry
797   if ( !theShapeObject->_is_nil() )
798     addReference( theStudy, aGroupSO, theShapeObject, 1 );
799
800   return aGroupSO._retn();
801 }
802
803 //=======================================================================
804 //function : PublishHypothesis
805 //purpose  : 
806 //=======================================================================
807
808 SALOMEDS::SObject_ptr
809   SMESH_Gen_i::PublishHypothesis (SALOMEDS::Study_ptr         theStudy,
810                                   SMESH::SMESH_Hypothesis_ptr theHyp,
811                                   const char*                 theName)
812 {
813   if(MYDEBUG) MESSAGE("PublishHypothesis")
814   if (theStudy->_is_nil() || theHyp->_is_nil())
815     return SALOMEDS::SObject::_nil();
816
817   CORBA::String_var hypType = theHyp->GetName();
818
819   SALOMEDS::SObject_wrap aHypSO = ObjectToSObject( theStudy, theHyp );
820   if ( aHypSO->_is_nil() )
821   {
822     SALOMEDS::SComponent_wrap father = PublishComponent( theStudy );
823     if ( father->_is_nil() )
824       return aHypSO._retn();
825
826     //Find or Create Hypothesis root
827     bool isAlgo = ( !SMESH::SMESH_Algo::_narrow( theHyp )->_is_nil() );
828     int aRootTag = isAlgo ? GetAlgorithmsRootTag() : GetHypothesisRootTag();
829     SALOMEDS::SObject_wrap aRootSO =
830       publish (theStudy, CORBA::Object::_nil(),father, aRootTag,
831                isAlgo ? "ICON_SMESH_TREE_ALGO" : "ICON_SMESH_TREE_HYPO", false);
832     SetName( aRootSO, isAlgo ?  "Algorithms" : "Hypotheses" );
833
834     // Add New Hypothesis
835     string aPmName = isAlgo ? "ICON_SMESH_TREE_ALGO_" : "ICON_SMESH_TREE_HYPO_";
836     aPmName += hypType.in();
837     // prepend plugin name to pixmap name
838     string pluginName = myHypCreatorMap[ hypType.in() ]->GetModuleName();
839     if ( pluginName != "StdMeshers" )
840       aPmName = pluginName + "::" + aPmName;
841     aHypSO = publish( theStudy, theHyp, aRootSO, 0, aPmName.c_str() );
842   }
843
844   SetName( aHypSO, theName, hypType.in() );
845
846   if(MYDEBUG) MESSAGE("PublishHypothesis--END")
847   return aHypSO._retn();
848 }
849
850 //=======================================================================
851 //function : GetMeshOrSubmeshByShape
852 //purpose  : 
853 //=======================================================================
854
855 SALOMEDS::SObject_ptr
856   SMESH_Gen_i::GetMeshOrSubmeshByShape (SALOMEDS::Study_ptr   theStudy,
857                                         SMESH::SMESH_Mesh_ptr theMesh,
858                                         GEOM::GEOM_Object_ptr theShape)
859 {
860   if(MYDEBUG) MESSAGE("GetMeshOrSubmeshByShape")
861   SALOMEDS::SObject_wrap aMeshOrSubMesh;
862   if (theMesh->_is_nil() || ( theShape->_is_nil() && theMesh->HasShapeToMesh()))
863     return aMeshOrSubMesh._retn();
864   
865   TopoDS_Shape aShape;
866   if(theMesh->HasShapeToMesh())
867     aShape = GeomObjectToShape( theShape );
868   else
869     aShape = SMESH_Mesh::PseudoShape();
870
871   SMESH_Mesh_i* mesh_i = objectToServant<SMESH_Mesh_i>( theMesh );
872
873   if ( !aShape.IsNull() && mesh_i && mesh_i->GetImpl().GetMeshDS() ) {
874     SMESHDS_Mesh* meshDS = mesh_i->GetImpl().GetMeshDS();
875     if ( aShape.IsSame( meshDS->ShapeToMesh() ))
876       aMeshOrSubMesh = ObjectToSObject( theStudy, theMesh );
877     else {
878       int shapeID = meshDS->ShapeToIndex( aShape );
879       SMESH::SMESH_subMesh_var aSubMesh = mesh_i->getSubMesh(shapeID);
880       if ( !aSubMesh->_is_nil() )
881         aMeshOrSubMesh = ObjectToSObject( theStudy, aSubMesh );
882     }
883   }
884   if(MYDEBUG) MESSAGE("GetMeshOrSubmeshByShape--END")
885   return aMeshOrSubMesh._retn();
886 }
887
888 //=======================================================================
889 //function : AddHypothesisToShape
890 //purpose  : 
891 //=======================================================================
892
893 bool SMESH_Gen_i::AddHypothesisToShape(SALOMEDS::Study_ptr         theStudy,
894                                        SMESH::SMESH_Mesh_ptr       theMesh,
895                                        GEOM::GEOM_Object_ptr       theShape,
896                                        SMESH::SMESH_Hypothesis_ptr theHyp)
897 {
898   if(MYDEBUG) MESSAGE("AddHypothesisToShape")
899   if (theStudy->_is_nil() || theMesh->_is_nil() ||
900       theHyp->_is_nil() || (theShape->_is_nil()
901                             && theMesh->HasShapeToMesh()) )
902     return false;
903
904   SALOMEDS::SObject_wrap aMeshSO = ObjectToSObject( theStudy, theMesh );
905   if ( aMeshSO->_is_nil() )
906     aMeshSO = PublishMesh( theStudy, theMesh );
907   SALOMEDS::SObject_wrap aHypSO = PublishHypothesis( theStudy, theHyp );
908   if ( aMeshSO->_is_nil() || aHypSO->_is_nil())
909     return false;
910
911   // Find a mesh or submesh refering to theShape
912   SALOMEDS::SObject_wrap aMeshOrSubMesh =
913     GetMeshOrSubmeshByShape( theStudy, theMesh, theShape );
914   if ( aMeshOrSubMesh->_is_nil() )
915   {
916     // publish submesh
917     TopoDS_Shape aShape = GeomObjectToShape( theShape );
918     SMESH_Mesh_i* mesh_i = objectToServant<SMESH_Mesh_i>( theMesh );
919     if ( !aShape.IsNull() && mesh_i && mesh_i->GetImpl().GetMeshDS() ) {
920       SMESHDS_Mesh* meshDS = mesh_i->GetImpl().GetMeshDS();
921       int shapeID = meshDS->ShapeToIndex( aShape );
922       SMESH::SMESH_subMesh_var aSubMesh = mesh_i->getSubMesh(shapeID);
923       aMeshOrSubMesh = PublishSubMesh( theStudy, theMesh, aSubMesh, theShape );
924     }
925     if ( aMeshOrSubMesh->_is_nil() )
926       return false;
927   }
928
929   //Find or Create Applied Hypothesis root
930   bool aIsAlgo = !SMESH::SMESH_Algo::_narrow( theHyp )->_is_nil();
931   SALOMEDS::SObject_wrap AHR =
932     publish (theStudy, CORBA::Object::_nil(), aMeshOrSubMesh,
933              aIsAlgo ? GetRefOnAppliedAlgorithmsTag() : GetRefOnAppliedHypothesisTag(),
934              aIsAlgo ? "ICON_SMESH_TREE_ALGO" : "ICON_SMESH_TREE_HYPO", false);
935   SetName( AHR, aIsAlgo ? "Applied algorithms" : "Applied hypotheses" );
936
937   addReference( theStudy, AHR, theHyp );
938
939   if(MYDEBUG) MESSAGE("AddHypothesisToShape--END")
940   return true;
941 }
942
943 //=======================================================================
944 //function : RemoveHypothesisFromShape
945 //purpose  : 
946 //=======================================================================
947
948 bool SMESH_Gen_i::RemoveHypothesisFromShape(SALOMEDS::Study_ptr         theStudy,
949                                             SMESH::SMESH_Mesh_ptr       theMesh,
950                                             GEOM::GEOM_Object_ptr       theShape,
951                                             SMESH::SMESH_Hypothesis_ptr theHyp)
952 {
953   if (theStudy->_is_nil() || theMesh->_is_nil() ||
954       theHyp->_is_nil() || (theShape->_is_nil()
955                             && theMesh->HasShapeToMesh()))
956     return false;
957
958   SALOMEDS::SObject_wrap aHypSO = ObjectToSObject( theStudy, theHyp );
959   if ( aHypSO->_is_nil() )
960     return false;
961
962   CORBA::String_var hypEntry = aHypSO->GetID();
963
964   // Find a mesh or submesh refering to theShape
965   SALOMEDS::SObject_wrap aMeshOrSubMesh =
966     GetMeshOrSubmeshByShape( theStudy, theMesh, theShape );
967   if ( aMeshOrSubMesh->_is_nil() )
968     return false;
969
970   // Find and remove a reference to aHypSO
971   SALOMEDS::SObject_wrap aRef, anObj;
972   SALOMEDS::ChildIterator_wrap it = theStudy->NewChildIterator( aMeshOrSubMesh );
973   bool found = false;
974   for ( it->InitEx( true ); ( it->More() && !found ); it->Next() ) {
975     anObj = it->Value();
976     if (anObj->ReferencedObject( aRef.inout() ))
977     {
978       CORBA::String_var refEntry = aRef->GetID();
979       found = ( strcmp( refEntry, hypEntry ) == 0 );
980     }
981     if ( found )
982     {
983       SALOMEDS::StudyBuilder_var builder = theStudy->NewBuilder();
984       builder->RemoveObject( anObj );
985     }
986   }
987
988   return true;
989 }
990
991 //================================================================================
992 /*!
993  * \brief Stores names of variables that WILL be passes as parameters when calling
994  *        some method of a given object.
995  *  \param [in] theObject - the object whose a method WILL be called with \a theParameters.
996  *  \param [in] theParameters - a string contating parameters separated by ':'.
997  */
998 //================================================================================
999
1000 void SMESH_Gen_i::UpdateParameters(CORBA::Object_ptr theObject, const char* theParameters)
1001 {
1002   SALOMEDS::Study_var aStudy = GetCurrentStudy();
1003   if ( aStudy->_is_nil() )
1004     return;
1005
1006   // find variable names within theParameters
1007
1008   myLastObj.clear();
1009   myLastParameters.clear();
1010   myLastParamIndex.clear(); /* vector holding indices of virables within the string
1011                                of all varibles used for theObject */ 
1012   int nbVars = 0;
1013   int pos = 0, prevPos = 0, len = strlen( theParameters );
1014   if ( len == 0 ) return;
1015   while ( pos <= len )
1016   {
1017     if ( pos == len || theParameters[pos] == ':' )
1018     {
1019       if ( prevPos < pos )
1020       {
1021         string val( theParameters + prevPos, theParameters + pos );
1022         if ( !aStudy->IsVariable( val.c_str() ))
1023           val.clear();
1024         myLastParameters.push_back( val );
1025         nbVars += (! myLastParameters.back().empty() );
1026       }
1027       else
1028       {
1029         myLastParameters.push_back("");
1030       }
1031       prevPos = pos+1;
1032     }
1033     ++pos;
1034   }
1035
1036   if ( nbVars < 1 )
1037     return;
1038
1039   // store
1040   // (1) variable names in the string of all varibles used for theObject and
1041   // (2) indices of found variables in myLastParamIndex.
1042
1043   // remember theObject
1044   SALOMEDS::SObject_wrap aSObj =  ObjectToSObject(aStudy,theObject);
1045   if ( aSObj->_is_nil() )
1046     return;
1047   CORBA::String_var anObjEntry = aSObj->GetID();
1048   myLastObj = anObjEntry.in();
1049
1050   // get a string of variable names
1051   SALOMEDS::StudyBuilder_var   aStudyBuilder = aStudy->NewBuilder();
1052   SALOMEDS::GenericAttribute_wrap     anAttr =
1053     aStudyBuilder->FindOrCreateAttribute( aSObj, "AttributeString" );
1054   SALOMEDS::AttributeString_wrap aStringAttr = anAttr;
1055   CORBA::String_var                  oldVars = aStringAttr->Value();
1056   std::string                         varStr = oldVars.in();
1057
1058   // add new variables and find indices of variables
1059   for ( size_t i = 0; i < myLastParameters.size(); ++i )
1060   {
1061     int varIndex = -1;
1062     if ( !myLastParameters[i].empty() )
1063     {
1064       // find index of myLastParameters[i] in varStr
1065       int curIndex  = 0;
1066       bool varFound = false;
1067       size_t pos    = 0;
1068       // varStr can be "A|B::C;*=2|D"
1069       const std::string separators(":|;*=");
1070       while ( pos < varStr.size() && !varFound )
1071       {
1072         // skip separators
1073         while ( separators.find( varStr[ pos ]) != std::string::npos )
1074           if ( ++pos >= varStr.size() )
1075             break;
1076         // skip repetition number following '='
1077         if ( varStr[ pos-1 ] == '=' )
1078         {
1079           while ( '0' <= varStr[ pos ] && varStr[ pos ] <= '9' )
1080             ++pos;
1081           continue; // to skip next separator
1082         }
1083         // compare variable name
1084         if ( pos < varStr.size() )
1085         {
1086           varFound = ( varStr.compare( pos, myLastParameters[i].size(), myLastParameters[i] ) == 0 &&
1087                        // same string begining but is length same?
1088                        ( pos + myLastParameters[i].size() >= varStr.size() ||
1089                          separators.find( varStr[ pos+1 ]) != std::string::npos ));
1090           if ( varFound )
1091             varIndex = curIndex;
1092           else
1093             pos = varStr.find_first_of( separators, pos ); // goto the next separator
1094           ++curIndex;
1095         }
1096       }
1097       // add new variable
1098       if ( !varFound )
1099       {
1100         varStr += ":" + myLastParameters[i];
1101         varIndex = curIndex;
1102       }
1103     }
1104     myLastParamIndex.push_back( varIndex );
1105   }
1106   aStringAttr->SetValue( varStr.c_str() );
1107 }
1108
1109 //================================================================================
1110 /*!
1111  * \brief Return all variables used to create an object
1112  *  \param [in] theObjectEntry - an object entry in the current study
1113  *  \return std::vector< std::string > - all variable names (or values of removed variables)
1114  */
1115 //================================================================================
1116
1117 std::vector< std::string > SMESH_Gen_i::GetAllParameters(const std::string& theObjectEntry) const
1118 {
1119   std::vector< std::string > varNames;
1120   if ( myCurrentStudy->_is_nil() )
1121     return varNames;
1122
1123   SALOMEDS::SObject_wrap aSObj = myCurrentStudy->FindObjectID( theObjectEntry.c_str() );
1124   if ( myCurrentStudy->_is_nil() )
1125     return varNames;
1126
1127   // get a string of variable names
1128   SALOMEDS::StudyBuilder_var   aStudyBuilder = myCurrentStudy->NewBuilder();
1129   SALOMEDS::GenericAttribute_wrap     anAttr =
1130     aStudyBuilder->FindOrCreateAttribute( aSObj, "AttributeString" );
1131   SALOMEDS::AttributeString_wrap aStringAttr = anAttr;
1132   CORBA::String_var                  oldVars = aStringAttr->Value();
1133   std::string                         varStr = oldVars.in();
1134
1135   // separate variables within varStr;
1136   // varStr can be "A|B::C;*=2|D"
1137   size_t pos = 0;
1138   const std::string separators(":|;*=");
1139   while ( pos < varStr.size() )
1140   {
1141     // skip separators
1142     pos = varStr.find_first_not_of( separators, pos );
1143     // while ( separators.find( varStr[ pos ]) != std::string::npos )
1144     //   if ( ++pos >= varStr.size() )
1145     //     break;
1146     // skip repetition number following '='
1147     if ( varStr[ pos-1 ] == '=' )
1148     {
1149       while ( '0' <= varStr[ pos ] && varStr[ pos ] <= '9' )
1150         ++pos;
1151       continue; // to skip next separator
1152     }
1153     // store variable name
1154     if ( pos < varStr.size() )
1155     {
1156       size_t pos2 = varStr.find_first_of( separators, pos );
1157       varNames.push_back( varStr.substr( pos, pos2 - pos));
1158       pos = pos2;
1159     }
1160   }
1161   return varNames;
1162 }
1163
1164 //=======================================================================
1165 //function : ParseParameters
1166 //purpose  : Replace variables by their values
1167 //=======================================================================
1168 // char* SMESH_Gen_i::ParseParameters(const char* theParameters)
1169 // {
1170 //   //const char* aParameters = theParameters;
1171 // //   const char* aParameters = CORBA::string_dup(theParameters);
1172 //   TCollection_AsciiString anInputParams;
1173 //   SALOMEDS::Study_var aStudy = GetCurrentStudy();
1174 //   if( !aStudy->_is_nil() ) {
1175 // //     SALOMEDS::ListOfListOfStrings_var aSections = aStudy->ParseVariables(theParameters);
1176 // //     for(int j=0;j<aSections->length();j++) {
1177 // //       SALOMEDS::ListOfStrings aVars= aSections[j];
1178 // //       for(int i=0;i<aVars.length();i++ ) {
1179 // //         anInputParams += aStudy->IsVariable(aVars[i].in()) ? 
1180 // //           TCollection_AsciiString(aVars[i].in()) : TCollection_AsciiString("");
1181 // //         if(i != aVars.length()-1)
1182 // //           anInputParams+=":";
1183 // //       }
1184 // //       if(j!=aSections->length()-1)
1185 // //         anInputParams+="|";
1186 // //     }
1187 //     TCollection_AsciiString paramStr( theParameters );
1188 //     int beg = 0, end;
1189 //     char sep, *pParams = (char*)paramStr.ToCString();
1190 //     while ( beg < paramStr.Length() )
1191 //     {
1192 //       end = beg-1;
1193 //       while ( ++end < paramStr.Length() )
1194 //         if ( pParams[end] == ':' || pParams[end] == '|')
1195 //           break;
1196 //       if ( end < paramStr.Length())
1197 //       {
1198 //         sep = pParams[end];
1199 //         pParams[end] = '\0';
1200 //       }
1201 //       if ( aStudy->IsVariable( pParams+beg ))
1202 //         anInputParams += pParams+beg;
1203 //       if ( end < paramStr.Length() )
1204 //         anInputParams += sep;
1205 //       else
1206 //         break;
1207 //       beg = end + 1;
1208 //     }
1209 //   }
1210 //   return CORBA::string_dup(anInputParams.ToCString());
1211 // }
1212
1213 //=======================================================================
1214 //function : GetParameters
1215 //purpose  : 
1216 //=======================================================================
1217
1218 char* SMESH_Gen_i::GetParameters(CORBA::Object_ptr theObject)
1219 {
1220   CORBA::String_var aResult("");
1221
1222   SALOMEDS::SObject_wrap aSObj = ObjectToSObject( myCurrentStudy, theObject );
1223   if ( !aSObj->_is_nil() )
1224   {
1225     SALOMEDS::GenericAttribute_wrap attr;
1226     if ( aSObj->FindAttribute( attr.inout(), "AttributeString"))
1227     {
1228       SALOMEDS::AttributeString_wrap strAttr = attr;
1229       aResult = strAttr->Value();
1230     }
1231   }
1232   return aResult._retn();
1233 }