1 // SMESH SMESHGUI : GUI for SMESH component
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File : SMESHGUI_TranslationDlg.cxx
23 // Author : Michael ZORIN, Open CASCADE S.A.S.
27 #include "SMESHGUI_TranslationDlg.h"
30 #include "SMESHGUI_SpinBox.h"
31 #include "SMESHGUI_Utils.h"
32 #include "SMESHGUI_VTKUtils.h"
33 #include "SMESHGUI_MeshUtils.h"
34 #include "SMESHGUI_IdValidator.h"
36 #include <SMESH_Actor.h>
37 #include <SMESH_TypeFilter.hxx>
38 #include <SMESH_LogicalFilter.hxx>
39 #include <SMDS_Mesh.hxx>
41 // SALOME GUI includes
42 #include <SUIT_Desktop.h>
43 #include <SUIT_ResourceMgr.h>
44 #include <SUIT_Session.h>
45 #include <SUIT_MessageBox.h>
46 #include <SUIT_OverrideCursor.h>
48 #include <LightApp_Application.h>
49 #include <LightApp_SelectionMgr.h>
51 #include <SVTK_ViewModel.h>
52 #include <SVTK_ViewWindow.h>
53 #include <SALOME_ListIO.hxx>
55 // SALOME KERNEL includes
56 #include <SALOMEDSClient_SObject.hxx>
59 #include <TColStd_MapOfInteger.hxx>
62 #include <QApplication>
63 #include <QButtonGroup>
67 #include <QPushButton>
68 #include <QRadioButton>
70 #include <QHBoxLayout>
71 #include <QVBoxLayout>
72 #include <QGridLayout>
77 #include <SALOMEconfig.h>
78 #include CORBA_SERVER_HEADER(SMESH_Group)
79 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
81 enum { MOVE_ELEMS_BUTTON = 0, COPY_ELEMS_BUTTON, MAKE_MESH_BUTTON }; //!< action type
86 //=================================================================================
87 // class : SMESHGUI_TranslationDlg()
89 //=================================================================================
90 SMESHGUI_TranslationDlg::SMESHGUI_TranslationDlg( SMESHGUI* theModule )
91 : QDialog( SMESH::GetDesktop( theModule ) ),
92 mySMESHGUI( theModule ),
93 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) )
95 QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SMESH_TRANSLATION_POINTS")));
96 QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SMESH_TRANSLATION_VECTOR")));
97 QPixmap image2 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
100 setAttribute(Qt::WA_DeleteOnClose, true);
101 setWindowTitle(tr("SMESH_TRANSLATION"));
102 setSizeGripEnabled(true);
104 QVBoxLayout* SMESHGUI_TranslationDlgLayout = new QVBoxLayout(this);
105 SMESHGUI_TranslationDlgLayout->setSpacing(SPACING);
106 SMESHGUI_TranslationDlgLayout->setMargin(MARGIN);
108 /***************************************************************/
109 ConstructorsBox = new QGroupBox(tr("SMESH_TRANSLATION"), this);
110 GroupConstructors = new QButtonGroup(this);
111 QHBoxLayout* ConstructorsBoxLayout = new QHBoxLayout(ConstructorsBox);
112 ConstructorsBoxLayout->setSpacing(SPACING);
113 ConstructorsBoxLayout->setMargin(MARGIN);
115 RadioButton1= new QRadioButton(ConstructorsBox);
116 RadioButton1->setIcon(image0);
117 RadioButton2= new QRadioButton(ConstructorsBox);
118 RadioButton2->setIcon(image1);
120 ConstructorsBoxLayout->addWidget(RadioButton1);
121 ConstructorsBoxLayout->addWidget(RadioButton2);
122 GroupConstructors->addButton(RadioButton1, 0);
123 GroupConstructors->addButton(RadioButton2, 1);
125 /***************************************************************/
126 GroupArguments = new QGroupBox(tr("SMESH_ARGUMENTS"), this);
127 QGridLayout* GroupArgumentsLayout = new QGridLayout(GroupArguments);
128 GroupArgumentsLayout->setSpacing(SPACING);
129 GroupArgumentsLayout->setMargin(MARGIN);
131 myIdValidator = new SMESHGUI_IdValidator(this);
133 // Controls for elements selection
134 TextLabelElements = new QLabel(tr("SMESH_ID_ELEMENTS"), GroupArguments);
135 SelectElementsButton = new QPushButton(GroupArguments);
136 SelectElementsButton->setIcon(image2);
137 LineEditElements = new QLineEdit(GroupArguments);
138 LineEditElements->setValidator(myIdValidator);
140 // Control for the whole mesh selection
141 CheckBoxMesh = new QCheckBox(tr("SMESH_SELECT_WHOLE_MESH"), GroupArguments);
143 // Controls for vector and points selection
144 TextLabel1 = new QLabel(GroupArguments);
145 SelectButton1 = new QPushButton(GroupArguments);
146 SelectButton1->setIcon(image2);
148 TextLabel1_1 = new QLabel(GroupArguments);
149 SpinBox1_1 = new SMESHGUI_SpinBox(GroupArguments);
150 TextLabel1_2 = new QLabel(GroupArguments);
151 SpinBox1_2 = new SMESHGUI_SpinBox(GroupArguments);
152 TextLabel1_3 = new QLabel(GroupArguments);
153 SpinBox1_3 = new SMESHGUI_SpinBox(GroupArguments);
155 TextLabel2 = new QLabel(tr("SMESH_POINT_2"), GroupArguments);
156 SelectButton2 = new QPushButton(GroupArguments);
157 SelectButton2->setIcon(image2);
159 TextLabel2_1 = new QLabel(tr("SMESH_X"), GroupArguments);
160 SpinBox2_1 = new SMESHGUI_SpinBox(GroupArguments);
161 TextLabel2_2 = new QLabel(tr("SMESH_Y"), GroupArguments);
162 SpinBox2_2 = new SMESHGUI_SpinBox(GroupArguments);
163 TextLabel2_3 = new QLabel(tr("SMESH_Z"), GroupArguments);
164 SpinBox2_3 = new SMESHGUI_SpinBox(GroupArguments);
166 // switch of action type
167 ActionBox = new QGroupBox(GroupArguments);
168 ActionGroup = new QButtonGroup(GroupArguments);
169 QVBoxLayout* ActionBoxLayout = new QVBoxLayout(ActionBox);
170 ActionBoxLayout->addSpacing(SPACING);
171 ActionBoxLayout->setMargin(MARGIN);
173 QRadioButton* aMoveElements = new QRadioButton(tr("SMESH_MOVE_ELEMENTS"), ActionBox);
174 QRadioButton* aCopyElements = new QRadioButton(tr("SMESH_COPY_ELEMENTS"), ActionBox);
175 QRadioButton* aCreateMesh = new QRadioButton(tr("SMESH_CREATE_MESH"), ActionBox);
177 ActionBoxLayout->addWidget(aMoveElements);
178 ActionBoxLayout->addWidget(aCopyElements);
179 ActionBoxLayout->addWidget(aCreateMesh);
180 ActionGroup->addButton(aMoveElements, MOVE_ELEMS_BUTTON);
181 ActionGroup->addButton(aCopyElements, COPY_ELEMS_BUTTON);
182 ActionGroup->addButton(aCreateMesh, MAKE_MESH_BUTTON);
184 // CheckBox for groups generation
185 MakeGroupsCheck = new QCheckBox(tr("SMESH_MAKE_GROUPS"), GroupArguments);
186 MakeGroupsCheck->setChecked(false);
188 // Name of a mesh to create
189 LineEditNewMesh = new QLineEdit(GroupArguments);
192 GroupArgumentsLayout->addWidget(TextLabelElements, 0, 0);
193 GroupArgumentsLayout->addWidget(SelectElementsButton, 0, 1);
194 GroupArgumentsLayout->addWidget(LineEditElements, 0, 2, 1, 6);
195 GroupArgumentsLayout->addWidget(CheckBoxMesh, 1, 0, 1, 8);
196 GroupArgumentsLayout->addWidget(TextLabel1, 2, 0);
197 GroupArgumentsLayout->addWidget(SelectButton1, 2, 1);
198 GroupArgumentsLayout->addWidget(TextLabel1_1, 2, 2);
199 GroupArgumentsLayout->addWidget(SpinBox1_1, 2, 3);
200 GroupArgumentsLayout->addWidget(TextLabel1_2, 2, 4);
201 GroupArgumentsLayout->addWidget(SpinBox1_2, 2, 5);
202 GroupArgumentsLayout->addWidget(TextLabel1_3, 2, 6);
203 GroupArgumentsLayout->addWidget(SpinBox1_3, 2, 7);
204 GroupArgumentsLayout->addWidget(TextLabel2, 3, 0);
205 GroupArgumentsLayout->addWidget(SelectButton2, 3, 1);
206 GroupArgumentsLayout->addWidget(TextLabel2_1, 3, 2);
207 GroupArgumentsLayout->addWidget(SpinBox2_1, 3, 3);
208 GroupArgumentsLayout->addWidget(TextLabel2_2, 3, 4);
209 GroupArgumentsLayout->addWidget(SpinBox2_2, 3, 5);
210 GroupArgumentsLayout->addWidget(TextLabel2_3, 3, 6);
211 GroupArgumentsLayout->addWidget(SpinBox2_3, 3, 7);
212 GroupArgumentsLayout->addWidget(ActionBox, 4, 0, 3, 4);
213 GroupArgumentsLayout->addWidget(MakeGroupsCheck, 5, 5, 1, 4);
214 GroupArgumentsLayout->addWidget(LineEditNewMesh, 6, 5, 1, 4);
216 /***************************************************************/
217 GroupButtons = new QGroupBox(this);
218 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
219 GroupButtonsLayout->setSpacing(SPACING);
220 GroupButtonsLayout->setMargin(MARGIN);
222 buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
223 buttonOk->setAutoDefault(true);
224 buttonOk->setDefault(true);
225 buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
226 buttonApply->setAutoDefault(true);
227 buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
228 buttonCancel->setAutoDefault(true);
229 buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
230 buttonHelp->setAutoDefault(true);
232 GroupButtonsLayout->addWidget(buttonOk);
233 GroupButtonsLayout->addSpacing(10);
234 GroupButtonsLayout->addWidget(buttonApply);
235 GroupButtonsLayout->addSpacing(10);
236 GroupButtonsLayout->addStretch();
237 GroupButtonsLayout->addWidget(buttonCancel);
238 GroupButtonsLayout->addWidget(buttonHelp);
240 /***************************************************************/
241 SMESHGUI_TranslationDlgLayout->addWidget(ConstructorsBox);
242 SMESHGUI_TranslationDlgLayout->addWidget(GroupArguments);
243 SMESHGUI_TranslationDlgLayout->addWidget(GroupButtons);
245 /* Initialisations */
246 SpinBox1_1->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, DBL_DIGITS_DISPLAY);
247 SpinBox1_2->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, DBL_DIGITS_DISPLAY);
248 SpinBox1_3->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, DBL_DIGITS_DISPLAY);
249 SpinBox2_1->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, DBL_DIGITS_DISPLAY);
250 SpinBox2_2->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, DBL_DIGITS_DISPLAY);
251 SpinBox2_3->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, DBL_DIGITS_DISPLAY);
253 RadioButton1->setChecked(true);
255 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
257 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
259 // Costruction of the logical filter
260 SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter (MESHorSUBMESH);
261 SMESH_TypeFilter* aSmeshGroupFilter = new SMESH_TypeFilter (GROUP);
263 QList<SUIT_SelectionFilter*> aListOfFilters;
264 if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
265 if (aSmeshGroupFilter) aListOfFilters.append(aSmeshGroupFilter);
267 myMeshOrSubMeshOrGroupFilter =
268 new SMESH_LogicalFilter(aListOfFilters, SMESH_LogicalFilter::LO_OR);
270 myHelpFileName = "translation_page.html";
274 /* signals and slots connections */
275 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
276 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
277 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
278 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
279 connect(GroupConstructors, SIGNAL(buttonClicked(int)), SLOT(ConstructorsClicked(int)));
281 connect(SelectElementsButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
282 connect(SelectButton1, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
283 connect(SelectButton2, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
285 connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
286 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
287 /* to close dialog if study change */
288 connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
289 connect(LineEditElements, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
290 connect(CheckBoxMesh, SIGNAL(toggled(bool)), SLOT(onSelectMesh(bool)));
291 connect(ActionGroup, SIGNAL(buttonClicked(int)), SLOT(onActionClicked(int)));
293 ConstructorsClicked(0);
294 SelectionIntoArgument();
295 onActionClicked(MOVE_ELEMS_BUTTON);
298 //=================================================================================
299 // function : ~SMESHGUI_TranslationDlg()
300 // purpose : Destroys the object and frees any allocated resources
301 //=================================================================================
302 SMESHGUI_TranslationDlg::~SMESHGUI_TranslationDlg()
306 //=================================================================================
309 //=================================================================================
310 void SMESHGUI_TranslationDlg::Init (bool ResetControls)
314 myEditCurrentArgument = 0;
315 LineEditElements->clear();
319 buttonOk->setEnabled(false);
320 buttonApply->setEnabled(false);
323 myMesh = SMESH::SMESH_Mesh::_nil();
326 SpinBox1_1->SetValue(0.0);
327 SpinBox1_2->SetValue(0.0);
328 SpinBox1_3->SetValue(0.0);
329 SpinBox2_1->SetValue(0.0);
330 SpinBox2_2->SetValue(0.0);
331 SpinBox2_3->SetValue(0.0);
333 ActionGroup->button( MOVE_ELEMS_BUTTON )->setChecked(true);
334 CheckBoxMesh->setChecked(false);
335 // MakeGroupsCheck->setChecked(false);
336 // MakeGroupsCheck->setEnabled(false);
341 //=================================================================================
342 // function : ConstructorsClicked()
343 // purpose : Radio button management
344 //=================================================================================
345 void SMESHGUI_TranslationDlg::ConstructorsClicked (int constructorId)
347 disconnect(mySelectionMgr, 0, this, 0);
349 switch (constructorId) {
352 TextLabel1->setText(tr("SMESH_POINT_1"));
353 TextLabel1_1->setText(tr("SMESH_X"));
354 TextLabel1_2->setText(tr("SMESH_Y"));
355 TextLabel1_3->setText(tr("SMESH_Z"));
357 SelectButton1->show();
359 SelectButton2->show();
360 TextLabel2_1->show();
362 TextLabel2_2->show();
364 TextLabel2_3->show();
370 TextLabel1->setText(tr("SMESH_VECTOR"));
371 TextLabel1_1->setText(tr("SMESH_DX"));
372 TextLabel1_2->setText(tr("SMESH_DY"));
373 TextLabel1_3->setText(tr("SMESH_DZ"));
375 SelectButton1->hide();
377 SelectButton2->hide();
378 TextLabel2_1->hide();
380 TextLabel2_2->hide();
382 TextLabel2_3->hide();
388 if (myEditCurrentArgument != (QWidget*)LineEditElements) {
389 SMESH::SetPointRepresentation(false);
390 if (!CheckBoxMesh->isChecked())
391 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
392 aViewWindow->SetSelectionMode( CellSelection );
395 myEditCurrentArgument = (QWidget*)LineEditElements;
396 LineEditElements->setFocus();
398 if (CheckBoxMesh->isChecked())
401 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
403 QApplication::instance()->processEvents();
405 resize( minimumSize() );
408 //=================================================================================
409 // function : ClickOnApply()
411 //=================================================================================
412 void SMESHGUI_TranslationDlg::ClickOnApply()
414 if (mySMESHGUI->isActiveStudyLocked())
417 if (myNbOkElements) {
418 QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
420 SMESH::long_array_var anElementsId = new SMESH::long_array;
422 anElementsId->length(aListElementsId.count());
423 for (int i = 0; i < aListElementsId.count(); i++)
424 anElementsId[i] = aListElementsId[i].toInt();
426 SMESH::DirStruct aVector;
427 if (GetConstructorId() == 0) {
428 aVector.PS.x = SpinBox2_1->GetValue() - SpinBox1_1->GetValue();
429 aVector.PS.y = SpinBox2_2->GetValue() - SpinBox1_2->GetValue();
430 aVector.PS.z = SpinBox2_3->GetValue() - SpinBox1_3->GetValue();
431 } else if (GetConstructorId() == 1) {
432 aVector.PS.x = SpinBox1_1->GetValue();
433 aVector.PS.y = SpinBox1_2->GetValue();
434 aVector.PS.z = SpinBox1_3->GetValue();
437 int actionButton = ActionGroup->checkedId();
438 bool makeGroups = ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() );
440 SUIT_OverrideCursor aWaitCursor;
441 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
442 switch ( actionButton ) {
443 case MOVE_ELEMS_BUTTON:
444 aMeshEditor->Translate(anElementsId, aVector, false);
446 case COPY_ELEMS_BUTTON:
448 SMESH::ListOfGroups_var groups =
449 aMeshEditor->TranslateMakeGroups(anElementsId, aVector);
451 aMeshEditor->Translate(anElementsId, aVector, true);
453 case MAKE_MESH_BUTTON:
454 SMESH::SMESH_Mesh_var mesh =
455 aMeshEditor->TranslateMakeMesh(anElementsId, aVector, makeGroups,
456 LineEditNewMesh->text().toLatin1().data());
462 if ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() ||
463 actionButton == MAKE_MESH_BUTTON )
464 mySMESHGUI->updateObjBrowser(true); // new groups may appear
466 ConstructorsClicked(GetConstructorId());
467 SelectionIntoArgument();
471 //=================================================================================
472 // function : ClickOnOk()
474 //=================================================================================
475 void SMESHGUI_TranslationDlg::ClickOnOk()
481 //=================================================================================
482 // function : ClickOnCancel()
484 //=================================================================================
485 void SMESHGUI_TranslationDlg::ClickOnCancel()
487 disconnect(mySelectionMgr, 0, this, 0);
488 mySelectionMgr->clearFilters();
489 //mySelectionMgr->clearSelected();
490 SMESH::SetPointRepresentation(false);
491 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
492 aViewWindow->SetSelectionMode( ActorSelection );
493 mySMESHGUI->ResetState();
497 //=================================================================================
498 // function : ClickOnHelp()
500 //=================================================================================
501 void SMESHGUI_TranslationDlg::ClickOnHelp()
503 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
505 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
509 platform = "winapplication";
511 platform = "application";
513 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
514 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
515 arg(app->resourceMgr()->stringValue("ExternalBrowser",
517 arg(myHelpFileName));
521 //=======================================================================
522 // function : onTextChange()
524 //=======================================================================
525 void SMESHGUI_TranslationDlg::onTextChange (const QString& theNewText)
527 QLineEdit* send = (QLineEdit*)sender();
532 if (send == LineEditElements)
535 buttonOk->setEnabled(false);
536 buttonApply->setEnabled(false);
538 // hilight entered elements
539 SMDS_Mesh* aMesh = 0;
541 aMesh = myActor->GetObject()->GetMesh();
544 Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
546 TColStd_MapOfInteger newIndices;
548 QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
550 if (send == LineEditElements) {
551 for (int i = 0; i < aListId.count(); i++) {
552 const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
554 newIndices.Add(e->GetID());
559 mySelector->AddOrRemoveIndex( anIO, newIndices, false );
560 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
561 aViewWindow->highlight( anIO, true, true );
563 myElementsId = theNewText;
566 if (myNbOkElements) {
567 buttonOk->setEnabled(true);
568 buttonApply->setEnabled(true);
574 //=================================================================================
575 // function : SelectionIntoArgument()
576 // purpose : Called when selection as changed or other case
577 //=================================================================================
578 void SMESHGUI_TranslationDlg::SelectionIntoArgument()
584 QString aString = "";
587 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
588 LineEditElements->setText(aString);
590 buttonOk->setEnabled(false);
591 buttonApply->setEnabled(false);
595 if (!GroupButtons->isEnabled()) // inactive
600 mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
602 int nbSel = aList.Extent();
606 Handle(SALOME_InteractiveObject) IO = aList.First();
607 myMesh = SMESH::GetMeshByIO(IO);
608 if (myMesh->_is_nil())
611 myActor = SMESH::FindActorByObject(myMesh);
613 myActor = SMESH::FindActorByEntry(IO->getEntry());
619 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
622 // MakeGroups is available if there are groups and "Copy"
623 if ( myMesh->NbGroups() == 0 ) {
624 MakeGroupsCheck->setChecked(false);
625 MakeGroupsCheck->setEnabled(false);
627 else if ( ActionGroup->checkedId() != MOVE_ELEMS_BUTTON ) {
628 MakeGroupsCheck->setEnabled(true);
631 if (CheckBoxMesh->isChecked()) {
632 SMESH::GetNameOfSelectedIObjects( mySelectionMgr, aString );
634 if (!SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO)->_is_nil()) { //MESH
636 SMDS_Mesh* aSMDSMesh = myActor->GetObject()->GetMesh();
640 for (int i = aSMDSMesh->MinElementID(); i <= aSMDSMesh->MaxElementID(); i++) {
641 const SMDS_MeshElement * e = aSMDSMesh->FindElement(i);
643 myElementsId += QString(" %1").arg(i);
647 } else if (!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil()) { //SUBMESH
649 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO);
651 // get IDs from submesh
652 SMESH::long_array_var anElementsIds = new SMESH::long_array;
653 anElementsIds = aSubMesh->GetElementsId();
654 for (int i = 0; i < anElementsIds->length(); i++) {
655 myElementsId += QString(" %1").arg(anElementsIds[i]);
657 aNbUnits = anElementsIds->length();
660 SMESH::SMESH_GroupBase_var aGroup =
661 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
662 if (aGroup->_is_nil())
665 // get IDs from smesh group
666 SMESH::long_array_var anElementsIds = new SMESH::long_array;
667 anElementsIds = aGroup->GetListOfID();
668 for (int i = 0; i < anElementsIds->length(); i++) {
669 myElementsId += QString(" %1").arg(anElementsIds[i]);
671 aNbUnits = anElementsIds->length();
674 aNbUnits = SMESH::GetNameOfSelectedElements(mySelector, IO, aString);
675 myElementsId = aString;
681 myNbOkElements = true;
683 aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, IO, aString);
687 SMDS_Mesh* aMesh = myActor->GetObject()->GetMesh();
691 const SMDS_MeshNode * n = aMesh->FindNode(aString.toInt());
699 if (myEditCurrentArgument == (QWidget*)SpinBox1_1) {
700 SpinBox1_1->SetValue(x);
701 SpinBox1_2->SetValue(y);
702 SpinBox1_3->SetValue(z);
703 } else if (myEditCurrentArgument == (QWidget*)SpinBox2_1) {
704 SpinBox2_1->SetValue(x);
705 SpinBox2_2->SetValue(y);
706 SpinBox2_3->SetValue(z);
711 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
712 LineEditElements->setText(aString);
718 if (myNbOkElements) {
719 buttonOk->setEnabled(true);
720 buttonApply->setEnabled(true);
724 //=================================================================================
725 // function : SetEditCurrentArgument()
727 //=================================================================================
728 void SMESHGUI_TranslationDlg::SetEditCurrentArgument()
730 QPushButton* send = (QPushButton*)sender();
732 disconnect(mySelectionMgr, 0, this, 0);
733 mySelectionMgr->clearSelected();
734 mySelectionMgr->clearFilters();
736 if (send == SelectElementsButton) {
737 myEditCurrentArgument = (QWidget*)LineEditElements;
738 SMESH::SetPointRepresentation(false);
739 if (CheckBoxMesh->isChecked()) {
740 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
741 aViewWindow->SetSelectionMode( ActorSelection );
742 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
745 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
746 aViewWindow->SetSelectionMode( CellSelection );
748 } else if (send == SelectButton1) {
749 myEditCurrentArgument = (QWidget*)SpinBox1_1;
750 SMESH::SetPointRepresentation(true);
752 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
753 aViewWindow->SetSelectionMode( NodeSelection );
754 } else if (send == SelectButton2) {
755 myEditCurrentArgument = (QWidget*)SpinBox2_1;
756 SMESH::SetPointRepresentation(true);
758 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
759 aViewWindow->SetSelectionMode( NodeSelection );
762 myEditCurrentArgument->setFocus();
763 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
764 SelectionIntoArgument();
767 //=================================================================================
768 // function : DeactivateActiveDialog()
770 //=================================================================================
771 void SMESHGUI_TranslationDlg::DeactivateActiveDialog()
773 if (ConstructorsBox->isEnabled()) {
774 ConstructorsBox->setEnabled(false);
775 GroupArguments->setEnabled(false);
776 GroupButtons->setEnabled(false);
777 mySMESHGUI->ResetState();
778 mySMESHGUI->SetActiveDialogBox(0);
782 //=================================================================================
783 // function : ActivateThisDialog()
785 //=================================================================================
786 void SMESHGUI_TranslationDlg::ActivateThisDialog()
788 /* Emit a signal to deactivate the active dialog */
789 mySMESHGUI->EmitSignalDeactivateDialog();
790 ConstructorsBox->setEnabled(true);
791 GroupArguments->setEnabled(true);
792 GroupButtons->setEnabled(true);
794 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
796 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
797 aViewWindow->SetSelectionMode( CellSelection );
799 SelectionIntoArgument();
802 //=================================================================================
803 // function : enterEvent()
805 //=================================================================================
806 void SMESHGUI_TranslationDlg::enterEvent (QEvent*)
808 if (!ConstructorsBox->isEnabled())
809 ActivateThisDialog();
812 //=================================================================================
813 // function : closeEvent()
815 //=================================================================================
816 void SMESHGUI_TranslationDlg::closeEvent (QCloseEvent*)
818 /* same than click on cancel button */
822 //=======================================================================
823 //function : hideEvent
824 //purpose : caused by ESC key
825 //=======================================================================
826 void SMESHGUI_TranslationDlg::hideEvent (QHideEvent*)
832 //=======================================================================
833 //function : onSelectMesh
835 //=======================================================================
836 void SMESHGUI_TranslationDlg::onSelectMesh (bool toSelectMesh)
839 TextLabelElements->setText(tr("SMESH_NAME"));
841 TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
843 if (myEditCurrentArgument != LineEditElements) {
844 LineEditElements->clear();
848 mySelectionMgr->clearFilters();
849 SMESH::SetPointRepresentation(false);
852 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
853 aViewWindow->SetSelectionMode( ActorSelection );
854 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
855 LineEditElements->setReadOnly(true);
856 LineEditElements->setValidator(0);
858 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
859 aViewWindow->SetSelectionMode( CellSelection );
860 LineEditElements->setReadOnly(false);
861 LineEditElements->setValidator(myIdValidator);
862 onTextChange(LineEditElements->text());
865 SelectionIntoArgument();
868 //=======================================================================
869 //function : onActionClicked
870 //purpose : slot called when an action type changed
871 //=======================================================================
873 void SMESHGUI_TranslationDlg::onActionClicked(int button)
876 case MOVE_ELEMS_BUTTON:
877 MakeGroupsCheck->setEnabled(false);
878 LineEditNewMesh->setEnabled(false);
880 case COPY_ELEMS_BUTTON:
881 LineEditNewMesh->setEnabled(false);
882 MakeGroupsCheck->setText( tr("SMESH_MAKE_GROUPS"));
883 if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
884 MakeGroupsCheck->setEnabled(true);
886 MakeGroupsCheck->setEnabled(false);
888 case MAKE_MESH_BUTTON:
889 LineEditNewMesh->setEnabled(true);
890 MakeGroupsCheck->setText( tr("SMESH_COPY_GROUPS"));
891 if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
892 MakeGroupsCheck->setEnabled(true);
894 MakeGroupsCheck->setEnabled(false);
900 //=======================================================================
901 //function : setNewMeshName
902 //purpose : update contents of LineEditNewMesh
903 //=======================================================================
905 void SMESHGUI_TranslationDlg::setNewMeshName()
907 LineEditNewMesh->setText("");
908 if ( LineEditNewMesh->isEnabled() && !myMesh->_is_nil() ) {
910 if ( CheckBoxMesh->isChecked() ) {
911 name = LineEditElements->text();
914 _PTR(SObject) meshSO = SMESH::FindSObject( myMesh );
915 name = meshSO->GetName().c_str();
917 if ( !name.isEmpty() )
918 LineEditNewMesh->setText( SMESH::UniqueMeshName( name, "translated"));
922 //=================================================================================
923 // function : GetConstructorId()
925 //=================================================================================
926 int SMESHGUI_TranslationDlg::GetConstructorId()
928 return GroupConstructors->checkedId();
931 //=================================================================================
932 // function : keyPressEvent()
934 //=================================================================================
935 void SMESHGUI_TranslationDlg::keyPressEvent( QKeyEvent* e )
937 QDialog::keyPressEvent( e );
938 if ( e->isAccepted() )
941 if ( e->key() == Qt::Key_F1 ) {