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