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 myFilterBtn = new QPushButton( tr( "SMESH_BUT_FILTER" ), GroupArguments );
161 connect(myFilterBtn, SIGNAL(clicked()), this, SLOT(setFilters()));
163 // Control for the whole mesh selection
164 CheckBoxMesh = new QCheckBox(tr("SMESH_SELECT_WHOLE_MESH"), GroupArguments);
166 // Controls for vector and points selection
167 TextLabel1 = new QLabel(GroupArguments);
168 SelectButton1 = new QPushButton(GroupArguments);
169 SelectButton1->setIcon(image2);
171 TextLabel1_1 = new QLabel(GroupArguments);
172 SpinBox1_1 = new SMESHGUI_SpinBox(GroupArguments);
173 TextLabel1_2 = new QLabel(GroupArguments);
174 SpinBox1_2 = new SMESHGUI_SpinBox(GroupArguments);
175 TextLabel1_3 = new QLabel(GroupArguments);
176 SpinBox1_3 = new SMESHGUI_SpinBox(GroupArguments);
178 TextLabel2 = new QLabel(tr("SMESH_POINT_2"), GroupArguments);
179 SelectButton2 = new QPushButton(GroupArguments);
180 SelectButton2->setIcon(image2);
182 TextLabel2_1 = new QLabel(tr("SMESH_X"), GroupArguments);
183 SpinBox2_1 = new SMESHGUI_SpinBox(GroupArguments);
184 TextLabel2_2 = new QLabel(tr("SMESH_Y"), GroupArguments);
185 SpinBox2_2 = new SMESHGUI_SpinBox(GroupArguments);
186 TextLabel2_3 = new QLabel(tr("SMESH_Z"), GroupArguments);
187 SpinBox2_3 = new SMESHGUI_SpinBox(GroupArguments);
189 // switch of action type
190 ActionBox = new QGroupBox(GroupArguments);
191 ActionGroup = new QButtonGroup(GroupArguments);
192 QVBoxLayout* ActionBoxLayout = new QVBoxLayout(ActionBox);
193 ActionBoxLayout->addSpacing(SPACING);
194 ActionBoxLayout->setMargin(MARGIN);
196 QRadioButton* aMoveElements = new QRadioButton(tr("SMESH_MOVE_ELEMENTS"), ActionBox);
197 QRadioButton* aCopyElements = new QRadioButton(tr("SMESH_COPY_ELEMENTS"), ActionBox);
198 QRadioButton* aCreateMesh = new QRadioButton(tr("SMESH_CREATE_MESH"), ActionBox);
200 ActionBoxLayout->addWidget(aMoveElements);
201 ActionBoxLayout->addWidget(aCopyElements);
202 ActionBoxLayout->addWidget(aCreateMesh);
203 ActionGroup->addButton(aMoveElements, MOVE_ELEMS_BUTTON);
204 ActionGroup->addButton(aCopyElements, COPY_ELEMS_BUTTON);
205 ActionGroup->addButton(aCreateMesh, MAKE_MESH_BUTTON);
207 // CheckBox for groups generation
208 MakeGroupsCheck = new QCheckBox(tr("SMESH_MAKE_GROUPS"), GroupArguments);
209 MakeGroupsCheck->setChecked(false);
211 // Name of a mesh to create
212 LineEditNewMesh = new QLineEdit(GroupArguments);
215 GroupArgumentsLayout->addWidget(TextLabelElements, 0, 0);
216 GroupArgumentsLayout->addWidget(SelectElementsButton, 0, 1);
217 GroupArgumentsLayout->addWidget(LineEditElements, 0, 2, 1, 5);
218 GroupArgumentsLayout->addWidget(myFilterBtn, 0, 7);
219 GroupArgumentsLayout->addWidget(CheckBoxMesh, 1, 0, 1, 8);
220 GroupArgumentsLayout->addWidget(TextLabel1, 2, 0);
221 GroupArgumentsLayout->addWidget(SelectButton1, 2, 1);
222 GroupArgumentsLayout->addWidget(TextLabel1_1, 2, 2);
223 GroupArgumentsLayout->addWidget(SpinBox1_1, 2, 3);
224 GroupArgumentsLayout->addWidget(TextLabel1_2, 2, 4);
225 GroupArgumentsLayout->addWidget(SpinBox1_2, 2, 5);
226 GroupArgumentsLayout->addWidget(TextLabel1_3, 2, 6);
227 GroupArgumentsLayout->addWidget(SpinBox1_3, 2, 7);
228 GroupArgumentsLayout->addWidget(TextLabel2, 3, 0);
229 GroupArgumentsLayout->addWidget(SelectButton2, 3, 1);
230 GroupArgumentsLayout->addWidget(TextLabel2_1, 3, 2);
231 GroupArgumentsLayout->addWidget(SpinBox2_1, 3, 3);
232 GroupArgumentsLayout->addWidget(TextLabel2_2, 3, 4);
233 GroupArgumentsLayout->addWidget(SpinBox2_2, 3, 5);
234 GroupArgumentsLayout->addWidget(TextLabel2_3, 3, 6);
235 GroupArgumentsLayout->addWidget(SpinBox2_3, 3, 7);
236 GroupArgumentsLayout->addWidget(ActionBox, 4, 0, 3, 4);
237 GroupArgumentsLayout->addWidget(MakeGroupsCheck, 5, 5, 1, 4);
238 GroupArgumentsLayout->addWidget(LineEditNewMesh, 6, 5, 1, 4);
240 /***************************************************************/
241 GroupButtons = new QGroupBox(this);
242 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
243 GroupButtonsLayout->setSpacing(SPACING);
244 GroupButtonsLayout->setMargin(MARGIN);
246 buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
247 buttonOk->setAutoDefault(true);
248 buttonOk->setDefault(true);
249 buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
250 buttonApply->setAutoDefault(true);
251 buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
252 buttonCancel->setAutoDefault(true);
253 buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
254 buttonHelp->setAutoDefault(true);
256 GroupButtonsLayout->addWidget(buttonOk);
257 GroupButtonsLayout->addSpacing(10);
258 GroupButtonsLayout->addWidget(buttonApply);
259 GroupButtonsLayout->addSpacing(10);
260 GroupButtonsLayout->addStretch();
261 GroupButtonsLayout->addWidget(buttonCancel);
262 GroupButtonsLayout->addWidget(buttonHelp);
264 /***************************************************************/
265 SMESHGUI_TranslationDlgLayout->addWidget(ConstructorsBox);
266 SMESHGUI_TranslationDlgLayout->addWidget(GroupArguments);
267 SMESHGUI_TranslationDlgLayout->addWidget(GroupButtons);
269 /* Initialisations */
270 SpinBox1_1->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
271 SpinBox1_2->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
272 SpinBox1_3->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
273 SpinBox2_1->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
274 SpinBox2_2->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
275 SpinBox2_3->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
277 RadioButton1->setChecked(true);
279 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
281 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
283 // Costruction of the logical filter
284 SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter (MESHorSUBMESH);
285 SMESH_TypeFilter* aSmeshGroupFilter = new SMESH_TypeFilter (GROUP);
287 QList<SUIT_SelectionFilter*> aListOfFilters;
288 if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
289 if (aSmeshGroupFilter) aListOfFilters.append(aSmeshGroupFilter);
291 myMeshOrSubMeshOrGroupFilter =
292 new SMESH_LogicalFilter(aListOfFilters, SMESH_LogicalFilter::LO_OR);
294 myHelpFileName = "translation_page.html";
298 /* signals and slots connections */
299 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
300 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
301 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
302 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
303 connect(GroupConstructors, SIGNAL(buttonClicked(int)), SLOT(ConstructorsClicked(int)));
305 connect(SelectElementsButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
306 connect(SelectButton1, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
307 connect(SelectButton2, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
309 connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
310 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
311 /* to close dialog if study change */
312 connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
313 connect(LineEditElements, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
314 connect(CheckBoxMesh, SIGNAL(toggled(bool)), SLOT(onSelectMesh(bool)));
315 connect(ActionGroup, SIGNAL(buttonClicked(int)), SLOT(onActionClicked(int)));
317 ConstructorsClicked(0);
318 SelectionIntoArgument();
319 onActionClicked(MOVE_ELEMS_BUTTON);
322 //=================================================================================
323 // function : ~SMESHGUI_TranslationDlg()
324 // purpose : Destroys the object and frees any allocated resources
325 //=================================================================================
326 SMESHGUI_TranslationDlg::~SMESHGUI_TranslationDlg()
329 myFilterDlg->setParent( 0 );
335 //=================================================================================
338 //=================================================================================
339 void SMESHGUI_TranslationDlg::Init (bool ResetControls)
343 myEditCurrentArgument = 0;
344 LineEditElements->clear();
348 buttonOk->setEnabled(false);
349 buttonApply->setEnabled(false);
352 myMesh = SMESH::SMESH_Mesh::_nil();
355 SpinBox1_1->SetValue(0.0);
356 SpinBox1_2->SetValue(0.0);
357 SpinBox1_3->SetValue(0.0);
358 SpinBox2_1->SetValue(0.0);
359 SpinBox2_2->SetValue(0.0);
360 SpinBox2_3->SetValue(0.0);
362 ActionGroup->button( MOVE_ELEMS_BUTTON )->setChecked(true);
363 CheckBoxMesh->setChecked(false);
364 // MakeGroupsCheck->setChecked(false);
365 // MakeGroupsCheck->setEnabled(false);
370 //=================================================================================
371 // function : ConstructorsClicked()
372 // purpose : Radio button management
373 //=================================================================================
374 void SMESHGUI_TranslationDlg::ConstructorsClicked (int constructorId)
376 disconnect(mySelectionMgr, 0, this, 0);
378 switch (constructorId) {
381 TextLabel1->setText(tr("SMESH_POINT_1"));
382 TextLabel1_1->setText(tr("SMESH_X"));
383 TextLabel1_2->setText(tr("SMESH_Y"));
384 TextLabel1_3->setText(tr("SMESH_Z"));
386 SelectButton1->show();
388 SelectButton2->show();
389 TextLabel2_1->show();
391 TextLabel2_2->show();
393 TextLabel2_3->show();
399 TextLabel1->setText(tr("SMESH_VECTOR"));
400 TextLabel1_1->setText(tr("SMESH_DX"));
401 TextLabel1_2->setText(tr("SMESH_DY"));
402 TextLabel1_3->setText(tr("SMESH_DZ"));
404 SelectButton1->hide();
406 SelectButton2->hide();
407 TextLabel2_1->hide();
409 TextLabel2_2->hide();
411 TextLabel2_3->hide();
417 if (myEditCurrentArgument != (QWidget*)LineEditElements) {
418 SMESH::SetPointRepresentation(false);
419 if (!CheckBoxMesh->isChecked())
420 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
421 aViewWindow->SetSelectionMode( CellSelection );
424 myEditCurrentArgument = (QWidget*)LineEditElements;
425 LineEditElements->setFocus();
427 if (CheckBoxMesh->isChecked())
430 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
432 QApplication::instance()->processEvents();
437 //=================================================================================
438 // function : ClickOnApply()
440 //=================================================================================
441 bool SMESHGUI_TranslationDlg::ClickOnApply()
443 if (mySMESHGUI->isActiveStudyLocked())
449 if (myNbOkElements) {
450 QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
452 SMESH::long_array_var anElementsId = new SMESH::long_array;
454 anElementsId->length(aListElementsId.count());
455 for (int i = 0; i < aListElementsId.count(); i++)
456 anElementsId[i] = aListElementsId[i].toInt();
458 SMESH::DirStruct aVector;
459 if (GetConstructorId() == 0) {
460 aVector.PS.x = SpinBox2_1->GetValue() - SpinBox1_1->GetValue();
461 aVector.PS.y = SpinBox2_2->GetValue() - SpinBox1_2->GetValue();
462 aVector.PS.z = SpinBox2_3->GetValue() - SpinBox1_3->GetValue();
463 } else if (GetConstructorId() == 1) {
464 aVector.PS.x = SpinBox1_1->GetValue();
465 aVector.PS.y = SpinBox1_2->GetValue();
466 aVector.PS.z = SpinBox1_3->GetValue();
469 QStringList aParameters;
470 aParameters << SpinBox1_1->text();
471 if (GetConstructorId() == 0)
472 aParameters << SpinBox2_1->text();
473 aParameters << SpinBox1_2->text();
474 if (GetConstructorId() == 0)
475 aParameters << SpinBox2_2->text();
476 aParameters << SpinBox1_3->text();
477 if (GetConstructorId() == 0)
478 aParameters << SpinBox2_3->text();
480 int actionButton = ActionGroup->checkedId();
481 bool makeGroups = ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() );
483 SUIT_OverrideCursor aWaitCursor;
484 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
485 switch ( actionButton ) {
486 case MOVE_ELEMS_BUTTON:
487 if(CheckBoxMesh->isChecked())
488 aMeshEditor->TranslateObject(mySelectedObject, aVector, false);
490 aMeshEditor->Translate(anElementsId, aVector, false);
491 if( !myMesh->_is_nil())
492 myMesh->SetParameters( aParameters.join(":").toLatin1().constData() );
494 case COPY_ELEMS_BUTTON:
496 SMESH::ListOfGroups_var groups;
497 if(CheckBoxMesh->isChecked())
498 groups = aMeshEditor->TranslateObjectMakeGroups(mySelectedObject,aVector);
500 groups = aMeshEditor->TranslateMakeGroups(anElementsId, aVector);
503 if(CheckBoxMesh->isChecked())
504 aMeshEditor->TranslateObject(mySelectedObject, aVector, true);
506 aMeshEditor->Translate(anElementsId, aVector, true);
508 if( !myMesh->_is_nil())
509 myMesh->SetParameters( aParameters.join(":").toLatin1().constData() );
511 case MAKE_MESH_BUTTON:
512 SMESH::SMESH_Mesh_var mesh;
513 if(CheckBoxMesh->isChecked())
514 mesh = aMeshEditor->TranslateObjectMakeMesh(mySelectedObject, aVector, makeGroups,
515 LineEditNewMesh->text().toLatin1().data());
517 mesh = aMeshEditor->TranslateMakeMesh(anElementsId, aVector, makeGroups,
518 LineEditNewMesh->text().toLatin1().data());
519 if( !mesh->_is_nil())
520 mesh->SetParameters( aParameters.join(":").toLatin1().constData() );
526 if ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() ||
527 actionButton == MAKE_MESH_BUTTON )
528 mySMESHGUI->updateObjBrowser(true); // new groups may appear
530 ConstructorsClicked(GetConstructorId());
531 mySelectedObject = SMESH::SMESH_IDSource::_nil();
532 SelectionIntoArgument();
534 SMESHGUI::Modified();
540 //=================================================================================
541 // function : ClickOnOk()
543 //=================================================================================
544 void SMESHGUI_TranslationDlg::ClickOnOk()
550 //=================================================================================
551 // function : ClickOnCancel()
553 //=================================================================================
554 void SMESHGUI_TranslationDlg::ClickOnCancel()
556 disconnect(mySelectionMgr, 0, this, 0);
557 mySelectionMgr->clearFilters();
558 //mySelectionMgr->clearSelected();
559 if (SMESH::GetCurrentVtkView()) {
560 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
561 SMESH::SetPointRepresentation(false);
563 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
564 aViewWindow->SetSelectionMode( ActorSelection );
565 mySMESHGUI->ResetState();
569 //=================================================================================
570 // function : ClickOnHelp()
572 //=================================================================================
573 void SMESHGUI_TranslationDlg::ClickOnHelp()
575 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
577 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
581 platform = "winapplication";
583 platform = "application";
585 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
586 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
587 arg(app->resourceMgr()->stringValue("ExternalBrowser",
589 arg(myHelpFileName));
593 //=======================================================================
594 // function : onTextChange()
596 //=======================================================================
597 void SMESHGUI_TranslationDlg::onTextChange (const QString& theNewText)
599 QLineEdit* send = (QLineEdit*)sender();
602 BusyLocker lock( myBusy );
604 if (send == LineEditElements)
607 buttonOk->setEnabled(false);
608 buttonApply->setEnabled(false);
610 // hilight entered elements
611 SMDS_Mesh* aMesh = 0;
613 aMesh = myActor->GetObject()->GetMesh();
616 Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
618 TColStd_MapOfInteger newIndices;
620 QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
622 if (send == LineEditElements) {
623 for (int i = 0; i < aListId.count(); i++) {
624 const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
626 newIndices.Add(e->GetID());
631 mySelector->AddOrRemoveIndex( anIO, newIndices, false );
632 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
633 aViewWindow->highlight( anIO, true, true );
635 myElementsId = theNewText;
638 if (myNbOkElements) {
639 buttonOk->setEnabled(true);
640 buttonApply->setEnabled(true);
644 //=================================================================================
645 // function : SelectionIntoArgument()
646 // purpose : Called when selection as changed or other case
647 //=================================================================================
648 void SMESHGUI_TranslationDlg::SelectionIntoArgument()
651 BusyLocker lock( myBusy );
654 QString aString = "";
656 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
657 LineEditElements->setText(aString);
659 buttonOk->setEnabled(false);
660 buttonApply->setEnabled(false);
663 if (!GroupButtons->isEnabled()) // inactive
668 mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
670 int nbSel = aList.Extent();
674 Handle(SALOME_InteractiveObject) IO = aList.First();
675 myMesh = SMESH::GetMeshByIO(IO);
676 if (myMesh->_is_nil())
679 myActor = SMESH::FindActorByObject(myMesh);
681 myActor = SMESH::FindActorByEntry(IO->getEntry());
683 if (!myActor && !CheckBoxMesh->isChecked())
688 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
691 // MakeGroups is available if there are groups and "Copy"
692 if ( myMesh->NbGroups() == 0 ) {
693 MakeGroupsCheck->setChecked(false);
694 MakeGroupsCheck->setEnabled(false);
696 else if ( ActionGroup->checkedId() != MOVE_ELEMS_BUTTON ) {
697 MakeGroupsCheck->setEnabled(true);
700 if (CheckBoxMesh->isChecked()) {
701 SMESH::GetNameOfSelectedIObjects( mySelectionMgr, aString );
703 if (!SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO)->_is_nil()) { //MESH, SUBMESH, OR GROUP
704 mySelectedObject = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO);
710 SMDS_Mesh* aSMDSMesh = myActor->GetObject()->GetMesh();
714 for (int i = aSMDSMesh->MinElementID(); i <= aSMDSMesh->MaxElementID(); i++) {
715 const SMDS_MeshElement * e = aSMDSMesh->FindElement(i);
717 myElementsId += QString(" %1").arg(i);
721 } else if (!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil()) { //SUBMESH
723 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO);
725 // get IDs from submesh
726 SMESH::long_array_var anElementsIds = new SMESH::long_array;
727 anElementsIds = aSubMesh->GetElementsId();
728 for (int i = 0; i < anElementsIds->length(); i++) {
729 myElementsId += QString(" %1").arg(anElementsIds[i]);
731 aNbUnits = anElementsIds->length();
734 SMESH::SMESH_GroupBase_var aGroup =
735 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
736 if (aGroup->_is_nil())
739 // get IDs from smesh group
740 SMESH::long_array_var anElementsIds = new SMESH::long_array;
741 anElementsIds = aGroup->GetListOfID();
742 for (int i = 0; i < anElementsIds->length(); i++) {
743 myElementsId += QString(" %1").arg(anElementsIds[i]);
745 aNbUnits = anElementsIds->length();
749 aNbUnits = SMESH::GetNameOfSelectedElements(mySelector, IO, aString);
750 myElementsId = aString;
755 myNbOkElements = true;
757 aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, IO, aString);
761 SMDS_Mesh* aMesh = myActor->GetObject()->GetMesh();
765 const SMDS_MeshNode * n = aMesh->FindNode(aString.toInt());
773 if (myEditCurrentArgument == (QWidget*)SpinBox1_1) {
774 SpinBox1_1->SetValue(x);
775 SpinBox1_2->SetValue(y);
776 SpinBox1_3->SetValue(z);
777 } else if (myEditCurrentArgument == (QWidget*)SpinBox2_1) {
778 SpinBox2_1->SetValue(x);
779 SpinBox2_2->SetValue(y);
780 SpinBox2_3->SetValue(z);
784 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
785 LineEditElements->setText(aString);
786 LineEditElements->repaint();
787 LineEditElements->setEnabled(false); // to fully update lineedit IPAL 19809
788 LineEditElements->setEnabled(true);
793 if (myNbOkElements) {
794 buttonOk->setEnabled(true);
795 buttonApply->setEnabled(true);
799 //=================================================================================
800 // function : SetEditCurrentArgument()
802 //=================================================================================
803 void SMESHGUI_TranslationDlg::SetEditCurrentArgument()
805 QPushButton* send = (QPushButton*)sender();
807 disconnect(mySelectionMgr, 0, this, 0);
808 mySelectionMgr->clearSelected();
809 mySelectionMgr->clearFilters();
811 if (send == SelectElementsButton) {
812 myEditCurrentArgument = (QWidget*)LineEditElements;
813 SMESH::SetPointRepresentation(false);
814 if (CheckBoxMesh->isChecked()) {
815 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
816 aViewWindow->SetSelectionMode( ActorSelection );
817 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
820 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
821 aViewWindow->SetSelectionMode( CellSelection );
823 } else if (send == SelectButton1) {
824 myEditCurrentArgument = (QWidget*)SpinBox1_1;
825 SMESH::SetPointRepresentation(true);
827 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
828 aViewWindow->SetSelectionMode( NodeSelection );
829 } else if (send == SelectButton2) {
830 myEditCurrentArgument = (QWidget*)SpinBox2_1;
831 SMESH::SetPointRepresentation(true);
833 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
834 aViewWindow->SetSelectionMode( NodeSelection );
837 myEditCurrentArgument->setFocus();
838 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
839 SelectionIntoArgument();
842 //=================================================================================
843 // function : DeactivateActiveDialog()
845 //=================================================================================
846 void SMESHGUI_TranslationDlg::DeactivateActiveDialog()
848 if (ConstructorsBox->isEnabled()) {
849 ConstructorsBox->setEnabled(false);
850 GroupArguments->setEnabled(false);
851 GroupButtons->setEnabled(false);
852 mySMESHGUI->ResetState();
853 mySMESHGUI->SetActiveDialogBox(0);
857 //=================================================================================
858 // function : ActivateThisDialog()
860 //=================================================================================
861 void SMESHGUI_TranslationDlg::ActivateThisDialog()
863 /* Emit a signal to deactivate the active dialog */
864 mySMESHGUI->EmitSignalDeactivateDialog();
865 ConstructorsBox->setEnabled(true);
866 GroupArguments->setEnabled(true);
867 GroupButtons->setEnabled(true);
869 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
871 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
872 aViewWindow->SetSelectionMode( CellSelection );
874 SelectionIntoArgument();
877 //=================================================================================
878 // function : enterEvent()
880 //=================================================================================
881 void SMESHGUI_TranslationDlg::enterEvent (QEvent*)
883 if (!ConstructorsBox->isEnabled())
884 ActivateThisDialog();
887 //=================================================================================
888 // function : closeEvent()
890 //=================================================================================
891 void SMESHGUI_TranslationDlg::closeEvent (QCloseEvent*)
893 /* same than click on cancel button */
897 //=======================================================================
898 //function : hideEvent
899 //purpose : caused by ESC key
900 //=======================================================================
901 void SMESHGUI_TranslationDlg::hideEvent (QHideEvent*)
907 //=======================================================================
908 //function : onSelectMesh
910 //=======================================================================
911 void SMESHGUI_TranslationDlg::onSelectMesh (bool toSelectMesh)
914 TextLabelElements->setText(tr("SMESH_NAME"));
916 TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
917 myFilterBtn->setEnabled(!toSelectMesh);
919 if (myEditCurrentArgument != LineEditElements) {
920 LineEditElements->clear();
924 mySelectionMgr->clearFilters();
925 SMESH::SetPointRepresentation(false);
928 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
929 aViewWindow->SetSelectionMode( ActorSelection );
930 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
931 LineEditElements->setReadOnly(true);
932 LineEditElements->setValidator(0);
934 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
935 aViewWindow->SetSelectionMode( CellSelection );
936 LineEditElements->setReadOnly(false);
937 LineEditElements->setValidator(myIdValidator);
938 onTextChange(LineEditElements->text());
941 SelectionIntoArgument();
944 //=======================================================================
945 //function : onActionClicked
946 //purpose : slot called when an action type changed
947 //=======================================================================
949 void SMESHGUI_TranslationDlg::onActionClicked(int button)
952 case MOVE_ELEMS_BUTTON:
953 MakeGroupsCheck->setEnabled(false);
954 LineEditNewMesh->setEnabled(false);
956 case COPY_ELEMS_BUTTON:
957 LineEditNewMesh->setEnabled(false);
958 MakeGroupsCheck->setText( tr("SMESH_MAKE_GROUPS"));
959 if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
960 MakeGroupsCheck->setEnabled(true);
962 MakeGroupsCheck->setEnabled(false);
964 case MAKE_MESH_BUTTON:
965 LineEditNewMesh->setEnabled(true);
966 MakeGroupsCheck->setText( tr("SMESH_COPY_GROUPS"));
967 if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
968 MakeGroupsCheck->setEnabled(true);
970 MakeGroupsCheck->setEnabled(false);
976 //=======================================================================
977 //function : setNewMeshName
978 //purpose : update contents of LineEditNewMesh
979 //=======================================================================
981 void SMESHGUI_TranslationDlg::setNewMeshName()
983 LineEditNewMesh->setText("");
984 if ( LineEditNewMesh->isEnabled() && !myMesh->_is_nil() ) {
986 if ( CheckBoxMesh->isChecked() ) {
987 name = LineEditElements->text();
990 _PTR(SObject) meshSO = SMESH::FindSObject( myMesh );
991 name = meshSO->GetName().c_str();
993 if ( !name.isEmpty() )
994 LineEditNewMesh->setText( SMESH::UniqueMeshName( name, "translated"));
998 //=================================================================================
999 // function : GetConstructorId()
1001 //=================================================================================
1002 int SMESHGUI_TranslationDlg::GetConstructorId()
1004 return GroupConstructors->checkedId();
1007 //=================================================================================
1008 // function : keyPressEvent()
1010 //=================================================================================
1011 void SMESHGUI_TranslationDlg::keyPressEvent( QKeyEvent* e )
1013 QDialog::keyPressEvent( e );
1014 if ( e->isAccepted() )
1017 if ( e->key() == Qt::Key_F1 ) {
1023 //=================================================================================
1024 // function : setFilters()
1025 // purpose : SLOT. Called when "Filter" button pressed.
1026 //=================================================================================
1027 void SMESHGUI_TranslationDlg::setFilters()
1029 if(myMesh->_is_nil()) {
1030 SUIT_MessageBox::critical(this,
1032 tr("NO_MESH_SELECTED"));
1036 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, SMESH::ALL );
1038 myFilterDlg->SetSelection();
1039 myFilterDlg->SetMesh( myMesh );
1040 myFilterDlg->SetSourceWg( LineEditElements );
1042 myFilterDlg->show();
1045 //=================================================================================
1046 // function : isValid
1048 //=================================================================================
1049 bool SMESHGUI_TranslationDlg::isValid()
1054 ok = SpinBox1_1->isValid( msg, true ) && ok;
1055 ok = SpinBox1_2->isValid( msg, true ) && ok;
1056 ok = SpinBox1_3->isValid( msg, true ) && ok;
1057 if (GetConstructorId() == 0) {
1058 ok = SpinBox2_1->isValid( msg, true ) && ok;
1059 ok = SpinBox2_2->isValid( msg, true ) && ok;
1060 ok = SpinBox2_3->isValid( msg, true ) && ok;
1064 QString str( tr( "SMESH_INCORRECT_INPUT" ) );
1065 if ( !msg.isEmpty() )
1067 SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );