00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "SMESHGUI_SymmetryDlg.h"
00027
00028 #include "SMESHGUI.h"
00029 #include "SMESHGUI_SpinBox.h"
00030 #include "SMESHGUI_Utils.h"
00031 #include "SMESHGUI_VTKUtils.h"
00032 #include "SMESHGUI_MeshUtils.h"
00033 #include "SMESHGUI_IdValidator.h"
00034 #include "SMESHGUI_FilterDlg.h"
00035 #include "SMESHGUI_MeshEditPreview.h"
00036
00037 #include <SMESH_Actor.h>
00038 #include <SMESH_TypeFilter.hxx>
00039 #include <SMESH_LogicalFilter.hxx>
00040 #include <SMDS_Mesh.hxx>
00041
00042
00043 #include <SUIT_Desktop.h>
00044 #include <SUIT_ResourceMgr.h>
00045 #include <SUIT_Session.h>
00046 #include <SUIT_MessageBox.h>
00047 #include <SUIT_OverrideCursor.h>
00048
00049 #include <LightApp_Application.h>
00050 #include <LightApp_SelectionMgr.h>
00051
00052 #include <SVTK_ViewModel.h>
00053 #include <SVTK_ViewWindow.h>
00054 #include <SALOME_ListIO.hxx>
00055
00056
00057 #include <SALOMEDSClient_SObject.hxx>
00058
00059
00060 #include <TColStd_MapOfInteger.hxx>
00061
00062
00063 #include <QApplication>
00064 #include <QButtonGroup>
00065 #include <QGroupBox>
00066 #include <QLabel>
00067 #include <QLineEdit>
00068 #include <QPushButton>
00069 #include <QRadioButton>
00070 #include <QCheckBox>
00071 #include <QHBoxLayout>
00072 #include <QVBoxLayout>
00073 #include <QGridLayout>
00074 #include <QKeyEvent>
00075
00076
00077 #include <SALOMEconfig.h>
00078 #include CORBA_SERVER_HEADER(SMESH_Group)
00079 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
00080
00081 enum { MOVE_ELEMS_BUTTON = 0, COPY_ELEMS_BUTTON, MAKE_MESH_BUTTON };
00082
00083 #define SPACING 6
00084 #define MARGIN 11
00085
00086
00087
00088 #define WITHGENERICOBJ
00089
00090
00091
00092
00093
00094
00095 SMESHGUI_SymmetryDlg::SMESHGUI_SymmetryDlg( SMESHGUI* theModule )
00096 : SMESHGUI_PreviewDlg( theModule ),
00097 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
00098 myFilterDlg(0),
00099 mySelectedObject(SMESH::SMESH_IDSource::_nil())
00100 {
00101 QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SMESH_SYMMETRY_POINT")));
00102 QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SMESH_SYMMETRY_AXIS")));
00103 QPixmap image2 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SMESH_SYMMETRY_PLANE")));
00104 QPixmap image3 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
00105
00106 setModal(false);
00107 setAttribute(Qt::WA_DeleteOnClose, true);
00108 setWindowTitle(tr("SMESH_SYMMETRY"));
00109 setSizeGripEnabled(true);
00110
00111 QVBoxLayout* SMESHGUI_SymmetryDlgLayout = new QVBoxLayout(this);
00112 SMESHGUI_SymmetryDlgLayout->setSpacing(SPACING);
00113 SMESHGUI_SymmetryDlgLayout->setMargin(MARGIN);
00114
00115
00116 ConstructorsBox = new QGroupBox(tr("SMESH_SYMMETRY"), this);
00117 GroupConstructors = new QButtonGroup(this);
00118 QHBoxLayout* ConstructorsBoxLayout = new QHBoxLayout(ConstructorsBox);
00119 ConstructorsBoxLayout->setSpacing(SPACING);
00120 ConstructorsBoxLayout->setMargin(MARGIN);
00121
00122 RadioButton1 = new QRadioButton(ConstructorsBox);
00123 RadioButton1->setIcon(image0);
00124 RadioButton2 = new QRadioButton(ConstructorsBox);
00125 RadioButton2->setIcon(image1);
00126 RadioButton3 = new QRadioButton(ConstructorsBox);
00127 RadioButton3->setIcon(image2);
00128
00129 ConstructorsBoxLayout->addWidget(RadioButton1);
00130 ConstructorsBoxLayout->addWidget(RadioButton2);
00131 ConstructorsBoxLayout->addWidget(RadioButton3);
00132 GroupConstructors->addButton(RadioButton1, 0);
00133 GroupConstructors->addButton(RadioButton2, 1);
00134 GroupConstructors->addButton(RadioButton3, 2);
00135
00136
00137 GroupArguments = new QGroupBox(tr("SMESH_ARGUMENTS"), this);
00138 QGridLayout* GroupArgumentsLayout = new QGridLayout(GroupArguments);
00139 GroupArgumentsLayout->setSpacing(SPACING);
00140 GroupArgumentsLayout->setMargin(MARGIN);
00141
00142 myIdValidator = new SMESHGUI_IdValidator(this);
00143
00144
00145 TextLabelElements = new QLabel(tr("SMESH_ID_ELEMENTS"), GroupArguments);
00146 SelectElementsButton = new QPushButton(GroupArguments);
00147 SelectElementsButton->setIcon(image3);
00148 LineEditElements = new QLineEdit(GroupArguments);
00149 LineEditElements->setValidator(myIdValidator);
00150 LineEditElements->setMaxLength(-1);
00151 myFilterBtn = new QPushButton( tr( "SMESH_BUT_FILTER" ), GroupArguments );
00152 connect(myFilterBtn, SIGNAL(clicked()), this, SLOT(setFilters()));
00153
00154
00155 CheckBoxMesh = new QCheckBox(tr("SMESH_SELECT_WHOLE_MESH"), GroupArguments);
00156
00157
00158 GroupMirror = new QGroupBox(GroupArguments);
00159 QGridLayout* GroupMirrorLayout = new QGridLayout(GroupMirror);
00160 GroupMirrorLayout->setSpacing(SPACING);
00161 GroupMirrorLayout->setMargin(MARGIN);
00162
00163 TextLabelPoint = new QLabel(tr("SMESH_POINT"), GroupMirror);
00164 SelectPointButton = new QPushButton(GroupMirror);
00165 SelectPointButton->setIcon(image3);
00166
00167 TextLabelX = new QLabel(tr("SMESH_X"), GroupMirror);
00168 SpinBox_X = new SMESHGUI_SpinBox(GroupMirror);
00169 TextLabelY = new QLabel(tr("SMESH_Y"), GroupMirror);
00170 SpinBox_Y = new SMESHGUI_SpinBox(GroupMirror);
00171 TextLabelZ = new QLabel(tr("SMESH_Z"), GroupMirror);
00172 SpinBox_Z = new SMESHGUI_SpinBox(GroupMirror);
00173
00174 TextLabelVector = new QLabel(GroupMirror);
00175 SelectVectorButton = new QPushButton(GroupMirror);
00176 SelectVectorButton->setIcon(image3);
00177
00178 TextLabelDX = new QLabel(tr("SMESH_DX"), GroupMirror);
00179 SpinBox_DX = new SMESHGUI_SpinBox(GroupMirror);
00180 TextLabelDY = new QLabel(tr("SMESH_DY"), GroupMirror);
00181 SpinBox_DY = new SMESHGUI_SpinBox(GroupMirror);
00182 TextLabelDZ = new QLabel(tr("SMESH_DZ"), GroupMirror);
00183 SpinBox_DZ = new SMESHGUI_SpinBox(GroupMirror);
00184
00185 GroupMirrorLayout->addWidget(TextLabelPoint, 0, 0);
00186 GroupMirrorLayout->addWidget(SelectPointButton, 0, 1);
00187 GroupMirrorLayout->addWidget(TextLabelX, 0, 2);
00188 GroupMirrorLayout->addWidget(SpinBox_X, 0, 3);
00189 GroupMirrorLayout->addWidget(TextLabelY, 0, 4);
00190 GroupMirrorLayout->addWidget(SpinBox_Y, 0, 5);
00191 GroupMirrorLayout->addWidget(TextLabelZ, 0, 6);
00192 GroupMirrorLayout->addWidget(SpinBox_Z, 0, 7);
00193 GroupMirrorLayout->addWidget(TextLabelVector, 1, 0);
00194 GroupMirrorLayout->addWidget(SelectVectorButton, 1, 1);
00195 GroupMirrorLayout->addWidget(TextLabelDX, 1, 2);
00196 GroupMirrorLayout->addWidget(SpinBox_DX, 1, 3);
00197 GroupMirrorLayout->addWidget(TextLabelDY, 1, 4);
00198 GroupMirrorLayout->addWidget(SpinBox_DY, 1, 5);
00199 GroupMirrorLayout->addWidget(TextLabelDZ, 1, 6);
00200 GroupMirrorLayout->addWidget(SpinBox_DZ, 1, 7);
00201
00202
00203 ActionBox = new QGroupBox(GroupArguments);
00204 ActionGroup = new QButtonGroup(GroupArguments);
00205 QVBoxLayout* ActionBoxLayout = new QVBoxLayout(ActionBox);
00206 ActionBoxLayout->addSpacing(SPACING);
00207 ActionBoxLayout->setMargin(MARGIN);
00208
00209 QRadioButton* aMoveElements = new QRadioButton(tr("SMESH_MOVE_ELEMENTS"), ActionBox);
00210 QRadioButton* aCopyElements = new QRadioButton(tr("SMESH_COPY_ELEMENTS"), ActionBox);
00211 QRadioButton* aCreateMesh = new QRadioButton(tr("SMESH_CREATE_MESH"), ActionBox);
00212
00213 ActionBoxLayout->addWidget(aMoveElements);
00214 ActionBoxLayout->addWidget(aCopyElements);
00215 ActionBoxLayout->addWidget(aCreateMesh);
00216 ActionGroup->addButton(aMoveElements, MOVE_ELEMS_BUTTON);
00217 ActionGroup->addButton(aCopyElements, COPY_ELEMS_BUTTON);
00218 ActionGroup->addButton(aCreateMesh, MAKE_MESH_BUTTON);
00219
00220
00221 MakeGroupsCheck = new QCheckBox(tr("SMESH_MAKE_GROUPS"), GroupArguments);
00222 MakeGroupsCheck->setChecked(false);
00223
00224
00225 LineEditNewMesh = new QLineEdit(GroupArguments);
00226
00227
00228
00229 myPreviewCheckBox = new QCheckBox(tr("PREVIEW"), GroupArguments);
00230
00231
00232 GroupArgumentsLayout->addWidget(TextLabelElements, 0, 0);
00233 GroupArgumentsLayout->addWidget(SelectElementsButton, 0, 1);
00234 GroupArgumentsLayout->addWidget(LineEditElements, 0, 2, 1, 1);
00235 GroupArgumentsLayout->addWidget(myFilterBtn, 0, 3);
00236 GroupArgumentsLayout->addWidget(CheckBoxMesh, 1, 0, 1, 4);
00237 GroupArgumentsLayout->addWidget(GroupMirror, 2, 0, 1, 4);
00238 GroupArgumentsLayout->addWidget(ActionBox, 3, 0, 3, 3);
00239 GroupArgumentsLayout->addWidget(MakeGroupsCheck, 4, 3);
00240 GroupArgumentsLayout->addWidget(LineEditNewMesh, 5, 3);
00241 GroupArgumentsLayout->addWidget(myPreviewCheckBox, 6, 0);
00242
00243
00244 GroupButtons = new QGroupBox(this);
00245 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
00246 GroupButtonsLayout->setSpacing(SPACING);
00247 GroupButtonsLayout->setMargin(MARGIN);
00248
00249 buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
00250 buttonOk->setAutoDefault(true);
00251 buttonOk->setDefault(true);
00252 buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
00253 buttonApply->setAutoDefault(true);
00254 buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
00255 buttonCancel->setAutoDefault(true);
00256 buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
00257 buttonHelp->setAutoDefault(true);
00258
00259 GroupButtonsLayout->addWidget(buttonOk);
00260 GroupButtonsLayout->addSpacing(10);
00261 GroupButtonsLayout->addWidget(buttonApply);
00262 GroupButtonsLayout->addSpacing(10);
00263 GroupButtonsLayout->addStretch();
00264 GroupButtonsLayout->addWidget(buttonCancel);
00265 GroupButtonsLayout->addWidget(buttonHelp);
00266
00267
00268 SMESHGUI_SymmetryDlgLayout->addWidget(ConstructorsBox);
00269 SMESHGUI_SymmetryDlgLayout->addWidget(GroupArguments);
00270 SMESHGUI_SymmetryDlgLayout->addWidget(GroupButtons);
00271
00272
00273 SpinBox_X->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
00274 SpinBox_Y->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
00275 SpinBox_Z->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
00276 SpinBox_DX->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
00277 SpinBox_DY->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
00278 SpinBox_DZ->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
00279
00280 RadioButton1->setChecked(true);
00281
00282 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
00283
00284 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
00285
00286
00287 SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter (MESHorSUBMESH);
00288 SMESH_TypeFilter* aSmeshGroupFilter = new SMESH_TypeFilter (GROUP);
00289
00290 QList<SUIT_SelectionFilter*> aListOfFilters;
00291 if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
00292 if (aSmeshGroupFilter) aListOfFilters.append(aSmeshGroupFilter);
00293
00294 myMeshOrSubMeshOrGroupFilter =
00295 new SMESH_LogicalFilter (aListOfFilters, SMESH_LogicalFilter::LO_OR);
00296
00297 myHelpFileName = "symmetry_page.html";
00298
00299 Init();
00300
00301
00302 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
00303 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
00304 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
00305 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
00306 connect(GroupConstructors, SIGNAL(buttonClicked(int)), SLOT(ConstructorsClicked(int)));
00307
00308 connect(SelectElementsButton, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
00309 connect(SelectPointButton, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
00310 connect(SelectVectorButton, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
00311
00312 connect(SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
00313 connect(SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
00314 connect(SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(onVectorChanged()));
00315
00316 connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
00317 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
00318
00319 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
00320 connect(LineEditElements, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
00321 connect(CheckBoxMesh, SIGNAL(toggled(bool)), SLOT(onSelectMesh(bool)));
00322 connect(ActionGroup, SIGNAL(buttonClicked(int)), SLOT(onActionClicked(int)));
00323
00324 connect(SpinBox_X, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
00325 connect(SpinBox_Y, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
00326 connect(SpinBox_Z, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
00327 connect(SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
00328 connect(SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
00329 connect(SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
00330
00331
00332 connectPreviewControl();
00333
00334 ConstructorsClicked(0);
00335 SelectionIntoArgument();
00336 onActionClicked(MOVE_ELEMS_BUTTON);
00337 }
00338
00339
00340
00341
00342
00343 SMESHGUI_SymmetryDlg::~SMESHGUI_SymmetryDlg()
00344 {
00345 if ( myFilterDlg != 0 ) {
00346 myFilterDlg->setParent( 0 );
00347 delete myFilterDlg;
00348 }
00349 }
00350
00351
00352
00353
00354
00355 void SMESHGUI_SymmetryDlg::Init (bool ResetControls)
00356 {
00357 myBusy = false;
00358
00359 myEditCurrentArgument = 0;
00360 LineEditElements->clear();
00361 myElementsId = "";
00362 myNbOkElements = 0;
00363
00364 buttonOk->setEnabled(false);
00365 buttonApply->setEnabled(false);
00366
00367 myActor = 0;
00368 myMesh = SMESH::SMESH_Mesh::_nil();
00369
00370 if (ResetControls) {
00371 SpinBox_X->SetValue(0.0);
00372 SpinBox_Y->SetValue(0.0);
00373 SpinBox_Z->SetValue(0.0);
00374 SpinBox_DX->SetValue(0.0);
00375 SpinBox_DY->SetValue(0.0);
00376 SpinBox_DZ->SetValue(0.0);
00377
00378 ActionGroup->button( MOVE_ELEMS_BUTTON )->setChecked(true);
00379 CheckBoxMesh->setChecked(false);
00380 myPreviewCheckBox->setChecked(false);
00381 onDisplaySimulation(false);
00382
00383
00384
00385 onSelectMesh(false);
00386 }
00387 }
00388
00389
00390
00391
00392
00393 void SMESHGUI_SymmetryDlg::ConstructorsClicked (int constructorId)
00394 {
00395 disconnect(mySelectionMgr, 0, this, 0);
00396
00397 if (constructorId != 0 && !TextLabelVector->isVisible()) {
00398 TextLabelVector->show();
00399 SelectVectorButton->show();
00400 TextLabelDX->show();
00401 SpinBox_DX->show();
00402 TextLabelDY->show();
00403 SpinBox_DY->show();
00404 TextLabelDZ->show();
00405 SpinBox_DZ->show();
00406 }
00407
00408 switch (constructorId) {
00409 case 0:
00410 {
00411 GroupMirror->setTitle(tr("SMESH_POINT"));
00412
00413 TextLabelVector->hide();
00414 SelectVectorButton->hide();
00415 TextLabelDX->hide();
00416 SpinBox_DX->hide();
00417 TextLabelDY->hide();
00418 SpinBox_DY->hide();
00419 TextLabelDZ->hide();
00420 SpinBox_DZ->hide();
00421 break;
00422 }
00423 case 1:
00424 {
00425 GroupMirror->setTitle(tr("SMESH_AXIS"));
00426 TextLabelVector->setText(tr("SMESH_VECTOR"));
00427 break;
00428 }
00429 case 2:
00430 {
00431 GroupMirror->setTitle(tr("SMESH_PLANE"));
00432 TextLabelVector->setText(tr("SMESH_NORMAL"));
00433 break;
00434 }
00435 }
00436
00437 if (myEditCurrentArgument != (QWidget*)LineEditElements) {
00438 SMESH::SetPointRepresentation(false);
00439 if (!CheckBoxMesh->isChecked())
00440 {
00441 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
00442 aViewWindow->SetSelectionMode(CellSelection);
00443 }
00444 }
00445
00446 myEditCurrentArgument = (QWidget*)LineEditElements;
00447 LineEditElements->setFocus();
00448
00449 if (CheckBoxMesh->isChecked())
00450 onSelectMesh(true);
00451
00452 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
00453
00454 onDisplaySimulation(true);
00455
00456 QApplication::instance()->processEvents();
00457 updateGeometry();
00458 resize(100,100);
00459 }
00460
00461
00462
00463
00464
00465 bool SMESHGUI_SymmetryDlg::ClickOnApply()
00466 {
00467 if (mySMESHGUI->isActiveStudyLocked())
00468 return false;
00469
00470 if( !isValid() )
00471 return false;
00472
00473 if (myNbOkElements && IsMirrorOk()) {
00474 QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
00475
00476 SMESH::long_array_var anElementsId = new SMESH::long_array;
00477
00478 anElementsId->length(aListElementsId.count());
00479 for (int i = 0; i < aListElementsId.count(); i++)
00480 anElementsId[i] = aListElementsId[i].toInt();
00481
00482 SMESH::AxisStruct aMirror;
00483 SMESH::SMESH_MeshEditor::MirrorType aMirrorType;
00484 getMirror(aMirror,aMirrorType);
00485
00486 QStringList aParameters;
00487 aParameters << SpinBox_X->text();
00488 aParameters << SpinBox_Y->text();
00489 aParameters << SpinBox_Z->text();
00490 aParameters << ( GetConstructorId() == 0 ? QString::number(0) : SpinBox_DX->text() );
00491 aParameters << ( GetConstructorId() == 0 ? QString::number(0) : SpinBox_DY->text() );
00492 aParameters << ( GetConstructorId() == 0 ? QString::number(0) : SpinBox_DZ->text() );
00493
00494 int actionButton = ActionGroup->checkedId();
00495 bool makeGroups = ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() );
00496 QStringList anEntryList;
00497 try {
00498 SUIT_OverrideCursor aWaitCursor;
00499 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
00500
00501 switch ( actionButton ) {
00502 case MOVE_ELEMS_BUTTON: {
00503 if(CheckBoxMesh->isChecked())
00504 aMeshEditor->MirrorObject(mySelectedObject, aMirror, aMirrorType, false );
00505 else
00506 aMeshEditor->Mirror(anElementsId, aMirror, aMirrorType, false );
00507
00508 if( !myMesh->_is_nil())
00509 myMesh->SetParameters( aParameters.join(":").toLatin1().constData() );
00510 break;
00511 }
00512 case COPY_ELEMS_BUTTON: {
00513 SMESH::ListOfGroups_var groups;
00514 if ( makeGroups ) {
00515 if(CheckBoxMesh->isChecked())
00516 groups = aMeshEditor->MirrorObjectMakeGroups(mySelectedObject, aMirror, aMirrorType);
00517 else
00518 groups = aMeshEditor->MirrorMakeGroups(anElementsId, aMirror, aMirrorType);
00519 }
00520 else {
00521 if(CheckBoxMesh->isChecked())
00522 aMeshEditor->MirrorObject(mySelectedObject, aMirror, aMirrorType, true);
00523 else
00524 aMeshEditor->Mirror(anElementsId, aMirror, aMirrorType, true);
00525 }
00526 if( !myMesh->_is_nil())
00527 myMesh->SetParameters( aParameters.join(":").toLatin1().constData() );
00528 break;
00529 }
00530 case MAKE_MESH_BUTTON: {
00531 SMESH::SMESH_Mesh_var mesh;
00532 if (CheckBoxMesh->isChecked())
00533 mesh = aMeshEditor->MirrorObjectMakeMesh(mySelectedObject, aMirror, aMirrorType, makeGroups,
00534 LineEditNewMesh->text().toLatin1().data());
00535 else
00536 mesh = aMeshEditor->MirrorMakeMesh(anElementsId, aMirror, aMirrorType, makeGroups,
00537 LineEditNewMesh->text().toLatin1().data());
00538 if (!mesh->_is_nil()) {
00539 mesh->SetParameters(aParameters.join(":").toLatin1().constData());
00540 if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( mesh ) )
00541 anEntryList.append( aSObject->GetID().c_str() );
00542 #ifdef WITHGENERICOBJ
00543
00544
00545
00546 mesh->UnRegister();
00547 #endif
00548 }
00549 break;
00550 }
00551 }
00552 } catch (...) {
00553 }
00554
00555 SMESH::UpdateView();
00556 if ( ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() ) ||
00557 actionButton == MAKE_MESH_BUTTON ) {
00558 mySMESHGUI->updateObjBrowser(true);
00559 if( LightApp_Application* anApp =
00560 dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
00561 anApp->browseObjects( anEntryList, isApplyAndClose() );
00562 }
00563 Init(false);
00564 ConstructorsClicked(GetConstructorId());
00565 mySelectedObject = SMESH::SMESH_IDSource::_nil();
00566 SelectionIntoArgument();
00567
00568 SMESHGUI::Modified();
00569 }
00570 return true;
00571 }
00572
00573
00574
00575
00576
00577 void SMESHGUI_SymmetryDlg::ClickOnOk()
00578 {
00579 setIsApplyAndClose( true );
00580 if( ClickOnApply() )
00581 ClickOnCancel();
00582 }
00583
00584
00585
00586
00587
00588 void SMESHGUI_SymmetryDlg::ClickOnCancel()
00589 {
00590 disconnect(mySelectionMgr, 0, this, 0);
00591 mySelectionMgr->clearFilters();
00592
00593 if (SMESH::GetCurrentVtkView()) {
00594 SMESH::RemoveFilters();
00595 SMESH::SetPointRepresentation(false);
00596 }
00597 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
00598 aViewWindow->SetSelectionMode(ActorSelection);
00599 mySMESHGUI->ResetState();
00600 reject();
00601 }
00602
00603
00604
00605
00606
00607 void SMESHGUI_SymmetryDlg::ClickOnHelp()
00608 {
00609 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
00610 if (app)
00611 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
00612 else {
00613 QString platform;
00614 #ifdef WIN32
00615 platform = "winapplication";
00616 #else
00617 platform = "application";
00618 #endif
00619 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
00620 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
00621 arg(app->resourceMgr()->stringValue("ExternalBrowser",
00622 platform)).
00623 arg(myHelpFileName));
00624 }
00625 }
00626
00627
00628
00629
00630
00631 void SMESHGUI_SymmetryDlg::onTextChange (const QString& theNewText)
00632 {
00633 QLineEdit* send = (QLineEdit*)sender();
00634
00635 if (myBusy) return;
00636 myBusy = true;
00637
00638 if (send == LineEditElements)
00639 myNbOkElements = 0;
00640
00641 buttonOk->setEnabled(false);
00642 buttonApply->setEnabled(false);
00643
00644
00645 SMDS_Mesh* aMesh = 0;
00646 if (myActor)
00647 aMesh = myActor->GetObject()->GetMesh();
00648
00649 if (aMesh) {
00650 Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
00651
00652 TColStd_MapOfInteger newIndices;
00653
00654 QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
00655
00656 if (send == LineEditElements) {
00657 for (int i = 0; i < aListId.count(); i++) {
00658 const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
00659 if (e)
00660 newIndices.Add(e->GetID());
00661 myNbOkElements++;
00662 }
00663
00664 mySelector->AddOrRemoveIndex( anIO, newIndices, false );
00665 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
00666 aViewWindow->highlight( anIO, true, true );
00667
00668 myElementsId = theNewText;
00669 }
00670 }
00671
00672 if (myNbOkElements && IsMirrorOk()) {
00673 buttonOk->setEnabled(true);
00674 buttonApply->setEnabled(true);
00675 }
00676
00677 myBusy = false;
00678 }
00679
00680
00681
00682
00683
00684 void SMESHGUI_SymmetryDlg::SelectionIntoArgument()
00685 {
00686 if (myBusy) return;
00687
00688
00689 myActor = 0;
00690 QString aString = "";
00691
00692 myBusy = true;
00693 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
00694 LineEditElements->setText(aString);
00695 myNbOkElements = 0;
00696 buttonOk->setEnabled(false);
00697 buttonApply->setEnabled(false);
00698 }
00699 myBusy = false;
00700
00701 if (!GroupButtons->isEnabled())
00702 return;
00703
00704
00705 SALOME_ListIO aList;
00706 mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
00707
00708 int nbSel = aList.Extent();
00709 if (nbSel != 1)
00710 return;
00711
00712 Handle(SALOME_InteractiveObject) IO = aList.First();
00713 myMesh = SMESH::GetMeshByIO(IO);
00714 if(myMesh->_is_nil())
00715 return;
00716
00717 myActor = SMESH::FindActorByObject(myMesh);
00718 if (!myActor)
00719 myActor = SMESH::FindActorByEntry(IO->getEntry());
00720 if (!myActor && !CheckBoxMesh->isChecked())
00721 return;
00722
00723 int aNbUnits = 0;
00724
00725 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
00726 myElementsId = "";
00727
00728
00729 if ( myMesh->NbGroups() == 0 ) {
00730 MakeGroupsCheck->setChecked(false);
00731 MakeGroupsCheck->setEnabled(false);
00732 }
00733 else if ( ActionGroup->checkedId() != MOVE_ELEMS_BUTTON ) {
00734 MakeGroupsCheck->setEnabled(true);
00735 }
00736 if (CheckBoxMesh->isChecked()) {
00737 SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
00738
00739 if (!SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO)->_is_nil()) {
00740 mySelectedObject = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO);
00741 }
00742 else
00743 return;
00744
00745
00746
00747
00748
00749
00750
00751
00752
00753
00754
00755
00756
00757
00758
00759
00760
00761
00762
00763
00764
00765
00766
00767
00768
00769
00770
00771
00772
00773
00774
00775
00776
00777
00778
00779
00780
00781
00782
00783
00784
00785 } else {
00786 aNbUnits = SMESH::GetNameOfSelectedElements( mySelector, IO, aString);
00787 myElementsId = aString;
00788 if (aNbUnits < 1)
00789 return;
00790 }
00791
00792 myNbOkElements = true;
00793 } else {
00794 aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, IO, aString);
00795 if (aNbUnits != 1)
00796 return;
00797
00798 SMDS_Mesh* aMesh = myActor->GetObject()->GetMesh();
00799 if (!aMesh)
00800 return;
00801
00802 const SMDS_MeshNode * n = aMesh->FindNode(aString.toInt());
00803 if (!n)
00804 return;
00805
00806 double x = n->X();
00807 double y = n->Y();
00808 double z = n->Z();
00809
00810 if (myEditCurrentArgument == (QWidget*)SpinBox_X) {
00811 SpinBox_X->SetValue(x);
00812 SpinBox_Y->SetValue(y);
00813 SpinBox_Z->SetValue(z);
00814 } else if (myEditCurrentArgument == (QWidget*)SpinBox_DX) {
00815 SpinBox_DX->SetValue(x - SpinBox_X->GetValue());
00816 SpinBox_DY->SetValue(y - SpinBox_Y->GetValue());
00817 SpinBox_DZ->SetValue(z - SpinBox_Z->GetValue());
00818 }
00819 }
00820
00821 myBusy = true;
00822 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
00823 LineEditElements->setText(aString);
00824 LineEditElements->repaint();
00825 LineEditElements->setEnabled(false);
00826 LineEditElements->setEnabled(true);
00827 setNewMeshName();
00828 }
00829 myBusy = false;
00830
00831
00832 if (myNbOkElements && IsMirrorOk()) {
00833 buttonOk->setEnabled(true);
00834 buttonApply->setEnabled(true);
00835 }
00836 onDisplaySimulation(true);
00837 }
00838
00839
00840
00841
00842
00843 void SMESHGUI_SymmetryDlg::SetEditCurrentArgument()
00844 {
00845 QPushButton* send = (QPushButton*)sender();
00846
00847 disconnect(mySelectionMgr, 0, this, 0);
00848 mySelectionMgr->clearSelected();
00849 mySelectionMgr->clearFilters();
00850
00851 if (send == SelectElementsButton) {
00852 myEditCurrentArgument = (QWidget*)LineEditElements;
00853 SMESH::SetPointRepresentation(false);
00854 if (CheckBoxMesh->isChecked()) {
00855 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
00856 aViewWindow->SetSelectionMode(ActorSelection);
00857 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
00858 } else {
00859 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
00860 aViewWindow->SetSelectionMode(CellSelection);
00861 }
00862 } else if (send == SelectPointButton) {
00863 myEditCurrentArgument = (QWidget*)SpinBox_X;
00864 SMESH::SetPointRepresentation(true);
00865 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
00866 aViewWindow->SetSelectionMode(NodeSelection);
00867 } else if (send == SelectVectorButton) {
00868 myEditCurrentArgument = (QWidget*)SpinBox_DX;
00869 SMESH::SetPointRepresentation(true);
00870
00871 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
00872 aViewWindow->SetSelectionMode(NodeSelection);
00873 } else {
00874 }
00875
00876 myEditCurrentArgument->setFocus();
00877 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
00878 SelectionIntoArgument();
00879 }
00880
00881
00882
00883
00884
00885 void SMESHGUI_SymmetryDlg::DeactivateActiveDialog()
00886 {
00887 if (ConstructorsBox->isEnabled()) {
00888 ConstructorsBox->setEnabled(false);
00889 GroupArguments->setEnabled(false);
00890 GroupButtons->setEnabled(false);
00891 mySMESHGUI->ResetState();
00892 mySMESHGUI->SetActiveDialogBox(0);
00893 }
00894 }
00895
00896
00897
00898
00899
00900 void SMESHGUI_SymmetryDlg::ActivateThisDialog()
00901 {
00902
00903 mySMESHGUI->EmitSignalDeactivateDialog();
00904 ConstructorsBox->setEnabled(true);
00905 GroupArguments->setEnabled(true);
00906 GroupButtons->setEnabled(true);
00907
00908 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
00909
00910 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
00911 aViewWindow->SetSelectionMode(CellSelection);
00912 SelectionIntoArgument();
00913 }
00914
00915
00916
00917
00918
00919 void SMESHGUI_SymmetryDlg::enterEvent (QEvent*)
00920 {
00921 if (!ConstructorsBox->isEnabled())
00922 ActivateThisDialog();
00923 }
00924
00925
00926
00927
00928
00929 void SMESHGUI_SymmetryDlg::closeEvent (QCloseEvent*)
00930 {
00931
00932 ClickOnCancel();
00933 }
00934
00935
00936
00937
00938
00939 void SMESHGUI_SymmetryDlg::hideEvent (QHideEvent*)
00940 {
00941 if (!isMinimized())
00942 ClickOnCancel();
00943 }
00944
00945
00946
00947
00948
00949 void SMESHGUI_SymmetryDlg::onSelectMesh (bool toSelectMesh)
00950 {
00951 if (toSelectMesh)
00952 TextLabelElements->setText(tr("SMESH_NAME"));
00953 else
00954 TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
00955 myFilterBtn->setEnabled(!toSelectMesh);
00956
00957 if (myEditCurrentArgument != LineEditElements) {
00958 LineEditElements->clear();
00959 return;
00960 }
00961
00962 mySelectionMgr->clearFilters();
00963 SMESH::SetPointRepresentation(false);
00964
00965 if (toSelectMesh) {
00966 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
00967 aViewWindow->SetSelectionMode(ActorSelection);
00968 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
00969 LineEditElements->setReadOnly(true);
00970 LineEditElements->setValidator(0);
00971 } else {
00972 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
00973 aViewWindow->SetSelectionMode(CellSelection);
00974 LineEditElements->setReadOnly(false);
00975 LineEditElements->setValidator(myIdValidator);
00976 onTextChange(LineEditElements->text());
00977 hidePreview();
00978 }
00979
00980 SelectionIntoArgument();
00981 }
00982
00983
00984
00985
00986
00987 int SMESHGUI_SymmetryDlg::GetConstructorId()
00988 {
00989 return GroupConstructors->checkedId();
00990 }
00991
00992
00993
00994
00995
00996 bool SMESHGUI_SymmetryDlg::IsMirrorOk()
00997 {
00998 bool isOk = true;
00999
01000 if (GetConstructorId() != 0)
01001 isOk = (SpinBox_DX->GetValue() != 0 ||
01002 SpinBox_DY->GetValue() != 0 ||
01003 SpinBox_DZ->GetValue() != 0);
01004
01005 return isOk;
01006 }
01007
01008
01009
01010
01011
01012 void SMESHGUI_SymmetryDlg::onVectorChanged()
01013 {
01014 if (IsMirrorOk()) {
01015 buttonOk->setEnabled(true);
01016 buttonApply->setEnabled(true);
01017 } else {
01018 buttonOk->setEnabled(false);
01019 buttonApply->setEnabled(false);
01020 }
01021 }
01022
01023
01024
01025
01026
01027
01028 void SMESHGUI_SymmetryDlg::onActionClicked(int button)
01029 {
01030 switch ( button ) {
01031 case MOVE_ELEMS_BUTTON:
01032 MakeGroupsCheck->setEnabled(false);
01033 LineEditNewMesh->setEnabled(false);
01034 break;
01035 case COPY_ELEMS_BUTTON:
01036 LineEditNewMesh->setEnabled(false);
01037 MakeGroupsCheck->setText( tr("SMESH_MAKE_GROUPS"));
01038 if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
01039 MakeGroupsCheck->setEnabled(true);
01040 else
01041 MakeGroupsCheck->setEnabled(false);
01042 break;
01043 case MAKE_MESH_BUTTON:
01044 LineEditNewMesh->setEnabled(true);
01045 MakeGroupsCheck->setText( tr("SMESH_COPY_GROUPS"));
01046 if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
01047 MakeGroupsCheck->setEnabled(true);
01048 else
01049 MakeGroupsCheck->setEnabled(false);
01050 break;
01051 }
01052 setNewMeshName();
01053 toDisplaySimulation();
01054 }
01055
01056
01057
01058
01059
01060
01061 void SMESHGUI_SymmetryDlg::setNewMeshName()
01062 {
01063 LineEditNewMesh->setText("");
01064 if ( LineEditNewMesh->isEnabled() && !myMesh->_is_nil() ) {
01065 QString name;
01066 if ( CheckBoxMesh->isChecked() ) {
01067 name = LineEditElements->text();
01068 }
01069 else {
01070 _PTR(SObject) meshSO = SMESH::FindSObject( myMesh );
01071 name = meshSO->GetName().c_str();
01072 }
01073 if ( !name.isEmpty() )
01074 LineEditNewMesh->setText( SMESH::UniqueMeshName( name, "mirrored"));
01075 }
01076 }
01077
01078
01079
01080
01081
01082 void SMESHGUI_SymmetryDlg::keyPressEvent( QKeyEvent* e )
01083 {
01084 QDialog::keyPressEvent( e );
01085 if ( e->isAccepted() )
01086 return;
01087
01088 if ( e->key() == Qt::Key_F1 ) {
01089 e->accept();
01090 ClickOnHelp();
01091 }
01092 }
01093
01094
01095
01096
01097
01098 void SMESHGUI_SymmetryDlg::setFilters()
01099 {
01100 if(myMesh->_is_nil()) {
01101 SUIT_MessageBox::critical(this,
01102 tr("SMESH_ERROR"),
01103 tr("NO_MESH_SELECTED"));
01104 return;
01105 }
01106 if ( !myFilterDlg )
01107 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, SMESH::ALL );
01108
01109 myFilterDlg->SetSelection();
01110 myFilterDlg->SetMesh( myMesh );
01111 myFilterDlg->SetSourceWg( LineEditElements );
01112
01113 myFilterDlg->show();
01114 }
01115
01116
01117
01118
01119
01120 bool SMESHGUI_SymmetryDlg::isValid()
01121 {
01122 bool ok = true;
01123 QString msg;
01124
01125 ok = SpinBox_X->isValid( msg, true ) && ok;
01126 ok = SpinBox_Y->isValid( msg, true ) && ok;
01127 ok = SpinBox_Z->isValid( msg, true ) && ok;
01128 if (GetConstructorId() != 0) {
01129 ok = SpinBox_DX->isValid( msg, true ) && ok;
01130 ok = SpinBox_DY->isValid( msg, true ) && ok;
01131 ok = SpinBox_DZ->isValid( msg, true ) && ok;
01132 }
01133
01134 if( !ok ) {
01135 QString str( tr( "SMESH_INCORRECT_INPUT" ) );
01136 if ( !msg.isEmpty() )
01137 str += "\n" + msg;
01138 SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
01139 return false;
01140 }
01141 return true;
01142 }
01143
01144
01145
01146
01147
01148 void SMESHGUI_SymmetryDlg::onDisplaySimulation( bool toDisplayPreview ) {
01149 if (myPreviewCheckBox->isChecked() && toDisplayPreview) {
01150 if ( myNbOkElements && isValid() && IsMirrorOk() ) {
01151 QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
01152 SMESH::long_array_var anElementsId = new SMESH::long_array;
01153
01154 anElementsId->length(aListElementsId.count());
01155 for (int i = 0; i < aListElementsId.count(); i++)
01156 anElementsId[i] = aListElementsId[i].toInt();
01157
01158 SMESH::AxisStruct aMirror;
01159 SMESH::SMESH_MeshEditor::MirrorType aMirrorType;
01160
01161 getMirror(aMirror,aMirrorType);
01162
01163 try {
01164 bool copy = ( ActionGroup->checkedId() == COPY_ELEMS_BUTTON ||
01165 ActionGroup->checkedId() == MAKE_MESH_BUTTON );
01166 SUIT_OverrideCursor aWaitCursor;
01167 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditPreviewer();
01168 if(CheckBoxMesh->isChecked())
01169 aMeshEditor->MirrorObject(mySelectedObject, aMirror, aMirrorType, copy );
01170 else
01171 aMeshEditor->Mirror(anElementsId, aMirror, aMirrorType, copy );
01172
01173 SMESH::MeshPreviewStruct_var aMeshPreviewStruct = aMeshEditor->GetPreviewData();
01174 mySimulation->SetData(aMeshPreviewStruct._retn());
01175 } catch (...) {
01176 hidePreview();
01177 }
01178 } else {
01179 hidePreview();
01180 }
01181 } else {
01182 hidePreview();
01183 }
01184 }
01185
01186
01187
01188
01189
01190 void SMESHGUI_SymmetryDlg::getMirror(SMESH::AxisStruct& theMirror, SMESH::SMESH_MeshEditor::MirrorType& theMirrorType) {
01191 theMirror.x = SpinBox_X->GetValue();
01192 theMirror.y = SpinBox_Y->GetValue();
01193 theMirror.z = SpinBox_Z->GetValue();
01194 if (GetConstructorId() == 0) {
01195 theMirror.vx = theMirror.vy = theMirror.vz = 0;
01196 } else {
01197 theMirror.vx = SpinBox_DX->GetValue();
01198 theMirror.vy = SpinBox_DY->GetValue();
01199 theMirror.vz = SpinBox_DZ->GetValue();
01200 }
01201 if (GetConstructorId() == 0)
01202 theMirrorType = SMESH::SMESH_MeshEditor::POINT;
01203 if (GetConstructorId() == 1)
01204 theMirrorType = SMESH::SMESH_MeshEditor::AXIS;
01205 if (GetConstructorId() == 2)
01206 theMirrorType = SMESH::SMESH_MeshEditor::PLANE;
01207 }