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