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