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