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