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