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>
47 #include <LightApp_Application.h>
48 #include <LightApp_SelectionMgr.h>
50 #include <SVTK_ViewModel.h>
51 #include <SVTK_ViewWindow.h>
52 #include <SALOME_ListIO.hxx>
54 // SALOME KERNEL includes
55 #include <SALOMEDSClient_SObject.hxx>
58 #include <TColStd_MapOfInteger.hxx>
61 #include <QApplication>
62 #include <QButtonGroup>
66 #include <QPushButton>
67 #include <QRadioButton>
69 #include <QHBoxLayout>
70 #include <QVBoxLayout>
71 #include <QGridLayout>
76 #include <SALOMEconfig.h>
77 #include CORBA_SERVER_HEADER(SMESH_Group)
78 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
80 enum { MOVE_ELEMS_BUTTON = 0, COPY_ELEMS_BUTTON, MAKE_MESH_BUTTON }; //!< action type
85 //=================================================================================
86 // class : SMESHGUI_TranslationDlg()
88 //=================================================================================
89 SMESHGUI_TranslationDlg::SMESHGUI_TranslationDlg( SMESHGUI* theModule )
90 : QDialog( SMESH::GetDesktop( theModule ) ),
91 mySMESHGUI( theModule ),
92 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) )
94 QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SMESH_TRANSLATION_POINTS")));
95 QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SMESH_TRANSLATION_VECTOR")));
96 QPixmap image2 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
99 setAttribute(Qt::WA_DeleteOnClose, true);
100 setWindowTitle(tr("SMESH_TRANSLATION"));
101 setSizeGripEnabled(true);
103 QVBoxLayout* SMESHGUI_TranslationDlgLayout = new QVBoxLayout(this);
104 SMESHGUI_TranslationDlgLayout->setSpacing(SPACING);
105 SMESHGUI_TranslationDlgLayout->setMargin(MARGIN);
107 /***************************************************************/
108 ConstructorsBox = new QGroupBox(tr("SMESH_TRANSLATION"), this);
109 GroupConstructors = new QButtonGroup(this);
110 QHBoxLayout* ConstructorsBoxLayout = new QHBoxLayout(ConstructorsBox);
111 ConstructorsBoxLayout->setSpacing(SPACING);
112 ConstructorsBoxLayout->setMargin(MARGIN);
114 RadioButton1= new QRadioButton(ConstructorsBox);
115 RadioButton1->setIcon(image0);
116 RadioButton2= new QRadioButton(ConstructorsBox);
117 RadioButton2->setIcon(image1);
119 ConstructorsBoxLayout->addWidget(RadioButton1);
120 ConstructorsBoxLayout->addWidget(RadioButton2);
121 GroupConstructors->addButton(RadioButton1, 0);
122 GroupConstructors->addButton(RadioButton2, 1);
124 /***************************************************************/
125 GroupArguments = new QGroupBox(tr("SMESH_ARGUMENTS"), this);
126 QGridLayout* GroupArgumentsLayout = new QGridLayout(GroupArguments);
127 GroupArgumentsLayout->setSpacing(SPACING);
128 GroupArgumentsLayout->setMargin(MARGIN);
130 // Controls for elements selection
131 TextLabelElements = new QLabel(tr("SMESH_ID_ELEMENTS"), GroupArguments);
132 SelectElementsButton = new QPushButton(GroupArguments);
133 SelectElementsButton->setIcon(image2);
134 LineEditElements = new QLineEdit(GroupArguments);
135 LineEditElements->setValidator(new SMESHGUI_IdValidator(this));
137 // Control for the whole mesh selection
138 CheckBoxMesh = new QCheckBox(tr("SMESH_SELECT_WHOLE_MESH"), GroupArguments);
140 // Controls for vector and points selection
141 TextLabel1 = new QLabel(GroupArguments);
142 SelectButton1 = new QPushButton(GroupArguments);
143 SelectButton1->setIcon(image2);
145 TextLabel1_1 = new QLabel(GroupArguments);
146 SpinBox1_1 = new SMESHGUI_SpinBox(GroupArguments);
147 TextLabel1_2 = new QLabel(GroupArguments);
148 SpinBox1_2 = new SMESHGUI_SpinBox(GroupArguments);
149 TextLabel1_3 = new QLabel(GroupArguments);
150 SpinBox1_3 = new SMESHGUI_SpinBox(GroupArguments);
152 TextLabel2 = new QLabel(tr("SMESH_POINT_2"), GroupArguments);
153 SelectButton2 = new QPushButton(GroupArguments);
154 SelectButton2->setIcon(image2);
156 TextLabel2_1 = new QLabel(tr("SMESH_X"), GroupArguments);
157 SpinBox2_1 = new SMESHGUI_SpinBox(GroupArguments);
158 TextLabel2_2 = new QLabel(tr("SMESH_Y"), GroupArguments);
159 SpinBox2_2 = new SMESHGUI_SpinBox(GroupArguments);
160 TextLabel2_3 = new QLabel(tr("SMESH_Z"), GroupArguments);
161 SpinBox2_3 = new SMESHGUI_SpinBox(GroupArguments);
163 // switch of action type
164 ActionBox = new QGroupBox(tr("ACTION"), GroupArguments);
165 ActionGroup = new QButtonGroup(GroupArguments);
166 QVBoxLayout* ActionBoxLayout = new QVBoxLayout(ActionBox);
167 ActionBoxLayout->addSpacing(SPACING);
168 ActionBoxLayout->setMargin(MARGIN);
170 QRadioButton* aMoveElements = new QRadioButton(tr("SMESH_MOVE_ELEMENTS"), ActionBox);
171 QRadioButton* aCopyElements = new QRadioButton(tr("SMESH_COPY_ELEMENTS"), ActionBox);
172 QRadioButton* aCreateMesh = new QRadioButton(tr("SMESH_CREATE_MESH"), ActionBox);
174 ActionBoxLayout->addWidget(aMoveElements);
175 ActionBoxLayout->addWidget(aCopyElements);
176 ActionBoxLayout->addWidget(aCreateMesh);
177 ActionGroup->addButton(aMoveElements, MOVE_ELEMS_BUTTON);
178 ActionGroup->addButton(aCopyElements, COPY_ELEMS_BUTTON);
179 ActionGroup->addButton(aCreateMesh, MAKE_MESH_BUTTON);
181 // CheckBox for groups generation
182 MakeGroupsCheck = new QCheckBox(tr("SMESH_MAKE_GROUPS"), GroupArguments);
183 MakeGroupsCheck->setChecked(false);
185 // Name of a mesh to create
186 LineEditNewMesh = new QLineEdit(GroupArguments);
189 GroupArgumentsLayout->addWidget(TextLabelElements, 0, 0);
190 GroupArgumentsLayout->addWidget(SelectElementsButton, 0, 1);
191 GroupArgumentsLayout->addWidget(LineEditElements, 0, 2, 1, 6);
192 GroupArgumentsLayout->addWidget(CheckBoxMesh, 1, 0, 1, 8);
193 GroupArgumentsLayout->addWidget(TextLabel1, 2, 0);
194 GroupArgumentsLayout->addWidget(SelectButton1, 2, 1);
195 GroupArgumentsLayout->addWidget(TextLabel1_1, 2, 2);
196 GroupArgumentsLayout->addWidget(SpinBox1_1, 2, 3);
197 GroupArgumentsLayout->addWidget(TextLabel1_2, 2, 4);
198 GroupArgumentsLayout->addWidget(SpinBox1_2, 2, 5);
199 GroupArgumentsLayout->addWidget(TextLabel1_3, 2, 6);
200 GroupArgumentsLayout->addWidget(SpinBox1_3, 2, 7);
201 GroupArgumentsLayout->addWidget(TextLabel2, 3, 0);
202 GroupArgumentsLayout->addWidget(SelectButton2, 3, 1);
203 GroupArgumentsLayout->addWidget(TextLabel2_1, 3, 2);
204 GroupArgumentsLayout->addWidget(SpinBox2_1, 3, 3);
205 GroupArgumentsLayout->addWidget(TextLabel2_2, 3, 4);
206 GroupArgumentsLayout->addWidget(SpinBox2_2, 3, 5);
207 GroupArgumentsLayout->addWidget(TextLabel2_3, 3, 6);
208 GroupArgumentsLayout->addWidget(SpinBox2_3, 3, 7);
209 GroupArgumentsLayout->addWidget(ActionBox, 4, 0, 3, 4);
210 GroupArgumentsLayout->addWidget(MakeGroupsCheck, 5, 5, 1, 4);
211 GroupArgumentsLayout->addWidget(LineEditNewMesh, 6, 5, 1, 4);
213 /***************************************************************/
214 GroupButtons = new QGroupBox(this);
215 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
216 GroupButtonsLayout->setSpacing(SPACING);
217 GroupButtonsLayout->setMargin(MARGIN);
219 buttonOk = new QPushButton(tr("SMESH_BUT_OK"), GroupButtons);
220 buttonOk->setAutoDefault(true);
221 buttonOk->setDefault(true);
222 buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
223 buttonApply->setAutoDefault(true);
224 buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
225 buttonCancel->setAutoDefault(true);
226 buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
227 buttonHelp->setAutoDefault(true);
229 GroupButtonsLayout->addWidget(buttonOk);
230 GroupButtonsLayout->addSpacing(10);
231 GroupButtonsLayout->addWidget(buttonApply);
232 GroupButtonsLayout->addSpacing(10);
233 GroupButtonsLayout->addStretch();
234 GroupButtonsLayout->addWidget(buttonCancel);
235 GroupButtonsLayout->addWidget(buttonHelp);
237 /***************************************************************/
238 SMESHGUI_TranslationDlgLayout->addWidget(ConstructorsBox);
239 SMESHGUI_TranslationDlgLayout->addWidget(GroupArguments);
240 SMESHGUI_TranslationDlgLayout->addWidget(GroupButtons);
242 /* Initialisations */
243 SpinBox1_1->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, DBL_DIGITS_DISPLAY);
244 SpinBox1_2->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, DBL_DIGITS_DISPLAY);
245 SpinBox1_3->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, DBL_DIGITS_DISPLAY);
246 SpinBox2_1->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, DBL_DIGITS_DISPLAY);
247 SpinBox2_2->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, DBL_DIGITS_DISPLAY);
248 SpinBox2_3->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, DBL_DIGITS_DISPLAY);
250 RadioButton1->setChecked(true);
252 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
254 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
256 // Costruction of the logical filter
257 SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter (MESHorSUBMESH);
258 SMESH_TypeFilter* aSmeshGroupFilter = new SMESH_TypeFilter (GROUP);
260 QList<SUIT_SelectionFilter*> aListOfFilters;
261 if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
262 if (aSmeshGroupFilter) aListOfFilters.append(aSmeshGroupFilter);
264 myMeshOrSubMeshOrGroupFilter =
265 new SMESH_LogicalFilter(aListOfFilters, SMESH_LogicalFilter::LO_OR);
267 myHelpFileName = "translation_page.html";
271 /* signals and slots connections */
272 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
273 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
274 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
275 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
276 connect(GroupConstructors, SIGNAL(buttonClicked(int)), SLOT(ConstructorsClicked(int)));
278 connect(SelectElementsButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
279 connect(SelectButton1, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
280 connect(SelectButton2, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
282 connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
283 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
284 /* to close dialog if study change */
285 connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
286 connect(LineEditElements, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
287 connect(CheckBoxMesh, SIGNAL(toggled(bool)), SLOT(onSelectMesh(bool)));
288 connect(ActionGroup, SIGNAL(buttonClicked(int)), SLOT(onActionClicked(int)));
290 ConstructorsClicked(0);
291 SelectionIntoArgument();
292 onActionClicked(MOVE_ELEMS_BUTTON);
295 //=================================================================================
296 // function : ~SMESHGUI_TranslationDlg()
297 // purpose : Destroys the object and frees any allocated resources
298 //=================================================================================
299 SMESHGUI_TranslationDlg::~SMESHGUI_TranslationDlg()
303 //=================================================================================
306 //=================================================================================
307 void SMESHGUI_TranslationDlg::Init (bool ResetControls)
311 myEditCurrentArgument = 0;
312 LineEditElements->clear();
316 buttonOk->setEnabled(false);
317 buttonApply->setEnabled(false);
320 myMesh = SMESH::SMESH_Mesh::_nil();
323 SpinBox1_1->SetValue(0.0);
324 SpinBox1_2->SetValue(0.0);
325 SpinBox1_3->SetValue(0.0);
326 SpinBox2_1->SetValue(0.0);
327 SpinBox2_2->SetValue(0.0);
328 SpinBox2_3->SetValue(0.0);
330 ActionGroup->button( MOVE_ELEMS_BUTTON )->setChecked(true);
331 CheckBoxMesh->setChecked(false);
332 // MakeGroupsCheck->setChecked(false);
333 // MakeGroupsCheck->setEnabled(false);
338 //=================================================================================
339 // function : ConstructorsClicked()
340 // purpose : Radio button management
341 //=================================================================================
342 void SMESHGUI_TranslationDlg::ConstructorsClicked (int constructorId)
344 disconnect(mySelectionMgr, 0, this, 0);
346 switch (constructorId) {
349 TextLabel1->setText(tr("SMESH_POINT_1"));
350 TextLabel1_1->setText(tr("SMESH_X"));
351 TextLabel1_2->setText(tr("SMESH_Y"));
352 TextLabel1_3->setText(tr("SMESH_Z"));
354 SelectButton1->show();
356 SelectButton2->show();
357 TextLabel2_1->show();
359 TextLabel2_2->show();
361 TextLabel2_3->show();
367 TextLabel1->setText(tr("SMESH_VECTOR"));
368 TextLabel1_1->setText(tr("SMESH_DX"));
369 TextLabel1_2->setText(tr("SMESH_DY"));
370 TextLabel1_3->setText(tr("SMESH_DZ"));
372 SelectButton1->hide();
374 SelectButton2->hide();
375 TextLabel2_1->hide();
377 TextLabel2_2->hide();
379 TextLabel2_3->hide();
385 if (myEditCurrentArgument != (QWidget*)LineEditElements) {
386 SMESH::SetPointRepresentation(false);
387 if (!CheckBoxMesh->isChecked())
388 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
389 aViewWindow->SetSelectionMode( CellSelection );
392 myEditCurrentArgument = (QWidget*)LineEditElements;
393 LineEditElements->setFocus();
395 if (CheckBoxMesh->isChecked())
398 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
400 QApplication::instance()->processEvents();
402 resize( minimumSize() );
405 //=================================================================================
406 // function : ClickOnApply()
408 //=================================================================================
409 void SMESHGUI_TranslationDlg::ClickOnApply()
411 if (mySMESHGUI->isActiveStudyLocked())
414 if (myNbOkElements) {
415 QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
417 SMESH::long_array_var anElementsId = new SMESH::long_array;
419 anElementsId->length(aListElementsId.count());
420 for (int i = 0; i < aListElementsId.count(); i++)
421 anElementsId[i] = aListElementsId[i].toInt();
423 SMESH::DirStruct aVector;
424 if (GetConstructorId() == 0) {
425 aVector.PS.x = SpinBox2_1->GetValue() - SpinBox1_1->GetValue();
426 aVector.PS.y = SpinBox2_2->GetValue() - SpinBox1_2->GetValue();
427 aVector.PS.z = SpinBox2_3->GetValue() - SpinBox1_3->GetValue();
428 } else if (GetConstructorId() == 1) {
429 aVector.PS.x = SpinBox1_1->GetValue();
430 aVector.PS.y = SpinBox1_2->GetValue();
431 aVector.PS.z = SpinBox1_3->GetValue();
434 int actionButton = ActionGroup->checkedId();
435 bool makeGroups = ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() );
437 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
438 QApplication::setOverrideCursor(Qt::WaitCursor);
439 switch ( actionButton ) {
440 case MOVE_ELEMS_BUTTON:
441 aMeshEditor->Translate(anElementsId, aVector, false);
443 case COPY_ELEMS_BUTTON:
445 SMESH::ListOfGroups_var groups =
446 aMeshEditor->TranslateMakeGroups(anElementsId, aVector);
448 aMeshEditor->Translate(anElementsId, aVector, true);
450 case MAKE_MESH_BUTTON:
451 SMESH::SMESH_Mesh_var mesh =
452 aMeshEditor->TranslateMakeMesh(anElementsId, aVector, makeGroups,
453 LineEditNewMesh->text().toLatin1().data());
455 QApplication::restoreOverrideCursor();
460 if ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() ||
461 actionButton == MAKE_MESH_BUTTON )
462 mySMESHGUI->updateObjBrowser(true); // new groups may appear
464 ConstructorsClicked(GetConstructorId());
465 SelectionIntoArgument();
469 //=================================================================================
470 // function : ClickOnOk()
472 //=================================================================================
473 void SMESHGUI_TranslationDlg::ClickOnOk()
479 //=================================================================================
480 // function : ClickOnCancel()
482 //=================================================================================
483 void SMESHGUI_TranslationDlg::ClickOnCancel()
485 disconnect(mySelectionMgr, 0, this, 0);
486 mySelectionMgr->clearFilters();
487 //mySelectionMgr->clearSelected();
488 SMESH::SetPointRepresentation(false);
489 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
490 aViewWindow->SetSelectionMode( ActorSelection );
491 mySMESHGUI->ResetState();
495 //=================================================================================
496 // function : ClickOnHelp()
498 //=================================================================================
499 void SMESHGUI_TranslationDlg::ClickOnHelp()
501 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
503 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
507 platform = "winapplication";
509 platform = "application";
511 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
512 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
513 arg(app->resourceMgr()->stringValue("ExternalBrowser",
515 arg(myHelpFileName));
519 //=======================================================================
520 // function : onTextChange()
522 //=======================================================================
523 void SMESHGUI_TranslationDlg::onTextChange (const QString& theNewText)
525 QLineEdit* send = (QLineEdit*)sender();
530 if (send == LineEditElements)
533 buttonOk->setEnabled(false);
534 buttonApply->setEnabled(false);
536 // hilight entered elements
537 SMDS_Mesh* aMesh = 0;
539 aMesh = myActor->GetObject()->GetMesh();
542 Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
544 TColStd_MapOfInteger newIndices;
546 QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
548 if (send == LineEditElements) {
549 for (int i = 0; i < aListId.count(); i++) {
550 const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
552 newIndices.Add(e->GetID());
557 mySelector->AddOrRemoveIndex( anIO, newIndices, false );
558 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
559 aViewWindow->highlight( anIO, true, true );
561 myElementsId = theNewText;
564 if (myNbOkElements) {
565 buttonOk->setEnabled(true);
566 buttonApply->setEnabled(true);
572 //=================================================================================
573 // function : SelectionIntoArgument()
574 // purpose : Called when selection as changed or other case
575 //=================================================================================
576 void SMESHGUI_TranslationDlg::SelectionIntoArgument()
582 QString aString = "";
585 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
586 LineEditElements->setText(aString);
588 buttonOk->setEnabled(false);
589 buttonApply->setEnabled(false);
593 if (!GroupButtons->isEnabled()) // inactive
598 mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
600 int nbSel = aList.Extent();
604 Handle(SALOME_InteractiveObject) IO = aList.First();
605 myMesh = SMESH::GetMeshByIO(IO);
606 if (myMesh->_is_nil())
609 myActor = SMESH::FindActorByObject(myMesh);
611 myActor = SMESH::FindActorByEntry(IO->getEntry());
617 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
620 // MakeGroups is available if there are groups and "Copy"
621 if ( myMesh->NbGroups() == 0 ) {
622 MakeGroupsCheck->setChecked(false);
623 MakeGroupsCheck->setEnabled(false);
625 else if ( ActionGroup->checkedId() != MOVE_ELEMS_BUTTON ) {
626 MakeGroupsCheck->setEnabled(true);
629 if (CheckBoxMesh->isChecked()) {
630 SMESH::GetNameOfSelectedIObjects( mySelectionMgr, aString );
632 if (!SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO)->_is_nil()) { //MESH
634 SMDS_Mesh* aSMDSMesh = myActor->GetObject()->GetMesh();
638 for (int i = aSMDSMesh->MinElementID(); i <= aSMDSMesh->MaxElementID(); i++) {
639 const SMDS_MeshElement * e = aSMDSMesh->FindElement(i);
641 myElementsId += QString(" %1").arg(i);
645 } else if (!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil()) { //SUBMESH
647 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO);
649 // get IDs from submesh
650 SMESH::long_array_var anElementsIds = new SMESH::long_array;
651 anElementsIds = aSubMesh->GetElementsId();
652 for (int i = 0; i < anElementsIds->length(); i++) {
653 myElementsId += QString(" %1").arg(anElementsIds[i]);
655 aNbUnits = anElementsIds->length();
658 SMESH::SMESH_GroupBase_var aGroup =
659 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
660 if (aGroup->_is_nil())
663 // get IDs from smesh group
664 SMESH::long_array_var anElementsIds = new SMESH::long_array;
665 anElementsIds = aGroup->GetListOfID();
666 for (int i = 0; i < anElementsIds->length(); i++) {
667 myElementsId += QString(" %1").arg(anElementsIds[i]);
669 aNbUnits = anElementsIds->length();
672 aNbUnits = SMESH::GetNameOfSelectedElements(mySelector, IO, aString);
673 myElementsId = aString;
679 myNbOkElements = true;
681 aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, IO, aString);
685 SMDS_Mesh* aMesh = myActor->GetObject()->GetMesh();
689 const SMDS_MeshNode * n = aMesh->FindNode(aString.toInt());
697 if (myEditCurrentArgument == (QWidget*)SpinBox1_1) {
698 SpinBox1_1->SetValue(x);
699 SpinBox1_2->SetValue(y);
700 SpinBox1_3->SetValue(z);
701 } else if (myEditCurrentArgument == (QWidget*)SpinBox2_1) {
702 SpinBox2_1->SetValue(x);
703 SpinBox2_2->SetValue(y);
704 SpinBox2_3->SetValue(z);
709 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
710 LineEditElements->setText(aString);
716 if (myNbOkElements) {
717 buttonOk->setEnabled(true);
718 buttonApply->setEnabled(true);
722 //=================================================================================
723 // function : SetEditCurrentArgument()
725 //=================================================================================
726 void SMESHGUI_TranslationDlg::SetEditCurrentArgument()
728 QPushButton* send = (QPushButton*)sender();
730 disconnect(mySelectionMgr, 0, this, 0);
731 mySelectionMgr->clearSelected();
732 mySelectionMgr->clearFilters();
734 if (send == SelectElementsButton) {
735 myEditCurrentArgument = (QWidget*)LineEditElements;
736 SMESH::SetPointRepresentation(false);
737 if (CheckBoxMesh->isChecked()) {
738 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
739 aViewWindow->SetSelectionMode( ActorSelection );
740 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
743 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
744 aViewWindow->SetSelectionMode( CellSelection );
746 } else if (send == SelectButton1) {
747 myEditCurrentArgument = (QWidget*)SpinBox1_1;
748 SMESH::SetPointRepresentation(true);
750 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
751 aViewWindow->SetSelectionMode( NodeSelection );
752 } else if (send == SelectButton2) {
753 myEditCurrentArgument = (QWidget*)SpinBox2_1;
754 SMESH::SetPointRepresentation(true);
756 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
757 aViewWindow->SetSelectionMode( NodeSelection );
760 myEditCurrentArgument->setFocus();
761 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
762 SelectionIntoArgument();
765 //=================================================================================
766 // function : DeactivateActiveDialog()
768 //=================================================================================
769 void SMESHGUI_TranslationDlg::DeactivateActiveDialog()
771 if (ConstructorsBox->isEnabled()) {
772 ConstructorsBox->setEnabled(false);
773 GroupArguments->setEnabled(false);
774 GroupButtons->setEnabled(false);
775 mySMESHGUI->ResetState();
776 mySMESHGUI->SetActiveDialogBox(0);
780 //=================================================================================
781 // function : ActivateThisDialog()
783 //=================================================================================
784 void SMESHGUI_TranslationDlg::ActivateThisDialog()
786 /* Emit a signal to deactivate the active dialog */
787 mySMESHGUI->EmitSignalDeactivateDialog();
788 ConstructorsBox->setEnabled(true);
789 GroupArguments->setEnabled(true);
790 GroupButtons->setEnabled(true);
792 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
794 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
795 aViewWindow->SetSelectionMode( CellSelection );
797 SelectionIntoArgument();
800 //=================================================================================
801 // function : enterEvent()
803 //=================================================================================
804 void SMESHGUI_TranslationDlg::enterEvent (QEvent*)
806 if (!ConstructorsBox->isEnabled())
807 ActivateThisDialog();
810 //=================================================================================
811 // function : closeEvent()
813 //=================================================================================
814 void SMESHGUI_TranslationDlg::closeEvent (QCloseEvent*)
816 /* same than click on cancel button */
820 //=======================================================================
821 //function : hideEvent
822 //purpose : caused by ESC key
823 //=======================================================================
824 void SMESHGUI_TranslationDlg::hideEvent (QHideEvent*)
830 //=======================================================================
831 //function : onSelectMesh
833 //=======================================================================
834 void SMESHGUI_TranslationDlg::onSelectMesh (bool toSelectMesh)
837 TextLabelElements->setText(tr("SMESH_NAME"));
839 TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
841 if (myEditCurrentArgument != LineEditElements) {
842 LineEditElements->clear();
846 mySelectionMgr->clearFilters();
847 SMESH::SetPointRepresentation(false);
850 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
851 aViewWindow->SetSelectionMode( ActorSelection );
852 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
853 LineEditElements->setReadOnly(true);
855 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
856 aViewWindow->SetSelectionMode( CellSelection );
857 LineEditElements->setReadOnly(false);
858 onTextChange(LineEditElements->text());
861 SelectionIntoArgument();
864 //=======================================================================
865 //function : onActionClicked
866 //purpose : slot called when an action type changed
867 //=======================================================================
869 void SMESHGUI_TranslationDlg::onActionClicked(int button)
872 case MOVE_ELEMS_BUTTON:
873 MakeGroupsCheck->setEnabled(false);
874 LineEditNewMesh->setEnabled(false);
876 case COPY_ELEMS_BUTTON:
877 LineEditNewMesh->setEnabled(false);
878 MakeGroupsCheck->setText( tr("SMESH_MAKE_GROUPS"));
879 if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
880 MakeGroupsCheck->setEnabled(true);
882 MakeGroupsCheck->setEnabled(false);
884 case MAKE_MESH_BUTTON:
885 LineEditNewMesh->setEnabled(true);
886 MakeGroupsCheck->setText( tr("SMESH_COPY_GROUPS"));
887 if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
888 MakeGroupsCheck->setEnabled(true);
890 MakeGroupsCheck->setEnabled(false);
896 //=======================================================================
897 //function : setNewMeshName
898 //purpose : update contents of LineEditNewMesh
899 //=======================================================================
901 void SMESHGUI_TranslationDlg::setNewMeshName()
903 LineEditNewMesh->setText("");
904 if ( LineEditNewMesh->isEnabled() && !myMesh->_is_nil() ) {
906 if ( CheckBoxMesh->isChecked() ) {
907 name = LineEditElements->text();
910 _PTR(SObject) meshSO = SMESH::FindSObject( myMesh );
911 name = meshSO->GetName().c_str();
913 if ( !name.isEmpty() )
914 LineEditNewMesh->setText( SMESH::UniqueMeshName( name, "translated"));
918 //=================================================================================
919 // function : GetConstructorId()
921 //=================================================================================
922 int SMESHGUI_TranslationDlg::GetConstructorId()
924 return GroupConstructors->checkedId();
927 //=================================================================================
928 // function : keyPressEvent()
930 //=================================================================================
931 void SMESHGUI_TranslationDlg::keyPressEvent( QKeyEvent* e )
933 QDialog::keyPressEvent( e );
934 if ( e->isAccepted() )
937 if ( e->key() == Qt::Key_F1 ) {