1 // Copyright (C) 2007-2012 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>
33 #include <SALOMEDS_wrap.hxx>
34 #include <SALOMEDS_Attributes_wrap.hxx>
40 static int MYDEBUG = 0;
42 static int MYDEBUG = 0;
51 * Set variable of the SMESH_ObjectStates from position to the _pyCommand
52 * method as nbArg argument
54 void SetVariable(Handle(_pyCommand) theCommand,
55 const SMESH_ObjectStates* theStates,
56 int position, int theArgNb)
58 if(theStates->GetCurrectState().size() > position)
59 if(!theStates->GetCurrectState().at(position).IsEmpty())
60 theCommand->SetArg(theArgNb,theStates->GetCurrectState().at(position));
64 //================================================================================
68 //================================================================================
69 SMESH_ObjectStates::SMESH_ObjectStates(TCollection_AsciiString theType)
75 //================================================================================
79 //================================================================================
80 SMESH_ObjectStates::~SMESH_ObjectStates()
84 //================================================================================
86 * \brief Add new object state
87 * \param theState - Object state (vector of notebook variable)
89 //================================================================================
90 void SMESH_ObjectStates::AddState(const TState &theState)
92 _states.push_back(theState);
95 //================================================================================
97 * \brief Return current object state
98 * \\retval state - Object state (vector of notebook variable)
100 //================================================================================
101 TState SMESH_ObjectStates::GetCurrectState() const
103 if(_states.size() > _dumpstate)
104 return _states[_dumpstate];
110 //================================================================================
114 //================================================================================
115 TAllStates SMESH_ObjectStates::GetAllStates() const
120 //================================================================================
124 //================================================================================
125 void SMESH_ObjectStates::IncrementState()
130 //================================================================================
134 //================================================================================
135 TCollection_AsciiString SMESH_ObjectStates::GetObjectType() const{
140 //================================================================================
144 //================================================================================
145 LayerDistributionStates::LayerDistributionStates():
146 SMESH_ObjectStates("LayerDistribution")
149 //================================================================================
153 //================================================================================
154 LayerDistributionStates::~LayerDistributionStates()
159 //================================================================================
161 * \brief AddDistribution
163 //================================================================================
164 void LayerDistributionStates::AddDistribution(const TCollection_AsciiString& theDistribution)
166 _distributions.insert(pair<TCollection_AsciiString,TCollection_AsciiString>(theDistribution,""));
169 //================================================================================
171 * \brief HasDistribution
173 //================================================================================
174 bool LayerDistributionStates::HasDistribution(const TCollection_AsciiString& theDistribution) const
176 return _distributions.find(theDistribution) != _distributions.end();
179 //================================================================================
181 * \brief SetDistributionType
183 //================================================================================
184 bool LayerDistributionStates::SetDistributionType(const TCollection_AsciiString& theDistribution,
185 const TCollection_AsciiString& theType)
187 TDistributionMap::iterator it = _distributions.find(theDistribution);
188 if(it == _distributions.end())
190 (*it).second = theType;
194 //================================================================================
196 * \brief GetDistributionType
198 //================================================================================
199 TCollection_AsciiString LayerDistributionStates::
200 GetDistributionType(const TCollection_AsciiString& theDistribution) const
202 TDistributionMap::const_iterator it = _distributions.find(theDistribution);
203 return (it == _distributions.end()) ? TCollection_AsciiString() : (*it).second;
206 //================================================================================
210 //================================================================================
211 SMESH_NoteBook::SMESH_NoteBook()
216 //================================================================================
220 //================================================================================
221 SMESH_NoteBook::~SMESH_NoteBook()
223 TVariablesMap::const_iterator it = _objectMap.begin();
224 for(;it!=_objectMap.end();it++) {
230 //================================================================================
232 * \brief Replace parameters of the functions on the Salome NoteBook Variables
233 * \param theString - Input string
234 * \retval TCollection_AsciiString - Convertion result
236 //================================================================================
237 void SMESH_NoteBook::ReplaceVariables()
239 for(int i=0;i<_commands.size();i++)
241 Handle(_pyCommand) aCmd = _commands[i];
242 TCollection_AsciiString aMethod = aCmd->GetMethod();
243 TCollection_AsciiString aObject = aCmd->GetObject();
244 TCollection_AsciiString aResultValue = aCmd->GetResultValue();
246 cout<<"Command before : "<< aCmd->GetString()<<endl;
247 cout<<"Method : "<< aMethod<<endl;
248 cout<<"Object : "<< aObject<<endl;
249 cout<<"Result : "<< aResultValue<<endl;
254 TEntry2VarVecMap::iterator ent2varVec = _entry2VarsMap.find( aObject );
255 if ( ent2varVec != _entry2VarsMap.end() && !ent2varVec->second.empty() )
257 TCollection_AsciiString & cmdStr = aCmd->GetString();
258 const std::vector< std::string >& vars = ent2varVec->second;
260 // look for '$VarIndex$' in cmdStr. TVar::Quote() == '$'
261 while (( pos = cmdStr.Location( 1, SMESH::TVar::Quote(), pos, cmdStr.Length() )) &&
262 ( pos2 = cmdStr.Location( 1, SMESH::TVar::Quote(), pos+1, cmdStr.Length() )) )
264 size_t varIndex = std::string::npos;
265 const char* varIndexPtr = cmdStr.ToCString() + pos;
266 if ( '0' <= *varIndexPtr && *varIndexPtr <= '9' )
267 varIndex = atoi( varIndexPtr );
268 if ( 0 <= varIndex && varIndex < vars.size() && !vars[varIndex].empty() )
270 // replace '$VarIndex$' either by var name of var value
271 const char var0 = vars[varIndex][0];
272 const bool isValue = (( '0' <= var0 && var0 <= '9' ) || var0 == '-');
273 if ( isValue ) // remove TVar::Quote() as well
274 pos2 += 2; // pos still points to '$'
275 int indexLen = pos2 - pos - 1;
276 int lenDiff = int( vars[varIndex].size() ) - indexLen;
278 cmdStr.InsertBefore( pos2, vars[varIndex].c_str() + vars[varIndex].size() - lenDiff );
279 else if ( lenDiff < 0 )
280 cmdStr.Remove( pos+1, -lenDiff );
281 cmdStr.SetValue( pos+(!isValue), vars[varIndex].c_str() );
284 if ( pos + 2 >= cmdStr.Length() )
291 // check if method modifies the object itself
292 TVariablesMap::const_iterator it = _objectMap.find(aObject);
293 if(it == _objectMap.end()) // check if method returns a new object
294 it = _objectMap.find(aResultValue);
296 if(it == _objectMap.end()) { // check if method modifies a mesh using mesh editor
297 TMeshEditorMap::const_iterator meIt = _meshEditors.find(aObject);
298 if(meIt != _meshEditors.end()) {
299 TCollection_AsciiString aMesh = (*meIt).second;
300 it = _objectMap.find(aMesh);
304 if(it == _objectMap.end()) { // additional check for pattern mapping
305 if(aMethod.IsEqual("ApplyToMeshFaces") ||
306 aMethod.IsEqual("ApplyToHexahedrons"))
307 it = _objectMap.find(aCmd->GetArg(1));
310 if(it != _objectMap.end()) {
312 cout << "Found object : " << (*it).first << endl;
313 SMESH_ObjectStates *aStates = (*it).second;
314 // Case for LocalLength hypothesis
315 if(aStates->GetObjectType().IsEqual("LocalLength") && aStates->GetCurrectState().size() >= 2)
317 if(aMethod.IsEqual("SetLength")) {
318 if(!aStates->GetCurrectState().at(0).IsEmpty() )
319 aCmd->SetArg(1,aStates->GetCurrectState().at(0));
320 aStates->IncrementState();
322 else if(aMethod.IsEqual("SetPrecision")) {
323 if(!aStates->GetCurrectState().at(1).IsEmpty() )
324 aCmd->SetArg(1,aStates->GetCurrectState().at(1));
325 aStates->IncrementState();
329 // Case for SegmentLengthAroundVertex hypothesis
330 else if(aStates->GetObjectType().IsEqual("SegmentLengthAroundVertex")
331 && aStates->GetCurrectState().size() >= 1) {
332 if(aMethod == "SetLength") {
333 if(!aStates->GetCurrectState().at(0).IsEmpty() )
334 aCmd->SetArg(1,aStates->GetCurrectState().at(0));
335 aStates->IncrementState();
339 // Case for Arithmetic1D and StartEndLength hypothesis
340 else if(aStates->GetObjectType().IsEqual("Arithmetic1D") ||
341 aStates->GetObjectType().IsEqual("StartEndLength")) {
342 if(aMethod == "SetLength" &&
343 aStates->GetCurrectState().size() >= 2) {
344 if(aCmd->GetArg(2) == "1" && !aStates->GetCurrectState().at(0).IsEmpty())
345 aCmd->SetArg(1,aStates->GetCurrectState().at(0));
346 else if(!aStates->GetCurrectState().at(1).IsEmpty())
347 aCmd->SetArg(1,aStates->GetCurrectState().at(1));
348 aStates->IncrementState();
352 //Case for Deflection1D hypothesis
353 else if(aStates->GetObjectType().IsEqual("Deflection1D")){
354 if(aMethod == "SetDeflection" && aStates->GetCurrectState().size() >= 1) {
355 if(!aStates->GetCurrectState().at(0).IsEmpty() )
356 aCmd->SetArg(1,aStates->GetCurrectState().at(0));
357 aStates->IncrementState();
361 // Case for LayerDistribution hypothesis (not finished yet)
362 else if(aStates->GetObjectType() == "LayerDistribution") {
363 if(aMethod == "SetLayerDistribution"){
364 LayerDistributionStates* aLDStates = (LayerDistributionStates*)(aStates);
365 aLDStates->AddDistribution(aCmd->GetArg(1));
367 cout<<"Add Distribution :"<<aCmd->GetArg(1)<<endl;
371 // Case for MaxElementArea hypothesis
372 else if(aStates->GetObjectType().IsEqual("MaxElementArea")){
373 if(aMethod == "SetMaxElementArea" && aStates->GetCurrectState().size() >= 1) {
374 if(!aStates->GetCurrectState().at(0).IsEmpty() )
375 aCmd->SetArg(1,aStates->GetCurrectState().at(0));
376 aStates->IncrementState();
380 // Case for MaxElementVolume hypothesis
381 else if(aStates->GetObjectType().IsEqual("MaxElementVolume")){
382 if(aMethod == "SetMaxElementVolume" && aStates->GetCurrectState().size() >= 1) {
383 if(!aStates->GetCurrectState().at(0).IsEmpty() )
384 aCmd->SetArg(1,aStates->GetCurrectState().at(0));
385 aStates->IncrementState();
388 // Case for NumberOfLayers hypothesis
389 else if(aStates->GetObjectType().IsEqual("NumberOfLayers")){
390 if(aMethod == "SetNumberOfLayers" && aStates->GetCurrectState().size() >= 1) {
391 if(!aStates->GetCurrectState().at(0).IsEmpty() )
392 aCmd->SetArg(1,aStates->GetCurrectState().at(0));
393 aStates->IncrementState();
397 // Case for NumberOfSegments hypothesis
398 else if(aStates->GetObjectType().IsEqual("NumberOfSegments")){
399 if(aMethod == "SetNumberOfSegments" && aStates->GetCurrectState().size() >= 1) {
400 if(!aStates->GetCurrectState().at(0).IsEmpty() )
401 aCmd->SetArg(1,aStates->GetCurrectState().at(0));
402 if(aStates->GetCurrectState().size()==1)
403 aStates->IncrementState();
405 else if (aMethod == "SetScaleFactor" && aStates->GetCurrectState().size() >= 2) {
406 if(!aStates->GetCurrectState().at(1).IsEmpty() )
407 aCmd->SetArg(1,aStates->GetCurrectState().at(1));
408 aStates->IncrementState();
412 else if(aStates->GetObjectType().IsEqual("Mesh")) {
413 TState aCurrentState = aStates->GetCurrectState();
414 int aCurrentStateSize = aCurrentState.size();
415 if(aMethod.IsEqual("Translate") ||
416 aMethod.IsEqual("TranslateMakeGroups") ||
417 aMethod.IsEqual("TranslateMakeMesh") ||
418 aMethod.IsEqual("TranslateObject") ||
419 aMethod.IsEqual("TranslateObjectMakeGroups") ||
420 aMethod.IsEqual("TranslateObjectMakeMesh")) {
421 bool isVariableFound = false;
423 for(int i = 1, n = aCmd->GetNbArgs(); i <= n; i++) {
424 if(aCmd->GetArg(i).IsEqual("SMESH.PointStruct")) {
430 if(aCurrentStateSize == 3) { // translation by dx, dy, dz
431 for(int j = 0; j < aCurrentStateSize; j++) {
432 if(!aCurrentState.at(j).IsEmpty()) {
433 isVariableFound = true;
434 aCmd->SetArg(anArgIndex+j, aCurrentState.at(j));
438 else if(aCurrentStateSize == 6) { // translation by x1, x2, y1, y2, z1, z2
439 // TODO: limitation until operations on the variables will be introduced
441 isVariableFound = true;
442 for(int j = 0; j < 3; j++) {
443 TCollection_AsciiString anArg = aCmd->GetArg(anArgIndex+j);
444 TCollection_AsciiString aValue1 = aCurrentState.at(2*j), aValue2 = aCurrentState.at(2*j+1);
445 bool aV1 = !aValue1.IsEmpty();
446 bool aV2 = !aValue2.IsEmpty();
447 double aValue, aCurrentValue = anArg.IsRealValue() ? anArg.RealValue() : 0;
449 if(!GetReal(aValue1, aValue))
451 aValue2 = TCollection_AsciiString( aValue + aCurrentValue );
453 else if(!aV1 && aV2) {
454 if(!GetReal(aValue2, aValue))
456 aValue1 = TCollection_AsciiString( aValue - aCurrentValue );
458 else if(!aV1 && !aV2) {
459 aValue1 = TCollection_AsciiString( 0 );
460 aValue2 = TCollection_AsciiString( aCurrentValue );
462 aCmd->SetArg(anArgIndex+j, aValue1 + ", " + aValue2 );
467 if(isVariableFound) {
468 TCollection_AsciiString aDim;
469 if(aCurrentStateSize == 6)
471 aCmd->SetArg(anArgIndex - 1, TCollection_AsciiString(SMESH_2smeshpy::SmeshpyName())+".PointStructStr"+aDim);
472 aCmd->SetArg(anArgIndex - 2, TCollection_AsciiString(SMESH_2smeshpy::SmeshpyName())+".DirStructStr");
474 aStates->IncrementState();
476 else if(aMethod.IsEqual("Rotate") ||
477 aMethod.IsEqual("RotateMakeGroups") ||
478 aMethod.IsEqual("RotateMakeMesh") ||
479 aMethod.IsEqual("RotateObject") ||
480 aMethod.IsEqual("RotateObjectMakeGroups") ||
481 aMethod.IsEqual("RotateObjectMakeMesh") ||
482 aMethod.IsEqual("RotationSweep") ||
483 aMethod.IsEqual("RotationSweepObject") ||
484 aMethod.IsEqual("RotationSweepObject1D") ||
485 aMethod.IsEqual("RotationSweepObject2D") ||
486 aMethod.IsEqual("RotationSweepMakeGroups") ||
487 aMethod.IsEqual("RotationSweepObjectMakeGroups") ||
488 aMethod.IsEqual("RotationSweepObject1DMakeGroups") ||
489 aMethod.IsEqual("RotationSweepObject2DMakeGroups") ||
490 aMethod.IsEqual("Mirror") ||
491 aMethod.IsEqual("MirrorMakeMesh") ||
492 aMethod.IsEqual("MirrorMakeGroups") ||
493 aMethod.IsEqual("MirrorObject") ||
494 aMethod.IsEqual("MirrorObjectMakeMesh") ||
495 aMethod.IsEqual("MirrorObjectMakeGroups")) {
496 bool isSubstitute = false;
498 for(int i = 1, n = aCmd->GetNbArgs(); i <= n; i++) {
499 if(aCmd->GetArg(i).IsEqual("SMESH.AxisStruct")) {
505 for(int j = 0; j < aCurrentStateSize; j++) {
506 if(!aCurrentState.at(j).IsEmpty()) {
507 if(j < 6) // 0-5 - axis struct, 6 - angle (rotation & sweep), 7-8 - nbSteps and tolerance (sweep)
509 aCmd->SetArg(anArgIndex+j, aCurrentState.at(j));
514 aCmd->SetArg(anArgIndex - 1, TCollection_AsciiString(SMESH_2smeshpy::SmeshpyName())+".AxisStructStr");
515 aStates->IncrementState();
517 else if(aMethod.IsEqual("AddNode") ||
518 aMethod.IsEqual("MoveClosestNodeToPoint")) {
519 for(int j = 0; j < aCurrentStateSize; j++) {
520 if(!aCurrentState.at(j).IsEmpty())
521 aCmd->SetArg(j+1, aCurrentState.at(j));
523 aStates->IncrementState();
525 else if(aMethod.IsEqual("MoveNode")) {
526 for(int j = 0; j < aCurrentStateSize; j++) {
527 if(!aCurrentState.at(j).IsEmpty())
528 aCmd->SetArg(j+2, aCurrentState.at(j));
530 aStates->IncrementState();
532 else if(aMethod.IsEqual("ExtrusionSweep") ||
533 aMethod.IsEqual("ExtrusionSweepObject") ||
534 aMethod.IsEqual("ExtrusionSweepObject1D") ||
535 aMethod.IsEqual("ExtrusionSweepObject2D") ||
536 aMethod.IsEqual("ExtrusionSweepMakeGroups") ||
537 aMethod.IsEqual("ExtrusionSweepObjectMakeGroups") ||
538 aMethod.IsEqual("ExtrusionSweepObject1DMakeGroups") ||
539 aMethod.IsEqual("ExtrusionSweepObject2DMakeGroups")) {
540 bool isSubstitute = false;
542 for(int i = 1, n = aCmd->GetNbArgs(); i <= n; i++) {
543 if(aCmd->GetArg(i).IsEqual("SMESH.PointStruct")) {
549 for(int j = 0; j < aCurrentStateSize; j++) {
550 if(!aCurrentState.at(j).IsEmpty()) {
551 if(j < 3) // 0-2 - dir struct, 3 - number of steps
553 aCmd->SetArg(anArgIndex+j, aCurrentState.at(j));
558 aCmd->SetArg(anArgIndex - 1, TCollection_AsciiString(SMESH_2smeshpy::SmeshpyName())+".PointStructStr");
559 aCmd->SetArg(anArgIndex - 2, TCollection_AsciiString(SMESH_2smeshpy::SmeshpyName())+".DirStructStr");
561 aStates->IncrementState();
563 else if(aMethod.IsEqual("ExtrusionAlongPath") ||
564 aMethod.IsEqual("ExtrusionAlongPathObject") ||
565 aMethod.IsEqual("ExtrusionAlongPathObject1D") ||
566 aMethod.IsEqual("ExtrusionAlongPathObject2D") ||
567 aMethod.IsEqual("ExtrusionAlongPathMakeGroups") ||
568 aMethod.IsEqual("ExtrusionAlongPathObjectMakeGroups") ||
569 aMethod.IsEqual("ExtrusionAlongPathObject1DMakeGroups") ||
570 aMethod.IsEqual("ExtrusionAlongPathObject2DMakeGroups") ||
571 /* workaround for a bug in the command parsing algorithm */
572 aCmd->GetString().Search("ExtrusionAlongPathMakeGroups") != -1 ||
573 aCmd->GetString().Search("ExtrusionAlongPathObjectMakeGroups") != -1 ||
574 aCmd->GetString().Search("ExtrusionAlongPathObject1DMakeGroups") != -1 ||
575 aCmd->GetString().Search("ExtrusionAlongPathObject2DMakeGroups") != -1 ) {
576 int aNbAngles = aCurrentStateSize-3; // State looks like "Angle1:...:AngleN:X:Y:Z"
577 bool isSubstitute = false;
579 for(int i = 1, n = aCmd->GetNbArgs(); i <= n; i++) {
580 if(aCmd->GetArg(i).IsEqual("SMESH.PointStruct")) {
581 anArgIndex = i-1-aNbAngles;
587 for(; j < aNbAngles; j++) {
588 if(!aCurrentState.at(j).IsEmpty()) {
589 aCmd->SetArg(anArgIndex+j-1, aCurrentState.at(j));
592 for(; j < aNbAngles+3; j++) {
593 if(!aCurrentState.at(j).IsEmpty()) {
595 aCmd->SetArg(anArgIndex+j+2, aCurrentState.at(j));
600 aCmd->SetArg(anArgIndex + aNbAngles + 1,
601 TCollection_AsciiString(SMESH_2smeshpy::SmeshpyName())+".PointStructStr");
602 aStates->IncrementState();
604 else if(aMethod.IsEqual("TriToQuad") ||
605 aMethod.IsEqual("Concatenate") ||
606 aMethod.IsEqual("ConcatenateWithGroups")) {
607 if(aCurrentStateSize && !aCurrentState.at(0).IsEmpty())
608 aCmd->SetArg(aCmd->GetNbArgs(), aCurrentState.at(0));
609 aStates->IncrementState();
611 else if(aMethod.IsEqual("Smooth") ||
612 aMethod.IsEqual("SmoothObject") ||
613 aMethod.IsEqual("SmoothParametric") ||
614 aMethod.IsEqual("SmoothParametricObject")) {
615 int anArgIndex = aCmd->GetNbArgs() - 2;
616 for(int j = 0; j < aCurrentStateSize; j++) {
617 if(!aCurrentState.at(j).IsEmpty())
618 aCmd->SetArg(anArgIndex+j, aCurrentState.at(j));
620 aStates->IncrementState();
622 else if(aMethod.IsEqual("ApplyToMeshFaces") ||
623 aMethod.IsEqual("ApplyToHexahedrons")) {
624 int anArgIndex = aCmd->GetNbArgs()-1;
625 for(int j = 0; j < aCurrentStateSize; j++)
626 if(!aCurrentState.at(j).IsEmpty())
627 aCmd->SetArg(anArgIndex+j, aCurrentState.at(j));
628 aStates->IncrementState();
630 } // if ( aStates->GetObjectType().IsEqual("Mesh"))
632 // Case for NETGEN_Parameters_2D or NETGEN_Parameters_2D hypothesis
633 // else if(aStates->GetObjectType().IsEqual("NETGEN_Parameters_2D") ||
634 // aStates->GetObjectType().IsEqual("NETGEN_Parameters")){
635 // if(aMethod == "SetMaxSize" && aStates->GetCurrectState().size() >= 1) {
636 // if(!aStates->GetCurrectState().at(0).IsEmpty() )
637 // aCmd->SetArg(1,aStates->GetCurrectState().at(0));
638 // aStates->IncrementState();
640 // else if(aMethod == "SetGrowthRate" && aStates->GetCurrectState().size() >= 2) {
641 // if(!aStates->GetCurrectState().at(1).IsEmpty() )
642 // aCmd->SetArg(1,aStates->GetCurrectState().at(1));
643 // aStates->IncrementState();
645 // else if(aMethod == "SetNbSegPerEdge" && aStates->GetCurrectState().size() >= 3) {
646 // if(!aStates->GetCurrectState().at(2).IsEmpty() )
647 // aCmd->SetArg(1,aStates->GetCurrectState().at(2));
648 // aStates->IncrementState();
650 // else if(aMethod == "SetNbSegPerRadius" && aStates->GetCurrectState().size() >= 4) {
651 // if(!aStates->GetCurrectState().at(3).IsEmpty() )
652 // aCmd->SetArg(1,aStates->GetCurrectState().at(3));
653 // aStates->IncrementState();
657 // // Case for NETGEN_SimpleParameters_3D or NETGEN_SimpleParameters_2D hypothesis
658 // else if(aStates->GetObjectType().IsEqual("NETGEN_SimpleParameters_3D") ||
659 // aStates->GetObjectType().IsEqual("NETGEN_SimpleParameters_2D")) {
661 // if((aMethod == "SetNumberOfSegments" || aMethod == "SetLocalLength") &&
662 // aStates->GetCurrectState().size() >= 1) {
663 // if(!aStates->GetCurrectState().at(0).IsEmpty() )
664 // aCmd->SetArg(1,aStates->GetCurrectState().at(0));
665 // aStates->IncrementState();
667 // else if(aMethod == "SetMaxElementArea" && aStates->GetCurrectState().size() >= 2) {
668 // if(!aStates->GetCurrectState().at(1).IsEmpty() )
669 // aCmd->SetArg(1,aStates->GetCurrectState().at(1));
670 // aStates->IncrementState();
672 // else if(aMethod == "SetMaxElementVolume" && aStates->GetCurrectState().size() >= 3) {
673 // if(!aStates->GetCurrectState().at(2).IsEmpty() )
674 // aCmd->SetArg(1,aStates->GetCurrectState().at(2));
675 // aStates->IncrementState();
677 // else if(aMethod == "LengthFromEdges" || aMethod == "LengthFromFaces"){
678 // aStates->IncrementState();
684 // treat Netgen hypotheses;
685 // this (and above) code can work wrong since nb of states can differ from nb of
686 // dumped calls due to the fix of
687 // issue 0021364:: Dump of netgen parameters has duplicate lines
688 SMESH_Gen_i * aGen = SMESH_Gen_i::GetSMESHGen();
689 SALOMEDS::Study_var aStudy = aGen->GetCurrentStudy();
690 SALOMEDS::SObject_wrap sobj = aStudy->FindObjectID( (*it).first.ToCString() );
691 CORBA::Object_var obj = aGen->SObjectToObject( sobj );
692 if ( SMESH_Hypothesis_i* h = SMESH::DownCast< SMESH_Hypothesis_i*>( obj ))
694 TState aCurrentState = aStates->GetCurrectState();
695 int argIndex = h->getParamIndex( aMethod, aCurrentState.size() );
696 if ( 0 <= argIndex && argIndex < aCurrentState.size() &&
697 !aCurrentState[argIndex].IsEmpty() )
698 aCmd->SetArg( 1, aCurrentState[argIndex] );
701 aStates->IncrementState();
707 cout << "Object not found" << endl;
710 cout<<"Command after: "<< aCmd->GetString()<<endl;
714 ProcessLayerDistribution();
716 //================================================================================
718 * \brief Private method
720 //================================================================================
721 void SMESH_NoteBook::InitObjectMap()
723 SMESH_Gen_i *aGen = SMESH_Gen_i::GetSMESHGen();
727 SALOMEDS::Study_var aStudy = aGen->GetCurrentStudy();
728 if(aStudy->_is_nil())
731 CORBA::String_var compDataType = aGen->ComponentDataType();
732 SALOMEDS::SObject_wrap aSO = aStudy->FindComponent( compDataType.in() );
733 if(CORBA::is_nil(aSO))
736 SALOMEDS::ChildIterator_wrap Itr = aStudy->NewChildIterator(aSO);
737 for( Itr->InitEx(true); Itr->More(); Itr->Next())
739 SALOMEDS::SObject_wrap aSObject = Itr->Value();
740 SALOMEDS::GenericAttribute_wrap anAttr;
741 if ( aSObject->FindAttribute( anAttr.inout(), "AttributeString"))
743 SALOMEDS::AttributeString_wrap strAttr = anAttr;
744 CORBA::String_var aParameters = strAttr->Value();
745 CORBA::String_var anID = aSObject->GetID();
746 std::vector< std::string > allVars = aGen->GetAllParameters( anID.in() );
747 SALOMEDS::ListOfListOfStrings_var aSections = aStudy->ParseVariables(aParameters.in());
748 _entry2VarsMap[ TCollection_AsciiString( anID.in() )] = allVars;
750 cout<<"Entry : "<< anID<<endl;
751 cout<<"aParameters : "<<aParameters<<endl;
753 TCollection_AsciiString anObjType;
754 CORBA::Object_var anObject = SMESH_Gen_i::SObjectToObject(aSObject);
755 SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow(anObject);
756 SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow(anObject);
757 if(!aHyp->_is_nil()) {
758 CORBA::String_var hypName = aHyp->GetName();
759 anObjType = hypName.in();
761 else if (!aMesh->_is_nil() ) {
765 cout<<"The object Type : "<<anObjType<<endl;
766 SMESH_ObjectStates *aState = NULL;
767 if(anObjType == "LayerDistribution")
768 aState = new LayerDistributionStates();
770 aState = new SMESH_ObjectStates(anObjType);
772 for(int i = 0; i < aSections->length(); i++) {
774 SALOMEDS::ListOfStrings aListOfVars = aSections[i];
775 for ( int j = 0; j<aListOfVars.length(); j++)
777 TCollection_AsciiString aVar(aListOfVars[j].in());
778 if(!aVar.IsEmpty() && aStudy->IsVariable(aVar.ToCString())) {
779 aVar.InsertBefore(1, SMESH::TVar::Quote() );
780 aVar.InsertAfter(aVar.Length(), SMESH::TVar::Quote() );
782 aVars.push_back(aVar);
784 cout<<"Variable: '"<<aVar<<"'"<<endl;
787 aState->AddState(aVars);
789 if ( aState->GetAllStates().empty() )
795 CORBA::String_var objID = aSObject->GetID();
796 _objectMap.insert( make_pair(TCollection_AsciiString( objID.in() ), aState ));
802 //================================================================================
806 //================================================================================
807 void SMESH_NoteBook::AddCommand(const TCollection_AsciiString& theString)
810 cout<<theString<<endl;
811 Handle(_pyCommand) aCommand = new _pyCommand( theString, -1);
812 _commands.push_back(aCommand);
814 if ( aCommand->GetMethod() == "GetMeshEditor" ) { // MeshEditor creation
815 _meshEditors.insert( make_pair( aCommand->GetResultValue(),
816 aCommand->GetObject() ) );
820 //================================================================================
824 //================================================================================
825 void SMESH_NoteBook::ProcessLayerDistribution()
827 // 1) Find all LayerDistribution states
828 vector<LayerDistributionStates*> aLDS;
829 TVariablesMap::const_iterator it = _objectMap.begin();
830 for(;it != _objectMap.end();it++) {
831 LayerDistributionStates* aLDStates = dynamic_cast<LayerDistributionStates*>(((*it).second));
832 if(aLDStates!=NULL) {
833 aLDS.push_back(aLDStates);
840 // 2) Initialize all type of 1D Distribution hypothesis
841 for(int i=0;i<_commands.size();i++){
842 for(int j =0;j < aLDS.size();j++){
843 TCollection_AsciiString aResultValue = _commands[i]->GetResultValue();
844 if(_commands[i]->GetMethod() == "CreateHypothesis" &&
845 aLDS[j]->HasDistribution(aResultValue)){
846 TCollection_AsciiString aType = _commands[i]->GetArg(1);
847 aType.RemoveAll('\'');
848 aLDS[j]->SetDistributionType(aResultValue,aType);
852 // 3) ... and replase variables ...
854 for(int i=0;i<_commands.size();i++){
855 for(int j =0;j < aLDS.size();j++){
856 TCollection_AsciiString anObject = _commands[i]->GetObject();
858 if(aLDS[j]->HasDistribution(anObject)) {
859 TCollection_AsciiString aType = aLDS[j]->GetDistributionType(anObject);
860 TCollection_AsciiString aMethod = _commands[i]->GetMethod();
861 if(aType == "LocalLength") {
862 if(aMethod == "SetLength") {
863 SetVariable(_commands[i], aLDS[j],0,1);
864 aLDS[j]->IncrementState();
866 else if(aMethod == "SetPrecision") {
867 SetVariable(_commands[i], aLDS[j],1,1);
868 aLDS[j]->IncrementState();
872 // Case for NumberOfSegments hypothesis
873 else if(aType == "NumberOfSegments"){
874 if(aMethod == "SetNumberOfSegments") {
875 SetVariable(_commands[i], aLDS[j],0,1);
876 if(aLDS[j]->GetCurrectState().size()==1)
877 aLDS[j]->IncrementState();
879 else if (aMethod == "SetScaleFactor") {
880 SetVariable(_commands[i], aLDS[j],1,1);
881 aLDS[j]->IncrementState();
885 else if( aType == "Deflection1D" ){
886 if(aMethod == "SetDeflection"){
887 SetVariable(_commands[i], aLDS[j],0,1);
888 aLDS[j]->IncrementState();
891 // Case for Arithmetic1D and StartEndLength hypothesis
892 else if(aType == "Arithmetic1D" || aType == "StartEndLength") {
893 if(aMethod == "SetLength") {
894 int anArgNb = (_commands[i]->GetArg(2) == "1") ? 0 : 1;
895 SetVariable(_commands[i], aLDS[j],anArgNb,1);
896 aLDS[j]->IncrementState();
903 //================================================================================
905 * \brief Return result script
907 //================================================================================
908 TCollection_AsciiString SMESH_NoteBook::GetResultScript() const
910 TCollection_AsciiString aResult;
911 for(int i=0;i<_commands.size();i++)
912 aResult+=_commands[i]->GetString()+"\n";
916 //================================================================================
918 * \brief Return value of the variable
920 //================================================================================
921 bool SMESH_NoteBook::GetReal(const TCollection_AsciiString& theVarName, double& theValue)
925 SMESH_Gen_i *aGen = SMESH_Gen_i::GetSMESHGen();
929 SALOMEDS::Study_ptr aStudy = aGen->GetCurrentStudy();
930 if(aStudy->_is_nil())
933 TCollection_AsciiString aVarName = theVarName;
934 aVarName.RemoveAll('\"');
936 if(aVarName.IsEmpty())
939 const char* aName = aVarName.ToCString();
940 if(aStudy->IsVariable(aName) && (aStudy->IsReal(aName) || aStudy->IsInteger(aName))) {
941 theValue = aStudy->GetReal(aName);