Salome HOME
14df8189a89d74779db64717bd067e78656d5600
[modules/smesh.git] / src / SMESH_I / SMESH_NoteBook.cxx
1 // Copyright (C) 2008  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
3 //
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
8 //
9 // This library is distributed in the hope that it will be useful
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 // Lesser General Public License for more details.
13 //
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 //
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 //
20 // File      : SMESH_NoteBook.cxx
21 // Author    : Roman NIKOLAEV
22
23 #include "SMESH_2smeshpy.hxx"
24 #include "SMESH_NoteBook.hxx"
25 #include "SMESH_Gen_i.hxx"
26 #include "SMESH_PythonDump.hxx"
27
28 #include <Resource_DataMapOfAsciiStringAsciiString.hxx>
29 #include <TColStd_SequenceOfAsciiString.hxx>
30 #include <TColStd_HSequenceOfInteger.hxx>
31
32 #include <vector>
33 #include <string>
34
35 #ifdef _DEBUG_
36 static int MYDEBUG = 1;
37 #else
38 static int MYDEBUG = 1;
39 #endif
40
41 using namespace std;
42
43
44
45 //================================================================================
46 /*!
47  * \brief Constructor
48  */
49 //================================================================================
50 ObjectStates::ObjectStates(TCollection_AsciiString theType)
51 {
52   _type = theType;
53   _dumpstate = 0;
54 }
55
56 //================================================================================
57 /*!
58  * \brief Destructor
59  */
60 //================================================================================
61 ObjectStates::~ObjectStates()
62 {
63 }
64
65 //================================================================================
66 /*!
67  * \brief Add new object state 
68  * \param theState - Object state (vector of notebook variable)
69  */
70 //================================================================================
71 void ObjectStates::AddState(const TState &theState)
72 {
73   _states.push_back(theState);
74 }
75
76 //================================================================================
77 /*!
78  * \brief Return current object state
79  * \\retval state - Object state (vector of notebook variable)
80  */
81 //================================================================================
82 TState ObjectStates::GetCurrectState() const
83 {
84   if(_states.size() > _dumpstate)
85     return _states[_dumpstate];
86   TState empty;
87   return empty;
88 }
89
90
91 //================================================================================
92 /*!
93  *
94  */
95 //================================================================================
96 TAllStates ObjectStates::GetAllStates() const
97 {
98   return _states;
99 }
100
101 //================================================================================
102 /*!
103  *
104  */
105 //================================================================================
106 void ObjectStates::IncrementState()
107 {
108   _dumpstate++;
109 }
110
111 //================================================================================
112 /*!
113  *
114  */
115 //================================================================================
116 TCollection_AsciiString ObjectStates::GetObjectType() const{
117   return _type;
118 }
119
120
121 //================================================================================
122 /*!
123  * \brief Constructor
124  */
125 //================================================================================
126 LayerDistributionStates::LayerDistributionStates():
127   ObjectStates("LayerDistribution")
128 {
129 }
130 //================================================================================
131 /*!
132  * \brief Destructor
133  */
134 //================================================================================
135 LayerDistributionStates::~LayerDistributionStates()
136 {
137 }
138
139
140 //================================================================================
141 /*!
142  * \brief AddDistribution
143  */
144 //================================================================================
145 void LayerDistributionStates::AddDistribution(const TCollection_AsciiString& theDistribution)
146 {
147   _distributions.insert(pair<TCollection_AsciiString,TCollection_AsciiString>(theDistribution,""));
148 }
149
150 //================================================================================
151 /*!
152  * \brief HasDistribution
153  */
154 //================================================================================
155 bool LayerDistributionStates::HasDistribution(const TCollection_AsciiString& theDistribution) const
156 {
157   return _distributions.find(theDistribution) != _distributions.end();
158 }
159
160 //================================================================================
161 /*!
162  * \brief SetDistributionType
163  */
164 //================================================================================
165 bool LayerDistributionStates::SetDistributionType(const TCollection_AsciiString& theDistribution,
166                                                   const TCollection_AsciiString& theType)
167 {
168   TDistributionMap::iterator it = _distributions.find(theDistribution);
169   if(it == _distributions.end())
170     return false;
171   (*it).second = theType;
172   return true;
173 }
174
175 //================================================================================
176 /*!
177  * \brief GetDistributionType
178  */
179 //================================================================================
180 TCollection_AsciiString LayerDistributionStates::
181 GetDistributionType(const TCollection_AsciiString& theDistribution) const
182 {
183   TDistributionMap::const_iterator it = _distributions.find(theDistribution);
184   return (it == _distributions.end()) ? TCollection_AsciiString() : (*it).second;
185 }
186
187 //================================================================================
188 /*!
189  * \brief Constructor
190  */
191 //================================================================================
192 SMESH_NoteBook::SMESH_NoteBook()
193 {
194   InitObjectMap();
195 }
196
197 //================================================================================
198 /*!
199  * \brief Destructor
200  */
201 //================================================================================
202 SMESH_NoteBook::~SMESH_NoteBook()
203 {
204   TVariablesMap::const_iterator it = _objectMap.begin();
205   for(;it!=_objectMap.end();it++) {
206     if((*it).second)
207       delete (*it).second;
208   }
209 }
210
211 //================================================================================
212 /*!
213  * \brief Replace parameters of the functions on the Salome NoteBook Variables
214  * \param theString - Input string
215  * \retval TCollection_AsciiString - Convertion result
216  */
217 //================================================================================
218 void SMESH_NoteBook::ReplaceVariables()
219 {
220   for(int i=0;i<_commands.size();i++) {
221     Handle(_pyCommand) aCmd = _commands[i];
222     TCollection_AsciiString aMethod = aCmd->GetMethod();
223     TCollection_AsciiString aObject = aCmd->GetObject();
224     TCollection_AsciiString aResultValue = aCmd->GetResultValue();
225     if(MYDEBUG) {
226       cout<<"Command before : "<< aCmd->GetString()<<endl;
227       cout<<"Method : "<< aMethod<<endl;
228       cout<<"Object : "<< aObject<<endl;
229       cout<<"Result : "<< aResultValue<<endl;
230     }
231     
232     // check if method modifies the object itself
233     TVariablesMap::const_iterator it = _objectMap.find(aObject);
234     if(it == _objectMap.end()) // check if method returns a new object
235       it = _objectMap.find(aResultValue);
236     
237     if(it == _objectMap.end()) { // check if method modifies a mesh using mesh editor
238       TMeshEditorMap::const_iterator meIt = myMeshEditors.find(aObject);
239       if(meIt != myMeshEditors.end()) {
240         TCollection_AsciiString aMesh = (*meIt).second;
241         it = _objectMap.find(aMesh);
242       }
243     }
244     
245     if(it != _objectMap.end()) {
246       ObjectStates *aStates = (*it).second;
247       // Case for LocalLength hypothesis
248       if(aStates->GetObjectType().IsEqual("LocalLength") && aStates->GetCurrectState().size() >= 2) {
249         if(aMethod.IsEqual("SetLength")) {
250           if(!aStates->GetCurrectState().at(0).IsEmpty() )
251             aCmd->SetArg(1,aStates->GetCurrectState().at(0));
252           aStates->IncrementState();
253         }
254         else if(aMethod.IsEqual("SetPrecision")) {
255           if(!aStates->GetCurrectState().at(1).IsEmpty() )
256             aCmd->SetArg(1,aStates->GetCurrectState().at(1));
257           aStates->IncrementState();
258         }
259       }
260       
261       // Case for SegmentLengthAroundVertex hypothesis
262       else if(aStates->GetObjectType().IsEqual("SegmentLengthAroundVertex")
263               && aStates->GetCurrectState().size() >= 1) {
264         if(aMethod == "SetLength") {
265           if(!aStates->GetCurrectState().at(0).IsEmpty() )
266             aCmd->SetArg(1,aStates->GetCurrectState().at(0));
267           aStates->IncrementState();
268         }
269       }
270
271       // Case for Arithmetic1D and StartEndLength hypothesis
272       else if(aStates->GetObjectType().IsEqual("Arithmetic1D") || 
273               aStates->GetObjectType().IsEqual("StartEndLength")) {
274         if(aMethod == "SetLength" &&
275            aStates->GetCurrectState().size() >= 2) {
276           if(aCmd->GetArg(2) == "1" && !aStates->GetCurrectState().at(0).IsEmpty())
277             aCmd->SetArg(1,aStates->GetCurrectState().at(0));
278           else if(!aStates->GetCurrectState().at(1).IsEmpty())
279             aCmd->SetArg(1,aStates->GetCurrectState().at(1));
280           aStates->IncrementState();
281         }
282       }
283       
284       //Case for Deflection1D hypothesis
285       else if(aStates->GetObjectType().IsEqual("Deflection1D")){
286         if(aMethod == "SetDeflection" && aStates->GetCurrectState().size() >= 1) {
287           if(!aStates->GetCurrectState().at(0).IsEmpty() )
288             aCmd->SetArg(1,aStates->GetCurrectState().at(0));
289           aStates->IncrementState();
290         }
291       }
292       
293       // Case for LayerDistribution hypothesis (not finished yet)
294       else if(aStates->GetObjectType() == "LayerDistribution") {
295         if(aMethod == "SetLayerDistribution"){
296           LayerDistributionStates* aLDStates = (LayerDistributionStates*)(aStates);
297           aLDStates->AddDistribution(aCmd->GetArg(1));
298         }
299       }
300       
301       // Case for MaxElementArea hypothesis
302       else if(aStates->GetObjectType().IsEqual("MaxElementArea")){
303         if(aMethod == "SetMaxElementArea" && aStates->GetCurrectState().size() >= 1) {
304           if(!aStates->GetCurrectState().at(0).IsEmpty() )
305             aCmd->SetArg(1,aStates->GetCurrectState().at(0));
306           aStates->IncrementState();
307         }
308       }
309
310       // Case for MaxElementVolume hypothesis
311       else if(aStates->GetObjectType().IsEqual("MaxElementVolume")){
312         if(aMethod == "SetMaxElementVolume" && aStates->GetCurrectState().size() >= 1) {
313           if(!aStates->GetCurrectState().at(0).IsEmpty() )
314             aCmd->SetArg(1,aStates->GetCurrectState().at(0));
315           aStates->IncrementState();
316         }
317       }
318
319       // Case for NETGEN_Parameters_2D or NETGEN_Parameters_2D hypothesis
320       else if(aStates->GetObjectType().IsEqual("NETGEN_Parameters_2D") ||
321               aStates->GetObjectType().IsEqual("NETGEN_Parameters")){
322         if(aMethod == "SetMaxSize" && aStates->GetCurrectState().size() >= 1) {
323           if(!aStates->GetCurrectState().at(0).IsEmpty() )
324             aCmd->SetArg(1,aStates->GetCurrectState().at(0));
325           aStates->IncrementState();
326         }
327         else if(aMethod == "SetGrowthRate" && aStates->GetCurrectState().size() >= 2) {
328           if(!aStates->GetCurrectState().at(1).IsEmpty() )
329             aCmd->SetArg(1,aStates->GetCurrectState().at(1));
330           aStates->IncrementState();
331         }
332         else if(aMethod == "SetNbSegPerEdge" && aStates->GetCurrectState().size() >= 3) {
333           if(!aStates->GetCurrectState().at(2).IsEmpty() )
334             aCmd->SetArg(1,aStates->GetCurrectState().at(2));
335           aStates->IncrementState();
336         } 
337         else if(aMethod == "SetNbSegPerRadius" && aStates->GetCurrectState().size() >= 4) {
338           if(!aStates->GetCurrectState().at(3).IsEmpty() )
339             aCmd->SetArg(1,aStates->GetCurrectState().at(3));
340           aStates->IncrementState();
341         } 
342       }
343
344       // Case for NETGEN_SimpleParameters_3D or NETGEN_SimpleParameters_2D hypothesis
345       else if(aStates->GetObjectType().IsEqual("NETGEN_SimpleParameters_3D") ||
346               aStates->GetObjectType().IsEqual("NETGEN_SimpleParameters_2D")){
347
348         if((aMethod == "SetNumberOfSegments" || aMethod == "LocalLength") && 
349            aStates->GetCurrectState().size() >= 1) {
350           if(!aStates->GetCurrectState().at(0).IsEmpty() )
351             aCmd->SetArg(1,aStates->GetCurrectState().at(0));
352           aStates->IncrementState();
353         }
354         else if(aMethod == "SetMaxElementArea" && aStates->GetCurrectState().size() >= 2) {
355           if(!aStates->GetCurrectState().at(1).IsEmpty() )
356             aCmd->SetArg(1,aStates->GetCurrectState().at(1));
357           aStates->IncrementState();
358         }
359         else if(aMethod == "SetMaxElementVolume" && aStates->GetCurrectState().size() >= 3) {
360           if(!aStates->GetCurrectState().at(2).IsEmpty() )
361             aCmd->SetArg(1,aStates->GetCurrectState().at(2));
362           aStates->IncrementState();
363         }
364         else if(aMethod == "LengthFromEdges" || aMethod == "LengthFromFaces"){
365           aStates->IncrementState();
366         }
367       }
368       
369       // Case for NumberOfLayers hypothesis
370       else if(aStates->GetObjectType().IsEqual("NumberOfLayers")){
371         if(aMethod == "SetNumberOfLayers" && aStates->GetCurrectState().size() >= 1) {
372           if(!aStates->GetCurrectState().at(0).IsEmpty() )
373             aCmd->SetArg(1,aStates->GetCurrectState().at(0));
374           aStates->IncrementState();
375         }
376       }
377
378       // Case for NumberOfSegments hypothesis
379       else if(aStates->GetObjectType().IsEqual("NumberOfSegments")){
380         if(aMethod == "SetNumberOfSegments" && aStates->GetCurrectState().size() >= 1) {
381           if(!aStates->GetCurrectState().at(0).IsEmpty() )
382             aCmd->SetArg(1,aStates->GetCurrectState().at(0));
383           if(aStates->GetCurrectState().size()==1)
384             aStates->IncrementState();
385         }
386         else if (aMethod == "SetScaleFactor" && aStates->GetCurrectState().size() >= 2) {
387           if(!aStates->GetCurrectState().at(1).IsEmpty() )
388             aCmd->SetArg(1,aStates->GetCurrectState().at(1));
389           aStates->IncrementState();
390         }
391       }
392       
393       else if(aStates->GetObjectType().IsEqual("Mesh")) {
394         TState aCurrentState = aStates->GetCurrectState();
395         int aCurrentStateSize = aCurrentState.size();
396         if(aMethod.IsEqual("Translate") ||
397            aMethod.IsEqual("TranslateMakeGroups") ||
398            aMethod.IsEqual("TranslateMakeMesh")) {
399           bool isVariableFound = false;
400           int anArgIndex = 0;
401           for(int i = 1, n = aCmd->GetNbArgs(); i <= n; i++) {
402             if(aCmd->GetArg(i).IsEqual("SMESH.PointStruct")) {
403               anArgIndex = i+1;
404               break;
405             }
406           }
407           if(anArgIndex > 0) {
408             if(aCurrentStateSize == 3) { // translation by dx, dy, dz
409               for(int j = 0; j < aCurrentStateSize; j++) {
410                 if(!aCurrentState.at(j).IsEmpty()) {
411                   isVariableFound = true;
412                   aCmd->SetArg(anArgIndex+j, aCurrentState.at(j));
413                 }
414               }
415             }
416             else if(aCurrentStateSize == 6) { // translation by x1, x2, y1, y2, z1, z2
417               isVariableFound = true;
418               for(int j = 0; j < 3; j++) {
419                 TCollection_AsciiString anArg = aCmd->GetArg(anArgIndex+j);
420                 TCollection_AsciiString aValue1 = aCurrentState.at(2*j), aValue2 = aCurrentState.at(2*j+1);
421                 bool aV1 = !aValue1.IsEmpty();
422                 bool aV2 = !aValue2.IsEmpty();
423                 double aValue, aCurrentValue = anArg.IsRealValue() ? anArg.RealValue() : 0;
424                 if(aV1 && !aV2) {
425                   if(!GetReal(aValue1, aValue))
426                     aValue = 0;
427                   aValue2 = TCollection_AsciiString( aValue + aCurrentValue );
428                 }
429                 else if(!aV1 && aV2) {
430                   if(!GetReal(aValue2, aValue))
431                     aValue = 0;
432                   aValue1 = TCollection_AsciiString( aValue - aCurrentValue );
433                 }
434                 else if(!aV1 && !aV2) {
435                   aValue1 = TCollection_AsciiString( 0 );
436                   aValue2 = TCollection_AsciiString( aCurrentValue );
437                 }
438                 aCmd->SetArg(anArgIndex+j, aValue1 + ", " + aValue2 );
439               }
440             }
441           }
442           if(isVariableFound) {
443             TCollection_AsciiString aDim;
444             if(aCurrentStateSize == 6)
445               aDim = "6";
446             aCmd->SetArg(anArgIndex - 1, TCollection_AsciiString(SMESH_2smeshpy::SmeshpyName())+".PointStructStr"+aDim);
447             aCmd->SetArg(anArgIndex - 2, TCollection_AsciiString(SMESH_2smeshpy::SmeshpyName())+".DirStructStr");
448           }
449           aStates->IncrementState();
450         }
451         else if(aMethod.IsEqual("Rotate") ||
452                 aMethod.IsEqual("RotateMakeGroups") ||
453                 aMethod.IsEqual("RotateMakeMesh") ||
454                 aMethod.IsEqual("RotationSweep") ||
455                 aMethod.IsEqual("RotationSweepMakeGroups") ||
456                 aMethod.IsEqual("Mirror") ||
457                 aMethod.IsEqual("MirrorMakeGroups")) {
458           bool isSubstitute = false;
459           int anArgIndex = 0;
460           for(int i = 1, n = aCmd->GetNbArgs(); i <= n; i++) {
461             if(aCmd->GetArg(i).IsEqual("SMESH.AxisStruct")) {
462               anArgIndex = i+1;
463               break;
464             }
465           }
466           if(anArgIndex > 0) {
467             for(int j = 0; j < aCurrentStateSize; j++) {
468               if(!aCurrentState.at(j).IsEmpty()) {
469                 if(j < 6) // 0-5 - axis struct, 6 - angle (rotation & sweep), 7-8 - nbSteps and tolerance (sweep)
470                   isSubstitute = true;
471                 aCmd->SetArg(anArgIndex+j, aCurrentState.at(j));
472               }
473             }
474           }
475           if(isSubstitute)
476             aCmd->SetArg(anArgIndex - 1, TCollection_AsciiString(SMESH_2smeshpy::SmeshpyName())+".AxisStructStr");
477           aStates->IncrementState();
478         }
479         else if(aMethod.IsEqual("AddNode") ||
480                 aMethod.IsEqual("MoveClosestNodeToPoint")) {
481           for(int j = 0; j < aCurrentStateSize; j++) {
482             if(!aCurrentState.at(j).IsEmpty())
483               aCmd->SetArg(j+1, aCurrentState.at(j));
484           }
485           aStates->IncrementState();
486         }
487         else if(aMethod.IsEqual("MoveNode")) {
488           for(int j = 0; j < aCurrentStateSize; j++) {
489             if(!aCurrentState.at(j).IsEmpty())
490               aCmd->SetArg(j+2, aCurrentState.at(j));
491           }
492           aStates->IncrementState();
493         }
494         else if(aMethod.IsEqual("ExtrusionSweep") ||
495                 aMethod.IsEqual("ExtrusionSweepMakeGroups")) {
496           bool isSubstitute = false;
497           int anArgIndex = 0;
498           for(int i = 1, n = aCmd->GetNbArgs(); i <= n; i++) {
499             if(aCmd->GetArg(i).IsEqual("SMESH.PointStruct")) {
500               anArgIndex = i+1;
501               break;
502             }
503           }
504           if(anArgIndex > 0) {
505             for(int j = 0; j < aCurrentStateSize; j++) {
506               if(!aCurrentState.at(j).IsEmpty()) {
507                 if(j < 3) // 0-2 - dir struct, 3 - number of steps
508                   isSubstitute = true;
509                 aCmd->SetArg(anArgIndex+j, aCurrentState.at(j));
510               }
511             }
512           }
513           if(isSubstitute) {
514             aCmd->SetArg(anArgIndex - 1, TCollection_AsciiString(SMESH_2smeshpy::SmeshpyName())+".PointStructStr");
515             aCmd->SetArg(anArgIndex - 2, TCollection_AsciiString(SMESH_2smeshpy::SmeshpyName())+".DirStructStr");
516           }
517           aStates->IncrementState();
518         }
519         else if(aMethod.IsEqual("ExtrusionAlongPath") ||
520                 aMethod.IsEqual("ExtrusionAlongPathMakeGroups") ||
521                 /* workaround for a bug in the command parsing algorithm */
522                 aCmd->GetString().Search("ExtrusionAlongPathMakeGroups") != -1) {
523           int aNbAngles = aCurrentStateSize-3; // State looks like "Angle1:...:AngleN:X:Y:Z"
524           bool isSubstitute = false;
525           int anArgIndex = 0;
526           for(int i = 1, n = aCmd->GetNbArgs(); i <= n; i++) {
527             if(aCmd->GetArg(i).IsEqual("SMESH.PointStruct")) {
528               anArgIndex = i-1-aNbAngles;
529               break;
530             }
531           }
532           if(anArgIndex > 0) {
533             int j = 0;
534             for(; j < aNbAngles; j++) {
535               if(!aCurrentState.at(j).IsEmpty()) {
536                 aCmd->SetArg(anArgIndex+j-1, aCurrentState.at(j));
537               }
538             }
539             for(; j < aNbAngles+3; j++) {
540               if(!aCurrentState.at(j).IsEmpty()) {
541                 isSubstitute = true;
542                 aCmd->SetArg(anArgIndex+j+2, aCurrentState.at(j));
543               }
544             }
545           }
546           if(isSubstitute)
547             aCmd->SetArg(anArgIndex + aNbAngles + 1,
548                          TCollection_AsciiString(SMESH_2smeshpy::SmeshpyName())+".PointStructStr");
549           aStates->IncrementState();
550         }
551         else if(aMethod.IsEqual("TriToQuad") ||
552                 aMethod.IsEqual("Concatenate") ||
553                 aMethod.IsEqual("ConcatenateWithGroups")) {
554           if(aCurrentStateSize && !aCurrentState.at(0).IsEmpty())
555             aCmd->SetArg(aCmd->GetNbArgs(), aCurrentState.at(0));
556           aStates->IncrementState();
557         }
558         else if(aMethod.IsEqual("Smooth") ||
559                 aMethod.IsEqual("SmoothParametric")) {
560           int anArgIndex = aCmd->GetNbArgs() - 2;
561           for(int j = 0; j < aCurrentStateSize; j++) {
562             if(!aCurrentState.at(j).IsEmpty())
563               aCmd->SetArg(anArgIndex+j, aCurrentState.at(j));
564           }
565           aStates->IncrementState();
566         }
567       }
568     }
569     if(MYDEBUG) {
570       cout<<"Command after: "<< aCmd->GetString()<<endl;
571     }
572   }
573   //  ProcessLayerDistribution();
574 }
575 //================================================================================
576 /*!
577  * \brief Private method
578  */
579 //================================================================================
580 void SMESH_NoteBook::InitObjectMap()
581 {
582   SMESH_Gen_i *aGen = SMESH_Gen_i::GetSMESHGen();
583   if(!aGen)
584     return;
585   
586   SALOMEDS::Study_ptr aStudy = aGen->GetCurrentStudy();
587   if(aStudy->_is_nil())
588     return;
589   
590   SALOMEDS::SObject_var aSO = aStudy->FindComponent(aGen->ComponentDataType());
591   if(CORBA::is_nil(aSO))
592     return;
593   
594   SALOMEDS::ChildIterator_var Itr = aStudy->NewChildIterator(aSO);
595   char* aParameters;
596   for(Itr->InitEx(true); Itr->More(); Itr->Next()) {
597     SALOMEDS::SObject_var aSObject = Itr->Value();
598     SALOMEDS::GenericAttribute_var anAttr;
599     if ( aSObject->FindAttribute(anAttr, "AttributeString")) {
600       aParameters = SALOMEDS::AttributeString::_narrow(anAttr)->Value();
601       SALOMEDS::ListOfListOfStrings_var aSections = aStudy->ParseVariables(aParameters);
602       if(MYDEBUG) {
603         cout<<"Entry : "<< aSObject->GetID()<<endl;
604         cout<<"aParameters : "<<aParameters<<endl;
605       }      
606       TCollection_AsciiString anObjType;
607       CORBA::Object_var anObject = SMESH_Gen_i::SObjectToObject(aSObject);
608       SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow(anObject);
609       if(!aHyp->_is_nil()) {
610         anObjType = TCollection_AsciiString(aHyp->GetName());
611       }
612       else if(SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow(anObject)) {
613         anObjType = TCollection_AsciiString("Mesh");
614       }
615       if(MYDEBUG)
616         cout<<"The object Type : "<<anObjType<<endl;
617       ObjectStates *aState = NULL;
618       if(anObjType == "LayerDistribution")
619         aState = new LayerDistributionStates();
620       else
621         aState = new  ObjectStates(anObjType);
622       
623       for(int i = 0; i < aSections->length(); i++) {
624         TState aVars;
625         SALOMEDS::ListOfStrings aListOfVars = aSections[i];
626         for(int j = 0;j<aListOfVars.length();j++) {
627           TCollection_AsciiString aVar(aListOfVars[j].in());
628           if(!aVar.IsEmpty() && aStudy->IsVariable(aVar.ToCString())) {
629             aVar.InsertBefore(1,"\"");
630             aVar.InsertAfter(aVar.Length(),"\"");
631           }
632           aVars.push_back(aVar);
633           if(MYDEBUG) {
634             cout<<"Variable: '"<<aVar<<"'"<<endl;
635           }
636         }
637         aState->AddState(aVars);
638       }
639       _objectMap.insert(pair<TCollection_AsciiString,ObjectStates*>(TCollection_AsciiString(aSObject->GetID()),aState));
640     }
641   }
642 }
643
644 //================================================================================
645 /*!
646  * 
647  */
648 //================================================================================
649 void SMESH_NoteBook::AddCommand(const TCollection_AsciiString& theString)
650 {
651   if(MYDEBUG)
652     cout<<theString<<endl;
653   Handle(_pyCommand) aCommand = new _pyCommand( theString, -1);
654   _commands.push_back(aCommand);
655
656   if ( aCommand->GetMethod() == "GetMeshEditor" ) { // MeshEditor creation
657     myMeshEditors.insert( make_pair( aCommand->GetResultValue(),
658                                      aCommand->GetObject() ) );
659   }
660 }
661
662 //================================================================================
663 /*!
664  * 
665  */
666 //================================================================================
667 void SMESH_NoteBook::ProcessLayerDistribution()
668 {
669   // 1) Find all LayerDistribution states
670   vector<LayerDistributionStates*> aLDS;
671   TVariablesMap::const_iterator it = _objectMap.begin();
672   for(;it != _objectMap.end();it++)
673     if(LayerDistributionStates* aLDStates = (LayerDistributionStates*)((*it).second)) {
674       aLDS.push_back(aLDStates);
675     }
676   
677   // 2) Initialize all type of 1D Distribution hypothesis
678   for(int i=0;i<_commands.size();i++){
679     for(int j =0;j < aLDS.size();j++){
680       TCollection_AsciiString aResultValue = _commands[i]->GetResultValue();
681       if(_commands[i]->GetMethod() == "CreateHypothesis" &&
682          aLDS[j]->HasDistribution(aResultValue)){
683         TCollection_AsciiString aType = _commands[i]->GetArg(1);
684         aType.RemoveAll('\'');
685         aLDS[j]->SetDistributionType(aResultValue,aType);
686       }
687     }
688   }
689   // 3) ... and replase variables ...
690
691   for(int i=0;i<_commands.size();i++){
692     for(int j =0;j < aLDS.size();j++){
693       TCollection_AsciiString anObject = _commands[i]->GetObject();
694
695       if(aLDS[j]->HasDistribution(anObject)) {
696         TCollection_AsciiString aType = aLDS[j]->GetDistributionType(anObject);
697         TCollection_AsciiString aMethod = _commands[i]->GetMethod();
698         if(aType == "LocalLength") {
699           if(aMethod == "SetLength") {
700             if(!aLDS[j]->GetCurrectState().at(0).IsEmpty() )
701               _commands[i]->SetArg(1,aLDS[j]->GetCurrectState().at(0));
702             aLDS[j]->IncrementState();
703           }
704           else if(aMethod == "SetPrecision") {
705             if(!aLDS[j]->GetCurrectState().at(1).IsEmpty() )
706               _commands[i]->SetArg(1,aLDS[j]->GetCurrectState().at(1));
707             aLDS[j]->IncrementState();
708           }
709         }
710       }
711     }
712   }
713 }
714 //================================================================================
715 /*!
716  *  \brief Return result script
717  */
718 //================================================================================
719 TCollection_AsciiString SMESH_NoteBook::GetResultScript() const
720 {
721   TCollection_AsciiString aResult;
722   for(int i=0;i<_commands.size();i++)
723     aResult+=_commands[i]->GetString()+"\n";
724   return aResult;
725 }
726
727 //================================================================================
728 /*!
729  *  \brief Return value of the variable
730  */
731 //================================================================================
732 bool SMESH_NoteBook::GetReal(const TCollection_AsciiString& theVarName, double& theValue)
733 {
734   bool ok = false;
735
736   SMESH_Gen_i *aGen = SMESH_Gen_i::GetSMESHGen();
737   if(!aGen)
738     return ok;
739
740   SALOMEDS::Study_ptr aStudy = aGen->GetCurrentStudy();
741   if(aStudy->_is_nil())
742     return ok;
743
744   TCollection_AsciiString aVarName = theVarName;
745   aVarName.RemoveAll('\"');
746
747   if(aVarName.IsEmpty())
748     return ok;
749
750   const char* aName = aVarName.ToCString();
751   if(aStudy->IsVariable(aName) && (aStudy->IsReal(aName) || aStudy->IsInteger(aName))) {
752     theValue = aStudy->GetReal(aVarName.ToCString());
753     ok = true;
754   }
755
756   return ok;
757 }