Version: 6.3.1

src/SMESH_I/SMESH_NoteBook.cxx

Go to the documentation of this file.
00001 // Copyright (C) 2007-2011  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 
00020 // File      : SMESH_NoteBook.cxx
00021 // Author    : Roman NIKOLAEV
00022 //
00023 #include "SMESH_2smeshpy.hxx"
00024 #include "SMESH_NoteBook.hxx"
00025 #include "SMESH_Gen_i.hxx"
00026 #include "SMESH_PythonDump.hxx"
00027 
00028 #include <Resource_DataMapOfAsciiStringAsciiString.hxx>
00029 #include <TColStd_SequenceOfAsciiString.hxx>
00030 #include <TColStd_HSequenceOfInteger.hxx>
00031 
00032 #include <vector>
00033 #include <string>
00034 
00035 #ifdef _DEBUG_
00036 static int MYDEBUG = 0;
00037 #else
00038 static int MYDEBUG = 0;
00039 #endif
00040 
00041 using namespace std;
00042 
00043 
00044 void SetVariable(Handle(_pyCommand) theCommand,const SMESH_ObjectStates* theStates, int position, int theArgNb);
00045 
00046 //================================================================================
00050 //================================================================================
00051 SMESH_ObjectStates::SMESH_ObjectStates(TCollection_AsciiString theType)
00052 {
00053   _type = theType;
00054   _dumpstate = 0;
00055 }
00056 
00057 //================================================================================
00061 //================================================================================
00062 SMESH_ObjectStates::~SMESH_ObjectStates()
00063 {
00064 }
00065 
00066 //================================================================================
00071 //================================================================================
00072 void SMESH_ObjectStates::AddState(const TState &theState)
00073 {
00074   _states.push_back(theState);
00075 }
00076 
00077 //================================================================================
00082 //================================================================================
00083 TState SMESH_ObjectStates::GetCurrectState() const
00084 {
00085   if(_states.size() > _dumpstate)
00086     return _states[_dumpstate];
00087   TState empty;
00088   return empty;
00089 }
00090 
00091 
00092 //================================================================================
00096 //================================================================================
00097 TAllStates SMESH_ObjectStates::GetAllStates() const
00098 {
00099   return _states;
00100 }
00101 
00102 //================================================================================
00106 //================================================================================
00107 void SMESH_ObjectStates::IncrementState()
00108 {
00109   _dumpstate++;
00110 }
00111 
00112 //================================================================================
00116 //================================================================================
00117 TCollection_AsciiString SMESH_ObjectStates::GetObjectType() const{
00118   return _type;
00119 }
00120 
00121 
00122 //================================================================================
00126 //================================================================================
00127 LayerDistributionStates::LayerDistributionStates():
00128   SMESH_ObjectStates("LayerDistribution")
00129 {
00130 }
00131 //================================================================================
00135 //================================================================================
00136 LayerDistributionStates::~LayerDistributionStates()
00137 {
00138 }
00139 
00140 
00141 //================================================================================
00145 //================================================================================
00146 void LayerDistributionStates::AddDistribution(const TCollection_AsciiString& theDistribution)
00147 {
00148   _distributions.insert(pair<TCollection_AsciiString,TCollection_AsciiString>(theDistribution,""));
00149 }
00150 
00151 //================================================================================
00155 //================================================================================
00156 bool LayerDistributionStates::HasDistribution(const TCollection_AsciiString& theDistribution) const
00157 {
00158   return _distributions.find(theDistribution) != _distributions.end();
00159 }
00160 
00161 //================================================================================
00165 //================================================================================
00166 bool LayerDistributionStates::SetDistributionType(const TCollection_AsciiString& theDistribution,
00167                                                   const TCollection_AsciiString& theType)
00168 {
00169   TDistributionMap::iterator it = _distributions.find(theDistribution);
00170   if(it == _distributions.end())
00171     return false;
00172   (*it).second = theType;
00173   return true;
00174 }
00175 
00176 //================================================================================
00180 //================================================================================
00181 TCollection_AsciiString LayerDistributionStates::
00182 GetDistributionType(const TCollection_AsciiString& theDistribution) const
00183 {
00184   TDistributionMap::const_iterator it = _distributions.find(theDistribution);
00185   return (it == _distributions.end()) ? TCollection_AsciiString() : (*it).second;
00186 }
00187 
00188 //================================================================================
00192 //================================================================================
00193 SMESH_NoteBook::SMESH_NoteBook()
00194 {
00195   InitObjectMap();
00196 }
00197 
00198 //================================================================================
00202 //================================================================================
00203 SMESH_NoteBook::~SMESH_NoteBook()
00204 {
00205   TVariablesMap::const_iterator it = _objectMap.begin();
00206   for(;it!=_objectMap.end();it++) {
00207     if((*it).second)
00208       delete (*it).second;
00209   }
00210 }
00211 
00212 //================================================================================
00218 //================================================================================
00219 void SMESH_NoteBook::ReplaceVariables()
00220 {
00221   for(int i=0;i<_commands.size();i++) {
00222     Handle(_pyCommand) aCmd = _commands[i];
00223     TCollection_AsciiString aMethod = aCmd->GetMethod();
00224     TCollection_AsciiString aObject = aCmd->GetObject();
00225     TCollection_AsciiString aResultValue = aCmd->GetResultValue();
00226     if(MYDEBUG) {
00227       cout<<"Command before : "<< aCmd->GetString()<<endl;
00228       cout<<"Method : "<< aMethod<<endl;
00229       cout<<"Object : "<< aObject<<endl;
00230       cout<<"Result : "<< aResultValue<<endl;
00231     }
00232     
00233     // check if method modifies the object itself
00234     TVariablesMap::const_iterator it = _objectMap.find(aObject);
00235     if(it == _objectMap.end()) // check if method returns a new object
00236       it = _objectMap.find(aResultValue);
00237     
00238     if(it == _objectMap.end()) { // check if method modifies a mesh using mesh editor
00239       TMeshEditorMap::const_iterator meIt = myMeshEditors.find(aObject);
00240       if(meIt != myMeshEditors.end()) {
00241         TCollection_AsciiString aMesh = (*meIt).second;
00242         it = _objectMap.find(aMesh);
00243       }
00244     }
00245     
00246     if(it == _objectMap.end()) { // additional check for pattern mapping
00247       if(aMethod.IsEqual("ApplyToMeshFaces") ||
00248          aMethod.IsEqual("ApplyToHexahedrons"))
00249         it = _objectMap.find(aCmd->GetArg(1));
00250     }
00251     
00252     if(it != _objectMap.end()) {
00253       if(MYDEBUG)
00254         cout << "Found object : " << (*it).first << endl;
00255       SMESH_ObjectStates *aStates = (*it).second;
00256       // Case for LocalLength hypothesis
00257       if(aStates->GetObjectType().IsEqual("LocalLength") && aStates->GetCurrectState().size() >= 2) {
00258         if(aMethod.IsEqual("SetLength")) {
00259           if(!aStates->GetCurrectState().at(0).IsEmpty() )
00260             aCmd->SetArg(1,aStates->GetCurrectState().at(0));
00261           aStates->IncrementState();
00262         }
00263         else if(aMethod.IsEqual("SetPrecision")) {
00264           if(!aStates->GetCurrectState().at(1).IsEmpty() )
00265             aCmd->SetArg(1,aStates->GetCurrectState().at(1));
00266           aStates->IncrementState();
00267         }
00268       }
00269       
00270       // Case for SegmentLengthAroundVertex hypothesis
00271       else if(aStates->GetObjectType().IsEqual("SegmentLengthAroundVertex")
00272               && aStates->GetCurrectState().size() >= 1) {
00273         if(aMethod == "SetLength") {
00274           if(!aStates->GetCurrectState().at(0).IsEmpty() )
00275             aCmd->SetArg(1,aStates->GetCurrectState().at(0));
00276           aStates->IncrementState();
00277         }
00278       }
00279 
00280       // Case for Arithmetic1D and StartEndLength hypothesis
00281       else if(aStates->GetObjectType().IsEqual("Arithmetic1D") || 
00282               aStates->GetObjectType().IsEqual("StartEndLength")) {
00283         if(aMethod == "SetLength" &&
00284            aStates->GetCurrectState().size() >= 2) {
00285           if(aCmd->GetArg(2) == "1" && !aStates->GetCurrectState().at(0).IsEmpty())
00286             aCmd->SetArg(1,aStates->GetCurrectState().at(0));
00287           else if(!aStates->GetCurrectState().at(1).IsEmpty())
00288             aCmd->SetArg(1,aStates->GetCurrectState().at(1));
00289           aStates->IncrementState();
00290         }
00291       }
00292       
00293       //Case for Deflection1D hypothesis
00294       else if(aStates->GetObjectType().IsEqual("Deflection1D")){
00295         if(aMethod == "SetDeflection" && aStates->GetCurrectState().size() >= 1) {
00296           if(!aStates->GetCurrectState().at(0).IsEmpty() )
00297             aCmd->SetArg(1,aStates->GetCurrectState().at(0));
00298           aStates->IncrementState();
00299         }
00300       }
00301       
00302       // Case for LayerDistribution hypothesis (not finished yet)
00303       else if(aStates->GetObjectType() == "LayerDistribution") {
00304         if(aMethod == "SetLayerDistribution"){
00305           LayerDistributionStates* aLDStates = (LayerDistributionStates*)(aStates);
00306           aLDStates->AddDistribution(aCmd->GetArg(1));
00307           if(MYDEBUG)
00308             cout<<"Add Distribution :"<<aCmd->GetArg(1)<<endl;
00309         }
00310       }
00311       
00312       // Case for MaxElementArea hypothesis
00313       else if(aStates->GetObjectType().IsEqual("MaxElementArea")){
00314         if(aMethod == "SetMaxElementArea" && aStates->GetCurrectState().size() >= 1) {
00315           if(!aStates->GetCurrectState().at(0).IsEmpty() )
00316             aCmd->SetArg(1,aStates->GetCurrectState().at(0));
00317           aStates->IncrementState();
00318         }
00319       }
00320 
00321       // Case for MaxElementVolume hypothesis
00322       else if(aStates->GetObjectType().IsEqual("MaxElementVolume")){
00323         if(aMethod == "SetMaxElementVolume" && aStates->GetCurrectState().size() >= 1) {
00324           if(!aStates->GetCurrectState().at(0).IsEmpty() )
00325             aCmd->SetArg(1,aStates->GetCurrectState().at(0));
00326           aStates->IncrementState();
00327         }
00328       }
00329 
00330       // Case for NETGEN_Parameters_2D or NETGEN_Parameters_2D hypothesis
00331       else if(aStates->GetObjectType().IsEqual("NETGEN_Parameters_2D") ||
00332               aStates->GetObjectType().IsEqual("NETGEN_Parameters")){
00333         if(aMethod == "SetMaxSize" && aStates->GetCurrectState().size() >= 1) {
00334           if(!aStates->GetCurrectState().at(0).IsEmpty() )
00335             aCmd->SetArg(1,aStates->GetCurrectState().at(0));
00336           aStates->IncrementState();
00337         }
00338         else if(aMethod == "SetGrowthRate" && aStates->GetCurrectState().size() >= 2) {
00339           if(!aStates->GetCurrectState().at(1).IsEmpty() )
00340             aCmd->SetArg(1,aStates->GetCurrectState().at(1));
00341           aStates->IncrementState();
00342         }
00343         else if(aMethod == "SetNbSegPerEdge" && aStates->GetCurrectState().size() >= 3) {
00344           if(!aStates->GetCurrectState().at(2).IsEmpty() )
00345             aCmd->SetArg(1,aStates->GetCurrectState().at(2));
00346           aStates->IncrementState();
00347         } 
00348         else if(aMethod == "SetNbSegPerRadius" && aStates->GetCurrectState().size() >= 4) {
00349           if(!aStates->GetCurrectState().at(3).IsEmpty() )
00350             aCmd->SetArg(1,aStates->GetCurrectState().at(3));
00351           aStates->IncrementState();
00352         } 
00353       }
00354 
00355       // Case for NETGEN_SimpleParameters_3D or NETGEN_SimpleParameters_2D hypothesis
00356       else if(aStates->GetObjectType().IsEqual("NETGEN_SimpleParameters_3D") ||
00357               aStates->GetObjectType().IsEqual("NETGEN_SimpleParameters_2D")){
00358 
00359         if((aMethod == "SetNumberOfSegments" || aMethod == "SetLocalLength") && 
00360            aStates->GetCurrectState().size() >= 1) {
00361           if(!aStates->GetCurrectState().at(0).IsEmpty() )
00362             aCmd->SetArg(1,aStates->GetCurrectState().at(0));
00363           aStates->IncrementState();
00364         }
00365         else if(aMethod == "SetMaxElementArea" && aStates->GetCurrectState().size() >= 2) {
00366           if(!aStates->GetCurrectState().at(1).IsEmpty() )
00367             aCmd->SetArg(1,aStates->GetCurrectState().at(1));
00368           aStates->IncrementState();
00369         }
00370         else if(aMethod == "SetMaxElementVolume" && aStates->GetCurrectState().size() >= 3) {
00371           if(!aStates->GetCurrectState().at(2).IsEmpty() )
00372             aCmd->SetArg(1,aStates->GetCurrectState().at(2));
00373           aStates->IncrementState();
00374         }
00375         else if(aMethod == "LengthFromEdges" || aMethod == "LengthFromFaces"){
00376           aStates->IncrementState();
00377         }
00378       }
00379       
00380       // Case for NumberOfLayers hypothesis
00381       else if(aStates->GetObjectType().IsEqual("NumberOfLayers")){
00382         if(aMethod == "SetNumberOfLayers" && aStates->GetCurrectState().size() >= 1) {
00383           if(!aStates->GetCurrectState().at(0).IsEmpty() )
00384             aCmd->SetArg(1,aStates->GetCurrectState().at(0));
00385           aStates->IncrementState();
00386         }
00387       }
00388 
00389       // Case for NumberOfSegments hypothesis
00390       else if(aStates->GetObjectType().IsEqual("NumberOfSegments")){
00391         if(aMethod == "SetNumberOfSegments" && aStates->GetCurrectState().size() >= 1) {
00392           if(!aStates->GetCurrectState().at(0).IsEmpty() )
00393             aCmd->SetArg(1,aStates->GetCurrectState().at(0));
00394           if(aStates->GetCurrectState().size()==1)
00395             aStates->IncrementState();
00396         }
00397         else if (aMethod == "SetScaleFactor" && aStates->GetCurrectState().size() >= 2) {
00398           if(!aStates->GetCurrectState().at(1).IsEmpty() )
00399             aCmd->SetArg(1,aStates->GetCurrectState().at(1));
00400           aStates->IncrementState();
00401         }
00402       }
00403       
00404       else if(aStates->GetObjectType().IsEqual("Mesh")) {
00405         TState aCurrentState = aStates->GetCurrectState();
00406         int aCurrentStateSize = aCurrentState.size();
00407         if(aMethod.IsEqual("Translate")                  ||
00408            aMethod.IsEqual("TranslateMakeGroups")        ||
00409            aMethod.IsEqual("TranslateMakeMesh")          ||
00410            aMethod.IsEqual("TranslateObject")            ||
00411            aMethod.IsEqual("TranslateObjectMakeGroups")  ||
00412            aMethod.IsEqual("TranslateObjectMakeMesh")) {
00413           bool isVariableFound = false;
00414           int anArgIndex = 0;
00415           for(int i = 1, n = aCmd->GetNbArgs(); i <= n; i++) {
00416             if(aCmd->GetArg(i).IsEqual("SMESH.PointStruct")) {
00417               anArgIndex = i+1;
00418               break;
00419             }
00420           }
00421           if(anArgIndex > 0) {
00422             if(aCurrentStateSize == 3) { // translation by dx, dy, dz
00423               for(int j = 0; j < aCurrentStateSize; j++) {
00424                 if(!aCurrentState.at(j).IsEmpty()) {
00425                   isVariableFound = true;
00426                   aCmd->SetArg(anArgIndex+j, aCurrentState.at(j));
00427                 }
00428               }
00429             }
00430             else if(aCurrentStateSize == 6) { // translation by x1, x2, y1, y2, z1, z2
00431               // TODO: limitation until operations on the variables will be introduced
00432               /*
00433               isVariableFound = true;
00434               for(int j = 0; j < 3; j++) {
00435                 TCollection_AsciiString anArg = aCmd->GetArg(anArgIndex+j);
00436                 TCollection_AsciiString aValue1 = aCurrentState.at(2*j), aValue2 = aCurrentState.at(2*j+1);
00437                 bool aV1 = !aValue1.IsEmpty();
00438                 bool aV2 = !aValue2.IsEmpty();
00439                 double aValue, aCurrentValue = anArg.IsRealValue() ? anArg.RealValue() : 0;
00440                 if(aV1 && !aV2) {
00441                   if(!GetReal(aValue1, aValue))
00442                     aValue = 0;
00443                   aValue2 = TCollection_AsciiString( aValue + aCurrentValue );
00444                 }
00445                 else if(!aV1 && aV2) {
00446                   if(!GetReal(aValue2, aValue))
00447                     aValue = 0;
00448                   aValue1 = TCollection_AsciiString( aValue - aCurrentValue );
00449                 }
00450                 else if(!aV1 && !aV2) {
00451                   aValue1 = TCollection_AsciiString( 0 );
00452                   aValue2 = TCollection_AsciiString( aCurrentValue );
00453                 }
00454                 aCmd->SetArg(anArgIndex+j, aValue1 + ", " + aValue2 );
00455               }
00456               */
00457             }
00458           }
00459           if(isVariableFound) {
00460             TCollection_AsciiString aDim;
00461             if(aCurrentStateSize == 6)
00462               aDim = "6";
00463             aCmd->SetArg(anArgIndex - 1, TCollection_AsciiString(SMESH_2smeshpy::SmeshpyName())+".PointStructStr"+aDim);
00464             aCmd->SetArg(anArgIndex - 2, TCollection_AsciiString(SMESH_2smeshpy::SmeshpyName())+".DirStructStr");
00465           }
00466           aStates->IncrementState();
00467         }
00468         else if(aMethod.IsEqual("Rotate")                  ||
00469                 aMethod.IsEqual("RotateMakeGroups")        ||
00470                 aMethod.IsEqual("RotateMakeMesh")          ||
00471                 aMethod.IsEqual("RotateObject")            ||
00472                 aMethod.IsEqual("RotateObjectMakeGroups")  ||
00473                 aMethod.IsEqual("RotateObjectMakeMesh")    ||
00474                 aMethod.IsEqual("RotationSweep")           ||
00475                 aMethod.IsEqual("RotationSweepObject")     ||
00476                 aMethod.IsEqual("RotationSweepObject1D")   ||
00477                 aMethod.IsEqual("RotationSweepObject2D")   ||
00478                 aMethod.IsEqual("RotationSweepMakeGroups") ||
00479                 aMethod.IsEqual("RotationSweepObjectMakeGroups") ||
00480                 aMethod.IsEqual("RotationSweepObject1DMakeGroups") ||
00481                 aMethod.IsEqual("RotationSweepObject2DMakeGroups") ||
00482                 aMethod.IsEqual("Mirror")                  ||
00483                 aMethod.IsEqual("MirrorMakeMesh")          ||
00484                 aMethod.IsEqual("MirrorMakeGroups")        ||
00485                 aMethod.IsEqual("MirrorObject")            || 
00486                 aMethod.IsEqual("MirrorObjectMakeMesh")    ||
00487                 aMethod.IsEqual("MirrorObjectMakeGroups")) {
00488           bool isSubstitute = false;
00489           int anArgIndex = 0;
00490           for(int i = 1, n = aCmd->GetNbArgs(); i <= n; i++) {
00491             if(aCmd->GetArg(i).IsEqual("SMESH.AxisStruct")) {
00492               anArgIndex = i+1;
00493               break;
00494             }
00495           }
00496           if(anArgIndex > 0) {
00497             for(int j = 0; j < aCurrentStateSize; j++) {
00498               if(!aCurrentState.at(j).IsEmpty()) {
00499                 if(j < 6) // 0-5 - axis struct, 6 - angle (rotation & sweep), 7-8 - nbSteps and tolerance (sweep)
00500                   isSubstitute = true;
00501                 aCmd->SetArg(anArgIndex+j, aCurrentState.at(j));
00502               }
00503             }
00504           }
00505           if(isSubstitute)
00506             aCmd->SetArg(anArgIndex - 1, TCollection_AsciiString(SMESH_2smeshpy::SmeshpyName())+".AxisStructStr");
00507           aStates->IncrementState();
00508         }
00509         else if(aMethod.IsEqual("AddNode") ||
00510                 aMethod.IsEqual("MoveClosestNodeToPoint")) {
00511           for(int j = 0; j < aCurrentStateSize; j++) {
00512             if(!aCurrentState.at(j).IsEmpty())
00513               aCmd->SetArg(j+1, aCurrentState.at(j));
00514           }
00515           aStates->IncrementState();
00516         }
00517         else if(aMethod.IsEqual("MoveNode")) {
00518           for(int j = 0; j < aCurrentStateSize; j++) {
00519             if(!aCurrentState.at(j).IsEmpty())
00520               aCmd->SetArg(j+2, aCurrentState.at(j));
00521           }
00522           aStates->IncrementState();
00523         }
00524         else if(aMethod.IsEqual("ExtrusionSweep") ||
00525                 aMethod.IsEqual("ExtrusionSweepObject") ||
00526                 aMethod.IsEqual("ExtrusionSweepObject1D") ||
00527                 aMethod.IsEqual("ExtrusionSweepObject2D") ||
00528                 aMethod.IsEqual("ExtrusionSweepMakeGroups") ||
00529                 aMethod.IsEqual("ExtrusionSweepObjectMakeGroups") ||
00530                 aMethod.IsEqual("ExtrusionSweepObject1DMakeGroups") ||
00531                 aMethod.IsEqual("ExtrusionSweepObject2DMakeGroups")) {
00532           bool isSubstitute = false;
00533           int anArgIndex = 0;
00534           for(int i = 1, n = aCmd->GetNbArgs(); i <= n; i++) {
00535             if(aCmd->GetArg(i).IsEqual("SMESH.PointStruct")) {
00536               anArgIndex = i+1;
00537               break;
00538             }
00539           }
00540           if(anArgIndex > 0) {
00541             for(int j = 0; j < aCurrentStateSize; j++) {
00542               if(!aCurrentState.at(j).IsEmpty()) {
00543                 if(j < 3) // 0-2 - dir struct, 3 - number of steps
00544                   isSubstitute = true;
00545                 aCmd->SetArg(anArgIndex+j, aCurrentState.at(j));
00546               }
00547             }
00548           }
00549           if(isSubstitute) {
00550             aCmd->SetArg(anArgIndex - 1, TCollection_AsciiString(SMESH_2smeshpy::SmeshpyName())+".PointStructStr");
00551             aCmd->SetArg(anArgIndex - 2, TCollection_AsciiString(SMESH_2smeshpy::SmeshpyName())+".DirStructStr");
00552           }
00553           aStates->IncrementState();
00554         }
00555         else if(aMethod.IsEqual("ExtrusionAlongPath") ||
00556                 aMethod.IsEqual("ExtrusionAlongPathObject") ||
00557                 aMethod.IsEqual("ExtrusionAlongPathObject1D") ||
00558                 aMethod.IsEqual("ExtrusionAlongPathObject2D") ||
00559                 aMethod.IsEqual("ExtrusionAlongPathMakeGroups") ||
00560                 aMethod.IsEqual("ExtrusionAlongPathObjectMakeGroups") ||
00561                 aMethod.IsEqual("ExtrusionAlongPathObject1DMakeGroups") ||
00562                 aMethod.IsEqual("ExtrusionAlongPathObject2DMakeGroups") ||
00563                 /* workaround for a bug in the command parsing algorithm */
00564                 aCmd->GetString().Search("ExtrusionAlongPathMakeGroups") != -1 ||
00565                 aCmd->GetString().Search("ExtrusionAlongPathObjectMakeGroups") != -1 ||
00566                 aCmd->GetString().Search("ExtrusionAlongPathObject1DMakeGroups") != -1 ||
00567                 aCmd->GetString().Search("ExtrusionAlongPathObject2DMakeGroups") != -1 ) {
00568           int aNbAngles = aCurrentStateSize-3; // State looks like "Angle1:...:AngleN:X:Y:Z"
00569           bool isSubstitute = false;
00570           int anArgIndex = 0;
00571           for(int i = 1, n = aCmd->GetNbArgs(); i <= n; i++) {
00572             if(aCmd->GetArg(i).IsEqual("SMESH.PointStruct")) {
00573               anArgIndex = i-1-aNbAngles;
00574               break;
00575             }
00576           }
00577           if(anArgIndex > 0) {
00578             int j = 0;
00579             for(; j < aNbAngles; j++) {
00580               if(!aCurrentState.at(j).IsEmpty()) {
00581                 aCmd->SetArg(anArgIndex+j-1, aCurrentState.at(j));
00582               }
00583             }
00584             for(; j < aNbAngles+3; j++) {
00585               if(!aCurrentState.at(j).IsEmpty()) {
00586                 isSubstitute = true;
00587                 aCmd->SetArg(anArgIndex+j+2, aCurrentState.at(j));
00588               }
00589             }
00590           }
00591           if(isSubstitute)
00592             aCmd->SetArg(anArgIndex + aNbAngles + 1,
00593                          TCollection_AsciiString(SMESH_2smeshpy::SmeshpyName())+".PointStructStr");
00594           aStates->IncrementState();
00595         }
00596         else if(aMethod.IsEqual("TriToQuad") ||
00597                 aMethod.IsEqual("Concatenate") ||
00598                 aMethod.IsEqual("ConcatenateWithGroups")) {
00599           if(aCurrentStateSize && !aCurrentState.at(0).IsEmpty())
00600             aCmd->SetArg(aCmd->GetNbArgs(), aCurrentState.at(0));
00601           aStates->IncrementState();
00602         }
00603         else if(aMethod.IsEqual("Smooth") ||
00604                 aMethod.IsEqual("SmoothObject") ||
00605                 aMethod.IsEqual("SmoothParametric") ||
00606                 aMethod.IsEqual("SmoothParametricObject")) {
00607           int anArgIndex = aCmd->GetNbArgs() - 2;
00608           for(int j = 0; j < aCurrentStateSize; j++) {
00609             if(!aCurrentState.at(j).IsEmpty())
00610               aCmd->SetArg(anArgIndex+j, aCurrentState.at(j));
00611           }
00612           aStates->IncrementState();
00613         }
00614         else if(aMethod.IsEqual("ApplyToMeshFaces") ||
00615                 aMethod.IsEqual("ApplyToHexahedrons")) {
00616           int anArgIndex = aCmd->GetNbArgs()-1;
00617           for(int j = 0; j < aCurrentStateSize; j++)
00618             if(!aCurrentState.at(j).IsEmpty())
00619               aCmd->SetArg(anArgIndex+j, aCurrentState.at(j));
00620           aStates->IncrementState();
00621         }
00622       }
00623     }
00624     else {
00625       if(MYDEBUG)
00626         cout << "Object not found" << endl;
00627     }
00628     if(MYDEBUG) {
00629       cout<<"Command after: "<< aCmd->GetString()<<endl;
00630     }
00631   }
00632   
00633   ProcessLayerDistribution();
00634 }
00635 //================================================================================
00639 //================================================================================
00640 void SMESH_NoteBook::InitObjectMap()
00641 {
00642   SMESH_Gen_i *aGen = SMESH_Gen_i::GetSMESHGen();
00643   if(!aGen)
00644     return;
00645   
00646   SALOMEDS::Study_ptr aStudy = aGen->GetCurrentStudy();
00647   if(aStudy->_is_nil())
00648     return;
00649   
00650   SALOMEDS::SObject_var aSO = aStudy->FindComponent(aGen->ComponentDataType());
00651   if(CORBA::is_nil(aSO))
00652     return;
00653   
00654   SALOMEDS::ChildIterator_var Itr = aStudy->NewChildIterator(aSO);
00655   char* aParameters;
00656   for(Itr->InitEx(true); Itr->More(); Itr->Next()) {
00657     SALOMEDS::SObject_var aSObject = Itr->Value();
00658     SALOMEDS::GenericAttribute_var anAttr;
00659     if ( aSObject->FindAttribute(anAttr, "AttributeString")) {
00660       aParameters = SALOMEDS::AttributeString::_narrow(anAttr)->Value();
00661       SALOMEDS::ListOfListOfStrings_var aSections = aStudy->ParseVariables(aParameters);
00662       if(MYDEBUG) {
00663         cout<<"Entry : "<< aSObject->GetID()<<endl;
00664         cout<<"aParameters : "<<aParameters<<endl;
00665       }      
00666       TCollection_AsciiString anObjType;
00667       CORBA::Object_var anObject = SMESH_Gen_i::SObjectToObject(aSObject);
00668       SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow(anObject);
00669       if(!aHyp->_is_nil()) {
00670         anObjType = TCollection_AsciiString(aHyp->GetName());
00671       }
00672       else if(SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow(anObject)) {
00673         anObjType = TCollection_AsciiString("Mesh");
00674       }
00675       if(MYDEBUG)
00676         cout<<"The object Type : "<<anObjType<<endl;
00677       SMESH_ObjectStates *aState = NULL;
00678       if(anObjType == "LayerDistribution") {
00679         aState = new LayerDistributionStates();
00680       }
00681       else
00682         aState = new  SMESH_ObjectStates(anObjType);
00683       
00684       for(int i = 0; i < aSections->length(); i++) {
00685         TState aVars;
00686         SALOMEDS::ListOfStrings aListOfVars = aSections[i];
00687         for(int j = 0;j<aListOfVars.length();j++) {
00688           TCollection_AsciiString aVar(aListOfVars[j].in());
00689           if(!aVar.IsEmpty() && aStudy->IsVariable(aVar.ToCString())) {
00690             aVar.InsertBefore(1,"\"");
00691             aVar.InsertAfter(aVar.Length(),"\"");
00692           }
00693           aVars.push_back(aVar);
00694           if(MYDEBUG) {
00695             cout<<"Variable: '"<<aVar<<"'"<<endl;
00696           }
00697         }
00698         aState->AddState(aVars);
00699       }
00700       _objectMap.insert(pair<TCollection_AsciiString,SMESH_ObjectStates*>(TCollection_AsciiString(aSObject->GetID()),aState));
00701     }
00702   }
00703 }
00704 
00705 //================================================================================
00709 //================================================================================
00710 void SMESH_NoteBook::AddCommand(const TCollection_AsciiString& theString)
00711 {
00712   if(MYDEBUG)
00713     cout<<theString<<endl;
00714   Handle(_pyCommand) aCommand = new _pyCommand( theString, -1);
00715   _commands.push_back(aCommand);
00716 
00717   if ( aCommand->GetMethod() == "GetMeshEditor" ) { // MeshEditor creation
00718     myMeshEditors.insert( make_pair( aCommand->GetResultValue(),
00719                                      aCommand->GetObject() ) );
00720   }
00721 }
00722 
00723 //================================================================================
00727 //================================================================================
00728 void SMESH_NoteBook::ProcessLayerDistribution()
00729 {
00730   // 1) Find all LayerDistribution states
00731   vector<LayerDistributionStates*> aLDS;
00732   TVariablesMap::const_iterator it = _objectMap.begin();
00733   for(;it != _objectMap.end();it++) {
00734     LayerDistributionStates* aLDStates = dynamic_cast<LayerDistributionStates*>(((*it).second));
00735     if(aLDStates!=NULL) {
00736       aLDS.push_back(aLDStates);
00737     }
00738   }
00739   
00740   if(!aLDS.size())
00741     return;
00742   
00743   // 2) Initialize all type of 1D Distribution hypothesis
00744   for(int i=0;i<_commands.size();i++){
00745     for(int j =0;j < aLDS.size();j++){
00746       TCollection_AsciiString aResultValue = _commands[i]->GetResultValue();
00747       if(_commands[i]->GetMethod() == "CreateHypothesis" &&
00748          aLDS[j]->HasDistribution(aResultValue)){
00749         TCollection_AsciiString aType = _commands[i]->GetArg(1);
00750         aType.RemoveAll('\'');
00751         aLDS[j]->SetDistributionType(aResultValue,aType);
00752       }
00753     }
00754   }
00755   // 3) ... and replase variables ...
00756 
00757   for(int i=0;i<_commands.size();i++){
00758     for(int j =0;j < aLDS.size();j++){
00759       TCollection_AsciiString anObject = _commands[i]->GetObject();
00760 
00761       if(aLDS[j]->HasDistribution(anObject)) {
00762         TCollection_AsciiString aType = aLDS[j]->GetDistributionType(anObject);
00763         TCollection_AsciiString aMethod = _commands[i]->GetMethod();
00764         if(aType == "LocalLength") {
00765           if(aMethod == "SetLength") {
00766             SetVariable(_commands[i], aLDS[j],0,1);
00767             aLDS[j]->IncrementState();
00768           }
00769           else if(aMethod == "SetPrecision") {
00770             SetVariable(_commands[i], aLDS[j],1,1);
00771             aLDS[j]->IncrementState();
00772           }
00773         }
00774 
00775         // Case for NumberOfSegments hypothesis
00776         else if(aType == "NumberOfSegments"){
00777           if(aMethod == "SetNumberOfSegments") {
00778             SetVariable(_commands[i], aLDS[j],0,1);
00779             if(aLDS[j]->GetCurrectState().size()==1)
00780               aLDS[j]->IncrementState();
00781           }
00782           else if (aMethod == "SetScaleFactor") {
00783             SetVariable(_commands[i], aLDS[j],1,1);
00784             aLDS[j]->IncrementState();
00785           }
00786         }
00787         
00788         else if( aType == "Deflection1D" ){
00789           if(aMethod == "SetDeflection"){
00790             SetVariable(_commands[i], aLDS[j],0,1);
00791             aLDS[j]->IncrementState();
00792           }
00793         }
00794         // Case for Arithmetic1D and StartEndLength hypothesis
00795         else if(aType == "Arithmetic1D" || aType == "StartEndLength") {
00796           if(aMethod == "SetLength") {
00797             int anArgNb = (_commands[i]->GetArg(2) == "1") ? 0 : 1;
00798             SetVariable(_commands[i], aLDS[j],anArgNb,1);
00799             aLDS[j]->IncrementState();
00800           }
00801         }
00802       }
00803     }
00804   }
00805 }
00806 //================================================================================
00810 //================================================================================
00811 TCollection_AsciiString SMESH_NoteBook::GetResultScript() const
00812 {
00813   TCollection_AsciiString aResult;
00814   for(int i=0;i<_commands.size();i++)
00815     aResult+=_commands[i]->GetString()+"\n";
00816   return aResult;
00817 }
00818 
00819 //================================================================================
00823 //================================================================================
00824 bool SMESH_NoteBook::GetReal(const TCollection_AsciiString& theVarName, double& theValue)
00825 {
00826   bool ok = false;
00827 
00828   SMESH_Gen_i *aGen = SMESH_Gen_i::GetSMESHGen();
00829   if(!aGen)
00830     return ok;
00831 
00832   SALOMEDS::Study_ptr aStudy = aGen->GetCurrentStudy();
00833   if(aStudy->_is_nil())
00834     return ok;
00835 
00836   TCollection_AsciiString aVarName = theVarName;
00837   aVarName.RemoveAll('\"');
00838 
00839   if(aVarName.IsEmpty())
00840     return ok;
00841 
00842   const char* aName = aVarName.ToCString();
00843   if(aStudy->IsVariable(aName) && (aStudy->IsReal(aName) || aStudy->IsInteger(aName))) {
00844     theValue = aStudy->GetReal(aVarName.ToCString());
00845     ok = true;
00846   }
00847 
00848   return ok;
00849 }
00850 
00851 
00856 void SetVariable(Handle(_pyCommand) theCommand, const SMESH_ObjectStates* theStates, int position, int theArgNb)
00857 {
00858   if(theStates->GetCurrectState().size() > position)
00859     if(!theStates->GetCurrectState().at(position).IsEmpty())
00860       theCommand->SetArg(theArgNb,theStates->GetCurrectState().at(position));
00861 }
Copyright © 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE
Copyright © 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS