1 // Copyright (C) 2008 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // File : SMESH_NoteBook.cxx
21 // Author : Roman NIKOLAEV
23 #include "SMESH_2smeshpy.hxx"
24 #include "SMESH_NoteBook.hxx"
25 #include "SMESH_Gen_i.hxx"
26 #include "SMESH_PythonDump.hxx"
28 #include <Resource_DataMapOfAsciiStringAsciiString.hxx>
29 #include <TColStd_SequenceOfAsciiString.hxx>
30 #include <TColStd_HSequenceOfInteger.hxx>
36 static int MYDEBUG = 0;
38 static int MYDEBUG = 0;
44 void SetVariable(Handle(_pyCommand) theCommand,const ObjectStates* theStates, int position, int theArgNb);
46 //================================================================================
50 //================================================================================
51 ObjectStates::ObjectStates(TCollection_AsciiString theType)
57 //================================================================================
61 //================================================================================
62 ObjectStates::~ObjectStates()
66 //================================================================================
68 * \brief Add new object state
69 * \param theState - Object state (vector of notebook variable)
71 //================================================================================
72 void ObjectStates::AddState(const TState &theState)
74 _states.push_back(theState);
77 //================================================================================
79 * \brief Return current object state
80 * \\retval state - Object state (vector of notebook variable)
82 //================================================================================
83 TState ObjectStates::GetCurrectState() const
85 if(_states.size() > _dumpstate)
86 return _states[_dumpstate];
92 //================================================================================
96 //================================================================================
97 TAllStates ObjectStates::GetAllStates() const
102 //================================================================================
106 //================================================================================
107 void ObjectStates::IncrementState()
112 //================================================================================
116 //================================================================================
117 TCollection_AsciiString ObjectStates::GetObjectType() const{
122 //================================================================================
126 //================================================================================
127 LayerDistributionStates::LayerDistributionStates():
128 ObjectStates("LayerDistribution")
131 //================================================================================
135 //================================================================================
136 LayerDistributionStates::~LayerDistributionStates()
141 //================================================================================
143 * \brief AddDistribution
145 //================================================================================
146 void LayerDistributionStates::AddDistribution(const TCollection_AsciiString& theDistribution)
148 _distributions.insert(pair<TCollection_AsciiString,TCollection_AsciiString>(theDistribution,""));
151 //================================================================================
153 * \brief HasDistribution
155 //================================================================================
156 bool LayerDistributionStates::HasDistribution(const TCollection_AsciiString& theDistribution) const
158 return _distributions.find(theDistribution) != _distributions.end();
161 //================================================================================
163 * \brief SetDistributionType
165 //================================================================================
166 bool LayerDistributionStates::SetDistributionType(const TCollection_AsciiString& theDistribution,
167 const TCollection_AsciiString& theType)
169 TDistributionMap::iterator it = _distributions.find(theDistribution);
170 if(it == _distributions.end())
172 (*it).second = theType;
176 //================================================================================
178 * \brief GetDistributionType
180 //================================================================================
181 TCollection_AsciiString LayerDistributionStates::
182 GetDistributionType(const TCollection_AsciiString& theDistribution) const
184 TDistributionMap::const_iterator it = _distributions.find(theDistribution);
185 return (it == _distributions.end()) ? TCollection_AsciiString() : (*it).second;
188 //================================================================================
192 //================================================================================
193 SMESH_NoteBook::SMESH_NoteBook()
198 //================================================================================
202 //================================================================================
203 SMESH_NoteBook::~SMESH_NoteBook()
205 TVariablesMap::const_iterator it = _objectMap.begin();
206 for(;it!=_objectMap.end();it++) {
212 //================================================================================
214 * \brief Replace parameters of the functions on the Salome NoteBook Variables
215 * \param theString - Input string
216 * \retval TCollection_AsciiString - Convertion result
218 //================================================================================
219 void SMESH_NoteBook::ReplaceVariables()
221 for(int i=0;i<_commands.size();i++) {
222 Handle(_pyCommand) aCmd = _commands[i];
223 TCollection_AsciiString aMethod = aCmd->GetMethod();
224 TCollection_AsciiString aObject = aCmd->GetObject();
225 TCollection_AsciiString aResultValue = aCmd->GetResultValue();
227 cout<<"Command before : "<< aCmd->GetString()<<endl;
228 cout<<"Method : "<< aMethod<<endl;
229 cout<<"Object : "<< aObject<<endl;
230 cout<<"Result : "<< aResultValue<<endl;
233 // check if method modifies the object itself
234 TVariablesMap::const_iterator it = _objectMap.find(aObject);
235 if(it == _objectMap.end()) // check if method returns a new object
236 it = _objectMap.find(aResultValue);
238 if(it == _objectMap.end()) { // check if method modifies a mesh using mesh editor
239 TMeshEditorMap::const_iterator meIt = myMeshEditors.find(aObject);
240 if(meIt != myMeshEditors.end()) {
241 TCollection_AsciiString aMesh = (*meIt).second;
242 it = _objectMap.find(aMesh);
246 if(it != _objectMap.end()) {
247 ObjectStates *aStates = (*it).second;
248 // Case for LocalLength hypothesis
249 if(aStates->GetObjectType().IsEqual("LocalLength") && aStates->GetCurrectState().size() >= 2) {
250 if(aMethod.IsEqual("SetLength")) {
251 if(!aStates->GetCurrectState().at(0).IsEmpty() )
252 aCmd->SetArg(1,aStates->GetCurrectState().at(0));
253 aStates->IncrementState();
255 else if(aMethod.IsEqual("SetPrecision")) {
256 if(!aStates->GetCurrectState().at(1).IsEmpty() )
257 aCmd->SetArg(1,aStates->GetCurrectState().at(1));
258 aStates->IncrementState();
262 // Case for SegmentLengthAroundVertex hypothesis
263 else if(aStates->GetObjectType().IsEqual("SegmentLengthAroundVertex")
264 && aStates->GetCurrectState().size() >= 1) {
265 if(aMethod == "SetLength") {
266 if(!aStates->GetCurrectState().at(0).IsEmpty() )
267 aCmd->SetArg(1,aStates->GetCurrectState().at(0));
268 aStates->IncrementState();
272 // Case for Arithmetic1D and StartEndLength hypothesis
273 else if(aStates->GetObjectType().IsEqual("Arithmetic1D") ||
274 aStates->GetObjectType().IsEqual("StartEndLength")) {
275 if(aMethod == "SetLength" &&
276 aStates->GetCurrectState().size() >= 2) {
277 if(aCmd->GetArg(2) == "1" && !aStates->GetCurrectState().at(0).IsEmpty())
278 aCmd->SetArg(1,aStates->GetCurrectState().at(0));
279 else if(!aStates->GetCurrectState().at(1).IsEmpty())
280 aCmd->SetArg(1,aStates->GetCurrectState().at(1));
281 aStates->IncrementState();
285 //Case for Deflection1D hypothesis
286 else if(aStates->GetObjectType().IsEqual("Deflection1D")){
287 if(aMethod == "SetDeflection" && aStates->GetCurrectState().size() >= 1) {
288 if(!aStates->GetCurrectState().at(0).IsEmpty() )
289 aCmd->SetArg(1,aStates->GetCurrectState().at(0));
290 aStates->IncrementState();
294 // Case for LayerDistribution hypothesis (not finished yet)
295 else if(aStates->GetObjectType() == "LayerDistribution") {
296 if(aMethod == "SetLayerDistribution"){
297 LayerDistributionStates* aLDStates = (LayerDistributionStates*)(aStates);
298 aLDStates->AddDistribution(aCmd->GetArg(1));
300 cout<<"Add Distribution :"<<aCmd->GetArg(1)<<endl;
304 // Case for MaxElementArea hypothesis
305 else if(aStates->GetObjectType().IsEqual("MaxElementArea")){
306 if(aMethod == "SetMaxElementArea" && aStates->GetCurrectState().size() >= 1) {
307 if(!aStates->GetCurrectState().at(0).IsEmpty() )
308 aCmd->SetArg(1,aStates->GetCurrectState().at(0));
309 aStates->IncrementState();
313 // Case for MaxElementVolume hypothesis
314 else if(aStates->GetObjectType().IsEqual("MaxElementVolume")){
315 if(aMethod == "SetMaxElementVolume" && aStates->GetCurrectState().size() >= 1) {
316 if(!aStates->GetCurrectState().at(0).IsEmpty() )
317 aCmd->SetArg(1,aStates->GetCurrectState().at(0));
318 aStates->IncrementState();
322 // Case for NETGEN_Parameters_2D or NETGEN_Parameters_2D hypothesis
323 else if(aStates->GetObjectType().IsEqual("NETGEN_Parameters_2D") ||
324 aStates->GetObjectType().IsEqual("NETGEN_Parameters")){
325 if(aMethod == "SetMaxSize" && aStates->GetCurrectState().size() >= 1) {
326 if(!aStates->GetCurrectState().at(0).IsEmpty() )
327 aCmd->SetArg(1,aStates->GetCurrectState().at(0));
328 aStates->IncrementState();
330 else if(aMethod == "SetGrowthRate" && aStates->GetCurrectState().size() >= 2) {
331 if(!aStates->GetCurrectState().at(1).IsEmpty() )
332 aCmd->SetArg(1,aStates->GetCurrectState().at(1));
333 aStates->IncrementState();
335 else if(aMethod == "SetNbSegPerEdge" && aStates->GetCurrectState().size() >= 3) {
336 if(!aStates->GetCurrectState().at(2).IsEmpty() )
337 aCmd->SetArg(1,aStates->GetCurrectState().at(2));
338 aStates->IncrementState();
340 else if(aMethod == "SetNbSegPerRadius" && aStates->GetCurrectState().size() >= 4) {
341 if(!aStates->GetCurrectState().at(3).IsEmpty() )
342 aCmd->SetArg(1,aStates->GetCurrectState().at(3));
343 aStates->IncrementState();
347 // Case for NETGEN_SimpleParameters_3D or NETGEN_SimpleParameters_2D hypothesis
348 else if(aStates->GetObjectType().IsEqual("NETGEN_SimpleParameters_3D") ||
349 aStates->GetObjectType().IsEqual("NETGEN_SimpleParameters_2D")){
351 if((aMethod == "SetNumberOfSegments" || aMethod == "SetLocalLength") &&
352 aStates->GetCurrectState().size() >= 1) {
353 if(!aStates->GetCurrectState().at(0).IsEmpty() )
354 aCmd->SetArg(1,aStates->GetCurrectState().at(0));
355 aStates->IncrementState();
357 else if(aMethod == "SetMaxElementArea" && aStates->GetCurrectState().size() >= 2) {
358 if(!aStates->GetCurrectState().at(1).IsEmpty() )
359 aCmd->SetArg(1,aStates->GetCurrectState().at(1));
360 aStates->IncrementState();
362 else if(aMethod == "SetMaxElementVolume" && aStates->GetCurrectState().size() >= 3) {
363 if(!aStates->GetCurrectState().at(2).IsEmpty() )
364 aCmd->SetArg(1,aStates->GetCurrectState().at(2));
365 aStates->IncrementState();
367 else if(aMethod == "LengthFromEdges" || aMethod == "LengthFromFaces"){
368 aStates->IncrementState();
372 // Case for NumberOfLayers hypothesis
373 else if(aStates->GetObjectType().IsEqual("NumberOfLayers")){
374 if(aMethod == "SetNumberOfLayers" && aStates->GetCurrectState().size() >= 1) {
375 if(!aStates->GetCurrectState().at(0).IsEmpty() )
376 aCmd->SetArg(1,aStates->GetCurrectState().at(0));
377 aStates->IncrementState();
381 // Case for NumberOfSegments hypothesis
382 else if(aStates->GetObjectType().IsEqual("NumberOfSegments")){
383 if(aMethod == "SetNumberOfSegments" && aStates->GetCurrectState().size() >= 1) {
384 if(!aStates->GetCurrectState().at(0).IsEmpty() )
385 aCmd->SetArg(1,aStates->GetCurrectState().at(0));
386 if(aStates->GetCurrectState().size()==1)
387 aStates->IncrementState();
389 else if (aMethod == "SetScaleFactor" && aStates->GetCurrectState().size() >= 2) {
390 if(!aStates->GetCurrectState().at(1).IsEmpty() )
391 aCmd->SetArg(1,aStates->GetCurrectState().at(1));
392 aStates->IncrementState();
396 else if(aStates->GetObjectType().IsEqual("Mesh")) {
397 TState aCurrentState = aStates->GetCurrectState();
398 int aCurrentStateSize = aCurrentState.size();
399 if(aMethod.IsEqual("Translate") ||
400 aMethod.IsEqual("TranslateMakeGroups") ||
401 aMethod.IsEqual("TranslateMakeMesh")) {
402 bool isVariableFound = false;
404 for(int i = 1, n = aCmd->GetNbArgs(); i <= n; i++) {
405 if(aCmd->GetArg(i).IsEqual("SMESH.PointStruct")) {
411 if(aCurrentStateSize == 3) { // translation by dx, dy, dz
412 for(int j = 0; j < aCurrentStateSize; j++) {
413 if(!aCurrentState.at(j).IsEmpty()) {
414 isVariableFound = true;
415 aCmd->SetArg(anArgIndex+j, aCurrentState.at(j));
419 else if(aCurrentStateSize == 6) { // translation by x1, x2, y1, y2, z1, z2
420 // TODO: limitation until operations on the variables will be introduced
422 isVariableFound = true;
423 for(int j = 0; j < 3; j++) {
424 TCollection_AsciiString anArg = aCmd->GetArg(anArgIndex+j);
425 TCollection_AsciiString aValue1 = aCurrentState.at(2*j), aValue2 = aCurrentState.at(2*j+1);
426 bool aV1 = !aValue1.IsEmpty();
427 bool aV2 = !aValue2.IsEmpty();
428 double aValue, aCurrentValue = anArg.IsRealValue() ? anArg.RealValue() : 0;
430 if(!GetReal(aValue1, aValue))
432 aValue2 = TCollection_AsciiString( aValue + aCurrentValue );
434 else if(!aV1 && aV2) {
435 if(!GetReal(aValue2, aValue))
437 aValue1 = TCollection_AsciiString( aValue - aCurrentValue );
439 else if(!aV1 && !aV2) {
440 aValue1 = TCollection_AsciiString( 0 );
441 aValue2 = TCollection_AsciiString( aCurrentValue );
443 aCmd->SetArg(anArgIndex+j, aValue1 + ", " + aValue2 );
448 if(isVariableFound) {
449 TCollection_AsciiString aDim;
450 if(aCurrentStateSize == 6)
452 aCmd->SetArg(anArgIndex - 1, TCollection_AsciiString(SMESH_2smeshpy::SmeshpyName())+".PointStructStr"+aDim);
453 aCmd->SetArg(anArgIndex - 2, TCollection_AsciiString(SMESH_2smeshpy::SmeshpyName())+".DirStructStr");
455 aStates->IncrementState();
457 else if(aMethod.IsEqual("Rotate") ||
458 aMethod.IsEqual("RotateMakeGroups") ||
459 aMethod.IsEqual("RotateMakeMesh") ||
460 aMethod.IsEqual("RotationSweep") ||
461 aMethod.IsEqual("RotationSweepMakeGroups") ||
462 aMethod.IsEqual("Mirror") ||
463 aMethod.IsEqual("MirrorMakeGroups")) {
464 bool isSubstitute = false;
466 for(int i = 1, n = aCmd->GetNbArgs(); i <= n; i++) {
467 if(aCmd->GetArg(i).IsEqual("SMESH.AxisStruct")) {
473 for(int j = 0; j < aCurrentStateSize; j++) {
474 if(!aCurrentState.at(j).IsEmpty()) {
475 if(j < 6) // 0-5 - axis struct, 6 - angle (rotation & sweep), 7-8 - nbSteps and tolerance (sweep)
477 aCmd->SetArg(anArgIndex+j, aCurrentState.at(j));
482 aCmd->SetArg(anArgIndex - 1, TCollection_AsciiString(SMESH_2smeshpy::SmeshpyName())+".AxisStructStr");
483 aStates->IncrementState();
485 else if(aMethod.IsEqual("AddNode") ||
486 aMethod.IsEqual("MoveClosestNodeToPoint")) {
487 for(int j = 0; j < aCurrentStateSize; j++) {
488 if(!aCurrentState.at(j).IsEmpty())
489 aCmd->SetArg(j+1, aCurrentState.at(j));
491 aStates->IncrementState();
493 else if(aMethod.IsEqual("MoveNode")) {
494 for(int j = 0; j < aCurrentStateSize; j++) {
495 if(!aCurrentState.at(j).IsEmpty())
496 aCmd->SetArg(j+2, aCurrentState.at(j));
498 aStates->IncrementState();
500 else if(aMethod.IsEqual("ExtrusionSweep") ||
501 aMethod.IsEqual("ExtrusionSweepMakeGroups")) {
502 bool isSubstitute = false;
504 for(int i = 1, n = aCmd->GetNbArgs(); i <= n; i++) {
505 if(aCmd->GetArg(i).IsEqual("SMESH.PointStruct")) {
511 for(int j = 0; j < aCurrentStateSize; j++) {
512 if(!aCurrentState.at(j).IsEmpty()) {
513 if(j < 3) // 0-2 - dir struct, 3 - number of steps
515 aCmd->SetArg(anArgIndex+j, aCurrentState.at(j));
520 aCmd->SetArg(anArgIndex - 1, TCollection_AsciiString(SMESH_2smeshpy::SmeshpyName())+".PointStructStr");
521 aCmd->SetArg(anArgIndex - 2, TCollection_AsciiString(SMESH_2smeshpy::SmeshpyName())+".DirStructStr");
523 aStates->IncrementState();
525 else if(aMethod.IsEqual("ExtrusionAlongPath") ||
526 aMethod.IsEqual("ExtrusionAlongPathMakeGroups") ||
527 /* workaround for a bug in the command parsing algorithm */
528 aCmd->GetString().Search("ExtrusionAlongPathMakeGroups") != -1) {
529 int aNbAngles = aCurrentStateSize-3; // State looks like "Angle1:...:AngleN:X:Y:Z"
530 bool isSubstitute = false;
532 for(int i = 1, n = aCmd->GetNbArgs(); i <= n; i++) {
533 if(aCmd->GetArg(i).IsEqual("SMESH.PointStruct")) {
534 anArgIndex = i-1-aNbAngles;
540 for(; j < aNbAngles; j++) {
541 if(!aCurrentState.at(j).IsEmpty()) {
542 aCmd->SetArg(anArgIndex+j-1, aCurrentState.at(j));
545 for(; j < aNbAngles+3; j++) {
546 if(!aCurrentState.at(j).IsEmpty()) {
548 aCmd->SetArg(anArgIndex+j+2, aCurrentState.at(j));
553 aCmd->SetArg(anArgIndex + aNbAngles + 1,
554 TCollection_AsciiString(SMESH_2smeshpy::SmeshpyName())+".PointStructStr");
555 aStates->IncrementState();
557 else if(aMethod.IsEqual("TriToQuad") ||
558 aMethod.IsEqual("Concatenate") ||
559 aMethod.IsEqual("ConcatenateWithGroups")) {
560 if(aCurrentStateSize && !aCurrentState.at(0).IsEmpty())
561 aCmd->SetArg(aCmd->GetNbArgs(), aCurrentState.at(0));
562 aStates->IncrementState();
564 else if(aMethod.IsEqual("Smooth") ||
565 aMethod.IsEqual("SmoothParametric")) {
566 int anArgIndex = aCmd->GetNbArgs() - 2;
567 for(int j = 0; j < aCurrentStateSize; j++) {
568 if(!aCurrentState.at(j).IsEmpty())
569 aCmd->SetArg(anArgIndex+j, aCurrentState.at(j));
571 aStates->IncrementState();
576 cout<<"Command after: "<< aCmd->GetString()<<endl;
580 ProcessLayerDistribution();
582 //================================================================================
584 * \brief Private method
586 //================================================================================
587 void SMESH_NoteBook::InitObjectMap()
589 SMESH_Gen_i *aGen = SMESH_Gen_i::GetSMESHGen();
593 SALOMEDS::Study_ptr aStudy = aGen->GetCurrentStudy();
594 if(aStudy->_is_nil())
597 SALOMEDS::SObject_var aSO = aStudy->FindComponent(aGen->ComponentDataType());
598 if(CORBA::is_nil(aSO))
601 SALOMEDS::ChildIterator_var Itr = aStudy->NewChildIterator(aSO);
603 for(Itr->InitEx(true); Itr->More(); Itr->Next()) {
604 SALOMEDS::SObject_var aSObject = Itr->Value();
605 SALOMEDS::GenericAttribute_var anAttr;
606 if ( aSObject->FindAttribute(anAttr, "AttributeString")) {
607 aParameters = SALOMEDS::AttributeString::_narrow(anAttr)->Value();
608 SALOMEDS::ListOfListOfStrings_var aSections = aStudy->ParseVariables(aParameters);
610 cout<<"Entry : "<< aSObject->GetID()<<endl;
611 cout<<"aParameters : "<<aParameters<<endl;
613 TCollection_AsciiString anObjType;
614 CORBA::Object_var anObject = SMESH_Gen_i::SObjectToObject(aSObject);
615 SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow(anObject);
616 if(!aHyp->_is_nil()) {
617 anObjType = TCollection_AsciiString(aHyp->GetName());
619 else if(SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow(anObject)) {
620 anObjType = TCollection_AsciiString("Mesh");
623 cout<<"The object Type : "<<anObjType<<endl;
624 ObjectStates *aState = NULL;
625 if(anObjType == "LayerDistribution") {
626 aState = new LayerDistributionStates();
629 aState = new ObjectStates(anObjType);
631 for(int i = 0; i < aSections->length(); i++) {
633 SALOMEDS::ListOfStrings aListOfVars = aSections[i];
634 for(int j = 0;j<aListOfVars.length();j++) {
635 TCollection_AsciiString aVar(aListOfVars[j].in());
636 if(!aVar.IsEmpty() && aStudy->IsVariable(aVar.ToCString())) {
637 aVar.InsertBefore(1,"\"");
638 aVar.InsertAfter(aVar.Length(),"\"");
640 aVars.push_back(aVar);
642 cout<<"Variable: '"<<aVar<<"'"<<endl;
645 aState->AddState(aVars);
647 _objectMap.insert(pair<TCollection_AsciiString,ObjectStates*>(TCollection_AsciiString(aSObject->GetID()),aState));
652 //================================================================================
656 //================================================================================
657 void SMESH_NoteBook::AddCommand(const TCollection_AsciiString& theString)
660 cout<<theString<<endl;
661 Handle(_pyCommand) aCommand = new _pyCommand( theString, -1);
662 _commands.push_back(aCommand);
664 if ( aCommand->GetMethod() == "GetMeshEditor" ) { // MeshEditor creation
665 myMeshEditors.insert( make_pair( aCommand->GetResultValue(),
666 aCommand->GetObject() ) );
670 //================================================================================
674 //================================================================================
675 void SMESH_NoteBook::ProcessLayerDistribution()
677 // 1) Find all LayerDistribution states
678 vector<LayerDistributionStates*> aLDS;
679 TVariablesMap::const_iterator it = _objectMap.begin();
680 for(;it != _objectMap.end();it++) {
681 LayerDistributionStates* aLDStates = dynamic_cast<LayerDistributionStates*>(((*it).second));
682 if(aLDStates!=NULL) {
683 aLDS.push_back(aLDStates);
690 // 2) Initialize all type of 1D Distribution hypothesis
691 for(int i=0;i<_commands.size();i++){
692 for(int j =0;j < aLDS.size();j++){
693 TCollection_AsciiString aResultValue = _commands[i]->GetResultValue();
694 if(_commands[i]->GetMethod() == "CreateHypothesis" &&
695 aLDS[j]->HasDistribution(aResultValue)){
696 TCollection_AsciiString aType = _commands[i]->GetArg(1);
697 aType.RemoveAll('\'');
698 aLDS[j]->SetDistributionType(aResultValue,aType);
702 // 3) ... and replase variables ...
704 for(int i=0;i<_commands.size();i++){
705 for(int j =0;j < aLDS.size();j++){
706 TCollection_AsciiString anObject = _commands[i]->GetObject();
708 if(aLDS[j]->HasDistribution(anObject)) {
709 TCollection_AsciiString aType = aLDS[j]->GetDistributionType(anObject);
710 TCollection_AsciiString aMethod = _commands[i]->GetMethod();
711 if(aType == "LocalLength") {
712 if(aMethod == "SetLength") {
713 SetVariable(_commands[i], aLDS[j],0,1);
714 aLDS[j]->IncrementState();
716 else if(aMethod == "SetPrecision") {
717 SetVariable(_commands[i], aLDS[j],1,1);
718 aLDS[j]->IncrementState();
722 // Case for NumberOfSegments hypothesis
723 else if(aType == "NumberOfSegments"){
724 if(aMethod == "SetNumberOfSegments") {
725 SetVariable(_commands[i], aLDS[j],0,1);
726 if(aLDS[j]->GetCurrectState().size()==1)
727 aLDS[j]->IncrementState();
729 else if (aMethod == "SetScaleFactor") {
730 SetVariable(_commands[i], aLDS[j],1,1);
731 aLDS[j]->IncrementState();
735 else if( aType == "Deflection1D" ){
736 if(aMethod == "SetDeflection"){
737 SetVariable(_commands[i], aLDS[j],0,1);
738 aLDS[j]->IncrementState();
741 // Case for Arithmetic1D and StartEndLength hypothesis
742 else if(aType == "Arithmetic1D" || aType == "StartEndLength") {
743 if(aMethod == "SetLength") {
744 int anArgNb = (_commands[i]->GetArg(2) == "1") ? 0 : 1;
745 SetVariable(_commands[i], aLDS[j],anArgNb,1);
746 aLDS[j]->IncrementState();
753 //================================================================================
755 * \brief Return result script
757 //================================================================================
758 TCollection_AsciiString SMESH_NoteBook::GetResultScript() const
760 TCollection_AsciiString aResult;
761 for(int i=0;i<_commands.size();i++)
762 aResult+=_commands[i]->GetString()+"\n";
766 //================================================================================
768 * \brief Return value of the variable
770 //================================================================================
771 bool SMESH_NoteBook::GetReal(const TCollection_AsciiString& theVarName, double& theValue)
775 SMESH_Gen_i *aGen = SMESH_Gen_i::GetSMESHGen();
779 SALOMEDS::Study_ptr aStudy = aGen->GetCurrentStudy();
780 if(aStudy->_is_nil())
783 TCollection_AsciiString aVarName = theVarName;
784 aVarName.RemoveAll('\"');
786 if(aVarName.IsEmpty())
789 const char* aName = aVarName.ToCString();
790 if(aStudy->IsVariable(aName) && (aStudy->IsReal(aName) || aStudy->IsInteger(aName))) {
791 theValue = aStudy->GetReal(aVarName.ToCString());
800 * Set variable of the ObjectStates from position to the _pyCommand
801 * method as nbArg argument
803 void SetVariable(Handle(_pyCommand) theCommand, const ObjectStates* theStates, int position, int theArgNb)
805 if(theStates->GetCurrectState().size() > position)
806 if(!theStates->GetCurrectState().at(position).IsEmpty())
807 theCommand->SetArg(theArgNb,theStates->GetCurrectState().at(position));