From 882884f6791da81b5ef562741458bc542c45edaf Mon Sep 17 00:00:00 2001 From: rnv Date: Fri, 28 Nov 2008 10:30:11 +0000 Subject: [PATCH] Implementation notebook in the SMESH module. --- src/SMESH/SMESH_Hypothesis.cxx | 21 ++ src/SMESH/SMESH_Hypothesis.hxx | 4 + src/SMESH_I/SMESH_2smeshpy.cxx | 21 +- src/SMESH_I/SMESH_2smeshpy.hxx | 1 - src/SMESH_I/SMESH_Gen_i.hxx | 1 + src/SMESH_I/SMESH_Gen_i_1.cxx | 43 ++- src/SMESH_I/SMESH_Hypothesis_i.cxx | 40 ++- src/SMESH_I/SMESH_Hypothesis_i.hxx | 7 +- src/SMESH_I/SMESH_NoteBook.cxx | 314 ++++++++++++++---- src/SMESH_I/SMESH_NoteBook.hxx | 39 ++- src/SMESH_SWIG/smeshDC.py | 22 +- .../StdMeshersGUI_StdHypothesisCreator.cxx | 35 +- 12 files changed, 439 insertions(+), 109 deletions(-) diff --git a/src/SMESH/SMESH_Hypothesis.cxx b/src/SMESH/SMESH_Hypothesis.cxx index ac80acd22..0d522463d 100644 --- a/src/SMESH/SMESH_Hypothesis.cxx +++ b/src/SMESH/SMESH_Hypothesis.cxx @@ -51,6 +51,7 @@ SMESH_Hypothesis::SMESH_Hypothesis(int hypId, _type = PARAM_ALGO; _shapeType = 0; // to be set by algo with TopAbs_Enum _param_algo_dim = -1; // to be set by algo parameter + _parameters = string(); } //============================================================================= @@ -150,3 +151,23 @@ void SMESH_Hypothesis::SetLibName(const char* theLibName) { _libName = string(theLibName); } + +//============================================================================= +/*! + * + */ +//============================================================================= +void SMESH_Hypothesis::SetParameters(const char *theParameters) +{ + _parameters = string(theParameters); +} + +//============================================================================= +/*! + * + */ +//============================================================================= +char* SMESH_Hypothesis::GetParameters() const +{ + return (char*)_parameters.c_str(); +} diff --git a/src/SMESH/SMESH_Hypothesis.hxx b/src/SMESH/SMESH_Hypothesis.hxx index a63ea921e..2e043186f 100644 --- a/src/SMESH/SMESH_Hypothesis.hxx +++ b/src/SMESH/SMESH_Hypothesis.hxx @@ -70,6 +70,9 @@ public: virtual const char* GetLibName() const; void SetLibName(const char* theLibName); + void SetParameters(const char *theParameters); + char* GetParameters() const; + /*! * \brief Initialize my parameter values by the mesh built on the geometry * \param theMesh - the built mesh @@ -97,6 +100,7 @@ protected: private: std::string _libName; + std::string _parameters; }; #endif diff --git a/src/SMESH_I/SMESH_2smeshpy.cxx b/src/SMESH_I/SMESH_2smeshpy.cxx index cad2d2f94..cde2fbebd 100644 --- a/src/SMESH_I/SMESH_2smeshpy.cxx +++ b/src/SMESH_I/SMESH_2smeshpy.cxx @@ -125,15 +125,30 @@ SMESH_2smeshpy::ConvertScript(const TCollection_AsciiString& theScript, { theGen = new _pyGen( theEntry2AccessorMethod ); - SMESH_NoteBook * aNoteBook = new SMESH_NoteBook( theGen ); + SMESH_NoteBook * aNoteBook = new SMESH_NoteBook(); - // split theScript into separate commands int from = 1, end = theScript.Length(), to; while ( from < end && ( to = theScript.Location( "\n", from, end ))) + { + if ( to != from ) + // cut out and store a command + aNoteBook->AddCommand( theScript.SubString( from, to - 1 )); + from = to + 1; + } + + aNoteBook->ReplaceVariables(); + + TCollection_AsciiString aNoteScript = aNoteBook->GetResultScript(); + delete aNoteBook; + aNoteBook = 0; + + // split theScript into separate commands + from = 1, end = aNoteScript.Length(); + while ( from < end && ( to = aNoteScript.Location( "\n", from, end ))) { if ( to != from ) // cut out and store a command - theGen->AddCommand( aNoteBook->ReplaceVariables(theScript.SubString( from, to - 1 ))); + theGen->AddCommand( aNoteScript.SubString( from, to - 1 )); from = to + 1; } // finish conversion diff --git a/src/SMESH_I/SMESH_2smeshpy.hxx b/src/SMESH_I/SMESH_2smeshpy.hxx index d5a26c627..cb8586f01 100644 --- a/src/SMESH_I/SMESH_2smeshpy.hxx +++ b/src/SMESH_I/SMESH_2smeshpy.hxx @@ -186,7 +186,6 @@ public: bool AddMeshAccessorMethod( Handle(_pyCommand) theCmd ) const; bool AddAlgoAccessorMethod( Handle(_pyCommand) theCmd ) const; const char* AccessorMethod() const; - const std::map< _pyID, Handle(_pyMeshEditor) >& getMeshEditors() const { return myMeshEditors; } private: std::map< _pyID, Handle(_pyMesh) > myMeshes; std::map< _pyID, Handle(_pyMeshEditor) > myMeshEditors; diff --git a/src/SMESH_I/SMESH_Gen_i.hxx b/src/SMESH_I/SMESH_Gen_i.hxx index 151925c49..e63753561 100644 --- a/src/SMESH_I/SMESH_Gen_i.hxx +++ b/src/SMESH_I/SMESH_Gen_i.hxx @@ -472,6 +472,7 @@ public: void UpdateParameters(CORBA::Object_ptr theObject, const char* theParameters); char* GetParameters(CORBA::Object_ptr theObject); + char* ParseParameters(const char* theParameters); private: diff --git a/src/SMESH_I/SMESH_Gen_i_1.cxx b/src/SMESH_I/SMESH_Gen_i_1.cxx index 55412b182..556d7e7c1 100644 --- a/src/SMESH_I/SMESH_Gen_i_1.cxx +++ b/src/SMESH_I/SMESH_Gen_i_1.cxx @@ -876,32 +876,47 @@ void SMESH_Gen_i::UpdateParameters(CORBA::Object_ptr theObject, const char* theP SALOMEDS::SObject_var aSObj = ObjectToSObject(aStudy,theObject); if(aSObj->_is_nil()) return; - + SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder(); - - TCollection_AsciiString aNewParams; - TCollection_AsciiString anInputParams; - SALOMEDS::ListOfListOfStrings_var aSections = aStudy->ParseVariables(theParameters); - SALOMEDS::GenericAttribute_var anAttr; anAttr = aStudyBuilder->FindOrCreateAttribute( aSObj, "AttributeString"); SALOMEDS::AttributeString_var aStringAttr = SALOMEDS::AttributeString::_narrow(anAttr); + + TCollection_AsciiString aNewParams; TCollection_AsciiString aOldParameters(aStringAttr->Value()); - SALOMEDS::ListOfStrings aVars= aSections[0]; - for(int i=0;iIsVariable(aVars[i].in()) ? - TCollection_AsciiString(aVars[i].in()) : TCollection_AsciiString(""); - if(i != aVars.length()-1) - anInputParams+=":"; - } + TCollection_AsciiString anInputParams(ParseParameters(theParameters)); + if(!aOldParameters.Length()) aNewParams = anInputParams; else aNewParams = aOldParameters+"|"+anInputParams; - + aStringAttr->SetValue( aNewParams.ToCString() ); } +//======================================================================= +//function : GetParameters +//purpose : +//======================================================================= +char* SMESH_Gen_i::ParseParameters(const char* theParameters) +{ + const char* aParameters = CORBA::string_dup(theParameters); + TCollection_AsciiString anInputParams; + 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 i=0;iIsVariable(aVars[i].in()) ? + TCollection_AsciiString(aVars[i].in()) : TCollection_AsciiString(""); + if(i != aVars.length()-1) + anInputParams+=":"; + } + } + } + return CORBA::string_dup(anInputParams.ToCString()); +} //======================================================================= //function : GetParameters diff --git a/src/SMESH_I/SMESH_Hypothesis_i.cxx b/src/SMESH_I/SMESH_Hypothesis_i.cxx index 5b8265af9..a65b84362 100644 --- a/src/SMESH_I/SMESH_Hypothesis_i.cxx +++ b/src/SMESH_I/SMESH_Hypothesis_i.cxx @@ -122,6 +122,23 @@ CORBA::Long SMESH_Hypothesis_i::GetId() return myBaseImpl->GetID(); } +//============================================================================= +/*! + * SMESH_Hypothesis_i::IsPublished() + * + */ +//============================================================================= +bool SMESH_Hypothesis_i::IsPublished(){ + bool res = false; + SMESH_Gen_i *gen = SMESH_Gen_i::GetSMESHGen(); + if(gen){ + SALOMEDS::SObject_var SO = + SMESH_Gen_i::ObjectToSObject(gen->GetCurrentStudy() , SMESH::SMESH_Hypothesis::_narrow(_this())); + res = !SO->_is_nil(); + } + return res; +} + //============================================================================= /*! * SMESH_Hypothesis_i::SetParameters() @@ -130,8 +147,16 @@ CORBA::Long SMESH_Hypothesis_i::GetId() //============================================================================= void SMESH_Hypothesis_i::SetParameters(const char* theParameters) { - SMESH_Gen_i::GetSMESHGen()->UpdateParameters(SMESH::SMESH_Hypothesis::_narrow(_this()), - CORBA::string_dup(theParameters)); + SMESH_Gen_i *gen = SMESH_Gen_i::GetSMESHGen(); + char * aParameters = CORBA::string_dup(theParameters); + if(gen){ + if(IsPublished()) { + SMESH_Gen_i::GetSMESHGen()->UpdateParameters(SMESH::SMESH_Hypothesis::_narrow(_this()),aParameters); + } + else { + myBaseImpl->SetParameters(gen->ParseParameters(aParameters)); + } + } } //============================================================================= @@ -143,7 +168,16 @@ void SMESH_Hypothesis_i::SetParameters(const char* theParameters) char* SMESH_Hypothesis_i::GetParameters() { SMESH_Gen_i *gen = SMESH_Gen_i::GetSMESHGen(); - return CORBA::string_dup(gen->GetParameters(SMESH::SMESH_Hypothesis::_narrow(_this()))); + char* aResult; + if(IsPublished()) { + MESSAGE("SMESH_Hypothesis_i::GetParameters() : Get Parameters from SObject"); + aResult = gen->GetParameters(SMESH::SMESH_Hypothesis::_narrow(_this())); + } + else { + MESSAGE("SMESH_Hypothesis_i::GetParameters() : Get local parameters"); + aResult = myBaseImpl->GetParameters(); + } + return CORBA::string_dup(aResult); } //============================================================================= diff --git a/src/SMESH_I/SMESH_Hypothesis_i.hxx b/src/SMESH_I/SMESH_Hypothesis_i.hxx index 28184a5f5..e93554ae6 100644 --- a/src/SMESH_I/SMESH_Hypothesis_i.hxx +++ b/src/SMESH_I/SMESH_Hypothesis_i.hxx @@ -65,7 +65,7 @@ public: // Get unique id of hypothesis CORBA::Long GetId(); - + // Set list of parameters separated by ":" symbol, used for Hypothesis creation void SetParameters (const char* theParameters); @@ -74,7 +74,10 @@ public: //Return list of last notebook variables used for Hypothesis creation. SMESH::ListOfParameters* GetLastParameters(); - + + //Return true if hypothesis was published in study + bool IsPublished(); + // Get implementation ::SMESH_Hypothesis* GetImpl(); diff --git a/src/SMESH_I/SMESH_NoteBook.cxx b/src/SMESH_I/SMESH_NoteBook.cxx index b540a88da..b143f63b4 100644 --- a/src/SMESH_I/SMESH_NoteBook.cxx +++ b/src/SMESH_I/SMESH_NoteBook.cxx @@ -33,9 +33,9 @@ #include #ifdef _DEBUG_ -static int MYDEBUG = 0; +static int MYDEBUG = 1; #else -static int MYDEBUG = 0; +static int MYDEBUG = 1; #endif using namespace std; @@ -114,13 +114,79 @@ TCollection_AsciiString ObjectStates::GetObjectType() const{ return _type; } + +//================================================================================ +/*! + * \brief Constructor + */ +//================================================================================ +LayerDistributionStates::LayerDistributionStates(): + ObjectStates("LayerDistribution") +{ +} +//================================================================================ +/*! + * \brief Destructor + */ +//================================================================================ +LayerDistributionStates::~LayerDistributionStates() +{ +} + + +//================================================================================ +/*! + * \brief AddDistribution + */ +//================================================================================ +void LayerDistributionStates::AddDistribution(const TCollection_AsciiString& theDistribution) +{ + _distributions.insert(pair(theDistribution,"")); +} + +//================================================================================ +/*! + * \brief HasDistribution + */ +//================================================================================ +bool LayerDistributionStates::HasDistribution(const TCollection_AsciiString& theDistribution) const +{ + return _distributions.find(theDistribution) != _distributions.end(); +} + +//================================================================================ +/*! + * \brief SetDistributionType + */ +//================================================================================ +bool LayerDistributionStates::SetDistributionType(const TCollection_AsciiString& theDistribution, + const TCollection_AsciiString& theType) +{ + TDistributionMap::iterator it = _distributions.find(theDistribution); + if(it == _distributions.end()) + return false; + (*it).second = theType; + return true; +} + +//================================================================================ +/*! + * \brief GetDistributionType + */ +//================================================================================ +TCollection_AsciiString LayerDistributionStates:: +GetDistributionType(const TCollection_AsciiString& theDistribution) const +{ + TDistributionMap::const_iterator it = _distributions.find(theDistribution); + return (it == _distributions.end()) ? TCollection_AsciiString() : (*it).second; +} + //================================================================================ /*! * \brief Constructor */ //================================================================================ -SMESH_NoteBook::SMESH_NoteBook(Handle(_pyGen) theGen): - myGen( theGen ) +SMESH_NoteBook::SMESH_NoteBook() { InitObjectMap(); } @@ -146,82 +212,99 @@ SMESH_NoteBook::~SMESH_NoteBook() * \retval TCollection_AsciiString - Convertion result */ //================================================================================ -TCollection_AsciiString SMESH_NoteBook::ReplaceVariables(const TCollection_AsciiString& theString) const +void SMESH_NoteBook::ReplaceVariables() { - _pyCommand aCmd( theString, -1); - TCollection_AsciiString aMethod = aCmd.GetMethod(); - TCollection_AsciiString aObject = aCmd.GetObject(); - TCollection_AsciiString aResultValue = aCmd.GetResultValue(); - if(aMethod.IsEmpty()) - return theString; - - // check if method modifies the object itself - TVariablesMap::const_iterator it = _objectMap.find(aObject); - if(it == _objectMap.end()) // check if method returns a new object - it = _objectMap.find(aResultValue); - - if(it == _objectMap.end()) { // check if method modifies a mesh using mesh editor - const std::map< _pyID, Handle(_pyMeshEditor) >& aMeshEditors = myGen->getMeshEditors(); - std::map< _pyID, Handle(_pyMeshEditor) >::const_iterator meIt = aMeshEditors.find(aObject); - if(meIt != aMeshEditors.end()) { - Handle(_pyMeshEditor) aMeshEditor = (*meIt).second; - if(!aMeshEditor.IsNull()) { - Handle(_pyCommand) aCreationCommand = aMeshEditor->GetCreationCmd(); - if(!aCreationCommand.IsNull()) { - TCollection_AsciiString aMesh = aCreationCommand->GetObject(); - it = _objectMap.find(aMesh); - } + + for(int i=0;i<_commands.size();i++) { + Handle(_pyCommand) aCmd = _commands[i]; + TCollection_AsciiString aMethod = aCmd->GetMethod(); + TCollection_AsciiString aObject = aCmd->GetObject(); + TCollection_AsciiString aResultValue = aCmd->GetResultValue(); + if(MYDEBUG) { + cout<<"Command before : "<< aCmd->GetString()<GetObjectType()<GetObjectType().IsEqual("LocalLength")) { - if(aMethod.IsEqual("SetLength")) { - if(!aStates->GetCurrectState().at(0).IsEmpty() ) - aCmd.SetArg(1,aStates->GetCurrectState().at(0)); - aStates->IncrementState(); + + if(it != _objectMap.end() && !aMethod.IsEmpty()) { + ObjectStates *aStates = (*it).second; + // Case for LocalLength hypothesis + if(aStates->GetObjectType().IsEqual("LocalLength")) { + if(aMethod.IsEqual("SetLength")) { + if(!aStates->GetCurrectState().at(0).IsEmpty() ) + aCmd->SetArg(1,aStates->GetCurrectState().at(0)); + aStates->IncrementState(); + } + else if(aMethod.IsEqual("SetPrecision")) { + if(!aStates->GetCurrectState().at(1).IsEmpty() ) + aCmd->SetArg(1,aStates->GetCurrectState().at(1)); + aStates->IncrementState(); + } } - else if(aMethod.IsEqual("SetPrecision")) { - if(!aStates->GetCurrectState().at(1).IsEmpty() ) - aCmd.SetArg(1,aStates->GetCurrectState().at(1)); - aStates->IncrementState(); + + // Case for SegmentLengthAroundVertex hypothesis + else if(aStates->GetObjectType().IsEqual("SegmentLengthAroundVertex")) { + if(aMethod == "SetLength") { + if(!aStates->GetCurrectState().at(0).IsEmpty() ) + aCmd->SetArg(1,aStates->GetCurrectState().at(0)); + aStates->IncrementState(); + } } - } - else if(aStates->GetObjectType().IsEqual("Mesh")) { - if(aMethod.IsEqual("Translate") || - aMethod.IsEqual("TranslateMakeGroups") || - aMethod.IsEqual("TranslateMakeMesh")) { - bool isVariableFound = false; - int anArgIndex = 0; - for(int i = 1, n = aCmd.GetNbArgs(); i <= n; i++) { - if(aCmd.GetArg(i).IsEqual("SMESH.PointStruct")) { - anArgIndex = i+1; - break; - } - } - if(anArgIndex > 0) { - for(int j = 0; j <= 2; j++) { - if(!aStates->GetCurrectState().at(j).IsEmpty()) { - isVariableFound = true; - aCmd.SetArg(anArgIndex+j, aStates->GetCurrectState().at(j)); - } - } - } - if(isVariableFound) { - aCmd.SetArg(anArgIndex - 1, TCollection_AsciiString(SMESH_2smeshpy::SmeshpyName())+".PointStructStr"); - aCmd.SetArg(anArgIndex - 2, TCollection_AsciiString(SMESH_2smeshpy::SmeshpyName())+".DirStructStr"); - } - aStates->IncrementState(); + // Case for LayerDistribution hypothesis (not finished yet) + else if(aStates->GetObjectType() == "LayerDistribution") { + if(aMethod == "SetLayerDistribution"){ + LayerDistributionStates* aLDStates = (LayerDistributionStates*)(aStates); + aLDStates->AddDistribution(aCmd->GetArg(1)); + } } + + else if(aStates->GetObjectType().IsEqual("Mesh")) { + if(aMethod.IsEqual("Translate") || + aMethod.IsEqual("TranslateMakeGroups") || + aMethod.IsEqual("TranslateMakeMesh")) { + bool isVariableFound = false; + int anArgIndex = 0; + for(int i = 1, n = aCmd->GetNbArgs(); i <= n; i++) { + if(aCmd->GetArg(i).IsEqual("SMESH.PointStruct")) { + anArgIndex = i+1; + break; + } + } + if(anArgIndex > 0) { + for(int j = 0; j <= 2; j++) { + if(!aStates->GetCurrectState().at(j).IsEmpty()) { + isVariableFound = true; + aCmd->SetArg(anArgIndex+j, aStates->GetCurrectState().at(j)); + } + } + } + if(isVariableFound) { + aCmd->SetArg(anArgIndex - 1, TCollection_AsciiString(SMESH_2smeshpy::SmeshpyName())+".PointStructStr"); + aCmd->SetArg(anArgIndex - 2, TCollection_AsciiString(SMESH_2smeshpy::SmeshpyName())+".DirStructStr"); + } + aStates->IncrementState(); + } + } + } + if(MYDEBUG) { + cout<<"Command after: "<< aCmd->GetString()<length(); i++) { TState aVars; SALOMEDS::ListOfStrings aListOfVars = aSections[i]; @@ -287,3 +374,84 @@ void SMESH_NoteBook::InitObjectMap() } } } + +//================================================================================ +/*! + * + */ +//================================================================================ +void SMESH_NoteBook::AddCommand(const TCollection_AsciiString& theString) +{ + Handle(_pyCommand) aCommand = new _pyCommand( theString, -1); + _commands.push_back(aCommand); + + if ( aCommand->GetMethod() == "GetMeshEditor" ) { // MeshEditor creation + myMeshEditors.insert( make_pair( aCommand->GetResultValue(), + aCommand->GetObject() ) ); + } +} + +//================================================================================ +/*! + * + */ +//================================================================================ +void SMESH_NoteBook::ProcessLayerDistribution() +{ + // 1) Find all LayerDistribution states + vector aLDS; + TVariablesMap::const_iterator it = _objectMap.begin(); + for(;it != _objectMap.end();it++) + if(LayerDistributionStates* aLDStates = (LayerDistributionStates*)((*it).second)) { + aLDS.push_back(aLDStates); + } + + // 2) Initialize all type of 1D Distribution hypothesis + for(int i=0;i<_commands.size();i++){ + for(int j =0;j < aLDS.size();j++){ + TCollection_AsciiString aResultValue = _commands[i]->GetResultValue(); + if(_commands[i]->GetMethod() == "CreateHypothesis" && + aLDS[j]->HasDistribution(aResultValue)){ + TCollection_AsciiString aType = _commands[i]->GetArg(1); + aType.RemoveAll('\''); + aLDS[j]->SetDistributionType(aResultValue,aType); + } + } + } + // 3) ... and replase variables ... + + for(int i=0;i<_commands.size();i++){ + for(int j =0;j < aLDS.size();j++){ + TCollection_AsciiString anObject = _commands[i]->GetObject(); + + if(aLDS[j]->HasDistribution(anObject)) { + TCollection_AsciiString aType = aLDS[j]->GetDistributionType(anObject); + 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)); + aLDS[j]->IncrementState(); + } + else if(aMethod == "SetPrecision") { + if(!aLDS[j]->GetCurrectState().at(1).IsEmpty() ) + _commands[i]->SetArg(1,aLDS[j]->GetCurrectState().at(1)); + aLDS[j]->IncrementState(); + } + } + } + } + } +} +//================================================================================ +/*! + * \brief Return result script + */ +//================================================================================ +TCollection_AsciiString SMESH_NoteBook::GetResultScript() const +{ + TCollection_AsciiString aResult; + for(int i=0;i<_commands.size();i++) + aResult+=_commands[i]->GetString()+"\n"; + return aResult; +} diff --git a/src/SMESH_I/SMESH_NoteBook.hxx b/src/SMESH_I/SMESH_NoteBook.hxx index 0eef2063d..bd8f4297c 100644 --- a/src/SMESH_I/SMESH_NoteBook.hxx +++ b/src/SMESH_I/SMESH_NoteBook.hxx @@ -26,12 +26,15 @@ #include #include + +class _pyCommand; #include #include typedef std::vector TState; typedef std::vector TAllStates; +typedef TCollection_AsciiString _pyID; class ObjectStates{ @@ -55,21 +58,47 @@ private: int _dumpstate; }; -class SMESH_NoteBook +class LayerDistributionStates : public ObjectStates { public: - SMESH_NoteBook(Handle(_pyGen) theGen); - ~SMESH_NoteBook(); - TCollection_AsciiString ReplaceVariables(const TCollection_AsciiString& theString) const; + typedef std::map TDistributionMap; + LayerDistributionStates(); + ~LayerDistributionStates(); + + void AddDistribution(const TCollection_AsciiString& theDistribution); + bool HasDistribution(const TCollection_AsciiString& theDistribution) const; + + bool SetDistributionType(const TCollection_AsciiString& theDistribution, + const TCollection_AsciiString& theType); + TCollection_AsciiString GetDistributionType(const TCollection_AsciiString& theDistribution) const; + +private: + + TDistributionMap _distributions; +}; + +class SMESH_NoteBook +{ +public: typedef std::map TVariablesMap; + typedef std::map TMeshEditorMap; + SMESH_NoteBook(); + ~SMESH_NoteBook(); + void ReplaceVariables(); + + void AddCommand(const TCollection_AsciiString& theString); + TCollection_AsciiString GetResultScript() const; private: void InitObjectMap(); + void ProcessLayerDistribution(); private: + TVariablesMap _objectMap; - Handle(_pyGen) myGen; + std::vector _commands; + TMeshEditorMap myMeshEditors; }; #endif //SMESH_NoteBook_HeaderFile diff --git a/src/SMESH_SWIG/smeshDC.py b/src/SMESH_SWIG/smeshDC.py index 980126d96..6df514bbf 100644 --- a/src/SMESH_SWIG/smeshDC.py +++ b/src/SMESH_SWIG/smeshDC.py @@ -4093,13 +4093,18 @@ def ParseParameters(last, nbParams,nbParam, value): counter = counter+1 return result, strResult +#Wrapper class for StdMeshers_LocalLength hypothesis class LocalLength(StdMeshers._objref_StdMeshers_LocalLength): - + + ## Set length parameter value + # @param length numerical value or name of variable from notebook def SetLength(self, length): length,parameters = ParseParameters(StdMeshers._objref_StdMeshers_LocalLength.GetLastParameters(self),2,1,length) StdMeshers._objref_StdMeshers_LocalLength.SetParameters(self,parameters) StdMeshers._objref_StdMeshers_LocalLength.SetLength(self,length) + ## Set precision parameter value + # @param precision numerical value or name of variable from notebook def SetPrecision(self, precision): precision,parameters = ParseParameters(StdMeshers._objref_StdMeshers_LocalLength.GetLastParameters(self),2,2,precision) StdMeshers._objref_StdMeshers_LocalLength.SetParameters(self,parameters) @@ -4107,3 +4112,18 @@ class LocalLength(StdMeshers._objref_StdMeshers_LocalLength): #Registering the new proxy for LocalLength omniORB.registerObjref(StdMeshers._objref_StdMeshers_LocalLength._NP_RepositoryId, LocalLength) + + +#Wrapper class for StdMeshers_SegmentLengthAroundVertex hypothesis +class SegmentLengthAroundVertex(StdMeshers._objref_StdMeshers_SegmentLengthAroundVertex): + parent = StdMeshers._objref_StdMeshers_SegmentLengthAroundVertex + + ## Set length parameter value + # @param length numerical value or name of variable from notebook + def SetLength(self, length): + length,parameters = ParseParameters(parent.GetLastParameters(self),1,1,length) + parent.SetParameters(self,parameters) + parent.SetLength(self,length) + +#Registering the new proxy for LocalLength +omniORB.registerObjref(StdMeshers._objref_StdMeshers_SegmentLengthAroundVertex._NP_RepositoryId, LocalLength) diff --git a/src/StdMeshersGUI/StdMeshersGUI_StdHypothesisCreator.cxx b/src/StdMeshersGUI/StdMeshersGUI_StdHypothesisCreator.cxx index d893462df..177950406 100644 --- a/src/StdMeshersGUI/StdMeshersGUI_StdHypothesisCreator.cxx +++ b/src/StdMeshersGUI/StdMeshersGUI_StdHypothesisCreator.cxx @@ -421,6 +421,7 @@ QString StdMeshersGUI_StdHypothesisCreator::storeParams() const StdMeshers::StdMeshers_SegmentLengthAroundVertex::_narrow( hypothesis() ); h->SetLength( params[0].myValue.toDouble() ); + h->SetParameters(SMESHGUI::JoinObjectParameters(aVariablesList)); } else if( hypType()=="Arithmetic1D" ) { @@ -479,8 +480,12 @@ QString StdMeshersGUI_StdHypothesisCreator::storeParams() const StdMeshers::StdMeshers_LayerDistribution::_narrow( hypothesis() ); StdMeshersGUI_LayerDistributionParamWdg* w = widget< StdMeshersGUI_LayerDistributionParamWdg >( 0 ); - + h->SetLayerDistribution( w->GetHypothesis() ); + /* h->SetParameters(w->GetHypothesis()->GetParameters()); + if(QString(w->GetHypothesis()->GetName()) == "LocalLength") + h->SetParameters(w->GetHypothesis()->GetParameters()); + */ } else if( hypType()=="ProjectionSource1D" ) { @@ -552,16 +557,17 @@ bool StdMeshersGUI_StdHypothesisCreator::stdParams( ListOfStdParams& p ) const } SMESH::SMESH_Hypothesis_var hyp = initParamsHypothesis(); + SMESH::ListOfParameters_var aParameters = hyp->GetLastParameters(); + QString aVaribaleName; if( hypType()=="LocalLength" ) { StdMeshers::StdMeshers_LocalLength_var h = StdMeshers::StdMeshers_LocalLength::_narrow( hyp ); - SMESH::ListOfParameters_var aParameters = hyp->GetLastParameters(); item.myName = tr("SMESH_LOCAL_LENGTH_PARAM"); - QString aVaribaleName = (aParameters->length() > 0) ? QString(aParameters[0].in()) : QString(""); + aVaribaleName = (aParameters->length() > 0) ? QString(aParameters[0].in()) : QString(""); item.isVariable = !aVaribaleName.isEmpty(); if(item.isVariable) item.myValue = aVaribaleName; @@ -583,9 +589,15 @@ bool StdMeshersGUI_StdHypothesisCreator::stdParams( ListOfStdParams& p ) const { StdMeshers::StdMeshers_SegmentLengthAroundVertex_var h = StdMeshers::StdMeshers_SegmentLengthAroundVertex::_narrow( hyp ); - item.myName = tr("SMESH_LOCAL_LENGTH_PARAM"); - item.myValue = h->GetLength(); + + aVaribaleName = (aParameters->length() > 0) ? QString(aParameters[0].in()) : QString(""); + item.isVariable = !aVaribaleName.isEmpty(); + + if(item.isVariable) + item.myValue = aVaribaleName; + else + item.myValue = h->GetLength(); p.append( item ); } else if( hypType()=="Arithmetic1D" ) @@ -660,11 +672,20 @@ bool StdMeshersGUI_StdHypothesisCreator::stdParams( ListOfStdParams& p ) const p.append( item ); } else if( hypType()=="LayerDistribution" ) - { - StdMeshers::StdMeshers_LayerDistribution_var h = + { + StdMeshers::StdMeshers_LayerDistribution_var h = StdMeshers::StdMeshers_LayerDistribution::_narrow( hyp ); item.myName = tr( "SMESH_LAYERS_DISTRIBUTION" ); p.append( item ); + + //Set into not published hypo last variables + /* QStringList aLastVarsList; + for(int i = 0;ilength();i++) + aLastVarsList.append(QString(aParameters[i].in())); + + if(!aLastVarsList.isEmpty()) + h->GetLayerDistribution()->SetParameters(SMESHGUI::JoinObjectParameters(aLastVarsList)); + */ customWidgets()->append ( new StdMeshersGUI_LayerDistributionParamWdg( h->GetLayerDistribution(), hypName(), dlg())); } -- 2.39.2