1 // Copyright (C) 2007-2015 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_page.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 (mySMESHGUI->isActiveStudyLocked())
484 if (myNbOkElements) {
485 QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
487 SMESH::long_array_var anElementsId = new SMESH::long_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( ":" ).toLatin1().constData());
524 aMeshEditor->TranslateObject(myObjects[i], aVector, false);
527 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[0]->GetMeshEditor();
528 myMeshes[0]->SetParameters(aParameters.join( ":" ).toLatin1().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( ":" ).toLatin1().constData());
539 groups = aMeshEditor->TranslateObjectMakeGroups(myObjects[i],aVector);
543 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[0]->GetMeshEditor();
544 myMeshes[0]->SetParameters(aParameters.join( ":" ).toLatin1().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( ":" ).toLatin1().constData());
553 aMeshEditor->TranslateObject(myObjects[i], aVector, true);
557 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[0]->GetMeshEditor();
558 myMeshes[0]->SetParameters(aParameters.join( ":" ).toLatin1().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( ":" ).toLatin1().constData());
570 mesh = aMeshEditor->TranslateObjectMakeMesh(myObjects[i], aVector, makeGroups,
571 aName.toLatin1().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( ":" ).toLatin1().constData());
579 mesh = aMeshEditor->TranslateMakeMesh(anElementsId, aVector, makeGroups,
580 LineEditNewMesh->text().toLatin1().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 // hilight entered elements
709 SMDS_Mesh* aMesh = 0;
711 aMesh = myActor->GetObject()->GetMesh();
714 Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
716 TColStd_MapOfInteger 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) {
778 myObjectsNames.clear();
781 for ( SALOME_ListIteratorOfListIO it( aList ); it.More(); it.Next() ) {
782 Handle(SALOME_InteractiveObject) IO = it.Value();
783 SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO( IO );
784 if ( aMesh->_is_nil() )
787 SMESH_Actor* anActor = SMESH::FindActorByObject( aMesh );
789 anActor = SMESH::FindActorByEntry( IO->getEntry() );
791 if ( !anActor && !CheckBoxMesh->isChecked() )
794 if ( !SMESH::IObjectToInterface<SMESH::SMESH_IDSource>( IO )->_is_nil() ) {
795 if ( _PTR(Study) aStudy = SMESH::GetActiveStudyDocument() ) {
796 _PTR(SObject) obj = aStudy->FindObjectID( qPrintable( QString( IO->getEntry() ) ) );
797 _PTR(GenericAttribute) anAttr;
798 if ( obj && obj->FindAttribute( anAttr, "AttributeName" ) ) {
799 _PTR(AttributeName) aNameAttr( anAttr );
800 myObjects << SMESH::IObjectToInterface<SMESH::SMESH_IDSource>( IO );
801 myObjectsNames << aNameAttr->Value().c_str();
810 // MakeGroups is available if there are groups and "Copy"
812 for ( int i = 0; i < myMeshes.count(); i++ )
813 aNbGroups += myMeshes[i]->NbGroups();
815 if ( aNbGroups == 0 ) {
816 MakeGroupsCheck->setChecked(false);
817 MakeGroupsCheck->setEnabled(false);
819 else if ( ActionGroup->checkedId() != MOVE_ELEMS_BUTTON ) {
820 MakeGroupsCheck->setEnabled(true);
823 if (CheckBoxMesh->isChecked()) {
824 SMESH::GetNameOfSelectedIObjects( mySelectionMgr, aString );
825 if (myMeshes.isEmpty())
828 aNbUnits = SMESH::GetNameOfSelectedElements(mySelector, aList.First(), aString);
829 myElementsId = aString;
834 myNbOkElements = true;
836 Handle(SALOME_InteractiveObject) IO = aList.First();
837 if ((SMESH::GetMeshByIO(IO))->_is_nil())
840 SMESH_Actor* anActor = SMESH::FindActorByObject(SMESH::GetMeshByIO(IO));
842 anActor = SMESH::FindActorByEntry(IO->getEntry());
843 if (!anActor && !CheckBoxMesh->isChecked())
845 aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, IO, aString);
849 SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh();
853 const SMDS_MeshNode * n = aMesh->FindNode(aString.toInt());
861 if (myEditCurrentArgument == (QWidget*)SpinBox1_1) {
862 SpinBox1_1->SetValue(x);
863 SpinBox1_2->SetValue(y);
864 SpinBox1_3->SetValue(z);
865 } else if (myEditCurrentArgument == (QWidget*)SpinBox2_1) {
866 SpinBox2_1->SetValue(x);
867 SpinBox2_2->SetValue(y);
868 SpinBox2_3->SetValue(z);
872 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
873 LineEditElements->setText(aString);
874 LineEditElements->repaint();
875 LineEditElements->setEnabled(false); // to fully update lineedit IPAL 19809
876 LineEditElements->setEnabled(true);
881 if (myNbOkElements) {
882 buttonOk->setEnabled(true);
883 buttonApply->setEnabled(true);
885 onDisplaySimulation(true);
888 //=================================================================================
889 // function : SetEditCurrentArgument()
891 //=================================================================================
892 void SMESHGUI_TranslationDlg::SetEditCurrentArgument()
894 QPushButton* send = (QPushButton*)sender();
896 disconnect(mySelectionMgr, 0, this, 0);
897 mySelectionMgr->clearSelected();
898 mySelectionMgr->clearFilters();
900 if (send == SelectElementsButton) {
901 myEditCurrentArgument = (QWidget*)LineEditElements;
902 SMESH::SetPointRepresentation(false);
903 if (CheckBoxMesh->isChecked()) {
904 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
905 aViewWindow->SetSelectionMode( ActorSelection );
906 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
909 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
910 aViewWindow->SetSelectionMode( CellSelection );
912 } else if (send == SelectButton1) {
913 myEditCurrentArgument = (QWidget*)SpinBox1_1;
914 SMESH::SetPointRepresentation(true);
916 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
917 aViewWindow->SetSelectionMode( NodeSelection );
918 } else if (send == SelectButton2) {
919 myEditCurrentArgument = (QWidget*)SpinBox2_1;
920 SMESH::SetPointRepresentation(true);
922 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
923 aViewWindow->SetSelectionMode( NodeSelection );
926 myEditCurrentArgument->setFocus();
927 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
928 SelectionIntoArgument();
931 //=================================================================================
932 // function : DeactivateActiveDialog()
934 //=================================================================================
935 void SMESHGUI_TranslationDlg::DeactivateActiveDialog()
937 if (ConstructorsBox->isEnabled()) {
938 ConstructorsBox->setEnabled(false);
939 GroupArguments->setEnabled(false);
940 GroupButtons->setEnabled(false);
941 mySMESHGUI->ResetState();
942 mySMESHGUI->SetActiveDialogBox(0);
946 //=================================================================================
947 // function : ActivateThisDialog()
949 //=================================================================================
950 void SMESHGUI_TranslationDlg::ActivateThisDialog()
952 /* Emit a signal to deactivate the active dialog */
953 mySMESHGUI->EmitSignalDeactivateDialog();
954 ConstructorsBox->setEnabled(true);
955 GroupArguments->setEnabled(true);
956 GroupButtons->setEnabled(true);
958 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
960 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
961 aViewWindow->SetSelectionMode( CellSelection );
963 SelectionIntoArgument();
966 //=================================================================================
967 // function : enterEvent()
969 //=================================================================================
970 void SMESHGUI_TranslationDlg::enterEvent (QEvent*)
972 if (!ConstructorsBox->isEnabled()) {
973 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI );
974 if ( aViewWindow && !mySelector) {
975 mySelector = aViewWindow->GetSelector();
977 ActivateThisDialog();
981 //=======================================================================
982 //function : onSelectMesh
984 //=======================================================================
985 void SMESHGUI_TranslationDlg::onSelectMesh (bool toSelectMesh)
988 TextLabelElements->setText(tr("SMESH_NAME"));
990 TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
991 myFilterBtn->setEnabled(!toSelectMesh);
993 if (myEditCurrentArgument != LineEditElements) {
994 LineEditElements->clear();
998 mySelectionMgr->clearFilters();
999 SMESH::SetPointRepresentation(false);
1002 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1003 aViewWindow->SetSelectionMode( ActorSelection );
1004 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
1005 LineEditElements->setReadOnly(true);
1006 LineEditElements->setValidator(0);
1008 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1009 aViewWindow->SetSelectionMode( CellSelection );
1010 LineEditElements->setReadOnly(false);
1011 LineEditElements->setValidator(myIdValidator);
1015 SelectionIntoArgument();
1018 //=======================================================================
1019 //function : onActionClicked
1020 //purpose : slot called when an action type changed
1021 //=======================================================================
1023 void SMESHGUI_TranslationDlg::onActionClicked(int button)
1026 for ( int i = 0; i < myMeshes.count(); i++ )
1027 aNbGroups += myMeshes[i]->NbGroups();
1030 case MOVE_ELEMS_BUTTON:
1031 MakeGroupsCheck->setEnabled(false);
1032 LineEditNewMesh->setEnabled(false);
1034 case COPY_ELEMS_BUTTON:
1035 LineEditNewMesh->setEnabled(false);
1036 MakeGroupsCheck->setText( tr("SMESH_MAKE_GROUPS"));
1037 MakeGroupsCheck->setEnabled( myMeshes.isEmpty() || aNbGroups > 0 );
1039 case MAKE_MESH_BUTTON:
1040 LineEditNewMesh->setEnabled(true);
1041 MakeGroupsCheck->setText( tr("SMESH_COPY_GROUPS"));
1042 MakeGroupsCheck->setEnabled( myMeshes.isEmpty() || aNbGroups > 0 );
1046 toDisplaySimulation();
1049 //=======================================================================
1050 //function : setNewMeshName
1051 //purpose : update contents of LineEditNewMesh
1052 //=======================================================================
1054 void SMESHGUI_TranslationDlg::setNewMeshName()
1056 LineEditNewMesh->setText("");
1057 if ( LineEditNewMesh->isEnabled() && !myMeshes.isEmpty() ) {
1059 if ( CheckBoxMesh->isChecked() ) {
1060 name = myObjects.count() > 1 ? "*" : LineEditElements->text();
1063 _PTR(SObject) meshSO = SMESH::FindSObject( myMeshes[0] );
1064 name = meshSO->GetName().c_str();
1066 if ( !name.isEmpty() )
1067 LineEditNewMesh->setText( SMESH::UniqueMeshName( name, "translated"));
1071 //=================================================================================
1072 // function : GetConstructorId()
1074 //=================================================================================
1075 int SMESHGUI_TranslationDlg::GetConstructorId()
1077 return GroupConstructors->checkedId();
1080 //=================================================================================
1081 // function : keyPressEvent()
1083 //=================================================================================
1084 void SMESHGUI_TranslationDlg::keyPressEvent( QKeyEvent* e )
1086 QDialog::keyPressEvent( e );
1087 if ( e->isAccepted() )
1090 if ( e->key() == Qt::Key_F1 ) {
1096 //=================================================================================
1097 // function : setFilters()
1098 // purpose : SLOT. Called when "Filter" button pressed.
1099 //=================================================================================
1100 void SMESHGUI_TranslationDlg::setFilters()
1102 if(myMeshes.isEmpty()) {
1103 SUIT_MessageBox::critical(this,
1105 tr("NO_MESH_SELECTED"));
1109 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, SMESH::ALL );
1112 if ( myMeshes[0]->NbEdges() ) types << SMESH::EDGE;
1113 if ( myMeshes[0]->NbFaces() ) types << SMESH::FACE;
1114 if ( myMeshes[0]->NbVolumes() ) types << SMESH::VOLUME;
1115 if ( myMeshes[0]->NbBalls() ) types << SMESH::BALL;
1116 if ( myMeshes[0]->Nb0DElements()) types << SMESH::ELEM0D;
1117 if ( types.count() > 1 ) types << SMESH::ALL;
1119 myFilterDlg->Init( types );
1120 myFilterDlg->SetSelection();
1121 myFilterDlg->SetMesh( myMeshes[0] );
1122 myFilterDlg->SetSourceWg( LineEditElements );
1124 myFilterDlg->show();
1127 //=================================================================================
1128 // function : isValid
1130 //=================================================================================
1131 bool SMESHGUI_TranslationDlg::isValid()
1136 ok = SpinBox1_1->isValid( msg, true ) && ok;
1137 ok = SpinBox1_2->isValid( msg, true ) && ok;
1138 ok = SpinBox1_3->isValid( msg, true ) && ok;
1139 if (GetConstructorId() == 0) {
1140 ok = SpinBox2_1->isValid( msg, true ) && ok;
1141 ok = SpinBox2_2->isValid( msg, true ) && ok;
1142 ok = SpinBox2_3->isValid( msg, true ) && ok;
1146 QString str( tr( "SMESH_INCORRECT_INPUT" ) );
1147 if ( !msg.isEmpty() )
1149 SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
1155 //=================================================================================
1156 // function : onDisplaySimulation
1157 // purpose : Show/Hide preview
1158 //=================================================================================
1159 void SMESHGUI_TranslationDlg::onDisplaySimulation( bool toDisplayPreview )
1161 if (myPreviewCheckBox->isChecked() && toDisplayPreview)
1163 if (isValid() && myNbOkElements)
1165 QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
1167 SMESH::long_array_var anElementsId = new SMESH::long_array;
1169 anElementsId->length(aListElementsId.count());
1170 for (int i = 0; i < aListElementsId.count(); i++)
1171 anElementsId[i] = aListElementsId[i].toInt();
1173 SMESH::DirStruct aVector;
1174 if (GetConstructorId() == 0) {
1175 aVector.PS.x = SpinBox2_1->GetValue() - SpinBox1_1->GetValue();
1176 aVector.PS.y = SpinBox2_2->GetValue() - SpinBox1_2->GetValue();
1177 aVector.PS.z = SpinBox2_3->GetValue() - SpinBox1_3->GetValue();
1178 } else if (GetConstructorId() == 1) {
1179 aVector.PS.x = SpinBox1_1->GetValue();
1180 aVector.PS.y = SpinBox1_2->GetValue();
1181 aVector.PS.z = SpinBox1_3->GetValue();
1185 bool copy = ( ActionGroup->checkedId() == COPY_ELEMS_BUTTON ||
1186 ActionGroup->checkedId() == MAKE_MESH_BUTTON );
1187 SUIT_OverrideCursor aWaitCursor;
1188 QList<SMESH::MeshPreviewStruct_var> aMeshPreviewStruct;
1189 if(CheckBoxMesh->isChecked())
1190 for ( int i = 0; i < myObjects.count(); i++ ) {
1191 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[i]->GetMeshEditPreviewer();
1192 aMeshEditor->TranslateObject(myObjects[i], aVector, copy);
1193 aMeshPreviewStruct << aMeshEditor->GetPreviewData();
1196 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[0]->GetMeshEditPreviewer();
1197 aMeshEditor->Translate(anElementsId, aVector, copy);
1198 aMeshPreviewStruct << aMeshEditor->GetPreviewData();
1200 setSimulationPreview( aMeshPreviewStruct );