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