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 <SalomeApp_Notebook.h>
54 #include <SVTK_ViewModel.h>
55 #include <SVTK_ViewWindow.h>
56 #include <SALOME_ListIO.hxx>
58 // SALOME KERNEL includes
59 #include <SALOMEDSClient_SObject.hxx>
62 #include <TColStd_MapOfInteger.hxx>
65 #include <QApplication>
66 #include <QButtonGroup>
70 #include <QPushButton>
71 #include <QRadioButton>
73 #include <QHBoxLayout>
74 #include <QVBoxLayout>
75 #include <QGridLayout>
80 #include <SALOMEconfig.h>
81 #include CORBA_SERVER_HEADER(SMESH_Group)
82 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
84 enum { MOVE_ELEMS_BUTTON = 0, COPY_ELEMS_BUTTON, MAKE_MESH_BUTTON }; //!< action type
88 \brief Simple 'busy state' flag locker.
95 //! Constructor. Sets passed boolean flag to \c true.
96 BusyLocker( bool& busy ) : myBusy( busy ) { myBusy = true; }
97 //! Destructor. Clear external boolean flag passed as parameter to the constructor to \c false.
98 ~BusyLocker() { myBusy = false; }
100 bool& myBusy; //! External 'busy state' boolean flag
106 //=================================================================================
107 // class : SMESHGUI_TranslationDlg()
109 //=================================================================================
110 SMESHGUI_TranslationDlg::SMESHGUI_TranslationDlg( SMESHGUI* theModule )
111 : QDialog( SMESH::GetDesktop( theModule ) ),
112 SMESHGUI_Helper( theModule ),
113 mySMESHGUI( theModule ),
114 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
116 mySelectedObject(SMESH::SMESH_IDSource::_nil())
118 QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SMESH_TRANSLATION_POINTS")));
119 QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SMESH_TRANSLATION_VECTOR")));
120 QPixmap image2 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
123 setAttribute(Qt::WA_DeleteOnClose, true);
124 setWindowTitle(tr("SMESH_TRANSLATION"));
125 setSizeGripEnabled(true);
127 QVBoxLayout* SMESHGUI_TranslationDlgLayout = new QVBoxLayout(this);
128 SMESHGUI_TranslationDlgLayout->setSpacing(SPACING);
129 SMESHGUI_TranslationDlgLayout->setMargin(MARGIN);
131 /***************************************************************/
132 ConstructorsBox = new QGroupBox(tr("SMESH_TRANSLATION"), this);
133 GroupConstructors = new QButtonGroup(this);
134 QHBoxLayout* ConstructorsBoxLayout = new QHBoxLayout(ConstructorsBox);
135 ConstructorsBoxLayout->setSpacing(SPACING);
136 ConstructorsBoxLayout->setMargin(MARGIN);
138 RadioButton1= new QRadioButton(ConstructorsBox);
139 RadioButton1->setIcon(image0);
140 RadioButton2= new QRadioButton(ConstructorsBox);
141 RadioButton2->setIcon(image1);
143 ConstructorsBoxLayout->addWidget(RadioButton1);
144 ConstructorsBoxLayout->addWidget(RadioButton2);
145 GroupConstructors->addButton(RadioButton1, 0);
146 GroupConstructors->addButton(RadioButton2, 1);
148 /***************************************************************/
149 GroupArguments = new QGroupBox(tr("SMESH_ARGUMENTS"), this);
150 QGridLayout* GroupArgumentsLayout = new QGridLayout(GroupArguments);
151 GroupArgumentsLayout->setSpacing(SPACING);
152 GroupArgumentsLayout->setMargin(MARGIN);
154 myIdValidator = new SMESHGUI_IdValidator(this);
156 // Controls for elements selection
157 TextLabelElements = new QLabel(tr("SMESH_ID_ELEMENTS"), GroupArguments);
158 SelectElementsButton = new QPushButton(GroupArguments);
159 SelectElementsButton->setIcon(image2);
160 LineEditElements = new QLineEdit(GroupArguments);
161 LineEditElements->setValidator(myIdValidator);
162 myFilterBtn = new QPushButton( tr( "SMESH_BUT_FILTER" ), GroupArguments );
163 connect(myFilterBtn, SIGNAL(clicked()), this, SLOT(setFilters()));
165 // Control for the whole mesh selection
166 CheckBoxMesh = new QCheckBox(tr("SMESH_SELECT_WHOLE_MESH"), GroupArguments);
168 // Controls for vector and points selection
169 TextLabel1 = new QLabel(GroupArguments);
170 SelectButton1 = new QPushButton(GroupArguments);
171 SelectButton1->setIcon(image2);
173 TextLabel1_1 = new QLabel(GroupArguments);
174 SpinBox1_1 = new SMESHGUI_SpinBox(GroupArguments);
175 TextLabel1_2 = new QLabel(GroupArguments);
176 SpinBox1_2 = new SMESHGUI_SpinBox(GroupArguments);
177 TextLabel1_3 = new QLabel(GroupArguments);
178 SpinBox1_3 = new SMESHGUI_SpinBox(GroupArguments);
180 TextLabel2 = new QLabel(tr("SMESH_POINT_2"), GroupArguments);
181 SelectButton2 = new QPushButton(GroupArguments);
182 SelectButton2->setIcon(image2);
184 TextLabel2_1 = new QLabel(tr("SMESH_X"), GroupArguments);
185 SpinBox2_1 = new SMESHGUI_SpinBox(GroupArguments);
186 TextLabel2_2 = new QLabel(tr("SMESH_Y"), GroupArguments);
187 SpinBox2_2 = new SMESHGUI_SpinBox(GroupArguments);
188 TextLabel2_3 = new QLabel(tr("SMESH_Z"), GroupArguments);
189 SpinBox2_3 = new SMESHGUI_SpinBox(GroupArguments);
191 // switch of action type
192 ActionBox = new QGroupBox(GroupArguments);
193 ActionGroup = new QButtonGroup(GroupArguments);
194 QVBoxLayout* ActionBoxLayout = new QVBoxLayout(ActionBox);
195 ActionBoxLayout->addSpacing(SPACING);
196 ActionBoxLayout->setMargin(MARGIN);
198 QRadioButton* aMoveElements = new QRadioButton(tr("SMESH_MOVE_ELEMENTS"), ActionBox);
199 QRadioButton* aCopyElements = new QRadioButton(tr("SMESH_COPY_ELEMENTS"), ActionBox);
200 QRadioButton* aCreateMesh = new QRadioButton(tr("SMESH_CREATE_MESH"), ActionBox);
202 ActionBoxLayout->addWidget(aMoveElements);
203 ActionBoxLayout->addWidget(aCopyElements);
204 ActionBoxLayout->addWidget(aCreateMesh);
205 ActionGroup->addButton(aMoveElements, MOVE_ELEMS_BUTTON);
206 ActionGroup->addButton(aCopyElements, COPY_ELEMS_BUTTON);
207 ActionGroup->addButton(aCreateMesh, MAKE_MESH_BUTTON);
209 // CheckBox for groups generation
210 MakeGroupsCheck = new QCheckBox(tr("SMESH_MAKE_GROUPS"), GroupArguments);
211 MakeGroupsCheck->setChecked(false);
213 // Name of a mesh to create
214 LineEditNewMesh = new QLineEdit(GroupArguments);
217 GroupArgumentsLayout->addWidget(TextLabelElements, 0, 0);
218 GroupArgumentsLayout->addWidget(SelectElementsButton, 0, 1);
219 GroupArgumentsLayout->addWidget(LineEditElements, 0, 2, 1, 5);
220 GroupArgumentsLayout->addWidget(myFilterBtn, 0, 7);
221 GroupArgumentsLayout->addWidget(CheckBoxMesh, 1, 0, 1, 8);
222 GroupArgumentsLayout->addWidget(TextLabel1, 2, 0);
223 GroupArgumentsLayout->addWidget(SelectButton1, 2, 1);
224 GroupArgumentsLayout->addWidget(TextLabel1_1, 2, 2);
225 GroupArgumentsLayout->addWidget(SpinBox1_1, 2, 3);
226 GroupArgumentsLayout->addWidget(TextLabel1_2, 2, 4);
227 GroupArgumentsLayout->addWidget(SpinBox1_2, 2, 5);
228 GroupArgumentsLayout->addWidget(TextLabel1_3, 2, 6);
229 GroupArgumentsLayout->addWidget(SpinBox1_3, 2, 7);
230 GroupArgumentsLayout->addWidget(TextLabel2, 3, 0);
231 GroupArgumentsLayout->addWidget(SelectButton2, 3, 1);
232 GroupArgumentsLayout->addWidget(TextLabel2_1, 3, 2);
233 GroupArgumentsLayout->addWidget(SpinBox2_1, 3, 3);
234 GroupArgumentsLayout->addWidget(TextLabel2_2, 3, 4);
235 GroupArgumentsLayout->addWidget(SpinBox2_2, 3, 5);
236 GroupArgumentsLayout->addWidget(TextLabel2_3, 3, 6);
237 GroupArgumentsLayout->addWidget(SpinBox2_3, 3, 7);
238 GroupArgumentsLayout->addWidget(ActionBox, 4, 0, 3, 4);
239 GroupArgumentsLayout->addWidget(MakeGroupsCheck, 5, 5, 1, 4);
240 GroupArgumentsLayout->addWidget(LineEditNewMesh, 6, 5, 1, 4);
242 /***************************************************************/
243 GroupButtons = new QGroupBox(this);
244 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
245 GroupButtonsLayout->setSpacing(SPACING);
246 GroupButtonsLayout->setMargin(MARGIN);
248 buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
249 buttonOk->setAutoDefault(true);
250 buttonOk->setDefault(true);
251 buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
252 buttonApply->setAutoDefault(true);
253 buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
254 buttonCancel->setAutoDefault(true);
255 buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
256 buttonHelp->setAutoDefault(true);
258 GroupButtonsLayout->addWidget(buttonOk);
259 GroupButtonsLayout->addSpacing(10);
260 GroupButtonsLayout->addWidget(buttonApply);
261 GroupButtonsLayout->addSpacing(10);
262 GroupButtonsLayout->addStretch();
263 GroupButtonsLayout->addWidget(buttonCancel);
264 GroupButtonsLayout->addWidget(buttonHelp);
266 /***************************************************************/
267 SMESHGUI_TranslationDlgLayout->addWidget(ConstructorsBox);
268 SMESHGUI_TranslationDlgLayout->addWidget(GroupArguments);
269 SMESHGUI_TranslationDlgLayout->addWidget(GroupButtons);
271 /* Initialisations */
272 SpinBox1_1->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, DBL_DIGITS_DISPLAY);
273 SpinBox1_2->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, DBL_DIGITS_DISPLAY);
274 SpinBox1_3->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, DBL_DIGITS_DISPLAY);
275 SpinBox2_1->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, DBL_DIGITS_DISPLAY);
276 SpinBox2_2->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, DBL_DIGITS_DISPLAY);
277 SpinBox2_3->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, DBL_DIGITS_DISPLAY);
279 RadioButton1->setChecked(true);
281 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
283 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
285 // Costruction of the logical filter
286 SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter (MESHorSUBMESH);
287 SMESH_TypeFilter* aSmeshGroupFilter = new SMESH_TypeFilter (GROUP);
289 QList<SUIT_SelectionFilter*> aListOfFilters;
290 if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
291 if (aSmeshGroupFilter) aListOfFilters.append(aSmeshGroupFilter);
293 myMeshOrSubMeshOrGroupFilter =
294 new SMESH_LogicalFilter(aListOfFilters, SMESH_LogicalFilter::LO_OR);
296 myHelpFileName = "translation_page.html";
300 /* signals and slots connections */
301 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
302 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
303 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
304 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
305 connect(GroupConstructors, SIGNAL(buttonClicked(int)), SLOT(ConstructorsClicked(int)));
307 connect(SelectElementsButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
308 connect(SelectButton1, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
309 connect(SelectButton2, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
311 connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
312 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
313 /* to close dialog if study change */
314 connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
315 connect(LineEditElements, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
316 connect(CheckBoxMesh, SIGNAL(toggled(bool)), SLOT(onSelectMesh(bool)));
317 connect(ActionGroup, SIGNAL(buttonClicked(int)), SLOT(onActionClicked(int)));
319 ConstructorsClicked(0);
320 SelectionIntoArgument();
321 onActionClicked(MOVE_ELEMS_BUTTON);
324 //=================================================================================
325 // function : ~SMESHGUI_TranslationDlg()
326 // purpose : Destroys the object and frees any allocated resources
327 //=================================================================================
328 SMESHGUI_TranslationDlg::~SMESHGUI_TranslationDlg()
331 myFilterDlg->setParent( 0 );
337 //=================================================================================
340 //=================================================================================
341 void SMESHGUI_TranslationDlg::Init (bool ResetControls)
345 myEditCurrentArgument = 0;
346 LineEditElements->clear();
350 buttonOk->setEnabled(false);
351 buttonApply->setEnabled(false);
354 myMesh = SMESH::SMESH_Mesh::_nil();
357 SpinBox1_1->SetValue(0.0);
358 SpinBox1_2->SetValue(0.0);
359 SpinBox1_3->SetValue(0.0);
360 SpinBox2_1->SetValue(0.0);
361 SpinBox2_2->SetValue(0.0);
362 SpinBox2_3->SetValue(0.0);
364 ActionGroup->button( MOVE_ELEMS_BUTTON )->setChecked(true);
365 CheckBoxMesh->setChecked(false);
366 // MakeGroupsCheck->setChecked(false);
367 // MakeGroupsCheck->setEnabled(false);
372 //=================================================================================
373 // function : ConstructorsClicked()
374 // purpose : Radio button management
375 //=================================================================================
376 void SMESHGUI_TranslationDlg::ConstructorsClicked (int constructorId)
378 disconnect(mySelectionMgr, 0, this, 0);
380 switch (constructorId) {
383 TextLabel1->setText(tr("SMESH_POINT_1"));
384 TextLabel1_1->setText(tr("SMESH_X"));
385 TextLabel1_2->setText(tr("SMESH_Y"));
386 TextLabel1_3->setText(tr("SMESH_Z"));
388 SelectButton1->show();
390 SelectButton2->show();
391 TextLabel2_1->show();
393 TextLabel2_2->show();
395 TextLabel2_3->show();
401 TextLabel1->setText(tr("SMESH_VECTOR"));
402 TextLabel1_1->setText(tr("SMESH_DX"));
403 TextLabel1_2->setText(tr("SMESH_DY"));
404 TextLabel1_3->setText(tr("SMESH_DZ"));
406 SelectButton1->hide();
408 SelectButton2->hide();
409 TextLabel2_1->hide();
411 TextLabel2_2->hide();
413 TextLabel2_3->hide();
419 if (myEditCurrentArgument != (QWidget*)LineEditElements) {
420 SMESH::SetPointRepresentation(false);
421 if (!CheckBoxMesh->isChecked())
422 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
423 aViewWindow->SetSelectionMode( CellSelection );
426 myEditCurrentArgument = (QWidget*)LineEditElements;
427 LineEditElements->setFocus();
429 if (CheckBoxMesh->isChecked())
432 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
434 QApplication::instance()->processEvents();
439 //=================================================================================
440 // function : ClickOnApply()
442 //=================================================================================
443 bool SMESHGUI_TranslationDlg::ClickOnApply()
445 if (mySMESHGUI->isActiveStudyLocked())
451 if (myNbOkElements) {
452 QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
454 SMESH::long_array_var anElementsId = new SMESH::long_array;
456 anElementsId->length(aListElementsId.count());
457 for (int i = 0; i < aListElementsId.count(); i++)
458 anElementsId[i] = aListElementsId[i].toInt();
460 SMESH::DirStruct aVector;
461 if (GetConstructorId() == 0) {
462 aVector.PS.x = SpinBox2_1->GetValue() - SpinBox1_1->GetValue();
463 aVector.PS.y = SpinBox2_2->GetValue() - SpinBox1_2->GetValue();
464 aVector.PS.z = SpinBox2_3->GetValue() - SpinBox1_3->GetValue();
465 } else if (GetConstructorId() == 1) {
466 aVector.PS.x = SpinBox1_1->GetValue();
467 aVector.PS.y = SpinBox1_2->GetValue();
468 aVector.PS.z = SpinBox1_3->GetValue();
471 QStringList aParameters;
472 aParameters << SpinBox1_1->text();
473 if (GetConstructorId() == 0)
474 aParameters << SpinBox2_1->text();
475 aParameters << SpinBox1_2->text();
476 if (GetConstructorId() == 0)
477 aParameters << SpinBox2_2->text();
478 aParameters << SpinBox1_3->text();
479 if (GetConstructorId() == 0)
480 aParameters << SpinBox2_3->text();
482 int actionButton = ActionGroup->checkedId();
483 bool makeGroups = ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() );
485 SUIT_OverrideCursor aWaitCursor;
486 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
487 switch ( actionButton ) {
488 case MOVE_ELEMS_BUTTON:
489 if(CheckBoxMesh->isChecked())
490 aMeshEditor->TranslateObject(mySelectedObject, aVector, false);
492 aMeshEditor->Translate(anElementsId, aVector, false);
493 if( !myMesh->_is_nil())
494 getNotebook()->setParameters( myMesh, aParameters );
496 case COPY_ELEMS_BUTTON:
498 SMESH::ListOfGroups_var groups;
499 if(CheckBoxMesh->isChecked())
500 groups = aMeshEditor->TranslateObjectMakeGroups(mySelectedObject,aVector);
502 groups = aMeshEditor->TranslateMakeGroups(anElementsId, aVector);
505 if(CheckBoxMesh->isChecked())
506 aMeshEditor->TranslateObject(mySelectedObject, aVector, true);
508 aMeshEditor->Translate(anElementsId, aVector, true);
510 if( !myMesh->_is_nil())
511 getNotebook()->setParameters( myMesh, aParameters );
513 case MAKE_MESH_BUTTON:
514 SMESH::SMESH_Mesh_var mesh;
515 if(CheckBoxMesh->isChecked())
516 mesh = aMeshEditor->TranslateObjectMakeMesh(mySelectedObject, aVector, makeGroups,
517 LineEditNewMesh->text().toLatin1().data());
519 mesh = aMeshEditor->TranslateMakeMesh(anElementsId, aVector, makeGroups,
520 LineEditNewMesh->text().toLatin1().data());
521 if( !mesh->_is_nil())
522 getNotebook()->setParameters( mesh, aParameters );
528 if ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() ||
529 actionButton == MAKE_MESH_BUTTON )
530 mySMESHGUI->updateObjBrowser(true); // new groups may appear
532 ConstructorsClicked(GetConstructorId());
533 mySelectedObject = SMESH::SMESH_IDSource::_nil();
534 SelectionIntoArgument();
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());
687 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
690 // MakeGroups is available if there are groups and "Copy"
691 if ( myMesh->NbGroups() == 0 ) {
692 MakeGroupsCheck->setChecked(false);
693 MakeGroupsCheck->setEnabled(false);
695 else if ( ActionGroup->checkedId() != MOVE_ELEMS_BUTTON ) {
696 MakeGroupsCheck->setEnabled(true);
699 if (CheckBoxMesh->isChecked()) {
700 SMESH::GetNameOfSelectedIObjects( mySelectionMgr, aString );
702 if (!SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO)->_is_nil()) { //MESH, SUBMESH, OR GROUP
703 mySelectedObject = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO);
709 SMDS_Mesh* aSMDSMesh = myActor->GetObject()->GetMesh();
713 for (int i = aSMDSMesh->MinElementID(); i <= aSMDSMesh->MaxElementID(); i++) {
714 const SMDS_MeshElement * e = aSMDSMesh->FindElement(i);
716 myElementsId += QString(" %1").arg(i);
720 } else if (!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil()) { //SUBMESH
722 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO);
724 // get IDs from submesh
725 SMESH::long_array_var anElementsIds = new SMESH::long_array;
726 anElementsIds = aSubMesh->GetElementsId();
727 for (int i = 0; i < anElementsIds->length(); i++) {
728 myElementsId += QString(" %1").arg(anElementsIds[i]);
730 aNbUnits = anElementsIds->length();
733 SMESH::SMESH_GroupBase_var aGroup =
734 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
735 if (aGroup->_is_nil())
738 // get IDs from smesh group
739 SMESH::long_array_var anElementsIds = new SMESH::long_array;
740 anElementsIds = aGroup->GetListOfID();
741 for (int i = 0; i < anElementsIds->length(); i++) {
742 myElementsId += QString(" %1").arg(anElementsIds[i]);
744 aNbUnits = anElementsIds->length();
748 aNbUnits = SMESH::GetNameOfSelectedElements(mySelector, IO, aString);
749 myElementsId = aString;
754 myNbOkElements = true;
756 aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, IO, aString);
760 SMDS_Mesh* aMesh = myActor->GetObject()->GetMesh();
764 const SMDS_MeshNode * n = aMesh->FindNode(aString.toInt());
772 if (myEditCurrentArgument == (QWidget*)SpinBox1_1) {
773 SpinBox1_1->SetValue(x);
774 SpinBox1_2->SetValue(y);
775 SpinBox1_3->SetValue(z);
776 } else if (myEditCurrentArgument == (QWidget*)SpinBox2_1) {
777 SpinBox2_1->SetValue(x);
778 SpinBox2_2->SetValue(y);
779 SpinBox2_3->SetValue(z);
783 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
784 LineEditElements->setText(aString);
785 LineEditElements->repaint();
786 LineEditElements->setEnabled(false); // to fully update lineedit IPAL 19809
787 LineEditElements->setEnabled(true);
792 if (myNbOkElements) {
793 buttonOk->setEnabled(true);
794 buttonApply->setEnabled(true);
798 //=================================================================================
799 // function : SetEditCurrentArgument()
801 //=================================================================================
802 void SMESHGUI_TranslationDlg::SetEditCurrentArgument()
804 QPushButton* send = (QPushButton*)sender();
806 disconnect(mySelectionMgr, 0, this, 0);
807 mySelectionMgr->clearSelected();
808 mySelectionMgr->clearFilters();
810 if (send == SelectElementsButton) {
811 myEditCurrentArgument = (QWidget*)LineEditElements;
812 SMESH::SetPointRepresentation(false);
813 if (CheckBoxMesh->isChecked()) {
814 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
815 aViewWindow->SetSelectionMode( ActorSelection );
816 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
819 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
820 aViewWindow->SetSelectionMode( CellSelection );
822 } else if (send == SelectButton1) {
823 myEditCurrentArgument = (QWidget*)SpinBox1_1;
824 SMESH::SetPointRepresentation(true);
826 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
827 aViewWindow->SetSelectionMode( NodeSelection );
828 } else if (send == SelectButton2) {
829 myEditCurrentArgument = (QWidget*)SpinBox2_1;
830 SMESH::SetPointRepresentation(true);
832 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
833 aViewWindow->SetSelectionMode( NodeSelection );
836 myEditCurrentArgument->setFocus();
837 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
838 SelectionIntoArgument();
841 //=================================================================================
842 // function : DeactivateActiveDialog()
844 //=================================================================================
845 void SMESHGUI_TranslationDlg::DeactivateActiveDialog()
847 if (ConstructorsBox->isEnabled()) {
848 ConstructorsBox->setEnabled(false);
849 GroupArguments->setEnabled(false);
850 GroupButtons->setEnabled(false);
851 mySMESHGUI->ResetState();
852 mySMESHGUI->SetActiveDialogBox(0);
856 //=================================================================================
857 // function : ActivateThisDialog()
859 //=================================================================================
860 void SMESHGUI_TranslationDlg::ActivateThisDialog()
862 /* Emit a signal to deactivate the active dialog */
863 mySMESHGUI->EmitSignalDeactivateDialog();
864 ConstructorsBox->setEnabled(true);
865 GroupArguments->setEnabled(true);
866 GroupButtons->setEnabled(true);
868 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
870 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
871 aViewWindow->SetSelectionMode( CellSelection );
873 SelectionIntoArgument();
876 //=================================================================================
877 // function : enterEvent()
879 //=================================================================================
880 void SMESHGUI_TranslationDlg::enterEvent (QEvent*)
882 if (!ConstructorsBox->isEnabled())
883 ActivateThisDialog();
886 //=================================================================================
887 // function : closeEvent()
889 //=================================================================================
890 void SMESHGUI_TranslationDlg::closeEvent (QCloseEvent*)
892 /* same than click on cancel button */
896 //=======================================================================
897 //function : hideEvent
898 //purpose : caused by ESC key
899 //=======================================================================
900 void SMESHGUI_TranslationDlg::hideEvent (QHideEvent*)
906 //=======================================================================
907 //function : onSelectMesh
909 //=======================================================================
910 void SMESHGUI_TranslationDlg::onSelectMesh (bool toSelectMesh)
913 TextLabelElements->setText(tr("SMESH_NAME"));
915 TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
916 myFilterBtn->setEnabled(!toSelectMesh);
918 if (myEditCurrentArgument != LineEditElements) {
919 LineEditElements->clear();
923 mySelectionMgr->clearFilters();
924 SMESH::SetPointRepresentation(false);
927 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
928 aViewWindow->SetSelectionMode( ActorSelection );
929 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
930 LineEditElements->setReadOnly(true);
931 LineEditElements->setValidator(0);
933 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
934 aViewWindow->SetSelectionMode( CellSelection );
935 LineEditElements->setReadOnly(false);
936 LineEditElements->setValidator(myIdValidator);
937 onTextChange(LineEditElements->text());
940 SelectionIntoArgument();
943 //=======================================================================
944 //function : onActionClicked
945 //purpose : slot called when an action type changed
946 //=======================================================================
948 void SMESHGUI_TranslationDlg::onActionClicked(int button)
951 case MOVE_ELEMS_BUTTON:
952 MakeGroupsCheck->setEnabled(false);
953 LineEditNewMesh->setEnabled(false);
955 case COPY_ELEMS_BUTTON:
956 LineEditNewMesh->setEnabled(false);
957 MakeGroupsCheck->setText( tr("SMESH_MAKE_GROUPS"));
958 if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
959 MakeGroupsCheck->setEnabled(true);
961 MakeGroupsCheck->setEnabled(false);
963 case MAKE_MESH_BUTTON:
964 LineEditNewMesh->setEnabled(true);
965 MakeGroupsCheck->setText( tr("SMESH_COPY_GROUPS"));
966 if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
967 MakeGroupsCheck->setEnabled(true);
969 MakeGroupsCheck->setEnabled(false);
975 //=======================================================================
976 //function : setNewMeshName
977 //purpose : update contents of LineEditNewMesh
978 //=======================================================================
980 void SMESHGUI_TranslationDlg::setNewMeshName()
982 LineEditNewMesh->setText("");
983 if ( LineEditNewMesh->isEnabled() && !myMesh->_is_nil() ) {
985 if ( CheckBoxMesh->isChecked() ) {
986 name = LineEditElements->text();
989 _PTR(SObject) meshSO = SMESH::FindSObject( myMesh );
990 name = meshSO->GetName().c_str();
992 if ( !name.isEmpty() )
993 LineEditNewMesh->setText( SMESH::UniqueMeshName( name, "translated"));
997 //=================================================================================
998 // function : GetConstructorId()
1000 //=================================================================================
1001 int SMESHGUI_TranslationDlg::GetConstructorId()
1003 return GroupConstructors->checkedId();
1006 //=================================================================================
1007 // function : keyPressEvent()
1009 //=================================================================================
1010 void SMESHGUI_TranslationDlg::keyPressEvent( QKeyEvent* e )
1012 QDialog::keyPressEvent( e );
1013 if ( e->isAccepted() )
1016 if ( e->key() == Qt::Key_F1 ) {
1022 //=================================================================================
1023 // function : setFilters()
1024 // purpose : SLOT. Called when "Filter" button pressed.
1025 //=================================================================================
1026 void SMESHGUI_TranslationDlg::setFilters()
1028 if(myMesh->_is_nil()) {
1029 SUIT_MessageBox::critical(this,
1031 tr("NO_MESH_SELECTED"));
1035 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, SMESH::ALL );
1037 myFilterDlg->SetSelection();
1038 myFilterDlg->SetMesh( myMesh );
1039 myFilterDlg->SetSourceWg( LineEditElements );
1041 myFilterDlg->show();
1044 //=================================================================================
1045 // function : isValid
1047 //=================================================================================
1048 bool SMESHGUI_TranslationDlg::isValid()
1050 QList<QAbstractSpinBox*> aSpinBoxList;
1051 aSpinBoxList << SpinBox1_1 << SpinBox1_2 << SpinBox1_3;
1052 if( GetConstructorId() == 0 )
1053 aSpinBoxList << SpinBox2_1 << SpinBox2_2 << SpinBox2_3;
1054 return checkParameters( true, aSpinBoxList );