mirror of
https://git.salome-platform.org/gitpub/modules/smesh.git
synced 2025-01-18 09:50:36 +05:00
0021308: Remove hard-coded dependency of the external mesh plugins from the SMESH module
Insert names of variables set via SMESH_Gen_i::UpdateParameters() into dump strings using TVar structure
This commit is contained in:
parent
b32aba1501
commit
27624ded2e
@ -51,8 +51,17 @@ namespace SMESH
|
||||
|
||||
size_t TPythonDump::myCounter = 0;
|
||||
|
||||
TVar::TVar(CORBA::Double value):myVals(1) { myVals[0] = SMESH_Comment(value); }
|
||||
TVar::TVar(CORBA::Long value):myVals(1) { myVals[0] = SMESH_Comment(value); }
|
||||
TVar::TVar(CORBA::Short value):myVals(1) { myVals[0] = SMESH_Comment(value); }
|
||||
TVar::TVar(const SMESH::double_array& value):myVals(value.length())
|
||||
{
|
||||
for ( size_t i = 0; i < value.length(); i++)
|
||||
myVals[i] = SMESH_Comment(value[i]);
|
||||
}
|
||||
|
||||
TPythonDump::
|
||||
TPythonDump()
|
||||
TPythonDump():myVarsCounter(0)
|
||||
{
|
||||
++myCounter;
|
||||
}
|
||||
@ -67,10 +76,44 @@ namespace SMESH
|
||||
if(!aStudy->_is_nil() && !aCollection.IsEmpty()){
|
||||
aSMESHGen->AddToPythonScript(aStudy->StudyId(),aCollection);
|
||||
if(MYDEBUG) MESSAGE(aString);
|
||||
aSMESHGen->UpdateParameters(""); // prevent misuse of already treated variables
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TPythonDump& //!< to store a variable value
|
||||
TPythonDump::
|
||||
operator<<(const TVar& theVarValue)
|
||||
{
|
||||
if ( theVarValue.myVals.empty() ) return *this;
|
||||
|
||||
const std::vector< std::string >& varNames = SMESH_Gen_i::GetSMESHGen()->GetLastParameters();
|
||||
if ( theVarValue.myVals.size() > 1 )
|
||||
{
|
||||
myStream << "[ ";
|
||||
for ( size_t i = 1; i <= theVarValue.myVals.size(); ++i )
|
||||
{
|
||||
if ( myVarsCounter < varNames.size() && !varNames[ myVarsCounter ].empty() )
|
||||
myStream << TVar::Quote() << varNames[ myVarsCounter ] << TVar::Quote();
|
||||
else
|
||||
myStream << theVarValue.myVals[i-1];
|
||||
if ( i < theVarValue.myVals.size() )
|
||||
myStream << ", ";
|
||||
++myVarsCounter;
|
||||
}
|
||||
myStream << " ]";
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( myVarsCounter < varNames.size() && !varNames[ myVarsCounter ].empty() )
|
||||
myStream << TVar::Quote() << varNames[ myVarsCounter ] << TVar::Quote();
|
||||
else
|
||||
myStream << theVarValue.myVals[0];
|
||||
++myVarsCounter;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
TPythonDump&
|
||||
TPythonDump::
|
||||
operator<<(long int theArg){
|
||||
@ -375,23 +418,32 @@ namespace SMESH
|
||||
|
||||
TPythonDump& TPythonDump::operator<<(const SMESH::AxisStruct & theAxis)
|
||||
{
|
||||
myStream << "SMESH.AxisStruct( "
|
||||
<< theAxis.x << ", "
|
||||
<< theAxis.y << ", "
|
||||
<< theAxis.z << ", "
|
||||
<< theAxis.vx << ", "
|
||||
<< theAxis.vy << ", "
|
||||
<< theAxis.vz << " )";
|
||||
*this << "SMESH.AxisStruct( "
|
||||
<< TVar( theAxis.x ) << ", "
|
||||
<< TVar( theAxis.y ) << ", "
|
||||
<< TVar( theAxis.z ) << ", "
|
||||
<< TVar( theAxis.vx ) << ", "
|
||||
<< TVar( theAxis.vy ) << ", "
|
||||
<< TVar( theAxis.vz ) << " )";
|
||||
return *this;
|
||||
}
|
||||
|
||||
TPythonDump& TPythonDump::operator<<(const SMESH::DirStruct & theDir)
|
||||
{
|
||||
const SMESH::PointStruct & P = theDir.PS;
|
||||
myStream << "SMESH.DirStruct( SMESH.PointStruct ( "
|
||||
<< P.x << ", "
|
||||
<< P.y << ", "
|
||||
<< P.z << " ))";
|
||||
*this << "SMESH.DirStruct( SMESH.PointStruct ( "
|
||||
<< TVar( P.x ) << ", "
|
||||
<< TVar( P.y ) << ", "
|
||||
<< TVar( P.z ) << " ))";
|
||||
return *this;
|
||||
}
|
||||
|
||||
TPythonDump& TPythonDump::operator<<(const SMESH::PointStruct & P)
|
||||
{
|
||||
*this << "SMESH.PointStruct ( "
|
||||
<< TVar( P.x ) << ", "
|
||||
<< TVar( P.y ) << ", "
|
||||
<< TVar( P.z ) << " )";
|
||||
return *this;
|
||||
}
|
||||
|
||||
@ -817,6 +869,13 @@ TCollection_AsciiString SMESH_Gen_i::DumpPython_impl
|
||||
aScript = SMESH_2smeshpy::ConvertScript( aScript, anEntry2AccessorMethod,
|
||||
theObjectNames, theStudy, isHistoricalDump );
|
||||
|
||||
// Replace characters used instead of quote marks to quote notebook variables
|
||||
{
|
||||
int pos = 1;
|
||||
while (( pos = aScript.Location( 1, SMESH::TVar::Quote(), pos, aScript.Length() )))
|
||||
aScript.SetValue( pos, '"' );
|
||||
}
|
||||
|
||||
// Find entries to be replaced by names
|
||||
Handle(TColStd_HSequenceOfInteger) aSeq = FindEntries(aScript);
|
||||
Standard_Integer aLen = aSeq->Length();
|
||||
|
@ -30,6 +30,7 @@
|
||||
#include CORBA_SERVER_HEADER(SALOMEDS)
|
||||
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
class SMESH_Gen_i;
|
||||
class SMESH_MeshEditor_i;
|
||||
@ -65,7 +66,7 @@ public:
|
||||
|
||||
/*!
|
||||
* \brief Return the name of the python file wrapping IDL API
|
||||
* \retval TCollection_AsciiString - The file name
|
||||
* \retval const char* - the file name
|
||||
*/
|
||||
static const char* SmeshpyName() { return "smesh"; }
|
||||
static const char* GenName() { return "smesh"; }
|
||||
@ -79,6 +80,26 @@ namespace SMESH
|
||||
class Functor_i;
|
||||
class Measurements_i;
|
||||
|
||||
// ===========================================================================================
|
||||
/*!
|
||||
* \brief Object used to make TPythonDump know that its held value can be a varible
|
||||
*
|
||||
* TPythonDump substitute TVar with names of notebook variables if any.
|
||||
*/
|
||||
// ===========================================================================================
|
||||
|
||||
struct SMESH_I_EXPORT TVar
|
||||
{
|
||||
std::vector< std::string > myVals;
|
||||
TVar(CORBA::Double value);
|
||||
TVar(CORBA::Long value);
|
||||
TVar(CORBA::Short value);
|
||||
TVar(const SMESH::double_array& value);
|
||||
// string used to temporary quote variable names in order
|
||||
// not to confuse variables with string arguments
|
||||
static char Quote() { return '$'; }
|
||||
};
|
||||
|
||||
// ===========================================================================================
|
||||
/*!
|
||||
* \brief Utility helping in storing SMESH engine calls as python commands
|
||||
@ -89,10 +110,14 @@ namespace SMESH
|
||||
{
|
||||
std::ostringstream myStream;
|
||||
static size_t myCounter;
|
||||
int myVarsCounter; // counts stored TVar's
|
||||
public:
|
||||
TPythonDump();
|
||||
virtual ~TPythonDump();
|
||||
|
||||
TPythonDump&
|
||||
operator<<(const TVar& theVariableValue);
|
||||
|
||||
TPythonDump&
|
||||
operator<<(long int theArg);
|
||||
|
||||
@ -168,6 +193,9 @@ namespace SMESH
|
||||
TPythonDump&
|
||||
operator<<(const SMESH::DirStruct & theDir);
|
||||
|
||||
TPythonDump&
|
||||
operator<<(const SMESH::PointStruct & P);
|
||||
|
||||
TPythonDump&
|
||||
operator<<(const TCollection_AsciiString & theArg);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user