Start implementation of the notebook in SMESH module.

This commit is contained in:
rnv 2008-11-13 09:28:44 +00:00
parent 7730fea77b
commit df96082091
14 changed files with 530 additions and 18 deletions

View File

@ -56,6 +56,18 @@ module SMESH
*/
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
*/

View File

@ -226,6 +226,27 @@ QFrame* SMESHGUI_GenericHypothesisCreator::buildStdFrame()
break;
case QVariant::String:
{
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 );
@ -233,6 +254,7 @@ QFrame* SMESHGUI_GenericHypothesisCreator::buildStdFrame()
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 = "";

View 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&,

View 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

View 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"
@ -124,13 +125,15 @@ SMESH_2smeshpy::ConvertScript(const TCollection_AsciiString& theScript,
{
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

View File

@ -470,6 +470,9 @@ public:
*/
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
SMESH::SMESH_Hypothesis_ptr createHypothesis( const char* theHypName,

View 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() );
}

View 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

View 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();

View File

@ -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;
}

View File

@ -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

View 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()

View 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,6 +409,12 @@ 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() );
@ -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");
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");
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;
}

View 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 {