From: rnv Date: Thu, 4 Dec 2008 14:48:57 +0000 (+0000) Subject: Dump python extension. X-Git-Tag: TG_DumpPython_Extension_3_1~5 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=044316562025258053dd5cdd512918e98fa55c58;p=modules%2Fsmesh.git Dump python extension. --- diff --git a/idl/SMESH_Hypothesis.idl b/idl/SMESH_Hypothesis.idl index cf226ef9f..0396338ab 100644 --- a/idl/SMESH_Hypothesis.idl +++ b/idl/SMESH_Hypothesis.idl @@ -76,6 +76,18 @@ module SMESH */ ListOfParameters GetLastParameters(); + /*! + * Set list of parameters + * \param theParameters is a string containing the last notebook variables separated by ":" symbol, + * used for Hypothesis creation + */ + void SetLastParameters(in string theParameters); + + /*! + * Clear parameters list + */ + void ClearParameters(); + /*! * Verify whether hypothesis supports given entity type */ diff --git a/src/SMESH/SMESH_Hypothesis.cxx b/src/SMESH/SMESH_Hypothesis.cxx index 0d522463d..4f447be5b 100644 --- a/src/SMESH/SMESH_Hypothesis.cxx +++ b/src/SMESH/SMESH_Hypothesis.cxx @@ -159,7 +159,23 @@ void SMESH_Hypothesis::SetLibName(const char* theLibName) //============================================================================= void SMESH_Hypothesis::SetParameters(const char *theParameters) { - _parameters = string(theParameters); + string aNewParameters(theParameters); + if(aNewParameters.size()==0 && _parameters.size()==0) + aNewParameters = " "; + if(_parameters.size()>0) + _parameters +="|"; + _parameters +=aNewParameters; + SetLastParameters(theParameters); +} + +//============================================================================= +/*! + * + */ +//============================================================================= +void SMESH_Hypothesis::ClearParameters() +{ + _parameters = string(); } //============================================================================= @@ -171,3 +187,23 @@ char* SMESH_Hypothesis::GetParameters() const { return (char*)_parameters.c_str(); } + +//============================================================================= +/*! + * + */ +//============================================================================= +char* SMESH_Hypothesis::GetLastParameters() const +{ + return (char*)_lastParameters.c_str(); +} + +//============================================================================= +/*! + * + */ +//============================================================================= +void SMESH_Hypothesis::SetLastParameters(const char* theParameters) +{ + _lastParameters = string(theParameters); +} diff --git a/src/SMESH/SMESH_Hypothesis.hxx b/src/SMESH/SMESH_Hypothesis.hxx index 2e043186f..f11a51567 100644 --- a/src/SMESH/SMESH_Hypothesis.hxx +++ b/src/SMESH/SMESH_Hypothesis.hxx @@ -71,8 +71,12 @@ public: void SetLibName(const char* theLibName); void SetParameters(const char *theParameters); - char* GetParameters() const; + char* GetParameters() const; + void SetLastParameters(const char* theParameters); + char* GetLastParameters() const; + void ClearParameters(); + /*! * \brief Initialize my parameter values by the mesh built on the geometry * \param theMesh - the built mesh @@ -101,6 +105,7 @@ protected: private: std::string _libName; std::string _parameters; + std::string _lastParameters; }; #endif diff --git a/src/SMESH_I/SMESH_Gen_i_1.cxx b/src/SMESH_I/SMESH_Gen_i_1.cxx index 0eaa31f61..03b6ac968 100644 --- a/src/SMESH_I/SMESH_Gen_i_1.cxx +++ b/src/SMESH_I/SMESH_Gen_i_1.cxx @@ -866,7 +866,7 @@ bool SMESH_Gen_i::RemoveHypothesisFromShape(SALOMEDS::Study_ptr theStudy } //======================================================================= -//function : UpdateSObject +//function : UpdateParameters //purpose : //======================================================================= void SMESH_Gen_i::UpdateParameters(CORBA::Object_ptr theObject, const char* theParameters) @@ -914,7 +914,7 @@ void SMESH_Gen_i::UpdateParameters(CORBA::Object_ptr theObject, const char* theP } //======================================================================= -//function : GetParameters +//function : ParseParameters //purpose : //======================================================================= char* SMESH_Gen_i::ParseParameters(const char* theParameters) @@ -924,14 +924,16 @@ char* SMESH_Gen_i::ParseParameters(const char* theParameters) SALOMEDS::Study_ptr aStudy = GetCurrentStudy(); if( !aStudy->_is_nil() ) { SALOMEDS::ListOfListOfStrings_var aSections = aStudy->ParseVariables(aParameters); - if(aSections->length() > 0) { - SALOMEDS::ListOfStrings aVars= aSections[0]; + for(int j=0;jlength();j++) { + SALOMEDS::ListOfStrings aVars= aSections[j]; for(int i=0;iIsVariable(aVars[i].in()) ? TCollection_AsciiString(aVars[i].in()) : TCollection_AsciiString(""); if(i != aVars.length()-1) anInputParams+=":"; } + if(j!=aSections->length()-1) + anInputParams+="|"; } } return CORBA::string_dup(anInputParams.ToCString()); diff --git a/src/SMESH_I/SMESH_Hypothesis_i.cxx b/src/SMESH_I/SMESH_Hypothesis_i.cxx index a65b84362..2031cdfc0 100644 --- a/src/SMESH_I/SMESH_Hypothesis_i.cxx +++ b/src/SMESH_I/SMESH_Hypothesis_i.cxx @@ -191,7 +191,12 @@ SMESH::ListOfParameters* SMESH_Hypothesis_i::GetLastParameters() SMESH::ListOfParameters_var aResult = new SMESH::ListOfParameters(); SMESH_Gen_i *gen = SMESH_Gen_i::GetSMESHGen(); if(gen) { - char *aParameters = GetParameters(); + char *aParameters; + if(IsPublished()) + aParameters = GetParameters(); + else + aParameters = myBaseImpl->GetLastParameters(); + SALOMEDS::Study_ptr aStudy = gen->GetCurrentStudy(); if(!aStudy->_is_nil()) { SALOMEDS::ListOfListOfStrings_var aSections = aStudy->ParseVariables(aParameters); @@ -206,6 +211,31 @@ SMESH::ListOfParameters* SMESH_Hypothesis_i::GetLastParameters() return aResult._retn(); } +//============================================================================= +/*! + * SMESH_Hypothesis_i::SetLastParameters() + * + */ +//============================================================================= +void SMESH_Hypothesis_i::SetLastParameters(const char* theParameters) +{ + if(!IsPublished()) { + myBaseImpl->SetLastParameters(theParameters); + } +} +//============================================================================= +/*! + * SMESH_Hypothesis_i::ClearParameters() + * + */ +//============================================================================= +void SMESH_Hypothesis_i::ClearParameters() +{ + if(!IsPublished()) { + myBaseImpl->ClearParameters(); + } +} + //============================================================================= /*! * SMESH_Hypothesis_i::GetImpl diff --git a/src/SMESH_I/SMESH_Hypothesis_i.hxx b/src/SMESH_I/SMESH_Hypothesis_i.hxx index e93554ae6..c176aba30 100644 --- a/src/SMESH_I/SMESH_Hypothesis_i.hxx +++ b/src/SMESH_I/SMESH_Hypothesis_i.hxx @@ -75,6 +75,13 @@ public: //Return list of last notebook variables used for Hypothesis creation. SMESH::ListOfParameters* GetLastParameters(); + //Set last parameters for not published hypothesis + + void SetLastParameters(const char* theParameters); + + // Clear parameters list + void ClearParameters(); + //Return true if hypothesis was published in study bool IsPublished(); diff --git a/src/SMESH_I/SMESH_NoteBook.cxx b/src/SMESH_I/SMESH_NoteBook.cxx index ac3ae0c15..91ae27def 100644 --- a/src/SMESH_I/SMESH_NoteBook.cxx +++ b/src/SMESH_I/SMESH_NoteBook.cxx @@ -41,6 +41,7 @@ static int MYDEBUG = 0; using namespace std; +void SetVariable(Handle(_pyCommand) theCommand,const ObjectStates* theStates, int position, int theArgNb); //================================================================================ /*! @@ -295,6 +296,8 @@ void SMESH_NoteBook::ReplaceVariables() if(aMethod == "SetLayerDistribution"){ LayerDistributionStates* aLDStates = (LayerDistributionStates*)(aStates); aLDStates->AddDistribution(aCmd->GetArg(1)); + if(MYDEBUG) + cout<<"Add Distribution :"<GetArg(1)<GetString()< aLDS; TVariablesMap::const_iterator it = _objectMap.begin(); - for(;it != _objectMap.end();it++) - if(LayerDistributionStates* aLDStates = (LayerDistributionStates*)((*it).second)) { + for(;it != _objectMap.end();it++) { + LayerDistributionStates* aLDStates = dynamic_cast(((*it).second)); + if(aLDStates!=NULL) { aLDS.push_back(aLDStates); } + } + + if(!aLDS.size()) + return; // 2) Initialize all type of 1D Distribution hypothesis for(int i=0;i<_commands.size();i++){ @@ -700,13 +710,39 @@ void SMESH_NoteBook::ProcessLayerDistribution() TCollection_AsciiString aMethod = _commands[i]->GetMethod(); if(aType == "LocalLength") { if(aMethod == "SetLength") { - if(!aLDS[j]->GetCurrectState().at(0).IsEmpty() ) - _commands[i]->SetArg(1,aLDS[j]->GetCurrectState().at(0)); + SetVariable(_commands[i], aLDS[j],0,1); aLDS[j]->IncrementState(); } else if(aMethod == "SetPrecision") { - if(!aLDS[j]->GetCurrectState().at(1).IsEmpty() ) - _commands[i]->SetArg(1,aLDS[j]->GetCurrectState().at(1)); + SetVariable(_commands[i], aLDS[j],1,1); + aLDS[j]->IncrementState(); + } + } + + // Case for NumberOfSegments hypothesis + else if(aType == "NumberOfSegments"){ + if(aMethod == "SetNumberOfSegments") { + SetVariable(_commands[i], aLDS[j],0,1); + if(aLDS[j]->GetCurrectState().size()==1) + aLDS[j]->IncrementState(); + } + else if (aMethod == "SetScaleFactor") { + SetVariable(_commands[i], aLDS[j],1,1); + aLDS[j]->IncrementState(); + } + } + + else if( aType == "Deflection1D" ){ + if(aMethod == "SetDeflection"){ + SetVariable(_commands[i], aLDS[j],0,1); + aLDS[j]->IncrementState(); + } + } + // Case for Arithmetic1D and StartEndLength hypothesis + else if(aType == "Arithmetic1D" || aType == "StartEndLength") { + if(aMethod == "SetLength") { + int anArgNb = (_commands[i]->GetArg(2) == "1") ? 0 : 1; + SetVariable(_commands[i], aLDS[j],anArgNb,1); aLDS[j]->IncrementState(); } } @@ -758,3 +794,15 @@ bool SMESH_NoteBook::GetReal(const TCollection_AsciiString& theVarName, double& return ok; } + + +/*! + * Set variable of the ObjectStates from position to the _pyCommand + * method as nbArg argument + */ +void SetVariable(Handle(_pyCommand) theCommand, const 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 5c0d2d7b0..dfeb3b50a 100644 --- a/src/SMESH_I/SMESH_NoteBook.hxx +++ b/src/SMESH_I/SMESH_NoteBook.hxx @@ -41,7 +41,7 @@ class ObjectStates{ public: ObjectStates(TCollection_AsciiString theType); - ~ObjectStates(); + virtual ~ObjectStates(); void AddState(const TState &theState); @@ -63,7 +63,7 @@ class LayerDistributionStates : public ObjectStates public: typedef std::map TDistributionMap; LayerDistributionStates(); - ~LayerDistributionStates(); + virtual ~LayerDistributionStates(); void AddDistribution(const TCollection_AsciiString& theDistribution); bool HasDistribution(const TCollection_AsciiString& theDistribution) const; diff --git a/src/SMESH_SWIG/smeshDC.py b/src/SMESH_SWIG/smeshDC.py index 9d8cfb94c..ff5a6c35f 100644 --- a/src/SMESH_SWIG/smeshDC.py +++ b/src/SMESH_SWIG/smeshDC.py @@ -4350,6 +4350,17 @@ class LocalLength(StdMeshers._objref_StdMeshers_LocalLength): omniORB.registerObjref(StdMeshers._objref_StdMeshers_LocalLength._NP_RepositoryId, LocalLength) +#Wrapper class for StdMeshers_LayerDistribution hypothesis +class LayerDistribution(StdMeshers._objref_StdMeshers_LayerDistribution): + + def SetLayerDistribution(self, hypo): + StdMeshers._objref_StdMeshers_LayerDistribution.SetParameters(self,hypo.GetParameters()) + hypo.ClearParameters(); + StdMeshers._objref_StdMeshers_LayerDistribution.SetLayerDistribution(self,hypo) + +#Registering the new proxy for LayerDistribution +omniORB.registerObjref(StdMeshers._objref_StdMeshers_LayerDistribution._NP_RepositoryId, LayerDistribution) + #Wrapper class for StdMeshers_SegmentLengthAroundVertex hypothesis class SegmentLengthAroundVertex(StdMeshers._objref_StdMeshers_SegmentLengthAroundVertex): @@ -4398,8 +4409,8 @@ omniORB.registerObjref(StdMeshers._objref_StdMeshers_Deflection1D._NP_Repository class StartEndLength(StdMeshers._objref_StdMeshers_StartEndLength): ## Set Length parameter value - # @param length numerical value or name of variable from notebook - # @param isStart true is length is Start Length, otherwise false + # @param length numerical value or name of variable from notebook + # @param isStart true is length is Start Length, otherwise false def SetLength(self, length, isStart): nb = 2 if isStart: diff --git a/src/StdMeshersGUI/StdMeshersGUI_StdHypothesisCreator.cxx b/src/StdMeshersGUI/StdMeshersGUI_StdHypothesisCreator.cxx index c7b62ea14..651d87f33 100644 --- a/src/StdMeshersGUI/StdMeshersGUI_StdHypothesisCreator.cxx +++ b/src/StdMeshersGUI/StdMeshersGUI_StdHypothesisCreator.cxx @@ -488,10 +488,8 @@ QString StdMeshersGUI_StdHypothesisCreator::storeParams() const widget< StdMeshersGUI_LayerDistributionParamWdg >( 0 ); h->SetLayerDistribution( w->GetHypothesis() ); - /* h->SetParameters(w->GetHypothesis()->GetParameters()); - if(QString(w->GetHypothesis()->GetName()) == "LocalLength") - h->SetParameters(w->GetHypothesis()->GetParameters()); - */ + h->SetParameters(w->GetHypothesis()->GetParameters()); + w->GetHypothesis()->ClearParameters(); } else if( hypType()=="ProjectionSource1D" ) { @@ -684,13 +682,13 @@ bool StdMeshersGUI_StdHypothesisCreator::stdParams( ListOfStdParams& p ) const item.myName = tr( "SMESH_LAYERS_DISTRIBUTION" ); p.append( item ); //Set into not published hypo last variables - /* QStringList aLastVarsList; + QStringList aLastVarsList; for(int i = 0;ilength();i++) aLastVarsList.append(QString(aParameters[i].in())); if(!aLastVarsList.isEmpty()) - h->GetLayerDistribution()->SetParameters(SMESHGUI::JoinObjectParameters(aLastVarsList)); - */ + h->GetLayerDistribution()->SetLastParameters(SMESHGUI::JoinObjectParameters(aLastVarsList)); + customWidgets()->append ( new StdMeshersGUI_LayerDistributionParamWdg( h->GetLayerDistribution(), hypName(), dlg())); }