Dump Python extension

This commit is contained in:
ouv 2008-11-29 16:25:48 +00:00
parent 246b043ec9
commit f7a07e2eda
10 changed files with 374 additions and 70 deletions

View File

@ -478,6 +478,9 @@ bool SMESHGUI_ExtrusionAlongPathDlg::ClickOnApply()
!myMeshActor || myPathMesh->_is_nil() || myPathShape->_is_nil())
return false;
if (!isValid())
return false;
SMESH::long_array_var anElementsId = new SMESH::long_array;
if (MeshCheck->isChecked()) {
@ -559,16 +562,17 @@ bool SMESHGUI_ExtrusionAlongPathDlg::ClickOnApply()
return false;
}
QStringList aParameters;
// get angles
SMESH::double_array_var anAngles = new SMESH::double_array;
if (AnglesGrp->isChecked()) {
anAngles->length(AnglesList->count());
anAngles->length(myAnglesList.count());
int j = 0;
bool bOk;
for (int i = 0; i < AnglesList->count(); i++) {
double angle = AnglesList->item(i)->text().toDouble(&bOk);
if (bOk)
anAngles[ j++ ] = angle*PI/180;
for (int i = 0; i < myAnglesList.count(); i++) {
double angle = myAnglesList[i];
anAngles[ j++ ] = angle*PI/180;
aParameters << AnglesList->item(i)->text();
}
anAngles->length(j);
}
@ -581,6 +585,10 @@ bool SMESHGUI_ExtrusionAlongPathDlg::ClickOnApply()
aBasePoint.z = ZSpin->GetValue();
}
aParameters << XSpin->text();
aParameters << YSpin->text();
aParameters << ZSpin->text();
try {
SUIT_OverrideCursor wc;
SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
@ -600,6 +608,9 @@ bool SMESHGUI_ExtrusionAlongPathDlg::ClickOnApply()
AnglesGrp->isChecked(), anAngles,
BasePointGrp->isChecked(), aBasePoint);
if( retVal == SMESH::SMESH_MeshEditor::EXTR_OK )
myMesh->SetParameters( SMESHGUI::JoinObjectParameters(aParameters) );
//wc.stop();
wc.suspend();
switch (retVal) {
@ -1140,7 +1151,18 @@ int SMESHGUI_ExtrusionAlongPathDlg::GetConstructorId()
//=======================================================================
void SMESHGUI_ExtrusionAlongPathDlg::OnAngleAdded()
{
AnglesList->addItem(QString::number(AngleSpin->GetValue()));
QString msg;
if( !AngleSpin->isValid( msg, true ) ) {
QString str( tr( "SMESH_INCORRECT_INPUT" ) );
if ( !msg.isEmpty() )
str += "\n" + msg;
SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
return;
}
AnglesList->addItem(AngleSpin->text());
myAnglesList.append(AngleSpin->GetValue());
updateLinearAngles();
}
//=======================================================================
@ -1151,7 +1173,12 @@ void SMESHGUI_ExtrusionAlongPathDlg::OnAngleRemoved()
{
QList<QListWidgetItem*> aList = AnglesList->selectedItems();
QListWidgetItem* anItem;
foreach(anItem, aList) delete anItem;
foreach(anItem, aList) {
myAnglesList.removeAt(AnglesList->row(anItem));
delete anItem;
}
updateLinearAngles();
}
//=================================================================================
@ -1199,3 +1226,45 @@ void SMESHGUI_ExtrusionAlongPathDlg::keyPressEvent( QKeyEvent* e )
ClickOnHelp();
}
}
//=================================================================================
// function : isValid
// purpose :
//=================================================================================
bool SMESHGUI_ExtrusionAlongPathDlg::isValid()
{
QString msg;
bool ok = true;
ok = XSpin->isValid( msg, true ) && ok;
ok = YSpin->isValid( msg, true ) && ok;
ok = ZSpin->isValid( msg, true ) && ok;
if( !ok ) {
QString str( tr( "SMESH_INCORRECT_INPUT" ) );
if ( !msg.isEmpty() )
str += "\n" + msg;
SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
return false;
}
return true;
}
//=================================================================================
// function : updateLinearAngles
// purpose :
//=================================================================================
void SMESHGUI_ExtrusionAlongPathDlg::updateLinearAngles()
{
bool enableLinear = true;
for( int row = 0, nbRows = AnglesList->count(); row < nbRows; row++ ) {
if( QListWidgetItem* anItem = AnglesList->item( row ) ) {
enableLinear = false;
anItem->text().toDouble(&enableLinear);
if( !enableLinear )
break;
}
}
if( !enableLinear )
LinearAnglesCheck->setChecked( false );
LinearAnglesCheck->setEnabled( enableLinear );
}

View File

@ -78,6 +78,10 @@ private:
int GetConstructorId();
void SetEditCurrentArgument( QToolButton* );
bool isValid();
void updateLinearAngles();
SMESHGUI* mySMESHGUI; /* Current SMESHGUI object */
SMESHGUI_IdValidator* myIdValidator;
LightApp_SelectionMgr* mySelectionMgr; /* User shape selection */
@ -94,6 +98,7 @@ private:
SUIT_SelectionFilter* myElementsFilter;
SUIT_SelectionFilter* myPathMeshFilter;
int myType;
QList<double> myAnglesList;
// widgets
QGroupBox* ConstructorsBox;

View File

@ -49,6 +49,7 @@
#include <LightApp_Application.h>
#include <LightApp_SelectionMgr.h>
#include <SalomeApp_Application.h>
#include <SalomeApp_IntSpinBox.h>
#include <SVTK_ViewWindow.h>
#include <SVTK_Selector.h>
@ -70,7 +71,6 @@
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QGridLayout>
#include <QSpinBox>
#include <QKeyEvent>
// IDL includes
@ -208,7 +208,7 @@ SMESHGUI_RevolutionDlg::SMESHGUI_RevolutionDlg( SMESHGUI* theModule )
SpinBox_Angle = new SMESHGUI_SpinBox(GroupAngleBox);
TextLabelNbSteps = new QLabel(tr("SMESH_NUMBEROFSTEPS"), GroupAngleBox);
SpinBox_NbSteps = new QSpinBox(GroupAngleBox);
SpinBox_NbSteps = new SalomeApp_IntSpinBox(GroupAngleBox);
GroupAngleLayout->addWidget(RadioButton3, 0, 0);
GroupAngleLayout->addWidget(RadioButton4, 0, 1);
@ -337,6 +337,8 @@ SMESHGUI_RevolutionDlg::SMESHGUI_RevolutionDlg( SMESHGUI* theModule )
connect(SpinBox_Tolerance, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
connect(CheckBoxPreview, SIGNAL(toggled(bool)), this, SLOT(onDisplaySimulation(bool)));
connect(SpinBox_Angle, SIGNAL(textChanged(const QString&)), this, SLOT(onAngleTextChange(const QString&)));
ConstructorsClicked(0);
SelectionIntoArgument();
}
@ -444,10 +446,13 @@ void SMESHGUI_RevolutionDlg::ConstructorsClicked (int constructorId)
// function : ClickOnApply()
// purpose :
//=================================================================================
void SMESHGUI_RevolutionDlg::ClickOnApply()
bool SMESHGUI_RevolutionDlg::ClickOnApply()
{
if (mySMESHGUI->isActiveStudyLocked())
return;
return false;
if (!isValid())
return false;
if (myNbOkElements && IsAxisOk()) {
QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
@ -474,6 +479,17 @@ void SMESHGUI_RevolutionDlg::ClickOnApply()
if ( GroupAngle->checkedId() == 1 )
anAngle = anAngle/aNbSteps;
QStringList aParameters;
aParameters << SpinBox_X->text();
aParameters << SpinBox_Y->text();
aParameters << SpinBox_Z->text();
aParameters << SpinBox_DX->text();
aParameters << SpinBox_DY->text();
aParameters << SpinBox_DZ->text();
aParameters << SpinBox_Angle->text();
aParameters << SpinBox_NbSteps->text();
aParameters << SpinBox_Tolerance->text();
try {
SUIT_OverrideCursor aWaitCursor;
SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
@ -484,6 +500,8 @@ void SMESHGUI_RevolutionDlg::ClickOnApply()
anAngle, aNbSteps, aTolerance);
else
aMeshEditor->RotationSweep(anElementsId.inout(), anAxis, anAngle, aNbSteps, aTolerance);
myMesh->SetParameters( SMESHGUI::JoinObjectParameters(aParameters) );
} catch (...) {
}
@ -494,6 +512,8 @@ void SMESHGUI_RevolutionDlg::ClickOnApply()
ConstructorsClicked(GetConstructorId());
SelectionIntoArgument();
}
return true;
}
//=================================================================================
@ -502,8 +522,8 @@ void SMESHGUI_RevolutionDlg::ClickOnApply()
//=================================================================================
void SMESHGUI_RevolutionDlg::ClickOnOk()
{
ClickOnApply();
ClickOnCancel();
if( ClickOnApply() )
ClickOnCancel();
}
//=================================================================================
@ -546,6 +566,19 @@ void SMESHGUI_RevolutionDlg::ClickOnHelp()
}
}
//=======================================================================
// function : onAngleTextChange()
// purpose :
//=======================================================================
void SMESHGUI_RevolutionDlg::onAngleTextChange (const QString& theNewText)
{
bool isNumber;
SpinBox_Angle->text().toDouble( &isNumber );
if( !isNumber )
RadioButton3->setChecked( true );
RadioButton4->setEnabled( isNumber );
}
//=======================================================================
// function : onTextChange()
// purpose :
@ -1051,3 +1084,32 @@ void SMESHGUI_RevolutionDlg::onDisplaySimulation(bool toDisplayPreview)
mySimulation->SetVisibility(false);
}
}
//=================================================================================
// function : isValid
// purpose :
//=================================================================================
bool SMESHGUI_RevolutionDlg::isValid()
{
QString msg;
bool ok = true;
ok = SpinBox_X->isValid( msg, true ) && ok;
ok = SpinBox_Y->isValid( msg, true ) && ok;
ok = SpinBox_Z->isValid( msg, true ) && ok;
ok = SpinBox_DX->isValid( msg, true ) && ok;
ok = SpinBox_DY->isValid( msg, true ) && ok;
ok = SpinBox_DZ->isValid( msg, true ) && ok;
ok = SpinBox_Angle->isValid( msg, true ) && ok;
ok = SpinBox_NbSteps->isValid( msg, true ) && ok;
ok = SpinBox_Tolerance->isValid( msg, true ) && ok;
if( !ok ) {
QString str( tr( "SMESH_INCORRECT_INPUT" ) );
if ( !msg.isEmpty() )
str += "\n" + msg;
SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
return false;
}
return true;
}

View File

@ -43,7 +43,7 @@ class QLineEdit;
class QPushButton;
class QRadioButton;
class QCheckBox;
class QSpinBox;
class SalomeApp_IntSpinBox;
class SMESHGUI_IdValidator;
class SMESHGUI_SpinBox;
class SMESHGUI;
@ -75,6 +75,8 @@ private:
int GetConstructorId();
bool IsAxisOk();
bool isValid();
SMESHGUI* mySMESHGUI; /* Current SMESHGUI object */
SMESHGUI_IdValidator* myIdValidator;
LightApp_SelectionMgr* mySelectionMgr; /* User shape selection */
@ -132,7 +134,7 @@ private:
QLabel* TextLabelAngle;
SMESHGUI_SpinBox* SpinBox_Angle;
QLabel* TextLabelNbSteps;
QSpinBox* SpinBox_NbSteps;
SalomeApp_IntSpinBox* SpinBox_NbSteps;
QLabel* TextLabelTolerance;
SMESHGUI_SpinBox* SpinBox_Tolerance;
@ -142,13 +144,14 @@ private slots:
void ConstructorsClicked( int );
void ClickOnOk();
void ClickOnCancel();
void ClickOnApply();
bool ClickOnApply();
void ClickOnHelp();
void SetEditCurrentArgument();
void SelectionIntoArgument();
void DeactivateActiveDialog();
void ActivateThisDialog();
void onTextChange( const QString& );
void onAngleTextChange( const QString& );
void onSelectMesh( bool );
void onVectorChanged();
void toDisplaySimulation();

View File

@ -439,13 +439,14 @@ bool SMESHGUI_TranslationDlg::ClickOnApply()
QStringList aParameters;
aParameters << SpinBox1_1->text();
aParameters << SpinBox1_2->text();
aParameters << SpinBox1_3->text();
if (GetConstructorId() == 0) {
if (GetConstructorId() == 0)
aParameters << SpinBox2_1->text();
aParameters << SpinBox1_2->text();
if (GetConstructorId() == 0)
aParameters << SpinBox2_2->text();
aParameters << SpinBox1_3->text();
if (GetConstructorId() == 0)
aParameters << SpinBox2_3->text();
}
int actionButton = ActionGroup->checkedId();
bool makeGroups = ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() );

View File

@ -899,8 +899,8 @@ void _pyMeshEditor::Process( const Handle(_pyCommand)& theCommand)
"BestSplit","Smooth","SmoothObject","SmoothParametric","SmoothParametricObject",
"ConvertToQuadratic","ConvertFromQuadratic","RenumberNodes","RenumberElements",
"RotationSweep","RotationSweepObject","ExtrusionSweep","AdvancedExtrusion",
"ExtrusionSweepObject","ExtrusionSweepObject1D","ExtrusionSweepObject2D","Mirror",
"MirrorObject","Translate","TranslateObject","Rotate","RotateObject",
"ExtrusionSweepObject","ExtrusionSweepObject1D","ExtrusionSweepObject2D","ExtrusionAlongPath",
"Mirror","MirrorObject","Translate","TranslateObject","Rotate","RotateObject",
"FindCoincidentNodes","FindCoincidentNodesOnPart","MergeNodes","FindEqualElements",
"MergeElements","MergeEqualElements","SewFreeBorders","SewConformFreeBorders",
"SewBorderToSide","SewSideElements","ChangeElemNodes","GetLastCreatedNodes",

View File

@ -1401,10 +1401,9 @@ void SMESH_MeshEditor_i::RotationSweep(const SMESH::long_array & theIDsOfElement
CORBA::Double theTolerance)
{
if ( !myPreviewMode ) {
TPythonDump() << "axis = " << theAxis;
TPythonDump() << this << ".RotationSweep( "
<< theIDsOfElements
<< ", axis, "
<< theIDsOfElements << ", "
<< theAxis << ", "
<< theAngleInRadians << ", "
<< theNbOfSteps << ", "
<< theTolerance << " )";
@ -1436,12 +1435,11 @@ SMESH_MeshEditor_i::RotationSweepMakeGroups(const SMESH::long_array& theIDsOfEle
theTolerance,
true);
if ( !myPreviewMode ) {
TPythonDump()<< "axis = " << theAxis;
TPythonDump aPythonDump;
DumpGroupsList(aPythonDump,aGroups);
aPythonDump<< this << ".RotationSweepMakeGroups( "
<< theIDsOfElements
<< ", axis, "
<< theIDsOfElements << ", "
<< theAxis << ", "
<< theAngleInRadians << ", "
<< theNbOfSteps << ", "
<< theTolerance << " )";
@ -1912,24 +1910,18 @@ SMESH::SMESH_MeshEditor::Extrusion_Error
const SMESH::PointStruct & theRefPoint)
{
if ( !myPreviewMode ) {
TPythonDump() << "rotAngles = " << theAngles;
if ( theHasRefPoint )
TPythonDump() << "refPoint = SMESH.PointStruct( "
<< theRefPoint.x << ", "
<< theRefPoint.y << ", "
<< theRefPoint.z << " )";
else
TPythonDump() << "refPoint = SMESH.PointStruct( 0,0,0 )";
TPythonDump() << "error = " << this << ".ExtrusionAlongPath( "
<< theIDsOfElements << ", "
<< thePathMesh << ", "
<< thePathShape << ", "
<< theNodeStart << ", "
<< theHasAngles << ", "
<< "rotAngles" << ", "
<< theHasRefPoint << ", refPoint )";
<< theAngles << ", "
<< theHasRefPoint << ", "
<< "SMESH.PointStruct( "
<< ( theHasRefPoint ? theRefPoint.x : 0 ) << ", "
<< ( theHasRefPoint ? theRefPoint.y : 0 ) << ", "
<< ( theHasRefPoint ? theRefPoint.z : 0 ) << " ) )";
}
SMESH::SMESH_MeshEditor::Extrusion_Error anError;
extrusionAlongPath( theIDsOfElements,
@ -2023,16 +2015,6 @@ SMESH_MeshEditor_i::ExtrusionAlongPathMakeGroups(const SMESH::long_array& theI
true,
Error);
if ( !myPreviewMode ) {
TPythonDump() << "rotAngles = " << theAngles;
if ( theHasRefPoint )
TPythonDump() << "refPoint = SMESH.PointStruct( "
<< theRefPoint.x << ", "
<< theRefPoint.y << ", "
<< theRefPoint.z << " )";
else
TPythonDump() << "refPoint = SMESH.PointStruct( 0,0,0 )";
bool isDumpGroups = aGroups && aGroups->length() > 0;
TPythonDump aPythonDump;
if(isDumpGroups) {
@ -2049,8 +2031,12 @@ SMESH_MeshEditor_i::ExtrusionAlongPathMakeGroups(const SMESH::long_array& theI
<< thePathShape << ", "
<< theNodeStart << ", "
<< theHasAngles << ", "
<< "rotAngles" << ", "
<< theHasRefPoint << ", refPoint )";
<< theAngles << ", "
<< theHasRefPoint << ", "
<< "SMESH.PointStruct( "
<< ( theHasRefPoint ? theRefPoint.x : 0 ) << ", "
<< ( theHasRefPoint ? theRefPoint.y : 0 ) << ", "
<< ( theHasRefPoint ? theRefPoint.z : 0 ) << " ) )";
}
return aGroups;
}

View File

@ -33,9 +33,9 @@
#include <string>
#ifdef _DEBUG_
static int MYDEBUG = 1;
static int MYDEBUG = 0;
#else
static int MYDEBUG = 1;
static int MYDEBUG = 0;
#endif
using namespace std;
@ -242,7 +242,7 @@ void SMESH_NoteBook::ReplaceVariables()
}
}
if(it != _objectMap.end() && !aMethod.IsEmpty()) {
if(it != _objectMap.end()) {
ObjectStates *aStates = (*it).second;
// Case for LocalLength hypothesis
if(aStates->GetObjectType().IsEqual("LocalLength") && aStates->GetCurrectState().size() >= 2) {
@ -355,11 +355,36 @@ void SMESH_NoteBook::ReplaceVariables()
}
}
else if(aCurrentStateSize == 6) { // translation by x1, x2, y1, y2, z1, z2
// TODO
isVariableFound = true;
for(int j = 0; j < 3; j++) {
TCollection_AsciiString anArg = aCmd->GetArg(anArgIndex+j);
TCollection_AsciiString aValue1 = aCurrentState.at(2*j), aValue2 = aCurrentState.at(2*j+1);
bool aV1 = !aValue1.IsEmpty();
bool aV2 = !aValue2.IsEmpty();
double aValue, aCurrentValue = anArg.IsRealValue() ? anArg.RealValue() : 0;
if(aV1 && !aV2) {
if(!GetReal(aValue1, aValue))
aValue = 0;
aValue2 = TCollection_AsciiString( aValue + aCurrentValue );
}
else if(!aV1 && aV2) {
if(!GetReal(aValue2, aValue))
aValue = 0;
aValue1 = TCollection_AsciiString( aValue - aCurrentValue );
}
else if(!aV1 && !aV2) {
aValue1 = TCollection_AsciiString( 0 );
aValue2 = TCollection_AsciiString( aCurrentValue );
}
aCmd->SetArg(anArgIndex+j, aValue1 + ", " + aValue2 );
}
}
}
if(isVariableFound) {
aCmd->SetArg(anArgIndex - 1, TCollection_AsciiString(SMESH_2smeshpy::SmeshpyName())+".PointStructStr");
TCollection_AsciiString aDim;
if(aCurrentStateSize == 6)
aDim = "6";
aCmd->SetArg(anArgIndex - 1, TCollection_AsciiString(SMESH_2smeshpy::SmeshpyName())+".PointStructStr"+aDim);
aCmd->SetArg(anArgIndex - 2, TCollection_AsciiString(SMESH_2smeshpy::SmeshpyName())+".DirStructStr");
}
aStates->IncrementState();
@ -367,9 +392,10 @@ void SMESH_NoteBook::ReplaceVariables()
else if(aMethod.IsEqual("Rotate") ||
aMethod.IsEqual("RotateMakeGroups") ||
aMethod.IsEqual("RotateMakeMesh") ||
aMethod.IsEqual("RotationSweep") ||
aMethod.IsEqual("RotationSweepMakeGroups") ||
aMethod.IsEqual("Mirror") ||
aMethod.IsEqual("MirrorMakeGroups") ||
aMethod.IsEqual("MirrorMakeMesh")) {
aMethod.IsEqual("MirrorMakeGroups")) {
bool isSubstitute = false;
int anArgIndex = 0;
for(int i = 1, n = aCmd->GetNbArgs(); i <= n; i++) {
@ -381,7 +407,7 @@ void SMESH_NoteBook::ReplaceVariables()
if(anArgIndex > 0) {
for(int j = 0; j < aCurrentStateSize; j++) {
if(!aCurrentState.at(j).IsEmpty()) {
if(j < 6) // from 0 to 5 - axis struct, 6 - angle
if(j < 6) // 0-5 - axis struct, 6 - angle (rotation & sweep), 7-8 - nbSteps and tolerance (sweep)
isSubstitute = true;
aCmd->SetArg(anArgIndex+j, aCurrentState.at(j));
}
@ -419,7 +445,7 @@ void SMESH_NoteBook::ReplaceVariables()
if(anArgIndex > 0) {
for(int j = 0; j < aCurrentStateSize; j++) {
if(!aCurrentState.at(j).IsEmpty()) {
if(j < 3) // from 0 to 2 - dir struct, 3 - number of steps
if(j < 3) // 0-2 - dir struct, 3 - number of steps
isSubstitute = true;
aCmd->SetArg(anArgIndex+j, aCurrentState.at(j));
}
@ -431,6 +457,38 @@ void SMESH_NoteBook::ReplaceVariables()
}
aStates->IncrementState();
}
else if(aMethod.IsEqual("ExtrusionAlongPath") ||
aMethod.IsEqual("ExtrusionAlongPathMakeGroups") ||
/* workaround for a bug in the command parsing algorithm */
aCmd->GetString().Search("ExtrusionAlongPathMakeGroups") != -1) {
int aNbAngles = aCurrentStateSize-3; // State looks like "Angle1:...:AngleN:X:Y:Z"
bool isSubstitute = false;
int anArgIndex = 0;
for(int i = 1, n = aCmd->GetNbArgs(); i <= n; i++) {
if(aCmd->GetArg(i).IsEqual("SMESH.PointStruct")) {
anArgIndex = i-1-aNbAngles;
break;
}
}
if(anArgIndex > 0) {
int j = 0;
for(; j < aNbAngles; j++) {
if(!aCurrentState.at(j).IsEmpty()) {
aCmd->SetArg(anArgIndex+j-1, aCurrentState.at(j));
}
}
for(; j < aNbAngles+3; j++) {
if(!aCurrentState.at(j).IsEmpty()) {
isSubstitute = true;
aCmd->SetArg(anArgIndex+j+2, aCurrentState.at(j));
}
}
}
if(isSubstitute)
aCmd->SetArg(anArgIndex + aNbAngles + 1,
TCollection_AsciiString(SMESH_2smeshpy::SmeshpyName())+".PointStructStr");
aStates->IncrementState();
}
else if(aMethod.IsEqual("TriToQuad") ||
aMethod.IsEqual("Concatenate") ||
aMethod.IsEqual("ConcatenateWithGroups")) {
@ -606,3 +664,35 @@ TCollection_AsciiString SMESH_NoteBook::GetResultScript() const
aResult+=_commands[i]->GetString()+"\n";
return aResult;
}
//================================================================================
/*!
* \brief Return value of the variable
*/
//================================================================================
bool SMESH_NoteBook::GetReal(const TCollection_AsciiString& theVarName, double& theValue)
{
bool ok = false;
SMESH_Gen_i *aGen = SMESH_Gen_i::GetSMESHGen();
if(!aGen)
return ok;
SALOMEDS::Study_ptr aStudy = aGen->GetCurrentStudy();
if(aStudy->_is_nil())
return ok;
TCollection_AsciiString aVarName = theVarName;
aVarName.RemoveAll('\"');
if(aVarName.IsEmpty())
return ok;
const char* aName = aVarName.ToCString();
if(aStudy->IsVariable(aName) && (aStudy->IsReal(aName) || aStudy->IsInteger(aName))) {
theValue = aStudy->GetReal(aVarName.ToCString());
ok = true;
}
return ok;
}

View File

@ -93,6 +93,8 @@ public:
private:
void InitObjectMap();
void ProcessLayerDistribution();
bool GetReal(const TCollection_AsciiString& theVarName, double& theValue);
private:

View File

@ -155,6 +155,11 @@ DefaultSize, DefaultGeom, Custom = 0,0,1
PrecisionConfusion = 1e-07
## Converts an angle from degrees to radians
def DegreesToRadians(AngleInDegrees):
from math import pi
return AngleInDegrees * pi / 180.0
# Salome notebook variable separator
variable_separator = ":"
@ -185,6 +190,54 @@ class PointStructStr:
else:
self.z = zStr
# Parametrized substitute for PointStruct (with 6 parameters)
class PointStructStr6:
x1 = 0
y1 = 0
z1 = 0
x2 = 0
y2 = 0
z2 = 0
xStr1 = ""
yStr1 = ""
zStr1 = ""
xStr2 = ""
yStr2 = ""
zStr2 = ""
def __init__(self, x1Str, x2Str, y1Str, y2Str, z1Str, z2Str):
self.x1Str = x1Str
self.x2Str = x2Str
self.y1Str = y1Str
self.y2Str = y2Str
self.z1Str = z1Str
self.z2Str = z2Str
if isinstance(x1Str, str) and notebook.isVariable(x1Str):
self.x1 = notebook.get(x1Str)
else:
self.x1 = x1Str
if isinstance(x2Str, str) and notebook.isVariable(x2Str):
self.x2 = notebook.get(x2Str)
else:
self.x2 = x2Str
if isinstance(y1Str, str) and notebook.isVariable(y1Str):
self.y1 = notebook.get(y1Str)
else:
self.y1 = y1Str
if isinstance(y2Str, str) and notebook.isVariable(y2Str):
self.y2 = notebook.get(y2Str)
else:
self.y2 = y2Str
if isinstance(z1Str, str) and notebook.isVariable(z1Str):
self.z1 = notebook.get(z1Str)
else:
self.z1 = z1Str
if isinstance(z2Str, str) and notebook.isVariable(z2Str):
self.z2 = notebook.get(z2Str)
else:
self.z2 = z2Str
# Parametrized substitute for AxisStruct
class AxisStructStr:
@ -252,8 +305,14 @@ def ParseDirStruct(Dir):
Parameters = "::"
if isinstance(Dir, DirStructStr):
pntStr = Dir.pointStruct
Parameters = str(pntStr.xStr) + ":" + str(pntStr.yStr) + ":" + str(pntStr.zStr)
Point = PointStruct(pntStr.x, pntStr.y, pntStr.z)
if isinstance(pntStr, PointStructStr6):
Parameters = str(pntStr.x1Str) + ":" + str(pntStr.x2Str) + ":"
Parameters += str(pntStr.y1Str) + ":" + str(pntStr.y2Str) + ":"
Parameters += str(pntStr.z1Str) + ":" + str(pntStr.z2Str)
Point = PointStruct(pntStr.x2 - pntStr.x1, pntStr.y2 - pntStr.y1, pntStr.z2 - pntStr.z1)
else:
Parameters = str(pntStr.xStr) + ":" + str(pntStr.yStr) + ":" + str(pntStr.zStr)
Point = PointStruct(pntStr.x, pntStr.y, pntStr.z)
Dir = DirStruct(Point)
return Dir, Parameters
@ -266,6 +325,24 @@ def ParseAxisStruct(Axis):
Axis = AxisStruct(Axis.x, Axis.y, Axis.z, Axis.dx, Axis.dy, Axis.dz)
return Axis, Parameters
## Return list of variable values from salome notebook
def ParseAngles(list):
Result = []
Parameters = ""
for parameter in list:
if isinstance(parameter,str) and notebook.isVariable(parameter):
Result.append(DegreesToRadians(notebook.get(parameter)))
pass
else:
Result.append(parameter)
pass
Parameters = Parameters + str(parameter)
Parameters = Parameters + ":"
pass
Parameters = Parameters[:len(Parameters)-1]
return Result, Parameters
def IsEqual(val1, val2, tol=PrecisionConfusion):
if abs(val1 - val2) < tol:
return True
@ -330,11 +407,6 @@ def TreatHypoStatus(status, hypName, geomName, isAlgo):
print hypName, "was not assigned to",geomName,":", reason
pass
## Converts an angle from degrees to radians
def DegreesToRadians(AngleInDegrees):
from math import pi
return AngleInDegrees * pi / 180.0
# end of l1_auxiliary
## @}
@ -2335,7 +2407,7 @@ class Mesh:
## Generates new elements by rotation of the elements around the axis
# @param IDsOfElements the list of ids of elements to sweep
# @param Axis the axis of rotation, AxisStruct or line(geom object)
# @param AngleInRadians the angle of Rotation
# @param AngleInRadians the angle of Rotation (in radians) or a name of variable which defines angle in degrees
# @param NbOfSteps the number of steps
# @param Tolerance tolerance
# @param MakeGroups forces the generation of new groups from existing ones
@ -2345,12 +2417,22 @@ class Mesh:
# @ingroup l2_modif_extrurev
def RotationSweep(self, IDsOfElements, Axis, AngleInRadians, NbOfSteps, Tolerance,
MakeGroups=False, TotalAngle=False):
flag = False
if isinstance(AngleInRadians,str):
flag = True
AngleInRadians,AngleParameters = geompyDC.ParseParameters(AngleInRadians)
if flag:
AngleInRadians = DegreesToRadians(AngleInRadians)
if IDsOfElements == []:
IDsOfElements = self.GetElementsId()
if ( isinstance( Axis, geompyDC.GEOM._objref_GEOM_Object)):
Axis = self.smeshpyD.GetAxisStruct(Axis)
Axis,AxisParameters = ParseAxisStruct(Axis)
if TotalAngle and NbOfSteps:
AngleInRadians /= NbOfSteps
NbOfSteps,Tolerance,Parameters = geompyDC.ParseParameters(NbOfSteps,Tolerance)
Parameters = AxisParameters + ":" + AngleParameters + ":" + Parameters
self.mesh.SetParameters(Parameters)
if MakeGroups:
return self.editor.RotationSweepMakeGroups(IDsOfElements, Axis,
AngleInRadians, NbOfSteps, Tolerance)
@ -2496,6 +2578,8 @@ class Mesh:
def ExtrusionAlongPath(self, IDsOfElements, PathMesh, PathShape, NodeStart,
HasAngles, Angles, HasRefPoint, RefPoint,
MakeGroups=False, LinearVariation=False):
Angles,AnglesParameters = ParseAngles(Angles)
RefPoint,RefPointParameters = ParsePointStruct(RefPoint)
if IDsOfElements == []:
IDsOfElements = self.GetElementsId()
if ( isinstance( RefPoint, geompyDC.GEOM._objref_GEOM_Object)):
@ -2506,6 +2590,8 @@ class Mesh:
if HasAngles and Angles and LinearVariation:
Angles = self.editor.LinearAnglesVariation( PathMesh, PathShape, Angles )
pass
Parameters = AnglesParameters + ":" + RefPointParameters
self.mesh.SetParameters(Parameters)
if MakeGroups:
return self.editor.ExtrusionAlongPathMakeGroups(IDsOfElements, PathMesh,
PathShape, NodeStart, HasAngles,