1 // SMESH SMESHGUI : GUI for SMESH component
3 // Copyright (C) 2003 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 // File : SMESHGUI_TranslationDlg.cxx
23 // 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"
36 #include <SMESH_Actor.h>
37 #include <SMESH_TypeFilter.hxx>
38 #include <SMESH_LogicalFilter.hxx>
39 #include <SMDS_Mesh.hxx>
41 // SALOME GUI includes
42 #include <SUIT_Desktop.h>
43 #include <SUIT_ResourceMgr.h>
44 #include <SUIT_Session.h>
45 #include <SUIT_MessageBox.h>
46 #include <SUIT_OverrideCursor.h>
48 #include <LightApp_Application.h>
49 #include <LightApp_SelectionMgr.h>
51 #include <SVTK_ViewModel.h>
52 #include <SVTK_ViewWindow.h>
53 #include <SALOME_ListIO.hxx>
55 // SALOME KERNEL includes
56 #include <SALOMEDSClient_SObject.hxx>
59 #include <TColStd_MapOfInteger.hxx>
62 #include <QApplication>
63 #include <QButtonGroup>
67 #include <QPushButton>
68 #include <QRadioButton>
70 #include <QHBoxLayout>
71 #include <QVBoxLayout>
72 #include <QGridLayout>
77 #include <SALOMEconfig.h>
78 #include CORBA_SERVER_HEADER(SMESH_Group)
79 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
81 enum { MOVE_ELEMS_BUTTON = 0, COPY_ELEMS_BUTTON, MAKE_MESH_BUTTON }; //!< action type
86 //=================================================================================
87 // class : SMESHGUI_TranslationDlg()
89 //=================================================================================
90 SMESHGUI_TranslationDlg::SMESHGUI_TranslationDlg( SMESHGUI* theModule )
91 : QDialog( SMESH::GetDesktop( theModule ) ),
92 mySMESHGUI( theModule ),
93 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
94 mySelectedObject(SMESH::SMESH_IDSource::_nil())
96 QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SMESH_TRANSLATION_POINTS")));
97 QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SMESH_TRANSLATION_VECTOR")));
98 QPixmap image2 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
101 setAttribute(Qt::WA_DeleteOnClose, true);
102 setWindowTitle(tr("SMESH_TRANSLATION"));
103 setSizeGripEnabled(true);
105 QVBoxLayout* SMESHGUI_TranslationDlgLayout = new QVBoxLayout(this);
106 SMESHGUI_TranslationDlgLayout->setSpacing(SPACING);
107 SMESHGUI_TranslationDlgLayout->setMargin(MARGIN);
109 /***************************************************************/
110 ConstructorsBox = new QGroupBox(tr("SMESH_TRANSLATION"), this);
111 GroupConstructors = new QButtonGroup(this);
112 QHBoxLayout* ConstructorsBoxLayout = new QHBoxLayout(ConstructorsBox);
113 ConstructorsBoxLayout->setSpacing(SPACING);
114 ConstructorsBoxLayout->setMargin(MARGIN);
116 RadioButton1= new QRadioButton(ConstructorsBox);
117 RadioButton1->setIcon(image0);
118 RadioButton2= new QRadioButton(ConstructorsBox);
119 RadioButton2->setIcon(image1);
121 ConstructorsBoxLayout->addWidget(RadioButton1);
122 ConstructorsBoxLayout->addWidget(RadioButton2);
123 GroupConstructors->addButton(RadioButton1, 0);
124 GroupConstructors->addButton(RadioButton2, 1);
126 /***************************************************************/
127 GroupArguments = new QGroupBox(tr("SMESH_ARGUMENTS"), this);
128 QGridLayout* GroupArgumentsLayout = new QGridLayout(GroupArguments);
129 GroupArgumentsLayout->setSpacing(SPACING);
130 GroupArgumentsLayout->setMargin(MARGIN);
132 myIdValidator = new SMESHGUI_IdValidator(this);
134 // Controls for elements selection
135 TextLabelElements = new QLabel(tr("SMESH_ID_ELEMENTS"), GroupArguments);
136 SelectElementsButton = new QPushButton(GroupArguments);
137 SelectElementsButton->setIcon(image2);
138 LineEditElements = new QLineEdit(GroupArguments);
139 LineEditElements->setValidator(myIdValidator);
141 // Control for the whole mesh selection
142 CheckBoxMesh = new QCheckBox(tr("SMESH_SELECT_WHOLE_MESH"), GroupArguments);
144 // Controls for vector and points selection
145 TextLabel1 = new QLabel(GroupArguments);
146 SelectButton1 = new QPushButton(GroupArguments);
147 SelectButton1->setIcon(image2);
149 TextLabel1_1 = new QLabel(GroupArguments);
150 SpinBox1_1 = new SMESHGUI_SpinBox(GroupArguments);
151 TextLabel1_2 = new QLabel(GroupArguments);
152 SpinBox1_2 = new SMESHGUI_SpinBox(GroupArguments);
153 TextLabel1_3 = new QLabel(GroupArguments);
154 SpinBox1_3 = new SMESHGUI_SpinBox(GroupArguments);
156 TextLabel2 = new QLabel(tr("SMESH_POINT_2"), GroupArguments);
157 SelectButton2 = new QPushButton(GroupArguments);
158 SelectButton2->setIcon(image2);
160 TextLabel2_1 = new QLabel(tr("SMESH_X"), GroupArguments);
161 SpinBox2_1 = new SMESHGUI_SpinBox(GroupArguments);
162 TextLabel2_2 = new QLabel(tr("SMESH_Y"), GroupArguments);
163 SpinBox2_2 = new SMESHGUI_SpinBox(GroupArguments);
164 TextLabel2_3 = new QLabel(tr("SMESH_Z"), GroupArguments);
165 SpinBox2_3 = new SMESHGUI_SpinBox(GroupArguments);
167 // switch of action type
168 ActionBox = new QGroupBox(GroupArguments);
169 ActionGroup = new QButtonGroup(GroupArguments);
170 QVBoxLayout* ActionBoxLayout = new QVBoxLayout(ActionBox);
171 ActionBoxLayout->addSpacing(SPACING);
172 ActionBoxLayout->setMargin(MARGIN);
174 QRadioButton* aMoveElements = new QRadioButton(tr("SMESH_MOVE_ELEMENTS"), ActionBox);
175 QRadioButton* aCopyElements = new QRadioButton(tr("SMESH_COPY_ELEMENTS"), ActionBox);
176 QRadioButton* aCreateMesh = new QRadioButton(tr("SMESH_CREATE_MESH"), ActionBox);
178 ActionBoxLayout->addWidget(aMoveElements);
179 ActionBoxLayout->addWidget(aCopyElements);
180 ActionBoxLayout->addWidget(aCreateMesh);
181 ActionGroup->addButton(aMoveElements, MOVE_ELEMS_BUTTON);
182 ActionGroup->addButton(aCopyElements, COPY_ELEMS_BUTTON);
183 ActionGroup->addButton(aCreateMesh, MAKE_MESH_BUTTON);
185 // CheckBox for groups generation
186 MakeGroupsCheck = new QCheckBox(tr("SMESH_MAKE_GROUPS"), GroupArguments);
187 MakeGroupsCheck->setChecked(false);
189 // Name of a mesh to create
190 LineEditNewMesh = new QLineEdit(GroupArguments);
193 GroupArgumentsLayout->addWidget(TextLabelElements, 0, 0);
194 GroupArgumentsLayout->addWidget(SelectElementsButton, 0, 1);
195 GroupArgumentsLayout->addWidget(LineEditElements, 0, 2, 1, 6);
196 GroupArgumentsLayout->addWidget(CheckBoxMesh, 1, 0, 1, 8);
197 GroupArgumentsLayout->addWidget(TextLabel1, 2, 0);
198 GroupArgumentsLayout->addWidget(SelectButton1, 2, 1);
199 GroupArgumentsLayout->addWidget(TextLabel1_1, 2, 2);
200 GroupArgumentsLayout->addWidget(SpinBox1_1, 2, 3);
201 GroupArgumentsLayout->addWidget(TextLabel1_2, 2, 4);
202 GroupArgumentsLayout->addWidget(SpinBox1_2, 2, 5);
203 GroupArgumentsLayout->addWidget(TextLabel1_3, 2, 6);
204 GroupArgumentsLayout->addWidget(SpinBox1_3, 2, 7);
205 GroupArgumentsLayout->addWidget(TextLabel2, 3, 0);
206 GroupArgumentsLayout->addWidget(SelectButton2, 3, 1);
207 GroupArgumentsLayout->addWidget(TextLabel2_1, 3, 2);
208 GroupArgumentsLayout->addWidget(SpinBox2_1, 3, 3);
209 GroupArgumentsLayout->addWidget(TextLabel2_2, 3, 4);
210 GroupArgumentsLayout->addWidget(SpinBox2_2, 3, 5);
211 GroupArgumentsLayout->addWidget(TextLabel2_3, 3, 6);
212 GroupArgumentsLayout->addWidget(SpinBox2_3, 3, 7);
213 GroupArgumentsLayout->addWidget(ActionBox, 4, 0, 3, 4);
214 GroupArgumentsLayout->addWidget(MakeGroupsCheck, 5, 5, 1, 4);
215 GroupArgumentsLayout->addWidget(LineEditNewMesh, 6, 5, 1, 4);
217 /***************************************************************/
218 GroupButtons = new QGroupBox(this);
219 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
220 GroupButtonsLayout->setSpacing(SPACING);
221 GroupButtonsLayout->setMargin(MARGIN);
223 buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
224 buttonOk->setAutoDefault(true);
225 buttonOk->setDefault(true);
226 buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
227 buttonApply->setAutoDefault(true);
228 buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
229 buttonCancel->setAutoDefault(true);
230 buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
231 buttonHelp->setAutoDefault(true);
233 GroupButtonsLayout->addWidget(buttonOk);
234 GroupButtonsLayout->addSpacing(10);
235 GroupButtonsLayout->addWidget(buttonApply);
236 GroupButtonsLayout->addSpacing(10);
237 GroupButtonsLayout->addStretch();
238 GroupButtonsLayout->addWidget(buttonCancel);
239 GroupButtonsLayout->addWidget(buttonHelp);
241 /***************************************************************/
242 SMESHGUI_TranslationDlgLayout->addWidget(ConstructorsBox);
243 SMESHGUI_TranslationDlgLayout->addWidget(GroupArguments);
244 SMESHGUI_TranslationDlgLayout->addWidget(GroupButtons);
246 /* Initialisations */
247 SpinBox1_1->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, DBL_DIGITS_DISPLAY);
248 SpinBox1_2->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, DBL_DIGITS_DISPLAY);
249 SpinBox1_3->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, DBL_DIGITS_DISPLAY);
250 SpinBox2_1->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, DBL_DIGITS_DISPLAY);
251 SpinBox2_2->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, DBL_DIGITS_DISPLAY);
252 SpinBox2_3->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, DBL_DIGITS_DISPLAY);
254 RadioButton1->setChecked(true);
256 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
258 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
260 // Costruction of the logical filter
261 SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter (MESHorSUBMESH);
262 SMESH_TypeFilter* aSmeshGroupFilter = new SMESH_TypeFilter (GROUP);
264 QList<SUIT_SelectionFilter*> aListOfFilters;
265 if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
266 if (aSmeshGroupFilter) aListOfFilters.append(aSmeshGroupFilter);
268 myMeshOrSubMeshOrGroupFilter =
269 new SMESH_LogicalFilter(aListOfFilters, SMESH_LogicalFilter::LO_OR);
271 myHelpFileName = "translation_page.html";
275 /* signals and slots connections */
276 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
277 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
278 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
279 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
280 connect(GroupConstructors, SIGNAL(buttonClicked(int)), SLOT(ConstructorsClicked(int)));
282 connect(SelectElementsButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
283 connect(SelectButton1, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
284 connect(SelectButton2, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
286 connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
287 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
288 /* to close dialog if study change */
289 connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
290 connect(LineEditElements, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
291 connect(CheckBoxMesh, SIGNAL(toggled(bool)), SLOT(onSelectMesh(bool)));
292 connect(ActionGroup, SIGNAL(buttonClicked(int)), SLOT(onActionClicked(int)));
294 ConstructorsClicked(0);
295 SelectionIntoArgument();
296 onActionClicked(MOVE_ELEMS_BUTTON);
299 //=================================================================================
300 // function : ~SMESHGUI_TranslationDlg()
301 // purpose : Destroys the object and frees any allocated resources
302 //=================================================================================
303 SMESHGUI_TranslationDlg::~SMESHGUI_TranslationDlg()
307 //=================================================================================
310 //=================================================================================
311 void SMESHGUI_TranslationDlg::Init (bool ResetControls)
315 myEditCurrentArgument = 0;
316 LineEditElements->clear();
320 buttonOk->setEnabled(false);
321 buttonApply->setEnabled(false);
324 myMesh = SMESH::SMESH_Mesh::_nil();
327 SpinBox1_1->SetValue(0.0);
328 SpinBox1_2->SetValue(0.0);
329 SpinBox1_3->SetValue(0.0);
330 SpinBox2_1->SetValue(0.0);
331 SpinBox2_2->SetValue(0.0);
332 SpinBox2_3->SetValue(0.0);
334 ActionGroup->button( MOVE_ELEMS_BUTTON )->setChecked(true);
335 CheckBoxMesh->setChecked(false);
336 // MakeGroupsCheck->setChecked(false);
337 // MakeGroupsCheck->setEnabled(false);
342 //=================================================================================
343 // function : ConstructorsClicked()
344 // purpose : Radio button management
345 //=================================================================================
346 void SMESHGUI_TranslationDlg::ConstructorsClicked (int constructorId)
348 disconnect(mySelectionMgr, 0, this, 0);
350 switch (constructorId) {
353 TextLabel1->setText(tr("SMESH_POINT_1"));
354 TextLabel1_1->setText(tr("SMESH_X"));
355 TextLabel1_2->setText(tr("SMESH_Y"));
356 TextLabel1_3->setText(tr("SMESH_Z"));
358 SelectButton1->show();
360 SelectButton2->show();
361 TextLabel2_1->show();
363 TextLabel2_2->show();
365 TextLabel2_3->show();
371 TextLabel1->setText(tr("SMESH_VECTOR"));
372 TextLabel1_1->setText(tr("SMESH_DX"));
373 TextLabel1_2->setText(tr("SMESH_DY"));
374 TextLabel1_3->setText(tr("SMESH_DZ"));
376 SelectButton1->hide();
378 SelectButton2->hide();
379 TextLabel2_1->hide();
381 TextLabel2_2->hide();
383 TextLabel2_3->hide();
389 if (myEditCurrentArgument != (QWidget*)LineEditElements) {
390 SMESH::SetPointRepresentation(false);
391 if (!CheckBoxMesh->isChecked())
392 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
393 aViewWindow->SetSelectionMode( CellSelection );
396 myEditCurrentArgument = (QWidget*)LineEditElements;
397 LineEditElements->setFocus();
399 if (CheckBoxMesh->isChecked())
402 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
404 QApplication::instance()->processEvents();
406 resize( minimumSize() );
409 //=================================================================================
410 // function : ClickOnApply()
412 //=================================================================================
413 bool SMESHGUI_TranslationDlg::ClickOnApply()
415 if (mySMESHGUI->isActiveStudyLocked())
421 if (myNbOkElements) {
422 QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
424 SMESH::long_array_var anElementsId = new SMESH::long_array;
426 anElementsId->length(aListElementsId.count());
427 for (int i = 0; i < aListElementsId.count(); i++)
428 anElementsId[i] = aListElementsId[i].toInt();
430 SMESH::DirStruct aVector;
431 if (GetConstructorId() == 0) {
432 aVector.PS.x = SpinBox2_1->GetValue() - SpinBox1_1->GetValue();
433 aVector.PS.y = SpinBox2_2->GetValue() - SpinBox1_2->GetValue();
434 aVector.PS.z = SpinBox2_3->GetValue() - SpinBox1_3->GetValue();
435 } else if (GetConstructorId() == 1) {
436 aVector.PS.x = SpinBox1_1->GetValue();
437 aVector.PS.y = SpinBox1_2->GetValue();
438 aVector.PS.z = SpinBox1_3->GetValue();
441 QStringList aParameters;
442 aParameters << SpinBox1_1->text();
443 if (GetConstructorId() == 0)
444 aParameters << SpinBox2_1->text();
445 aParameters << SpinBox1_2->text();
446 if (GetConstructorId() == 0)
447 aParameters << SpinBox2_2->text();
448 aParameters << SpinBox1_3->text();
449 if (GetConstructorId() == 0)
450 aParameters << SpinBox2_3->text();
452 int actionButton = ActionGroup->checkedId();
453 bool makeGroups = ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() );
455 SUIT_OverrideCursor aWaitCursor;
456 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
457 switch ( actionButton ) {
458 case MOVE_ELEMS_BUTTON:
459 if(CheckBoxMesh->isChecked())
460 aMeshEditor->TranslateObject(mySelectedObject, aVector, false);
462 aMeshEditor->Translate(anElementsId, aVector, false);
463 if( !myMesh->_is_nil())
464 myMesh->SetParameters(SMESHGUI::JoinObjectParameters(aParameters));
466 case COPY_ELEMS_BUTTON:
468 SMESH::ListOfGroups_var groups;
469 if(CheckBoxMesh->isChecked())
470 groups = aMeshEditor->TranslateObjectMakeGroups(mySelectedObject,aVector);
472 groups = aMeshEditor->TranslateMakeGroups(anElementsId, aVector);
475 if(CheckBoxMesh->isChecked())
476 aMeshEditor->TranslateObject(mySelectedObject, aVector, true);
478 aMeshEditor->Translate(anElementsId, aVector, true);
480 if( !myMesh->_is_nil())
481 myMesh->SetParameters(SMESHGUI::JoinObjectParameters(aParameters));
483 case MAKE_MESH_BUTTON:
484 SMESH::SMESH_Mesh_var mesh;
485 if(CheckBoxMesh->isChecked())
486 mesh = aMeshEditor->TranslateObjectMakeMesh(mySelectedObject, aVector, makeGroups,
487 LineEditNewMesh->text().toLatin1().data());
489 mesh = aMeshEditor->TranslateMakeMesh(anElementsId, aVector, makeGroups,
490 LineEditNewMesh->text().toLatin1().data());
491 if( !mesh->_is_nil())
492 mesh->SetParameters(SMESHGUI::JoinObjectParameters(aParameters));
498 if ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() ||
499 actionButton == MAKE_MESH_BUTTON )
500 mySMESHGUI->updateObjBrowser(true); // new groups may appear
502 ConstructorsClicked(GetConstructorId());
503 mySelectedObject = SMESH::SMESH_IDSource::_nil();
504 SelectionIntoArgument();
510 //=================================================================================
511 // function : ClickOnOk()
513 //=================================================================================
514 void SMESHGUI_TranslationDlg::ClickOnOk()
520 //=================================================================================
521 // function : ClickOnCancel()
523 //=================================================================================
524 void SMESHGUI_TranslationDlg::ClickOnCancel()
526 disconnect(mySelectionMgr, 0, this, 0);
527 mySelectionMgr->clearFilters();
528 //mySelectionMgr->clearSelected();
529 SMESH::SetPointRepresentation(false);
530 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
531 aViewWindow->SetSelectionMode( ActorSelection );
532 mySMESHGUI->ResetState();
536 //=================================================================================
537 // function : ClickOnHelp()
539 //=================================================================================
540 void SMESHGUI_TranslationDlg::ClickOnHelp()
542 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
544 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
548 platform = "winapplication";
550 platform = "application";
552 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
553 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
554 arg(app->resourceMgr()->stringValue("ExternalBrowser",
556 arg(myHelpFileName));
560 //=======================================================================
561 // function : onTextChange()
563 //=======================================================================
564 void SMESHGUI_TranslationDlg::onTextChange (const QString& theNewText)
566 QLineEdit* send = (QLineEdit*)sender();
571 if (send == LineEditElements)
574 buttonOk->setEnabled(false);
575 buttonApply->setEnabled(false);
577 // hilight entered elements
578 SMDS_Mesh* aMesh = 0;
580 aMesh = myActor->GetObject()->GetMesh();
583 Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
585 TColStd_MapOfInteger newIndices;
587 QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
589 if (send == LineEditElements) {
590 for (int i = 0; i < aListId.count(); i++) {
591 const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
593 newIndices.Add(e->GetID());
598 mySelector->AddOrRemoveIndex( anIO, newIndices, false );
599 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
600 aViewWindow->highlight( anIO, true, true );
602 myElementsId = theNewText;
605 if (myNbOkElements) {
606 buttonOk->setEnabled(true);
607 buttonApply->setEnabled(true);
613 //=================================================================================
614 // function : SelectionIntoArgument()
615 // purpose : Called when selection as changed or other case
616 //=================================================================================
617 void SMESHGUI_TranslationDlg::SelectionIntoArgument()
623 QString aString = "";
626 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
627 LineEditElements->setText(aString);
629 buttonOk->setEnabled(false);
630 buttonApply->setEnabled(false);
634 if (!GroupButtons->isEnabled()) // inactive
639 mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
641 int nbSel = aList.Extent();
645 Handle(SALOME_InteractiveObject) IO = aList.First();
646 myMesh = SMESH::GetMeshByIO(IO);
647 if (myMesh->_is_nil())
650 myActor = SMESH::FindActorByObject(myMesh);
652 myActor = SMESH::FindActorByEntry(IO->getEntry());
658 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
661 // MakeGroups is available if there are groups and "Copy"
662 if ( myMesh->NbGroups() == 0 ) {
663 MakeGroupsCheck->setChecked(false);
664 MakeGroupsCheck->setEnabled(false);
666 else if ( ActionGroup->checkedId() != MOVE_ELEMS_BUTTON ) {
667 MakeGroupsCheck->setEnabled(true);
670 if (CheckBoxMesh->isChecked()) {
671 SMESH::GetNameOfSelectedIObjects( mySelectionMgr, aString );
673 if (!SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO)->_is_nil()) { //MESH, SUBMESH, OR GROUP
674 mySelectedObject = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO);
680 SMDS_Mesh* aSMDSMesh = myActor->GetObject()->GetMesh();
684 for (int i = aSMDSMesh->MinElementID(); i <= aSMDSMesh->MaxElementID(); i++) {
685 const SMDS_MeshElement * e = aSMDSMesh->FindElement(i);
687 myElementsId += QString(" %1").arg(i);
691 } else if (!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil()) { //SUBMESH
693 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO);
695 // get IDs from submesh
696 SMESH::long_array_var anElementsIds = new SMESH::long_array;
697 anElementsIds = aSubMesh->GetElementsId();
698 for (int i = 0; i < anElementsIds->length(); i++) {
699 myElementsId += QString(" %1").arg(anElementsIds[i]);
701 aNbUnits = anElementsIds->length();
704 SMESH::SMESH_GroupBase_var aGroup =
705 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
706 if (aGroup->_is_nil())
709 // get IDs from smesh group
710 SMESH::long_array_var anElementsIds = new SMESH::long_array;
711 anElementsIds = aGroup->GetListOfID();
712 for (int i = 0; i < anElementsIds->length(); i++) {
713 myElementsId += QString(" %1").arg(anElementsIds[i]);
715 aNbUnits = anElementsIds->length();
719 aNbUnits = SMESH::GetNameOfSelectedElements(mySelector, IO, aString);
720 myElementsId = aString;
725 myNbOkElements = true;
727 aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, IO, aString);
731 SMDS_Mesh* aMesh = myActor->GetObject()->GetMesh();
735 const SMDS_MeshNode * n = aMesh->FindNode(aString.toInt());
743 if (myEditCurrentArgument == (QWidget*)SpinBox1_1) {
744 SpinBox1_1->SetValue(x);
745 SpinBox1_2->SetValue(y);
746 SpinBox1_3->SetValue(z);
747 } else if (myEditCurrentArgument == (QWidget*)SpinBox2_1) {
748 SpinBox2_1->SetValue(x);
749 SpinBox2_2->SetValue(y);
750 SpinBox2_3->SetValue(z);
755 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
756 LineEditElements->setText(aString);
762 if (myNbOkElements) {
763 buttonOk->setEnabled(true);
764 buttonApply->setEnabled(true);
768 //=================================================================================
769 // function : SetEditCurrentArgument()
771 //=================================================================================
772 void SMESHGUI_TranslationDlg::SetEditCurrentArgument()
774 QPushButton* send = (QPushButton*)sender();
776 disconnect(mySelectionMgr, 0, this, 0);
777 mySelectionMgr->clearSelected();
778 mySelectionMgr->clearFilters();
780 if (send == SelectElementsButton) {
781 myEditCurrentArgument = (QWidget*)LineEditElements;
782 SMESH::SetPointRepresentation(false);
783 if (CheckBoxMesh->isChecked()) {
784 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
785 aViewWindow->SetSelectionMode( ActorSelection );
786 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
789 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
790 aViewWindow->SetSelectionMode( CellSelection );
792 } else if (send == SelectButton1) {
793 myEditCurrentArgument = (QWidget*)SpinBox1_1;
794 SMESH::SetPointRepresentation(true);
796 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
797 aViewWindow->SetSelectionMode( NodeSelection );
798 } else if (send == SelectButton2) {
799 myEditCurrentArgument = (QWidget*)SpinBox2_1;
800 SMESH::SetPointRepresentation(true);
802 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
803 aViewWindow->SetSelectionMode( NodeSelection );
806 myEditCurrentArgument->setFocus();
807 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
808 SelectionIntoArgument();
811 //=================================================================================
812 // function : DeactivateActiveDialog()
814 //=================================================================================
815 void SMESHGUI_TranslationDlg::DeactivateActiveDialog()
817 if (ConstructorsBox->isEnabled()) {
818 ConstructorsBox->setEnabled(false);
819 GroupArguments->setEnabled(false);
820 GroupButtons->setEnabled(false);
821 mySMESHGUI->ResetState();
822 mySMESHGUI->SetActiveDialogBox(0);
826 //=================================================================================
827 // function : ActivateThisDialog()
829 //=================================================================================
830 void SMESHGUI_TranslationDlg::ActivateThisDialog()
832 /* Emit a signal to deactivate the active dialog */
833 mySMESHGUI->EmitSignalDeactivateDialog();
834 ConstructorsBox->setEnabled(true);
835 GroupArguments->setEnabled(true);
836 GroupButtons->setEnabled(true);
838 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
840 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
841 aViewWindow->SetSelectionMode( CellSelection );
843 SelectionIntoArgument();
846 //=================================================================================
847 // function : enterEvent()
849 //=================================================================================
850 void SMESHGUI_TranslationDlg::enterEvent (QEvent*)
852 if (!ConstructorsBox->isEnabled())
853 ActivateThisDialog();
856 //=================================================================================
857 // function : closeEvent()
859 //=================================================================================
860 void SMESHGUI_TranslationDlg::closeEvent (QCloseEvent*)
862 /* same than click on cancel button */
866 //=======================================================================
867 //function : hideEvent
868 //purpose : caused by ESC key
869 //=======================================================================
870 void SMESHGUI_TranslationDlg::hideEvent (QHideEvent*)
876 //=======================================================================
877 //function : onSelectMesh
879 //=======================================================================
880 void SMESHGUI_TranslationDlg::onSelectMesh (bool toSelectMesh)
883 TextLabelElements->setText(tr("SMESH_NAME"));
885 TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
887 if (myEditCurrentArgument != LineEditElements) {
888 LineEditElements->clear();
892 mySelectionMgr->clearFilters();
893 SMESH::SetPointRepresentation(false);
896 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
897 aViewWindow->SetSelectionMode( ActorSelection );
898 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
899 LineEditElements->setReadOnly(true);
900 LineEditElements->setValidator(0);
902 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
903 aViewWindow->SetSelectionMode( CellSelection );
904 LineEditElements->setReadOnly(false);
905 LineEditElements->setValidator(myIdValidator);
906 onTextChange(LineEditElements->text());
909 SelectionIntoArgument();
912 //=======================================================================
913 //function : onActionClicked
914 //purpose : slot called when an action type changed
915 //=======================================================================
917 void SMESHGUI_TranslationDlg::onActionClicked(int button)
920 case MOVE_ELEMS_BUTTON:
921 MakeGroupsCheck->setEnabled(false);
922 LineEditNewMesh->setEnabled(false);
924 case COPY_ELEMS_BUTTON:
925 LineEditNewMesh->setEnabled(false);
926 MakeGroupsCheck->setText( tr("SMESH_MAKE_GROUPS"));
927 if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
928 MakeGroupsCheck->setEnabled(true);
930 MakeGroupsCheck->setEnabled(false);
932 case MAKE_MESH_BUTTON:
933 LineEditNewMesh->setEnabled(true);
934 MakeGroupsCheck->setText( tr("SMESH_COPY_GROUPS"));
935 if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
936 MakeGroupsCheck->setEnabled(true);
938 MakeGroupsCheck->setEnabled(false);
944 //=======================================================================
945 //function : setNewMeshName
946 //purpose : update contents of LineEditNewMesh
947 //=======================================================================
949 void SMESHGUI_TranslationDlg::setNewMeshName()
951 LineEditNewMesh->setText("");
952 if ( LineEditNewMesh->isEnabled() && !myMesh->_is_nil() ) {
954 if ( CheckBoxMesh->isChecked() ) {
955 name = LineEditElements->text();
958 _PTR(SObject) meshSO = SMESH::FindSObject( myMesh );
959 name = meshSO->GetName().c_str();
961 if ( !name.isEmpty() )
962 LineEditNewMesh->setText( SMESH::UniqueMeshName( name, "translated"));
966 //=================================================================================
967 // function : GetConstructorId()
969 //=================================================================================
970 int SMESHGUI_TranslationDlg::GetConstructorId()
972 return GroupConstructors->checkedId();
975 //=================================================================================
976 // function : keyPressEvent()
978 //=================================================================================
979 void SMESHGUI_TranslationDlg::keyPressEvent( QKeyEvent* e )
981 QDialog::keyPressEvent( e );
982 if ( e->isAccepted() )
985 if ( e->key() == Qt::Key_F1 ) {
991 //=================================================================================
992 // function : isValid
994 //=================================================================================
995 bool SMESHGUI_TranslationDlg::isValid()
1000 ok = SpinBox1_1->isValid( msg, true ) && ok;
1001 ok = SpinBox1_2->isValid( msg, true ) && ok;
1002 ok = SpinBox1_3->isValid( msg, true ) && ok;
1003 if (GetConstructorId() == 0) {
1004 ok = SpinBox2_1->isValid( msg, true ) && ok;
1005 ok = SpinBox2_2->isValid( msg, true ) && ok;
1006 ok = SpinBox2_3->isValid( msg, true ) && ok;
1010 QString str( tr( "SMESH_INCORRECT_INPUT" ) );
1011 if ( !msg.isEmpty() )
1013 SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );