1 // Copyright (C) 2007-2010 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.
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
23 // SMESH SMESHGUI : GUI for SMESH component
24 // File : SMESHGUI_TranslationDlg.cxx
25 // Author : Michael ZORIN, Open CASCADE S.A.S.
28 #include "SMESHGUI_TranslationDlg.h"
31 #include "SMESHGUI_SpinBox.h"
32 #include "SMESHGUI_Utils.h"
33 #include "SMESHGUI_VTKUtils.h"
34 #include "SMESHGUI_MeshUtils.h"
35 #include "SMESHGUI_IdValidator.h"
36 #include "SMESHGUI_FilterDlg.h"
38 #include <SMESH_Actor.h>
39 #include <SMESH_TypeFilter.hxx>
40 #include <SMESH_LogicalFilter.hxx>
41 #include <SMDS_Mesh.hxx>
43 // SALOME GUI includes
44 #include <SUIT_Desktop.h>
45 #include <SUIT_ResourceMgr.h>
46 #include <SUIT_Session.h>
47 #include <SUIT_MessageBox.h>
48 #include <SUIT_OverrideCursor.h>
50 #include <LightApp_Application.h>
51 #include <LightApp_SelectionMgr.h>
53 #include <SVTK_ViewModel.h>
54 #include <SVTK_ViewWindow.h>
55 #include <SALOME_ListIO.hxx>
57 // SALOME KERNEL includes
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
105 //=================================================================================
106 // class : SMESHGUI_TranslationDlg()
108 //=================================================================================
109 SMESHGUI_TranslationDlg::SMESHGUI_TranslationDlg( SMESHGUI* theModule )
110 : QDialog( SMESH::GetDesktop( theModule ) ),
111 mySMESHGUI( theModule ),
112 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
114 mySelectedObject(SMESH::SMESH_IDSource::_nil())
116 QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SMESH_TRANSLATION_POINTS")));
117 QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SMESH_TRANSLATION_VECTOR")));
118 QPixmap image2 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
121 setAttribute(Qt::WA_DeleteOnClose, true);
122 setWindowTitle(tr("SMESH_TRANSLATION"));
123 setSizeGripEnabled(true);
125 QVBoxLayout* SMESHGUI_TranslationDlgLayout = new QVBoxLayout(this);
126 SMESHGUI_TranslationDlgLayout->setSpacing(SPACING);
127 SMESHGUI_TranslationDlgLayout->setMargin(MARGIN);
129 /***************************************************************/
130 ConstructorsBox = new QGroupBox(tr("SMESH_TRANSLATION"), this);
131 GroupConstructors = new QButtonGroup(this);
132 QHBoxLayout* ConstructorsBoxLayout = new QHBoxLayout(ConstructorsBox);
133 ConstructorsBoxLayout->setSpacing(SPACING);
134 ConstructorsBoxLayout->setMargin(MARGIN);
136 RadioButton1= new QRadioButton(ConstructorsBox);
137 RadioButton1->setIcon(image0);
138 RadioButton2= new QRadioButton(ConstructorsBox);
139 RadioButton2->setIcon(image1);
141 ConstructorsBoxLayout->addWidget(RadioButton1);
142 ConstructorsBoxLayout->addWidget(RadioButton2);
143 GroupConstructors->addButton(RadioButton1, 0);
144 GroupConstructors->addButton(RadioButton2, 1);
146 /***************************************************************/
147 GroupArguments = new QGroupBox(tr("SMESH_ARGUMENTS"), this);
148 QGridLayout* GroupArgumentsLayout = new QGridLayout(GroupArguments);
149 GroupArgumentsLayout->setSpacing(SPACING);
150 GroupArgumentsLayout->setMargin(MARGIN);
152 myIdValidator = new SMESHGUI_IdValidator(this);
154 // Controls for elements selection
155 TextLabelElements = new QLabel(tr("SMESH_ID_ELEMENTS"), GroupArguments);
156 SelectElementsButton = new QPushButton(GroupArguments);
157 SelectElementsButton->setIcon(image2);
158 LineEditElements = new QLineEdit(GroupArguments);
159 LineEditElements->setValidator(myIdValidator);
160 LineEditElements->setMaxLength(-1);
161 myFilterBtn = new QPushButton( tr( "SMESH_BUT_FILTER" ), GroupArguments );
162 connect(myFilterBtn, SIGNAL(clicked()), this, SLOT(setFilters()));
164 // Control for the whole mesh selection
165 CheckBoxMesh = new QCheckBox(tr("SMESH_SELECT_WHOLE_MESH"), GroupArguments);
167 // Controls for vector and points selection
168 TextLabel1 = new QLabel(GroupArguments);
169 SelectButton1 = new QPushButton(GroupArguments);
170 SelectButton1->setIcon(image2);
172 TextLabel1_1 = new QLabel(GroupArguments);
173 SpinBox1_1 = new SMESHGUI_SpinBox(GroupArguments);
174 TextLabel1_2 = new QLabel(GroupArguments);
175 SpinBox1_2 = new SMESHGUI_SpinBox(GroupArguments);
176 TextLabel1_3 = new QLabel(GroupArguments);
177 SpinBox1_3 = new SMESHGUI_SpinBox(GroupArguments);
179 TextLabel2 = new QLabel(tr("SMESH_POINT_2"), GroupArguments);
180 SelectButton2 = new QPushButton(GroupArguments);
181 SelectButton2->setIcon(image2);
183 TextLabel2_1 = new QLabel(tr("SMESH_X"), GroupArguments);
184 SpinBox2_1 = new SMESHGUI_SpinBox(GroupArguments);
185 TextLabel2_2 = new QLabel(tr("SMESH_Y"), GroupArguments);
186 SpinBox2_2 = new SMESHGUI_SpinBox(GroupArguments);
187 TextLabel2_3 = new QLabel(tr("SMESH_Z"), GroupArguments);
188 SpinBox2_3 = new SMESHGUI_SpinBox(GroupArguments);
190 // switch of action type
191 ActionBox = new QGroupBox(GroupArguments);
192 ActionGroup = new QButtonGroup(GroupArguments);
193 QVBoxLayout* ActionBoxLayout = new QVBoxLayout(ActionBox);
194 ActionBoxLayout->addSpacing(SPACING);
195 ActionBoxLayout->setMargin(MARGIN);
197 QRadioButton* aMoveElements = new QRadioButton(tr("SMESH_MOVE_ELEMENTS"), ActionBox);
198 QRadioButton* aCopyElements = new QRadioButton(tr("SMESH_COPY_ELEMENTS"), ActionBox);
199 QRadioButton* aCreateMesh = new QRadioButton(tr("SMESH_CREATE_MESH"), ActionBox);
201 ActionBoxLayout->addWidget(aMoveElements);
202 ActionBoxLayout->addWidget(aCopyElements);
203 ActionBoxLayout->addWidget(aCreateMesh);
204 ActionGroup->addButton(aMoveElements, MOVE_ELEMS_BUTTON);
205 ActionGroup->addButton(aCopyElements, COPY_ELEMS_BUTTON);
206 ActionGroup->addButton(aCreateMesh, MAKE_MESH_BUTTON);
208 // CheckBox for groups generation
209 MakeGroupsCheck = new QCheckBox(tr("SMESH_MAKE_GROUPS"), GroupArguments);
210 MakeGroupsCheck->setChecked(false);
212 // Name of a mesh to create
213 LineEditNewMesh = new QLineEdit(GroupArguments);
216 GroupArgumentsLayout->addWidget(TextLabelElements, 0, 0);
217 GroupArgumentsLayout->addWidget(SelectElementsButton, 0, 1);
218 GroupArgumentsLayout->addWidget(LineEditElements, 0, 2, 1, 5);
219 GroupArgumentsLayout->addWidget(myFilterBtn, 0, 7);
220 GroupArgumentsLayout->addWidget(CheckBoxMesh, 1, 0, 1, 8);
221 GroupArgumentsLayout->addWidget(TextLabel1, 2, 0);
222 GroupArgumentsLayout->addWidget(SelectButton1, 2, 1);
223 GroupArgumentsLayout->addWidget(TextLabel1_1, 2, 2);
224 GroupArgumentsLayout->addWidget(SpinBox1_1, 2, 3);
225 GroupArgumentsLayout->addWidget(TextLabel1_2, 2, 4);
226 GroupArgumentsLayout->addWidget(SpinBox1_2, 2, 5);
227 GroupArgumentsLayout->addWidget(TextLabel1_3, 2, 6);
228 GroupArgumentsLayout->addWidget(SpinBox1_3, 2, 7);
229 GroupArgumentsLayout->addWidget(TextLabel2, 3, 0);
230 GroupArgumentsLayout->addWidget(SelectButton2, 3, 1);
231 GroupArgumentsLayout->addWidget(TextLabel2_1, 3, 2);
232 GroupArgumentsLayout->addWidget(SpinBox2_1, 3, 3);
233 GroupArgumentsLayout->addWidget(TextLabel2_2, 3, 4);
234 GroupArgumentsLayout->addWidget(SpinBox2_2, 3, 5);
235 GroupArgumentsLayout->addWidget(TextLabel2_3, 3, 6);
236 GroupArgumentsLayout->addWidget(SpinBox2_3, 3, 7);
237 GroupArgumentsLayout->addWidget(ActionBox, 4, 0, 3, 4);
238 GroupArgumentsLayout->addWidget(MakeGroupsCheck, 5, 5, 1, 4);
239 GroupArgumentsLayout->addWidget(LineEditNewMesh, 6, 5, 1, 4);
241 /***************************************************************/
242 GroupButtons = new QGroupBox(this);
243 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
244 GroupButtonsLayout->setSpacing(SPACING);
245 GroupButtonsLayout->setMargin(MARGIN);
247 buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
248 buttonOk->setAutoDefault(true);
249 buttonOk->setDefault(true);
250 buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
251 buttonApply->setAutoDefault(true);
252 buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
253 buttonCancel->setAutoDefault(true);
254 buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
255 buttonHelp->setAutoDefault(true);
257 GroupButtonsLayout->addWidget(buttonOk);
258 GroupButtonsLayout->addSpacing(10);
259 GroupButtonsLayout->addWidget(buttonApply);
260 GroupButtonsLayout->addSpacing(10);
261 GroupButtonsLayout->addStretch();
262 GroupButtonsLayout->addWidget(buttonCancel);
263 GroupButtonsLayout->addWidget(buttonHelp);
265 /***************************************************************/
266 SMESHGUI_TranslationDlgLayout->addWidget(ConstructorsBox);
267 SMESHGUI_TranslationDlgLayout->addWidget(GroupArguments);
268 SMESHGUI_TranslationDlgLayout->addWidget(GroupButtons);
270 /* Initialisations */
271 SpinBox1_1->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
272 SpinBox1_2->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
273 SpinBox1_3->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
274 SpinBox2_1->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
275 SpinBox2_2->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
276 SpinBox2_3->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
278 RadioButton1->setChecked(true);
280 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
282 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
284 // Costruction of the logical filter
285 SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter (MESHorSUBMESH);
286 SMESH_TypeFilter* aSmeshGroupFilter = new SMESH_TypeFilter (GROUP);
288 QList<SUIT_SelectionFilter*> aListOfFilters;
289 if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
290 if (aSmeshGroupFilter) aListOfFilters.append(aSmeshGroupFilter);
292 myMeshOrSubMeshOrGroupFilter =
293 new SMESH_LogicalFilter(aListOfFilters, SMESH_LogicalFilter::LO_OR);
295 myHelpFileName = "translation_page.html";
299 /* signals and slots connections */
300 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
301 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
302 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
303 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
304 connect(GroupConstructors, SIGNAL(buttonClicked(int)), SLOT(ConstructorsClicked(int)));
306 connect(SelectElementsButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
307 connect(SelectButton1, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
308 connect(SelectButton2, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
310 connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
311 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
312 /* to close dialog if study change */
313 connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
314 connect(LineEditElements, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
315 connect(CheckBoxMesh, SIGNAL(toggled(bool)), SLOT(onSelectMesh(bool)));
316 connect(ActionGroup, SIGNAL(buttonClicked(int)), SLOT(onActionClicked(int)));
318 ConstructorsClicked(0);
319 SelectionIntoArgument();
320 onActionClicked(MOVE_ELEMS_BUTTON);
323 //=================================================================================
324 // function : ~SMESHGUI_TranslationDlg()
325 // purpose : Destroys the object and frees any allocated resources
326 //=================================================================================
327 SMESHGUI_TranslationDlg::~SMESHGUI_TranslationDlg()
330 myFilterDlg->setParent( 0 );
336 //=================================================================================
339 //=================================================================================
340 void SMESHGUI_TranslationDlg::Init (bool ResetControls)
344 myEditCurrentArgument = 0;
345 LineEditElements->clear();
349 buttonOk->setEnabled(false);
350 buttonApply->setEnabled(false);
353 myMesh = SMESH::SMESH_Mesh::_nil();
356 SpinBox1_1->SetValue(0.0);
357 SpinBox1_2->SetValue(0.0);
358 SpinBox1_3->SetValue(0.0);
359 SpinBox2_1->SetValue(0.0);
360 SpinBox2_2->SetValue(0.0);
361 SpinBox2_3->SetValue(0.0);
363 ActionGroup->button( MOVE_ELEMS_BUTTON )->setChecked(true);
364 CheckBoxMesh->setChecked(false);
365 // MakeGroupsCheck->setChecked(false);
366 // MakeGroupsCheck->setEnabled(false);
371 //=================================================================================
372 // function : ConstructorsClicked()
373 // purpose : Radio button management
374 //=================================================================================
375 void SMESHGUI_TranslationDlg::ConstructorsClicked (int constructorId)
377 disconnect(mySelectionMgr, 0, this, 0);
379 switch (constructorId) {
382 TextLabel1->setText(tr("SMESH_POINT_1"));
383 TextLabel1_1->setText(tr("SMESH_X"));
384 TextLabel1_2->setText(tr("SMESH_Y"));
385 TextLabel1_3->setText(tr("SMESH_Z"));
387 SelectButton1->show();
389 SelectButton2->show();
390 TextLabel2_1->show();
392 TextLabel2_2->show();
394 TextLabel2_3->show();
400 TextLabel1->setText(tr("SMESH_VECTOR"));
401 TextLabel1_1->setText(tr("SMESH_DX"));
402 TextLabel1_2->setText(tr("SMESH_DY"));
403 TextLabel1_3->setText(tr("SMESH_DZ"));
405 SelectButton1->hide();
407 SelectButton2->hide();
408 TextLabel2_1->hide();
410 TextLabel2_2->hide();
412 TextLabel2_3->hide();
418 if (myEditCurrentArgument != (QWidget*)LineEditElements) {
419 SMESH::SetPointRepresentation(false);
420 if (!CheckBoxMesh->isChecked())
421 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
422 aViewWindow->SetSelectionMode( CellSelection );
425 myEditCurrentArgument = (QWidget*)LineEditElements;
426 LineEditElements->setFocus();
428 if (CheckBoxMesh->isChecked())
431 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
433 QApplication::instance()->processEvents();
438 //=================================================================================
439 // function : ClickOnApply()
441 //=================================================================================
442 bool SMESHGUI_TranslationDlg::ClickOnApply()
444 if (mySMESHGUI->isActiveStudyLocked())
450 if (myNbOkElements) {
451 QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
453 SMESH::long_array_var anElementsId = new SMESH::long_array;
455 anElementsId->length(aListElementsId.count());
456 for (int i = 0; i < aListElementsId.count(); i++)
457 anElementsId[i] = aListElementsId[i].toInt();
459 SMESH::DirStruct aVector;
460 if (GetConstructorId() == 0) {
461 aVector.PS.x = SpinBox2_1->GetValue() - SpinBox1_1->GetValue();
462 aVector.PS.y = SpinBox2_2->GetValue() - SpinBox1_2->GetValue();
463 aVector.PS.z = SpinBox2_3->GetValue() - SpinBox1_3->GetValue();
464 } else if (GetConstructorId() == 1) {
465 aVector.PS.x = SpinBox1_1->GetValue();
466 aVector.PS.y = SpinBox1_2->GetValue();
467 aVector.PS.z = SpinBox1_3->GetValue();
470 QStringList aParameters;
471 aParameters << SpinBox1_1->text();
472 if (GetConstructorId() == 0)
473 aParameters << SpinBox2_1->text();
474 aParameters << SpinBox1_2->text();
475 if (GetConstructorId() == 0)
476 aParameters << SpinBox2_2->text();
477 aParameters << SpinBox1_3->text();
478 if (GetConstructorId() == 0)
479 aParameters << SpinBox2_3->text();
481 int actionButton = ActionGroup->checkedId();
482 bool makeGroups = ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() );
484 SUIT_OverrideCursor aWaitCursor;
485 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
486 switch ( actionButton ) {
487 case MOVE_ELEMS_BUTTON:
488 if(CheckBoxMesh->isChecked())
489 aMeshEditor->TranslateObject(mySelectedObject, aVector, false);
491 aMeshEditor->Translate(anElementsId, aVector, false);
492 if( !myMesh->_is_nil())
493 myMesh->SetParameters( aParameters.join(":").toLatin1().constData() );
495 case COPY_ELEMS_BUTTON:
497 SMESH::ListOfGroups_var groups;
498 if(CheckBoxMesh->isChecked())
499 groups = aMeshEditor->TranslateObjectMakeGroups(mySelectedObject,aVector);
501 groups = aMeshEditor->TranslateMakeGroups(anElementsId, aVector);
504 if(CheckBoxMesh->isChecked())
505 aMeshEditor->TranslateObject(mySelectedObject, aVector, true);
507 aMeshEditor->Translate(anElementsId, aVector, true);
509 if( !myMesh->_is_nil())
510 myMesh->SetParameters( aParameters.join(":").toLatin1().constData() );
512 case MAKE_MESH_BUTTON:
513 SMESH::SMESH_Mesh_var mesh;
514 if(CheckBoxMesh->isChecked())
515 mesh = aMeshEditor->TranslateObjectMakeMesh(mySelectedObject, aVector, makeGroups,
516 LineEditNewMesh->text().toLatin1().data());
518 mesh = aMeshEditor->TranslateMakeMesh(anElementsId, aVector, makeGroups,
519 LineEditNewMesh->text().toLatin1().data());
520 if( !mesh->_is_nil())
521 mesh->SetParameters( aParameters.join(":").toLatin1().constData() );
527 if ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() ||
528 actionButton == MAKE_MESH_BUTTON )
529 mySMESHGUI->updateObjBrowser(true); // new groups may appear
531 ConstructorsClicked(GetConstructorId());
532 mySelectedObject = SMESH::SMESH_IDSource::_nil();
533 SelectionIntoArgument();
535 SMESHGUI::Modified();
541 //=================================================================================
542 // function : ClickOnOk()
544 //=================================================================================
545 void SMESHGUI_TranslationDlg::ClickOnOk()
551 //=================================================================================
552 // function : ClickOnCancel()
554 //=================================================================================
555 void SMESHGUI_TranslationDlg::ClickOnCancel()
557 disconnect(mySelectionMgr, 0, this, 0);
558 mySelectionMgr->clearFilters();
559 //mySelectionMgr->clearSelected();
560 if (SMESH::GetCurrentVtkView()) {
561 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
562 SMESH::SetPointRepresentation(false);
564 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
565 aViewWindow->SetSelectionMode( ActorSelection );
566 mySMESHGUI->ResetState();
570 //=================================================================================
571 // function : ClickOnHelp()
573 //=================================================================================
574 void SMESHGUI_TranslationDlg::ClickOnHelp()
576 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
578 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
582 platform = "winapplication";
584 platform = "application";
586 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
587 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
588 arg(app->resourceMgr()->stringValue("ExternalBrowser",
590 arg(myHelpFileName));
594 //=======================================================================
595 // function : onTextChange()
597 //=======================================================================
598 void SMESHGUI_TranslationDlg::onTextChange (const QString& theNewText)
600 QLineEdit* send = (QLineEdit*)sender();
603 BusyLocker lock( myBusy );
605 if (send == LineEditElements)
608 buttonOk->setEnabled(false);
609 buttonApply->setEnabled(false);
611 // hilight entered elements
612 SMDS_Mesh* aMesh = 0;
614 aMesh = myActor->GetObject()->GetMesh();
617 Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
619 TColStd_MapOfInteger newIndices;
621 QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
623 if (send == LineEditElements) {
624 for (int i = 0; i < aListId.count(); i++) {
625 const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
627 newIndices.Add(e->GetID());
632 mySelector->AddOrRemoveIndex( anIO, newIndices, false );
633 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
634 aViewWindow->highlight( anIO, true, true );
636 myElementsId = theNewText;
639 if (myNbOkElements) {
640 buttonOk->setEnabled(true);
641 buttonApply->setEnabled(true);
645 //=================================================================================
646 // function : SelectionIntoArgument()
647 // purpose : Called when selection as changed or other case
648 //=================================================================================
649 void SMESHGUI_TranslationDlg::SelectionIntoArgument()
652 BusyLocker lock( myBusy );
655 QString aString = "";
657 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
658 LineEditElements->setText(aString);
660 buttonOk->setEnabled(false);
661 buttonApply->setEnabled(false);
664 if (!GroupButtons->isEnabled()) // inactive
669 mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
671 int nbSel = aList.Extent();
675 Handle(SALOME_InteractiveObject) IO = aList.First();
676 myMesh = SMESH::GetMeshByIO(IO);
677 if (myMesh->_is_nil())
680 myActor = SMESH::FindActorByObject(myMesh);
682 myActor = SMESH::FindActorByEntry(IO->getEntry());
684 if (!myActor && !CheckBoxMesh->isChecked())
689 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
692 // MakeGroups is available if there are groups and "Copy"
693 if ( myMesh->NbGroups() == 0 ) {
694 MakeGroupsCheck->setChecked(false);
695 MakeGroupsCheck->setEnabled(false);
697 else if ( ActionGroup->checkedId() != MOVE_ELEMS_BUTTON ) {
698 MakeGroupsCheck->setEnabled(true);
701 if (CheckBoxMesh->isChecked()) {
702 SMESH::GetNameOfSelectedIObjects( mySelectionMgr, aString );
704 if (!SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO)->_is_nil()) { //MESH, SUBMESH, OR GROUP
705 mySelectedObject = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO);
711 SMDS_Mesh* aSMDSMesh = myActor->GetObject()->GetMesh();
715 for (int i = aSMDSMesh->MinElementID(); i <= aSMDSMesh->MaxElementID(); i++) {
716 const SMDS_MeshElement * e = aSMDSMesh->FindElement(i);
718 myElementsId += QString(" %1").arg(i);
722 } else if (!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil()) { //SUBMESH
724 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO);
726 // get IDs from submesh
727 SMESH::long_array_var anElementsIds = new SMESH::long_array;
728 anElementsIds = aSubMesh->GetElementsId();
729 for (int i = 0; i < anElementsIds->length(); i++) {
730 myElementsId += QString(" %1").arg(anElementsIds[i]);
732 aNbUnits = anElementsIds->length();
735 SMESH::SMESH_GroupBase_var aGroup =
736 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
737 if (aGroup->_is_nil())
740 // get IDs from smesh group
741 SMESH::long_array_var anElementsIds = new SMESH::long_array;
742 anElementsIds = aGroup->GetListOfID();
743 for (int i = 0; i < anElementsIds->length(); i++) {
744 myElementsId += QString(" %1").arg(anElementsIds[i]);
746 aNbUnits = anElementsIds->length();
750 aNbUnits = SMESH::GetNameOfSelectedElements(mySelector, IO, aString);
751 myElementsId = aString;
756 myNbOkElements = true;
758 aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, IO, aString);
762 SMDS_Mesh* aMesh = myActor->GetObject()->GetMesh();
766 const SMDS_MeshNode * n = aMesh->FindNode(aString.toInt());
774 if (myEditCurrentArgument == (QWidget*)SpinBox1_1) {
775 SpinBox1_1->SetValue(x);
776 SpinBox1_2->SetValue(y);
777 SpinBox1_3->SetValue(z);
778 } else if (myEditCurrentArgument == (QWidget*)SpinBox2_1) {
779 SpinBox2_1->SetValue(x);
780 SpinBox2_2->SetValue(y);
781 SpinBox2_3->SetValue(z);
785 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
786 LineEditElements->setText(aString);
787 LineEditElements->repaint();
788 LineEditElements->setEnabled(false); // to fully update lineedit IPAL 19809
789 LineEditElements->setEnabled(true);
794 if (myNbOkElements) {
795 buttonOk->setEnabled(true);
796 buttonApply->setEnabled(true);
800 //=================================================================================
801 // function : SetEditCurrentArgument()
803 //=================================================================================
804 void SMESHGUI_TranslationDlg::SetEditCurrentArgument()
806 QPushButton* send = (QPushButton*)sender();
808 disconnect(mySelectionMgr, 0, this, 0);
809 mySelectionMgr->clearSelected();
810 mySelectionMgr->clearFilters();
812 if (send == SelectElementsButton) {
813 myEditCurrentArgument = (QWidget*)LineEditElements;
814 SMESH::SetPointRepresentation(false);
815 if (CheckBoxMesh->isChecked()) {
816 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
817 aViewWindow->SetSelectionMode( ActorSelection );
818 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
821 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
822 aViewWindow->SetSelectionMode( CellSelection );
824 } else if (send == SelectButton1) {
825 myEditCurrentArgument = (QWidget*)SpinBox1_1;
826 SMESH::SetPointRepresentation(true);
828 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
829 aViewWindow->SetSelectionMode( NodeSelection );
830 } else if (send == SelectButton2) {
831 myEditCurrentArgument = (QWidget*)SpinBox2_1;
832 SMESH::SetPointRepresentation(true);
834 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
835 aViewWindow->SetSelectionMode( NodeSelection );
838 myEditCurrentArgument->setFocus();
839 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
840 SelectionIntoArgument();
843 //=================================================================================
844 // function : DeactivateActiveDialog()
846 //=================================================================================
847 void SMESHGUI_TranslationDlg::DeactivateActiveDialog()
849 if (ConstructorsBox->isEnabled()) {
850 ConstructorsBox->setEnabled(false);
851 GroupArguments->setEnabled(false);
852 GroupButtons->setEnabled(false);
853 mySMESHGUI->ResetState();
854 mySMESHGUI->SetActiveDialogBox(0);
858 //=================================================================================
859 // function : ActivateThisDialog()
861 //=================================================================================
862 void SMESHGUI_TranslationDlg::ActivateThisDialog()
864 /* Emit a signal to deactivate the active dialog */
865 mySMESHGUI->EmitSignalDeactivateDialog();
866 ConstructorsBox->setEnabled(true);
867 GroupArguments->setEnabled(true);
868 GroupButtons->setEnabled(true);
870 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
872 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
873 aViewWindow->SetSelectionMode( CellSelection );
875 SelectionIntoArgument();
878 //=================================================================================
879 // function : enterEvent()
881 //=================================================================================
882 void SMESHGUI_TranslationDlg::enterEvent (QEvent*)
884 if (!ConstructorsBox->isEnabled())
885 ActivateThisDialog();
888 //=================================================================================
889 // function : closeEvent()
891 //=================================================================================
892 void SMESHGUI_TranslationDlg::closeEvent (QCloseEvent*)
894 /* same than click on cancel button */
898 //=======================================================================
899 //function : hideEvent
900 //purpose : caused by ESC key
901 //=======================================================================
902 void SMESHGUI_TranslationDlg::hideEvent (QHideEvent*)
908 //=======================================================================
909 //function : onSelectMesh
911 //=======================================================================
912 void SMESHGUI_TranslationDlg::onSelectMesh (bool toSelectMesh)
915 TextLabelElements->setText(tr("SMESH_NAME"));
917 TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
918 myFilterBtn->setEnabled(!toSelectMesh);
920 if (myEditCurrentArgument != LineEditElements) {
921 LineEditElements->clear();
925 mySelectionMgr->clearFilters();
926 SMESH::SetPointRepresentation(false);
929 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
930 aViewWindow->SetSelectionMode( ActorSelection );
931 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
932 LineEditElements->setReadOnly(true);
933 LineEditElements->setValidator(0);
935 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
936 aViewWindow->SetSelectionMode( CellSelection );
937 LineEditElements->setReadOnly(false);
938 LineEditElements->setValidator(myIdValidator);
939 onTextChange(LineEditElements->text());
942 SelectionIntoArgument();
945 //=======================================================================
946 //function : onActionClicked
947 //purpose : slot called when an action type changed
948 //=======================================================================
950 void SMESHGUI_TranslationDlg::onActionClicked(int button)
953 case MOVE_ELEMS_BUTTON:
954 MakeGroupsCheck->setEnabled(false);
955 LineEditNewMesh->setEnabled(false);
957 case COPY_ELEMS_BUTTON:
958 LineEditNewMesh->setEnabled(false);
959 MakeGroupsCheck->setText( tr("SMESH_MAKE_GROUPS"));
960 if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
961 MakeGroupsCheck->setEnabled(true);
963 MakeGroupsCheck->setEnabled(false);
965 case MAKE_MESH_BUTTON:
966 LineEditNewMesh->setEnabled(true);
967 MakeGroupsCheck->setText( tr("SMESH_COPY_GROUPS"));
968 if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
969 MakeGroupsCheck->setEnabled(true);
971 MakeGroupsCheck->setEnabled(false);
977 //=======================================================================
978 //function : setNewMeshName
979 //purpose : update contents of LineEditNewMesh
980 //=======================================================================
982 void SMESHGUI_TranslationDlg::setNewMeshName()
984 LineEditNewMesh->setText("");
985 if ( LineEditNewMesh->isEnabled() && !myMesh->_is_nil() ) {
987 if ( CheckBoxMesh->isChecked() ) {
988 name = LineEditElements->text();
991 _PTR(SObject) meshSO = SMESH::FindSObject( myMesh );
992 name = meshSO->GetName().c_str();
994 if ( !name.isEmpty() )
995 LineEditNewMesh->setText( SMESH::UniqueMeshName( name, "translated"));
999 //=================================================================================
1000 // function : GetConstructorId()
1002 //=================================================================================
1003 int SMESHGUI_TranslationDlg::GetConstructorId()
1005 return GroupConstructors->checkedId();
1008 //=================================================================================
1009 // function : keyPressEvent()
1011 //=================================================================================
1012 void SMESHGUI_TranslationDlg::keyPressEvent( QKeyEvent* e )
1014 QDialog::keyPressEvent( e );
1015 if ( e->isAccepted() )
1018 if ( e->key() == Qt::Key_F1 ) {
1024 //=================================================================================
1025 // function : setFilters()
1026 // purpose : SLOT. Called when "Filter" button pressed.
1027 //=================================================================================
1028 void SMESHGUI_TranslationDlg::setFilters()
1030 if(myMesh->_is_nil()) {
1031 SUIT_MessageBox::critical(this,
1033 tr("NO_MESH_SELECTED"));
1037 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, SMESH::ALL );
1039 myFilterDlg->SetSelection();
1040 myFilterDlg->SetMesh( myMesh );
1041 myFilterDlg->SetSourceWg( LineEditElements );
1043 myFilterDlg->show();
1046 //=================================================================================
1047 // function : isValid
1049 //=================================================================================
1050 bool SMESHGUI_TranslationDlg::isValid()
1055 ok = SpinBox1_1->isValid( msg, true ) && ok;
1056 ok = SpinBox1_2->isValid( msg, true ) && ok;
1057 ok = SpinBox1_3->isValid( msg, true ) && ok;
1058 if (GetConstructorId() == 0) {
1059 ok = SpinBox2_1->isValid( msg, true ) && ok;
1060 ok = SpinBox2_2->isValid( msg, true ) && ok;
1061 ok = SpinBox2_3->isValid( msg, true ) && ok;
1065 QString str( tr( "SMESH_INCORRECT_INPUT" ) );
1066 if ( !msg.isEmpty() )
1068 SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );