From c03e6618d505c54b6619acabf0e9e44385473dba Mon Sep 17 00:00:00 2001 From: eap Date: Fri, 23 Nov 2007 10:56:14 +0000 Subject: [PATCH] PAL16617 (Modification/Transformation operations with copy don't create a new mesh) + SMESH_Mesh MirrorMakeMesh (in long_array IDsOfElements, + SMESH_Mesh MirrorObjectMakeMesh (in SMESH_IDSource theObject, + SMESH_Mesh TranslateMakeMesh (in long_array IDsOfElements, + SMESH_Mesh TranslateObjectMakeMesh (in SMESH_IDSource theObject, + SMESH_Mesh RotateMakeMesh (in long_array IDsOfElements, + SMESH_Mesh RotateObjectMakeMesh (in SMESH_IDSource theObject, --- idl/SMESH_MeshEditor.idl | 36 +++- src/SMESHGUI/SMESHGUI_RotationDlg.cxx | 134 ++++++++++---- src/SMESHGUI/SMESHGUI_RotationDlg.h | 7 +- src/SMESHGUI/SMESHGUI_SymmetryDlg.cxx | 134 +++++++++++--- src/SMESHGUI/SMESHGUI_SymmetryDlg.h | 7 +- src/SMESHGUI/SMESHGUI_TranslationDlg.cxx | 123 ++++++++++--- src/SMESHGUI/SMESHGUI_TranslationDlg.h | 7 +- src/SMESH_I/SMESH_MeshEditor_i.cxx | 224 ++++++++++++++++++++++- src/SMESH_I/SMESH_MeshEditor_i.hxx | 40 +++- src/SMESH_SWIG/smesh.py | 116 ++++++++++++ 10 files changed, 721 insertions(+), 107 deletions(-) diff --git a/idl/SMESH_MeshEditor.idl b/idl/SMESH_MeshEditor.idl index f5a8cc421..121f8a307 100644 --- a/idl/SMESH_MeshEditor.idl +++ b/idl/SMESH_MeshEditor.idl @@ -418,31 +418,49 @@ module SMESH void Mirror (in long_array IDsOfElements, in AxisStruct Mirror, - in MirrorType theMirrorType, + in MirrorType Type, in boolean Copy); ListOfGroups MirrorMakeGroups (in long_array IDsOfElements, in AxisStruct Mirror, - in MirrorType theMirrorType); + in MirrorType Type); + SMESH_Mesh MirrorMakeMesh (in long_array IDsOfElements, + in AxisStruct Mirror, + in MirrorType Type, + in boolean CopyGroups, + in string MeshName); void MirrorObject (in SMESH_IDSource theObject, in AxisStruct Mirror, - in MirrorType theMirrorType, + in MirrorType Type, in boolean Copy); ListOfGroups MirrorObjectMakeGroups (in SMESH_IDSource theObject, in AxisStruct Mirror, - in MirrorType theMirrorType); + in MirrorType Type); + SMESH_Mesh MirrorObjectMakeMesh (in SMESH_IDSource theObject, + in AxisStruct Mirror, + in MirrorType Type, + in boolean CopyGroups, + in string MeshName); void Translate (in long_array IDsOfElements, in DirStruct Vector, in boolean Copy); ListOfGroups TranslateMakeGroups (in long_array IDsOfElements, in DirStruct Vector); + SMESH_Mesh TranslateMakeMesh (in long_array IDsOfElements, + in DirStruct Vector, + in boolean CopyGroups, + in string MeshName); void TranslateObject (in SMESH_IDSource theObject, in DirStruct Vector, in boolean Copy); ListOfGroups TranslateObjectMakeGroups (in SMESH_IDSource theObject, in DirStruct Vector); + SMESH_Mesh TranslateObjectMakeMesh (in SMESH_IDSource theObject, + in DirStruct Vector, + in boolean CopyGroups, + in string MeshName); void Rotate (in long_array IDsOfElements, in AxisStruct Axis, @@ -451,6 +469,11 @@ module SMESH ListOfGroups RotateMakeGroups (in long_array IDsOfElements, in AxisStruct Axis, in double AngleInRadians); + SMESH_Mesh RotateMakeMesh (in long_array IDsOfElements, + in AxisStruct Axis, + in double AngleInRadians, + in boolean CopyGroups, + in string MeshName); void RotateObject (in SMESH_IDSource theObject, in AxisStruct Axis, @@ -459,6 +482,11 @@ module SMESH ListOfGroups RotateObjectMakeGroups (in SMESH_IDSource theObject, in AxisStruct Axis, in double AngleInRadians); + SMESH_Mesh RotateObjectMakeMesh (in SMESH_IDSource theObject, + in AxisStruct Axis, + in double AngleInRadians, + in boolean CopyGroups, + in string MeshName); void FindCoincidentNodes (in double Tolerance, out array_of_long_array GroupsOfNodes); diff --git a/src/SMESHGUI/SMESHGUI_RotationDlg.cxx b/src/SMESHGUI/SMESHGUI_RotationDlg.cxx index 10f109222..a5cc46d98 100644 --- a/src/SMESHGUI/SMESHGUI_RotationDlg.cxx +++ b/src/SMESHGUI/SMESHGUI_RotationDlg.cxx @@ -51,6 +51,7 @@ #include "SVTK_Selector.h" #include "SVTK_Selection.h" #include "SALOME_ListIO.hxx" +#include "SALOMEDSClient_SObject.hxx" #include "utilities.h" @@ -77,6 +78,8 @@ using namespace std; +enum { MOVE_ELEMS_BUTTON = 0, COPY_ELEMS_BUTTON, MAKE_MESH_BUTTON }; //!< action type + //================================================================================= // class : SMESHGUI_RotationDlg() // purpose : @@ -175,7 +178,7 @@ SMESHGUI_RotationDlg::SMESHGUI_RotationDlg( SMESHGUI* theModule, const char* nam // Controls for elements selection TextLabelElements = new QLabel(GroupArguments, "TextLabelElements"); TextLabelElements->setText(tr("SMESH_ID_ELEMENTS" )); - TextLabelElements->setFixedWidth(74); + //TextLabelElements->setFixedWidth(74); GroupArgumentsLayout->addWidget(TextLabelElements, 0, 0); SelectElementsButton = new QPushButton(GroupArguments, "SelectElementsButton"); @@ -184,14 +187,14 @@ SMESHGUI_RotationDlg::SMESHGUI_RotationDlg( SMESHGUI* theModule, const char* nam SelectElementsButton->setToggleButton(FALSE); GroupArgumentsLayout->addWidget(SelectElementsButton, 0, 1); - LineEditElements = new QLineEdit(GroupArguments, "LineEditElements"); + LineEditElements = new QLineEdit(GroupArguments, "LineEditElements"); LineEditElements->setValidator(new SMESHGUI_IdValidator(this, "validator")); - GroupArgumentsLayout->addWidget(LineEditElements, 0, 2); + GroupArgumentsLayout->addMultiCellWidget(LineEditElements, 0, 0, 2, 3); // Control for the whole mesh selection CheckBoxMesh = new QCheckBox(GroupArguments, "CheckBoxMesh"); CheckBoxMesh->setText(tr("SMESH_SELECT_WHOLE_MESH" )); - GroupArgumentsLayout->addMultiCellWidget(CheckBoxMesh, 1, 1, 0, 2); + GroupArgumentsLayout->addMultiCellWidget(CheckBoxMesh, 1, 1, 0, 3); // Controls for axis defining GroupAxis = new QGroupBox(GroupArguments, "GroupAxis"); @@ -268,24 +271,31 @@ SMESHGUI_RotationDlg::SMESHGUI_RotationDlg( SMESHGUI* theModule, const char* nam SpinBox_DZ = new SMESHGUI_SpinBox(GroupAxis, "SpinBox_DZ"); GroupAxisLayout->addWidget(SpinBox_DZ, 1, 7); - GroupArgumentsLayout->addMultiCellWidget(GroupAxis, 2, 2, 0, 2); + GroupArgumentsLayout->addMultiCellWidget(GroupAxis, 2, 2, 0, 3); // Controls for angle defining TextLabelAngle = new QLabel(GroupArguments, "TextLabelAngle"); TextLabelAngle->setText(tr("SMESH_ANGLE")); - GroupArgumentsLayout->addMultiCellWidget(TextLabelAngle, 3, 3, 0, 1); + GroupArgumentsLayout->addMultiCellWidget(TextLabelAngle, 3, 3, 0, 2); SpinBox_Angle = new SMESHGUI_SpinBox(GroupArguments, "SpinBox_Angle"); GroupArgumentsLayout->addWidget(SpinBox_Angle, 3, 2); - // Controls for "Create a copy" option - CheckBoxCopy = new QCheckBox(GroupArguments, "CheckBoxCopy"); - CheckBoxCopy->setText(tr("SMESH_CREATE_COPY")); - GroupArgumentsLayout->addMultiCellWidget(CheckBoxCopy, 4, 4, 0, 2); + // action switch + ActionGroup = new QButtonGroup(1, Qt::Horizontal, GroupArguments, "ActionGroup"); + ActionGroup->setExclusive(true); + ActionGroup->insert(new QRadioButton(tr("SMESH_MOVE_ELEMENTS"),ActionGroup), MOVE_ELEMS_BUTTON); + ActionGroup->insert(new QRadioButton(tr("SMESH_COPY_ELEMENTS"),ActionGroup), COPY_ELEMS_BUTTON); + ActionGroup->insert(new QRadioButton(tr("SMESH_CREATE_MESH" ),ActionGroup), MAKE_MESH_BUTTON); + GroupArgumentsLayout->addMultiCellWidget(ActionGroup, 4, 6, 0, 2); // CheckBox for groups generation MakeGroupsCheck = new QCheckBox(tr("SMESH_MAKE_GROUPS"), GroupArguments); - GroupArgumentsLayout->addMultiCellWidget(MakeGroupsCheck, 5, 5, 0, 2); + GroupArgumentsLayout->addWidget(MakeGroupsCheck, 5, 3); + + // Name of a mesh to create + LineEditNewMesh = new QLineEdit(GroupArguments, "LineEditNewMesh"); + GroupArgumentsLayout->addWidget(LineEditNewMesh, 6, 3); SMESHGUI_RotationDlgLayout->addWidget(GroupArguments, 1, 0); @@ -343,11 +353,13 @@ SMESHGUI_RotationDlg::SMESHGUI_RotationDlg( SMESHGUI* theModule, const char* nam connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), this, SLOT(ClickOnCancel())); connect(LineEditElements, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&))); connect(CheckBoxMesh, SIGNAL(toggled(bool)), SLOT(onSelectMesh(bool))); - connect(CheckBoxCopy, SIGNAL(toggled(bool)), SLOT(onCopyChecked(bool))); + connect(ActionGroup, SIGNAL(clicked(int)), SLOT(onActionClicked(int))); this->show(); /* displays Dialog */ ConstructorsClicked(0); + //SelectionIntoArgument(); + onActionClicked(MOVE_ELEMS_BUTTON); resize(0,0); // ?? } @@ -389,10 +401,11 @@ void SMESHGUI_RotationDlg::Init (bool ResetControls) SpinBox_Angle->SetValue(45); - CheckBoxCopy->setChecked(false); + ((QRadioButton*) ActionGroup->find( MOVE_ELEMS_BUTTON ))->setChecked(TRUE); CheckBoxMesh->setChecked(false); - MakeGroupsCheck->setChecked(false); - MakeGroupsCheck->setEnabled(false); +// MakeGroupsCheck->setChecked(false); +// MakeGroupsCheck->setEnabled(false); +// onSelectMesh(false); } onSelectMesh(CheckBoxMesh->isChecked()); @@ -434,24 +447,37 @@ void SMESHGUI_RotationDlg::ClickOnApply() anAxis.vz = SpinBox_DZ->GetValue(); double anAngle = (SpinBox_Angle->GetValue())*PI/180; - bool toCreateCopy = CheckBoxCopy->isChecked(); - + int actionButton = ActionGroup->id( ActionGroup->selected() ); + bool makeGroups = ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() ); try { SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor(); QApplication::setOverrideCursor(Qt::waitCursor); - if ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() ) - SMESH::ListOfGroups_var groups = - aMeshEditor->RotateMakeGroups(anElementsId.inout(), anAxis, anAngle); - else - aMeshEditor->Rotate(anElementsId.inout(), anAxis, anAngle, toCreateCopy); + switch ( actionButton ) { + case MOVE_ELEMS_BUTTON: + aMeshEditor->Rotate(anElementsId, anAxis, anAngle, false); + break; + case COPY_ELEMS_BUTTON: + if ( makeGroups ) + SMESH::ListOfGroups_var groups = + aMeshEditor->RotateMakeGroups(anElementsId, anAxis, anAngle); + else + aMeshEditor->Rotate(anElementsId, anAxis, anAngle, true); + break; + case MAKE_MESH_BUTTON: + SMESH::SMESH_Mesh_var mesh = + aMeshEditor->RotateMakeMesh(anElementsId, anAxis, anAngle, makeGroups, + LineEditNewMesh->text().latin1()); + } QApplication::restoreOverrideCursor(); } catch (...) { } SMESH::UpdateView(); - if ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() ) + if ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() || + actionButton == MAKE_MESH_BUTTON ) mySMESHGUI->updateObjBrowser(true); // new groups may appear Init(false); + //ConstructorsClicked(GetConstructorId()); SelectionIntoArgument(); } } @@ -604,7 +630,7 @@ void SMESHGUI_RotationDlg::SelectionIntoArgument() MakeGroupsCheck->setChecked(false); MakeGroupsCheck->setEnabled(false); } - else if (CheckBoxCopy->isChecked() ) { + else if ( ActionGroup->id( ActionGroup->selected() ) != MOVE_ELEMS_BUTTON ) { MakeGroupsCheck->setEnabled(true); } if (CheckBoxMesh->isChecked()) { @@ -687,8 +713,10 @@ void SMESHGUI_RotationDlg::SelectionIntoArgument() } myBusy = true; - if (myEditCurrentArgument == (QWidget*)LineEditElements) + if (myEditCurrentArgument == (QWidget*)LineEditElements) { LineEditElements->setText(aString); + setNewMeshName(); + } myBusy = false; // OK @@ -869,17 +897,59 @@ void SMESHGUI_RotationDlg::onVectorChanged() } } + //======================================================================= -//function : onCopyChecked -//purpose : slot called when Copy checkBox is checked +//function : onActionClicked +//purpose : slot called when an action type changed //======================================================================= -void SMESHGUI_RotationDlg::onCopyChecked(bool isOn) +void SMESHGUI_RotationDlg::onActionClicked(int button) { - // enable "MakeGroupsCheck" - if ( !myMesh->_is_nil() && myMesh->NbGroups() == 0) - isOn = false; - MakeGroupsCheck->setEnabled(isOn); + switch ( button ) { + case MOVE_ELEMS_BUTTON: + MakeGroupsCheck->setEnabled(false); + LineEditNewMesh->setEnabled(false); + break; + case COPY_ELEMS_BUTTON: + LineEditNewMesh->setEnabled(false); + MakeGroupsCheck->setText( tr("SMESH_MAKE_GROUPS")); + if ( myMesh->_is_nil() || myMesh->NbGroups() > 0) + MakeGroupsCheck->setEnabled(true); + else + MakeGroupsCheck->setEnabled(false); + break; + case MAKE_MESH_BUTTON: + LineEditNewMesh->setEnabled(true); + MakeGroupsCheck->setText( tr("SMESH_COPY_GROUPS")); + if ( myMesh->_is_nil() || myMesh->NbGroups() > 0) + MakeGroupsCheck->setEnabled(true); + else + MakeGroupsCheck->setEnabled(false); + break; + } + setNewMeshName(); +} + +//======================================================================= +//function : setNewMeshName +//purpose : update contents of LineEditNewMesh +//======================================================================= + +void SMESHGUI_RotationDlg::setNewMeshName() +{ + LineEditNewMesh->setText(""); + if ( LineEditNewMesh->isEnabled() && !myMesh->_is_nil() ) { + QString name; + if ( CheckBoxMesh->isChecked() ) { + name = LineEditElements->text(); + } + else { + _PTR(SObject) meshSO = SMESH::FindSObject( myMesh ); + name = meshSO->GetName(); + } + if ( !name.isEmpty() ) + LineEditNewMesh->setText( SMESH::UniqueMeshName( name.latin1(), "rotated")); + } } //================================================================================= diff --git a/src/SMESHGUI/SMESHGUI_RotationDlg.h b/src/SMESHGUI/SMESHGUI_RotationDlg.h index ceebea7cf..066bf35d4 100644 --- a/src/SMESHGUI/SMESHGUI_RotationDlg.h +++ b/src/SMESHGUI/SMESHGUI_RotationDlg.h @@ -79,6 +79,7 @@ private: void hideEvent (QHideEvent*); /* ESC key */ void keyPressEvent(QKeyEvent*); bool IsAxisOk(); + void setNewMeshName(); SMESHGUI* mySMESHGUI; /* Current SMESHGUI object */ LightApp_SelectionMgr* mySelectionMgr; /* User shape selection */ @@ -126,8 +127,10 @@ private: QLabel* TextLabelAngle; SMESHGUI_SpinBox* SpinBox_Angle; - QCheckBox* CheckBoxCopy; + //QCheckBox* CheckBoxCopy; + QButtonGroup* ActionGroup; QCheckBox* MakeGroupsCheck; + QLineEdit* LineEditNewMesh; QString myHelpFileName; @@ -145,7 +148,7 @@ private slots: void onTextChange (const QString&); void onSelectMesh (bool toSelectMesh); void onVectorChanged(); - void onCopyChecked(bool isOn); + void onActionClicked(int button); protected: QGridLayout* SMESHGUI_RotationDlgLayout; diff --git a/src/SMESHGUI/SMESHGUI_SymmetryDlg.cxx b/src/SMESHGUI/SMESHGUI_SymmetryDlg.cxx index 9ee18b075..1b373a16a 100644 --- a/src/SMESHGUI/SMESHGUI_SymmetryDlg.cxx +++ b/src/SMESHGUI/SMESHGUI_SymmetryDlg.cxx @@ -52,6 +52,7 @@ #include "SVTK_Selector.h" #include "SVTK_Selection.h" #include "SALOME_ListIO.hxx" +#include "SALOMEDSClient_SObject.hxx" #include "utilities.h" @@ -78,10 +79,13 @@ using namespace std; +enum { MOVE_ELEMS_BUTTON = 0, COPY_ELEMS_BUTTON, MAKE_MESH_BUTTON }; //!< action type + //================================================================================= // class : SMESHGUI_SymmetryDlg() // purpose : //================================================================================= + SMESHGUI_SymmetryDlg::SMESHGUI_SymmetryDlg( SMESHGUI* theModule, const char* name, bool modal, WFlags fl) : QDialog( SMESH::GetDesktop( theModule ), name, modal, WStyle_Customize | WStyle_NormalBorder | @@ -182,8 +186,9 @@ SMESHGUI_SymmetryDlg::SMESHGUI_SymmetryDlg( SMESHGUI* theModule, const char* nam // Controls for elements selection TextLabelElements = new QLabel(GroupArguments, "TextLabelElements"); TextLabelElements->setText(tr("SMESH_ID_ELEMENTS" )); - TextLabelElements->setFixedWidth(74); + //TextLabelElements->setFixedWidth(74); GroupArgumentsLayout->addWidget(TextLabelElements, 0, 0); + //GroupArgumentsLayout->addMultiCellWidget(TextLabelElements, 0, 0, 0, 1); SelectElementsButton = new QPushButton(GroupArguments, "SelectElementsButton"); SelectElementsButton->setText(tr("" )); @@ -191,14 +196,15 @@ SMESHGUI_SymmetryDlg::SMESHGUI_SymmetryDlg( SMESHGUI* theModule, const char* nam SelectElementsButton->setToggleButton(FALSE); GroupArgumentsLayout->addWidget(SelectElementsButton, 0, 1); - LineEditElements = new QLineEdit(GroupArguments, "LineEditElements"); + LineEditElements = new QLineEdit(GroupArguments, "LineEditElements"); LineEditElements->setValidator(new SMESHGUI_IdValidator(this, "validator")); - GroupArgumentsLayout->addWidget(LineEditElements, 0, 2); + //GroupArgumentsLayout->addWidget(LineEditElements, 0, 3); + GroupArgumentsLayout->addMultiCellWidget(LineEditElements, 0, 0, 2, 4); // Control for the whole mesh selection CheckBoxMesh = new QCheckBox(GroupArguments, "CheckBoxMesh"); CheckBoxMesh->setText(tr("SMESH_SELECT_WHOLE_MESH" )); - GroupArgumentsLayout->addMultiCellWidget(CheckBoxMesh, 1, 1, 0, 2); + GroupArgumentsLayout->addMultiCellWidget(CheckBoxMesh, 1, 1, 0, 4); // Controls for mirror selection GroupMirror = new QGroupBox(GroupArguments, "GroupMirror"); @@ -251,6 +257,7 @@ SMESHGUI_SymmetryDlg::SMESHGUI_SymmetryDlg( SMESHGUI* theModule, const char* nam TextLabelDX = new QLabel(GroupMirror, "TextLabelDX"); TextLabelDX->setText(tr("SMESH_DX")); + TextLabelDX->setAlignment( Qt::AlignRight | Qt::AlignVCenter | Qt::ExpandTabs ); GroupMirrorLayout->addWidget(TextLabelDX, 1, 2); SpinBox_DX = new SMESHGUI_SpinBox(GroupMirror, "SpinBox_DX"); @@ -258,6 +265,7 @@ SMESHGUI_SymmetryDlg::SMESHGUI_SymmetryDlg( SMESHGUI* theModule, const char* nam TextLabelDY = new QLabel(GroupMirror, "TextLabelDY"); TextLabelDY->setText(tr("SMESH_DY")); + TextLabelDY->setAlignment( Qt::AlignRight | Qt::AlignVCenter | Qt::ExpandTabs ); GroupMirrorLayout->addWidget(TextLabelDY, 1, 4); SpinBox_DY = new SMESHGUI_SpinBox(GroupMirror, "SpinBox_DY"); @@ -265,22 +273,30 @@ SMESHGUI_SymmetryDlg::SMESHGUI_SymmetryDlg( SMESHGUI* theModule, const char* nam TextLabelDZ = new QLabel(GroupMirror, "TextLabelDZ"); TextLabelDZ->setText(tr("SMESH_DZ")); + TextLabelDZ->setAlignment( Qt::AlignRight | Qt::AlignVCenter | Qt::ExpandTabs ); GroupMirrorLayout->addWidget(TextLabelDZ, 1, 6); SpinBox_DZ = new SMESHGUI_SpinBox(GroupMirror, "SpinBox_DZ"); GroupMirrorLayout->addWidget(SpinBox_DZ, 1, 7); - GroupArgumentsLayout->addMultiCellWidget(GroupMirror, 2, 2, 0, 2); + GroupArgumentsLayout->addMultiCellWidget(GroupMirror, 2, 2, 0, 4); - // Controls for "Create a copy" option - CheckBoxCopy = new QCheckBox(GroupArguments, "CheckBoxCopy"); - CheckBoxCopy->setText(tr("SMESH_CREATE_COPY")); - GroupArgumentsLayout->addMultiCellWidget(CheckBoxCopy, 3, 3, 0, 2); + // switch of action type + ActionGroup = new QButtonGroup(1, Qt::Horizontal, GroupArguments, "ActionGroup"); + ActionGroup->setExclusive(true); + ActionGroup->insert(new QRadioButton(tr("SMESH_MOVE_ELEMENTS"),ActionGroup), MOVE_ELEMS_BUTTON); + ActionGroup->insert(new QRadioButton(tr("SMESH_COPY_ELEMENTS"),ActionGroup), COPY_ELEMS_BUTTON); + ActionGroup->insert(new QRadioButton(tr("SMESH_CREATE_MESH" ),ActionGroup), MAKE_MESH_BUTTON); + GroupArgumentsLayout->addMultiCellWidget(ActionGroup, 3, 5, 0, 3); // CheckBox for groups generation MakeGroupsCheck = new QCheckBox(tr("SMESH_MAKE_GROUPS"), GroupArguments); MakeGroupsCheck->setChecked(false); - GroupArgumentsLayout->addMultiCellWidget(MakeGroupsCheck, 4, 4, 0, 2); + GroupArgumentsLayout->addWidget(MakeGroupsCheck, 4, 4); + + // Name of a mesh to create + LineEditNewMesh = new QLineEdit(GroupArguments, "LineEditNewMesh"); + GroupArgumentsLayout->addWidget(LineEditNewMesh, 5, 4); SMESHGUI_SymmetryDlgLayout->addWidget(GroupArguments, 1, 0); @@ -335,12 +351,13 @@ SMESHGUI_SymmetryDlg::SMESHGUI_SymmetryDlg( SMESHGUI* theModule, const char* nam connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel())); connect(LineEditElements, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&))); connect(CheckBoxMesh, SIGNAL(toggled(bool)), SLOT(onSelectMesh(bool))); - connect(CheckBoxCopy, SIGNAL(toggled(bool)), SLOT(onCopyChecked(bool))); + connect(ActionGroup, SIGNAL(clicked(int)), SLOT(onActionClicked(int))); this->show(); /* displays Dialog */ ConstructorsClicked(0); SelectionIntoArgument(); + onActionClicked(MOVE_ELEMS_BUTTON); resize(0,0); // ?? } @@ -380,10 +397,10 @@ void SMESHGUI_SymmetryDlg::Init (bool ResetControls) SpinBox_DY->SetValue(0.0); SpinBox_DZ->SetValue(0.0); - CheckBoxCopy->setChecked(false); + ((QRadioButton*) ActionGroup->find( MOVE_ELEMS_BUTTON ))->setChecked(TRUE); CheckBoxMesh->setChecked(false); - MakeGroupsCheck->setChecked(false); - MakeGroupsCheck->setEnabled(false); +// MakeGroupsCheck->setChecked(false); +// MakeGroupsCheck->setEnabled(false); onSelectMesh(false); } } @@ -485,7 +502,6 @@ void SMESHGUI_SymmetryDlg::ClickOnApply() aMirror.vz = SpinBox_DZ->GetValue(); } - bool toCreateCopy = CheckBoxCopy->isChecked(); SMESH::SMESH_MeshEditor::MirrorType aMirrorType; @@ -496,20 +512,35 @@ void SMESHGUI_SymmetryDlg::ClickOnApply() if (GetConstructorId() == 2) aMirrorType = SMESH::SMESH_MeshEditor::PLANE; + int actionButton = ActionGroup->id( ActionGroup->selected() ); + bool makeGroups = ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() ); + try { SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor(); QApplication::setOverrideCursor(Qt::waitCursor); - if ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() ) - SMESH::ListOfGroups_var groups = - aMeshEditor->MirrorMakeGroups(anElementsId, aMirror, aMirrorType); - else - aMeshEditor->Mirror(anElementsId, aMirror, aMirrorType, toCreateCopy); + switch ( actionButton ) { + case MOVE_ELEMS_BUTTON: + aMeshEditor->Mirror(anElementsId, aMirror, aMirrorType, false ); + break; + case COPY_ELEMS_BUTTON: + if ( makeGroups ) + SMESH::ListOfGroups_var groups = + aMeshEditor->MirrorMakeGroups(anElementsId, aMirror, aMirrorType); + else + aMeshEditor->Mirror(anElementsId, aMirror, aMirrorType, true); + break; + case MAKE_MESH_BUTTON: + SMESH::SMESH_Mesh_var mesh = + aMeshEditor->MirrorMakeMesh(anElementsId, aMirror, aMirrorType, makeGroups, + LineEditNewMesh->text().latin1()); + } QApplication::restoreOverrideCursor(); } catch (...) { } SMESH::UpdateView(); - if ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() ) + if ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() || + actionButton == MAKE_MESH_BUTTON ) mySMESHGUI->updateObjBrowser(true); // new groups may appear Init(false); ConstructorsClicked(GetConstructorId()); @@ -666,7 +697,7 @@ void SMESHGUI_SymmetryDlg::SelectionIntoArgument() MakeGroupsCheck->setChecked(false); MakeGroupsCheck->setEnabled(false); } - else if (CheckBoxCopy->isChecked() ) { + else if ( ActionGroup->id( ActionGroup->selected() ) != MOVE_ELEMS_BUTTON ) { MakeGroupsCheck->setEnabled(true); } if (CheckBoxMesh->isChecked()) { @@ -749,8 +780,10 @@ void SMESHGUI_SymmetryDlg::SelectionIntoArgument() } myBusy = true; - if (myEditCurrentArgument == (QWidget*)LineEditElements) + if (myEditCurrentArgument == (QWidget*)LineEditElements) { LineEditElements->setText(aString); + setNewMeshName(); + } myBusy = false; // OK @@ -943,16 +976,57 @@ void SMESHGUI_SymmetryDlg::onVectorChanged() } //======================================================================= -//function : onCopyChecked -//purpose : slot called when Copy checkBox is checked +//function : onActionClicked +//purpose : slot called when an action type changed //======================================================================= -void SMESHGUI_SymmetryDlg::onCopyChecked(bool isOn) +void SMESHGUI_SymmetryDlg::onActionClicked(int button) { - // enable "MakeGroupsCheck" - if ( !myMesh->_is_nil() && myMesh->NbGroups() == 0) - isOn = false; - MakeGroupsCheck->setEnabled(isOn); + switch ( button ) { + case MOVE_ELEMS_BUTTON: + MakeGroupsCheck->setEnabled(false); + LineEditNewMesh->setEnabled(false); + break; + case COPY_ELEMS_BUTTON: + LineEditNewMesh->setEnabled(false); + MakeGroupsCheck->setText( tr("SMESH_MAKE_GROUPS")); + if ( myMesh->_is_nil() || myMesh->NbGroups() > 0) + MakeGroupsCheck->setEnabled(true); + else + MakeGroupsCheck->setEnabled(false); + break; + case MAKE_MESH_BUTTON: + LineEditNewMesh->setEnabled(true); + MakeGroupsCheck->setText( tr("SMESH_COPY_GROUPS")); + if ( myMesh->_is_nil() || myMesh->NbGroups() > 0) + MakeGroupsCheck->setEnabled(true); + else + MakeGroupsCheck->setEnabled(false); + break; + } + setNewMeshName(); +} + +//======================================================================= +//function : setNewMeshName +//purpose : update contents of LineEditNewMesh +//======================================================================= + +void SMESHGUI_SymmetryDlg::setNewMeshName() +{ + LineEditNewMesh->setText(""); + if ( LineEditNewMesh->isEnabled() && !myMesh->_is_nil() ) { + QString name; + if ( CheckBoxMesh->isChecked() ) { + name = LineEditElements->text(); + } + else { + _PTR(SObject) meshSO = SMESH::FindSObject( myMesh ); + name = meshSO->GetName(); + } + if ( !name.isEmpty() ) + LineEditNewMesh->setText( SMESH::UniqueMeshName( name.latin1(), "mirrored")); + } } //================================================================================= diff --git a/src/SMESHGUI/SMESHGUI_SymmetryDlg.h b/src/SMESHGUI/SMESHGUI_SymmetryDlg.h index c09a35a02..ef0b78f05 100644 --- a/src/SMESHGUI/SMESHGUI_SymmetryDlg.h +++ b/src/SMESHGUI/SMESHGUI_SymmetryDlg.h @@ -79,6 +79,7 @@ private: void keyPressEvent(QKeyEvent*); int GetConstructorId(); bool IsMirrorOk(); + void setNewMeshName(); SMESHGUI* mySMESHGUI; /* Current SMESHGUI object */ LightApp_SelectionMgr* mySelectionMgr; /* User shape selection */ @@ -126,8 +127,10 @@ private: QLabel* TextLabelDZ; SMESHGUI_SpinBox* SpinBox_DZ; - QCheckBox* CheckBoxCopy; + //QCheckBox* CheckBoxCopy; + QButtonGroup* ActionGroup; QCheckBox* MakeGroupsCheck; + QLineEdit* LineEditNewMesh; QString myHelpFileName; @@ -145,7 +148,7 @@ private: void onTextChange(const QString&); void onSelectMesh(bool toSelectMesh); void onVectorChanged(); - void onCopyChecked(bool isOn); + void onActionClicked(int button); protected: QGridLayout* SMESHGUI_SymmetryDlgLayout; diff --git a/src/SMESHGUI/SMESHGUI_TranslationDlg.cxx b/src/SMESHGUI/SMESHGUI_TranslationDlg.cxx index 2a73f6a9b..0481378ee 100644 --- a/src/SMESHGUI/SMESHGUI_TranslationDlg.cxx +++ b/src/SMESHGUI/SMESHGUI_TranslationDlg.cxx @@ -52,6 +52,7 @@ #include "SVTK_ViewWindow.h" #include "SVTK_Selector.h" #include "SALOME_ListIO.hxx" +#include "SALOMEDSClient_SObject.hxx" #include "utilities.h" @@ -79,6 +80,8 @@ using namespace std; +enum { MOVE_ELEMS_BUTTON = 0, COPY_ELEMS_BUTTON, MAKE_MESH_BUTTON }; //!< action type + //================================================================================= // class : SMESHGUI_TranslationDlg() // purpose : @@ -181,7 +184,7 @@ SMESHGUI_TranslationDlg::SMESHGUI_TranslationDlg( SMESHGUI* theModule, const cha SelectElementsButton->setToggleButton(FALSE); GroupArgumentsLayout->addWidget(SelectElementsButton, 0, 1); - LineEditElements = new QLineEdit(GroupArguments, "LineEditElements"); + LineEditElements = new QLineEdit(GroupArguments, "LineEditElements"); LineEditElements->setValidator(new SMESHGUI_IdValidator(this, "validator")); GroupArgumentsLayout->addMultiCellWidget(LineEditElements, 0, 0, 2, 7); @@ -256,14 +259,26 @@ SMESHGUI_TranslationDlg::SMESHGUI_TranslationDlg( SMESHGUI* theModule, const cha GroupArgumentsLayout->addWidget(SpinBox2_3, 3, 7); // Controls for "Create a copy" option - CheckBoxCopy = new QCheckBox(GroupArguments, "CheckBoxCopy"); - CheckBoxCopy->setText(tr("SMESH_CREATE_COPY")); - GroupArgumentsLayout->addMultiCellWidget(CheckBoxCopy, 4, 4, 0, 2); +// CheckBoxCopy = new QCheckBox(GroupArguments, "CheckBoxCopy"); +// CheckBoxCopy->setText(tr("SMESH_CREATE_COPY")); +// GroupArgumentsLayout->addMultiCellWidget(CheckBoxCopy, 4, 4, 0, 2); + + // switch of action type + ActionGroup = new QButtonGroup(1, Qt::Horizontal, GroupArguments, "ActionGroup"); + ActionGroup->setExclusive(true); + ActionGroup->insert(new QRadioButton(tr("SMESH_MOVE_ELEMENTS"),ActionGroup), MOVE_ELEMS_BUTTON); + ActionGroup->insert(new QRadioButton(tr("SMESH_COPY_ELEMENTS"),ActionGroup), COPY_ELEMS_BUTTON); + ActionGroup->insert(new QRadioButton(tr("SMESH_CREATE_MESH" ),ActionGroup), MAKE_MESH_BUTTON); + GroupArgumentsLayout->addMultiCellWidget(ActionGroup, 4, 6, 0, 3); // CheckBox for groups generation MakeGroupsCheck = new QCheckBox(tr("SMESH_MAKE_GROUPS"), GroupArguments); MakeGroupsCheck->setChecked(false); - GroupArgumentsLayout->addMultiCellWidget(MakeGroupsCheck, 5, 5, 0, 2); + GroupArgumentsLayout->addMultiCellWidget(MakeGroupsCheck, 5, 5, 4, 7); + + // Name of a mesh to create + LineEditNewMesh = new QLineEdit(GroupArguments, "LineEditNewMesh"); + GroupArgumentsLayout->addMultiCellWidget(LineEditNewMesh, 6, 6, 4, 7); SMESHGUI_TranslationDlgLayout->addWidget(GroupArguments, 1, 0); @@ -314,12 +329,13 @@ SMESHGUI_TranslationDlg::SMESHGUI_TranslationDlg( SMESHGUI* theModule, const cha connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), this, SLOT(ClickOnCancel())); connect(LineEditElements, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&))); connect(CheckBoxMesh, SIGNAL(toggled(bool)), SLOT(onSelectMesh(bool))); - connect(CheckBoxCopy, SIGNAL(toggled(bool)), SLOT(onCopyChecked(bool))); + connect(ActionGroup, SIGNAL(clicked(int)), SLOT(onActionClicked(int))); this->show(); /* displays Dialog */ ConstructorsClicked(0); SelectionIntoArgument(); + onActionClicked(MOVE_ELEMS_BUTTON); resize(0,0); // ?? } @@ -359,10 +375,10 @@ void SMESHGUI_TranslationDlg::Init (bool ResetControls) SpinBox2_2->SetValue(0.0); SpinBox2_3->SetValue(0.0); - CheckBoxCopy->setChecked(false); + ((QRadioButton*) ActionGroup->find( MOVE_ELEMS_BUTTON ))->setChecked(TRUE); CheckBoxMesh->setChecked(false); - MakeGroupsCheck->setChecked(false); - MakeGroupsCheck->setEnabled(false); +// MakeGroupsCheck->setChecked(false); +// MakeGroupsCheck->setEnabled(false); onSelectMesh(false); } } @@ -459,22 +475,34 @@ void SMESHGUI_TranslationDlg::ClickOnApply() aVector.PS.z = SpinBox1_3->GetValue(); } - bool toCreateCopy = CheckBoxCopy->isChecked(); - + int actionButton = ActionGroup->id( ActionGroup->selected() ); + bool makeGroups = ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() ); try { SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor(); QApplication::setOverrideCursor(Qt::waitCursor); - if ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() ) - SMESH::ListOfGroups_var groups = - aMeshEditor->TranslateMakeGroups(anElementsId.inout(), aVector); - else - aMeshEditor->Translate(anElementsId.inout(), aVector, toCreateCopy); + switch ( actionButton ) { + case MOVE_ELEMS_BUTTON: + aMeshEditor->Translate(anElementsId, aVector, false); + break; + case COPY_ELEMS_BUTTON: + if ( makeGroups ) + SMESH::ListOfGroups_var groups = + aMeshEditor->TranslateMakeGroups(anElementsId, aVector); + else + aMeshEditor->Translate(anElementsId, aVector, true); + break; + case MAKE_MESH_BUTTON: + SMESH::SMESH_Mesh_var mesh = + aMeshEditor->TranslateMakeMesh(anElementsId, aVector, makeGroups, + LineEditNewMesh->text().latin1()); + } QApplication::restoreOverrideCursor(); } catch (...) { } SMESH::UpdateView(); - if ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() ) + if ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() || + actionButton == MAKE_MESH_BUTTON ) mySMESHGUI->updateObjBrowser(true); // new groups may appear Init(false); ConstructorsClicked(GetConstructorId()); @@ -631,7 +659,7 @@ void SMESHGUI_TranslationDlg::SelectionIntoArgument() MakeGroupsCheck->setChecked(false); MakeGroupsCheck->setEnabled(false); } - else if (CheckBoxCopy->isChecked() ) { + else if ( ActionGroup->id( ActionGroup->selected() ) != MOVE_ELEMS_BUTTON ) { MakeGroupsCheck->setEnabled(true); } @@ -715,8 +743,10 @@ void SMESHGUI_TranslationDlg::SelectionIntoArgument() } myBusy = true; - if (myEditCurrentArgument == (QWidget*)LineEditElements) + if (myEditCurrentArgument == (QWidget*)LineEditElements) { LineEditElements->setText(aString); + setNewMeshName(); + } myBusy = false; // OK @@ -869,16 +899,57 @@ void SMESHGUI_TranslationDlg::onSelectMesh (bool toSelectMesh) } //======================================================================= -//function : onCopyChecked -//purpose : slot called when Copy checkBox is checked +//function : onActionClicked +//purpose : slot called when an action type changed +//======================================================================= + +void SMESHGUI_TranslationDlg::onActionClicked(int button) +{ + switch ( button ) { + case MOVE_ELEMS_BUTTON: + MakeGroupsCheck->setEnabled(false); + LineEditNewMesh->setEnabled(false); + break; + case COPY_ELEMS_BUTTON: + LineEditNewMesh->setEnabled(false); + MakeGroupsCheck->setText( tr("SMESH_MAKE_GROUPS")); + if ( myMesh->_is_nil() || myMesh->NbGroups() > 0) + MakeGroupsCheck->setEnabled(true); + else + MakeGroupsCheck->setEnabled(false); + break; + case MAKE_MESH_BUTTON: + LineEditNewMesh->setEnabled(true); + MakeGroupsCheck->setText( tr("SMESH_COPY_GROUPS")); + if ( myMesh->_is_nil() || myMesh->NbGroups() > 0) + MakeGroupsCheck->setEnabled(true); + else + MakeGroupsCheck->setEnabled(false); + break; + } + setNewMeshName(); +} + +//======================================================================= +//function : setNewMeshName +//purpose : update contents of LineEditNewMesh //======================================================================= -void SMESHGUI_TranslationDlg::onCopyChecked(bool isOn) +void SMESHGUI_TranslationDlg::setNewMeshName() { - // enable "MakeGroupsCheck" - if ( !myMesh->_is_nil() && myMesh->NbGroups() == 0) - isOn = false; - MakeGroupsCheck->setEnabled(isOn); + LineEditNewMesh->setText(""); + if ( LineEditNewMesh->isEnabled() && !myMesh->_is_nil() ) { + QString name; + if ( CheckBoxMesh->isChecked() ) { + name = LineEditElements->text(); + } + else { + _PTR(SObject) meshSO = SMESH::FindSObject( myMesh ); + name = meshSO->GetName(); + } + if ( !name.isEmpty() ) + LineEditNewMesh->setText( SMESH::UniqueMeshName( name.latin1(), "translated")); + } } //================================================================================= diff --git a/src/SMESHGUI/SMESHGUI_TranslationDlg.h b/src/SMESHGUI/SMESHGUI_TranslationDlg.h index 2188bc54d..e3953d0f8 100644 --- a/src/SMESHGUI/SMESHGUI_TranslationDlg.h +++ b/src/SMESHGUI/SMESHGUI_TranslationDlg.h @@ -77,6 +77,7 @@ private: void hideEvent (QHideEvent*); /* ESC key */ void keyPressEvent(QKeyEvent*); int GetConstructorId(); + void setNewMeshName(); SMESHGUI* mySMESHGUI; /* Current SMESHGUI object */ LightApp_SelectionMgr* mySelectionMgr; /* User shape selection */ @@ -121,8 +122,10 @@ private: SMESHGUI_SpinBox* SpinBox2_2; QLabel* TextLabel2_3; SMESHGUI_SpinBox* SpinBox2_3; - QCheckBox* CheckBoxCopy; + //QCheckBox* CheckBoxCopy; + QButtonGroup* ActionGroup; QCheckBox* MakeGroupsCheck; + QLineEdit* LineEditNewMesh; QString myHelpFileName; @@ -139,7 +142,7 @@ private: void ActivateThisDialog() ; void onTextChange(const QString&); void onSelectMesh(bool toSelectMesh); - void onCopyChecked(bool isOn); + void onActionClicked(int button); protected: QGridLayout* SMESHGUI_TranslationDlgLayout; diff --git a/src/SMESH_I/SMESH_MeshEditor_i.cxx b/src/SMESH_I/SMESH_MeshEditor_i.cxx index 77914d16e..3dc98cae9 100644 --- a/src/SMESH_I/SMESH_MeshEditor_i.cxx +++ b/src/SMESH_I/SMESH_MeshEditor_i.cxx @@ -2112,7 +2112,8 @@ SMESH_MeshEditor_i::mirror(const SMESH::long_array & theIDsOfElements, const SMESH::AxisStruct & theAxis, SMESH::SMESH_MeshEditor::MirrorType theMirrorType, CORBA::Boolean theCopy, - const bool theMakeGroups) + const bool theMakeGroups, + ::SMESH_Mesh* theTargetMesh) { initData(); @@ -2136,7 +2137,7 @@ SMESH_MeshEditor_i::mirror(const SMESH::long_array & theIDsOfElements, ::SMESH_MeshEditor anEditor( myMesh ); ::SMESH_MeshEditor::PGroupIDs groupIds = - anEditor.Transform (elements, aTrsf, theCopy, theMakeGroups); + anEditor.Transform (elements, aTrsf, theCopy, theMakeGroups, theTargetMesh); if(theCopy) { storeResult(anEditor); @@ -2225,6 +2226,71 @@ SMESH_MeshEditor_i::MirrorObjectMakeGroups(SMESH::SMESH_IDSource_ptr t return mirror(anElementsId, theMirror, theMirrorType, true, true); } +//======================================================================= +//function : MirrorMakeMesh +//purpose : +//======================================================================= + +SMESH::SMESH_Mesh_ptr +SMESH_MeshEditor_i::MirrorMakeMesh(const SMESH::long_array& theIDsOfElements, + const SMESH::AxisStruct& theMirror, + SMESH::SMESH_MeshEditor::MirrorType theMirrorType, + CORBA::Boolean theCopyGroups, + const char* theMeshName) +{ + TPythonDump pydump; // to prevent dump at mesh creation + + SMESH::SMESH_Mesh_var mesh = makeMesh( theMeshName ); + if ( SMESH_Mesh_i* mesh_i = SMESH::DownCast( mesh )) + { + mirror(theIDsOfElements, theMirror, theMirrorType, + false, theCopyGroups, & mesh_i->GetImpl()); + mesh_i->CreateGroupServants(); + } + + if ( !myPreviewMode ) { + pydump << mesh << " = " << this << ".MirrorMakeMesh( " + << theIDsOfElements << ", " + << theMirror << ", " + << mirrorTypeName(theMirrorType) << ", " + << theCopyGroups << ", '" + << theMeshName << "' )"; + } + return mesh._retn(); +} + +//======================================================================= +//function : MirrorObjectMakeMesh +//purpose : +//======================================================================= + +SMESH::SMESH_Mesh_ptr +SMESH_MeshEditor_i::MirrorObjectMakeMesh(SMESH::SMESH_IDSource_ptr theObject, + const SMESH::AxisStruct& theMirror, + SMESH::SMESH_MeshEditor::MirrorType theMirrorType, + CORBA::Boolean theCopyGroups, + const char* theMeshName) +{ + TPythonDump pydump; // to prevent dump at mesh creation + + SMESH::SMESH_Mesh_var mesh = makeMesh( theMeshName ); + if ( SMESH_Mesh_i* mesh_i = SMESH::DownCast( mesh )) + { + SMESH::long_array_var anElementsId = theObject->GetIDs(); + mirror(anElementsId, theMirror, theMirrorType, + false, theCopyGroups, & mesh_i->GetImpl()); + mesh_i->CreateGroupServants(); + } + if ( !myPreviewMode ) { + pydump << mesh << " = " << this << ".MirrorObjectMakeMesh( " + << theObject << ", " + << theMirror << ", " + << mirrorTypeName(theMirrorType) << ", " + << theCopyGroups << ", '" + << theMeshName << "' )"; + } + return mesh._retn(); +} //======================================================================= //function : translate @@ -2235,7 +2301,8 @@ SMESH::ListOfGroups* SMESH_MeshEditor_i::translate(const SMESH::long_array & theIDsOfElements, const SMESH::DirStruct & theVector, CORBA::Boolean theCopy, - const bool theMakeGroups) + const bool theMakeGroups, + ::SMESH_Mesh* theTargetMesh) { initData(); @@ -2248,7 +2315,7 @@ SMESH_MeshEditor_i::translate(const SMESH::long_array & theIDsOfElements, ::SMESH_MeshEditor anEditor( myMesh ); ::SMESH_MeshEditor::PGroupIDs groupIds = - anEditor.Transform (elements, aTrsf, theCopy, theMakeGroups); + anEditor.Transform (elements, aTrsf, theCopy, theMakeGroups, theTargetMesh); if(theCopy) storeResult(anEditor); @@ -2328,6 +2395,7 @@ SMESH_MeshEditor_i::TranslateObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObjec const SMESH::DirStruct& theVector) { if ( !myPreviewMode ) { + TPythonDump() << "vector = " << theVector; TPythonDump() << this << ".TranslateObjectMakeGroups( " << theObject << ", vector )"; @@ -2336,6 +2404,65 @@ SMESH_MeshEditor_i::TranslateObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObjec return translate(anElementsId, theVector, true, true); } +//======================================================================= +//function : TranslateMakeMesh +//purpose : +//======================================================================= + +SMESH::SMESH_Mesh_ptr +SMESH_MeshEditor_i::TranslateMakeMesh(const SMESH::long_array& theIDsOfElements, + const SMESH::DirStruct& theVector, + CORBA::Boolean theCopyGroups, + const char* theMeshName) +{ + TPythonDump pydump; // to prevent dump at mesh creation + SMESH::SMESH_Mesh_var mesh = makeMesh( theMeshName ); + + if ( SMESH_Mesh_i* mesh_i = SMESH::DownCast( mesh )) { + translate(theIDsOfElements, theVector, + false, theCopyGroups, & mesh_i->GetImpl()); + mesh_i->CreateGroupServants(); + } + if ( !myPreviewMode ) { + pydump << mesh << " = " << this << ".TranslateMakeMesh( " + << theIDsOfElements << ", " + << theVector << ", " + << theCopyGroups << ", '" + << theMeshName << "' )"; + } + return mesh._retn(); +} + +//======================================================================= +//function : TranslateObjectMakeMesh +//purpose : +//======================================================================= + +SMESH::SMESH_Mesh_ptr +SMESH_MeshEditor_i::TranslateObjectMakeMesh(SMESH::SMESH_IDSource_ptr theObject, + const SMESH::DirStruct& theVector, + CORBA::Boolean theCopyGroups, + const char* theMeshName) +{ + TPythonDump pydump; // to prevent dump at mesh creation + SMESH::SMESH_Mesh_var mesh = makeMesh( theMeshName ); + + if ( SMESH_Mesh_i* mesh_i = SMESH::DownCast( mesh )) { + SMESH::long_array_var anElementsId = theObject->GetIDs(); + translate(anElementsId, theVector, + false, theCopyGroups, & mesh_i->GetImpl()); + mesh_i->CreateGroupServants(); + } + if ( !myPreviewMode ) { + pydump << mesh << " = " << this << ".TranslateObjectMakeMesh( " + << theObject << ", " + << theVector << ", " + << theCopyGroups << ", '" + << theMeshName << "' )"; + } + return mesh._retn(); +} + //======================================================================= //function : rotate //purpose : @@ -2346,7 +2473,8 @@ SMESH_MeshEditor_i::rotate(const SMESH::long_array & theIDsOfElements, const SMESH::AxisStruct & theAxis, CORBA::Double theAngle, CORBA::Boolean theCopy, - const bool theMakeGroups) + const bool theMakeGroups, + ::SMESH_Mesh* theTargetMesh) { initData(); @@ -2361,7 +2489,7 @@ SMESH_MeshEditor_i::rotate(const SMESH::long_array & theIDsOfElements, ::SMESH_MeshEditor anEditor( myMesh ); ::SMESH_MeshEditor::PGroupIDs groupIds = - anEditor.Transform (elements, aTrsf, theCopy, theMakeGroups); + anEditor.Transform (elements, aTrsf, theCopy, theMakeGroups, theTargetMesh); if(theCopy) { storeResult(anEditor); @@ -2461,6 +2589,69 @@ SMESH_MeshEditor_i::RotateObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject, return rotate(anElementsId,theAxis,theAngle,true,true); } +//======================================================================= +//function : RotateMakeMesh +//purpose : +//======================================================================= + +SMESH::SMESH_Mesh_ptr +SMESH_MeshEditor_i::RotateMakeMesh(const SMESH::long_array& theIDsOfElements, + const SMESH::AxisStruct& theAxis, + CORBA::Double theAngleInRadians, + CORBA::Boolean theCopyGroups, + const char* theMeshName) +{ + TPythonDump pydump; // to prevent dump at mesh creation + SMESH::SMESH_Mesh_var mesh = makeMesh( theMeshName ); + + if ( SMESH_Mesh_i* mesh_i = SMESH::DownCast( mesh )) { + rotate(theIDsOfElements, theAxis, theAngleInRadians, + false, theCopyGroups, & mesh_i->GetImpl()); + mesh_i->CreateGroupServants(); + } + if ( !myPreviewMode ) { + pydump << mesh << " = " << this << ".RotateMakeMesh( " + << theIDsOfElements << ", " + << theAxis << ", " + << theAngleInRadians << ", " + << theCopyGroups << ", '" + << theMeshName << "' )"; + } + return mesh._retn(); +} + +//======================================================================= +//function : RotateObjectMakeMesh +//purpose : +//======================================================================= + +SMESH::SMESH_Mesh_ptr +SMESH_MeshEditor_i::RotateObjectMakeMesh(SMESH::SMESH_IDSource_ptr theObject, + const SMESH::AxisStruct& theAxis, + CORBA::Double theAngleInRadians, + CORBA::Boolean theCopyGroups, + const char* theMeshName) +{ + TPythonDump pydump; // to prevent dump at mesh creation + SMESH::SMESH_Mesh_var mesh = makeMesh( theMeshName ); + + if ( SMESH_Mesh_i* mesh_i = SMESH::DownCast( mesh )) { + SMESH::long_array_var anElementsId = theObject->GetIDs(); + rotate(anElementsId, theAxis, theAngleInRadians, + false, theCopyGroups, & mesh_i->GetImpl()); + mesh_i->CreateGroupServants(); + } + if ( !myPreviewMode ) { + pydump << mesh << " = " << this << ".RotateObjectMakeMesh( " + << theObject << ", " + << theAxis << ", " + << theAngleInRadians << ", " + << theCopyGroups << ", '" + << theMeshName << "' )"; + } + return mesh._retn(); +} + //======================================================================= //function : FindCoincidentNodes //purpose : @@ -3200,3 +3391,24 @@ CORBA::Boolean SMESH_MeshEditor_i::ConvertFromQuadratic() TPythonDump() << this << ".ConvertFromQuadratic()"; return isDone; } + +//======================================================================= +//function : makeMesh +//purpose : create a named imported mesh +//======================================================================= + +SMESH::SMESH_Mesh_ptr SMESH_MeshEditor_i::makeMesh(const char* theMeshName) +{ + SMESH_Gen_i* gen = SMESH_Gen_i::GetSMESHGen(); + SMESH::SMESH_Mesh_var mesh = gen->CreateEmptyMesh(); + SALOMEDS::Study_var study = gen->GetCurrentStudy(); + SALOMEDS::SObject_var meshSO = gen->ObjectToSObject( study, mesh ); + gen->SetName( meshSO, theMeshName, "Mesh" ); + + SALOMEDS::StudyBuilder_var builder = study->NewBuilder(); + SALOMEDS::GenericAttribute_var anAttr + = builder->FindOrCreateAttribute( meshSO, "AttributePixMap" ); + SALOMEDS::AttributePixMap::_narrow( anAttr )->SetPixMap( "ICON_SMESH_TREE_MESH_IMPORTED" ); + + return mesh._retn(); +} diff --git a/src/SMESH_I/SMESH_MeshEditor_i.hxx b/src/SMESH_I/SMESH_MeshEditor_i.hxx index 2e57b19ea..03134cec9 100644 --- a/src/SMESH_I/SMESH_MeshEditor_i.hxx +++ b/src/SMESH_I/SMESH_MeshEditor_i.hxx @@ -309,6 +309,35 @@ class SMESH_MeshEditor_i: public POA_SMESH::SMESH_MeshEditor const SMESH::AxisStruct& Axis, CORBA::Double AngleInRadians); + SMESH::SMESH_Mesh_ptr MirrorMakeMesh(const SMESH::long_array& IDsOfElements, + const SMESH::AxisStruct& Mirror, + SMESH::SMESH_MeshEditor::MirrorType MirrorType, + CORBA::Boolean CopyGroups, + const char* MeshName); + SMESH::SMESH_Mesh_ptr MirrorObjectMakeMesh(SMESH::SMESH_IDSource_ptr Object, + const SMESH::AxisStruct& Mirror, + SMESH::SMESH_MeshEditor::MirrorType MirrorType, + CORBA::Boolean CopyGroups, + const char* MeshName); + SMESH::SMESH_Mesh_ptr TranslateMakeMesh(const SMESH::long_array& IDsOfElements, + const SMESH::DirStruct& Vector, + CORBA::Boolean CopyGroups, + const char* MeshName); + SMESH::SMESH_Mesh_ptr TranslateObjectMakeMesh(SMESH::SMESH_IDSource_ptr Object, + const SMESH::DirStruct& Vector, + CORBA::Boolean CopyGroups, + const char* MeshName); + SMESH::SMESH_Mesh_ptr RotateMakeMesh(const SMESH::long_array& IDsOfElements, + const SMESH::AxisStruct& Axis, + CORBA::Double AngleInRadians, + CORBA::Boolean CopyGroups, + const char* MeshName); + SMESH::SMESH_Mesh_ptr RotateObjectMakeMesh(SMESH::SMESH_IDSource_ptr Object, + const SMESH::AxisStruct& Axis, + CORBA::Double AngleInRadians, + CORBA::Boolean CopyGroups, + const char* MeshName); + void FindCoincidentNodes (CORBA::Double Tolerance, SMESH::array_of_long_array_out GroupsOfNodes); void FindCoincidentNodesOnPart(SMESH::SMESH_IDSource_ptr Object, @@ -440,16 +469,21 @@ private: //!< private methods const SMESH::AxisStruct & Axis, SMESH::SMESH_MeshEditor::MirrorType MirrorType, CORBA::Boolean Copy, - const bool MakeGroups); + const bool MakeGroups, + ::SMESH_Mesh* TargetMesh=0); SMESH::ListOfGroups* translate(const SMESH::long_array & IDsOfElements, const SMESH::DirStruct & Vector, CORBA::Boolean Copy, - const bool MakeGroups); + const bool MakeGroups, + ::SMESH_Mesh* TargetMesh=0); SMESH::ListOfGroups* rotate(const SMESH::long_array & IDsOfElements, const SMESH::AxisStruct & Axis, CORBA::Double Angle, CORBA::Boolean Copy, - const bool MakeGroups); + const bool MakeGroups, + ::SMESH_Mesh* TargetMesh=0); + + SMESH::SMESH_Mesh_ptr makeMesh(const char* theMeshName); private: //!< fields diff --git a/src/SMESH_SWIG/smesh.py b/src/SMESH_SWIG/smesh.py index ad4895a00..1a74977ca 100644 --- a/src/SMESH_SWIG/smesh.py +++ b/src/SMESH_SWIG/smesh.py @@ -2374,6 +2374,8 @@ class Mesh: ## Reorient all elements of the object # @param theObject is mesh, submesh or group def ReorientObject(self, theObject): + if ( isinstance( theObject, Mesh )): + theObject = theObject.GetMesh() return self.editor.ReorientObject(theObject) ## Fuse neighbour triangles into quadrangles. @@ -2394,6 +2396,8 @@ class Mesh: # is still performed; theMaxAngle is mesured in radians. # @return TRUE in case of success, FALSE otherwise. def TriToQuadObject (self, theObject, theCriterion, MaxAngle): + if ( isinstance( theObject, Mesh )): + theObject = theObject.GetMesh() return self.editor.TriToQuadObject(theObject, GetFunctor(theCriterion), MaxAngle) ## Split quadrangles into triangles. @@ -2409,6 +2413,8 @@ class Mesh: # @param theObject object to taking list of elements from, is mesh, submesh or group # @param theCriterion is FT_...; used to choose a diagonal for splitting. def QuadToTriObject (self, theObject, theCriterion): + if ( isinstance( theObject, Mesh )): + theObject = theObject.GetMesh() return self.editor.QuadToTriObject(theObject, GetFunctor(theCriterion)) ## Split quadrangles into triangles. @@ -2423,6 +2429,8 @@ class Mesh: ## Split quadrangles into triangles. # @param theObject is object to taking list of elements from, is mesh, submesh or group def SplitQuadObject (self, theObject, Diag13): + if ( isinstance( theObject, Mesh )): + theObject = theObject.GetMesh() return self.editor.SplitQuadObject(theObject, Diag13) ## Find better splitting of the given quadrangle. @@ -2595,6 +2603,8 @@ class Mesh: # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH) def SmoothObject(self, theObject, IDsOfFixedNodes, MaxNbOfIterations, MaxxAspectRatio, Method): + if ( isinstance( theObject, Mesh )): + theObject = theObject.GetMesh() return self.editor.SmoothObject(theObject, IDsOfFixedNodes, MaxNbOfIterations, MaxxAspectRatio, Method) @@ -2621,6 +2631,8 @@ class Mesh: # @param Method is Laplacian(LAPLACIAN_SMOOTH) or Centroidal(CENTROIDAL_SMOOTH) def SmoothParametricObject(self, theObject, IDsOfFixedNodes, MaxNbOfIterations, MaxAspectRatio, Method): + if ( isinstance( theObject, Mesh )): + theObject = theObject.GetMesh() return self.editor.SmoothParametricObject(theObject, IDsOfFixedNodes, MaxNbOfIterations, MaxAspectRatio, Method) @@ -2669,6 +2681,8 @@ class Mesh: # @param Tolerance tolerance # @param MakeGroups to generate new groups from existing ones def RotationSweepObject(self, theObject, Axix, AngleInRadians, NbOfSteps, Tolerance, MakeGroups=False): + if ( isinstance( theObject, Mesh )): + theObject = theObject.GetMesh() if ( isinstance( Axix, geompy.GEOM._objref_GEOM_Object)): Axix = GetAxisStruct(Axix) if MakeGroups: @@ -2716,6 +2730,8 @@ class Mesh: # @param NbOfSteps the number of steps # @param MakeGroups to generate new groups from existing ones def ExtrusionSweepObject(self, theObject, StepVector, NbOfSteps, MakeGroups=False): + if ( isinstance( theObject, Mesh )): + theObject = theObject.GetMesh() if ( isinstance( StepVector, geompy.GEOM._objref_GEOM_Object)): StepVector = GetDirStruct(StepVector) if MakeGroups: @@ -2729,6 +2745,8 @@ class Mesh: # @param NbOfSteps the number of steps # @param MakeGroups to generate new groups from existing ones def ExtrusionSweepObject1D(self, theObject, StepVector, NbOfSteps, MakeGroups=False): + if ( isinstance( theObject, Mesh )): + theObject = theObject.GetMesh() if ( isinstance( StepVector, geompy.GEOM._objref_GEOM_Object)): StepVector = GetDirStruct(StepVector) if MakeGroups: @@ -2742,6 +2760,8 @@ class Mesh: # @param NbOfSteps the number of steps # @param MakeGroups to generate new groups from existing ones def ExtrusionSweepObject2D(self, theObject, StepVector, NbOfSteps, MakeGroups=False): + if ( isinstance( theObject, Mesh )): + theObject = theObject.GetMesh() if ( isinstance( StepVector, geompy.GEOM._objref_GEOM_Object)): StepVector = GetDirStruct(StepVector) if MakeGroups: @@ -2793,6 +2813,8 @@ class Mesh: def ExtrusionAlongPathObject(self, theObject, PathMesh, PathShape, NodeStart, HasAngles, Angles, HasRefPoint, RefPoint, MakeGroups=False, LinearVariation=False): + if ( isinstance( theObject, Mesh )): + theObject = theObject.GetMesh() if ( isinstance( RefPoint, geompy.GEOM._objref_GEOM_Object)): RefPoint = GetPointStruct(RefPoint) if MakeGroups: @@ -2820,6 +2842,22 @@ class Mesh: self.editor.Mirror(IDsOfElements, Mirror, theMirrorType, Copy) return [] + ## Create a new mesh by symmetrical copy of mesh elements + # @param IDsOfElements list of elements ids + # @param Mirror is AxisStruct or geom object(point, line, plane) + # @param theMirrorType is POINT, AXIS or PLANE + # If the Mirror is geom object this parameter is unnecessary + # @param MakeGroups to generate new groups from existing ones + # @param NewMeshName is a name of new mesh to create + def MirrorMakeMesh(self, IDsOfElements, Mirror, theMirrorType, MakeGroups=0, NewMeshName=""): + if IDsOfElements == []: + IDsOfElements = self.GetElementsId() + if ( isinstance( Mirror, geompy.GEOM._objref_GEOM_Object)): + Mirror = GetAxisStruct(Mirror) + mesh = self.editor.MirrorMakeMesh(IDsOfElements, Mirror, theMirrorType, + MakeGroups, NewMeshName) + return Mesh(mesh) + ## Symmetrical copy of object # @param theObject mesh, submesh or group # @param Mirror is AxisStruct or geom object(point, line, plane) @@ -2828,6 +2866,8 @@ class Mesh: # @param Copy allows to copy element(Copy is 1) or to replace with its mirroring(Copy is 0) # @param MakeGroups to generate new groups from existing ones (if Copy) def MirrorObject (self, theObject, Mirror, theMirrorType, Copy=0, MakeGroups=False): + if ( isinstance( theObject, Mesh )): + theObject = theObject.GetMesh() if ( isinstance( Mirror, geompy.GEOM._objref_GEOM_Object)): Mirror = GetAxisStruct(Mirror) if Copy and MakeGroups: @@ -2835,6 +2875,22 @@ class Mesh: self.editor.MirrorObject(theObject, Mirror, theMirrorType, Copy) return [] + ## Create a new mesh by symmetrical copy of object + # @param theObject mesh, submesh or group + # @param Mirror is AxisStruct or geom object(point, line, plane) + # @param theMirrorType is POINT, AXIS or PLANE + # If the Mirror is geom object this parameter is unnecessary + # @param MakeGroups to generate new groups from existing ones + # @param NewMeshName is a name of new mesh to create + def MirrorObjectMakeMesh (self, theObject, Mirror, theMirrorType,MakeGroups=0, NewMeshName=""): + if ( isinstance( theObject, Mesh )): + theObject = theObject.GetMesh() + if ( isinstance( Mirror, geompy.GEOM._objref_GEOM_Object)): + Mirror = GetAxisStruct(Mirror) + mesh = self.editor.MirrorObjectMakeMesh(theObject, Mirror, theMirrorType, + MakeGroups, NewMeshName) + return Mesh( mesh ) + ## Translates the elements # @param IDsOfElements list of elements ids # @param Vector direction of translation(DirStruct or vector) @@ -2850,12 +2906,27 @@ class Mesh: self.editor.Translate(IDsOfElements, Vector, Copy) return [] + ## Create a new mesh of translated elements + # @param IDsOfElements list of elements ids + # @param Vector direction of translation(DirStruct or vector) + # @param MakeGroups to generate new groups from existing ones + # @param NewMeshName is a name of new mesh to create + def TranslateMakeMesh(self, IDsOfElements, Vector, MakeGroups=False, NewMeshName=""): + if IDsOfElements == []: + IDsOfElements = self.GetElementsId() + if ( isinstance( Vector, geompy.GEOM._objref_GEOM_Object)): + Vector = GetDirStruct(Vector) + mesh = self.editor.TranslateMakeMesh(IDsOfElements, Vector, MakeGroups, NewMeshName) + return Mesh ( mesh ) + ## Translates the object # @param theObject object to translate(mesh, submesh, or group) # @param Vector direction of translation(DirStruct or geom vector) # @param Copy allows to copy the translated elements # @param MakeGroups to generate new groups from existing ones (if Copy) def TranslateObject(self, theObject, Vector, Copy, MakeGroups=False): + if ( isinstance( theObject, Mesh )): + theObject = theObject.GetMesh() if ( isinstance( Vector, geompy.GEOM._objref_GEOM_Object)): Vector = GetDirStruct(Vector) if Copy and MakeGroups: @@ -2863,6 +2934,19 @@ class Mesh: self.editor.TranslateObject(theObject, Vector, Copy) return [] + ## Create a new mesh from translated object + # @param theObject object to translate(mesh, submesh, or group) + # @param Vector direction of translation(DirStruct or geom vector) + # @param MakeGroups to generate new groups from existing ones + # @param NewMeshName is a name of new mesh to create + def TranslateObjectMakeMesh(self, theObject, Vector, MakeGroups=False, NewMeshName=""): + if ( isinstance( theObject, Mesh )): + theObject = theObject.GetMesh() + if ( isinstance( Vector, geompy.GEOM._objref_GEOM_Object)): + Vector = GetDirStruct(Vector) + mesh = self.editor.TranslateObjectMakeMesh(theObject, Vector, MakeGroups, NewMeshName) + return Mesh( mesh ) + ## Rotates the elements # @param IDsOfElements list of elements ids # @param Axis axis of rotation(AxisStruct or geom line) @@ -2879,6 +2963,21 @@ class Mesh: self.editor.Rotate(IDsOfElements, Axis, AngleInRadians, Copy) return [] + ## Create a new mesh of rotated elements + # @param IDsOfElements list of element ids + # @param Axis axis of rotation(AxisStruct or geom line) + # @param AngleInRadians angle of rotation(in radians) + # @param MakeGroups to generate new groups from existing ones + # @param NewMeshName is a name of new mesh to create + def RotateMakeMesh (self, IDsOfElements, Axis, AngleInRadians, MakeGroups=0, NewMeshName=""): + if IDsOfElements == []: + IDsOfElements = self.GetElementsId() + if ( isinstance( Axis, geompy.GEOM._objref_GEOM_Object)): + Axis = GetAxisStruct(Axis) + mesh = self.editor.RotateMakeMesh(IDsOfElements, Axis, AngleInRadians, + MakeGroups, NewMeshName) + return Mesh( mesh ) + ## Rotates the object # @param theObject object to rotate(mesh, submesh, or group) # @param Axis axis of rotation(AxisStruct or geom line) @@ -2886,6 +2985,8 @@ class Mesh: # @param Copy allows to copy the rotated elements # @param MakeGroups to generate new groups from existing ones (if Copy) def RotateObject (self, theObject, Axis, AngleInRadians, Copy, MakeGroups=False): + if ( isinstance( theObject, Mesh )): + theObject = theObject.GetMesh() if ( isinstance( Axis, geompy.GEOM._objref_GEOM_Object)): Axis = GetAxisStruct(Axis) if Copy and MakeGroups: @@ -2893,6 +2994,21 @@ class Mesh: self.editor.RotateObject(theObject, Axis, AngleInRadians, Copy) return [] + ## Create a new mesh from a rotated object + # @param theObject object to rotate (mesh, submesh, or group) + # @param Axis axis of rotation(AxisStruct or geom line) + # @param AngleInRadians angle of rotation(in radians) + # @param MakeGroups to generate new groups from existing ones + # @param NewMeshName is a name of new mesh to create + def RotateObjectMakeMesh(self, theObject, Axis, AngleInRadians, MakeGroups=0,NewMeshName=""): + if ( isinstance( theObject, Mesh )): + theObject = theObject.GetMesh() + if ( isinstance( Axis, geompy.GEOM._objref_GEOM_Object)): + Axis = GetAxisStruct(Axis) + mesh = self.editor.RotateObjectMakeMesh(theObject, Axis, AngleInRadians, + MakeGroups, NewMeshName) + return Mesh( mesh ) + ## Find group of nodes close to each other within Tolerance. # @param Tolerance tolerance value # @param list of group of nodes -- 2.39.2