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
85 \brief Simple 'busy state' flag locker.
92 //! Constructor. Sets passed boolean flag to \c true.
93 BusyLocker( bool& busy ) : myBusy( busy ) { myBusy = true; }
94 //! Destructor. Clear external boolean flag passed as parameter to the constructor to \c false.
95 ~BusyLocker() { myBusy = false; }
97 bool& myBusy; //! External 'busy state' boolean flag
103 //=================================================================================
104 // class : SMESHGUI_TranslationDlg()
106 //=================================================================================
107 SMESHGUI_TranslationDlg::SMESHGUI_TranslationDlg( SMESHGUI* theModule )
108 : QDialog( SMESH::GetDesktop( theModule ) ),
109 mySMESHGUI( theModule ),
110 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) )
112 QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SMESH_TRANSLATION_POINTS")));
113 QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SMESH_TRANSLATION_VECTOR")));
114 QPixmap image2 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
117 setAttribute(Qt::WA_DeleteOnClose, true);
118 setWindowTitle(tr("SMESH_TRANSLATION"));
119 setSizeGripEnabled(true);
121 QVBoxLayout* SMESHGUI_TranslationDlgLayout = new QVBoxLayout(this);
122 SMESHGUI_TranslationDlgLayout->setSpacing(SPACING);
123 SMESHGUI_TranslationDlgLayout->setMargin(MARGIN);
125 /***************************************************************/
126 ConstructorsBox = new QGroupBox(tr("SMESH_TRANSLATION"), this);
127 GroupConstructors = new QButtonGroup(this);
128 QHBoxLayout* ConstructorsBoxLayout = new QHBoxLayout(ConstructorsBox);
129 ConstructorsBoxLayout->setSpacing(SPACING);
130 ConstructorsBoxLayout->setMargin(MARGIN);
132 RadioButton1= new QRadioButton(ConstructorsBox);
133 RadioButton1->setIcon(image0);
134 RadioButton2= new QRadioButton(ConstructorsBox);
135 RadioButton2->setIcon(image1);
137 ConstructorsBoxLayout->addWidget(RadioButton1);
138 ConstructorsBoxLayout->addWidget(RadioButton2);
139 GroupConstructors->addButton(RadioButton1, 0);
140 GroupConstructors->addButton(RadioButton2, 1);
142 /***************************************************************/
143 GroupArguments = new QGroupBox(tr("SMESH_ARGUMENTS"), this);
144 QGridLayout* GroupArgumentsLayout = new QGridLayout(GroupArguments);
145 GroupArgumentsLayout->setSpacing(SPACING);
146 GroupArgumentsLayout->setMargin(MARGIN);
148 myIdValidator = new SMESHGUI_IdValidator(this);
150 // Controls for elements selection
151 TextLabelElements = new QLabel(tr("SMESH_ID_ELEMENTS"), GroupArguments);
152 SelectElementsButton = new QPushButton(GroupArguments);
153 SelectElementsButton->setIcon(image2);
154 LineEditElements = new QLineEdit(GroupArguments);
155 LineEditElements->setValidator(myIdValidator);
157 // Control for the whole mesh selection
158 CheckBoxMesh = new QCheckBox(tr("SMESH_SELECT_WHOLE_MESH"), GroupArguments);
160 // Controls for vector and points selection
161 TextLabel1 = new QLabel(GroupArguments);
162 SelectButton1 = new QPushButton(GroupArguments);
163 SelectButton1->setIcon(image2);
165 TextLabel1_1 = new QLabel(GroupArguments);
166 SpinBox1_1 = new SMESHGUI_SpinBox(GroupArguments);
167 TextLabel1_2 = new QLabel(GroupArguments);
168 SpinBox1_2 = new SMESHGUI_SpinBox(GroupArguments);
169 TextLabel1_3 = new QLabel(GroupArguments);
170 SpinBox1_3 = new SMESHGUI_SpinBox(GroupArguments);
172 TextLabel2 = new QLabel(tr("SMESH_POINT_2"), GroupArguments);
173 SelectButton2 = new QPushButton(GroupArguments);
174 SelectButton2->setIcon(image2);
176 TextLabel2_1 = new QLabel(tr("SMESH_X"), GroupArguments);
177 SpinBox2_1 = new SMESHGUI_SpinBox(GroupArguments);
178 TextLabel2_2 = new QLabel(tr("SMESH_Y"), GroupArguments);
179 SpinBox2_2 = new SMESHGUI_SpinBox(GroupArguments);
180 TextLabel2_3 = new QLabel(tr("SMESH_Z"), GroupArguments);
181 SpinBox2_3 = new SMESHGUI_SpinBox(GroupArguments);
183 // switch of action type
184 ActionBox = new QGroupBox(GroupArguments);
185 ActionGroup = new QButtonGroup(GroupArguments);
186 QVBoxLayout* ActionBoxLayout = new QVBoxLayout(ActionBox);
187 ActionBoxLayout->addSpacing(SPACING);
188 ActionBoxLayout->setMargin(MARGIN);
190 QRadioButton* aMoveElements = new QRadioButton(tr("SMESH_MOVE_ELEMENTS"), ActionBox);
191 QRadioButton* aCopyElements = new QRadioButton(tr("SMESH_COPY_ELEMENTS"), ActionBox);
192 QRadioButton* aCreateMesh = new QRadioButton(tr("SMESH_CREATE_MESH"), ActionBox);
194 ActionBoxLayout->addWidget(aMoveElements);
195 ActionBoxLayout->addWidget(aCopyElements);
196 ActionBoxLayout->addWidget(aCreateMesh);
197 ActionGroup->addButton(aMoveElements, MOVE_ELEMS_BUTTON);
198 ActionGroup->addButton(aCopyElements, COPY_ELEMS_BUTTON);
199 ActionGroup->addButton(aCreateMesh, MAKE_MESH_BUTTON);
201 // CheckBox for groups generation
202 MakeGroupsCheck = new QCheckBox(tr("SMESH_MAKE_GROUPS"), GroupArguments);
203 MakeGroupsCheck->setChecked(false);
205 // Name of a mesh to create
206 LineEditNewMesh = new QLineEdit(GroupArguments);
209 GroupArgumentsLayout->addWidget(TextLabelElements, 0, 0);
210 GroupArgumentsLayout->addWidget(SelectElementsButton, 0, 1);
211 GroupArgumentsLayout->addWidget(LineEditElements, 0, 2, 1, 6);
212 GroupArgumentsLayout->addWidget(CheckBoxMesh, 1, 0, 1, 8);
213 GroupArgumentsLayout->addWidget(TextLabel1, 2, 0);
214 GroupArgumentsLayout->addWidget(SelectButton1, 2, 1);
215 GroupArgumentsLayout->addWidget(TextLabel1_1, 2, 2);
216 GroupArgumentsLayout->addWidget(SpinBox1_1, 2, 3);
217 GroupArgumentsLayout->addWidget(TextLabel1_2, 2, 4);
218 GroupArgumentsLayout->addWidget(SpinBox1_2, 2, 5);
219 GroupArgumentsLayout->addWidget(TextLabel1_3, 2, 6);
220 GroupArgumentsLayout->addWidget(SpinBox1_3, 2, 7);
221 GroupArgumentsLayout->addWidget(TextLabel2, 3, 0);
222 GroupArgumentsLayout->addWidget(SelectButton2, 3, 1);
223 GroupArgumentsLayout->addWidget(TextLabel2_1, 3, 2);
224 GroupArgumentsLayout->addWidget(SpinBox2_1, 3, 3);
225 GroupArgumentsLayout->addWidget(TextLabel2_2, 3, 4);
226 GroupArgumentsLayout->addWidget(SpinBox2_2, 3, 5);
227 GroupArgumentsLayout->addWidget(TextLabel2_3, 3, 6);
228 GroupArgumentsLayout->addWidget(SpinBox2_3, 3, 7);
229 GroupArgumentsLayout->addWidget(ActionBox, 4, 0, 3, 4);
230 GroupArgumentsLayout->addWidget(MakeGroupsCheck, 5, 5, 1, 4);
231 GroupArgumentsLayout->addWidget(LineEditNewMesh, 6, 5, 1, 4);
233 /***************************************************************/
234 GroupButtons = new QGroupBox(this);
235 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
236 GroupButtonsLayout->setSpacing(SPACING);
237 GroupButtonsLayout->setMargin(MARGIN);
239 buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
240 buttonOk->setAutoDefault(true);
241 buttonOk->setDefault(true);
242 buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
243 buttonApply->setAutoDefault(true);
244 buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
245 buttonCancel->setAutoDefault(true);
246 buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
247 buttonHelp->setAutoDefault(true);
249 GroupButtonsLayout->addWidget(buttonOk);
250 GroupButtonsLayout->addSpacing(10);
251 GroupButtonsLayout->addWidget(buttonApply);
252 GroupButtonsLayout->addSpacing(10);
253 GroupButtonsLayout->addStretch();
254 GroupButtonsLayout->addWidget(buttonCancel);
255 GroupButtonsLayout->addWidget(buttonHelp);
257 /***************************************************************/
258 SMESHGUI_TranslationDlgLayout->addWidget(ConstructorsBox);
259 SMESHGUI_TranslationDlgLayout->addWidget(GroupArguments);
260 SMESHGUI_TranslationDlgLayout->addWidget(GroupButtons);
262 /* Initialisations */
263 SpinBox1_1->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, DBL_DIGITS_DISPLAY);
264 SpinBox1_2->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, DBL_DIGITS_DISPLAY);
265 SpinBox1_3->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, DBL_DIGITS_DISPLAY);
266 SpinBox2_1->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, DBL_DIGITS_DISPLAY);
267 SpinBox2_2->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, DBL_DIGITS_DISPLAY);
268 SpinBox2_3->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, DBL_DIGITS_DISPLAY);
270 RadioButton1->setChecked(true);
272 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
274 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
276 // Costruction of the logical filter
277 SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter (MESHorSUBMESH);
278 SMESH_TypeFilter* aSmeshGroupFilter = new SMESH_TypeFilter (GROUP);
280 QList<SUIT_SelectionFilter*> aListOfFilters;
281 if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
282 if (aSmeshGroupFilter) aListOfFilters.append(aSmeshGroupFilter);
284 myMeshOrSubMeshOrGroupFilter =
285 new SMESH_LogicalFilter(aListOfFilters, SMESH_LogicalFilter::LO_OR);
287 myHelpFileName = "translation_page.html";
291 /* signals and slots connections */
292 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
293 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
294 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
295 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
296 connect(GroupConstructors, SIGNAL(buttonClicked(int)), SLOT(ConstructorsClicked(int)));
298 connect(SelectElementsButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
299 connect(SelectButton1, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
300 connect(SelectButton2, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
302 connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
303 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
304 /* to close dialog if study change */
305 connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
306 connect(LineEditElements, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
307 connect(CheckBoxMesh, SIGNAL(toggled(bool)), SLOT(onSelectMesh(bool)));
308 connect(ActionGroup, SIGNAL(buttonClicked(int)), SLOT(onActionClicked(int)));
310 ConstructorsClicked(0);
311 SelectionIntoArgument();
312 onActionClicked(MOVE_ELEMS_BUTTON);
315 //=================================================================================
316 // function : ~SMESHGUI_TranslationDlg()
317 // purpose : Destroys the object and frees any allocated resources
318 //=================================================================================
319 SMESHGUI_TranslationDlg::~SMESHGUI_TranslationDlg()
323 //=================================================================================
326 //=================================================================================
327 void SMESHGUI_TranslationDlg::Init (bool ResetControls)
331 myEditCurrentArgument = 0;
332 LineEditElements->clear();
336 buttonOk->setEnabled(false);
337 buttonApply->setEnabled(false);
340 myMesh = SMESH::SMESH_Mesh::_nil();
343 SpinBox1_1->SetValue(0.0);
344 SpinBox1_2->SetValue(0.0);
345 SpinBox1_3->SetValue(0.0);
346 SpinBox2_1->SetValue(0.0);
347 SpinBox2_2->SetValue(0.0);
348 SpinBox2_3->SetValue(0.0);
350 ActionGroup->button( MOVE_ELEMS_BUTTON )->setChecked(true);
351 CheckBoxMesh->setChecked(false);
352 // MakeGroupsCheck->setChecked(false);
353 // MakeGroupsCheck->setEnabled(false);
358 //=================================================================================
359 // function : ConstructorsClicked()
360 // purpose : Radio button management
361 //=================================================================================
362 void SMESHGUI_TranslationDlg::ConstructorsClicked (int constructorId)
364 disconnect(mySelectionMgr, 0, this, 0);
366 switch (constructorId) {
369 TextLabel1->setText(tr("SMESH_POINT_1"));
370 TextLabel1_1->setText(tr("SMESH_X"));
371 TextLabel1_2->setText(tr("SMESH_Y"));
372 TextLabel1_3->setText(tr("SMESH_Z"));
374 SelectButton1->show();
376 SelectButton2->show();
377 TextLabel2_1->show();
379 TextLabel2_2->show();
381 TextLabel2_3->show();
387 TextLabel1->setText(tr("SMESH_VECTOR"));
388 TextLabel1_1->setText(tr("SMESH_DX"));
389 TextLabel1_2->setText(tr("SMESH_DY"));
390 TextLabel1_3->setText(tr("SMESH_DZ"));
392 SelectButton1->hide();
394 SelectButton2->hide();
395 TextLabel2_1->hide();
397 TextLabel2_2->hide();
399 TextLabel2_3->hide();
405 if (myEditCurrentArgument != (QWidget*)LineEditElements) {
406 SMESH::SetPointRepresentation(false);
407 if (!CheckBoxMesh->isChecked())
408 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
409 aViewWindow->SetSelectionMode( CellSelection );
412 myEditCurrentArgument = (QWidget*)LineEditElements;
413 LineEditElements->setFocus();
415 if (CheckBoxMesh->isChecked())
418 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
420 QApplication::instance()->processEvents();
422 resize( minimumSize() );
425 //=================================================================================
426 // function : ClickOnApply()
428 //=================================================================================
429 void SMESHGUI_TranslationDlg::ClickOnApply()
431 if (mySMESHGUI->isActiveStudyLocked())
434 if (myNbOkElements) {
435 QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
437 SMESH::long_array_var anElementsId = new SMESH::long_array;
439 anElementsId->length(aListElementsId.count());
440 for (int i = 0; i < aListElementsId.count(); i++)
441 anElementsId[i] = aListElementsId[i].toInt();
443 SMESH::DirStruct aVector;
444 if (GetConstructorId() == 0) {
445 aVector.PS.x = SpinBox2_1->GetValue() - SpinBox1_1->GetValue();
446 aVector.PS.y = SpinBox2_2->GetValue() - SpinBox1_2->GetValue();
447 aVector.PS.z = SpinBox2_3->GetValue() - SpinBox1_3->GetValue();
448 } else if (GetConstructorId() == 1) {
449 aVector.PS.x = SpinBox1_1->GetValue();
450 aVector.PS.y = SpinBox1_2->GetValue();
451 aVector.PS.z = SpinBox1_3->GetValue();
454 int actionButton = ActionGroup->checkedId();
455 bool makeGroups = ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() );
457 SUIT_OverrideCursor aWaitCursor;
458 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
459 switch ( actionButton ) {
460 case MOVE_ELEMS_BUTTON:
461 aMeshEditor->Translate(anElementsId, aVector, false);
463 case COPY_ELEMS_BUTTON:
465 SMESH::ListOfGroups_var groups =
466 aMeshEditor->TranslateMakeGroups(anElementsId, aVector);
468 aMeshEditor->Translate(anElementsId, aVector, true);
470 case MAKE_MESH_BUTTON:
471 SMESH::SMESH_Mesh_var mesh =
472 aMeshEditor->TranslateMakeMesh(anElementsId, aVector, makeGroups,
473 LineEditNewMesh->text().toLatin1().data());
479 if ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() ||
480 actionButton == MAKE_MESH_BUTTON )
481 mySMESHGUI->updateObjBrowser(true); // new groups may appear
483 ConstructorsClicked(GetConstructorId());
484 SelectionIntoArgument();
488 //=================================================================================
489 // function : ClickOnOk()
491 //=================================================================================
492 void SMESHGUI_TranslationDlg::ClickOnOk()
498 //=================================================================================
499 // function : ClickOnCancel()
501 //=================================================================================
502 void SMESHGUI_TranslationDlg::ClickOnCancel()
504 disconnect(mySelectionMgr, 0, this, 0);
505 mySelectionMgr->clearFilters();
506 //mySelectionMgr->clearSelected();
507 SMESH::SetPointRepresentation(false);
508 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
509 aViewWindow->SetSelectionMode( ActorSelection );
510 mySMESHGUI->ResetState();
514 //=================================================================================
515 // function : ClickOnHelp()
517 //=================================================================================
518 void SMESHGUI_TranslationDlg::ClickOnHelp()
520 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
522 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
526 platform = "winapplication";
528 platform = "application";
530 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
531 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
532 arg(app->resourceMgr()->stringValue("ExternalBrowser",
534 arg(myHelpFileName));
538 //=======================================================================
539 // function : onTextChange()
541 //=======================================================================
542 void SMESHGUI_TranslationDlg::onTextChange (const QString& theNewText)
544 QLineEdit* send = (QLineEdit*)sender();
547 BusyLocker lock( myBusy );
549 if (send == LineEditElements)
552 buttonOk->setEnabled(false);
553 buttonApply->setEnabled(false);
555 // hilight entered elements
556 SMDS_Mesh* aMesh = 0;
558 aMesh = myActor->GetObject()->GetMesh();
561 Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
563 TColStd_MapOfInteger newIndices;
565 QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
567 if (send == LineEditElements) {
568 for (int i = 0; i < aListId.count(); i++) {
569 const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
571 newIndices.Add(e->GetID());
576 mySelector->AddOrRemoveIndex( anIO, newIndices, false );
577 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
578 aViewWindow->highlight( anIO, true, true );
580 myElementsId = theNewText;
583 if (myNbOkElements) {
584 buttonOk->setEnabled(true);
585 buttonApply->setEnabled(true);
589 //=================================================================================
590 // function : SelectionIntoArgument()
591 // purpose : Called when selection as changed or other case
592 //=================================================================================
593 void SMESHGUI_TranslationDlg::SelectionIntoArgument()
596 BusyLocker lock( myBusy );
599 QString aString = "";
601 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
602 LineEditElements->setText(aString);
604 buttonOk->setEnabled(false);
605 buttonApply->setEnabled(false);
608 if (!GroupButtons->isEnabled()) // inactive
613 mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
615 int nbSel = aList.Extent();
619 Handle(SALOME_InteractiveObject) IO = aList.First();
620 myMesh = SMESH::GetMeshByIO(IO);
621 if (myMesh->_is_nil())
624 myActor = SMESH::FindActorByObject(myMesh);
626 myActor = SMESH::FindActorByEntry(IO->getEntry());
632 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
635 // MakeGroups is available if there are groups and "Copy"
636 if ( myMesh->NbGroups() == 0 ) {
637 MakeGroupsCheck->setChecked(false);
638 MakeGroupsCheck->setEnabled(false);
640 else if ( ActionGroup->checkedId() != MOVE_ELEMS_BUTTON ) {
641 MakeGroupsCheck->setEnabled(true);
644 if (CheckBoxMesh->isChecked()) {
645 SMESH::GetNameOfSelectedIObjects( mySelectionMgr, aString );
647 if (!SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO)->_is_nil()) { //MESH
649 SMDS_Mesh* aSMDSMesh = myActor->GetObject()->GetMesh();
653 for (int i = aSMDSMesh->MinElementID(); i <= aSMDSMesh->MaxElementID(); i++) {
654 const SMDS_MeshElement * e = aSMDSMesh->FindElement(i);
656 myElementsId += QString(" %1").arg(i);
660 } else if (!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil()) { //SUBMESH
662 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO);
664 // get IDs from submesh
665 SMESH::long_array_var anElementsIds = new SMESH::long_array;
666 anElementsIds = aSubMesh->GetElementsId();
667 for (int i = 0; i < anElementsIds->length(); i++) {
668 myElementsId += QString(" %1").arg(anElementsIds[i]);
670 aNbUnits = anElementsIds->length();
673 SMESH::SMESH_GroupBase_var aGroup =
674 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
675 if (aGroup->_is_nil())
678 // get IDs from smesh group
679 SMESH::long_array_var anElementsIds = new SMESH::long_array;
680 anElementsIds = aGroup->GetListOfID();
681 for (int i = 0; i < anElementsIds->length(); i++) {
682 myElementsId += QString(" %1").arg(anElementsIds[i]);
684 aNbUnits = anElementsIds->length();
687 aNbUnits = SMESH::GetNameOfSelectedElements(mySelector, IO, aString);
688 myElementsId = aString;
694 myNbOkElements = true;
696 aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, IO, aString);
700 SMDS_Mesh* aMesh = myActor->GetObject()->GetMesh();
704 const SMDS_MeshNode * n = aMesh->FindNode(aString.toInt());
712 if (myEditCurrentArgument == (QWidget*)SpinBox1_1) {
713 SpinBox1_1->SetValue(x);
714 SpinBox1_2->SetValue(y);
715 SpinBox1_3->SetValue(z);
716 } else if (myEditCurrentArgument == (QWidget*)SpinBox2_1) {
717 SpinBox2_1->SetValue(x);
718 SpinBox2_2->SetValue(y);
719 SpinBox2_3->SetValue(z);
723 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
724 LineEditElements->setEnabled(true);
725 LineEditElements->setText(aString);
726 LineEditElements->repaint();
727 LineEditElements->setEnabled(false);
732 if (myNbOkElements) {
733 buttonOk->setEnabled(true);
734 buttonApply->setEnabled(true);
738 //=================================================================================
739 // function : SetEditCurrentArgument()
741 //=================================================================================
742 void SMESHGUI_TranslationDlg::SetEditCurrentArgument()
744 QPushButton* send = (QPushButton*)sender();
746 disconnect(mySelectionMgr, 0, this, 0);
747 mySelectionMgr->clearSelected();
748 mySelectionMgr->clearFilters();
750 if (send == SelectElementsButton) {
751 myEditCurrentArgument = (QWidget*)LineEditElements;
752 SMESH::SetPointRepresentation(false);
753 if (CheckBoxMesh->isChecked()) {
754 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
755 aViewWindow->SetSelectionMode( ActorSelection );
756 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
759 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
760 aViewWindow->SetSelectionMode( CellSelection );
762 } else if (send == SelectButton1) {
763 myEditCurrentArgument = (QWidget*)SpinBox1_1;
764 SMESH::SetPointRepresentation(true);
766 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
767 aViewWindow->SetSelectionMode( NodeSelection );
768 } else if (send == SelectButton2) {
769 myEditCurrentArgument = (QWidget*)SpinBox2_1;
770 SMESH::SetPointRepresentation(true);
772 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
773 aViewWindow->SetSelectionMode( NodeSelection );
776 myEditCurrentArgument->setFocus();
777 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
778 SelectionIntoArgument();
781 //=================================================================================
782 // function : DeactivateActiveDialog()
784 //=================================================================================
785 void SMESHGUI_TranslationDlg::DeactivateActiveDialog()
787 if (ConstructorsBox->isEnabled()) {
788 ConstructorsBox->setEnabled(false);
789 GroupArguments->setEnabled(false);
790 GroupButtons->setEnabled(false);
791 mySMESHGUI->ResetState();
792 mySMESHGUI->SetActiveDialogBox(0);
796 //=================================================================================
797 // function : ActivateThisDialog()
799 //=================================================================================
800 void SMESHGUI_TranslationDlg::ActivateThisDialog()
802 /* Emit a signal to deactivate the active dialog */
803 mySMESHGUI->EmitSignalDeactivateDialog();
804 ConstructorsBox->setEnabled(true);
805 GroupArguments->setEnabled(true);
806 GroupButtons->setEnabled(true);
808 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
810 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
811 aViewWindow->SetSelectionMode( CellSelection );
813 SelectionIntoArgument();
816 //=================================================================================
817 // function : enterEvent()
819 //=================================================================================
820 void SMESHGUI_TranslationDlg::enterEvent (QEvent*)
822 if (!ConstructorsBox->isEnabled())
823 ActivateThisDialog();
826 //=================================================================================
827 // function : closeEvent()
829 //=================================================================================
830 void SMESHGUI_TranslationDlg::closeEvent (QCloseEvent*)
832 /* same than click on cancel button */
836 //=======================================================================
837 //function : hideEvent
838 //purpose : caused by ESC key
839 //=======================================================================
840 void SMESHGUI_TranslationDlg::hideEvent (QHideEvent*)
846 //=======================================================================
847 //function : onSelectMesh
849 //=======================================================================
850 void SMESHGUI_TranslationDlg::onSelectMesh (bool toSelectMesh)
853 TextLabelElements->setText(tr("SMESH_NAME"));
855 TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
857 if (myEditCurrentArgument != LineEditElements) {
858 LineEditElements->clear();
862 mySelectionMgr->clearFilters();
863 SMESH::SetPointRepresentation(false);
866 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
867 aViewWindow->SetSelectionMode( ActorSelection );
868 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
869 LineEditElements->setReadOnly(true);
870 LineEditElements->setValidator(0);
872 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
873 aViewWindow->SetSelectionMode( CellSelection );
874 LineEditElements->setReadOnly(false);
875 LineEditElements->setValidator(myIdValidator);
876 onTextChange(LineEditElements->text());
879 SelectionIntoArgument();
882 //=======================================================================
883 //function : onActionClicked
884 //purpose : slot called when an action type changed
885 //=======================================================================
887 void SMESHGUI_TranslationDlg::onActionClicked(int button)
890 case MOVE_ELEMS_BUTTON:
891 MakeGroupsCheck->setEnabled(false);
892 LineEditNewMesh->setEnabled(false);
894 case COPY_ELEMS_BUTTON:
895 LineEditNewMesh->setEnabled(false);
896 MakeGroupsCheck->setText( tr("SMESH_MAKE_GROUPS"));
897 if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
898 MakeGroupsCheck->setEnabled(true);
900 MakeGroupsCheck->setEnabled(false);
902 case MAKE_MESH_BUTTON:
903 LineEditNewMesh->setEnabled(true);
904 MakeGroupsCheck->setText( tr("SMESH_COPY_GROUPS"));
905 if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
906 MakeGroupsCheck->setEnabled(true);
908 MakeGroupsCheck->setEnabled(false);
914 //=======================================================================
915 //function : setNewMeshName
916 //purpose : update contents of LineEditNewMesh
917 //=======================================================================
919 void SMESHGUI_TranslationDlg::setNewMeshName()
921 LineEditNewMesh->setText("");
922 if ( LineEditNewMesh->isEnabled() && !myMesh->_is_nil() ) {
924 if ( CheckBoxMesh->isChecked() ) {
925 name = LineEditElements->text();
928 _PTR(SObject) meshSO = SMESH::FindSObject( myMesh );
929 name = meshSO->GetName().c_str();
931 if ( !name.isEmpty() )
932 LineEditNewMesh->setText( SMESH::UniqueMeshName( name, "translated"));
936 //=================================================================================
937 // function : GetConstructorId()
939 //=================================================================================
940 int SMESHGUI_TranslationDlg::GetConstructorId()
942 return GroupConstructors->checkedId();
945 //=================================================================================
946 // function : keyPressEvent()
948 //=================================================================================
949 void SMESHGUI_TranslationDlg::keyPressEvent( QKeyEvent* e )
951 QDialog::keyPressEvent( e );
952 if ( e->isAccepted() )
955 if ( e->key() == Qt::Key_F1 ) {