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++) {
240 Handle(_pyCommand) aCmd = _commands[i];
241 TCollection_AsciiString aMethod = aCmd->GetMethod();
242 TCollection_AsciiString aObject = aCmd->GetObject();
243 TCollection_AsciiString aResultValue = aCmd->GetResultValue();
245 cout<<"Command before : "<< aCmd->GetString()<<endl;
246 cout<<"Method : "<< aMethod<<endl;
247 cout<<"Object : "<< aObject<<endl;
248 cout<<"Result : "<< aResultValue<<endl;
251 // check if method modifies the object itself
252 TVariablesMap::const_iterator it = _objectMap.find(aObject);
253 if(it == _objectMap.end()) // check if method returns a new object
254 it = _objectMap.find(aResultValue);
256 if(it == _objectMap.end()) { // check if method modifies a mesh using mesh editor
257 TMeshEditorMap::const_iterator meIt = myMeshEditors.find(aObject);
258 if(meIt != myMeshEditors.end()) {
259 TCollection_AsciiString aMesh = (*meIt).second;
260 it = _objectMap.find(aMesh);
264 if(it == _objectMap.end()) { // additional check for pattern mapping
265 if(aMethod.IsEqual("ApplyToMeshFaces") ||
266 aMethod.IsEqual("ApplyToHexahedrons"))
267 it = _objectMap.find(aCmd->GetArg(1));
270 if(it != _objectMap.end()) {
272 cout << "Found object : " << (*it).first << endl;
273 SMESH_ObjectStates *aStates = (*it).second;
274 // Case for LocalLength hypothesis
275 if(aStates->GetObjectType().IsEqual("LocalLength") && aStates->GetCurrectState().size() >= 2)
277 if(aMethod.IsEqual("SetLength")) {
278 if(!aStates->GetCurrectState().at(0).IsEmpty() )
279 aCmd->SetArg(1,aStates->GetCurrectState().at(0));
280 aStates->IncrementState();
282 else if(aMethod.IsEqual("SetPrecision")) {
283 if(!aStates->GetCurrectState().at(1).IsEmpty() )
284 aCmd->SetArg(1,aStates->GetCurrectState().at(1));
285 aStates->IncrementState();
289 // Case for SegmentLengthAroundVertex hypothesis
290 else if(aStates->GetObjectType().IsEqual("SegmentLengthAroundVertex")
291 && aStates->GetCurrectState().size() >= 1) {
292 if(aMethod == "SetLength") {
293 if(!aStates->GetCurrectState().at(0).IsEmpty() )
294 aCmd->SetArg(1,aStates->GetCurrectState().at(0));
295 aStates->IncrementState();
299 // Case for Arithmetic1D and StartEndLength hypothesis
300 else if(aStates->GetObjectType().IsEqual("Arithmetic1D") ||
301 aStates->GetObjectType().IsEqual("StartEndLength")) {
302 if(aMethod == "SetLength" &&
303 aStates->GetCurrectState().size() >= 2) {
304 if(aCmd->GetArg(2) == "1" && !aStates->GetCurrectState().at(0).IsEmpty())
305 aCmd->SetArg(1,aStates->GetCurrectState().at(0));
306 else if(!aStates->GetCurrectState().at(1).IsEmpty())
307 aCmd->SetArg(1,aStates->GetCurrectState().at(1));
308 aStates->IncrementState();
312 //Case for Deflection1D hypothesis
313 else if(aStates->GetObjectType().IsEqual("Deflection1D")){
314 if(aMethod == "SetDeflection" && aStates->GetCurrectState().size() >= 1) {
315 if(!aStates->GetCurrectState().at(0).IsEmpty() )
316 aCmd->SetArg(1,aStates->GetCurrectState().at(0));
317 aStates->IncrementState();
321 // Case for LayerDistribution hypothesis (not finished yet)
322 else if(aStates->GetObjectType() == "LayerDistribution") {
323 if(aMethod == "SetLayerDistribution"){
324 LayerDistributionStates* aLDStates = (LayerDistributionStates*)(aStates);
325 aLDStates->AddDistribution(aCmd->GetArg(1));
327 cout<<"Add Distribution :"<<aCmd->GetArg(1)<<endl;
331 // Case for MaxElementArea hypothesis
332 else if(aStates->GetObjectType().IsEqual("MaxElementArea")){
333 if(aMethod == "SetMaxElementArea" && aStates->GetCurrectState().size() >= 1) {
334 if(!aStates->GetCurrectState().at(0).IsEmpty() )
335 aCmd->SetArg(1,aStates->GetCurrectState().at(0));
336 aStates->IncrementState();
340 // Case for MaxElementVolume hypothesis
341 else if(aStates->GetObjectType().IsEqual("MaxElementVolume")){
342 if(aMethod == "SetMaxElementVolume" && aStates->GetCurrectState().size() >= 1) {
343 if(!aStates->GetCurrectState().at(0).IsEmpty() )
344 aCmd->SetArg(1,aStates->GetCurrectState().at(0));
345 aStates->IncrementState();
348 // Case for NumberOfLayers hypothesis
349 else if(aStates->GetObjectType().IsEqual("NumberOfLayers")){
350 if(aMethod == "SetNumberOfLayers" && aStates->GetCurrectState().size() >= 1) {
351 if(!aStates->GetCurrectState().at(0).IsEmpty() )
352 aCmd->SetArg(1,aStates->GetCurrectState().at(0));
353 aStates->IncrementState();
357 // Case for NumberOfSegments hypothesis
358 else if(aStates->GetObjectType().IsEqual("NumberOfSegments")){
359 if(aMethod == "SetNumberOfSegments" && aStates->GetCurrectState().size() >= 1) {
360 if(!aStates->GetCurrectState().at(0).IsEmpty() )
361 aCmd->SetArg(1,aStates->GetCurrectState().at(0));
362 if(aStates->GetCurrectState().size()==1)
363 aStates->IncrementState();
365 else if (aMethod == "SetScaleFactor" && aStates->GetCurrectState().size() >= 2) {
366 if(!aStates->GetCurrectState().at(1).IsEmpty() )
367 aCmd->SetArg(1,aStates->GetCurrectState().at(1));
368 aStates->IncrementState();
372 else if(aStates->GetObjectType().IsEqual("Mesh")) {
373 TState aCurrentState = aStates->GetCurrectState();
374 int aCurrentStateSize = aCurrentState.size();
375 if(aMethod.IsEqual("Translate") ||
376 aMethod.IsEqual("TranslateMakeGroups") ||
377 aMethod.IsEqual("TranslateMakeMesh") ||
378 aMethod.IsEqual("TranslateObject") ||
379 aMethod.IsEqual("TranslateObjectMakeGroups") ||
380 aMethod.IsEqual("TranslateObjectMakeMesh")) {
381 bool isVariableFound = false;
383 for(int i = 1, n = aCmd->GetNbArgs(); i <= n; i++) {
384 if(aCmd->GetArg(i).IsEqual("SMESH.PointStruct")) {
390 if(aCurrentStateSize == 3) { // translation by dx, dy, dz
391 for(int j = 0; j < aCurrentStateSize; j++) {
392 if(!aCurrentState.at(j).IsEmpty()) {
393 isVariableFound = true;
394 aCmd->SetArg(anArgIndex+j, aCurrentState.at(j));
398 else if(aCurrentStateSize == 6) { // translation by x1, x2, y1, y2, z1, z2
399 // TODO: limitation until operations on the variables will be introduced
401 isVariableFound = true;
402 for(int j = 0; j < 3; j++) {
403 TCollection_AsciiString anArg = aCmd->GetArg(anArgIndex+j);
404 TCollection_AsciiString aValue1 = aCurrentState.at(2*j), aValue2 = aCurrentState.at(2*j+1);
405 bool aV1 = !aValue1.IsEmpty();
406 bool aV2 = !aValue2.IsEmpty();
407 double aValue, aCurrentValue = anArg.IsRealValue() ? anArg.RealValue() : 0;
409 if(!GetReal(aValue1, aValue))
411 aValue2 = TCollection_AsciiString( aValue + aCurrentValue );
413 else if(!aV1 && aV2) {
414 if(!GetReal(aValue2, aValue))
416 aValue1 = TCollection_AsciiString( aValue - aCurrentValue );
418 else if(!aV1 && !aV2) {
419 aValue1 = TCollection_AsciiString( 0 );
420 aValue2 = TCollection_AsciiString( aCurrentValue );
422 aCmd->SetArg(anArgIndex+j, aValue1 + ", " + aValue2 );
427 if(isVariableFound) {
428 TCollection_AsciiString aDim;
429 if(aCurrentStateSize == 6)
431 aCmd->SetArg(anArgIndex - 1, TCollection_AsciiString(SMESH_2smeshpy::SmeshpyName())+".PointStructStr"+aDim);
432 aCmd->SetArg(anArgIndex - 2, TCollection_AsciiString(SMESH_2smeshpy::SmeshpyName())+".DirStructStr");
434 aStates->IncrementState();
436 else if(aMethod.IsEqual("Rotate") ||
437 aMethod.IsEqual("RotateMakeGroups") ||
438 aMethod.IsEqual("RotateMakeMesh") ||
439 aMethod.IsEqual("RotateObject") ||
440 aMethod.IsEqual("RotateObjectMakeGroups") ||
441 aMethod.IsEqual("RotateObjectMakeMesh") ||
442 aMethod.IsEqual("RotationSweep") ||
443 aMethod.IsEqual("RotationSweepObject") ||
444 aMethod.IsEqual("RotationSweepObject1D") ||
445 aMethod.IsEqual("RotationSweepObject2D") ||
446 aMethod.IsEqual("RotationSweepMakeGroups") ||
447 aMethod.IsEqual("RotationSweepObjectMakeGroups") ||
448 aMethod.IsEqual("RotationSweepObject1DMakeGroups") ||
449 aMethod.IsEqual("RotationSweepObject2DMakeGroups") ||
450 aMethod.IsEqual("Mirror") ||
451 aMethod.IsEqual("MirrorMakeMesh") ||
452 aMethod.IsEqual("MirrorMakeGroups") ||
453 aMethod.IsEqual("MirrorObject") ||
454 aMethod.IsEqual("MirrorObjectMakeMesh") ||
455 aMethod.IsEqual("MirrorObjectMakeGroups")) {
456 bool isSubstitute = false;
458 for(int i = 1, n = aCmd->GetNbArgs(); i <= n; i++) {
459 if(aCmd->GetArg(i).IsEqual("SMESH.AxisStruct")) {
465 for(int j = 0; j < aCurrentStateSize; j++) {
466 if(!aCurrentState.at(j).IsEmpty()) {
467 if(j < 6) // 0-5 - axis struct, 6 - angle (rotation & sweep), 7-8 - nbSteps and tolerance (sweep)
469 aCmd->SetArg(anArgIndex+j, aCurrentState.at(j));
474 aCmd->SetArg(anArgIndex - 1, TCollection_AsciiString(SMESH_2smeshpy::SmeshpyName())+".AxisStructStr");
475 aStates->IncrementState();
477 else if(aMethod.IsEqual("AddNode") ||
478 aMethod.IsEqual("MoveClosestNodeToPoint")) {
479 for(int j = 0; j < aCurrentStateSize; j++) {
480 if(!aCurrentState.at(j).IsEmpty())
481 aCmd->SetArg(j+1, aCurrentState.at(j));
483 aStates->IncrementState();
485 else if(aMethod.IsEqual("MoveNode")) {
486 for(int j = 0; j < aCurrentStateSize; j++) {
487 if(!aCurrentState.at(j).IsEmpty())
488 aCmd->SetArg(j+2, aCurrentState.at(j));
490 aStates->IncrementState();
492 else if(aMethod.IsEqual("ExtrusionSweep") ||
493 aMethod.IsEqual("ExtrusionSweepObject") ||
494 aMethod.IsEqual("ExtrusionSweepObject1D") ||
495 aMethod.IsEqual("ExtrusionSweepObject2D") ||
496 aMethod.IsEqual("ExtrusionSweepMakeGroups") ||
497 aMethod.IsEqual("ExtrusionSweepObjectMakeGroups") ||
498 aMethod.IsEqual("ExtrusionSweepObject1DMakeGroups") ||
499 aMethod.IsEqual("ExtrusionSweepObject2DMakeGroups")) {
500 bool isSubstitute = false;
502 for(int i = 1, n = aCmd->GetNbArgs(); i <= n; i++) {
503 if(aCmd->GetArg(i).IsEqual("SMESH.PointStruct")) {
509 for(int j = 0; j < aCurrentStateSize; j++) {
510 if(!aCurrentState.at(j).IsEmpty()) {
511 if(j < 3) // 0-2 - dir struct, 3 - number of steps
513 aCmd->SetArg(anArgIndex+j, aCurrentState.at(j));
518 aCmd->SetArg(anArgIndex - 1, TCollection_AsciiString(SMESH_2smeshpy::SmeshpyName())+".PointStructStr");
519 aCmd->SetArg(anArgIndex - 2, TCollection_AsciiString(SMESH_2smeshpy::SmeshpyName())+".DirStructStr");
521 aStates->IncrementState();
523 else if(aMethod.IsEqual("ExtrusionAlongPath") ||
524 aMethod.IsEqual("ExtrusionAlongPathObject") ||
525 aMethod.IsEqual("ExtrusionAlongPathObject1D") ||
526 aMethod.IsEqual("ExtrusionAlongPathObject2D") ||
527 aMethod.IsEqual("ExtrusionAlongPathMakeGroups") ||
528 aMethod.IsEqual("ExtrusionAlongPathObjectMakeGroups") ||
529 aMethod.IsEqual("ExtrusionAlongPathObject1DMakeGroups") ||
530 aMethod.IsEqual("ExtrusionAlongPathObject2DMakeGroups") ||
531 /* workaround for a bug in the command parsing algorithm */
532 aCmd->GetString().Search("ExtrusionAlongPathMakeGroups") != -1 ||
533 aCmd->GetString().Search("ExtrusionAlongPathObjectMakeGroups") != -1 ||
534 aCmd->GetString().Search("ExtrusionAlongPathObject1DMakeGroups") != -1 ||
535 aCmd->GetString().Search("ExtrusionAlongPathObject2DMakeGroups") != -1 ) {
536 int aNbAngles = aCurrentStateSize-3; // State looks like "Angle1:...:AngleN:X:Y:Z"
537 bool isSubstitute = false;
539 for(int i = 1, n = aCmd->GetNbArgs(); i <= n; i++) {
540 if(aCmd->GetArg(i).IsEqual("SMESH.PointStruct")) {
541 anArgIndex = i-1-aNbAngles;
547 for(; j < aNbAngles; j++) {
548 if(!aCurrentState.at(j).IsEmpty()) {
549 aCmd->SetArg(anArgIndex+j-1, aCurrentState.at(j));
552 for(; j < aNbAngles+3; j++) {
553 if(!aCurrentState.at(j).IsEmpty()) {
555 aCmd->SetArg(anArgIndex+j+2, aCurrentState.at(j));
560 aCmd->SetArg(anArgIndex + aNbAngles + 1,
561 TCollection_AsciiString(SMESH_2smeshpy::SmeshpyName())+".PointStructStr");
562 aStates->IncrementState();
564 else if(aMethod.IsEqual("TriToQuad") ||
565 aMethod.IsEqual("Concatenate") ||
566 aMethod.IsEqual("ConcatenateWithGroups")) {
567 if(aCurrentStateSize && !aCurrentState.at(0).IsEmpty())
568 aCmd->SetArg(aCmd->GetNbArgs(), aCurrentState.at(0));
569 aStates->IncrementState();
571 else if(aMethod.IsEqual("Smooth") ||
572 aMethod.IsEqual("SmoothObject") ||
573 aMethod.IsEqual("SmoothParametric") ||
574 aMethod.IsEqual("SmoothParametricObject")) {
575 int anArgIndex = aCmd->GetNbArgs() - 2;
576 for(int j = 0; j < aCurrentStateSize; j++) {
577 if(!aCurrentState.at(j).IsEmpty())
578 aCmd->SetArg(anArgIndex+j, aCurrentState.at(j));
580 aStates->IncrementState();
582 else if(aMethod.IsEqual("ApplyToMeshFaces") ||
583 aMethod.IsEqual("ApplyToHexahedrons")) {
584 int anArgIndex = aCmd->GetNbArgs()-1;
585 for(int j = 0; j < aCurrentStateSize; j++)
586 if(!aCurrentState.at(j).IsEmpty())
587 aCmd->SetArg(anArgIndex+j, aCurrentState.at(j));
588 aStates->IncrementState();
590 } // if ( aStates->GetObjectType().IsEqual("Mesh"))
592 // Case for NETGEN_Parameters_2D or NETGEN_Parameters_2D hypothesis
593 // else if(aStates->GetObjectType().IsEqual("NETGEN_Parameters_2D") ||
594 // aStates->GetObjectType().IsEqual("NETGEN_Parameters")){
595 // if(aMethod == "SetMaxSize" && aStates->GetCurrectState().size() >= 1) {
596 // if(!aStates->GetCurrectState().at(0).IsEmpty() )
597 // aCmd->SetArg(1,aStates->GetCurrectState().at(0));
598 // aStates->IncrementState();
600 // else if(aMethod == "SetGrowthRate" && aStates->GetCurrectState().size() >= 2) {
601 // if(!aStates->GetCurrectState().at(1).IsEmpty() )
602 // aCmd->SetArg(1,aStates->GetCurrectState().at(1));
603 // aStates->IncrementState();
605 // else if(aMethod == "SetNbSegPerEdge" && aStates->GetCurrectState().size() >= 3) {
606 // if(!aStates->GetCurrectState().at(2).IsEmpty() )
607 // aCmd->SetArg(1,aStates->GetCurrectState().at(2));
608 // aStates->IncrementState();
610 // else if(aMethod == "SetNbSegPerRadius" && aStates->GetCurrectState().size() >= 4) {
611 // if(!aStates->GetCurrectState().at(3).IsEmpty() )
612 // aCmd->SetArg(1,aStates->GetCurrectState().at(3));
613 // aStates->IncrementState();
617 // // Case for NETGEN_SimpleParameters_3D or NETGEN_SimpleParameters_2D hypothesis
618 // else if(aStates->GetObjectType().IsEqual("NETGEN_SimpleParameters_3D") ||
619 // aStates->GetObjectType().IsEqual("NETGEN_SimpleParameters_2D")) {
621 // if((aMethod == "SetNumberOfSegments" || aMethod == "SetLocalLength") &&
622 // aStates->GetCurrectState().size() >= 1) {
623 // if(!aStates->GetCurrectState().at(0).IsEmpty() )
624 // aCmd->SetArg(1,aStates->GetCurrectState().at(0));
625 // aStates->IncrementState();
627 // else if(aMethod == "SetMaxElementArea" && aStates->GetCurrectState().size() >= 2) {
628 // if(!aStates->GetCurrectState().at(1).IsEmpty() )
629 // aCmd->SetArg(1,aStates->GetCurrectState().at(1));
630 // aStates->IncrementState();
632 // else if(aMethod == "SetMaxElementVolume" && aStates->GetCurrectState().size() >= 3) {
633 // if(!aStates->GetCurrectState().at(2).IsEmpty() )
634 // aCmd->SetArg(1,aStates->GetCurrectState().at(2));
635 // aStates->IncrementState();
637 // else if(aMethod == "LengthFromEdges" || aMethod == "LengthFromFaces"){
638 // aStates->IncrementState();
644 // treat Netgen hypotheses;
645 // this (and above) code can work wrong since nb of states can differ from nb of
646 // dumped calls due to the fix of
647 // issue 0021364:: Dump of netgen parameters has duplicate lines
648 SMESH_Gen_i * aGen = SMESH_Gen_i::GetSMESHGen();
649 SALOMEDS::Study_var aStudy = aGen->GetCurrentStudy();
650 SALOMEDS::SObject_wrap sobj = aStudy->FindObjectID( (*it).first.ToCString() );
651 CORBA::Object_var obj = aGen->SObjectToObject( sobj );
652 if ( SMESH_Hypothesis_i* h = SMESH::DownCast< SMESH_Hypothesis_i*>( obj ))
654 TState aCurrentState = aStates->GetCurrectState();
655 int argIndex = h->getParamIndex( aMethod, aCurrentState.size() );
656 if ( 0 <= argIndex && argIndex < aCurrentState.size() &&
657 !aCurrentState[argIndex].IsEmpty() )
658 aCmd->SetArg( 1, aCurrentState[argIndex] );
661 aStates->IncrementState();
667 cout << "Object not found" << endl;
670 cout<<"Command after: "<< aCmd->GetString()<<endl;
674 ProcessLayerDistribution();
676 //================================================================================
678 * \brief Private method
680 //================================================================================
681 void SMESH_NoteBook::InitObjectMap()
683 SMESH_Gen_i *aGen = SMESH_Gen_i::GetSMESHGen();
687 SALOMEDS::Study_var aStudy = aGen->GetCurrentStudy();
688 if(aStudy->_is_nil())
691 CORBA::String_var compDataType = aGen->ComponentDataType();
692 SALOMEDS::SObject_wrap aSO = aStudy->FindComponent( compDataType.in() );
693 if(CORBA::is_nil(aSO))
696 SALOMEDS::ChildIterator_wrap Itr = aStudy->NewChildIterator(aSO);
697 CORBA::String_var aParameters;
698 for( Itr->InitEx(true); Itr->More(); Itr->Next())
700 SALOMEDS::SObject_wrap aSObject = Itr->Value();
701 SALOMEDS::GenericAttribute_wrap anAttr;
702 if ( aSObject->FindAttribute( anAttr.inout(), "AttributeString"))
704 SALOMEDS::AttributeString_wrap strAttr = anAttr;
705 aParameters = strAttr->Value();
706 SALOMEDS::ListOfListOfStrings_var aSections = aStudy->ParseVariables(aParameters.in());
708 cout<<"Entry : "<< aSObject->GetID()<<endl;
709 cout<<"aParameters : "<<aParameters<<endl;
711 TCollection_AsciiString anObjType;
712 CORBA::Object_var anObject = SMESH_Gen_i::SObjectToObject(aSObject);
713 SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow(anObject);
714 SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow(anObject);
715 if(!aHyp->_is_nil()) {
716 CORBA::String_var hypName = aHyp->GetName();
717 anObjType = hypName.in();
719 else if (!aMesh->_is_nil() ) {
723 cout<<"The object Type : "<<anObjType<<endl;
724 SMESH_ObjectStates *aState = NULL;
725 if(anObjType == "LayerDistribution")
726 aState = new LayerDistributionStates();
728 aState = new SMESH_ObjectStates(anObjType);
730 for(int i = 0; i < aSections->length(); i++) {
732 SALOMEDS::ListOfStrings aListOfVars = aSections[i];
733 for ( int j = 0; j<aListOfVars.length(); j++)
735 TCollection_AsciiString aVar(aListOfVars[j].in());
736 if(!aVar.IsEmpty() && aStudy->IsVariable(aVar.ToCString())) {
737 aVar.InsertBefore(1, SMESH::TVar::Quote() );
738 aVar.InsertAfter(aVar.Length(), SMESH::TVar::Quote() );
740 aVars.push_back(aVar);
742 cout<<"Variable: '"<<aVar<<"'"<<endl;
745 aState->AddState(aVars);
747 if ( aState->GetAllStates().empty() )
753 CORBA::String_var objID = aSObject->GetID();
754 _objectMap.insert( make_pair(TCollection_AsciiString( objID.in() ), aState ));
760 //================================================================================
764 //================================================================================
765 void SMESH_NoteBook::AddCommand(const TCollection_AsciiString& theString)
768 cout<<theString<<endl;
769 Handle(_pyCommand) aCommand = new _pyCommand( theString, -1);
770 _commands.push_back(aCommand);
772 if ( aCommand->GetMethod() == "GetMeshEditor" ) { // MeshEditor creation
773 myMeshEditors.insert( make_pair( aCommand->GetResultValue(),
774 aCommand->GetObject() ) );
778 //================================================================================
782 //================================================================================
783 void SMESH_NoteBook::ProcessLayerDistribution()
785 // 1) Find all LayerDistribution states
786 vector<LayerDistributionStates*> aLDS;
787 TVariablesMap::const_iterator it = _objectMap.begin();
788 for(;it != _objectMap.end();it++) {
789 LayerDistributionStates* aLDStates = dynamic_cast<LayerDistributionStates*>(((*it).second));
790 if(aLDStates!=NULL) {
791 aLDS.push_back(aLDStates);
798 // 2) Initialize all type of 1D Distribution hypothesis
799 for(int i=0;i<_commands.size();i++){
800 for(int j =0;j < aLDS.size();j++){
801 TCollection_AsciiString aResultValue = _commands[i]->GetResultValue();
802 if(_commands[i]->GetMethod() == "CreateHypothesis" &&
803 aLDS[j]->HasDistribution(aResultValue)){
804 TCollection_AsciiString aType = _commands[i]->GetArg(1);
805 aType.RemoveAll('\'');
806 aLDS[j]->SetDistributionType(aResultValue,aType);
810 // 3) ... and replase variables ...
812 for(int i=0;i<_commands.size();i++){
813 for(int j =0;j < aLDS.size();j++){
814 TCollection_AsciiString anObject = _commands[i]->GetObject();
816 if(aLDS[j]->HasDistribution(anObject)) {
817 TCollection_AsciiString aType = aLDS[j]->GetDistributionType(anObject);
818 TCollection_AsciiString aMethod = _commands[i]->GetMethod();
819 if(aType == "LocalLength") {
820 if(aMethod == "SetLength") {
821 SetVariable(_commands[i], aLDS[j],0,1);
822 aLDS[j]->IncrementState();
824 else if(aMethod == "SetPrecision") {
825 SetVariable(_commands[i], aLDS[j],1,1);
826 aLDS[j]->IncrementState();
830 // Case for NumberOfSegments hypothesis
831 else if(aType == "NumberOfSegments"){
832 if(aMethod == "SetNumberOfSegments") {
833 SetVariable(_commands[i], aLDS[j],0,1);
834 if(aLDS[j]->GetCurrectState().size()==1)
835 aLDS[j]->IncrementState();
837 else if (aMethod == "SetScaleFactor") {
838 SetVariable(_commands[i], aLDS[j],1,1);
839 aLDS[j]->IncrementState();
843 else if( aType == "Deflection1D" ){
844 if(aMethod == "SetDeflection"){
845 SetVariable(_commands[i], aLDS[j],0,1);
846 aLDS[j]->IncrementState();
849 // Case for Arithmetic1D and StartEndLength hypothesis
850 else if(aType == "Arithmetic1D" || aType == "StartEndLength") {
851 if(aMethod == "SetLength") {
852 int anArgNb = (_commands[i]->GetArg(2) == "1") ? 0 : 1;
853 SetVariable(_commands[i], aLDS[j],anArgNb,1);
854 aLDS[j]->IncrementState();
861 //================================================================================
863 * \brief Return result script
865 //================================================================================
866 TCollection_AsciiString SMESH_NoteBook::GetResultScript() const
868 TCollection_AsciiString aResult;
869 for(int i=0;i<_commands.size();i++)
870 aResult+=_commands[i]->GetString()+"\n";
874 //================================================================================
876 * \brief Return value of the variable
878 //================================================================================
879 bool SMESH_NoteBook::GetReal(const TCollection_AsciiString& theVarName, double& theValue)
883 SMESH_Gen_i *aGen = SMESH_Gen_i::GetSMESHGen();
887 SALOMEDS::Study_ptr aStudy = aGen->GetCurrentStudy();
888 if(aStudy->_is_nil())
891 TCollection_AsciiString aVarName = theVarName;
892 aVarName.RemoveAll('\"');
894 if(aVarName.IsEmpty())
897 const char* aName = aVarName.ToCString();
898 if(aStudy->IsVariable(aName) && (aStudy->IsReal(aName) || aStudy->IsInteger(aName))) {
899 theValue = aStudy->GetReal(aName);