From: eap Date: Wed, 7 Mar 2012 15:02:16 +0000 (+0000) Subject: 0021308: Remove hard-coded dependency of the external mesh plugins from the SMESH... X-Git-Tag: V6_5_0a1~74 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=130a2297e9115e5518ec9cb84e6173a674348c20;p=modules%2Fsmesh.git 0021308: Remove hard-coded dependency of the external mesh plugins from the SMESH module Remove explicit treatment of NETGEN commands --- diff --git a/src/SMESH_I/SMESH_NoteBook.cxx b/src/SMESH_I/SMESH_NoteBook.cxx index 179abfc19..072de3be2 100644 --- a/src/SMESH_I/SMESH_NoteBook.cxx +++ b/src/SMESH_I/SMESH_NoteBook.cxx @@ -24,6 +24,7 @@ #include "SMESH_NoteBook.hxx" #include "SMESH_Gen_i.hxx" #include "SMESH_PythonDump.hxx" +#include "SMESH_Hypothesis_i.hxx" #include #include @@ -41,7 +42,21 @@ static int MYDEBUG = 0; using namespace std; -void SetVariable(Handle(_pyCommand) theCommand,const SMESH_ObjectStates* theStates, int position, int theArgNb); +namespace +{ + /*! + * Set variable of the SMESH_ObjectStates from position to the _pyCommand + * method as nbArg argument + */ + void SetVariable(Handle(_pyCommand) theCommand, + const SMESH_ObjectStates* theStates, + int position, int theArgNb) + { + if(theStates->GetCurrectState().size() > position) + if(!theStates->GetCurrectState().at(position).IsEmpty()) + theCommand->SetArg(theArgNb,theStates->GetCurrectState().at(position)); + } +} //================================================================================ /*! @@ -229,7 +244,7 @@ void SMESH_NoteBook::ReplaceVariables() cout<<"Object : "<< aObject<GetArg(1)); } - + if(it != _objectMap.end()) { if(MYDEBUG) cout << "Found object : " << (*it).first << endl; SMESH_ObjectStates *aStates = (*it).second; // Case for LocalLength hypothesis - if(aStates->GetObjectType().IsEqual("LocalLength") && aStates->GetCurrectState().size() >= 2) { + if(aStates->GetObjectType().IsEqual("LocalLength") && aStates->GetCurrectState().size() >= 2) + { if(aMethod.IsEqual("SetLength")) { if(!aStates->GetCurrectState().at(0).IsEmpty() ) aCmd->SetArg(1,aStates->GetCurrectState().at(0)); @@ -326,57 +342,6 @@ void SMESH_NoteBook::ReplaceVariables() aStates->IncrementState(); } } - - // Case for NETGEN_Parameters_2D or NETGEN_Parameters_2D hypothesis - else if(aStates->GetObjectType().IsEqual("NETGEN_Parameters_2D") || - aStates->GetObjectType().IsEqual("NETGEN_Parameters")){ - if(aMethod == "SetMaxSize" && aStates->GetCurrectState().size() >= 1) { - if(!aStates->GetCurrectState().at(0).IsEmpty() ) - aCmd->SetArg(1,aStates->GetCurrectState().at(0)); - aStates->IncrementState(); - } - else if(aMethod == "SetGrowthRate" && aStates->GetCurrectState().size() >= 2) { - if(!aStates->GetCurrectState().at(1).IsEmpty() ) - aCmd->SetArg(1,aStates->GetCurrectState().at(1)); - aStates->IncrementState(); - } - else if(aMethod == "SetNbSegPerEdge" && aStates->GetCurrectState().size() >= 3) { - if(!aStates->GetCurrectState().at(2).IsEmpty() ) - aCmd->SetArg(1,aStates->GetCurrectState().at(2)); - aStates->IncrementState(); - } - else if(aMethod == "SetNbSegPerRadius" && aStates->GetCurrectState().size() >= 4) { - if(!aStates->GetCurrectState().at(3).IsEmpty() ) - aCmd->SetArg(1,aStates->GetCurrectState().at(3)); - aStates->IncrementState(); - } - } - - // Case for NETGEN_SimpleParameters_3D or NETGEN_SimpleParameters_2D hypothesis - else if(aStates->GetObjectType().IsEqual("NETGEN_SimpleParameters_3D") || - aStates->GetObjectType().IsEqual("NETGEN_SimpleParameters_2D")){ - - if((aMethod == "SetNumberOfSegments" || aMethod == "SetLocalLength") && - aStates->GetCurrectState().size() >= 1) { - if(!aStates->GetCurrectState().at(0).IsEmpty() ) - aCmd->SetArg(1,aStates->GetCurrectState().at(0)); - aStates->IncrementState(); - } - else if(aMethod == "SetMaxElementArea" && aStates->GetCurrectState().size() >= 2) { - if(!aStates->GetCurrectState().at(1).IsEmpty() ) - aCmd->SetArg(1,aStates->GetCurrectState().at(1)); - aStates->IncrementState(); - } - else if(aMethod == "SetMaxElementVolume" && aStates->GetCurrectState().size() >= 3) { - if(!aStates->GetCurrectState().at(2).IsEmpty() ) - aCmd->SetArg(1,aStates->GetCurrectState().at(2)); - aStates->IncrementState(); - } - else if(aMethod == "LengthFromEdges" || aMethod == "LengthFromFaces"){ - aStates->IncrementState(); - } - } - // Case for NumberOfLayers hypothesis else if(aStates->GetObjectType().IsEqual("NumberOfLayers")){ if(aMethod == "SetNumberOfLayers" && aStates->GetCurrectState().size() >= 1) { @@ -619,6 +584,79 @@ void SMESH_NoteBook::ReplaceVariables() aCmd->SetArg(anArgIndex+j, aCurrentState.at(j)); aStates->IncrementState(); } + } // if ( aStates->GetObjectType().IsEqual("Mesh")) + + // Case for NETGEN_Parameters_2D or NETGEN_Parameters_2D hypothesis + // else if(aStates->GetObjectType().IsEqual("NETGEN_Parameters_2D") || + // aStates->GetObjectType().IsEqual("NETGEN_Parameters")){ + // if(aMethod == "SetMaxSize" && aStates->GetCurrectState().size() >= 1) { + // if(!aStates->GetCurrectState().at(0).IsEmpty() ) + // aCmd->SetArg(1,aStates->GetCurrectState().at(0)); + // aStates->IncrementState(); + // } + // else if(aMethod == "SetGrowthRate" && aStates->GetCurrectState().size() >= 2) { + // if(!aStates->GetCurrectState().at(1).IsEmpty() ) + // aCmd->SetArg(1,aStates->GetCurrectState().at(1)); + // aStates->IncrementState(); + // } + // else if(aMethod == "SetNbSegPerEdge" && aStates->GetCurrectState().size() >= 3) { + // if(!aStates->GetCurrectState().at(2).IsEmpty() ) + // aCmd->SetArg(1,aStates->GetCurrectState().at(2)); + // aStates->IncrementState(); + // } + // else if(aMethod == "SetNbSegPerRadius" && aStates->GetCurrectState().size() >= 4) { + // if(!aStates->GetCurrectState().at(3).IsEmpty() ) + // aCmd->SetArg(1,aStates->GetCurrectState().at(3)); + // aStates->IncrementState(); + // } + // } + + // // Case for NETGEN_SimpleParameters_3D or NETGEN_SimpleParameters_2D hypothesis + // else if(aStates->GetObjectType().IsEqual("NETGEN_SimpleParameters_3D") || + // aStates->GetObjectType().IsEqual("NETGEN_SimpleParameters_2D")) { + + // if((aMethod == "SetNumberOfSegments" || aMethod == "SetLocalLength") && + // aStates->GetCurrectState().size() >= 1) { + // if(!aStates->GetCurrectState().at(0).IsEmpty() ) + // aCmd->SetArg(1,aStates->GetCurrectState().at(0)); + // aStates->IncrementState(); + // } + // else if(aMethod == "SetMaxElementArea" && aStates->GetCurrectState().size() >= 2) { + // if(!aStates->GetCurrectState().at(1).IsEmpty() ) + // aCmd->SetArg(1,aStates->GetCurrectState().at(1)); + // aStates->IncrementState(); + // } + // else if(aMethod == "SetMaxElementVolume" && aStates->GetCurrectState().size() >= 3) { + // if(!aStates->GetCurrectState().at(2).IsEmpty() ) + // aCmd->SetArg(1,aStates->GetCurrectState().at(2)); + // aStates->IncrementState(); + // } + // else if(aMethod == "LengthFromEdges" || aMethod == "LengthFromFaces"){ + // aStates->IncrementState(); + // } + // } + + else + { + // treat Netgen hypotheses; + // this (and above) code can work wrong since nb of states can differ from nb of + // dumped calls due to the fix of + // issue 0021364:: Dump of netgen parameters has duplicate lines + SMESH_Gen_i *aGen = SMESH_Gen_i::GetSMESHGen(); + SALOMEDS::Study_ptr aStudy = aGen->GetCurrentStudy(); + SALOMEDS::SObject_var sobj = aStudy->FindObjectID( (*it).first.ToCString() ); + CORBA::Object_var obj = aGen->SObjectToObject( sobj ); + if ( SMESH_Hypothesis_i* h = SMESH::DownCast< SMESH_Hypothesis_i*>( obj )) + { + TState aCurrentState = aStates->GetCurrectState(); + int argIndex = h->getParamIndex( aMethod, aCurrentState.size() ); + if ( 0 <= argIndex && argIndex < aCurrentState.size() && + !aCurrentState[argIndex].IsEmpty() ) + aCmd->SetArg( 1, aCurrentState[argIndex] ); + + if ( argIndex >= 0 ) + aStates->IncrementState(); + } } } else { @@ -664,31 +702,32 @@ void SMESH_NoteBook::InitObjectMap() cout<<"aParameters : "<_is_nil()) { - anObjType = TCollection_AsciiString(aHyp->GetName()); + CORBA::String_var hypName = aHyp->GetName(); + anObjType = hypName.in(); } - else if(SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow(anObject)) { - anObjType = TCollection_AsciiString("Mesh"); + else if (!aMesh->_is_nil() ) { + anObjType = "Mesh"; } if(MYDEBUG) cout<<"The object Type : "<length(); i++) { TState aVars; SALOMEDS::ListOfStrings aListOfVars = aSections[i]; for(int j = 0;jIsVariable(aVar.ToCString())) { - aVar.InsertBefore(1,"\""); - aVar.InsertAfter(aVar.Length(),"\""); + aVar.InsertBefore(1, SMESH::TVar::Quote() ); + aVar.InsertAfter(aVar.Length(), SMESH::TVar::Quote() ); } aVars.push_back(aVar); if(MYDEBUG) { @@ -697,7 +736,15 @@ void SMESH_NoteBook::InitObjectMap() } aState->AddState(aVars); } - _objectMap.insert(pair(TCollection_AsciiString(aSObject->GetID()),aState)); + if ( aState->GetAllStates().empty() ) + { + delete aState; + } + else + { + CORBA::String_var objID = aSObject->GetID(); + _objectMap.insert( make_pair(TCollection_AsciiString( objID.in() ), aState )); + } } } } @@ -848,14 +895,3 @@ bool SMESH_NoteBook::GetReal(const TCollection_AsciiString& theVarName, double& return ok; } - -/*! - * Set variable of the SMESH_ObjectStates from position to the _pyCommand - * method as nbArg argument - */ -void SetVariable(Handle(_pyCommand) theCommand, const SMESH_ObjectStates* theStates, int position, int theArgNb) -{ - if(theStates->GetCurrectState().size() > position) - if(!theStates->GetCurrectState().at(position).IsEmpty()) - theCommand->SetArg(theArgNb,theStates->GetCurrectState().at(position)); -} diff --git a/src/SMESH_I/SMESH_NoteBook.hxx b/src/SMESH_I/SMESH_NoteBook.hxx index c30780e01..f861abeaf 100644 --- a/src/SMESH_I/SMESH_NoteBook.hxx +++ b/src/SMESH_I/SMESH_NoteBook.hxx @@ -23,6 +23,10 @@ #ifndef SMESH_NoteBook_HeaderFile #define SMESH_NoteBook_HeaderFile +// All this stuff is obsolete since issue 0021308: +// "Remove hard-coded dependency of the external mesh plugins from the SMESH module" +// is implemented (Mar 2012). It is kept for backward compatibility only. + #include #include @@ -33,7 +37,7 @@ class _pyCommand; typedef std::vector TState; typedef std::vector TAllStates; -typedef TCollection_AsciiString _pyID; +typedef TCollection_AsciiString _pyID; class SMESH_ObjectStates{