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 ) ),
113 mySelectedObject(SMESH::SMESH_IDSource::_nil())
115 QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SMESH_TRANSLATION_POINTS")));
116 QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SMESH_TRANSLATION_VECTOR")));
117 QPixmap image2 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
120 setAttribute(Qt::WA_DeleteOnClose, true);
121 setWindowTitle(tr("SMESH_TRANSLATION"));
122 setSizeGripEnabled(true);
124 QVBoxLayout* SMESHGUI_TranslationDlgLayout = new QVBoxLayout(this);
125 SMESHGUI_TranslationDlgLayout->setSpacing(SPACING);
126 SMESHGUI_TranslationDlgLayout->setMargin(MARGIN);
128 /***************************************************************/
129 ConstructorsBox = new QGroupBox(tr("SMESH_TRANSLATION"), this);
130 GroupConstructors = new QButtonGroup(this);
131 QHBoxLayout* ConstructorsBoxLayout = new QHBoxLayout(ConstructorsBox);
132 ConstructorsBoxLayout->setSpacing(SPACING);
133 ConstructorsBoxLayout->setMargin(MARGIN);
135 RadioButton1= new QRadioButton(ConstructorsBox);
136 RadioButton1->setIcon(image0);
137 RadioButton2= new QRadioButton(ConstructorsBox);
138 RadioButton2->setIcon(image1);
140 ConstructorsBoxLayout->addWidget(RadioButton1);
141 ConstructorsBoxLayout->addWidget(RadioButton2);
142 GroupConstructors->addButton(RadioButton1, 0);
143 GroupConstructors->addButton(RadioButton2, 1);
145 /***************************************************************/
146 GroupArguments = new QGroupBox(tr("SMESH_ARGUMENTS"), this);
147 QGridLayout* GroupArgumentsLayout = new QGridLayout(GroupArguments);
148 GroupArgumentsLayout->setSpacing(SPACING);
149 GroupArgumentsLayout->setMargin(MARGIN);
151 myIdValidator = new SMESHGUI_IdValidator(this);
153 // Controls for elements selection
154 TextLabelElements = new QLabel(tr("SMESH_ID_ELEMENTS"), GroupArguments);
155 SelectElementsButton = new QPushButton(GroupArguments);
156 SelectElementsButton->setIcon(image2);
157 LineEditElements = new QLineEdit(GroupArguments);
158 LineEditElements->setValidator(myIdValidator);
159 myFilterBtn = new QPushButton( tr( "SMESH_BUT_FILTER" ), GroupArguments );
160 connect(myFilterBtn, SIGNAL(clicked()), this, SLOT(setFilters()));
162 // Control for the whole mesh selection
163 CheckBoxMesh = new QCheckBox(tr("SMESH_SELECT_WHOLE_MESH"), GroupArguments);
165 // Controls for vector and points selection
166 TextLabel1 = new QLabel(GroupArguments);
167 SelectButton1 = new QPushButton(GroupArguments);
168 SelectButton1->setIcon(image2);
170 TextLabel1_1 = new QLabel(GroupArguments);
171 SpinBox1_1 = new SMESHGUI_SpinBox(GroupArguments);
172 TextLabel1_2 = new QLabel(GroupArguments);
173 SpinBox1_2 = new SMESHGUI_SpinBox(GroupArguments);
174 TextLabel1_3 = new QLabel(GroupArguments);
175 SpinBox1_3 = new SMESHGUI_SpinBox(GroupArguments);
177 TextLabel2 = new QLabel(tr("SMESH_POINT_2"), GroupArguments);
178 SelectButton2 = new QPushButton(GroupArguments);
179 SelectButton2->setIcon(image2);
181 TextLabel2_1 = new QLabel(tr("SMESH_X"), GroupArguments);
182 SpinBox2_1 = new SMESHGUI_SpinBox(GroupArguments);
183 TextLabel2_2 = new QLabel(tr("SMESH_Y"), GroupArguments);
184 SpinBox2_2 = new SMESHGUI_SpinBox(GroupArguments);
185 TextLabel2_3 = new QLabel(tr("SMESH_Z"), GroupArguments);
186 SpinBox2_3 = new SMESHGUI_SpinBox(GroupArguments);
188 // switch of action type
189 ActionBox = new QGroupBox(GroupArguments);
190 ActionGroup = new QButtonGroup(GroupArguments);
191 QVBoxLayout* ActionBoxLayout = new QVBoxLayout(ActionBox);
192 ActionBoxLayout->addSpacing(SPACING);
193 ActionBoxLayout->setMargin(MARGIN);
195 QRadioButton* aMoveElements = new QRadioButton(tr("SMESH_MOVE_ELEMENTS"), ActionBox);
196 QRadioButton* aCopyElements = new QRadioButton(tr("SMESH_COPY_ELEMENTS"), ActionBox);
197 QRadioButton* aCreateMesh = new QRadioButton(tr("SMESH_CREATE_MESH"), ActionBox);
199 ActionBoxLayout->addWidget(aMoveElements);
200 ActionBoxLayout->addWidget(aCopyElements);
201 ActionBoxLayout->addWidget(aCreateMesh);
202 ActionGroup->addButton(aMoveElements, MOVE_ELEMS_BUTTON);
203 ActionGroup->addButton(aCopyElements, COPY_ELEMS_BUTTON);
204 ActionGroup->addButton(aCreateMesh, MAKE_MESH_BUTTON);
206 // CheckBox for groups generation
207 MakeGroupsCheck = new QCheckBox(tr("SMESH_MAKE_GROUPS"), GroupArguments);
208 MakeGroupsCheck->setChecked(false);
210 // Name of a mesh to create
211 LineEditNewMesh = new QLineEdit(GroupArguments);
214 GroupArgumentsLayout->addWidget(TextLabelElements, 0, 0);
215 GroupArgumentsLayout->addWidget(SelectElementsButton, 0, 1);
216 GroupArgumentsLayout->addWidget(LineEditElements, 0, 2, 1, 5);
217 GroupArgumentsLayout->addWidget(myFilterBtn, 0, 7);
218 GroupArgumentsLayout->addWidget(CheckBoxMesh, 1, 0, 1, 8);
219 GroupArgumentsLayout->addWidget(TextLabel1, 2, 0);
220 GroupArgumentsLayout->addWidget(SelectButton1, 2, 1);
221 GroupArgumentsLayout->addWidget(TextLabel1_1, 2, 2);
222 GroupArgumentsLayout->addWidget(SpinBox1_1, 2, 3);
223 GroupArgumentsLayout->addWidget(TextLabel1_2, 2, 4);
224 GroupArgumentsLayout->addWidget(SpinBox1_2, 2, 5);
225 GroupArgumentsLayout->addWidget(TextLabel1_3, 2, 6);
226 GroupArgumentsLayout->addWidget(SpinBox1_3, 2, 7);
227 GroupArgumentsLayout->addWidget(TextLabel2, 3, 0);
228 GroupArgumentsLayout->addWidget(SelectButton2, 3, 1);
229 GroupArgumentsLayout->addWidget(TextLabel2_1, 3, 2);
230 GroupArgumentsLayout->addWidget(SpinBox2_1, 3, 3);
231 GroupArgumentsLayout->addWidget(TextLabel2_2, 3, 4);
232 GroupArgumentsLayout->addWidget(SpinBox2_2, 3, 5);
233 GroupArgumentsLayout->addWidget(TextLabel2_3, 3, 6);
234 GroupArgumentsLayout->addWidget(SpinBox2_3, 3, 7);
235 GroupArgumentsLayout->addWidget(ActionBox, 4, 0, 3, 4);
236 GroupArgumentsLayout->addWidget(MakeGroupsCheck, 5, 5, 1, 4);
237 GroupArgumentsLayout->addWidget(LineEditNewMesh, 6, 5, 1, 4);
239 /***************************************************************/
240 GroupButtons = new QGroupBox(this);
241 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
242 GroupButtonsLayout->setSpacing(SPACING);
243 GroupButtonsLayout->setMargin(MARGIN);
245 buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
246 buttonOk->setAutoDefault(true);
247 buttonOk->setDefault(true);
248 buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
249 buttonApply->setAutoDefault(true);
250 buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
251 buttonCancel->setAutoDefault(true);
252 buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
253 buttonHelp->setAutoDefault(true);
255 GroupButtonsLayout->addWidget(buttonOk);
256 GroupButtonsLayout->addSpacing(10);
257 GroupButtonsLayout->addWidget(buttonApply);
258 GroupButtonsLayout->addSpacing(10);
259 GroupButtonsLayout->addStretch();
260 GroupButtonsLayout->addWidget(buttonCancel);
261 GroupButtonsLayout->addWidget(buttonHelp);
263 /***************************************************************/
264 SMESHGUI_TranslationDlgLayout->addWidget(ConstructorsBox);
265 SMESHGUI_TranslationDlgLayout->addWidget(GroupArguments);
266 SMESHGUI_TranslationDlgLayout->addWidget(GroupButtons);
268 /* Initialisations */
269 SpinBox1_1->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, DBL_DIGITS_DISPLAY);
270 SpinBox1_2->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, DBL_DIGITS_DISPLAY);
271 SpinBox1_3->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, DBL_DIGITS_DISPLAY);
272 SpinBox2_1->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, DBL_DIGITS_DISPLAY);
273 SpinBox2_2->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, DBL_DIGITS_DISPLAY);
274 SpinBox2_3->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, DBL_DIGITS_DISPLAY);
276 RadioButton1->setChecked(true);
278 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
280 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
282 // Costruction of the logical filter
283 SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter (MESHorSUBMESH);
284 SMESH_TypeFilter* aSmeshGroupFilter = new SMESH_TypeFilter (GROUP);
286 QList<SUIT_SelectionFilter*> aListOfFilters;
287 if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
288 if (aSmeshGroupFilter) aListOfFilters.append(aSmeshGroupFilter);
290 myMeshOrSubMeshOrGroupFilter =
291 new SMESH_LogicalFilter(aListOfFilters, SMESH_LogicalFilter::LO_OR);
293 myHelpFileName = "translation_page.html";
297 /* signals and slots connections */
298 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
299 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
300 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
301 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
302 connect(GroupConstructors, SIGNAL(buttonClicked(int)), SLOT(ConstructorsClicked(int)));
304 connect(SelectElementsButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
305 connect(SelectButton1, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
306 connect(SelectButton2, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
308 connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
309 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
310 /* to close dialog if study change */
311 connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
312 connect(LineEditElements, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
313 connect(CheckBoxMesh, SIGNAL(toggled(bool)), SLOT(onSelectMesh(bool)));
314 connect(ActionGroup, SIGNAL(buttonClicked(int)), SLOT(onActionClicked(int)));
316 ConstructorsClicked(0);
317 SelectionIntoArgument();
318 onActionClicked(MOVE_ELEMS_BUTTON);
321 //=================================================================================
322 // function : ~SMESHGUI_TranslationDlg()
323 // purpose : Destroys the object and frees any allocated resources
324 //=================================================================================
325 SMESHGUI_TranslationDlg::~SMESHGUI_TranslationDlg()
328 myFilterDlg->setParent( 0 );
334 //=================================================================================
337 //=================================================================================
338 void SMESHGUI_TranslationDlg::Init (bool ResetControls)
342 myEditCurrentArgument = 0;
343 LineEditElements->clear();
347 buttonOk->setEnabled(false);
348 buttonApply->setEnabled(false);
351 myMesh = SMESH::SMESH_Mesh::_nil();
354 SpinBox1_1->SetValue(0.0);
355 SpinBox1_2->SetValue(0.0);
356 SpinBox1_3->SetValue(0.0);
357 SpinBox2_1->SetValue(0.0);
358 SpinBox2_2->SetValue(0.0);
359 SpinBox2_3->SetValue(0.0);
361 ActionGroup->button( MOVE_ELEMS_BUTTON )->setChecked(true);
362 CheckBoxMesh->setChecked(false);
363 // MakeGroupsCheck->setChecked(false);
364 // MakeGroupsCheck->setEnabled(false);
369 //=================================================================================
370 // function : ConstructorsClicked()
371 // purpose : Radio button management
372 //=================================================================================
373 void SMESHGUI_TranslationDlg::ConstructorsClicked (int constructorId)
375 disconnect(mySelectionMgr, 0, this, 0);
377 switch (constructorId) {
380 TextLabel1->setText(tr("SMESH_POINT_1"));
381 TextLabel1_1->setText(tr("SMESH_X"));
382 TextLabel1_2->setText(tr("SMESH_Y"));
383 TextLabel1_3->setText(tr("SMESH_Z"));
385 SelectButton1->show();
387 SelectButton2->show();
388 TextLabel2_1->show();
390 TextLabel2_2->show();
392 TextLabel2_3->show();
398 TextLabel1->setText(tr("SMESH_VECTOR"));
399 TextLabel1_1->setText(tr("SMESH_DX"));
400 TextLabel1_2->setText(tr("SMESH_DY"));
401 TextLabel1_3->setText(tr("SMESH_DZ"));
403 SelectButton1->hide();
405 SelectButton2->hide();
406 TextLabel2_1->hide();
408 TextLabel2_2->hide();
410 TextLabel2_3->hide();
416 if (myEditCurrentArgument != (QWidget*)LineEditElements) {
417 SMESH::SetPointRepresentation(false);
418 if (!CheckBoxMesh->isChecked())
419 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
420 aViewWindow->SetSelectionMode( CellSelection );
423 myEditCurrentArgument = (QWidget*)LineEditElements;
424 LineEditElements->setFocus();
426 if (CheckBoxMesh->isChecked())
429 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
431 QApplication::instance()->processEvents();
433 resize( minimumSize() );
436 //=================================================================================
437 // function : ClickOnApply()
439 //=================================================================================
440 bool SMESHGUI_TranslationDlg::ClickOnApply()
442 if (mySMESHGUI->isActiveStudyLocked())
448 if (myNbOkElements) {
449 QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
451 SMESH::long_array_var anElementsId = new SMESH::long_array;
453 anElementsId->length(aListElementsId.count());
454 for (int i = 0; i < aListElementsId.count(); i++)
455 anElementsId[i] = aListElementsId[i].toInt();
457 SMESH::DirStruct aVector;
458 if (GetConstructorId() == 0) {
459 aVector.PS.x = SpinBox2_1->GetValue() - SpinBox1_1->GetValue();
460 aVector.PS.y = SpinBox2_2->GetValue() - SpinBox1_2->GetValue();
461 aVector.PS.z = SpinBox2_3->GetValue() - SpinBox1_3->GetValue();
462 } else if (GetConstructorId() == 1) {
463 aVector.PS.x = SpinBox1_1->GetValue();
464 aVector.PS.y = SpinBox1_2->GetValue();
465 aVector.PS.z = SpinBox1_3->GetValue();
468 QStringList aParameters;
469 aParameters << SpinBox1_1->text();
470 if (GetConstructorId() == 0)
471 aParameters << SpinBox2_1->text();
472 aParameters << SpinBox1_2->text();
473 if (GetConstructorId() == 0)
474 aParameters << SpinBox2_2->text();
475 aParameters << SpinBox1_3->text();
476 if (GetConstructorId() == 0)
477 aParameters << SpinBox2_3->text();
479 int actionButton = ActionGroup->checkedId();
480 bool makeGroups = ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() );
482 SUIT_OverrideCursor aWaitCursor;
483 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
484 switch ( actionButton ) {
485 case MOVE_ELEMS_BUTTON:
486 if(CheckBoxMesh->isChecked())
487 aMeshEditor->TranslateObject(mySelectedObject, aVector, false);
489 aMeshEditor->Translate(anElementsId, aVector, false);
490 if( !myMesh->_is_nil())
491 myMesh->SetParameters(SMESHGUI::JoinObjectParameters(aParameters));
493 case COPY_ELEMS_BUTTON:
495 SMESH::ListOfGroups_var groups;
496 if(CheckBoxMesh->isChecked())
497 groups = aMeshEditor->TranslateObjectMakeGroups(mySelectedObject,aVector);
499 groups = aMeshEditor->TranslateMakeGroups(anElementsId, aVector);
502 if(CheckBoxMesh->isChecked())
503 aMeshEditor->TranslateObject(mySelectedObject, aVector, true);
505 aMeshEditor->Translate(anElementsId, aVector, true);
507 if( !myMesh->_is_nil())
508 myMesh->SetParameters(SMESHGUI::JoinObjectParameters(aParameters));
510 case MAKE_MESH_BUTTON:
511 SMESH::SMESH_Mesh_var mesh;
512 if(CheckBoxMesh->isChecked())
513 mesh = aMeshEditor->TranslateObjectMakeMesh(mySelectedObject, aVector, makeGroups,
514 LineEditNewMesh->text().toLatin1().data());
516 mesh = aMeshEditor->TranslateMakeMesh(anElementsId, aVector, makeGroups,
517 LineEditNewMesh->text().toLatin1().data());
518 if( !mesh->_is_nil())
519 mesh->SetParameters(SMESHGUI::JoinObjectParameters(aParameters));
525 if ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() ||
526 actionButton == MAKE_MESH_BUTTON )
527 mySMESHGUI->updateObjBrowser(true); // new groups may appear
529 ConstructorsClicked(GetConstructorId());
530 mySelectedObject = SMESH::SMESH_IDSource::_nil();
531 SelectionIntoArgument();
537 //=================================================================================
538 // function : ClickOnOk()
540 //=================================================================================
541 void SMESHGUI_TranslationDlg::ClickOnOk()
547 //=================================================================================
548 // function : ClickOnCancel()
550 //=================================================================================
551 void SMESHGUI_TranslationDlg::ClickOnCancel()
553 disconnect(mySelectionMgr, 0, this, 0);
554 mySelectionMgr->clearFilters();
555 //mySelectionMgr->clearSelected();
556 if (SMESH::GetCurrentVtkView()) {
557 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
558 SMESH::SetPointRepresentation(false);
560 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
561 aViewWindow->SetSelectionMode( ActorSelection );
562 mySMESHGUI->ResetState();
566 //=================================================================================
567 // function : ClickOnHelp()
569 //=================================================================================
570 void SMESHGUI_TranslationDlg::ClickOnHelp()
572 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
574 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
578 platform = "winapplication";
580 platform = "application";
582 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
583 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
584 arg(app->resourceMgr()->stringValue("ExternalBrowser",
586 arg(myHelpFileName));
590 //=======================================================================
591 // function : onTextChange()
593 //=======================================================================
594 void SMESHGUI_TranslationDlg::onTextChange (const QString& theNewText)
596 QLineEdit* send = (QLineEdit*)sender();
599 BusyLocker lock( myBusy );
601 if (send == LineEditElements)
604 buttonOk->setEnabled(false);
605 buttonApply->setEnabled(false);
607 // hilight entered elements
608 SMDS_Mesh* aMesh = 0;
610 aMesh = myActor->GetObject()->GetMesh();
613 Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
615 TColStd_MapOfInteger newIndices;
617 QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
619 if (send == LineEditElements) {
620 for (int i = 0; i < aListId.count(); i++) {
621 const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
623 newIndices.Add(e->GetID());
628 mySelector->AddOrRemoveIndex( anIO, newIndices, false );
629 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
630 aViewWindow->highlight( anIO, true, true );
632 myElementsId = theNewText;
635 if (myNbOkElements) {
636 buttonOk->setEnabled(true);
637 buttonApply->setEnabled(true);
641 //=================================================================================
642 // function : SelectionIntoArgument()
643 // purpose : Called when selection as changed or other case
644 //=================================================================================
645 void SMESHGUI_TranslationDlg::SelectionIntoArgument()
648 BusyLocker lock( myBusy );
651 QString aString = "";
653 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
654 LineEditElements->setText(aString);
656 buttonOk->setEnabled(false);
657 buttonApply->setEnabled(false);
660 if (!GroupButtons->isEnabled()) // inactive
665 mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
667 int nbSel = aList.Extent();
671 Handle(SALOME_InteractiveObject) IO = aList.First();
672 myMesh = SMESH::GetMeshByIO(IO);
673 if (myMesh->_is_nil())
676 myActor = SMESH::FindActorByObject(myMesh);
678 myActor = SMESH::FindActorByEntry(IO->getEntry());
684 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
687 // MakeGroups is available if there are groups and "Copy"
688 if ( myMesh->NbGroups() == 0 ) {
689 MakeGroupsCheck->setChecked(false);
690 MakeGroupsCheck->setEnabled(false);
692 else if ( ActionGroup->checkedId() != MOVE_ELEMS_BUTTON ) {
693 MakeGroupsCheck->setEnabled(true);
696 if (CheckBoxMesh->isChecked()) {
697 SMESH::GetNameOfSelectedIObjects( mySelectionMgr, aString );
699 if (!SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO)->_is_nil()) { //MESH, SUBMESH, OR GROUP
700 mySelectedObject = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO);
706 SMDS_Mesh* aSMDSMesh = myActor->GetObject()->GetMesh();
710 for (int i = aSMDSMesh->MinElementID(); i <= aSMDSMesh->MaxElementID(); i++) {
711 const SMDS_MeshElement * e = aSMDSMesh->FindElement(i);
713 myElementsId += QString(" %1").arg(i);
717 } else if (!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil()) { //SUBMESH
719 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO);
721 // get IDs from submesh
722 SMESH::long_array_var anElementsIds = new SMESH::long_array;
723 anElementsIds = aSubMesh->GetElementsId();
724 for (int i = 0; i < anElementsIds->length(); i++) {
725 myElementsId += QString(" %1").arg(anElementsIds[i]);
727 aNbUnits = anElementsIds->length();
730 SMESH::SMESH_GroupBase_var aGroup =
731 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
732 if (aGroup->_is_nil())
735 // get IDs from smesh group
736 SMESH::long_array_var anElementsIds = new SMESH::long_array;
737 anElementsIds = aGroup->GetListOfID();
738 for (int i = 0; i < anElementsIds->length(); i++) {
739 myElementsId += QString(" %1").arg(anElementsIds[i]);
741 aNbUnits = anElementsIds->length();
745 aNbUnits = SMESH::GetNameOfSelectedElements(mySelector, IO, aString);
746 myElementsId = aString;
751 myNbOkElements = true;
753 aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, IO, aString);
757 SMDS_Mesh* aMesh = myActor->GetObject()->GetMesh();
761 const SMDS_MeshNode * n = aMesh->FindNode(aString.toInt());
769 if (myEditCurrentArgument == (QWidget*)SpinBox1_1) {
770 SpinBox1_1->SetValue(x);
771 SpinBox1_2->SetValue(y);
772 SpinBox1_3->SetValue(z);
773 } else if (myEditCurrentArgument == (QWidget*)SpinBox2_1) {
774 SpinBox2_1->SetValue(x);
775 SpinBox2_2->SetValue(y);
776 SpinBox2_3->SetValue(z);
780 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
781 LineEditElements->setText(aString);
782 LineEditElements->repaint();
783 LineEditElements->setEnabled(false); // to fully update lineedit IPAL 19809
784 LineEditElements->setEnabled(true);
789 if (myNbOkElements) {
790 buttonOk->setEnabled(true);
791 buttonApply->setEnabled(true);
795 //=================================================================================
796 // function : SetEditCurrentArgument()
798 //=================================================================================
799 void SMESHGUI_TranslationDlg::SetEditCurrentArgument()
801 QPushButton* send = (QPushButton*)sender();
803 disconnect(mySelectionMgr, 0, this, 0);
804 mySelectionMgr->clearSelected();
805 mySelectionMgr->clearFilters();
807 if (send == SelectElementsButton) {
808 myEditCurrentArgument = (QWidget*)LineEditElements;
809 SMESH::SetPointRepresentation(false);
810 if (CheckBoxMesh->isChecked()) {
811 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
812 aViewWindow->SetSelectionMode( ActorSelection );
813 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
816 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
817 aViewWindow->SetSelectionMode( CellSelection );
819 } else if (send == SelectButton1) {
820 myEditCurrentArgument = (QWidget*)SpinBox1_1;
821 SMESH::SetPointRepresentation(true);
823 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
824 aViewWindow->SetSelectionMode( NodeSelection );
825 } else if (send == SelectButton2) {
826 myEditCurrentArgument = (QWidget*)SpinBox2_1;
827 SMESH::SetPointRepresentation(true);
829 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
830 aViewWindow->SetSelectionMode( NodeSelection );
833 myEditCurrentArgument->setFocus();
834 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
835 SelectionIntoArgument();
838 //=================================================================================
839 // function : DeactivateActiveDialog()
841 //=================================================================================
842 void SMESHGUI_TranslationDlg::DeactivateActiveDialog()
844 if (ConstructorsBox->isEnabled()) {
845 ConstructorsBox->setEnabled(false);
846 GroupArguments->setEnabled(false);
847 GroupButtons->setEnabled(false);
848 mySMESHGUI->ResetState();
849 mySMESHGUI->SetActiveDialogBox(0);
853 //=================================================================================
854 // function : ActivateThisDialog()
856 //=================================================================================
857 void SMESHGUI_TranslationDlg::ActivateThisDialog()
859 /* Emit a signal to deactivate the active dialog */
860 mySMESHGUI->EmitSignalDeactivateDialog();
861 ConstructorsBox->setEnabled(true);
862 GroupArguments->setEnabled(true);
863 GroupButtons->setEnabled(true);
865 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
867 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
868 aViewWindow->SetSelectionMode( CellSelection );
870 SelectionIntoArgument();
873 //=================================================================================
874 // function : enterEvent()
876 //=================================================================================
877 void SMESHGUI_TranslationDlg::enterEvent (QEvent*)
879 if (!ConstructorsBox->isEnabled())
880 ActivateThisDialog();
883 //=================================================================================
884 // function : closeEvent()
886 //=================================================================================
887 void SMESHGUI_TranslationDlg::closeEvent (QCloseEvent*)
889 /* same than click on cancel button */
893 //=======================================================================
894 //function : hideEvent
895 //purpose : caused by ESC key
896 //=======================================================================
897 void SMESHGUI_TranslationDlg::hideEvent (QHideEvent*)
903 //=======================================================================
904 //function : onSelectMesh
906 //=======================================================================
907 void SMESHGUI_TranslationDlg::onSelectMesh (bool toSelectMesh)
910 TextLabelElements->setText(tr("SMESH_NAME"));
912 TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
913 myFilterBtn->setEnabled(!toSelectMesh);
915 if (myEditCurrentArgument != LineEditElements) {
916 LineEditElements->clear();
920 mySelectionMgr->clearFilters();
921 SMESH::SetPointRepresentation(false);
924 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
925 aViewWindow->SetSelectionMode( ActorSelection );
926 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
927 LineEditElements->setReadOnly(true);
928 LineEditElements->setValidator(0);
930 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
931 aViewWindow->SetSelectionMode( CellSelection );
932 LineEditElements->setReadOnly(false);
933 LineEditElements->setValidator(myIdValidator);
934 onTextChange(LineEditElements->text());
937 SelectionIntoArgument();
940 //=======================================================================
941 //function : onActionClicked
942 //purpose : slot called when an action type changed
943 //=======================================================================
945 void SMESHGUI_TranslationDlg::onActionClicked(int button)
948 case MOVE_ELEMS_BUTTON:
949 MakeGroupsCheck->setEnabled(false);
950 LineEditNewMesh->setEnabled(false);
952 case COPY_ELEMS_BUTTON:
953 LineEditNewMesh->setEnabled(false);
954 MakeGroupsCheck->setText( tr("SMESH_MAKE_GROUPS"));
955 if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
956 MakeGroupsCheck->setEnabled(true);
958 MakeGroupsCheck->setEnabled(false);
960 case MAKE_MESH_BUTTON:
961 LineEditNewMesh->setEnabled(true);
962 MakeGroupsCheck->setText( tr("SMESH_COPY_GROUPS"));
963 if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
964 MakeGroupsCheck->setEnabled(true);
966 MakeGroupsCheck->setEnabled(false);
972 //=======================================================================
973 //function : setNewMeshName
974 //purpose : update contents of LineEditNewMesh
975 //=======================================================================
977 void SMESHGUI_TranslationDlg::setNewMeshName()
979 LineEditNewMesh->setText("");
980 if ( LineEditNewMesh->isEnabled() && !myMesh->_is_nil() ) {
982 if ( CheckBoxMesh->isChecked() ) {
983 name = LineEditElements->text();
986 _PTR(SObject) meshSO = SMESH::FindSObject( myMesh );
987 name = meshSO->GetName().c_str();
989 if ( !name.isEmpty() )
990 LineEditNewMesh->setText( SMESH::UniqueMeshName( name, "translated"));
994 //=================================================================================
995 // function : GetConstructorId()
997 //=================================================================================
998 int SMESHGUI_TranslationDlg::GetConstructorId()
1000 return GroupConstructors->checkedId();
1003 //=================================================================================
1004 // function : keyPressEvent()
1006 //=================================================================================
1007 void SMESHGUI_TranslationDlg::keyPressEvent( QKeyEvent* e )
1009 QDialog::keyPressEvent( e );
1010 if ( e->isAccepted() )
1013 if ( e->key() == Qt::Key_F1 ) {
1019 //=================================================================================
1020 // function : setFilters()
1021 // purpose : SLOT. Called when "Filter" button pressed.
1022 //=================================================================================
1023 void SMESHGUI_TranslationDlg::setFilters()
1025 if(myMesh->_is_nil()) {
1026 SUIT_MessageBox::critical(this,
1028 tr("NO_MESH_SELECTED"));
1032 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, SMESH::ALL );
1034 myFilterDlg->SetSelection();
1035 myFilterDlg->SetMesh( myMesh );
1036 myFilterDlg->SetSourceWg( LineEditElements );
1038 myFilterDlg->show();
1041 //=================================================================================
1042 // function : isValid
1044 //=================================================================================
1045 bool SMESHGUI_TranslationDlg::isValid()
1050 ok = SpinBox1_1->isValid( msg, true ) && ok;
1051 ok = SpinBox1_2->isValid( msg, true ) && ok;
1052 ok = SpinBox1_3->isValid( msg, true ) && ok;
1053 if (GetConstructorId() == 0) {
1054 ok = SpinBox2_1->isValid( msg, true ) && ok;
1055 ok = SpinBox2_2->isValid( msg, true ) && ok;
1056 ok = SpinBox2_3->isValid( msg, true ) && ok;
1060 QString str( tr( "SMESH_INCORRECT_INPUT" ) );
1061 if ( !msg.isEmpty() )
1063 SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );