Salome HOME
Start implementation of the notebook in SMESH module.
authorrnv <rnv@opencascade.com>
Thu, 13 Nov 2008 09:28:44 +0000 (09:28 +0000)
committerrnv <rnv@opencascade.com>
Thu, 13 Nov 2008 09:28:44 +0000 (09:28 +0000)
14 files changed:
idl/SMESH_Hypothesis.idl
src/SMESHGUI/SMESHGUI_Hypotheses.cxx
src/SMESHGUI/SMESHGUI_Hypotheses.h
src/SMESH_I/Makefile.am
src/SMESH_I/SMESH_2smeshpy.cxx
src/SMESH_I/SMESH_Gen_i.hxx
src/SMESH_I/SMESH_Gen_i_1.cxx
src/SMESH_I/SMESH_Hypothesis_i.cxx
src/SMESH_I/SMESH_Hypothesis_i.hxx
src/SMESH_I/SMESH_NoteBook.cxx [new file with mode: 0644]
src/SMESH_I/SMESH_NoteBook.hxx [new file with mode: 0644]
src/SMESH_SWIG/smeshDC.py
src/StdMeshersGUI/StdMeshersGUI_StdHypothesisCreator.cxx
src/StdMeshersGUI/StdMeshersGUI_StdHypothesisCreator.h

index 4076e5c8af353bca37fd5549547bb95af62a844f..45f3c4d5d52ddefde65d6173feadfc0dae3512df 100644 (file)
@@ -55,6 +55,18 @@ module SMESH
      * Get the internal Id 
      */
     long GetId();
+
+    /*!
+     *  Set list of parameters
+     *  \param theParameters is a string containing the notebook variables separated by ":" symbol,
+     *         used for Hypothesis creation
+     */
+    void SetParameters (in string theParameters);
+
+    /*!
+     *  Return list of notebook variables used for Hypothesis creation separated by ":" symbol
+     */
+    string GetParameters();
     
     /*!
      * Verify whether hypothesis supports given entity type 
index f22331a4a6240d42c34868d72e2bdaa5d4610db2..25f761469f7b3cfdf9044464ade61f829b559d4a 100644 (file)
@@ -226,12 +226,34 @@ QFrame* SMESHGUI_GenericHypothesisCreator::buildStdFrame()
         break;
       case QVariant::String:
         {
-          QLineEdit* le = new QLineEdit( GroupC1 );
-         le->setObjectName( (*anIt).myName );
-          attuneStdWidget( le, i );
-          le->setText( (*anIt).myValue.toString() );
-          connect( le, SIGNAL( textChanged( const QString& ) ), this, SLOT( onValueChanged() ) );
-          w = le;
+          if((*anIt).isVariable) {
+            _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
+            QString aVar = (*anIt).myValue.toString();
+            if(aStudy->IsInteger(aVar.toLatin1().constData())){
+              SalomeApp_IntSpinBox* sb = new SalomeApp_IntSpinBox( GroupC1 );
+              sb->setObjectName( (*anIt).myName );
+              attuneStdWidget( sb, i );
+              sb->setText( aVar );
+              connect( sb, SIGNAL( valueChanged( int ) ), this, SLOT( onValueChanged() ) );
+              w = sb;
+            }
+            else if(aStudy->IsReal(aVar.toLatin1().constData())){
+              SalomeApp_DoubleSpinBox* sb = new SMESHGUI_SpinBox( GroupC1 );
+              sb->setObjectName( (*anIt).myName );
+              attuneStdWidget( sb, i );
+              sb->setText( aVar );
+              connect( sb, SIGNAL( valueChanged( double ) ), this, SLOT( onValueChanged() ) );
+              w = sb;
+            }
+          }
+          else {
+            QLineEdit* le = new QLineEdit( GroupC1 );
+            le->setObjectName( (*anIt).myName );
+            attuneStdWidget( le, i );
+            le->setText( (*anIt).myValue.toString() );
+            connect( le, SIGNAL( textChanged( const QString& ) ), this, SLOT( onValueChanged() ) );
+            w = le;
+          }
         }
         break;
       }
@@ -301,6 +323,42 @@ bool SMESHGUI_GenericHypothesisCreator::getStdParamFromDlg( ListOfStdParams& par
   return res;
 }
 
+
+QStringList SMESHGUI_GenericHypothesisCreator::getVariablesFromDlg() const
+{
+  QStringList aResult;
+  QString item;
+  _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
+  if(aStudy) {
+    ListOfWidgets::const_iterator anIt = widgets().begin(), aLast = widgets().end();
+    for( ; anIt!=aLast; anIt++ ) {
+      if( (*anIt)->inherits( "SalomeApp_IntSpinBox" ) )
+        {
+          SalomeApp_IntSpinBox* sb = ( SalomeApp_IntSpinBox* )( *anIt );
+          item = sb->text();
+         bool isVariable = aStudy->IsVariable(item.toLatin1().constData()); 
+          isVariable ? aResult.append( item ) : aResult.append(QString());
+        }
+      
+      else if( (*anIt)->inherits( "QtxDoubleSpinBox" ) )
+      {
+        QtxDoubleSpinBox* sb = ( QtxDoubleSpinBox* )( *anIt );
+        item = sb->text();
+        bool isVariable = aStudy->IsVariable(item.toLatin1().constData());
+       isVariable ? aResult.append( item ) : aResult.append(QString());
+      } 
+    }
+    bool hasVar = false;
+    for (int i = 0;i<aResult.size();i++)
+      if(!aResult[i].isEmpty())
+        hasVar = true;
+
+    if(!hasVar)
+      aResult.clear();
+  }
+  return aResult;
+}
+
 QString SMESHGUI_GenericHypothesisCreator::stdParamValues( const ListOfStdParams& params)
 {
   QString valueStr = "";
index 8749450aab908469e39598f262269a72171c4850..587bbc9b7f22039d7bb6faafb772a3b635fd8f17 100644 (file)
@@ -64,12 +64,15 @@ public:
   bool                         isCreation() const;
 
 protected:
-  typedef struct
+  struct StdParam
   {
     QString   myName;
     QVariant  myValue;
-
-  } StdParam;
+    bool      isVariable;
+    StdParam(){
+      isVariable = false;
+    }
+  };
 
   typedef QList<StdParam>      ListOfStdParams;
   typedef QList<QWidget*>      ListOfWidgets;
@@ -86,6 +89,7 @@ protected:
   virtual QString              storeParams() const = 0;
   virtual bool                 stdParams( ListOfStdParams& ) const;
   bool                         getStdParamFromDlg( ListOfStdParams& ) const;
+  virtual QStringList          getVariablesFromDlg() const;
   static  QString              stdParamValues( const ListOfStdParams& );
   virtual void                 attuneStdWidget( QWidget*, const int ) const;
   virtual QWidget*             getCustomWidget( const StdParam&, 
index c58d29629c413a948bf50890b122b9e7b76d5d5e..f28bbbe7f8fe9d81ff473070991e9a36dbe4030c 100644 (file)
@@ -49,6 +49,7 @@ salomeinclude_HEADERS = \
        SMESH_MEDSupport_i.hxx \
        SMESH_Pattern_i.hxx \
        SMESH_2smeshpy.hxx \
+       SMESH_NoteBook.hxx \
        SMESH.hxx
 
 # Scripts to be installed.
@@ -78,7 +79,8 @@ dist_libSMESHEngine_la_SOURCES = \
        SMESH_Filter_i.cxx \
        SMESH_Group_i.cxx \
        SMESH_Pattern_i.cxx \
-       SMESH_2smeshpy.cxx
+       SMESH_2smeshpy.cxx \
+       SMESH_NoteBook.cxx 
 
 # Executables targets
 bin_PROGRAMS = SMESHEngine
index cfa660a2c3f7882da212debfd7ff21b5f7a0176b..f1673f85e4bf0920381649e182ce63bd6a6a2b6d 100644 (file)
@@ -34,6 +34,7 @@
 
 #include "utilities.h"
 #include "SMESH_PythonDump.hxx"
+#include "SMESH_NoteBook.hxx"
 #include "Resource_DataMapOfAsciiStringAsciiString.hxx"
 
 #include "SMESH_Gen_i.hxx"
@@ -123,14 +124,16 @@ SMESH_2smeshpy::ConvertScript(const TCollection_AsciiString& theScript,
                               Resource_DataMapOfAsciiStringAsciiString& theEntry2AccessorMethod)
 {
   theGen = new _pyGen( theEntry2AccessorMethod );
-
+  
+  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
-      theGen->AddCommand( theScript.SubString( from, to - 1 ));
+      theGen->AddCommand( aNoteBook->ReplaceVariables(theScript.SubString( from, to - 1 )));
     from = to + 1;
   }
   // finish conversion
index 06601716ad5c13367c1cd32b71648b51c179146c..64a45c395190c439dbbdfa15aa04b3ac017d642b 100644 (file)
@@ -469,6 +469,9 @@ public:
    * \brief Find SObject for an algo
    */
   SALOMEDS::SObject_ptr GetAlgoSO(const ::SMESH_Algo* algo);
+
+  void UpdateParameters(CORBA::Object_ptr theObject, const char* theParameters);
+  char* GetParameters(CORBA::Object_ptr theObject);
  
 private:
   // Create hypothesis of given type
index 3d87ad4f6d96938e36e7546dc87b8e9993774811..e088deb942a9fe25068c4858b4cf226c7f9083f2 100644 (file)
@@ -863,3 +863,59 @@ bool SMESH_Gen_i::RemoveHypothesisFromShape(SALOMEDS::Study_ptr         theStudy
   return true;
 }
 
+//=======================================================================
+//function : UpdateSObject
+//purpose  : 
+//=======================================================================
+void SMESH_Gen_i::UpdateParameters(CORBA::Object_ptr theObject, const char* theParameters)
+{
+  SALOMEDS::Study_ptr aStudy = GetCurrentStudy();
+  if(aStudy->_is_nil() || CORBA::is_nil(theObject)) 
+    return;
+
+  SALOMEDS::SObject_var aSObj =  ObjectToSObject(aStudy,theObject);
+  if(aSObj->_is_nil())
+    return;
+
+  SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
+  SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow( theObject );
+
+  if ( !aHyp->_is_nil() ) {
+    CORBA::String_var objStr = aHyp->GetParameters();
+    TCollection_AsciiString aParams(theParameters);
+    if(aParams.Length()) {
+      SALOMEDS::GenericAttribute_var anAttr;
+      anAttr = aStudyBuilder->FindOrCreateAttribute( aSObj, "AttributeString");
+      SALOMEDS::AttributeString::_narrow(anAttr)->SetValue( aParams.ToCString() );
+    }
+    else
+      aStudyBuilder->RemoveAttribute(aSObj,"AttributeString");
+  }
+}
+
+
+//=======================================================================
+//function : GetParameters
+//purpose  : 
+//=======================================================================
+char* SMESH_Gen_i::GetParameters(CORBA::Object_ptr theObject)
+{
+  TCollection_AsciiString aResult;
+
+  SALOMEDS::Study_ptr aStudy = GetCurrentStudy();
+  SALOMEDS::SObject_var aSObj =  ObjectToSObject(aStudy,theObject);
+  SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow( theObject );
+
+  if(!aStudy->_is_nil() && 
+     !CORBA::is_nil(theObject) && 
+     !aSObj->_is_nil() && 
+     !aHyp->_is_nil()){
+    
+    SALOMEDS::GenericAttribute_var anAttr;
+    if ( aSObj->FindAttribute(anAttr, "AttributeString")) {
+      aResult = TCollection_AsciiString(SALOMEDS::AttributeString::_narrow(anAttr)->Value());
+    }
+  }
+  
+  return CORBA::string_dup( aResult.ToCString() );
+}
index 28eda61b2c79e63ab5d8da7c4119772dcb340d57..09e12ce0b734fc6ec547052716b186dc74edb20e 100644 (file)
@@ -29,6 +29,7 @@
 #include <iostream>
 #include <sstream>
 #include "SMESH_Hypothesis_i.hxx"
+#include "SMESH_Gen_i.hxx"
 #include "utilities.h"
 
 using namespace std;
@@ -121,6 +122,27 @@ CORBA::Long SMESH_Hypothesis_i::GetId()
   return myBaseImpl->GetID();
 }
 
+//=============================================================================
+/*!
+ *  SMESH_Hypothesis_i::SetParameters()
+ *
+ */
+//=============================================================================
+void SMESH_Hypothesis_i::SetParameters(const char* theParameters)
+{
+  string aNewParameters(theParameters);
+  string anOldParameters(GetParameters());
+  if(aNewParameters.compare(anOldParameters) != 0)
+    SMESH_Gen_i::GetSMESHGen()->UpdateParameters(SMESH::SMESH_Hypothesis::_narrow(_this()), 
+                                                 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())));
+}
+
 //=============================================================================
 /*!
  *  SMESH_Hypothesis_i::GetImpl
index 634e245c6c267436452ca2309d6d16047b8b05d3..99e3854691dd3c482531cd89b38a5e9a27f8b667 100644 (file)
@@ -66,6 +66,12 @@ 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);
+  
+  // Return list of notebook variables used for Hypothesis creation separated by ":" symbol
+  char* GetParameters();
+  
   // Get implementation
   ::SMESH_Hypothesis* GetImpl();
   
diff --git a/src/SMESH_I/SMESH_NoteBook.cxx b/src/SMESH_I/SMESH_NoteBook.cxx
new file mode 100644 (file)
index 0000000..7f68eeb
--- /dev/null
@@ -0,0 +1,161 @@
+// Copyright (C) 2008  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+// File      : SMESH_NoteBook.cxx
+// Author    : Roman NIKOLAEV
+
+#include "SMESH_2smeshpy.hxx"
+#include "SMESH_NoteBook.hxx"
+#include "SMESH_Gen_i.hxx"
+
+#include <Resource_DataMapOfAsciiStringAsciiString.hxx>
+#include <TColStd_SequenceOfAsciiString.hxx>
+#include <TColStd_HSequenceOfInteger.hxx>
+
+#include <vector>
+#include <string>
+
+#ifdef _DEBUG_
+static int MYDEBUG = 0;
+#else
+static int MYDEBUG = 0;
+#endif
+
+using namespace std;
+
+//================================================================================
+/*!
+ * \brief Constructor
+ */
+//================================================================================
+SMESH_NoteBook::SMESH_NoteBook()
+{
+  InitObjectMap();
+}
+
+//================================================================================
+/*!
+ * \brief Constructor
+ */
+//================================================================================
+SMESH_NoteBook::~SMESH_NoteBook()
+{
+}
+
+//================================================================================
+/*!
+ * \brief Replace parameters of the functions on the Salome NoteBook Variables
+ * \param theString - Input string
+ * \retval TCollection_AsciiString - Convertion result
+ */
+//================================================================================
+TCollection_AsciiString SMESH_NoteBook::ReplaceVariables(const TCollection_AsciiString& theString) const
+{
+  _pyCommand aCmd( theString, -1);
+  TCollection_AsciiString aMethod = aCmd.GetMethod();
+  TCollection_AsciiString aObject = aCmd.GetObject();
+  TVariablesMap::const_iterator it = _objectMap.find(aObject);
+  if(!aMethod.IsEmpty() && it != _objectMap.end() ) {
+    
+    if(aMethod == "SetLength" && !(*it).second.at(0).IsEmpty() ) {
+      aCmd.SetArg(1,(*it).second.at(0));
+    }
+    else if(aMethod == "SetPrecision" && !(*it).second.at(1).IsEmpty() ){
+      aCmd.SetArg(1,(*it).second.at(1));
+    }
+    return aCmd.GetString();
+  }
+  
+  return theString;
+}
+//================================================================================
+/*!
+ * \brief Private method
+ */
+//================================================================================
+void SMESH_NoteBook::InitObjectMap()
+{
+  SMESH_Gen_i *aGen = SMESH_Gen_i::GetSMESHGen();
+  if(!aGen)
+    return;
+  
+  SALOMEDS::Study_ptr aStudy = aGen->GetCurrentStudy();
+  if(aStudy->_is_nil())
+    return;
+  
+  SALOMEDS::SObject_var aSO = aStudy->FindComponent(aGen->ComponentDataType());
+  if(CORBA::is_nil(aSO))
+    return;
+
+  SALOMEDS::ChildIterator_var Itr = aStudy->NewChildIterator(aSO);
+  TCollection_AsciiString aParameters;
+  for(Itr->InitEx(true); Itr->More(); Itr->Next()) {
+    SALOMEDS::SObject_var aSObject = Itr->Value();
+    SALOMEDS::GenericAttribute_var anAttr;
+    if ( aSObject->FindAttribute(anAttr, "AttributeString")) {
+      aParameters = TCollection_AsciiString(SALOMEDS::AttributeString::_narrow(anAttr)->Value());
+      vector<string> vect = ParseVariables(aParameters.ToCString(),':');
+      if(MYDEBUG) {
+        cout<<"Entry : "<< aSObject->GetID()<<endl;
+        cout<<"aParameters : "<<aParameters<<endl;
+      }
+      vector<TCollection_AsciiString> aVars;
+      for(int i = 0;i<vect.size();i++) {
+        TCollection_AsciiString aVar(vect[i].c_str());
+        if(!aVar.IsEmpty() && aStudy->IsVariable(vect[i].c_str())) {
+          aVar.InsertBefore(1,"\"");
+          aVar.InsertAfter(aVar.Length(),"\"");
+        }
+        aVars.push_back(aVar);
+        if(MYDEBUG) {
+          cout<<"Variable: "<<aVar<<endl;
+        }
+      }
+      _objectMap.insert(pair<TCollection_AsciiString,vector<TCollection_AsciiString> >(TCollection_AsciiString(aSObject->GetID()),aVars));
+    }
+  }
+}
+
+//================================================================================
+/*!
+ * \brief Private method
+ */
+//================================================================================
+vector<string> SMESH_NoteBook::ParseVariables(const string& theVariables, const char sep) const
+{
+  vector<string> aResult;
+  if(theVariables[0] == sep ) aResult.push_back(string());
+  int pos = theVariables.find(sep);
+  if(pos < 0) {
+    aResult.push_back(theVariables);
+    return aResult;
+  }
+
+  string s = theVariables;
+  if(s[0] == sep) s = s.substr(1, s.size());
+  while((pos = s.find(sep)) >= 0) {
+    aResult.push_back(s.substr(0, pos));
+    s = s.substr(pos+1, s.size());
+  }
+
+  if(!s.empty() && s[0] != sep) aResult.push_back(s);
+  if(theVariables[theVariables.size()-1] == sep) aResult.push_back(string());
+
+  return aResult;
+}
diff --git a/src/SMESH_I/SMESH_NoteBook.hxx b/src/SMESH_I/SMESH_NoteBook.hxx
new file mode 100644 (file)
index 0000000..4bc3955
--- /dev/null
@@ -0,0 +1,51 @@
+// Copyright (C) 2008  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+// File      : SMESH_NoteBook.hxx
+// Author    : Roman NIKOLAEV ()
+
+
+#ifndef SMESH_NoteBook_HeaderFile
+#define SMESH_NoteBook_HeaderFile
+
+#include <TCollection_AsciiString.hxx>
+#include <Resource_DataMapOfAsciiStringAsciiString.hxx>
+
+#include <vector>
+#include <string>
+
+
+class SMESH_NoteBook
+{
+public:
+  SMESH_NoteBook();
+  ~SMESH_NoteBook();
+  TCollection_AsciiString ReplaceVariables(const TCollection_AsciiString& theString) const;
+
+  typedef std::map<TCollection_AsciiString,std::vector<TCollection_AsciiString> > TVariablesMap;
+
+private:
+  void InitObjectMap();
+  std::vector<std::string> ParseVariables(const std::string& theVariables, const char sep) const;
+  
+private:
+  TVariablesMap _objectMap;
+};
+
+#endif //SMESH_NoteBook_HeaderFile
index d5e8661d6315a5724f0389693a04eb8556634e0a..16e298cd2fc8bc7eb14c2e8e2f200381220c340d 100644 (file)
@@ -174,6 +174,8 @@ def GetName(obj):
 
 ## Sets a name to the object
 def SetName(obj, name):
+    if isinstance(obj, BaseWrapper):
+        obj = obj.GetAlgorithm()
     ior  = salome.orb.object_to_string(obj)
     sobj = salome.myStudy.FindObjectIOR(ior)
     if not sobj is None:
@@ -942,7 +944,7 @@ class Mesh:
     #  @return SMESH.Hypothesis_Status
     #  @ingroup l2_hypotheses
     def AddHypothesis(self, hyp, geom=0):
-        if isinstance( hyp, Mesh_Algorithm ):
+        if isinstance( hyp, Mesh_Algorithm ) or isinstance( hyp, BaseWrapper):
             hyp = hyp.GetAlgorithm()
             pass
         if not geom:
@@ -961,7 +963,7 @@ class Mesh:
     #  @return SMESH.Hypothesis_Status
     #  @ingroup l2_hypotheses
     def RemoveHypothesis(self, hyp, geom=0):
-        if isinstance( hyp, Mesh_Algorithm ):
+        if isinstance( hyp, Mesh_Algorithm ) or isinstance( hyp, BaseWrapper):
             hyp = hyp.GetAlgorithm()
             pass
         if not geom:
@@ -2876,6 +2878,7 @@ class Mesh_Algorithm:
             pass
         status = self.mesh.mesh.AddHypothesis(self.geom, hypo)
         TreatHypoStatus( status, GetName(hypo), GetName(self.geom), 0 )
+        hypo = WrapHypothesis(hypo,hyp)
         return hypo
 
 
@@ -4012,3 +4015,74 @@ class Mesh_UseExisting(Mesh_Algorithm):
             self.Create(mesh, geom, "UseExisting_1D")
         else:
             self.Create(mesh, geom, "UseExisting_2D")
+
+
+
+
+def WrapHypothesis(hypo, hyp):
+    if hyp == "LocalLength":
+        return LocalLength(hypo)
+    return hypo
+
+from salome_notebook import *
+
+##Base class for wrap all StdMeshers interfaces
+class BaseWrapper:
+    
+    ##Return instance of a _objref_StdMeshers hypothesis
+    def GetAlgorithm(self):
+        return self.hypo
+
+    ##Return values of the notebook variables
+    def ParseParameters(self, params ,nbParams, nbParam, arg):
+        result = None
+        strResult = ""
+        isVar = False
+        if isinstance(arg, str):
+            if notebook.isVariable(arg):
+                result = notebook.get(arg)
+                isVar = True
+        else:
+            result = arg
+
+        isEmpty = True
+        paramsList = []
+        if len(params) > 0:
+            paramsList = params.split(":")
+            isEmpty = False
+            
+        for n in range(1,nbParams+1):
+            if n != nbParam and not isEmpty and len(paramsList[n-1])> 0:
+                strResult = paramsList[n-1] + ":"
+                pass
+            if isVar and n == nbParam:
+                if len(strResult) == 0 and nbParam != 1:
+                    strResult = strResult + ":"
+                    pass
+                strResult = strResult+arg
+                if n != nbParams:
+                    strResult = strResult + ":"
+                    
+        return result, strResult
+            
+       
+#Wrapper class for StdMeshers_LocalLength hypothesis
+class LocalLength(BaseWrapper):
+    def __init__(self, hypo):
+        self.hypo = hypo
+
+    def SetLength(self, length):
+        length,parameters = self.ParseParameters(self.hypo.GetParameters(),2,1,length)
+        self.hypo.SetParameters(parameters)
+        self.hypo.SetLength(length)
+
+    def SetPrecision(self, precision):
+        precision,parameters = self.ParseParameters(self.hypo.GetParameters(),2,2,precision)
+        self.hypo.SetParameters(parameters)
+        self.hypo.SetPrecision(precision)
+
+    def GetLength(self):
+        return self.hypo.GetLength()
+
+    def GetPrecision(self):
+        return self.hypo.GetLength()
index 5efe23ee71c16dfdeb5ac4626c3571fb022c7ade..f2bec67af131609c801c44ff4b4cfbc8824fb218 100644 (file)
@@ -32,6 +32,7 @@
 #include <SMESH_NumberFilter.hxx>
 #include <StdMeshersGUI_ObjectReferenceParamWdg.h>
 #include <StdMeshersGUI_LayerDistributionParamWdg.h>
+#include <SALOMEDSClient_Study.hxx>
 
 // SALOME GUI includes
 #include <SUIT_ResourceMgr.h>
@@ -400,6 +401,7 @@ QString StdMeshersGUI_StdHypothesisCreator::storeParams() const
   }
 
   QString valueStr = stdParamValues( params );
+  QStringList aVariablesList = getVariablesFromDlg();
 
   if( res && !params.isEmpty() )
   {
@@ -407,7 +409,13 @@ QString StdMeshersGUI_StdHypothesisCreator::storeParams() const
     {
       StdMeshers::StdMeshers_LocalLength_var h =
        StdMeshers::StdMeshers_LocalLength::_narrow( hypothesis() );
-
+      if(!aVariablesList.isEmpty()) {
+        QString aVariables = aVariablesList.join(":");
+        h->SetParameters(aVariables.toLatin1().constData());
+      }
+      else
+        h->SetParameters("");
+        
       h->SetLength( params[0].myValue.toDouble() );
       h->SetPrecision( params[1].myValue.toDouble() );
     }
@@ -546,7 +554,7 @@ bool StdMeshersGUI_StdHypothesisCreator::stdParams( ListOfStdParams& p ) const
     p.append( item );
     customWidgets()->append(0);
   }
-
+  
   SMESH::SMESH_Hypothesis_var hyp = initParamsHypothesis();
 
   if( hypType()=="LocalLength" )
@@ -554,12 +562,31 @@ bool StdMeshersGUI_StdHypothesisCreator::stdParams( ListOfStdParams& p ) const
     StdMeshers::StdMeshers_LocalLength_var h =
       StdMeshers::StdMeshers_LocalLength::_narrow( hyp );
 
+    QString aParameters(h->GetParameters());
+    QStringList aParametersList;
+    if(aParameters.length())
+      aParametersList = aParameters.split(":");
+
     item.myName = tr("SMESH_LOCAL_LENGTH_PARAM");
-    item.myValue = h->GetLength();
+    QVariant aVariable = parseParameter(aParametersList,0);
+    if(aVariable.type() != QVariant::Invalid) {
+      item.myValue = aVariable;
+      item.isVariable = true;
+    }
+    else
+      item.myValue = h->GetLength();
     p.append( item );
+     
     item.myName = tr("SMESH_LOCAL_LENGTH_PRECISION");
-    item.myValue = h->GetPrecision();
+    aVariable = parseParameter(aParametersList,1);
+    if(aVariable.type() !=  QVariant::Invalid) {
+      item.myValue = aVariable;
+      item.isVariable = true;
+    }
+    else
+      item.myValue = h->GetPrecision();
     p.append( item );
+    
   }
   else if( hypType()=="SegmentLengthAroundVertex" )
   {
@@ -915,3 +942,35 @@ void StdMeshersGUI_StdHypothesisCreator::onReject()
     deactivateObjRefParamWdg( customWidgets() );
   }
 }
+
+//================================================================================
+/*!
+ * \brief
+ */
+//================================================================================
+QVariant StdMeshersGUI_StdHypothesisCreator::
+parseParameter(const QStringList& theList, int theNbParam) const
+{
+  _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
+  QVariant aResult;
+  if(theList.size() > theNbParam) {
+    QString aParameter =  theList[theNbParam];
+    if(QString::compare(QString(""),aParameter) !=0 ) {
+      if(aStudy->IsVariable(aParameter.toLatin1().constData())) {
+        aResult=aParameter;
+      }
+      else {
+        bool aResult = false;
+        int anIResult = aParameter.toInt(&aResult);
+        if(aResult)
+          aResult = anIResult;
+        else {
+          double aDResult = aParameter.toDouble(&aResult);
+          if(aResult)
+            aResult = aDResult;
+        } 
+      }
+    }
+  }
+  return aResult;
+}
index f62c9590ecc8bde475d369463967fd859a41303f..acd2357b5fd8bdddade04dbab27f94cba0a4509f 100644 (file)
@@ -58,6 +58,7 @@ protected:
   virtual QWidget* getWidgetForParam( int paramIndex ) const;
   virtual ListOfWidgets* customWidgets() const;
   virtual void     onReject();
+  virtual QVariant parseParameter(const QStringList& theList, int theNbParam) const;
 
   template<class T>
     T* widget(int i) const {