Salome HOME
52863: Convert To Bi-Quadratic incorrectly locate in-face central nodes
[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         SMESH::array_of_ElementType_var allElemTypes = theMesh->GetTypes();
775         for ( size_t i =0; i < allElemTypes->length() && isEmpty; ++i )
776           isEmpty = ( allElemTypes[i] != theGroup->GetType() );
777       }
778       aGroupSO = publish (theStudy, theGroup, aRootSO, 0, pm[isEmpty].c_str() );
779     }
780     if ( aGroupSO->_is_nil() )
781       return aGroupSO._retn();
782   }
783
784   SetName( aGroupSO, theName, "Group" );
785
786   //Add reference to geometry
787   if ( !theShapeObject->_is_nil() )
788     addReference( theStudy, aGroupSO, theShapeObject, 1 );
789
790   return aGroupSO._retn();
791 }
792
793 //=======================================================================
794 //function : PublishHypothesis
795 //purpose  : 
796 //=======================================================================
797
798 SALOMEDS::SObject_ptr
799   SMESH_Gen_i::PublishHypothesis (SALOMEDS::Study_ptr         theStudy,
800                                   SMESH::SMESH_Hypothesis_ptr theHyp,
801                                   const char*                 theName)
802 {
803   if(MYDEBUG) MESSAGE("PublishHypothesis")
804   if (theStudy->_is_nil() || theHyp->_is_nil())
805     return SALOMEDS::SObject::_nil();
806
807   CORBA::String_var hypType = theHyp->GetName();
808
809   SALOMEDS::SObject_wrap aHypSO = ObjectToSObject( theStudy, theHyp );
810   if ( aHypSO->_is_nil() )
811   {
812     SALOMEDS::SComponent_wrap father = PublishComponent( theStudy );
813     if ( father->_is_nil() )
814       return aHypSO._retn();
815
816     //Find or Create Hypothesis root
817     bool isAlgo = ( !SMESH::SMESH_Algo::_narrow( theHyp )->_is_nil() );
818     int aRootTag = isAlgo ? GetAlgorithmsRootTag() : GetHypothesisRootTag();
819     SALOMEDS::SObject_wrap aRootSO =
820       publish (theStudy, CORBA::Object::_nil(),father, aRootTag,
821                isAlgo ? "ICON_SMESH_TREE_ALGO" : "ICON_SMESH_TREE_HYPO", false);
822     SetName( aRootSO, isAlgo ?  "Algorithms" : "Hypotheses" );
823
824     // Add New Hypothesis
825     string aPmName = isAlgo ? "ICON_SMESH_TREE_ALGO_" : "ICON_SMESH_TREE_HYPO_";
826     aPmName += hypType.in();
827     // prepend plugin name to pixmap name
828     string pluginName = myHypCreatorMap[ hypType.in() ]->GetModuleName();
829     if ( pluginName != "StdMeshers" )
830       aPmName = pluginName + "::" + aPmName;
831     aHypSO = publish( theStudy, theHyp, aRootSO, 0, aPmName.c_str() );
832   }
833
834   SetName( aHypSO, theName, hypType.in() );
835
836   if(MYDEBUG) MESSAGE("PublishHypothesis--END")
837   return aHypSO._retn();
838 }
839
840 //=======================================================================
841 //function : GetMeshOrSubmeshByShape
842 //purpose  : 
843 //=======================================================================
844
845 SALOMEDS::SObject_ptr
846   SMESH_Gen_i::GetMeshOrSubmeshByShape (SALOMEDS::Study_ptr   theStudy,
847                                         SMESH::SMESH_Mesh_ptr theMesh,
848                                         GEOM::GEOM_Object_ptr theShape)
849 {
850   if(MYDEBUG) MESSAGE("GetMeshOrSubmeshByShape")
851   SALOMEDS::SObject_wrap aMeshOrSubMesh;
852   if (theMesh->_is_nil() || ( theShape->_is_nil() && theMesh->HasShapeToMesh()))
853     return aMeshOrSubMesh._retn();
854   
855   TopoDS_Shape aShape;
856   if(theMesh->HasShapeToMesh())
857     aShape = GeomObjectToShape( theShape );
858   else
859     aShape = SMESH_Mesh::PseudoShape();
860
861   SMESH_Mesh_i* mesh_i = objectToServant<SMESH_Mesh_i>( theMesh );
862
863   if ( !aShape.IsNull() && mesh_i && mesh_i->GetImpl().GetMeshDS() ) {
864     SMESHDS_Mesh* meshDS = mesh_i->GetImpl().GetMeshDS();
865     if ( aShape.IsSame( meshDS->ShapeToMesh() ))
866       aMeshOrSubMesh = ObjectToSObject( theStudy, theMesh );
867     else {
868       int shapeID = meshDS->ShapeToIndex( aShape );
869       SMESH::SMESH_subMesh_var aSubMesh = mesh_i->getSubMesh(shapeID);
870       if ( !aSubMesh->_is_nil() )
871         aMeshOrSubMesh = ObjectToSObject( theStudy, aSubMesh );
872     }
873   }
874   if(MYDEBUG) MESSAGE("GetMeshOrSubmeshByShape--END")
875   return aMeshOrSubMesh._retn();
876 }
877
878 //=======================================================================
879 //function : AddHypothesisToShape
880 //purpose  : 
881 //=======================================================================
882
883 bool SMESH_Gen_i::AddHypothesisToShape(SALOMEDS::Study_ptr         theStudy,
884                                        SMESH::SMESH_Mesh_ptr       theMesh,
885                                        GEOM::GEOM_Object_ptr       theShape,
886                                        SMESH::SMESH_Hypothesis_ptr theHyp)
887 {
888   if(MYDEBUG) MESSAGE("AddHypothesisToShape")
889   if (theStudy->_is_nil() || theMesh->_is_nil() ||
890       theHyp->_is_nil() || (theShape->_is_nil()
891                             && theMesh->HasShapeToMesh()) )
892     return false;
893
894   SALOMEDS::SObject_wrap aMeshSO = ObjectToSObject( theStudy, theMesh );
895   if ( aMeshSO->_is_nil() )
896     aMeshSO = PublishMesh( theStudy, theMesh );
897   SALOMEDS::SObject_wrap aHypSO = PublishHypothesis( theStudy, theHyp );
898   if ( aMeshSO->_is_nil() || aHypSO->_is_nil())
899     return false;
900
901   // Find a mesh or submesh refering to theShape
902   SALOMEDS::SObject_wrap aMeshOrSubMesh =
903     GetMeshOrSubmeshByShape( theStudy, theMesh, theShape );
904   if ( aMeshOrSubMesh->_is_nil() )
905   {
906     // publish submesh
907     TopoDS_Shape aShape = GeomObjectToShape( theShape );
908     SMESH_Mesh_i* mesh_i = objectToServant<SMESH_Mesh_i>( theMesh );
909     if ( !aShape.IsNull() && mesh_i && mesh_i->GetImpl().GetMeshDS() ) {
910       SMESHDS_Mesh* meshDS = mesh_i->GetImpl().GetMeshDS();
911       int shapeID = meshDS->ShapeToIndex( aShape );
912       SMESH::SMESH_subMesh_var aSubMesh = mesh_i->getSubMesh(shapeID);
913       aMeshOrSubMesh = PublishSubMesh( theStudy, theMesh, aSubMesh, theShape );
914     }
915     if ( aMeshOrSubMesh->_is_nil() )
916       return false;
917   }
918
919   //Find or Create Applied Hypothesis root
920   bool aIsAlgo = !SMESH::SMESH_Algo::_narrow( theHyp )->_is_nil();
921   SALOMEDS::SObject_wrap AHR =
922     publish (theStudy, CORBA::Object::_nil(), aMeshOrSubMesh,
923              aIsAlgo ? GetRefOnAppliedAlgorithmsTag() : GetRefOnAppliedHypothesisTag(),
924              aIsAlgo ? "ICON_SMESH_TREE_ALGO" : "ICON_SMESH_TREE_HYPO", false);
925   SetName( AHR, aIsAlgo ? "Applied algorithms" : "Applied hypotheses" );
926
927   addReference( theStudy, AHR, theHyp );
928
929   if(MYDEBUG) MESSAGE("AddHypothesisToShape--END")
930   return true;
931 }
932
933 //=======================================================================
934 //function : RemoveHypothesisFromShape
935 //purpose  : 
936 //=======================================================================
937
938 bool SMESH_Gen_i::RemoveHypothesisFromShape(SALOMEDS::Study_ptr         theStudy,
939                                             SMESH::SMESH_Mesh_ptr       theMesh,
940                                             GEOM::GEOM_Object_ptr       theShape,
941                                             SMESH::SMESH_Hypothesis_ptr theHyp)
942 {
943   if (theStudy->_is_nil() || theMesh->_is_nil() ||
944       theHyp->_is_nil() || (theShape->_is_nil()
945                             && theMesh->HasShapeToMesh()))
946     return false;
947
948   SALOMEDS::SObject_wrap aHypSO = ObjectToSObject( theStudy, theHyp );
949   if ( aHypSO->_is_nil() )
950     return false;
951
952   CORBA::String_var hypEntry = aHypSO->GetID();
953
954   // Find a mesh or sub-mesh referring to theShape
955   SALOMEDS::SObject_wrap aMeshOrSubMesh =
956     GetMeshOrSubmeshByShape( theStudy, theMesh, theShape );
957   if ( aMeshOrSubMesh->_is_nil() )
958     return false;
959
960   // Find and remove a reference to aHypSO
961   SALOMEDS::SObject_wrap aRef, anObj;
962   SALOMEDS::ChildIterator_wrap it = theStudy->NewChildIterator( aMeshOrSubMesh );
963   bool found = false;
964   for ( it->InitEx( true ); ( it->More() && !found ); it->Next() ) {
965     anObj = it->Value();
966     if (anObj->ReferencedObject( aRef.inout() ))
967     {
968       CORBA::String_var refEntry = aRef->GetID();
969       found = ( strcmp( refEntry, hypEntry ) == 0 );
970     }
971     if ( found )
972     {
973       SALOMEDS::StudyBuilder_var builder = theStudy->NewBuilder();
974       builder->RemoveObject( anObj );
975     }
976   }
977
978   return true;
979 }
980
981 //================================================================================
982 /*!
983  * \brief Stores names of variables that WILL be passes as parameters when calling
984  *        some method of a given object.
985  *  \param [in] theObject - the object whose a method WILL be called with \a theParameters.
986  *  \param [in] theParameters - a string contating parameters separated by ':'.
987  */
988 //================================================================================
989
990 void SMESH_Gen_i::UpdateParameters(CORBA::Object_ptr theObject, const char* theParameters)
991 {
992   SALOMEDS::Study_var aStudy = GetCurrentStudy();
993   if ( aStudy->_is_nil() )
994     return;
995
996   // find variable names within theParameters
997
998   myLastObj.clear();
999   myLastParameters.clear();
1000   myLastParamIndex.clear(); /* vector holding indices of virables within the string
1001                                of all varibles used for theObject */ 
1002   int nbVars = 0;
1003   int pos = 0, prevPos = 0, len = strlen( theParameters );
1004   if ( len == 0 ) return;
1005   while ( pos <= len )
1006   {
1007     if ( pos == len || theParameters[pos] == ':' )
1008     {
1009       if ( prevPos < pos )
1010       {
1011         string val( theParameters + prevPos, theParameters + pos );
1012         if ( !aStudy->IsVariable( val.c_str() ))
1013           val.clear();
1014         myLastParameters.push_back( val );
1015         nbVars += (! myLastParameters.back().empty() );
1016       }
1017       else
1018       {
1019         myLastParameters.push_back("");
1020       }
1021       prevPos = pos+1;
1022     }
1023     ++pos;
1024   }
1025
1026   if ( nbVars < 1 )
1027     return;
1028
1029   // store
1030   // (1) variable names in the string of all varibles used for theObject and
1031   // (2) indices of found variables in myLastParamIndex.
1032
1033   // remember theObject
1034   SALOMEDS::SObject_wrap aSObj =  ObjectToSObject(aStudy,theObject);
1035   if ( aSObj->_is_nil() )
1036     return;
1037   CORBA::String_var anObjEntry = aSObj->GetID();
1038   myLastObj = anObjEntry.in();
1039
1040   // get a string of variable names
1041   SALOMEDS::StudyBuilder_var   aStudyBuilder = aStudy->NewBuilder();
1042   SALOMEDS::GenericAttribute_wrap     anAttr =
1043     aStudyBuilder->FindOrCreateAttribute( aSObj, "AttributeString" );
1044   SALOMEDS::AttributeString_wrap aStringAttr = anAttr;
1045   CORBA::String_var                  oldVars = aStringAttr->Value();
1046   std::string                         varStr = oldVars.in();
1047
1048   // add new variables and find indices of variables
1049   for ( size_t i = 0; i < myLastParameters.size(); ++i )
1050   {
1051     int varIndex = -1;
1052     if ( !myLastParameters[i].empty() )
1053     {
1054       // find index of myLastParameters[i] in varStr
1055       int curIndex  = 0;
1056       bool varFound = false;
1057       size_t pos    = 0;
1058       // varStr can be "A|B::C;*=2|D"
1059       const std::string separators(":|;*=");
1060       while ( pos < varStr.size() && !varFound )
1061       {
1062         // skip separators
1063         while ( separators.find( varStr[ pos ]) != std::string::npos )
1064           if ( ++pos >= varStr.size() )
1065             break;
1066         // skip repetition number following '='
1067         if ( varStr[ pos-1 ] == '=' )
1068         {
1069           while ( '0' <= varStr[ pos ] && varStr[ pos ] <= '9' )
1070             ++pos;
1071           continue; // to skip next separator
1072         }
1073         // compare variable name
1074         if ( pos < varStr.size() )
1075         {
1076           varFound = ( varStr.compare( pos, myLastParameters[i].size(), myLastParameters[i] ) == 0 &&
1077                        // same string begining but is length same?
1078                        ( pos + myLastParameters[i].size() >= varStr.size() ||
1079                          separators.find( varStr[ pos+1 ]) != std::string::npos ));
1080           if ( varFound )
1081             varIndex = curIndex;
1082           else
1083             pos = varStr.find_first_of( separators, pos ); // goto the next separator
1084           ++curIndex;
1085         }
1086       }
1087       // add new variable
1088       if ( !varFound )
1089       {
1090         varStr += ":" + myLastParameters[i];
1091         varIndex = curIndex;
1092       }
1093     }
1094     myLastParamIndex.push_back( varIndex );
1095   }
1096   aStringAttr->SetValue( varStr.c_str() );
1097 }
1098
1099 //================================================================================
1100 /*!
1101  * \brief Return all variables used to create an object
1102  *  \param [in] theObjectEntry - an object entry in the current study
1103  *  \return std::vector< std::string > - all variable names (or values of removed variables)
1104  */
1105 //================================================================================
1106
1107 std::vector< std::string > SMESH_Gen_i::GetAllParameters(const std::string& theObjectEntry) const
1108 {
1109   std::vector< std::string > varNames;
1110   if ( myCurrentStudy->_is_nil() )
1111     return varNames;
1112
1113   SALOMEDS::SObject_wrap aSObj = myCurrentStudy->FindObjectID( theObjectEntry.c_str() );
1114   if ( myCurrentStudy->_is_nil() )
1115     return varNames;
1116
1117   // get a string of variable names
1118   SALOMEDS::StudyBuilder_var   aStudyBuilder = myCurrentStudy->NewBuilder();
1119   SALOMEDS::GenericAttribute_wrap     anAttr =
1120     aStudyBuilder->FindOrCreateAttribute( aSObj, "AttributeString" );
1121   SALOMEDS::AttributeString_wrap aStringAttr = anAttr;
1122   CORBA::String_var                  oldVars = aStringAttr->Value();
1123   std::string                         varStr = oldVars.in();
1124
1125   // separate variables within varStr;
1126   // varStr can be "A|B::C;*=2|D"
1127   size_t pos = 0;
1128   const std::string separators(":|;*=");
1129   while ( pos < varStr.size() )
1130   {
1131     // skip separators
1132     pos = varStr.find_first_not_of( separators, pos );
1133     // while ( separators.find( varStr[ pos ]) != std::string::npos )
1134     //   if ( ++pos >= varStr.size() )
1135     //     break;
1136     // skip repetition number following '='
1137     if ( varStr[ pos-1 ] == '=' )
1138     {
1139       while ( '0' <= varStr[ pos ] && varStr[ pos ] <= '9' )
1140         ++pos;
1141       continue; // to skip next separator
1142     }
1143     // store variable name
1144     if ( pos < varStr.size() )
1145     {
1146       size_t pos2 = varStr.find_first_of( separators, pos );
1147       varNames.push_back( varStr.substr( pos, pos2 - pos));
1148       pos = pos2;
1149     }
1150   }
1151   return varNames;
1152 }
1153
1154 //=======================================================================
1155 //function : ParseParameters
1156 //purpose  : Replace variables by their values
1157 //=======================================================================
1158 // char* SMESH_Gen_i::ParseParameters(const char* theParameters)
1159 // {
1160 //   //const char* aParameters = theParameters;
1161 // //   const char* aParameters = CORBA::string_dup(theParameters);
1162 //   TCollection_AsciiString anInputParams;
1163 //   SALOMEDS::Study_var aStudy = GetCurrentStudy();
1164 //   if( !aStudy->_is_nil() ) {
1165 // //     SALOMEDS::ListOfListOfStrings_var aSections = aStudy->ParseVariables(theParameters);
1166 // //     for(int j=0;j<aSections->length();j++) {
1167 // //       SALOMEDS::ListOfStrings aVars= aSections[j];
1168 // //       for(int i=0;i<aVars.length();i++ ) {
1169 // //         anInputParams += aStudy->IsVariable(aVars[i].in()) ? 
1170 // //           TCollection_AsciiString(aVars[i].in()) : TCollection_AsciiString("");
1171 // //         if(i != aVars.length()-1)
1172 // //           anInputParams+=":";
1173 // //       }
1174 // //       if(j!=aSections->length()-1)
1175 // //         anInputParams+="|";
1176 // //     }
1177 //     TCollection_AsciiString paramStr( theParameters );
1178 //     int beg = 0, end;
1179 //     char sep, *pParams = (char*)paramStr.ToCString();
1180 //     while ( beg < paramStr.Length() )
1181 //     {
1182 //       end = beg-1;
1183 //       while ( ++end < paramStr.Length() )
1184 //         if ( pParams[end] == ':' || pParams[end] == '|')
1185 //           break;
1186 //       if ( end < paramStr.Length())
1187 //       {
1188 //         sep = pParams[end];
1189 //         pParams[end] = '\0';
1190 //       }
1191 //       if ( aStudy->IsVariable( pParams+beg ))
1192 //         anInputParams += pParams+beg;
1193 //       if ( end < paramStr.Length() )
1194 //         anInputParams += sep;
1195 //       else
1196 //         break;
1197 //       beg = end + 1;
1198 //     }
1199 //   }
1200 //   return CORBA::string_dup(anInputParams.ToCString());
1201 // }
1202
1203 //=======================================================================
1204 //function : GetParameters
1205 //purpose  : 
1206 //=======================================================================
1207
1208 char* SMESH_Gen_i::GetParameters(CORBA::Object_ptr theObject)
1209 {
1210   CORBA::String_var aResult("");
1211
1212   SALOMEDS::SObject_wrap aSObj = ObjectToSObject( myCurrentStudy, theObject );
1213   if ( !aSObj->_is_nil() )
1214   {
1215     SALOMEDS::GenericAttribute_wrap attr;
1216     if ( aSObj->FindAttribute( attr.inout(), "AttributeString"))
1217     {
1218       SALOMEDS::AttributeString_wrap strAttr = attr;
1219       aResult = strAttr->Value();
1220     }
1221   }
1222   return aResult._retn();
1223 }