1 // Copyright (C) 2007-2021 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File : SMESHGUI_TranslationDlg.cxx
23 // Author : Michael ZORIN, Open CASCADE S.A.S.
26 #include "SMESHGUI_TranslationDlg.h"
29 #include "SMESHGUI_SpinBox.h"
30 #include "SMESHGUI_Utils.h"
31 #include "SMESHGUI_VTKUtils.h"
32 #include "SMESHGUI_MeshUtils.h"
33 #include "SMESHGUI_IdValidator.h"
34 #include "SMESHGUI_FilterDlg.h"
35 #include "SMESHGUI_MeshEditPreview.h"
37 #include <SMESH_Actor.h>
38 #include <SMESH_TypeFilter.hxx>
39 #include <SMESH_LogicalFilter.hxx>
40 #include <SMDS_Mesh.hxx>
42 // SALOME GUI includes
43 #include <SUIT_Desktop.h>
44 #include <SUIT_ResourceMgr.h>
45 #include <SUIT_Session.h>
46 #include <SUIT_MessageBox.h>
47 #include <SUIT_OverrideCursor.h>
49 #include <LightApp_Application.h>
50 #include <LightApp_SelectionMgr.h>
52 #include <SVTK_ViewModel.h>
53 #include <SVTK_ViewWindow.h>
54 #include <SALOME_ListIO.hxx>
56 // SALOME KERNEL includes
57 #include <SALOMEDSClient.hxx>
58 #include <SALOMEDSClient_SObject.hxx>
61 #include <TColStd_MapOfInteger.hxx>
64 #include <QApplication>
65 #include <QButtonGroup>
69 #include <QPushButton>
70 #include <QRadioButton>
72 #include <QHBoxLayout>
73 #include <QVBoxLayout>
74 #include <QGridLayout>
79 #include <SALOMEconfig.h>
80 #include CORBA_SERVER_HEADER(SMESH_Group)
81 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
83 enum { MOVE_ELEMS_BUTTON = 0, COPY_ELEMS_BUTTON, MAKE_MESH_BUTTON }; //!< action type
87 \brief Simple 'busy state' flag locker.
94 //! Constructor. Sets passed boolean flag to \c true.
95 BusyLocker( bool& busy ) : myBusy( busy ) { myBusy = true; }
96 //! Destructor. Clear external boolean flag passed as parameter to the constructor to \c false.
97 ~BusyLocker() { myBusy = false; }
99 bool& myBusy; //! External 'busy state' boolean flag
106 //=================================================================================
107 // class : SMESHGUI_TranslationDlg()
109 //=================================================================================
110 SMESHGUI_TranslationDlg::SMESHGUI_TranslationDlg( SMESHGUI* theModule ) :
111 SMESHGUI_MultiPreviewDlg( theModule ),
112 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
115 QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SMESH_TRANSLATION_POINTS")));
116 QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SMESH_TRANSLATION_VECTOR")));
117 QPixmap image2 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
120 setAttribute(Qt::WA_DeleteOnClose, true);
121 setWindowTitle(tr("SMESH_TRANSLATION"));
122 setSizeGripEnabled(true);
124 QVBoxLayout* SMESHGUI_TranslationDlgLayout = new QVBoxLayout(this);
125 SMESHGUI_TranslationDlgLayout->setSpacing(SPACING);
126 SMESHGUI_TranslationDlgLayout->setMargin(MARGIN);
128 /***************************************************************/
129 ConstructorsBox = new QGroupBox(tr("SMESH_TRANSLATION"), this);
130 GroupConstructors = new QButtonGroup(this);
131 QHBoxLayout* ConstructorsBoxLayout = new QHBoxLayout(ConstructorsBox);
132 ConstructorsBoxLayout->setSpacing(SPACING);
133 ConstructorsBoxLayout->setMargin(MARGIN);
135 RadioButton1= new QRadioButton(ConstructorsBox);
136 RadioButton1->setIcon(image0);
137 RadioButton2= new QRadioButton(ConstructorsBox);
138 RadioButton2->setIcon(image1);
140 ConstructorsBoxLayout->addWidget(RadioButton1);
141 ConstructorsBoxLayout->addWidget(RadioButton2);
142 GroupConstructors->addButton(RadioButton1, 0);
143 GroupConstructors->addButton(RadioButton2, 1);
145 /***************************************************************/
146 GroupArguments = new QGroupBox(tr("SMESH_ARGUMENTS"), this);
147 QGridLayout* GroupArgumentsLayout = new QGridLayout(GroupArguments);
148 GroupArgumentsLayout->setSpacing(SPACING);
149 GroupArgumentsLayout->setMargin(MARGIN);
151 myIdValidator = new SMESHGUI_IdValidator(this);
153 // Controls for elements selection
154 TextLabelElements = new QLabel(tr("SMESH_ID_ELEMENTS"), GroupArguments);
155 SelectElementsButton = new QPushButton(GroupArguments);
156 SelectElementsButton->setIcon(image2);
157 LineEditElements = new QLineEdit(GroupArguments);
158 LineEditElements->setValidator(myIdValidator);
159 LineEditElements->setMaxLength(-1);
160 myFilterBtn = new QPushButton( tr( "SMESH_BUT_FILTER" ), GroupArguments );
161 connect(myFilterBtn, SIGNAL(clicked()), this, SLOT(setFilters()));
163 // Control for the whole mesh selection
164 CheckBoxMesh = new QCheckBox(tr("SMESH_SELECT_WHOLE_MESH"), GroupArguments);
166 // Controls for vector and points selection
167 TextLabel1 = new QLabel(GroupArguments);
168 SelectButton1 = new QPushButton(GroupArguments);
169 SelectButton1->setIcon(image2);
171 TextLabel1_1 = new QLabel(GroupArguments);
172 SpinBox1_1 = new SMESHGUI_SpinBox(GroupArguments);
173 TextLabel1_2 = new QLabel(GroupArguments);
174 SpinBox1_2 = new SMESHGUI_SpinBox(GroupArguments);
175 TextLabel1_3 = new QLabel(GroupArguments);
176 SpinBox1_3 = new SMESHGUI_SpinBox(GroupArguments);
178 TextLabel2 = new QLabel(tr("SMESH_POINT_2"), GroupArguments);
179 SelectButton2 = new QPushButton(GroupArguments);
180 SelectButton2->setIcon(image2);
182 TextLabel2_1 = new QLabel(tr("SMESH_X"), GroupArguments);
183 SpinBox2_1 = new SMESHGUI_SpinBox(GroupArguments);
184 TextLabel2_2 = new QLabel(tr("SMESH_Y"), GroupArguments);
185 SpinBox2_2 = new SMESHGUI_SpinBox(GroupArguments);
186 TextLabel2_3 = new QLabel(tr("SMESH_Z"), GroupArguments);
187 SpinBox2_3 = new SMESHGUI_SpinBox(GroupArguments);
189 // switch of action type
190 ActionBox = new QGroupBox(GroupArguments);
191 ActionGroup = new QButtonGroup(GroupArguments);
192 QVBoxLayout* ActionBoxLayout = new QVBoxLayout(ActionBox);
193 ActionBoxLayout->addSpacing(SPACING);
194 ActionBoxLayout->setMargin(MARGIN);
196 QRadioButton* aMoveElements = new QRadioButton(tr("SMESH_MOVE_ELEMENTS"), ActionBox);
197 QRadioButton* aCopyElements = new QRadioButton(tr("SMESH_COPY_ELEMENTS"), ActionBox);
198 QRadioButton* aCreateMesh = new QRadioButton(tr("SMESH_CREATE_MESH"), ActionBox);
200 ActionBoxLayout->addWidget(aMoveElements);
201 ActionBoxLayout->addWidget(aCopyElements);
202 ActionBoxLayout->addWidget(aCreateMesh);
203 ActionGroup->addButton(aMoveElements, MOVE_ELEMS_BUTTON);
204 ActionGroup->addButton(aCopyElements, COPY_ELEMS_BUTTON);
205 ActionGroup->addButton(aCreateMesh, MAKE_MESH_BUTTON);
207 // CheckBox for groups generation
208 MakeGroupsCheck = new QCheckBox(tr("SMESH_MAKE_GROUPS"), GroupArguments);
209 MakeGroupsCheck->setChecked(false);
211 // Name of a mesh to create
212 LineEditNewMesh = new QLineEdit(GroupArguments);
215 myPreviewCheckBox = new QCheckBox(tr("PREVIEW"), GroupArguments);
218 GroupArgumentsLayout->addWidget(TextLabelElements, 0, 0);
219 GroupArgumentsLayout->addWidget(SelectElementsButton, 0, 1);
220 GroupArgumentsLayout->addWidget(LineEditElements, 0, 2, 1, 5);
221 GroupArgumentsLayout->addWidget(myFilterBtn, 0, 7);
222 GroupArgumentsLayout->addWidget(CheckBoxMesh, 1, 0, 1, 8);
223 GroupArgumentsLayout->addWidget(TextLabel1, 2, 0);
224 GroupArgumentsLayout->addWidget(SelectButton1, 2, 1);
225 GroupArgumentsLayout->addWidget(TextLabel1_1, 2, 2);
226 GroupArgumentsLayout->addWidget(SpinBox1_1, 2, 3);
227 GroupArgumentsLayout->addWidget(TextLabel1_2, 2, 4);
228 GroupArgumentsLayout->addWidget(SpinBox1_2, 2, 5);
229 GroupArgumentsLayout->addWidget(TextLabel1_3, 2, 6);
230 GroupArgumentsLayout->addWidget(SpinBox1_3, 2, 7);
231 GroupArgumentsLayout->addWidget(TextLabel2, 3, 0);
232 GroupArgumentsLayout->addWidget(SelectButton2, 3, 1);
233 GroupArgumentsLayout->addWidget(TextLabel2_1, 3, 2);
234 GroupArgumentsLayout->addWidget(SpinBox2_1, 3, 3);
235 GroupArgumentsLayout->addWidget(TextLabel2_2, 3, 4);
236 GroupArgumentsLayout->addWidget(SpinBox2_2, 3, 5);
237 GroupArgumentsLayout->addWidget(TextLabel2_3, 3, 6);
238 GroupArgumentsLayout->addWidget(SpinBox2_3, 3, 7);
239 GroupArgumentsLayout->addWidget(ActionBox, 4, 0, 3, 4);
240 GroupArgumentsLayout->addWidget(MakeGroupsCheck, 5, 5, 1, 4);
241 GroupArgumentsLayout->addWidget(LineEditNewMesh, 6, 5, 1, 4);
242 GroupArgumentsLayout->addWidget(myPreviewCheckBox, 7, 0);
244 /***************************************************************/
245 GroupButtons = new QGroupBox(this);
246 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
247 GroupButtonsLayout->setSpacing(SPACING);
248 GroupButtonsLayout->setMargin(MARGIN);
250 buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
251 buttonOk->setAutoDefault(true);
252 buttonOk->setDefault(true);
253 buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
254 buttonApply->setAutoDefault(true);
255 buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
256 buttonCancel->setAutoDefault(true);
257 buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
258 buttonHelp->setAutoDefault(true);
260 GroupButtonsLayout->addWidget(buttonOk);
261 GroupButtonsLayout->addSpacing(10);
262 GroupButtonsLayout->addWidget(buttonApply);
263 GroupButtonsLayout->addSpacing(10);
264 GroupButtonsLayout->addStretch();
265 GroupButtonsLayout->addWidget(buttonCancel);
266 GroupButtonsLayout->addWidget(buttonHelp);
268 /***************************************************************/
269 SMESHGUI_TranslationDlgLayout->addWidget(ConstructorsBox);
270 SMESHGUI_TranslationDlgLayout->addWidget(GroupArguments);
271 SMESHGUI_TranslationDlgLayout->addWidget(GroupButtons);
273 /* Initialisations */
274 SpinBox1_1->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
275 SpinBox1_2->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
276 SpinBox1_3->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
277 SpinBox2_1->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
278 SpinBox2_2->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
279 SpinBox2_3->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
281 RadioButton1->setChecked(true);
283 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
285 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
287 // Costruction of the logical filter
288 SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter (SMESH::MESHorSUBMESH);
289 SMESH_TypeFilter* aSmeshGroupFilter = new SMESH_TypeFilter (SMESH::GROUP);
291 QList<SUIT_SelectionFilter*> aListOfFilters;
292 if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
293 if (aSmeshGroupFilter) aListOfFilters.append(aSmeshGroupFilter);
295 myMeshOrSubMeshOrGroupFilter =
296 new SMESH_LogicalFilter(aListOfFilters, SMESH_LogicalFilter::LO_OR);
298 myHelpFileName = "translation.html";
302 /* signals and slots connections */
303 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
304 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));
305 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
306 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
307 connect(GroupConstructors, SIGNAL(buttonClicked(int)), SLOT(ConstructorsClicked(int)));
309 connect(SelectElementsButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
310 connect(SelectButton1, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
311 connect(SelectButton2, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
313 connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
314 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
315 /* to close dialog if study change */
316 connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), this, SLOT(reject()));
317 connect(mySMESHGUI, SIGNAL (SignalActivatedViewManager()), this, SLOT(onOpenView()));
318 connect(mySMESHGUI, SIGNAL (SignalCloseView()), this, SLOT(onCloseView()));
320 connect(LineEditElements, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
321 connect(CheckBoxMesh, SIGNAL(toggled(bool)), SLOT(onSelectMesh(bool)));
322 connect(ActionGroup, SIGNAL(buttonClicked(int)), SLOT(onActionClicked(int)));
324 connect(SpinBox1_1, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
325 connect(SpinBox1_2, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
326 connect(SpinBox1_3, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
328 connect(SpinBox2_1, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
329 connect(SpinBox2_2, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
330 connect(SpinBox2_3, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
333 //To Connect preview check box
334 connectPreviewControl();
336 ConstructorsClicked(0);
337 SelectionIntoArgument();
338 onActionClicked(MOVE_ELEMS_BUTTON);
341 //=================================================================================
342 // function : ~SMESHGUI_TranslationDlg()
343 // purpose : Destroys the object and frees any allocated resources
344 //=================================================================================
345 SMESHGUI_TranslationDlg::~SMESHGUI_TranslationDlg()
348 myFilterDlg->setParent( 0 );
354 //=================================================================================
357 //=================================================================================
358 void SMESHGUI_TranslationDlg::Init (bool ResetControls)
362 myObjectsNames.clear();
365 myEditCurrentArgument = LineEditElements;
366 LineEditElements->setFocus();
370 buttonOk->setEnabled(false);
371 buttonApply->setEnabled(false);
373 if ( !ResetControls && !isApplyAndClose() && // make highlight move upon [Apply] (IPAL20729)
374 myActor && !myActor->getIO().IsNull() &&
375 ActionGroup->button( MOVE_ELEMS_BUTTON )->isChecked() &&
376 !CheckBoxMesh->isChecked() ) // move selected elements
378 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
380 aViewWindow->highlight( myActor->getIO(), false, false );
381 aViewWindow->highlight( myActor->getIO(), true, true );
387 SpinBox1_1->SetValue(0.0);
388 SpinBox1_2->SetValue(0.0);
389 SpinBox1_3->SetValue(0.0);
390 SpinBox2_1->SetValue(0.0);
391 SpinBox2_2->SetValue(0.0);
392 SpinBox2_3->SetValue(0.0);
394 ActionGroup->button( MOVE_ELEMS_BUTTON )->setChecked(true);
395 CheckBoxMesh->setChecked(false);
396 myPreviewCheckBox->setChecked(false);
397 onDisplaySimulation(false);
399 onSelectMesh(CheckBoxMesh->isChecked());
402 //=================================================================================
403 // function : ConstructorsClicked()
404 // purpose : Radio button management
405 //=================================================================================
406 void SMESHGUI_TranslationDlg::ConstructorsClicked (int constructorId)
408 disconnect(mySelectionMgr, 0, this, 0);
410 switch (constructorId) {
413 TextLabel1->setText(tr("SMESH_POINT_1"));
414 TextLabel1_1->setText(tr("SMESH_X"));
415 TextLabel1_2->setText(tr("SMESH_Y"));
416 TextLabel1_3->setText(tr("SMESH_Z"));
418 SelectButton1->show();
420 SelectButton2->show();
421 TextLabel2_1->show();
423 TextLabel2_2->show();
425 TextLabel2_3->show();
431 TextLabel1->setText(tr("SMESH_VECTOR"));
432 TextLabel1_1->setText(tr("SMESH_DX"));
433 TextLabel1_2->setText(tr("SMESH_DY"));
434 TextLabel1_3->setText(tr("SMESH_DZ"));
436 SelectButton1->hide();
438 SelectButton2->hide();
439 TextLabel2_1->hide();
441 TextLabel2_2->hide();
443 TextLabel2_3->hide();
449 if (myEditCurrentArgument != (QWidget*)LineEditElements) {
450 SMESH::SetPointRepresentation(false);
451 if (!CheckBoxMesh->isChecked())
452 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
453 aViewWindow->SetSelectionMode( CellSelection );
456 myEditCurrentArgument = (QWidget*)LineEditElements;
457 LineEditElements->setFocus();
459 if (CheckBoxMesh->isChecked())
462 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
464 onDisplaySimulation(true);
465 myEditCurrentArgument->hide();
466 myEditCurrentArgument->show();
467 QApplication::instance()->processEvents();
472 //=================================================================================
473 // function : ClickOnApply()
475 //=================================================================================
476 bool SMESHGUI_TranslationDlg::ClickOnApply()
478 if (SMESHGUI::isStudyLocked())
484 if (myNbOkElements) {
485 QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
487 SMESH::smIdType_array_var anElementsId = new SMESH::smIdType_array;
489 anElementsId->length(aListElementsId.count());
490 for (int i = 0; i < aListElementsId.count(); i++)
491 anElementsId[i] = aListElementsId[i].toInt();
493 SMESH::DirStruct aVector;
494 QStringList aParameters;
495 if (GetConstructorId() == 0) {
496 aVector.PS.x = SpinBox2_1->GetValue() - SpinBox1_1->GetValue();
497 aVector.PS.y = SpinBox2_2->GetValue() - SpinBox1_2->GetValue();
498 aVector.PS.z = SpinBox2_3->GetValue() - SpinBox1_3->GetValue();
499 // not supported so far
500 // aParameters << QString("%1 - %2").arg( SpinBox2_1->text() ).arg( SpinBox1_1->text() );
501 // aParameters << QString("%1 - %2").arg( SpinBox2_2->text() ).arg( SpinBox1_2->text() );
502 // aParameters << QString("%1 - %2").arg( SpinBox2_3->text() ).arg( SpinBox1_3->text() );
503 } else if (GetConstructorId() == 1) {
504 aVector.PS.x = SpinBox1_1->GetValue();
505 aVector.PS.y = SpinBox1_2->GetValue();
506 aVector.PS.z = SpinBox1_3->GetValue();
507 aParameters << SpinBox1_1->text();
508 aParameters << SpinBox1_2->text();
509 aParameters << SpinBox1_3->text();
512 int actionButton = ActionGroup->checkedId();
513 bool makeGroups = ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() );
514 QStringList anEntryList;
516 SUIT_OverrideCursor aWaitCursor;
518 switch ( actionButton ) {
519 case MOVE_ELEMS_BUTTON:
520 if(CheckBoxMesh->isChecked())
521 for ( int i = 0; i < myObjects.count(); i++ ) {
522 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[i]->GetMeshEditor();
523 myMeshes[i]->SetParameters(aParameters.join( ":" ).toUtf8().constData());
524 aMeshEditor->TranslateObject(myObjects[i], aVector, false);
527 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[0]->GetMeshEditor();
528 myMeshes[0]->SetParameters(aParameters.join( ":" ).toUtf8().constData());
529 aMeshEditor->Translate(anElementsId, aVector, false);
532 case COPY_ELEMS_BUTTON:
534 SMESH::ListOfGroups_var groups;
535 if(CheckBoxMesh->isChecked()) {
536 for ( int i = 0; i < myObjects.count(); i++ ) {
537 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[i]->GetMeshEditor();
538 myMeshes[i]->SetParameters(aParameters.join( ":" ).toUtf8().constData());
539 groups = aMeshEditor->TranslateObjectMakeGroups(myObjects[i],aVector);
543 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[0]->GetMeshEditor();
544 myMeshes[0]->SetParameters(aParameters.join( ":" ).toUtf8().constData());
545 groups = aMeshEditor->TranslateMakeGroups(anElementsId, aVector);
549 if(CheckBoxMesh->isChecked()) {
550 for ( int i = 0; i < myObjects.count(); i++ ) {
551 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[i]->GetMeshEditor();
552 myMeshes[i]->SetParameters(aParameters.join( ":" ).toUtf8().constData());
553 aMeshEditor->TranslateObject(myObjects[i], aVector, true);
557 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[0]->GetMeshEditor();
558 myMeshes[0]->SetParameters(aParameters.join( ":" ).toUtf8().constData());
559 aMeshEditor->Translate(anElementsId, aVector, true);
563 case MAKE_MESH_BUTTON: {
564 SMESH::SMESH_Mesh_var mesh;
565 if (CheckBoxMesh->isChecked()) {
566 for ( int i = 0; i < myObjects.count(); i++ ) {
567 QString aName = SMESH::UniqueMeshName( LineEditNewMesh->text().replace( "*", myObjectsNames[i] ) );
568 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[i]->GetMeshEditor();
569 myMeshes[i]->SetParameters(aParameters.join( ":" ).toUtf8().constData());
570 mesh = aMeshEditor->TranslateObjectMakeMesh(myObjects[i], aVector, makeGroups,
571 aName.toUtf8().data());
572 if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( mesh ) )
573 anEntryList.append( aSObject->GetID().c_str() );
577 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[0]->GetMeshEditor();
578 myMeshes[0]->SetParameters(aParameters.join( ":" ).toUtf8().constData());
579 mesh = aMeshEditor->TranslateMakeMesh(anElementsId, aVector, makeGroups,
580 LineEditNewMesh->text().toUtf8().data());
581 if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( mesh ) )
582 anEntryList.append( aSObject->GetID().c_str() );
590 for ( int i = 0; i < myObjects.count(); i++ ) {
591 SMESH_Actor* actor = SMESH::FindActorByObject( myObjects[i] );
592 if ( actor ) SMESH::Update( actor->getIO(), true );
595 if ( ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() ) ||
596 actionButton == MAKE_MESH_BUTTON ) {
597 mySMESHGUI->updateObjBrowser(true); // new groups may appear
598 if( LightApp_Application* anApp =
599 dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
600 anApp->browseObjects( anEntryList, isApplyAndClose() );
604 ConstructorsClicked(GetConstructorId());
606 SMESHGUI::Modified();
612 //=================================================================================
613 // function : ClickOnOk()
615 //=================================================================================
616 void SMESHGUI_TranslationDlg::ClickOnOk()
618 setIsApplyAndClose( true );
623 //=================================================================================
624 // function : reject()
626 //=================================================================================
627 void SMESHGUI_TranslationDlg::reject()
629 disconnect(mySelectionMgr, 0, this, 0);
630 mySelectionMgr->clearFilters();
631 //mySelectionMgr->clearSelected();
632 if (SMESH::GetCurrentVtkView()) {
633 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
634 SMESH::SetPointRepresentation(false);
636 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
637 aViewWindow->SetSelectionMode( ActorSelection );
638 mySMESHGUI->ResetState();
642 //=================================================================================
643 // function : onOpenView()
645 //=================================================================================
646 void SMESHGUI_TranslationDlg::onOpenView()
649 SMESH::SetPointRepresentation(false);
652 mySelector = SMESH::GetViewWindow( mySMESHGUI )->GetSelector();
653 ActivateThisDialog();
657 //=================================================================================
658 // function : onCloseView()
660 //=================================================================================
661 void SMESHGUI_TranslationDlg::onCloseView()
663 DeactivateActiveDialog();
667 //=================================================================================
668 // function : ClickOnHelp()
670 //=================================================================================
671 void SMESHGUI_TranslationDlg::ClickOnHelp()
673 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
675 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
679 platform = "winapplication";
681 platform = "application";
683 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
684 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
685 arg(app->resourceMgr()->stringValue("ExternalBrowser",
687 arg(myHelpFileName));
691 //=======================================================================
692 // function : onTextChange()
694 //=======================================================================
695 void SMESHGUI_TranslationDlg::onTextChange (const QString& theNewText)
697 QLineEdit* send = (QLineEdit*)sender();
700 BusyLocker lock( myBusy );
702 if (send == LineEditElements)
705 buttonOk->setEnabled(false);
706 buttonApply->setEnabled(false);
708 // highlight entered elements
709 SMDS_Mesh* aMesh = 0;
711 aMesh = myActor->GetObject()->GetMesh();
714 Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
716 SVTK_TVtkIDsMap newIndices;
718 QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
720 if (send == LineEditElements) {
721 for (int i = 0; i < aListId.count(); i++) {
722 const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
724 newIndices.Add(e->GetID());
728 mySelector->AddOrRemoveIndex( anIO, newIndices, false );
729 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
730 aViewWindow->highlight( anIO, true, true );
732 myElementsId = theNewText;
735 if (myNbOkElements) {
736 buttonOk->setEnabled(true);
737 buttonApply->setEnabled(true);
741 //=================================================================================
742 // function : SelectionIntoArgument()
743 // purpose : Called when selection as changed or other case
744 //=================================================================================
745 void SMESHGUI_TranslationDlg::SelectionIntoArgument()
748 if (myFilterDlg && myFilterDlg->isVisible()) return; // filter dlg active
750 BusyLocker lock( myBusy );
753 QString aString = "";
754 onDisplaySimulation(false);
756 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
757 LineEditElements->setText(aString);
759 buttonOk->setEnabled(false);
760 buttonApply->setEnabled(false);
763 if (!GroupButtons->isEnabled()) // inactive
768 mySelectionMgr->selectedObjects(aList);
770 int nbSel = aList.Extent();
775 if (myEditCurrentArgument == (QWidget*)LineEditElements)
779 myObjectsNames.clear();
782 for ( SALOME_ListIteratorOfListIO it( aList ); it.More(); it.Next() )
784 Handle(SALOME_InteractiveObject) IO = it.Value();
785 SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO( IO );
786 if ( aMesh->_is_nil() )
789 SMESH_Actor* anActor = SMESH::FindActorByObject( aMesh );
791 anActor = SMESH::FindActorByEntry( IO->getEntry() );
793 // if ( !anActor && !CheckBoxMesh->isChecked() ) -- elems can be selected by Filter
796 SMESH::SMESH_IDSource_var idSrc = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>( IO );
797 if ( _PTR(SObject) obj = SMESH::FindSObject( idSrc ))
799 std::string name = obj->GetName();
803 myObjectsNames << name.c_str();
811 // MakeGroups is available if there are groups and "Copy"
813 for ( int i = 0; i < myMeshes.count(); i++ )
814 aNbGroups += myMeshes[i]->NbGroups();
816 if ( aNbGroups == 0 ) {
817 MakeGroupsCheck->setChecked(false);
818 MakeGroupsCheck->setEnabled(false);
820 else if ( ActionGroup->checkedId() != MOVE_ELEMS_BUTTON ) {
821 MakeGroupsCheck->setEnabled(true);
824 if (CheckBoxMesh->isChecked()) {
825 if (myMeshes.isEmpty())
827 SMESH::GetNameOfSelectedIObjects( mySelectionMgr, aString );
830 aNbUnits = SMESH::GetNameOfSelectedElements(mySelector, aList.First(), aString);
831 myElementsId = aString;
836 myNbOkElements = true;
838 else // set coordinates by a picked node
840 Handle(SALOME_InteractiveObject) IO = aList.First();
842 SMESH_Actor* anActor = SMESH::FindActorByEntry( IO->getEntry() );
846 aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, IO, aString);
850 SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh();
854 const SMDS_MeshNode * n = aMesh->FindNode(aString.toInt());
862 if (myEditCurrentArgument == (QWidget*)SpinBox1_1) {
863 SpinBox1_1->SetValue(x);
864 SpinBox1_2->SetValue(y);
865 SpinBox1_3->SetValue(z);
866 } else if (myEditCurrentArgument == (QWidget*)SpinBox2_1) {
867 SpinBox2_1->SetValue(x);
868 SpinBox2_2->SetValue(y);
869 SpinBox2_3->SetValue(z);
873 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
874 LineEditElements->setText(aString);
875 LineEditElements->repaint();
876 LineEditElements->setEnabled(false); // to fully update lineedit IPAL 19809
877 LineEditElements->setEnabled(true);
882 if (myNbOkElements) {
883 buttonOk->setEnabled(true);
884 buttonApply->setEnabled(true);
886 onDisplaySimulation(true);
889 //=================================================================================
890 // function : SetEditCurrentArgument()
892 //=================================================================================
893 void SMESHGUI_TranslationDlg::SetEditCurrentArgument()
895 QPushButton* send = (QPushButton*)sender();
897 disconnect(mySelectionMgr, 0, this, 0);
898 mySelectionMgr->clearSelected();
899 mySelectionMgr->clearFilters();
901 if (send == SelectElementsButton) {
902 myEditCurrentArgument = (QWidget*)LineEditElements;
903 SMESH::SetPointRepresentation(false);
904 if (CheckBoxMesh->isChecked()) {
905 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
906 aViewWindow->SetSelectionMode( ActorSelection );
907 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
910 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
911 aViewWindow->SetSelectionMode( CellSelection );
913 } else if (send == SelectButton1) {
914 myEditCurrentArgument = (QWidget*)SpinBox1_1;
915 SMESH::SetPointRepresentation(true);
917 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
918 aViewWindow->SetSelectionMode( NodeSelection );
919 } else if (send == SelectButton2) {
920 myEditCurrentArgument = (QWidget*)SpinBox2_1;
921 SMESH::SetPointRepresentation(true);
923 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
924 aViewWindow->SetSelectionMode( NodeSelection );
927 myEditCurrentArgument->setFocus();
928 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
929 SelectionIntoArgument();
932 //=================================================================================
933 // function : DeactivateActiveDialog()
935 //=================================================================================
936 void SMESHGUI_TranslationDlg::DeactivateActiveDialog()
938 if (ConstructorsBox->isEnabled()) {
939 ConstructorsBox->setEnabled(false);
940 GroupArguments->setEnabled(false);
941 GroupButtons->setEnabled(false);
942 mySMESHGUI->ResetState();
943 mySMESHGUI->SetActiveDialogBox(0);
947 //=================================================================================
948 // function : ActivateThisDialog()
950 //=================================================================================
951 void SMESHGUI_TranslationDlg::ActivateThisDialog()
953 /* Emit a signal to deactivate the active dialog */
954 mySMESHGUI->EmitSignalDeactivateDialog();
955 ConstructorsBox->setEnabled(true);
956 GroupArguments->setEnabled(true);
957 GroupButtons->setEnabled(true);
959 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
961 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
962 aViewWindow->SetSelectionMode( CellSelection );
964 SelectionIntoArgument();
967 //=================================================================================
968 // function : enterEvent()
970 //=================================================================================
971 void SMESHGUI_TranslationDlg::enterEvent (QEvent*)
973 if (!ConstructorsBox->isEnabled()) {
974 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI );
975 if ( aViewWindow && !mySelector) {
976 mySelector = aViewWindow->GetSelector();
978 ActivateThisDialog();
982 //=======================================================================
983 //function : onSelectMesh
985 //=======================================================================
986 void SMESHGUI_TranslationDlg::onSelectMesh (bool toSelectMesh)
989 TextLabelElements->setText(tr("SMESH_NAME"));
991 TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
992 myFilterBtn->setEnabled(!toSelectMesh);
994 if (myEditCurrentArgument != LineEditElements) {
995 LineEditElements->clear();
999 mySelectionMgr->clearFilters();
1000 SMESH::SetPointRepresentation(false);
1003 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1004 aViewWindow->SetSelectionMode( ActorSelection );
1005 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
1006 LineEditElements->setReadOnly(true);
1007 LineEditElements->setValidator(0);
1009 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1010 aViewWindow->SetSelectionMode( CellSelection );
1011 LineEditElements->setReadOnly(false);
1012 LineEditElements->setValidator(myIdValidator);
1016 SelectionIntoArgument();
1019 //=======================================================================
1020 //function : onActionClicked
1021 //purpose : slot called when an action type changed
1022 //=======================================================================
1024 void SMESHGUI_TranslationDlg::onActionClicked(int button)
1027 for ( int i = 0; i < myMeshes.count(); i++ )
1028 aNbGroups += myMeshes[i]->NbGroups();
1031 case MOVE_ELEMS_BUTTON:
1032 MakeGroupsCheck->setEnabled(false);
1033 LineEditNewMesh->setEnabled(false);
1035 case COPY_ELEMS_BUTTON:
1036 LineEditNewMesh->setEnabled(false);
1037 MakeGroupsCheck->setText( tr("SMESH_MAKE_GROUPS"));
1038 MakeGroupsCheck->setEnabled( myMeshes.isEmpty() || aNbGroups > 0 );
1040 case MAKE_MESH_BUTTON:
1041 LineEditNewMesh->setEnabled(true);
1042 MakeGroupsCheck->setText( tr("SMESH_COPY_GROUPS"));
1043 MakeGroupsCheck->setEnabled( myMeshes.isEmpty() || aNbGroups > 0 );
1047 toDisplaySimulation();
1050 //=======================================================================
1051 //function : setNewMeshName
1052 //purpose : update contents of LineEditNewMesh
1053 //=======================================================================
1055 void SMESHGUI_TranslationDlg::setNewMeshName()
1057 LineEditNewMesh->setText("");
1058 if ( LineEditNewMesh->isEnabled() && !myMeshes.isEmpty() ) {
1060 if ( CheckBoxMesh->isChecked() ) {
1061 name = myObjects.count() > 1 ? "*" : LineEditElements->text();
1064 _PTR(SObject) meshSO = SMESH::FindSObject( myMeshes[0] );
1065 name = meshSO->GetName().c_str();
1067 if ( !name.isEmpty() )
1068 LineEditNewMesh->setText( SMESH::UniqueMeshName( name, "translated"));
1072 //=================================================================================
1073 // function : GetConstructorId()
1075 //=================================================================================
1076 int SMESHGUI_TranslationDlg::GetConstructorId()
1078 return GroupConstructors->checkedId();
1081 //=================================================================================
1082 // function : keyPressEvent()
1084 //=================================================================================
1085 void SMESHGUI_TranslationDlg::keyPressEvent( QKeyEvent* e )
1087 QDialog::keyPressEvent( e );
1088 if ( e->isAccepted() )
1091 if ( e->key() == Qt::Key_F1 ) {
1097 //=================================================================================
1098 // function : setFilters()
1099 // purpose : SLOT. Called when "Filter" button pressed.
1100 //=================================================================================
1101 void SMESHGUI_TranslationDlg::setFilters()
1103 if ( myMeshes.isEmpty() ) {
1104 SUIT_MessageBox::critical(this, tr("SMESH_ERROR"), tr("NO_MESH_SELECTED"));
1107 if ( !myFilterDlg ) {
1108 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, SMESH::ALL );
1109 connect(myFilterDlg, SIGNAL(Accepted()), SLOT(onFilterAccepted()));
1113 if ( myMeshes[0]->NbEdges() ) types << SMESH::EDGE;
1114 if ( myMeshes[0]->NbFaces() ) types << SMESH::FACE;
1115 if ( myMeshes[0]->NbVolumes() ) types << SMESH::VOLUME;
1116 if ( myMeshes[0]->NbBalls() ) types << SMESH::BALL;
1117 if ( myMeshes[0]->Nb0DElements()) types << SMESH::ELEM0D;
1118 if ( types.count() > 1 ) types << SMESH::ALL;
1120 myFilterDlg->Init( types );
1121 myFilterDlg->SetSelection();
1122 myFilterDlg->SetMesh( myMeshes[0] );
1123 myFilterDlg->SetSourceWg( LineEditElements );
1125 myFilterDlg->show();
1128 //=======================================================================
1129 // name : onFilterAccepted()
1130 // Purpose : SLOT. Called when Filter dlg closed with OK button.
1131 // Activate [Apply] if no Actor is available
1132 //=======================================================================
1133 void SMESHGUI_TranslationDlg::onFilterAccepted()
1135 if ( myMeshes.length() > 0 && !buttonOk->isEnabled() )
1137 myElementsId = LineEditElements->text();
1138 QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
1139 myNbOkElements = aListElementsId.count();
1140 buttonOk->setEnabled( myNbOkElements );
1141 buttonApply->setEnabled( myNbOkElements );
1145 //=================================================================================
1146 // function : isValid
1148 //=================================================================================
1149 bool SMESHGUI_TranslationDlg::isValid()
1154 ok = SpinBox1_1->isValid( msg, true ) && ok;
1155 ok = SpinBox1_2->isValid( msg, true ) && ok;
1156 ok = SpinBox1_3->isValid( msg, true ) && ok;
1157 if (GetConstructorId() == 0) {
1158 ok = SpinBox2_1->isValid( msg, true ) && ok;
1159 ok = SpinBox2_2->isValid( msg, true ) && ok;
1160 ok = SpinBox2_3->isValid( msg, true ) && ok;
1164 QString str( tr( "SMESH_INCORRECT_INPUT" ) );
1165 if ( !msg.isEmpty() )
1167 SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
1173 //=================================================================================
1174 // function : onDisplaySimulation
1175 // purpose : Show/Hide preview
1176 //=================================================================================
1177 void SMESHGUI_TranslationDlg::onDisplaySimulation( bool toDisplayPreview )
1179 if (myPreviewCheckBox->isChecked() && toDisplayPreview)
1181 if (isValid() && myNbOkElements)
1183 QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
1185 SMESH::smIdType_array_var anElementsId = new SMESH::smIdType_array;
1187 anElementsId->length(aListElementsId.count());
1188 for (int i = 0; i < aListElementsId.count(); i++)
1189 anElementsId[i] = aListElementsId[i].toInt();
1191 SMESH::DirStruct aVector;
1192 if (GetConstructorId() == 0) {
1193 aVector.PS.x = SpinBox2_1->GetValue() - SpinBox1_1->GetValue();
1194 aVector.PS.y = SpinBox2_2->GetValue() - SpinBox1_2->GetValue();
1195 aVector.PS.z = SpinBox2_3->GetValue() - SpinBox1_3->GetValue();
1196 } else if (GetConstructorId() == 1) {
1197 aVector.PS.x = SpinBox1_1->GetValue();
1198 aVector.PS.y = SpinBox1_2->GetValue();
1199 aVector.PS.z = SpinBox1_3->GetValue();
1203 bool copy = ( ActionGroup->checkedId() == COPY_ELEMS_BUTTON ||
1204 ActionGroup->checkedId() == MAKE_MESH_BUTTON );
1205 SUIT_OverrideCursor aWaitCursor;
1206 QList<SMESH::MeshPreviewStruct_var> aMeshPreviewStruct;
1207 if(CheckBoxMesh->isChecked())
1208 for ( int i = 0; i < myObjects.count(); i++ ) {
1209 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[i]->GetMeshEditPreviewer();
1210 aMeshEditor->TranslateObject(myObjects[i], aVector, copy);
1211 aMeshPreviewStruct << aMeshEditor->GetPreviewData();
1214 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[0]->GetMeshEditPreviewer();
1215 aMeshEditor->Translate(anElementsId, aVector, copy);
1216 aMeshPreviewStruct << aMeshEditor->GetPreviewData();
1218 setSimulationPreview( aMeshPreviewStruct );