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