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