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