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
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 //To disable automatic genericobj management, the following line should be commented.
105 //Otherwise, it should be uncommented. Refer to KERNEL_SRC/src/SALOMEDSImpl/SALOMEDSImpl_AttributeIOR.cxx
106 #define WITHGENERICOBJ
108 //=================================================================================
109 // class : SMESHGUI_TranslationDlg()
111 //=================================================================================
112 SMESHGUI_TranslationDlg::SMESHGUI_TranslationDlg( SMESHGUI* theModule )
113 : QDialog( SMESH::GetDesktop( theModule ) ),
114 mySMESHGUI( theModule ),
115 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
117 mySelectedObject(SMESH::SMESH_IDSource::_nil())
119 QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SMESH_TRANSLATION_POINTS")));
120 QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SMESH_TRANSLATION_VECTOR")));
121 QPixmap image2 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
124 setAttribute(Qt::WA_DeleteOnClose, true);
125 setWindowTitle(tr("SMESH_TRANSLATION"));
126 setSizeGripEnabled(true);
128 QVBoxLayout* SMESHGUI_TranslationDlgLayout = new QVBoxLayout(this);
129 SMESHGUI_TranslationDlgLayout->setSpacing(SPACING);
130 SMESHGUI_TranslationDlgLayout->setMargin(MARGIN);
132 /***************************************************************/
133 ConstructorsBox = new QGroupBox(tr("SMESH_TRANSLATION"), this);
134 GroupConstructors = new QButtonGroup(this);
135 QHBoxLayout* ConstructorsBoxLayout = new QHBoxLayout(ConstructorsBox);
136 ConstructorsBoxLayout->setSpacing(SPACING);
137 ConstructorsBoxLayout->setMargin(MARGIN);
139 RadioButton1= new QRadioButton(ConstructorsBox);
140 RadioButton1->setIcon(image0);
141 RadioButton2= new QRadioButton(ConstructorsBox);
142 RadioButton2->setIcon(image1);
144 ConstructorsBoxLayout->addWidget(RadioButton1);
145 ConstructorsBoxLayout->addWidget(RadioButton2);
146 GroupConstructors->addButton(RadioButton1, 0);
147 GroupConstructors->addButton(RadioButton2, 1);
149 /***************************************************************/
150 GroupArguments = new QGroupBox(tr("SMESH_ARGUMENTS"), this);
151 QGridLayout* GroupArgumentsLayout = new QGridLayout(GroupArguments);
152 GroupArgumentsLayout->setSpacing(SPACING);
153 GroupArgumentsLayout->setMargin(MARGIN);
155 myIdValidator = new SMESHGUI_IdValidator(this);
157 // Controls for elements selection
158 TextLabelElements = new QLabel(tr("SMESH_ID_ELEMENTS"), GroupArguments);
159 SelectElementsButton = new QPushButton(GroupArguments);
160 SelectElementsButton->setIcon(image2);
161 LineEditElements = new QLineEdit(GroupArguments);
162 LineEditElements->setValidator(myIdValidator);
163 LineEditElements->setMaxLength(-1);
164 myFilterBtn = new QPushButton( tr( "SMESH_BUT_FILTER" ), GroupArguments );
165 connect(myFilterBtn, SIGNAL(clicked()), this, SLOT(setFilters()));
167 // Control for the whole mesh selection
168 CheckBoxMesh = new QCheckBox(tr("SMESH_SELECT_WHOLE_MESH"), GroupArguments);
170 // Controls for vector and points selection
171 TextLabel1 = new QLabel(GroupArguments);
172 SelectButton1 = new QPushButton(GroupArguments);
173 SelectButton1->setIcon(image2);
175 TextLabel1_1 = new QLabel(GroupArguments);
176 SpinBox1_1 = new SMESHGUI_SpinBox(GroupArguments);
177 TextLabel1_2 = new QLabel(GroupArguments);
178 SpinBox1_2 = new SMESHGUI_SpinBox(GroupArguments);
179 TextLabel1_3 = new QLabel(GroupArguments);
180 SpinBox1_3 = new SMESHGUI_SpinBox(GroupArguments);
182 TextLabel2 = new QLabel(tr("SMESH_POINT_2"), GroupArguments);
183 SelectButton2 = new QPushButton(GroupArguments);
184 SelectButton2->setIcon(image2);
186 TextLabel2_1 = new QLabel(tr("SMESH_X"), GroupArguments);
187 SpinBox2_1 = new SMESHGUI_SpinBox(GroupArguments);
188 TextLabel2_2 = new QLabel(tr("SMESH_Y"), GroupArguments);
189 SpinBox2_2 = new SMESHGUI_SpinBox(GroupArguments);
190 TextLabel2_3 = new QLabel(tr("SMESH_Z"), GroupArguments);
191 SpinBox2_3 = new SMESHGUI_SpinBox(GroupArguments);
193 // switch of action type
194 ActionBox = new QGroupBox(GroupArguments);
195 ActionGroup = new QButtonGroup(GroupArguments);
196 QVBoxLayout* ActionBoxLayout = new QVBoxLayout(ActionBox);
197 ActionBoxLayout->addSpacing(SPACING);
198 ActionBoxLayout->setMargin(MARGIN);
200 QRadioButton* aMoveElements = new QRadioButton(tr("SMESH_MOVE_ELEMENTS"), ActionBox);
201 QRadioButton* aCopyElements = new QRadioButton(tr("SMESH_COPY_ELEMENTS"), ActionBox);
202 QRadioButton* aCreateMesh = new QRadioButton(tr("SMESH_CREATE_MESH"), ActionBox);
204 ActionBoxLayout->addWidget(aMoveElements);
205 ActionBoxLayout->addWidget(aCopyElements);
206 ActionBoxLayout->addWidget(aCreateMesh);
207 ActionGroup->addButton(aMoveElements, MOVE_ELEMS_BUTTON);
208 ActionGroup->addButton(aCopyElements, COPY_ELEMS_BUTTON);
209 ActionGroup->addButton(aCreateMesh, MAKE_MESH_BUTTON);
211 // CheckBox for groups generation
212 MakeGroupsCheck = new QCheckBox(tr("SMESH_MAKE_GROUPS"), GroupArguments);
213 MakeGroupsCheck->setChecked(false);
215 // Name of a mesh to create
216 LineEditNewMesh = new QLineEdit(GroupArguments);
219 GroupArgumentsLayout->addWidget(TextLabelElements, 0, 0);
220 GroupArgumentsLayout->addWidget(SelectElementsButton, 0, 1);
221 GroupArgumentsLayout->addWidget(LineEditElements, 0, 2, 1, 5);
222 GroupArgumentsLayout->addWidget(myFilterBtn, 0, 7);
223 GroupArgumentsLayout->addWidget(CheckBoxMesh, 1, 0, 1, 8);
224 GroupArgumentsLayout->addWidget(TextLabel1, 2, 0);
225 GroupArgumentsLayout->addWidget(SelectButton1, 2, 1);
226 GroupArgumentsLayout->addWidget(TextLabel1_1, 2, 2);
227 GroupArgumentsLayout->addWidget(SpinBox1_1, 2, 3);
228 GroupArgumentsLayout->addWidget(TextLabel1_2, 2, 4);
229 GroupArgumentsLayout->addWidget(SpinBox1_2, 2, 5);
230 GroupArgumentsLayout->addWidget(TextLabel1_3, 2, 6);
231 GroupArgumentsLayout->addWidget(SpinBox1_3, 2, 7);
232 GroupArgumentsLayout->addWidget(TextLabel2, 3, 0);
233 GroupArgumentsLayout->addWidget(SelectButton2, 3, 1);
234 GroupArgumentsLayout->addWidget(TextLabel2_1, 3, 2);
235 GroupArgumentsLayout->addWidget(SpinBox2_1, 3, 3);
236 GroupArgumentsLayout->addWidget(TextLabel2_2, 3, 4);
237 GroupArgumentsLayout->addWidget(SpinBox2_2, 3, 5);
238 GroupArgumentsLayout->addWidget(TextLabel2_3, 3, 6);
239 GroupArgumentsLayout->addWidget(SpinBox2_3, 3, 7);
240 GroupArgumentsLayout->addWidget(ActionBox, 4, 0, 3, 4);
241 GroupArgumentsLayout->addWidget(MakeGroupsCheck, 5, 5, 1, 4);
242 GroupArgumentsLayout->addWidget(LineEditNewMesh, 6, 5, 1, 4);
244 /***************************************************************/
245 GroupButtons = new QGroupBox(this);
246 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
247 GroupButtonsLayout->setSpacing(SPACING);
248 GroupButtonsLayout->setMargin(MARGIN);
250 buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
251 buttonOk->setAutoDefault(true);
252 buttonOk->setDefault(true);
253 buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
254 buttonApply->setAutoDefault(true);
255 buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
256 buttonCancel->setAutoDefault(true);
257 buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
258 buttonHelp->setAutoDefault(true);
260 GroupButtonsLayout->addWidget(buttonOk);
261 GroupButtonsLayout->addSpacing(10);
262 GroupButtonsLayout->addWidget(buttonApply);
263 GroupButtonsLayout->addSpacing(10);
264 GroupButtonsLayout->addStretch();
265 GroupButtonsLayout->addWidget(buttonCancel);
266 GroupButtonsLayout->addWidget(buttonHelp);
268 /***************************************************************/
269 SMESHGUI_TranslationDlgLayout->addWidget(ConstructorsBox);
270 SMESHGUI_TranslationDlgLayout->addWidget(GroupArguments);
271 SMESHGUI_TranslationDlgLayout->addWidget(GroupButtons);
273 /* Initialisations */
274 SpinBox1_1->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
275 SpinBox1_2->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
276 SpinBox1_3->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
277 SpinBox2_1->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
278 SpinBox2_2->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
279 SpinBox2_3->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
281 RadioButton1->setChecked(true);
283 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
285 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
287 // Costruction of the logical filter
288 SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter (MESHorSUBMESH);
289 SMESH_TypeFilter* aSmeshGroupFilter = new SMESH_TypeFilter (GROUP);
291 QList<SUIT_SelectionFilter*> aListOfFilters;
292 if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
293 if (aSmeshGroupFilter) aListOfFilters.append(aSmeshGroupFilter);
295 myMeshOrSubMeshOrGroupFilter =
296 new SMESH_LogicalFilter(aListOfFilters, SMESH_LogicalFilter::LO_OR);
298 myHelpFileName = "translation_page.html";
302 /* signals and slots connections */
303 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
304 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
305 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
306 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
307 connect(GroupConstructors, SIGNAL(buttonClicked(int)), SLOT(ConstructorsClicked(int)));
309 connect(SelectElementsButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
310 connect(SelectButton1, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
311 connect(SelectButton2, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
313 connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
314 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
315 /* to close dialog if study change */
316 connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
317 connect(LineEditElements, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
318 connect(CheckBoxMesh, SIGNAL(toggled(bool)), SLOT(onSelectMesh(bool)));
319 connect(ActionGroup, SIGNAL(buttonClicked(int)), SLOT(onActionClicked(int)));
321 ConstructorsClicked(0);
322 SelectionIntoArgument();
323 onActionClicked(MOVE_ELEMS_BUTTON);
326 //=================================================================================
327 // function : ~SMESHGUI_TranslationDlg()
328 // purpose : Destroys the object and frees any allocated resources
329 //=================================================================================
330 SMESHGUI_TranslationDlg::~SMESHGUI_TranslationDlg()
333 myFilterDlg->setParent( 0 );
339 //=================================================================================
342 //=================================================================================
343 void SMESHGUI_TranslationDlg::Init (bool ResetControls)
347 myEditCurrentArgument = 0;
348 LineEditElements->clear();
352 buttonOk->setEnabled(false);
353 buttonApply->setEnabled(false);
356 myMesh = SMESH::SMESH_Mesh::_nil();
359 SpinBox1_1->SetValue(0.0);
360 SpinBox1_2->SetValue(0.0);
361 SpinBox1_3->SetValue(0.0);
362 SpinBox2_1->SetValue(0.0);
363 SpinBox2_2->SetValue(0.0);
364 SpinBox2_3->SetValue(0.0);
366 ActionGroup->button( MOVE_ELEMS_BUTTON )->setChecked(true);
367 CheckBoxMesh->setChecked(false);
368 // MakeGroupsCheck->setChecked(false);
369 // MakeGroupsCheck->setEnabled(false);
374 //=================================================================================
375 // function : ConstructorsClicked()
376 // purpose : Radio button management
377 //=================================================================================
378 void SMESHGUI_TranslationDlg::ConstructorsClicked (int constructorId)
380 disconnect(mySelectionMgr, 0, this, 0);
382 switch (constructorId) {
385 TextLabel1->setText(tr("SMESH_POINT_1"));
386 TextLabel1_1->setText(tr("SMESH_X"));
387 TextLabel1_2->setText(tr("SMESH_Y"));
388 TextLabel1_3->setText(tr("SMESH_Z"));
390 SelectButton1->show();
392 SelectButton2->show();
393 TextLabel2_1->show();
395 TextLabel2_2->show();
397 TextLabel2_3->show();
403 TextLabel1->setText(tr("SMESH_VECTOR"));
404 TextLabel1_1->setText(tr("SMESH_DX"));
405 TextLabel1_2->setText(tr("SMESH_DY"));
406 TextLabel1_3->setText(tr("SMESH_DZ"));
408 SelectButton1->hide();
410 SelectButton2->hide();
411 TextLabel2_1->hide();
413 TextLabel2_2->hide();
415 TextLabel2_3->hide();
421 if (myEditCurrentArgument != (QWidget*)LineEditElements) {
422 SMESH::SetPointRepresentation(false);
423 if (!CheckBoxMesh->isChecked())
424 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
425 aViewWindow->SetSelectionMode( CellSelection );
428 myEditCurrentArgument = (QWidget*)LineEditElements;
429 LineEditElements->setFocus();
431 if (CheckBoxMesh->isChecked())
434 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
436 QApplication::instance()->processEvents();
441 //=================================================================================
442 // function : ClickOnApply()
444 //=================================================================================
445 bool SMESHGUI_TranslationDlg::ClickOnApply()
447 if (mySMESHGUI->isActiveStudyLocked())
453 if (myNbOkElements) {
454 QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
456 SMESH::long_array_var anElementsId = new SMESH::long_array;
458 anElementsId->length(aListElementsId.count());
459 for (int i = 0; i < aListElementsId.count(); i++)
460 anElementsId[i] = aListElementsId[i].toInt();
462 SMESH::DirStruct aVector;
463 if (GetConstructorId() == 0) {
464 aVector.PS.x = SpinBox2_1->GetValue() - SpinBox1_1->GetValue();
465 aVector.PS.y = SpinBox2_2->GetValue() - SpinBox1_2->GetValue();
466 aVector.PS.z = SpinBox2_3->GetValue() - SpinBox1_3->GetValue();
467 } else if (GetConstructorId() == 1) {
468 aVector.PS.x = SpinBox1_1->GetValue();
469 aVector.PS.y = SpinBox1_2->GetValue();
470 aVector.PS.z = SpinBox1_3->GetValue();
473 QStringList aParameters;
474 aParameters << SpinBox1_1->text();
475 if (GetConstructorId() == 0)
476 aParameters << SpinBox2_1->text();
477 aParameters << SpinBox1_2->text();
478 if (GetConstructorId() == 0)
479 aParameters << SpinBox2_2->text();
480 aParameters << SpinBox1_3->text();
481 if (GetConstructorId() == 0)
482 aParameters << SpinBox2_3->text();
484 int actionButton = ActionGroup->checkedId();
485 bool makeGroups = ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() );
487 SUIT_OverrideCursor aWaitCursor;
488 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
489 switch ( actionButton ) {
490 case MOVE_ELEMS_BUTTON:
491 if(CheckBoxMesh->isChecked())
492 aMeshEditor->TranslateObject(mySelectedObject, aVector, false);
494 aMeshEditor->Translate(anElementsId, aVector, false);
495 if( !myMesh->_is_nil())
496 myMesh->SetParameters( aParameters.join(":").toLatin1().constData() );
498 case COPY_ELEMS_BUTTON:
500 SMESH::ListOfGroups_var groups;
501 if(CheckBoxMesh->isChecked())
502 groups = aMeshEditor->TranslateObjectMakeGroups(mySelectedObject,aVector);
504 groups = aMeshEditor->TranslateMakeGroups(anElementsId, aVector);
507 if(CheckBoxMesh->isChecked())
508 aMeshEditor->TranslateObject(mySelectedObject, aVector, true);
510 aMeshEditor->Translate(anElementsId, aVector, true);
512 if( !myMesh->_is_nil())
513 myMesh->SetParameters( aParameters.join(":").toLatin1().constData() );
515 case MAKE_MESH_BUTTON:
516 SMESH::SMESH_Mesh_var mesh;
517 if (CheckBoxMesh->isChecked())
518 mesh = aMeshEditor->TranslateObjectMakeMesh(mySelectedObject, aVector, makeGroups,
519 LineEditNewMesh->text().toLatin1().data());
521 mesh = aMeshEditor->TranslateMakeMesh(anElementsId, aVector, makeGroups,
522 LineEditNewMesh->text().toLatin1().data());
523 if (!mesh->_is_nil()) {
524 mesh->SetParameters(aParameters.join(":").toLatin1().constData());
525 #ifdef WITHGENERICOBJ
526 // obj has been published in study. Its refcount has been incremented.
527 // It is safe to decrement its refcount
528 // so that it will be destroyed when the entry in study will be removed
537 if ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() ||
538 actionButton == MAKE_MESH_BUTTON )
539 mySMESHGUI->updateObjBrowser(true); // new groups may appear
541 ConstructorsClicked(GetConstructorId());
542 mySelectedObject = SMESH::SMESH_IDSource::_nil();
543 SelectionIntoArgument();
545 SMESHGUI::Modified();
551 //=================================================================================
552 // function : ClickOnOk()
554 //=================================================================================
555 void SMESHGUI_TranslationDlg::ClickOnOk()
561 //=================================================================================
562 // function : ClickOnCancel()
564 //=================================================================================
565 void SMESHGUI_TranslationDlg::ClickOnCancel()
567 disconnect(mySelectionMgr, 0, this, 0);
568 mySelectionMgr->clearFilters();
569 //mySelectionMgr->clearSelected();
570 if (SMESH::GetCurrentVtkView()) {
571 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
572 SMESH::SetPointRepresentation(false);
574 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
575 aViewWindow->SetSelectionMode( ActorSelection );
576 mySMESHGUI->ResetState();
580 //=================================================================================
581 // function : ClickOnHelp()
583 //=================================================================================
584 void SMESHGUI_TranslationDlg::ClickOnHelp()
586 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
588 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
592 platform = "winapplication";
594 platform = "application";
596 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
597 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
598 arg(app->resourceMgr()->stringValue("ExternalBrowser",
600 arg(myHelpFileName));
604 //=======================================================================
605 // function : onTextChange()
607 //=======================================================================
608 void SMESHGUI_TranslationDlg::onTextChange (const QString& theNewText)
610 QLineEdit* send = (QLineEdit*)sender();
613 BusyLocker lock( myBusy );
615 if (send == LineEditElements)
618 buttonOk->setEnabled(false);
619 buttonApply->setEnabled(false);
621 // hilight entered elements
622 SMDS_Mesh* aMesh = 0;
624 aMesh = myActor->GetObject()->GetMesh();
627 Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
629 TColStd_MapOfInteger newIndices;
631 QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
633 if (send == LineEditElements) {
634 for (int i = 0; i < aListId.count(); i++) {
635 const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
637 newIndices.Add(e->GetID());
642 mySelector->AddOrRemoveIndex( anIO, newIndices, false );
643 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
644 aViewWindow->highlight( anIO, true, true );
646 myElementsId = theNewText;
649 if (myNbOkElements) {
650 buttonOk->setEnabled(true);
651 buttonApply->setEnabled(true);
655 //=================================================================================
656 // function : SelectionIntoArgument()
657 // purpose : Called when selection as changed or other case
658 //=================================================================================
659 void SMESHGUI_TranslationDlg::SelectionIntoArgument()
662 BusyLocker lock( myBusy );
665 QString aString = "";
667 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
668 LineEditElements->setText(aString);
670 buttonOk->setEnabled(false);
671 buttonApply->setEnabled(false);
674 if (!GroupButtons->isEnabled()) // inactive
679 mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
681 int nbSel = aList.Extent();
685 Handle(SALOME_InteractiveObject) IO = aList.First();
686 myMesh = SMESH::GetMeshByIO(IO);
687 if (myMesh->_is_nil())
690 myActor = SMESH::FindActorByObject(myMesh);
692 myActor = SMESH::FindActorByEntry(IO->getEntry());
694 if (!myActor && !CheckBoxMesh->isChecked())
699 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
702 // MakeGroups is available if there are groups and "Copy"
703 if ( myMesh->NbGroups() == 0 ) {
704 MakeGroupsCheck->setChecked(false);
705 MakeGroupsCheck->setEnabled(false);
707 else if ( ActionGroup->checkedId() != MOVE_ELEMS_BUTTON ) {
708 MakeGroupsCheck->setEnabled(true);
711 if (CheckBoxMesh->isChecked()) {
712 SMESH::GetNameOfSelectedIObjects( mySelectionMgr, aString );
714 if (!SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO)->_is_nil()) { //MESH, SUBMESH, OR GROUP
715 mySelectedObject = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO);
721 SMDS_Mesh* aSMDSMesh = myActor->GetObject()->GetMesh();
725 for (int i = aSMDSMesh->MinElementID(); i <= aSMDSMesh->MaxElementID(); i++) {
726 const SMDS_MeshElement * e = aSMDSMesh->FindElement(i);
728 myElementsId += QString(" %1").arg(i);
732 } else if (!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil()) { //SUBMESH
734 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO);
736 // get IDs from submesh
737 SMESH::long_array_var anElementsIds = new SMESH::long_array;
738 anElementsIds = aSubMesh->GetElementsId();
739 for (int i = 0; i < anElementsIds->length(); i++) {
740 myElementsId += QString(" %1").arg(anElementsIds[i]);
742 aNbUnits = anElementsIds->length();
745 SMESH::SMESH_GroupBase_var aGroup =
746 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
747 if (aGroup->_is_nil())
750 // get IDs from smesh group
751 SMESH::long_array_var anElementsIds = new SMESH::long_array;
752 anElementsIds = aGroup->GetListOfID();
753 for (int i = 0; i < anElementsIds->length(); i++) {
754 myElementsId += QString(" %1").arg(anElementsIds[i]);
756 aNbUnits = anElementsIds->length();
760 aNbUnits = SMESH::GetNameOfSelectedElements(mySelector, IO, aString);
761 myElementsId = aString;
766 myNbOkElements = true;
768 aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, IO, aString);
772 SMDS_Mesh* aMesh = myActor->GetObject()->GetMesh();
776 const SMDS_MeshNode * n = aMesh->FindNode(aString.toInt());
784 if (myEditCurrentArgument == (QWidget*)SpinBox1_1) {
785 SpinBox1_1->SetValue(x);
786 SpinBox1_2->SetValue(y);
787 SpinBox1_3->SetValue(z);
788 } else if (myEditCurrentArgument == (QWidget*)SpinBox2_1) {
789 SpinBox2_1->SetValue(x);
790 SpinBox2_2->SetValue(y);
791 SpinBox2_3->SetValue(z);
795 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
796 LineEditElements->setText(aString);
797 LineEditElements->repaint();
798 LineEditElements->setEnabled(false); // to fully update lineedit IPAL 19809
799 LineEditElements->setEnabled(true);
804 if (myNbOkElements) {
805 buttonOk->setEnabled(true);
806 buttonApply->setEnabled(true);
810 //=================================================================================
811 // function : SetEditCurrentArgument()
813 //=================================================================================
814 void SMESHGUI_TranslationDlg::SetEditCurrentArgument()
816 QPushButton* send = (QPushButton*)sender();
818 disconnect(mySelectionMgr, 0, this, 0);
819 mySelectionMgr->clearSelected();
820 mySelectionMgr->clearFilters();
822 if (send == SelectElementsButton) {
823 myEditCurrentArgument = (QWidget*)LineEditElements;
824 SMESH::SetPointRepresentation(false);
825 if (CheckBoxMesh->isChecked()) {
826 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
827 aViewWindow->SetSelectionMode( ActorSelection );
828 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
831 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
832 aViewWindow->SetSelectionMode( CellSelection );
834 } else if (send == SelectButton1) {
835 myEditCurrentArgument = (QWidget*)SpinBox1_1;
836 SMESH::SetPointRepresentation(true);
838 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
839 aViewWindow->SetSelectionMode( NodeSelection );
840 } else if (send == SelectButton2) {
841 myEditCurrentArgument = (QWidget*)SpinBox2_1;
842 SMESH::SetPointRepresentation(true);
844 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
845 aViewWindow->SetSelectionMode( NodeSelection );
848 myEditCurrentArgument->setFocus();
849 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
850 SelectionIntoArgument();
853 //=================================================================================
854 // function : DeactivateActiveDialog()
856 //=================================================================================
857 void SMESHGUI_TranslationDlg::DeactivateActiveDialog()
859 if (ConstructorsBox->isEnabled()) {
860 ConstructorsBox->setEnabled(false);
861 GroupArguments->setEnabled(false);
862 GroupButtons->setEnabled(false);
863 mySMESHGUI->ResetState();
864 mySMESHGUI->SetActiveDialogBox(0);
868 //=================================================================================
869 // function : ActivateThisDialog()
871 //=================================================================================
872 void SMESHGUI_TranslationDlg::ActivateThisDialog()
874 /* Emit a signal to deactivate the active dialog */
875 mySMESHGUI->EmitSignalDeactivateDialog();
876 ConstructorsBox->setEnabled(true);
877 GroupArguments->setEnabled(true);
878 GroupButtons->setEnabled(true);
880 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
882 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
883 aViewWindow->SetSelectionMode( CellSelection );
885 SelectionIntoArgument();
888 //=================================================================================
889 // function : enterEvent()
891 //=================================================================================
892 void SMESHGUI_TranslationDlg::enterEvent (QEvent*)
894 if (!ConstructorsBox->isEnabled())
895 ActivateThisDialog();
898 //=================================================================================
899 // function : closeEvent()
901 //=================================================================================
902 void SMESHGUI_TranslationDlg::closeEvent (QCloseEvent*)
904 /* same than click on cancel button */
908 //=======================================================================
909 //function : hideEvent
910 //purpose : caused by ESC key
911 //=======================================================================
912 void SMESHGUI_TranslationDlg::hideEvent (QHideEvent*)
918 //=======================================================================
919 //function : onSelectMesh
921 //=======================================================================
922 void SMESHGUI_TranslationDlg::onSelectMesh (bool toSelectMesh)
925 TextLabelElements->setText(tr("SMESH_NAME"));
927 TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
928 myFilterBtn->setEnabled(!toSelectMesh);
930 if (myEditCurrentArgument != LineEditElements) {
931 LineEditElements->clear();
935 mySelectionMgr->clearFilters();
936 SMESH::SetPointRepresentation(false);
939 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
940 aViewWindow->SetSelectionMode( ActorSelection );
941 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
942 LineEditElements->setReadOnly(true);
943 LineEditElements->setValidator(0);
945 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
946 aViewWindow->SetSelectionMode( CellSelection );
947 LineEditElements->setReadOnly(false);
948 LineEditElements->setValidator(myIdValidator);
949 onTextChange(LineEditElements->text());
952 SelectionIntoArgument();
955 //=======================================================================
956 //function : onActionClicked
957 //purpose : slot called when an action type changed
958 //=======================================================================
960 void SMESHGUI_TranslationDlg::onActionClicked(int button)
963 case MOVE_ELEMS_BUTTON:
964 MakeGroupsCheck->setEnabled(false);
965 LineEditNewMesh->setEnabled(false);
967 case COPY_ELEMS_BUTTON:
968 LineEditNewMesh->setEnabled(false);
969 MakeGroupsCheck->setText( tr("SMESH_MAKE_GROUPS"));
970 if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
971 MakeGroupsCheck->setEnabled(true);
973 MakeGroupsCheck->setEnabled(false);
975 case MAKE_MESH_BUTTON:
976 LineEditNewMesh->setEnabled(true);
977 MakeGroupsCheck->setText( tr("SMESH_COPY_GROUPS"));
978 if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
979 MakeGroupsCheck->setEnabled(true);
981 MakeGroupsCheck->setEnabled(false);
987 //=======================================================================
988 //function : setNewMeshName
989 //purpose : update contents of LineEditNewMesh
990 //=======================================================================
992 void SMESHGUI_TranslationDlg::setNewMeshName()
994 LineEditNewMesh->setText("");
995 if ( LineEditNewMesh->isEnabled() && !myMesh->_is_nil() ) {
997 if ( CheckBoxMesh->isChecked() ) {
998 name = LineEditElements->text();
1001 _PTR(SObject) meshSO = SMESH::FindSObject( myMesh );
1002 name = meshSO->GetName().c_str();
1004 if ( !name.isEmpty() )
1005 LineEditNewMesh->setText( SMESH::UniqueMeshName( name, "translated"));
1009 //=================================================================================
1010 // function : GetConstructorId()
1012 //=================================================================================
1013 int SMESHGUI_TranslationDlg::GetConstructorId()
1015 return GroupConstructors->checkedId();
1018 //=================================================================================
1019 // function : keyPressEvent()
1021 //=================================================================================
1022 void SMESHGUI_TranslationDlg::keyPressEvent( QKeyEvent* e )
1024 QDialog::keyPressEvent( e );
1025 if ( e->isAccepted() )
1028 if ( e->key() == Qt::Key_F1 ) {
1034 //=================================================================================
1035 // function : setFilters()
1036 // purpose : SLOT. Called when "Filter" button pressed.
1037 //=================================================================================
1038 void SMESHGUI_TranslationDlg::setFilters()
1040 if(myMesh->_is_nil()) {
1041 SUIT_MessageBox::critical(this,
1043 tr("NO_MESH_SELECTED"));
1047 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, SMESH::ALL );
1049 myFilterDlg->SetSelection();
1050 myFilterDlg->SetMesh( myMesh );
1051 myFilterDlg->SetSourceWg( LineEditElements );
1053 myFilterDlg->show();
1056 //=================================================================================
1057 // function : isValid
1059 //=================================================================================
1060 bool SMESHGUI_TranslationDlg::isValid()
1065 ok = SpinBox1_1->isValid( msg, true ) && ok;
1066 ok = SpinBox1_2->isValid( msg, true ) && ok;
1067 ok = SpinBox1_3->isValid( msg, true ) && ok;
1068 if (GetConstructorId() == 0) {
1069 ok = SpinBox2_1->isValid( msg, true ) && ok;
1070 ok = SpinBox2_2->isValid( msg, true ) && ok;
1071 ok = SpinBox2_3->isValid( msg, true ) && ok;
1075 QString str( tr( "SMESH_INCORRECT_INPUT" ) );
1076 if ( !msg.isEmpty() )
1078 SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );