1 // Copyright (C) 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // 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"
27 #include "SMESH_Hypothesis_i.hxx"
29 #include <Resource_DataMapOfAsciiStringAsciiString.hxx>
30 #include <TColStd_SequenceOfAsciiString.hxx>
31 #include <TColStd_HSequenceOfInteger.hxx>
37 static int MYDEBUG = 0;
39 static int MYDEBUG = 0;
48 * Set variable of the SMESH_ObjectStates from position to the _pyCommand
49 * method as nbArg argument
51 void SetVariable(Handle(_pyCommand) theCommand,
52 const SMESH_ObjectStates* theStates,
53 int position, int theArgNb)
55 if(theStates->GetCurrectState().size() > position)
56 if(!theStates->GetCurrectState().at(position).IsEmpty())
57 theCommand->SetArg(theArgNb,theStates->GetCurrectState().at(position));
61 //================================================================================
65 //================================================================================
66 SMESH_ObjectStates::SMESH_ObjectStates(TCollection_AsciiString theType)
72 //================================================================================
76 //================================================================================
77 SMESH_ObjectStates::~SMESH_ObjectStates()
81 //================================================================================
83 * \brief Add new object state
84 * \param theState - Object state (vector of notebook variable)
86 //================================================================================
87 void SMESH_ObjectStates::AddState(const TState &theState)
89 _states.push_back(theState);
92 //================================================================================
94 * \brief Return current object state
95 * \\retval state - Object state (vector of notebook variable)
97 //================================================================================
98 TState SMESH_ObjectStates::GetCurrectState() const
100 if(_states.size() > _dumpstate)
101 return _states[_dumpstate];
107 //================================================================================
111 //================================================================================
112 TAllStates SMESH_ObjectStates::GetAllStates() const
117 //================================================================================
121 //================================================================================
122 void SMESH_ObjectStates::IncrementState()
127 //================================================================================
131 //================================================================================
132 TCollection_AsciiString SMESH_ObjectStates::GetObjectType() const{
137 //================================================================================
141 //================================================================================
142 LayerDistributionStates::LayerDistributionStates():
143 SMESH_ObjectStates("LayerDistribution")
146 //================================================================================
150 //================================================================================
151 LayerDistributionStates::~LayerDistributionStates()
156 //================================================================================
158 * \brief AddDistribution
160 //================================================================================
161 void LayerDistributionStates::AddDistribution(const TCollection_AsciiString& theDistribution)
163 _distributions.insert(pair<TCollection_AsciiString,TCollection_AsciiString>(theDistribution,""));
166 //================================================================================
168 * \brief HasDistribution
170 //================================================================================
171 bool LayerDistributionStates::HasDistribution(const TCollection_AsciiString& theDistribution) const
173 return _distributions.find(theDistribution) != _distributions.end();
176 //================================================================================
178 * \brief SetDistributionType
180 //================================================================================
181 bool LayerDistributionStates::SetDistributionType(const TCollection_AsciiString& theDistribution,
182 const TCollection_AsciiString& theType)
184 TDistributionMap::iterator it = _distributions.find(theDistribution);
185 if(it == _distributions.end())
187 (*it).second = theType;
191 //================================================================================
193 * \brief GetDistributionType
195 //================================================================================
196 TCollection_AsciiString LayerDistributionStates::
197 GetDistributionType(const TCollection_AsciiString& theDistribution) const
199 TDistributionMap::const_iterator it = _distributions.find(theDistribution);
200 return (it == _distributions.end()) ? TCollection_AsciiString() : (*it).second;
203 //================================================================================
207 //================================================================================
208 SMESH_NoteBook::SMESH_NoteBook()
213 //================================================================================
217 //================================================================================
218 SMESH_NoteBook::~SMESH_NoteBook()
220 TVariablesMap::const_iterator it = _objectMap.begin();
221 for(;it!=_objectMap.end();it++) {
227 //================================================================================
229 * \brief Replace parameters of the functions on the Salome NoteBook Variables
230 * \param theString - Input string
231 * \retval TCollection_AsciiString - Convertion result
233 //================================================================================
234 void SMESH_NoteBook::ReplaceVariables()
236 for(int i=0;i<_commands.size();i++) {
237 Handle(_pyCommand) aCmd = _commands[i];
238 TCollection_AsciiString aMethod = aCmd->GetMethod();
239 TCollection_AsciiString aObject = aCmd->GetObject();
240 TCollection_AsciiString aResultValue = aCmd->GetResultValue();
242 cout<<"Command before : "<< aCmd->GetString()<<endl;
243 cout<<"Method : "<< aMethod<<endl;
244 cout<<"Object : "<< aObject<<endl;
245 cout<<"Result : "<< aResultValue<<endl;
248 // check if method modifies the object itself
249 TVariablesMap::const_iterator it = _objectMap.find(aObject);
250 if(it == _objectMap.end()) // check if method returns a new object
251 it = _objectMap.find(aResultValue);
253 if(it == _objectMap.end()) { // check if method modifies a mesh using mesh editor
254 TMeshEditorMap::const_iterator meIt = myMeshEditors.find(aObject);
255 if(meIt != myMeshEditors.end()) {
256 TCollection_AsciiString aMesh = (*meIt).second;
257 it = _objectMap.find(aMesh);
261 if(it == _objectMap.end()) { // additional check for pattern mapping
262 if(aMethod.IsEqual("ApplyToMeshFaces") ||
263 aMethod.IsEqual("ApplyToHexahedrons"))
264 it = _objectMap.find(aCmd->GetArg(1));
267 if(it != _objectMap.end()) {
269 cout << "Found object : " << (*it).first << endl;
270 SMESH_ObjectStates *aStates = (*it).second;
271 // Case for LocalLength hypothesis
272 if(aStates->GetObjectType().IsEqual("LocalLength") && aStates->GetCurrectState().size() >= 2)
274 if(aMethod.IsEqual("SetLength")) {
275 if(!aStates->GetCurrectState().at(0).IsEmpty() )
276 aCmd->SetArg(1,aStates->GetCurrectState().at(0));
277 aStates->IncrementState();
279 else if(aMethod.IsEqual("SetPrecision")) {
280 if(!aStates->GetCurrectState().at(1).IsEmpty() )
281 aCmd->SetArg(1,aStates->GetCurrectState().at(1));
282 aStates->IncrementState();
286 // Case for SegmentLengthAroundVertex hypothesis
287 else if(aStates->GetObjectType().IsEqual("SegmentLengthAroundVertex")
288 && aStates->GetCurrectState().size() >= 1) {
289 if(aMethod == "SetLength") {
290 if(!aStates->GetCurrectState().at(0).IsEmpty() )
291 aCmd->SetArg(1,aStates->GetCurrectState().at(0));
292 aStates->IncrementState();
296 // Case for Arithmetic1D and StartEndLength hypothesis
297 else if(aStates->GetObjectType().IsEqual("Arithmetic1D") ||
298 aStates->GetObjectType().IsEqual("StartEndLength")) {
299 if(aMethod == "SetLength" &&
300 aStates->GetCurrectState().size() >= 2) {
301 if(aCmd->GetArg(2) == "1" && !aStates->GetCurrectState().at(0).IsEmpty())
302 aCmd->SetArg(1,aStates->GetCurrectState().at(0));
303 else if(!aStates->GetCurrectState().at(1).IsEmpty())
304 aCmd->SetArg(1,aStates->GetCurrectState().at(1));
305 aStates->IncrementState();
309 //Case for Deflection1D hypothesis
310 else if(aStates->GetObjectType().IsEqual("Deflection1D")){
311 if(aMethod == "SetDeflection" && aStates->GetCurrectState().size() >= 1) {
312 if(!aStates->GetCurrectState().at(0).IsEmpty() )
313 aCmd->SetArg(1,aStates->GetCurrectState().at(0));
314 aStates->IncrementState();
318 // Case for LayerDistribution hypothesis (not finished yet)
319 else if(aStates->GetObjectType() == "LayerDistribution") {
320 if(aMethod == "SetLayerDistribution"){
321 LayerDistributionStates* aLDStates = (LayerDistributionStates*)(aStates);
322 aLDStates->AddDistribution(aCmd->GetArg(1));
324 cout<<"Add Distribution :"<<aCmd->GetArg(1)<<endl;
328 // Case for MaxElementArea hypothesis
329 else if(aStates->GetObjectType().IsEqual("MaxElementArea")){
330 if(aMethod == "SetMaxElementArea" && aStates->GetCurrectState().size() >= 1) {
331 if(!aStates->GetCurrectState().at(0).IsEmpty() )
332 aCmd->SetArg(1,aStates->GetCurrectState().at(0));
333 aStates->IncrementState();
337 // Case for MaxElementVolume hypothesis
338 else if(aStates->GetObjectType().IsEqual("MaxElementVolume")){
339 if(aMethod == "SetMaxElementVolume" && aStates->GetCurrectState().size() >= 1) {
340 if(!aStates->GetCurrectState().at(0).IsEmpty() )
341 aCmd->SetArg(1,aStates->GetCurrectState().at(0));
342 aStates->IncrementState();
345 // Case for NumberOfLayers hypothesis
346 else if(aStates->GetObjectType().IsEqual("NumberOfLayers")){
347 if(aMethod == "SetNumberOfLayers" && aStates->GetCurrectState().size() >= 1) {
348 if(!aStates->GetCurrectState().at(0).IsEmpty() )
349 aCmd->SetArg(1,aStates->GetCurrectState().at(0));
350 aStates->IncrementState();
354 // Case for NumberOfSegments hypothesis
355 else if(aStates->GetObjectType().IsEqual("NumberOfSegments")){
356 if(aMethod == "SetNumberOfSegments" && aStates->GetCurrectState().size() >= 1) {
357 if(!aStates->GetCurrectState().at(0).IsEmpty() )
358 aCmd->SetArg(1,aStates->GetCurrectState().at(0));
359 if(aStates->GetCurrectState().size()==1)
360 aStates->IncrementState();
362 else if (aMethod == "SetScaleFactor" && aStates->GetCurrectState().size() >= 2) {
363 if(!aStates->GetCurrectState().at(1).IsEmpty() )
364 aCmd->SetArg(1,aStates->GetCurrectState().at(1));
365 aStates->IncrementState();
369 else if(aStates->GetObjectType().IsEqual("Mesh")) {
370 TState aCurrentState = aStates->GetCurrectState();
371 int aCurrentStateSize = aCurrentState.size();
372 if(aMethod.IsEqual("Translate") ||
373 aMethod.IsEqual("TranslateMakeGroups") ||
374 aMethod.IsEqual("TranslateMakeMesh") ||
375 aMethod.IsEqual("TranslateObject") ||
376 aMethod.IsEqual("TranslateObjectMakeGroups") ||
377 aMethod.IsEqual("TranslateObjectMakeMesh")) {
378 bool isVariableFound = false;
380 for(int i = 1, n = aCmd->GetNbArgs(); i <= n; i++) {
381 if(aCmd->GetArg(i).IsEqual("SMESH.PointStruct")) {
387 if(aCurrentStateSize == 3) { // translation by dx, dy, dz
388 for(int j = 0; j < aCurrentStateSize; j++) {
389 if(!aCurrentState.at(j).IsEmpty()) {
390 isVariableFound = true;
391 aCmd->SetArg(anArgIndex+j, aCurrentState.at(j));
395 else if(aCurrentStateSize == 6) { // translation by x1, x2, y1, y2, z1, z2
396 // TODO: limitation until operations on the variables will be introduced
398 isVariableFound = true;
399 for(int j = 0; j < 3; j++) {
400 TCollection_AsciiString anArg = aCmd->GetArg(anArgIndex+j);
401 TCollection_AsciiString aValue1 = aCurrentState.at(2*j), aValue2 = aCurrentState.at(2*j+1);
402 bool aV1 = !aValue1.IsEmpty();
403 bool aV2 = !aValue2.IsEmpty();
404 double aValue, aCurrentValue = anArg.IsRealValue() ? anArg.RealValue() : 0;
406 if(!GetReal(aValue1, aValue))
408 aValue2 = TCollection_AsciiString( aValue + aCurrentValue );
410 else if(!aV1 && aV2) {
411 if(!GetReal(aValue2, aValue))
413 aValue1 = TCollection_AsciiString( aValue - aCurrentValue );
415 else if(!aV1 && !aV2) {
416 aValue1 = TCollection_AsciiString( 0 );
417 aValue2 = TCollection_AsciiString( aCurrentValue );
419 aCmd->SetArg(anArgIndex+j, aValue1 + ", " + aValue2 );
424 if(isVariableFound) {
425 TCollection_AsciiString aDim;
426 if(aCurrentStateSize == 6)
428 aCmd->SetArg(anArgIndex - 1, TCollection_AsciiString(SMESH_2smeshpy::SmeshpyName())+".PointStructStr"+aDim);
429 aCmd->SetArg(anArgIndex - 2, TCollection_AsciiString(SMESH_2smeshpy::SmeshpyName())+".DirStructStr");
431 aStates->IncrementState();
433 else if(aMethod.IsEqual("Rotate") ||
434 aMethod.IsEqual("RotateMakeGroups") ||
435 aMethod.IsEqual("RotateMakeMesh") ||
436 aMethod.IsEqual("RotateObject") ||
437 aMethod.IsEqual("RotateObjectMakeGroups") ||
438 aMethod.IsEqual("RotateObjectMakeMesh") ||
439 aMethod.IsEqual("RotationSweep") ||
440 aMethod.IsEqual("RotationSweepObject") ||
441 aMethod.IsEqual("RotationSweepObject1D") ||
442 aMethod.IsEqual("RotationSweepObject2D") ||
443 aMethod.IsEqual("RotationSweepMakeGroups") ||
444 aMethod.IsEqual("RotationSweepObjectMakeGroups") ||
445 aMethod.IsEqual("RotationSweepObject1DMakeGroups") ||
446 aMethod.IsEqual("RotationSweepObject2DMakeGroups") ||
447 aMethod.IsEqual("Mirror") ||
448 aMethod.IsEqual("MirrorMakeMesh") ||
449 aMethod.IsEqual("MirrorMakeGroups") ||
450 aMethod.IsEqual("MirrorObject") ||
451 aMethod.IsEqual("MirrorObjectMakeMesh") ||
452 aMethod.IsEqual("MirrorObjectMakeGroups")) {
453 bool isSubstitute = false;
455 for(int i = 1, n = aCmd->GetNbArgs(); i <= n; i++) {
456 if(aCmd->GetArg(i).IsEqual("SMESH.AxisStruct")) {
462 for(int j = 0; j < aCurrentStateSize; j++) {
463 if(!aCurrentState.at(j).IsEmpty()) {
464 if(j < 6) // 0-5 - axis struct, 6 - angle (rotation & sweep), 7-8 - nbSteps and tolerance (sweep)
466 aCmd->SetArg(anArgIndex+j, aCurrentState.at(j));
471 aCmd->SetArg(anArgIndex - 1, TCollection_AsciiString(SMESH_2smeshpy::SmeshpyName())+".AxisStructStr");
472 aStates->IncrementState();
474 else if(aMethod.IsEqual("AddNode") ||
475 aMethod.IsEqual("MoveClosestNodeToPoint")) {
476 for(int j = 0; j < aCurrentStateSize; j++) {
477 if(!aCurrentState.at(j).IsEmpty())
478 aCmd->SetArg(j+1, aCurrentState.at(j));
480 aStates->IncrementState();
482 else if(aMethod.IsEqual("MoveNode")) {
483 for(int j = 0; j < aCurrentStateSize; j++) {
484 if(!aCurrentState.at(j).IsEmpty())
485 aCmd->SetArg(j+2, aCurrentState.at(j));
487 aStates->IncrementState();
489 else if(aMethod.IsEqual("ExtrusionSweep") ||
490 aMethod.IsEqual("ExtrusionSweepObject") ||
491 aMethod.IsEqual("ExtrusionSweepObject1D") ||
492 aMethod.IsEqual("ExtrusionSweepObject2D") ||
493 aMethod.IsEqual("ExtrusionSweepMakeGroups") ||
494 aMethod.IsEqual("ExtrusionSweepObjectMakeGroups") ||
495 aMethod.IsEqual("ExtrusionSweepObject1DMakeGroups") ||
496 aMethod.IsEqual("ExtrusionSweepObject2DMakeGroups")) {
497 bool isSubstitute = false;
499 for(int i = 1, n = aCmd->GetNbArgs(); i <= n; i++) {
500 if(aCmd->GetArg(i).IsEqual("SMESH.PointStruct")) {
506 for(int j = 0; j < aCurrentStateSize; j++) {
507 if(!aCurrentState.at(j).IsEmpty()) {
508 if(j < 3) // 0-2 - dir struct, 3 - number of steps
510 aCmd->SetArg(anArgIndex+j, aCurrentState.at(j));
515 aCmd->SetArg(anArgIndex - 1, TCollection_AsciiString(SMESH_2smeshpy::SmeshpyName())+".PointStructStr");
516 aCmd->SetArg(anArgIndex - 2, TCollection_AsciiString(SMESH_2smeshpy::SmeshpyName())+".DirStructStr");
518 aStates->IncrementState();
520 else if(aMethod.IsEqual("ExtrusionAlongPath") ||
521 aMethod.IsEqual("ExtrusionAlongPathObject") ||
522 aMethod.IsEqual("ExtrusionAlongPathObject1D") ||
523 aMethod.IsEqual("ExtrusionAlongPathObject2D") ||
524 aMethod.IsEqual("ExtrusionAlongPathMakeGroups") ||
525 aMethod.IsEqual("ExtrusionAlongPathObjectMakeGroups") ||
526 aMethod.IsEqual("ExtrusionAlongPathObject1DMakeGroups") ||
527 aMethod.IsEqual("ExtrusionAlongPathObject2DMakeGroups") ||
528 /* workaround for a bug in the command parsing algorithm */
529 aCmd->GetString().Search("ExtrusionAlongPathMakeGroups") != -1 ||
530 aCmd->GetString().Search("ExtrusionAlongPathObjectMakeGroups") != -1 ||
531 aCmd->GetString().Search("ExtrusionAlongPathObject1DMakeGroups") != -1 ||
532 aCmd->GetString().Search("ExtrusionAlongPathObject2DMakeGroups") != -1 ) {
533 int aNbAngles = aCurrentStateSize-3; // State looks like "Angle1:...:AngleN:X:Y:Z"
534 bool isSubstitute = false;
536 for(int i = 1, n = aCmd->GetNbArgs(); i <= n; i++) {
537 if(aCmd->GetArg(i).IsEqual("SMESH.PointStruct")) {
538 anArgIndex = i-1-aNbAngles;
544 for(; j < aNbAngles; j++) {
545 if(!aCurrentState.at(j).IsEmpty()) {
546 aCmd->SetArg(anArgIndex+j-1, aCurrentState.at(j));
549 for(; j < aNbAngles+3; j++) {
550 if(!aCurrentState.at(j).IsEmpty()) {
552 aCmd->SetArg(anArgIndex+j+2, aCurrentState.at(j));
557 aCmd->SetArg(anArgIndex + aNbAngles + 1,
558 TCollection_AsciiString(SMESH_2smeshpy::SmeshpyName())+".PointStructStr");
559 aStates->IncrementState();
561 else if(aMethod.IsEqual("TriToQuad") ||
562 aMethod.IsEqual("Concatenate") ||
563 aMethod.IsEqual("ConcatenateWithGroups")) {
564 if(aCurrentStateSize && !aCurrentState.at(0).IsEmpty())
565 aCmd->SetArg(aCmd->GetNbArgs(), aCurrentState.at(0));
566 aStates->IncrementState();
568 else if(aMethod.IsEqual("Smooth") ||
569 aMethod.IsEqual("SmoothObject") ||
570 aMethod.IsEqual("SmoothParametric") ||
571 aMethod.IsEqual("SmoothParametricObject")) {
572 int anArgIndex = aCmd->GetNbArgs() - 2;
573 for(int j = 0; j < aCurrentStateSize; j++) {
574 if(!aCurrentState.at(j).IsEmpty())
575 aCmd->SetArg(anArgIndex+j, aCurrentState.at(j));
577 aStates->IncrementState();
579 else if(aMethod.IsEqual("ApplyToMeshFaces") ||
580 aMethod.IsEqual("ApplyToHexahedrons")) {
581 int anArgIndex = aCmd->GetNbArgs()-1;
582 for(int j = 0; j < aCurrentStateSize; j++)
583 if(!aCurrentState.at(j).IsEmpty())
584 aCmd->SetArg(anArgIndex+j, aCurrentState.at(j));
585 aStates->IncrementState();
587 } // if ( aStates->GetObjectType().IsEqual("Mesh"))
589 // Case for NETGEN_Parameters_2D or NETGEN_Parameters_2D hypothesis
590 // else if(aStates->GetObjectType().IsEqual("NETGEN_Parameters_2D") ||
591 // aStates->GetObjectType().IsEqual("NETGEN_Parameters")){
592 // if(aMethod == "SetMaxSize" && aStates->GetCurrectState().size() >= 1) {
593 // if(!aStates->GetCurrectState().at(0).IsEmpty() )
594 // aCmd->SetArg(1,aStates->GetCurrectState().at(0));
595 // aStates->IncrementState();
597 // else if(aMethod == "SetGrowthRate" && aStates->GetCurrectState().size() >= 2) {
598 // if(!aStates->GetCurrectState().at(1).IsEmpty() )
599 // aCmd->SetArg(1,aStates->GetCurrectState().at(1));
600 // aStates->IncrementState();
602 // else if(aMethod == "SetNbSegPerEdge" && aStates->GetCurrectState().size() >= 3) {
603 // if(!aStates->GetCurrectState().at(2).IsEmpty() )
604 // aCmd->SetArg(1,aStates->GetCurrectState().at(2));
605 // aStates->IncrementState();
607 // else if(aMethod == "SetNbSegPerRadius" && aStates->GetCurrectState().size() >= 4) {
608 // if(!aStates->GetCurrectState().at(3).IsEmpty() )
609 // aCmd->SetArg(1,aStates->GetCurrectState().at(3));
610 // aStates->IncrementState();
614 // // Case for NETGEN_SimpleParameters_3D or NETGEN_SimpleParameters_2D hypothesis
615 // else if(aStates->GetObjectType().IsEqual("NETGEN_SimpleParameters_3D") ||
616 // aStates->GetObjectType().IsEqual("NETGEN_SimpleParameters_2D")) {
618 // if((aMethod == "SetNumberOfSegments" || aMethod == "SetLocalLength") &&
619 // aStates->GetCurrectState().size() >= 1) {
620 // if(!aStates->GetCurrectState().at(0).IsEmpty() )
621 // aCmd->SetArg(1,aStates->GetCurrectState().at(0));
622 // aStates->IncrementState();
624 // else if(aMethod == "SetMaxElementArea" && aStates->GetCurrectState().size() >= 2) {
625 // if(!aStates->GetCurrectState().at(1).IsEmpty() )
626 // aCmd->SetArg(1,aStates->GetCurrectState().at(1));
627 // aStates->IncrementState();
629 // else if(aMethod == "SetMaxElementVolume" && aStates->GetCurrectState().size() >= 3) {
630 // if(!aStates->GetCurrectState().at(2).IsEmpty() )
631 // aCmd->SetArg(1,aStates->GetCurrectState().at(2));
632 // aStates->IncrementState();
634 // else if(aMethod == "LengthFromEdges" || aMethod == "LengthFromFaces"){
635 // aStates->IncrementState();
641 // treat Netgen hypotheses;
642 // this (and above) code can work wrong since nb of states can differ from nb of
643 // dumped calls due to the fix of
644 // issue 0021364:: Dump of netgen parameters has duplicate lines
645 SMESH_Gen_i *aGen = SMESH_Gen_i::GetSMESHGen();
646 SALOMEDS::Study_ptr aStudy = aGen->GetCurrentStudy();
647 SALOMEDS::SObject_var sobj = aStudy->FindObjectID( (*it).first.ToCString() );
648 CORBA::Object_var obj = aGen->SObjectToObject( sobj );
649 if ( SMESH_Hypothesis_i* h = SMESH::DownCast< SMESH_Hypothesis_i*>( obj ))
651 TState aCurrentState = aStates->GetCurrectState();
652 int argIndex = h->getParamIndex( aMethod, aCurrentState.size() );
653 if ( 0 <= argIndex && argIndex < aCurrentState.size() &&
654 !aCurrentState[argIndex].IsEmpty() )
655 aCmd->SetArg( 1, aCurrentState[argIndex] );
658 aStates->IncrementState();
664 cout << "Object not found" << endl;
667 cout<<"Command after: "<< aCmd->GetString()<<endl;
671 ProcessLayerDistribution();
673 //================================================================================
675 * \brief Private method
677 //================================================================================
678 void SMESH_NoteBook::InitObjectMap()
680 SMESH_Gen_i *aGen = SMESH_Gen_i::GetSMESHGen();
684 SALOMEDS::Study_ptr aStudy = aGen->GetCurrentStudy();
685 if(aStudy->_is_nil())
688 SALOMEDS::SObject_var aSO = aStudy->FindComponent(aGen->ComponentDataType());
689 if(CORBA::is_nil(aSO))
692 SALOMEDS::ChildIterator_var Itr = aStudy->NewChildIterator(aSO);
694 for(Itr->InitEx(true); Itr->More(); Itr->Next()) {
695 SALOMEDS::SObject_var aSObject = Itr->Value();
696 SALOMEDS::GenericAttribute_var anAttr;
697 if ( aSObject->FindAttribute(anAttr, "AttributeString")) {
698 aParameters = SALOMEDS::AttributeString::_narrow(anAttr)->Value();
699 SALOMEDS::ListOfListOfStrings_var aSections = aStudy->ParseVariables(aParameters);
701 cout<<"Entry : "<< aSObject->GetID()<<endl;
702 cout<<"aParameters : "<<aParameters<<endl;
704 TCollection_AsciiString anObjType;
705 CORBA::Object_var anObject = SMESH_Gen_i::SObjectToObject(aSObject);
706 SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow(anObject);
707 SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow(anObject);
708 if(!aHyp->_is_nil()) {
709 CORBA::String_var hypName = aHyp->GetName();
710 anObjType = hypName.in();
712 else if (!aMesh->_is_nil() ) {
716 cout<<"The object Type : "<<anObjType<<endl;
717 SMESH_ObjectStates *aState = NULL;
718 if(anObjType == "LayerDistribution")
719 aState = new LayerDistributionStates();
721 aState = new SMESH_ObjectStates(anObjType);
723 for(int i = 0; i < aSections->length(); i++) {
725 SALOMEDS::ListOfStrings aListOfVars = aSections[i];
726 for(int j = 0;j<aListOfVars.length();j++) {
727 TCollection_AsciiString aVar(aListOfVars[j].in());
728 if(!aVar.IsEmpty() && aStudy->IsVariable(aVar.ToCString())) {
729 aVar.InsertBefore(1, SMESH::TVar::Quote() );
730 aVar.InsertAfter(aVar.Length(), SMESH::TVar::Quote() );
732 aVars.push_back(aVar);
734 cout<<"Variable: '"<<aVar<<"'"<<endl;
737 aState->AddState(aVars);
739 if ( aState->GetAllStates().empty() )
745 CORBA::String_var objID = aSObject->GetID();
746 _objectMap.insert( make_pair(TCollection_AsciiString( objID.in() ), aState ));
752 //================================================================================
756 //================================================================================
757 void SMESH_NoteBook::AddCommand(const TCollection_AsciiString& theString)
760 cout<<theString<<endl;
761 Handle(_pyCommand) aCommand = new _pyCommand( theString, -1);
762 _commands.push_back(aCommand);
764 if ( aCommand->GetMethod() == "GetMeshEditor" ) { // MeshEditor creation
765 myMeshEditors.insert( make_pair( aCommand->GetResultValue(),
766 aCommand->GetObject() ) );
770 //================================================================================
774 //================================================================================
775 void SMESH_NoteBook::ProcessLayerDistribution()
777 // 1) Find all LayerDistribution states
778 vector<LayerDistributionStates*> aLDS;
779 TVariablesMap::const_iterator it = _objectMap.begin();
780 for(;it != _objectMap.end();it++) {
781 LayerDistributionStates* aLDStates = dynamic_cast<LayerDistributionStates*>(((*it).second));
782 if(aLDStates!=NULL) {
783 aLDS.push_back(aLDStates);
790 // 2) Initialize all type of 1D Distribution hypothesis
791 for(int i=0;i<_commands.size();i++){
792 for(int j =0;j < aLDS.size();j++){
793 TCollection_AsciiString aResultValue = _commands[i]->GetResultValue();
794 if(_commands[i]->GetMethod() == "CreateHypothesis" &&
795 aLDS[j]->HasDistribution(aResultValue)){
796 TCollection_AsciiString aType = _commands[i]->GetArg(1);
797 aType.RemoveAll('\'');
798 aLDS[j]->SetDistributionType(aResultValue,aType);
802 // 3) ... and replase variables ...
804 for(int i=0;i<_commands.size();i++){
805 for(int j =0;j < aLDS.size();j++){
806 TCollection_AsciiString anObject = _commands[i]->GetObject();
808 if(aLDS[j]->HasDistribution(anObject)) {
809 TCollection_AsciiString aType = aLDS[j]->GetDistributionType(anObject);
810 TCollection_AsciiString aMethod = _commands[i]->GetMethod();
811 if(aType == "LocalLength") {
812 if(aMethod == "SetLength") {
813 SetVariable(_commands[i], aLDS[j],0,1);
814 aLDS[j]->IncrementState();
816 else if(aMethod == "SetPrecision") {
817 SetVariable(_commands[i], aLDS[j],1,1);
818 aLDS[j]->IncrementState();
822 // Case for NumberOfSegments hypothesis
823 else if(aType == "NumberOfSegments"){
824 if(aMethod == "SetNumberOfSegments") {
825 SetVariable(_commands[i], aLDS[j],0,1);
826 if(aLDS[j]->GetCurrectState().size()==1)
827 aLDS[j]->IncrementState();
829 else if (aMethod == "SetScaleFactor") {
830 SetVariable(_commands[i], aLDS[j],1,1);
831 aLDS[j]->IncrementState();
835 else if( aType == "Deflection1D" ){
836 if(aMethod == "SetDeflection"){
837 SetVariable(_commands[i], aLDS[j],0,1);
838 aLDS[j]->IncrementState();
841 // Case for Arithmetic1D and StartEndLength hypothesis
842 else if(aType == "Arithmetic1D" || aType == "StartEndLength") {
843 if(aMethod == "SetLength") {
844 int anArgNb = (_commands[i]->GetArg(2) == "1") ? 0 : 1;
845 SetVariable(_commands[i], aLDS[j],anArgNb,1);
846 aLDS[j]->IncrementState();
853 //================================================================================
855 * \brief Return result script
857 //================================================================================
858 TCollection_AsciiString SMESH_NoteBook::GetResultScript() const
860 TCollection_AsciiString aResult;
861 for(int i=0;i<_commands.size();i++)
862 aResult+=_commands[i]->GetString()+"\n";
866 //================================================================================
868 * \brief Return value of the variable
870 //================================================================================
871 bool SMESH_NoteBook::GetReal(const TCollection_AsciiString& theVarName, double& theValue)
875 SMESH_Gen_i *aGen = SMESH_Gen_i::GetSMESHGen();
879 SALOMEDS::Study_ptr aStudy = aGen->GetCurrentStudy();
880 if(aStudy->_is_nil())
883 TCollection_AsciiString aVarName = theVarName;
884 aVarName.RemoveAll('\"');
886 if(aVarName.IsEmpty())
889 const char* aName = aVarName.ToCString();
890 if(aStudy->IsVariable(aName) && (aStudy->IsReal(aName) || aStudy->IsInteger(aName))) {
891 theValue = aStudy->GetReal(aVarName.ToCString());