1 // Copyright (C) 2007-2008 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
22 // SMESH SMESHGUI : GUI for SMESH component
23 // File : SMESHGUI_TranslationDlg.cxx
24 // Author : Michael ZORIN, Open CASCADE S.A.S.
27 #include "SMESHGUI_TranslationDlg.h"
30 #include "SMESHGUI_SpinBox.h"
31 #include "SMESHGUI_Utils.h"
32 #include "SMESHGUI_VTKUtils.h"
33 #include "SMESHGUI_MeshUtils.h"
34 #include "SMESHGUI_IdValidator.h"
35 #include "SMESHGUI_FilterDlg.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_SObject.hxx>
60 #include <TColStd_MapOfInteger.hxx>
63 #include <QApplication>
64 #include <QButtonGroup>
68 #include <QPushButton>
69 #include <QRadioButton>
71 #include <QHBoxLayout>
72 #include <QVBoxLayout>
73 #include <QGridLayout>
78 #include <SALOMEconfig.h>
79 #include CORBA_SERVER_HEADER(SMESH_Group)
80 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
82 enum { MOVE_ELEMS_BUTTON = 0, COPY_ELEMS_BUTTON, MAKE_MESH_BUTTON }; //!< action type
86 \brief Simple 'busy state' flag locker.
93 //! Constructor. Sets passed boolean flag to \c true.
94 BusyLocker( bool& busy ) : myBusy( busy ) { myBusy = true; }
95 //! Destructor. Clear external boolean flag passed as parameter to the constructor to \c false.
96 ~BusyLocker() { myBusy = false; }
98 bool& myBusy; //! External 'busy state' boolean flag
104 //=================================================================================
105 // class : SMESHGUI_TranslationDlg()
107 //=================================================================================
108 SMESHGUI_TranslationDlg::SMESHGUI_TranslationDlg( SMESHGUI* theModule )
109 : QDialog( SMESH::GetDesktop( theModule ) ),
110 mySMESHGUI( theModule ),
111 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
114 QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SMESH_TRANSLATION_POINTS")));
115 QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SMESH_TRANSLATION_VECTOR")));
116 QPixmap image2 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
119 setAttribute(Qt::WA_DeleteOnClose, true);
120 setWindowTitle(tr("SMESH_TRANSLATION"));
121 setSizeGripEnabled(true);
123 QVBoxLayout* SMESHGUI_TranslationDlgLayout = new QVBoxLayout(this);
124 SMESHGUI_TranslationDlgLayout->setSpacing(SPACING);
125 SMESHGUI_TranslationDlgLayout->setMargin(MARGIN);
127 /***************************************************************/
128 ConstructorsBox = new QGroupBox(tr("SMESH_TRANSLATION"), this);
129 GroupConstructors = new QButtonGroup(this);
130 QHBoxLayout* ConstructorsBoxLayout = new QHBoxLayout(ConstructorsBox);
131 ConstructorsBoxLayout->setSpacing(SPACING);
132 ConstructorsBoxLayout->setMargin(MARGIN);
134 RadioButton1= new QRadioButton(ConstructorsBox);
135 RadioButton1->setIcon(image0);
136 RadioButton2= new QRadioButton(ConstructorsBox);
137 RadioButton2->setIcon(image1);
139 ConstructorsBoxLayout->addWidget(RadioButton1);
140 ConstructorsBoxLayout->addWidget(RadioButton2);
141 GroupConstructors->addButton(RadioButton1, 0);
142 GroupConstructors->addButton(RadioButton2, 1);
144 /***************************************************************/
145 GroupArguments = new QGroupBox(tr("SMESH_ARGUMENTS"), this);
146 QGridLayout* GroupArgumentsLayout = new QGridLayout(GroupArguments);
147 GroupArgumentsLayout->setSpacing(SPACING);
148 GroupArgumentsLayout->setMargin(MARGIN);
150 myIdValidator = new SMESHGUI_IdValidator(this);
152 // Controls for elements selection
153 TextLabelElements = new QLabel(tr("SMESH_ID_ELEMENTS"), GroupArguments);
154 SelectElementsButton = new QPushButton(GroupArguments);
155 SelectElementsButton->setIcon(image2);
156 LineEditElements = new QLineEdit(GroupArguments);
157 LineEditElements->setValidator(myIdValidator);
158 QPushButton* filterBtn = new QPushButton( tr( "SMESH_BUT_FILTER" ), GroupArguments );
159 connect(filterBtn, SIGNAL(clicked()), this, SLOT(setFilters()));
161 // Control for the whole mesh selection
162 CheckBoxMesh = new QCheckBox(tr("SMESH_SELECT_WHOLE_MESH"), GroupArguments);
164 // Controls for vector and points selection
165 TextLabel1 = new QLabel(GroupArguments);
166 SelectButton1 = new QPushButton(GroupArguments);
167 SelectButton1->setIcon(image2);
169 TextLabel1_1 = new QLabel(GroupArguments);
170 SpinBox1_1 = new SMESHGUI_SpinBox(GroupArguments);
171 TextLabel1_2 = new QLabel(GroupArguments);
172 SpinBox1_2 = new SMESHGUI_SpinBox(GroupArguments);
173 TextLabel1_3 = new QLabel(GroupArguments);
174 SpinBox1_3 = new SMESHGUI_SpinBox(GroupArguments);
176 TextLabel2 = new QLabel(tr("SMESH_POINT_2"), GroupArguments);
177 SelectButton2 = new QPushButton(GroupArguments);
178 SelectButton2->setIcon(image2);
180 TextLabel2_1 = new QLabel(tr("SMESH_X"), GroupArguments);
181 SpinBox2_1 = new SMESHGUI_SpinBox(GroupArguments);
182 TextLabel2_2 = new QLabel(tr("SMESH_Y"), GroupArguments);
183 SpinBox2_2 = new SMESHGUI_SpinBox(GroupArguments);
184 TextLabel2_3 = new QLabel(tr("SMESH_Z"), GroupArguments);
185 SpinBox2_3 = new SMESHGUI_SpinBox(GroupArguments);
187 // switch of action type
188 ActionBox = new QGroupBox(GroupArguments);
189 ActionGroup = new QButtonGroup(GroupArguments);
190 QVBoxLayout* ActionBoxLayout = new QVBoxLayout(ActionBox);
191 ActionBoxLayout->addSpacing(SPACING);
192 ActionBoxLayout->setMargin(MARGIN);
194 QRadioButton* aMoveElements = new QRadioButton(tr("SMESH_MOVE_ELEMENTS"), ActionBox);
195 QRadioButton* aCopyElements = new QRadioButton(tr("SMESH_COPY_ELEMENTS"), ActionBox);
196 QRadioButton* aCreateMesh = new QRadioButton(tr("SMESH_CREATE_MESH"), ActionBox);
198 ActionBoxLayout->addWidget(aMoveElements);
199 ActionBoxLayout->addWidget(aCopyElements);
200 ActionBoxLayout->addWidget(aCreateMesh);
201 ActionGroup->addButton(aMoveElements, MOVE_ELEMS_BUTTON);
202 ActionGroup->addButton(aCopyElements, COPY_ELEMS_BUTTON);
203 ActionGroup->addButton(aCreateMesh, MAKE_MESH_BUTTON);
205 // CheckBox for groups generation
206 MakeGroupsCheck = new QCheckBox(tr("SMESH_MAKE_GROUPS"), GroupArguments);
207 MakeGroupsCheck->setChecked(false);
209 // Name of a mesh to create
210 LineEditNewMesh = new QLineEdit(GroupArguments);
213 GroupArgumentsLayout->addWidget(TextLabelElements, 0, 0);
214 GroupArgumentsLayout->addWidget(SelectElementsButton, 0, 1);
215 GroupArgumentsLayout->addWidget(LineEditElements, 0, 2, 1, 5);
216 GroupArgumentsLayout->addWidget(filterBtn, 0, 7);
217 GroupArgumentsLayout->addWidget(CheckBoxMesh, 1, 0, 1, 8);
218 GroupArgumentsLayout->addWidget(TextLabel1, 2, 0);
219 GroupArgumentsLayout->addWidget(SelectButton1, 2, 1);
220 GroupArgumentsLayout->addWidget(TextLabel1_1, 2, 2);
221 GroupArgumentsLayout->addWidget(SpinBox1_1, 2, 3);
222 GroupArgumentsLayout->addWidget(TextLabel1_2, 2, 4);
223 GroupArgumentsLayout->addWidget(SpinBox1_2, 2, 5);
224 GroupArgumentsLayout->addWidget(TextLabel1_3, 2, 6);
225 GroupArgumentsLayout->addWidget(SpinBox1_3, 2, 7);
226 GroupArgumentsLayout->addWidget(TextLabel2, 3, 0);
227 GroupArgumentsLayout->addWidget(SelectButton2, 3, 1);
228 GroupArgumentsLayout->addWidget(TextLabel2_1, 3, 2);
229 GroupArgumentsLayout->addWidget(SpinBox2_1, 3, 3);
230 GroupArgumentsLayout->addWidget(TextLabel2_2, 3, 4);
231 GroupArgumentsLayout->addWidget(SpinBox2_2, 3, 5);
232 GroupArgumentsLayout->addWidget(TextLabel2_3, 3, 6);
233 GroupArgumentsLayout->addWidget(SpinBox2_3, 3, 7);
234 GroupArgumentsLayout->addWidget(ActionBox, 4, 0, 3, 4);
235 GroupArgumentsLayout->addWidget(MakeGroupsCheck, 5, 5, 1, 4);
236 GroupArgumentsLayout->addWidget(LineEditNewMesh, 6, 5, 1, 4);
238 /***************************************************************/
239 GroupButtons = new QGroupBox(this);
240 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
241 GroupButtonsLayout->setSpacing(SPACING);
242 GroupButtonsLayout->setMargin(MARGIN);
244 buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
245 buttonOk->setAutoDefault(true);
246 buttonOk->setDefault(true);
247 buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
248 buttonApply->setAutoDefault(true);
249 buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
250 buttonCancel->setAutoDefault(true);
251 buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
252 buttonHelp->setAutoDefault(true);
254 GroupButtonsLayout->addWidget(buttonOk);
255 GroupButtonsLayout->addSpacing(10);
256 GroupButtonsLayout->addWidget(buttonApply);
257 GroupButtonsLayout->addSpacing(10);
258 GroupButtonsLayout->addStretch();
259 GroupButtonsLayout->addWidget(buttonCancel);
260 GroupButtonsLayout->addWidget(buttonHelp);
262 /***************************************************************/
263 SMESHGUI_TranslationDlgLayout->addWidget(ConstructorsBox);
264 SMESHGUI_TranslationDlgLayout->addWidget(GroupArguments);
265 SMESHGUI_TranslationDlgLayout->addWidget(GroupButtons);
267 /* Initialisations */
268 SpinBox1_1->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, DBL_DIGITS_DISPLAY);
269 SpinBox1_2->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, DBL_DIGITS_DISPLAY);
270 SpinBox1_3->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, DBL_DIGITS_DISPLAY);
271 SpinBox2_1->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, DBL_DIGITS_DISPLAY);
272 SpinBox2_2->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, DBL_DIGITS_DISPLAY);
273 SpinBox2_3->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, DBL_DIGITS_DISPLAY);
275 RadioButton1->setChecked(true);
277 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
279 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
281 // Costruction of the logical filter
282 SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter (MESHorSUBMESH);
283 SMESH_TypeFilter* aSmeshGroupFilter = new SMESH_TypeFilter (GROUP);
285 QList<SUIT_SelectionFilter*> aListOfFilters;
286 if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
287 if (aSmeshGroupFilter) aListOfFilters.append(aSmeshGroupFilter);
289 myMeshOrSubMeshOrGroupFilter =
290 new SMESH_LogicalFilter(aListOfFilters, SMESH_LogicalFilter::LO_OR);
292 myHelpFileName = "translation_page.html";
296 /* signals and slots connections */
297 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
298 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
299 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
300 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
301 connect(GroupConstructors, SIGNAL(buttonClicked(int)), SLOT(ConstructorsClicked(int)));
303 connect(SelectElementsButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
304 connect(SelectButton1, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
305 connect(SelectButton2, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
307 connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
308 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
309 /* to close dialog if study change */
310 connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
311 connect(LineEditElements, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
312 connect(CheckBoxMesh, SIGNAL(toggled(bool)), SLOT(onSelectMesh(bool)));
313 connect(ActionGroup, SIGNAL(buttonClicked(int)), SLOT(onActionClicked(int)));
315 ConstructorsClicked(0);
316 SelectionIntoArgument();
317 onActionClicked(MOVE_ELEMS_BUTTON);
320 //=================================================================================
321 // function : ~SMESHGUI_TranslationDlg()
322 // purpose : Destroys the object and frees any allocated resources
323 //=================================================================================
324 SMESHGUI_TranslationDlg::~SMESHGUI_TranslationDlg()
327 myFilterDlg->setParent( 0 );
333 //=================================================================================
336 //=================================================================================
337 void SMESHGUI_TranslationDlg::Init (bool ResetControls)
341 myEditCurrentArgument = 0;
342 LineEditElements->clear();
346 buttonOk->setEnabled(false);
347 buttonApply->setEnabled(false);
350 myMesh = SMESH::SMESH_Mesh::_nil();
353 SpinBox1_1->SetValue(0.0);
354 SpinBox1_2->SetValue(0.0);
355 SpinBox1_3->SetValue(0.0);
356 SpinBox2_1->SetValue(0.0);
357 SpinBox2_2->SetValue(0.0);
358 SpinBox2_3->SetValue(0.0);
360 ActionGroup->button( MOVE_ELEMS_BUTTON )->setChecked(true);
361 CheckBoxMesh->setChecked(false);
362 // MakeGroupsCheck->setChecked(false);
363 // MakeGroupsCheck->setEnabled(false);
368 //=================================================================================
369 // function : ConstructorsClicked()
370 // purpose : Radio button management
371 //=================================================================================
372 void SMESHGUI_TranslationDlg::ConstructorsClicked (int constructorId)
374 disconnect(mySelectionMgr, 0, this, 0);
376 switch (constructorId) {
379 TextLabel1->setText(tr("SMESH_POINT_1"));
380 TextLabel1_1->setText(tr("SMESH_X"));
381 TextLabel1_2->setText(tr("SMESH_Y"));
382 TextLabel1_3->setText(tr("SMESH_Z"));
384 SelectButton1->show();
386 SelectButton2->show();
387 TextLabel2_1->show();
389 TextLabel2_2->show();
391 TextLabel2_3->show();
397 TextLabel1->setText(tr("SMESH_VECTOR"));
398 TextLabel1_1->setText(tr("SMESH_DX"));
399 TextLabel1_2->setText(tr("SMESH_DY"));
400 TextLabel1_3->setText(tr("SMESH_DZ"));
402 SelectButton1->hide();
404 SelectButton2->hide();
405 TextLabel2_1->hide();
407 TextLabel2_2->hide();
409 TextLabel2_3->hide();
415 if (myEditCurrentArgument != (QWidget*)LineEditElements) {
416 SMESH::SetPointRepresentation(false);
417 if (!CheckBoxMesh->isChecked())
418 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
419 aViewWindow->SetSelectionMode( CellSelection );
422 myEditCurrentArgument = (QWidget*)LineEditElements;
423 LineEditElements->setFocus();
425 if (CheckBoxMesh->isChecked())
428 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
430 QApplication::instance()->processEvents();
432 resize( minimumSize() );
435 //=================================================================================
436 // function : ClickOnApply()
438 //=================================================================================
439 void SMESHGUI_TranslationDlg::ClickOnApply()
441 if (mySMESHGUI->isActiveStudyLocked())
444 if (myNbOkElements) {
445 QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
447 SMESH::long_array_var anElementsId = new SMESH::long_array;
449 anElementsId->length(aListElementsId.count());
450 for (int i = 0; i < aListElementsId.count(); i++)
451 anElementsId[i] = aListElementsId[i].toInt();
453 SMESH::DirStruct aVector;
454 if (GetConstructorId() == 0) {
455 aVector.PS.x = SpinBox2_1->GetValue() - SpinBox1_1->GetValue();
456 aVector.PS.y = SpinBox2_2->GetValue() - SpinBox1_2->GetValue();
457 aVector.PS.z = SpinBox2_3->GetValue() - SpinBox1_3->GetValue();
458 } else if (GetConstructorId() == 1) {
459 aVector.PS.x = SpinBox1_1->GetValue();
460 aVector.PS.y = SpinBox1_2->GetValue();
461 aVector.PS.z = SpinBox1_3->GetValue();
464 int actionButton = ActionGroup->checkedId();
465 bool makeGroups = ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() );
467 SUIT_OverrideCursor aWaitCursor;
468 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
469 switch ( actionButton ) {
470 case MOVE_ELEMS_BUTTON:
471 aMeshEditor->Translate(anElementsId, aVector, false);
473 case COPY_ELEMS_BUTTON:
475 SMESH::ListOfGroups_var groups =
476 aMeshEditor->TranslateMakeGroups(anElementsId, aVector);
478 aMeshEditor->Translate(anElementsId, aVector, true);
480 case MAKE_MESH_BUTTON:
481 SMESH::SMESH_Mesh_var mesh =
482 aMeshEditor->TranslateMakeMesh(anElementsId, aVector, makeGroups,
483 LineEditNewMesh->text().toLatin1().data());
489 if ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() ||
490 actionButton == MAKE_MESH_BUTTON )
491 mySMESHGUI->updateObjBrowser(true); // new groups may appear
493 ConstructorsClicked(GetConstructorId());
494 SelectionIntoArgument();
498 //=================================================================================
499 // function : ClickOnOk()
501 //=================================================================================
502 void SMESHGUI_TranslationDlg::ClickOnOk()
508 //=================================================================================
509 // function : ClickOnCancel()
511 //=================================================================================
512 void SMESHGUI_TranslationDlg::ClickOnCancel()
514 disconnect(mySelectionMgr, 0, this, 0);
515 mySelectionMgr->clearFilters();
516 //mySelectionMgr->clearSelected();
517 if (SMESH::GetCurrentVtkView()) {
518 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
519 SMESH::SetPointRepresentation(false);
521 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
522 aViewWindow->SetSelectionMode( ActorSelection );
523 mySMESHGUI->ResetState();
527 //=================================================================================
528 // function : ClickOnHelp()
530 //=================================================================================
531 void SMESHGUI_TranslationDlg::ClickOnHelp()
533 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
535 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
539 platform = "winapplication";
541 platform = "application";
543 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
544 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
545 arg(app->resourceMgr()->stringValue("ExternalBrowser",
547 arg(myHelpFileName));
551 //=======================================================================
552 // function : onTextChange()
554 //=======================================================================
555 void SMESHGUI_TranslationDlg::onTextChange (const QString& theNewText)
557 QLineEdit* send = (QLineEdit*)sender();
560 BusyLocker lock( myBusy );
562 if (send == LineEditElements)
565 buttonOk->setEnabled(false);
566 buttonApply->setEnabled(false);
568 // hilight entered elements
569 SMDS_Mesh* aMesh = 0;
571 aMesh = myActor->GetObject()->GetMesh();
574 Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
576 TColStd_MapOfInteger newIndices;
578 QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
580 if (send == LineEditElements) {
581 for (int i = 0; i < aListId.count(); i++) {
582 const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
584 newIndices.Add(e->GetID());
589 mySelector->AddOrRemoveIndex( anIO, newIndices, false );
590 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
591 aViewWindow->highlight( anIO, true, true );
593 myElementsId = theNewText;
596 if (myNbOkElements) {
597 buttonOk->setEnabled(true);
598 buttonApply->setEnabled(true);
602 //=================================================================================
603 // function : SelectionIntoArgument()
604 // purpose : Called when selection as changed or other case
605 //=================================================================================
606 void SMESHGUI_TranslationDlg::SelectionIntoArgument()
609 BusyLocker lock( myBusy );
612 QString aString = "";
614 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
615 LineEditElements->setText(aString);
617 buttonOk->setEnabled(false);
618 buttonApply->setEnabled(false);
621 if (!GroupButtons->isEnabled()) // inactive
626 mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
628 int nbSel = aList.Extent();
632 Handle(SALOME_InteractiveObject) IO = aList.First();
633 myMesh = SMESH::GetMeshByIO(IO);
634 if (myMesh->_is_nil())
637 myActor = SMESH::FindActorByObject(myMesh);
639 myActor = SMESH::FindActorByEntry(IO->getEntry());
645 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
648 // MakeGroups is available if there are groups and "Copy"
649 if ( myMesh->NbGroups() == 0 ) {
650 MakeGroupsCheck->setChecked(false);
651 MakeGroupsCheck->setEnabled(false);
653 else if ( ActionGroup->checkedId() != MOVE_ELEMS_BUTTON ) {
654 MakeGroupsCheck->setEnabled(true);
657 if (CheckBoxMesh->isChecked()) {
658 SMESH::GetNameOfSelectedIObjects( mySelectionMgr, aString );
660 if (!SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO)->_is_nil()) { //MESH
662 SMDS_Mesh* aSMDSMesh = myActor->GetObject()->GetMesh();
666 for (int i = aSMDSMesh->MinElementID(); i <= aSMDSMesh->MaxElementID(); i++) {
667 const SMDS_MeshElement * e = aSMDSMesh->FindElement(i);
669 myElementsId += QString(" %1").arg(i);
673 } else if (!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil()) { //SUBMESH
675 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO);
677 // get IDs from submesh
678 SMESH::long_array_var anElementsIds = new SMESH::long_array;
679 anElementsIds = aSubMesh->GetElementsId();
680 for (int i = 0; i < anElementsIds->length(); i++) {
681 myElementsId += QString(" %1").arg(anElementsIds[i]);
683 aNbUnits = anElementsIds->length();
686 SMESH::SMESH_GroupBase_var aGroup =
687 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
688 if (aGroup->_is_nil())
691 // get IDs from smesh group
692 SMESH::long_array_var anElementsIds = new SMESH::long_array;
693 anElementsIds = aGroup->GetListOfID();
694 for (int i = 0; i < anElementsIds->length(); i++) {
695 myElementsId += QString(" %1").arg(anElementsIds[i]);
697 aNbUnits = anElementsIds->length();
700 aNbUnits = SMESH::GetNameOfSelectedElements(mySelector, IO, aString);
701 myElementsId = aString;
707 myNbOkElements = true;
709 aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, IO, aString);
713 SMDS_Mesh* aMesh = myActor->GetObject()->GetMesh();
717 const SMDS_MeshNode * n = aMesh->FindNode(aString.toInt());
725 if (myEditCurrentArgument == (QWidget*)SpinBox1_1) {
726 SpinBox1_1->SetValue(x);
727 SpinBox1_2->SetValue(y);
728 SpinBox1_3->SetValue(z);
729 } else if (myEditCurrentArgument == (QWidget*)SpinBox2_1) {
730 SpinBox2_1->SetValue(x);
731 SpinBox2_2->SetValue(y);
732 SpinBox2_3->SetValue(z);
736 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
737 LineEditElements->setText(aString);
738 LineEditElements->repaint();
739 LineEditElements->setEnabled(false); // to fully update lineedit IPAL 19809
740 LineEditElements->setEnabled(true);
745 if (myNbOkElements) {
746 buttonOk->setEnabled(true);
747 buttonApply->setEnabled(true);
751 //=================================================================================
752 // function : SetEditCurrentArgument()
754 //=================================================================================
755 void SMESHGUI_TranslationDlg::SetEditCurrentArgument()
757 QPushButton* send = (QPushButton*)sender();
759 disconnect(mySelectionMgr, 0, this, 0);
760 mySelectionMgr->clearSelected();
761 mySelectionMgr->clearFilters();
763 if (send == SelectElementsButton) {
764 myEditCurrentArgument = (QWidget*)LineEditElements;
765 SMESH::SetPointRepresentation(false);
766 if (CheckBoxMesh->isChecked()) {
767 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
768 aViewWindow->SetSelectionMode( ActorSelection );
769 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
772 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
773 aViewWindow->SetSelectionMode( CellSelection );
775 } else if (send == SelectButton1) {
776 myEditCurrentArgument = (QWidget*)SpinBox1_1;
777 SMESH::SetPointRepresentation(true);
779 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
780 aViewWindow->SetSelectionMode( NodeSelection );
781 } else if (send == SelectButton2) {
782 myEditCurrentArgument = (QWidget*)SpinBox2_1;
783 SMESH::SetPointRepresentation(true);
785 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
786 aViewWindow->SetSelectionMode( NodeSelection );
789 myEditCurrentArgument->setFocus();
790 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
791 SelectionIntoArgument();
794 //=================================================================================
795 // function : DeactivateActiveDialog()
797 //=================================================================================
798 void SMESHGUI_TranslationDlg::DeactivateActiveDialog()
800 if (ConstructorsBox->isEnabled()) {
801 ConstructorsBox->setEnabled(false);
802 GroupArguments->setEnabled(false);
803 GroupButtons->setEnabled(false);
804 mySMESHGUI->ResetState();
805 mySMESHGUI->SetActiveDialogBox(0);
809 //=================================================================================
810 // function : ActivateThisDialog()
812 //=================================================================================
813 void SMESHGUI_TranslationDlg::ActivateThisDialog()
815 /* Emit a signal to deactivate the active dialog */
816 mySMESHGUI->EmitSignalDeactivateDialog();
817 ConstructorsBox->setEnabled(true);
818 GroupArguments->setEnabled(true);
819 GroupButtons->setEnabled(true);
821 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
823 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
824 aViewWindow->SetSelectionMode( CellSelection );
826 SelectionIntoArgument();
829 //=================================================================================
830 // function : enterEvent()
832 //=================================================================================
833 void SMESHGUI_TranslationDlg::enterEvent (QEvent*)
835 if (!ConstructorsBox->isEnabled())
836 ActivateThisDialog();
839 //=================================================================================
840 // function : closeEvent()
842 //=================================================================================
843 void SMESHGUI_TranslationDlg::closeEvent (QCloseEvent*)
845 /* same than click on cancel button */
849 //=======================================================================
850 //function : hideEvent
851 //purpose : caused by ESC key
852 //=======================================================================
853 void SMESHGUI_TranslationDlg::hideEvent (QHideEvent*)
859 //=======================================================================
860 //function : onSelectMesh
862 //=======================================================================
863 void SMESHGUI_TranslationDlg::onSelectMesh (bool toSelectMesh)
866 TextLabelElements->setText(tr("SMESH_NAME"));
868 TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
870 if (myEditCurrentArgument != LineEditElements) {
871 LineEditElements->clear();
875 mySelectionMgr->clearFilters();
876 SMESH::SetPointRepresentation(false);
879 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
880 aViewWindow->SetSelectionMode( ActorSelection );
881 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
882 LineEditElements->setReadOnly(true);
883 LineEditElements->setValidator(0);
885 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
886 aViewWindow->SetSelectionMode( CellSelection );
887 LineEditElements->setReadOnly(false);
888 LineEditElements->setValidator(myIdValidator);
889 onTextChange(LineEditElements->text());
892 SelectionIntoArgument();
895 //=======================================================================
896 //function : onActionClicked
897 //purpose : slot called when an action type changed
898 //=======================================================================
900 void SMESHGUI_TranslationDlg::onActionClicked(int button)
903 case MOVE_ELEMS_BUTTON:
904 MakeGroupsCheck->setEnabled(false);
905 LineEditNewMesh->setEnabled(false);
907 case COPY_ELEMS_BUTTON:
908 LineEditNewMesh->setEnabled(false);
909 MakeGroupsCheck->setText( tr("SMESH_MAKE_GROUPS"));
910 if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
911 MakeGroupsCheck->setEnabled(true);
913 MakeGroupsCheck->setEnabled(false);
915 case MAKE_MESH_BUTTON:
916 LineEditNewMesh->setEnabled(true);
917 MakeGroupsCheck->setText( tr("SMESH_COPY_GROUPS"));
918 if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
919 MakeGroupsCheck->setEnabled(true);
921 MakeGroupsCheck->setEnabled(false);
927 //=======================================================================
928 //function : setNewMeshName
929 //purpose : update contents of LineEditNewMesh
930 //=======================================================================
932 void SMESHGUI_TranslationDlg::setNewMeshName()
934 LineEditNewMesh->setText("");
935 if ( LineEditNewMesh->isEnabled() && !myMesh->_is_nil() ) {
937 if ( CheckBoxMesh->isChecked() ) {
938 name = LineEditElements->text();
941 _PTR(SObject) meshSO = SMESH::FindSObject( myMesh );
942 name = meshSO->GetName().c_str();
944 if ( !name.isEmpty() )
945 LineEditNewMesh->setText( SMESH::UniqueMeshName( name, "translated"));
949 //=================================================================================
950 // function : GetConstructorId()
952 //=================================================================================
953 int SMESHGUI_TranslationDlg::GetConstructorId()
955 return GroupConstructors->checkedId();
958 //=================================================================================
959 // function : keyPressEvent()
961 //=================================================================================
962 void SMESHGUI_TranslationDlg::keyPressEvent( QKeyEvent* e )
964 QDialog::keyPressEvent( e );
965 if ( e->isAccepted() )
968 if ( e->key() == Qt::Key_F1 ) {
974 //=================================================================================
975 // function : setFilters()
976 // purpose : SLOT. Called when "Filter" button pressed.
977 //=================================================================================
978 void SMESHGUI_TranslationDlg::setFilters()
981 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, SMESH::ALL );
983 myFilterDlg->SetSelection();
984 myFilterDlg->SetMesh( myMesh );
985 myFilterDlg->SetSourceWg( LineEditElements );