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